10 /* output troff code; newlines may appear only at the end of s */
11 static void out_out(char *s
, va_list ap
)
13 out_nl
= strchr(s
, '\n') != NULL
;
14 vfprintf(stdout
, s
, ap
);
17 /* output troff code; no preceding newline is necessary */
18 static void outnn(char *s
, ...)
26 /* output troff cmd; should appear after a newline */
27 void out(char *s
, ...)
54 static char *utf8get(char *d
, char *s
)
58 for (i
= 0; i
< l
; i
++)
67 static void out_ps(int n
)
75 static void out_ft(int n
)
77 if (n
>= 0 && o_f
!= n
) {
83 static char *escarg(char *s
, char *d
, int cmd
)
86 if (strchr(ESC_P
, cmd
)) {
87 if (cmd
== 's' && (*s
== '-' || *s
== '+'))
95 if (cmd
== 's' && s
[-1] >= '1' && s
[-1] <= '3')
100 if (strchr(ESC_Q
, cmd
)) {
102 while (*s
&& *s
!= q
)
113 static char *tok_str(char *d
, char *s
)
117 while (*s
&& !isspace(*s
))
123 static char *tok_num(int *d
, char *s
, char **cc
, int scale
)
127 *d
= eval(tok
, 0, scale
);
129 *cc
+= sprintf(*cc
, " %du", *d
);
135 /* parse \D arguments and copy them into cc; return the width */
136 int out_draw(char *s
, char *cc
)
147 s
= tok_num(&h1
, s
, &cc
, 'm');
148 s
= tok_num(&v1
, s
, &cc
, 'v');
149 if (!cc
) /* dpost requires this */
155 s
= tok_num(&h1
, s
, &cc
, 'm');
160 s
= tok_num(&h1
, s
, &cc
, 'm');
161 s
= tok_num(&v1
, s
, &cc
, 'v');
166 s
= tok_num(&h1
, s
, &cc
, 'm');
167 s
= tok_num(&v1
, s
, &cc
, 'v');
168 s
= tok_num(&h2
, s
, &cc
, 'm');
169 s
= tok_num(&v2
, s
, &cc
, 'v');
174 s
= tok_num(&h1
, s
, &cc
, 'm');
175 s
= tok_num(&v1
, s
, &cc
, 'v');
179 s
= tok_num(&h2
, s
, &cc
, 'm');
180 s
= tok_num(&v2
, s
, &cc
, 'v');
193 void out_line(char *s
)
204 s
= utf8get(c
+ strlen(c
), s
);
205 } else if (strchr("DfhsvX", c
[0])) {
206 s
= escarg(s
, arg
, c
[0]);
212 out_ft(dev_font(arg
));
216 outnn("h%d", eval(arg
, 0, 'm'));
220 out_ps(eval(arg
, o_s
, '\0'));
224 outnn("v%d", eval(arg
, 0, 'v'));
228 out("x X %s\n", arg
);
233 g
= dev_glyph(c
, o_f
);
235 if (utf8len(c
[0]) == strlen(c
)) {
236 outnn("c%s%s", c
, c
[1] ? "\n" : "");
241 outnn("h%d", charwid(g
? g
->wid
: dev_spacewid(), o_s
));