/* * Read the file's contents for the given page and set up the display in case * we decide to use it. */ static int StartPage(int *infile, /* in/out: current-line # */ int skip, /* in: # of lines to skip */ int *eoff) /* out: set iff we got eof */ { int c; int blank = (*infile == 0) || (*infile + 1 == LineAt[*infile].blank); int y = mark_W + 1; showMARK(Shift); move(y, 0); typeinit(); HadPattern = FALSE; *eoff = FALSE; for (;;) { if ((c = GetC()) == EOF) { *eoff = TRUE; if (Tlen == 0) break; } if (*eoff || typeconv(c)) { if (Tlen == 0) { LineAt[(*infile)].blank = *infile > 0 ? LineAt[(*infile) - 1].blank + 1 : 1; } else { LineAt[(*infile)].blank = 0; } MarkLine(infile); if ((Tlen == 0) && blank) { typeinit(); continue; } blank = (Tlen == 0); y = typeline(y, skip); if (*eoff || (y >= LINES - 1)) break; } } if (!feof(InFile) && ferror(InFile)) clearerr(InFile); return y; /* result is the current line of display */ }
static int typeline(int y, int skip) { int found; if ((found = (UsePattern && GOT_REGEX(ToFind, Text))) != 0) HadPattern = TRUE; if (!skip) { move(y, 0); Tlen -= Shift; if (Tlen > COLS) Tlen = COLS; if (found) { (void) standout(); if (Tlen > 0) PRINTW("%.*s", Tlen, Text + Shift); else addstr(" "); (void) standend(); } else if (Tlen > 0) { int now = Shift, j; while (Tlen > 0) { for (j = now; j < now + Tlen; j++) { if (Over[j] != Over[now]) break; } if (Over[now]) (void) standout(); PRINTW("%.*s", (j - now), Text + now); if (Over[now]) (void) standend(); Tlen -= (j - now); now = j; } } clrtoeol(); } typeinit(); return (++y); }
int main(int argc, char *argv[]) { int i; char *s; while(argc>1 && argv[1][0]=='-'){ s=argv[1]+1; while(*s) switch(*s++){ case 'b': /* suppress become flattening */ bflag=1; break; case 'c': /* print constants */ cflag=1; break; case 'C': /* suppress constant compilation */ Cflag=1; break; case 'e': /* dump core on errors */ eflag=1; break; case 'i': /* print compiled instructions */ iflag=1; break; case 'm': /* trace message passing */ mflag=1; break; case 'P': /* set number of procs */ if(*s==0){ --argc, argv++; s=argv[1]; if(s==0) goto Usage; } Nproc=atol(s); if(Nproc<=0) goto Usage; goto Out; case 'p': /* trace process creation */ pflag++; break; case 't': /* dump parse trees */ tflag=1; break; case 'x': /* trace execution */ xflag=1; break; default: Usage: fprint(2, "usage: squint [-ixpb -PNPROC] <files>\n"); return 1; } Out: --argc; argv++; } interactive=argc==1; procinit(); fmtinstall('b', bconv); fmtinstall('e', econv); fmtinstall('m', mconv); fmtinstall('n', nconv); fmtinstall('t', tconv); fmtinstall('i', iconv); fmtinstall('A', Aconv); fmtinstall('C', Cconv); fmtinstall('U', Uconv); fmtinstall('z', zconv); fmtinstall('Z', zconv); lexinit(); typeinit(); initializing=1; if(errmark()){ fprint(2, "squint: error during initialization; exiting\n"); exits("initialization error"); } if(argc==1) newfile("<stdin>", 1); for(i=argc-1; i>0; --i) newfile(argv[i], 0); initializing=0; errmark(); /* Fflush(1); */ do; while(yyparse()); return 0; }