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