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