2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
8 /* Added termcap (termlib): BSB:3Com 9/17/80 */
9 /* Rewrite for VAX: BSB 9/9/79 */
10 /* Compiled with V7 cc: BSB 6/2/79 */
16 #include <sys/types.h>
23 # define CLEARPAGE { tputs(cl, 1, toutc); putchar('\000'); }
25 # define CLEARPAGE putchar('\014');
27 #define discard(io) { io->_cnt = BUFSIZ; io->_ptr = io->_base; }
42 short ontty
= 1; /* assume we're outputting to a tty */
43 short delflg
; /* a <DEL> was typed. */
45 char cl
[40]; /* Clear Screen string */
57 register char *c1
, *c2
;
62 extern char _sibuf
[], _sobuf
[];
63 extern char *getenv();
66 if((c1
= getenv("TERM")) == NULL
)
68 if(tgetent(bp
, c1
) != 1) {
69 fprintf(stderr
, "l: TERM env not in termcap\n");
72 if((width
= tgetnum("co")) == -1 ||
73 (spage
= tgetnum("li")) == -1) {
74 fprintf(stderr
, "l: Can't find term width/length\n");
84 if(gtty(1, &sg
) == -1) {
96 for( i
=1; i
<argc
; i
++ ) {/* look for - args */
97 if(argv
[i
][0] == '-' ) {
98 switch( argv
[i
][1] ) {
99 case 'c': noclr
++; break;
100 case 'f': first
=num(&argv
[i
][2]); /* set first line */
102 case 'n': numop
=1; /* set number option */
105 case 'p': spage
=num(&argv
[i
][2]); /* set page size */
107 case 'w': width
=num(&argv
[i
][2]);
109 case 'x': flagctl
= !flagctl
;
111 default: printf("Unknown switch: %s\n", argv
[i
]);
119 spage
= 0x07fffffff; /* largest positive number! */
120 setbuf(stdout
, _sobuf
);
123 signal(SIGQUIT
,getout
);
125 if(k
== 0) { /* filter */
138 if(fin
!= NULL
) { fclose(fin
); fin
= NULL
; }
139 if(stat(argv
[i
], &st
) == 0 && (st
.st_mode
&S_IFMT
) == S_IFDIR
){
140 printf("%s: Is a directory!\n", argv
[i
]);
143 if((fin
= fopen(argv
[i
],"r")) == NULL
) {
144 printf("Cannot open \"%s\" for reading!\n", argv
[i
]);
147 if(st
.st_size
== 0) {
148 printf("File \"%s\" is empty.\n", argv
[i
]);
156 printf("Press <RETURN> to list \"%s\"\n", argv
[i
]);
159 printf(">>>>> File \"%s\"\n", argv
[i
]);
167 int linpos
, line
, ct
;
178 while (line
< first
) /* Dcrocker: skip to first line */
179 if((c
= getch()) == EOF
)
185 if ((c
= getch()) != EOF
) {
186 if(!flg
&& !noclr
&& ontty
)
190 while ((c
= getch()) != EOF
);
195 num(s
) /* computes the internal form of a number */
196 register char *s
; /* bad chars are ignored */
198 register int c
, i
, sign
;
202 if(c
=='-' && sign
==1) sign
= -1;
204 if(c
>=0 && c
<=9) i
=i
*10+c
;
214 if (clearpage
& NOTIFY
)
218 while(read(2, &c
, 1) && c
!= '\n') ;
219 if (clearpage
& CLEAR
&& c
) {
223 page
= (spage
>>1) + (spage
>>3);
224 /*** page = spage * .6; ***/
243 return(peekc
= getch());
264 if(linpos
== 0 && numop
) {
266 printf("%5d\t", line
);
271 if(c
< 040 || c
== 0177) {
286 case '\b': /* ignore backspaces */
306 if(width
&& linpos
>= width
&& peekch() != '\n') {
307 putchar('\n'); linpos
= 0;
309 if(linpos
== 0 && --ct
<= 0) {
310 npage
: nextpage(NOTICLEAR
);