148302Sbostic /*-
248302Sbostic * Copyright (c) 1991 The Regents of the University of California.
348302Sbostic * All rights reserved.
448302Sbostic *
548302Sbostic * %sccs.include.proprietary.c%
648302Sbostic */
748302Sbostic
87071Srrh #ifndef lint
9*48929Sbostic static char sccsid[] = "@(#)n7.c 4.6 (Berkeley) 05/02/91";
1048302Sbostic #endif /* not lint */
117071Srrh
127071Srrh #include "tdef.h"
137071Srrh extern
147071Srrh #include "d.h"
157071Srrh extern
167071Srrh #include "v.h"
177071Srrh #ifdef NROFF
187071Srrh extern
197071Srrh #include "tw.h"
207071Srrh #endif
217071Srrh #include "sdef.h"
227071Srrh #ifdef NROFF
237071Srrh #define GETCH gettch
247071Srrh #endif
257071Srrh #ifndef NROFF
267071Srrh #define GETCH getch
277071Srrh #endif
287071Srrh
297071Srrh /*
307071Srrh troff7.c
317071Srrh
327071Srrh text
337071Srrh */
347071Srrh
357071Srrh extern struct s *frame, *stk;
367071Srrh extern struct s *ejl;
377071Srrh
387071Srrh extern int pl;
397071Srrh extern int trap;
407071Srrh extern int flss;
417071Srrh extern int npnflg;
427071Srrh extern int npn;
437071Srrh extern int stop;
447071Srrh extern int nflush;
457071Srrh extern int ejf;
467071Srrh extern int ascii;
477071Srrh extern int donef;
487071Srrh extern int nc;
497071Srrh extern int wch;
507071Srrh extern int dpn;
517071Srrh extern int ndone;
527071Srrh extern int lss;
537071Srrh extern int pto;
547071Srrh extern int pfrom;
557071Srrh extern int print;
56*48929Sbostic extern int nlistx[NTRAP];
577071Srrh extern int mlist[NTRAP];
587071Srrh extern int *pnp;
597071Srrh extern int nb;
607071Srrh extern int ic;
617071Srrh extern int icf;
627071Srrh extern int ics;
637071Srrh extern int ne;
647071Srrh extern int ll;
657071Srrh extern int un;
667071Srrh extern int un1;
677071Srrh extern int in;
687071Srrh extern int ls;
697071Srrh extern int spread;
707071Srrh extern int totout;
717071Srrh extern int nwd;
727071Srrh extern int *pendw;
737071Srrh extern int *linep;
747071Srrh extern int line[];
757071Srrh extern int lastl;
767071Srrh extern int ch;
777071Srrh extern int ce;
787071Srrh extern int fi;
797071Srrh extern int nlflg;
807071Srrh extern int pendt;
817071Srrh extern int sps;
827071Srrh extern int adsp;
837071Srrh extern int pendnf;
847071Srrh extern int over;
857071Srrh extern int adrem;
867071Srrh extern int nel;
877071Srrh extern int ad;
887071Srrh extern int ohc;
897071Srrh extern int hyoff;
907071Srrh extern int nhyp;
917071Srrh extern int spflg;
927071Srrh extern int word[];
937071Srrh extern int *wordp;
947071Srrh extern int wne;
957071Srrh extern int chbits;
967071Srrh extern int cwidth;
977071Srrh extern int widthp;
987071Srrh extern int hyf;
997071Srrh extern int xbitf;
1007071Srrh extern int vflag;
1017071Srrh extern int ul;
1027071Srrh extern int cu;
1037071Srrh extern int font;
1047071Srrh extern int sfont;
1057071Srrh extern int it;
1067071Srrh extern int itmac;
1077071Srrh extern int *hyptr[NHYP];
1087071Srrh extern int **hyp;
1097071Srrh extern int *wdstart, *wdend;
1107071Srrh extern int lnmod;
1117071Srrh extern int admod;
1127071Srrh extern int nn;
1137071Srrh extern int nms;
1147071Srrh extern int ndf;
1157071Srrh extern int ni;
1167071Srrh extern int nform;
1177071Srrh extern int lnsize;
1187071Srrh extern int po;
1197071Srrh extern int ulbit;
1207071Srrh extern int *vlist;
1217071Srrh extern int nrbits;
1227071Srrh extern int nmbits;
1237071Srrh extern char trtab[];
1247071Srrh extern int xxx;
1257071Srrh int brflg;
1267071Srrh
tbreak()1277071Srrh tbreak(){
1287071Srrh register *i, j, pad;
1297071Srrh int res;
1307071Srrh
1317071Srrh trap = 0;
1327071Srrh if(nb)return;
1337071Srrh if((dip == d) && (v.nl == -1)){
1347071Srrh newline(1);
1357071Srrh return;
1367071Srrh }
1377071Srrh if(!nc){
1387071Srrh setnel();
1397071Srrh if(!wch)return;
1407071Srrh if(pendw)getword(1);
1417071Srrh movword();
1427071Srrh }else if(pendw && !brflg){
1437071Srrh getword(1);
1447071Srrh movword();
1457071Srrh }
1467071Srrh *linep = dip->nls = 0;
1477071Srrh #ifdef NROFF
1487071Srrh if(dip == d)horiz(po);
1497071Srrh #endif
1507071Srrh if(lnmod)donum();
1517071Srrh lastl = ne;
1527071Srrh if(brflg != 1){
1537071Srrh totout = 0;
1547071Srrh }else if(ad){
1557071Srrh if((lastl = (ll - un)) < ne)lastl = ne;
1567071Srrh }
1577071Srrh if(admod && ad && (brflg != 2)){
1587071Srrh lastl = ne;
1597071Srrh adsp = adrem = 0;
1607071Srrh #ifdef NROFF
1617071Srrh if(admod == 1)un += quant(nel/2,t.Adj);
1627071Srrh #endif
1637071Srrh #ifndef NROFF
1647071Srrh if(admod == 1)un += nel/2;
1657071Srrh #endif
1667071Srrh else if(admod ==2)un += nel;
1677071Srrh }
1687071Srrh totout++;
1697071Srrh brflg = 0;
1707071Srrh if((lastl+un) > dip->maxl)dip->maxl = (lastl+un);
1717071Srrh horiz(un);
1727071Srrh #ifdef NROFF
1737071Srrh if(adrem%t.Adj)res = t.Hor; else res = t.Adj;
1747071Srrh #endif
1757071Srrh for(i = line;nc > 0;){
1767071Srrh if(((j = *i++) & CMASK) == ' '){
1777071Srrh pad = 0;
1787071Srrh do{
1797071Srrh pad += width(j);
1807071Srrh nc--;
1817071Srrh }while(((j = *i++) & CMASK) == ' ');
1827071Srrh i--;
1837071Srrh pad += adsp;
1847071Srrh --nwd;
1857071Srrh if(adrem){
1867071Srrh if(adrem < 0){
1877071Srrh #ifdef NROFF
1887071Srrh pad -= res;
1897071Srrh adrem += res;
1907071Srrh }else if((totout&01) ||
1917071Srrh ((adrem/res)>=(nwd))){
1927071Srrh pad += res;
1937071Srrh adrem -= res;
1947071Srrh #endif
1957071Srrh #ifndef NROFF
1967071Srrh pad--;
1977071Srrh adrem++;
1987071Srrh }else{
1997071Srrh pad++;
2007071Srrh adrem--;
2017071Srrh #endif
2027071Srrh }
2037071Srrh }
2047071Srrh horiz(pad);
2057071Srrh }else{
2067071Srrh pchar(j);
2077071Srrh nc--;
2087071Srrh }
2097071Srrh }
2107071Srrh if(ic){
2117071Srrh if((j = ll - un - lastl + ics) > 0)horiz(j);
2127071Srrh pchar(ic);
2137071Srrh }
2147071Srrh if(icf)icf++;
2157071Srrh else ic = 0;
2167071Srrh ne = nwd = 0;
2177071Srrh un = in;
2187071Srrh setnel();
2197071Srrh newline(0);
2207071Srrh if(dip != d){if(dip->dnl > dip->hnl)dip->hnl = dip->dnl;}
2217071Srrh else{if(v.nl > dip->hnl)dip->hnl = v.nl;}
2227071Srrh for(j=ls-1; (j >0) && !trap; j--)newline(0);
2237071Srrh spread = 0;
2247071Srrh }
donum()2257071Srrh donum(){
2267071Srrh register i, nw;
2277071Srrh extern pchar();
2287071Srrh
2297071Srrh nrbits = nmbits;
2307071Srrh nw = width('1' | nrbits);
2317071Srrh if(nn){
2327071Srrh nn--;
2337071Srrh goto d1;
2347071Srrh }
2357071Srrh if(v.ln%ndf){
2367071Srrh v.ln++;
2377071Srrh d1:
2387071Srrh un += nw*(3+nms+ni);
2397071Srrh return;
2407071Srrh }
2417071Srrh i = 0;
2427071Srrh if(v.ln<100)i++;
2437071Srrh if(v.ln<10)i++;
2447071Srrh horiz(nw*(ni+i));
2457071Srrh nform = 0;
2467071Srrh fnumb(v.ln,pchar);
2477071Srrh un += nw*nms;
2487071Srrh v.ln++;
2497071Srrh }
text()2507071Srrh text(){
2517071Srrh register i;
2527071Srrh static int spcnt;
2537071Srrh
2547071Srrh nflush++;
2557071Srrh if((dip == d) && (v.nl == -1)){newline(1); return;}
2567071Srrh setnel();
2577071Srrh if(ce || !fi){
2587071Srrh nofill();
2597071Srrh return;
2607071Srrh }
2617071Srrh if(pendw)goto t4;
2627071Srrh if(pendt)if(spcnt)goto t2; else goto t3;
2637071Srrh pendt++;
2647071Srrh if(spcnt)goto t2;
2657071Srrh while(((i = GETCH()) & CMASK) == ' ')spcnt++;
2667071Srrh if(nlflg){
2677071Srrh t1:
2687071Srrh nflush = pendt = ch = spcnt = 0;
2697071Srrh callsp();
2707071Srrh return;
2717071Srrh }
2727071Srrh ch = i;
2737071Srrh if(spcnt){
2747071Srrh t2:
2757071Srrh tbreak();
2767071Srrh if(nc || wch)goto rtn;
2777071Srrh un += spcnt*sps;
2787071Srrh spcnt = 0;
2797071Srrh setnel();
2807071Srrh if(trap)goto rtn;
2817071Srrh if(nlflg)goto t1;
2827071Srrh }
2837071Srrh t3:
2847071Srrh if(spread)goto t5;
2857071Srrh if(pendw || !wch)
2867071Srrh t4:
2877071Srrh if(getword(0))goto t6;
2887071Srrh if(!movword())goto t3;
2897071Srrh t5:
2907071Srrh if(nlflg)pendt = 0;
2917071Srrh adsp = adrem = 0;
2927071Srrh if(ad){
2937071Srrh /* jfr */ if (nwd==1) adsp=nel; else adsp=nel/(nwd-1);
2947071Srrh #ifdef NROFF
2957071Srrh adsp = (adsp/t.Adj)*t.Adj;
2967071Srrh #endif
2977071Srrh adrem = nel - adsp*(nwd-1);
2987071Srrh }
2997071Srrh brflg = 1;
3007071Srrh tbreak();
3017071Srrh spread = 0;
3027071Srrh if(!trap)goto t3;
3037071Srrh if(!nlflg)goto rtn;
3047071Srrh t6:
3057071Srrh pendt = 0;
3067071Srrh ckul();
3077071Srrh rtn:
3087071Srrh nflush = 0;
3097071Srrh }
nofill()3107071Srrh nofill(){
3117071Srrh register i, j;
3127071Srrh
3137071Srrh if(!pendnf){
3147071Srrh over = 0;
3157071Srrh tbreak();
3167071Srrh if(trap)goto rtn;
3177071Srrh if(nlflg){
3187071Srrh ch = nflush = 0;
3197071Srrh callsp();
3207071Srrh return;
3217071Srrh }
3227071Srrh adsp = adrem = 0;
3237071Srrh nwd = 10000;
3247071Srrh }
3257071Srrh while((j = ((i = GETCH()) & CMASK)) != '\n'){
3267071Srrh if(j == ohc)continue;
3277071Srrh if(j == CONT){
3287071Srrh pendnf++;
3297071Srrh nflush = 0;
3307071Srrh flushi();
3317071Srrh ckul();
3327071Srrh return;
3337071Srrh }
3347071Srrh storeline(i,-1);
3357071Srrh }
3367071Srrh if(ce){
3377071Srrh ce--;
3387071Srrh if((i=quant(nel/2,HOR)) > 0)un += i;
3397071Srrh }
3407071Srrh if(!nc)storeline(FILLER,0);
3417071Srrh brflg = 2;
3427071Srrh tbreak();
3437071Srrh ckul();
3447071Srrh rtn:
3457071Srrh pendnf = nflush = 0;
3467071Srrh }
callsp()3477071Srrh callsp(){
3487071Srrh register i;
3497071Srrh
3507071Srrh if(flss)i = flss; else i = lss;
3517071Srrh flss = 0;
3527071Srrh casesp(i);
3537071Srrh }
ckul()3547071Srrh ckul(){
3557071Srrh if(ul && (--ul == 0)){
3567071Srrh cu = 0;
3577071Srrh font = sfont;
3587071Srrh mchbits();
3597071Srrh }
3607071Srrh if(it && (--it == 0) && itmac)control(itmac,0);
3617071Srrh }
storeline(c,w)3627071Srrh storeline(c,w){
3637071Srrh register i;
3647071Srrh
3657071Srrh if((c & CMASK) == JREG){
3667071Srrh if((i=findr(c>>BYTE)) != -1)vlist[i] = ne;
3677071Srrh return;
3687071Srrh }
3697071Srrh if(linep >= (line + lnsize - 1)){
3707071Srrh if(!over){
3717071Srrh prstrfl("Line overflow.\n");
3727071Srrh over++;
3737071Srrh c = 0343;
3747071Srrh w = -1;
3757071Srrh goto s1;
3767071Srrh }
3777071Srrh return;
3787071Srrh }
3797071Srrh s1:
3807071Srrh if(w == -1)w = width(c);
3817071Srrh ne += w;
3827071Srrh nel -= w;
3837071Srrh /*
3847071Srrh * if( cu && !(c & MOT) && (trtab[(c & CMASK)] == ' '))
3857071Srrh * c = ((c & ~ulbit) & ~CMASK) | '_';
3867071Srrh */
3877071Srrh *linep++ = c;
3887071Srrh nc++;
3897071Srrh }
newline(a)3907071Srrh newline(a)
3917071Srrh int a;
3927071Srrh {
3937071Srrh register i, j, nlss;
3947071Srrh int opn;
3957071Srrh
3967071Srrh if(a)goto nl1;
3977071Srrh if(dip != d){
3987071Srrh j = lss;
3997071Srrh pchar1(FLSS);
4007071Srrh if(flss)lss = flss;
4017071Srrh i = lss + dip->blss;
4027071Srrh dip->dnl += i;
4037071Srrh pchar1(i);
4047071Srrh pchar1('\n');
4057071Srrh lss = j;
4067071Srrh dip->blss = flss = 0;
4077071Srrh if(dip->alss){
4087071Srrh pchar1(FLSS);
4097071Srrh pchar1(dip->alss);
4107071Srrh pchar1('\n');
4117071Srrh dip->dnl += dip->alss;
4127071Srrh dip->alss = 0;
4137071Srrh }
4147071Srrh if(dip->ditrap && !dip->ditf &&
4157071Srrh (dip->dnl >= dip->ditrap) && dip->dimac)
4167071Srrh if(control(dip->dimac,0)){trap++; dip->ditf++;}
4177071Srrh return;
4187071Srrh }
4197071Srrh j = lss;
4207071Srrh if(flss)lss = flss;
4217071Srrh nlss = dip->alss + dip->blss + lss;
4227071Srrh v.nl += nlss;
4237071Srrh #ifndef NROFF
4247071Srrh if(ascii){dip->alss = dip->blss = 0;}
4257071Srrh #endif
4267071Srrh pchar1('\n');
4277071Srrh flss = 0;
4287071Srrh lss = j;
4297071Srrh if(v.nl < pl)goto nl2;
4307071Srrh nl1:
4317071Srrh ejf = dip->hnl = v.nl = 0;
4327071Srrh ejl = frame;
43332270Sbostic if(donef == 1){
4347071Srrh if((!nc && !wch) || ndone)done1(0);
4357071Srrh ndone++;
4367071Srrh donef = 0;
4377071Srrh if(frame == stk)nflush++;
4387071Srrh }
4397071Srrh opn = v.pn;
4407071Srrh v.pn++;
4417071Srrh if(npnflg){
4427071Srrh v.pn = npn;
4437071Srrh npn = npnflg = 0;
4447071Srrh }
4457071Srrh nlpn:
4467071Srrh if(v.pn == pfrom){
4477071Srrh print++;
44833264Smckusick }else if(opn == pto || v.pn > pto){
4497071Srrh print = 0;
4507071Srrh chkpn();
4517071Srrh goto nlpn;
4527071Srrh }
4537071Srrh if(stop && print){
4547071Srrh dpn++;
4557071Srrh if(dpn >= stop){
4567071Srrh dpn = 0;
4577071Srrh dostop();
4587071Srrh }
4597071Srrh }
4607071Srrh nl2:
4617071Srrh trap = 0;
4627071Srrh if(v.nl == 0){
4637071Srrh if((j = findn(0)) != NTRAP)
4647071Srrh trap = control(mlist[j],0);
4657071Srrh } else if((i = findt(v.nl-nlss)) <= nlss){
4667071Srrh if((j = findn1(v.nl-nlss+i)) == NTRAP){
4677071Srrh prstrfl("Trap botch.\n");
4687071Srrh done2(-5);
4697071Srrh }
4707071Srrh trap = control(mlist[j],0);
4717071Srrh }
4727071Srrh }
findn1(a)4737071Srrh findn1(a)
4747071Srrh int a;
4757071Srrh {
4767071Srrh register i, j;
4777071Srrh
4787071Srrh for(i=0; i<NTRAP; i++){
4797071Srrh if(mlist[i]){
480*48929Sbostic if((j = nlistx[i]) < 0)j += pl;
4817071Srrh if(j == a)break;
4827071Srrh }
4837071Srrh }
4847071Srrh return(i);
4857071Srrh }
chkpn()4867071Srrh chkpn(){
48740363Smckusick pfrom = pto = *(pnp++);
4887071Srrh if(pto == -1){
4897071Srrh flusho();
4907071Srrh done1(0);
4917071Srrh }
49240363Smckusick if(pto == -2){
4937071Srrh print++;
4947071Srrh pfrom = 0;
49540363Smckusick pto = 10000;
4967071Srrh }
49740363Smckusick else if(pto & MOT){
49840363Smckusick print++;
49940363Smckusick pto &= ~MOT;
50040363Smckusick pfrom = 0;
50140363Smckusick }
5027071Srrh }
findt(a)5037071Srrh findt(a)
5047071Srrh int a;
5057071Srrh {
5067071Srrh register i, j, k;
5077071Srrh
5087071Srrh k = 32767;
5097071Srrh if(dip != d){
5107071Srrh if(dip->dimac && ((i = dip->ditrap -a) > 0))k = i;
5117071Srrh return(k);
5127071Srrh }
5137071Srrh for(i=0; i<NTRAP; i++){
5147071Srrh if(mlist[i]){
515*48929Sbostic if((j = nlistx[i]) < 0)j += pl;
5167071Srrh if((j -= a) <= 0)continue;
5177071Srrh if(j < k)k = j;
5187071Srrh }
5197071Srrh }
5207071Srrh i = pl - a;
5217071Srrh if(k > i)k = i;
5227071Srrh return(k);
5237071Srrh }
findt1()5247071Srrh findt1(){
5257071Srrh register i;
5267071Srrh
5277071Srrh if(dip != d)i = dip->dnl;
5287071Srrh else i = v.nl;
5297071Srrh return(findt(i));
5307071Srrh }
5317071Srrh eject(a)
5327071Srrh struct s *a;
5337071Srrh {
5347071Srrh register savlss;
5357071Srrh
5367071Srrh if(dip != d)return;
5377071Srrh ejf++;
5387071Srrh if(a)ejl = a;
5397071Srrh else ejl = frame;
5407071Srrh if(trap)return;
5417071Srrh e1:
5427071Srrh savlss = lss;
5437071Srrh lss = findt(v.nl);
5447071Srrh newline(0);
5457071Srrh lss = savlss;
5467071Srrh if(v.nl && !trap)goto e1;
5477071Srrh }
movword()5487071Srrh movword(){
5497071Srrh register i, w, *wp;
5507071Srrh int savwch, hys;
5517071Srrh
5527071Srrh over = 0;
5537071Srrh wp = wordp;
5547071Srrh if(!nwd){
5557071Srrh while(((i = *wp++) & CMASK) == ' '){
5567071Srrh wch--;
5577071Srrh wne -= width(i);
5587071Srrh }
5597071Srrh wp--;
5607071Srrh }
5617071Srrh if((wne > nel) &&
5627071Srrh !hyoff && hyf &&
5637071Srrh (!nwd || (nel > 3*sps)) &&
5647071Srrh (!(hyf & 02) || (findt1() > lss))
5657071Srrh )hyphen(wp);
5667071Srrh savwch = wch;
5677071Srrh hyp = hyptr;
5687071Srrh nhyp = 0;
5697071Srrh while(*hyp && (*hyp <= wp))hyp++;
5707071Srrh while(wch){
5717071Srrh if((hyoff != 1) && (*hyp == wp)){
5727071Srrh hyp++;
5737071Srrh if(!wdstart ||
5747071Srrh ((wp > (wdstart+1)) &&
5757071Srrh (wp < wdend) &&
5767071Srrh (!(hyf & 04) || (wp < (wdend-1))) &&
5777071Srrh (!(hyf & 010) || (wp > (wdstart+2)))
5787071Srrh )
5797071Srrh ){
5807071Srrh nhyp++;
5817071Srrh storeline(IMP,0);
5827071Srrh }
5837071Srrh }
5847071Srrh i = *wp++;
5857071Srrh w = width(i);
5867071Srrh wne -= w;
5877071Srrh wch--;
5887071Srrh storeline(i,w);
5897071Srrh }
5907071Srrh if(nel >= 0){
5917071Srrh nwd++;
5927071Srrh return(0);
5937071Srrh }
5947071Srrh xbitf = 1;
5957071Srrh hys = width(0200); /*hyphen*/
5967071Srrh m1:
5977071Srrh if(!nhyp){
5987071Srrh if(!nwd)goto m3;
5997071Srrh if(wch == savwch)goto m4;
6007071Srrh }
6017071Srrh if(*--linep != IMP)goto m5;
6027071Srrh if(!(--nhyp))
6037071Srrh if(!nwd)goto m2;
6047071Srrh if(nel < hys){
6057071Srrh nc--;
6067071Srrh goto m1;
6077071Srrh }
6087071Srrh m2:
6097071Srrh if(((i = *(linep-1) & CMASK) != '-') &&
6107071Srrh (i != 0203)
6117071Srrh ){
6127071Srrh *linep = (*(linep-1) & ~CMASK) | 0200;
6137071Srrh w = width(*linep);
6147071Srrh nel -= w;
6157071Srrh ne += w;
6167071Srrh linep++;
6177071Srrh /*
6187071Srrh hsend();
6197071Srrh */
6207071Srrh }
6217071Srrh m3:
6227071Srrh nwd++;
6237071Srrh m4:
6247071Srrh wordp = wp;
6257071Srrh return(1);
6267071Srrh m5:
6277071Srrh nc--;
6287071Srrh w = width(*linep);
6297071Srrh ne -= w;
6307071Srrh nel += w;
6317071Srrh wne += w;
6327071Srrh wch++;
6337071Srrh wp--;
6347071Srrh goto m1;
6357071Srrh }
horiz(i)6367071Srrh horiz(i)
6377071Srrh int i;
6387071Srrh {
6397071Srrh vflag = 0;
6407071Srrh if(i)pchar(makem(i));
6417071Srrh }
setnel()6427071Srrh setnel(){
6437071Srrh if(!nc){
6447071Srrh linep = line;
6457071Srrh if(un1 >= 0){
6467071Srrh un = un1;
6477071Srrh un1 = -1;
6487071Srrh }
6497071Srrh nel = ll - un;
6507071Srrh ne = adsp = adrem = 0;
6517071Srrh }
6527071Srrh }
getword(x)6537071Srrh getword(x)
6547071Srrh int x;
6557071Srrh {
6567071Srrh register i, j, swp;
6577071Srrh int noword;
6587071Srrh
6597071Srrh noword = 0;
6607071Srrh if(x)if(pendw){
6617071Srrh *pendw = 0;
6627071Srrh goto rtn;
6637071Srrh }
6647071Srrh if(wordp = pendw)goto g1;
6657071Srrh hyp = hyptr;
6667071Srrh wordp = word;
6677071Srrh over = wne = wch = 0;
6687071Srrh hyoff = 0;
6697071Srrh while(1){
6707071Srrh j = (i = GETCH()) & CMASK;
6717071Srrh if(j == '\n'){
6727071Srrh wne = wch = 0;
6737071Srrh noword = 1;
6747071Srrh goto rtn;
6757071Srrh }
6767071Srrh if(j == ohc){
6777071Srrh hyoff = 1;
6787071Srrh continue;
6797071Srrh }
6807071Srrh if(j == ' '){
6817071Srrh storeword(i,width(i)); /* XXX */
6827071Srrh continue;
6837071Srrh }
6847071Srrh break;
6857071Srrh }
6867071Srrh swp = widthp;
6877071Srrh storeword(' ' | chbits, -1);
6887071Srrh if(spflg){
6897071Srrh storeword(' ' | chbits, -1);
6907071Srrh spflg = 0;
6917071Srrh }
6927071Srrh widthp = swp;
6937071Srrh g0:
6947071Srrh if(j == CONT){
6957071Srrh pendw = wordp;
6967071Srrh nflush = 0;
6977071Srrh flushi();
6987071Srrh return(1);
6997071Srrh }
7007071Srrh if(hyoff != 1){
7017071Srrh if(j == ohc){
7027071Srrh hyoff = 2;
7037071Srrh *hyp++ = wordp;
7047071Srrh if(hyp > (hyptr+NHYP-1))hyp = hyptr+NHYP-1;
7057071Srrh goto g1;
7067071Srrh }
7077071Srrh if((j == '-') ||
7087071Srrh (j == 0203) /*3/4 Em dash*/
7097071Srrh )if(wordp > word+1){
7107071Srrh hyoff = 2;
7117071Srrh *hyp++ = wordp + 1;
7127071Srrh if(hyp > (hyptr+NHYP-1))hyp = hyptr+NHYP-1;
7137071Srrh }
7147071Srrh }
7157071Srrh storeword(i,width(i)); /* XXX */
7167071Srrh g1:
7177071Srrh j = (i = GETCH()) & CMASK;
7187071Srrh if(j != ' '){
7197071Srrh if(j != '\n')goto g0;
7207071Srrh j = *(wordp-1) & CMASK;
7217071Srrh if((j == '.') ||
7227071Srrh (j == '!') ||
7237071Srrh (j == '?'))spflg++;
7247071Srrh }
7257071Srrh *wordp = 0;
7267071Srrh rtn:
7277071Srrh wdstart = 0;
7287071Srrh wordp = word;
7297071Srrh pendw = 0;
7307071Srrh *hyp++ = 0;
7317071Srrh setnel();
7327071Srrh return(noword);
7337071Srrh }
storeword(c,w)7347071Srrh storeword(c,w)
7357071Srrh int c, w;
7367071Srrh {
7377071Srrh
7387071Srrh if(wordp >= &word[WDSIZE - 1]){
7397071Srrh if(!over){
7407071Srrh prstrfl("Word overflow.\n");
7417071Srrh over++;
7427071Srrh c = 0343;
7437071Srrh w = -1;
7447071Srrh goto s1;
7457071Srrh }
7467071Srrh return;
7477071Srrh }
7487071Srrh s1:
7497071Srrh if(w == -1)w = width(c);
7507071Srrh wne += w;
7517071Srrh *wordp++ = c;
7527071Srrh wch++;
7537071Srrh }
7547071Srrh #ifdef NROFF
7557071Srrh extern char trtab[];
gettch()7567071Srrh gettch(){
7577071Srrh register int i, j;
7587071Srrh
7597071Srrh if(!((i = getch()) & MOT) && (i & ulbit)){
7607071Srrh j = i&CMASK;
7617071Srrh if(cu && (trtab[j] == ' '))
7627071Srrh i = ((i & ~ulbit)& ~CMASK) | '_';
7637071Srrh if(!cu && (j>32) && (j<0370) && !(*t.codetab[j-32] & 0200))
7647071Srrh i &= ~ulbit;
7657071Srrh }
7667071Srrh return(i);
7677071Srrh }
7687071Srrh #endif
769