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