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