📄 cmds.c
字号:
} } if (!VALID_CELL(p, currow, curcol)) { switch (rowinc) { case -1: while (!VALID_CELL(p, currow, curcol) && currow > 0) currow--; break; case 1: while (!VALID_CELL(p, currow, curcol) && currow < maxrows-1) currow++; break; case 0: switch (colinc) { case -1: while (!VALID_CELL(p, currow, curcol) && curcol > 0) curcol--; break; case 1: while (!VALID_CELL(p, currow, curcol) && curcol < maxcols-1) curcol++; break; } break; } error (""); /* clear line */ return; } switch (rowinc) { case -1: while (VALID_CELL(p, currow, curcol) && currow > 0) currow--; break; case 1: while (VALID_CELL(p, currow, curcol) && currow < maxrows-1) currow++; break; case 0: switch (colinc) { case -1: while (VALID_CELL(p, currow, curcol) && curcol > 0) curcol--; break; case 1: while (VALID_CELL(p, currow, curcol) && curcol < maxcols-1) curcol++; break; } break; } if (!VALID_CELL(p, currow, curcol)) { currow -= rowinc; curcol -= colinc; }}voiddoformat(c1,c2,w,p)int c1,c2,w,p;{ register int i; if (w > COLS - RESCOL - 2) { error("Format too large - Maximum = %d", COLS - RESCOL - 2); w = COLS-RESCOL-2; } if (p > w) { error("Precision too large"); p = w; } for(i = c1; i<=c2; i++) fwidth[i] = w, precision[i] = p; FullUpdate++; modflg++;}voidprint_options(f)FILE *f;{ if( autocalc && propagation == 10 && calc_order == BYROWS && !numeric && prescale == 1.0 && !extfunc && showcell && showtop && tbl_style == 0 ) return; /* No reason to do this */ (void) fprintf(f, "set"); if(!autocalc) (void) fprintf(f," !autocalc"); if(propagation != 10) (void) fprintf(f, " iterations = %d", propagation); if(calc_order != BYROWS ) (void) fprintf(f, " bycols"); if (numeric) (void) fprintf(f, " numeric"); if (prescale != 1.0) (void) fprintf(f, " prescale"); if (extfunc) (void) fprintf(f, " extfun"); if (!showcell) (void) fprintf(f, " !cellcur"); if (!showtop) (void) fprintf(f, " !toprow"); if (tbl_style) (void) fprintf(f, " tblstyle = %s", tbl_style == TBL ? "tbl" : tbl_style == LATEX ? "latex" : tbl_style == TEX ? "tex" : "0" ); (void) fprintf(f, "\n");}voidprintfile (fname, r0, c0, rn, cn)char *fname;int r0, c0, rn, cn;{ FILE *f; char pline[FBUFLEN]; int plinelim; int pid; int fieldlen, nextcol; register row, col; register struct ent **pp; if ((strcmp(fname, curfile) == 0) && !yn_ask("Confirm that you want to destroy the data base: (y,n)")) return; if ((f = openout(fname, &pid)) == (FILE *)0) { error ("Can't create file \"%s\"", fname); return; } for (row=r0;row<=rn; row++) { register c = 0; if (row_hidden[row]) continue; pline[plinelim=0] = '\0'; for (pp = ATBL(tbl, row, col=c0); col<=cn; pp += nextcol-col, col = nextcol, c += fieldlen) { nextcol = col+1; if (col_hidden[col]) { fieldlen = 0; continue; } fieldlen = fwidth[col]; if (*pp) { char *s; while (plinelim<c) pline[plinelim++] = ' '; plinelim = c; if ((*pp)->flags&is_valid) { (void)sprintf (pline+plinelim,"%*.*f",fwidth[col], precision[col], (*pp)->v); plinelim += strlen (pline+plinelim); } if (s = (*pp)->label) { int slen; char *start, *last; register char *fp; struct ent *nc; /* Figure out if the label slops over to a blank field */ slen = strlen(s); while (slen > fieldlen && nextcol <= cn && !((nc = lookat(row,nextcol))->flags & is_valid) && !(nc->label)) { if (!col_hidden[nextcol]) fieldlen += fwidth[nextcol]; nextcol++; } if (slen > fieldlen) slen = fieldlen; /* Now justify and print */ start = (*pp)->flags & is_leftflush ? pline + c : pline + c + fieldlen - slen; last = pline + c + fieldlen; fp = plinelim < c ? pline + plinelim : pline + c; while (fp < start) *fp++ = ' '; while (slen--) *fp++ = *s++; if (!((*pp)->flags & is_valid) || fieldlen != fwidth[col]) while(fp < last) *fp++ = ' '; if (plinelim < fp - pline) plinelim = fp - pline; } } } pline[plinelim++] = '\n'; pline[plinelim] = '\0'; (void) fputs (pline, f); } closeout(f, pid);}voidtblprintfile (fname, r0, c0, rn, cn)char *fname;int r0, c0, rn, cn;{ FILE *f; int pid; register row, col; register struct ent **pp; char coldelim = DEFCOLDELIM; if ((strcmp(fname, curfile) == 0) && !yn_ask("Confirm that you want to destroy the data base: (y,n)")) return; if ((f = openout(fname, &pid)) == (FILE *)0) { error ("Can't create file \"%s\"", fname); return; } if ( tbl_style == TBL ) { fprintf(f,".\\\" ** %s spreadsheet output \n.TS\n",progname); fprintf(f,"tab(%c);\n",coldelim); for (col=c0;col<=cn; col++) fprintf(f," n"); fprintf(f, ".\n"); } else if ( tbl_style == LATEX ) { fprintf(f,"%% ** %s spreadsheet output\n\\begin{tabular}{",progname); for (col=c0;col<=cn; col++) fprintf(f,"c"); fprintf(f, "}\n"); coldelim = '&'; } else if ( tbl_style == TEX ) { fprintf(f,"{\t%% ** %s spreadsheet output\n\\settabs %d \\columns\n", progname, cn-c0+1); coldelim = '&'; } for (row=r0; row<=rn; row++) { if ( tbl_style == TEX ) (void) fprintf (f, "\\+"); for (pp = ATBL(tbl, row, col=c0); col<=cn; col++, pp++) { if (*pp) { char *s; if ((*pp)->flags&is_valid) { (void) fprintf (f,"%.*f",precision[col], (*pp)->v); } if (s = (*pp)->label) { (void) fprintf (f,"%s",s); } } if ( col < cn ) (void) fprintf(f,"%c",coldelim); } if ( tbl_style == LATEX ) { if ( row < rn ) (void) fprintf (f, "\\\\"); } else if ( tbl_style == TEX ) { (void) fprintf (f, "\\cr"); } (void) fprintf (f,"\n"); } if ( tbl_style == TBL ) (void) fprintf (f,".TE\n.\\\" ** end of %s spreadsheet output\n", progname); else if ( tbl_style == LATEX ) (void) fprintf (f,"\\end{tabular}\n%% ** end of %s spreadsheet output\n", progname); else if ( tbl_style == TEX ) (void) fprintf (f,"}\n%% ** end of %s spreadsheet output\n", progname); closeout(f, pid);}struct enode *copye (e, Rdelta, Cdelta)register struct enode *e;int Rdelta, Cdelta;{ register struct enode *ret; if (e == (struct enode *)0) { ret = (struct enode *)0; } else if (e->op & REDUCE) { int newrow, newcol; ret = (struct enode *) xmalloc ((unsigned) sizeof (struct enode)); ret->op = e->op; newrow=e->e.r.left.vf & FIX_ROW ? e->e.r.left.vp->row : e->e.r.left.vp->row+Rdelta; newcol=e->e.r.left.vf & FIX_COL ? e->e.r.left.vp->col : e->e.r.left.vp->col+Cdelta; ret->e.r.left.vp = lookat (newrow, newcol); ret->e.r.left.vf = e->e.r.left.vf; newrow=e->e.r.right.vf & FIX_ROW ? e->e.r.right.vp->row : e->e.r.right.vp->row+Rdelta; newcol=e->e.r.right.vf & FIX_COL ? e->e.r.right.vp->col : e->e.r.right.vp->col+Cdelta; ret->e.r.right.vp = lookat (newrow, newcol); ret->e.r.right.vf = e->e.r.right.vf; } else { ret = (struct enode *) xmalloc ((unsigned) sizeof (struct enode)); ret->op = e->op; switch (ret->op) { case 'v': { int newrow, newcol; newrow=e->e.v.vf & FIX_ROW ? e->e.v.vp->row : e->e.v.vp->row+Rdelta; newcol=e->e.v.vf & FIX_COL ? e->e.v.vp->col : e->e.v.vp->col+Cdelta; ret->e.v.vp = lookat (newrow, newcol); ret->e.v.vf = e->e.v.vf; break; } case 'k': ret->e.k = e->e.k; break; case 'f': ret->e.o.right = copye (e->e.o.right,0,0); ret->e.o.left = (struct enode *)0; break; case '$': ret->e.s = xmalloc((unsigned) strlen(e->e.s)+1); (void) strcpy(ret->e.s, e->e.s); break; default: ret->e.o.right = copye (e->e.o.right,Rdelta,Cdelta); ret->e.o.left = copye (e->e.o.left,Rdelta,Cdelta); break; } } return ret;}/* * sync_refs and syncref are used to remove references to * deleted struct ents. Note that the deleted structure must still * be hanging around before the call, but not referenced by an entry * in tbl. Thus the free_ent, fix_ent calls in sc.c */voidsync_refs (){ register i,j; register struct ent *p; sync_ranges(); for (i=0; i<=maxrow; i++) for (j=0; j<=maxcol; j++) if ((p = *ATBL(tbl, i, j)) && p->expr) syncref(p->expr);}voidsyncref(e)register struct enode *e;{ if (e == (struct enode *)0) return; else if (e->op & REDUCE) { e->e.r.right.vp = lookat(e->e.r.right.vp->row, e->e.r.right.vp->col); e->e.r.left.vp = lookat(e->e.r.left.vp->row, e->e.r.left.vp->col); } else { switch (e->op) { case 'v': e->e.v.vp = lookat(e->e.v.vp->row, e->e.v.vp->col); break; case 'k': break; case '$': break; default: syncref(e->e.o.right); syncref(e->e.o.left); break; } }}voidhiderow(arg)int arg;{ register int r1; register int r2; r1 = currow; r2 = r1 + arg - 1; if (r1 < 0 || r1 > r2) { error ("Invalid range"); return; } if (r2 >= maxrows-1) { if (!growtbl(GROWROW, arg+1, 0)) { error("You can't hide the last row"); return; } } FullUpdate++; modflg++; while (r1 <= r2) row_hidden[r1++] = 1;}voidhidecol(arg)int arg;{ register int c1; register int c2; c1 = curcol; c2 = c1 + arg - 1; if (c1 < 0 || c1 > c2) { error ("Invalid range"); return; } if (c2 >= maxcols-1) { if ((arg >= ABSMAXCOLS-1) || !growtbl(GROWCOL, 0, arg+1)) { error("You can't hide the last col"); return; } } FullUpdate++; modflg++; while (c1 <= c2) col_hidden[c1++] = 1;}voidshowrow(r1, r2)int r1, r2;{ if (r1 < 0 || r1 > r2) { error ("Invalid range"); return; } if (r2 > maxrows-1) { r2 = maxrows-1; } FullUpdate++; modflg++; while (r1 <= r2) row_hidden[r1++] = 0;}voidshowcol(c1, c2)int c1, c2;{ if (c1 < 0 || c1 > c2) { error ("Invalid range"); return; } if (c2 > maxcols-1) { c2 = maxcols-1; } FullUpdate++; modflg++; while (c1 <= c2) col_hidden[c1++] = 0;}/* Open the output file, setting up a pipe if needed */FILE *openout(fname, rpid)char *fname;int *rpid;{ int pipefd[2]; int pid; FILE *f; char *efname; while (*fname && (*fname == ' ')) /* Skip leading blanks */ fname++; if (*fname != '|') { /* Open file if not pipe */ *rpid = 0; efname = findhome(fname);#ifdef DOBACKUPS if (!backup_file(efname) && (yn_ask("Could not create backup copy, Save anyhow?: (y,n)") != 1)) return(0);#endif return(fopen(efname, "w")); } fname++; /* Skip | */ if ( pipe (pipefd) < 0) { error("Can't make pipe to child"); *rpid = 0; return(0); } deraw();#ifdef VMS fprintf(stderr, "No son tasks available yet under VMS--sorry\n");#else /* VMS */ if ((pid=fork()) == 0) /* if child */ {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -