|
|
1.1 root 1: #include "tdef.h"
2: #include <sgtty.h>
3: #include <ctype.h>
4: #include "ext.h"
5: /*
6: * troff10.c
7: *
8: * typesetter interface
9: */
10:
11: int vpos = 0; /* absolute vertical position on page */
12: int hpos = 0; /* ditto horizontal */
13:
14: short *chtab;
15: char *chname;
16: char *fontab[NFONT+1];
17: char *kerntab[NFONT+1];
18: char *fitab[NFONT+1];
19: char *codetab[NFONT+1];
20:
21: int Inch;
22: int Hor;
23: int Vert;
24: int Unitwidth;
25: int nfonts;
26: int nsizes;
27: int nchtab;
28:
29: /* these characters are used as various signals or values
30: /* in miscellaneous places.
31: /* values are set in specnames in t10.c
32: */
33:
34: int c_hyphen;
35: int c_emdash;
36: int c_rule;
37: int c_minus;
38: int c_fi;
39: int c_fl;
40: int c_ff;
41: int c_ffi;
42: int c_ffl;
43: int c_acute;
44: int c_grave;
45: int c_under;
46: int c_rooten;
47: int c_boxrule;
48: int c_lefthand;
49: int c_dagger;
50:
51: #include "dev.h"
52: struct dev dev;
53: struct Font *fontbase[NFONT+1];
54:
55:
56: ptinit()
57: {
58: int i, fin, nw;
59: char *setbrk(), *filebase, *p;
60:
61: /* open table for device,
62: /* read in resolution, size info, font info, etc.
63: /* and set params
64: */
65: strcat(termtab, "/dev");
66: strcat(termtab, devname);
67: strcat(termtab, "/DESC.out"); /* makes "..../devXXX/DESC.out" */
68: if ((fin = open(termtab, 0)) < 0) {
69: errprint("can't open tables for %s", termtab);
70: done3(1);
71: }
72: read(fin, (char *) &dev, sizeof(struct dev ));
73: Inch = dev.res;
74: Hor = dev.hor;
75: Vert = dev.vert;
76: Unitwidth = dev.unitwidth;
77: nfonts = dev.nfonts;
78: nsizes = dev.nsizes;
79: nchtab = dev.nchtab;
80: filebase = setbrk(dev.filesize + 2*EXTRAFONT); /* enough room for whole file */
81: read(fin, filebase, dev.filesize); /* all at once */
82: pstab = (short *) filebase;
83: chtab = pstab + nsizes + 1;
84: chname = (char *) (chtab + dev.nchtab);
85: p = chname + dev.lchname;
86: for (i = 1; i <= nfonts; i++) {
87: fontbase[i] = (struct Font *) p;
88: nw = *p & BYTEMASK; /* 1st thing is width count */
89: fontlab[i] = PAIR(fontbase[i]->namefont[0], fontbase[i]->namefont[1]);
90: /* for now, still 2 char names */
91: if (smnt == 0 && fontbase[i]->specfont == 1)
92: smnt = i; /* first special font */
93: p += sizeof(struct Font); /* that's what's on the beginning */
94: fontab[i] = p;
95: kerntab[i] = p + nw;
96: codetab[i] = p + 2 * nw;
97: fitab[i] = p + 3 * nw; /* skip width, kern, code */
98: p += 3 * nw + dev.nchtab + 128 - 32;
99: }
100: fontbase[0] = (struct Font *) p; /* the last shall be first */
101: fontbase[0]->nwfont = EXTRAFONT - dev.nchtab - (128-32) - sizeof (struct Font);
102: fontab[0] = p + sizeof (struct Font);
103: close(fin);
104: /* there are a lot of things that used to be constant
105: /* that now require code to be executed.
106: */
107: sps = SPS;
108: ics = ICS;
109: for (i = 0; i < 16; i++)
110: tabtab[i] = DTAB * (i + 1);
111: pl = 11 * INCH;
112: po = PO;
113: spacesz = SS;
114: lss = lss1 = VS;
115: ll = ll1 = lt = lt1 = LL;
116: specnames(); /* install names like "hyphen", etc. */
117: if (ascii)
118: return;
119: fdprintf(ptid, "x T %s\n", devname);
120: fdprintf(ptid, "x res %d %d %d\n", Inch, Hor, Vert);
121: fdprintf(ptid, "x init\n"); /* do initialization for particular device */
122: /*
123: for (i = 1; i <= nfonts; i++)
124: fdprintf(ptid, "x font %d %s\n", i, fontbase[i]->namefont);
125: fdprintf(ptid, "x xxx fonts=%d sizes=%d unit=%d\n", nfonts, nsizes, Unitwidth);
126: fdprintf(ptid, "x xxx nchtab=%d lchname=%d nfitab=%d\n",
127: dev.nchtab, dev.lchname, dev.nchtab+128-32);
128: fdprintf(ptid, "x xxx sizes:\nx xxx ");
129: for (i = 0; i < nsizes; i++)
130: fdprintf(ptid, " %d", pstab[i]);
131: fdprintf(ptid, "\nx xxx chars:\nx xxx ");
132: for (i = 0; i < dev.nchtab; i++)
133: fdprintf(ptid, " %s", &chname[chtab[i]]);
134: fdprintf(ptid, "\nx xxx\n");
135: */
136: }
137:
138: specnames()
139: {
140: static struct {
141: int *n;
142: char *v;
143: } spnames[] = {
144: &c_hyphen, "hy",
145: &c_emdash, "em",
146: &c_rule, "ru",
147: &c_minus, "\\-",
148: &c_fi, "fi",
149: &c_fl, "fl",
150: &c_ff, "ff",
151: &c_ffi, "Fi",
152: &c_ffl, "Fl",
153: &c_acute, "aa",
154: &c_grave, "ga",
155: &c_under, "ul",
156: &c_rooten, "rn",
157: &c_boxrule, "br",
158: &c_lefthand, "lh",
159: &c_dagger, "dg",
160: 0, 0
161: };
162: int i;
163:
164: for (i = 0; spnames[i].n; i++)
165: *spnames[i].n = findch(spnames[i].v);
166: }
167:
168: findch(s) /* find char s in chname */
169: register char *s;
170: {
171: register int i;
172:
173: for (i = 0; i < nchtab; i++)
174: if (strcmp(s, &chname[chtab[i]]) == 0)
175: return(i + 128);
176: return(0);
177: }
178:
179: ptout(i)
180: register tchar i;
181: {
182: register dv;
183: register tchar *k;
184: int temp, a, b;
185:
186: if (cbits(i) != '\n') {
187: *olinep++ = i;
188: return;
189: }
190: if (olinep == oline) {
191: lead += lss;
192: return;
193: }
194:
195: hpos = po; /* ??? */
196: esc = 0; /* ??? */
197: ptesc(); /* the problem is to get back to the left end of the line */
198: dv = 0;
199: for (k = oline; k < olinep; k++) {
200: if (ismot(*k) && isvmot(*k)) {
201: temp = absmot(*k);
202: if (isnmot(*k))
203: temp = -temp;
204: dv += temp;
205: }
206: }
207: if (dv) {
208: vflag++;
209: *olinep++ = makem(-dv);
210: vflag = 0;
211: }
212:
213: b = dip->blss + lss;
214: lead += dip->blss + lss;
215: dip->blss = 0;
216: for (k = oline; k < olinep; )
217: k += ptout0(k); /* now passing a pointer! */
218: olinep = oline;
219: lead += dip->alss;
220: a = dip->alss;
221: dip->alss = 0;
222: /*
223: fdprintf(ptid, "x xxx end of line: hpos=%d, vpos=%d\n", hpos, vpos);
224: */
225: fdprintf(ptid, "n%d %d\n", b, a); /* be nice to chuck */
226: }
227:
228: ptout0(pi)
229: tchar *pi;
230: {
231: register short j, k, w;
232: short z, dx, dy, dx2, dy2, n;
233: register tchar i;
234: int outsize; /* size of object being printed */
235:
236: outsize = 1; /* default */
237: i = *pi;
238: k = cbits(i);
239: if (ismot(i)) {
240: j = absmot(i);
241: if (isnmot(i))
242: j = -j;
243: if (isvmot(i))
244: lead += j;
245: else
246: esc += j;
247: return(outsize);
248: }
249: if (k == CHARHT) {
250: if (xpts != mpts)
251: ptps();
252: fdprintf(ptid, "x H %d\n", sbits(i));
253: return(outsize);
254: }
255: if (k == SLANT) {
256: fdprintf(ptid, "x S %d\n", sfbits(i)-180);
257: return(outsize);
258: }
259: if (k == WORDSP) {
260: oput('w');
261: return(outsize);
262: }
263: if (k == FONTPOS) {
264: char temp[3];
265: n = i >> 16;
266: temp[0] = n & BYTEMASK;
267: temp[1] = n >> BYTE;
268: temp[2] = 0;
269: ptfpcmd(0, temp);
270: return(outsize);
271: }
272: if (sfbits(i) == oldbits) {
273: xfont = pfont;
274: xpts = ppts;
275: } else
276: xbits(i, 2);
277: if (k == XON) {
278: int c;
279: if (xfont != mfont)
280: ptfont();
281: if (xpts != mpts)
282: ptps();
283: if (lead)
284: ptlead();
285: fdprintf(ptid, "x X ");
286: for (j = 1; (c=cbits(pi[j])) != XOFF; j++)
287: outascii(pi[j]);
288: oput('\n');
289: return j+1;
290: }
291: if (k < 040 && k != DRAWFCN)
292: return(outsize);
293: if (widcache[k-32].fontpts == (xfont<<8) + xpts && !setwdf) {
294: w = widcache[k-32].width;
295: bd = 0;
296: cs = 0;
297: } else
298: w = getcw(k-32);
299: j = z = 0;
300: if (k != DRAWFCN) {
301: if (cs) {
302: if (bd)
303: w += (bd - 1) * HOR;
304: j = (cs - w) / 2;
305: w = cs - j;
306: if (bd)
307: w -= (bd - 1) * HOR;
308: }
309: if (iszbit(i)) {
310: if (cs)
311: w = -j;
312: else
313: w = 0;
314: z = 1;
315: }
316: }
317: esc += j;
318: if (xfont != mfont)
319: ptfont();
320: if (xpts != mpts)
321: ptps();
322: if (lead)
323: ptlead();
324: /* put out the real character here */
325: if (k == DRAWFCN) {
326: if (esc)
327: ptesc();
328: dx = absmot(pi[3]);
329: if (isnmot(pi[3]))
330: dx = -dx;
331: dy = absmot(pi[4]);
332: if (isnmot(pi[4]))
333: dy = -dy;
334: switch (cbits(pi[1])) {
335: case DRAWCIRCLE: /* circle */
336: fdprintf(ptid, "D%c %d\n", DRAWCIRCLE, dx); /* dx is diameter */
337: w = 0;
338: hpos += dx;
339: break;
340: case DRAWELLIPSE:
341: fdprintf(ptid, "D%c %d %d\n", DRAWELLIPSE, dx, dy);
342: w = 0;
343: hpos += dx;
344: break;
345: case DRAWLINE: /* line */
346: k = cbits(pi[2]);
347: fdprintf(ptid, "D%c %d %d ", DRAWLINE, dx, dy);
348: if (k < 128)
349: fdprintf(ptid, "%c\n", k);
350: else
351: fdprintf(ptid, "%s\n", &chname[chtab[k - 128]]);
352: w = 0;
353: hpos += dx;
354: vpos += dy;
355: break;
356: case DRAWARC: /* arc */
357: dx2 = absmot(pi[5]);
358: if (isnmot(pi[5]))
359: dx2 = -dx2;
360: dy2 = absmot(pi[6]);
361: if (isnmot(pi[6]))
362: dy2 = -dy2;
363: fdprintf(ptid, "D%c %d %d %d %d\n", DRAWARC,
364: dx, dy, dx2, dy2);
365: w = 0;
366: hpos += dx + dx2;
367: vpos += dy + dy2;
368: break;
369: case DRAWSPLINE: /* spline */
370: default: /* something else; copy it like spline */
371: fdprintf(ptid, "D%c %d %d", cbits(pi[1]), dx, dy);
372: w = 0;
373: hpos += dx;
374: vpos += dy;
375: if (cbits(pi[3]) == DRAWFCN || cbits(pi[4]) == DRAWFCN) {
376: /* it was somehow defective */
377: fdprintf(ptid, "\n");
378: break;
379: }
380: for (n = 5; cbits(pi[n]) != DRAWFCN; n += 2) {
381: dx = absmot(pi[n]);
382: if (isnmot(pi[n]))
383: dx = -dx;
384: dy = absmot(pi[n+1]);
385: if (isnmot(pi[n+1]))
386: dy = -dy;
387: fdprintf(ptid, " %d %d", dx, dy);
388: hpos += dx;
389: vpos += dy;
390: }
391: fdprintf(ptid, "\n");
392: break;
393: }
394: for (n = 3; cbits(pi[n]) != DRAWFCN; n++)
395: ;
396: outsize = n + 1;
397: } else if (k < 128) {
398: /* try to go faster and compress output */
399: /* by printing nnc for small positive motion followed by c */
400: /* kludgery; have to make sure set all the vars too */
401: if (esc > 0 && esc < 100) {
402: oput(esc / 10 + '0');
403: oput(esc % 10 + '0');
404: oput(k);
405: hpos += esc;
406: esc = 0;
407: } else {
408: if (esc)
409: ptesc();
410: oput('c');
411: oput(k);
412: oput('\n');
413: }
414: } else {
415: if (esc)
416: ptesc();
417: if (k >= nchtab + 128)
418: fdprintf(ptid, "N%d\n", k - (nchtab+128));
419: else
420: fdprintf(ptid, "C%s\n", &chname[chtab[k - 128]]);
421: }
422: if (bd) {
423: bd -= HOR;
424: if (esc += bd)
425: ptesc();
426: if (k < 128) {
427: fdprintf(ptid, "c%c\n", k);
428: } else if (k >= nchtab + 128) {
429: fdprintf(ptid, "N%d\n", k - (nchtab+128));
430: } else
431: fdprintf(ptid, "C%s\n", &chname[chtab[k - 128]]);
432: if (z)
433: esc -= bd;
434: }
435: esc += w;
436: return(outsize);
437: }
438:
439: ptps()
440: {
441: register i, j, k;
442:
443: i = xpts;
444: for (j = 0; i > (k = pstab[j]); j++)
445: if (!k) {
446: k = pstab[--j];
447: break;
448: }
449: fdprintf(ptid, "s%d\n", k); /* really should put out string rep of size */
450: mpts = i;
451: }
452:
453: ptfont()
454: {
455: mfont = xfont;
456: fdprintf(ptid, "f%d\n", xfont);
457: }
458:
459: ptfpcmd(f, s)
460: int f;
461: char *s;
462: {
463: if (ascii)
464: return;
465: fdprintf(ptid, "x font %d %s\n", f, s);
466: ptfont(); /* make sure that it gets noticed */
467: }
468:
469: ptlead()
470: {
471: vpos += lead;
472: if (!ascii)
473: fdprintf(ptid, "V%d\n", vpos);
474: lead = 0;
475: }
476:
477: ptesc()
478: {
479: hpos += esc;
480: if (esc > 0) {
481: oput('h');
482: if (esc>=10 && esc<100) {
483: oput(esc/10 + '0');
484: oput(esc%10 + '0');
485: } else
486: fdprintf(ptid, "%d", esc);
487: } else
488: fdprintf(ptid, "H%d\n", hpos);
489: esc = 0;
490: }
491:
492: newpage(n) /* called at end of each output page (we hope) */
493: {
494: int i;
495:
496: ptlead();
497: vpos = 0;
498: if (ascii)
499: return;
500: fdprintf(ptid, "p%d\n", n); /* new page */
501: for (i = 0; i <= nfonts; i++)
502: if (fontbase[i]->namefont && fontbase[i]->namefont[0])
503: fdprintf(ptid, "x font %d %s\n", i, fontbase[i]->namefont);
504: ptps();
505: ptfont();
506: }
507:
508: pttrailer()
509: {
510: fdprintf(ptid, "x trailer\n");
511: }
512:
513: ptstop()
514: {
515: fdprintf(ptid, "x stop\n");
516: }
517:
518: dostop()
519: {
520: if (ascii)
521: return;
522: ptlead();
523: vpos = 0;
524: /* fdprintf(ptid, "x xxx end of page\n");*/
525: if (!nofeed)
526: pttrailer();
527: ptlead();
528: fdprintf(ptid, "x pause\n");
529: flusho();
530: mpts = mfont = 0;
531: ptesc();
532: esc = po;
533: hpos = vpos = 0; /* probably in wrong place */
534: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.