summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actions/shift.c8
-rw-r--r--src/actions/sort.c8
-rw-r--r--src/clipboard.c4
-rw-r--r--src/cmds/cmds.c48
-rw-r--r--src/cmds/cmds.h2
-rw-r--r--src/cmds/cmds_normal.c58
-rw-r--r--src/cmds/cmds_visual.c43
-rw-r--r--src/file.c25
-rw-r--r--src/format.c15
-rw-r--r--src/format.h1
-rwxr-xr-xsrc/gram.y37
-rw-r--r--src/graph.c13
-rw-r--r--src/graph.h2
-rw-r--r--src/help.c2
-rw-r--r--src/interp.c27
-rw-r--r--src/interp.h8
-rw-r--r--src/main.c4
-rw-r--r--src/marks.c38
-rw-r--r--src/marks.h8
-rw-r--r--src/sc.h6
-rw-r--r--src/sheet.c26
-rw-r--r--src/sheet.h2
-rw-r--r--src/undo.c55
-rw-r--r--src/undo.h7
-rw-r--r--src/yank.c134
-rw-r--r--src/yank.h4
26 files changed, 394 insertions, 191 deletions
diff --git a/src/actions/shift.c b/src/actions/shift.c
index f96ada0..2b37fdb 100644
--- a/src/actions/shift.c
+++ b/src/actions/shift.c
@@ -92,7 +92,7 @@ void shift(struct sheet * sh, int r, int c, int rf, int cf, wchar_t type) {
switch (type) {
case L'j':
- fix_marks( (rf - r + 1) * cmd_multiplier, 0, r, sh->maxrow, c, cf);
+ fix_marks(sh, (rf - r + 1) * cmd_multiplier, 0, r, sh->maxrow, c, cf);
#ifdef UNDO
save_undo_range_shift(cmd_multiplier, 0, r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf);
#endif
@@ -100,7 +100,7 @@ void shift(struct sheet * sh, int r, int c, int rf, int cf, wchar_t type) {
break;
case L'k':
- fix_marks( -(rf - r + 1) * cmd_multiplier, 0, r, sh->maxrow, c, cf);
+ fix_marks(sh, -(rf - r + 1) * cmd_multiplier, 0, r, sh->maxrow, c, cf);
yank_area(sh, 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(sh, r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf);
@@ -115,7 +115,7 @@ void shift(struct sheet * sh, int r, int c, int rf, int cf, wchar_t type) {
break;
case L'h':
- fix_marks(0, -(cf - c + 1) * cmd_multiplier, r, rf, c, sh->maxcol);
+ fix_marks(sh, 0, -(cf - c + 1) * cmd_multiplier, r, rf, c, sh->maxcol);
yank_area(sh, r, c, rf, cf + (cf-c+1) * (cmd_multiplier - 1), 'a', cmd_multiplier); // keep ents in yanklist for sk
#ifdef UNDO
// here we save in undostruct, all the ents that depends on the deleted one (before change)
@@ -133,7 +133,7 @@ void shift(struct sheet * sh, int r, int c, int rf, int cf, wchar_t type) {
break;
case L'l':
- fix_marks(0, (cf - c + 1) * cmd_multiplier, r, rf, c, sh->maxcol);
+ fix_marks(sh, 0, (cf - c + 1) * cmd_multiplier, r, rf, c, sh->maxcol);
#ifdef UNDO
save_undo_range_shift(0, cmd_multiplier, r, c, rf, cf + (cf-c+1) * (cmd_multiplier - 1));
#endif
diff --git a/src/actions/sort.c b/src/actions/sort.c
index b1e8733..1c8fcac 100644
--- a/src/actions/sort.c
+++ b/src/actions/sort.c
@@ -161,17 +161,17 @@ void sortrange(struct sheet * sh, struct ent * left, struct ent * right, char *
// Fix the 'ent' elements in the sorted range
- struct ent * p_aux, * yl = get_yanklist();
+ struct ent_ptr * p_aux, * yl = get_yanklist();
for (c = 0, p_aux = yl; p_aux; p_aux = p_aux->next) {
- if (rows[c] != p_aux->row) {
- for (c = 0; c <= maxr - minr && rows[c] != p_aux->row; c++) ;
+ if (rows[c] != p_aux->vp->row) {
+ for (c = 0; c <= maxr - minr && rows[c] != p_aux->vp->row; c++) ;
if (c > maxr - minr) {
sc_error("sort error");
return;
}
}
- p_aux->row = minr + c;
+ p_aux->vp->row = minr + c;
}
sh->currow = minr;
diff --git a/src/clipboard.c b/src/clipboard.c
index 5d04a8a..c121f01 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -109,7 +109,9 @@ int paste_from_clipboard() {
sc_debug("Content from clipboard exceeds maximum width for a label. Cutting it to %d chars", MAX_IB_LEN);
st[MAX_IB_LEN-1]='\0';
}
- swprintf(line_interp, BUFFERSIZE, L"label %s%d=\"%s\"", coltoa(c), r, st);
+ char * std = str_replace(st, "\"", "\\\""); // backspace double quotes
+ swprintf(line_interp, BUFFERSIZE, L"label %s%d=\"%s\"", coltoa(c), r, std);
+ free(std);
}
if (strlen(st)) send_to_interp(line_interp);
c++;
diff --git a/src/cmds/cmds.c b/src/cmds/cmds.c
index a0af61a..cc24180 100644
--- a/src/cmds/cmds.c
+++ b/src/cmds/cmds.c
@@ -214,7 +214,8 @@ void deletecol(struct sheet * sh, int col, int mult) {
struct roman * roman = session->cur_doc;
- if (col - 1 + mult >= sh->maxcols) {
+ //if (col - 1 + mult >= sh->maxcols) {
+ if (col - 1 + mult > sh->maxcol) {
sc_error("current column + multiplier exceeds max column. Nothing changed");
return;
} else if (any_locked_cells(sh, 0, col, sh->maxrow, col - 1 + mult)) {
@@ -237,7 +238,7 @@ void deletecol(struct sheet * sh, int col, int mult) {
}
#endif
- fix_marks(0, -mult, 0, sh->maxrow, col + mult -1, sh->maxcol);
+ fix_marks(sh, 0, -mult, 0, sh->maxrow, col + mult -1, sh->maxcol);
if (! roman->loading) yank_area(sh, 0, col, sh->maxrow, col + mult - 1, 'c', mult);
// do the job
@@ -325,7 +326,7 @@ void int_deletecol(struct sheet * sh, int col, int mult) {
sh->col_frozen[i] = FALSE;
}
- sh->maxcol--;
+ if (sh->maxcol) sh->maxcol--;
sync_refs(sh);
EvalAll();
//flush_saved(); // we have to flush_saved only at exit.
@@ -357,9 +358,11 @@ void int_deletecol(struct sheet * sh, int col, int mult) {
* \param[in] c2
* \param[in] special
* \return none
+ *
+ * struct ent * n should be already alloc'ed
*/
void copyent(struct ent * n, struct sheet * sh_p, struct ent * p, int dr, int dc, int r1, int c1, int r2, int c2, int special) {
- if (!n || !p) {
+ if (!p) {
sc_error("copyent: internal error");
return;
}
@@ -376,7 +379,6 @@ void copyent(struct ent * n, struct sheet * sh_p, struct ent * p, int dr, int dc
n->expr = copye(p->expr, sh_p, dr, dc, r1, c1, r2, c2, special == 't');
#ifdef UNDO
} else if (special == 'u' && p->expr) { // from spreadsheet to undo
- if (p->expr == NULL) sc_debug("copyent is null!");
n->expr = copye(p->expr, sh_p, dr, dc, r1, c1, r2, c2, 2);
#endif
}
@@ -394,6 +396,11 @@ void copyent(struct ent * n, struct sheet * sh_p, struct ent * p, int dr, int dc
}
n->flags |= p->flags & is_locked;
}
+ if (p->label && special == 'f' && n->label) {
+ n->flags &= ~is_leftflush;
+ n->flags |= ((p->flags & is_label) | (p->flags & is_leftflush));
+ }
+
if (p->format && special != 'v') {
if (n->format) scxfree(n->format);
n->format = scxmalloc((unsigned) (strlen(p->format) + 1));
@@ -907,7 +914,8 @@ void insert_col(struct sheet * sh, int after) {
*/
void deleterow(struct sheet * sh, int row, int mult) {
struct roman * roman = session->cur_doc;
- if (row + mult - 1 > sh->maxrows) {
+ //if (row + mult - 1 >= sh->maxrows) {
+ if (row + mult - 1 > sh->maxrow) {
sc_error("current row + multiplier exceeds max row. Nothing changed");
return;
} else if (any_locked_cells(sh, row, 0, row + mult - 1, sh->maxcol)) {
@@ -928,7 +936,7 @@ void deleterow(struct sheet * sh, int row, int mult) {
}
#endif
- fix_marks(-mult, 0, row + mult - 1, sh->maxrow, 0, sh->maxcol);
+ fix_marks(sh, -mult, 0, row + mult - 1, sh->maxrow, 0, sh->maxcol);
if (! roman->loading) yank_area(sh, row, 0, row + mult - 1, sh->maxcol, 'r', mult);
// do the job
@@ -999,7 +1007,7 @@ void int_deleterow(struct sheet * sh, int row, int mult) {
rebuild_graph(); //TODO CHECK HERE WHY REBUILD IS NEEDED. See NOTE1 in shift.c
sync_refs(sh);
EvalAll();
- sh->maxrow--;
+ if (sh->maxrow) sh->maxrow--;
}
return;
}
@@ -1607,22 +1615,27 @@ struct ent * go_end(struct sheet * sh) {
/**
- * \brief TODO Document tick()
- * \details if ticks a cell, returns struct ent *
- * if ticks a range, return struct ent * to top left cell
- * \return lookat; NULL otherwise
+ * \brief tick(): return an ent_ptr to an ent (or range) previously marked with the 'm' command.
+ * \details
+ * if ticks a cell, malloc's and returns an ent_ptr with struct ent * in ->vp.
+ * if ticks a range, malloc's and returns struct ent * to top left cell in ->vp.
+ * \return ent_ptr (should be free later on).
*/
-struct ent * tick(char ch) {
+struct ent_ptr * tick(char ch) {
struct roman * roman = session->cur_doc;
struct sheet * sh = roman->cur_sh;
int r, c;
struct mark * m = get_mark(ch);
+ if (m->sheet != NULL) sh = m->sheet;
+ struct ent_ptr * ep_result = calloc(1, sizeof(struct ent_ptr));
+
//tick cell
r = m->row;
-
if (r != -1) {
checkbounds(sh, &r, &(sh->curcol));
- return lookat(sh, r, m->col);
+ ep_result->sheet = sh;
+ ep_result->vp = lookat(sh, r, m->col);
+ return ep_result;
}
// tick range
@@ -1631,8 +1644,11 @@ struct ent * tick(char ch) {
c = m->rng->tlcol;
m->rng->selected = 1;
checkbounds(sh, &r, &c);
- return lookat(sh, r, c);
+ ep_result->sheet = sh;
+ ep_result->vp = lookat(sh, r, c);
+ return ep_result;
}
+ free(ep_result);
return NULL;
}
diff --git a/src/cmds/cmds.h b/src/cmds/cmds.h
index 267abb7..89d4145 100644
--- a/src/cmds/cmds.h
+++ b/src/cmds/cmds.h
@@ -77,7 +77,7 @@ void scroll_left (struct sheet * sh, int n);
void scroll_right (struct sheet * sh, int n);
void scroll_down(struct sheet * sh, int n);
void scroll_up(struct sheet * sh, int n);
-struct ent * tick(char c); // 'tick' ( ' ) command
+struct ent_ptr * tick(char ch); // 'tick' ( ' ) command
struct ent * left_limit(struct sheet * sh);
struct ent * right_limit(struct sheet * sh, int row);
struct ent * goto_top(struct sheet * sh);
diff --git a/src/cmds/cmds_normal.c b/src/cmds/cmds_normal.c
index d60a011..60455c7 100644
--- a/src/cmds/cmds_normal.c
+++ b/src/cmds/cmds_normal.c
@@ -184,19 +184,23 @@ void do_normalmode(struct block * buf) {
case L'\'':
if (bs != 2) break;
unselect_ranges();
- e = tick(buf->pnext->value);
- if (sh->row_hidden[e->row]) {
+ struct ent_ptr * ep = tick(buf->pnext->value);
+ if (sh->row_hidden[ep->vp->row]) {
sc_error("Cell row is hidden");
+ if (ep != NULL) free(ep);
break;
}
- if (sh->col_hidden[e->col]) {
+ if (sh->col_hidden[ep->vp->col]) {
sc_error("Cell column is hidden");
+ if (ep != NULL) free(ep);
break;
}
- sh->lastrow = sh->currow;
- sh->lastcol = sh->curcol;
- sh->currow = e->row;
- sh->curcol = e->col;
+ if (ep->sheet != NULL) roman->cur_sh = ep->sheet;
+ roman->cur_sh->lastrow = roman->cur_sh->currow;
+ roman->cur_sh->lastcol = roman->cur_sh->curcol;
+ roman->cur_sh->currow = ep->vp->row;
+ roman->cur_sh->curcol = ep->vp->col;
+ if (ep != NULL) free(ep);
ui_update(TRUE);
break;
@@ -411,14 +415,38 @@ void do_normalmode(struct block * buf) {
// repeat last goto command - backwards
case L'N':
- go_previous();
+ {
+ struct roman * roman = session->cur_doc;
+ struct sheet * sh = roman->cur_sh;
+ extern struct go_save gs;
+ if (gs.g_sheet == sh) {
+ go_previous();
+ } else if (gs.g_type == G_NUM) {
+ num_search(sh, gs.g_n, 0, 0, sh->maxrow, sh->maxcol, 0, gs.g_flow);
+ } else if (gs.g_type == G_STR) {
+ gs.g_type = G_NONE; /* Don't free the string */
+ str_search(sh, gs.g_s, 0, 0, sh->maxrow, sh->maxcol, 0, gs.g_flow);
+ }
ui_update(TRUE);
+ }
break;
// repeat last goto command
case L'n':
- go_last();
+ {
+ struct roman * roman = session->cur_doc;
+ struct sheet * sh = roman->cur_sh;
+ extern struct go_save gs;
+ if (gs.g_sheet == sh) {
+ go_last();
+ } else if (gs.g_type == G_NUM) {
+ num_search(sh, gs.g_n, 0, 0, sh->maxrow, sh->maxcol, 0, gs.g_flow);
+ } else if (gs.g_type == G_STR) {
+ gs.g_type = G_NONE; /* Don't free the string */
+ str_search(sh, gs.g_s, 0, 0, sh->maxrow, sh->maxcol, 0, gs.g_flow);
+ }
ui_update(TRUE);
+ }
break;
// END OF MOVEMENT COMMANDS
@@ -608,9 +636,9 @@ void do_normalmode(struct block * buf) {
int p = is_range_selected();
if (p != -1) { // mark range
struct srange * sr = get_range_by_pos(p);
- set_range_mark(buf->pnext->value, sr);
+ set_range_mark(buf->pnext->value, sh, sr);
} else // mark cell
- set_cell_mark(buf->pnext->value, sh->currow, sh->curcol);
+ set_cell_mark(buf->pnext->value, sh, sh->currow, sh->curcol);
roman->modflg++;
break;
@@ -792,7 +820,7 @@ void do_normalmode(struct block * buf) {
#ifdef UNDO
save_undo_range_shift(1, 0, sh->currow, 0, sh->currow, sh->maxcol);
#endif
- fix_marks(1, 0, sh->currow, sh->maxrow, 0, sh->maxcol);
+ fix_marks(sh, 1, 0, sh->currow, sh->maxrow, 0, sh->maxcol);
insert_row(sh, 0);
#ifdef UNDO
add_undo_row_format(sh->currow, 'A', sh->row_format[sh->currow]);
@@ -802,7 +830,7 @@ void do_normalmode(struct block * buf) {
#ifdef UNDO
save_undo_range_shift(0, 1, 0, sh->curcol, sh->maxrow, sh->curcol);
#endif
- fix_marks(0, 1, 0, sh->maxrow, sh->curcol, sh->maxcol);
+ fix_marks(sh, 0, 1, 0, sh->maxrow, sh->curcol, sh->maxcol);
insert_col(sh, 0);
#ifdef UNDO
add_undo_col_format(sh->curcol, 'A', sh->fwidth[sh->curcol], sh->precision[sh->curcol], sh->realfmt[sh->curcol]);
@@ -826,7 +854,7 @@ void do_normalmode(struct block * buf) {
#ifdef UNDO
save_undo_range_shift(1, 0, sh->currow+1, 0, sh->currow+1, sh->maxcol);
#endif
- fix_marks(1, 0, sh->currow+1, sh->maxrow, 0, sh->maxcol);
+ fix_marks(sh, 1, 0, sh->currow+1, sh->maxrow, 0, sh->maxcol);
insert_row(sh, 1);
#ifdef UNDO
add_undo_row_format(sh->currow, 'A', sh->row_format[sh->currow]);
@@ -836,7 +864,7 @@ void do_normalmode(struct block * buf) {
#ifdef UNDO
save_undo_range_shift(0, 1, 0, sh->curcol+1, sh->maxrow, sh->curcol+1);
#endif
- fix_marks(0, 1, 0, sh->maxrow, sh->curcol+1, sh->maxcol);
+ fix_marks(sh, 0, 1, 0, sh->maxrow, sh->curcol+1, sh->maxcol);
insert_col(sh, 1);
#ifdef UNDO
add_undo_col_format(sh->curcol, 'A', sh->fwidth[sh->curcol], sh->precision[sh->curcol], sh->realfmt[sh->curcol]);
diff --git a/src/cmds/cmds_visual.c b/src/cmds/cmds_visual.c
index a813d72..19c6778 100644
--- a/src/cmds/cmds_visual.c
+++ b/src/cmds/cmds_visual.c
@@ -327,20 +327,35 @@ void do_visualmode(struct block * buf) {
// '
} else if (buf->value == L'\'') {
// if we receive a mark of a range, just return.
- if (get_mark(buf->pnext->value)->row == -1) return;
+ if (get_mark(buf->pnext->value)->row == -1) {
+ sc_error("That is a mark of a range. Returning.");
+ return;
+ }
+
+ struct ent_ptr * ep = tick(buf->pnext->value);
+ if (ep == NULL) {
+ sc_error("No mark. Returning.");
+ return;
+ } else if (ep->sheet != NULL && ep->sheet != roman->cur_sh) {
+ sc_error("Cell marked is on other sheet. Dismissing.");
+ if (ep != NULL) free(ep);
+ return;
+ }
- struct ent * e = tick(buf->pnext->value);
- if (sh->row_hidden[e->row]) {
+ if (sh->row_hidden[ep->vp->row]) {
sc_error("Cell row is hidden");
+ if (ep != NULL) free(ep);
return;
- } else if (sh->col_hidden[e->col]) {
+ } else if (sh->col_hidden[ep->vp->col]) {
sc_error("Cell column is hidden");
+ if (ep != NULL) free(ep);
return;
}
- r->tlrow = r->tlrow < e->row ? r->tlrow : e->row;
- r->tlcol = r->tlcol < e->col ? r->tlcol : e->col;
- r->brrow = r->brrow > e->row ? r->brrow : e->row;
- r->brcol = r->brcol > e->col ? r->brcol : e->col;
+ r->tlrow = r->tlrow < ep->vp->row ? r->tlrow : ep->vp->row;
+ r->tlcol = r->tlcol < ep->vp->col ? r->tlcol : ep->vp->col;
+ r->brrow = r->brrow > ep->vp->row ? r->brrow : ep->vp->row;
+ r->brcol = r->brcol > ep->vp->col ? r->brcol : ep->vp->col;
+ if (ep != NULL) free(ep);
// w
} else if (buf->value == L'w') {
@@ -396,7 +411,7 @@ void do_visualmode(struct block * buf) {
} else if (buf->value == L'm' && get_bufsize(buf) == 2) {
del_ranges_by_mark(buf->pnext->value);
srange * rn = create_range('\0', '\0', lookat(sh, r->tlrow, r->tlcol), lookat(sh, r->brrow, r->brcol));
- set_range_mark(buf->pnext->value, rn);
+ set_range_mark(buf->pnext->value, sh, rn);
exit_visualmode();
chg_mode('.');
ui_show_header();
@@ -445,15 +460,15 @@ void do_visualmode(struct block * buf) {
// 'p' normal paste
// 'P' Works like 'p' except that all cell references are adjusted.
} else if (buf->value == 'P' || buf->value == 'p') {
- struct ent * yl = get_yanklist();
+ struct ent_ptr * yl = get_yanklist();
int type_paste = (buf->value == 'P') ? 'c' : 'a' ;
int row, col;
if( yl != NULL) {
- int colsize = -(yl->col); //calculate colsize for correct repeating if paste area is bigger than yank area
- int rowsize = -(yl->row); //calculate rowsize
+ int colsize = -(yl->vp->col); //calculate colsize for correct repeating if paste area is bigger than yank area
+ int rowsize = -(yl->vp->row); //calculate rowsize
while (yl->next != NULL) { yl = yl->next; } //get the last one to calculated size of yank_area
- colsize += (yl->col +1); //calculate size
- rowsize += (yl->row +1); //calculate size
+ colsize += (yl->vp->col +1); //calculate size
+ rowsize += (yl->vp->row +1); //calculate size
#ifdef DEBUG
char str[20];
sprintf(str, "RowSize:%d ColSize:%d Type Paste:%d", rowsize, colsize, type_paste);
diff --git a/src/file.c b/src/file.c
index 3e1d06c..f532efd 100644
--- a/src/file.c
+++ b/src/file.c
@@ -113,18 +113,15 @@ void erasedb(struct sheet * sheet, int _free) {
struct ent ** pp = ATBL(sheet, sheet->tbl, r, 0);
for (c = 0; c++ < sheet->maxcols; pp++)
if (*pp != NULL) {
- //(*pp)->next = freeents; /* save [struct ent] for reuse */
- //freeents = *pp;
clearent(*pp);
if (_free) free(*pp);
+ else {
+ (*pp)->next = freeents; /* save [struct ent] for reuse */
+ freeents = *pp;
+ }
}
}
- for (c = 0; c < COLFORMATS; c++) {
- if (colformat[c] != NULL) scxfree(colformat[c]);
- colformat[c] = NULL;
- }
-
sheet->maxrow = 0;
sheet->maxcol = 0;
@@ -479,8 +476,6 @@ void write_fd(FILE * f, struct roman * doc) {
}
}
- write_marks(f);
-
write_cells(f, doc, sh, 0, 0, sh->maxrow, sh->maxcol, 0, 0);
struct custom_color * cc;
@@ -616,6 +611,8 @@ void write_fd(FILE * f, struct roman * doc) {
sh = sh->next;
}
+ // write marks of document
+ write_marks(f);
}
@@ -625,7 +622,7 @@ void write_fd(FILE * f, struct roman * doc) {
* \param[in] f file pointer
* \return none
*/
-void write_marks(register FILE *f) {
+void write_marks(FILE * f) {
int i;
struct mark * m;
@@ -633,11 +630,11 @@ void write_marks(register FILE *f) {
m = get_mark((char) i);
// m->rng should never be NULL if both m->col and m->row are -1 !!
- if ( m->row == -1 && m->col == -1) { // && m->rng != NULL ) {
- fprintf(f, "mark %c %s%d ", i, coltoa(m->rng->tlcol), m->rng->tlrow);
+ if ( m->row == -1 && m->col == -1) {
+ fprintf(f, "mark %c \"%s\" %s%d ", i, m->sheet->name, coltoa(m->rng->tlcol), m->rng->tlrow);
fprintf(f, "%s%d\n", coltoa(m->rng->brcol), m->rng->brrow);
- } else if ( m->row != 0 && m->row != 0) { // && m->rng == NULL) {
- fprintf(f, "mark %c %s%d\n", i, coltoa(m->col), m->row);
+ } else if ( m->row != 0 && m->row != 0) {
+ fprintf(f, "mark %c \"%s\" %s%d\n", i, m->sheet->name, coltoa(m->col), m->row);
}
}
return;
diff --git a/src/format.c b/src/format.c
index 99ab736..e85e20b 100644
--- a/src/format.c
+++ b/src/format.c
@@ -129,6 +129,7 @@
#include <sys/types.h>
#include <time.h>
#include "sc.h"
+#include "xmalloc.h"
#define EOS '\0'
#define MAXBUF 256
@@ -635,3 +636,17 @@ int engformat(int fmt, int width, int lprecision, double val, char *buf, int buf
}
return (TRUE);
}
+
+/**
+ * \brief free_formats()
+ * \return none
+ */
+void free_formats() {
+ int c;
+ for (c = 0; c < COLFORMATS; c++) {
+ if (colformat[c] != NULL)
+ scxfree(colformat[c]);
+ colformat[c] = NULL;
+ }
+ return;
+}
diff --git a/src/format.h b/src/format.h
index cee1d13..af58ee4 100644
--- a/src/format.h
+++ b/src/format.h
@@ -44,3 +44,4 @@
int format(char *fmt, int lprecision, double val, char *buf, int buflen);
int engformat(int fmt, int width, int lprecision, double val, char *buf, int buflen);
+void free_formats();
diff --git a/src/gram.y b/src/gram.y
index 824fe0c..0ee0939 100755
--- a/src/gram.y
+++ b/src/gram.y
@@ -587,14 +587,39 @@ command:
scxfree($3);
}
- | S_MARK COL var_or_range { set_cell_mark($2 + 97, $3.left.vp->row, $3.left.vp->col); }
+ | S_MARK COL var_or_range {
+ struct roman * roman = session->cur_doc;
+ struct sheet * sh = roman->cur_sh;
+ set_cell_mark($2 + 97, sh, $3.left.vp->row, $3.left.vp->col);
+ }
- | S_MARK COL var_or_range var_or_range { ;
+ | S_MARK COL var_or_range var_or_range {
+ struct roman * roman = session->cur_doc;
+ struct sheet * sh = roman->cur_sh;
srange * sr = create_range('\0', '\0', $3.left.vp, $4.left.vp);
unselect_ranges();
- set_range_mark($2 + 97, sr);
+ set_range_mark($2 + 97, sh, sr);
}
+ | S_MARK COL STRING var_or_range {
+ struct roman * roman = session->cur_doc;
+ struct sheet * sh;
+ if ((sh = search_sheet(roman, $3)) != NULL ) {
+ set_cell_mark($2 + 97, sh, $4.left.vp->row, $4.left.vp->col);
+ }
+ scxfree($3);
+ }
+
+ | S_MARK COL STRING var_or_range var_or_range {
+ struct roman * roman = session->cur_doc;
+ struct sheet * sh;
+ if ((sh = search_sheet(roman, $3)) != NULL ) {
+ srange * sr = create_range('\0', '\0', $4.left.vp, $5.left.vp);
+ unselect_ranges();
+ set_range_mark($2 + 97, sh, sr);
+ }
+ scxfree($3);
+ }
| S_FILL var_or_range num num {
struct roman * roman = session->cur_doc;
struct sheet * sh = roman->cur_sh;
@@ -803,7 +828,8 @@ command:
roman->cur_sh = sh->next;
else if (roman->cur_sh == sh)
roman->cur_sh = sh->prev;
- delete_sheet(roman, sh);
+ delete_sheet(roman, sh, 0);
+ sh = NULL;
roman->modflg++;
scxfree($2);
chg_mode('.');
@@ -820,7 +846,8 @@ command:
roman->cur_sh = sh->next;
else if (roman->cur_sh == sh)
roman->cur_sh = sh->prev;
- delete_sheet(roman, sh);
+ delete_sheet(roman, sh, 0);
+ sh = NULL;
roman->modflg++;
chg_mode('.');
ui_update(TRUE);
diff --git a/src/graph.c b/src/graph.c
index bfb47b4..5848d54 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -632,12 +632,8 @@ void ents_that_depends_on_range(struct sheet * sh, int r1, int c1, int r2, int c
*
* \return none
*/
- /* TODO double check its use (only in yank.c. the origin its always from an only sheet).
- * SHOULD take ent_ptr rather than struct ent * as parameter ! */
-void ents_that_depends_on_list(struct ent * e_ori, int deltar, int deltac) {
- struct roman * roman = session->cur_doc;
- struct sheet * sh = roman->cur_sh;
- struct ent * e = e_ori;
+void ents_that_depends_on_list(struct ent_ptr * e_ori, int deltar, int deltac) {
+ struct ent_ptr * e = e_ori;
struct ent * p;
if (graph == NULL || e == NULL) return;
@@ -646,7 +642,10 @@ void ents_that_depends_on_list(struct ent * e_ori, int deltar, int deltac) {
dep_size = 0;
while (e != NULL) {
- p = *ATBL(sh, sh->tbl, e->row+deltar, e->col+deltac);
+ struct sheet * sh = e->sheet;
+ // update sheet to current sheet if is null (a sheet was deleted)
+ if (sh == NULL) sh = session->cur_doc->cur_sh;
+ p = *ATBL(sh, sh->tbl, e->vp->row+deltar, e->vp->col+deltac);
if (p != NULL) {
markAllVerticesNotVisited(0);
ents_that_depends_on(sh, p);
diff --git a/src/graph.h b/src/graph.h
index 37c1f59..06cc7bf 100644
--- a/src/graph.h
+++ b/src/graph.h
@@ -81,7 +81,7 @@ void delete_reference(vertexT * v_cur, vertexT * vc, int back_reference);
void markAllVerticesNotVisited(int eval_visited);
void ents_that_depends_on(struct sheet * sh, struct ent * ent);
void ents_that_depends_on_range(struct sheet * sh, int r1, int c1, int r2, int c2);
-void ents_that_depends_on_list(struct ent * e_ori, int deltar, int deltac);
+void ents_that_depends_on_list(struct ent_ptr * e_ori, int deltar, int deltac);
int GraphIsReachable(vertexT * src, vertexT * dest, int back_dep);
void rebuild_graph();
diff --git a/src/help.c b/src/help.c
index 1967299..9eb3df9 100644
--- a/src/help.c
+++ b/src/help.c
@@ -594,4 +594,4 @@ void show_usage_and_quit(){
put(user_conf_d, "quit_afterload", "1");
}
-char * rev = "version 0.8.3-main";
+char * rev = "version 0.8.3-dev";
diff --git a/src/interp.c b/src/interp.c
index eb202ae..4fd9f7a 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -84,14 +84,6 @@
#endif
#include "graph.h"
-/* g_type can be: */
-#define G_NONE 0 /* Starting value - must be 0 */
-#define G_NUM 1
-#define G_STR 2
-#define G_NSTR 3
-#define G_XSTR 4
-#define G_CELL 5
-
extern int find_range(char * name, int len, struct ent * lmatch, struct ent * rmatch, struct range ** rng);
extern bool decimal; /* Set if there was a decimal point in the number */
extern struct session * session;
@@ -967,11 +959,11 @@ void go_previous() {
sc_error("Nothing to repeat");
break;
case G_NUM:
- num_search(session->cur_doc->cur_sh, gs.g_n, gs.g_row, gs.g_col, gs.g_lastrow, gs.g_lastcol, gs.errsearch, 0);
+ num_search(gs.g_sheet, gs.g_n, gs.g_row, gs.g_col, gs.g_lastrow, gs.g_lastcol, gs.errsearch, 0);
break;
case G_STR:
gs.g_type = G_NONE; /* Don't free the string */
- str_search(session->cur_doc->cur_sh, gs.g_s, gs.g_row, gs.g_col, gs.g_lastrow, gs.g_lastcol, num, 0);
+ str_search(gs.g_sheet, gs.g_s, gs.g_row, gs.g_col, gs.g_lastrow, gs.g_lastcol, num, 0);
break;
default:
sc_error("go_previous: internal error");
@@ -991,17 +983,17 @@ void go_last() {
sc_error("Nothing to repeat");
break;
case G_NUM:
- num_search(session->cur_doc->cur_sh, gs.g_n, gs.g_row, gs.g_col, gs.g_lastrow, gs.g_lastcol, gs.errsearch, 1);
+ num_search(gs.g_sheet, gs.g_n, gs.g_row, gs.g_col, gs.g_lastrow, gs.g_lastcol, gs.errsearch, 1);
break;
case G_CELL:
- moveto(session->cur_doc->cur_sh, gs.g_row, gs.g_col, gs.g_lastrow, gs.g_lastcol, gs.strow, gs.stcol);
+ moveto(gs.g_sheet, gs.g_row, gs.g_col, gs.g_lastrow, gs.g_lastcol, gs.strow, gs.stcol);
break;
case G_XSTR:
case G_NSTR:
num++;
case G_STR:
gs.g_type = G_NONE; /* Don't free the string */
- str_search(session->cur_doc->cur_sh, gs.g_s, gs.g_row, gs.g_col, gs.g_lastrow, gs.g_lastcol, num, 1);
+ str_search(gs.g_sheet, gs.g_s, gs.g_row, gs.g_col, gs.g_lastrow, gs.g_lastcol, num, 1);
break;