diff options
author | mongo <mongo@iomega> | 2016-10-18 16:36:32 -0300 |
---|---|---|
committer | mongo <mongo@iomega> | 2016-10-18 16:36:32 -0300 |
commit | 2debe13b692ff798fc6e9b80c79d510a8f5e3215 (patch) | |
tree | 98c0f4c899f0509133be091296682b4a9dc44d58 | |
parent | feb72886c192fb9d0d129395470f9d2354457f33 (diff) |
sum special command renamed to fsum
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | src/cmds.c | 51 | ||||
-rw-r--r-- | src/cmds.h | 1 | ||||
-rw-r--r-- | src/cmds_command.c | 49 | ||||
-rw-r--r-- | src/doc | 2 | ||||
-rw-r--r-- | src/gram.y | 2 |
6 files changed, 58 insertions, 49 deletions
@@ -30,6 +30,8 @@ v0.4.0 * Restored old SC fill function * Fix in seval calls * New :fcopy special command +* Added UNDO and LOCK check to fcopy special command. Added fcopy to gram.y +* sum special command renamed to fsum v0.3.0 * FIX when importing large CSV files @@ -1521,6 +1521,57 @@ int any_locked_cells(int r1, int c1, int r2, int c2) { } // sum special command +int fsum() { + int r = currow, c = curcol; + struct ent * p; + +#ifdef UNDO + create_undo_action(); + copy_to_undostruct(currow, curcol, currow, curcol, 'd'); +#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--) { + p = *ATBL(tbl, r, c); + if (p == NULL) break; + if (! (p->flags & is_valid)) break; + } + if (currow == r) { +#ifdef UNDO + dismiss_undo_item(); + end_undo_action(); +#endif + } else { + swprintf(interp_line, BUFFERSIZE, L"let %s%d = @SUM(", coltoa(curcol), currow); + swprintf(interp_line + wcslen(interp_line), BUFFERSIZE, L"%s%d:", coltoa(curcol), r+1); + swprintf(interp_line + wcslen(interp_line), BUFFERSIZE, L"%s%d)", coltoa(curcol), currow-1); + } + } else if (c > 0 && (*ATBL(tbl, r, c-1) != NULL) && (*ATBL(tbl, r, c-1))->flags & is_valid) { + for (c = curcol-1; c >= 0; c--) { + p = *ATBL(tbl, r, c); + if (p == NULL) break; + if (! (p->flags & is_valid)) break; + } + if (curcol == c) { +#ifdef UNDO + dismiss_undo_item(); + end_undo_action(); +#endif + } else { + swprintf(interp_line, BUFFERSIZE, L"let %s%d = @SUM(", coltoa(curcol), currow); + swprintf(interp_line + wcslen(interp_line), BUFFERSIZE, L"%s%d:", coltoa(c+1), r); + swprintf(interp_line + wcslen(interp_line), BUFFERSIZE, L"%s%d)", coltoa(curcol-1), r); + } + } + + if ((currow != r || curcol != c) && wcslen(interp_line)) { + send_to_interp(interp_line); +#ifdef UNDO + copy_to_undostruct(currow, curcol, currow, curcol, 'a'); + end_undo_action(); +#endif + } + return 0; +} // fcopy special command int fcopy() { @@ -64,5 +64,6 @@ void auto_justify(int ci, int cf, int min); void valueize_area(int sr, int sc, int er, int ec); void sync_refs(); int fcopy(); +int fsum(); int pad(int n, int r1, int c1, int r2, int c2); void mark_ent_as_deleted(register struct ent * p); diff --git a/src/cmds_command.c b/src/cmds_command.c index ba42a83..08fbfd2 100644 --- a/src/cmds_command.c +++ b/src/cmds_command.c @@ -626,54 +626,7 @@ void do_commandmode(struct block * sb) { fcopy(); } else if ( ! wcscmp(inputline, L"sum") ) { - int r = currow, c = curcol; - struct ent * p; - -#ifdef UNDO - create_undo_action(); - copy_to_undostruct(currow, curcol, currow, curcol, 'd'); -#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--) { - p = *ATBL(tbl, r, c); - if (p == NULL) break; - if (! (p->flags & is_valid)) break; - } - if (currow == r) { -#ifdef UNDO - dismiss_undo_item(); - end_undo_action(); -#endif - } else { - swprintf(interp_line, BUFFERSIZE, L"let %s%d = @SUM(", coltoa(curcol), currow); - swprintf(interp_line + wcslen(interp_line), BUFFERSIZE, L"%s%d:", coltoa(curcol), r+1); - swprintf(interp_line + wcslen(interp_line), BUFFERSIZE, L"%s%d)", coltoa(curcol), currow-1); - } - } else if (c > 0 && (*ATBL(tbl, r, c-1) != NULL) && (*ATBL(tbl, r, c-1))->flags & is_valid) { - for (c = curcol-1; c >= 0; c--) { - p = *ATBL(tbl, r, c); - if (p == NULL) break; - if (! (p->flags & is_valid)) break; - } - if (curcol == c) { -#ifdef UNDO - dismiss_undo_item(); - end_undo_action(); -#endif - } else { - swprintf(interp_line, BUFFERSIZE, L"let %s%d = @SUM(", coltoa(curcol), currow); - swprintf(interp_line + wcslen(interp_line), BUFFERSIZE, L"%s%d:", coltoa(c+1), r); - swprintf(interp_line + wcslen(interp_line), BUFFERSIZE, L"%s%d)", coltoa(curcol-1), r); - } - } - - if ((currow != r || curcol != c) && wcslen(interp_line)) { - send_to_interp(interp_line); -#ifdef UNDO - copy_to_undostruct(currow, curcol, currow, curcol, 'a'); - end_undo_action(); -#endif - } + fsum(); } else if ( ! wcsncmp(inputline, L"e csv" , 5) || @@ -579,7 +579,7 @@ Commands for handling cell content: :autojus same as previous command, but the columns resized are the columns represented by the selected cell or range. - :sum summarize the numeric values of a range. + :fsum summarize the numeric values of a range. the range is defined by the immediate cell above current cell, in case of vertical ranges, or by the immediate cell at the left of current cell, in case of horizontal ranges. the top / left corner is always limited by the first non numeric cell found. @@ -197,6 +197,7 @@ token S_YANKCOL %token S_CELLCOLOR %token S_REDEFINE_COLOR %token S_FCOPY +%token S_FSUM %token K_ERROR %token K_INVALID @@ -511,6 +512,7 @@ command: scxfree($2); } | S_FCOPY { fcopy(); } + | S_FSUM { fsum(); } | S_PAD NUMBER COL ':' COL { pad($2, 0, $3, maxrow, $5); } | S_PAD NUMBER COL { pad($2, 0, $3, maxrow, $3); } | S_PAD NUMBER var_or_range { pad($2, $3.left.vp->row, $3.left.vp->col, $3.right.vp->row, $3.right.vp->col); } |