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