Print this page
5051 import mdocml-1.12.3
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Approved by: TBD
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mandoc/mdoc_term.c
+++ new/usr/src/cmd/mandoc/mdoc_term.c
1 -/* $Id: mdoc_term.c,v 1.238 2011/11/13 13:15:14 schwarze Exp $ */
1 +/* $Id: mdoc_term.c,v 1.258 2013/12/25 21:24:12 schwarze Exp $ */
2 2 /*
3 3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 - * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
4 + * Copyright (c) 2010, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
5 + * Copyright (c) 2013 Franco Fichtner <franco@lastsummer.de>
5 6 *
6 7 * Permission to use, copy, modify, and distribute this software for any
7 8 * purpose with or without fee is hereby granted, provided that the above
8 9 * copyright notice and this permission notice appear in all copies.
9 10 *
10 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 18 */
18 19 #ifdef HAVE_CONFIG_H
19 20 #include "config.h"
20 21 #endif
21 22
22 23 #include <sys/types.h>
23 24
24 25 #include <assert.h>
25 26 #include <ctype.h>
26 27 #include <stdint.h>
27 28 #include <stdio.h>
28 29 #include <stdlib.h>
29 30 #include <string.h>
30 31
31 32 #include "mandoc.h"
32 33 #include "out.h"
33 34 #include "term.h"
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
34 35 #include "mdoc.h"
35 36 #include "main.h"
36 37
37 38 struct termpair {
38 39 struct termpair *ppair;
39 40 int count;
40 41 };
41 42
42 43 #define DECL_ARGS struct termp *p, \
43 44 struct termpair *pair, \
44 - const struct mdoc_meta *m, \
45 - const struct mdoc_node *n
45 + const struct mdoc_meta *meta, \
46 + struct mdoc_node *n
46 47
47 48 struct termact {
48 49 int (*pre)(DECL_ARGS);
49 50 void (*post)(DECL_ARGS);
50 51 };
51 52
52 53 static size_t a2width(const struct termp *, const char *);
53 54 static size_t a2height(const struct termp *, const char *);
54 55 static size_t a2offs(const struct termp *, const char *);
55 56
56 57 static void print_bvspace(struct termp *,
57 58 const struct mdoc_node *,
58 59 const struct mdoc_node *);
59 60 static void print_mdoc_node(DECL_ARGS);
60 61 static void print_mdoc_nodelist(DECL_ARGS);
61 62 static void print_mdoc_head(struct termp *, const void *);
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
62 63 static void print_mdoc_foot(struct termp *, const void *);
63 64 static void synopsis_pre(struct termp *,
64 65 const struct mdoc_node *);
65 66
66 67 static void termp____post(DECL_ARGS);
67 68 static void termp__t_post(DECL_ARGS);
68 69 static void termp_an_post(DECL_ARGS);
69 70 static void termp_bd_post(DECL_ARGS);
70 71 static void termp_bk_post(DECL_ARGS);
71 72 static void termp_bl_post(DECL_ARGS);
72 -static void termp_d1_post(DECL_ARGS);
73 +static void termp_fd_post(DECL_ARGS);
73 74 static void termp_fo_post(DECL_ARGS);
74 75 static void termp_in_post(DECL_ARGS);
75 76 static void termp_it_post(DECL_ARGS);
76 77 static void termp_lb_post(DECL_ARGS);
77 78 static void termp_nm_post(DECL_ARGS);
78 79 static void termp_pf_post(DECL_ARGS);
79 80 static void termp_quote_post(DECL_ARGS);
80 81 static void termp_sh_post(DECL_ARGS);
81 82 static void termp_ss_post(DECL_ARGS);
82 83
83 84 static int termp__a_pre(DECL_ARGS);
84 85 static int termp__t_pre(DECL_ARGS);
85 86 static int termp_an_pre(DECL_ARGS);
86 87 static int termp_ap_pre(DECL_ARGS);
87 88 static int termp_bd_pre(DECL_ARGS);
88 89 static int termp_bf_pre(DECL_ARGS);
89 90 static int termp_bk_pre(DECL_ARGS);
90 91 static int termp_bl_pre(DECL_ARGS);
91 92 static int termp_bold_pre(DECL_ARGS);
92 93 static int termp_bt_pre(DECL_ARGS);
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
93 94 static int termp_bx_pre(DECL_ARGS);
94 95 static int termp_cd_pre(DECL_ARGS);
95 96 static int termp_d1_pre(DECL_ARGS);
96 97 static int termp_ex_pre(DECL_ARGS);
97 98 static int termp_fa_pre(DECL_ARGS);
98 99 static int termp_fd_pre(DECL_ARGS);
99 100 static int termp_fl_pre(DECL_ARGS);
100 101 static int termp_fn_pre(DECL_ARGS);
101 102 static int termp_fo_pre(DECL_ARGS);
102 103 static int termp_ft_pre(DECL_ARGS);
103 -static int termp_igndelim_pre(DECL_ARGS);
104 104 static int termp_in_pre(DECL_ARGS);
105 105 static int termp_it_pre(DECL_ARGS);
106 106 static int termp_li_pre(DECL_ARGS);
107 107 static int termp_lk_pre(DECL_ARGS);
108 108 static int termp_nd_pre(DECL_ARGS);
109 109 static int termp_nm_pre(DECL_ARGS);
110 110 static int termp_ns_pre(DECL_ARGS);
111 111 static int termp_quote_pre(DECL_ARGS);
112 112 static int termp_rs_pre(DECL_ARGS);
113 113 static int termp_rv_pre(DECL_ARGS);
114 114 static int termp_sh_pre(DECL_ARGS);
115 115 static int termp_sm_pre(DECL_ARGS);
116 116 static int termp_sp_pre(DECL_ARGS);
117 117 static int termp_ss_pre(DECL_ARGS);
118 118 static int termp_under_pre(DECL_ARGS);
119 119 static int termp_ud_pre(DECL_ARGS);
120 120 static int termp_vt_pre(DECL_ARGS);
121 121 static int termp_xr_pre(DECL_ARGS);
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
122 122 static int termp_xx_pre(DECL_ARGS);
123 123
124 124 static const struct termact termacts[MDOC_MAX] = {
125 125 { termp_ap_pre, NULL }, /* Ap */
126 126 { NULL, NULL }, /* Dd */
127 127 { NULL, NULL }, /* Dt */
128 128 { NULL, NULL }, /* Os */
129 129 { termp_sh_pre, termp_sh_post }, /* Sh */
130 130 { termp_ss_pre, termp_ss_post }, /* Ss */
131 131 { termp_sp_pre, NULL }, /* Pp */
132 - { termp_d1_pre, termp_d1_post }, /* D1 */
133 - { termp_d1_pre, termp_d1_post }, /* Dl */
132 + { termp_d1_pre, termp_bl_post }, /* D1 */
133 + { termp_d1_pre, termp_bl_post }, /* Dl */
134 134 { termp_bd_pre, termp_bd_post }, /* Bd */
135 135 { NULL, NULL }, /* Ed */
136 136 { termp_bl_pre, termp_bl_post }, /* Bl */
137 137 { NULL, NULL }, /* El */
138 138 { termp_it_pre, termp_it_post }, /* It */
139 139 { termp_under_pre, NULL }, /* Ad */
140 140 { termp_an_pre, termp_an_post }, /* An */
141 141 { termp_under_pre, NULL }, /* Ar */
142 142 { termp_cd_pre, NULL }, /* Cd */
143 143 { termp_bold_pre, NULL }, /* Cm */
144 144 { NULL, NULL }, /* Dv */
145 145 { NULL, NULL }, /* Er */
146 146 { NULL, NULL }, /* Ev */
147 147 { termp_ex_pre, NULL }, /* Ex */
148 148 { termp_fa_pre, NULL }, /* Fa */
149 - { termp_fd_pre, NULL }, /* Fd */
149 + { termp_fd_pre, termp_fd_post }, /* Fd */
150 150 { termp_fl_pre, NULL }, /* Fl */
151 151 { termp_fn_pre, NULL }, /* Fn */
152 152 { termp_ft_pre, NULL }, /* Ft */
153 153 { termp_bold_pre, NULL }, /* Ic */
154 154 { termp_in_pre, termp_in_post }, /* In */
155 155 { termp_li_pre, NULL }, /* Li */
156 156 { termp_nd_pre, NULL }, /* Nd */
157 157 { termp_nm_pre, termp_nm_post }, /* Nm */
158 158 { termp_quote_pre, termp_quote_post }, /* Op */
159 159 { NULL, NULL }, /* Ot */
160 160 { termp_under_pre, NULL }, /* Pa */
161 161 { termp_rv_pre, NULL }, /* Rv */
162 162 { NULL, NULL }, /* St */
163 163 { termp_under_pre, NULL }, /* Va */
164 164 { termp_vt_pre, NULL }, /* Vt */
165 165 { termp_xr_pre, NULL }, /* Xr */
166 166 { termp__a_pre, termp____post }, /* %A */
167 167 { termp_under_pre, termp____post }, /* %B */
168 168 { NULL, termp____post }, /* %D */
169 169 { termp_under_pre, termp____post }, /* %I */
170 170 { termp_under_pre, termp____post }, /* %J */
171 171 { NULL, termp____post }, /* %N */
172 172 { NULL, termp____post }, /* %O */
173 173 { NULL, termp____post }, /* %P */
174 174 { NULL, termp____post }, /* %R */
175 175 { termp__t_pre, termp__t_post }, /* %T */
176 176 { NULL, termp____post }, /* %V */
177 177 { NULL, NULL }, /* Ac */
178 178 { termp_quote_pre, termp_quote_post }, /* Ao */
179 179 { termp_quote_pre, termp_quote_post }, /* Aq */
180 180 { NULL, NULL }, /* At */
181 181 { NULL, NULL }, /* Bc */
182 182 { termp_bf_pre, NULL }, /* Bf */
183 183 { termp_quote_pre, termp_quote_post }, /* Bo */
184 184 { termp_quote_pre, termp_quote_post }, /* Bq */
185 185 { termp_xx_pre, NULL }, /* Bsx */
186 186 { termp_bx_pre, NULL }, /* Bx */
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
187 187 { NULL, NULL }, /* Db */
188 188 { NULL, NULL }, /* Dc */
189 189 { termp_quote_pre, termp_quote_post }, /* Do */
190 190 { termp_quote_pre, termp_quote_post }, /* Dq */
191 191 { NULL, NULL }, /* Ec */ /* FIXME: no space */
192 192 { NULL, NULL }, /* Ef */
193 193 { termp_under_pre, NULL }, /* Em */
194 194 { termp_quote_pre, termp_quote_post }, /* Eo */
195 195 { termp_xx_pre, NULL }, /* Fx */
196 196 { termp_bold_pre, NULL }, /* Ms */
197 - { termp_igndelim_pre, NULL }, /* No */
197 + { NULL, NULL }, /* No */
198 198 { termp_ns_pre, NULL }, /* Ns */
199 199 { termp_xx_pre, NULL }, /* Nx */
200 200 { termp_xx_pre, NULL }, /* Ox */
201 201 { NULL, NULL }, /* Pc */
202 - { termp_igndelim_pre, termp_pf_post }, /* Pf */
202 + { NULL, termp_pf_post }, /* Pf */
203 203 { termp_quote_pre, termp_quote_post }, /* Po */
204 204 { termp_quote_pre, termp_quote_post }, /* Pq */
205 205 { NULL, NULL }, /* Qc */
206 206 { termp_quote_pre, termp_quote_post }, /* Ql */
207 207 { termp_quote_pre, termp_quote_post }, /* Qo */
208 208 { termp_quote_pre, termp_quote_post }, /* Qq */
209 209 { NULL, NULL }, /* Re */
210 210 { termp_rs_pre, NULL }, /* Rs */
211 211 { NULL, NULL }, /* Sc */
212 212 { termp_quote_pre, termp_quote_post }, /* So */
213 213 { termp_quote_pre, termp_quote_post }, /* Sq */
214 214 { termp_sm_pre, NULL }, /* Sm */
215 215 { termp_under_pre, NULL }, /* Sx */
216 216 { termp_bold_pre, NULL }, /* Sy */
217 217 { NULL, NULL }, /* Tn */
218 218 { termp_xx_pre, NULL }, /* Ux */
219 219 { NULL, NULL }, /* Xc */
220 220 { NULL, NULL }, /* Xo */
221 221 { termp_fo_pre, termp_fo_post }, /* Fo */
222 222 { NULL, NULL }, /* Fc */
223 223 { termp_quote_pre, termp_quote_post }, /* Oo */
224 224 { NULL, NULL }, /* Oc */
225 225 { termp_bk_pre, termp_bk_post }, /* Bk */
226 226 { NULL, NULL }, /* Ek */
227 227 { termp_bt_pre, NULL }, /* Bt */
228 228 { NULL, NULL }, /* Hf */
229 229 { NULL, NULL }, /* Fr */
230 230 { termp_ud_pre, NULL }, /* Ud */
231 231 { NULL, termp_lb_post }, /* Lb */
232 232 { termp_sp_pre, NULL }, /* Lp */
233 233 { termp_lk_pre, NULL }, /* Lk */
234 234 { termp_under_pre, NULL }, /* Mt */
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
235 235 { termp_quote_pre, termp_quote_post }, /* Brq */
236 236 { termp_quote_pre, termp_quote_post }, /* Bro */
237 237 { NULL, NULL }, /* Brc */
238 238 { NULL, termp____post }, /* %C */
239 239 { NULL, NULL }, /* Es */ /* TODO */
240 240 { NULL, NULL }, /* En */ /* TODO */
241 241 { termp_xx_pre, NULL }, /* Dx */
242 242 { NULL, termp____post }, /* %Q */
243 243 { termp_sp_pre, NULL }, /* br */
244 244 { termp_sp_pre, NULL }, /* sp */
245 - { termp_under_pre, termp____post }, /* %U */
245 + { NULL, termp____post }, /* %U */
246 246 { NULL, NULL }, /* Ta */
247 247 };
248 248
249 249
250 250 void
251 251 terminal_mdoc(void *arg, const struct mdoc *mdoc)
252 252 {
253 253 const struct mdoc_node *n;
254 - const struct mdoc_meta *m;
254 + const struct mdoc_meta *meta;
255 255 struct termp *p;
256 256
257 257 p = (struct termp *)arg;
258 258
259 259 if (0 == p->defindent)
260 260 p->defindent = 5;
261 261
262 262 p->overstep = 0;
263 263 p->maxrmargin = p->defrmargin;
264 264 p->tabwidth = term_len(p, 5);
265 265
266 266 if (NULL == p->symtab)
267 267 p->symtab = mchars_alloc();
268 268
269 269 n = mdoc_node(mdoc);
270 - m = mdoc_meta(mdoc);
270 + meta = mdoc_meta(mdoc);
271 271
272 - term_begin(p, print_mdoc_head, print_mdoc_foot, m);
272 + term_begin(p, print_mdoc_head, print_mdoc_foot, meta);
273 273
274 274 if (n->child)
275 - print_mdoc_nodelist(p, NULL, m, n->child);
275 + print_mdoc_nodelist(p, NULL, meta, n->child);
276 276
277 277 term_end(p);
278 278 }
279 279
280 280
281 281 static void
282 282 print_mdoc_nodelist(DECL_ARGS)
283 283 {
284 284
285 - print_mdoc_node(p, pair, m, n);
285 + print_mdoc_node(p, pair, meta, n);
286 286 if (n->next)
287 - print_mdoc_nodelist(p, pair, m, n->next);
287 + print_mdoc_nodelist(p, pair, meta, n->next);
288 288 }
289 289
290 290
291 291 /* ARGSUSED */
292 292 static void
293 293 print_mdoc_node(DECL_ARGS)
294 294 {
295 295 int chld;
296 - const void *font;
297 296 struct termpair npair;
298 297 size_t offset, rmargin;
299 298
300 299 chld = 1;
301 300 offset = p->offset;
302 301 rmargin = p->rmargin;
303 - font = term_fontq(p);
302 + n->prev_font = term_fontq(p);
304 303
305 304 memset(&npair, 0, sizeof(struct termpair));
306 305 npair.ppair = pair;
307 306
308 307 /*
309 308 * Keeps only work until the end of a line. If a keep was
310 309 * invoked in a prior line, revert it to PREKEEP.
311 - *
312 - * Also let SYNPRETTY sections behave as if they were wrapped
313 - * in a `Bk' block.
314 310 */
315 311
316 - if (TERMP_KEEP & p->flags || MDOC_SYNPRETTY & n->flags) {
317 - if (n->prev && n->prev->line != n->line) {
312 + if (TERMP_KEEP & p->flags) {
313 + if (n->prev ? (n->prev->lastline != n->line) :
314 + (n->parent && n->parent->line != n->line)) {
318 315 p->flags &= ~TERMP_KEEP;
319 316 p->flags |= TERMP_PREKEEP;
320 - } else if (NULL == n->prev) {
321 - if (n->parent && n->parent->line != n->line) {
322 - p->flags &= ~TERMP_KEEP;
323 - p->flags |= TERMP_PREKEEP;
324 - }
325 317 }
326 318 }
327 319
328 320 /*
329 - * Since SYNPRETTY sections aren't "turned off" with `Ek',
330 - * we have to intuit whether we should disable formatting.
331 - */
332 -
333 - if ( ! (MDOC_SYNPRETTY & n->flags) &&
334 - ((n->prev && MDOC_SYNPRETTY & n->prev->flags) ||
335 - (n->parent && MDOC_SYNPRETTY & n->parent->flags)))
336 - p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
337 -
338 - /*
339 321 * After the keep flags have been set up, we may now
340 322 * produce output. Note that some pre-handlers do so.
341 323 */
342 324
343 325 switch (n->type) {
344 326 case (MDOC_TEXT):
345 327 if (' ' == *n->string && MDOC_LINE & n->flags)
346 328 term_newln(p);
347 329 if (MDOC_DELIMC & n->flags)
348 330 p->flags |= TERMP_NOSPACE;
349 331 term_word(p, n->string);
350 332 if (MDOC_DELIMO & n->flags)
351 333 p->flags |= TERMP_NOSPACE;
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
352 334 break;
353 335 case (MDOC_EQN):
354 336 term_eqn(p, n->eqn);
355 337 break;
356 338 case (MDOC_TBL):
357 339 term_tbl(p, n->span);
358 340 break;
359 341 default:
360 342 if (termacts[n->tok].pre && ENDBODY_NOT == n->end)
361 343 chld = (*termacts[n->tok].pre)
362 - (p, &npair, m, n);
344 + (p, &npair, meta, n);
363 345 break;
364 346 }
365 347
366 348 if (chld && n->child)
367 - print_mdoc_nodelist(p, &npair, m, n->child);
349 + print_mdoc_nodelist(p, &npair, meta, n->child);
368 350
369 - term_fontpopq(p, font);
351 + term_fontpopq(p,
352 + (ENDBODY_NOT == n->end ? n : n->pending)->prev_font);
370 353
371 354 switch (n->type) {
372 355 case (MDOC_TEXT):
373 356 break;
374 357 case (MDOC_TBL):
375 358 break;
376 359 case (MDOC_EQN):
377 360 break;
378 361 default:
379 362 if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags)
380 363 break;
381 - (void)(*termacts[n->tok].post)(p, &npair, m, n);
364 + (void)(*termacts[n->tok].post)(p, &npair, meta, n);
382 365
383 366 /*
384 367 * Explicit end tokens not only call the post
385 368 * handler, but also tell the respective block
386 369 * that it must not call the post handler again.
387 370 */
388 371 if (ENDBODY_NOT != n->end)
389 372 n->pending->flags |= MDOC_ENDED;
390 373
391 374 /*
392 375 * End of line terminating an implicit block
393 376 * while an explicit block is still open.
394 377 * Continue the explicit block without spacing.
395 378 */
396 379 if (ENDBODY_NOSPACE == n->end)
397 380 p->flags |= TERMP_NOSPACE;
398 381 break;
399 382 }
400 383
401 384 if (MDOC_EOS & n->flags)
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
402 385 p->flags |= TERMP_SENTENCE;
403 386
404 387 p->offset = offset;
405 388 p->rmargin = rmargin;
406 389 }
407 390
408 391
409 392 static void
410 393 print_mdoc_foot(struct termp *p, const void *arg)
411 394 {
412 - const struct mdoc_meta *m;
395 + const struct mdoc_meta *meta;
413 396
414 - m = (const struct mdoc_meta *)arg;
397 + meta = (const struct mdoc_meta *)arg;
415 398
416 399 term_fontrepl(p, TERMFONT_NONE);
417 400
418 401 /*
419 402 * Output the footer in new-groff style, that is, three columns
420 403 * with the middle being the manual date and flanking columns
421 404 * being the operating system:
422 405 *
423 406 * SYSTEM DATE SYSTEM
424 407 */
425 408
426 409 term_vspace(p);
427 410
428 411 p->offset = 0;
429 412 p->rmargin = (p->maxrmargin -
430 - term_strlen(p, m->date) + term_len(p, 1)) / 2;
413 + term_strlen(p, meta->date) + term_len(p, 1)) / 2;
414 + p->trailspace = 1;
431 415 p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
432 416
433 - term_word(p, m->os);
417 + term_word(p, meta->os);
434 418 term_flushln(p);
435 419
436 420 p->offset = p->rmargin;
437 - p->rmargin = p->maxrmargin - term_strlen(p, m->os);
421 + p->rmargin = p->maxrmargin - term_strlen(p, meta->os);
438 422 p->flags |= TERMP_NOSPACE;
439 423
440 - term_word(p, m->date);
424 + term_word(p, meta->date);
441 425 term_flushln(p);
442 426
443 427 p->offset = p->rmargin;
444 428 p->rmargin = p->maxrmargin;
429 + p->trailspace = 0;
445 430 p->flags &= ~TERMP_NOBREAK;
446 431 p->flags |= TERMP_NOSPACE;
447 432
448 - term_word(p, m->os);
433 + term_word(p, meta->os);
449 434 term_flushln(p);
450 435
451 436 p->offset = 0;
452 437 p->rmargin = p->maxrmargin;
453 438 p->flags = 0;
454 439 }
455 440
456 441
457 442 static void
458 443 print_mdoc_head(struct termp *p, const void *arg)
459 444 {
460 445 char buf[BUFSIZ], title[BUFSIZ];
461 446 size_t buflen, titlen;
462 - const struct mdoc_meta *m;
447 + const struct mdoc_meta *meta;
463 448
464 - m = (const struct mdoc_meta *)arg;
449 + meta = (const struct mdoc_meta *)arg;
465 450
466 451 /*
467 452 * The header is strange. It has three components, which are
468 453 * really two with the first duplicated. It goes like this:
469 454 *
470 455 * IDENTIFIER TITLE IDENTIFIER
471 456 *
472 457 * The IDENTIFIER is NAME(SECTION), which is the command-name
473 458 * (if given, or "unknown" if not) followed by the manual page
474 459 * section. These are given in `Dt'. The TITLE is a free-form
475 460 * string depending on the manual volume. If not specified, it
476 461 * switches on the manual section.
477 462 */
478 463
479 464 p->offset = 0;
480 465 p->rmargin = p->maxrmargin;
481 466
482 - assert(m->vol);
483 - strlcpy(buf, m->vol, BUFSIZ);
467 + assert(meta->vol);
468 + strlcpy(buf, meta->vol, BUFSIZ);
484 469 buflen = term_strlen(p, buf);
485 470
486 - if (m->arch) {
471 + if (meta->arch) {
487 472 strlcat(buf, " (", BUFSIZ);
488 - strlcat(buf, m->arch, BUFSIZ);
473 + strlcat(buf, meta->arch, BUFSIZ);
489 474 strlcat(buf, ")", BUFSIZ);
490 475 }
491 476
492 - snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec);
477 + snprintf(title, BUFSIZ, "%s(%s)", meta->title, meta->msec);
493 478 titlen = term_strlen(p, title);
494 479
495 480 p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
481 + p->trailspace = 1;
496 482 p->offset = 0;
497 483 p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ?
498 484 (p->maxrmargin -
499 485 term_strlen(p, buf) + term_len(p, 1)) / 2 :
500 486 p->maxrmargin - buflen;
501 487
502 488 term_word(p, title);
503 489 term_flushln(p);
504 490
505 491 p->flags |= TERMP_NOSPACE;
506 492 p->offset = p->rmargin;
507 493 p->rmargin = p->offset + buflen + titlen < p->maxrmargin ?
508 494 p->maxrmargin - titlen : p->maxrmargin;
509 495
510 496 term_word(p, buf);
511 497 term_flushln(p);
512 498
513 499 p->flags &= ~TERMP_NOBREAK;
500 + p->trailspace = 0;
514 501 if (p->rmargin + titlen <= p->maxrmargin) {
515 502 p->flags |= TERMP_NOSPACE;
516 503 p->offset = p->rmargin;
517 504 p->rmargin = p->maxrmargin;
518 505 term_word(p, title);
519 506 term_flushln(p);
520 507 }
521 508
522 509 p->flags &= ~TERMP_NOSPACE;
523 510 p->offset = 0;
524 511 p->rmargin = p->maxrmargin;
525 512 }
526 513
527 514
528 515 static size_t
529 516 a2height(const struct termp *p, const char *v)
530 517 {
531 518 struct roffsu su;
532 519
533 520
534 521 assert(v);
535 522 if ( ! a2roffsu(v, &su, SCALE_VS))
536 523 SCALE_VS_INIT(&su, atoi(v));
537 524
538 525 return(term_vspan(p, &su));
539 526 }
540 527
541 528
542 529 static size_t
543 530 a2width(const struct termp *p, const char *v)
544 531 {
545 532 struct roffsu su;
546 533
547 534 assert(v);
548 535 if ( ! a2roffsu(v, &su, SCALE_MAX))
549 536 SCALE_HS_INIT(&su, term_strlen(p, v));
550 537
551 538 return(term_hspan(p, &su));
552 539 }
553 540
554 541
555 542 static size_t
556 543 a2offs(const struct termp *p, const char *v)
557 544 {
558 545 struct roffsu su;
559 546
560 547 if ('\0' == *v)
561 548 return(0);
562 549 else if (0 == strcmp(v, "left"))
563 550 return(0);
564 551 else if (0 == strcmp(v, "indent"))
565 552 return(term_len(p, p->defindent + 1));
566 553 else if (0 == strcmp(v, "indent-two"))
567 554 return(term_len(p, (p->defindent + 1) * 2));
568 555 else if ( ! a2roffsu(v, &su, SCALE_MAX))
569 556 SCALE_HS_INIT(&su, term_strlen(p, v));
570 557
571 558 return(term_hspan(p, &su));
572 559 }
573 560
574 561
575 562 /*
576 563 * Determine how much space to print out before block elements of `It'
577 564 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
578 565 * too.
579 566 */
580 567 static void
581 568 print_bvspace(struct termp *p,
582 569 const struct mdoc_node *bl,
583 570 const struct mdoc_node *n)
584 571 {
585 572 const struct mdoc_node *nn;
586 573
587 574 assert(n);
588 575
589 576 term_newln(p);
590 577
591 578 if (MDOC_Bd == bl->tok && bl->norm->Bd.comp)
592 579 return;
593 580 if (MDOC_Bl == bl->tok && bl->norm->Bl.comp)
594 581 return;
595 582
596 583 /* Do not vspace directly after Ss/Sh. */
597 584
598 585 for (nn = n; nn; nn = nn->parent) {
599 586 if (MDOC_BLOCK != nn->type)
600 587 continue;
601 588 if (MDOC_Ss == nn->tok)
602 589 return;
603 590 if (MDOC_Sh == nn->tok)
604 591 return;
605 592 if (NULL == nn->prev)
606 593 continue;
607 594 break;
608 595 }
609 596
610 597 /* A `-column' does not assert vspace within the list. */
611 598
612 599 if (MDOC_Bl == bl->tok && LIST_column == bl->norm->Bl.type)
613 600 if (n->prev && MDOC_It == n->prev->tok)
614 601 return;
615 602
616 603 /* A `-diag' without body does not vspace. */
617 604
618 605 if (MDOC_Bl == bl->tok && LIST_diag == bl->norm->Bl.type)
619 606 if (n->prev && MDOC_It == n->prev->tok) {
620 607 assert(n->prev->body);
621 608 if (NULL == n->prev->body->child)
622 609 return;
623 610 }
624 611
625 612 term_vspace(p);
626 613 }
627 614
628 615
629 616 /* ARGSUSED */
630 617 static int
631 618 termp_it_pre(DECL_ARGS)
632 619 {
633 620 const struct mdoc_node *bl, *nn;
634 621 char buf[7];
635 622 int i;
636 623 size_t width, offset, ncols, dcol;
637 624 enum mdoc_list type;
638 625
639 626 if (MDOC_BLOCK == n->type) {
640 627 print_bvspace(p, n->parent->parent, n);
641 628 return(1);
642 629 }
643 630
644 631 bl = n->parent->parent->parent;
645 632 type = bl->norm->Bl.type;
646 633
647 634 /*
648 635 * First calculate width and offset. This is pretty easy unless
649 636 * we're a -column list, in which case all prior columns must
650 637 * be accounted for.
651 638 */
652 639
653 640 width = offset = 0;
654 641
655 642 if (bl->norm->Bl.offs)
656 643 offset = a2offs(p, bl->norm->Bl.offs);
657 644
658 645 switch (type) {
659 646 case (LIST_column):
660 647 if (MDOC_HEAD == n->type)
661 648 break;
662 649
663 650 /*
664 651 * Imitate groff's column handling:
665 652 * - For each earlier column, add its width.
666 653 * - For less than 5 columns, add four more blanks per
667 654 * column.
668 655 * - For exactly 5 columns, add three more blank per
669 656 * column.
670 657 * - For more than 5 columns, add only one column.
671 658 */
672 659 ncols = bl->norm->Bl.ncols;
673 660
674 661 /* LINTED */
675 662 dcol = ncols < 5 ? term_len(p, 4) :
676 663 ncols == 5 ? term_len(p, 3) : term_len(p, 1);
677 664
678 665 /*
679 666 * Calculate the offset by applying all prior MDOC_BODY,
680 667 * so we stop at the MDOC_HEAD (NULL == nn->prev).
681 668 */
682 669
683 670 for (i = 0, nn = n->prev;
684 671 nn->prev && i < (int)ncols;
685 672 nn = nn->prev, i++)
686 673 offset += dcol + a2width
687 674 (p, bl->norm->Bl.cols[i]);
688 675
689 676 /*
690 677 * When exceeding the declared number of columns, leave
691 678 * the remaining widths at 0. This will later be
692 679 * adjusted to the default width of 10, or, for the last
693 680 * column, stretched to the right margin.
694 681 */
695 682 if (i >= (int)ncols)
696 683 break;
697 684
698 685 /*
699 686 * Use the declared column widths, extended as explained
700 687 * in the preceding paragraph.
701 688 */
702 689 width = a2width(p, bl->norm->Bl.cols[i]) + dcol;
703 690 break;
704 691 default:
705 692 if (NULL == bl->norm->Bl.width)
706 693 break;
707 694
708 695 /*
709 696 * Note: buffer the width by 2, which is groff's magic
710 697 * number for buffering single arguments. See the above
711 698 * handling for column for how this changes.
712 699 */
713 700 assert(bl->norm->Bl.width);
714 701 width = a2width(p, bl->norm->Bl.width) + term_len(p, 2);
715 702 break;
716 703 }
717 704
718 705 /*
719 706 * List-type can override the width in the case of fixed-head
↓ open down ↓ |
196 lines elided |
↑ open up ↑ |
720 707 * values (bullet, dash/hyphen, enum). Tags need a non-zero
721 708 * offset.
722 709 */
723 710
724 711 switch (type) {
725 712 case (LIST_bullet):
726 713 /* FALLTHROUGH */
727 714 case (LIST_dash):
728 715 /* FALLTHROUGH */
729 716 case (LIST_hyphen):
730 - if (width < term_len(p, 4))
731 - width = term_len(p, 4);
732 - break;
717 + /* FALLTHROUGH */
733 718 case (LIST_enum):
734 - if (width < term_len(p, 5))
735 - width = term_len(p, 5);
719 + if (width < term_len(p, 2))
720 + width = term_len(p, 2);
736 721 break;
737 722 case (LIST_hang):
738 723 if (0 == width)
739 724 width = term_len(p, 8);
740 725 break;
741 726 case (LIST_column):
742 727 /* FALLTHROUGH */
743 728 case (LIST_tag):
744 729 if (0 == width)
745 730 width = term_len(p, 10);
746 731 break;
747 732 default:
748 733 break;
749 734 }
750 735
751 736 /*
752 737 * Whitespace control. Inset bodies need an initial space,
753 738 * while diagonal bodies need two.
754 739 */
755 740
756 741 p->flags |= TERMP_NOSPACE;
757 742
758 743 switch (type) {
759 744 case (LIST_diag):
760 745 if (MDOC_BODY == n->type)
761 746 term_word(p, "\\ \\ ");
762 747 break;
763 748 case (LIST_inset):
764 749 if (MDOC_BODY == n->type)
765 750 term_word(p, "\\ ");
766 751 break;
767 752 default:
768 753 break;
769 754 }
770 755
771 756 p->flags |= TERMP_NOSPACE;
772 757
773 758 switch (type) {
774 759 case (LIST_diag):
775 760 if (MDOC_HEAD == n->type)
776 761 term_fontpush(p, TERMFONT_BOLD);
777 762 break;
778 763 default:
779 764 break;
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
780 765 }
781 766
782 767 /*
783 768 * Pad and break control. This is the tricky part. These flags
784 769 * are documented in term_flushln() in term.c. Note that we're
785 770 * going to unset all of these flags in termp_it_post() when we
786 771 * exit.
787 772 */
788 773
789 774 switch (type) {
775 + case (LIST_enum):
776 + /*
777 + * Weird special case.
778 + * Very narrow enum lists actually hang.
779 + */
780 + if (width == term_len(p, 2))
781 + p->flags |= TERMP_HANG;
782 + /* FALLTHROUGH */
790 783 case (LIST_bullet):
791 784 /* FALLTHROUGH */
792 785 case (LIST_dash):
793 786 /* FALLTHROUGH */
794 - case (LIST_enum):
795 - /* FALLTHROUGH */
796 787 case (LIST_hyphen):
797 - if (MDOC_HEAD == n->type)
798 - p->flags |= TERMP_NOBREAK;
788 + if (MDOC_HEAD != n->type)
789 + break;
790 + p->flags |= TERMP_NOBREAK;
791 + p->trailspace = 1;
799 792 break;
800 793 case (LIST_hang):
801 - if (MDOC_HEAD == n->type)
802 - p->flags |= TERMP_NOBREAK;
803 - else
794 + if (MDOC_HEAD != n->type)
804 795 break;
805 796
806 797 /*
807 798 * This is ugly. If `-hang' is specified and the body
808 799 * is a `Bl' or `Bd', then we want basically to nullify
809 800 * the "overstep" effect in term_flushln() and treat
810 801 * this as a `-ohang' list instead.
811 802 */
812 803 if (n->next->child &&
813 804 (MDOC_Bl == n->next->child->tok ||
814 805 MDOC_Bd == n->next->child->tok))
815 - p->flags &= ~TERMP_NOBREAK;
816 - else
817 - p->flags |= TERMP_HANG;
806 + break;
807 +
808 + p->flags |= TERMP_NOBREAK | TERMP_HANG;
809 + p->trailspace = 1;
818 810 break;
819 811 case (LIST_tag):
820 - if (MDOC_HEAD == n->type)
821 - p->flags |= TERMP_NOBREAK | TERMP_TWOSPACE;
822 -
823 812 if (MDOC_HEAD != n->type)
824 813 break;
814 +
815 + p->flags |= TERMP_NOBREAK;
816 + p->trailspace = 2;
817 +
825 818 if (NULL == n->next || NULL == n->next->child)
826 819 p->flags |= TERMP_DANGLE;
827 820 break;
828 821 case (LIST_column):
829 822 if (MDOC_HEAD == n->type)
830 823 break;
831 824
832 - if (NULL == n->next)
825 + if (NULL == n->next) {
833 826 p->flags &= ~TERMP_NOBREAK;
834 - else
827 + p->trailspace = 0;
828 + } else {
835 829 p->flags |= TERMP_NOBREAK;
830 + p->trailspace = 1;
831 + }
836 832
837 833 break;
838 834 case (LIST_diag):
839 - if (MDOC_HEAD == n->type)
840 - p->flags |= TERMP_NOBREAK;
835 + if (MDOC_HEAD != n->type)
836 + break;
837 + p->flags |= TERMP_NOBREAK;
838 + p->trailspace = 1;
841 839 break;
842 840 default:
843 841 break;
844 842 }
845 843
846 844 /*
847 845 * Margin control. Set-head-width lists have their right
848 846 * margins shortened. The body for these lists has the offset
849 847 * necessarily lengthened. Everybody gets the offset.
850 848 */
851 849
852 850 p->offset += offset;
853 851
854 852 switch (type) {
855 853 case (LIST_hang):
856 854 /*
857 855 * Same stipulation as above, regarding `-hang'. We
858 856 * don't want to recalculate rmargin and offsets when
859 857 * using `Bd' or `Bl' within `-hang' overstep lists.
860 858 */
861 859 if (MDOC_HEAD == n->type && n->next->child &&
862 860 (MDOC_Bl == n->next->child->tok ||
863 861 MDOC_Bd == n->next->child->tok))
864 862 break;
865 863 /* FALLTHROUGH */
866 864 case (LIST_bullet):
867 865 /* FALLTHROUGH */
868 866 case (LIST_dash):
869 867 /* FALLTHROUGH */
870 868 case (LIST_enum):
871 869 /* FALLTHROUGH */
872 870 case (LIST_hyphen):
873 871 /* FALLTHROUGH */
874 872 case (LIST_tag):
875 873 assert(width);
876 874 if (MDOC_HEAD == n->type)
877 875 p->rmargin = p->offset + width;
878 876 else
879 877 p->offset += width;
880 878 break;
881 879 case (LIST_column):
882 880 assert(width);
883 881 p->rmargin = p->offset + width;
884 882 /*
885 883 * XXX - this behaviour is not documented: the
886 884 * right-most column is filled to the right margin.
887 885 */
888 886 if (MDOC_HEAD == n->type)
889 887 break;
890 888 if (NULL == n->next && p->rmargin < p->maxrmargin)
891 889 p->rmargin = p->maxrmargin;
892 890 break;
893 891 default:
894 892 break;
895 893 }
896 894
897 895 /*
898 896 * The dash, hyphen, bullet and enum lists all have a special
899 897 * HEAD character (temporarily bold, in some cases).
900 898 */
901 899
902 900 if (MDOC_HEAD == n->type)
903 901 switch (type) {
904 902 case (LIST_bullet):
905 903 term_fontpush(p, TERMFONT_BOLD);
906 904 term_word(p, "\\[bu]");
907 905 term_fontpop(p);
908 906 break;
909 907 case (LIST_dash):
910 908 /* FALLTHROUGH */
911 909 case (LIST_hyphen):
912 910 term_fontpush(p, TERMFONT_BOLD);
913 911 term_word(p, "\\(hy");
914 912 term_fontpop(p);
915 913 break;
916 914 case (LIST_enum):
917 915 (pair->ppair->ppair->count)++;
918 916 snprintf(buf, sizeof(buf), "%d.",
919 917 pair->ppair->ppair->count);
920 918 term_word(p, buf);
921 919 break;
922 920 default:
923 921 break;
924 922 }
925 923
926 924 /*
927 925 * If we're not going to process our children, indicate so here.
928 926 */
929 927
930 928 switch (type) {
931 929 case (LIST_bullet):
932 930 /* FALLTHROUGH */
933 931 case (LIST_item):
934 932 /* FALLTHROUGH */
935 933 case (LIST_dash):
936 934 /* FALLTHROUGH */
937 935 case (LIST_hyphen):
938 936 /* FALLTHROUGH */
939 937 case (LIST_enum):
940 938 if (MDOC_HEAD == n->type)
941 939 return(0);
942 940 break;
943 941 case (LIST_column):
944 942 if (MDOC_HEAD == n->type)
945 943 return(0);
946 944 break;
947 945 default:
948 946 break;
949 947 }
950 948
951 949 return(1);
952 950 }
953 951
954 952
955 953 /* ARGSUSED */
956 954 static void
957 955 termp_it_post(DECL_ARGS)
958 956 {
959 957 enum mdoc_list type;
960 958
961 959 if (MDOC_BLOCK == n->type)
962 960 return;
963 961
964 962 type = n->parent->parent->parent->norm->Bl.type;
965 963
966 964 switch (type) {
967 965 case (LIST_item):
968 966 /* FALLTHROUGH */
969 967 case (LIST_diag):
970 968 /* FALLTHROUGH */
971 969 case (LIST_inset):
972 970 if (MDOC_BODY == n->type)
973 971 term_newln(p);
974 972 break;
975 973 case (LIST_column):
976 974 if (MDOC_BODY == n->type)
977 975 term_flushln(p);
978 976 break;
979 977 default:
980 978 term_newln(p);
981 979 break;
↓ open down ↓ |
131 lines elided |
↑ open up ↑ |
982 980 }
983 981
984 982 /*
985 983 * Now that our output is flushed, we can reset our tags. Since
986 984 * only `It' sets these flags, we're free to assume that nobody
987 985 * has munged them in the meanwhile.
988 986 */
989 987
990 988 p->flags &= ~TERMP_DANGLE;
991 989 p->flags &= ~TERMP_NOBREAK;
992 - p->flags &= ~TERMP_TWOSPACE;
993 990 p->flags &= ~TERMP_HANG;
991 + p->trailspace = 0;
994 992 }
995 993
996 994
997 995 /* ARGSUSED */
998 996 static int
999 997 termp_nm_pre(DECL_ARGS)
1000 998 {
1001 999
1002 - if (MDOC_BLOCK == n->type)
1000 + if (MDOC_BLOCK == n->type) {
1001 + p->flags |= TERMP_PREKEEP;
1003 1002 return(1);
1003 + }
1004 1004
1005 1005 if (MDOC_BODY == n->type) {
1006 1006 if (NULL == n->child)
1007 1007 return(0);
1008 1008 p->flags |= TERMP_NOSPACE;
1009 1009 p->offset += term_len(p, 1) +
1010 - (NULL == n->prev->child ? term_strlen(p, m->name) :
1010 + (NULL == n->prev->child ?
1011 + term_strlen(p, meta->name) :
1011 1012 MDOC_TEXT == n->prev->child->type ?
1012 - term_strlen(p, n->prev->child->string) :
1013 + term_strlen(p, n->prev->child->string) :
1013 1014 term_len(p, 5));
1014 1015 return(1);
1015 1016 }
1016 1017
1017 - if (NULL == n->child && NULL == m->name)
1018 + if (NULL == n->child && NULL == meta->name)
1018 1019 return(0);
1019 1020
1020 1021 if (MDOC_HEAD == n->type)
1021 1022 synopsis_pre(p, n->parent);
1022 1023
1023 1024 if (MDOC_HEAD == n->type && n->next->child) {
1024 1025 p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
1026 + p->trailspace = 1;
1025 1027 p->rmargin = p->offset + term_len(p, 1);
1026 1028 if (NULL == n->child) {
1027 - p->rmargin += term_strlen(p, m->name);
1029 + p->rmargin += term_strlen(p, meta->name);
1028 1030 } else if (MDOC_TEXT == n->child->type) {
1029 1031 p->rmargin += term_strlen(p, n->child->string);
1030 1032 if (n->child->next)
1031 1033 p->flags |= TERMP_HANG;
1032 1034 } else {
1033 1035 p->rmargin += term_len(p, 5);
1034 1036 p->flags |= TERMP_HANG;
1035 1037 }
1036 1038 }
1037 1039
1038 1040 term_fontpush(p, TERMFONT_BOLD);
1039 1041 if (NULL == n->child)
1040 - term_word(p, m->name);
1042 + term_word(p, meta->name);
1041 1043 return(1);
1042 1044 }
1043 1045
1044 1046
1045 1047 /* ARGSUSED */
1046 1048 static void
1047 1049 termp_nm_post(DECL_ARGS)
1048 1050 {
1049 1051
1050 - if (MDOC_HEAD == n->type && n->next->child) {
1052 + if (MDOC_BLOCK == n->type) {
1053 + p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1054 + } else if (MDOC_HEAD == n->type && n->next->child) {
1051 1055 term_flushln(p);
1052 1056 p->flags &= ~(TERMP_NOBREAK | TERMP_HANG);
1057 + p->trailspace = 0;
1053 1058 } else if (MDOC_BODY == n->type && n->child)
1054 1059 term_flushln(p);
1055 1060 }
1056 1061
1057 1062
1058 1063 /* ARGSUSED */
1059 1064 static int
1060 1065 termp_fl_pre(DECL_ARGS)
1061 1066 {
1062 1067
1063 1068 term_fontpush(p, TERMFONT_BOLD);
1064 1069 term_word(p, "\\-");
1065 1070
1066 1071 if (n->child)
1067 1072 p->flags |= TERMP_NOSPACE;
1068 1073 else if (n->next && n->next->line == n->line)
1069 1074 p->flags |= TERMP_NOSPACE;
1070 1075
1071 1076 return(1);
1072 1077 }
1073 1078
1074 1079
1075 1080 /* ARGSUSED */
1076 1081 static int
1077 1082 termp__a_pre(DECL_ARGS)
1078 1083 {
1079 1084
1080 1085 if (n->prev && MDOC__A == n->prev->tok)
1081 1086 if (NULL == n->next || MDOC__A != n->next->tok)
1082 1087 term_word(p, "and");
1083 1088
1084 1089 return(1);
1085 1090 }
1086 1091
1087 1092
1088 1093 /* ARGSUSED */
1089 1094 static int
1090 1095 termp_an_pre(DECL_ARGS)
1091 1096 {
1092 1097
1093 1098 if (NULL == n->child)
1094 1099 return(1);
1095 1100
1096 1101 /*
1097 1102 * If not in the AUTHORS section, `An -split' will cause
1098 1103 * newlines to occur before the author name. If in the AUTHORS
1099 1104 * section, by default, the first `An' invocation is nosplit,
1100 1105 * then all subsequent ones, regardless of whether interspersed
1101 1106 * with other macros/text, are split. -split, in this case,
1102 1107 * will override the condition of the implied first -nosplit.
1103 1108 */
1104 1109
1105 1110 if (n->sec == SEC_AUTHORS) {
1106 1111 if ( ! (TERMP_ANPREC & p->flags)) {
1107 1112 if (TERMP_SPLIT & p->flags)
1108 1113 term_newln(p);
1109 1114 return(1);
1110 1115 }
1111 1116 if (TERMP_NOSPLIT & p->flags)
1112 1117 return(1);
1113 1118 term_newln(p);
1114 1119 return(1);
1115 1120 }
1116 1121
1117 1122 if (TERMP_SPLIT & p->flags)
1118 1123 term_newln(p);
1119 1124
1120 1125 return(1);
1121 1126 }
1122 1127
1123 1128
1124 1129 /* ARGSUSED */
1125 1130 static void
1126 1131 termp_an_post(DECL_ARGS)
1127 1132 {
1128 1133
1129 1134 if (n->child) {
1130 1135 if (SEC_AUTHORS == n->sec)
1131 1136 p->flags |= TERMP_ANPREC;
1132 1137 return;
1133 1138 }
1134 1139
1135 1140 if (AUTH_split == n->norm->An.auth) {
1136 1141 p->flags &= ~TERMP_NOSPLIT;
1137 1142 p->flags |= TERMP_SPLIT;
1138 1143 } else if (AUTH_nosplit == n->norm->An.auth) {
1139 1144 p->flags &= ~TERMP_SPLIT;
1140 1145 p->flags |= TERMP_NOSPLIT;
1141 1146 }
1142 1147
1143 1148 }
1144 1149
1145 1150
1146 1151 /* ARGSUSED */
1147 1152 static int
1148 1153 termp_ns_pre(DECL_ARGS)
1149 1154 {
1150 1155
1151 1156 if ( ! (MDOC_LINE & n->flags))
1152 1157 p->flags |= TERMP_NOSPACE;
1153 1158 return(1);
1154 1159 }
1155 1160
1156 1161
1157 1162 /* ARGSUSED */
1158 1163 static int
1159 1164 termp_rs_pre(DECL_ARGS)
1160 1165 {
1161 1166
1162 1167 if (SEC_SEE_ALSO != n->sec)
1163 1168 return(1);
1164 1169 if (MDOC_BLOCK == n->type && n->prev)
1165 1170 term_vspace(p);
1166 1171 return(1);
1167 1172 }
1168 1173
1169 1174
1170 1175 /* ARGSUSED */
1171 1176 static int
1172 1177 termp_rv_pre(DECL_ARGS)
1173 1178 {
1174 1179 int nchild;
1175 1180
1176 1181 term_newln(p);
1177 1182 term_word(p, "The");
1178 1183
1179 1184 nchild = n->nchild;
1180 1185 for (n = n->child; n; n = n->next) {
1181 1186 term_fontpush(p, TERMFONT_BOLD);
1182 1187 term_word(p, n->string);
1183 1188 term_fontpop(p);
1184 1189
1185 1190 p->flags |= TERMP_NOSPACE;
1186 1191 term_word(p, "()");
1187 1192
1188 1193 if (nchild > 2 && n->next) {
1189 1194 p->flags |= TERMP_NOSPACE;
1190 1195 term_word(p, ",");
1191 1196 }
1192 1197
1193 1198 if (n->next && NULL == n->next->next)
1194 1199 term_word(p, "and");
1195 1200 }
1196 1201
1197 1202 if (nchild > 1)
1198 1203 term_word(p, "functions return");
1199 1204 else
1200 1205 term_word(p, "function returns");
1201 1206
1202 1207 term_word(p, "the value 0 if successful; otherwise the value "
1203 1208 "-1 is returned and the global variable");
1204 1209
1205 1210 term_fontpush(p, TERMFONT_UNDER);
1206 1211 term_word(p, "errno");
1207 1212 term_fontpop(p);
1208 1213
1209 1214 term_word(p, "is set to indicate the error.");
1210 1215 p->flags |= TERMP_SENTENCE;
1211 1216
1212 1217 return(0);
1213 1218 }
1214 1219
1215 1220
1216 1221 /* ARGSUSED */
1217 1222 static int
1218 1223 termp_ex_pre(DECL_ARGS)
1219 1224 {
1220 1225 int nchild;
1221 1226
1222 1227 term_newln(p);
1223 1228 term_word(p, "The");
1224 1229
1225 1230 nchild = n->nchild;
1226 1231 for (n = n->child; n; n = n->next) {
1227 1232 term_fontpush(p, TERMFONT_BOLD);
1228 1233 term_word(p, n->string);
1229 1234 term_fontpop(p);
1230 1235
1231 1236 if (nchild > 2 && n->next) {
1232 1237 p->flags |= TERMP_NOSPACE;
1233 1238 term_word(p, ",");
1234 1239 }
1235 1240
1236 1241 if (n->next && NULL == n->next->next)
1237 1242 term_word(p, "and");
1238 1243 }
1239 1244
1240 1245 if (nchild > 1)
1241 1246 term_word(p, "utilities exit");
1242 1247 else
1243 1248 term_word(p, "utility exits");
1244 1249
1245 1250 term_word(p, "0 on success, and >0 if an error occurs.");
1246 1251
1247 1252 p->flags |= TERMP_SENTENCE;
1248 1253 return(0);
1249 1254 }
1250 1255
1251 1256
1252 1257 /* ARGSUSED */
1253 1258 static int
1254 1259 termp_nd_pre(DECL_ARGS)
1255 1260 {
1256 1261
1257 1262 if (MDOC_BODY != n->type)
1258 1263 return(1);
1259 1264
1260 1265 #if defined(__OpenBSD__) || defined(__linux__)
1261 1266 term_word(p, "\\(en");
1262 1267 #else
1263 1268 term_word(p, "\\(em");
1264 1269 #endif
1265 1270 return(1);
1266 1271 }
1267 1272
1268 1273
1269 1274 /* ARGSUSED */
1270 1275 static int
1271 1276 termp_bl_pre(DECL_ARGS)
1272 1277 {
1273 1278
1274 1279 return(MDOC_HEAD != n->type);
1275 1280 }
1276 1281
1277 1282
1278 1283 /* ARGSUSED */
1279 1284 static void
1280 1285 termp_bl_post(DECL_ARGS)
1281 1286 {
1282 1287
1283 1288 if (MDOC_BLOCK == n->type)
1284 1289 term_newln(p);
1285 1290 }
1286 1291
1287 1292 /* ARGSUSED */
1288 1293 static int
1289 1294 termp_xr_pre(DECL_ARGS)
1290 1295 {
1291 1296
1292 1297 if (NULL == (n = n->child))
1293 1298 return(0);
1294 1299
1295 1300 assert(MDOC_TEXT == n->type);
1296 1301 term_word(p, n->string);
1297 1302
1298 1303 if (NULL == (n = n->next))
1299 1304 return(0);
1300 1305
1301 1306 p->flags |= TERMP_NOSPACE;
1302 1307 term_word(p, "(");
1303 1308 p->flags |= TERMP_NOSPACE;
1304 1309
1305 1310 assert(MDOC_TEXT == n->type);
1306 1311 term_word(p, n->string);
1307 1312
1308 1313 p->flags |= TERMP_NOSPACE;
1309 1314 term_word(p, ")");
1310 1315
1311 1316 return(0);
1312 1317 }
1313 1318
1314 1319 /*
1315 1320 * This decides how to assert whitespace before any of the SYNOPSIS set
1316 1321 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1317 1322 * macro combos).
1318 1323 */
1319 1324 static void
1320 1325 synopsis_pre(struct termp *p, const struct mdoc_node *n)
1321 1326 {
1322 1327 /*
1323 1328 * Obviously, if we're not in a SYNOPSIS or no prior macros
1324 1329 * exist, do nothing.
1325 1330 */
1326 1331 if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
1327 1332 return;
1328 1333
1329 1334 /*
1330 1335 * If we're the second in a pair of like elements, emit our
1331 1336 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1332 1337 * case we soldier on.
1333 1338 */
1334 1339 if (n->prev->tok == n->tok &&
1335 1340 MDOC_Ft != n->tok &&
1336 1341 MDOC_Fo != n->tok &&
1337 1342 MDOC_Fn != n->tok) {
1338 1343 term_newln(p);
1339 1344 return;
1340 1345 }
1341 1346
1342 1347 /*
1343 1348 * If we're one of the SYNOPSIS set and non-like pair-wise after
1344 1349 * another (or Fn/Fo, which we've let slip through) then assert
1345 1350 * vertical space, else only newline and move on.
1346 1351 */
1347 1352 switch (n->prev->tok) {
1348 1353 case (MDOC_Fd):
1349 1354 /* FALLTHROUGH */
1350 1355 case (MDOC_Fn):
1351 1356 /* FALLTHROUGH */
1352 1357 case (MDOC_Fo):
1353 1358 /* FALLTHROUGH */
1354 1359 case (MDOC_In):
1355 1360 /* FALLTHROUGH */
1356 1361 case (MDOC_Vt):
1357 1362 term_vspace(p);
1358 1363 break;
1359 1364 case (MDOC_Ft):
1360 1365 if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
1361 1366 term_vspace(p);
1362 1367 break;
1363 1368 }
1364 1369 /* FALLTHROUGH */
1365 1370 default:
1366 1371 term_newln(p);
1367 1372 break;
↓ open down ↓ |
305 lines elided |
↑ open up ↑ |
1368 1373 }
1369 1374 }
1370 1375
1371 1376
1372 1377 static int
1373 1378 termp_vt_pre(DECL_ARGS)
1374 1379 {
1375 1380
1376 1381 if (MDOC_ELEM == n->type) {
1377 1382 synopsis_pre(p, n);
1378 - return(termp_under_pre(p, pair, m, n));
1383 + return(termp_under_pre(p, pair, meta, n));
1379 1384 } else if (MDOC_BLOCK == n->type) {
1380 1385 synopsis_pre(p, n);
1381 1386 return(1);
1382 1387 } else if (MDOC_HEAD == n->type)
1383 1388 return(0);
1384 1389
1385 - return(termp_under_pre(p, pair, m, n));
1390 + return(termp_under_pre(p, pair, meta, n));
1386 1391 }
1387 1392
1388 1393
1389 1394 /* ARGSUSED */
1390 1395 static int
1391 1396 termp_bold_pre(DECL_ARGS)
1392 1397 {
1393 1398
1394 1399 term_fontpush(p, TERMFONT_BOLD);
1395 1400 return(1);
1396 1401 }
1397 1402
1398 1403
1399 1404 /* ARGSUSED */
1400 1405 static int
1401 1406 termp_fd_pre(DECL_ARGS)
1402 1407 {
1403 1408
1404 1409 synopsis_pre(p, n);
1405 - return(termp_bold_pre(p, pair, m, n));
1410 + return(termp_bold_pre(p, pair, meta, n));
1406 1411 }
1407 1412
1408 1413
1409 1414 /* ARGSUSED */
1415 +static void
1416 +termp_fd_post(DECL_ARGS)
1417 +{
1418 +
1419 + term_newln(p);
1420 +}
1421 +
1422 +
1423 +/* ARGSUSED */
1410 1424 static int
1411 1425 termp_sh_pre(DECL_ARGS)
1412 1426 {
1413 1427
1414 1428 /* No vspace between consecutive `Sh' calls. */
1415 1429
1416 1430 switch (n->type) {
1417 1431 case (MDOC_BLOCK):
1418 1432 if (n->prev && MDOC_Sh == n->prev->tok)
1419 1433 if (NULL == n->prev->body->child)
1420 1434 break;
1421 1435 term_vspace(p);
1422 1436 break;
1423 1437 case (MDOC_HEAD):
1424 1438 term_fontpush(p, TERMFONT_BOLD);
1425 1439 break;
1426 1440 case (MDOC_BODY):
1427 1441 p->offset = term_len(p, p->defindent);
1442 + if (SEC_AUTHORS == n->sec)
1443 + p->flags &= ~(TERMP_SPLIT|TERMP_NOSPLIT);
1428 1444 break;
1429 1445 default:
1430 1446 break;
1431 1447 }
1432 1448 return(1);
1433 1449 }
1434 1450
1435 1451
1436 1452 /* ARGSUSED */
1437 1453 static void
1438 1454 termp_sh_post(DECL_ARGS)
1439 1455 {
1440 1456
1441 1457 switch (n->type) {
1442 1458 case (MDOC_HEAD):
1443 1459 term_newln(p);
1444 1460 break;
1445 1461 case (MDOC_BODY):
1446 1462 term_newln(p);
1447 1463 p->offset = 0;
1448 1464 break;
1449 1465 default:
1450 1466 break;
1451 1467 }
1452 1468 }
1453 1469
1454 1470
1455 1471 /* ARGSUSED */
1456 1472 static int
1457 1473 termp_bt_pre(DECL_ARGS)
1458 1474 {
1459 1475
1460 1476 term_word(p, "is currently in beta test.");
1461 1477 p->flags |= TERMP_SENTENCE;
1462 1478 return(0);
1463 1479 }
1464 1480
1465 1481
1466 1482 /* ARGSUSED */
1467 1483 static void
1468 1484 termp_lb_post(DECL_ARGS)
1469 1485 {
1470 1486
1471 1487 if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
1472 1488 term_newln(p);
1473 1489 }
1474 1490
1475 1491
1476 1492 /* ARGSUSED */
1477 1493 static int
1478 1494 termp_ud_pre(DECL_ARGS)
1479 1495 {
1480 1496
1481 1497 term_word(p, "currently under development.");
1482 1498 p->flags |= TERMP_SENTENCE;
1483 1499 return(0);
1484 1500 }
1485 1501
1486 1502
1487 1503 /* ARGSUSED */
1488 1504 static int
1489 1505 termp_d1_pre(DECL_ARGS)
1490 1506 {
↓ open down ↓ |
53 lines elided |
↑ open up ↑ |
1491 1507
1492 1508 if (MDOC_BLOCK != n->type)
1493 1509 return(1);
1494 1510 term_newln(p);
1495 1511 p->offset += term_len(p, p->defindent + 1);
1496 1512 return(1);
1497 1513 }
1498 1514
1499 1515
1500 1516 /* ARGSUSED */
1501 -static void
1502 -termp_d1_post(DECL_ARGS)
1503 -{
1504 -
1505 - if (MDOC_BLOCK != n->type)
1506 - return;
1507 - term_newln(p);
1508 -}
1509 -
1510 -
1511 -/* ARGSUSED */
1512 1517 static int
1513 1518 termp_ft_pre(DECL_ARGS)
1514 1519 {
1515 1520
1516 1521 /* NB: MDOC_LINE does not effect this! */
1517 1522 synopsis_pre(p, n);
1518 1523 term_fontpush(p, TERMFONT_UNDER);
1519 1524 return(1);
1520 1525 }
1521 1526
1522 1527
1523 1528 /* ARGSUSED */
1524 1529 static int
1525 1530 termp_fn_pre(DECL_ARGS)
1526 1531 {
1532 + size_t rmargin = 0;
1527 1533 int pretty;
1528 1534
1529 1535 pretty = MDOC_SYNPRETTY & n->flags;
1530 1536
1531 1537 synopsis_pre(p, n);
1532 1538
1533 1539 if (NULL == (n = n->child))
1534 1540 return(0);
1535 1541
1542 + if (pretty) {
1543 + rmargin = p->rmargin;
1544 + p->rmargin = p->offset + term_len(p, 4);
1545 + p->flags |= TERMP_NOBREAK | TERMP_HANG;
1546 + }
1547 +
1536 1548 assert(MDOC_TEXT == n->type);
1537 1549 term_fontpush(p, TERMFONT_BOLD);
1538 1550 term_word(p, n->string);
1539 1551 term_fontpop(p);
1540 1552
1553 + if (pretty) {
1554 + term_flushln(p);
1555 + p->flags &= ~(TERMP_NOBREAK | TERMP_HANG);
1556 + p->offset = p->rmargin;
1557 + p->rmargin = rmargin;
1558 + }
1559 +
1541 1560 p->flags |= TERMP_NOSPACE;
1542 1561 term_word(p, "(");
1543 1562 p->flags |= TERMP_NOSPACE;
1544 1563
1545 1564 for (n = n->next; n; n = n->next) {
1546 1565 assert(MDOC_TEXT == n->type);
1547 1566 term_fontpush(p, TERMFONT_UNDER);
1567 + if (pretty)
1568 + p->flags |= TERMP_NBRWORD;
1548 1569 term_word(p, n->string);
1549 1570 term_fontpop(p);
1550 1571
1551 1572 if (n->next) {
1552 1573 p->flags |= TERMP_NOSPACE;
1553 1574 term_word(p, ",");
1554 1575 }
1555 1576 }
1556 1577
1557 1578 p->flags |= TERMP_NOSPACE;
1558 1579 term_word(p, ")");
1559 1580
1560 1581 if (pretty) {
1561 1582 p->flags |= TERMP_NOSPACE;
1562 1583 term_word(p, ";");
1584 + term_flushln(p);
1563 1585 }
1564 1586
1565 1587 return(0);
1566 1588 }
1567 1589
1568 1590
1569 1591 /* ARGSUSED */
1570 1592 static int
1571 1593 termp_fa_pre(DECL_ARGS)
1572 1594 {
1573 1595 const struct mdoc_node *nn;
1574 1596
1575 1597 if (n->parent->tok != MDOC_Fo) {
1576 1598 term_fontpush(p, TERMFONT_UNDER);
1577 1599 return(1);
1578 1600 }
1579 1601
1580 1602 for (nn = n->child; nn; nn = nn->next) {
1581 1603 term_fontpush(p, TERMFONT_UNDER);
1604 + p->flags |= TERMP_NBRWORD;
1582 1605 term_word(p, nn->string);
1583 1606 term_fontpop(p);
1584 1607
1585 - if (nn->next) {
1608 + if (nn->next || (n->next && n->next->tok == MDOC_Fa)) {
1586 1609 p->flags |= TERMP_NOSPACE;
1587 1610 term_word(p, ",");
1588 1611 }
1589 1612 }
1590 1613
1591 - if (n->child && n->next && n->next->tok == MDOC_Fa) {
1592 - p->flags |= TERMP_NOSPACE;
1593 - term_word(p, ",");
1594 - }
1595 -
1596 1614 return(0);
1597 1615 }
1598 1616
1599 1617
1600 1618 /* ARGSUSED */
1601 1619 static int
1602 1620 termp_bd_pre(DECL_ARGS)
1603 1621 {
1604 1622 size_t tabwidth, rm, rmax;
1605 - const struct mdoc_node *nn;
1623 + struct mdoc_node *nn;
1606 1624
1607 1625 if (MDOC_BLOCK == n->type) {
1608 1626 print_bvspace(p, n, n);
1609 1627 return(1);
1610 1628 } else if (MDOC_HEAD == n->type)
1611 1629 return(0);
1612 1630
1613 1631 if (n->norm->Bd.offs)
1614 1632 p->offset += a2offs(p, n->norm->Bd.offs);
1615 1633
1616 1634 /*
1617 1635 * If -ragged or -filled are specified, the block does nothing
1618 1636 * but change the indentation. If -unfilled or -literal are
1619 1637 * specified, text is printed exactly as entered in the display:
1620 1638 * for macro lines, a newline is appended to the line. Blank
1621 1639 * lines are allowed.
1622 1640 */
1623 1641
1624 1642 if (DISP_literal != n->norm->Bd.type &&
1625 1643 DISP_unfilled != n->norm->Bd.type)
1626 1644 return(1);
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
1627 1645
1628 1646 tabwidth = p->tabwidth;
1629 1647 if (DISP_literal == n->norm->Bd.type)
1630 1648 p->tabwidth = term_len(p, 8);
1631 1649
1632 1650 rm = p->rmargin;
1633 1651 rmax = p->maxrmargin;
1634 1652 p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1635 1653
1636 1654 for (nn = n->child; nn; nn = nn->next) {
1637 - print_mdoc_node(p, pair, m, nn);
1655 + print_mdoc_node(p, pair, meta, nn);
1638 1656 /*
1639 1657 * If the printed node flushes its own line, then we
1640 1658 * needn't do it here as well. This is hacky, but the
1641 1659 * notion of selective eoln whitespace is pretty dumb
1642 1660 * anyway, so don't sweat it.
1643 1661 */
1644 1662 switch (nn->tok) {
1645 1663 case (MDOC_Sm):
1646 1664 /* FALLTHROUGH */
1647 1665 case (MDOC_br):
1648 1666 /* FALLTHROUGH */
1649 1667 case (MDOC_sp):
1650 1668 /* FALLTHROUGH */
1651 1669 case (MDOC_Bl):
1652 1670 /* FALLTHROUGH */
1653 1671 case (MDOC_D1):
1654 1672 /* FALLTHROUGH */
1655 1673 case (MDOC_Dl):
1656 1674 /* FALLTHROUGH */
1657 1675 case (MDOC_Lp):
1658 1676 /* FALLTHROUGH */
1659 1677 case (MDOC_Pp):
1660 1678 continue;
1661 1679 default:
1662 1680 break;
1663 1681 }
1664 1682 if (nn->next && nn->next->line == nn->line)
1665 1683 continue;
1666 1684 term_flushln(p);
1667 1685 p->flags |= TERMP_NOSPACE;
1668 1686 }
1669 1687
1670 1688 p->tabwidth = tabwidth;
1671 1689 p->rmargin = rm;
1672 1690 p->maxrmargin = rmax;
1673 1691 return(0);
1674 1692 }
1675 1693
1676 1694
1677 1695 /* ARGSUSED */
1678 1696 static void
1679 1697 termp_bd_post(DECL_ARGS)
1680 1698 {
1681 1699 size_t rm, rmax;
1682 1700
1683 1701 if (MDOC_BODY != n->type)
1684 1702 return;
1685 1703
1686 1704 rm = p->rmargin;
1687 1705 rmax = p->maxrmargin;
1688 1706
1689 1707 if (DISP_literal == n->norm->Bd.type ||
1690 1708 DISP_unfilled == n->norm->Bd.type)
1691 1709 p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1692 1710
1693 1711 p->flags |= TERMP_NOSPACE;
1694 1712 term_newln(p);
1695 1713
1696 1714 p->rmargin = rm;
1697 1715 p->maxrmargin = rmax;
1698 1716 }
1699 1717
1700 1718
1701 1719 /* ARGSUSED */
1702 1720 static int
1703 1721 termp_bx_pre(DECL_ARGS)
1704 1722 {
1705 1723
1706 1724 if (NULL != (n = n->child)) {
1707 1725 term_word(p, n->string);
1708 1726 p->flags |= TERMP_NOSPACE;
1709 1727 term_word(p, "BSD");
1710 1728 } else {
1711 1729 term_word(p, "BSD");
1712 1730 return(0);
1713 1731 }
1714 1732
1715 1733 if (NULL != (n = n->next)) {
1716 1734 p->flags |= TERMP_NOSPACE;
1717 1735 term_word(p, "-");
1718 1736 p->flags |= TERMP_NOSPACE;
1719 1737 term_word(p, n->string);
1720 1738 }
1721 1739
1722 1740 return(0);
1723 1741 }
1724 1742
1725 1743
1726 1744 /* ARGSUSED */
1727 1745 static int
1728 1746 termp_xx_pre(DECL_ARGS)
1729 1747 {
1730 1748 const char *pp;
1731 1749 int flags;
1732 1750
1733 1751 pp = NULL;
1734 1752 switch (n->tok) {
1735 1753 case (MDOC_Bsx):
1736 1754 pp = "BSD/OS";
1737 1755 break;
1738 1756 case (MDOC_Dx):
1739 1757 pp = "DragonFly";
1740 1758 break;
1741 1759 case (MDOC_Fx):
1742 1760 pp = "FreeBSD";
1743 1761 break;
↓ open down ↓ |
96 lines elided |
↑ open up ↑ |
1744 1762 case (MDOC_Nx):
1745 1763 pp = "NetBSD";
1746 1764 break;
1747 1765 case (MDOC_Ox):
1748 1766 pp = "OpenBSD";
1749 1767 break;
1750 1768 case (MDOC_Ux):
1751 1769 pp = "UNIX";
1752 1770 break;
1753 1771 default:
1754 - break;
1772 + abort();
1773 + /* NOTREACHED */
1755 1774 }
1756 1775
1757 1776 term_word(p, pp);
1758 1777 if (n->child) {
1759 1778 flags = p->flags;
1760 1779 p->flags |= TERMP_KEEP;
1761 1780 term_word(p, n->child->string);
1762 1781 p->flags = flags;
1763 1782 }
1764 1783 return(0);
1765 1784 }
1766 1785
1767 1786
1768 1787 /* ARGSUSED */
1769 -static int
1770 -termp_igndelim_pre(DECL_ARGS)
1771 -{
1772 -
1773 - p->flags |= TERMP_IGNDELIM;
1774 - return(1);
1775 -}
1776 -
1777 -
1778 -/* ARGSUSED */
1779 1788 static void
1780 1789 termp_pf_post(DECL_ARGS)
1781 1790 {
1782 1791
1783 1792 p->flags |= TERMP_NOSPACE;
1784 1793 }
1785 1794
1786 1795
1787 1796 /* ARGSUSED */
1788 1797 static int
1789 1798 termp_ss_pre(DECL_ARGS)
1790 1799 {
1791 1800
1792 1801 switch (n->type) {
1793 1802 case (MDOC_BLOCK):
1794 1803 term_newln(p);
1795 1804 if (n->prev)
1796 1805 term_vspace(p);
1797 1806 break;
1798 1807 case (MDOC_HEAD):
1799 1808 term_fontpush(p, TERMFONT_BOLD);
1800 1809 p->offset = term_len(p, (p->defindent+1)/2);
1801 1810 break;
1802 1811 default:
1803 1812 break;
1804 1813 }
1805 1814
1806 1815 return(1);
1807 1816 }
1808 1817
1809 1818
1810 1819 /* ARGSUSED */
1811 1820 static void
1812 1821 termp_ss_post(DECL_ARGS)
1813 1822 {
1814 1823
1815 1824 if (MDOC_HEAD == n->type)
1816 1825 term_newln(p);
1817 1826 }
1818 1827
1819 1828
1820 1829 /* ARGSUSED */
1821 1830 static int
1822 1831 termp_cd_pre(DECL_ARGS)
1823 1832 {
1824 1833
1825 1834 synopsis_pre(p, n);
1826 1835 term_fontpush(p, TERMFONT_BOLD);
1827 1836 return(1);
1828 1837 }
1829 1838
1830 1839
1831 1840 /* ARGSUSED */
1832 1841 static int
1833 1842 termp_in_pre(DECL_ARGS)
1834 1843 {
1835 1844
1836 1845 synopsis_pre(p, n);
1837 1846
1838 1847 if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags) {
1839 1848 term_fontpush(p, TERMFONT_BOLD);
1840 1849 term_word(p, "#include");
1841 1850 term_word(p, "<");
1842 1851 } else {
1843 1852 term_word(p, "<");
1844 1853 term_fontpush(p, TERMFONT_UNDER);
1845 1854 }
1846 1855
1847 1856 p->flags |= TERMP_NOSPACE;
1848 1857 return(1);
1849 1858 }
1850 1859
1851 1860
1852 1861 /* ARGSUSED */
1853 1862 static void
1854 1863 termp_in_post(DECL_ARGS)
1855 1864 {
1856 1865
1857 1866 if (MDOC_SYNPRETTY & n->flags)
1858 1867 term_fontpush(p, TERMFONT_BOLD);
1859 1868
1860 1869 p->flags |= TERMP_NOSPACE;
1861 1870 term_word(p, ">");
1862 1871
1863 1872 if (MDOC_SYNPRETTY & n->flags)
1864 1873 term_fontpop(p);
1865 1874 }
1866 1875
1867 1876
1868 1877 /* ARGSUSED */
1869 1878 static int
1870 1879 termp_sp_pre(DECL_ARGS)
1871 1880 {
1872 1881 size_t i, len;
1873 1882
1874 1883 switch (n->tok) {
1875 1884 case (MDOC_sp):
1876 1885 len = n->child ? a2height(p, n->child->string) : 1;
1877 1886 break;
1878 1887 case (MDOC_br):
1879 1888 len = 0;
1880 1889 break;
1881 1890 default:
1882 1891 len = 1;
1883 1892 break;
1884 1893 }
1885 1894
1886 1895 if (0 == len)
1887 1896 term_newln(p);
1888 1897 for (i = 0; i < len; i++)
1889 1898 term_vspace(p);
1890 1899
1891 1900 return(0);
1892 1901 }
1893 1902
1894 1903
1895 1904 /* ARGSUSED */
1896 1905 static int
1897 1906 termp_quote_pre(DECL_ARGS)
1898 1907 {
1899 1908
1900 1909 if (MDOC_BODY != n->type && MDOC_ELEM != n->type)
1901 1910 return(1);
1902 1911
1903 1912 switch (n->tok) {
1904 1913 case (MDOC_Ao):
1905 1914 /* FALLTHROUGH */
1906 1915 case (MDOC_Aq):
1907 1916 term_word(p, "<");
1908 1917 break;
1909 1918 case (MDOC_Bro):
1910 1919 /* FALLTHROUGH */
1911 1920 case (MDOC_Brq):
1912 1921 term_word(p, "{");
1913 1922 break;
1914 1923 case (MDOC_Oo):
1915 1924 /* FALLTHROUGH */
↓ open down ↓ |
127 lines elided |
↑ open up ↑ |
1916 1925 case (MDOC_Op):
1917 1926 /* FALLTHROUGH */
1918 1927 case (MDOC_Bo):
1919 1928 /* FALLTHROUGH */
1920 1929 case (MDOC_Bq):
1921 1930 term_word(p, "[");
1922 1931 break;
1923 1932 case (MDOC_Do):
1924 1933 /* FALLTHROUGH */
1925 1934 case (MDOC_Dq):
1926 - term_word(p, "``");
1935 + term_word(p, "\\(lq");
1927 1936 break;
1928 1937 case (MDOC_Eo):
1929 1938 break;
1930 1939 case (MDOC_Po):
1931 1940 /* FALLTHROUGH */
1932 1941 case (MDOC_Pq):
1933 1942 term_word(p, "(");
1934 1943 break;
1935 1944 case (MDOC__T):
1936 1945 /* FALLTHROUGH */
1937 1946 case (MDOC_Qo):
1938 1947 /* FALLTHROUGH */
1939 1948 case (MDOC_Qq):
1940 1949 term_word(p, "\"");
1941 1950 break;
1942 1951 case (MDOC_Ql):
1943 1952 /* FALLTHROUGH */
1944 1953 case (MDOC_So):
1945 1954 /* FALLTHROUGH */
1946 1955 case (MDOC_Sq):
1947 - term_word(p, "`");
1956 + term_word(p, "\\(oq");
1948 1957 break;
1949 1958 default:
1950 1959 abort();
1951 1960 /* NOTREACHED */
1952 1961 }
1953 1962
1954 1963 p->flags |= TERMP_NOSPACE;
1955 1964 return(1);
1956 1965 }
1957 1966
1958 1967
1959 1968 /* ARGSUSED */
1960 1969 static void
1961 1970 termp_quote_post(DECL_ARGS)
1962 1971 {
1963 1972
1964 1973 if (MDOC_BODY != n->type && MDOC_ELEM != n->type)
1965 1974 return;
1966 1975
1967 1976 p->flags |= TERMP_NOSPACE;
1968 1977
1969 1978 switch (n->tok) {
1970 1979 case (MDOC_Ao):
1971 1980 /* FALLTHROUGH */
1972 1981 case (MDOC_Aq):
1973 1982 term_word(p, ">");
1974 1983 break;
1975 1984 case (MDOC_Bro):
1976 1985 /* FALLTHROUGH */
1977 1986 case (MDOC_Brq):
1978 1987 term_word(p, "}");
1979 1988 break;
1980 1989 case (MDOC_Oo):
1981 1990 /* FALLTHROUGH */
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
1982 1991 case (MDOC_Op):
1983 1992 /* FALLTHROUGH */
1984 1993 case (MDOC_Bo):
1985 1994 /* FALLTHROUGH */
1986 1995 case (MDOC_Bq):
1987 1996 term_word(p, "]");
1988 1997 break;
1989 1998 case (MDOC_Do):
1990 1999 /* FALLTHROUGH */
1991 2000 case (MDOC_Dq):
1992 - term_word(p, "''");
2001 + term_word(p, "\\(rq");
1993 2002 break;
1994 2003 case (MDOC_Eo):
1995 2004 break;
1996 2005 case (MDOC_Po):
1997 2006 /* FALLTHROUGH */
1998 2007 case (MDOC_Pq):
1999 2008 term_word(p, ")");
2000 2009 break;
2001 2010 case (MDOC__T):
2002 2011 /* FALLTHROUGH */
2003 2012 case (MDOC_Qo):
2004 2013 /* FALLTHROUGH */
2005 2014 case (MDOC_Qq):
2006 2015 term_word(p, "\"");
2007 2016 break;
2008 2017 case (MDOC_Ql):
2009 2018 /* FALLTHROUGH */
2010 2019 case (MDOC_So):
2011 2020 /* FALLTHROUGH */
2012 2021 case (MDOC_Sq):
2013 - term_word(p, "'");
2022 + term_word(p, "\\(cq");
2014 2023 break;
2015 2024 default:
2016 2025 abort();
2017 2026 /* NOTREACHED */
2018 2027 }
2019 2028 }
2020 2029
2021 2030
2022 2031 /* ARGSUSED */
2023 2032 static int
2024 2033 termp_fo_pre(DECL_ARGS)
2025 2034 {
2035 + size_t rmargin = 0;
2036 + int pretty;
2026 2037
2038 + pretty = MDOC_SYNPRETTY & n->flags;
2039 +
2027 2040 if (MDOC_BLOCK == n->type) {
2028 2041 synopsis_pre(p, n);
2029 2042 return(1);
2030 2043 } else if (MDOC_BODY == n->type) {
2044 + if (pretty) {
2045 + rmargin = p->rmargin;
2046 + p->rmargin = p->offset + term_len(p, 4);
2047 + p->flags |= TERMP_NOBREAK | TERMP_HANG;
2048 + }
2031 2049 p->flags |= TERMP_NOSPACE;
2032 2050 term_word(p, "(");
2033 2051 p->flags |= TERMP_NOSPACE;
2052 + if (pretty) {
2053 + term_flushln(p);
2054 + p->flags &= ~(TERMP_NOBREAK | TERMP_HANG);
2055 + p->offset = p->rmargin;
2056 + p->rmargin = rmargin;
2057 + }
2034 2058 return(1);
2035 - }
2059 + }
2036 2060
2037 2061 if (NULL == n->child)
2038 2062 return(0);
2039 2063
2040 2064 /* XXX: we drop non-initial arguments as per groff. */
2041 2065
2042 2066 assert(n->child->string);
2043 2067 term_fontpush(p, TERMFONT_BOLD);
2044 2068 term_word(p, n->child->string);
2045 2069 return(0);
2046 2070 }
2047 2071
2048 2072
2049 2073 /* ARGSUSED */
2050 2074 static void
2051 2075 termp_fo_post(DECL_ARGS)
2052 2076 {
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
2053 2077
2054 2078 if (MDOC_BODY != n->type)
2055 2079 return;
2056 2080
2057 2081 p->flags |= TERMP_NOSPACE;
2058 2082 term_word(p, ")");
2059 2083
2060 2084 if (MDOC_SYNPRETTY & n->flags) {
2061 2085 p->flags |= TERMP_NOSPACE;
2062 2086 term_word(p, ";");
2087 + term_flushln(p);
2063 2088 }
2064 2089 }
2065 2090
2066 2091
2067 2092 /* ARGSUSED */
2068 2093 static int
2069 2094 termp_bf_pre(DECL_ARGS)
2070 2095 {
2071 2096
2072 2097 if (MDOC_HEAD == n->type)
2073 2098 return(0);
2074 - else if (MDOC_BLOCK != n->type)
2099 + else if (MDOC_BODY != n->type)
2075 2100 return(1);
2076 2101
2077 2102 if (FONT_Em == n->norm->Bf.font)
2078 2103 term_fontpush(p, TERMFONT_UNDER);
2079 2104 else if (FONT_Sy == n->norm->Bf.font)
2080 2105 term_fontpush(p, TERMFONT_BOLD);
2081 2106 else
2082 2107 term_fontpush(p, TERMFONT_NONE);
2083 2108
2084 2109 return(1);
2085 2110 }
2086 2111
2087 2112
2088 2113 /* ARGSUSED */
2089 2114 static int
2090 2115 termp_sm_pre(DECL_ARGS)
2091 2116 {
2092 2117
2093 2118 assert(n->child && MDOC_TEXT == n->child->type);
2094 2119 if (0 == strcmp("on", n->child->string)) {
2095 2120 if (p->col)
2096 2121 p->flags &= ~TERMP_NOSPACE;
2097 2122 p->flags &= ~TERMP_NONOSPACE;
2098 2123 } else
2099 2124 p->flags |= TERMP_NONOSPACE;
2100 2125
2101 2126 return(0);
2102 2127 }
2103 2128
2104 2129
2105 2130 /* ARGSUSED */
2106 2131 static int
2107 2132 termp_ap_pre(DECL_ARGS)
2108 2133 {
2109 2134
2110 2135 p->flags |= TERMP_NOSPACE;
2111 2136 term_word(p, "'");
2112 2137 p->flags |= TERMP_NOSPACE;
2113 2138 return(1);
2114 2139 }
2115 2140
2116 2141
2117 2142 /* ARGSUSED */
2118 2143 static void
2119 2144 termp____post(DECL_ARGS)
2120 2145 {
2121 2146
2122 2147 /*
2123 2148 * Handle lists of authors. In general, print each followed by
2124 2149 * a comma. Don't print the comma if there are only two
2125 2150 * authors.
2126 2151 */
2127 2152 if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
2128 2153 if (NULL == n->next->next || MDOC__A != n->next->next->tok)
2129 2154 if (NULL == n->prev || MDOC__A != n->prev->tok)
2130 2155 return;
2131 2156
2132 2157 /* TODO: %U. */
2133 2158
2134 2159 if (NULL == n->parent || MDOC_Rs != n->parent->tok)
2135 2160 return;
2136 2161
2137 2162 p->flags |= TERMP_NOSPACE;
2138 2163 if (NULL == n->next) {
2139 2164 term_word(p, ".");
2140 2165 p->flags |= TERMP_SENTENCE;
2141 2166 } else
2142 2167 term_word(p, ",");
2143 2168 }
2144 2169
2145 2170
2146 2171 /* ARGSUSED */
2147 2172 static int
2148 2173 termp_li_pre(DECL_ARGS)
2149 2174 {
↓ open down ↓ |
65 lines elided |
↑ open up ↑ |
2150 2175
2151 2176 term_fontpush(p, TERMFONT_NONE);
2152 2177 return(1);
2153 2178 }
2154 2179
2155 2180
2156 2181 /* ARGSUSED */
2157 2182 static int
2158 2183 termp_lk_pre(DECL_ARGS)
2159 2184 {
2160 - const struct mdoc_node *nn, *sv;
2185 + const struct mdoc_node *link, *descr;
2161 2186
2162 - term_fontpush(p, TERMFONT_UNDER);
2187 + if (NULL == (link = n->child))
2188 + return(0);
2163 2189
2164 - nn = sv = n->child;
2190 + if (NULL != (descr = link->next)) {
2191 + term_fontpush(p, TERMFONT_UNDER);
2192 + while (NULL != descr) {
2193 + term_word(p, descr->string);
2194 + descr = descr->next;
2195 + }
2196 + p->flags |= TERMP_NOSPACE;
2197 + term_word(p, ":");
2198 + term_fontpop(p);
2199 + }
2165 2200
2166 - if (NULL == nn || NULL == nn->next)
2167 - return(1);
2168 -
2169 - for (nn = nn->next; nn; nn = nn->next)
2170 - term_word(p, nn->string);
2171 -
2172 - term_fontpop(p);
2173 -
2174 - p->flags |= TERMP_NOSPACE;
2175 - term_word(p, ":");
2176 -
2177 2201 term_fontpush(p, TERMFONT_BOLD);
2178 - term_word(p, sv->string);
2202 + term_word(p, link->string);
2179 2203 term_fontpop(p);
2180 2204
2181 2205 return(0);
2182 2206 }
2183 2207
2184 2208
2185 2209 /* ARGSUSED */
2186 2210 static int
2187 2211 termp_bk_pre(DECL_ARGS)
2188 2212 {
2189 2213
2190 2214 switch (n->type) {
2191 2215 case (MDOC_BLOCK):
2192 2216 break;
2193 2217 case (MDOC_HEAD):
2194 2218 return(0);
2195 2219 case (MDOC_BODY):
2196 2220 if (n->parent->args || 0 == n->prev->nchild)
2197 2221 p->flags |= TERMP_PREKEEP;
2198 2222 break;
2199 2223 default:
2200 2224 abort();
2201 2225 /* NOTREACHED */
2202 2226 }
2203 2227
2204 2228 return(1);
2205 2229 }
2206 2230
2207 2231
2208 2232 /* ARGSUSED */
2209 2233 static void
2210 2234 termp_bk_post(DECL_ARGS)
2211 2235 {
2212 2236
2213 2237 if (MDOC_BODY == n->type)
2214 2238 p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
2215 2239 }
2216 2240
2217 2241 /* ARGSUSED */
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
2218 2242 static void
2219 2243 termp__t_post(DECL_ARGS)
2220 2244 {
2221 2245
2222 2246 /*
2223 2247 * If we're in an `Rs' and there's a journal present, then quote
2224 2248 * us instead of underlining us (for disambiguation).
2225 2249 */
2226 2250 if (n->parent && MDOC_Rs == n->parent->tok &&
2227 2251 n->parent->norm->Rs.quote_T)
2228 - termp_quote_post(p, pair, m, n);
2252 + termp_quote_post(p, pair, meta, n);
2229 2253
2230 - termp____post(p, pair, m, n);
2254 + termp____post(p, pair, meta, n);
2231 2255 }
2232 2256
2233 2257 /* ARGSUSED */
2234 2258 static int
2235 2259 termp__t_pre(DECL_ARGS)
2236 2260 {
2237 2261
2238 2262 /*
2239 2263 * If we're in an `Rs' and there's a journal present, then quote
2240 2264 * us instead of underlining us (for disambiguation).
2241 2265 */
2242 2266 if (n->parent && MDOC_Rs == n->parent->tok &&
2243 2267 n->parent->norm->Rs.quote_T)
2244 - return(termp_quote_pre(p, pair, m, n));
2268 + return(termp_quote_pre(p, pair, meta, n));
2245 2269
2246 2270 term_fontpush(p, TERMFONT_UNDER);
2247 2271 return(1);
2248 2272 }
2249 2273
2250 2274 /* ARGSUSED */
2251 2275 static int
2252 2276 termp_under_pre(DECL_ARGS)
2253 2277 {
2254 2278
2255 2279 term_fontpush(p, TERMFONT_UNDER);
2256 2280 return(1);
2257 2281 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX