1 /* $Id: mdoc_term.c,v 1.62 2009/10/27 21:40:07 schwarze Exp $ */
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>
36 struct termpair *ppair;
41 #define DECL_ARGS struct termp *p, \
42 struct termpair *pair, \
43 const struct mdoc_meta *m, \
44 const struct mdoc_node *n
47 int (*pre)(DECL_ARGS);
48 void (*post)(DECL_ARGS);
51 static size_t a2width(const struct mdoc_argv *, int);
52 static size_t a2height(const struct mdoc_node *);
53 static size_t a2offs(const struct mdoc_argv *);
55 static int arg_hasattr(int, const struct mdoc_node *);
56 static int arg_getattrs(const int *, int *, size_t,
57 const struct mdoc_node *);
58 static int arg_getattr(int, const struct mdoc_node *);
59 static int arg_listtype(const struct mdoc_node *);
60 static void print_bvspace(struct termp *,
61 const struct mdoc_node *,
62 const struct mdoc_node *);
63 static void print_node(DECL_ARGS);
64 static void print_head(DECL_ARGS);
65 static void print_body(DECL_ARGS);
66 static void print_foot(DECL_ARGS);
68 static void termp____post(DECL_ARGS);
69 static void termp_an_post(DECL_ARGS);
70 static void termp_aq_post(DECL_ARGS);
71 static void termp_bd_post(DECL_ARGS);
72 static void termp_bl_post(DECL_ARGS);
73 static void termp_bq_post(DECL_ARGS);
74 static void termp_brq_post(DECL_ARGS);
75 static void termp_bx_post(DECL_ARGS);
76 static void termp_d1_post(DECL_ARGS);
77 static void termp_dq_post(DECL_ARGS);
78 static void termp_fd_post(DECL_ARGS);
79 static void termp_fn_post(DECL_ARGS);
80 static void termp_fo_post(DECL_ARGS);
81 static void termp_ft_post(DECL_ARGS);
82 static void termp_in_post(DECL_ARGS);
83 static void termp_it_post(DECL_ARGS);
84 static void termp_lb_post(DECL_ARGS);
85 static void termp_op_post(DECL_ARGS);
86 static void termp_pf_post(DECL_ARGS);
87 static void termp_pq_post(DECL_ARGS);
88 static void termp_qq_post(DECL_ARGS);
89 static void termp_sh_post(DECL_ARGS);
90 static void termp_sq_post(DECL_ARGS);
91 static void termp_ss_post(DECL_ARGS);
92 static void termp_vt_post(DECL_ARGS);
94 static int termp__t_pre(DECL_ARGS);
95 static int termp_an_pre(DECL_ARGS);
96 static int termp_ap_pre(DECL_ARGS);
97 static int termp_aq_pre(DECL_ARGS);
98 static int termp_bd_pre(DECL_ARGS);
99 static int termp_bf_pre(DECL_ARGS);
100 static int termp_bold_pre(DECL_ARGS);
101 static int termp_bq_pre(DECL_ARGS);
102 static int termp_brq_pre(DECL_ARGS);
103 static int termp_bt_pre(DECL_ARGS);
104 static int termp_cd_pre(DECL_ARGS);
105 static int termp_d1_pre(DECL_ARGS);
106 static int termp_dq_pre(DECL_ARGS);
107 static int termp_ex_pre(DECL_ARGS);
108 static int termp_fa_pre(DECL_ARGS);
109 static int termp_fl_pre(DECL_ARGS);
110 static int termp_fn_pre(DECL_ARGS);
111 static int termp_fo_pre(DECL_ARGS);
112 static int termp_ft_pre(DECL_ARGS);
113 static int termp_in_pre(DECL_ARGS);
114 static int termp_it_pre(DECL_ARGS);
115 static int termp_lk_pre(DECL_ARGS);
116 static int termp_nd_pre(DECL_ARGS);
117 static int termp_nm_pre(DECL_ARGS);
118 static int termp_ns_pre(DECL_ARGS);
119 static int termp_op_pre(DECL_ARGS);
120 static int termp_pf_pre(DECL_ARGS);
121 static int termp_pq_pre(DECL_ARGS);
122 static int termp_qq_pre(DECL_ARGS);
123 static int termp_rs_pre(DECL_ARGS);
124 static int termp_rv_pre(DECL_ARGS);
125 static int termp_sh_pre(DECL_ARGS);
126 static int termp_sm_pre(DECL_ARGS);
127 static int termp_sp_pre(DECL_ARGS);
128 static int termp_sq_pre(DECL_ARGS);
129 static int termp_ss_pre(DECL_ARGS);
130 static int termp_under_pre(DECL_ARGS);
131 static int termp_ud_pre(DECL_ARGS);
132 static int termp_xr_pre(DECL_ARGS);
133 static int termp_xx_pre(DECL_ARGS);
135 static const struct termact termacts[MDOC_MAX] = {
136 { termp_ap_pre, NULL }, /* Ap */
137 { NULL, NULL }, /* Dd */
138 { NULL, NULL }, /* Dt */
139 { NULL, NULL }, /* Os */
140 { termp_sh_pre, termp_sh_post }, /* Sh */
141 { termp_ss_pre, termp_ss_post }, /* Ss */
142 { termp_sp_pre, NULL }, /* Pp */
143 { termp_d1_pre, termp_d1_post }, /* D1 */
144 { termp_d1_pre, termp_d1_post }, /* Dl */
145 { termp_bd_pre, termp_bd_post }, /* Bd */
146 { NULL, NULL }, /* Ed */
147 { NULL, termp_bl_post }, /* Bl */
148 { NULL, NULL }, /* El */
149 { termp_it_pre, termp_it_post }, /* It */
150 { NULL, NULL }, /* Ad */
151 { termp_an_pre, termp_an_post }, /* An */
152 { termp_under_pre, NULL }, /* Ar */
153 { termp_cd_pre, NULL }, /* Cd */
154 { termp_bold_pre, NULL }, /* Cm */
155 { NULL, NULL }, /* Dv */
156 { NULL, NULL }, /* Er */
157 { NULL, NULL }, /* Ev */
158 { termp_ex_pre, NULL }, /* Ex */
159 { termp_fa_pre, NULL }, /* Fa */
160 { termp_bold_pre, termp_fd_post }, /* Fd */
161 { termp_fl_pre, NULL }, /* Fl */
162 { termp_fn_pre, termp_fn_post }, /* Fn */
163 { termp_ft_pre, termp_ft_post }, /* Ft */
164 { termp_bold_pre, NULL }, /* Ic */
165 { termp_in_pre, termp_in_post }, /* In */
166 { NULL, NULL }, /* Li */
167 { termp_nd_pre, NULL }, /* Nd */
168 { termp_nm_pre, NULL }, /* Nm */
169 { termp_op_pre, termp_op_post }, /* Op */
170 { NULL, NULL }, /* Ot */
171 { termp_under_pre, NULL }, /* Pa */
172 { termp_rv_pre, NULL }, /* Rv */
173 { NULL, NULL }, /* St */
174 { termp_under_pre, NULL }, /* Va */
175 { termp_under_pre, termp_vt_post }, /* Vt */
176 { termp_xr_pre, NULL }, /* Xr */
177 { NULL, termp____post }, /* %A */
178 { termp_under_pre, termp____post }, /* %B */
179 { NULL, termp____post }, /* %D */
180 { termp_under_pre, termp____post }, /* %I */
181 { termp_under_pre, termp____post }, /* %J */
182 { NULL, termp____post }, /* %N */
183 { NULL, termp____post }, /* %O */
184 { NULL, termp____post }, /* %P */
185 { NULL, termp____post }, /* %R */
186 { termp__t_pre, termp____post }, /* %T */
187 { NULL, termp____post }, /* %V */
188 { NULL, NULL }, /* Ac */
189 { termp_aq_pre, termp_aq_post }, /* Ao */
190 { termp_aq_pre, termp_aq_post }, /* Aq */
191 { NULL, NULL }, /* At */
192 { NULL, NULL }, /* Bc */
193 { termp_bf_pre, NULL }, /* Bf */
194 { termp_bq_pre, termp_bq_post }, /* Bo */
195 { termp_bq_pre, termp_bq_post }, /* Bq */
196 { termp_xx_pre, NULL }, /* Bsx */
197 { NULL, termp_bx_post }, /* Bx */
198 { NULL, NULL }, /* Db */
199 { NULL, NULL }, /* Dc */
200 { termp_dq_pre, termp_dq_post }, /* Do */
201 { termp_dq_pre, termp_dq_post }, /* Dq */
202 { NULL, NULL }, /* Ec */
203 { NULL, NULL }, /* Ef */
204 { termp_under_pre, NULL }, /* Em */
205 { NULL, NULL }, /* Eo */
206 { termp_xx_pre, NULL }, /* Fx */
207 { termp_bold_pre, NULL }, /* Ms */ /* FIXME: convert to symbol? */
208 { NULL, NULL }, /* No */
209 { termp_ns_pre, NULL }, /* Ns */
210 { termp_xx_pre, NULL }, /* Nx */
211 { termp_xx_pre, NULL }, /* Ox */
212 { NULL, NULL }, /* Pc */
213 { termp_pf_pre, termp_pf_post }, /* Pf */
214 { termp_pq_pre, termp_pq_post }, /* Po */
215 { termp_pq_pre, termp_pq_post }, /* Pq */
216 { NULL, NULL }, /* Qc */
217 { termp_sq_pre, termp_sq_post }, /* Ql */
218 { termp_qq_pre, termp_qq_post }, /* Qo */
219 { termp_qq_pre, termp_qq_post }, /* Qq */
220 { NULL, NULL }, /* Re */
221 { termp_rs_pre, NULL }, /* Rs */
222 { NULL, NULL }, /* Sc */
223 { termp_sq_pre, termp_sq_post }, /* So */
224 { termp_sq_pre, termp_sq_post }, /* Sq */
225 { termp_sm_pre, NULL }, /* Sm */
226 { termp_under_pre, NULL }, /* Sx */
227 { termp_bold_pre, NULL }, /* Sy */
228 { NULL, NULL }, /* Tn */
229 { termp_xx_pre, NULL }, /* Ux */
230 { NULL, NULL }, /* Xc */
231 { NULL, NULL }, /* Xo */
232 { termp_fo_pre, termp_fo_post }, /* Fo */
233 { NULL, NULL }, /* Fc */
234 { termp_op_pre, termp_op_post }, /* Oo */
235 { NULL, NULL }, /* Oc */
236 { NULL, NULL }, /* Bk */
237 { NULL, NULL }, /* Ek */
238 { termp_bt_pre, NULL }, /* Bt */
239 { NULL, NULL }, /* Hf */
240 { NULL, NULL }, /* Fr */
241 { termp_ud_pre, NULL }, /* Ud */
242 { NULL, termp_lb_post }, /* Lb */
243 { termp_sp_pre, NULL }, /* Lp */
244 { termp_lk_pre, NULL }, /* Lk */
245 { termp_under_pre, NULL }, /* Mt */
246 { termp_brq_pre, termp_brq_post }, /* Brq */
247 { termp_brq_pre, termp_brq_post }, /* Bro */
248 { NULL, NULL }, /* Brc */
249 { NULL, termp____post }, /* %C */
250 { NULL, NULL }, /* Es */ /* TODO */
251 { NULL, NULL }, /* En */ /* TODO */
252 { termp_xx_pre, NULL }, /* Dx */
253 { NULL, termp____post }, /* %Q */
254 { termp_sp_pre, NULL }, /* br */
255 { termp_sp_pre, NULL }, /* sp */
256 { termp_under_pre, termp____post }, /* %U */
261 terminal_mdoc(void *arg, const struct mdoc *mdoc)
263 const struct mdoc_node *n;
264 const struct mdoc_meta *m;
267 p = (struct termp *)arg;
269 if (NULL == p->symtab)
271 case (TERMENC_ASCII):
272 p->symtab = chars_init(CHARS_ASCII);
282 print_head(p, NULL, m, n);
284 print_body(p, NULL, m, n->child);
285 print_foot(p, NULL, m, n);
290 print_body(DECL_ARGS)
293 print_node(p, pair, m, n);
295 print_body(p, pair, m, n->next);
301 print_node(DECL_ARGS)
303 int chld, bold, under;
304 struct termpair npair;
305 size_t offset, rmargin;
309 rmargin = p->rmargin;
313 bzero(&npair, sizeof(struct termpair));
316 if (MDOC_TEXT != n->type) {
317 if (termacts[n->tok].pre)
318 chld = (*termacts[n->tok].pre)(p, &npair, m, n);
320 term_word(p, n->string);
321 if (chld && n->child)
322 print_body(p, &npair, m, n->child);
325 * XXX - if bold/under were to span scopes, this wouldn't be
326 * possible, but because decoration is always in-scope, we can
327 * get away with this.
333 if (MDOC_TEXT != n->type)
334 if (termacts[n->tok].post)
335 (*termacts[n->tok].post)(p, &npair, m, n);
338 p->rmargin = rmargin;
344 print_foot(DECL_ARGS)
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:
357 if (NULL == (os = malloc(p->rmargin)))
358 err(EXIT_FAILURE, "malloc");
360 time2a(m->date, buf, DATESIZ);
362 (void)strlcpy(os, m->os, p->rmargin);
367 p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2;
368 p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
373 p->offset = p->rmargin;
374 p->rmargin = p->maxrmargin - strlen(os);
375 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
380 p->offset = p->rmargin;
381 p->rmargin = p->maxrmargin;
382 p->flags &= ~TERMP_NOBREAK;
383 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
389 p->rmargin = p->maxrmargin;
396 /* FIXME: put in utility library. */
399 print_head(DECL_ARGS)
403 p->rmargin = p->maxrmargin;
406 if (NULL == (buf = malloc(p->rmargin)))
407 err(EXIT_FAILURE, "malloc");
408 if (NULL == (title = malloc(p->rmargin)))
409 err(EXIT_FAILURE, "malloc");
412 * The header is strange. It has three components, which are
413 * really two with the first duplicated. It goes like this:
415 * IDENTIFIER TITLE IDENTIFIER
417 * The IDENTIFIER is NAME(SECTION), which is the command-name
418 * (if given, or "unknown" if not) followed by the manual page
419 * section. These are given in `Dt'. The TITLE is a free-form
420 * string depending on the manual volume. If not specified, it
421 * switches on the manual section.
425 (void)strlcpy(buf, m->vol, p->rmargin);
428 (void)strlcat(buf, " (", p->rmargin);
429 (void)strlcat(buf, m->arch, p->rmargin);
430 (void)strlcat(buf, ")", p->rmargin);
433 snprintf(title, p->rmargin, "%s(%d)", m->title, m->msec);
436 p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2;
437 p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
442 p->offset = p->rmargin;
443 p->rmargin = p->maxrmargin - strlen(title);
444 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
449 p->offset = p->rmargin;
450 p->rmargin = p->maxrmargin;
451 p->flags &= ~TERMP_NOBREAK;
452 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
458 p->rmargin = p->maxrmargin;
459 p->flags &= ~TERMP_NOSPACE;
467 a2height(const struct mdoc_node *n)
471 assert(MDOC_TEXT == n->type);
473 if ( ! a2roffsu(n->string, &su, SCALE_VS))
474 SCALE_VS_INIT(&su, strlen(n->string));
476 return(term_vspan(&su));
481 a2width(const struct mdoc_argv *arg, int pos)
485 assert(arg->value[pos]);
486 if ( ! a2roffsu(arg->value[pos], &su, SCALE_MAX))
487 SCALE_HS_INIT(&su, strlen(arg->value[pos]));
490 return(term_hspan(&su) + 2);
495 arg_listtype(const struct mdoc_node *n)
499 assert(MDOC_BLOCK == n->type);
501 len = (int)(n->args ? n->args->argc : 0);
503 for (i = 0; i < len; i++)
504 switch (n->args->argv[i].arg) {
526 return(n->args->argv[i].arg);
536 a2offs(const struct mdoc_argv *arg)
540 if ('\0' == arg->value[0][0])
542 else if (0 == strcmp(arg->value[0], "left"))
544 else if (0 == strcmp(arg->value[0], "indent"))
546 else if (0 == strcmp(arg->value[0], "indent-two"))
547 return((INDENT + 1) * 2);
548 else if ( ! a2roffsu(arg->value[0], &su, SCALE_MAX))
549 SCALE_HS_INIT(&su, strlen(arg->value[0]));
551 return(term_hspan(&su));
556 arg_hasattr(int arg, const struct mdoc_node *n)
559 return(-1 != arg_getattr(arg, n));
564 arg_getattr(int v, const struct mdoc_node *n)
568 return(arg_getattrs(&v, &val, 1, n) ? val : -1);
573 arg_getattrs(const int *keys, int *vals,
574 size_t sz, const struct mdoc_node *n)
581 for (k = i = 0; i < (int)n->args->argc; i++)
582 for (j = 0; j < (int)sz; j++)
583 if (n->args->argv[i].arg == keys[j]) {
592 print_bvspace(struct termp *p,
593 const struct mdoc_node *bl,
594 const struct mdoc_node *n)
596 const struct mdoc_node *nn;
599 if (arg_hasattr(MDOC_Compact, bl))
602 /* Do not vspace directly after Ss/Sh. */
604 for (nn = n; nn; nn = nn->parent) {
605 if (MDOC_BLOCK != nn->type)
607 if (MDOC_Ss == nn->tok)
609 if (MDOC_Sh == nn->tok)
611 if (NULL == nn->prev)
616 /* A `-column' does not assert vspace within the list. */
618 if (MDOC_Bl == bl->tok && arg_hasattr(MDOC_Column, bl))
619 if (n->prev && MDOC_It == n->prev->tok)
622 /* A `-diag' without body does not vspace. */
624 if (MDOC_Bl == bl->tok && arg_hasattr(MDOC_Diag, bl))
625 if (n->prev && MDOC_It == n->prev->tok) {
626 assert(n->prev->body);
627 if (NULL == n->prev->body->child)
637 termp_dq_pre(DECL_ARGS)
640 if (MDOC_BODY != n->type)
643 term_word(p, "\\(lq");
644 p->flags |= TERMP_NOSPACE;
651 termp_dq_post(DECL_ARGS)
654 if (MDOC_BODY != n->type)
657 p->flags |= TERMP_NOSPACE;
658 term_word(p, "\\(rq");
664 termp_it_pre(DECL_ARGS)
666 const struct mdoc_node *bl, *nn;
668 int i, type, keys[3], vals[3];
669 size_t width, offset;
671 if (MDOC_BLOCK == n->type) {
672 print_bvspace(p, n->parent->parent, n);
676 bl = n->parent->parent->parent;
678 /* Save parent attributes. */
680 pair->flag = p->flags;
682 /* Get list width and offset. */
684 keys[0] = MDOC_Width;
685 keys[1] = MDOC_Offset;
686 keys[2] = MDOC_Column;
688 vals[0] = vals[1] = vals[2] = -1;
692 (void)arg_getattrs(keys, vals, 3, bl);
694 type = arg_listtype(bl);
697 /* Calculate real width and offset. */
701 if (MDOC_BODY == n->type)
704 * Work around groff's column handling. The offset is
705 * equal to the sum of all widths leading to the current
706 * column (plus the -offset value). If this column
707 * exceeds the stated number of columns, the width is
708 * set as 0, else it's the stated column width (later
709 * the 0 will be adjusted to default 10 or, if in the
710 * last column case, set to stretch to the margin).
712 for (i = 0, nn = n->prev; nn &&
713 i < (int)bl->args->argv[vals[2]].sz;
716 (&bl->args->argv[vals[2]], i);
718 /* Whether exceeds maximum column. */
719 if (i < (int)bl->args->argv[vals[2]].sz)
720 width = a2width(&bl->args->argv[vals[2]], i);
725 offset += a2offs(&bl->args->argv[vals[1]]);
729 width = a2width(&bl->args->argv[vals[0]], 0);
731 offset += a2offs(&bl->args->argv[vals[1]]);
736 * List-type can override the width in the case of fixed-head
737 * values (bullet, dash/hyphen, enum). Tags need a non-zero
769 * Whitespace control. Inset bodies need an initial space,
770 * while diagonal bodies need two.
773 p->flags |= TERMP_NOSPACE;
777 if (MDOC_BODY == n->type)
778 term_word(p, "\\ \\ ");
781 if (MDOC_BODY == n->type)
788 p->flags |= TERMP_NOSPACE;
792 if (MDOC_HEAD == n->type)
800 * Pad and break control. This is the tricker part. Lists with
801 * set right-margins for the head get TERMP_NOBREAK because, if
802 * they overrun the margin, they wrap to the new margin.
803 * Correspondingly, the body for these types don't left-pad, as
804 * the head will pad out to to the right.
815 if (MDOC_HEAD == n->type)
816 p->flags |= TERMP_NOBREAK;
818 p->flags |= TERMP_NOLPAD;
821 if (MDOC_HEAD == n->type)
822 p->flags |= TERMP_NOBREAK;
824 p->flags |= TERMP_NOLPAD;
826 if (MDOC_HEAD != n->type)
830 * This is ugly. If `-hang' is specified and the body
831 * is a `Bl' or `Bd', then we want basically to nullify
832 * the "overstep" effect in term_flushln() and treat
833 * this as a `-ohang' list instead.
835 if (n->next->child &&
836 (MDOC_Bl == n->next->child->tok ||
837 MDOC_Bd == n->next->child->tok)) {
838 p->flags &= ~TERMP_NOBREAK;
839 p->flags &= ~TERMP_NOLPAD;
841 p->flags |= TERMP_HANG;
844 if (MDOC_HEAD == n->type)
845 p->flags |= TERMP_NOBREAK | TERMP_TWOSPACE;
847 p->flags |= TERMP_NOLPAD;
849 if (MDOC_HEAD != n->type)
851 if (NULL == n->next || NULL == n->next->child)
852 p->flags |= TERMP_DANGLE;
855 if (MDOC_HEAD == n->type) {
857 if (MDOC_BODY == n->next->type)
858 p->flags &= ~TERMP_NOBREAK;
860 p->flags |= TERMP_NOBREAK;
862 p->flags |= TERMP_NOLPAD;
866 if (MDOC_HEAD == n->type)
867 p->flags |= TERMP_NOBREAK;
874 * Margin control. Set-head-width lists have their right
875 * margins shortened. The body for these lists has the offset
876 * necessarily lengthened. Everybody gets the offset.
884 * Same stipulation as above, regarding `-hang'. We
885 * don't want to recalculate rmargin and offsets when
886 * using `Bd' or `Bl' within `-hang' overstep lists.
888 if (MDOC_HEAD == n->type && n->next->child &&
889 (MDOC_Bl == n->next->child->tok ||
890 MDOC_Bd == n->next->child->tok))
903 if (MDOC_HEAD == n->type)
904 p->rmargin = p->offset + width;
910 p->rmargin = p->offset + width;
912 * XXX - this behaviour is not documented: the
913 * right-most column is filled to the right margin.
915 if (MDOC_HEAD == n->type &&
916 MDOC_BODY == n->next->type)
917 p->rmargin = p->maxrmargin;
924 * The dash, hyphen, bullet and enum lists all have a special
925 * HEAD character (temporarily bold, in some cases).
928 if (MDOC_HEAD == n->type)
932 term_word(p, "\\[bu]");
939 term_word(p, "\\(hy");
943 (pair->ppair->ppair->count)++;
944 (void)snprintf(buf, sizeof(buf), "%d.",
945 pair->ppair->ppair->count);
953 * If we're not going to process our children, indicate so here.
966 if (MDOC_HEAD == n->type)
970 if (MDOC_BODY == n->type)
983 termp_it_post(DECL_ARGS)
987 if (MDOC_BODY != n->type && MDOC_HEAD != n->type)
990 type = arg_listtype(n->parent->parent->parent);
999 if (MDOC_BODY == n->type)
1003 if (MDOC_HEAD == n->type)
1011 p->flags = pair->flag;
1017 termp_nm_pre(DECL_ARGS)
1020 if (SEC_SYNOPSIS == n->sec)
1023 if (NULL == n->child)
1024 term_word(p, m->name);
1031 termp_fl_pre(DECL_ARGS)
1035 term_word(p, "\\-");
1036 p->flags |= TERMP_NOSPACE;
1043 termp_an_pre(DECL_ARGS)
1046 if (NULL == n->child)
1050 * If not in the AUTHORS section, `An -split' will cause
1051 * newlines to occur before the author name. If in the AUTHORS
1052 * section, by default, the first `An' invocation is nosplit,
1053 * then all subsequent ones, regardless of whether interspersed
1054 * with other macros/text, are split. -split, in this case,
1055 * will override the condition of the implied first -nosplit.
1058 if (n->sec == SEC_AUTHORS) {
1059 if ( ! (TERMP_ANPREC & p->flags)) {
1060 if (TERMP_SPLIT & p->flags)
1064 if (TERMP_NOSPLIT & p->flags)
1070 if (TERMP_SPLIT & p->flags)
1079 termp_an_post(DECL_ARGS)
1083 if (SEC_AUTHORS == n->sec)
1084 p->flags |= TERMP_ANPREC;
1088 if (arg_getattr(MDOC_Split, n) > -1) {
1089 p->flags &= ~TERMP_NOSPLIT;
1090 p->flags |= TERMP_SPLIT;
1092 p->flags &= ~TERMP_SPLIT;
1093 p->flags |= TERMP_NOSPLIT;
1101 termp_ns_pre(DECL_ARGS)
1104 p->flags |= TERMP_NOSPACE;
1111 termp_rs_pre(DECL_ARGS)
1114 if (SEC_SEE_ALSO != n->sec)
1116 if (MDOC_BLOCK == n->type && n->prev)
1124 termp_rv_pre(DECL_ARGS)
1126 const struct mdoc_node *nn;
1129 term_word(p, "The");
1131 for (nn = n->child; nn; nn = nn->next) {
1133 term_word(p, nn->string);
1135 p->flags |= TERMP_NOSPACE;
1136 if (nn->next && NULL == nn->next->next)
1137 term_word(p, "(), and");
1139 term_word(p, "(),");
1145 term_word(p, "functions return");
1147 term_word(p, "function returns");
1149 term_word(p, "the value 0 if successful; otherwise the value "
1150 "-1 is returned and the global variable");
1153 term_word(p, "errno");
1156 term_word(p, "is set to indicate the error.");
1164 termp_ex_pre(DECL_ARGS)
1166 const struct mdoc_node *nn;
1168 term_word(p, "The");
1170 for (nn = n->child; nn; nn = nn->next) {
1172 term_word(p, nn->string);
1174 p->flags |= TERMP_NOSPACE;
1175 if (nn->next && NULL == nn->next->next)
1176 term_word(p, ", and");
1180 p->flags &= ~TERMP_NOSPACE;
1184 term_word(p, "utilities exit");
1186 term_word(p, "utility exits");
1188 term_word(p, "0 on success, and >0 if an error occurs.");
1196 termp_nd_pre(DECL_ARGS)
1199 if (MDOC_BODY != n->type)
1202 #if defined(__OpenBSD__) || defined(__linux__)
1203 term_word(p, "\\(en");
1205 term_word(p, "\\(em");
1213 termp_bl_post(DECL_ARGS)
1216 if (MDOC_BLOCK == n->type)
1223 termp_op_post(DECL_ARGS)
1226 if (MDOC_BODY != n->type)
1228 p->flags |= TERMP_NOSPACE;
1229 term_word(p, "\\(rB");
1235 termp_xr_pre(DECL_ARGS)
1237 const struct mdoc_node *nn;
1239 assert(n->child && MDOC_TEXT == n->child->type);
1242 term_word(p, nn->string);
1243 if (NULL == (nn = nn->next))
1245 p->flags |= TERMP_NOSPACE;
1247 p->flags |= TERMP_NOSPACE;
1248 term_word(p, nn->string);
1249 p->flags |= TERMP_NOSPACE;
1258 termp_vt_post(DECL_ARGS)
1261 if (n->sec != SEC_SYNOPSIS)
1263 if (n->next && MDOC_Vt == n->next->tok)
1272 termp_bold_pre(DECL_ARGS)
1282 termp_fd_post(DECL_ARGS)
1285 if (n->sec != SEC_SYNOPSIS)
1289 if (n->next && MDOC_Fd != n->next->tok)
1296 termp_sh_pre(DECL_ARGS)
1299 /* No vspace between consecutive `Sh' calls. */
1303 if (n->prev && MDOC_Sh == n->prev->tok)
1304 if (NULL == n->prev->body->child)
1323 termp_sh_post(DECL_ARGS)
1342 termp_op_pre(DECL_ARGS)
1347 term_word(p, "\\(lB");
1348 p->flags |= TERMP_NOSPACE;
1359 termp_bt_pre(DECL_ARGS)
1362 term_word(p, "is currently in beta test.");
1369 termp_lb_post(DECL_ARGS)
1372 if (SEC_LIBRARY == n->sec)
1379 termp_ud_pre(DECL_ARGS)
1382 term_word(p, "currently under development.");
1389 termp_d1_pre(DECL_ARGS)
1392 if (MDOC_BLOCK != n->type)
1395 p->offset += (INDENT + 1);
1402 termp_d1_post(DECL_ARGS)
1405 if (MDOC_BLOCK != n->type)
1413 termp_aq_pre(DECL_ARGS)
1416 if (MDOC_BODY != n->type)
1418 term_word(p, "\\(la");
1419 p->flags |= TERMP_NOSPACE;
1426 termp_aq_post(DECL_ARGS)
1429 if (MDOC_BODY != n->type)
1431 p->flags |= TERMP_NOSPACE;
1432 term_word(p, "\\(ra");
1438 termp_ft_pre(DECL_ARGS)
1441 if (SEC_SYNOPSIS == n->sec)
1442 if (n->prev && MDOC_Fo == n->prev->tok)
1451 termp_ft_post(DECL_ARGS)
1454 if (SEC_SYNOPSIS == n->sec)
1461 termp_fn_pre(DECL_ARGS)
1463 const struct mdoc_node *nn;
1466 term_word(p, n->child->string);
1469 p->flags |= TERMP_NOSPACE;
1472 for (nn = n->child->next; nn; nn = nn->next) {
1474 term_word(p, nn->string);
1482 if (SEC_SYNOPSIS == n->sec)
1491 termp_fn_post(DECL_ARGS)
1494 if (n->sec == SEC_SYNOPSIS && n->next)
1501 termp_fa_pre(DECL_ARGS)
1503 const struct mdoc_node *nn;
1505 if (n->parent->tok != MDOC_Fo) {
1510 for (nn = n->child; nn; nn = nn->next) {
1512 term_word(p, nn->string);
1518 if (n->child && n->next && n->next->tok == MDOC_Fa)
1527 termp_bd_pre(DECL_ARGS)
1530 const struct mdoc_node *nn;
1532 if (MDOC_BLOCK == n->type) {
1533 print_bvspace(p, n, n);
1535 } else if (MDOC_BODY != n->type)
1540 for (type = -1, i = 0; i < (int)nn->args->argc; i++) {
1541 switch (nn->args->argv[i].arg) {
1542 case (MDOC_Centred):
1548 case (MDOC_Unfilled):
1550 case (MDOC_Literal):
1551 type = nn->args->argv[i].arg;
1554 p->offset += a2offs(&nn->args->argv[i]);
1562 * If -ragged or -filled are specified, the block does nothing
1563 * but change the indentation. If -unfilled or -literal are
1564 * specified, text is printed exactly as entered in the display:
1565 * for macro lines, a newline is appended to the line. Blank
1566 * lines are allowed.
1570 if (MDOC_Literal != type && MDOC_Unfilled != type)
1573 for (nn = n->child; nn; nn = nn->next) {
1574 p->flags |= TERMP_NOSPACE;
1575 print_node(p, pair, m, nn);
1576 if (NULL == nn->next)
1578 if (nn->prev && nn->prev->line < nn->line)
1580 else if (NULL == nn->prev)
1590 termp_bd_post(DECL_ARGS)
1593 if (MDOC_BODY != n->type)
1595 p->flags |= TERMP_NOSPACE;
1602 termp_qq_pre(DECL_ARGS)
1605 if (MDOC_BODY != n->type)
1608 p->flags |= TERMP_NOSPACE;
1615 termp_qq_post(DECL_ARGS)
1618 if (MDOC_BODY != n->type)
1620 p->flags |= TERMP_NOSPACE;
1627 termp_bx_post(DECL_ARGS)
1631 p->flags |= TERMP_NOSPACE;
1632 term_word(p, "BSD");
1638 termp_xx_pre(DECL_ARGS)
1648 pp = "DragonFlyBSD";
1674 termp_sq_pre(DECL_ARGS)
1677 if (MDOC_BODY != n->type)
1679 term_word(p, "\\(oq");
1680 p->flags |= TERMP_NOSPACE;
1687 termp_sq_post(DECL_ARGS)
1690 if (MDOC_BODY != n->type)
1692 p->flags |= TERMP_NOSPACE;
1693 term_word(p, "\\(aq");
1699 termp_pf_pre(DECL_ARGS)
1702 p->flags |= TERMP_IGNDELIM;
1709 termp_pf_post(DECL_ARGS)
1712 p->flags &= ~TERMP_IGNDELIM;
1713 p->flags |= TERMP_NOSPACE;
1719 termp_ss_pre(DECL_ARGS)
1730 p->offset = HALFINDENT;
1742 termp_ss_post(DECL_ARGS)
1745 if (MDOC_HEAD == n->type)
1752 termp_cd_pre(DECL_ARGS)
1763 termp_in_pre(DECL_ARGS)
1767 if (SEC_SYNOPSIS == n->sec)
1768 term_word(p, "#include");
1771 p->flags |= TERMP_NOSPACE;
1778 termp_in_post(DECL_ARGS)
1782 p->flags |= TERMP_NOSPACE;
1786 if (SEC_SYNOPSIS != n->sec)
1791 * XXX Not entirely correct. If `.In foo bar' is specified in
1792 * the SYNOPSIS section, then it produces a single break after
1793 * the <foo>; mandoc asserts a vertical space. Since this
1794 * construction is rarely used, I think it's fine.
1796 if (n->next && MDOC_In != n->next->tok)
1803 termp_sp_pre(DECL_ARGS)
1809 len = n->child ? a2height(n->child) : 1;
1821 for (i = 0; i < len; i++)
1830 termp_brq_pre(DECL_ARGS)
1833 if (MDOC_BODY != n->type)
1835 term_word(p, "\\(lC");
1836 p->flags |= TERMP_NOSPACE;
1843 termp_brq_post(DECL_ARGS)
1846 if (MDOC_BODY != n->type)
1848 p->flags |= TERMP_NOSPACE;
1849 term_word(p, "\\(rC");
1855 termp_bq_pre(DECL_ARGS)
1858 if (MDOC_BODY != n->type)
1860 term_word(p, "\\(lB");
1861 p->flags |= TERMP_NOSPACE;
1868 termp_bq_post(DECL_ARGS)
1871 if (MDOC_BODY != n->type)
1873 p->flags |= TERMP_NOSPACE;
1874 term_word(p, "\\(rB");
1880 termp_pq_pre(DECL_ARGS)
1883 if (MDOC_BODY != n->type)
1885 term_word(p, "\\&(");
1886 p->flags |= TERMP_NOSPACE;
1893 termp_pq_post(DECL_ARGS)
1896 if (MDOC_BODY != n->type)
1904 termp_fo_pre(DECL_ARGS)
1906 const struct mdoc_node *nn;
1908 if (MDOC_BODY == n->type) {
1909 p->flags |= TERMP_NOSPACE;
1911 p->flags |= TERMP_NOSPACE;
1913 } else if (MDOC_HEAD != n->type)
1917 for (nn = n->child; nn; nn = nn->next) {
1918 assert(MDOC_TEXT == nn->type);
1919 term_word(p, nn->string);
1929 termp_fo_post(DECL_ARGS)
1932 if (MDOC_BODY != n->type)
1934 p->flags |= TERMP_NOSPACE;
1936 p->flags |= TERMP_NOSPACE;
1944 termp_bf_pre(DECL_ARGS)
1946 const struct mdoc_node *nn;
1948 if (MDOC_HEAD == n->type)
1950 else if (MDOC_BLOCK != n->type)
1953 if (NULL == (nn = n->head->child)) {
1954 if (arg_hasattr(MDOC_Emphasis, n))
1956 else if (arg_hasattr(MDOC_Symbolic, n))
1962 assert(MDOC_TEXT == nn->type);
1963 if (0 == strcmp("Em", nn->string))
1965 else if (0 == strcmp("Sy", nn->string))
1974 termp_sm_pre(DECL_ARGS)
1977 assert(n->child && MDOC_TEXT == n->child->type);
1978 if (0 == strcmp("on", n->child->string)) {
1979 p->flags &= ~TERMP_NONOSPACE;
1980 p->flags &= ~TERMP_NOSPACE;
1982 p->flags |= TERMP_NONOSPACE;
1990 termp_ap_pre(DECL_ARGS)
1993 p->flags |= TERMP_NOSPACE;
1994 term_word(p, "\\(aq");
1995 p->flags |= TERMP_NOSPACE;
2002 termp____post(DECL_ARGS)
2007 p->flags |= TERMP_NOSPACE;
2010 term_word(p, "\\(rq");
2011 p->flags |= TERMP_NOSPACE;
2016 term_word(p, n->next ? "," : ".");
2022 termp_lk_pre(DECL_ARGS)
2024 const struct mdoc_node *nn;
2029 if (NULL == nn->next)
2032 term_word(p, nn->string);
2035 p->flags |= TERMP_NOSPACE;
2039 for (nn = nn->next; nn; nn = nn->next)
2040 term_word(p, nn->string);
2049 termp_under_pre(DECL_ARGS)
2059 termp__t_pre(DECL_ARGS)
2062 term_word(p, "\\(lq");
2063 p->flags |= TERMP_NOSPACE;