kernel - Video - Add suppor for Intel IGD chipsets (netbook / N450 etc)
[dragonfly.git] / usr.bin / mandoc / mdoc_term.c
blob40b732db3731575ada322208acdd38d3c98bb78d
1 /* $Id: mdoc_term.c,v 1.102 2009/11/12 05:50:12 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
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.
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.
17 #include <sys/types.h>
19 #include <assert.h>
20 #include <ctype.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
25 #include "out.h"
26 #include "term.h"
27 #include "mdoc.h"
28 #include "chars.h"
29 #include "main.h"
31 #define INDENT 5
32 #define HALFINDENT 3
34 struct termpair {
35 struct termpair *ppair;
36 int flag;
37 int count;
40 #define DECL_ARGS struct termp *p, \
41 struct termpair *pair, \
42 const struct mdoc_meta *m, \
43 const struct mdoc_node *n
45 struct termact {
46 int (*pre)(DECL_ARGS);
47 void (*post)(DECL_ARGS);
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 *);
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);
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
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);
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);
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 */
265 void
266 terminal_mdoc(void *arg, const struct mdoc *mdoc)
268 const struct mdoc_node *n;
269 const struct mdoc_meta *m;
270 struct termp *p;
272 p = (struct termp *)arg;
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 */
284 n = mdoc_node(mdoc);
285 m = mdoc_meta(mdoc);
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);
294 static void
295 print_mdoc_nodelist(DECL_ARGS)
298 print_mdoc_node(p, pair, m, n);
299 if (n->next)
300 print_mdoc_nodelist(p, pair, m, n->next);
304 /* ARGSUSED */
305 static void
306 print_mdoc_node(DECL_ARGS)
308 int chld;
309 const void *font;
310 struct termpair npair;
311 size_t offset, rmargin;
313 chld = 1;
314 offset = p->offset;
315 rmargin = p->rmargin;
316 font = term_fontq(p);
318 memset(&npair, 0, sizeof(struct termpair));
319 npair.ppair = pair;
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);
327 if (chld && n->child)
328 print_mdoc_nodelist(p, &npair, m, n->child);
330 term_fontpopq(p, font);
332 if (MDOC_TEXT != n->type)
333 if (termacts[n->tok].post)
334 (*termacts[n->tok].post)(p, &npair, m, n);
336 p->offset = offset;
337 p->rmargin = rmargin;
341 /* ARGSUSED */
342 static void
343 print_foot(DECL_ARGS)
345 char buf[DATESIZ], os[BUFSIZ];
347 term_fontrepl(p, TERMFONT_NONE);
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:
354 * SYSTEM DATE SYSTEM
357 time2a(m->date, buf, DATESIZ);
358 strlcpy(os, m->os, BUFSIZ);
360 term_vspace(p);
362 p->offset = 0;
363 p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2;
364 p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
366 term_word(p, os);
367 term_flushln(p);
369 p->offset = p->rmargin;
370 p->rmargin = p->maxrmargin - strlen(os);
371 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
373 term_word(p, buf);
374 term_flushln(p);
376 p->offset = p->rmargin;
377 p->rmargin = p->maxrmargin;
378 p->flags &= ~TERMP_NOBREAK;
379 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
381 term_word(p, os);
382 term_flushln(p);
384 p->offset = 0;
385 p->rmargin = p->maxrmargin;
386 p->flags = 0;
390 /* ARGSUSED */
391 static void
392 print_mdoc_head(DECL_ARGS)
394 char buf[BUFSIZ], title[BUFSIZ];
396 p->rmargin = p->maxrmargin;
397 p->offset = 0;
400 * The header is strange. It has three components, which are
401 * really two with the first duplicated. It goes like this:
403 * IDENTIFIER TITLE IDENTIFIER
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.
412 assert(m->vol);
413 strlcpy(buf, m->vol, BUFSIZ);
415 if (m->arch) {
416 strlcat(buf, " (", BUFSIZ);
417 strlcat(buf, m->arch, BUFSIZ);
418 strlcat(buf, ")", BUFSIZ);
421 snprintf(title, BUFSIZ, "%s(%d)", m->title, m->msec);
423 p->offset = 0;
424 p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2;
425 p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
427 term_word(p, title);
428 term_flushln(p);
430 p->offset = p->rmargin;
431 p->rmargin = p->maxrmargin - strlen(title);
432 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
434 term_word(p, buf);
435 term_flushln(p);
437 p->offset = p->rmargin;
438 p->rmargin = p->maxrmargin;
439 p->flags &= ~TERMP_NOBREAK;
440 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
442 term_word(p, title);
443 term_flushln(p);
445 p->offset = 0;
446 p->rmargin = p->maxrmargin;
447 p->flags &= ~TERMP_NOSPACE;
451 static size_t
452 a2height(const struct mdoc_node *n)
454 struct roffsu su;
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));
461 return(term_vspan(&su));
465 static size_t
466 a2width(const struct mdoc_argv *arg, int pos)
468 struct roffsu su;
470 assert(arg->value[pos]);
471 if ( ! a2roffsu(arg->value[pos], &su, SCALE_MAX))
472 SCALE_HS_INIT(&su, strlen(arg->value[pos]));
474 /* XXX: pachemu? */
475 return(term_hspan(&su) + 2);
479 static int
480 arg_listtype(const struct mdoc_node *n)
482 int i, len;
484 assert(MDOC_BLOCK == n->type);
486 len = (int)(n->args ? n->args->argc : 0);
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;
516 return(-1);
520 static size_t
521 a2offs(const struct mdoc_argv *arg)
523 struct roffsu su;
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]));
536 return(term_hspan(&su));
540 static int
541 arg_hasattr(int arg, const struct mdoc_node *n)
544 return(-1 != arg_getattr(arg, n));
548 static int
549 arg_getattr(int v, const struct mdoc_node *n)
551 int val;
553 return(arg_getattrs(&v, &val, 1, n) ? val : -1);
557 static int
558 arg_getattrs(const int *keys, int *vals,
559 size_t sz, const struct mdoc_node *n)
561 int i, j, k;
563 if (NULL == n->args)
564 return(0);
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++;
572 return(k);
576 static void
577 print_bvspace(struct termp *p,
578 const struct mdoc_node *bl,
579 const struct mdoc_node *n)
581 const struct mdoc_node *nn;
583 term_newln(p);
584 if (arg_hasattr(MDOC_Compact, bl))
585 return;
587 /* Do not vspace directly after Ss/Sh. */
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;
601 /* A `-column' does not assert vspace within the list. */
603 if (MDOC_Bl == bl->tok && arg_hasattr(MDOC_Column, bl))
604 if (n->prev && MDOC_It == n->prev->tok)
605 return;
607 /* A `-diag' without body does not vspace. */
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;
616 term_vspace(p);
620 /* ARGSUSED */
621 static int
622 termp_dq_pre(DECL_ARGS)
625 if (MDOC_BODY != n->type)
626 return(1);
628 term_word(p, "\\(lq");
629 p->flags |= TERMP_NOSPACE;
630 return(1);
634 /* ARGSUSED */
635 static void
636 termp_dq_post(DECL_ARGS)
639 if (MDOC_BODY != n->type)
640 return;
642 p->flags |= TERMP_NOSPACE;
643 term_word(p, "\\(rq");
647 /* ARGSUSED */
648 static int
649 termp_it_pre(DECL_ARGS)
651 const struct mdoc_node *bl, *nn;
652 char buf[7];
653 int i, type, keys[3], vals[3];
654 size_t width, offset;
656 if (MDOC_BLOCK == n->type) {
657 print_bvspace(p, n->parent->parent, n);
658 return(1);
661 bl = n->parent->parent->parent;
663 /* Save parent attributes. */
665 pair->flag = p->flags;
667 /* Get list width and offset. */
669 keys[0] = MDOC_Width;
670 keys[1] = MDOC_Offset;
671 keys[2] = MDOC_Column;
673 vals[0] = vals[1] = vals[2] = -1;
675 width = offset = 0;
677 (void)arg_getattrs(keys, vals, 3, bl);
679 type = arg_listtype(bl);
680 assert(-1 != type);
682 /* Calculate real width and offset. */
684 switch (type) {
685 case (MDOC_Column):
686 if (MDOC_BODY == n->type)
687 break;
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).
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);
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;
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;
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.
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;
754 * Whitespace control. Inset bodies need an initial space,
755 * while diagonal bodies need two.
758 p->flags |= TERMP_NOSPACE;
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;
773 p->flags |= TERMP_NOSPACE;
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;
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.
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;
811 if (MDOC_HEAD != n->type)
812 break;
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.
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;
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;
849 break;
850 case (MDOC_Diag):
851 if (MDOC_HEAD == n->type)
852 p->flags |= TERMP_NOBREAK;
853 break;
854 default:
855 break;
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.
864 p->offset += offset;
866 switch (type) {
867 case (MDOC_Hang):
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.
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;
897 * XXX - this behaviour is not documented: the
898 * right-most column is filled to the right margin.
900 if (MDOC_HEAD == n->type &&
901 MDOC_BODY == n->next->type)
902 p->rmargin = p->maxrmargin;
903 break;
904 default:
905 break;
909 * The dash, hyphen, bullet and enum lists all have a special
910 * HEAD character (temporarily bold, in some cases).
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;
938 * If we're not going to process our children, indicate so here.
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;
962 return(1);
966 /* ARGSUSED */
967 static void
968 termp_it_post(DECL_ARGS)
970 int type;
972 if (MDOC_BODY != n->type && MDOC_HEAD != n->type)
973 return;
975 type = arg_listtype(n->parent->parent->parent);
976 assert(-1 != type);
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;
996 p->flags = pair->flag;
1000 /* ARGSUSED */
1001 static int
1002 termp_nm_pre(DECL_ARGS)
1005 if (SEC_SYNOPSIS == n->sec)
1006 term_newln(p);
1008 term_fontpush(p, TERMFONT_BOLD);
1010 if (NULL == n->child)
1011 term_word(p, m->name);
1012 return(1);
1016 /* ARGSUSED */
1017 static int
1018 termp_fl_pre(DECL_ARGS)
1021 term_fontpush(p, TERMFONT_BOLD);
1022 term_word(p, "\\-");
1023 p->flags |= TERMP_NOSPACE;
1024 return(1);
1028 /* ARGSUSED */
1029 static int
1030 termp_an_pre(DECL_ARGS)
1033 if (NULL == n->child)
1034 return(1);
1037 * If not in the AUTHORS section, `An -split' will cause
1038 * newlines to occur before the author name. If in the AUTHORS
1039 * section, by default, the first `An' invocation is nosplit,
1040 * then all subsequent ones, regardless of whether interspersed
1041 * with other macros/text, are split. -split, in this case,
1042 * will override the condition of the implied first -nosplit.
1045 if (n->sec == SEC_AUTHORS) {
1046 if ( ! (TERMP_ANPREC & p->flags)) {
1047 if (TERMP_SPLIT & p->flags)
1048 term_newln(p);
1049 return(1);
1051 if (TERMP_NOSPLIT & p->flags)
1052 return(1);
1053 term_newln(p);
1054 return(1);
1057 if (TERMP_SPLIT & p->flags)
1058 term_newln(p);
1060 return(1);
1064 /* ARGSUSED */
1065 static void
1066 termp_an_post(DECL_ARGS)
1069 if (n->child) {
1070 if (SEC_AUTHORS == n->sec)
1071 p->flags |= TERMP_ANPREC;
1072 return;
1075 if (arg_getattr(MDOC_Split, n) > -1) {
1076 p->flags &= ~TERMP_NOSPLIT;
1077 p->flags |= TERMP_SPLIT;
1078 } else {
1079 p->flags &= ~TERMP_SPLIT;
1080 p->flags |= TERMP_NOSPLIT;
1086 /* ARGSUSED */
1087 static int
1088 termp_ns_pre(DECL_ARGS)
1091 p->flags |= TERMP_NOSPACE;
1092 return(1);
1096 /* ARGSUSED */
1097 static int
1098 termp_rs_pre(DECL_ARGS)
1101 if (SEC_SEE_ALSO != n->sec)
1102 return(1);
1103 if (MDOC_BLOCK == n->type && n->prev)
1104 term_vspace(p);
1105 return(1);
1109 /* ARGSUSED */
1110 static int
1111 termp_rv_pre(DECL_ARGS)
1113 const struct mdoc_node *nn;
1115 term_newln(p);
1116 term_word(p, "The");
1118 for (nn = n->child; nn; nn = nn->next) {
1119 term_fontpush(p, TERMFONT_BOLD);
1120 term_word(p, nn->string);
1121 term_fontpop(p);
1122 p->flags |= TERMP_NOSPACE;
1123 if (nn->next && NULL == nn->next->next)
1124 term_word(p, "(), and");
1125 else if (nn->next)
1126 term_word(p, "(),");
1127 else
1128 term_word(p, "()");
1131 if (n->child->next)
1132 term_word(p, "functions return");
1133 else
1134 term_word(p, "function returns");
1136 term_word(p, "the value 0 if successful; otherwise the value "
1137 "-1 is returned and the global variable");
1139 term_fontpush(p, TERMFONT_UNDER);
1140 term_word(p, "errno");
1141 term_fontpop(p);
1143 term_word(p, "is set to indicate the error.");
1145 return(0);
1149 /* ARGSUSED */
1150 static int
1151 termp_ex_pre(DECL_ARGS)
1153 const struct mdoc_node *nn;
1155 term_word(p, "The");
1157 for (nn = n->child; nn; nn = nn->next) {
1158 term_fontpush(p, TERMFONT_BOLD);
1159 term_word(p, nn->string);
1160 term_fontpop(p);
1161 p->flags |= TERMP_NOSPACE;
1162 if (nn->next && NULL == nn->next->next)
1163 term_word(p, ", and");
1164 else if (nn->next)
1165 term_word(p, ",");
1166 else
1167 p->flags &= ~TERMP_NOSPACE;
1170 if (n->child->next)
1171 term_word(p, "utilities exit");
1172 else
1173 term_word(p, "utility exits");
1175 term_word(p, "0 on success, and >0 if an error occurs.");
1177 return(0);
1181 /* ARGSUSED */
1182 static int
1183 termp_nd_pre(DECL_ARGS)
1186 if (MDOC_BODY != n->type)
1187 return(1);
1189 #if defined(__OpenBSD__) || defined(__linux__)
1190 term_word(p, "\\(en");
1191 #else
1192 term_word(p, "\\(em");
1193 #endif
1194 return(1);
1198 /* ARGSUSED */
1199 static void
1200 termp_bl_post(DECL_ARGS)
1203 if (MDOC_BLOCK == n->type)
1204 term_newln(p);
1208 /* ARGSUSED */
1209 static void
1210 termp_op_post(DECL_ARGS)
1213 if (MDOC_BODY != n->type)
1214 return;
1215 p->flags |= TERMP_NOSPACE;
1216 term_word(p, "\\(rB");
1220 /* ARGSUSED */
1221 static int
1222 termp_xr_pre(DECL_ARGS)
1224 const struct mdoc_node *nn;
1226 assert(n->child && MDOC_TEXT == n->child->type);
1227 nn = n->child;
1229 term_word(p, nn->string);
1230 if (NULL == (nn = nn->next))
1231 return(0);
1232 p->flags |= TERMP_NOSPACE;
1233 term_word(p, "(");
1234 p->flags |= TERMP_NOSPACE;
1235 term_word(p, nn->string);
1236 p->flags |= TERMP_NOSPACE;
1237 term_word(p, ")");
1239 return(0);
1243 /* ARGSUSED */
1244 static void
1245 termp_vt_post(DECL_ARGS)
1248 if (n->sec != SEC_SYNOPSIS)
1249 return;
1250 if (n->next && MDOC_Vt == n->next->tok)
1251 term_newln(p);
1252 else if (n->next)
1253 term_vspace(p);
1257 /* ARGSUSED */
1258 static int
1259 termp_bold_pre(DECL_ARGS)
1262 term_fontpush(p, TERMFONT_BOLD);
1263 return(1);
1267 /* ARGSUSED */
1268 static void
1269 termp_fd_post(DECL_ARGS)
1272 if (n->sec != SEC_SYNOPSIS)
1273 return;
1275 term_newln(p);
1276 if (n->next && MDOC_Fd != n->next->tok)
1277 term_vspace(p);
1281 /* ARGSUSED */
1282 static int
1283 termp_sh_pre(DECL_ARGS)
1286 /* No vspace between consecutive `Sh' calls. */
1288 switch (n->type) {
1289 case (MDOC_BLOCK):
1290 if (n->prev && MDOC_Sh == n->prev->tok)
1291 if (NULL == n->prev->body->child)
1292 break;
1293 term_vspace(p);
1294 break;
1295 case (MDOC_HEAD):
1296 term_fontpush(p, TERMFONT_BOLD);
1297 break;
1298 case (MDOC_BODY):
1299 p->offset = INDENT;
1300 break;
1301 default:
1302 break;
1304 return(1);
1308 /* ARGSUSED */
1309 static void
1310 termp_sh_post(DECL_ARGS)
1313 switch (n->type) {
1314 case (MDOC_HEAD):
1315 term_newln(p);
1316 break;
1317 case (MDOC_BODY):
1318 term_newln(p);
1319 p->offset = 0;
1320 break;
1321 default:
1322 break;
1327 /* ARGSUSED */
1328 static int
1329 termp_op_pre(DECL_ARGS)
1332 switch (n->type) {
1333 case (MDOC_BODY):
1334 term_word(p, "\\(lB");
1335 p->flags |= TERMP_NOSPACE;
1336 break;
1337 default:
1338 break;
1340 return(1);
1344 /* ARGSUSED */
1345 static int
1346 termp_bt_pre(DECL_ARGS)
1349 term_word(p, "is currently in beta test.");
1350 return(0);
1354 /* ARGSUSED */
1355 static void
1356 termp_lb_post(DECL_ARGS)
1359 if (SEC_LIBRARY == n->sec)
1360 term_newln(p);
1364 /* ARGSUSED */
1365 static int
1366 termp_ud_pre(DECL_ARGS)
1369 term_word(p, "currently under development.");
1370 return(0);
1374 /* ARGSUSED */
1375 static int
1376 termp_d1_pre(DECL_ARGS)
1379 if (MDOC_BLOCK != n->type)
1380 return(1);
1381 term_newln(p);
1382 p->offset += (INDENT + 1);
1383 return(1);
1387 /* ARGSUSED */
1388 static void
1389 termp_d1_post(DECL_ARGS)
1392 if (MDOC_BLOCK != n->type)
1393 return;
1394 term_newln(p);
1398 /* ARGSUSED */
1399 static int
1400 termp_aq_pre(DECL_ARGS)
1403 if (MDOC_BODY != n->type)
1404 return(1);
1405 term_word(p, "\\(la");
1406 p->flags |= TERMP_NOSPACE;
1407 return(1);
1411 /* ARGSUSED */
1412 static void
1413 termp_aq_post(DECL_ARGS)
1416 if (MDOC_BODY != n->type)
1417 return;
1418 p->flags |= TERMP_NOSPACE;
1419 term_word(p, "\\(ra");
1423 /* ARGSUSED */
1424 static int
1425 termp_ft_pre(DECL_ARGS)
1428 if (SEC_SYNOPSIS == n->sec)
1429 if (n->prev && MDOC_Fo == n->prev->tok)
1430 term_vspace(p);
1432 term_fontpush(p, TERMFONT_UNDER);
1433 return(1);
1437 /* ARGSUSED */
1438 static void
1439 termp_ft_post(DECL_ARGS)
1442 if (SEC_SYNOPSIS == n->sec)
1443 term_newln(p);
1447 /* ARGSUSED */
1448 static int
1449 termp_fn_pre(DECL_ARGS)
1451 const struct mdoc_node *nn;
1453 term_fontpush(p, TERMFONT_BOLD);
1454 term_word(p, n->child->string);
1455 term_fontpop(p);
1457 p->flags |= TERMP_NOSPACE;
1458 term_word(p, "(");
1460 for (nn = n->child->next; nn; nn = nn->next) {
1461 term_fontpush(p, TERMFONT_UNDER);
1462 term_word(p, nn->string);
1463 term_fontpop(p);
1465 if (nn->next)
1466 term_word(p, ",");
1469 term_word(p, ")");
1471 if (SEC_SYNOPSIS == n->sec)
1472 term_word(p, ";");
1474 return(0);
1478 /* ARGSUSED */
1479 static void
1480 termp_fn_post(DECL_ARGS)
1483 if (n->sec == SEC_SYNOPSIS && n->next)
1484 term_vspace(p);
1488 /* ARGSUSED */
1489 static int
1490 termp_fa_pre(DECL_ARGS)
1492 const struct mdoc_node *nn;
1494 if (n->parent->tok != MDOC_Fo) {
1495 term_fontpush(p, TERMFONT_UNDER);
1496 return(1);
1499 for (nn = n->child; nn; nn = nn->next) {
1500 term_fontpush(p, TERMFONT_UNDER);
1501 term_word(p, nn->string);
1502 term_fontpop(p);
1504 if (nn->next)
1505 term_word(p, ",");
1508 if (n->child && n->next && n->next->tok == MDOC_Fa)
1509 term_word(p, ",");
1511 return(0);
1515 /* ARGSUSED */
1516 static int
1517 termp_bd_pre(DECL_ARGS)
1519 int i, type;
1520 const struct mdoc_node *nn;
1522 if (MDOC_BLOCK == n->type) {
1523 print_bvspace(p, n, n);
1524 return(1);
1525 } else if (MDOC_BODY != n->type)
1526 return(1);
1528 nn = n->parent;
1530 for (type = -1, i = 0; i < (int)nn->args->argc; i++) {
1531 switch (nn->args->argv[i].arg) {
1532 case (MDOC_Centred):
1533 /* FALLTHROUGH */
1534 case (MDOC_Ragged):
1535 /* FALLTHROUGH */
1536 case (MDOC_Filled):
1537 /* FALLTHROUGH */
1538 case (MDOC_Unfilled):
1539 /* FALLTHROUGH */
1540 case (MDOC_Literal):
1541 type = nn->args->argv[i].arg;
1542 break;
1543 case (MDOC_Offset):
1544 p->offset += a2offs(&nn->args->argv[i]);
1545 break;
1546 default:
1547 break;
1552 * If -ragged or -filled are specified, the block does nothing
1553 * but change the indentation. If -unfilled or -literal are
1554 * specified, text is printed exactly as entered in the display:
1555 * for macro lines, a newline is appended to the line. Blank
1556 * lines are allowed.
1559 assert(type > -1);
1560 if (MDOC_Literal != type && MDOC_Unfilled != type)
1561 return(1);
1563 for (nn = n->child; nn; nn = nn->next) {
1564 p->flags |= TERMP_NOSPACE;
1565 print_mdoc_node(p, pair, m, nn);
1566 if (NULL == nn->next)
1567 continue;
1568 if (nn->prev && nn->prev->line < nn->line)
1569 term_flushln(p);
1570 else if (NULL == nn->prev)
1571 term_flushln(p);
1574 return(0);
1578 /* ARGSUSED */
1579 static void
1580 termp_bd_post(DECL_ARGS)
1583 if (MDOC_BODY != n->type)
1584 return;
1585 p->flags |= TERMP_NOSPACE;
1586 term_flushln(p);
1590 /* ARGSUSED */
1591 static int
1592 termp_qq_pre(DECL_ARGS)
1595 if (MDOC_BODY != n->type)
1596 return(1);
1597 term_word(p, "\"");
1598 p->flags |= TERMP_NOSPACE;
1599 return(1);
1603 /* ARGSUSED */
1604 static void
1605 termp_qq_post(DECL_ARGS)
1608 if (MDOC_BODY != n->type)
1609 return;
1610 p->flags |= TERMP_NOSPACE;
1611 term_word(p, "\"");
1615 /* ARGSUSED */
1616 static void
1617 termp_bx_post(DECL_ARGS)
1620 if (n->child)
1621 p->flags |= TERMP_NOSPACE;
1622 term_word(p, "BSD");
1626 /* ARGSUSED */
1627 static int
1628 termp_xx_pre(DECL_ARGS)
1630 const char *pp;
1632 pp = NULL;
1633 switch (n->tok) {
1634 case (MDOC_Bsx):
1635 pp = "BSDI BSD/OS";
1636 break;
1637 case (MDOC_Dx):
1638 pp = "DragonFly";
1639 break;
1640 case (MDOC_Fx):
1641 pp = "FreeBSD";
1642 break;
1643 case (MDOC_Nx):
1644 pp = "NetBSD";
1645 break;
1646 case (MDOC_Ox):
1647 pp = "OpenBSD";
1648 break;
1649 case (MDOC_Ux):
1650 pp = "UNIX";
1651 break;
1652 default:
1653 break;
1656 assert(pp);
1657 term_word(p, pp);
1658 return(1);
1662 /* ARGSUSED */
1663 static int
1664 termp_sq_pre(DECL_ARGS)
1667 if (MDOC_BODY != n->type)
1668 return(1);
1669 term_word(p, "\\(oq");
1670 p->flags |= TERMP_NOSPACE;
1671 return(1);
1675 /* ARGSUSED */
1676 static void
1677 termp_sq_post(DECL_ARGS)
1680 if (MDOC_BODY != n->type)
1681 return;
1682 p->flags |= TERMP_NOSPACE;
1683 term_word(p, "\\(aq");
1687 /* ARGSUSED */
1688 static int
1689 termp_pf_pre(DECL_ARGS)
1692 p->flags |= TERMP_IGNDELIM;
1693 return(1);
1697 /* ARGSUSED */
1698 static void
1699 termp_pf_post(DECL_ARGS)
1702 p->flags &= ~TERMP_IGNDELIM;
1703 p->flags |= TERMP_NOSPACE;
1707 /* ARGSUSED */
1708 static int
1709 termp_ss_pre(DECL_ARGS)
1712 switch (n->type) {
1713 case (MDOC_BLOCK):
1714 term_newln(p);
1715 if (n->prev)
1716 term_vspace(p);
1717 break;
1718 case (MDOC_HEAD):
1719 term_fontpush(p, TERMFONT_BOLD);
1720 p->offset = HALFINDENT;
1721 break;
1722 default:
1723 break;
1726 return(1);
1730 /* ARGSUSED */
1731 static void
1732 termp_ss_post(DECL_ARGS)
1735 if (MDOC_HEAD == n->type)
1736 term_newln(p);
1740 /* ARGSUSED */
1741 static int
1742 termp_cd_pre(DECL_ARGS)
1745 term_fontpush(p, TERMFONT_BOLD);
1746 term_newln(p);
1747 return(1);
1751 /* ARGSUSED */
1752 static int
1753 termp_in_pre(DECL_ARGS)
1756 term_fontpush(p, TERMFONT_BOLD);
1757 if (SEC_SYNOPSIS == n->sec)
1758 term_word(p, "#include");
1760 term_word(p, "<");
1761 p->flags |= TERMP_NOSPACE;
1762 return(1);
1766 /* ARGSUSED */
1767 static void
1768 termp_in_post(DECL_ARGS)
1771 term_fontpush(p, TERMFONT_BOLD);
1772 p->flags |= TERMP_NOSPACE;
1773 term_word(p, ">");
1774 term_fontpop(p);
1776 if (SEC_SYNOPSIS != n->sec)
1777 return;
1779 term_newln(p);
1781 * XXX Not entirely correct. If `.In foo bar' is specified in
1782 * the SYNOPSIS section, then it produces a single break after
1783 * the <foo>; mandoc asserts a vertical space. Since this
1784 * construction is rarely used, I think it's fine.
1786 if (n->next && MDOC_In != n->next->tok)
1787 term_vspace(p);
1791 /* ARGSUSED */
1792 static int
1793 termp_sp_pre(DECL_ARGS)
1795 size_t i, len;
1797 switch (n->tok) {
1798 case (MDOC_sp):
1799 len = n->child ? a2height(n->child) : 1;
1800 break;
1801 case (MDOC_br):
1802 len = 0;
1803 break;
1804 default:
1805 len = 1;
1806 break;
1809 if (0 == len)
1810 term_newln(p);
1811 for (i = 0; i < len; i++)
1812 term_vspace(p);
1814 return(0);
1818 /* ARGSUSED */
1819 static int
1820 termp_brq_pre(DECL_ARGS)
1823 if (MDOC_BODY != n->type)
1824 return(1);
1825 term_word(p, "\\(lC");
1826 p->flags |= TERMP_NOSPACE;
1827 return(1);
1831 /* ARGSUSED */
1832 static void
1833 termp_brq_post(DECL_ARGS)
1836 if (MDOC_BODY != n->type)
1837 return;
1838 p->flags |= TERMP_NOSPACE;
1839 term_word(p, "\\(rC");
1843 /* ARGSUSED */
1844 static int
1845 termp_bq_pre(DECL_ARGS)
1848 if (MDOC_BODY != n->type)
1849 return(1);
1850 term_word(p, "\\(lB");
1851 p->flags |= TERMP_NOSPACE;
1852 return(1);
1856 /* ARGSUSED */
1857 static void
1858 termp_bq_post(DECL_ARGS)
1861 if (MDOC_BODY != n->type)
1862 return;
1863 p->flags |= TERMP_NOSPACE;
1864 term_word(p, "\\(rB");
1868 /* ARGSUSED */
1869 static int
1870 termp_pq_pre(DECL_ARGS)
1873 if (MDOC_BODY != n->type)
1874 return(1);
1875 term_word(p, "\\&(");
1876 p->flags |= TERMP_NOSPACE;
1877 return(1);
1881 /* ARGSUSED */
1882 static void
1883 termp_pq_post(DECL_ARGS)
1886 if (MDOC_BODY != n->type)
1887 return;
1888 term_word(p, ")");
1892 /* ARGSUSED */
1893 static int
1894 termp_fo_pre(DECL_ARGS)
1896 const struct mdoc_node *nn;
1898 if (MDOC_BODY == n->type) {
1899 p->flags |= TERMP_NOSPACE;
1900 term_word(p, "(");
1901 p->flags |= TERMP_NOSPACE;
1902 return(1);
1903 } else if (MDOC_HEAD != n->type)
1904 return(1);
1906 term_fontpush(p, TERMFONT_BOLD);
1907 for (nn = n->child; nn; nn = nn->next) {
1908 assert(MDOC_TEXT == nn->type);
1909 term_word(p, nn->string);
1911 term_fontpop(p);
1913 return(0);
1917 /* ARGSUSED */
1918 static void
1919 termp_fo_post(DECL_ARGS)
1922 if (MDOC_BODY != n->type)
1923 return;
1924 p->flags |= TERMP_NOSPACE;
1925 term_word(p, ")");
1926 p->flags |= TERMP_NOSPACE;
1927 term_word(p, ";");
1928 term_newln(p);
1932 /* ARGSUSED */
1933 static int
1934 termp_bf_pre(DECL_ARGS)
1936 const struct mdoc_node *nn;
1938 if (MDOC_HEAD == n->type)
1939 return(0);
1940 else if (MDOC_BLOCK != n->type)
1941 return(1);
1943 if (NULL == (nn = n->head->child)) {
1944 if (arg_hasattr(MDOC_Emphasis, n))
1945 term_fontpush(p, TERMFONT_UNDER);
1946 else if (arg_hasattr(MDOC_Symbolic, n))
1947 term_fontpush(p, TERMFONT_BOLD);
1948 else
1949 term_fontpush(p, TERMFONT_NONE);
1951 return(1);
1954 assert(MDOC_TEXT == nn->type);
1955 if (0 == strcmp("Em", nn->string))
1956 term_fontpush(p, TERMFONT_UNDER);
1957 else if (0 == strcmp("Sy", nn->string))
1958 term_fontpush(p, TERMFONT_BOLD);
1959 else
1960 term_fontpush(p, TERMFONT_NONE);
1962 return(1);
1966 /* ARGSUSED */
1967 static int
1968 termp_sm_pre(DECL_ARGS)
1971 assert(n->child && MDOC_TEXT == n->child->type);
1972 if (0 == strcmp("on", n->child->string)) {
1973 p->flags &= ~TERMP_NONOSPACE;
1974 p->flags &= ~TERMP_NOSPACE;
1975 } else
1976 p->flags |= TERMP_NONOSPACE;
1978 return(0);
1982 /* ARGSUSED */
1983 static int
1984 termp_ap_pre(DECL_ARGS)
1987 p->flags |= TERMP_NOSPACE;
1988 term_word(p, "\\(aq");
1989 p->flags |= TERMP_NOSPACE;
1990 return(1);
1994 /* ARGSUSED */
1995 static void
1996 termp____post(DECL_ARGS)
1999 /* TODO: %U. */
2001 p->flags |= TERMP_NOSPACE;
2002 switch (n->tok) {
2003 case (MDOC__T):
2004 term_word(p, "\\(rq");
2005 p->flags |= TERMP_NOSPACE;
2006 break;
2007 default:
2008 break;
2010 term_word(p, n->next ? "," : ".");
2014 /* ARGSUSED */
2015 static int
2016 termp_li_pre(DECL_ARGS)
2019 term_fontpush(p, TERMFONT_NONE);
2020 return(1);
2024 /* ARGSUSED */
2025 static int
2026 termp_lk_pre(DECL_ARGS)
2028 const struct mdoc_node *nn;
2030 term_fontpush(p, TERMFONT_UNDER);
2031 nn = n->child;
2033 if (NULL == nn->next)
2034 return(1);
2036 term_word(p, nn->string);
2037 term_fontpop(p);
2039 p->flags |= TERMP_NOSPACE;
2040 term_word(p, ":");
2042 term_fontpush(p, TERMFONT_BOLD);
2043 for (nn = nn->next; nn; nn = nn->next)
2044 term_word(p, nn->string);
2045 term_fontpop(p);
2047 return(0);
2051 /* ARGSUSED */
2052 static int
2053 termp_under_pre(DECL_ARGS)
2056 term_fontpush(p, TERMFONT_UNDER);
2057 return(1);
2061 /* ARGSUSED */
2062 static int
2063 termp__t_pre(DECL_ARGS)
2066 term_word(p, "\\(lq");
2067 p->flags |= TERMP_NOSPACE;
2068 return(1);