1: #ifndef lint
   2: static char sccsid[] = "@(#)n1.c	4.8 7/21/87";
   3: #endif lint
   4: 
   5: #include "tdef.h"
   6: #include <sys/types.h>
   7: #include <sys/stat.h>
   8: #include <time.h>
   9: extern
  10: #include "d.h"
  11: extern
  12: #include "v.h"
  13: #ifdef NROFF
  14: extern
  15: #include "tw.h"
  16: #endif
  17: #include "sdef.h"
  18: #include <setjmp.h>
  19: jmp_buf sjbuf;
  20: #include    <sgtty.h>
  21: /*
  22: troff1.c
  23: 
  24: consume options, initialization, main loop,
  25: input routines, escape function calling
  26: */
  27: 
  28: int inchar[LNSIZE], *pinchar = inchar;  /* XXX */
  29: extern struct s *frame, *stk, *nxf;
  30: extern struct s *ejl, *litlev;
  31: extern filep ip;
  32: extern filep offset;
  33: extern filep nextb;
  34: 
  35: 
  36: extern int stdi;
  37: extern int waitf;
  38: extern int nofeed;
  39: extern int quiet;
  40: extern int ptid;
  41: extern int ascii;
  42: extern int npn;
  43: extern int xflg;
  44: extern int stop;
  45: extern char ibuf[IBUFSZ];
  46: extern char xbuf[IBUFSZ];
  47: extern char *ibufp;
  48: extern char *xbufp;
  49: extern char *eibuf;
  50: extern char *xeibuf;
  51: extern int cbuf[NC];
  52: extern int *cp;
  53: extern int *vlist;
  54: extern int nx;
  55: extern int mflg;
  56: extern int ch;
  57: extern int pto;
  58: extern int pfrom;
  59: extern int cps;
  60: extern int chbits;
  61: extern int ibf;
  62: extern int ttyod;
  63: extern struct sgttyb ttys;
  64: extern int iflg;
  65: extern int init;
  66: extern int rargc;
  67: extern char **argp;
  68: extern char trtab[256];
  69: extern int lgf;
  70: extern int copyf;
  71: extern int eschar;
  72: extern int ch0;
  73: extern int cwidth;
  74: extern int nlflg;
  75: extern int *ap;
  76: extern int donef;
  77: extern int nflush;
  78: extern int nchar;
  79: extern int rchar;
  80: extern int nfo;
  81: extern int ifile;
  82: extern int fc;
  83: extern int padc;
  84: extern int tabc;
  85: extern int dotc;
  86: extern int raw;
  87: extern int tabtab[NTAB];
  88: extern char nextf[];
  89: extern int nfi;
  90: #ifdef NROFF
  91: extern char termtab[];
  92: extern int tti;
  93: #endif
  94: extern int ifl[NSO];
  95: extern int ifi;
  96: extern int pendt;
  97: extern int flss;
  98: extern int fi;
  99: extern int lg;
 100: extern char ptname[];
 101: extern int print;
 102: extern int nonumb;
 103: extern int pnlist[];
 104: extern int *pnp;
 105: extern int nb;
 106: extern int trap;
 107: extern int tflg;
 108: extern int ejf;
 109: extern int lit;
 110: extern int cc;
 111: extern int c2;
 112: extern int spread;
 113: extern int gflag;
 114: extern int oline[];
 115: extern int *olinep;
 116: extern int dpn;
 117: extern int noscale;
 118: extern char *unlkp;
 119: extern int pts;
 120: extern int level;
 121: extern int ttysave;
 122: extern int tdelim;
 123: extern int dotT;
 124: extern int tabch, ldrch;
 125: extern int eqflg;
 126: extern no_out;
 127: extern int hflg;
 128: #ifndef NROFF
 129: extern char codetab[];
 130: extern int spbits;
 131: #endif
 132: extern int xxx;
 133: int stopmesg;
 134: filep ipl[NSO];
 135: long offl[NSO];
 136: long ioff;
 137: char *ttyp;
 138: extern struct contab {
 139:     int rq;
 140:     union {
 141:         int (*f)();
 142:         unsigned mx;
 143:     }x;
 144: }contab[NM];
 145: int ms[] = {31,28,31,30,31,30,31,31,30,31,30,31};
 146: #ifndef NROFF
 147: int acctf;
 148: #endif
 149: 
 150: main(argc,argv)
 151: int argc;
 152: char **argv;
 153: {
 154:     char *p, *q;
 155:     register i, j;
 156:     extern catch(), fpecatch(), kcatch();
 157: 
 158:     signal(SIGHUP,catch);
 159:     if(signal(SIGINT,catch) == SIG_IGN){
 160:         signal(SIGHUP,SIG_IGN);
 161:         signal(SIGINT,SIG_IGN);
 162:         signal(SIGQUIT,SIG_IGN);
 163:     }
 164:     signal(SIGFPE,fpecatch);
 165:     signal(SIGPIPE,catch);
 166:     signal(SIGTERM,kcatch);
 167:     init1(argv[0][0]);
 168: options:
 169:     while(--argc > 0 && (++argv)[0][0]=='-')
 170:         switch(argv[0][1]){
 171: 
 172:         case 0:
 173:             goto start;
 174:         case 'i':
 175:             stdi++;
 176:             continue;
 177:         case 'q':
 178:             quiet++;
 179:             if(gtty(0, &ttys) >= 0)
 180:                 ttysave = ttys.sg_flags;
 181:             continue;
 182:         case 'n':
 183:             npn = cnum(&argv[0][2]);
 184:             continue;
 185:         case 'p':
 186:             xflg = 0;
 187:             cps = cnum(&argv[0][2]);
 188:             continue;
 189:         case 'S':
 190:             stopmesg++;
 191:             continue;
 192:         case 's':
 193:             if(!(stop = cnum(&argv[0][2])))stop++;
 194:             continue;
 195:         case 'r':
 196:             vlist[findr(argv[0][2])] = cnum(&argv[0][3]);
 197:             continue;
 198:         case 'm':
 199:             p = &nextf[nfi];
 200:             q = &argv[0][2];
 201:             while((*p++ = *q++) != 0);
 202:             if (access(nextf, 4) < 0) {
 203: char *local = "/usr/local/lib/tmac/tmac.\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
 204:                 strcat(local, &argv[0][2]);
 205:                 if (access(local, 4) == 0)
 206:                     strcpy(nextf, local);
 207:             }
 208:             mflg++;
 209:             continue;
 210:         case 'o':
 211:             getpn(&argv[0][2]);
 212:             continue;
 213: #ifdef NROFF
 214:         case 'h':
 215:             hflg++;
 216:             continue;
 217:         case 'z':
 218:             no_out++;
 219:             continue;
 220:         case 'e':
 221:             eqflg++;
 222:             continue;
 223:         case 'T':
 224:             p = &termtab[tti];
 225:             q = &argv[0][2];
 226:             if(!((*q) & 0177))continue;
 227:             while((*p++ = *q++) != 0);
 228:             dotT++;
 229:             continue;
 230: #endif
 231: #ifndef NROFF
 232:         case 'z':
 233:             no_out++;
 234:         case 'a':
 235:             ascii = 1;
 236:             nofeed++;
 237:         case 't':
 238:             ptid = 1;
 239:             continue;
 240:         case 'w':
 241:             waitf = 1;
 242:             continue;
 243:         case 'f':
 244:             nofeed++;
 245:             continue;
 246:         case 'x':
 247:             xflg = 0;
 248:             continue;
 249:         case 'b':
 250:             if(open(ptname,1) < 0)prstr("Busy.\n");
 251:             else prstr("Available.\n");
 252:             done3(0);
 253:         case 'g':
 254:             stop = ptid = gflag = 1;
 255:             dpn = 0;
 256:             continue;
 257:         case 'F':
 258:             {
 259:               extern char *fontfile;
 260:               fontfile = &argv[0][2];
 261:             }
 262:             continue;
 263: #endif
 264:         default:
 265:             pto = cnum(&argv[0][1]);
 266:             continue;
 267:         }
 268: 
 269:     if(argv[0][0] == '+'){
 270:         pfrom = cnum(&argv[0][1]);
 271:         print = 0;
 272:         if(argc > 0)goto options;
 273:     }
 274: 
 275: start:
 276:     argp = argv;
 277:     rargc = argc;
 278:     init2();
 279:     setjmp(sjbuf);
 280: loop:
 281:     copyf = lgf = nb = nflush = nlflg = 0;
 282:     if(ip && (rbf0(ip)==0) && ejf && (frame->pframe <= ejl)){
 283:         nflush++;
 284:         trap = 0;
 285:         eject((struct s *)0);
 286:         goto loop;
 287:     }
 288:     i = getch();
 289:     if(pendt)goto lt;
 290:     if(lit && (frame <= litlev)){
 291:         lit--;
 292:         goto lt;
 293:     }
 294:     if((j = (i & CMASK)) == XPAR){
 295:         copyf++;
 296:         tflg++;
 297:         for(;(i & CMASK) != '\n';)pchar(i = getch());
 298:         tflg = 0;
 299:         copyf--;
 300:         goto loop;
 301:     }
 302:     if((j == cc) || (j == c2)){
 303:         if(j == c2)nb++;
 304:         copyf++;
 305:         while(((j=((i=getch()) & CMASK)) == ' ') ||
 306:             (j == '\t'));
 307:         ch = i;
 308:         copyf--;
 309:         control(getrq(),1);
 310:         flushi();
 311:         goto loop;
 312:     }
 313: lt:
 314:     ch = i;
 315:     text();
 316:     goto loop;
 317: }
 318: catch(){
 319: /*
 320: 	prstr("Interrupt\n");
 321: */
 322:     done3(01);
 323: }
 324: fpecatch(){
 325:     prstrfl("Floating Exception.\n");
 326:     signal(SIGFPE,fpecatch);
 327: }
 328: kcatch(){
 329:     signal(SIGTERM,SIG_IGN);
 330:     done3(01);
 331: }
 332: #ifndef NROFF
 333: acctg() {
 334:     static char *acct_file = "/usr/adm/tracct";
 335:     acctf = open(acct_file,1);
 336:     setuid(getuid());
 337: }
 338: #endif
 339: init1(a)
 340: char a;
 341: {
 342:     register char *p;
 343:     char *mktemp();
 344:     register i;
 345: 
 346: #ifndef NROFF
 347:     acctg();/*open troff actg file while mode 4755*/
 348: #endif
 349:     p = mktemp("/tmp/taXXXXX");
 350:     if(a == 'a')p = &p[5];
 351:     if((close(creat(p, 0600))) < 0){
 352:         prstr("Cannot create temp file.\n");
 353:         exit(-1);
 354:     }
 355:     ibf = open(p, 2);
 356:     for(i=256; --i;)trtab[i]=i;
 357:     trtab[UNPAD] = ' ';
 358:     mchbits();
 359:     if(a != 'a')unlkp = p;
 360: }
 361: init2()
 362: {
 363:     register i,j;
 364:     extern int block;
 365:     extern char *setbrk();
 366:     extern char *ttyname();
 367: 
 368:     ttyod = 2;
 369:     if(((ttyp=ttyname(j=0)) != (char *)0) ||
 370:        ((ttyp=ttyname(j=1)) != (char *)0) ||
 371:        ((ttyp=ttyname(j=2)) != (char *)0)
 372:       );else ttyp = "notty";
 373:     iflg = j;
 374:     if(ascii)mesg(0);
 375: 
 376:     if((!ptid) && (!waitf)){
 377:         if((ptid = open(ptname,1)) < 0){
 378:             prstr("Typesetter busy.\n");
 379:             done3(-2);
 380:         }
 381:     }
 382:     ptinit();
 383:     for(i=NEV; i--;)write(ibf, (char *)&block, EVS*sizeof(int));
 384:     olinep = oline;
 385:     ibufp = eibuf = ibuf;
 386:     v.hp = init = 0;
 387:     pinchar = inchar;   /* XXX */
 388:     ioff = 0;
 389:     v.nl = -1;
 390:     cvtime();
 391:     frame = stk = (struct s *)setbrk(DELTA);
 392:     dip = &d[0];
 393:     nxf = frame + 1;
 394:     nx = mflg;
 395: }
 396: cvtime()
 397: {
 398:     extern time_t time();
 399:     time_t t;
 400:     register struct tm *tmp;
 401: 
 402:     t = time((time_t *)0);
 403:     tmp = localtime(&t);
 404:     v.dy = tmp->tm_mday;
 405:     v.dw = tmp->tm_wday + 1;
 406:     v.yr = tmp->tm_year;
 407:     v.mo = tmp->tm_mon + 1;
 408: }
 409: cnum(a)
 410: char *a;
 411: {
 412:     register i;
 413: 
 414:     ibufp = a;
 415:     eibuf = (char *) MAXPTR;
 416:     i = atoi();
 417:     ch = 0;
 418:     return(i);
 419: }
 420: mesg(f)
 421: int f;
 422: {
 423:     static int mode;
 424: 
 425:     if (ttyp==0)
 426:         return;
 427:     if(!f){
 428:         stat(ttyp,cbuf);
 429:         mode = ((struct stat *)(cbuf))->st_mode;
 430:         chmod(ttyp,mode & ~022);
 431:     }else{
 432:         chmod(ttyp,mode);
 433:     }
 434: }
 435: prstrfl(s)
 436: char *s;
 437: {
 438:     flusho();
 439:     prstr(s);
 440: }
 441: prstr(s)
 442: char *s;
 443: {
 444:     register i;
 445:     register char *j;
 446: 
 447:     j = s;
 448:     for(i=0;*s;i++)s++;
 449:     write(ttyod,j,i);
 450: }
 451: control(a,b)
 452: int a,b;
 453: {
 454:     register i,j;
 455:     extern filep boff();
 456: 
 457:     i = a;
 458:     if((i == 0) || ((j = findmn(i)) == -1))return(0);
 459:     if(contab[j].rq & MMASK){
 460:         nxf->nargs = 0;
 461:         if(b)collect();
 462:         flushi();
 463:         return(pushi(((filep)contab[j].x.mx)<<BLKBITS));
 464:     }else{
 465:         if(!b)return(0);
 466:         return((*contab[j].x.f)(0));
 467:     }
 468: }
 469: 
 470: getrq(){
 471:     register i,j;
 472: 
 473:     if(((i=getach()) == 0) ||
 474:        ((j=getach()) == 0))goto rtn;
 475:     i = PAIR(i,j);
 476: rtn:
 477:     return(i);
 478: }
 479: getch(){
 480:     register int i, j, k;
 481: 
 482:     level++;
 483: g0:
 484:     if(ch){
 485:         if(((i = ch) & CMASK) == '\n')nlflg++;
 486:         ch = 0;
 487:         level--;
 488:         return(i);
 489:     }
 490: 
 491:     if(nlflg){
 492:         level--;
 493:         return('\n');
 494:     }
 495: 
 496:     if((k = (i = getch0()) & CMASK) != ESC){
 497:         if(i & MOT)goto g2;
 498:         if(k == FLSS){
 499:             copyf++; raw++;
 500:             i = getch0();
 501:             if(!fi)flss = i;
 502:             copyf--; raw--;
 503:             goto g0;
 504:         }
 505:         if(k == RPT){
 506:             setrpt();
 507:             goto g0;
 508:         }
 509:         if(!copyf){
 510:             if((k == 'f') && lg && !lgf){
 511:                 i = getlg(i);
 512:                 goto g2;
 513:             }
 514:             if((k == fc) || (k == tabch) || (k == ldrch)){
 515:                 if((i=setfield(k)) == 0)goto g0; else goto g2;
 516:             }
 517:             if(k == 010){
 518:                 i = makem(-width(' ' | chbits));
 519:                 goto g2;
 520:             }
 521:         }
 522:         goto g2;
 523:     }
 524:     k = (j = getch0()) & CMASK;
 525:     if(j & MOT){
 526:         i = j;
 527:         goto g2;
 528:     }
 529: /*
 530: 	if(k == tdelim){
 531: 		i = TDELIM;
 532: 		tdelim = IMP;
 533: 		goto g2;
 534: 	}
 535: */
 536:     switch(k){
 537: 
 538:         case '\n':  /*concealed newline*/
 539:             goto g0;
 540:         case 'n':   /*number register*/
 541:             setn();
 542:             goto g0;
 543:         case '*':   /*string indicator*/
 544:             setstr();
 545:             goto g0;
 546:         case '$':   /*argument indicator*/
 547:             seta();
 548:             goto g0;
 549:         case '{':   /*LEFT*/
 550:             i = LEFT;
 551:             goto gx;
 552:         case '}':   /*RIGHT*/
 553:             i = RIGHT;
 554:             goto gx;
 555:         case '"':   /*comment*/
 556:             while(((i=getch0()) & CMASK ) != '\n');
 557:             goto g2;
 558:         case ESC:   /*double backslash*/
 559:             i = eschar;
 560:             goto gx;
 561:         case 'e':   /*printable version of current eschar*/
 562:             i = PRESC;
 563:             goto gx;
 564:         case ' ':   /*unpaddable space*/
 565:             i = UNPAD;
 566:             goto gx;
 567:         case '|':   /*narrow space*/
 568:             i = NARSP;
 569:             goto gx;
 570:         case '^':   /*half of narrow space*/
 571:             i = HNSP;
 572:             goto gx;
 573:         case '\'':  /*\(aa*/
 574:             i = 0222;
 575:             goto gx;
 576:         case '`':   /*\(ga*/
 577:             i = 0223;
 578:             goto gx;
 579:         case '_':   /*\(ul*/
 580:             i = 0224;
 581:             goto gx;
 582:         case '-':   /*current font minus*/
 583:             i = 0210;
 584:             goto gx;
 585:         case '&':   /*filler*/
 586:             i = FILLER;
 587:             goto gx;
 588:         case 'c':   /*to be continued*/
 589:             i = CONT;
 590:             goto gx;
 591:         case ':':   /*lem's char*/
 592:             i = COLON;
 593:             goto gx;
 594:         case '!':   /*transparent indicator*/
 595:             i = XPAR;
 596:             goto gx;
 597:         case 't':   /*tab*/
 598:             i = '\t';
 599:             goto g2;
 600:         case 'a':   /*leader (SOH)*/
 601:             i = LEADER;
 602:             goto g2;
 603:         case '%':   /*ohc*/
 604:             i = OHC;
 605:             goto g2;
 606:         case '.':   /*.*/
 607:             i = '.';
 608:         gx:
 609:             i = (j & ~CMASK) | i;
 610:             goto g2;
 611:     }
 612:     if(!copyf)
 613:         switch(k){
 614: 
 615:             case 'p':   /*spread*/
 616:                 spread++;
 617:                 goto g0;
 618:             case '(':   /*special char name*/
 619:                 if((i=setch()) == 0)goto g0;
 620:                 break;
 621:             case 's':   /*size indicator*/
 622:                 setps();
 623:                 goto g0;
 624:             case 'f':   /*font indicator*/
 625:                 setfont(0);
 626:                 goto g0;
 627:             case 'w':   /*width function*/
 628:                 setwd();
 629:                 goto g0;
 630:             case 'v':   /*vert mot*/
 631:                 if(i = vmot())break;
 632:                 goto g0;
 633:             case 'h':   /*horiz mot*/
 634:                 if(i = hmot())break;
 635:                 goto g0;
 636:             case 'z':   /*zero with char*/
 637:                 i = setz();
 638:                 break;
 639:             case 'l':   /*hor line*/
 640:                 setline();
 641:                 goto g0;
 642:             case 'L':   /*vert line*/
 643:                 setvline();
 644:                 goto g0;
 645:             case 'b':   /*bracket*/
 646:                 setbra();
 647:                 goto g0;
 648:             case 'o':   /*overstrike*/
 649:                 setov();
 650:                 goto g0;
 651:             case 'k':   /*mark hor place*/
 652:                 if((i=findr(getsn())) == -1)goto g0;
 653:                 vlist[i] = v.hp = sumhp();  /* XXX */
 654:                 goto g0;
 655:             case 'j':   /*mark output hor place*/
 656:                 if(!(i=getach()))goto g0;
 657:                 i = (i<<BYTE) | JREG;
 658:                 break;
 659:             case '0':   /*number space*/
 660:                 i = makem(width('0' | chbits));
 661:                 break;
 662:             case 'x':   /*extra line space*/
 663:                 if(i = xlss())break;
 664:                 goto g0;
 665:             case 'u':   /*half em up*/
 666:             case 'r':   /*full em up*/
 667:             case 'd':   /*half em down*/
 668:                 i = sethl(k);
 669:                 break;
 670:             default:
 671:                 i = j;
 672:         }
 673:     else{
 674:         ch0 = j;
 675:         i = eschar;
 676:     }
 677: g2:
 678:     if((i & CMASK) == '\n'){
 679:         nlflg++;
 680:         v.hp = 0;
 681:         pinchar = inchar;   /* XXX */
 682:         if(ip == 0)v.cd++;
 683:     }
 684:     if(!--level){
 685:         /* j = width(i); */
 686:         /* v.hp += j; */
 687:         /* cwidth = j; */
 688:         if (pinchar >= inchar + LNSIZE) {   /* XXX */
 689:             inchar[0] = makem(sumhp());
 690:             pinchar = &inchar[1];
 691:         }
 692:         *pinchar++ = i; /* XXX */
 693:     }
 694:     return(i);
 695: }
 696: 
 697: sumhp() /* XXX - add up widths in inchar array */
 698: {
 699:     register int n;
 700:     register int *p;
 701: 
 702:     n = 0;
 703:     for (p = inchar; p < pinchar; p++)
 704:         n += width(*p);
 705:     return(n);
 706: }
 707: char ifilt[32] = {0,001,002,003,0,005,006,007,010,011,012};
 708: getch0(){
 709:     register int i, j;
 710: 
 711:     if(ch0){i=ch0; ch0=0; return(i);}
 712:     if(nchar){nchar--; return(rchar);}
 713: 
 714: again:
 715:     if(cp){
 716:         if((i = *cp++) == 0){
 717:             cp = 0;
 718:             goto again;
 719:         }
 720:     }else if(ap){
 721:         if((i = *ap++) == 0){
 722:             ap = 0;
 723:             goto again;
 724:         }
 725:     }else if(ip){
 726:         if(ip == -1)i = rdtty();
 727:         else i = rbf();
 728:     }else{
 729:         if(donef)done(0);
 730:         if(nx || ((ibufp >= eibuf) && (eibuf != (char *) MAXPTR))){
 731:             if(nfo)goto g1;
 732:         g0:
 733:             if(nextfile()){
 734:                 if(ip)goto again;
 735:                 if(ibufp < eibuf)goto g2;
 736:             }
 737:         g1:
 738:             nx = 0;
 739:             if((j=read(ifile,ibuf,IBUFSZ)) <= 0)goto g0;
 740:             ibufp = ibuf;
 741:             eibuf = ibuf + j;
 742:             if(ip)goto again;
 743:         }
 744:     g2:
 745:         i = *ibufp++ & 0177;
 746:         ioff++;
 747:         if(i >= 040)goto g4; else i = ifilt[i];
 748:     }
 749:     if(raw)return(i);
 750:     if((j = i & CMASK) == IMP)goto again;
 751:     if((i == 0) && !init)goto again;
 752: g4:
 753:     if((copyf == 0) && ((i & ~BMASK) == 0) && ((i & CMASK) < 0370))
 754: #ifndef NROFF
 755:         if(spbits && (i>31) && ((codetab[i-32] & 0200))) i |= spbits;
 756:         else
 757: #endif
 758:         i |= chbits;
 759:     if((i & CMASK) == eschar)i = (i & ~CMASK) | ESC;
 760:     return(i);
 761: }
 762: nextfile(){
 763:     register char *p;
 764: 
 765: n0:
 766:     if(ifile)close(ifile);
 767:     if(nx){
 768:         p = nextf;
 769:         if(*p != 0)goto n1;
 770:     }
 771:     if(ifi > 0){
 772:         if(popf())goto n0; /*popf error*/
 773:         return(1); /*popf ok*/
 774:     }
 775:     if(rargc-- <= 0)goto n2;
 776:     p = (argp++)[0];
 777: n1:
 778:     if((p[0] == '-') && (p[1] == 0)){
 779:         ifile = 0;
 780:     }else if((ifile=open(p,0)) < 0){
 781:         prstr("Cannot open ");
 782:         prstr(p);
 783:         prstr("\n");
 784:         nfo -= mflg;
 785:         done(02);
 786:     }
 787:     nfo++;
 788:     v.cd = 0;
 789:     ioff = 0;
 790:     return(0);
 791: n2:
 792:     if((nfo -= mflg) && !stdi)done(0);
 793:     nfo++;
 794:     v.cd = ifile =  stdi = mflg = 0;
 795:     ioff = 0;
 796:     return(0);
 797: }
 798: popf(){
 799:     register i;
 800:     register char *p, *q;
 801:     extern char *ttyname();
 802: 
 803:     ioff = offl[--ifi];
 804:     ip = ipl[ifi];
 805:     if((ifile = ifl[ifi]) == 0){
 806:         p = xbuf;
 807:         q = ibuf;
 808:         ibufp = xbufp;
 809:         eibuf = xeibuf;
 810:         while(q < eibuf)*q++ = *p++;
 811:         return(0);
 812:     }
 813:     if((lseek(ifile,(long)(ioff & ~(IBUFSZ-1)),0) < 0) ||
 814:        ((i = read(ifile,ibuf,IBUFSZ)) < 0))return(1);
 815:     eibuf = ibuf + i;
 816:     ibufp = ibuf;
 817:     if(ttyname(ifile) == (char *)0)
 818:         if((ibufp = ibuf + (int)(ioff & (IBUFSZ-1)))  >= eibuf)return(1);
 819:     return(0);
 820: }
 821: flushi(){
 822:     if(nflush)return;
 823:     ch = 0;
 824:     if((ch0 & CMASK) == '\n')nlflg++;
 825:     ch0 = 0;
 826:     copyf++;
 827:     while(!nlflg){
 828:         if(donef && (frame == stk))break;
 829:         getch();
 830:     }
 831:     copyf--;
 832:     v.hp = 0;
 833:     pinchar = inchar;   /* XXX */
 834: }
 835: getach(){
 836:     register i;
 837: 
 838:     lgf++;
 839:     if(((i = getch()) & MOT) ||
 840:         ((i&CMASK) == ' ') ||
 841:         ((i&CMASK) == '\n')||
 842:         (i & 0200)){
 843:             ch = i;
 844:             i = 0;
 845:     }
 846:     lgf--;
 847:     return(i & 0177);
 848: }
 849: casenx(){
 850:     lgf++;
 851:     skip();
 852:     getname();
 853:     nx++;
 854:     nextfile();
 855:     nlflg++;
 856:     ip = 0;
 857:     ap = 0;
 858:     nchar = pendt = 0;
 859:     frame = stk;
 860:     nxf = frame + 1;
 861: }
 862: getname(){
 863:     register int i, j, k;
 864: 
 865:     lgf++;
 866:     for(k=0; k < (NS-1); k++){
 867:         if(((j=(i=getch()) & CMASK) <= ' ') ||
 868:             (j > 0176))break;
 869:         nextf[k] = j;
 870:     }
 871:     nextf[k] = 0;
 872:     ch = i;
 873:     lgf--;
 874:     return(nextf[0]);
 875: }
 876: caseso(){
 877:     register i;
 878:     register char *p, *q;
 879: 
 880:     lgf++;
 881:     nextf[0] = 0;
 882:     if(skip() || !getname() || ((i=open(nextf,0)) <0) || (ifi >= NSO)) {
 883:         prstr("can't open file ");
 884:         prstr(nextf);
 885:         prstr("\n");
 886:         done(02);
 887:     }
 888:     flushi();
 889:     ifl[ifi] = ifile;
 890:     ifile = i;
 891:     offl[ifi] = ioff;
 892:     ioff = 0;
 893:     ipl[ifi] = ip;
 894:     ip = 0;
 895:     nx++;
 896:     nflush++;
 897:     if(!ifl[ifi++]){
 898:         p = ibuf;
 899:         q = xbuf;
 900:         xbufp = ibufp;
 901:         xeibuf = eibuf;
 902:         while(p < eibuf)*q++ = *p++;
 903:     }
 904: }
 905: 
 906: casecf(){   /* copy file without change */
 907:     int fd, i, n;
 908:     char buf[OBUFSZ];
 909: 
 910:     flusho();
 911:     lgf++;
 912:     nextf[0] = 0;
 913:     if(skip() || !getname() || ((fd=open(nextf,0)) <0) || (ifi >= NSO)) {
 914:         prstr("can't open file ");
 915:         prstr(nextf);
 916:         prstr("\n");
 917:         done(02);
 918:     }
 919:     while ((n = read(fd, buf, OBUFSZ)) > 0)
 920:         for (i = 0; i < n; i++)
 921:             oput(buf[i]);
 922:     flusho();
 923:     close(fd);
 924: }
 925: getpn(a)
 926: char *a;
 927: {
 928:     register i, neg;
 929:     long atoi1();
 930: 
 931:     if((*a & 0177) == 0)return;
 932:     neg = 0;
 933:     ibufp = a;
 934:     eibuf = (char *) MAXPTR;
 935:     noscale++;
 936:     while((i = getch() & CMASK) != 0)switch(i){
 937:         case '+':
 938:         case ',':
 939:             continue;
 940:         case '-':
 941:             neg = MOT;
 942:             goto d2;
 943:         default:
 944:             ch = i;
 945:         d2:
 946:             i = atoi1();
 947:             if(nonumb)goto fini;
 948:             else{
 949:                 *pnp++ = i | neg;
 950:                 neg = 0;
 951:                 if(pnp >= &pnlist[NPN-2]){
 952:                     prstr("Too many page numbers\n");
 953:                     done3(-3);
 954:                 }
 955:             }
 956:         }
 957: fini:
 958:     if(neg)*pnp++ = -2;
 959:     *pnp = -1;
 960:     ch = noscale = print = 0;
 961:     pnp = pnlist;
 962:     if(*pnp != -1)chkpn();
 963: }
 964: setrpt(){
 965:     register i, j;
 966: 
 967:     copyf++;raw++;
 968:     i = getch0();
 969:     copyf--;raw--;
 970:     if((i < 0) ||
 971:        (((j = getch0()) & CMASK) == RPT))return;
 972:     rchar = j;
 973:     nchar = i & BMASK;
 974: }

Defined functions

acctg defined in line 333; used 1 times
casecf defined in line 906; used 2 times
casenx defined in line 849; used 2 times
caseso defined in line 876; used 2 times
catch defined in line 318; used 4 times
cnum defined in line 409; used 6 times
cvtime defined in line 396; used 1 times
fpecatch defined in line 324; used 3 times
getach defined in line 835; used 5 times
getpn defined in line 925; used 1 times
init1 defined in line 339; used 1 times
init2 defined in line 361; used 1 times
kcatch defined in line 328; used 2 times
main defined in line 150; never used
mesg defined in line 420; used 2 times
nextfile defined in line 762; used 2 times
popf defined in line 798; used 1 times
setrpt defined in line 964; used 1 times

Defined variables

acctf defined in line 147; used 4 times
ifilt defined in line 707; used 1 times
ioff defined in line 136; used 9 times
ipl defined in line 134; used 2 times
ms defined in line 145; never used
offl defined in line 135; used 2 times
sccsid defined in line 2; never used
ttyp defined in line 137; used 8 times

Defined struct's

contab defined in line 138; never used
Last modified: 1987-07-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 4454
Valid CSS Valid XHTML 1.0 Strict