summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrés <andmarti@gmail.com>2021-04-01 13:00:10 -0300
committerAndrés <andmarti@gmail.com>2021-04-01 13:00:10 -0300
commit8e397ff0d4df30db3ea429052968a44862531576 (patch)
tree8095431eb9bc684dc1013f9c4f8e734c7d31aa46
parent877aecba58951524cc549a02f1e86143f22a0b6e (diff)
Revert "Improve undo / yank using malloc for batches"
-rw-r--r--src/cmds.c117
-rw-r--r--src/cmds.h1
-rw-r--r--src/cmds_command.c4
-rw-r--r--src/cmds_normal.c41
-rw-r--r--src/cmds_visual.c4
-rw-r--r--src/color.c18
-rw-r--r--src/dep_graph.c38
-rw-r--r--src/dep_graph.h1
-rwxr-xr-xsrc/gram.y23
-rw-r--r--src/interp.c47
-rw-r--r--src/shift.c29
-rw-r--r--src/undo.c217
-rw-r--r--src/undo.h10
-rw-r--r--src/yank.c117
14 files changed, 333 insertions, 334 deletions
diff --git a/src/cmds.c b/src/cmds.c
index 5dfa089..e2562c9 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -219,12 +219,15 @@ void deletecol(int col, int mult) {
}
#ifdef UNDO
create_undo_action();
- // here we save in undostruct, all the ents that depends on the deleted one (before change)
- ents_that_depends_on_range(0, col, maxrow, col - 1 + mult);
- copy_to_undostruct(0, col, maxrow, col - 1 + mult, UNDO_DEL, HANDLE_DEPS, NULL);
+ 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)
+ extern struct ent_ptr * deps;
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, UNDO_DEL);
for (i=col; i < col + mult; i++)
add_undo_col_format(i, 'R', fwidth[i], precision[i], realfmt[i]);
#endif
@@ -240,10 +243,10 @@ void deletecol(int col, int mult) {
if (!loading) modflg++;
#ifdef UNDO
- // here we save in undostruct, just the ents that depends on the deleted one (after change)
- copy_to_undostruct(0, 0, -1, -1, UNDO_ADD, HANDLE_DEPS, NULL);
+ // 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, UNDO_ADD);
- extern struct ent_ptr * deps;
if (deps != NULL) free(deps);
deps = NULL;
@@ -375,7 +378,7 @@ void copyent(register struct ent * n, register struct ent * p, int dr, int dc, i
if (p->label) {
if (n->label) scxfree(n->label);
- n->label = scxmalloc((unsigned) (strlen(p->label) + 1));
+ n->label = scxmalloc((unsigned) (strlen(p->label) + 1));
(void) strcpy(n->label, p->label);
n->flags &= ~is_leftflush;
n->flags |= ((p->flags & is_label) | (p->flags & is_leftflush));
@@ -519,8 +522,8 @@ void erase_area(int sr, int sc, int er, int ec, int ignorelock, int mark_as_dele
if (mark_as_deleted) {
mark_ent_as_deleted(*pp, TRUE);
} else {
- clearent(*pp); // free memory
- cleanent(*pp); // fill ent with empty values
+ clearent(*pp);// free memory
+ cleanent(*pp);
mark_ent_as_deleted(*pp, FALSE);
}
*pp = NULL;
@@ -563,11 +566,21 @@ struct enode * copye(register struct enode *e, int Rdelta, int Cdelta, int r1, i
newrow = e->e.r.left.vf & FIX_ROW || e->e.r.left.vp->row < r1 || e->e.r.left.vp->row > r2 || e->e.r.left.vp->col < c1 || e->e.r.left.vp->col > c2 ? e->e.r.left.vp->row : special == 1 ? r1 + Rdelta + e->e.r.left.vp->col - c1 : e->e.r.left.vp->row + Rdelta;
newcol = e->e.r.left.vf & FIX_COL || e->e.r.left.vp->row < r1 || e->e.r.left.vp->row > r2 || e->e.r.left.vp->col < c1 || e->e.r.left.vp->col > c2 ? e->e.r.left.vp->col : special == 1 ? c1 + Cdelta + e->e.r.left.vp->row - r1 : e->e.r.left.vp->col + Cdelta;
ret->e.r.left.vp =
+#ifdef UNDO
+ // Commented for issue #433
+ // track down in what cases this was needed and change it
+ //special == 2 ? add_undo_aux_ent(lookat(newrow, newcol)) :
+#endif
lookat(newrow, newcol);
ret->e.r.left.vf = e->e.r.left.vf;
newrow = e->e.r.right.vf & FIX_ROW || e->e.r.right.vp->row < r1 || e->e.r.right.vp->row > r2 || e->e.r.right.vp->col < c1 || e->e.r.right.vp->col > c2 ? e->e.r.right.vp->row : special == 1 ? r1 + Rdelta + e->e.r.right.vp->col - c1 : e->e.r.right.vp->row + Rdelta;
newcol = e->e.r.right.vf & FIX_COL || e->e.r.right.vp->row < r1 || e->e.r.right.vp->row > r2 || e->e.r.right.vp->col < c1 || e->e.r.right.vp->col > c2 ? e->e.r.right.vp->col : special == 1 ? c1 + Cdelta + e->e.r.right.vp->row - r1 : e->e.r.right.vp->col + Cdelta;
ret->e.r.right.vp =
+#ifdef UNDO
+ // Commented for issue #433
+ // track down in what cases this was needed and change it
+ //special == 2 ? add_undo_aux_ent(lookat(newrow, newcol)) :
+#endif
lookat(newrow, newcol);
ret->e.r.right.vf = e->e.r.right.vf;
} else {
@@ -600,7 +613,13 @@ struct enode * copye(register struct enode *e, int Rdelta, int Cdelta, int r1, i
newrow = e->e.v.vf & FIX_ROW || e->e.v.vp->row < r1 || e->e.v.vp->row > r2 || e->e.v.vp->col < c1 || e->e.v.vp->col > c2 ? e->e.v.vp->row : special == 1 ? r1 + Rdelta + e->e.v.vp->col - c1 : e->e.v.vp->row + Rdelta;
newcol = e->e.v.vf & FIX_COL || e->e.v.vp->row < r1 || e->e.v.vp->row > r2 || e->e.v.vp->col < c1 || e->e.v.vp->col > c2 ? e->e.v.vp->col : special == 1 ? c1 + Cdelta + e->e.v.vp->row - r1 : e->e.v.vp->col + Cdelta;
}
- ret->e.v.vp = lookat(newrow, newcol);
+ ret->e.v.vp =
+#ifdef UNDO
+ // Commented for issue #433
+ // track down in what cases this was needed and change it
+ //special == 2 ? add_undo_aux_ent(lookat(newrow, newcol)) :
+#endif
+ lookat(newrow, newcol);
ret->e.v.vf = e->e.v.vf;
break;
}
@@ -876,11 +895,15 @@ void deleterow(int row, int mult) {
}
#ifdef UNDO
create_undo_action();
- // here we save in undostruct, all the ents that depends on the deleted one (before change)
- ents_that_depends_on_range(row, 0, row + mult - 1, maxcol);
- copy_to_undostruct(row, 0, row + mult - 1, maxcol, UNDO_DEL, HANDLE_DEPS, NULL);
+ 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)
+ extern struct ent_ptr * deps;
+ 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, UNDO_DEL);
#endif
fix_marks(-mult, 0, row + mult - 1, maxrow, 0, maxcol);
@@ -894,10 +917,10 @@ void deleterow(int row, int mult) {
if (!loading) modflg++;
#ifdef UNDO
- // here we save in undostruct, just the ents that depends on the deleted one (after the change)
- copy_to_undostruct(0, 0, -1, -1, UNDO_ADD, HANDLE_DEPS, NULL);
+ // 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, UNDO_ADD);
- extern struct ent_ptr * deps;
if (deps != NULL) free(deps);
deps = NULL;
@@ -1146,12 +1169,20 @@ void del_selected_cells() {
else
yank_area(tlrow, tlcol, brrow, brcol, 'e', 1);
-#ifdef UNDO
+ #ifdef UNDO
create_undo_action();
+ 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;
+ int i, n = 0;
ents_that_depends_on_range(tlrow, tlcol, brrow, brcol);
- copy_to_undostruct(tlrow, tlcol, brrow, brcol, UNDO_DEL, HANDLE_DEPS, NULL);
-#endif
+ 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, UNDO_DEL);
+ }
+ #endif
erase_area(tlrow, tlcol, brrow, brcol, 0, 0); //important: this erases the ents, but does NOT mark them as deleted
modflg++;
@@ -1160,14 +1191,20 @@ void del_selected_cells() {
EvalAll();
-#ifdef UNDO
+ #ifdef UNDO
// here we save in undostruct, all the ents that depends on the deleted one (after the change)
- copy_to_undostruct(tlrow, tlcol, brrow, brcol, UNDO_ADD, HANDLE_DEPS, NULL);
- extern struct ent_ptr * deps;
+ 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, UNDO_ADD);
+
if (deps != NULL) free(deps);
deps = NULL;
+ #endif
+
+
+ #ifdef UNDO
+ copy_to_undostruct(tlrow, tlcol, brrow, brcol, UNDO_ADD);
end_undo_action();
-#endif
+ #endif
return;
}
@@ -1209,6 +1246,7 @@ void send_to_interp(wchar_t * oper) {
if ((pos = wstr_in_wstr(oper, L"\n")) != -1)
oper[pos] = L'\0';
sc_debug("Interp GOT: %ls", oper);
+ //wprintf(L"Interp GOT: %ls", oper);
}
wcstombs(line, oper, BUFFERSIZE);
@@ -1267,10 +1305,8 @@ struct ent * lookat(int row, int col) {
void cleanent(struct ent * p) {
if (!p) return;
p->label = (char *) 0;
- // do not uncomment. if so mod erase_area.
//p->row = 0;
//p->col = 0;
-
p->flags = may_sync;
p->expr = (struct enode *) 0;
p->v = (double) 0.0;
@@ -1985,7 +2021,6 @@ void valueize_area(int sr, int sc, int er, int ec) {
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(sr, sc, er, ec, UNDO_DEL, IGNORE_DEPS, NULL);
#endif
for (r = sr; r <= er; r++) {
for (c = sc; c <= ec; c++) {
@@ -1994,6 +2029,9 @@ void valueize_area(int sr, int sc, int er, int ec) {
sc_error(" Cell %s%d is locked", coltoa(c), r);
continue;
}
+ #ifdef UNDO
+ copy_to_undostruct(r, c, r, c, UNDO_DEL);
+ #endif
if (p && p->expr) {
efree(p->expr);
p->expr = (struct enode *)0;
@@ -2024,10 +2062,13 @@ void valueize_area(int sr, int sc, int er, int ec) {
if (v_cur->back_edges == NULL ) destroy_vertex(p);
}
}
+
+ #ifdef UNDO
+ copy_to_undostruct(r, c, r, c, UNDO_ADD);
+ #endif
}
}
#ifdef UNDO
- copy_to_undostruct(sr, sc, er, ec, UNDO_ADD, IGNORE_DEPS, NULL);
end_undo_action();
#endif
return;
@@ -2133,7 +2174,7 @@ int fsum() {
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(currow, curcol, currow, curcol, UNDO_DEL, IGNORE_DEPS, NULL);
+ 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--) {
@@ -2170,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, UNDO_ADD, IGNORE_DEPS, NULL);
+ copy_to_undostruct(currow, curcol, currow, curcol, UNDO_ADD);
end_undo_action();
#endif
}
@@ -2238,6 +2279,7 @@ int fcopy(char * action) {
all_formulas_found:
+
if (any_locked_cells(ri, ci, rf, cf)) {
swprintf(interp_line, BUFFERSIZE, L"");
sc_error("Locked cells encountered. Nothing changed");
@@ -2245,7 +2287,7 @@ int fcopy(char * action) {
}
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(ri, ci, rf, cf, UNDO_DEL, IGNORE_DEPS, NULL);
+ copy_to_undostruct(ri, ci, rf, cf, UNDO_DEL);
#endif
if (! strcmp(action, "")) {
@@ -2285,7 +2327,7 @@ int fcopy(char * action) {
}
#ifdef UNDO
- copy_to_undostruct(ri, ci, rf, cf, UNDO_ADD, IGNORE_DEPS, NULL);
+ copy_to_undostruct(ri, ci, rf, cf, UNDO_ADD);
end_undo_action();
#endif
@@ -2313,7 +2355,6 @@ int pad(int n, int r1, int c1, int r2, int c2) {
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(r1, c1, r2, c2, UNDO_DEL, IGNORE_DEPS, NULL);
#endif
for (r = r1; r <= r2; r++) {
@@ -2322,13 +2363,21 @@ int pad(int n, int r1, int c1, int r2, int c2) {
pad_exceed_width = 1;
continue;
}
- if ((p = *ATBL(tbl, r, c)) != NULL) p->pad = n;
+ //p = lookat(r, c);
+ if ((p = *ATBL(tbl, r, c)) != NULL) {
+#ifdef UNDO
+ copy_to_undostruct(r, c, r, c, UNDO_DEL);
+#endif
+ p->pad = n;
+#ifdef UNDO
+ copy_to_undostruct(r, c, r, c, UNDO_ADD);
+#endif
+ }
modflg++;
}
}
#ifdef UNDO
- copy_to_undostruct(r1, c1, r2, c2, UNDO_ADD, IGNORE_DEPS, NULL);
end_undo_action();
#endif
diff --git a/src/cmds.h b/src/cmds.h
index eae624f..42cbe0d 100644
--- a/src/cmds.h
+++ b/src/cmds.h
@@ -109,7 +109,6 @@ void erase_area(int sr, int sc, int er, int ec, int ignorelock, int mark_ent_as_
void auto_justify(int ci, int cf, int min);
void valueize_area(int sr, int sc, int er, int ec);
void sync_refs();
-void syncref(register struct enode * e);
int fcopy(char * action);
int fsum();
int pad(int n, int r1, int c1, int r2, int c2);
diff --git a/src/cmds_command.c b/src/cmds_command.c
index f96c53b..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, UNDO_DEL, IGNORE_DEPS, NULL);
+ copy_to_undostruct(r, c, rf, cf, UNDO_DEL);
#endif
send_to_interp(interp_line);
#ifdef UNDO
- copy_to_undostruct(r, c, rf, cf, UNDO_ADD, IGNORE_DEPS, NULL);
+ 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 5a43eb4..4251ccf 100644
--- a/src/cmds_normal.c
+++ b/src/cmds_normal.c
@@ -569,6 +569,9 @@ void do_normalmode(struct block * buf) {
struct mark * m = get_mark(buf->pnext->value);
if ( m == NULL) return;
+ // added for #244 - 22/03/2018
+ int i;
+ extern struct ent_ptr * deps;
// if m represents a range
if ( m->row == -1 && m->col == -1) {
@@ -602,9 +605,7 @@ void do_normalmode(struct block * buf) {
n = lookat(currow, c1);
}
#ifdef UNDO
- // added for #244 - 22/03/2018
- ents_that_depends_on_range(n->row, n->col, n->row, n->col);
- copy_to_undostruct(currow, c1, currow, c1, UNDO_DEL, HANDLE_DEPS, NULL);
+ 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);
@@ -615,13 +616,27 @@ 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, UNDO_ADD, HANDLE_DEPS, NULL);
+ copy_to_undostruct(currow, c1, currow, c1, UNDO_ADD);
+#endif
+
+ // added for #244 - 22/03/2018
+ ents_that_depends_on_range(n->row, n->col, n->row, n->col);
+
+#ifdef UNDO
+ 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, UNDO_DEL);
#endif
+
+ EvalJustOneVertex(deps[i].vp, deps[i].vp->row, deps[i].vp->col, 0);
+#ifdef UNDO
+ 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, UNDO_ADD);
+#endif
+
}
#ifdef UNDO
- extern struct ent_ptr * deps;
- if (deps != NULL) free(deps);
- deps = NULL;
end_undo_action();
#endif
}
@@ -1055,11 +1070,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, UNDO_DEL, IGNORE_DEPS, NULL);
+ copy_to_undostruct(r, c, rf, cf, UNDO_DEL);
#endif
send_to_interp(interp_line);
#ifdef UNDO
- copy_to_undostruct(r, c, rf, cf, UNDO_ADD, IGNORE_DEPS, NULL);
+ copy_to_undostruct(r, c, rf, cf, UNDO_ADD);
end_undo_action();
#endif
cmd_multiplier = 0;
@@ -1096,7 +1111,6 @@ void do_normalmode(struct block * buf) {
struct ent * p;
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(tlrow, tlcol, brrow, brcol, UNDO_DEL, IGNORE_DEPS, NULL);
#endif
int arg = cmd_multiplier;
int mf = modflg; // keep original modflg
@@ -1109,13 +1123,18 @@ void do_normalmode(struct block * buf) {
//sc_error("Can't increment / decrement a formula");
continue;
} else if (p->flags & is_valid) {
+#ifdef UNDO
+ 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, UNDO_ADD);
+#endif
if (mf == modflg) modflg++; // increase just one time
}
}
}
#ifdef UNDO
- copy_to_undostruct(tlrow, tlcol, brrow, brcol, UNDO_ADD, IGNORE_DEPS, NULL);
end_undo_action();
#endif
if (get_conf_int("autocalc")) EvalAll();
diff --git a/src/cmds_visual.c b/src/cmds_visual.c
index 4f00897..1c1f1fd 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, UNDO_DEL, IGNORE_DEPS, NULL);
+ 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, UNDO_ADD, IGNORE_DEPS, NULL);
+ copy_to_undostruct(r->tlrow, r->tlcol, r->brrow, r->brcol, UNDO_ADD);
end_undo_action();
#endif
cmd_multiplier = 0;
diff --git a/src/color.c b/src/color.c
index 3b2d01a..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, UNDO_DEL, IGNORE_DEPS, NULL);
+ 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, UNDO_ADD, IGNORE_DEPS, NULL);
+ copy_to_undostruct(i, j, i, j, UNDO_ADD);
end_undo_action();
#endif
}
@@ -483,7 +483,6 @@ void unformat(int r, int c, int rf, int cf) {
modflg++;
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(r, rf, c, cf, UNDO_DEL, IGNORE_DEPS, NULL);
#endif
}
@@ -495,15 +494,26 @@ void unformat(int r, int c, int rf, int cf) {
// action
if ( (n = *ATBL(tbl, i, j)) && n->ucolor != NULL) {
+ if (! loading) {
+ #ifdef UNDO
+ copy_to_undostruct(i, j, i, j, UNDO_DEL);
+ #endif
+ }
+
free(n->ucolor);
n->ucolor = NULL;
+
+ if (! loading) {
+ #ifdef UNDO
+ copy_to_undostruct(i, j, i, j, UNDO_ADD);
+ #endif
+ }
}
}
}
if (! loading) {
#ifdef UNDO
- copy_to_undostruct(r, rf, c, cf, UNDO_ADD, IGNORE_DEPS, NULL);
end_undo_action();
#endif
ui_update(TRUE);
diff --git a/src/dep_graph.c b/src/dep_graph.c
index 207ba86..1565f10 100644
--- a/src/dep_graph.c
+++ b/src/dep_graph.c
@@ -384,7 +384,7 @@ void destroy_vertex(struct ent * ent) {
if (e->connectsTo->edges == NULL && e->connectsTo->back_edges == NULL && !e->connectsTo->ent->expr && !(e->connectsTo->ent->flags & is_valid) && ! e->connectsTo->ent->label)
destroy_vertex(e->connectsTo->ent);
// WARNING: an orphan vertex now represents an ent that has an enode thats
-// need to be evaluated, but do not depends on another cell.
+// need to be evaluated, but do not depend in another cell.
e = e->next;
}
@@ -778,39 +778,3 @@ void ents_that_depends_on_range (int r1, int c1, int r2, int c2) {
}
return;
}
-
-/**
- * \brief ents_that_depends_on_list()
- *
- * \details Checks dependency of list of ents.
- *
- * since this is used for pasting yanked ents, on which we may
- * have a difference on rows and columns on which the cells are pasted
- * we take care of it with deltar and deltac
- *
- * \param[in] struct ent * (e_ori)
- * \param[in] deltar
- * \param[in] deltac
- *
- * \return none
- */
-
-void ents_that_depends_on_list(struct ent * e_ori, int deltar, int deltac) {
- struct ent * e = e_ori;
- struct ent * p;
- if (graph == NULL || e == NULL) return;
-
- // at this point deps must be NULL
- deps = NULL;
- dep_size = 0;
-
- while (e != NULL) {
- p = *ATBL(tbl, e->row+deltar, e->col+deltac);
- if (p != NULL) {
- markAllVerticesNotVisited(0);
- ents_that_depends_on(p);
- }
- e = e->next;
- }
- return;
-}
diff --git a/src/dep_graph.h b/src/dep_graph.h
index b23a69d..8edf1ef 100644
--- a/src/dep_graph.h
+++ b/src/dep_graph.h
@@ -80,7 +80,6 @@ void delete_reference(vertexT * v_cur, vertexT * vc, int back_reference);
void markAllVerticesNotVisited(int eval_visited);
void ents_that_depends_on (struct ent * ent);
void ents_that_depends_on_range (int r1, int c1, int r2, int c2);
-void ents_that_depends_on_list(struct ent * e_ori, int deltar, int deltac);
int GraphIsReachable(vertexT * src, vertexT * dest, int back_dep);
void rebuild_graph();
diff --git a/src/gram.y b/src/gram.y
index 5d177c1..7f4f390 100755
--- a/src/gram.y
+++ b/src/gram.y
@@ -417,13 +417,17 @@ command:
{
// TODO get this code out of gram.y
extern graphADT graph;
-#ifdef UNDO
+ #ifdef UNDO
+ create_undo_action();
+ 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);
- create_undo_action();
- copy_to_undostruct($2.left.vp->row, $2.left.vp->col, $2.left.vp->row, $2.left.vp->col, UNDO_DEL, HANDLE_DEPS, NULL);
-#endif
-
+ 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, 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));
$2.left.vp->v = (double) 0.0;
@@ -440,16 +444,17 @@ command:
if (( $2.left.vp->trigger ) && (($2.left.vp->trigger->flag & TRG_WRITE) == TRG_WRITE))
do_trigger($2.left.vp, TRG_WRITE);
-#ifdef UNDO
+ #ifdef UNDO
+ 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)
- copy_to_undostruct($2.left.vp->row, $2.left.vp->col, $2.left.vp->row, $2.left.vp->col, UNDO_ADD, HANDLE_DEPS, NULL);
- extern struct ent_ptr * deps;
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, UNDO_ADD);
free(deps);
deps = NULL;
}
end_undo_action();
-#endif
+ #endif
}
| S_LABEL var_or_range '=' e { slet($2.left.vp, $4, 0); }
diff --git a/src/interp.c b/src/interp.c
index b1483e4..b26ca62 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -2342,7 +2342,7 @@ void fill(struct ent *v1, struct ent *v2, double start, double inc) {
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL, IGNORE_DEPS, NULL);
+ copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL);
#endif
if (calc_order == BYROWS) {
@@ -2372,7 +2372,7 @@ void fill(struct ent *v1, struct ent *v2, double start, double inc) {
sc_error(" Internal error calc_order");
}
#ifdef UNDO
- copy_to_undostruct(minr, minc, maxr, maxc, UNDO_ADD, IGNORE_DEPS, NULL);
+ copy_to_undostruct(minr, minc, maxr, maxc, UNDO_ADD);
end_undo_action();
#endif
}
@@ -2404,7 +2404,7 @@ void lock_cells(struct ent * v1, struct ent * v2) {
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL, IGNORE_DEPS, NULL);
+ copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL);
#endif
for (r = minr; r <= maxr; r++)
for (c = minc; c <= maxc; c++) {
@@ -2412,7 +2412,7 @@ void lock_cells(struct ent * v1, struct ent * v2) {
n->flags |= is_locked;
}
#ifdef UNDO
- copy_to_undostruct(minr, minc, maxr, maxc, UNDO_ADD, IGNORE_DEPS, NULL);
+ copy_to_undostruct(minr, minc, maxr, maxc, UNDO_ADD);
end_undo_action();
#endif
}
@@ -2444,7 +2444,7 @@ void unlock_cells(struct ent * v1, struct ent * v2) {
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL, IGNORE_DEPS, NULL);
+ copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL);
#endif
for (r = minr; r <= maxr; r++)
for (c = minc; c <= maxc; c++) {
@@ -2452,7 +2452,7 @@ void unlock_cells(struct ent * v1, struct ent * v2) {
n->flags &= ~is_locked;
}
#ifdef UNDO
- copy_to_undostruct(minr, minc, maxr, maxc, UNDO_ADD, IGNORE_DEPS, NULL);
+ copy_to_undostruct(minr, minc, maxr, maxc, UNDO_ADD);
end_undo_action();
#endif
}
@@ -2472,12 +2472,17 @@ void let(struct ent * v, struct enode * e) {
if (locked_cell(v->row, v->col)) return;
#ifdef UNDO
+ int i;
extern struct ent_ptr * deps;
if (!loading) {
create_undo_action();
+ 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);
- copy_to_undostruct(v->row, v->col, v->row, v->col, UNDO_DEL, HANDLE_DEPS, NULL);
+ 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, UNDO_DEL);
}
#endif
//if (getVertex(graph, lookat(v->row, v->col), 0) != NULL) {
@@ -2552,9 +2557,11 @@ void let(struct ent * v, struct enode * e) {
}
#ifdef UNDO
if (!loading) {
- // here we also save in undostruct, all the ents that depends on the deleted ones (after change)
- copy_to_undostruct(v->row, v->col, v->row, v->col, UNDO_ADD, HANDLE_DEPS, NULL);
+ 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) {
+ 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, UNDO_ADD);
free(deps);
deps = NULL;
}
@@ -2580,11 +2587,15 @@ void slet(struct ent * v, struct enode * se, int flushdir) {
#ifdef UNDO
extern struct ent_ptr * deps;
+ int i;
if (!loading) {
+ create_undo_action();
+ 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);
- create_undo_action();
- copy_to_undostruct(v->row, v->col, v->row, v->col, UNDO_DEL, HANDLE_DEPS, NULL);
+ 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, UNDO_DEL);
}
#endif
// No debe borrarse el vertex. Ver comentario en LET
@@ -2641,17 +2652,19 @@ void slet(struct ent * v, struct enode * se, int flushdir) {
modflg++;
if (( v->trigger ) && ((v->trigger->flag & TRG_WRITE) == TRG_WRITE)) do_trigger(v,TRG_WRITE);
-#ifdef UNDO
+ #ifdef UNDO
if (!loading) {
- // here we also save in undostruct, all the ents that depends on the deleted ones (after change)
- copy_to_undostruct(v->row, v->col, v->row, v->col, UNDO_ADD, HANDLE_DEPS, NULL);
+ 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) {
+ 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, UNDO_ADD);
free(deps);
deps = NULL;
}
end_undo_action();
}
-#endif
+ #endif
return;
}
@@ -3344,7 +3357,7 @@ int dateformat(struct ent *v1, struct ent *v2, char * fmt) {
#ifdef UNDO
create_undo_action();
- copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL, IGNORE_DEPS, NULL);
+ copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL);
#endif
for (r = minr; r <= maxr; r++) {
for (c = minc; c <= maxc; c++) {
@@ -3372,7 +3385,7 @@ int dateformat(struct ent *v1, struct ent *v2, char * fmt) {
}
}
#ifdef UNDO
- copy_to_undostruct(minr, minc, maxr, maxc, UNDO_ADD, IGNORE_DEPS, NULL);
+ copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL);
end_undo_action();
#endif
modflg++; // increase just one time
diff --git a/src/shift.c b/src/shift.c
index 08945b4..e8e69b3 100644
--- a/src/shift.c
+++ b/src/shift.c
@@ -79,6 +79,10 @@ void shift(int r, int c, int rf, int cf, wchar_t type) {
}
#ifdef UNDO
create_undo_action();
+
+ // here we save in undostruct, all the ents that depends on the deleted one (before change)
+ extern struct ent_ptr * deps;
+ int i;
#endif
int ic = cmd_multiplier + 1;
@@ -96,14 +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
- ents_that_depends_on_range(r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf);
- copy_to_undostruct(r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf, UNDO_DEL, HANDLE_DEPS, NULL);
+ 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, UNDO_DEL);
#endif
while (ic--) shift_range(-ic, 0, r, c, rf, cf);
if (get_conf_int("autocalc") && ! loading) EvalAll();
#ifdef UNDO
- copy_to_undostruct(0, 0, -1, -1, UNDO_ADD, HANDLE_DEPS, NULL);
+ // 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, UNDO_ADD);