diff options
author | Andrés <andmarti@gmail.com> | 2021-04-01 12:39:53 -0300 |
---|---|---|
committer | Andrés <andmarti@gmail.com> | 2021-04-01 12:39:53 -0300 |
commit | 7633c8e177ff19a5ff0ccbfc1c28ac624ac38e06 (patch) | |
tree | c829e10c984384f07c8490fc7645d66c1a17444f | |
parent | 78611978eb8bbbc9743dc12615e4f1a38368c38e (diff) |
Improve undo / yank using malloc for batches
-rw-r--r-- | src/cmds.c | 117 | ||||
-rw-r--r-- | src/cmds.h | 1 | ||||
-rw-r--r-- | src/cmds_command.c | 4 | ||||
-rw-r--r-- | src/cmds_normal.c | 41 | ||||
-rw-r--r-- | src/cmds_visual.c | 4 | ||||
-rw-r--r-- | src/color.c | 18 | ||||
-rw-r--r-- | src/dep_graph.c | 38 | ||||
-rw-r--r-- | src/dep_graph.h | 1 | ||||
-rwxr-xr-x | src/gram.y | 23 | ||||
-rw-r--r-- | src/interp.c | 47 | ||||
-rw-r--r-- | src/shift.c | 29 | ||||
-rw-r--r-- | src/undo.c | 217 | ||||
-rw-r--r-- | src/undo.h | 10 | ||||
-rw-r--r-- | src/yank.c | 117 |
14 files changed, 334 insertions, 333 deletions
@@ -219,15 +219,12 @@ void deletecol(int col, int mult) { } #ifdef UNDO create_undo_action(); - copy_to_undostruct(0, col, maxrow, col - 1 + mult, UNDO_DEL); + // 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); 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 @@ -243,10 +240,10 @@ void deletecol(int col, int mult) { if (!loading) modflg++; #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, UNDO_ADD); + // 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); + extern struct ent_ptr * deps; if (deps != NULL) free(deps); deps = NULL; @@ -378,7 +375,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)); @@ -522,8 +519,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); + clearent(*pp); // free memory + cleanent(*pp); // fill ent with empty values mark_ent_as_deleted(*pp, FALSE); } *pp = NULL; @@ -566,21 +563,11 @@ 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 { @@ -613,13 +600,7 @@ 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 = -#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.vp = lookat(newrow, newcol); ret->e.v.vf = e->e.v.vf; break; } @@ -895,15 +876,11 @@ void deleterow(int row, int mult) { } #ifdef UNDO create_undo_action(); - 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); + copy_to_undostruct(row, 0, row + mult - 1, maxcol, UNDO_DEL, HANDLE_DEPS, NULL); + save_undo_range_shift(-mult, 0, row, 0, row - 1 + mult, maxcol); + #endif fix_marks(-mult, 0, row + mult - 1, maxrow, 0, maxcol); @@ -917,10 +894,10 @@ void deleterow(int row, int mult) { if (!loading) modflg++; #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, UNDO_ADD); + // 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); + extern struct ent_ptr * deps; if (deps != NULL) free(deps); deps = NULL; @@ -1169,20 +1146,12 @@ 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); - 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 + copy_to_undostruct(tlrow, tlcol, brrow, brcol, UNDO_DEL, HANDLE_DEPS, NULL); +#endif erase_area(tlrow, tlcol, brrow, brcol, 0, 0); //important: this erases the ents, but does NOT mark them as deleted modflg++; @@ -1191,20 +1160,14 @@ 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) - 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); - + copy_to_undostruct(tlrow, tlcol, brrow, brcol, UNDO_ADD, HANDLE_DEPS, NULL); + extern struct ent_ptr * deps; 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; } @@ -1246,7 +1209,6 @@ 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); @@ -1305,8 +1267,10 @@ 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; @@ -2021,6 +1985,7 @@ 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++) { @@ -2029,9 +1994,6 @@ 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; @@ -2062,13 +2024,10 @@ 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; @@ -2174,7 +2133,7 @@ int fsum() { #ifdef UNDO create_undo_action(); - copy_to_undostruct(currow, curcol, currow, curcol, UNDO_DEL); + copy_to_undostruct(currow, curcol, currow, curcol, UNDO_DEL, IGNORE_DEPS, NULL); #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 +2170,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); + copy_to_undostruct(currow, curcol, currow, curcol, UNDO_ADD, IGNORE_DEPS, NULL); end_undo_action(); #endif } @@ -2279,7 +2238,6 @@ 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"); @@ -2287,7 +2245,7 @@ int fcopy(char * action) { } #ifdef UNDO create_undo_action(); - copy_to_undostruct(ri, ci, rf, cf, UNDO_DEL); + copy_to_undostruct(ri, ci, rf, cf, UNDO_DEL, IGNORE_DEPS, NULL); #endif if (! strcmp(action, "")) { @@ -2327,7 +2285,7 @@ int fcopy(char * action) { } #ifdef UNDO - copy_to_undostruct(ri, ci, rf, cf, UNDO_ADD); + copy_to_undostruct(ri, ci, rf, cf, UNDO_ADD, IGNORE_DEPS, NULL); end_undo_action(); #endif @@ -2355,6 +2313,7 @@ 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++) { @@ -2363,21 +2322,13 @@ int pad(int n, int r1, int c1, int r2, int c2) { pad_exceed_width = 1; continue; } - //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 - } + if ((p = *ATBL(tbl, r, c)) != NULL) p->pad = n; modflg++; } } #ifdef UNDO + copy_to_undostruct(r1, c1, r2, c2, UNDO_ADD, IGNORE_DEPS, NULL); end_undo_action(); #endif @@ -109,6 +109,7 @@ 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 2b98acf..f96c53b 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); + copy_to_undostruct(r, c, rf, cf, UNDO_DEL, IGNORE_DEPS, NULL); #endif send_to_interp(interp_line); #ifdef UNDO - copy_to_undostruct(r, c, rf, cf, UNDO_ADD); + copy_to_undostruct(r, c, rf, cf, UNDO_ADD, IGNORE_DEPS, NULL); end_undo_action(); #endif } diff --git a/src/cmds_normal.c b/src/cmds_normal.c index 4251ccf..5a43eb4 100644 --- a/src/cmds_normal.c +++ b/src/cmds_normal.c @@ -569,9 +569,6 @@ 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) { @@ -605,7 +602,9 @@ void do_normalmode(struct block * buf) { n = lookat(currow, c1); } #ifdef UNDO - copy_to_undostruct(currow, c1, currow, c1, UNDO_DEL); + // 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); #endif copyent(n, p, currow - get_mark(buf->pnext->value)->row, c1 - get_mark(buf->pnext->value)->col, 0, 0, maxrow, maxcol, 0); @@ -616,27 +615,13 @@ 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); -#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); + copy_to_undostruct(currow, c1, currow, c1, UNDO_ADD, HANDLE_DEPS, NULL); #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 } @@ -1070,11 +1055,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); + copy_to_undostruct(r, c, rf, cf, UNDO_DEL, IGNORE_DEPS, NULL); #endif send_to_interp(interp_line); #ifdef UNDO - copy_to_undostruct(r, c, rf, cf, UNDO_ADD); + copy_to_undostruct(r, c, rf, cf, UNDO_ADD, IGNORE_DEPS, NULL); end_undo_action(); #endif cmd_multiplier = 0; @@ -1111,6 +1096,7 @@ 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 @@ -1123,18 +1109,13 @@ 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 1c1f1fd..4f00897 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); + copy_to_undostruct(r->tlrow, r->tlcol, r->brrow, r->brcol, UNDO_DEL, IGNORE_DEPS, NULL); #endif send_to_interp(interp_line); #ifdef UNDO - copy_to_undostruct(r->tlrow, r->tlcol, r->brrow, r->brcol, UNDO_ADD); + copy_to_undostruct(r->tlrow, r->tlcol, r->brrow, r->brcol, UNDO_ADD, IGNORE_DEPS, NULL); end_undo_action(); #endif cmd_multiplier = 0; diff --git a/src/color.c b/src/color.c index 6106853..3b2d01a 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); + copy_to_undostruct(i, j, i, j, UNDO_DEL, IGNORE_DEPS, NULL); #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); + copy_to_undostruct(i, j, i, j, UNDO_ADD, IGNORE_DEPS, NULL); end_undo_action(); #endif } @@ -483,6 +483,7 @@ 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 } @@ -494,26 +495,15 @@ 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 1565f10..207ba86 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 depend in another cell. +// need to be evaluated, but do not depends on another cell. e = e->next; } @@ -778,3 +778,39 @@ 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 8edf1ef..b23a69d 100644 --- a/src/dep_graph.h +++ b/src/dep_graph.h @@ -80,6 +80,7 @@ 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(); @@ -417,17 +417,13 @@ command: { // TODO get this code out of gram.y 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, UNDO_DEL); +#ifdef UNDO // 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, UNDO_DEL); - #endif + 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 (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; @@ -444,17 +440,16 @@ command: if (( $2.left.vp->trigger ) && (($2.left.vp->trigger->flag & TRG_WRITE) == TRG_WRITE)) 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, UNDO_ADD); +#ifdef UNDO // 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 b26ca62..b1483e4 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); + copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL, IGNORE_DEPS, NULL); #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); + copy_to_undostruct(minr, minc, maxr, maxc, UNDO_ADD, IGNORE_DEPS, NULL); 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); + copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL, IGNORE_DEPS, NULL); #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); + copy_to_undostruct(minr, minc, maxr, maxc, UNDO_ADD, IGNORE_DEPS, NULL); 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); + copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL, IGNORE_DEPS, NULL); #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); + copy_to_undostruct(minr, minc, maxr, maxc, UNDO_ADD, IGNORE_DEPS, NULL); end_undo_action(); #endif } @@ -2472,17 +2472,12 @@ 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); - 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); + copy_to_undostruct(v->row, v->col, v->row, v->col, UNDO_DEL, HANDLE_DEPS, NULL); } #endif //if (getVertex(graph, lookat(v->row, v->col), 0) != NULL) { @@ -2557,11 +2552,9 @@ void let(struct ent * v, struct enode * e) { } #ifdef UNDO if (!loading) { - 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) + // 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); 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; } @@ -2587,15 +2580,11 @@ 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); - 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); + create_undo_action(); + copy_to_undostruct(v->row, v->col, v->row, v->col, UNDO_DEL, HANDLE_DEPS, NULL); } #endif // No debe borrarse el vertex. Ver comentario en LET @@ -2652,19 +2641,17 @@ 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) { - 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) + // 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); 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; } @@ -3357,7 +3344,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); + copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL, IGNORE_DEPS, NULL); #endif for (r = minr; r <= maxr; r++) { for (c = minc; c <= maxc; c++) { @@ -3385,7 +3372,7 @@ int dateformat(struct ent *v1, struct ent *v2, char * fmt) { } } #ifdef UNDO - copy_to_undostruct(minr, minc, maxr, maxc, UNDO_DEL); + copy_to_undostruct(minr, minc, maxr, maxc, UNDO_ADD, IGNORE_DEPS, NULL); end_undo_action(); #endif modflg++; // increase just one time diff --git a/src/shift.c b/src/shift.c index e8e69b3..08945b4 100644 --- a/src/shift.c +++ b/src/shift.c @@ -79,10 +79,6 @@ 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; @@ -100,18 +96,14 @@ 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, 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); + copy_to_undostruct(r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf, UNDO_DEL, HANDLE_DEPS, NULL); + save_undo_range_shift(-cmd_multiplier, 0, r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf); #endif while (ic--) shift_range(-ic, 0, r, c, rf, cf); if (get_conf_int("autocalc") && ! loading) EvalAll(); #ifdef UNDO - |