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