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