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