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