xref: /plan9/sys/src/cmd/postscript/tr2post/conv.c (revision 456a8764e4ea95d7aa2c2cf34e5112293070bc84)
1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include "../common/common.h"
5 #include "tr2post.h"
6 
7 void
conv(Biobufhdr * Bp)8 conv(Biobufhdr *Bp) {
9 	long n;
10 	int r;
11 	char special[10];
12 	int save;
13 
14 	inputlineno = 1;
15 	if (debug)
16 		fprint(2, "conv(Biobufhdr *Bp=%#p)\n", Bp);
17 	while ((r = Bgetrune(Bp)) >= 0) {
18 		switch (r) {
19 		case 's':	/* set point size */
20 			Bgetfield(Bp, 'd', &fontsize, 0);
21 			break;
22 		case 'f':	/* set font to postion */
23 			Bgetfield(Bp, 'd', &fontpos, 0);
24 			save = inputlineno;
25 			settrfont();
26 			inputlineno = save;	/* ugh */
27 			break;
28 		case 'c':	/* print rune */
29 			r = Bgetrune(Bp);
30 			runeout(r);
31 			break;
32 		case 'C':	/* print special character */
33 			Bgetfield(Bp, 's', special, 10);
34 			specialout(special);
35 			break;
36 		case 'N':	/* print character with numeric value from current font */
37 			Bgetfield(Bp, 'd', &n, 0);
38 			break;
39 		case 'H':	/* go to absolute horizontal position */
40 			Bgetfield(Bp, 'd', &n, 0);
41 			hgoto(n);
42 			break;
43 		case 'V':	/* go to absolute vertical position */
44 			Bgetfield(Bp, 'd', &n, 0);
45 			vgoto(n);
46 			break;
47 		case 'h':	/* go to relative horizontal position */
48 			Bgetfield(Bp, 'd', &n, 0);
49 			hmot(n);
50 			break;
51 		case 'v':	/* go to relative vertical position */
52 			Bgetfield(Bp, 'd', &n, 0);
53 			vmot(n);
54 			break;
55 		case '0': case '1': case '2': case '3': case '4':
56 		case '5': case '6': case '7': case '8': case '9':
57 				/* move right nn units, then print character c */
58 			n = (r - '0') * 10;
59 			r = Bgetrune(Bp);
60 			if (r < 0)
61 				error(FATAL, "EOF or error reading input\n");
62 			else if (r < '0' || r > '9')
63 				error(FATAL, "integer expected\n");
64 			n += r - '0';
65 			r = Bgetrune(Bp);
66 			hmot(n);
67 			runeout(r);
68 			break;
69 		case 'p':	/* begin page */
70 			Bgetfield(Bp, 'd', &n, 0);
71 			endpage();
72 			startpage();
73 			break;
74 		case 'n':	/* end of line (information only 'b a' follows) */
75 			Brdline(Bp, '\n');	/* toss rest of line */
76 			inputlineno++;
77 			break;
78 		case 'w':	/* paddable word space (information only) */
79 			break;
80 		case 'D':	/* graphics function */
81 			draw(Bp);
82 			break;
83 		case 'x':	/* device control functions */
84 			devcntl(Bp);
85 			break;
86 		case '#':	/* comment */
87 			Brdline(Bp, '\n');	/* toss rest of line */
88 		case '\n':
89 			inputlineno++;
90 			break;
91 		default:
92 			error(WARNING, "unknown troff function <%c>\n", r);
93 			break;
94 		}
95 	}
96 	endpage();
97 	if (debug) {
98 		fprint(2, "r=%#ux\n", r);
99 		fprint(2, "leaving conv\n");
100 	}
101 }
102