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