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