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