1: #include "sdef.h"
   2: #include "d.h"
   3: #include "v.h"
   4: #include "tw.h"
   5: #include "s.h"
   6: 
   7: /*
   8: sroff7.c
   9: 
  10: text
  11: */
  12: 
  13: extern struct s *frame, *stk;
  14: extern struct s *ejl;
  15: 
  16: extern int pl;
  17: extern int trap;
  18: extern int flss;
  19: extern int npnflg;
  20: extern int nflush;
  21: extern int ejf;
  22: extern int donef;
  23: extern int nc;
  24: extern int wch;
  25: extern int npn;
  26: extern int ndone;
  27: extern int lss;
  28: extern int nlss;
  29: extern int pto;
  30: extern int pfrom;
  31: extern int print;
  32: extern int nlist[NTRAP];
  33: extern int mlist[NTRAP];
  34: extern int *pnp;
  35: extern int nb;
  36: extern int ic;
  37: extern int icf;
  38: extern int ics;
  39: extern int ne;
  40: extern int ll;
  41: extern int un;
  42: extern int un1;
  43: extern int in;
  44: extern int ls;
  45: extern int spread;
  46: extern int totout;
  47: extern int nwd;
  48: extern int *pendw;
  49: extern int *linep;
  50: extern int line[];
  51: extern int lastl;
  52: extern int ch;
  53: extern int ce;
  54: extern int fi;
  55: extern int nlflg;
  56: extern int pendt;
  57: extern int space;
  58: extern int sps;
  59: extern int adsp;
  60: extern int pendnf;
  61: extern int over;
  62: extern int adrem;
  63: extern int nel;
  64: extern int ad;
  65: extern int ohc;
  66: extern int hyoff;
  67: extern int nhyp;
  68: extern int spflg;
  69: extern int word[];
  70: extern int *wordp;
  71: extern int wne;
  72: extern int chbits;
  73: extern int cwidth;
  74: extern int widthp;
  75: extern int hyf;
  76: extern int xbitf;
  77: extern int vflag;
  78: extern int ul;
  79: extern int cu;
  80: extern int font;
  81: extern int sfont;
  82: extern int it;
  83: extern int itmac;
  84: extern int *hyptr[NHYP];
  85: extern int **hyp;
  86: extern int *wdstart, *wdend;
  87: extern int lnmod;
  88: extern int admod;
  89: extern int nn;
  90: extern int nms;
  91: extern int ndf;
  92: extern int ni;
  93: extern int nform;
  94: extern int lnsize;
  95: extern int po;
  96: extern int *vlist;
  97: extern int nrbits;
  98: extern int nmbits;
  99: extern char trtab[];
 100: extern int fontab[];
 101: extern int xxx;
 102: int brflg;
 103: 
 104: tbreak(){
 105:     register *i, j, pad;
 106:     int res;
 107: 
 108:     trap = 0;
 109:     if(nb)return;
 110:     if((dip == d) && (v.nl == -1)){
 111:         newline(1);
 112:         return;
 113:     }
 114:     if(!nc){
 115:         setnel();
 116:         if(!wch)return;
 117:         if(pendw)getword(1);
 118:         movword();
 119:     }else if(pendw && !brflg){
 120:         getword(1);
 121:         movword();
 122:     }
 123:     *linep = dip->nls = 0;
 124: #ifndef PGOFF
 125:     if(dip == d)horiz(po);
 126: #endif
 127:     if(lnmod)donum();
 128:     lastl = ne;
 129:     if(brflg != 1){
 130:         totout = 0;
 131:     }else if(ad){
 132:         if((lastl = (ll - un)) < ne)lastl = ne;
 133:     }
 134:     if(admod && ad && (brflg != 2)){
 135:         lastl = ne;
 136: #ifndef ADJ
 137:         adsp = adrem = 0;
 138:         if(admod == 1)un += nel/2;
 139:         else if(admod ==2)un += nel;
 140: #endif
 141:     }
 142:     totout++;
 143:     if((lastl+un) > dip->maxl)dip->maxl = (lastl+un);
 144:     horiz(un);
 145: #ifdef ADJ
 146:     for (i=line;nc>0; nc--)
 147:         pchar(*i++);
 148: #else
 149:     for(i = line;nc > 0;){
 150:         if(((j = *i++) & CMASK) == ' '){
 151:             pad = 0;
 152:             do{
 153:                 pad += width(j);
 154:                 nc--;
 155:               }while(((j = *i++) & CMASK) == ' ');
 156:             i--;
 157:             pad += adsp;
 158:             --nwd;
 159:             if(adrem){
 160:                 if(adrem < 0){
 161:                     pad--;
 162:                     adrem++;
 163:                 }else{
 164:                     pad++;
 165:                     adrem--;
 166:                 }
 167:             }
 168:             horiz(pad);
 169:         }else{
 170:             pchar(j);
 171:             nc--;
 172:         }
 173:     }
 174: #endif
 175:     if(ic){
 176:         if((j = ll - un - lastl + ics) > 0)horiz(j);
 177:         pchar(ic);
 178:     }
 179:     if(icf)icf++;
 180:         else ic = 0;
 181:     ne = nwd = 0;
 182: #ifdef ADJ
 183:     un = 0;
 184: #else
 185:     un = in;
 186: #endif
 187:     setnel();
 188:     newline(0);
 189:     if(dip != d){if(dip->dnl > dip->hnl)dip->hnl = dip->dnl;}
 190:     else{if(v.nl > dip->hnl)dip->hnl = v.nl;}
 191:     for(j=ls-1; (j >0) && !trap; j--)newline(0);
 192:     spread = 0;
 193:     brflg = 0;
 194: }
 195: donum(){
 196:     register i, nw;
 197:     extern pchar();
 198: 
 199:     nrbits = nmbits;
 200:     nw = width('1' | nrbits);
 201:     if(nn){
 202:         nn--;
 203:         goto d1;
 204:     }
 205:     if(v.ln%ndf){
 206:         v.ln++;
 207:     d1:
 208:         un += nw*(3+nms+ni);
 209:         return;
 210:     }
 211:     i = 0;
 212:     if(v.ln<100)i++;
 213:     if(v.ln<10)i++;
 214:     horiz(nw*(ni+i));
 215:     nform = 0;
 216:     fnumb(v.ln,pchar);
 217:     un += nw*nms;
 218:     v.ln++;
 219: }
 220: text(){
 221:     register i;
 222:     static int spcnt;
 223: 
 224:     nflush++;
 225:     if((dip == d) && (v.nl == -1)){newline(1); return;}
 226:     setnel();
 227:     if(ce || !fi){
 228:         nofill();
 229:         return;
 230:     }
 231:     if(pendw)goto t4;
 232:     if(pendt)if(spcnt)goto t2; else goto t3;
 233:     pendt++;
 234:     if(spcnt)goto t2;
 235:     while(((i = gettch()) & CMASK) == ' ')spcnt++;
 236:     if(nlflg){
 237:     t1:
 238:         nflush = pendt = ch = spcnt = 0;
 239:         callsp();
 240:         return;
 241:     }
 242:     ch = i;
 243:     if(spcnt){
 244:     t2:
 245:         tbreak();
 246:         if(nc || wch)goto rtn;
 247:         un += spcnt*sps;
 248:         spcnt = 0;
 249:         setnel();
 250:         if(trap)goto rtn;
 251:         if(nlflg)goto t1;
 252:     }
 253: t3:
 254:     if(spread)goto t5;
 255:     if(pendw || !wch)
 256:     t4:
 257:         if(getword(0))goto t6;
 258:     if(!movword())goto t3;
 259: t5:
 260:     if(nlflg)pendt = 0;
 261:     adsp = adrem = 0;
 262:     if(ad){
 263: /* jfr */   if (nwd==1) adsp=nel; else adsp=nel/(nwd-1);
 264:         adrem = nel - adsp*(nwd-1);
 265:     }
 266:     brflg = 1;
 267:     tbreak();
 268:     spread = 0;
 269:     if(!trap)goto t3;
 270:     if(!nlflg)goto rtn;
 271: t6:
 272:     pendt = 0;
 273:     ckul();
 274: rtn:
 275:     nflush = 0;
 276: }
 277: nofill(){
 278:     register i, j;
 279: 
 280:     if(!pendnf){
 281:         over = 0;
 282:         tbreak();
 283:         if(trap)goto rtn;
 284:         if(nlflg){
 285:             ch = nflush = 0;
 286:             callsp();
 287:             return;
 288:         }
 289:         adsp = adrem = 0;
 290:         nwd = 10000;
 291:     }
 292:     while((j = ((i = gettch()) & CMASK)) != '\n'){
 293:         if(j == ohc)continue;
 294:         if(j == CONT){
 295:             pendnf++;
 296:             nflush = 0;
 297:             flushi();
 298:             ckul();
 299:             return;
 300:         }
 301:         storeline(i,-1);
 302:     }
 303:     if(ce){
 304:         ce--;
 305:         if((i = nel/2) > 0)un += i;
 306:     }
 307:     if(!nc)storeline(FILLER,0);
 308:     brflg = 2;
 309:     tbreak();
 310:     ckul();
 311: rtn:
 312:     pendnf = nflush = 0;
 313: }
 314: callsp(){
 315:     register i;
 316: 
 317:     if(flss)i = flss; else i = lss;
 318:     flss = 0;
 319:     casesp(i);
 320: }
 321: ckul(){
 322:     if(ul && (--ul == 0)){
 323:             cu = 0;
 324:             font = sfont;
 325:             mchbits();
 326:     }
 327:     if(it && (--it == 0) && itmac)control(itmac,0);
 328: }
 329: storeline(c,w){
 330:     register i;
 331: 
 332:     if((c & CMASK) == JREG){
 333:         if((i=findr(c>>BYTE)) != -1)vlist[i] = ne;
 334:         return;
 335:     }
 336:     if(linep >= (line + lnsize - 1)){
 337:         if(!over){
 338:             prstrfl("Line overflow.\n");
 339:             over++;
 340:         c = 052;    /* star */
 341:         w = -1;
 342:         goto s1;
 343:         }
 344:         return;
 345:     }
 346: s1:
 347:     if(w == -1)w = width(c);
 348:     ne += w;
 349:     nel -= w;
 350:     *linep++ = c;
 351:     nc++;
 352: }
 353: newline(a)
 354: int a;
 355: {
 356:     register i, j;
 357:     int opn;
 358: 
 359:     if(a)goto nl1;
 360:     if(dip != d){
 361:         j = lss;
 362:         pchar1(FLSS);
 363:         if(flss)lss = flss;
 364:         i = lss + dip->blss;
 365:         dip->dnl += i;
 366:         pchar1(i);
 367: #ifdef ADJ
 368:         if (ad && (brflg == 1))
 369:             pchar1('\n'|EBIT);  /* force print */
 370:         else
 371: #endif
 372:         pchar1('\n');
 373:         lss = j;
 374:         dip->blss = flss = 0;
 375:         if(dip->alss){
 376:             pchar1(FLSS);
 377:             pchar1(dip->alss);
 378:             pchar1('\n');
 379:             dip->dnl += dip->alss;
 380:             dip->alss = 0;
 381:         }
 382:         if(dip->ditrap && !dip->ditf &&
 383:             (dip->dnl >= dip->ditrap) && dip->dimac)
 384:             if(control(dip->dimac,0)){trap++; dip->ditf++;}
 385:         return;
 386:     }
 387:     j = lss;
 388:     if(flss)lss = flss;
 389:     nlss = dip->alss + dip->blss + lss;
 390:     v.nl += nlss;
 391: #ifdef ADJ
 392:     if (ad && (brflg == 1))
 393:         pchar1('\n'|EBIT);  /* force print */
 394:     else
 395: #endif
 396:     pchar1('\n');
 397:     flss = 0;
 398:     lss = j;
 399:     if(v.nl < pl)goto nl2;
 400: nl1:
 401:     ejf = dip->hnl = v.nl = 0;
 402:     ejl = frame;
 403:     if(donef){
 404:         if((!nc && !wch) || ndone)done1(0);
 405:         ndone++;
 406:         donef = 0;
 407:         if(frame == stk)nflush++;
 408:     }
 409:     opn = v.pn;
 410:     v.pn++;
 411:     if(npnflg){
 412:         v.pn = npn;
 413:         npn = npnflg = 0;
 414:     }
 415: nlpn:
 416:     if(v.pn == pfrom){
 417:         print++;
 418:         pfrom = -1;
 419:     }else if(opn == pto){
 420:         print = 0;
 421:         opn = -1;
 422:         chkpn();
 423:         goto nlpn;
 424:         }
 425: nl2:
 426:     trap = 0;
 427:     if(v.nl == 0){
 428:         if((j = findn(0)) != NTRAP)
 429:             trap = control(mlist[j],0);
 430:     } else if((i = findt(v.nl-nlss)) <= nlss){
 431:         if((j = findn1(v.nl-nlss+i)) == NTRAP){
 432:             prstrfl("Trap botch.\n");
 433:             done2(-5);
 434:         }
 435:         trap = control(mlist[j],0);
 436:     }
 437: }
 438: findn1(a)
 439: int a;
 440: {
 441:     register i, j;
 442: 
 443:     for(i=0; i<NTRAP; i++){
 444:         if(mlist[i]){
 445:             if((j = nlist[i]) < 0)j += pl;
 446:             if(j == a)break;
 447:         }
 448:     }
 449:     return(i);
 450: }
 451: chkpn(){
 452:     pto = *(pnp++);
 453:     pfrom = pto & ~MOT;
 454:     if(pto == -1){
 455:         flusho();
 456:         done1(0);
 457:     }
 458:     if(pto & MOT){
 459:         pto &= ~MOT;
 460:         print++;
 461:         pfrom = 0;
 462:     }
 463: }
 464: findt(a)
 465: int a;
 466: {
 467:     register i, j, k;
 468: 
 469:     k = 32767;
 470:     if(dip != d){
 471:         if(dip->dimac && ((i = dip->ditrap -a) > 0))k = i;
 472:         return(k);
 473:     }
 474:     for(i=0; i<NTRAP; i++){
 475:         if(mlist[i]){
 476:             if((j = nlist[i]) < 0)j += pl;
 477:             if((j -= a)  <=  0)continue;
 478:             if(j < k)k = j;
 479:         }
 480:     }
 481:     i = pl - a;
 482:     if(k > i)k = i;
 483:     return(k);
 484: }
 485: findt1(){
 486:     register i;
 487: 
 488:     if(dip != d)i = dip->dnl;
 489:         else i = v.nl;
 490:     return(findt(i));
 491: }
 492: eject(a)
 493: struct s *a;
 494: {
 495:     register savlss;
 496: 
 497:     if(dip != d)return;
 498:     ejf++;
 499:     if(a)ejl = a;
 500:         else ejl = frame;
 501:     if(trap)return;
 502: e1:
 503:     savlss = lss;
 504:     lss = findt(v.nl);
 505:     newline(0);
 506:     lss = savlss;
 507:     if(v.nl && !trap)goto e1;
 508: }
 509: movword(){
 510:     register i, w, *wp;
 511:     int savwch, hys;
 512: 
 513:     over = 0;
 514:     wp = wordp;
 515:     if(!nwd){
 516:         while(((i = *wp++) & CMASK) == ' '){
 517:             wch--;
 518:             wne -= width(i);
 519:         }
 520:         wp--;
 521:     }
 522:     if((wne > nel) &&
 523:        !hyoff && hyf &&
 524:        (!nwd || (nel > 3*sps)) &&
 525:        (!(hyf & 02) || (findt1() > lss))
 526:       )hyphen(wp);
 527:     savwch = wch;
 528:     hyp = hyptr;
 529:     nhyp = 0;
 530:     while(*hyp && (*hyp <= wp))hyp++;
 531:     while(wch){
 532:         if((hyoff != 1) && (*hyp == wp)){
 533:             hyp++;
 534:             if(!wdstart ||
 535:                ((wp > (wdstart+1)) &&
 536:                 (wp < wdend) &&
 537:                 (!(hyf & 04) || (wp < (wdend-1))) &&
 538:                 (!(hyf & 010) || (wp > (wdstart+2)))
 539:                )
 540:               ){
 541:                 nhyp++;
 542:                 storeline(IMP,0);
 543:             }
 544:         }
 545:         i = *wp++;
 546:         w = width(i);
 547:         wne -= w;
 548:         wch--;
 549:         storeline(i,w);
 550:     }
 551:     if(nel >= 0){
 552:         nwd++;
 553:         return(0);
 554:     }
 555:     xbitf = 1;
 556:     hys = width(C_HY);
 557: m1:
 558:     if(!nhyp){
 559:         if(!nwd)goto m3;
 560:         if(wch == savwch)goto m4;
 561:     }
 562:     if(*--linep != IMP)goto m5;
 563:     if(!(--nhyp))
 564:         if(!nwd)goto m2;
 565:     if(nel < hys){
 566:         nc--;
 567:         goto m1;
 568:     }
 569: m2:
 570:     if(((i = *(linep-1) & CMASK) != '-') &&
 571:        (i != C_EM)
 572:       ){
 573:     *linep = (*(linep-1) & ~CMASK) | C_HY;
 574:     w = width(*linep);
 575:     nel -= w;
 576:     ne += w;
 577:     linep++;
 578: /*
 579: 	hsend();
 580: */
 581:     }
 582: m3:
 583:     nwd++;
 584: m4:
 585:     wordp = wp;
 586:     return(1);
 587: m5:
 588:     nc--;
 589:     w = width(*linep);
 590:     ne -= w;
 591:     nel += w;
 592:     wne += w;
 593:     wch++;
 594:     wp--;
 595:     goto m1;
 596: }
 597: horiz(i)
 598: int i;
 599: {
 600:     vflag = 0;
 601:     if(i)pchar(makem(i));
 602: }
 603: setnel(){
 604:     if(!nc){
 605:         linep = line;
 606: #ifndef ADJ
 607:         if(un1 >= 0){
 608:             un = un1;
 609:             un1 = -1;
 610:         }
 611:         nel = ll - un;
 612: #else
 613:         nel = ll - un - in;
 614: #endif
 615:         ne = adsp = adrem = 0;
 616:     }
 617: }
 618: getword(x)
 619: int x;
 620: {
 621:     register i, j, swp;
 622:     int noword;
 623: 
 624:     noword = 0;
 625:     if(x)if(pendw){
 626:         *pendw = 0;
 627:         goto rtn;
 628:     }
 629:     if(wordp = pendw)goto g1;
 630:     hyp = hyptr;
 631:     wordp = word;
 632:     over = wne = wch = 0;
 633:     hyoff = 0;
 634:     while(1){
 635:         j = (i = gettch()) & CMASK;
 636:         if(j == '\n'){
 637:             wne = wch = 0;
 638:             noword = 1;
 639:             goto rtn;
 640:         }
 641:         if(j == ohc){
 642:             hyoff = 1;
 643:             continue;
 644:         }
 645:         if(j == ' '){
 646:             storeword(i,cwidth);
 647:             continue;
 648:         }
 649:         break;
 650:     }
 651:     swp = widthp;
 652:     storeword(space, -1);
 653:     if(spflg){
 654:         storeword(space, -1);
 655:         spflg = 0;
 656:     }
 657:     widthp = swp;
 658: g0:
 659:     if(j == CONT){
 660:         pendw = wordp;
 661:         nflush = 0;
 662:         flushi();
 663:         return(1);
 664:     }
 665:     if(hyoff != 1){
 666:         if(j == ohc){
 667:             hyoff = 2;
 668:             *hyp++ = wordp;
 669:             if(hyp > (hyptr+NHYP-1))hyp = hyptr+NHYP-1;
 670:             goto g1;
 671:         }
 672:         if((j == '-') ||
 673:            (j == C_EM)
 674:           )if(wordp > word+1){
 675:             hyoff = 2;
 676:             *hyp++ = wordp + 1;
 677:             if(hyp > (hyptr+NHYP-1))hyp = hyptr+NHYP-1;
 678:         }
 679:     }
 680:     storeword(i,cwidth);
 681: g1:
 682:     j = (i = gettch()) & CMASK;
 683:     if(j != ' '){
 684:         if(j != '\n')goto g0;
 685:         j = *(wordp-1) & CMASK;
 686:         if((j == '.') ||
 687:            (j == '!') ||
 688:            (j == '?'))spflg++;
 689:     }
 690:     *wordp = 0;
 691: rtn:
 692:     wdstart = 0;
 693:     wordp = word;
 694:     pendw = 0;
 695:     *hyp++ = 0;
 696:     setnel();
 697:     return(noword);
 698: }
 699: storeword(c,w)
 700: int c, w;
 701: {
 702: 
 703:     if(wordp >= &word[WDSIZE - 1]){
 704:         if(!over){
 705:             prstrfl("Word overflow.\n");
 706:             over++;
 707:             c = 052;    /* star */
 708:             w = -1;
 709:         goto s1;
 710:         }
 711:         return;
 712:     }
 713: s1:
 714:     if(w == -1)w = width(c);
 715:     wne += w;
 716:     *wordp++ = c;
 717:     wch++;
 718: }
 719: extern char trtab[];
 720: gettch(){
 721:     register int i, j;
 722: 
 723:     if(!((i = getch()) & MOT) && (chbits & ULMODE)){
 724:         j = i&CMASK;
 725:         if(!cu && (j>=32) && (j<MAXCHAR) && !(fontab[j-32] & ULMODE))
 726:             i &= ~ULMODE;
 727:     }
 728:     return(i);
 729: }

Defined functions

callsp defined in line 314; used 2 times
chkpn defined in line 451; used 2 times
ckul defined in line 321; used 3 times
donum defined in line 195; used 1 times
eject defined in line 492; used 4 times
findn1 defined in line 438; used 1 times
findt defined in line 464; used 3 times
findt1 defined in line 485; used 5 times
gettch defined in line 720; used 4 times
getword defined in line 618; used 4 times
horiz defined in line 597; used 8 times
movword defined in line 509; used 3 times
newline defined in line 353; used 10 times
nofill defined in line 277; used 1 times
setnel defined in line 603; used 8 times
storeline defined in line 329; used 4 times
storeword defined in line 699; used 4 times
tbreak defined in line 104; used 15 times
text defined in line 220; used 1 times

Defined variables

brflg defined in line 102; used 8 times
Last modified: 1982-03-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2157
Valid CSS Valid XHTML 1.0 Strict