Annotation of mandoc/mdoc_term.c, Revision 1.215
1.215 ! kristaps 1: /* $Id: mdoc_term.c,v 1.214 2011/01/25 16:20:24 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_d1_post(DECL_ARGS);
77: static void termp_fo_post(DECL_ARGS);
78: static void termp_in_post(DECL_ARGS);
79: static void termp_it_post(DECL_ARGS);
80: static void termp_lb_post(DECL_ARGS);
1.164 schwarze 81: static void termp_nm_post(DECL_ARGS);
1.31 kristaps 82: static void termp_pf_post(DECL_ARGS);
1.188 kristaps 83: static void termp_quote_post(DECL_ARGS);
1.31 kristaps 84: static void termp_sh_post(DECL_ARGS);
85: static void termp_ss_post(DECL_ARGS);
86:
1.184 kristaps 87: static int termp__a_pre(DECL_ARGS);
1.203 kristaps 88: static int termp__t_pre(DECL_ARGS);
1.61 kristaps 89: static int termp_an_pre(DECL_ARGS);
1.31 kristaps 90: static int termp_ap_pre(DECL_ARGS);
91: static int termp_bd_pre(DECL_ARGS);
92: static int termp_bf_pre(DECL_ARGS);
1.159 schwarze 93: static int termp_bk_pre(DECL_ARGS);
1.115 kristaps 94: static int termp_bl_pre(DECL_ARGS);
1.69 kristaps 95: static int termp_bold_pre(DECL_ARGS);
1.31 kristaps 96: static int termp_bt_pre(DECL_ARGS);
1.211 kristaps 97: static int termp_bx_pre(DECL_ARGS);
1.31 kristaps 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.211 kristaps 190: { termp_bx_pre, NULL }, /* Bx */
1.1 kristaps 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:
1.215 ! kristaps 1154: if ( ! (MDOC_LINE & n->flags))
! 1155: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1156: return(1);
1157: }
1158:
1159:
1160: /* ARGSUSED */
1161: static int
1162: termp_rs_pre(DECL_ARGS)
1163: {
1164:
1.86 kristaps 1165: if (SEC_SEE_ALSO != n->sec)
1.80 kristaps 1166: return(1);
1.86 kristaps 1167: if (MDOC_BLOCK == n->type && n->prev)
1.1 kristaps 1168: term_vspace(p);
1169: return(1);
1170: }
1171:
1172:
1173: /* ARGSUSED */
1174: static int
1175: termp_rv_pre(DECL_ARGS)
1176: {
1.68 kristaps 1177: const struct mdoc_node *nn;
1.1 kristaps 1178:
1179: term_newln(p);
1180: term_word(p, "The");
1181:
1.86 kristaps 1182: for (nn = n->child; nn; nn = nn->next) {
1.102 kristaps 1183: term_fontpush(p, TERMFONT_BOLD);
1.68 kristaps 1184: term_word(p, nn->string);
1.102 kristaps 1185: term_fontpop(p);
1.68 kristaps 1186: p->flags |= TERMP_NOSPACE;
1187: if (nn->next && NULL == nn->next->next)
1188: term_word(p, "(), and");
1189: else if (nn->next)
1190: term_word(p, "(),");
1191: else
1192: term_word(p, "()");
1193: }
1194:
1.125 kristaps 1195: if (n->child && n->child->next)
1.68 kristaps 1196: term_word(p, "functions return");
1197: else
1198: term_word(p, "function returns");
1.1 kristaps 1199:
1.68 kristaps 1200: term_word(p, "the value 0 if successful; otherwise the value "
1201: "-1 is returned and the global variable");
1.1 kristaps 1202:
1.102 kristaps 1203: term_fontpush(p, TERMFONT_UNDER);
1.1 kristaps 1204: term_word(p, "errno");
1.102 kristaps 1205: term_fontpop(p);
1.1 kristaps 1206:
1207: term_word(p, "is set to indicate the error.");
1.131 kristaps 1208: p->flags |= TERMP_SENTENCE;
1.1 kristaps 1209:
1.68 kristaps 1210: return(0);
1.1 kristaps 1211: }
1212:
1213:
1214: /* ARGSUSED */
1215: static int
1216: termp_ex_pre(DECL_ARGS)
1217: {
1.68 kristaps 1218: const struct mdoc_node *nn;
1.1 kristaps 1219:
1.68 kristaps 1220: term_word(p, "The");
1.1 kristaps 1221:
1.86 kristaps 1222: for (nn = n->child; nn; nn = nn->next) {
1.102 kristaps 1223: term_fontpush(p, TERMFONT_BOLD);
1.68 kristaps 1224: term_word(p, nn->string);
1.102 kristaps 1225: term_fontpop(p);
1.68 kristaps 1226: p->flags |= TERMP_NOSPACE;
1227: if (nn->next && NULL == nn->next->next)
1228: term_word(p, ", and");
1229: else if (nn->next)
1230: term_word(p, ",");
1231: else
1232: p->flags &= ~TERMP_NOSPACE;
1233: }
1234:
1.125 kristaps 1235: if (n->child && n->child->next)
1.68 kristaps 1236: term_word(p, "utilities exit");
1237: else
1238: term_word(p, "utility exits");
1239:
1240: term_word(p, "0 on success, and >0 if an error occurs.");
1.131 kristaps 1241: p->flags |= TERMP_SENTENCE;
1.1 kristaps 1242:
1.68 kristaps 1243: return(0);
1.1 kristaps 1244: }
1245:
1246:
1247: /* ARGSUSED */
1248: static int
1249: termp_nd_pre(DECL_ARGS)
1250: {
1.25 kristaps 1251:
1.86 kristaps 1252: if (MDOC_BODY != n->type)
1.25 kristaps 1253: return(1);
1.30 kristaps 1254:
1.27 kristaps 1255: #if defined(__OpenBSD__) || defined(__linux__)
1.41 kristaps 1256: term_word(p, "\\(en");
1.23 kristaps 1257: #else
1258: term_word(p, "\\(em");
1259: #endif
1.1 kristaps 1260: return(1);
1.115 kristaps 1261: }
1262:
1263:
1264: /* ARGSUSED */
1265: static int
1266: termp_bl_pre(DECL_ARGS)
1267: {
1268:
1269: return(MDOC_HEAD != n->type);
1.1 kristaps 1270: }
1271:
1272:
1273: /* ARGSUSED */
1274: static void
1275: termp_bl_post(DECL_ARGS)
1276: {
1277:
1.86 kristaps 1278: if (MDOC_BLOCK == n->type)
1.1 kristaps 1279: term_newln(p);
1280: }
1281:
1282:
1283: /* ARGSUSED */
1284: static int
1285: termp_xr_pre(DECL_ARGS)
1286: {
1.86 kristaps 1287: const struct mdoc_node *nn;
1.1 kristaps 1288:
1.113 kristaps 1289: if (NULL == n->child)
1290: return(0);
1291:
1292: assert(MDOC_TEXT == n->child->type);
1.86 kristaps 1293: nn = n->child;
1.11 kristaps 1294:
1.86 kristaps 1295: term_word(p, nn->string);
1296: if (NULL == (nn = nn->next))
1.1 kristaps 1297: return(0);
1298: p->flags |= TERMP_NOSPACE;
1299: term_word(p, "(");
1.86 kristaps 1300: term_word(p, nn->string);
1.1 kristaps 1301: term_word(p, ")");
1.86 kristaps 1302:
1.1 kristaps 1303: return(0);
1304: }
1305:
1306:
1.143 kristaps 1307: /*
1308: * This decides how to assert whitespace before any of the SYNOPSIS set
1309: * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1310: * macro combos).
1311: */
1312: static void
1313: synopsis_pre(struct termp *p, const struct mdoc_node *n)
1314: {
1315: /*
1316: * Obviously, if we're not in a SYNOPSIS or no prior macros
1317: * exist, do nothing.
1318: */
1.160 kristaps 1319: if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
1.143 kristaps 1320: return;
1321:
1322: /*
1323: * If we're the second in a pair of like elements, emit our
1324: * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1325: * case we soldier on.
1326: */
1327: if (n->prev->tok == n->tok &&
1328: MDOC_Ft != n->tok &&
1329: MDOC_Fo != n->tok &&
1330: MDOC_Fn != n->tok) {
1331: term_newln(p);
1332: return;
1333: }
1334:
1335: /*
1336: * If we're one of the SYNOPSIS set and non-like pair-wise after
1337: * another (or Fn/Fo, which we've let slip through) then assert
1338: * vertical space, else only newline and move on.
1339: */
1340: switch (n->prev->tok) {
1341: case (MDOC_Fd):
1342: /* FALLTHROUGH */
1343: case (MDOC_Fn):
1344: /* FALLTHROUGH */
1345: case (MDOC_Fo):
1346: /* FALLTHROUGH */
1347: case (MDOC_In):
1348: /* FALLTHROUGH */
1349: case (MDOC_Vt):
1350: term_vspace(p);
1351: break;
1352: case (MDOC_Ft):
1353: if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
1354: term_vspace(p);
1355: break;
1356: }
1357: /* FALLTHROUGH */
1358: default:
1359: term_newln(p);
1360: break;
1361: }
1362: }
1363:
1364:
1.110 kristaps 1365: static int
1366: termp_vt_pre(DECL_ARGS)
1367: {
1368:
1.143 kristaps 1369: if (MDOC_ELEM == n->type) {
1370: synopsis_pre(p, n);
1.110 kristaps 1371: return(termp_under_pre(p, pair, m, n));
1.143 kristaps 1372: } else if (MDOC_BLOCK == n->type) {
1373: synopsis_pre(p, n);
1374: return(1);
1375: } else if (MDOC_HEAD == n->type)
1.110 kristaps 1376: return(0);
1377:
1378: return(termp_under_pre(p, pair, m, n));
1379: }
1380:
1381:
1.1 kristaps 1382: /* ARGSUSED */
1383: static int
1.69 kristaps 1384: termp_bold_pre(DECL_ARGS)
1.1 kristaps 1385: {
1386:
1.102 kristaps 1387: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1388: return(1);
1389: }
1390:
1391:
1392: /* ARGSUSED */
1.143 kristaps 1393: static int
1394: termp_fd_pre(DECL_ARGS)
1.1 kristaps 1395: {
1396:
1.143 kristaps 1397: synopsis_pre(p, n);
1398: return(termp_bold_pre(p, pair, m, n));
1.1 kristaps 1399: }
1400:
1401:
1402: /* ARGSUSED */
1403: static int
1404: termp_sh_pre(DECL_ARGS)
1405: {
1.85 kristaps 1406:
1407: /* No vspace between consecutive `Sh' calls. */
1408:
1.86 kristaps 1409: switch (n->type) {
1.65 kristaps 1410: case (MDOC_BLOCK):
1.86 kristaps 1411: if (n->prev && MDOC_Sh == n->prev->tok)
1412: if (NULL == n->prev->body->child)
1.65 kristaps 1413: break;
1414: term_vspace(p);
1415: break;
1.1 kristaps 1416: case (MDOC_HEAD):
1.102 kristaps 1417: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1418: break;
1419: case (MDOC_BODY):
1.157 kristaps 1420: p->offset = term_len(p, INDENT);
1.1 kristaps 1421: break;
1422: default:
1423: break;
1424: }
1425: return(1);
1426: }
1427:
1428:
1429: /* ARGSUSED */
1430: static void
1431: termp_sh_post(DECL_ARGS)
1432: {
1433:
1.86 kristaps 1434: switch (n->type) {
1.1 kristaps 1435: case (MDOC_HEAD):
1436: term_newln(p);
1437: break;
1438: case (MDOC_BODY):
1439: term_newln(p);
1440: p->offset = 0;
1441: break;
1442: default:
1443: break;
1444: }
1445: }
1446:
1447:
1448: /* ARGSUSED */
1449: static int
1450: termp_bt_pre(DECL_ARGS)
1451: {
1452:
1453: term_word(p, "is currently in beta test.");
1.131 kristaps 1454: p->flags |= TERMP_SENTENCE;
1.81 kristaps 1455: return(0);
1.1 kristaps 1456: }
1457:
1458:
1459: /* ARGSUSED */
1460: static void
1461: termp_lb_post(DECL_ARGS)
1462: {
1463:
1.122 kristaps 1464: if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
1.81 kristaps 1465: term_newln(p);
1.1 kristaps 1466: }
1467:
1468:
1469: /* ARGSUSED */
1470: static int
1471: termp_ud_pre(DECL_ARGS)
1472: {
1473:
1474: term_word(p, "currently under development.");
1.131 kristaps 1475: p->flags |= TERMP_SENTENCE;
1.86 kristaps 1476: return(0);
1.1 kristaps 1477: }
1478:
1479:
1480: /* ARGSUSED */
1481: static int
1482: termp_d1_pre(DECL_ARGS)
1483: {
1484:
1.86 kristaps 1485: if (MDOC_BLOCK != n->type)
1.1 kristaps 1486: return(1);
1487: term_newln(p);
1.157 kristaps 1488: p->offset += term_len(p, (INDENT + 1));
1.1 kristaps 1489: return(1);
1490: }
1491:
1492:
1493: /* ARGSUSED */
1494: static void
1495: termp_d1_post(DECL_ARGS)
1496: {
1497:
1.86 kristaps 1498: if (MDOC_BLOCK != n->type)
1.1 kristaps 1499: return;
1500: term_newln(p);
1501: }
1502:
1503:
1504: /* ARGSUSED */
1505: static int
1506: termp_ft_pre(DECL_ARGS)
1507: {
1508:
1.141 kristaps 1509: /* NB: MDOC_LINE does not effect this! */
1.143 kristaps 1510: synopsis_pre(p, n);
1.102 kristaps 1511: term_fontpush(p, TERMFONT_UNDER);
1.1 kristaps 1512: return(1);
1513: }
1514:
1515:
1516: /* ARGSUSED */
1517: static int
1518: termp_fn_pre(DECL_ARGS)
1519: {
1.86 kristaps 1520: const struct mdoc_node *nn;
1.1 kristaps 1521:
1.143 kristaps 1522: synopsis_pre(p, n);
1.139 kristaps 1523:
1.102 kristaps 1524: term_fontpush(p, TERMFONT_BOLD);
1.86 kristaps 1525: term_word(p, n->child->string);
1.102 kristaps 1526: term_fontpop(p);
1.1 kristaps 1527:
1528: p->flags |= TERMP_NOSPACE;
1529: term_word(p, "(");
1530:
1.86 kristaps 1531: for (nn = n->child->next; nn; nn = nn->next) {
1.102 kristaps 1532: term_fontpush(p, TERMFONT_UNDER);
1.86 kristaps 1533: term_word(p, nn->string);
1.102 kristaps 1534: term_fontpop(p);
1535:
1.86 kristaps 1536: if (nn->next)
1.1 kristaps 1537: term_word(p, ",");
1538: }
1539:
1540: term_word(p, ")");
1541:
1.160 kristaps 1542: if (MDOC_SYNPRETTY & n->flags)
1.1 kristaps 1543: term_word(p, ";");
1544:
1545: return(0);
1546: }
1547:
1548:
1549: /* ARGSUSED */
1550: static int
1551: termp_fa_pre(DECL_ARGS)
1552: {
1.86 kristaps 1553: const struct mdoc_node *nn;
1.1 kristaps 1554:
1.86 kristaps 1555: if (n->parent->tok != MDOC_Fo) {
1.102 kristaps 1556: term_fontpush(p, TERMFONT_UNDER);
1.1 kristaps 1557: return(1);
1558: }
1559:
1.86 kristaps 1560: for (nn = n->child; nn; nn = nn->next) {
1.102 kristaps 1561: term_fontpush(p, TERMFONT_UNDER);
1.86 kristaps 1562: term_word(p, nn->string);
1.102 kristaps 1563: term_fontpop(p);
1564:
1.86 kristaps 1565: if (nn->next)
1.1 kristaps 1566: term_word(p, ",");
1567: }
1568:
1.86 kristaps 1569: if (n->child && n->next && n->next->tok == MDOC_Fa)
1.1 kristaps 1570: term_word(p, ",");
1571:
1572: return(0);
1573: }
1574:
1575:
1576: /* ARGSUSED */
1577: static int
1578: termp_bd_pre(DECL_ARGS)
1579: {
1.179 kristaps 1580: size_t tabwidth, rm, rmax;
1.85 kristaps 1581: const struct mdoc_node *nn;
1.1 kristaps 1582:
1.86 kristaps 1583: if (MDOC_BLOCK == n->type) {
1.151 kristaps 1584: print_bvspace(p, n, n);
1.54 kristaps 1585: return(1);
1.116 kristaps 1586: } else if (MDOC_HEAD == n->type)
1587: return(0);
1.1 kristaps 1588:
1.202 kristaps 1589: if (n->norm->Bd.offs)
1590: p->offset += a2offs(p, n->norm->Bd.offs);
1.85 kristaps 1591:
1592: /*
1593: * If -ragged or -filled are specified, the block does nothing
1594: * but change the indentation. If -unfilled or -literal are
1595: * specified, text is printed exactly as entered in the display:
1596: * for macro lines, a newline is appended to the line. Blank
1597: * lines are allowed.
1598: */
1.60 kristaps 1599:
1.202 kristaps 1600: if (DISP_literal != n->norm->Bd.type &&
1601: DISP_unfilled != n->norm->Bd.type)
1.1 kristaps 1602: return(1);
1603:
1.129 schwarze 1604: tabwidth = p->tabwidth;
1.208 kristaps 1605: if (DISP_literal == n->norm->Bd.type)
1606: p->tabwidth = term_len(p, 8);
1607:
1.119 kristaps 1608: rm = p->rmargin;
1609: rmax = p->maxrmargin;
1.120 kristaps 1610: p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1.118 kristaps 1611:
1.86 kristaps 1612: for (nn = n->child; nn; nn = nn->next) {
1.102 kristaps 1613: print_mdoc_node(p, pair, m, nn);
1.190 kristaps 1614: /*
1615: * If the printed node flushes its own line, then we
1616: * needn't do it here as well. This is hacky, but the
1617: * notion of selective eoln whitespace is pretty dumb
1618: * anyway, so don't sweat it.
1619: */
1620: switch (nn->tok) {
1.193 kristaps 1621: case (MDOC_Sm):
1622: /* FALLTHROUGH */
1.190 kristaps 1623: case (MDOC_br):
1624: /* FALLTHROUGH */
1625: case (MDOC_sp):
1626: /* FALLTHROUGH */
1627: case (MDOC_Bl):
1.196 kristaps 1628: /* FALLTHROUGH */
1629: case (MDOC_D1):
1630: /* FALLTHROUGH */
1631: case (MDOC_Dl):
1.190 kristaps 1632: /* FALLTHROUGH */
1633: case (MDOC_Lp):
1634: /* FALLTHROUGH */
1635: case (MDOC_Pp):
1636: continue;
1637: default:
1638: break;
1639: }
1.180 schwarze 1640: if (nn->next && nn->next->line == nn->line)
1641: continue;
1642: term_flushln(p);
1643: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1644: }
1.147 kristaps 1645:
1.129 schwarze 1646: p->tabwidth = tabwidth;
1.119 kristaps 1647: p->rmargin = rm;
1648: p->maxrmargin = rmax;
1.1 kristaps 1649: return(0);
1650: }
1651:
1652:
1653: /* ARGSUSED */
1654: static void
1655: termp_bd_post(DECL_ARGS)
1656: {
1.119 kristaps 1657: size_t rm, rmax;
1.1 kristaps 1658:
1.86 kristaps 1659: if (MDOC_BODY != n->type)
1.1 kristaps 1660: return;
1.118 kristaps 1661:
1.119 kristaps 1662: rm = p->rmargin;
1663: rmax = p->maxrmargin;
1.118 kristaps 1664:
1.202 kristaps 1665: if (DISP_literal == n->norm->Bd.type ||
1666: DISP_unfilled == n->norm->Bd.type)
1.120 kristaps 1667: p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1.118 kristaps 1668:
1.60 kristaps 1669: p->flags |= TERMP_NOSPACE;
1.130 schwarze 1670: term_newln(p);
1.118 kristaps 1671:
1.119 kristaps 1672: p->rmargin = rm;
1673: p->maxrmargin = rmax;
1.1 kristaps 1674: }
1675:
1676:
1677: /* ARGSUSED */
1.211 kristaps 1678: static int
1679: termp_bx_pre(DECL_ARGS)
1.1 kristaps 1680: {
1681:
1.211 kristaps 1682: if (NULL != (n = n->child)) {
1683: term_word(p, n->string);
1684: p->flags |= TERMP_NOSPACE;
1685: term_word(p, "BSD");
1686: } else {
1687: term_word(p, "BSD");
1688: return(0);
1689: }
1690:
1691: if (NULL != (n = n->next)) {
1692: p->flags |= TERMP_NOSPACE;
1.213 kristaps 1693: term_word(p, "-");
1.1 kristaps 1694: p->flags |= TERMP_NOSPACE;
1.213 kristaps 1695: term_word(p, n->string);
1.211 kristaps 1696: }
1697:
1698: return(0);
1.1 kristaps 1699: }
1700:
1701:
1702: /* ARGSUSED */
1703: static int
1.26 kristaps 1704: termp_xx_pre(DECL_ARGS)
1.1 kristaps 1705: {
1.26 kristaps 1706: const char *pp;
1.1 kristaps 1707:
1.26 kristaps 1708: pp = NULL;
1.86 kristaps 1709: switch (n->tok) {
1.26 kristaps 1710: case (MDOC_Bsx):
1.194 schwarze 1711: pp = "BSD/OS";
1.26 kristaps 1712: break;
1713: case (MDOC_Dx):
1.100 kristaps 1714: pp = "DragonFly";
1.26 kristaps 1715: break;
1716: case (MDOC_Fx):
1717: pp = "FreeBSD";
1718: break;
1719: case (MDOC_Nx):
1720: pp = "NetBSD";
1721: break;
1722: case (MDOC_Ox):
1723: pp = "OpenBSD";
1724: break;
1725: case (MDOC_Ux):
1726: pp = "UNIX";
1727: break;
1728: default:
1729: break;
1730: }
1.1 kristaps 1731:
1.26 kristaps 1732: term_word(p, pp);
1.214 kristaps 1733: if (n->child) {
1734: p->flags |= TERMP_KEEP;
1735: term_word(p, n->child->string);
1736: p->flags &= ~TERMP_KEEP;
1737: }
1738: return(0);
1.1 kristaps 1739: }
1740:
1741:
1742: /* ARGSUSED */
1743: static int
1.192 schwarze 1744: termp_igndelim_pre(DECL_ARGS)
1.1 kristaps 1745: {
1746:
1747: p->flags |= TERMP_IGNDELIM;
1748: return(1);
1749: }
1750:
1751:
1752: /* ARGSUSED */
1753: static void
1754: termp_pf_post(DECL_ARGS)
1755: {
1756:
1757: p->flags |= TERMP_NOSPACE;
1758: }
1759:
1760:
1761: /* ARGSUSED */
1762: static int
1763: termp_ss_pre(DECL_ARGS)
1764: {
1765:
1.86 kristaps 1766: switch (n->type) {
1.1 kristaps 1767: case (MDOC_BLOCK):
1768: term_newln(p);
1.86 kristaps 1769: if (n->prev)
1.1 kristaps 1770: term_vspace(p);
1771: break;
1772: case (MDOC_HEAD):
1.102 kristaps 1773: term_fontpush(p, TERMFONT_BOLD);
1.157 kristaps 1774: p->offset = term_len(p, HALFINDENT);
1.1 kristaps 1775: break;
1776: default:
1777: break;
1778: }
1779:
1780: return(1);
1781: }
1782:
1783:
1784: /* ARGSUSED */
1785: static void
1786: termp_ss_post(DECL_ARGS)
1787: {
1788:
1.86 kristaps 1789: if (MDOC_HEAD == n->type)
1.1 kristaps 1790: term_newln(p);
1791: }
1792:
1793:
1794: /* ARGSUSED */
1795: static int
1796: termp_cd_pre(DECL_ARGS)
1797: {
1798:
1.143 kristaps 1799: synopsis_pre(p, n);
1.102 kristaps 1800: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1801: return(1);
1802: }
1803:
1804:
1805: /* ARGSUSED */
1806: static int
1807: termp_in_pre(DECL_ARGS)
1808: {
1.142 schwarze 1809:
1.143 kristaps 1810: synopsis_pre(p, n);
1.1 kristaps 1811:
1.160 kristaps 1812: if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags) {
1.138 kristaps 1813: term_fontpush(p, TERMFONT_BOLD);
1.22 kristaps 1814: term_word(p, "#include");
1.138 kristaps 1815: term_word(p, "<");
1816: } else {
1817: term_word(p, "<");
1818: term_fontpush(p, TERMFONT_UNDER);
1819: }
1.22 kristaps 1820:
1.1 kristaps 1821: p->flags |= TERMP_NOSPACE;
1822: return(1);
1823: }
1824:
1825:
1826: /* ARGSUSED */
1827: static void
1828: termp_in_post(DECL_ARGS)
1829: {
1830:
1.160 kristaps 1831: if (MDOC_SYNPRETTY & n->flags)
1.138 kristaps 1832: term_fontpush(p, TERMFONT_BOLD);
1833:
1.79 kristaps 1834: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1835: term_word(p, ">");
1836:
1.160 kristaps 1837: if (MDOC_SYNPRETTY & n->flags)
1.138 kristaps 1838: term_fontpop(p);
1.1 kristaps 1839: }
1840:
1841:
1842: /* ARGSUSED */
1843: static int
1.45 kristaps 1844: termp_sp_pre(DECL_ARGS)
1845: {
1.91 kristaps 1846: size_t i, len;
1.45 kristaps 1847:
1.86 kristaps 1848: switch (n->tok) {
1.76 kristaps 1849: case (MDOC_sp):
1.157 kristaps 1850: len = n->child ? a2height(p, n->child->string) : 1;
1.76 kristaps 1851: break;
1852: case (MDOC_br):
1853: len = 0;
1854: break;
1855: default:
1856: len = 1;
1857: break;
1.45 kristaps 1858: }
1859:
1860: if (0 == len)
1861: term_newln(p);
1862: for (i = 0; i < len; i++)
1863: term_vspace(p);
1864:
1865: return(0);
1866: }
1867:
1868:
1.189 kristaps 1869: /* ARGSUSED */
1.45 kristaps 1870: static int
1.188 kristaps 1871: termp_quote_pre(DECL_ARGS)
1.1 kristaps 1872: {
1873:
1.203 kristaps 1874: if (MDOC_BODY != n->type && MDOC_ELEM != n->type)
1.1 kristaps 1875: return(1);
1876:
1.188 kristaps 1877: switch (n->tok) {
1878: case (MDOC_Ao):
1879: /* FALLTHROUGH */
1880: case (MDOC_Aq):
1881: term_word(p, "<");
1882: break;
1883: case (MDOC_Bro):
1884: /* FALLTHROUGH */
1885: case (MDOC_Brq):
1886: term_word(p, "{");
1887: break;
1888: case (MDOC_Oo):
1889: /* FALLTHROUGH */
1890: case (MDOC_Op):
1891: /* FALLTHROUGH */
1892: case (MDOC_Bo):
1893: /* FALLTHROUGH */
1894: case (MDOC_Bq):
1895: term_word(p, "[");
1896: break;
1897: case (MDOC_Do):
1898: /* FALLTHROUGH */
1899: case (MDOC_Dq):
1900: term_word(p, "``");
1901: break;
1902: case (MDOC_Po):
1903: /* FALLTHROUGH */
1904: case (MDOC_Pq):
1905: term_word(p, "(");
1906: break;
1.205 kristaps 1907: case (MDOC__T):
1908: /* FALLTHROUGH */
1.188 kristaps 1909: case (MDOC_Qo):
1910: /* FALLTHROUGH */
1911: case (MDOC_Qq):
1912: term_word(p, "\"");
1913: break;
1914: case (MDOC_Ql):
1915: /* FALLTHROUGH */
1916: case (MDOC_So):
1917: /* FALLTHROUGH */
1918: case (MDOC_Sq):
1919: term_word(p, "`");
1920: break;
1921: default:
1922: abort();
1923: /* NOTREACHED */
1924: }
1.1 kristaps 1925:
1926: p->flags |= TERMP_NOSPACE;
1927: return(1);
1928: }
1929:
1930:
1.189 kristaps 1931: /* ARGSUSED */
1.1 kristaps 1932: static void
1.188 kristaps 1933: termp_quote_post(DECL_ARGS)
1.1 kristaps 1934: {
1935:
1.203 kristaps 1936: if (MDOC_BODY != n->type && MDOC_ELEM != n->type)
1.1 kristaps 1937: return;
1938:
1939: p->flags |= TERMP_NOSPACE;
1940:
1.188 kristaps 1941: switch (n->tok) {
1942: case (MDOC_Ao):
1943: /* FALLTHROUGH */
1944: case (MDOC_Aq):
1945: term_word(p, ">");
1946: break;
1947: case (MDOC_Bro):
1948: /* FALLTHROUGH */
1949: case (MDOC_Brq):
1950: term_word(p, "}");
1951: break;
1952: case (MDOC_Oo):
1953: /* FALLTHROUGH */
1954: case (MDOC_Op):
1955: /* FALLTHROUGH */
1956: case (MDOC_Bo):
1957: /* FALLTHROUGH */
1958: case (MDOC_Bq):
1959: term_word(p, "]");
1960: break;
1961: case (MDOC_Do):
1962: /* FALLTHROUGH */
1963: case (MDOC_Dq):
1964: term_word(p, "''");
1965: break;
1966: case (MDOC_Po):
1967: /* FALLTHROUGH */
1968: case (MDOC_Pq):
1969: term_word(p, ")");
1970: break;
1.205 kristaps 1971: case (MDOC__T):
1972: /* FALLTHROUGH */
1.188 kristaps 1973: case (MDOC_Qo):
1974: /* FALLTHROUGH */
1975: case (MDOC_Qq):
1976: term_word(p, "\"");
1977: break;
1978: case (MDOC_Ql):
1979: /* FALLTHROUGH */
1980: case (MDOC_So):
1981: /* FALLTHROUGH */
1982: case (MDOC_Sq):
1983: term_word(p, "'");
1984: break;
1985: default:
1986: abort();
1987: /* NOTREACHED */
1988: }
1.1 kristaps 1989: }
1990:
1991:
1992: /* ARGSUSED */
1993: static int
1994: termp_fo_pre(DECL_ARGS)
1995: {
1996:
1.141 kristaps 1997: if (MDOC_BLOCK == n->type) {
1.143 kristaps 1998: synopsis_pre(p, n);
1.141 kristaps 1999: return(1);
2000: } else if (MDOC_BODY == n->type) {
1.33 kristaps 2001: p->flags |= TERMP_NOSPACE;
1.1 kristaps 2002: term_word(p, "(");
2003: return(1);
1.141 kristaps 2004: }
2005:
1.169 kristaps 2006: if (NULL == n->child)
2007: return(0);
2008:
1.141 kristaps 2009: /* XXX: we drop non-initial arguments as per groff. */
1.1 kristaps 2010:
1.141 kristaps 2011: assert(n->child->string);
1.102 kristaps 2012: term_fontpush(p, TERMFONT_BOLD);
1.141 kristaps 2013: term_word(p, n->child->string);
1.1 kristaps 2014: return(0);
2015: }
2016:
2017:
2018: /* ARGSUSED */
2019: static void
2020: termp_fo_post(DECL_ARGS)
2021: {
2022:
1.143 kristaps 2023: if (MDOC_BODY != n->type)
2024: return;
2025:
2026: term_word(p, ")");
2027:
1.188 kristaps 2028: if (MDOC_SYNPRETTY & n->flags)
1.143 kristaps 2029: term_word(p, ";");
1.1 kristaps 2030: }
2031:
2032:
2033: /* ARGSUSED */
2034: static int
2035: termp_bf_pre(DECL_ARGS)
2036: {
2037:
1.86 kristaps 2038: if (MDOC_HEAD == n->type)
1.1 kristaps 2039: return(0);
1.86 kristaps 2040: else if (MDOC_BLOCK != n->type)
1.1 kristaps 2041: return(1);
2042:
1.202 kristaps 2043: if (FONT_Em == n->norm->Bf.font)
1.102 kristaps 2044: term_fontpush(p, TERMFONT_UNDER);
1.202 kristaps 2045: else if (FONT_Sy == n->norm->Bf.font)
1.102 kristaps 2046: term_fontpush(p, TERMFONT_BOLD);
1.167 kristaps 2047: else
1.102 kristaps 2048: term_fontpush(p, TERMFONT_NONE);
1.1 kristaps 2049:
2050: return(1);
2051: }
2052:
2053:
2054: /* ARGSUSED */
2055: static int
2056: termp_sm_pre(DECL_ARGS)
2057: {
2058:
1.86 kristaps 2059: assert(n->child && MDOC_TEXT == n->child->type);
1.174 schwarze 2060: if (0 == strcmp("on", n->child->string)) {
2061: if (p->col)
2062: p->flags &= ~TERMP_NOSPACE;
1.1 kristaps 2063: p->flags &= ~TERMP_NONOSPACE;
1.174 schwarze 2064: } else
1.1 kristaps 2065: p->flags |= TERMP_NONOSPACE;
2066:
2067: return(0);
2068: }
2069:
2070:
2071: /* ARGSUSED */
2072: static int
2073: termp_ap_pre(DECL_ARGS)
2074: {
2075:
2076: p->flags |= TERMP_NOSPACE;
1.188 kristaps 2077: term_word(p, "'");
1.1 kristaps 2078: p->flags |= TERMP_NOSPACE;
2079: return(1);
2080: }
2081:
2082:
2083: /* ARGSUSED */
2084: static void
2085: termp____post(DECL_ARGS)
2086: {
1.184 kristaps 2087:
2088: /*
2089: * Handle lists of authors. In general, print each followed by
2090: * a comma. Don't print the comma if there are only two
2091: * authors.
2092: */
2093: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
2094: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
2095: if (NULL == n->prev || MDOC__A != n->prev->tok)
2096: return;
1.1 kristaps 2097:
1.95 kristaps 2098: /* TODO: %U. */
2099:
1.187 kristaps 2100: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
2101: return;
2102:
1.186 kristaps 2103: if (NULL == n->next) {
2104: term_word(p, ".");
2105: p->flags |= TERMP_SENTENCE;
2106: } else
2107: term_word(p, ",");
1.1 kristaps 2108: }
2109:
2110:
2111: /* ARGSUSED */
2112: static int
1.102 kristaps 2113: termp_li_pre(DECL_ARGS)
2114: {
2115:
2116: term_fontpush(p, TERMFONT_NONE);
2117: return(1);
2118: }
2119:
2120:
2121: /* ARGSUSED */
2122: static int
1.1 kristaps 2123: termp_lk_pre(DECL_ARGS)
2124: {
1.181 kristaps 2125: const struct mdoc_node *nn, *sv;
1.1 kristaps 2126:
1.102 kristaps 2127: term_fontpush(p, TERMFONT_UNDER);
1.181 kristaps 2128:
2129: nn = sv = n->child;
1.96 kristaps 2130:
1.195 kristaps 2131: if (NULL == nn || NULL == nn->next)
1.12 kristaps 2132: return(1);
2133:
1.181 kristaps 2134: for (nn = nn->next; nn; nn = nn->next)
2135: term_word(p, nn->string);
2136:
1.102 kristaps 2137: term_fontpop(p);
1.96 kristaps 2138:
1.1 kristaps 2139: term_word(p, ":");
2140:
1.102 kristaps 2141: term_fontpush(p, TERMFONT_BOLD);
1.181 kristaps 2142: term_word(p, sv->string);
1.102 kristaps 2143: term_fontpop(p);
1.12 kristaps 2144:
1.1 kristaps 2145: return(0);
2146: }
2147:
1.159 schwarze 2148:
2149: /* ARGSUSED */
2150: static int
2151: termp_bk_pre(DECL_ARGS)
2152: {
2153:
1.161 schwarze 2154: switch (n->type) {
2155: case (MDOC_BLOCK):
1.166 kristaps 2156: break;
1.161 schwarze 2157: case (MDOC_HEAD):
2158: return(0);
2159: case (MDOC_BODY):
1.200 schwarze 2160: if (n->parent->args || 0 == n->prev->nchild)
2161: p->flags |= TERMP_PREKEEP;
1.166 kristaps 2162: break;
1.161 schwarze 2163: default:
2164: abort();
1.166 kristaps 2165: /* NOTREACHED */
1.161 schwarze 2166: }
1.166 kristaps 2167:
2168: return(1);
1.159 schwarze 2169: }
2170:
2171:
2172: /* ARGSUSED */
2173: static void
2174: termp_bk_post(DECL_ARGS)
2175: {
2176:
1.161 schwarze 2177: if (MDOC_BODY == n->type)
2178: p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.203 kristaps 2179: }
2180:
2181: /* ARGSUSED */
2182: static void
2183: termp__t_post(DECL_ARGS)
2184: {
2185:
2186: /*
2187: * If we're in an `Rs' and there's a journal present, then quote
2188: * us instead of underlining us (for disambiguation).
2189: */
1.204 kristaps 2190: if (n->parent && MDOC_Rs == n->parent->tok &&
1.210 kristaps 2191: n->parent->norm->Rs.quote_T)
1.203 kristaps 2192: termp_quote_post(p, pair, m, n);
2193:
2194: termp____post(p, pair, m, n);
2195: }
2196:
2197: /* ARGSUSED */
2198: static int
2199: termp__t_pre(DECL_ARGS)
2200: {
2201:
2202: /*
2203: * If we're in an `Rs' and there's a journal present, then quote
2204: * us instead of underlining us (for disambiguation).
2205: */
2206: if (n->parent && MDOC_Rs == n->parent->tok &&
1.210 kristaps 2207: n->parent->norm->Rs.quote_T)
1.203 kristaps 2208: return(termp_quote_pre(p, pair, m, n));
2209:
2210: term_fontpush(p, TERMFONT_UNDER);
2211: return(1);
1.159 schwarze 2212: }
1.1 kristaps 2213:
2214: /* ARGSUSED */
2215: static int
1.69 kristaps 2216: termp_under_pre(DECL_ARGS)
1.1 kristaps 2217: {
2218:
1.102 kristaps 2219: term_fontpush(p, TERMFONT_UNDER);
1.84 kristaps 2220: return(1);
2221: }
CVSweb