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