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