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: /*
11: troff9.c
12:
13: misc functions
14: */
15:
16: extern int cbuf[];
17: extern int *cp;
18: extern int ch;
19: extern int chbits;
20: extern int dfact;
21: extern int vflag;
22: extern int pts;
23: extern int fc;
24: extern int padc;
25: extern int tabtab[];
26: extern int nlflg;
27: extern int lss;
28: extern int tabch, ldrch;
29: extern int tabc, dotc;
30: extern int nchar, rchar;
31: extern int xxx;
32:
33: setz(){
34: register i;
35:
36: if(!((i = getch()) & MOT))i |= ZBIT;
37: return(i);
38: }
39: setline(){
40: register *i, length, c;
41: int w, cnt, delim, rem, temp;
42:
43: if((delim = getch()) & MOT)return;
44: else delim &= CMASK;
45: vflag = 0;
46: dfact = EM;
47: length = quant(atoi(),HOR);
48: dfact = 1;
49: if(!length){
50: eat(delim);
51: return;
52: }
53: s0:
54: if(((c = getch()) & CMASK) == delim){
55: ch = c;
56: c = 0204 | chbits;
57: }else if((c & CMASK) == FILLER)goto s0;
58: w = width(c);
59: i = cbuf;
60: if(length < 0){
61: *i++ = makem(length);
62: length = -length;
63: }
64: if(!(cnt = length/w)){
65: *i++ = makem(-(temp = ((w-length)/2)));
66: *i++ = c;
67: *i++ = makem(-(w - length - temp));
68: goto s1;
69: }
70: if(rem = length%w){
71: switch(c & CMASK){
72: case 0204: /*rule*/
73: case 0224: /*underrule*/
74: case 0276: /*root en*/
75: *i++ = c | ZBIT;
76: default:
77: *i++ = makem(rem);
78: }
79: }
80: if(cnt){
81: *i++ = RPT;
82: *i++ = cnt;
83: *i++ = c;
84: }
85: s1:
86: *i++ = 0;
87: eat(delim);
88: cp = cbuf;
89: }
90: eat(c)
91: int c;
92: {
93: register i;
94:
95: while(((i = getch() & CMASK) != c) &&
96: (i != '\n'));
97: return(i);
98: }
99: setov(){
100: register i, j, k;
101: int *p, delim, o[NOV], w[NOV];
102:
103: if((delim = getch()) & MOT)return;
104: else delim &= CMASK;
105: for(k=0; (k<NOV) && ((j=(i = getch()) & CMASK) != delim) &&
106: (j != '\n'); k++){
107: o[k] = i;
108: w[k] = width(i);
109: }
110: o[k] = w[k] = 0;
111: if(o[0])for(j=1; j;){
112: j = 0;
113: for(k=1; o[k] ; k++){
114: if(w[k-1] < w[k]){
115: j++;
116: i = w[k];
117: w[k] = w[k-1];
118: w[k-1] = i;
119: i = o[k];
120: o[k] = o[k-1];
121: o[k-1] = i;
122: }
123: }
124: }else return;
125: p = cbuf;
126: for(k=0; o[k]; k++){
127: *p++ = o[k];
128: *p++ = makem(-((w[k]+w[k+1])/2));
129: }
130: *p++ = makem(w[0]/2);
131: *p = 0;
132: cp = cbuf;
133: }
134: setbra(){
135: register i, *j, k;
136: int cnt, delim, dwn;
137:
138: if((delim = getch()) & MOT)return;
139: else delim &= CMASK;
140: j = cbuf + 1;
141: cnt = 0;
142: #ifdef NROFF
143: dwn = (2*t.Halfline) | MOT | VMOT;
144: #endif
145: #ifndef NROFF
146: dwn = EM | MOT | VMOT;
147: #endif
148: while(((k = (i = getch()) & CMASK) != delim) && (k != '\n') &&
149: (j <= (cbuf+NC-4))){
150: *j++ = i | ZBIT;
151: *j++ = dwn;
152: cnt++;
153: }
154: if(--cnt < 0)return;
155: else if (!cnt){
156: ch = *(j-2);
157: return;
158: }
159: *j = 0;
160: #ifdef NROFF
161: *--j = *cbuf = (cnt*t.Halfline) | MOT | NMOT | VMOT;
162: #endif
163: #ifndef NROFF
164: *--j = *cbuf = (cnt*EM)/2 | MOT | NMOT | VMOT;
165: #endif
166: *--j &= ~ZBIT;
167: cp = cbuf;
168: }
169: setvline(){
170: register i, c, *k;
171: int cnt, neg, rem, ver, delim;
172:
173: if((delim = getch()) & MOT)return;
174: else delim &= CMASK;
175: dfact = lss;
176: vflag++;
177: i = quant(atoi(),VERT);
178: dfact = 1;
179: if(!i){
180: eat(delim);
181: vflag = 0;
182: return;
183: }
184: if(((c = getch()) & CMASK) == delim){
185: c = 0337 | chbits; /*default box rule*/
186: }else getch();
187: c |= ZBIT;
188: neg = 0;
189: if(i < 0){
190: i = -i;
191: neg = NMOT;
192: }
193: #ifdef NROFF
194: ver = 2*t.Halfline;
195: #endif
196: #ifndef NROFF
197: ver = EM;
198: #endif
199: cnt = i/ver;
200: rem = makem(i%ver) | neg;
201: ver = makem(ver) | neg;
202: k = cbuf;
203: if(!neg)*k++ = ver;
204: if(rem & ~MOTV){
205: *k++ = c;
206: *k++ = rem;
207: }
208: while((k < (cbuf+NC-3)) && cnt--){
209: *k++ = c;
210: *k++ = ver;
211: }
212: *(k-2) &= ~ZBIT;
213: if(!neg)k--;
214: *k = 0;
215: cp = cbuf;
216: vflag = 0;
217: }
218: casefc(){
219: register i;
220:
221: fc = IMP;
222: padc = ' ';
223: if(skip() ||
224: ((i = getch()) & MOT) ||
225: ((i &= CMASK) == '\n'))return;
226: fc = i;
227: if(skip() || (ch & MOT) || ((ch &= CMASK) == fc))return;
228: padc = ch;
229: }
230: setfield(x)
231: int x;
232: {
233: register i, j, *fp;
234: int length, ws, npad, temp, type;
235: int **pp, *padptr[NPP];
236: static int fbuf[FBUFSZ];
237: int savfc, savtc, savlc;
238:
239: if(x == tabch) rchar = tabc | chbits;
240: else if(x == ldrch) rchar = dotc | chbits;
241: temp = npad = ws = 0;
242: savfc = fc; savtc = tabch; savlc = ldrch;
243: tabch = ldrch = fc = IMP;
244: for(j=0;;j++){
245: if((tabtab[j] & TMASK)== 0){
246: if(x==savfc)prstr("Zero field width.\n");
247: j = 0;
248: goto rtn;
249: }
250: if((length = ((tabtab[j] & TMASK) - v.hp)) > 0 )break;
251: }
252: type = tabtab[j] & (~TMASK);
253: fp = fbuf;
254: pp = padptr;
255: if(x == savfc){while(1){
256: if(((j = (i = getch()) & CMASK)) == padc){
257: npad++;
258: *pp++ = fp;
259: if(pp > (padptr + NPP - 1))break;
260: goto s1;
261: }else if(j == savfc) break;
262: else if(j == '\n'){
263: temp = j;
264: nlflg = 0;
265: break;
266: }
267: ws += width(i);
268: s1:
269: *fp++ = i;
270: if(fp > (fbuf + FBUFSZ -3))break;
271: }
272: if(!npad){
273: npad++;
274: *pp++ = fp;
275: *fp++ = 0;
276: }
277: *fp++ = temp;
278: *fp++ = 0;
279: temp = i = (j = length-ws)/npad;
280: i = (i/HOR)*HOR;
281: if((j -= i*npad) <0)j = -j;
282: i = makem(i);
283: if(temp <0)i |= NMOT;
284: for(;npad > 0; npad--){
285: *(*--pp) = i;
286: if(j){
287: j -= HOR;
288: (*(*pp)) += HOR;
289: }
290: }
291: cp = fbuf;
292: j = 0;
293: }else if(type == 0){
294: /*plain tab or leader*/
295: if((j = width(rchar)) == 0)nchar = 0;
296: else{
297: nchar = length /j;
298: length %= j;
299: }
300: if(length)j = length | MOT;
301: else j = getch0();
302: }else{
303: /*center tab*/
304: /*right tab*/
305: while(((j = (i = getch()) & CMASK) != savtc) &&
306: (j != '\n') && (j != savlc)){
307: ws += width(i);
308: *fp++ = i;
309: if(fp > (fbuf +FBUFSZ - 3)) break;
310: }
311: *fp++ = i;
312: *fp++ = 0;
313: if(type == RTAB)length -= ws;
314: else length -= ws/2; /*CTAB*/
315: if(((j = width(rchar)) == 0) || (length <= 0))nchar = 0;
316: else{
317: nchar = length/j;
318: length %= j;
319: }
320: length = (length/HOR)*HOR;
321: j = makem(length);
322: cp = fbuf;
323: nlflg = 0;
324: }
325: rtn:
326: fc = savfc; tabch = savtc; ldrch = savlc;
327: return(j);
328: }
Defined functions
eat
defined in line
90; used 6 times
setov
defined in line
99; used 1 times
setz
defined in line
33; used 1 times