📄 sc.c
字号:
(void) move(y,x); c = inch() & A_CHARTEXT; (void) addch(c); x++; }}char *progname;intmain (argc, argv)int argc;char **argv;{ int inloop = 1; register int c; int edistate = -1; int arg = 1; int narg; int nedistate; int running; char *revi; int anychanged = FALSE; /* * Keep command line options around until the file is read so the * command line overrides file options */ int Mopt = 0; int Nopt = 0; int Copt = 0; int Ropt = 0; int tempx, tempy; /* Temp versions of curx, cury */ if ((revi = strrchr(argv[0], '/')) != NULL) progname = revi+1; else progname = argv[0]; while (argc > 1 && argv[1][0] == '-') { argv++; argc--; switch (argv[0][1]) { case 'x':#ifdef VMS (void) fprintf(stderr, "Crypt not available for VMS\n"); exit(1);#else Crypt = 1;#endif break; case 'm': Mopt = 1; break; case 'n': Nopt = 1; break; case 'c': Copt = 1; break; case 'r': Ropt = 1; break; default: (void) fprintf(stderr,"%s: unrecognized option: \"%c\"\n", progname,argv[0][1]); exit(1); } } *curfile ='\0'; signals(); (void) initscr(); /* setup the spreadsheet arrays, initscr() will get the screen size */ if (!growtbl(GROWNEW, 0, 0)) { endwin(); exit(1); } (void) clear();#ifdef VMS VMS_read_raw = 1;#else nonl(); noecho (); cbreak();#endif initkbd(); scrollok(stdscr, 1); /* * Build revision message for later use: */ (void) strcpy (revmsg, progname); for (revi = rev; (*revi++) != ':'; ); /* copy after colon */ (void) strcat (revmsg, revi); revmsg [strlen (revmsg) - 2] = 0; /* erase last character */ (void) strcat (revmsg, ": Type '?' for help."); if (argc > 1) { (void) strcpy(curfile,argv[1]); readfile (argv[1], 0); } if (Mopt) autocalc = 0; if (Nopt) numeric = 1; if (Copt) calc_order = BYCOLS; if (Ropt) calc_order = BYROWS; modflg = 0;#ifdef VENIX setbuf (stdin, NULL);#endif FullUpdate++; 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 (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); (void) fflush (stdout); seenerr = 0; showneed = 0; /* reset after each update */ showexpr = 0; /* if ((c < ' ') || ( c == DEL )) how about international here ? PB */ if ( iscntrl(c) ) switch (c) {#ifdef SIGTSTP case ctl('z'): (void) deraw(); (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'): backcol(arg); break; case ctl('c'): running = 0; break; case ctl('e'): switch (nmgetch()) { case ctl('p'): case 'k': doend (-1, 0); break; case ctl('n'): case 'j': doend ( 1, 0); break; case ctl('b'): case 'h': case ctl('h'): doend ( 0,-1); break; case ctl('f'): case 'l': case ctl('i'): case ' ': doend ( 0, 1); break; case ESC: case ctl('g'): break; default: error("Invalid ^E command"); break; } break; case ctl('f'): forwcol(arg); 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 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; } if (!showrange) { startshow(); } else { showdr(); linelim = strlen(line); line[linelim++] = ' '; line[linelim] = 0; showrange = 0; } linelim = strlen (line); break; case ctl('m'): case ctl('j'): write_line(ctl('m')); break; case ctl('n'): forwrow(arg); break; case ctl('p'): backrow(arg); break; case ctl('q'): break; /* ignore flow control */ case ctl('s'): break; /* ignore flow control */ case ctl('t'): error("Toggle: a:auto c:cell e:ext funcs n:numeric t:top x:encrypt $:pre-scale"); (void) refresh(); switch (nmgetch()) { case 'a': case 'A': case 'm': case 'M': autocalc ^= 1; error("Automatic recalculation %sabled.", autocalc ? "en":"dis"); break; case 'n': case 'N': numeric = (! numeric); error ("Numeric input %sabled.", numeric ? "en" : "dis"); break; case 't': case 'T': showtop = (! showtop); repaint(lastmx, lastmy, fwidth[lastcol]); error ("Top line %sabled.", showtop ? "en" : "dis"); break; case 'c': case 'C': showcell = (! showcell); repaint(lastmx, lastmy, fwidth[lastcol]); error ("Cell highlighting %sabled.", showcell ? "en" : "dis"); break; case 'x': case 'X': Crypt = (! Crypt); error ("Encryption %sabled.", Crypt? "en" : "dis"); break; case '$': if (prescale == 1.0) { error ("Prescale enabled."); prescale = 0.01; } else { prescale = 1.0; error ("Prescale disabled."); } break; case 'e': case 'E': extfunc = (! extfunc); error ("External functions %sabled.", extfunc? "en" : "dis"); break; case ESC: case ctl('g'): --modflg; /* negate the modflg++ */ 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'): /* insert variable name */ if (linelim > 0) ins_string(v_name(currow, curcol)); break; case ctl('w'): /* insert variable expression */ if (linelim > 0) { char *temp, *temp1; int templim; temp = strcpy(xmalloc((unsigned)(strlen(line)+1)),line); templim = linelim; editexp(currow,curcol); temp1= strcpy(xmalloc((unsigned)(strlen(line)+1)),line); strcpy(line, temp); linelim = templim; ins_string(temp1); xfree(temp); xfree(temp1); } break; case ctl('a'): /* insert variable value */ if (linelim > 0) { struct ent *p = *ATBL(tbl, currow, curcol); char temp[100]; if (p && p -> flags & is_valid) { (void) sprintf (temp, "%.*f", precision[curcol],p -> v); ins_string(temp); } } break; } /* End of the control char switch stmt */ else if (isdigit(c) && ((numeric && edistate >= 0) || (!numeric && (linelim < 0 || 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 */ curcol = 0; else { nedistate = 0; narg = c - '0'; } } else { /* Succeeding count chars */ nedistate = 0; narg = arg * 10 + (c - '0'); } } else if (linelim >= 0) { /* Editing line */ switch(c) { case ')': if (showrange) { showdr(); showrange = 0; linelim = strlen (line); } break; default: break; } write_line(c); } else if (!numeric && ( c == '+' || c == '-' ) ) { /* increment/decrement ops */ register struct ent *p = *ATBL(tbl, currow, curcol); if (!p) continue; if (p->expr && !(p->flags & is_strexpr)) { error("Can't increment/decrement a formula\n"); continue; } FullUpdate++; modflg++; if( c == '+' ) p -> v += (double) arg; else p -> v -= (double) arg; } else /* switch on a normal command character */ switch (c) { case ':': break; /* Be nice to vi users */ case '@': EvalAll (); changed = 0; anychanged = TRUE; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '-': case '.': case '+': (void) sprintf(line,"let %s = %c", v_name(currow, curcol), c); linelim = strlen (line); insert_mode(); break; case '=': (void) sprintf(line,"let %s = ", v_name(currow, curcol)); linelim = strlen (line); insert_mode(); break; case '!': { /* * "! command" executes command * "!" forks a shell * "!!" repeats last command */#ifdef VMS error("Not implemented on VMS");#else /* VMS */ char *shl; int pid, temp; char cmd[MAXCMD]; static char lastcmd[MAXCMD]; if (!(shl = getenv("SHELL"))) shl = "/bin/sh"; deraw(); (void) fputs("! ", stdout); (void) fflush(stdout); (void) fgets(cmd, MAXCMD, stdin); cmd[strlen(cmd) - 1] = '\0'; /* clobber \n */ if(strcmp(cmd,"!") == 0) /* repeat? */ (void) strcpy(cmd, lastcmd); else (void) strcpy(lastcmd, cmd); if (modflg) { (void) puts ("[No write since last change]"); (void) fflush (stdout); } if (!(pid = fork())) { (void) signal (SIGINT, SIG_DFL); /* reset */ if(strlen(cmd)) (void)execl(shl,shl,"-c",cmd,(char *)0); else (void) execl(shl, shl, (char *)0); exit(-127); } while (pid != wait(&temp)); (void) printf("Press RETURN to continue "); (void)nmgetch(); goraw();#endif /* VMS */ break; } /* * Range commands: */ case '/': error ("Range: x:erase v:value c:copy f:fill d:define s:show u:undefine"); (void) refresh(); switch (nmgetch()) { case 'c': (void) sprintf(line,"copy [dest_range src_range] "); linelim = strlen(line); startshow(); insert_mode(); break; case 'x': (void) sprintf(line,"erase [range] "); linelim = strlen(line); startshow(); insert_mode(); break; case 'v': (void) sprintf(line, "value [range] "); linelim = strlen(line); startshow(); insert_mode(); break; case 'f': (void) sprintf(line,"fill [range start inc] "); linelim = strlen(line); startshow(); insert_mode(); break; case 'd':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -