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