Annotation of mandoc/mdoc_term.c, Revision 1.360
1.360 ! schwarze 1: /* $Id: mdoc_term.c,v 1.359 2017/06/01 19:05:37 schwarze Exp $ */
1.1 kristaps 2: /*
1.217 schwarze 3: * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.339 schwarze 4: * Copyright (c) 2010, 2012-2017 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.314 schwarze 11: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1.6 kristaps 12: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.314 schwarze 13: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1.6 kristaps 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: #include "config.h"
20:
1.1 kristaps 21: #include <sys/types.h>
22:
23: #include <assert.h>
24: #include <ctype.h>
1.302 schwarze 25: #include <limits.h>
1.118 kristaps 26: #include <stdint.h>
1.1 kristaps 27: #include <stdio.h>
28: #include <stdlib.h>
29: #include <string.h>
30:
1.314 schwarze 31: #include "mandoc_aux.h"
1.125 kristaps 32: #include "mandoc.h"
1.314 schwarze 33: #include "roff.h"
34: #include "mdoc.h"
1.92 kristaps 35: #include "out.h"
1.1 kristaps 36: #include "term.h"
1.320 schwarze 37: #include "tag.h"
1.89 kristaps 38: #include "main.h"
1.1 kristaps 39:
40: struct termpair {
41: struct termpair *ppair;
1.31 kristaps 42: int count;
1.1 kristaps 43: };
44:
1.31 kristaps 45: #define DECL_ARGS struct termp *p, \
46: struct termpair *pair, \
1.316 schwarze 47: const struct roff_meta *meta, \
1.315 schwarze 48: struct roff_node *n
1.1 kristaps 49:
50: struct termact {
51: int (*pre)(DECL_ARGS);
52: void (*post)(DECL_ARGS);
53: };
54:
1.302 schwarze 55: static int a2width(const struct termp *, const char *);
1.96 kristaps 56:
57: static void print_bvspace(struct termp *,
1.315 schwarze 58: const struct roff_node *,
59: const struct roff_node *);
1.264 schwarze 60: static void print_mdoc_node(DECL_ARGS);
1.145 kristaps 61: static void print_mdoc_nodelist(DECL_ARGS);
1.316 schwarze 62: static void print_mdoc_head(struct termp *, const struct roff_meta *);
63: static void print_mdoc_foot(struct termp *, const struct roff_meta *);
1.264 schwarze 64: static void synopsis_pre(struct termp *,
1.315 schwarze 65: const struct roff_node *);
1.96 kristaps 66:
1.31 kristaps 67: static void termp____post(DECL_ARGS);
1.203 kristaps 68: static void termp__t_post(DECL_ARGS);
1.31 kristaps 69: static void termp_bd_post(DECL_ARGS);
1.159 schwarze 70: static void termp_bk_post(DECL_ARGS);
1.31 kristaps 71: static void termp_bl_post(DECL_ARGS);
1.306 schwarze 72: static void termp_eo_post(DECL_ARGS);
1.241 schwarze 73: static void termp_fd_post(DECL_ARGS);
1.31 kristaps 74: static void termp_fo_post(DECL_ARGS);
75: static void termp_in_post(DECL_ARGS);
76: static void termp_it_post(DECL_ARGS);
77: static void termp_lb_post(DECL_ARGS);
1.164 schwarze 78: static void termp_nm_post(DECL_ARGS);
1.31 kristaps 79: static void termp_pf_post(DECL_ARGS);
1.188 kristaps 80: static void termp_quote_post(DECL_ARGS);
1.31 kristaps 81: static void termp_sh_post(DECL_ARGS);
82: static void termp_ss_post(DECL_ARGS);
1.339 schwarze 83: static void termp_xx_post(DECL_ARGS);
1.31 kristaps 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_cd_pre(DECL_ARGS);
95: static int termp_d1_pre(DECL_ARGS);
1.306 schwarze 96: static int termp_eo_pre(DECL_ARGS);
1.334 schwarze 97: static int termp_em_pre(DECL_ARGS);
1.323 schwarze 98: static int termp_er_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.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_sh_pre(DECL_ARGS);
1.294 schwarze 116: static int termp_skip_pre(DECL_ARGS);
1.31 kristaps 117: static int termp_sm_pre(DECL_ARGS);
1.355 schwarze 118: static int termp_pp_pre(DECL_ARGS);
1.31 kristaps 119: static int termp_ss_pre(DECL_ARGS);
1.334 schwarze 120: static int termp_sy_pre(DECL_ARGS);
1.320 schwarze 121: static int termp_tag_pre(DECL_ARGS);
1.69 kristaps 122: static int termp_under_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.350 schwarze 127: static const struct termact __termacts[MDOC_MAX - MDOC_Dd] = {
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 */
1.355 schwarze 133: { termp_pp_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.282 schwarze 142: { termp_an_pre, NULL }, /* An */
1.350 schwarze 143: { termp_ap_pre, NULL }, /* Ap */
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.325 schwarze 147: { termp_li_pre, NULL }, /* Dv */
1.323 schwarze 148: { termp_er_pre, NULL }, /* Er */
1.320 schwarze 149: { termp_tag_pre, 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.341 schwarze 164: { termp_ex_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.339 schwarze 188: { termp_xx_pre, termp_xx_post }, /* Bsx */
1.340 schwarze 189: { NULL, NULL }, /* Bx */
1.294 schwarze 190: { termp_skip_pre, NULL }, /* Db */
1.1 kristaps 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.334 schwarze 196: { termp_em_pre, NULL }, /* Em */
1.306 schwarze 197: { termp_eo_pre, termp_eo_post }, /* Eo */
1.339 schwarze 198: { termp_xx_pre, termp_xx_post }, /* Fx */
1.176 kristaps 199: { termp_bold_pre, NULL }, /* Ms */
1.290 schwarze 200: { termp_li_pre, NULL }, /* No */
1.1 kristaps 201: { termp_ns_pre, NULL }, /* Ns */
1.339 schwarze 202: { termp_xx_pre, termp_xx_post }, /* Nx */
203: { termp_xx_pre, termp_xx_post }, /* 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 */
1.334 schwarze 219: { termp_sy_pre, NULL }, /* Sy */
1.1 kristaps 220: { NULL, NULL }, /* Tn */
1.339 schwarze 221: { termp_xx_pre, termp_xx_post }, /* 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 */
1.341 schwarze 230: { NULL, NULL }, /* Bt */
1.1 kristaps 231: { NULL, NULL }, /* Hf */
1.268 schwarze 232: { termp_under_pre, NULL }, /* Fr */
1.341 schwarze 233: { NULL, NULL }, /* Ud */
1.37 kristaps 234: { NULL, termp_lb_post }, /* Lb */
1.355 schwarze 235: { termp_pp_pre, NULL }, /* Lp */
1.264 schwarze 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.294 schwarze 242: { termp_skip_pre, NULL }, /* Es */
1.268 schwarze 243: { termp_quote_pre, termp_quote_post }, /* En */
1.339 schwarze 244: { termp_xx_pre, termp_xx_post }, /* Dx */
1.264 schwarze 245: { NULL, termp____post }, /* %Q */
246: { NULL, termp____post }, /* %U */
247: { NULL, NULL }, /* Ta */
1.1 kristaps 248: };
1.350 schwarze 249: static const struct termact *const termacts = __termacts - MDOC_Dd;
1.1 kristaps 250:
1.322 schwarze 251: static int fn_prio;
1.1 kristaps 252:
1.350 schwarze 253:
1.70 kristaps 254: void
1.318 schwarze 255: terminal_mdoc(void *arg, const struct roff_man *mdoc)
1.1 kristaps 256: {
1.315 schwarze 257: struct roff_node *n;
1.89 kristaps 258: struct termp *p;
1.342 schwarze 259: size_t save_defindent;
1.89 kristaps 260:
261: p = (struct termp *)arg;
1.281 schwarze 262: p->rmargin = p->maxrmargin = p->defrmargin;
1.356 schwarze 263: term_tab_set(p, NULL);
264: term_tab_set(p, "T");
265: term_tab_set(p, ".5i");
1.70 kristaps 266:
1.319 schwarze 267: n = mdoc->first->child;
1.281 schwarze 268: if (p->synopsisonly) {
269: while (n != NULL) {
270: if (n->tok == MDOC_Sh && n->sec == SEC_SYNOPSIS) {
271: if (n->child->next->child != NULL)
272: print_mdoc_nodelist(p, NULL,
1.319 schwarze 273: &mdoc->meta,
274: n->child->next->child);
1.281 schwarze 275: term_newln(p);
276: break;
277: }
278: n = n->next;
279: }
280: } else {
1.342 schwarze 281: save_defindent = p->defindent;
1.281 schwarze 282: if (p->defindent == 0)
283: p->defindent = 5;
1.319 schwarze 284: term_begin(p, print_mdoc_head, print_mdoc_foot,
285: &mdoc->meta);
1.337 schwarze 286: while (n != NULL && n->flags & NODE_NOPRT)
287: n = n->next;
1.281 schwarze 288: if (n != NULL) {
289: if (n->tok != MDOC_Sh)
290: term_vspace(p);
1.319 schwarze 291: print_mdoc_nodelist(p, NULL, &mdoc->meta, n);
1.281 schwarze 292: }
293: term_end(p);
1.342 schwarze 294: p->defindent = save_defindent;
1.271 schwarze 295: }
1.1 kristaps 296: }
297:
1.3 kristaps 298: static void
1.102 kristaps 299: print_mdoc_nodelist(DECL_ARGS)
1.1 kristaps 300: {
301:
1.304 schwarze 302: while (n != NULL) {
303: print_mdoc_node(p, pair, meta, n);
304: n = n->next;
305: }
1.1 kristaps 306: }
307:
1.3 kristaps 308: static void
1.102 kristaps 309: print_mdoc_node(DECL_ARGS)
1.1 kristaps 310: {
1.102 kristaps 311: int chld;
1.1 kristaps 312: struct termpair npair;
1.30 kristaps 313: size_t offset, rmargin;
1.1 kristaps 314:
1.337 schwarze 315: if (n->flags & NODE_NOPRT)
316: return;
317:
1.70 kristaps 318: chld = 1;
1.29 kristaps 319: offset = p->offset;
1.30 kristaps 320: rmargin = p->rmargin;
1.338 schwarze 321: n->flags &= ~NODE_ENDED;
1.305 schwarze 322: n->prev_font = p->fonti;
1.29 kristaps 323:
1.97 kristaps 324: memset(&npair, 0, sizeof(struct termpair));
1.1 kristaps 325: npair.ppair = pair;
1.172 kristaps 326:
327: /*
328: * Keeps only work until the end of a line. If a keep was
329: * invoked in a prior line, revert it to PREKEEP.
330: */
331:
1.338 schwarze 332: if (p->flags & TERMP_KEEP && n->flags & NODE_LINE) {
1.307 schwarze 333: p->flags &= ~TERMP_KEEP;
334: p->flags |= TERMP_PREKEEP;
1.172 kristaps 335: }
1.197 schwarze 336:
337: /*
1.217 schwarze 338: * After the keep flags have been set up, we may now
339: * produce output. Note that some pre-handlers do so.
340: */
341:
342: switch (n->type) {
1.314 schwarze 343: case ROFFT_TEXT:
1.357 schwarze 344: if (*n->string == ' ' && n->flags & NODE_LINE &&
345: (p->flags & TERMP_NONEWLINE) == 0)
1.217 schwarze 346: term_newln(p);
1.338 schwarze 347: if (NODE_DELIMC & n->flags)
1.222 kristaps 348: p->flags |= TERMP_NOSPACE;
1.217 schwarze 349: term_word(p, n->string);
1.338 schwarze 350: if (NODE_DELIMO & n->flags)
1.222 kristaps 351: p->flags |= TERMP_NOSPACE;
1.217 schwarze 352: break;
1.314 schwarze 353: case ROFFT_EQN:
1.338 schwarze 354: if ( ! (n->flags & NODE_LINE))
1.284 schwarze 355: p->flags |= TERMP_NOSPACE;
1.233 kristaps 356: term_eqn(p, n->eqn);
1.338 schwarze 357: if (n->next != NULL && ! (n->next->flags & NODE_LINE))
1.285 schwarze 358: p->flags |= TERMP_NOSPACE;
1.217 schwarze 359: break;
1.314 schwarze 360: case ROFFT_TBL:
1.313 schwarze 361: if (p->tbl.cols == NULL)
362: term_newln(p);
1.217 schwarze 363: term_tbl(p, n->span);
364: break;
365: default:
1.351 schwarze 366: if (n->tok < ROFF_MAX) {
1.352 schwarze 367: roff_term_pre(p, n);
1.354 schwarze 368: return;
1.351 schwarze 369: }
370: assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
1.350 schwarze 371: if (termacts[n->tok].pre != NULL &&
1.331 schwarze 372: (n->end == ENDBODY_NOT || n->child != NULL))
1.217 schwarze 373: chld = (*termacts[n->tok].pre)
1.245 schwarze 374: (p, &npair, meta, n);
1.217 schwarze 375: break;
376: }
377:
1.86 kristaps 378: if (chld && n->child)
1.245 schwarze 379: print_mdoc_nodelist(p, &npair, meta, n->child);
1.1 kristaps 380:
1.244 schwarze 381: term_fontpopq(p,
1.310 schwarze 382: (ENDBODY_NOT == n->end ? n : n->body)->prev_font);
1.46 kristaps 383:
1.206 kristaps 384: switch (n->type) {
1.314 schwarze 385: case ROFFT_TEXT:
1.206 kristaps 386: break;
1.314 schwarze 387: case ROFFT_TBL:
1.216 kristaps 388: break;
1.314 schwarze 389: case ROFFT_EQN:
1.206 kristaps 390: break;
391: default:
1.354 schwarze 392: if (termacts[n->tok].post == NULL || n->flags & NODE_ENDED)
1.206 kristaps 393: break;
1.245 schwarze 394: (void)(*termacts[n->tok].post)(p, &npair, meta, n);
1.162 schwarze 395:
396: /*
397: * Explicit end tokens not only call the post
398: * handler, but also tell the respective block
399: * that it must not call the post handler again.
400: */
1.165 kristaps 401: if (ENDBODY_NOT != n->end)
1.338 schwarze 402: n->body->flags |= NODE_ENDED;
1.206 kristaps 403: break;
1.162 schwarze 404: }
1.121 kristaps 405:
1.338 schwarze 406: if (NODE_EOS & n->flags)
1.121 kristaps 407: p->flags |= TERMP_SENTENCE;
1.29 kristaps 408:
1.359 schwarze 409: if (n->type != ROFFT_TEXT)
410: p->offset = offset;
1.354 schwarze 411: p->rmargin = rmargin;
1.1 kristaps 412: }
413:
1.3 kristaps 414: static void
1.316 schwarze 415: print_mdoc_foot(struct termp *p, const struct roff_meta *meta)
1.1 kristaps 416: {
1.292 schwarze 417: size_t sz;
1.144 kristaps 418:
1.102 kristaps 419: term_fontrepl(p, TERMFONT_NONE);
1.101 kristaps 420:
1.264 schwarze 421: /*
1.9 kristaps 422: * Output the footer in new-groff style, that is, three columns
423: * with the middle being the manual date and flanking columns
424: * being the operating system:
425: *
426: * SYSTEM DATE SYSTEM
427: */
428:
1.1 kristaps 429: term_vspace(p);
430:
1.9 kristaps 431: p->offset = 0;
1.292 schwarze 432: sz = term_strlen(p, meta->date);
433: p->rmargin = p->maxrmargin > sz ?
434: (p->maxrmargin + term_len(p, 1) - sz) / 2 : 0;
1.250 schwarze 435: p->trailspace = 1;
1.1 kristaps 436: p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
437:
1.245 schwarze 438: term_word(p, meta->os);
1.1 kristaps 439: term_flushln(p);
440:
1.9 kristaps 441: p->offset = p->rmargin;
1.292 schwarze 442: sz = term_strlen(p, meta->os);
443: p->rmargin = p->maxrmargin > sz ? p->maxrmargin - sz : 0;
1.234 schwarze 444: p->flags |= TERMP_NOSPACE;
1.9 kristaps 445:
1.245 schwarze 446: term_word(p, meta->date);
1.9 kristaps 447: term_flushln(p);
448:
1.1 kristaps 449: p->offset = p->rmargin;
450: p->rmargin = p->maxrmargin;
1.250 schwarze 451: p->trailspace = 0;
1.1 kristaps 452: p->flags &= ~TERMP_NOBREAK;
1.234 schwarze 453: p->flags |= TERMP_NOSPACE;
1.1 kristaps 454:
1.245 schwarze 455: term_word(p, meta->os);
1.1 kristaps 456: term_flushln(p);
457:
1.9 kristaps 458: p->offset = 0;
459: p->rmargin = p->maxrmargin;
460: p->flags = 0;
1.1 kristaps 461: }
462:
1.3 kristaps 463: static void
1.316 schwarze 464: print_mdoc_head(struct termp *p, const struct roff_meta *meta)
1.1 kristaps 465: {
1.267 schwarze 466: char *volume, *title;
467: size_t vollen, titlen;
1.1 kristaps 468:
469: /*
470: * The header is strange. It has three components, which are
471: * really two with the first duplicated. It goes like this:
472: *
473: * IDENTIFIER TITLE IDENTIFIER
474: *
475: * The IDENTIFIER is NAME(SECTION), which is the command-name
476: * (if given, or "unknown" if not) followed by the manual page
477: * section. These are given in `Dt'. The TITLE is a free-form
478: * string depending on the manual volume. If not specified, it
479: * switches on the manual section.
480: */
1.235 schwarze 481:
1.245 schwarze 482: assert(meta->vol);
1.267 schwarze 483: if (NULL == meta->arch)
484: volume = mandoc_strdup(meta->vol);
485: else
486: mandoc_asprintf(&volume, "%s (%s)",
487: meta->vol, meta->arch);
488: vollen = term_strlen(p, volume);
1.1 kristaps 489:
1.275 schwarze 490: if (NULL == meta->msec)
491: title = mandoc_strdup(meta->title);
492: else
493: mandoc_asprintf(&title, "%s(%s)",
494: meta->title, meta->msec);
1.235 schwarze 495: titlen = term_strlen(p, title);
1.1 kristaps 496:
1.235 schwarze 497: p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
1.250 schwarze 498: p->trailspace = 1;
1.1 kristaps 499: p->offset = 0;
1.267 schwarze 500: p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ?
501: (p->maxrmargin - vollen + term_len(p, 1)) / 2 :
1.292 schwarze 502: vollen < p->maxrmargin ? p->maxrmargin - vollen : 0;
1.1 kristaps 503:
504: term_word(p, title);
505: term_flushln(p);
506:
1.235 schwarze 507: p->flags |= TERMP_NOSPACE;
1.1 kristaps 508: p->offset = p->rmargin;
1.267 schwarze 509: p->rmargin = p->offset + vollen + titlen < p->maxrmargin ?
1.235 schwarze 510: p->maxrmargin - titlen : p->maxrmargin;
1.1 kristaps 511:
1.267 schwarze 512: term_word(p, volume);
1.1 kristaps 513: term_flushln(p);
514:
515: p->flags &= ~TERMP_NOBREAK;
1.250 schwarze 516: p->trailspace = 0;
1.235 schwarze 517: if (p->rmargin + titlen <= p->maxrmargin) {
518: p->flags |= TERMP_NOSPACE;
519: p->offset = p->rmargin;
520: p->rmargin = p->maxrmargin;
521: term_word(p, title);
522: term_flushln(p);
523: }
1.1 kristaps 524:
1.235 schwarze 525: p->flags &= ~TERMP_NOSPACE;
1.9 kristaps 526: p->offset = 0;
1.1 kristaps 527: p->rmargin = p->maxrmargin;
1.266 schwarze 528: free(title);
1.267 schwarze 529: free(volume);
1.1 kristaps 530: }
531:
1.302 schwarze 532: static int
1.157 kristaps 533: a2width(const struct termp *p, const char *v)
1.91 kristaps 534: {
1.92 kristaps 535: struct roffsu su;
1.1 kristaps 536:
1.300 schwarze 537: if (a2roffsu(v, &su, SCALE_MAX) < 2) {
1.157 kristaps 538: SCALE_HS_INIT(&su, term_strlen(p, v));
1.283 schwarze 539: su.scale /= term_strlen(p, "0");
1.302 schwarze 540: }
1.328 schwarze 541: return term_hspan(p, &su) / 24;
1.1 kristaps 542: }
543:
1.108 kristaps 544: /*
545: * Determine how much space to print out before block elements of `It'
546: * (and thus `Bl') and `Bd'. And then go ahead and print that space,
547: * too.
548: */
1.54 kristaps 549: static void
1.264 schwarze 550: print_bvspace(struct termp *p,
1.315 schwarze 551: const struct roff_node *bl,
552: const struct roff_node *n)
1.1 kristaps 553: {
1.315 schwarze 554: const struct roff_node *nn;
1.236 schwarze 555:
556: assert(n);
1.1 kristaps 557:
558: term_newln(p);
1.150 kristaps 559:
1.202 kristaps 560: if (MDOC_Bd == bl->tok && bl->norm->Bd.comp)
1.150 kristaps 561: return;
1.202 kristaps 562: if (MDOC_Bl == bl->tok && bl->norm->Bl.comp)
1.54 kristaps 563: return;
564:
1.85 kristaps 565: /* Do not vspace directly after Ss/Sh. */
1.1 kristaps 566:
1.289 schwarze 567: nn = n;
1.337 schwarze 568: while (nn->prev != NULL && nn->prev->flags & NODE_NOPRT)
569: nn = nn->prev;
1.289 schwarze 570: while (nn->prev == NULL) {
571: do {
572: nn = nn->parent;
1.314 schwarze 573: if (nn->type == ROFFT_ROOT)
1.289 schwarze 574: return;
1.314 schwarze 575: } while (nn->type != ROFFT_BLOCK);
1.289 schwarze 576: if (nn->tok == MDOC_Sh || nn->tok == MDOC_Ss)
1.54 kristaps 577: return;
1.289 schwarze 578: if (nn->tok == MDOC_It &&
579: nn->parent->parent->norm->Bl.type != LIST_item)
580: break;
1.1 kristaps 581: }
582:
1.85 kristaps 583: /* A `-column' does not assert vspace within the list. */
1.54 kristaps 584:
1.202 kristaps 585: if (MDOC_Bl == bl->tok && LIST_column == bl->norm->Bl.type)
1.86 kristaps 586: if (n->prev && MDOC_It == n->prev->tok)
1.54 kristaps 587: return;
588:
1.85 kristaps 589: /* A `-diag' without body does not vspace. */
590:
1.202 kristaps 591: if (MDOC_Bl == bl->tok && LIST_diag == bl->norm->Bl.type)
1.86 kristaps 592: if (n->prev && MDOC_It == n->prev->tok) {
593: assert(n->prev->body);
594: if (NULL == n->prev->body->child)
1.55 kristaps 595: return;
596: }
597:
1.54 kristaps 598: term_vspace(p);
1.260 schwarze 599: }
600:
1.1 kristaps 601:
602: static int
603: termp_it_pre(DECL_ARGS)
604: {
1.345 schwarze 605: struct roffsu su;
1.302 schwarze 606: char buf[24];
1.315 schwarze 607: const struct roff_node *bl, *nn;
1.302 schwarze 608: size_t ncols, dcol;
609: int i, offset, width;
1.126 kristaps 610: enum mdoc_list type;
1.1 kristaps 611:
1.314 schwarze 612: if (n->type == ROFFT_BLOCK) {
1.151 kristaps 613: print_bvspace(p, n->parent->parent, n);
1.328 schwarze 614: return 1;
1.54 kristaps 615: }
1.1 kristaps 616:
1.86 kristaps 617: bl = n->parent->parent->parent;
1.202 kristaps 618: type = bl->norm->Bl.type;
1.1 kristaps 619:
1.264 schwarze 620: /*
1.302 schwarze 621: * Defaults for specific list types.
622: */
623:
624: switch (type) {
625: case LIST_bullet:
626: case LIST_dash:
627: case LIST_hyphen:
628: case LIST_enum:
629: width = term_len(p, 2);
630: break;
631: case LIST_hang:
1.332 schwarze 632: case LIST_tag:
1.302 schwarze 633: width = term_len(p, 8);
634: break;
635: case LIST_column:
636: width = term_len(p, 10);
637: break;
638: default:
639: width = 0;
640: break;
641: }
642: offset = 0;
643:
644: /*
1.108 kristaps 645: * First calculate width and offset. This is pretty easy unless
646: * we're a -column list, in which case all prior columns must
647: * be accounted for.
648: */
649:
1.302 schwarze 650: if (bl->norm->Bl.offs != NULL) {
1.288 schwarze 651: offset = a2width(p, bl->norm->Bl.offs);
1.302 schwarze 652: if (offset < 0 && (size_t)(-offset) > p->offset)
653: offset = -p->offset;
654: else if (offset > SHRT_MAX)
655: offset = 0;
656: }
1.152 kristaps 657:
1.1 kristaps 658: switch (type) {
1.264 schwarze 659: case LIST_column:
1.314 schwarze 660: if (n->type == ROFFT_HEAD)
1.1 kristaps 661: break;
1.155 kristaps 662:
1.105 kristaps 663: /*
1.108 kristaps 664: * Imitate groff's column handling:
665: * - For each earlier column, add its width.
666: * - For less than 5 columns, add four more blanks per
667: * column.
668: * - For exactly 5 columns, add three more blank per
669: * column.
670: * - For more than 5 columns, add only one column.
1.105 kristaps 671: */
1.202 kristaps 672: ncols = bl->norm->Bl.ncols;
1.264 schwarze 673: dcol = ncols < 5 ? term_len(p, 4) :
674: ncols == 5 ? term_len(p, 3) : term_len(p, 1);
1.108 kristaps 675:
1.134 kristaps 676: /*
1.314 schwarze 677: * Calculate the offset by applying all prior ROFFT_BODY,
678: * so we stop at the ROFFT_HEAD (nn->prev == NULL).
1.134 kristaps 679: */
680:
1.264 schwarze 681: for (i = 0, nn = n->prev;
682: nn->prev && i < (int)ncols;
1.345 schwarze 683: nn = nn->prev, i++) {
684: SCALE_HS_INIT(&su,
685: term_strlen(p, bl->norm->Bl.cols[i]));
686: su.scale /= term_strlen(p, "0");
687: offset += term_hspan(p, &su) / 24 + dcol;
688: }
1.105 kristaps 689:
690: /*
1.108 kristaps 691: * When exceeding the declared number of columns, leave
692: * the remaining widths at 0. This will later be
693: * adjusted to the default width of 10, or, for the last
694: * column, stretched to the right margin.
1.58 kristaps 695: */
1.108 kristaps 696: if (i >= (int)ncols)
697: break;
1.58 kristaps 698:
1.105 kristaps 699: /*
1.108 kristaps 700: * Use the declared column widths, extended as explained
701: * in the preceding paragraph.
1.105 kristaps 702: */
1.345 schwarze 703: SCALE_HS_INIT(&su, term_strlen(p, bl->norm->Bl.cols[i]));
704: su.scale /= term_strlen(p, "0");
705: width = term_hspan(p, &su) / 24 + dcol;
1.1 kristaps 706: break;
707: default:
1.202 kristaps 708: if (NULL == bl->norm->Bl.width)
1.108 kristaps 709: break;
710:
1.264 schwarze 711: /*
1.108 kristaps 712: * Note: buffer the width by 2, which is groff's magic
713: * number for buffering single arguments. See the above
714: * handling for column for how this changes.
715: */
1.202 kristaps 716: width = a2width(p, bl->norm->Bl.width) + term_len(p, 2);
1.302 schwarze 717: if (width < 0 && (size_t)(-width) > p->offset)
718: width = -p->offset;
719: else if (width > SHRT_MAX)
720: width = 0;
1.1 kristaps 721: break;
722: }
723:
1.264 schwarze 724: /*
1.17 kristaps 725: * Whitespace control. Inset bodies need an initial space,
726: * while diagonal bodies need two.
1.1 kristaps 727: */
728:
1.51 kristaps 729: p->flags |= TERMP_NOSPACE;
730:
1.1 kristaps 731: switch (type) {
1.264 schwarze 732: case LIST_diag:
1.314 schwarze 733: if (n->type == ROFFT_BODY)
1.62 kristaps 734: term_word(p, "\\ \\ ");
1.51 kristaps 735: break;
1.264 schwarze 736: case LIST_inset:
1.331 schwarze 737: if (n->type == ROFFT_BODY && n->parent->head->child != NULL)
1.51 kristaps 738: term_word(p, "\\ ");
1.1 kristaps 739: break;
740: default:
741: break;
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.314 schwarze 748: if (n->type == ROFFT_HEAD)
1.102 kristaps 749: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 750: break;
751: default:
752: break;
753: }
754:
755: /*
1.109 kristaps 756: * Pad and break control. This is the tricky part. These flags
757: * are documented in term_flushln() in term.c. Note that we're
758: * going to unset all of these flags in termp_it_post() when we
759: * exit.
1.1 kristaps 760: */
761:
762: switch (type) {
1.264 schwarze 763: case LIST_enum:
1.329 schwarze 764: case LIST_bullet:
765: case LIST_dash:
766: case LIST_hyphen:
1.360 ! schwarze 767: if (n->type == ROFFT_HEAD) {
! 768: p->flags |= TERMP_NOBREAK | TERMP_HANG;
! 769: p->trailspace = 1;
! 770: } else if (width <= (int)term_len(p, 2))
! 771: p->flags |= TERMP_NOPAD;
1.39 kristaps 772: break;
1.264 schwarze 773: case LIST_hang:
1.314 schwarze 774: if (n->type != ROFFT_HEAD)
1.59 kristaps 775: break;
1.263 schwarze 776: p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG;
1.250 schwarze 777: p->trailspace = 1;
1.39 kristaps 778: break;
1.264 schwarze 779: case LIST_tag:
1.314 schwarze 780: if (n->type != ROFFT_HEAD)
1.39 kristaps 781: break;
1.250 schwarze 782:
1.326 schwarze 783: p->flags |= TERMP_NOBREAK | TERMP_BRTRSP | TERMP_BRIND;
1.250 schwarze 784: p->trailspace = 2;
785:
1.86 kristaps 786: if (NULL == n->next || NULL == n->next->child)
1.360 ! schwarze 787: p->flags |= TERMP_HANG;
1.1 kristaps 788: break;
1.264 schwarze 789: case LIST_column:
1.314 schwarze 790: if (n->type == ROFFT_HEAD)
1.134 kristaps 791: break;
792:
1.250 schwarze 793: if (NULL == n->next) {
1.134 kristaps 794: p->flags &= ~TERMP_NOBREAK;
1.250 schwarze 795: p->trailspace = 0;
796: } else {
1.134 kristaps 797: p->flags |= TERMP_NOBREAK;
1.250 schwarze 798: p->trailspace = 1;
799: }
1.134 kristaps 800:
1.1 kristaps 801: break;
1.264 schwarze 802: case LIST_diag:
1.314 schwarze 803: if (n->type != ROFFT_HEAD)
1.250 schwarze 804: break;
1.263 schwarze 805: p->flags |= TERMP_NOBREAK | TERMP_BRIND;
1.250 schwarze 806: p->trailspace = 1;
1.1 kristaps 807: break;
808: default:
809: break;
810: }
811:
1.264 schwarze 812: /*
1.1 kristaps 813: * Margin control. Set-head-width lists have their right
814: * margins shortened. The body for these lists has the offset
815: * necessarily lengthened. Everybody gets the offset.
816: */
817:
818: p->offset += offset;
819:
820: switch (type) {
1.264 schwarze 821: case LIST_bullet:
822: case LIST_dash:
823: case LIST_enum:
824: case LIST_hyphen:
1.360 ! schwarze 825: case LIST_hang:
1.264 schwarze 826: case LIST_tag:
1.314 schwarze 827: if (n->type == ROFFT_HEAD)
1.1 kristaps 828: p->rmargin = p->offset + width;
1.292 schwarze 829: else
1.1 kristaps 830: p->offset += width;
831: break;
1.264 schwarze 832: case LIST_column:
1.49 kristaps 833: assert(width);
1.1 kristaps 834: p->rmargin = p->offset + width;
1.264 schwarze 835: /*
1.50 kristaps 836: * XXX - this behaviour is not documented: the
837: * right-most column is filled to the right margin.
838: */
1.314 schwarze 839: if (n->type == ROFFT_HEAD)
1.134 kristaps 840: break;
841: if (NULL == n->next && p->rmargin < p->maxrmargin)
1.50 kristaps 842: p->rmargin = p->maxrmargin;
1.1 kristaps 843: break;
844: default:
845: break;
846: }
847:
1.264 schwarze 848: /*
1.1 kristaps 849: * The dash, hyphen, bullet and enum lists all have a special
1.264 schwarze 850: * HEAD character (temporarily bold, in some cases).
1.1 kristaps 851: */
852:
1.314 schwarze 853: if (n->type == ROFFT_HEAD)
1.1 kristaps 854: switch (type) {
1.264 schwarze 855: case LIST_bullet:
1.102 kristaps 856: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 857: term_word(p, "\\[bu]");
1.102 kristaps 858: term_fontpop(p);
1.1 kristaps 859: break;
1.264 schwarze 860: case LIST_dash:
861: case LIST_hyphen:
1.102 kristaps 862: term_fontpush(p, TERMFONT_BOLD);
1.330 schwarze 863: term_word(p, "-");
1.102 kristaps 864: term_fontpop(p);
1.1 kristaps 865: break;
1.264 schwarze 866: case LIST_enum:
1.1 kristaps 867: (pair->ppair->ppair->count)++;
1.265 schwarze 868: (void)snprintf(buf, sizeof(buf), "%d.",
1.264 schwarze 869: pair->ppair->ppair->count);
1.1 kristaps 870: term_word(p, buf);
871: break;
872: default:
873: break;
874: }
875:
1.264 schwarze 876: /*
1.1 kristaps 877: * If we're not going to process our children, indicate so here.
878: */
879:
880: switch (type) {
1.264 schwarze 881: case LIST_bullet:
882: case LIST_item:
883: case LIST_dash:
884: case LIST_hyphen:
885: case LIST_enum:
1.314 schwarze 886: if (n->type == ROFFT_HEAD)
1.328 schwarze 887: return 0;
1.1 kristaps 888: break;
1.264 schwarze 889: case LIST_column:
1.314 schwarze 890: if (n->type == ROFFT_HEAD)
1.328 schwarze 891: return 0;
1.360 ! schwarze 892: p->minbl = 0;
1.1 kristaps 893: break;
894: default:
895: break;
896: }
897:
1.328 schwarze 898: return 1;
1.1 kristaps 899: }
900:
901: static void
902: termp_it_post(DECL_ARGS)
903: {
1.126 kristaps 904: enum mdoc_list type;
1.1 kristaps 905:
1.314 schwarze 906: if (n->type == ROFFT_BLOCK)
1.1 kristaps 907: return;
908:
1.202 kristaps 909: type = n->parent->parent->parent->norm->Bl.type;
1.1 kristaps 910:
911: switch (type) {
1.264 schwarze 912: case LIST_item:
913: case LIST_diag:
914: case LIST_inset:
1.314 schwarze 915: if (n->type == ROFFT_BODY)
1.130 schwarze 916: term_newln(p);
1.1 kristaps 917: break;
1.264 schwarze 918: case LIST_column:
1.314 schwarze 919: if (n->type == ROFFT_BODY)
1.1 kristaps 920: term_flushln(p);
921: break;
922: default:
1.130 schwarze 923: term_newln(p);
1.1 kristaps 924: break;
925: }
926:
1.264 schwarze 927: /*
1.109 kristaps 928: * Now that our output is flushed, we can reset our tags. Since
929: * only `It' sets these flags, we're free to assume that nobody
930: * has munged them in the meanwhile.
931: */
932:
1.360 ! schwarze 933: p->flags &= ~(TERMP_NOBREAK | TERMP_BRTRSP | TERMP_BRIND | TERMP_HANG);
1.250 schwarze 934: p->trailspace = 0;
1.1 kristaps 935: }
936:
937: static int
938: termp_nm_pre(DECL_ARGS)
939: {
1.296 schwarze 940: const char *cp;
1.1 kristaps 941:
1.314 schwarze 942: if (n->type == ROFFT_BLOCK) {
1.253 schwarze 943: p->flags |= TERMP_PREKEEP;
1.328 schwarze 944: return 1;
1.253 schwarze 945: }
1.164 schwarze 946:
1.314 schwarze 947: if (n->type == ROFFT_BODY) {
1.164 schwarze 948: if (NULL == n->child)
1.328 schwarze 949: return 0;
1.234 schwarze 950: p->flags |= TERMP_NOSPACE;
1.296 schwarze 951: cp = NULL;
952: if (n->prev->child != NULL)
953: cp = n->prev->child->string;
954: if (cp == NULL)
955: cp = meta->name;
956: if (cp == NULL)
957: p->offset += term_len(p, 6);
958: else
959: p->offset += term_len(p, 1) + term_strlen(p, cp);
1.328 schwarze 960: return 1;
1.164 schwarze 961: }
962:
1.343 schwarze 963: if (n->child == NULL)
1.328 schwarze 964: return 0;
1.125 kristaps 965:
1.314 schwarze 966: if (n->type == ROFFT_HEAD)
1.177 schwarze 967: synopsis_pre(p, n->parent);
1.102 kristaps 968:
1.314 schwarze 969: if (n->type == ROFFT_HEAD &&
1.278 schwarze 970: NULL != n->next && NULL != n->next->child) {
1.263 schwarze 971: p->flags |= TERMP_NOSPACE | TERMP_NOBREAK | TERMP_BRIND;
1.250 schwarze 972: p->trailspace = 1;
1.185 schwarze 973: p->rmargin = p->offset + term_len(p, 1);
974: if (NULL == n->child) {
1.245 schwarze 975: p->rmargin += term_strlen(p, meta->name);
1.314 schwarze 976: } else if (n->child->type == ROFFT_TEXT) {
1.185 schwarze 977: p->rmargin += term_strlen(p, n->child->string);
978: if (n->child->next)
979: p->flags |= TERMP_HANG;
980: } else {
981: p->rmargin += term_len(p, 5);
982: p->flags |= TERMP_HANG;
983: }
1.164 schwarze 984: }
985:
1.102 kristaps 986: term_fontpush(p, TERMFONT_BOLD);
1.328 schwarze 987: return 1;
1.1 kristaps 988: }
989:
1.164 schwarze 990: static void
991: termp_nm_post(DECL_ARGS)
992: {
993:
1.314 schwarze 994: if (n->type == ROFFT_BLOCK) {
1.253 schwarze 995: p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.314 schwarze 996: } else if (n->type == ROFFT_HEAD &&
1.278 schwarze 997: NULL != n->next && NULL != n->next->child) {
1.164 schwarze 998: term_flushln(p);
1.263 schwarze 999: p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
1.250 schwarze 1000: p->trailspace = 0;
1.314 schwarze 1001: } else if (n->type == ROFFT_BODY && n->child != NULL)
1.164 schwarze 1002: term_flushln(p);
1003: }
1004:
1.1 kristaps 1005: static int
1006: termp_fl_pre(DECL_ARGS)
1007: {
1008:
1.320 schwarze 1009: termp_tag_pre(p, pair, meta, n);
1.102 kristaps 1010: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1011: term_word(p, "\\-");
1.103 kristaps 1012:
1.331 schwarze 1013: if (!(n->child == NULL &&
1.280 schwarze 1014: (n->next == NULL ||
1.314 schwarze 1015: n->next->type == ROFFT_TEXT ||
1.338 schwarze 1016: n->next->flags & NODE_LINE)))
1.103 kristaps 1017: p->flags |= TERMP_NOSPACE;
1018:
1.328 schwarze 1019: return 1;
1.1 kristaps 1020: }
1021:
1022: static int
1.184 kristaps 1023: termp__a_pre(DECL_ARGS)
1024: {
1025:
1026: if (n->prev && MDOC__A == n->prev->tok)
1027: if (NULL == n->next || MDOC__A != n->next->tok)
1028: term_word(p, "and");
1029:
1.328 schwarze 1030: return 1;
1.184 kristaps 1031: }
1032:
1033: static int
1.61 kristaps 1034: termp_an_pre(DECL_ARGS)
1035: {
1036:
1.282 schwarze 1037: if (n->norm->An.auth == AUTH_split) {
1038: p->flags &= ~TERMP_NOSPLIT;
1039: p->flags |= TERMP_SPLIT;
1.328 schwarze 1040: return 0;
1.282 schwarze 1041: }
1042: if (n->norm->An.auth == AUTH_nosplit) {
1043: p->flags &= ~TERMP_SPLIT;
1044: p->flags |= TERMP_NOSPLIT;
1.328 schwarze 1045: return 0;
1.282 schwarze 1046: }
1.264 schwarze 1047:
1.282 schwarze 1048: if (p->flags & TERMP_SPLIT)
1.61 kristaps 1049: term_newln(p);
1050:
1.282 schwarze 1051: if (n->sec == SEC_AUTHORS && ! (p->flags & TERMP_NOSPLIT))
1052: p->flags |= TERMP_SPLIT;
1.61 kristaps 1053:
1.328 schwarze 1054: return 1;
1.61 kristaps 1055: }
1056:
1057: static int
1.1 kristaps 1058: termp_ns_pre(DECL_ARGS)
1059: {
1060:
1.338 schwarze 1061: if ( ! (NODE_LINE & n->flags))
1.215 kristaps 1062: p->flags |= TERMP_NOSPACE;
1.328 schwarze 1063: return 1;
1.1 kristaps 1064: }
1065:
1066: static int
1067: termp_rs_pre(DECL_ARGS)
1068: {
1069:
1.86 kristaps 1070: if (SEC_SEE_ALSO != n->sec)
1.328 schwarze 1071: return 1;
1.314 schwarze 1072: if (n->type == ROFFT_BLOCK && n->prev != NULL)
1.1 kristaps 1073: term_vspace(p);
1.328 schwarze 1074: return 1;
1.1 kristaps 1075: }
1076:
1077: static int
1078: termp_ex_pre(DECL_ARGS)
1079: {
1.224 kristaps 1080: term_newln(p);
1.341 schwarze 1081: return 1;
1.1 kristaps 1082: }
1083:
1084: static int
1085: termp_nd_pre(DECL_ARGS)
1086: {
1.25 kristaps 1087:
1.314 schwarze 1088: if (n->type == ROFFT_BODY)
1.297 schwarze 1089: term_word(p, "\\(en");
1.328 schwarze 1090: return 1;
1.115 kristaps 1091: }
1092:
1093: static int
1094: termp_bl_pre(DECL_ARGS)
1095: {
1096:
1.328 schwarze 1097: return n->type != ROFFT_HEAD;
1.1 kristaps 1098: }
1099:
1100: static void
1101: termp_bl_post(DECL_ARGS)
1102: {
1103:
1.356 schwarze 1104: if (n->type != ROFFT_BLOCK)
1105: return;
1106: term_newln(p);
1107: if (n->tok != MDOC_Bl || n->norm->Bl.type != LIST_column)
1108: return;
1109: term_tab_set(p, NULL);
1110: term_tab_set(p, "T");
1111: term_tab_set(p, ".5i");
1.1 kristaps 1112: }
1113:
1114: static int
1115: termp_xr_pre(DECL_ARGS)
1116: {
1117:
1.225 kristaps 1118: if (NULL == (n = n->child))
1.328 schwarze 1119: return 0;
1.113 kristaps 1120:
1.314 schwarze 1121: assert(n->type == ROFFT_TEXT);
1.225 kristaps 1122: term_word(p, n->string);
1.11 kristaps 1123:
1.264 schwarze 1124: if (NULL == (n = n->next))
1.328 schwarze 1125: return 0;
1.225 kristaps 1126:
1.1 kristaps 1127: p->flags |= TERMP_NOSPACE;
1128: term_word(p, "(");
1.222 kristaps 1129: p->flags |= TERMP_NOSPACE;
1.225 kristaps 1130:
1.314 schwarze 1131: assert(n->type == ROFFT_TEXT);
1.225 kristaps 1132: term_word(p, n->string);
1133:
1.222 kristaps 1134: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1135: term_word(p, ")");
1.86 kristaps 1136:
1.328 schwarze 1137: return 0;
1.1 kristaps 1138: }
1139:
1.143 kristaps 1140: /*
1141: * This decides how to assert whitespace before any of the SYNOPSIS set
1142: * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1143: * macro combos).
1144: */
1145: static void
1.315 schwarze 1146: synopsis_pre(struct termp *p, const struct roff_node *n)
1.143 kristaps 1147: {
1.264 schwarze 1148: /*
1.143 kristaps 1149: * Obviously, if we're not in a SYNOPSIS or no prior macros
1150: * exist, do nothing.
1151: */
1.338 schwarze 1152: if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags))
1.143 kristaps 1153: return;
1154:
1155: /*
1156: * If we're the second in a pair of like elements, emit our
1157: * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1158: * case we soldier on.
1159: */
1.264 schwarze 1160: if (n->prev->tok == n->tok &&
1161: MDOC_Ft != n->tok &&
1162: MDOC_Fo != n->tok &&
1163: MDOC_Fn != n->tok) {
1.143 kristaps 1164: term_newln(p);
1165: return;
1166: }
1167:
1168: /*
1169: * If we're one of the SYNOPSIS set and non-like pair-wise after
1170: * another (or Fn/Fo, which we've let slip through) then assert
1171: * vertical space, else only newline and move on.
1172: */
1173: switch (n->prev->tok) {
1.264 schwarze 1174: case MDOC_Fd:
1175: case MDOC_Fn:
1176: case MDOC_Fo:
1177: case MDOC_In:
1178: case MDOC_Vt:
1.143 kristaps 1179: term_vspace(p);
1180: break;
1.264 schwarze 1181: case MDOC_Ft:
1.143 kristaps 1182: if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
1183: term_vspace(p);
1184: break;
1185: }
1186: /* FALLTHROUGH */
1187: default:
1188: term_newln(p);
1189: break;
1190: }
1191: }
1192:
1.110 kristaps 1193: static int
1194: termp_vt_pre(DECL_ARGS)
1195: {
1196:
1.314 schwarze 1197: if (n->type == ROFFT_ELEM) {
1.143 kristaps 1198: synopsis_pre(p, n);
1.328 schwarze 1199: return termp_under_pre(p, pair, meta, n);
1.314 schwarze 1200: } else if (n->type == ROFFT_BLOCK) {
1.143 kristaps 1201: synopsis_pre(p, n);
1.328 schwarze 1202: return 1;
1.314 schwarze 1203: } else if (n->type == ROFFT_HEAD)
1.328 schwarze 1204: return 0;
1.110 kristaps 1205:
1.328 schwarze 1206: return termp_under_pre(p, pair, meta, n);
1.110 kristaps 1207: }
1208:
1.1 kristaps 1209: static int
1.69 kristaps 1210: termp_bold_pre(DECL_ARGS)
1.1 kristaps 1211: {
1212:
1.320 schwarze 1213: termp_tag_pre(p, pair, meta, n);
1.102 kristaps 1214: term_fontpush(p, TERMFONT_BOLD);
1.328 schwarze 1215: return 1;
1.1 kristaps 1216: }
1217:
1.143 kristaps 1218: static int
1219: termp_fd_pre(DECL_ARGS)
1.1 kristaps 1220: {
1221:
1.143 kristaps 1222: synopsis_pre(p, n);
1.328 schwarze 1223: return termp_bold_pre(p, pair, meta, n);
1.1 kristaps 1224: }
1225:
1.241 schwarze 1226: static void
1227: termp_fd_post(DECL_ARGS)
1228: {
1229:
1230: term_newln(p);
1231: }
1232:
1.1 kristaps 1233: static int
1234: termp_sh_pre(DECL_ARGS)
1235: {
1.85 kristaps 1236:
1.86 kristaps 1237: switch (n->type) {
1.314 schwarze 1238: case ROFFT_BLOCK:
1.293 schwarze 1239: /*
1240: * Vertical space before sections, except
1241: * when the previous section was empty.
1242: */
1243: if (n->prev == NULL ||
1.322 schwarze 1244: n->prev->tok != MDOC_Sh ||
1.293 schwarze 1245: (n->prev->body != NULL &&
1246: n->prev->body->child != NULL))
1247: term_vspace(p);
1.65 kristaps 1248: break;
1.314 schwarze 1249: case ROFFT_HEAD:
1.102 kristaps 1250: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1251: break;
1.314 schwarze 1252: case ROFFT_BODY:
1.238 schwarze 1253: p->offset = term_len(p, p->defindent);
1.356 schwarze 1254: term_tab_set(p, NULL);
1255: term_tab_set(p, "T");
1256: term_tab_set(p, ".5i");
1.322 schwarze 1257: switch (n->sec) {
1258: case SEC_DESCRIPTION:
1259: fn_prio = 0;
1260: break;
1261: case SEC_AUTHORS:
1.239 schwarze 1262: p->flags &= ~(TERMP_SPLIT|TERMP_NOSPLIT);
1.322 schwarze 1263: break;
1264: default:
1265: break;
1266: }
1.1 kristaps 1267: break;
1268: default:
1269: break;
1270: }
1.328 schwarze 1271: return 1;
1.1 kristaps 1272: }
1273:
1274: static void
1275: termp_sh_post(DECL_ARGS)
1276: {
1277:
1.86 kristaps 1278: switch (n->type) {
1.314 schwarze 1279: case ROFFT_HEAD:
1.1 kristaps 1280: term_newln(p);
1281: break;
1.314 schwarze 1282: case ROFFT_BODY:
1.1 kristaps 1283: term_newln(p);
1284: p->offset = 0;
1285: break;
1286: default:
1287: break;
1288: }
1289: }
1290:
1291: static void
1292: termp_lb_post(DECL_ARGS)
1293: {
1294:
1.338 schwarze 1295: if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags)
1.81 kristaps 1296: term_newln(p);
1.1 kristaps 1297: }
1298:
1299: static int
1300: termp_d1_pre(DECL_ARGS)
1301: {
1302:
1.314 schwarze 1303: if (n->type != ROFFT_BLOCK)
1.328 schwarze 1304: return 1;
1.1 kristaps 1305: term_newln(p);
1.238 schwarze 1306: p->offset += term_len(p, p->defindent + 1);
1.356 schwarze 1307: term_tab_set(p, NULL);
1308: term_tab_set(p, "T");
1309: term_tab_set(p, ".5i");
1.328 schwarze 1310: return 1;
1.1 kristaps 1311: }
1312:
1313: static int
1314: termp_ft_pre(DECL_ARGS)
1315: {
1316:
1.338 schwarze 1317: /* NB: NODE_LINE does not effect this! */
1.143 kristaps 1318: synopsis_pre(p, n);
1.102 kristaps 1319: term_fontpush(p, TERMFONT_UNDER);
1.328 schwarze 1320: return 1;
1.1 kristaps 1321: }
1322:
1323: static int
1324: termp_fn_pre(DECL_ARGS)
1325: {
1.257 schwarze 1326: size_t rmargin = 0;
1.226 kristaps 1327: int pretty;
1328:
1.338 schwarze 1329: pretty = NODE_SYNPRETTY & n->flags;
1.1 kristaps 1330:
1.143 kristaps 1331: synopsis_pre(p, n);
1.139 kristaps 1332:
1.226 kristaps 1333: if (NULL == (n = n->child))
1.328 schwarze 1334: return 0;
1.226 kristaps 1335:
1.251 schwarze 1336: if (pretty) {
1337: rmargin = p->rmargin;
1.257 schwarze 1338: p->rmargin = p->offset + term_len(p, 4);
1.263 schwarze 1339: p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG;
1.251 schwarze 1340: }
1341:
1.314 schwarze 1342: assert(n->type == ROFFT_TEXT);
1.102 kristaps 1343: term_fontpush(p, TERMFONT_BOLD);
1.226 kristaps 1344: term_word(p, n->string);
1.102 kristaps 1345: term_fontpop(p);
1.1 kristaps 1346:
1.336 schwarze 1347: if (n->sec == SEC_DESCRIPTION || n->sec == SEC_CUSTOM)
1.324 schwarze 1348: tag_put(n->string, ++fn_prio, p->line);
1.322 schwarze 1349:
1.251 schwarze 1350: if (pretty) {
1351: term_flushln(p);
1.263 schwarze 1352: p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
1.360 ! schwarze 1353: p->flags |= TERMP_NOPAD;
1.251 schwarze 1354: p->offset = p->rmargin;
1355: p->rmargin = rmargin;
1356: }
1357:
1.1 kristaps 1358: p->flags |= TERMP_NOSPACE;
1359: term_word(p, "(");
1.222 kristaps 1360: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1361:
1.226 kristaps 1362: for (n = n->next; n; n = n->next) {
1.314 schwarze 1363: assert(n->type == ROFFT_TEXT);
1.102 kristaps 1364: term_fontpush(p, TERMFONT_UNDER);
1.255 schwarze 1365: if (pretty)
1366: p->flags |= TERMP_NBRWORD;
1.226 kristaps 1367: term_word(p, n->string);
1.102 kristaps 1368: term_fontpop(p);
1369:
1.226 kristaps 1370: if (n->next) {
1.222 kristaps 1371: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1372: term_word(p, ",");
1.222 kristaps 1373: }
1.1 kristaps 1374: }
1375:
1.222 kristaps 1376: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1377: term_word(p, ")");
1378:
1.226 kristaps 1379: if (pretty) {
1.222 kristaps 1380: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1381: term_word(p, ";");
1.251 schwarze 1382: term_flushln(p);
1.222 kristaps 1383: }
1.1 kristaps 1384:
1.328 schwarze 1385: return 0;
1.1 kristaps 1386: }
1387:
1388: static int
1389: termp_fa_pre(DECL_ARGS)
1390: {
1.315 schwarze 1391: const struct roff_node *nn;
1.1 kristaps 1392:
1.86 kristaps 1393: if (n->parent->tok != MDOC_Fo) {
1.102 kristaps 1394: term_fontpush(p, TERMFONT_UNDER);
1.328 schwarze 1395: return 1;
1.1 kristaps 1396: }
1397:
1.86 kristaps 1398: for (nn = n->child; nn; nn = nn->next) {
1.102 kristaps 1399: term_fontpush(p, TERMFONT_UNDER);
1.258 schwarze 1400: p->flags |= TERMP_NBRWORD;
1.86 kristaps 1401: term_word(p, nn->string);
1.102 kristaps 1402: term_fontpop(p);
1403:
1.256 schwarze 1404: if (nn->next || (n->next && n->next->tok == MDOC_Fa)) {
1.222 kristaps 1405: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1406: term_word(p, ",");
1.222 kristaps 1407: }
1.1 kristaps 1408: }
1409:
1.328 schwarze 1410: return 0;
1.1 kristaps 1411: }
1412:
1413: static int
1414: termp_bd_pre(DECL_ARGS)
1415: {
1.356 schwarze 1416: size_t lm, len, rm, rmax;
1.315 schwarze 1417: struct roff_node *nn;
1.302 schwarze 1418: int offset;
1.1 kristaps 1419:
1.314 schwarze 1420: if (n->type == ROFFT_BLOCK) {
1.151 kristaps 1421: print_bvspace(p, n, n);
1.328 schwarze 1422: return 1;
1.314 schwarze 1423: } else if (n->type == ROFFT_HEAD)
1.328 schwarze 1424: return 0;
1.1 kristaps 1425:
1.288 schwarze 1426: /* Handle the -offset argument. */
1427:
1428: if (n->norm->Bd.offs == NULL ||
1429: ! strcmp(n->norm->Bd.offs, "left"))
1430: /* nothing */;
1431: else if ( ! strcmp(n->norm->Bd.offs, "indent"))
1432: p->offset += term_len(p, p->defindent + 1);
1433: else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
1434: p->offset += term_len(p, (p->defindent + 1) * 2);
1.302 schwarze 1435: else {
1436: offset = a2width(p, n->norm->Bd.offs);
1437: if (offset < 0 && (size_t)(-offset) > p->offset)
1438: p->offset = 0;
1439: else if (offset < SHRT_MAX)
1440: p->offset += offset;
1441: }
1.85 kristaps 1442:
1443: /*
1444: * If -ragged or -filled are specified, the block does nothing
1445: * but change the indentation. If -unfilled or -literal are
1446: * specified, text is printed exactly as entered in the display:
1447: * for macro lines, a newline is appended to the line. Blank
1448: * lines are allowed.
1449: */
1.264 schwarze 1450:
1451: if (DISP_literal != n->norm->Bd.type &&
1.272 schwarze 1452: DISP_unfilled != n->norm->Bd.type &&
1453: DISP_centered != n->norm->Bd.type)
1.328 schwarze 1454: return 1;
1.1 kristaps 1455:
1.356 schwarze 1456: if (n->norm->Bd.type == DISP_literal) {
1457: term_tab_set(p, NULL);
1458: term_tab_set(p, "T");
1459: term_tab_set(p, "8n");
1460: }
1.208 kristaps 1461:
1.272 schwarze 1462: lm = p->offset;
1.119 kristaps 1463: rm = p->rmargin;
1464: rmax = p->maxrmargin;
1.120 kristaps 1465: p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1.118 kristaps 1466:
1.86 kristaps 1467: for (nn = n->child; nn; nn = nn->next) {
1.272 schwarze 1468: if (DISP_centered == n->norm->Bd.type) {
1.314 schwarze 1469: if (nn->type == ROFFT_TEXT) {
1.272 schwarze 1470: len = term_strlen(p, nn->string);
1471: p->offset = len >= rm ? 0 :
1472: lm + len >= rm ? rm - len :
1473: (lm + rm - len) / 2;
1474: } else
1475: p->offset = lm;
1476: }
1.245 schwarze 1477: print_mdoc_node(p, pair, meta, nn);
1.190 kristaps 1478: /*
1479: * If the printed node flushes its own line, then we
1480: * needn't do it here as well. This is hacky, but the
1481: * notion of selective eoln whitespace is pretty dumb
1482: * anyway, so don't sweat it.
1483: */
1.356 schwarze 1484: if (nn->tok < ROFF_MAX)
1485: continue;
1.190 kristaps 1486: switch (nn->tok) {
1.264 schwarze 1487: case MDOC_Sm:
1488: case MDOC_Bl:
1489: case MDOC_D1:
1490: case MDOC_Dl:
1491: case MDOC_Lp:
1492: case MDOC_Pp:
1.190 kristaps 1493: continue;
1494: default:
1495: break;
1496: }
1.299 schwarze 1497: if (p->flags & TERMP_NONEWLINE ||
1.338 schwarze 1498: (nn->next && ! (nn->next->flags & NODE_LINE)))
1.180 schwarze 1499: continue;
1500: term_flushln(p);
1501: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1502: }
1.147 kristaps 1503:
1.119 kristaps 1504: p->rmargin = rm;
1505: p->maxrmargin = rmax;
1.328 schwarze 1506: return 0;
1.1 kristaps 1507: }
1508:
1509: static void
1510: termp_bd_post(DECL_ARGS)
1511: {
1.119 kristaps 1512: size_t rm, rmax;
1.1 kristaps 1513:
1.314 schwarze 1514: if (n->type != ROFFT_BODY)
1.1 kristaps 1515: return;
1.118 kristaps 1516:
1.119 kristaps 1517: rm = p->rmargin;
1518: rmax = p->maxrmargin;
1.118 kristaps 1519:
1.264 schwarze 1520: if (DISP_literal == n->norm->Bd.type ||
1521: DISP_unfilled == n->norm->Bd.type)
1.120 kristaps 1522: p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1.118 kristaps 1523:
1.60 kristaps 1524: p->flags |= TERMP_NOSPACE;
1.130 schwarze 1525: term_newln(p);
1.118 kristaps 1526:
1.119 kristaps 1527: p->rmargin = rm;
1528: p->maxrmargin = rmax;
1.1 kristaps 1529: }
1530:
1531: static int
1.26 kristaps 1532: termp_xx_pre(DECL_ARGS)
1.1 kristaps 1533: {
1.339 schwarze 1534: if ((n->aux = p->flags & TERMP_PREKEEP) == 0)
1535: p->flags |= TERMP_PREKEEP;
1536: return 1;
1537: }
1.1 kristaps 1538:
1.339 schwarze 1539: static void
1540: termp_xx_post(DECL_ARGS)
1541: {
1542: if (n->aux == 0)
1543: p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.1 kristaps 1544: }
1545:
1546: static void
1547: termp_pf_post(DECL_ARGS)
1548: {
1549:
1.338 schwarze 1550: if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
1.298 schwarze 1551: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1552: }
1553:
1554: static int
1555: termp_ss_pre(DECL_ARGS)
1556: {
1.337 schwarze 1557: struct roff_node *nn;
1.1 kristaps 1558:
1.86 kristaps 1559: switch (n->type) {
1.314 schwarze 1560: case ROFFT_BLOCK:
1.1 kristaps 1561: term_newln(p);
1.337 schwarze 1562: for (nn = n->prev; nn != NULL; nn = nn->prev)
1563: if ((nn->flags & NODE_NOPRT) == 0)
1564: break;
1565: if (nn != NULL)
1.1 kristaps 1566: term_vspace(p);
1567: break;
1.314 schwarze 1568: case ROFFT_HEAD:
1.102 kristaps 1569: term_fontpush(p, TERMFONT_BOLD);
1.238 schwarze 1570: p->offset = term_len(p, (p->defindent+1)/2);
1.1 kristaps 1571: break;
1.314 schwarze 1572: case ROFFT_BODY:
1.274 schwarze 1573: p->offset = term_len(p, p->defindent);
1.356 schwarze 1574: term_tab_set(p, NULL);
1575: term_tab_set(p, "T");
1576: term_tab_set(p, ".5i");
1.274 schwarze 1577: break;
1.1 kristaps 1578: default:
1579: break;
1580: }
1581:
1.328 schwarze 1582: return 1;
1.1 kristaps 1583: }
1584:
1585: static void
1586: termp_ss_post(DECL_ARGS)
1587: {
1588:
1.314 schwarze 1589: if (n->type == ROFFT_HEAD || n->type == ROFFT_BODY)
1.1 kristaps 1590: term_newln(p);
1591: }
1592:
1593: static int
1594: termp_cd_pre(DECL_ARGS)
1595: {
1596:
1.143 kristaps 1597: synopsis_pre(p, n);
1.102 kristaps 1598: term_fontpush(p, TERMFONT_BOLD);
1.328 schwarze 1599: return 1;
1.1 kristaps 1600: }
1601:
1602: static int
1603: termp_in_pre(DECL_ARGS)
1604: {
1.142 schwarze 1605:
1.143 kristaps 1606: synopsis_pre(p, n);
1.1 kristaps 1607:
1.338 schwarze 1608: if (NODE_SYNPRETTY & n->flags && NODE_LINE & n->flags) {
1.138 kristaps 1609: term_fontpush(p, TERMFONT_BOLD);
1.22 kristaps 1610: term_word(p, "#include");
1.138 kristaps 1611: term_word(p, "<");
1612: } else {
1613: term_word(p, "<");
1614: term_fontpush(p, TERMFONT_UNDER);
1615: }
1.22 kristaps 1616:
1.1 kristaps 1617: p->flags |= TERMP_NOSPACE;
1.328 schwarze 1618: return 1;
1.1 kristaps 1619: }
1620:
1621: static void
1622: termp_in_post(DECL_ARGS)
1623: {
1624:
1.338 schwarze 1625: if (NODE_SYNPRETTY & n->flags)
1.138 kristaps 1626: term_fontpush(p, TERMFONT_BOLD);
1627:
1.79 kristaps 1628: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1629: term_word(p, ">");
1630:
1.338 schwarze 1631: if (NODE_SYNPRETTY & n->flags)
1.138 kristaps 1632: term_fontpop(p);
1.1 kristaps 1633: }
1634:
1635: static int
1.355 schwarze 1636: termp_pp_pre(DECL_ARGS)
1.45 kristaps 1637: {
1.355 schwarze 1638: fn_prio = 0;
1639: term_vspace(p);
1.328 schwarze 1640: return 0;
1.45 kristaps 1641: }
1642:
1643: static int
1.294 schwarze 1644: termp_skip_pre(DECL_ARGS)
1.268 schwarze 1645: {
1646:
1.328 schwarze 1647: return 0;
1.268 schwarze 1648: }
1649:
1650: static int
1.188 kristaps 1651: termp_quote_pre(DECL_ARGS)
1.1 kristaps 1652: {
1653:
1.314 schwarze 1654: if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1.328 schwarze 1655: return 1;
1.1 kristaps 1656:
1.188 kristaps 1657: switch (n->tok) {
1.264 schwarze 1658: case MDOC_Ao:
1659: case MDOC_Aq:
1.331 schwarze 1660: term_word(p, n->child != NULL && n->child->next == NULL &&
1.303 schwarze 1661: n->child->tok == MDOC_Mt ? "<" : "\\(la");
1.188 kristaps 1662: break;
1.264 schwarze 1663: case MDOC_Bro:
1664: case MDOC_Brq:
1.188 kristaps 1665: term_word(p, "{");
1666: break;
1.264 schwarze 1667: case MDOC_Oo:
1668: case MDOC_Op:
1669: case MDOC_Bo:
1670: case MDOC_Bq:
1.188 kristaps 1671: term_word(p, "[");
1672: break;
1.346 schwarze 1673: case MDOC__T:
1674: /* FALLTHROUGH */
1.264 schwarze 1675: case MDOC_Do:
1676: case MDOC_Dq:
1.311 schwarze 1677: term_word(p, "\\(Lq");
1.188 kristaps 1678: break;
1.268 schwarze 1679: case MDOC_En:
1680: if (NULL == n->norm->Es ||
1681: NULL == n->norm->Es->child)
1.328 schwarze 1682: return 1;
1.268 schwarze 1683: term_word(p, n->norm->Es->child->string);
1684: break;
1.264 schwarze 1685: case MDOC_Po:
1686: case MDOC_Pq:
1.188 kristaps 1687: term_word(p, "(");
1688: break;
1.264 schwarze 1689: case MDOC_Qo:
1690: case MDOC_Qq:
1.188 kristaps 1691: term_word(p, "\"");
1692: break;
1.264 schwarze 1693: case MDOC_Ql:
1694: case MDOC_So:
1695: case MDOC_Sq:
1.249 schwarze 1696: term_word(p, "\\(oq");
1.188 kristaps 1697: break;
1698: default:
1699: abort();
1700: }
1.1 kristaps 1701:
1702: p->flags |= TERMP_NOSPACE;
1.328 schwarze 1703: return 1;
1.1 kristaps 1704: }
1705:
1706: static void
1.188 kristaps 1707: termp_quote_post(DECL_ARGS)
1.1 kristaps 1708: {
1709:
1.314 schwarze 1710: if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1.1 kristaps 1711: return;
1712:
1.306 schwarze 1713: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1714:
1.188 kristaps 1715: switch (n->tok) {
1.264 schwarze 1716: case MDOC_Ao:
1717: case MDOC_Aq:
1.331 schwarze 1718: term_word(p, n->child != NULL && n->child->next == NULL &&
1.303 schwarze 1719: n->child->tok == MDOC_Mt ? ">" : "\\(ra");
1.188 kristaps 1720: break;
1.264 schwarze 1721: case MDOC_Bro:
1722: case MDOC_Brq:
1.188 kristaps 1723: term_word(p, "}");
1724: break;
1.264 schwarze 1725: case MDOC_Oo:
1726: case MDOC_Op:
1727: case MDOC_Bo:
1728: case MDOC_Bq:
1.188 kristaps 1729: term_word(p, "]");
1730: break;
1.346 schwarze 1731: case MDOC__T:
1732: /* FALLTHROUGH */
1.264 schwarze 1733: case MDOC_Do:
1734: case MDOC_Dq:
1.311 schwarze 1735: term_word(p, "\\(Rq");
1.268 schwarze 1736: break;
1737: case MDOC_En:
1.306 schwarze 1738: if (n->norm->Es == NULL ||
1739: n->norm->Es->child == NULL ||
1740: n->norm->Es->child->next == NULL)
1741: p->flags &= ~TERMP_NOSPACE;
1742: else
1.268 schwarze 1743: term_word(p, n->norm->Es->child->next->string);
1.188 kristaps 1744: break;
1.264 schwarze 1745: case MDOC_Po:
1746: case MDOC_Pq:
1.188 kristaps 1747: term_word(p, ")");
1748: break;
1.264 schwarze 1749: case MDOC_Qo:
1750: case MDOC_Qq:
1.188 kristaps 1751: term_word(p, "\"");
1752: break;
1.264 schwarze 1753: case MDOC_Ql:
1754: case MDOC_So:
1755: case MDOC_Sq:
1.249 schwarze 1756: term_word(p, "\\(cq");
1.188 kristaps 1757: break;
1758: default:
1759: abort();
1760: }
1.306 schwarze 1761: }
1762:
1763: static int
1764: termp_eo_pre(DECL_ARGS)
1765: {
1766:
1.314 schwarze 1767: if (n->type != ROFFT_BODY)
1.328 schwarze 1768: return 1;
1.306 schwarze 1769:
1770: if (n->end == ENDBODY_NOT &&
1771: n->parent->head->child == NULL &&
1772: n->child != NULL &&
1773: n->child->end != ENDBODY_NOT)
1774: term_word(p, "\\&");
1775: else if (n->end != ENDBODY_NOT ? n->child != NULL :
1.309 schwarze 1776: n->parent->head->child != NULL && (n->child != NULL ||
1777: (n->parent->tail != NULL && n->parent->tail->child != NULL)))
1.306 schwarze 1778: p->flags |= TERMP_NOSPACE;
1779:
1.328 schwarze 1780: return 1;
1.306 schwarze 1781: }
1782:
1783: static void
1784: termp_eo_post(DECL_ARGS)
1785: {
1786: int body, tail;
1787:
1.314 schwarze 1788: if (n->type != ROFFT_BODY)
1.306 schwarze 1789: return;
1790:
1791: if (n->end != ENDBODY_NOT) {
1792: p->flags &= ~TERMP_NOSPACE;
1793: return;
1794: }
1795:
1796: body = n->child != NULL || n->parent->head->child != NULL;
1797: tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
1798:
1799: if (body && tail)
1800: p->flags |= TERMP_NOSPACE;
1801: else if ( ! (body || tail))
1802: term_word(p, "\\&");
1803: else if ( ! tail)
1804: p->flags &= ~TERMP_NOSPACE;
1.1 kristaps 1805: }
1806:
1807: static int
1808: termp_fo_pre(DECL_ARGS)
1809: {
1.257 schwarze 1810: size_t rmargin = 0;
1.256 schwarze 1811: int pretty;
1812:
1.338 schwarze 1813: pretty = NODE_SYNPRETTY & n->flags;
1.1 kristaps 1814:
1.314 schwarze 1815: if (n->type == ROFFT_BLOCK) {
1.143 kristaps 1816: synopsis_pre(p, n);
1.328 schwarze 1817: return 1;
1.314 schwarze 1818: } else if (n->type == ROFFT_BODY) {
1.256 schwarze 1819: if (pretty) {
1820: rmargin = p->rmargin;
1.257 schwarze 1821: p->rmargin = p->offset + term_len(p, 4);
1.263 schwarze 1822: p->flags |= TERMP_NOBREAK | TERMP_BRIND |
1823: TERMP_HANG;
1.256 schwarze 1824: }
1.33 kristaps 1825: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1826: term_word(p, "(");
1.222 kristaps 1827: p->flags |= TERMP_NOSPACE;
1.256 schwarze 1828: if (pretty) {
1829: term_flushln(p);
1.263 schwarze 1830: p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND |
1831: TERMP_HANG);
1.360 ! schwarze 1832: p->flags |= TERMP_NOPAD;
1.256 schwarze 1833: p->offset = p->rmargin;
1834: p->rmargin = rmargin;
1835: }
1.328 schwarze 1836: return 1;
1.256 schwarze 1837: }
1.141 kristaps 1838:
1.169 kristaps 1839: if (NULL == n->child)
1.328 schwarze 1840: return 0;
1.169 kristaps 1841:
1.141 kristaps 1842: /* XXX: we drop non-initial arguments as per groff. */
1.1 kristaps 1843:
1.141 kristaps 1844: assert(n->child->string);
1.102 kristaps 1845: term_fontpush(p, TERMFONT_BOLD);
1.141 kristaps 1846: term_word(p, n->child->string);
1.328 schwarze 1847: return 0;
1.1 kristaps 1848: }
1849:
1850: static void
1851: termp_fo_post(DECL_ARGS)
1852: {
1853:
1.314 schwarze 1854: if (n->type != ROFFT_BODY)
1.143 kristaps 1855: return;
1856:
1.222 kristaps 1857: p->flags |= TERMP_NOSPACE;
1.143 kristaps 1858: term_word(p, ")");
1859:
1.338 schwarze 1860: if (NODE_SYNPRETTY & n->flags) {
1.222 kristaps 1861: p->flags |= TERMP_NOSPACE;
1.143 kristaps 1862: term_word(p, ";");
1.256 schwarze 1863: term_flushln(p);
1.222 kristaps 1864: }
1.1 kristaps 1865: }
1866:
1867: static int
1868: termp_bf_pre(DECL_ARGS)
1869: {
1870:
1.314 schwarze 1871: if (n->type == ROFFT_HEAD)
1.328 schwarze 1872: return 0;
1.314 schwarze 1873: else if (n->type != ROFFT_BODY)
1.328 schwarze 1874: return 1;
1.1 kristaps 1875:
1.264 schwarze 1876: if (FONT_Em == n->norm->Bf.font)
1.102 kristaps 1877: term_fontpush(p, TERMFONT_UNDER);
1.264 schwarze 1878: else if (FONT_Sy == n->norm->Bf.font)
1.102 kristaps 1879: term_fontpush(p, TERMFONT_BOLD);
1.264 schwarze 1880: else
1.102 kristaps 1881: term_fontpush(p, TERMFONT_NONE);
1.1 kristaps 1882:
1.328 schwarze 1883: return 1;
1.1 kristaps 1884: }
1885:
1886: static int
1887: termp_sm_pre(DECL_ARGS)
1888: {
1889:
1.269 schwarze 1890: if (NULL == n->child)
1891: p->flags ^= TERMP_NONOSPACE;
1892: else if (0 == strcmp("on", n->child->string))
1.1 kristaps 1893: p->flags &= ~TERMP_NONOSPACE;
1.269 schwarze 1894: else
1.1 kristaps 1895: p->flags |= TERMP_NONOSPACE;
1.269 schwarze 1896:
1897: if (p->col && ! (TERMP_NONOSPACE & p->flags))
1898: p->flags &= ~TERMP_NOSPACE;
1.1 kristaps 1899:
1.328 schwarze 1900: return 0;
1.1 kristaps 1901: }
1902:
1903: static int
1904: termp_ap_pre(DECL_ARGS)
1905: {
1906:
1907: p->flags |= TERMP_NOSPACE;
1.188 kristaps 1908: term_word(p, "'");
1.1 kristaps 1909: p->flags |= TERMP_NOSPACE;
1.328 schwarze 1910: return 1;
1.1 kristaps 1911: }
1912:
1913: static void
1914: termp____post(DECL_ARGS)
1915: {
1.184 kristaps 1916:
1917: /*
1918: * Handle lists of authors. In general, print each followed by
1919: * a comma. Don't print the comma if there are only two
1920: * authors.
1921: */
1922: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
1923: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
1924: if (NULL == n->prev || MDOC__A != n->prev->tok)
1925: return;
1.1 kristaps 1926:
1.95 kristaps 1927: /* TODO: %U. */
1928:
1.187 kristaps 1929: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
1930: return;
1931:
1.222 kristaps 1932: p->flags |= TERMP_NOSPACE;
1.186 kristaps 1933: if (NULL == n->next) {
1934: term_word(p, ".");
1935: p->flags |= TERMP_SENTENCE;
1936: } else
1937: term_word(p, ",");
1.1 kristaps 1938: }
1939:
1940: static int
1.102 kristaps 1941: termp_li_pre(DECL_ARGS)
1942: {
1943:
1.335 schwarze 1944: termp_tag_pre(p, pair, meta, n);
1.102 kristaps 1945: term_fontpush(p, TERMFONT_NONE);
1.328 schwarze 1946: return 1;
1.102 kristaps 1947: }
1948:
1949: static int
1.1 kristaps 1950: termp_lk_pre(DECL_ARGS)
1951: {
1.358 schwarze 1952: const struct roff_node *link, *descr, *punct;
1.348 schwarze 1953: int display;
1.1 kristaps 1954:
1.349 schwarze 1955: if ((link = n->child) == NULL)
1.328 schwarze 1956: return 0;
1.181 kristaps 1957:
1.358 schwarze 1958: /* Find beginning of trailing punctuation. */
1959: punct = n->last;
1960: while (punct != link && punct->flags & NODE_DELIMC)
1961: punct = punct->prev;
1962: punct = punct->next;
1963:
1.349 schwarze 1964: /* Link text. */
1.358 schwarze 1965: if ((descr = link->next) != NULL && descr != punct) {
1.240 schwarze 1966: term_fontpush(p, TERMFONT_UNDER);
1.358 schwarze 1967: while (descr != punct) {
1968: if (descr->flags & (NODE_DELIMC | NODE_DELIMO))
1969: p->flags |= TERMP_NOSPACE;
1.240 schwarze 1970: term_word(p, descr->string);
1971: descr = descr->next;
1972: }
1.347 schwarze 1973: term_fontpop(p);
1.240 schwarze 1974: p->flags |= TERMP_NOSPACE;
1975: term_word(p, ":");
1976: }
1.1 kristaps 1977:
1.349 schwarze 1978: /* Link target. */
1.348 schwarze 1979: display = term_strlen(p, link->string) >= 26;
1980: if (display) {
1981: term_newln(p);
1982: p->offset += term_len(p, p->defindent + 1);
1983: }
1.102 kristaps 1984: term_fontpush(p, TERMFONT_BOLD);
1.240 schwarze 1985: term_word(p, link->string);
1.102 kristaps 1986: term_fontpop(p);
1.348 schwarze 1987:
1.349 schwarze 1988: /* Trailing punctuation. */
1.358 schwarze 1989: while (punct != NULL) {
1.349 schwarze 1990: p->flags |= TERMP_NOSPACE;
1.358 schwarze 1991: term_word(p, punct->string);
1992: punct = punct->next;
1.349 schwarze 1993: }
1.348 schwarze 1994: if (display)
1995: term_newln(p);
1.328 schwarze 1996: return 0;
1.1 kristaps 1997: }
1998:
1.159 schwarze 1999: static int
2000: termp_bk_pre(DECL_ARGS)
2001: {
2002:
1.161 schwarze 2003: switch (n->type) {
1.314 schwarze 2004: case ROFFT_BLOCK:
1.166 kristaps 2005: break;
1.314 schwarze 2006: case ROFFT_HEAD:
1.328 schwarze 2007: return 0;
1.314 schwarze 2008: case ROFFT_BODY:
1.331 schwarze 2009: if (n->parent->args != NULL || n->prev->child == NULL)
1.200 schwarze 2010: p->flags |= TERMP_PREKEEP;
1.166 kristaps 2011: break;
1.161 schwarze 2012: default:
2013: abort();
2014: }
1.166 kristaps 2015:
1.328 schwarze 2016: return 1;
1.159 schwarze 2017: }
2018:
2019: static void
2020: termp_bk_post(DECL_ARGS)
2021: {
2022:
1.314 schwarze 2023: if (n->type == ROFFT_BODY)
1.161 schwarze 2024: p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.203 kristaps 2025: }
2026:
2027: static void
2028: termp__t_post(DECL_ARGS)
2029: {
2030:
2031: /*
2032: * If we're in an `Rs' and there's a journal present, then quote
2033: * us instead of underlining us (for disambiguation).
2034: */
1.217 schwarze 2035: if (n->parent && MDOC_Rs == n->parent->tok &&
1.264 schwarze 2036: n->parent->norm->Rs.quote_T)
1.245 schwarze 2037: termp_quote_post(p, pair, meta, n);
1.203 kristaps 2038:
1.245 schwarze 2039: termp____post(p, pair, meta, n);
1.203 kristaps 2040: }
2041:
2042: static int
2043: termp__t_pre(DECL_ARGS)
2044: {
2045:
2046: /*
2047: * If we're in an `Rs' and there's a journal present, then quote
2048: * us instead of underlining us (for disambiguation).
2049: */
2050: if (n->parent && MDOC_Rs == n->parent->tok &&
1.264 schwarze 2051: n->parent->norm->Rs.quote_T)
1.328 schwarze 2052: return termp_quote_pre(p, pair, meta, n);
1.203 kristaps 2053:
2054: term_fontpush(p, TERMFONT_UNDER);
1.328 schwarze 2055: return 1;
1.159 schwarze 2056: }
1.1 kristaps 2057:
2058: static int
1.69 kristaps 2059: termp_under_pre(DECL_ARGS)
1.1 kristaps 2060: {
2061:
1.102 kristaps 2062: term_fontpush(p, TERMFONT_UNDER);
1.334 schwarze 2063: return 1;
2064: }
2065:
2066: static int
2067: termp_em_pre(DECL_ARGS)
2068: {
2069: if (n->child != NULL &&
2070: n->child->type == ROFFT_TEXT)
2071: tag_put(n->child->string, 0, p->line);
2072: term_fontpush(p, TERMFONT_UNDER);
2073: return 1;
2074: }
2075:
2076: static int
2077: termp_sy_pre(DECL_ARGS)
2078: {
2079: if (n->child != NULL &&
2080: n->child->type == ROFFT_TEXT)
2081: tag_put(n->child->string, 0, p->line);
2082: term_fontpush(p, TERMFONT_BOLD);
1.328 schwarze 2083: return 1;
1.323 schwarze 2084: }
2085:
2086: static int
2087: termp_er_pre(DECL_ARGS)
2088: {
2089:
2090: if (n->sec == SEC_ERRORS &&
2091: (n->parent->tok == MDOC_It ||
2092: (n->parent->tok == MDOC_Bq &&
1.324 schwarze 2093: n->parent->parent->parent->tok == MDOC_It)))
2094: tag_put(n->child->string, 1, p->line);
1.328 schwarze 2095: return 1;
1.320 schwarze 2096: }
2097:
2098: static int
2099: termp_tag_pre(DECL_ARGS)
2100: {
2101:
2102: if (n->child != NULL &&
2103: n->child->type == ROFFT_TEXT &&
1.333 schwarze 2104: (n->prev == NULL ||
2105: (n->prev->type == ROFFT_TEXT &&
2106: strcmp(n->prev->string, "|") == 0)) &&
1.320 schwarze 2107: (n->parent->tok == MDOC_It ||
2108: (n->parent->tok == MDOC_Xo &&
2109: n->parent->parent->prev == NULL &&
1.324 schwarze 2110: n->parent->parent->parent->tok == MDOC_It)))
2111: tag_put(n->child->string, 1, p->line);
1.328 schwarze 2112: return 1;
1.84 kristaps 2113: }
CVSweb