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