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