1 /* generating troff output */
11 /* output troff code; newlines may appear only at the end of s */
12 static void out_out(char *s
, va_list ap
)
14 out_nl
= strchr(s
, '\n') != NULL
;
15 vfprintf(stdout
, s
, ap
);
18 /* output troff code; no preceding newline is necessary */
19 static void outnn(char *s
, ...)
27 /* output troff cmd; should appear after a newline */
28 void out(char *s
, ...)
42 static void out_ps(int n
)
50 static void out_ft(int n
)
52 if (n
>= 0 && o_f
!= n
) {
58 static void out_clr(int n
)
60 if (n
>= 0 && o_m
!= n
) {
62 out("m%s\n", clr_str(o_m
));
66 static int tok_num(char **s
, int scale
)
72 while (**s
&& !isspace(**s
))
75 return eval(tok
, scale
);
78 static void out_draw(char *s
)
84 outnn(" %d", tok_num(&s
, 'm'));
85 outnn(" %d", tok_num(&s
, 'v'));
86 outnn(" ."); /* dpost requires this */
89 outnn(" %d", tok_num(&s
, 'm'));
92 outnn(" %d", tok_num(&s
, 'm'));
93 outnn(" %d", tok_num(&s
, 'v'));
96 outnn(" %d", tok_num(&s
, 'm'));
97 outnn(" %d", tok_num(&s
, 'v'));
98 outnn(" %d", tok_num(&s
, 'm'));
99 outnn(" %d", tok_num(&s
, 'v'));
103 outnn(" %d", tok_num(&s
, 'm'));
104 outnn(" %d", tok_num(&s
, 'v'));
106 outnn(" %d", tok_num(&s
, 'm'));
107 outnn(" %d", tok_num(&s
, 'v'));
114 static void outg(char *c
, int fn
)
119 outnn("c%s%s", c
, c
[1] ? "\n" : "");
121 out("C%s\n", c
[0] == c_ec
&& c
[1] == '(' ? c
+ 2 : c
);
125 static void outc(char *c
)
127 struct glyph
*g
= dev_glyph(c
, o_f
);
131 cwid
= charwid(o_f
, o_s
, g
->wid
);
132 bwid
= DEVWID(o_s
, g
->wid
);
133 if (font_mapped(g
->font
, c
))
136 outnn("h%d", (cwid
- bwid
) / 2);
137 outg(c
, dev_fontpos(g
->font
));
138 if (dev_getbd(o_f
)) {
139 outnn("h%d", dev_getbd(o_f
) - 1);
140 outg(c
, dev_fontpos(g
->font
));
141 outnn("h%d", -dev_getbd(o_f
) + 1);
144 outnn("h%d", -(cwid
- bwid
) / 2);
148 void out_line(char *s
)
150 char c
[ILNLEN
+ GNLEN
* 4];
152 while ((t
= escread(&s
, c
)) >= 0) {
154 if (c
[0] == c_ni
|| (c
[0] == '\\' && c
[1] == '\\')) {
158 if (c
[0] == '\t' || c
[0] == '\x01' ||
159 !strcmp(c_hc
, c
) || !strcmp(c_bp
, c
))
172 outnn("h%d", eval(c
, 'm'));
179 out_ps(eval_re(c
, o_s
, '\0'));
182 outnn("v%d", eval(c
, 'v'));