1: #include "tdef.h"
2: extern
3: #include "d.h"
4: extern
5: #include "v.h"
6: /*
7: troff10.c
8:
9: CAT interface
10: */
11:
12: extern int *olinep;
13: extern int oline[];
14: extern int *pslp;
15: extern int back;
16: extern int xpts;
17: extern int mpts;
18: extern int po;
19: extern int xflg;
20: extern int line[];
21: extern int lss;
22: extern int xbitf;
23: extern char obuf[];
24: extern char *obufp;
25: extern int esct;
26: extern int trflg;
27: extern int cs;
28: extern int smnt;
29: extern int mfont;
30: extern int xfont;
31: extern int code;
32: extern int mcase;
33: extern int esc;
34: extern int lead;
35: extern int paper;
36: extern int cps;
37: extern int psflg;
38: extern int ptid;
39: extern int verm;
40: extern int escm;
41: extern char pstab[], psctab[];
42: extern int dpn;
43: extern int ascii;
44: int mrail = 0; /*0=LR,1=UR*/
45: int mmag = 1; /*0=UM,1=LM*/
46: extern int nofeed;
47: extern int gflag;
48: extern int fontlab[];
49: int papflg;
50: extern int pfont;
51: extern int ppts;
52: extern int oldbits;
53: extern int bd;
54: extern int vflag;
55: extern int stopmesg;
56: extern int xxx;
57:
58: ptinit(){
59:
60: if(ascii || gflag)return;
61: oput(T_INIT);
62: esc = T_IESC;
63: ptesc();
64: esct = 0;
65: esc = po;
66: oput(0140); /*some initial lead*/
67: }
68: ptout(i)
69: int i;
70: {
71: register *k, lw, *j;
72: int ds, de, inith, temp, *slp, dv;
73: int psl[16];
74:
75: if((i & CMASK) != '\n'){
76: *olinep++ = i;
77: return;
78: }
79: if(olinep == oline){
80: lead += lss;
81: return;
82: }
83: pslp = psl;
84: *pslp = lw = inith = dv = 0;
85: for(k=oline; k<olinep; k++){
86: trflg++;
87: xbitf = 1;
88: lw += width(*k);
89: if((*k & (MOT | VMOT)) == (MOT | VMOT)){
90: temp = *k & ~MOTV;
91: if(*k & NMOT)temp = -temp;
92: dv += temp;
93: }
94: if(!(*k & MOT) && xflg)for(j=psl; j<=pslp; j++){
95: if(xpts == *j)break;
96: if(j == pslp){
97: *j = xpts;
98: *++pslp = 0;
99: break;
100: }
101: }
102: }
103: if(dv){
104: vflag++;
105: *olinep++ = makem(-dv);
106: vflag = 0;
107: }
108: if(xflg){
109: --pslp;
110: for(j=psl; j<=pslp; j++){
111: if(*j == mpts){
112: temp = *j;
113: *j = *pslp;
114: *pslp = temp;
115: break;
116: }
117: }
118: }
119: for(k=oline; k<olinep; k++){
120: if(!(*k & MOT) || (*k & VMOT))break;
121: *k &= ~MOT;
122: if(*k & NMOT){
123: *k &= ~NMOT;
124: *k = -*k;
125: }
126: inith += *k;
127: }
128: lead += dip->blss + lss;
129: dip->blss = 0;
130: slp = k;
131: scan:
132: temp = esct - po;
133: if(mpts & DBL)temp -= 55;
134: ds = temp - inith;
135: de = lw - temp;
136: if(de >= ds){
137: back = 0;
138: esc = -ds;
139: for(k=slp; k<olinep; k++)ptout0(*k);
140: }else{
141: back = 1;
142: esc = de;
143: for(k = olinep-1; k>=slp; --k)ptout0(*k);
144: }
145: if(xflg && (--pslp >= psl))goto scan;
146: olinep = oline;
147: lead += dip->alss;
148: dip->alss = 0;
149: }
150: ptout0(i)
151: int i;
152: {
153: register j, k, w;
154: int z;
155:
156: if(i & MOT){
157: j = i & ~MOTV;
158: if(i & NMOT)j = -j;
159: if(back)j = -j;
160: if(i & VMOT)lead += j;
161: else esc += j;
162: return;
163: }
164: xbitf = 2;
165: if((i>>BYTE) == oldbits){
166: xfont = pfont;
167: xpts = ppts;
168: xbitf = 0;
169: }else xbits(i);
170: if((k = (i & CMASK)) < 040){
171: return;
172: }
173: w = getcw(k-32);
174: if(cs){
175: if(bd)w += bd - 1;
176: j = (cs-w)/2;
177: w = cs - j;
178: if(bd)w -= bd - 1;
179: }else j = 0;
180: if(i & ZBIT){
181: if(cs)w = -j; else w = 0;
182: z = 1;
183: }else z = 0;
184: if(back){
185: k = j;
186: j = -w;
187: w = -k;
188: }
189: esc += j;
190: if((!xflg || (xpts == *pslp)) && (code & 077)){
191: if(code & 0200){
192: if(smnt)xfont = smnt -1;
193: else goto p1;
194: }
195: if((k=(code>>6)&01)^mcase)oput((mcase=k)+0105);
196: if(xfont != mfont){
197: mfont = xfont;
198: if(mrail != (xfont&01))
199: oput(0101 + (mrail=xfont&01));
200: if(mmag != (xfont<2))
201: oput(0103 + (mmag=(xfont<2)));
202: }
203: if(xpts != mpts)ptps();
204: if(lead)ptlead();
205: if(esc)ptesc();
206: /*
207: oput(code & 077);
208: */
209: *obufp++ = code & 077;
210: if(obufp == (obuf + OBUFSZ + ascii - 1))flusho();
211: if(bd){
212: bd -= 1;
213: if(back && !z)bd = -bd;
214: if(esc += bd)ptesc();
215: oput(code & 077);
216: if(z)esc -= bd;
217: }
218: }else if(bd && !z){
219: bd -= 1;
220: if(back)bd = -bd;
221: esc += bd;
222: }
223: p1:
224: esc += w;
225: return;
226: }
227: ptps(){
228: register i, j, k;
229:
230: if(psflg)return;
231: if(cps){
232: psflg++;
233: i = findps(cps);
234: }else i = xpts;
235: for(j=0; (i&077) > (k = pstab[j]);j++)if(!k){k=pstab[--j];break;}
236: j = psctab[j];
237: oput((j & ~0200) | 0120);
238: if((!(mpts & DBL))^(!(j & 0200))){
239: if(j & 0200)k = 55;
240: else k = -55;
241: esc += k;
242: }
243: mpts = i;
244: }
245: ptlead(){
246: register i, k;
247:
248: if(k = lead < 0)lead = -lead;
249: if(k^verm)oput(0112 + ((verm=k)<<1));
250: if(((k=lead)%3) == 2)k++;
251: k /= 3;
252: while(k > 0){
253: if((i=31) > k)i = k;
254: if(verm)paper -= i;
255: else paper += i;
256: oput(((~i) & 037) | 0140);
257: if((paper > (11*144*15)) && !papflg && ptid != 1){
258: prstr("Excessive paper use.\n");
259: papflg++;
260: if(ptid != 1){
261: lead = 0;
262: done2(0200);
263: }
264: }
265: k -= i;
266: }
267: lead = 0;
268: }
269: ptesc(){
270: register i, j, k;
271:
272: if(k = esc < 0)esc = -esc;
273: if(k^escm)oput(0107 + (escm=k));
274: k = esc;
275: while(k > 0){
276: if((i=127) > k)i = k;
277: if(((j = (esct + i*(1-2*escm))) > (46*72+18-T_IESC)) ||
278: (j < 0))break;
279: /*
280: oput(~i);
281: */
282: *obufp++ = ~i;
283: if(obufp == (obuf + OBUFSZ + ascii - 1))flusho();
284: esct = j;
285: k -= i;
286: }
287: esc = 0;
288: }
289: dostop(){
290: register i;
291:
292: if(ascii)return;
293: if(!nofeed && !gflag)lead += TRAILER;
294: ptlead();
295: flusho();
296: oput(T_INIT);
297: oput(T_STOP);
298: if(gflag){
299: oput('f');
300: for(i=0; i<4; i++){
301: oput(fontlab[i] & BMASK);
302: oput((fontlab[i]>>BYTE) & BMASK);
303: }
304: }else for(i=8; i>0; i--)oput(T_PAD);
305: flusho();
306: if(stopmesg)prstr("Pages finished.\n");
307: mcase = mpts = mfont = mrail = verm = escm = 0;
308: mmag = 1;
309: report();
310: paper = 0;
311: esc = T_IESC;
312: ptesc();
313: esct = 0;
314: esc = po;
315: }
Defined functions
ptout
defined in line
68; used 1 times
ptps
defined in line
227; used 1 times
Defined variables
mmag
defined in line
45; used 3 times
mrail
defined in line
44; used 3 times