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