Annotation of src/usr.bin/mandoc/mdoc_term.c, Revision 1.84
1.84 ! schwarze 1: /* $Id: mdoc_term.c,v 1.83 2010/05/24 00:37: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)
1.83 schwarze 1044: return(1);
1.81 schwarze 1045:
1.77 schwarze 1046: if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
1.1 kristaps 1047: term_newln(p);
1.65 schwarze 1048:
1049: term_fontpush(p, TERMFONT_BOLD);
1050:
1.60 schwarze 1051: if (NULL == n->child)
1052: term_word(p, m->name);
1.81 schwarze 1053:
1.1 kristaps 1054: return(1);
1055: }
1056:
1057:
1058: /* ARGSUSED */
1059: static int
1060: termp_fl_pre(DECL_ARGS)
1061: {
1062:
1.65 schwarze 1063: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1064: term_word(p, "\\-");
1.67 schwarze 1065:
1066: if (n->child)
1067: p->flags |= TERMP_NOSPACE;
1.73 schwarze 1068: else if (n->next && n->next->line == n->line)
1069: p->flags |= TERMP_NOSPACE;
1.67 schwarze 1070:
1.1 kristaps 1071: return(1);
1.49 schwarze 1072: }
1073:
1074:
1075: /* ARGSUSED */
1076: static int
1077: termp_an_pre(DECL_ARGS)
1078: {
1079:
1.60 schwarze 1080: if (NULL == n->child)
1.49 schwarze 1081: return(1);
1082:
1083: /*
1.60 schwarze 1084: * If not in the AUTHORS section, `An -split' will cause
1085: * newlines to occur before the author name. If in the AUTHORS
1086: * section, by default, the first `An' invocation is nosplit,
1087: * then all subsequent ones, regardless of whether interspersed
1088: * with other macros/text, are split. -split, in this case,
1089: * will override the condition of the implied first -nosplit.
1.49 schwarze 1090: */
1091:
1.60 schwarze 1092: if (n->sec == SEC_AUTHORS) {
1.49 schwarze 1093: if ( ! (TERMP_ANPREC & p->flags)) {
1094: if (TERMP_SPLIT & p->flags)
1095: term_newln(p);
1096: return(1);
1097: }
1098: if (TERMP_NOSPLIT & p->flags)
1099: return(1);
1100: term_newln(p);
1101: return(1);
1102: }
1103:
1104: if (TERMP_SPLIT & p->flags)
1105: term_newln(p);
1106:
1107: return(1);
1108: }
1109:
1110:
1111: /* ARGSUSED */
1112: static void
1113: termp_an_post(DECL_ARGS)
1114: {
1115:
1.60 schwarze 1116: if (n->child) {
1117: if (SEC_AUTHORS == n->sec)
1.49 schwarze 1118: p->flags |= TERMP_ANPREC;
1119: return;
1120: }
1121:
1.77 schwarze 1122: if (arg_hasattr(MDOC_Split, n)) {
1.49 schwarze 1123: p->flags &= ~TERMP_NOSPLIT;
1124: p->flags |= TERMP_SPLIT;
1125: } else {
1126: p->flags &= ~TERMP_SPLIT;
1127: p->flags |= TERMP_NOSPLIT;
1128: }
1129:
1.1 kristaps 1130: }
1131:
1132:
1133: /* ARGSUSED */
1134: static int
1135: termp_ns_pre(DECL_ARGS)
1136: {
1137:
1138: p->flags |= TERMP_NOSPACE;
1139: return(1);
1140: }
1141:
1142:
1143: /* ARGSUSED */
1144: static int
1145: termp_rs_pre(DECL_ARGS)
1146: {
1147:
1.60 schwarze 1148: if (SEC_SEE_ALSO != n->sec)
1.57 schwarze 1149: return(1);
1.60 schwarze 1150: if (MDOC_BLOCK == n->type && n->prev)
1.1 kristaps 1151: term_vspace(p);
1152: return(1);
1153: }
1154:
1155:
1156: /* ARGSUSED */
1157: static int
1158: termp_rv_pre(DECL_ARGS)
1159: {
1.53 schwarze 1160: const struct mdoc_node *nn;
1.1 kristaps 1161:
1162: term_newln(p);
1163: term_word(p, "The");
1164:
1.60 schwarze 1165: for (nn = n->child; nn; nn = nn->next) {
1.65 schwarze 1166: term_fontpush(p, TERMFONT_BOLD);
1.53 schwarze 1167: term_word(p, nn->string);
1.65 schwarze 1168: term_fontpop(p);
1.53 schwarze 1169: p->flags |= TERMP_NOSPACE;
1170: if (nn->next && NULL == nn->next->next)
1171: term_word(p, "(), and");
1172: else if (nn->next)
1173: term_word(p, "(),");
1174: else
1175: term_word(p, "()");
1176: }
1177:
1.81 schwarze 1178: if (n->child && n->child->next)
1.53 schwarze 1179: term_word(p, "functions return");
1180: else
1181: term_word(p, "function returns");
1.1 kristaps 1182:
1.53 schwarze 1183: term_word(p, "the value 0 if successful; otherwise the value "
1184: "-1 is returned and the global variable");
1.1 kristaps 1185:
1.65 schwarze 1186: term_fontpush(p, TERMFONT_UNDER);
1.1 kristaps 1187: term_word(p, "errno");
1.65 schwarze 1188: term_fontpop(p);
1.1 kristaps 1189:
1190: term_word(p, "is set to indicate the error.");
1.84 ! schwarze 1191: p->flags |= TERMP_SENTENCE;
1.1 kristaps 1192:
1.53 schwarze 1193: return(0);
1.1 kristaps 1194: }
1195:
1196:
1197: /* ARGSUSED */
1198: static int
1199: termp_ex_pre(DECL_ARGS)
1200: {
1.53 schwarze 1201: const struct mdoc_node *nn;
1.1 kristaps 1202:
1.53 schwarze 1203: term_word(p, "The");
1.1 kristaps 1204:
1.60 schwarze 1205: for (nn = n->child; nn; nn = nn->next) {
1.65 schwarze 1206: term_fontpush(p, TERMFONT_BOLD);
1.53 schwarze 1207: term_word(p, nn->string);
1.65 schwarze 1208: term_fontpop(p);
1.53 schwarze 1209: p->flags |= TERMP_NOSPACE;
1210: if (nn->next && NULL == nn->next->next)
1211: term_word(p, ", and");
1212: else if (nn->next)
1213: term_word(p, ",");
1214: else
1215: p->flags &= ~TERMP_NOSPACE;
1216: }
1217:
1.81 schwarze 1218: if (n->child && n->child->next)
1.53 schwarze 1219: term_word(p, "utilities exit");
1220: else
1221: term_word(p, "utility exits");
1222:
1223: term_word(p, "0 on success, and >0 if an error occurs.");
1.84 ! schwarze 1224: p->flags |= TERMP_SENTENCE;
1.1 kristaps 1225:
1.53 schwarze 1226: return(0);
1.1 kristaps 1227: }
1228:
1229:
1230: /* ARGSUSED */
1231: static int
1232: termp_nd_pre(DECL_ARGS)
1233: {
1.25 schwarze 1234:
1.60 schwarze 1235: if (MDOC_BODY != n->type)
1.25 schwarze 1236: return(1);
1237:
1238: #if defined(__OpenBSD__) || defined(__linux__)
1239: term_word(p, "\\(en");
1.24 schwarze 1240: #else
1241: term_word(p, "\\(em");
1242: #endif
1.1 kristaps 1243: return(1);
1244: }
1245:
1246:
1247: /* ARGSUSED */
1.73 schwarze 1248: static int
1249: termp_bl_pre(DECL_ARGS)
1250: {
1251:
1252: return(MDOC_HEAD != n->type);
1253: }
1254:
1255:
1256: /* ARGSUSED */
1.1 kristaps 1257: static void
1258: termp_bl_post(DECL_ARGS)
1259: {
1260:
1.60 schwarze 1261: if (MDOC_BLOCK == n->type)
1.1 kristaps 1262: term_newln(p);
1263: }
1264:
1265:
1266: /* ARGSUSED */
1267: static void
1268: termp_op_post(DECL_ARGS)
1269: {
1270:
1.60 schwarze 1271: if (MDOC_BODY != n->type)
1.1 kristaps 1272: return;
1273: p->flags |= TERMP_NOSPACE;
1274: term_word(p, "\\(rB");
1275: }
1276:
1277:
1278: /* ARGSUSED */
1279: static int
1280: termp_xr_pre(DECL_ARGS)
1281: {
1.60 schwarze 1282: const struct mdoc_node *nn;
1.1 kristaps 1283:
1.72 schwarze 1284: if (NULL == n->child)
1285: return(0);
1286:
1287: assert(MDOC_TEXT == n->child->type);
1.60 schwarze 1288: nn = n->child;
1.10 schwarze 1289:
1.60 schwarze 1290: term_word(p, nn->string);
1291: if (NULL == (nn = nn->next))
1.1 kristaps 1292: return(0);
1293: p->flags |= TERMP_NOSPACE;
1294: term_word(p, "(");
1295: p->flags |= TERMP_NOSPACE;
1.60 schwarze 1296: term_word(p, nn->string);
1.1 kristaps 1297: p->flags |= TERMP_NOSPACE;
1298: term_word(p, ")");
1.60 schwarze 1299:
1.1 kristaps 1300: return(0);
1301: }
1302:
1303:
1.69 schwarze 1304: static int
1305: termp_vt_pre(DECL_ARGS)
1306: {
1307:
1308: if (MDOC_ELEM == n->type)
1309: return(termp_under_pre(p, pair, m, n));
1310: else if (MDOC_HEAD == n->type)
1311: return(0);
1312: else if (MDOC_BLOCK == n->type)
1313: return(1);
1314:
1315: return(termp_under_pre(p, pair, m, n));
1316: }
1317:
1318:
1.1 kristaps 1319: /* ARGSUSED */
1320: static void
1321: termp_vt_post(DECL_ARGS)
1322: {
1323:
1.69 schwarze 1324: if (MDOC_BLOCK != n->type)
1.30 schwarze 1325: return;
1.60 schwarze 1326: if (n->next && MDOC_Vt == n->next->tok)
1.30 schwarze 1327: term_newln(p);
1.60 schwarze 1328: else if (n->next)
1.1 kristaps 1329: term_vspace(p);
1330: }
1331:
1332:
1333: /* ARGSUSED */
1334: static int
1.54 schwarze 1335: termp_bold_pre(DECL_ARGS)
1.1 kristaps 1336: {
1337:
1.65 schwarze 1338: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1339: return(1);
1340: }
1341:
1342:
1343: /* ARGSUSED */
1344: static void
1345: termp_fd_post(DECL_ARGS)
1346: {
1347:
1.77 schwarze 1348: if (n->sec != SEC_SYNOPSIS || ! (MDOC_LINE & n->flags))
1.1 kristaps 1349: return;
1.27 schwarze 1350:
1.1 kristaps 1351: term_newln(p);
1.60 schwarze 1352: if (n->next && MDOC_Fd != n->next->tok)
1.1 kristaps 1353: term_vspace(p);
1354: }
1355:
1356:
1357: /* ARGSUSED */
1358: static int
1359: termp_sh_pre(DECL_ARGS)
1360: {
1.60 schwarze 1361:
1362: /* No vspace between consecutive `Sh' calls. */
1363:
1364: switch (n->type) {
1.52 schwarze 1365: case (MDOC_BLOCK):
1.60 schwarze 1366: if (n->prev && MDOC_Sh == n->prev->tok)
1367: if (NULL == n->prev->body->child)
1.52 schwarze 1368: break;
1369: term_vspace(p);
1370: break;
1.1 kristaps 1371: case (MDOC_HEAD):
1.65 schwarze 1372: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1373: break;
1374: case (MDOC_BODY):
1375: p->offset = INDENT;
1376: break;
1377: default:
1378: break;
1379: }
1380: return(1);
1381: }
1382:
1383:
1384: /* ARGSUSED */
1385: static void
1386: termp_sh_post(DECL_ARGS)
1387: {
1388:
1.60 schwarze 1389: switch (n->type) {
1.1 kristaps 1390: case (MDOC_HEAD):
1391: term_newln(p);
1392: break;
1393: case (MDOC_BODY):
1394: term_newln(p);
1395: p->offset = 0;
1396: break;
1397: default:
1398: break;
1399: }
1400: }
1401:
1402:
1403: /* ARGSUSED */
1404: static int
1405: termp_op_pre(DECL_ARGS)
1406: {
1407:
1.60 schwarze 1408: switch (n->type) {
1.1 kristaps 1409: case (MDOC_BODY):
1410: term_word(p, "\\(lB");
1411: p->flags |= TERMP_NOSPACE;
1412: break;
1413: default:
1414: break;
1415: }
1416: return(1);
1417: }
1418:
1419:
1420: /* ARGSUSED */
1421: static int
1422: termp_bt_pre(DECL_ARGS)
1423: {
1424:
1425: term_word(p, "is currently in beta test.");
1.84 ! schwarze 1426: p->flags |= TERMP_SENTENCE;
1.59 schwarze 1427: return(0);
1.1 kristaps 1428: }
1429:
1430:
1431: /* ARGSUSED */
1432: static void
1433: termp_lb_post(DECL_ARGS)
1434: {
1435:
1.77 schwarze 1436: if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
1.57 schwarze 1437: term_newln(p);
1.1 kristaps 1438: }
1439:
1440:
1441: /* ARGSUSED */
1442: static int
1443: termp_ud_pre(DECL_ARGS)
1444: {
1445:
1446: term_word(p, "currently under development.");
1.84 ! schwarze 1447: p->flags |= TERMP_SENTENCE;
1.60 schwarze 1448: return(0);
1.1 kristaps 1449: }
1450:
1451:
1452: /* ARGSUSED */
1453: static int
1454: termp_d1_pre(DECL_ARGS)
1455: {
1456:
1.60 schwarze 1457: if (MDOC_BLOCK != n->type)
1.1 kristaps 1458: return(1);
1459: term_newln(p);
1.28 schwarze 1460: p->offset += (INDENT + 1);
1.1 kristaps 1461: return(1);
1462: }
1463:
1464:
1465: /* ARGSUSED */
1466: static void
1467: termp_d1_post(DECL_ARGS)
1468: {
1469:
1.60 schwarze 1470: if (MDOC_BLOCK != n->type)
1.1 kristaps 1471: return;
1472: term_newln(p);
1473: }
1474:
1475:
1476: /* ARGSUSED */
1477: static int
1478: termp_aq_pre(DECL_ARGS)
1479: {
1480:
1.60 schwarze 1481: if (MDOC_BODY != n->type)
1.1 kristaps 1482: return(1);
1483: term_word(p, "\\(la");
1484: p->flags |= TERMP_NOSPACE;
1485: return(1);
1486: }
1487:
1488:
1489: /* ARGSUSED */
1490: static void
1491: termp_aq_post(DECL_ARGS)
1492: {
1493:
1.60 schwarze 1494: if (MDOC_BODY != n->type)
1.1 kristaps 1495: return;
1496: p->flags |= TERMP_NOSPACE;
1497: term_word(p, "\\(ra");
1498: }
1499:
1500:
1501: /* ARGSUSED */
1502: static int
1503: termp_ft_pre(DECL_ARGS)
1504: {
1505:
1.77 schwarze 1506: if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
1.60 schwarze 1507: if (n->prev && MDOC_Fo == n->prev->tok)
1.1 kristaps 1508: term_vspace(p);
1.65 schwarze 1509:
1510: term_fontpush(p, TERMFONT_UNDER);
1.1 kristaps 1511: return(1);
1512: }
1513:
1514:
1515: /* ARGSUSED */
1516: static void
1517: termp_ft_post(DECL_ARGS)
1518: {
1519:
1.77 schwarze 1520: if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
1.1 kristaps 1521: term_newln(p);
1522: }
1523:
1524:
1525: /* ARGSUSED */
1526: static int
1527: termp_fn_pre(DECL_ARGS)
1528: {
1.60 schwarze 1529: const struct mdoc_node *nn;
1.1 kristaps 1530:
1.65 schwarze 1531: term_fontpush(p, TERMFONT_BOLD);
1.60 schwarze 1532: term_word(p, n->child->string);
1.65 schwarze 1533: term_fontpop(p);
1.1 kristaps 1534:
1535: p->flags |= TERMP_NOSPACE;
1536: term_word(p, "(");
1537:
1.60 schwarze 1538: for (nn = n->child->next; nn; nn = nn->next) {
1.65 schwarze 1539: term_fontpush(p, TERMFONT_UNDER);
1.60 schwarze 1540: term_word(p, nn->string);
1.65 schwarze 1541: term_fontpop(p);
1542:
1.60 schwarze 1543: if (nn->next)
1.1 kristaps 1544: term_word(p, ",");
1545: }
1546:
1547: term_word(p, ")");
1548:
1.60 schwarze 1549: if (SEC_SYNOPSIS == n->sec)
1.1 kristaps 1550: term_word(p, ";");
1551:
1552: return(0);
1553: }
1554:
1555:
1556: /* ARGSUSED */
1557: static void
1558: termp_fn_post(DECL_ARGS)
1559: {
1560:
1.77 schwarze 1561: if (n->sec == SEC_SYNOPSIS && n->next && MDOC_LINE & n->flags)
1.1 kristaps 1562: term_vspace(p);
1563: }
1564:
1565:
1566: /* ARGSUSED */
1567: static int
1568: termp_fa_pre(DECL_ARGS)
1569: {
1.60 schwarze 1570: const struct mdoc_node *nn;
1.1 kristaps 1571:
1.60 schwarze 1572: if (n->parent->tok != MDOC_Fo) {
1.65 schwarze 1573: term_fontpush(p, TERMFONT_UNDER);
1.1 kristaps 1574: return(1);
1575: }
1576:
1.60 schwarze 1577: for (nn = n->child; nn; nn = nn->next) {
1.65 schwarze 1578: term_fontpush(p, TERMFONT_UNDER);
1.60 schwarze 1579: term_word(p, nn->string);
1.65 schwarze 1580: term_fontpop(p);
1581:
1.60 schwarze 1582: if (nn->next)
1.1 kristaps 1583: term_word(p, ",");
1584: }
1585:
1.60 schwarze 1586: if (n->child && n->next && n->next->tok == MDOC_Fa)
1.1 kristaps 1587: term_word(p, ",");
1588:
1589: return(0);
1590: }
1591:
1592:
1593: /* ARGSUSED */
1594: static int
1595: termp_bd_pre(DECL_ARGS)
1596: {
1.75 schwarze 1597: size_t tabwidth;
1.60 schwarze 1598: int i, type;
1.77 schwarze 1599: size_t rm, rmax;
1.60 schwarze 1600: const struct mdoc_node *nn;
1.1 kristaps 1601:
1.60 schwarze 1602: if (MDOC_BLOCK == n->type) {
1.61 schwarze 1603: print_bvspace(p, n, n);
1.45 schwarze 1604: return(1);
1.73 schwarze 1605: } else if (MDOC_HEAD == n->type)
1606: return(0);
1.1 kristaps 1607:
1.60 schwarze 1608: nn = n->parent;
1.1 kristaps 1609:
1.77 schwarze 1610: type = arg_disptype(nn);
1611: assert(-1 != type);
1612:
1613: if (-1 != (i = arg_getattr(MDOC_Offset, nn)))
1614: p->offset += a2offs(&nn->args->argv[i]);
1.60 schwarze 1615:
1616: /*
1617: * If -ragged or -filled are specified, the block does nothing
1618: * but change the indentation. If -unfilled or -literal are
1619: * specified, text is printed exactly as entered in the display:
1620: * for macro lines, a newline is appended to the line. Blank
1621: * lines are allowed.
1622: */
1.48 schwarze 1623:
1.60 schwarze 1624: if (MDOC_Literal != type && MDOC_Unfilled != type)
1.1 kristaps 1625: return(1);
1626:
1.75 schwarze 1627: tabwidth = p->tabwidth;
1628: p->tabwidth = 8;
1.77 schwarze 1629: rm = p->rmargin;
1630: rmax = p->maxrmargin;
1631: p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1632:
1.60 schwarze 1633: for (nn = n->child; nn; nn = nn->next) {
1.48 schwarze 1634: p->flags |= TERMP_NOSPACE;
1.65 schwarze 1635: print_mdoc_node(p, pair, m, nn);
1.75 schwarze 1636: if (NULL == nn->prev ||
1637: nn->prev->line < nn->line ||
1638: NULL == nn->next)
1.1 kristaps 1639: term_flushln(p);
1640: }
1.75 schwarze 1641: p->tabwidth = tabwidth;
1.1 kristaps 1642:
1.77 schwarze 1643: p->rmargin = rm;
1644: p->maxrmargin = rmax;
1.1 kristaps 1645: return(0);
1646: }
1647:
1648:
1649: /* ARGSUSED */
1650: static void
1651: termp_bd_post(DECL_ARGS)
1652: {
1.77 schwarze 1653: int type;
1654: size_t rm, rmax;
1.1 kristaps 1655:
1.60 schwarze 1656: if (MDOC_BODY != n->type)
1.1 kristaps 1657: return;
1.77 schwarze 1658:
1659: type = arg_disptype(n->parent);
1660: assert(-1 != type);
1661:
1662: rm = p->rmargin;
1663: rmax = p->maxrmargin;
1664:
1665: if (MDOC_Literal == type || MDOC_Unfilled == type)
1666: p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1667:
1.48 schwarze 1668: p->flags |= TERMP_NOSPACE;
1.75 schwarze 1669: term_newln(p);
1.77 schwarze 1670:
1671: p->rmargin = rm;
1672: p->maxrmargin = rmax;
1.1 kristaps 1673: }
1674:
1675:
1676: /* ARGSUSED */
1677: static int
1678: termp_qq_pre(DECL_ARGS)
1679: {
1680:
1.60 schwarze 1681: if (MDOC_BODY != n->type)
1.1 kristaps 1682: return(1);
1683: term_word(p, "\"");
1684: p->flags |= TERMP_NOSPACE;
1685: return(1);
1686: }
1687:
1688:
1689: /* ARGSUSED */
1690: static void
1691: termp_qq_post(DECL_ARGS)
1692: {
1693:
1.60 schwarze 1694: if (MDOC_BODY != n->type)
1.1 kristaps 1695: return;
1696: p->flags |= TERMP_NOSPACE;
1697: term_word(p, "\"");
1698: }
1699:
1700:
1701: /* ARGSUSED */
1702: static void
1703: termp_bx_post(DECL_ARGS)
1704: {
1705:
1.60 schwarze 1706: if (n->child)
1.1 kristaps 1707: p->flags |= TERMP_NOSPACE;
1708: term_word(p, "BSD");
1709: }
1710:
1711:
1712: /* ARGSUSED */
1713: static int
1.26 schwarze 1714: termp_xx_pre(DECL_ARGS)
1.1 kristaps 1715: {
1.26 schwarze 1716: const char *pp;
1.1 kristaps 1717:
1.26 schwarze 1718: pp = NULL;
1.60 schwarze 1719: switch (n->tok) {
1.26 schwarze 1720: case (MDOC_Bsx):
1721: pp = "BSDI BSD/OS";
1722: break;
1723: case (MDOC_Dx):
1.64 schwarze 1724: pp = "DragonFly";
1.26 schwarze 1725: break;
1726: case (MDOC_Fx):
1727: pp = "FreeBSD";
1728: break;
1729: case (MDOC_Nx):
1730: pp = "NetBSD";
1731: break;
1732: case (MDOC_Ox):
1733: pp = "OpenBSD";
1734: break;
1735: case (MDOC_Ux):
1736: pp = "UNIX";
1737: break;
1738: default:
1739: break;
1740: }
1.1 kristaps 1741:
1.26 schwarze 1742: assert(pp);
1743: term_word(p, pp);
1.1 kristaps 1744: return(1);
1745: }
1746:
1747:
1748: /* ARGSUSED */
1749: static int
1750: termp_sq_pre(DECL_ARGS)
1751: {
1752:
1.60 schwarze 1753: if (MDOC_BODY != n->type)
1.1 kristaps 1754: return(1);
1755: term_word(p, "\\(oq");
1756: p->flags |= TERMP_NOSPACE;
1757: return(1);
1758: }
1759:
1760:
1761: /* ARGSUSED */
1762: static void
1763: termp_sq_post(DECL_ARGS)
1764: {
1765:
1.60 schwarze 1766: if (MDOC_BODY != n->type)
1.1 kristaps 1767: return;
1768: p->flags |= TERMP_NOSPACE;
1769: term_word(p, "\\(aq");
1770: }
1771:
1772:
1773: /* ARGSUSED */
1774: static int
1775: termp_pf_pre(DECL_ARGS)
1776: {
1777:
1778: p->flags |= TERMP_IGNDELIM;
1779: return(1);
1780: }
1781:
1782:
1783: /* ARGSUSED */
1784: static void
1785: termp_pf_post(DECL_ARGS)
1786: {
1787:
1788: p->flags &= ~TERMP_IGNDELIM;
1789: p->flags |= TERMP_NOSPACE;
1790: }
1791:
1792:
1793: /* ARGSUSED */
1794: static int
1795: termp_ss_pre(DECL_ARGS)
1796: {
1797:
1.60 schwarze 1798: switch (n->type) {
1.1 kristaps 1799: case (MDOC_BLOCK):
1800: term_newln(p);
1.60 schwarze 1801: if (n->prev)
1.1 kristaps 1802: term_vspace(p);
1803: break;
1804: case (MDOC_HEAD):
1.65 schwarze 1805: term_fontpush(p, TERMFONT_BOLD);
1.3 schwarze 1806: p->offset = HALFINDENT;
1.1 kristaps 1807: break;
1808: default:
1809: break;
1810: }
1811:
1812: return(1);
1813: }
1814:
1815:
1816: /* ARGSUSED */
1817: static void
1818: termp_ss_post(DECL_ARGS)
1819: {
1820:
1.60 schwarze 1821: if (MDOC_HEAD == n->type)
1.1 kristaps 1822: term_newln(p);
1823: }
1824:
1825:
1826: /* ARGSUSED */
1827: static int
1828: termp_cd_pre(DECL_ARGS)
1829: {
1830:
1.65 schwarze 1831: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1832: term_newln(p);
1833: return(1);
1834: }
1835:
1836:
1837: /* ARGSUSED */
1838: static int
1839: termp_in_pre(DECL_ARGS)
1840: {
1841:
1.65 schwarze 1842: term_fontpush(p, TERMFONT_BOLD);
1.60 schwarze 1843: if (SEC_SYNOPSIS == n->sec)
1.23 schwarze 1844: term_word(p, "#include");
1845:
1.1 kristaps 1846: term_word(p, "<");
1847: p->flags |= TERMP_NOSPACE;
1848: return(1);
1849: }
1850:
1851:
1852: /* ARGSUSED */
1853: static void
1854: termp_in_post(DECL_ARGS)
1855: {
1856:
1.65 schwarze 1857: term_fontpush(p, TERMFONT_BOLD);
1.59 schwarze 1858: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1859: term_word(p, ">");
1.65 schwarze 1860: term_fontpop(p);
1.1 kristaps 1861:
1.77 schwarze 1862: if (SEC_SYNOPSIS != n->sec && ! (MDOC_LINE & n->flags))
1.1 kristaps 1863: return;
1.23 schwarze 1864:
1865: term_newln(p);
1866: /*
1867: * XXX Not entirely correct. If `.In foo bar' is specified in
1868: * the SYNOPSIS section, then it produces a single break after
1869: * the <foo>; mandoc asserts a vertical space. Since this
1870: * construction is rarely used, I think it's fine.
1871: */
1.60 schwarze 1872: if (n->next && MDOC_In != n->next->tok)
1.1 kristaps 1873: term_vspace(p);
1.38 schwarze 1874: }
1875:
1876:
1877: /* ARGSUSED */
1878: static int
1879: termp_sp_pre(DECL_ARGS)
1880: {
1.61 schwarze 1881: size_t i, len;
1.38 schwarze 1882:
1.60 schwarze 1883: switch (n->tok) {
1.54 schwarze 1884: case (MDOC_sp):
1.62 schwarze 1885: len = n->child ? a2height(n->child) : 1;
1.54 schwarze 1886: break;
1887: case (MDOC_br):
1888: len = 0;
1889: break;
1890: default:
1891: len = 1;
1892: break;
1.38 schwarze 1893: }
1894:
1895: if (0 == len)
1896: term_newln(p);
1897: for (i = 0; i < len; i++)
1898: term_vspace(p);
1899:
1900: return(0);
1901: }
1902:
1903:
1904: /* ARGSUSED */
1905: static int
1.1 kristaps 1906: termp_brq_pre(DECL_ARGS)
1907: {
1908:
1.60 schwarze 1909: if (MDOC_BODY != n->type)
1.1 kristaps 1910: return(1);
1911: term_word(p, "\\(lC");
1912: p->flags |= TERMP_NOSPACE;
1913: return(1);
1914: }
1915:
1916:
1917: /* ARGSUSED */
1918: static void
1919: termp_brq_post(DECL_ARGS)
1920: {
1921:
1.60 schwarze 1922: if (MDOC_BODY != n->type)
1.1 kristaps 1923: return;
1924: p->flags |= TERMP_NOSPACE;
1925: term_word(p, "\\(rC");
1926: }
1927:
1928:
1929: /* ARGSUSED */
1930: static int
1931: termp_bq_pre(DECL_ARGS)
1932: {
1933:
1.60 schwarze 1934: if (MDOC_BODY != n->type)
1.1 kristaps 1935: return(1);
1936: term_word(p, "\\(lB");
1937: p->flags |= TERMP_NOSPACE;
1938: return(1);
1939: }
1940:
1941:
1942: /* ARGSUSED */
1943: static void
1944: termp_bq_post(DECL_ARGS)
1945: {
1946:
1.60 schwarze 1947: if (MDOC_BODY != n->type)
1.1 kristaps 1948: return;
1949: p->flags |= TERMP_NOSPACE;
1950: term_word(p, "\\(rB");
1951: }
1952:
1953:
1954: /* ARGSUSED */
1955: static int
1956: termp_pq_pre(DECL_ARGS)
1957: {
1958:
1.60 schwarze 1959: if (MDOC_BODY != n->type)
1.1 kristaps 1960: return(1);
1961: term_word(p, "\\&(");
1962: p->flags |= TERMP_NOSPACE;
1963: return(1);
1964: }
1965:
1966:
1967: /* ARGSUSED */
1968: static void
1969: termp_pq_post(DECL_ARGS)
1970: {
1971:
1.60 schwarze 1972: if (MDOC_BODY != n->type)
1.1 kristaps 1973: return;
1974: term_word(p, ")");
1975: }
1976:
1977:
1978: /* ARGSUSED */
1979: static int
1980: termp_fo_pre(DECL_ARGS)
1981: {
1.60 schwarze 1982: const struct mdoc_node *nn;
1.1 kristaps 1983:
1.60 schwarze 1984: if (MDOC_BODY == n->type) {
1.31 schwarze 1985: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1986: term_word(p, "(");
1987: p->flags |= TERMP_NOSPACE;
1988: return(1);
1.60 schwarze 1989: } else if (MDOC_HEAD != n->type)
1.1 kristaps 1990: return(1);
1991:
1.65 schwarze 1992: term_fontpush(p, TERMFONT_BOLD);
1.60 schwarze 1993: for (nn = n->child; nn; nn = nn->next) {
1994: assert(MDOC_TEXT == nn->type);
1995: term_word(p, nn->string);
1.1 kristaps 1996: }
1.65 schwarze 1997: term_fontpop(p);
1.1 kristaps 1998:
1999: return(0);
2000: }
2001:
2002:
2003: /* ARGSUSED */
2004: static void
2005: termp_fo_post(DECL_ARGS)
2006: {
2007:
1.60 schwarze 2008: if (MDOC_BODY != n->type)
1.1 kristaps 2009: return;
2010: p->flags |= TERMP_NOSPACE;
2011: term_word(p, ")");
2012: p->flags |= TERMP_NOSPACE;
2013: term_word(p, ";");
2014: term_newln(p);
2015: }
2016:
2017:
2018: /* ARGSUSED */
2019: static int
2020: termp_bf_pre(DECL_ARGS)
2021: {
1.60 schwarze 2022: const struct mdoc_node *nn;
1.1 kristaps 2023:
1.60 schwarze 2024: if (MDOC_HEAD == n->type)
1.1 kristaps 2025: return(0);
1.60 schwarze 2026: else if (MDOC_BLOCK != n->type)
1.1 kristaps 2027: return(1);
2028:
1.60 schwarze 2029: if (NULL == (nn = n->head->child)) {
2030: if (arg_hasattr(MDOC_Emphasis, n))
1.65 schwarze 2031: term_fontpush(p, TERMFONT_UNDER);
1.60 schwarze 2032: else if (arg_hasattr(MDOC_Symbolic, n))
1.65 schwarze 2033: term_fontpush(p, TERMFONT_BOLD);
2034: else
2035: term_fontpush(p, TERMFONT_NONE);
1.1 kristaps 2036:
2037: return(1);
2038: }
2039:
1.60 schwarze 2040: assert(MDOC_TEXT == nn->type);
2041: if (0 == strcmp("Em", nn->string))
1.65 schwarze 2042: term_fontpush(p, TERMFONT_UNDER);
1.60 schwarze 2043: else if (0 == strcmp("Sy", nn->string))
1.65 schwarze 2044: term_fontpush(p, TERMFONT_BOLD);
2045: else
2046: term_fontpush(p, TERMFONT_NONE);
1.1 kristaps 2047:
2048: return(1);
2049: }
2050:
2051:
2052: /* ARGSUSED */
2053: static int
2054: termp_sm_pre(DECL_ARGS)
2055: {
2056:
1.60 schwarze 2057: assert(n->child && MDOC_TEXT == n->child->type);
1.68 schwarze 2058: if (0 == strcmp("on", n->child->string))
1.1 kristaps 2059: p->flags &= ~TERMP_NONOSPACE;
1.68 schwarze 2060: else
1.1 kristaps 2061: p->flags |= TERMP_NONOSPACE;
2062:
2063: return(0);
2064: }
2065:
2066:
2067: /* ARGSUSED */
2068: static int
2069: termp_ap_pre(DECL_ARGS)
2070: {
2071:
2072: p->flags |= TERMP_NOSPACE;
2073: term_word(p, "\\(aq");
2074: p->flags |= TERMP_NOSPACE;
2075: return(1);
2076: }
2077:
2078:
2079: /* ARGSUSED */
2080: static void
2081: termp____post(DECL_ARGS)
2082: {
2083:
1.62 schwarze 2084: /* TODO: %U. */
2085:
1.1 kristaps 2086: p->flags |= TERMP_NOSPACE;
1.60 schwarze 2087: term_word(p, n->next ? "," : ".");
1.1 kristaps 2088: }
2089:
2090:
2091: /* ARGSUSED */
2092: static int
1.65 schwarze 2093: termp_li_pre(DECL_ARGS)
2094: {
2095:
2096: term_fontpush(p, TERMFONT_NONE);
2097: return(1);
2098: }
2099:
2100:
2101: /* ARGSUSED */
2102: static int
1.1 kristaps 2103: termp_lk_pre(DECL_ARGS)
2104: {
1.60 schwarze 2105: const struct mdoc_node *nn;
1.1 kristaps 2106:
1.65 schwarze 2107: term_fontpush(p, TERMFONT_UNDER);
1.62 schwarze 2108: nn = n->child;
2109:
2110: if (NULL == nn->next)
1.6 schwarze 2111: return(1);
1.1 kristaps 2112:
1.60 schwarze 2113: term_word(p, nn->string);
1.65 schwarze 2114: term_fontpop(p);
1.62 schwarze 2115:
1.1 kristaps 2116: p->flags |= TERMP_NOSPACE;
2117: term_word(p, ":");
2118:
1.65 schwarze 2119: term_fontpush(p, TERMFONT_BOLD);
1.60 schwarze 2120: for (nn = nn->next; nn; nn = nn->next)
2121: term_word(p, nn->string);
1.65 schwarze 2122: term_fontpop(p);
1.6 schwarze 2123:
1.1 kristaps 2124: return(0);
2125: }
2126:
2127:
2128: /* ARGSUSED */
2129: static int
1.54 schwarze 2130: termp_under_pre(DECL_ARGS)
1.1 kristaps 2131: {
2132:
1.65 schwarze 2133: term_fontpush(p, TERMFONT_UNDER);
1.1 kristaps 2134: return(1);
2135: }