summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormongo <mongo@iomega>2016-10-18 16:36:32 -0300
committermongo <mongo@iomega>2016-10-18 16:36:32 -0300
commit2debe13b692ff798fc6e9b80c79d510a8f5e3215 (patch)
tree98c0f4c899f0509133be091296682b4a9dc44d58
parentfeb72886c192fb9d0d129395470f9d2354457f33 (diff)
sum special command renamed to fsum
-rw-r--r--CHANGES2
-rw-r--r--src/cmds.c51
-rw-r--r--src/cmds.h1
-rw-r--r--src/cmds_command.c49
-rw-r--r--src/doc2
-rw-r--r--src/gram.y2
6 files changed, 58 insertions, 49 deletions
diff --git a/CHANGES b/CHANGES
index e31f0d6..9056318 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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
diff --git a/src/cmds.c b/src/cmds.c
index 3d6a61d..954eb5d 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -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() {
diff --git a/src/cmds.h b/src/cmds.h
index 0322557..d612cd2 100644
--- a/src/cmds.h
+++ b/src/cmds.h
@@ -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) ||
diff --git a/src/doc b/src/doc
index a701076..f7c193a 100644
--- a/src/doc
+++ b/src/doc
@@ -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.
diff --git a/src/gram.y b/src/gram.y
index 9407054..0ce1870 100644
--- a/src/gram.y
+++ b/src/gram.y
@@ -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); }