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