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