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