1: #include "tdef.h" 2: #include <sgtty.h> 3: extern 4: #include "d.h" 5: extern 6: #include "v.h" 7: #include "s.h" 8: 9: /* 10: troff5.c 11: 12: misc processing requests 13: */ 14: 15: extern struct s *frame; 16: extern struct s *litlev; 17: extern filep ip; 18: extern filep offset; 19: 20: extern int ascii; 21: extern int nonumb; 22: extern int admod; 23: extern int ad; 24: extern int fi; 25: extern int cc; 26: extern int c2; 27: extern int ohc; 28: extern int tabc; 29: extern int dotc; 30: extern int pendnf; 31: extern int hyf; 32: extern int ce; 33: extern int po; 34: extern int po1; 35: extern int nc; 36: extern int in; 37: extern int un; 38: extern int un1; 39: extern int in1; 40: extern int ll; 41: extern int ll1; 42: extern int lt; 43: extern int lt1; 44: extern int nlist[NTRAP]; 45: extern int mlist[NTRAP]; 46: extern int lgf; 47: extern int pl; 48: extern int npn; 49: extern int npnflg; 50: extern int copyf; 51: extern char nextf[]; 52: extern int trap; 53: extern int lss; 54: extern int em; 55: extern int evlist[EVLSZ]; 56: extern int evi; 57: extern int ibf; 58: extern int ev; 59: extern int ch; 60: extern int nflush; 61: extern int tty; 62: extern struct sgttyb ttys; 63: extern int quiet; 64: extern int iflg; 65: extern int eschar; 66: extern int lit; 67: extern int ls; 68: extern int ls1; 69: extern int tabtab[]; 70: extern char trtab[]; 71: extern int ul; 72: extern int cu; 73: extern int sfont; 74: extern int font; 75: extern int fontlab[]; 76: extern int it; 77: extern int itmac; 78: extern int noscale; 79: extern int ic; 80: extern int icf; 81: extern int ics; 82: extern int *vlist; 83: extern int sv; 84: extern int esc; 85: extern int nn; 86: extern int nms; 87: extern int ndf; 88: extern int lnmod; 89: extern int ni; 90: extern int lnsize; 91: extern int nb; 92: extern int nlflg; 93: extern int apts, apts1, pts, pts1, font, font1; 94: extern int ulfont; 95: extern int ulbit; 96: extern int error; 97: extern int nmbits; 98: extern int chbits; 99: extern int tdelim; 100: extern int xxx; 101: int iflist[NIF]; 102: int ifx; 103: 104: casead(){ 105: register i; 106: 107: ad = 1; 108: /*leave admod alone*/ 109: if(skip())return; 110: switch(i = getch() & CMASK){ 111: case 'r': /*right adj, left ragged*/ 112: admod = 2; 113: break; 114: case 'l': /*left adj, right ragged*/ 115: admod = ad = 0; /*same as casena*/ 116: break; 117: case 'c': /*centered adj*/ 118: admod = 1; 119: break; 120: case 'b': case 'n': 121: admod = 0; 122: break; 123: case '0': case '2': case '4': 124: ad = 0; 125: case '1': case '3': case '5': 126: admod = (i - '0')/2; 127: } 128: } 129: casena(){ 130: ad = 0; 131: } 132: casefi(){ 133: tbreak(); 134: fi++; 135: pendnf = 0; 136: lnsize = LNSIZE; 137: } 138: casenf(){ 139: tbreak(); 140: fi = 0; 141: /* can't do while oline is only LNSIZE 142: lnsize = LNSIZE + WDSIZE; 143: */ 144: } 145: casers(){ 146: dip->nls = 0; 147: } 148: casens(){ 149: dip->nls++; 150: } 151: chget(c) 152: int c; 153: { 154: register i; 155: 156: if(skip() || 157: ((i = getch()) & MOT) || 158: ((i&CMASK) == ' ') || 159: ((i&CMASK) == '\n')){ 160: ch = i; 161: return(c); 162: }else return(i & BMASK); 163: } 164: casecc(){ 165: cc = chget('.'); 166: } 167: casec2(){ 168: c2 = chget('\''); 169: } 170: casehc(){ 171: ohc = chget(OHC); 172: } 173: casetc(){ 174: tabc = chget(0); 175: } 176: caselc(){ 177: dotc = chget(0); 178: } 179: casehy(){ 180: register i; 181: 182: hyf = 1; 183: if(skip())return; 184: noscale++; 185: i = atoi(); 186: noscale = 0; 187: if(nonumb)return; 188: hyf = max(i,0); 189: } 190: casenh(){ 191: hyf = 0; 192: } 193: max(aa,bb) 194: int aa,bb; 195: { 196: if(aa>bb)return(aa); 197: else return(bb); 198: } 199: casece(){ 200: register i; 201: 202: noscale++; 203: skip(); 204: i = max(atoi(),0); 205: if(nonumb)i = 1; 206: tbreak(); 207: ce = i; 208: noscale = 0; 209: } 210: casein(){ 211: register i; 212: 213: if(skip())i = in1; 214: else i = max(hnumb(&in),0); 215: tbreak(); 216: in1 = in; 217: in = i; 218: if(!nc){ 219: un = in; 220: setnel(); 221: } 222: } 223: casell(){ 224: register i; 225: 226: if(skip())i = ll1; 227: else i = max(hnumb(&ll),INCH/10); 228: ll1 = ll; 229: ll = i; 230: setnel(); 231: } 232: caselt(){ 233: register i; 234: 235: if(skip())i = lt1; 236: else i = max(hnumb(<),0); 237: lt1 = lt; 238: lt = i; 239: } 240: caseti(){ 241: register i; 242: 243: if(skip())return; 244: i = max(hnumb(&in),0); 245: tbreak(); 246: un1 = i; 247: setnel(); 248: } 249: casels(){ 250: register i; 251: 252: noscale++; 253: if(skip())i = ls1; 254: else i = max(inumb(&ls),1); 255: ls1 = ls; 256: ls = i; 257: noscale = 0; 258: } 259: casepo(){ 260: register i; 261: 262: if(skip())i = po1; 263: else i = max(hnumb(&po),0); 264: po1 = po; 265: po = i; 266: #ifndef NROFF 267: if(!ascii)esc += po - po1; 268: #endif 269: } 270: casepl(){ 271: register i; 272: 273: skip(); 274: if((i = vnumb(&pl)) == 0)pl = 11 * INCH; /*11in*/ 275: else pl = i; 276: if(v.nl > pl)v.nl = pl; 277: } 278: casewh(){ 279: register i, j, k; 280: 281: lgf++; 282: skip(); 283: i = vnumb((int *)0); 284: if(nonumb)return; 285: skip(); 286: j = getrq(); 287: if((k=findn(i)) != NTRAP){ 288: mlist[k] = j; 289: return; 290: } 291: for(k=0; k<NTRAP; k++)if(mlist[k] == 0)break; 292: if(k == NTRAP){ 293: prstrfl("Cannot plant trap.\n"); 294: return; 295: } 296: mlist[k] = j; 297: nlist[k] = i; 298: } 299: casech(){ 300: register i, j, k; 301: 302: lgf++; 303: skip(); 304: if(!(j=getrq()))return; 305: else for(k=0; k<NTRAP; k++)if(mlist[k] == j)break; 306: if(k == NTRAP)return; 307: skip(); 308: i = vnumb((int *)0); 309: if(nonumb)mlist[k] = 0; 310: nlist[k] = i; 311: } 312: findn(i) 313: int i; 314: { 315: register k; 316: 317: for(k=0; k<NTRAP; k++) 318: if((nlist[k] == i) && (mlist[k] != 0))break; 319: return(k); 320: } 321: casepn(){ 322: register i; 323: 324: skip(); 325: noscale++; 326: i = max(inumb(&v.pn),0); 327: noscale = 0; 328: if(!nonumb){ 329: npn = i; 330: npnflg++; 331: } 332: } 333: casebp(){ 334: register i; 335: register struct s *savframe; 336: 337: if(dip != d)return; 338: savframe = frame; 339: skip(); 340: if((i = inumb(&v.pn)) < 0)i = 0; 341: tbreak(); 342: if(!nonumb){ 343: npn = i; 344: npnflg++; 345: }else if(dip->nls)return; 346: eject(savframe); 347: } 348: casetm(x) int x;{ 349: register i; 350: char tmbuf[NTM]; 351: 352: lgf++; 353: copyf++; 354: if(skip() && x)prstrfl("User Abort."); 355: for(i=0; i<NTM-2;)if((tmbuf[i++]=getch()) == '\n')break; 356: if(i == NTM-2)tmbuf[i++] = '\n'; 357: tmbuf[i] = 0; 358: prstrfl(tmbuf); 359: copyf--; 360: } 361: casesp(a) 362: int a; 363: { 364: register i, j, savlss; 365: 366: tbreak(); 367: if(dip->nls || trap)return; 368: i = findt1(); 369: if(!a){ 370: skip(); 371: j = vnumb((int *)0); 372: if(nonumb)j = lss; 373: }else j = a; 374: if(j == 0)return; 375: if(i < j)j = i; 376: savlss = lss; 377: if(dip != d)i = dip->dnl; else i = v.nl; 378: if((i + j) < 0)j = -i; 379: lss = j; 380: newline(0); 381: lss = savlss; 382: } 383: casert(){ 384: register a, *p; 385: 386: skip(); 387: if(dip != d)p = &dip->dnl; else p = &v.nl; 388: a = vnumb(p); 389: if(nonumb)a = dip->mkline; 390: if((a < 0) || (a >= *p))return; 391: nb++; 392: casesp(a - *p); 393: } 394: caseem(){ 395: lgf++; 396: skip(); 397: em = getrq(); 398: } 399: casefl(){ 400: tbreak(); 401: flusho(); 402: } 403: caseev(){ 404: register nxev; 405: extern int block; 406: 407: if(skip()){ 408: e0: 409: if(evi == 0)return; 410: nxev = evlist[--evi]; 411: goto e1; 412: } 413: noscale++; 414: nxev = atoi(); 415: noscale = 0; 416: if(nonumb)goto e0; 417: flushi(); 418: if((nxev >= NEV) || (nxev < 0) || (evi >= EVLSZ)){ 419: prstrfl("Cannot do ev.\n"); 420: if(error)done2(040);else edone(040); 421: return; 422: } 423: evlist[evi++] = ev; 424: e1: 425: if(ev == nxev)return; 426: lseek(ibf, (long)(ev*EVS*sizeof(int)), 0); 427: write(ibf,(char *)&block, EVS*sizeof(int)); 428: lseek(ibf, (long)(nxev*EVS*sizeof(int)), 0); 429: read(ibf,(char *)&block, EVS*sizeof(int)); 430: ev = nxev; 431: } 432: caseel(){ 433: if(--ifx < 0){ 434: ifx = 0; 435: iflist[0] = 0; 436: } 437: caseif(2); 438: } 439: caseie(){ 440: if(ifx >= NIF){ 441: prstr("if-else overflow.\n"); 442: ifx = 0; 443: edone(040); 444: } 445: caseif(1); 446: ifx++; 447: } 448: caseif(x) 449: int x; 450: { 451: register i, notflag, true; 452: 453: if(x == 2){ 454: notflag = 0; 455: true = iflist[ifx]; 456: goto i1; 457: } 458: true = 0; 459: skip(); 460: if(((i = getch()) & CMASK) == '!'){ 461: notflag = 1; 462: }else{ 463: notflag = 0; 464: ch = i; 465: } 466: i = atoi(); 467: if(!nonumb){ 468: if(i > 0)true++; 469: goto i1; 470: } 471: switch((i = getch()) & CMASK){ 472: case 'e': 473: if(!(v.pn & 01))true++; 474: break; 475: case 'o': 476: if(v.pn & 01)true++; 477: break; 478: #ifdef NROFF 479: case 'n': 480: true++; 481: case 't': 482: #endif 483: #ifndef NROFF 484: case 't': 485: true++; 486: case 'n': 487: #endif 488: case ' ': 489: break; 490: default: 491: true = cmpstr(i); 492: } 493: i1: 494: true ^= notflag; 495: if(x == 1)iflist[ifx] = !true; 496: if(true){ 497: i2: 498: do{ 499: v.hp = 0; 500: } 501: while(((i = getch()) & CMASK) == ' '); 502: if((i & CMASK) == LEFT)goto i2; 503: ch = i; 504: nflush++; 505: }else{ 506: copyf++; 507: if(eat(LEFT) == LEFT){ 508: while(eatblk(RIGHT,LEFT) != RIGHT)nlflg = 0; 509: } 510: copyf--; 511: } 512: } 513: eatblk(right,left) 514: int right,left; 515: { 516: register i; 517: 518: e0: 519: while(((i = getch() & CMASK) != right) && 520: (i != left) && 521: (i != '\n')); 522: if(i == left){ 523: while((i=eatblk(right,left)) != right)nlflg = 0; 524: goto e0; 525: } 526: return(i); 527: } 528: cmpstr(delim) 529: int delim; 530: { 531: register i, j; 532: register filep p; 533: extern filep alloc(); 534: extern filep incoff(); 535: filep begin; 536: int cnt, k; 537: int savapts, savapts1, savfont, savfont1, 538: savpts, savpts1; 539: 540: if(delim & MOT)return(0); 541: delim &= CMASK; 542: if(dip != d)wbfl(); 543: if((offset = begin = alloc()) == (filep)0)return(0); 544: cnt = 0; 545: v.hp = 0; 546: savapts = apts; 547: savapts1 = apts1; 548: savfont = font; 549: savfont1 = font1; 550: savpts = pts; 551: savpts1 = pts1; 552: while(((j = (i=getch()) & CMASK) != delim) && (j != '\n')){ 553: wbf(i); 554: cnt++; 555: } 556: wbt(0); 557: k = !cnt; 558: if(nlflg)goto rtn; 559: p = begin; 560: apts = savapts; 561: apts1 = savapts1; 562: font = savfont; 563: font1 = savfont1; 564: pts = savpts; 565: pts1 = savpts1; 566: mchbits(); 567: v.hp = 0; 568: while(((j = (i=getch()) & CMASK) != delim) && (j != '\n')){ 569: if(rbf0(p) != i){ 570: eat(delim); 571: k = 0; 572: break; 573: } 574: p = incoff(p); 575: k = !(--cnt); 576: } 577: rtn: 578: apts = savapts; 579: apts1 = savapts1; 580: font = savfont; 581: font1 = savfont1; 582: pts = savpts; 583: pts1 = savpts1; 584: mchbits(); 585: offset = dip->op; 586: ffree(begin); 587: return(k); 588: } 589: caserd(){ 590: 591: lgf++; 592: skip(); 593: getname(); 594: if(!iflg){ 595: if(quiet){ 596: ttys.sg_flags &= ~ECHO; 597: stty(0, &ttys); 598: prstrfl(""); /*bell*/ 599: }else{ 600: if(nextf[0]){ 601: prstr(nextf); 602: prstr(":"); 603: }else{ 604: prstr(""); /*bell*/ 605: } 606: } 607: } 608: collect(); 609: tty++; 610: pushi((filep)-1); 611: } 612: rdtty(){ 613: char onechar; 614: 615: onechar = 0; 616: if(read(0, &onechar, 1) == 1){ 617: if(onechar == '\n')tty++; 618: else tty = 1; 619: if(tty != 3)return(onechar); 620: } 621: popi(); 622: tty = 0; 623: if(quiet){ 624: ttys.sg_flags |= ECHO; 625: stty(0, &ttys); 626: } 627: return(0); 628: } 629: caseec(){ 630: eschar = chget('\\'); 631: } 632: caseeo(){ 633: eschar = 0; 634: } 635: caseli(){ 636: 637: skip(); 638: lit = max(inumb((int *)0),1); 639: litlev = frame; 640: if((dip == d) && (v.nl == -1))newline(1); 641: } 642: caseta(){ 643: register i; 644: 645: tabtab[0] = nonumb = 0; 646: for(i=0; ((i < (NTAB-1)) && !nonumb); i++){ 647: if(skip())break; 648: tabtab[i] = max(hnumb(&tabtab[max(i-1,0)]),0) & TMASK; 649: if(!nonumb) switch(ch & CMASK){ 650: case 'C': 651: tabtab[i] |= CTAB; 652: break; 653: case 'R': 654: tabtab[i] |= RTAB; 655: break; 656: default: /*includes L*/ 657: break; 658: } 659: nonumb = ch = 0; 660: } 661: tabtab[i] = 0; 662: } 663: casene(){ 664: register i, j; 665: 666: skip(); 667: i = vnumb((int *)0); 668: if(nonumb)i = lss; 669: if(i > (j = findt1())){ 670: i = lss; 671: lss = j; 672: dip->nls = 0; 673: newline(0); 674: lss = i; 675: } 676: } 677: casetr(){ 678: register i, j; 679: 680: lgf++; 681: skip(); 682: while((i = getch() & CMASK) != '\n'){ 683: if((i & MOT) || ((j = getch()) & MOT))return; 684: if((j &= CMASK) == '\n')j = ' '; 685: trtab[i] = j; 686: } 687: } 688: casecu(){ 689: cu++; 690: caseul(); 691: } 692: caseul(){ 693: register i; 694: 695: noscale++; 696: if(skip())i = 1; 697: else i = atoi(); 698: if(ul && (i == 0)){ 699: font = sfont; 700: ul = cu = 0; 701: } 702: if(i){ 703: if(!ul){ 704: sfont = font; 705: font = ulfont; 706: } 707: ul = i; 708: } 709: noscale = 0; 710: mchbits(); 711: } 712: caseuf(){ 713: register i, j; 714: 715: if(skip() || !(i = getrq()) || (i == 'S') || 716: ((j = find(i,fontlab)) == -1)) 717: ulfont = 1; /*default position 2*/ 718: else ulfont = j; 719: #ifdef NROFF 720: if(ulfont == 0)ulfont = 1; 721: #endif 722: ulbit = ulfont<<9; 723: } 724: caseit(){ 725: register i; 726: 727: lgf++; 728: it = itmac = 0; 729: noscale++; 730: skip(); 731: i = atoi(); 732: skip(); 733: if(!nonumb && (itmac = getrq()))it = i; 734: noscale = 0; 735: } 736: casemc(){ 737: register i; 738: 739: if(icf > 1)ic = 0; 740: icf = 0; 741: if(skip())return; 742: ic = getch(); 743: icf = 1; 744: skip(); 745: i = max(hnumb((int *)0),0); 746: if(!nonumb)ics = i; 747: } 748: casemk(){ 749: register i, j; 750: 751: if(dip != d)j = dip->dnl; else j = v.nl; 752: if(skip()){ 753: dip->mkline = j; 754: return; 755: } 756: if((i = getrq()) == 0)return; 757: vlist[findr(i)] = j; 758: } 759: casesv(){ 760: register i; 761: 762: skip(); 763: if((i = vnumb((int *)0)) < 0)return; 764: if(nonumb)i = 1; 765: sv += i; 766: caseos(); 767: } 768: caseos(){ 769: register savlss; 770: 771: if(sv <= findt1()){ 772: savlss = lss; 773: lss = sv; 774: newline(0); 775: lss = savlss; 776: sv = 0; 777: } 778: } 779: casenm(){ 780: register i; 781: 782: lnmod = nn = 0; 783: if(skip())return; 784: lnmod++; 785: noscale++; 786: i = inumb(&v.ln); 787: if(!nonumb)v.ln = max(i,0); 788: getnm(&ndf,1); 789: getnm(&nms,0); 790: getnm(&ni,0); 791: noscale = 0; 792: nmbits = chbits; 793: } 794: getnm(p,min) 795: int *p, min; 796: { 797: register i; 798: 799: eat(' '); 800: if(skip())return; 801: i = atoi(); 802: if(nonumb)return; 803: *p = max(i,min); 804: } 805: casenn(){ 806: noscale++; 807: skip(); 808: nn = max(atoi(),1); 809: noscale = 0; 810: } 811: caseab(){ 812: dummy(); 813: casetm(1); 814: done2(0); 815: }