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