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