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