#ifdef COMMENT Proprietary Rand Corporation, 1981. Further distribution of this software subject to the terms of the Rand license agreement. #endif /* Added termcap (termlib): BSB:3Com 9/17/80 */ /* Rewrite for VAX: BSB 9/9/79 */ /* Compiled with V7 cc: BSB 6/2/79 */ #include #include #include #include #include #include #define YES 1 #define NO 0 #ifdef TERMCAP # define CLEARPAGE { tputs(cl, 1, toutc); putchar('\000'); } #else # define CLEARPAGE putchar('\014'); #endif #define discard(io) { io->_cnt = BUFSIZ; io->_ptr = io->_base; } #define PAUSE 0 #define NOTIFY 1 #define CLEAR 2 #define NOTICLEAR 3 int spage; int page; short width; short noclr = 0; short first = 0; short numop = 0; short wrap = 0; short flagctl = 1; short ontty = 1; /* assume we're outputting to a tty */ short delflg; /* a was typed. */ char bp[1024]; char cl[40]; /* Clear Screen string */ char *clp = cl; int toutc(); FILE *fin; jmp_buf envir; main(argc, argv) int argc; char *argv[]; { register int i,k; register char *c1, *c2; int j, clrflag; int int2(), getout(); struct sgttyb sg; struct stat st; extern char _sibuf[], _sobuf[]; extern char *getenv(); #ifdef TERMCAP if((c1 = getenv("TERM")) == NULL) c1 = "aa"; /* RAND */ if(tgetent(bp, c1) != 1) { fprintf(stderr, "l: TERM env not in termcap\n"); exit(1); } if((width = tgetnum("co")) == -1 || (spage = tgetnum("li")) == -1) { fprintf(stderr, "l: Can't find term width/length\n"); exit(1); } tgetstr("cl", &clp); #else width = 80; spage = 24; #endif width--; spage -= 2; if(gtty(1, &sg) == -1) { ontty = 0; flagctl = 0; } c1 = c2 = argv[0]; do if(*c1++ == '/') c2 = c1; while(*c1); if(*c2 == 'c') noclr++; k=0; for( i=1; i1) { if(i && delflg <= 0) printf("\n\n"); delflg = 0; if(ontty) { printf("Press to list \"%s\"\n", argv[i]); clrflag = 1; } else printf(">>>>> File \"%s\"\n", argv[i]); } pfile(clrflag); } getout(); } int linpos, line, ct; pfile(flg) { register int c; if(flg) nextpage(NOTICLEAR); delflg = -1; line = 1; ct = page; while (line < first) /* Dcrocker: skip to first line */ if((c = getch()) == EOF) return; else if(c == '\n') line++; linpos = 0; if ((c = getch()) != EOF) { if(!flg && !noclr && ontty) CLEARPAGE; do putch(c); while ((c = getch()) != EOF); } fflush(stdout); } num(s) /* computes the internal form of a number */ register char *s; /* bad chars are ignored */ { register int c, i, sign; sign=1; i=0; while(c = *s++) { if(c=='-' && sign==1) sign = -1; c -= '0'; if(c>=0 && c<=9) i=i*10+c; } return(i*sign); } nextpage (clearpage) { char c; if(!ontty) return; if (clearpage & NOTIFY) putchar('\007'); fflush(stdout); c = 0; while(read(2, &c, 1) && c != '\n') ; if (clearpage & CLEAR && c) { CLEARPAGE; page = spage; } else { page = (spage>>1) + (spage>>3); /*** page = spage * .6; ***/ } return; } int2() { signal(SIGINT,int2); discard(stdout); if(delflg) putchar('\n'); delflg++; longjmp(envir, 1); } int peekc = -2; peekch() { return(peekc = getch()); } getch() { register int c; if(peekc != -2) { c = peekc; peekc = -2; return(c); }; c = getc(fin); if(c != EOF) c &= 0177; return(c); } putch(c) register int c; { if(linpos == 0 && numop) { if(!wrap) printf("%5d\t", line); else printf("\t"); linpos += 8; } if(c < 040 || c == 0177) { switch(c) { case '\n': line++; linpos = 0; wrap = 0; putchar(c); break; case '\f': goto npage; case '\t': linpos += 8; linpos &= ~07; putchar(c); break; case '\b': /* ignore backspaces */ break; default: if(flagctl) { if(c == '\7') putchar(c); putch('^'); if(c != 0177) c += '@'; else c = 'd'; } putchar(c); break; } } else { putchar(c); linpos++; } if(width && linpos >= width && peekch() != '\n') { putchar('\n'); linpos = 0; } if(linpos == 0 && --ct <= 0) { npage: nextpage(NOTICLEAR); ct = page; } } getout() { exit(0); } toutc(ch) { putchar