1: #
   2: /*
   3:  *   print file with headings
   4:  *  2+head+2+page[56]+5
   5:  */
   6: 
   7: int ncol    1;
   8: char    *header;
   9: int col;
  10: int icol;
  11: int file;
  12: char    *bufp;
  13: #define BUFS    5120
  14: char    buffer[BUFS];
  15: #define FF  014
  16: int line;
  17: char    *colp[72];
  18: int nofile;
  19: char    isclosed[10];
  20: int peekc;
  21: int fpage;
  22: int page;
  23: int colw;
  24: int nspace;
  25: int width   72;
  26: int length  66;
  27: int plength 61;
  28: int margin  10;
  29: int ntflg;
  30: int mflg;
  31: int tabc;
  32: char    *tty;
  33: int mode;
  34: 
  35: struct inode {
  36:     int dev;
  37:     int inum;
  38:     int flags;
  39:     char nlink;
  40:     char uid;
  41:     char gid;
  42:     char siz0;
  43:     int size;
  44:     int ptr[8];
  45:     int atime[2];
  46:     int mtime[2];
  47: };
  48: 
  49: main(argc, argv)
  50: char **argv;
  51: {
  52:     int nfdone;
  53:     int onintr();
  54:     extern fout;
  55: 
  56:     tty = "/dev/ttyx";
  57:     fout = dup(1);
  58:     close(1);
  59:     if ((signal(2, 1) & 01) == 0)
  60:         signal(2, onintr);
  61:     fixtty();
  62:     for (nfdone=0; argc>1; argc--) {
  63:         argv++;
  64:         if (**argv == '-') {
  65:             switch (*++*argv) {
  66:             case 'h':
  67:                 if (argc>=2) {
  68:                     header = *++argv;
  69:                     argc--;
  70:                 }
  71:                 continue;
  72: 
  73:             case 't':
  74:                 ntflg++;
  75:                 continue;
  76: 
  77:             case 'l':
  78:                 length = getn(++*argv);
  79:                 continue;
  80: 
  81:             case 'w':
  82:                 width = getn(++*argv);
  83:                 continue;
  84: 
  85:             case 's':
  86:                 if (*++*argv)
  87:                     tabc = **argv;
  88:                 else
  89:                     tabc = '\t';
  90:                 continue;
  91: 
  92:             case 'm':
  93:                 mflg++;
  94:                 continue;
  95: 
  96:             default:
  97:                 ncol = getn(*argv);
  98:                 continue;
  99:             }
 100:         } else if (**argv == '+') {
 101:             fpage = getn(++*argv);
 102:         } else {
 103:             print(*argv, argv);
 104:             nfdone++;
 105:             if (mflg)
 106:                 break;
 107:         }
 108:     }
 109:     if (nfdone==0)
 110:         print(0);
 111:     flush();
 112:     onintr();
 113: }
 114: 
 115: onintr()
 116: {
 117: 
 118:     chmod(tty, mode);
 119:     exit(0);
 120: }
 121: 
 122: fixtty()
 123: {
 124:     struct inode sbuf;
 125:     extern fout;
 126: 
 127:     tty[8] = ttyn(fout);
 128:     fstat(fout, &sbuf);
 129:     mode = sbuf.flags&0777;
 130:     chmod(tty, 0600);
 131: }
 132: 
 133: print(fp, argp)
 134: char *fp;
 135: char **argp;
 136: {
 137:     struct inode sbuf;
 138:     register int sncol, sheader;
 139:     register char *cbuf;
 140:     extern fout;
 141: 
 142:     if (ntflg)
 143:         margin = 0;
 144:     else
 145:         margin = 10;
 146:     if (length <= margin)
 147:         length = 66;
 148:     if (width <= 0)
 149:         width = 72;
 150:     if (ncol>72 || ncol>width) {
 151:         write(2, "Very funny.\n", 12);
 152:         exit();
 153:     }
 154:     if (mflg) {
 155:         mopen(argp);
 156:         ncol = nofile;
 157:     }
 158:     colw = width/ncol;
 159:     sncol = ncol;
 160:     sheader = header;
 161:     plength = length-5;
 162:     if (ntflg)
 163:         plength = length;
 164:     if (--ncol<0)
 165:         ncol = 0;
 166:     if (mflg)
 167:         fp = 0;
 168:     if (fp) {
 169:         file = open(fp, 0);
 170:         if (file<0)
 171:             return;
 172:         fstat(file, &sbuf);
 173:     } else {
 174:         file = 0;
 175:         time(sbuf.mtime);
 176:     }
 177:     if (header == 0)
 178:         header = fp;
 179:     cbuf = ctime(sbuf.mtime);
 180:     cbuf[16] = '\0';
 181:     cbuf[24] = '\0';
 182:     page = 1;
 183:     icol = 0;
 184:     colp[ncol] = bufp = buffer;
 185:     if (mflg==0)
 186:         nexbuf();
 187:     while (mflg&&nofile || (!mflg)&&tpgetc(ncol)>0) {
 188:         if (mflg==0) {
 189:             colp[ncol]--;
 190:             if (colp[ncol] < buffer)
 191:                 colp[ncol] = &buffer[BUFS];
 192:         }
 193:         line = 0;
 194:         if (ntflg==0) {
 195:             puts("\n\n");
 196:             puts(cbuf+4);
 197:             puts(" ");
 198:             puts(cbuf+20);
 199:             puts("  ");
 200:             puts(header);
 201:             puts(" Page ");
 202:             putd(page);
 203:             puts("\n\n\n");
 204:         }
 205:         putpage();
 206:         if (ntflg==0)
 207:             while(line<length)
 208:                 put('\n');
 209:         page++;
 210:     }
 211:     if (file)
 212:         close(file);
 213:     ncol = sncol;
 214:     header = sheader;
 215: }
 216: 
 217: mopen(ap)
 218: char **ap;
 219: {
 220:     register char **p, *p1;
 221: 
 222:     p = ap;
 223:     while ((p1 = *p++) && p1 != -1) {
 224:         isclosed[nofile] = fopen(p1, &buffer[2*259*nofile]);
 225:         if (++nofile>=10) {
 226:             write(2, "Too many args.\n", 15);
 227:             exit();
 228:         }
 229:     }
 230: }
 231: 
 232: putpage()
 233: {
 234:     register int lastcol, i, c;
 235:     int j;
 236: 
 237:     if (ncol==0) {
 238:         while (line<plength) {
 239:             while((c = tpgetc(0)) && c!='\n' && c!=FF)
 240:                 putcp(c);
 241:             putcp('\n');
 242:             line++;
 243:             if (c==FF)
 244:                 break;
 245:         }
 246:         return;
 247:     }
 248:     colp[0] = colp[ncol];
 249:     if (mflg==0) for (i=1; i<=ncol; i++) {
 250:         colp[i] = colp[i-1];
 251:         for (j = margin; j<length; j++)
 252:             while((c=tpgetc(i))!='\n')
 253:                 if (c==0)
 254:                     break;
 255:     }
 256:     while (line<plength) {
 257:         lastcol = colw;
 258:         for (i=0; i<ncol; i++) {
 259:             while ((c=pgetc(i)) && c!='\n')
 260:                 if (col<lastcol || tabc!=0)
 261:                     put(c);
 262:             if (c==0 && ntflg)
 263:                 return;
 264:             if (tabc)
 265:                 put(tabc);
 266:             else while (col<lastcol)
 267:                 put(' ');
 268:             lastcol =+ colw;
 269:         }
 270:         while ((c = pgetc(ncol)) && c!='\n')
 271:             put(c);
 272:         put('\n');
 273:     }
 274: }
 275: 
 276: nexbuf()
 277: {
 278:     register int n;
 279:     register char *rbufp;
 280: 
 281:     rbufp = bufp;
 282:     n = &buffer[BUFS] - rbufp;
 283:     if (n>512)
 284:         n = 512;
 285:     if ((n = read(file, rbufp, n)) <= 0)
 286:         *rbufp = 0376;
 287:     else {
 288:         rbufp =+ n;
 289:         if (rbufp >= &buffer[BUFS])
 290:             rbufp = buffer;
 291:         *rbufp = 0375;
 292:     }
 293:     bufp = rbufp;
 294: }
 295: 
 296: tpgetc(ai)
 297: {
 298:     register char **p;
 299:     register int c, i;
 300: 
 301:     i = ai;
 302:     if (mflg) {
 303:         if ((c = getc(&buffer[2*259*i])) < 0) {
 304:             if (isclosed[i]==0) {
 305:                 isclosed[i] = 1;
 306:                 if (--nofile <= 0)
 307:                     return(0);
 308:             }
 309:             return('\n');
 310:         }
 311:         if (c==FF && ncol>0)
 312:             c = '\n';
 313:         return(c);
 314:     }
 315: loop:
 316:     c = **(p = &colp[i]) & 0377;
 317:     if (c == 0375) {
 318:         nexbuf();
 319:         c = **p & 0377;
 320:     }
 321:     if (c == 0376)
 322:         return(0);
 323:     (*p)++;
 324:     if (*p >= &buffer[BUFS])
 325:         *p = buffer;
 326:     if (c==0)
 327:         goto loop;
 328:     return(c);
 329: }
 330: 
 331: pgetc(i)
 332: {
 333:     register int c;
 334: 
 335:     if (peekc) {
 336:         c = peekc;
 337:         peekc = 0;
 338:     } else
 339:         c = tpgetc(i);
 340:     if (tabc)
 341:         return(c);
 342:     switch (c) {
 343: 
 344:     case '\t':
 345:         icol++;
 346:         if ((icol&07) != 0)
 347:             peekc = '\t';
 348:         return(' ');
 349: 
 350:     case '\n':
 351:         icol = 0;
 352:         break;
 353: 
 354:     case 010:
 355:     case 033:
 356:         icol--;
 357:         break;
 358:     }
 359:     if (c >= ' ')
 360:         icol++;
 361:     return(c);
 362: }
 363: 
 364: puts(as)
 365: char *as;
 366: {
 367:     register int c;
 368:     register char *s;
 369: 
 370:     if ((s=as)==0)
 371:         return;
 372:     while (c = *s++)
 373:         put(c);
 374: }
 375: 
 376: putd(an)
 377: {
 378:     register int a, n;
 379: 
 380:     n = an;
 381:     if (a = n/10)
 382:         putd(a);
 383:     put(n%10 + '0');
 384: }
 385: 
 386: put(ac)
 387: {
 388:     register int ns, c;
 389: 
 390:     c = ac;
 391:     if (tabc) {
 392:         putcp(c);
 393:         if (c=='\n')
 394:             line++;
 395:         return;
 396:     }
 397:     switch (c) {
 398: 
 399:     case ' ':
 400:         nspace++;
 401:         col++;
 402:         return;
 403: 
 404:     case '\n':
 405:         col = 0;
 406:         nspace = 0;
 407:         line++;
 408:         break;
 409: 
 410:     case 010:
 411:     case 033:
 412:         if (--col<0)
 413:             col = 0;
 414:         if (--nspace<0)
 415:             nspace = 0;
 416: 
 417:     }
 418:     while(nspace) {
 419:         if (nspace>2 && col > (ns=((col-nspace)|07))) {
 420:             nspace = col-ns-1;
 421:             putcp('\t');
 422:         } else {
 423:             nspace--;
 424:             putcp(' ');
 425:         }
 426:     }
 427:     if (c >= ' ')
 428:         col++;
 429:     putcp(c);
 430: }
 431: 
 432: getn(ap)
 433: char *ap;
 434: {
 435:     register int n, c;
 436:     register char *p;
 437: 
 438:     p = ap;
 439:     n = 0;
 440:     while ((c = *p++) >= '0' && c <= '9')
 441:         n = n*10 + c - '0';
 442:     return(n);
 443: }
 444: 
 445: putcp(c)
 446: {
 447:     if (page >= fpage)
 448:         putchar(c);
 449: }

Defined functions

fixtty defined in line 122; used 1 times
  • in line 61
getn defined in line 432; used 4 times
main defined in line 49; never used
mopen defined in line 217; used 1 times
nexbuf defined in line 276; used 2 times
onintr defined in line 115; used 3 times
pgetc defined in line 331; used 2 times
print defined in line 133; used 2 times
put defined in line 386; used 8 times
putcp defined in line 445; used 6 times
putd defined in line 376; used 2 times
putpage defined in line 232; used 1 times
puts defined in line 364; used 9 times
tpgetc defined in line 296; used 4 times

Defined variables

buffer defined in line 14; used 10 times
bufp defined in line 12; used 3 times
col defined in line 9; used 10 times
colp defined in line 17; used 9 times
colw defined in line 23; used 3 times
file defined in line 11; used 7 times
fpage defined in line 21; used 2 times
header defined in line 8; used 6 times
icol defined in line 10; used 6 times
isclosed defined in line 19; used 3 times
length defined in line 26; used 7 times
line defined in line 16; used 7 times
margin defined in line 28; used 4 times
mflg defined in line 30; used 10 times
mode defined in line 33; used 2 times
ncol defined in line 7; used 20 times
nofile defined in line 18; used 6 times
nspace defined in line 24; used 9 times
ntflg defined in line 29; used 6 times
page defined in line 22; used 4 times
peekc defined in line 20; used 4 times
plength defined in line 27; used 4 times
tabc defined in line 31; used 7 times
tty defined in line 32; used 4 times
width defined in line 25; used 5 times

Defined struct's

inode defined in line 35; used 4 times

Defined macros

BUFS defined in line 13; used 5 times
FF defined in line 15; used 3 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1813
Valid CSS Valid XHTML 1.0 Strict