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