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