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