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