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