summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrés <andmarti@gmail.com>2021-03-30 17:01:32 -0300
committerAndrés <andmarti@gmail.com>2021-03-30 17:01:32 -0300
commit341b1ff59874ecd07dfe4b6290637d826f1100a6 (patch)
treeca743b8a31b4b0ad8a289f3a38d731bac4069b0c
parentaa0cf0e4a5b33944dcecdef85520ddd27373a8ce (diff)
Added UNDO and YANK macros
-rw-r--r--src/cmds.c36
-rw-r--r--src/cmds_command.c4
-rw-r--r--src/cmds_normal.c16
-rw-r--r--src/cmds_visual.c6
-rw-r--r--src/color.c8
-rwxr-xr-xsrc/gram.y8
-rw-r--r--src/interp.c36
-rw-r--r--src/shift.c12
-rw-r--r--src/undo.h3
-rw-r--r--src/yank.c86
-rw-r--r--src/yank.h11
11 files changed, 111 insertions, 115 deletions
diff --git a/src/cmds.c b/src/cmds.c
index 18eb57a..e2562c9 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -219,7 +219,7 @@ void deletecol(int col, int mult) {
}
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(0, col, maxrow, col - 1 + mult, 'd');
+ copy_to_undostruct(0, col, maxrow, col - 1 + mult, UNDO_DEL);
save_undo_range_shift(0, -mult, 0, col, maxrow, col - 1 + mult);
// here we save in undostruct, all the ents that depends on the deleted one (before change)
@@ -227,7 +227,7 @@ void deletecol(int col, int mult) {
int i;
ents_that_depends_on_range(0, col, maxrow, col+mult);
for (i = 0; deps != NULL && i < deps->vf; i++)
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'd');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_DEL);
for (i=col; i < col + mult; i++)
add_undo_col_format(i, 'R', fwidth[i], precision[i], realfmt[i]);
#endif
@@ -245,7 +245,7 @@ void deletecol(int col, int mult) {
#ifdef UNDO
// here we save in undostruct, all the ents that depends on the deleted one (after change)
for (i = 0; deps != NULL && i < deps->vf; i++) // TODO here save just ents that are off the shifted range
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'a');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_ADD);
if (deps != NULL) free(deps);
deps = NULL;
@@ -895,7 +895,7 @@ void deleterow(int row, int mult) {
}
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(row, 0, row + mult - 1, maxcol, 'd');
+ copy_to_undostruct(row, 0, row + mult - 1, maxcol, UNDO_DEL);
save_undo_range_shift(-mult, 0, row, 0, row - 1 + mult, maxcol);
// here we save in undostruct, all the ents that depends on the deleted one (before change)
@@ -903,7 +903,7 @@ void deleterow(int row, int mult) {
int i;
ents_that_depends_on_range(row, 0, row + mult - 1, maxcol);
for (i = 0; deps != NULL && i < deps->vf; i++)
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'd');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_DEL);
#endif
fix_marks(-mult, 0, row + mult - 1, maxrow, 0, maxcol);
@@ -919,7 +919,7 @@ void deleterow(int row, int mult) {
#ifdef UNDO
// here we save in undostruct, all the ents that depends on the deleted one (after the change)
for (i = 0; deps != NULL && i < deps->vf; i++) // TODO here save just ents that are off the shifted range
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'a');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_ADD);
if (deps != NULL) free(deps);
deps = NULL;
@@ -1171,7 +1171,7 @@ void del_selected_cells() {
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(tlrow, tlcol, brrow, brcol, 'd');
+ copy_to_undostruct(tlrow, tlcol, brrow, brcol, UNDO_DEL);
// here we save in undostruct, all the ents that depends on the deleted one (before change)
extern struct ent_ptr * deps;
@@ -1180,7 +1180,7 @@ void del_selected_cells() {
if (deps != NULL) {
n = deps->vf;
for (i = 0; i < n; i++)
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'd');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_DEL);
}
#endif
@@ -1194,7 +1194,7 @@ void del_selected_cells() {
#ifdef UNDO
// here we save in undostruct, all the ents that depends on the deleted one (after the change)
for (i = 0; i < n; i++)
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'a');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_ADD);
if (deps != NULL) free(deps);
deps = NULL;
@@ -1202,7 +1202,7 @@ void del_selected_cells() {
#ifdef UNDO
- copy_to_undostruct(tlrow, tlcol, brrow, brcol, 'a');
+ copy_to_undostruct(tlrow, tlcol, brrow, brcol, UNDO_ADD);
end_undo_action();
#endif
@@ -2030,7 +2030,7 @@ void valueize_area(int sr, int sc, int er, int ec) {
continue;
}
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'd');
+ copy_to_undostruct(r, c, r, c, UNDO_DEL);
#endif
if (p && p->expr) {
efree(p->expr);
@@ -2064,7 +2064,7 @@ void valueize_area(int sr, int sc, int er, int ec) {
}
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'a');
+ copy_to_undostruct(r, c, r, c, UNDO_ADD);
#endif
}
}
@@ -2174,7 +2174,7 @@ int fsum() {
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(currow, curcol, currow, curcol, 'd');
+ copy_to_undostruct(currow, curcol, currow, curcol, UNDO_DEL);
#endif
if (r > 0 && (*ATBL(tbl, r-1, c) != NULL) && (*ATBL(tbl, r-1, c))->flags & is_valid) {
for (r = currow-1; r >= 0; r--) {
@@ -2211,7 +2211,7 @@ int fsum() {
if ((currow != r || curcol != c) && wcslen(interp_line)) {
send_to_interp(interp_line);
#ifdef UNDO
- copy_to_undostruct(currow, curcol, currow, curcol, 'a');
+ copy_to_undostruct(currow, curcol, currow, curcol, UNDO_ADD);
end_undo_action();
#endif
}
@@ -2287,7 +2287,7 @@ int fcopy(char * action) {
}
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(ri, ci, rf, cf, 'd');
+ copy_to_undostruct(ri, ci, rf, cf, UNDO_DEL);
#endif
if (! strcmp(action, "")) {
@@ -2327,7 +2327,7 @@ int fcopy(char * action) {
}
#ifdef UNDO
- copy_to_undostruct(ri, ci, rf, cf, 'a');
+ copy_to_undostruct(ri, ci, rf, cf, UNDO_ADD);
end_undo_action();
#endif
@@ -2366,11 +2366,11 @@ int pad(int n, int r1, int c1, int r2, int c2) {
//p = lookat(r, c);
if ((p = *ATBL(tbl, r, c)) != NULL) {
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'd');
+ copy_to_undostruct(r, c, r, c, UNDO_DEL);
#endif
p->pad = n;
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'a');
+ copy_to_undostruct(r, c, r, c, UNDO_ADD);
#endif
}
modflg++;
diff --git a/src/cmds_command.c b/src/cmds_command.c
index 073f997..2b98acf 100644
--- a/src/cmds_command.c
+++ b/src/cmds_command.c
@@ -702,11 +702,11 @@ void do_commandmode(struct block * sb) {
del_range_wchars(interp_line, l, l + 5);
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(r, c, rf, cf, 'd');
+ copy_to_undostruct(r, c, rf, cf, UNDO_DEL);
#endif
send_to_interp(interp_line);
#ifdef UNDO
- copy_to_undostruct(r, c, rf, cf, 'a');
+ copy_to_undostruct(r, c, rf, cf, UNDO_ADD);
end_undo_action();
#endif
}
diff --git a/src/cmds_normal.c b/src/cmds_normal.c
index 2c9baef..6fb0b4e 100644
--- a/src/cmds_normal.c
+++ b/src/cmds_normal.c
@@ -605,7 +605,7 @@ void do_normalmode(struct block * buf) {
n = lookat(currow, c1);
}
#ifdef UNDO
- copy_to_undostruct(currow, c1, currow, c1, 'd');
+ copy_to_undostruct(currow, c1, currow, c1, UNDO_DEL);
#endif
copyent(n, p, currow - get_mark(buf->pnext->value)->row, c1 - get_mark(buf->pnext->value)->col, 0, 0, maxrow, maxcol, 0);
@@ -616,7 +616,7 @@ void do_normalmode(struct block * buf) {
if (n->expr) EvalJustOneVertex(n, n->row, n->col, 1);
#ifdef UNDO
- copy_to_undostruct(currow, c1, currow, c1, 'a');
+ copy_to_undostruct(currow, c1, currow, c1, UNDO_ADD);
#endif
// added for #244 - 22/03/2018
@@ -624,11 +624,11 @@ void do_normalmode(struct block * buf) {
if (deps != NULL) {
for (i = 0; i < deps->vf; i++) {
#ifdef UNDO
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'd');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_DEL);
#endif
EvalJustOneVertex(deps[i].vp, deps[i].vp->row, deps[i].vp->col, 0);
#ifdef UNDO
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'a');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_ADD);
#endif
}
}
@@ -1071,11 +1071,11 @@ void do_normalmode(struct block * buf) {
else if (buf->value == L'|') swprintf(interp_line, BUFFERSIZE, L"center %s", v_name(r, c));
if (p != -1) swprintf(interp_line + wcslen(interp_line), BUFFERSIZE, L":%s", v_name(rf, cf));
#ifdef UNDO
- copy_to_undostruct(r, c, rf, cf, 'd');
+ copy_to_undostruct(r, c, rf, cf, UNDO_DEL);
#endif
send_to_interp(interp_line);
#ifdef UNDO
- copy_to_undostruct(r, c, rf, cf, 'a');
+ copy_to_undostruct(r, c, rf, cf, UNDO_ADD);
end_undo_action();
#endif
cmd_multiplier = 0;
@@ -1125,11 +1125,11 @@ void do_normalmode(struct block * buf) {
continue;
} else if (p->flags & is_valid) {
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'd');
+ copy_to_undostruct(r, c, r, c, UNDO_DEL);
#endif
p->v += buf->value == L'+' ? (double) arg : - 1 * (double) arg;
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'a');
+ copy_to_undostruct(r, c, r, c, UNDO_ADD);
#endif
if (mf == modflg) modflg++; // increase just one time
}
diff --git a/src/cmds_visual.c b/src/cmds_visual.c
index 768064d..ebf7750 100644
--- a/src/cmds_visual.c
+++ b/src/cmds_visual.c
@@ -488,11 +488,11 @@ void do_visualmode(struct block * buf) {
swprintf(interp_line + wcslen(interp_line), BUFFERSIZE, L":%s", v_name(r->brrow, r->brcol));
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(r->tlrow, r->tlcol, r->brrow, r->brcol, 'd');
+ copy_to_undostruct(r->tlrow, r->tlcol, r->brrow, r->brcol, UNDO_DEL);
#endif
send_to_interp(interp_line);
#ifdef UNDO
- copy_to_undostruct(r->tlrow, r->tlcol, r->brrow, r->brcol, 'a');
+ copy_to_undostruct(r->tlrow, r->tlcol, r->brrow, r->brcol, UNDO_ADD);
end_undo_action();
#endif
cmd_multiplier = 0;
@@ -503,7 +503,7 @@ void do_visualmode(struct block * buf) {
// freeze a range
} else if (buf->value == L'f') {
- add_frange(lookat(r->tlrow, r->tlcol), lookat(r->brrow, r->brcol), 'a');
+ add_frange(lookat(r->tlrow, r->tlcol), lookat(r->brrow, r->brcol), UNDO_ADD);
center_hidden_rows = 0;
center_hidden_cols = 0;
cmd_multiplier = 0;
diff --git a/src/color.c b/src/color.c
index c7836a1..6106853 100644
--- a/src/color.c
+++ b/src/color.c
@@ -397,7 +397,7 @@ void color_cell(int r, int c, int rf, int cf, char * str) {
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(i, j, i, j, 'd');
+ copy_to_undostruct(i, j, i, j, UNDO_DEL);
#endif
}
@@ -448,7 +448,7 @@ void color_cell(int r, int c, int rf, int cf, char * str) {
if (! loading) {
#ifdef UNDO
- copy_to_undostruct(i, j, i, j, 'a');
+ copy_to_undostruct(i, j, i, j, UNDO_ADD);
end_undo_action();
#endif
}
@@ -496,7 +496,7 @@ void unformat(int r, int c, int rf, int cf) {
if ( (n = *ATBL(tbl, i, j)) && n->ucolor != NULL) {
if (! loading) {
#ifdef UNDO
- copy_to_undostruct(i, j, i, j, 'd');
+ copy_to_undostruct(i, j, i, j, UNDO_DEL);
#endif
}
@@ -505,7 +505,7 @@ void unformat(int r, int c, int rf, int cf) {
if (! loading) {
#ifdef UNDO
- copy_to_undostruct(i, j, i, j, 'a');
+ copy_to_undostruct(i, j, i, j, UNDO_ADD);
#endif
}
}
diff --git a/src/gram.y b/src/gram.y
index d3f64b8..0791b20 100755
--- a/src/gram.y
+++ b/src/gram.y
@@ -419,14 +419,14 @@ command:
extern graphADT graph;
#ifdef UNDO
create_undo_action();
- copy_to_undostruct($2.left.vp->row, $2.left.vp->col, $2.left.vp->row, $2.left.vp->col, 'd');
+ copy_to_undostruct($2.left.vp->row, $2.left.vp->col, $2.left.vp->row, $2.left.vp->col, UNDO_DEL);
// here we save in undostruct, all the ents that depends on the deleted one (before change)
extern struct ent_ptr * deps;
int i, n = 0;
ents_that_depends_on_range($2.left.vp->row, $2.left.vp->col, $2.left.vp->row, $2.left.vp->col);
if (deps != NULL) {
for (i = 0, n = deps->vf; i < n; i++)
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'd');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_DEL);
}
#endif
if (getVertex(graph, lookat($2.left.vp->row, $2.left.vp->col), 0) != NULL) destroy_vertex(lookat($2.left.vp->row, $2.left.vp->col));
@@ -446,13 +446,13 @@ command:
do_trigger($2.left.vp,TRG_WRITE);
#ifdef UNDO
- copy_to_undostruct($2.left.vp->row, $2.left.vp->col, $2.left.vp->row, $2.left.vp->col, 'a');
+ copy_to_undostruct($2.left.vp->row, $2.left.vp->col, $2.left.vp->row, $2.left.vp->col, UNDO_ADD);
// here we save in undostruct, all the ents that depends on the deleted one (after change)
if (deps != NULL) free(deps);
ents_that_depends_on_range($2.left.vp->row, $2.left.vp->col, $2.left.vp->row, $2.left.vp->col);
if (deps != NULL) {
for (i = 0, n = deps->vf; i < n; i++)
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'a');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_ADD);
free(deps);
deps = NULL;
}
diff --git a/src/interp.c b/src/interp.c
index affc72f..dd2ca55 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -2348,7 +2348,7 @@ void fill(struct ent *v1, struct ent *v2, double start, double inc) {
for (r = minr; r<=maxr; r++)
for (c = minc; c<=maxc; c++) {
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'd');
+ copy_to_undostruct(r, c, r, c, UNDO_DEL);
#endif
n = lookat(r, c);
if (n->flags&is_locked) continue;
@@ -2358,7 +2358,7 @@ void fill(struct ent *v1, struct ent *v2, double start, double inc) {
n->flags |= (is_changed|is_valid);
n->flags &= ~(iscleared);
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'a');
+ copy_to_undostruct(r, c, r, c, UNDO_ADD);
#endif
}
}
@@ -2366,7 +2366,7 @@ void fill(struct ent *v1, struct ent *v2, double start, double inc) {
for (c = minc; c<=maxc; c++)
for (r = minr; r<=maxr; r++) {
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'd');
+ copy_to_undostruct(r, c, r, c, UNDO_DEL);
#endif
n = lookat(r, c);
(void) clearent(n);
@@ -2375,7 +2375,7 @@ void fill(struct ent *v1, struct ent *v2, double start, double inc) {
n->flags |= (is_changed|is_valid);
n->flags &= ~(iscleared);
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'a');
+ copy_to_undostruct(r, c, r, c, UNDO_ADD);
#endif
}
}
@@ -2419,11 +2419,11 @@ void lock_cells(struct ent * v1, struct ent * v2) {
for (c = minc; c <= maxc; c++) {
n = lookat(r, c);
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'd');
+ copy_to_undostruct(r, c, r, c, UNDO_DEL);
#endif
n->flags |= is_locked;
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'a');
+ copy_to_undostruct(r, c, r, c, UNDO_ADD);
#endif
}
#ifdef UNDO
@@ -2463,11 +2463,11 @@ void unlock_cells(struct ent * v1, struct ent * v2) {
for (c = minc; c <= maxc; c++) {
n = lookat(r, c);
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'd');
+ copy_to_undostruct(r, c, r, c, UNDO_DEL);
#endif
n->flags &= ~is_locked;
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'a');
+ copy_to_undostruct(r, c, r, c, UNDO_ADD);
#endif
}
#ifdef UNDO
@@ -2494,13 +2494,13 @@ void let(struct ent * v, struct enode * e) {
extern struct ent_ptr * deps;
if (!loading) {
create_undo_action();
- copy_to_undostruct(v->row, v->col, v->row, v->col, 'd');
+ copy_to_undostruct(v->row, v->col, v->row, v->col, UNDO_DEL);
// here we save in undostruct, all the ents that depends on the deleted one (before change)
ents_that_depends_on_range(v->row, v->col, v->row, v->col);
if (deps != NULL) {
for (i = 0; i < deps->vf; i++)
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'd');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_DEL);
}
}
#endif
@@ -2577,13 +2577,13 @@ void let(struct ent * v, struct enode * e) {
}
#ifdef UNDO
if (!loading) {
- copy_to_undostruct(v->row, v->col, v->row, v->col, 'a');
+ copy_to_undostruct(v->row, v->col, v->row, v->col, UNDO_ADD);
// here we save in undostruct, all the ents that depends on the deleted one (after change)
if (deps != NULL) free(deps);
ents_that_depends_on_range(v->row, v->col, v->row, v->col);
if (deps != NULL) {
for (i = 0; i < deps->vf; i++)
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'a');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_ADD);
free(deps);
deps = NULL;
}
@@ -2612,12 +2612,12 @@ void slet(struct ent * v, struct enode * se, int flushdir) {
int i;
if (!loading) {
create_undo_action();
- copy_to_undostruct(v->row, v->col, v->row, v->col, 'd');
+ copy_to_undostruct(v->row, v->col, v->row, v->col, UNDO_DEL);
// here we save in undostruct, all the ents that depends on the deleted one (before change)
ents_that_depends_on_range(v->row, v->col, v->row, v->col);
for (i = 0; deps != NULL && i < deps->vf; i++)
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'd');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_DEL);
}
#endif
// No debe borrarse el vertex. Ver comentario en LET
@@ -2677,13 +2677,13 @@ void slet(struct ent * v, struct enode * se, int flushdir) {
#ifdef UNDO
if (!loading) {
- copy_to_undostruct(v->row, v->col, v->row, v->col, 'a');
+ copy_to_undostruct(v->row, v->col, v->row, v->col, UNDO_ADD);
// here we save in undostruct, all the ents that depends on the deleted one (after change)
if (deps != NULL) free(deps);
ents_that_depends_on_range(v->row, v->col, v->row, v->col);
if (deps != NULL) {
for (i = 0; i < deps->vf; i++)
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'a');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_ADD);
free(deps);
deps = NULL;
}
@@ -3387,7 +3387,7 @@ int dateformat(struct ent *v1, struct ent *v2, char * fmt) {
for (c = minc; c <= maxc; c++) {
n = lookat(r, c);
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'd');
+ copy_to_undostruct(r, c, r, c, UNDO_DEL);
#endif
if ( locked_cell(n->row, n->col) || ! (n)->label ) continue;
@@ -3411,7 +3411,7 @@ int dateformat(struct ent *v1, struct ent *v2, char * fmt) {
n->format = s;
#ifdef UNDO
- copy_to_undostruct(r, c, r, c, 'a');
+ copy_to_undostruct(r, c, r, c, UNDO_ADD);
#endif
}
}
diff --git a/src/shift.c b/src/shift.c
index 7f1081b..e8e69b3 100644
--- a/src/shift.c
+++ b/src/shift.c
@@ -100,18 +100,18 @@ void shift(int r, int c, int rf, int cf, wchar_t type) {
fix_marks( -(rf - r + 1) * cmd_multiplier, 0, r, maxrow, c, cf);
yank_area(r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf, 'a', cmd_multiplier); // keep ents in yanklist for sk
#ifdef UNDO
- copy_to_undostruct(r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf, 'd');
+ copy_to_undostruct(r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf, UNDO_DEL);
save_undo_range_shift(-cmd_multiplier, 0, r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf);
ents_that_depends_on_range(r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf);
for (i = 0; deps != NULL && i < deps->vf; i++)
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'd');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_DEL);
#endif
while (ic--) shift_range(-ic, 0, r, c, rf, cf);
if (get_conf_int("autocalc") && ! loading) EvalAll();
#ifdef UNDO
// update(TRUE); this is used just to make debugging easier
for (i = 0; deps != NULL && i < deps->vf; i++) // TODO here save just ents that are off the shifted range
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'a');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_ADD);
#endif
break;
@@ -119,11 +119,11 @@ void shift(int r, int c, int rf, int cf, wchar_t type) {
fix_marks(0, -(cf - c + 1) * cmd_multiplier, r, rf, c, maxcol);
yank_area(r, c, rf, cf + (cf-c+1) * (cmd_multiplier - 1), 'a', cmd_multiplier); // keep ents in yanklist for sk
#ifdef UNDO
- copy_to_undostruct(r, c, rf, cf + (cf-c+1) * (cmd_multiplier - 1), 'd');
+ copy_to_undostruct(r, c, rf, cf + (cf-c+1) * (cmd_multiplier - 1), UNDO_DEL);
save_undo_range_shift(0, -cmd_multiplier, r, c, rf, cf + (cf-c+1) * (cmd_multiplier - 1));
ents_that_depends_on_range(r, c, rf, cf + (cf-c+1) * (cmd_multiplier - 1));
for (i = 0; deps != NULL && i < deps->vf; i++) {
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'd');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_DEL);
}
#endif
while (ic--) shift_range(0, -ic, r, c, rf, cf);
@@ -133,7 +133,7 @@ void shift(int r, int c, int rf, int cf, wchar_t type) {
#ifdef UNDO
for (i = 0; deps != NULL && i < deps->vf; i++) {
if (deps[i].vp->col > cf || deps[i].vp->col <= c) {
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'a');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_ADD);
}
}
#endif
diff --git a/src/undo.h b/src/undo.h
index 3926779..0535c7f 100644
--- a/src/undo.h
+++ b/src/undo.h
@@ -42,6 +42,9 @@
* \brief Header file for undo.c
*/
+#define UNDO_ADD 'a'
+#define UNDO_DEL 'd'
+
struct undo {
struct undo * p_ant;
struct ent * added;
diff --git a/src/yank.c b/src/yank.c
index fe81542..c71411f 100644
--- a/src/yank.c
+++ b/src/yank.c
@@ -52,6 +52,7 @@
#include "stdlib.h"
#include "marks.h"
#include "cmds.h"
+#include "yank.h"
#include "dep_graph.h"
#include "xmalloc.h" // for scxfree
@@ -67,6 +68,7 @@ extern struct ent * back_col(int arg);
int yank_arg; // number of rows and columns yanked. Used for commands like `4yr`
char type_of_yank; // yank type. c=col, r=row, a=range, e=cell, '\0'=no yanking
static struct ent * yanklist;
+struct ent * yanklist_tail; // so we can always add ents at the end of the list easily
/**
* \brief TODO Document init_yanklist()
@@ -75,8 +77,9 @@ static struct ent * yanklist;
*/
void init_yanklist() {
- type_of_yank = '\0';
+ type_of_yank = YANK_NULL;
yanklist = NULL;
+ yanklist_tail = NULL;
}
/**
@@ -119,27 +122,11 @@ void free_yanklist () {
}
yanklist = NULL;
+ yanklist_tail = NULL;
return;
}
/**
- * \brief Count and return number of entries in the yanklist
- *
- * \return number of yanklist entries
- */
-
-int count_yank_ents() {
- int i = 0;
-
- struct ent * r = yanklist;
- while (r != NULL) {
- i++;
- r = r->next;
- }
- return i;
-}
-
-/**
* \brief Add 'ent' element to the yanklist
*
* \param[in] item 'ent' element to add to the yanklist
@@ -167,20 +154,17 @@ void add_ent_to_yanklist(struct ent * item) {
(i_ent)->row = item->row;
(i_ent)->col = item->col;
- // If yanklist is empty, insert at the beginning
+ // If yanklist is empty, insert at the beginning
if (yanklist == NULL) {
yanklist = i_ent;
+ yanklist_tail = i_ent;
return;
}
// If yanklist is NOT empty, insert at the end
- struct ent * r = yanklist;
- struct ent * ant;
- while (r != NULL) {
- ant = r;
- r = r->next;
- }
- ant->next = i_ent;
+ // insert at the end
+ yanklist_tail->next = i_ent;
+ yanklist_tail = i_ent;
return;
}
@@ -210,9 +194,11 @@ void yank_area(int tlrow, int tlcol, int brrow, int brcol, char type, int arg) {
struct ent * elm = *ATBL(tbl, r, c);
// Important: each 'ent' element keeps the corresponding row and col
- if (elm == NULL) elm = lookat(r, c);
- add_ent_to_yanklist(elm);
+ //if (elm == NULL) elm = lookat(r, c);
+ //why create an empty ent where is not one?
+ //better this:
+ if (elm != NULL) add_ent_to_yanklist(elm);
}
return;
}
@@ -242,7 +228,7 @@ void yank_area(int tlrow, int tlcol, int brrow, int brcol, char type, int arg) {
*/
int paste_yanked_ents(int above, int type_paste) {
- if (! count_yank_ents()) return 0;
+ if (yanklist == NULL) return 0;
struct ent * yl = yanklist;
struct ent * yll = yl;
@@ -254,22 +240,22 @@ int paste_yanked_ents(int above, int type_paste) {
create_undo_action();
#endif
- if (type_of_yank == 's') { // paste a range that was yanked in the sort function
+ if (type_of_yank == YANK_SORT) { // paste a range that was yanked in the sort function
diffr = 0;
diffc = curcol - yl->col;
ignorelock = 1;
- } else if (type_of_yank == 'a' || type_of_yank == 'e') { // paste cell or range
+ } else if (type_of_yank == YANK_RANGE || type_of_yank == YANK_CELL) { // paste cell or range
diffr = currow - yl->row;
diffc = curcol - yl->col;
- } else if (type_of_yank == 'r') { // paste row
+ } else if (type_of_yank == YANK_ROW) { // paste row
int c = yank_arg;
#ifdef UNDO
- copy_to_undostruct(currow + ! above, 0, currow + ! above - 1 + yank_arg, maxcol, 'd');
+ copy_to_undostruct(currow + ! above, 0, currow + ! above - 1 + yank_arg, maxcol, UNDO_DEL);
#endif
while (c--) above ? insert_row(0) : insert_row(1);
- if (! above) currow = forw_row(1)->row; // paste below
+ if (! above) currow = forw_row(1)->row; // paste below
diffr = currow - yl->row;
diffc = yl->col;
fix_marks(yank_arg, 0, currow, maxrow, 0, maxcol);
@@ -277,12 +263,12 @@ int paste_yanked_ents(int above, int type_paste) {
save_undo_range_shift(yank_arg, 0, currow, 0, currow - 1 + yank_arg, maxcol);
#endif
- } else if (type_of_yank == 'c') { // paste col
+ } else if (type_of_yank == YANK_COL) { // paste col
int c = yank_arg;
#ifdef UNDO
- copy_to_undostruct(0, curcol + above, maxrow, curcol + above - 1 + yank_arg, 'd');
+ copy_to_undostruct(0, curcol + above, maxrow, curcol + above - 1 + yank_arg, UNDO_DEL);
#endif
- while (c--) above ? insert_col(1) : insert_col(0); // insert cols to the right if above or to the left
+ while (c--) above ? insert_col(1) : insert_col(0); // insert cols to the right if above or to the left
diffr = yl->row;
diffc = curcol - yl->col;
fix_marks(0, yank_arg, 0, maxrow, curcol, maxcol);
@@ -291,26 +277,26 @@ int paste_yanked_ents(int above, int type_paste) {
#endif
}
- // first check if there are any locked cells
+ // first check if there are any locked cells over destination
// if so, just return
- if (type_of_yank == 'a' || type_of_yank == 'e') {
+ if (type_of_yank == YANK_RANGE || type_of_yank == YANK_CELL) {
while (yll != NULL) {
int r = yll->row + diffr;
int c = yll->col + diffc;
checkbounds(&r, &c);
if (any_locked_cells(yll->row + diffr, yll->col + diffc, yll->row + diffr, yll->col + diffc))
+ // TODO: dismiss UNDO here
return -1;
yll = yll->next;
}
}
// otherwise continue
- // por cada ent en yanklist
+ // for each ent in yanklist
while (yl != NULL) {
-
#ifdef UNDO
- copy_to_undostruct(yl->row + diffr, yl->col + diffc, yl->row + diffr, yl->col + diffc, 'd');
+ copy_to_undostruct(yl->row + diffr, yl->col + diffc, yl->row + diffr, yl->col + diffc, UNDO_DEL);
// save graph dependencies as well
@@ -318,12 +304,12 @@ int paste_yanked_ents(int above, int type_paste) {
ents_that_depends_on_range(yl->row + diffr, yl->col + diffc, yl->row + diffr, yl->col + diffc);
if (deps != NULL) {
for (i = 0; i < deps->vf; i++)
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'd');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_DEL);
}
#endif
// here we delete current content of "destino" ent
- if (type_paste == 'a' || type_paste == 's')
+ if (type_paste == YANK_RANGE || type_paste == YANK_SORT)
erase_area(yl->row + diffr, yl->col + diffc, yl->row + diffr, yl->col + diffc, ignorelock, 0);
/*struct ent **pp = ATBL(tbl, yl->row + diffr, yl->col + diffc);
@@ -334,13 +320,13 @@ int paste_yanked_ents(int above, int type_paste) {
struct ent * destino = lookat(yl->row + diffr, yl->col + diffc);
- if (type_paste == 'a' || type_paste == 's') {
+ if (type_paste == YANK_RANGE || type_paste == YANK_SORT) {
(void) copyent(destino, yl, 0, 0, 0, 0, 0, 0, 0);
- } else if (type_paste == 'f') {
+ } else if (type_paste == YANK_FORMAT) {
(void) copyent(destino, yl, 0, 0, 0, 0, 0, 0, 'f');
- } else if (type_paste == 'v') {
+ } else if (type_paste == YANK_VALUE) {
(void) copyent(destino, yl, 0, 0, 0, 0, 0, 0, 'v');
- } else if (type_paste == 'c') {
+ } else if (type_paste == YANK_REF) {
(void) copyent(destino, yl, diffr, diffc, 0, 0, maxrows, maxcols, 'c');
}
@@ -354,14 +340,14 @@ int paste_yanked_ents(int above, int type_paste) {
}
#ifdef UNDO
- copy_to_undostruct(yl->row + diffr, yl->col + diffc, yl->row + diffr, yl->col + diffc, 'a');
+ copy_to_undostruct(yl->row + diffr, yl->col + diffc, yl->row + diffr, yl->col + diffc, UNDO_ADD);
// store dependencies after the change as well
// added for #244 - 22/03/2018
if (deps != NULL) {
for (i = 0; i < deps->vf; i++) {
EvalJustOneVertex(deps[i].vp, deps[i].vp->row, deps[i].vp->col, 0);
- copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, 'a');
+ copy_to_undostruct(deps[i].vp->row, deps[i].vp->col, deps[i].vp->row, deps[i].vp->col, UNDO_ADD);
}
}
#endif
diff --git a/src/yank.h b/src/yank.h
index e912038..be5e8f3 100644
--- a/src/yank.h
+++ b/src/yank.h
@@ -44,12 +44,19 @@
#include "sc.h"
-extern struct ent * yanklist;
+#define YANK_COL 'c'
+#define YANK_ROW 'r'
+#define YANK_RANGE 'a'
+#define YANK_CELL 'e'
+#define YANK_SORT 's'