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