tbl: fix handling single-digit fonts when switching fonts
[troff.git] / tr2ps / conv.c
blobb391ed5d56d12d32e00face074ae224034546262
1 #include <string.h>
2 #include <stdio.h>
3 #include "ustr.h"
4 #include "common.h"
5 #include "tr2ps.h"
7 void conv(struct ustr *ustr)
9 int n;
10 int r;
11 char special[10];
12 int save;
14 inputlineno = 1;
15 if (debug)
16 fprintf(ferr, "conv(Biobufhdr *Bp=0x%p)\n", ustr);
17 while (ustr_uc(ustr, &r) >= 0) {
18 switch (r) {
19 case 's': /* set point size */
20 ustr_int(ustr, &fontsize);
21 break;
22 case 'f': /* set font to postion */
23 ustr_int(ustr, &fontpos);
24 save = inputlineno;
25 settrfont();
26 inputlineno = save; /* ugh */
27 break;
28 case 'c': /* print rune */
29 ustr_uc(ustr, &r);
30 runeout(r);
31 break;
32 case 'C': /* print special character */
33 ustr_str(ustr, special, 10);
34 specialout(special);
35 break;
36 case 'N': /* print character with numeric value from current font */
37 ustr_int(ustr, &n);
38 break;
39 case 'H': /* go to absolute horizontal position */
40 ustr_int(ustr, &n);
41 hgoto(n);
42 break;
43 case 'V': /* go to absolute vertical position */
44 ustr_int(ustr, &n);
45 vgoto(n);
46 break;
47 case 'h': /* go to relative horizontal position */
48 ustr_int(ustr, &n);
49 hmot(n);
50 break;
51 case 'v': /* go to relative vertical position */
52 ustr_int(ustr, &n);
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 ustr_uc(ustr, &r);
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 ustr_uc(ustr, &r);
66 hmot(n);
67 runeout(r);
68 break;
69 case 'p': /* begin page */
70 ustr_int(ustr, &n);
71 endpage();
72 startpage();
73 break;
74 case 'n': /* end of line (information only 'b a' follows) */
75 ustr_eol(ustr); /* toss rest of line */
76 inputlineno++;
77 break;
78 case 'w': /* paddable word space (information only) */
79 break;
80 case 'D': /* graphics function */
81 /* flush ps font before drawing pictures */
82 setpsfont(findpfn(troffontab[fontpos].psfontid), fontsize);
83 draw(ustr);
84 break;
85 case 'x': /* device control functions */
86 devcntl(ustr);
87 break;
88 case '#': /* comment */
89 ustr_eol(ustr); /* toss rest of line */
90 case '\n':
91 inputlineno++;
92 break;
93 default:
94 error(WARNING, "unknown troff function <%c>\n", r);
95 break;
98 endpage();
99 if (debug)
100 fprintf(ferr, "r=0x%x\n", r);
101 if (debug)
102 fprintf(ferr, "leaving conv\n");