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