-
Notifications
You must be signed in to change notification settings - Fork 20
/
sc.c
2387 lines (2227 loc) · 52.5 KB
/
sc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SC A Spreadsheet Calculator
* Main driver
*
* original by James Gosling, September 1982
* modifications by Mark Weiser and Bruce Israel,
* University of Maryland
*
* More mods Robert Bond, 12/86
* More mods by Alan Silverstein, 3-4/88, see list of changes.
* $Revision: 7.16 $
*
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <ctype.h>
#include <string.h>
#include <sys/file.h>
#include <fcntl.h>
#ifndef MSDOS
#include <unistd.h>
#endif
#include <termios.h>
#include <errno.h>
#include <stdlib.h>
#include <limits.h>
#include "compat.h"
#include "sc.h"
#include "version.h"
#ifndef SAVENAME
#define SAVENAME "SC.SAVE" /* file name to use for emergency saves */
#endif /* SAVENAME */
static void settcattr(void);
static void scroll_down(void);
static void scroll_up(int);
/* Globals defined in sc.h */
struct ent ***tbl;
int arg = 1;
int strow = 0, stcol = 0;
int currow = 0, curcol = 0;
int savedrow[37], savedcol[37];
int savedstrow[37], savedstcol[37];
int FullUpdate = 0;
int maxrow, maxcol;
int maxrows, maxcols;
int *fwidth;
int *precision;
int *realfmt;
char *col_hidden;
char *row_hidden;
char line[FBUFLEN];
int changed;
struct ent *delbuf[DELBUFSIZE];
char *delbuffmt[DELBUFSIZE];
int dbidx;
int qbuf; /* buffer no. specified by " command */
int modflg;
int cellassign;
int numeric;
char *mdir;
char *autorun;
int skipautorun;
char *fkey[FKEYS];
char *scext;
char *ascext;
char *tbl0ext;
char *tblext;
char *latexext;
char *slatexext;
char *texext;
int scrc = 0;
int showsc, showsr; /* Starting cell for highlighted range */
int usecurses = TRUE; /* Use curses unless piping/redirection or using -q */
int brokenpipe = FALSE; /* Set to true if SIGPIPE is received */
#ifdef RIGHT_CBUG
int wasforw = FALSE;
#endif
char curfile[PATHLEN];
char revmsg[80];
/* numeric separators, country-dependent if locale support enabled: */
char dpoint = '.'; /* decimal point */
char thsep = ','; /* thousands separator */
ssize_t linelim = -1;
int showtop = 1; /* Causes current cell value display in top line */
int showcell = 1; /* Causes current cell to be highlighted */
int showrange = 0; /* Causes ranges to be highlighted */
int showneed = 0; /* Causes cells needing values to be highlighted */
int showexpr = 0; /* Causes cell exprs to be displayed, highlighted */
int shownote = 0; /* Causes cells with attached notes to be
highlighted */
int braille = 0; /* Be nice to users of braille displays */
int braillealt = 0; /* Alternate mode for braille users */
int autocalc = 1; /* 1 to calculate after each update */
int autolabel = 1; /* If room, causes label to be created after a define */
int autoinsert = 0; /* Causes rows to be inserted if craction is non-zero
and the last cell in a row/column of the scrolling
portion of a framed range has been filled */
int autowrap = 0; /* Causes cursor to move to next row/column if craction
is non-zero and the last cell in a row/column of
the scrolling portion of a framed range has been
filled */
int calc_order = BYROWS;
int optimize = 0; /* Causes numeric expressions to be optimized */
int tbl_style = 0; /* headers for T command output */
int rndtoeven = 0;
int color = 0; /* Use color */
int colorneg = 0; /* Increment color number for cells with negative
numbers */
int colorerr = 0; /* Color cells with errors with color 3 */
int numeric_field = 0; /* Started the line editing with a number */
int craction = 0; /* 1 for down, 2 for right */
int pagesize = 0; /* If nonzero, use instead of 1/2 screen height */
int dobackups; /* Copy current database file to backup file */
/* before overwriting */
int rowlimit = -1;
int collimit = -1;
int rowsinrange = 1;
int colsinrange = DEFWIDTH;
/* a linked list of free [struct ent]'s, uses .next as the pointer */
struct ent *freeents = NULL;
#ifdef VMS
int VMS_read_raw = 0;
#endif
#ifdef NCURSES_MOUSE_VERSION
static int mouse_sel_cell(int);
MEVENT mevent;
#endif
/* return a pointer to a cell's [struct ent *], creating if needed */
struct ent *
lookat(int row, int col)
{
register struct ent **pp;
checkbounds(&row, &col);
pp = ATBL(tbl, row, col);
if (*pp == NULL) {
if (freeents != NULL) {
*pp = freeents;
(*pp)->flags &= ~IS_CLEARED;
(*pp)->flags |= MAY_SYNC;
freeents = freeents->next;
} else
*pp = scxmalloc(sizeof(struct ent));
if (row > maxrow) maxrow = row;
if (col > maxcol) maxcol = col;
(*pp)->label = (char *)0;
(*pp)->row = row;
(*pp)->col = col;
(*pp)->nrow = -1;
(*pp)->ncol = -1;
(*pp)->flags = MAY_SYNC;
(*pp)->expr = (struct enode *)0;
(*pp)->v = (double) 0.0;
(*pp)->format = (char *)0;
(*pp)->cellerror = CELLOK;
(*pp)->next = NULL;
}
return (*pp);
}
/*
* This structure is used to keep ent structs around before they
* are deleted to allow the sync_refs routine a chance to fix the
* variable references.
* We also use it as a last-deleted buffer for the 'p' command.
*/
void
free_ent(register struct ent *p, int unlock)
{
p->next = delbuf[dbidx];
delbuf[dbidx] = p;
p->flags |= IS_DELETED;
if (unlock)
p->flags &= ~IS_LOCKED;
}
/* free deleted cells */
void
flush_saved(void) {
register struct ent *p;
register struct ent *q;
if (dbidx < 0)
return;
if ((p = delbuf[dbidx])) {
scxfree(delbuffmt[dbidx]);
delbuffmt[dbidx] = NULL;
}
while (p) {
(void) clearent(p);
q = p->next;
p->next = freeents; /* put this ent on the front of freeents */
freeents = p;
p = q;
}
delbuf[dbidx--] = NULL;
}
char *progname;
int Vopt;
#ifdef TRACE
FILE *ftrace;
#endif
int
main (int argc, char **argv)
{
int inloop = 1;
register int c;
int edistate = -1;
int narg;
int nedistate;
int running;
char *revi;
int anychanged = FALSE;
int tempx, tempy; /* Temp versions of curx, cury */
/*
* Keep command line options around until the file is read so the
* command line overrides file options
*/
int mopt = 0;
int oopt = 0;
int nopt = 0;
int copt = 0;
int ropt = 0;
int Copt = 0;
int Ropt = 0;
int eopt = 0;
int popt = 0;
int qopt = 0;
int Mopt = 0;
Vopt = 0;
#ifdef MSDOS
if ((revi = strrchr(argv[0], '\\')) != NULL)
#else
#ifdef VMS
if ((revi = strrchr(argv[0], ']')) != NULL)
#else
if ((revi = strrchr(argv[0], '/')) != NULL)
#endif
#endif
progname = revi+1;
else
progname = argv[0];
#ifdef TRACE
if (!(ftrace = fopen(TRACE, "w"))) {
fprintf(stderr, "%s: fopen(%s, 'w') failed: %s\n",
progname, TRACE, strerror(errno));
exit(1);
}
#endif
while ((c = getopt(argc, argv, "axmoncrCReP:W:vqM")) != EOF) {
switch (c) {
case 'a':
skipautorun = 1;
break;
case 'x':
#if defined(VMS) || defined(MSDOS) || !defined(CRYPT_PATH)
(void) fprintf(stderr, "Crypt not available\n");
exit (1);
#else
Crypt = 1;
#endif
break;
case 'm':
mopt = 1;
break;
case 'o':
oopt = 1;
break;
case 'n':
nopt = 1;
break;
case 'c':
copt = 1;
break;
case 'r':
ropt = 1;
break;
case 'C':
Copt = 1;
craction = CRCOLS;
break;
case 'R':
Ropt = 1;
craction = CRROWS;
break;
case 'e':
rndtoeven = 1;
eopt = 1;
break;
case 'P':
case 'W':
popt = 1;
case 'v':
break;
case 'q':
qopt = 1;
break;
case 'M':
Mopt = 1;
break;
default:
exit (1);
}
}
if (!isatty(STDOUT_FILENO) || popt || qopt) usecurses = FALSE;
startdisp();
signals();
settcattr();
read_hist();
/* setup the spreadsheet arrays, initscr() will get the screen size */
if (!growtbl(GROWNEW, 0, 0)) {
stopdisp();
exit (1);
}
/*
* Build revision message for later use:
*/
if (popt)
*revmsg = '\0';
else {
strlcpy(revmsg, progname, sizeof revmsg);
for (revi = rev; (*revi++) != ':'; ); /* copy after colon */
strlcat(revmsg, revi, sizeof revmsg);
revmsg[strlen(revmsg) - 2] = 0; /* erase last character */
strlcat(revmsg, ": Type '?' for help.", sizeof revmsg);
}
#ifdef MSDOS
if (optind < argc)
#else
if (optind < argc && !strcmp(argv[optind], "--"))
optind++;
if (optind < argc && argv[optind][0] != '|' &&
strcmp(argv[optind], "-"))
#endif /* MSDOS */
strlcpy(curfile, argv[optind], sizeof curfile);
for (dbidx = DELBUFSIZE - 1; dbidx >= 0; ) {
delbuf[dbidx] = NULL;
delbuffmt[dbidx--] = NULL;
}
if (usecurses && has_colors())
initcolor(0);
if (optind < argc) {
if (!readfile(argv[optind], 1) && (optind == argc - 1))
error("New file: \"%s\"", curfile);
EvalAll();
optind++;
} else
erasedb();
while (optind < argc) {
(void) readfile(argv[optind], 0);
optind++;
}
savedrow[0] = currow;
savedcol[0] = curcol;
savedstrow[0] = strow;
savedstcol[0] = stcol;
EvalAll();
if (!(popt || isatty(STDIN_FILENO)))
(void) readfile("-", 0);
if (qopt) {
stopdisp();
exit (0);
}
if (usecurses)
clearok(stdscr, TRUE);
EvalAll();
if (mopt)
autocalc = 0;
if (oopt)
optimize = 1;
if (nopt)
numeric = 1;
if (copt)
calc_order = BYCOLS;
if (ropt)
calc_order = BYROWS;
if (Copt)
craction = CRCOLS;
if (Ropt)
craction = CRROWS;
if (eopt)
rndtoeven = 1;
if (Mopt)
mouseon();
if (popt) {
char *redraw = NULL;
int o;
#ifdef BSD43
optreset = 1;
#endif
optind = 1;
stopdisp();
while ((o = getopt(argc, argv, "axmoncrCReP:W:vq")) != EOF) {
switch (o) {
case 'v':
Vopt = 1;
break;
case 'P':
if (*optarg == '/') {
int in, out;
in = dup(STDIN_FILENO);
out = dup(STDOUT_FILENO);
freopen("/dev/tty", "r", stdin);
freopen("/dev/tty", "w", stdout);
usecurses = TRUE;
startdisp();
if (has_colors()) {
initcolor(0);
bkgd(COLOR_PAIR(1) | ' ');
}
clearok(stdscr, TRUE);
FullUpdate++;
linelim = 0;
*line = '\0';
if (mode_ind != 'v')
write_line(ctl('v'));
error("Select range:");
update(1);
while (!linelim) {
int c_;
switch (c_ = nmgetch()) {
case '.':
case ':':
case ctl('i'):
if (!showrange) {
write_line(c_);
break;
}
/* else drop through */
case ctl('m'):
strlcpy(line, "put ", sizeof line);
linelim = 4;
write_line('.');
if (showrange)
write_line('.');
strlcat(line, optarg, sizeof line);
break;
case ESC:
case ctl('g'):
case 'q':
linelim = -1;
break;
case ctl('l'):
FullUpdate++;
clearok(stdscr, 1);
break;
default:
write_line(c_);
break;
}
/* goto switches to insert mode when done, so we
* have to switch back.
*/
if (mode_ind == 'i')
write_line(ctl('v'));
CLEAR_LINE;
update(1);
}
stopdisp();
dup2(in, STDIN_FILENO);
dup2(out, STDOUT_FILENO);
close(in);
close(out);
redraw = "recalc\nredraw\n";
} else {
strlcpy(line, "put ", sizeof line);
linelim = 4;
strlcat(line, optarg, sizeof line);
}
if (linelim > 0) {
linelim = 0;
yyparse();
}
Vopt = 0;
break;
case 'W':
strlcpy(line, "write ", sizeof line);
strlcat(line, optarg, sizeof line);
linelim = 0;
yyparse();
break;
default:
break;
}
}
if (redraw) fputs(redraw, stdout);
exit (0);
}
if (!isatty(STDOUT_FILENO)) {
stopdisp();
write_fd(stdout, 0, 0, maxrow, maxcol);
exit (0);
}
modflg = 0;
cellassign = 0;
#ifdef VENIX
setbuf(stdin, NULL);
#endif
while (inloop) { running = 1;
while (running) {
nedistate = -1;
narg = 1;
if (edistate < 0 && linelim < 0 && autocalc && (changed || FullUpdate))
{
EvalAll();
if (changed) /* if EvalAll changed or was before */
anychanged = TRUE;
changed = 0;
}
else /* any cells change? */
if (changed)
anychanged = TRUE;
update(anychanged);
anychanged = FALSE;
#ifndef SYSV3 /* HP/Ux 3.1 this may not be wanted */
(void) refresh(); /* 5.3 does a refresh in getch */
#endif
c = nmgetch();
getyx(stdscr, tempy, tempx);
(void) move(1, 0);
(void) clrtoeol();
(void) move(tempy, tempx);
seenerr = 0;
showneed = 0; /* reset after each update */
showexpr = 0;
shownote = 0;
/*
* there seems to be some question about what to do w/ the iscntrl
* some BSD systems are reportedly broken as well
*/
/* if ((c < ' ') || ( c == DEL )) how about international here ? PB */
#if pyr
if(iscntrl(c) || (c >= 011 && c <= 015)) /* iscntrl broken in OSx4.1 */
#else
if ((isascii(c) && (iscntrl(c) || (c == 020))) || /* iscntrl broken in OSx4.1 */
c == KEY_END || c == KEY_BACKSPACE)
#endif
switch(c) {
#ifdef SIGTSTP
case ctl('z'):
(void) deraw(1);
(void) kill(0, SIGTSTP); /* Nail process group */
/* the pc stops here */
(void) goraw();
break;
#endif
case ctl('r'):
showneed = 1;
case ctl('l'):
FullUpdate++;
(void) clearok(stdscr,1);
break;
case ctl('x'):
FullUpdate++;
showexpr = 1;
(void) clearok(stdscr,1);
break;
default:
error ("No such command (^%c)", c + 0100);
break;
case ctl('b'):
{
int ps;
ps = pagesize ? pagesize : (LINES - RESROW - framerows)/2;
backrow(arg * ps);
strow = strow - (arg * ps);
if (strow < 0) strow = 0;
FullUpdate++;
}
break;
case ctl('c'):
running = 0;
break;
case KEY_END:
case ctl('e'):
if (linelim < 0 || mode_ind == 'v') {
switch (c = nmgetch()) {
case KEY_UP:
case ctl('p'): case 'k': doend(-1, 0); break;
case KEY_DOWN:
case ctl('n'): case 'j': doend( 1, 0); break;
case KEY_LEFT:
case KEY_BACKSPACE:
case ctl('h'): case 'h': doend( 0,-1); break;
case KEY_RIGHT:
case ' ':
case ctl('i'): case 'l': doend( 0, 1); break;
case ctl('e'):
case ctl('y'):
while (c == ctl('e') || c == ctl('y')) {
int x = arg;
while (arg) {
if (c == ctl('e')) {
scroll_down();
} else {
scroll_up(x);
}
arg--;
}
FullUpdate++;
update(0);
arg++;
c = nmgetch();
}
ungetch(c);
break;
case ESC:
case ctl('g'):
break;
default:
error("Invalid ^E command");
break;
}
} else
write_line(ctl('e'));
break;
case ctl('y'):
while (c == ctl('e') || c == ctl('y')) {
int x = arg;
while (arg) {
if (c == ctl('e')) {
scroll_down();
} else {
scroll_up(x);
}
arg--;
}
FullUpdate++;
update(0);
arg++;
c = nmgetch();
}
ungetch(c);
break;
case ctl('f'):
{
int ps;
ps = pagesize ? pagesize : (LINES - RESROW - framerows)/2;
forwrow(arg * ps);
strow = strow + (arg * ps);
FullUpdate++;
}
break;
case ctl('g'):
showrange = 0;
linelim = -1;
(void) move(1, 0);
(void) clrtoeol();
break;
case ESC: /* ctl('[') */
write_line(ESC);
break;
case ctl('d'):
write_line(ctl('d'));
break;
case KEY_BACKSPACE:
case DEL:
case ctl('h'):
if (linelim < 0) { /* not editing line */
backcol(arg); /* treat like ^B */
break;
}
write_line(ctl('h'));
break;
case ctl('i'): /* tab */
if (linelim < 0) { /* not editing line */
forwcol(arg);
break;
}
write_line(ctl('i'));
break;
case ctl('m'):
case ctl('j'):
write_line(ctl('m'));
break;
case ctl('n'):
c = craction;
if (numeric_field) {
craction = 0;
write_line(ctl('m'));
numeric_field = 0;
}
craction = c;
if (linelim < 0) {
forwrow(arg);
break;
}
write_line(ctl('n'));
break;
case ctl('p'):
c = craction;
if (numeric_field) {
craction = 0;
write_line(ctl('m'));
numeric_field = 0;
}
craction = c;
if (linelim < 0) {
backrow(arg);
break;
}
write_line(ctl('p'));
break;
case ctl('q'):
break; /* ignore flow control */
case ctl('s'):
break; /* ignore flow control */
case ctl('t'):
#if !defined(VMS) && !defined(MSDOS) && defined(CRYPT_PATH)
error(
"Toggle: a:auto,c:cell,e:ext funcs,n:numeric,t:top,x:encrypt,$:pre-scale,<MORE>");
#else /* no encryption available */
error(
"Toggle: a:auto,c:cell,e:ext funcs,n:numeric,t:top,$:pre-scale,<MORE>");
#endif
if (braille) move(1, 0);
(void) refresh();
switch (nmgetch()) {
case 'a': case 'A':
case 'm': case 'M':
autocalc ^= 1;
error("Automatic recalculation %sabled.",
autocalc ? "en":"dis");
break;
case 'o': case 'O':
optimize ^= 1;
error("%sptimize expressions upon entry.",
optimize ? "O":"Do not o");
break;
case 'n':
numeric = (!numeric);
error("Numeric input %sabled.",
numeric ? "en" : "dis");
break;
case 't': case 'T':
showtop = (!showtop);
error("Top line %sabled.", showtop ? "en" : "dis");
break;
case 'c':
showcell = (!showcell);
repaint(lastmx, lastmy, fwidth[lastcol], 0, 0);
error("Cell highlighting %sabled.",
showcell ? "en" : "dis");
--modflg; /* negate the modflg++ */
break;
case 'b':
braille ^= 1;
error("Braille enhancement %sabled.",
braille ? "en" : "dis");
--modflg; /* negate the modflg++ */
break;
case 's':
cslop ^= 1;
error("Color slop %sabled.",
cslop ? "en" : "dis");
break;
case 'C':
color = !color;
if (has_colors()) {
if (color) {
attron(COLOR_PAIR(1));
bkgd(COLOR_PAIR(1) | ' ');
} else {
attron(COLOR_PAIR(0));
bkgd(COLOR_PAIR(0) | ' ');
}
}
error("Color %sabled.", color ? "en" : "dis");
break;
case 'N':
colorneg = !colorneg;
error("Color changing of negative numbers %sabled.",
colorneg ? "en" : "dis");
break;
case 'E':
colorerr = !colorerr;
error("Color changing of cells with errors %sabled.",
colorerr ? "en" : "dis");
break;
case 'x': case 'X':
#if defined(VMS) || defined(MSDOS) || !defined(CRYPT_PATH)
error("Encryption not available.");
#else
Crypt = (! Crypt);
error("Encryption %sabled.", Crypt? "en" : "dis");
#endif
break;
case 'l': case 'L':
autolabel = (!autolabel);
error("Autolabel %sabled.",
autolabel? "en" : "dis");
break;
case '$':
if (prescale == 1.0) {
error("Prescale enabled.");
prescale = 0.01;
} else {
prescale = 1.0;
error("Prescale disabled.");
}
break;
case 'e':
extfunc = (!extfunc);
error("External functions %sabled.",
extfunc? "en" : "dis");
break;
case ESC:
case ctl('g'):
CLEAR_LINE;
--modflg; /* negate the modflg++ */
break;
case 'r': case 'R':
error("Which direction after return key?");
switch(nmgetch()) {
case ctl('m'):
craction = 0;
error("No action after new line");
break;
case 'j':
case ctl('n'):
case KEY_DOWN:
craction = CRROWS;
error("Down row after new line");
break;
case 'l':
case ' ':
case KEY_RIGHT:
craction = CRCOLS;
error("Right column after new line");
break;
case ESC:
case ctl('g'):
CLEAR_LINE;
break;
default:
error("Not a valid direction");
}
break;
case 'i': case 'I':
autoinsert = (!autoinsert);
error("Autoinsert %sabled.",
autoinsert? "en" : "dis");
break;
case 'w': case 'W':
autowrap = (!autowrap);
error("Autowrap %sabled.",
autowrap? "en" : "dis");
break;
case 'z': case 'Z':
rowlimit = currow;
collimit = curcol;
error("Row and column limits set");
break;
default:
error("Invalid toggle command");
--modflg; /* negate the modflg++ */
}
FullUpdate++;
modflg++;
break;
case ctl('u'):
narg = arg * 4;
nedistate = 1;
break;
case ctl('v'): /* switch to navigate mode, or if already *
* in navigate mode, insert variable name */
if (linelim >= 0)
write_line(ctl('v'));
break;
case ctl('w'): /* insert variable expression */
if (linelim >= 0) {
static char *temp = NULL, *temp1 = NULL;
static unsigned templen = 0;
int templim;
/* scxrealloc will scxmalloc if needed */
if (strlen(line)+1 > templen) {
templen = strlen(line)+40;
temp = scxrealloc(temp, templen);
temp1= scxrealloc(temp1, templen);
}
strlcpy(temp, line, templen);
templim = linelim;
linelim = 0; /* reset line to empty */
editexp(currow,curcol);
strlcpy(temp1, line, templen);
strlcpy(line, temp, sizeof line);
linelim = templim;
ins_string(temp1);
}
break;
case ctl('a'):
if (linelim >= 0)
write_line(c);
else {
remember(0);
currow = 0;
curcol = 0;
rowsinrange = 1;
colsinrange = fwidth[curcol];
remember(1);
FullUpdate++;
}
break;
case '\035': /* ^] */
if (linelim >= 0)
write_line(c);
break;
} /* End of the control char switch stmt */
else if (isascii(c) && isdigit(c) && ((!numeric && linelim < 0) ||
(linelim >= 0 && (mode_ind == 'e' || mode_ind == 'v')) ||
edistate >= 0)) {
/* we got a leading number */
if (edistate != 0) {
/* First char of the count */
if (c == '0') { /* just a '0' goes to left col */
if (linelim >= 0)
write_line(c);
else
leftlimit();
} else {
nedistate = 0;
narg = c - '0';
}