Annotation of mandoc/mdoc_term.c, Revision 1.67
1.67 ! kristaps 1: /* $Id: mdoc_term.c,v 1.66 2009/08/10 10:09:51 kristaps Exp $ */
1.1 kristaps 2: /*
1.7 kristaps 3: * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
1.1 kristaps 4: *
5: * Permission to use, copy, modify, and distribute this software for any
1.6 kristaps 6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
1.1 kristaps 8: *
1.6 kristaps 9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 kristaps 16: */
17: #include <sys/types.h>
18:
19: #include <assert.h>
20: #include <ctype.h>
21: #include <err.h>
22: #include <stdio.h>
23: #include <stdlib.h>
24: #include <string.h>
25:
26: #include "term.h"
27: #include "mdoc.h"
28:
1.66 kristaps 29: #define INDENT 5
30: #define HALFINDENT 3
31:
1.1 kristaps 32: #define TTYPE_PROG 0
33: #define TTYPE_CMD_FLAG 1
34: #define TTYPE_CMD_ARG 2
35: #define TTYPE_SECTION 3
36: #define TTYPE_FUNC_DECL 4
37: #define TTYPE_VAR_DECL 5
38: #define TTYPE_FUNC_TYPE 6
39: #define TTYPE_FUNC_NAME 7
40: #define TTYPE_FUNC_ARG 8
41: #define TTYPE_LINK 9
42: #define TTYPE_SSECTION 10
43: #define TTYPE_FILE 11
44: #define TTYPE_EMPH 12
45: #define TTYPE_CONFIG 13
46: #define TTYPE_CMD 14
47: #define TTYPE_INCLUDE 15
48: #define TTYPE_SYMB 16
49: #define TTYPE_SYMBOL 17
50: #define TTYPE_DIAG 18
51: #define TTYPE_LINK_ANCHOR 19
52: #define TTYPE_LINK_TEXT 20
53: #define TTYPE_REF_JOURNAL 21
1.56 kristaps 54: #define TTYPE_REF_TITLE 22
55: #define TTYPE_LIST 23
56: #define TTYPE_NMAX 24
1.1 kristaps 57:
58: const int ttypes[TTYPE_NMAX] = {
59: TERMP_BOLD, /* TTYPE_PROG */
60: TERMP_BOLD, /* TTYPE_CMD_FLAG */
61: TERMP_UNDER, /* TTYPE_CMD_ARG */
62: TERMP_BOLD, /* TTYPE_SECTION */
63: TERMP_BOLD, /* TTYPE_FUNC_DECL */
64: TERMP_UNDER, /* TTYPE_VAR_DECL */
65: TERMP_UNDER, /* TTYPE_FUNC_TYPE */
66: TERMP_BOLD, /* TTYPE_FUNC_NAME */
67: TERMP_UNDER, /* TTYPE_FUNC_ARG */
68: TERMP_UNDER, /* TTYPE_LINK */
69: TERMP_BOLD, /* TTYPE_SSECTION */
1.57 kristaps 70: TERMP_UNDER, /* TTYPE_FILE */
1.1 kristaps 71: TERMP_UNDER, /* TTYPE_EMPH */
72: TERMP_BOLD, /* TTYPE_CONFIG */
73: TERMP_BOLD, /* TTYPE_CMD */
74: TERMP_BOLD, /* TTYPE_INCLUDE */
75: TERMP_BOLD, /* TTYPE_SYMB */
76: TERMP_BOLD, /* TTYPE_SYMBOL */
77: TERMP_BOLD, /* TTYPE_DIAG */
78: TERMP_UNDER, /* TTYPE_LINK_ANCHOR */
79: TERMP_BOLD, /* TTYPE_LINK_TEXT */
80: TERMP_UNDER, /* TTYPE_REF_JOURNAL */
1.56 kristaps 81: TERMP_UNDER, /* TTYPE_REF_TITLE */
1.1 kristaps 82: TERMP_BOLD /* TTYPE_LIST */
83: };
84:
85: struct termpair {
86: struct termpair *ppair;
1.31 kristaps 87: int flag;
88: int count;
1.1 kristaps 89: };
90:
1.31 kristaps 91: #define DECL_ARGS struct termp *p, \
92: struct termpair *pair, \
93: const struct mdoc_meta *meta, \
94: const struct mdoc_node *node
1.1 kristaps 95:
96: struct termact {
97: int (*pre)(DECL_ARGS);
98: void (*post)(DECL_ARGS);
99: };
100:
1.31 kristaps 101: static void termp____post(DECL_ARGS);
1.61 kristaps 102: static void termp_an_post(DECL_ARGS);
1.31 kristaps 103: static void termp_aq_post(DECL_ARGS);
104: static void termp_bd_post(DECL_ARGS);
105: static void termp_bl_post(DECL_ARGS);
106: static void termp_bq_post(DECL_ARGS);
107: static void termp_brq_post(DECL_ARGS);
108: static void termp_bx_post(DECL_ARGS);
109: static void termp_d1_post(DECL_ARGS);
110: static void termp_dq_post(DECL_ARGS);
111: static void termp_fd_post(DECL_ARGS);
112: static void termp_fn_post(DECL_ARGS);
113: static void termp_fo_post(DECL_ARGS);
114: static void termp_ft_post(DECL_ARGS);
115: static void termp_in_post(DECL_ARGS);
116: static void termp_it_post(DECL_ARGS);
117: static void termp_lb_post(DECL_ARGS);
118: static void termp_op_post(DECL_ARGS);
119: static void termp_pf_post(DECL_ARGS);
120: static void termp_pq_post(DECL_ARGS);
121: static void termp_qq_post(DECL_ARGS);
122: static void termp_sh_post(DECL_ARGS);
123: static void termp_sq_post(DECL_ARGS);
124: static void termp_ss_post(DECL_ARGS);
125: static void termp_vt_post(DECL_ARGS);
126:
127: static int termp__j_pre(DECL_ARGS);
128: static int termp__t_pre(DECL_ARGS);
1.61 kristaps 129: static int termp_an_pre(DECL_ARGS);
1.31 kristaps 130: static int termp_ap_pre(DECL_ARGS);
131: static int termp_aq_pre(DECL_ARGS);
132: static int termp_ar_pre(DECL_ARGS);
133: static int termp_bd_pre(DECL_ARGS);
134: static int termp_bf_pre(DECL_ARGS);
135: static int termp_bq_pre(DECL_ARGS);
1.44 kristaps 136: static int termp_br_pre(DECL_ARGS);
1.31 kristaps 137: static int termp_brq_pre(DECL_ARGS);
138: static int termp_bt_pre(DECL_ARGS);
139: static int termp_cd_pre(DECL_ARGS);
140: static int termp_cm_pre(DECL_ARGS);
141: static int termp_d1_pre(DECL_ARGS);
142: static int termp_dq_pre(DECL_ARGS);
143: static int termp_em_pre(DECL_ARGS);
144: static int termp_ex_pre(DECL_ARGS);
145: static int termp_fa_pre(DECL_ARGS);
146: static int termp_fd_pre(DECL_ARGS);
147: static int termp_fl_pre(DECL_ARGS);
148: static int termp_fn_pre(DECL_ARGS);
149: static int termp_fo_pre(DECL_ARGS);
150: static int termp_ft_pre(DECL_ARGS);
151: static int termp_ic_pre(DECL_ARGS);
152: static int termp_in_pre(DECL_ARGS);
153: static int termp_it_pre(DECL_ARGS);
154: static int termp_lk_pre(DECL_ARGS);
155: static int termp_ms_pre(DECL_ARGS);
156: static int termp_mt_pre(DECL_ARGS);
157: static int termp_nd_pre(DECL_ARGS);
158: static int termp_nm_pre(DECL_ARGS);
159: static int termp_ns_pre(DECL_ARGS);
160: static int termp_op_pre(DECL_ARGS);
1.57 kristaps 161: static int termp_pa_pre(DECL_ARGS);
1.31 kristaps 162: static int termp_pf_pre(DECL_ARGS);
163: static int termp_pp_pre(DECL_ARGS);
164: static int termp_pq_pre(DECL_ARGS);
165: static int termp_qq_pre(DECL_ARGS);
166: static int termp_rs_pre(DECL_ARGS);
167: static int termp_rv_pre(DECL_ARGS);
168: static int termp_sh_pre(DECL_ARGS);
169: static int termp_sm_pre(DECL_ARGS);
1.45 kristaps 170: static int termp_sp_pre(DECL_ARGS);
1.31 kristaps 171: static int termp_sq_pre(DECL_ARGS);
172: static int termp_ss_pre(DECL_ARGS);
173: static int termp_sx_pre(DECL_ARGS);
174: static int termp_sy_pre(DECL_ARGS);
175: static int termp_ud_pre(DECL_ARGS);
176: static int termp_va_pre(DECL_ARGS);
177: static int termp_vt_pre(DECL_ARGS);
178: static int termp_xr_pre(DECL_ARGS);
179: static int termp_xx_pre(DECL_ARGS);
180:
1.1 kristaps 181: static const struct termact termacts[MDOC_MAX] = {
1.14 kristaps 182: { termp_ap_pre, NULL }, /* Ap */
1.1 kristaps 183: { NULL, NULL }, /* Dd */
184: { NULL, NULL }, /* Dt */
185: { NULL, NULL }, /* Os */
186: { termp_sh_pre, termp_sh_post }, /* Sh */
187: { termp_ss_pre, termp_ss_post }, /* Ss */
188: { termp_pp_pre, NULL }, /* Pp */
189: { termp_d1_pre, termp_d1_post }, /* D1 */
190: { termp_d1_pre, termp_d1_post }, /* Dl */
191: { termp_bd_pre, termp_bd_post }, /* Bd */
192: { NULL, NULL }, /* Ed */
193: { NULL, termp_bl_post }, /* Bl */
194: { NULL, NULL }, /* El */
195: { termp_it_pre, termp_it_post }, /* It */
196: { NULL, NULL }, /* Ad */
1.61 kristaps 197: { termp_an_pre, termp_an_post }, /* An */
1.1 kristaps 198: { termp_ar_pre, NULL }, /* Ar */
199: { termp_cd_pre, NULL }, /* Cd */
200: { termp_cm_pre, NULL }, /* Cm */
201: { NULL, NULL }, /* Dv */
202: { NULL, NULL }, /* Er */
203: { NULL, NULL }, /* Ev */
204: { termp_ex_pre, NULL }, /* Ex */
205: { termp_fa_pre, NULL }, /* Fa */
206: { termp_fd_pre, termp_fd_post }, /* Fd */
207: { termp_fl_pre, NULL }, /* Fl */
208: { termp_fn_pre, termp_fn_post }, /* Fn */
209: { termp_ft_pre, termp_ft_post }, /* Ft */
210: { termp_ic_pre, NULL }, /* Ic */
211: { termp_in_pre, termp_in_post }, /* In */
212: { NULL, NULL }, /* Li */
213: { termp_nd_pre, NULL }, /* Nd */
214: { termp_nm_pre, NULL }, /* Nm */
215: { termp_op_pre, termp_op_post }, /* Op */
216: { NULL, NULL }, /* Ot */
1.57 kristaps 217: { termp_pa_pre, NULL }, /* Pa */
1.1 kristaps 218: { termp_rv_pre, NULL }, /* Rv */
1.36 kristaps 219: { NULL, NULL }, /* St */
1.1 kristaps 220: { termp_va_pre, NULL }, /* Va */
221: { termp_vt_pre, termp_vt_post }, /* Vt */
222: { termp_xr_pre, NULL }, /* Xr */
223: { NULL, termp____post }, /* %A */
224: { NULL, termp____post }, /* %B */
225: { NULL, termp____post }, /* %D */
226: { NULL, termp____post }, /* %I */
227: { termp__j_pre, termp____post }, /* %J */
228: { NULL, termp____post }, /* %N */
229: { NULL, termp____post }, /* %O */
230: { NULL, termp____post }, /* %P */
231: { NULL, termp____post }, /* %R */
1.56 kristaps 232: { termp__t_pre, termp____post }, /* %T */
1.1 kristaps 233: { NULL, termp____post }, /* %V */
234: { NULL, NULL }, /* Ac */
235: { termp_aq_pre, termp_aq_post }, /* Ao */
236: { termp_aq_pre, termp_aq_post }, /* Aq */
1.35 kristaps 237: { NULL, NULL }, /* At */
1.1 kristaps 238: { NULL, NULL }, /* Bc */
239: { termp_bf_pre, NULL }, /* Bf */
240: { termp_bq_pre, termp_bq_post }, /* Bo */
241: { termp_bq_pre, termp_bq_post }, /* Bq */
1.26 kristaps 242: { termp_xx_pre, NULL }, /* Bsx */
1.1 kristaps 243: { NULL, termp_bx_post }, /* Bx */
244: { NULL, NULL }, /* Db */
245: { NULL, NULL }, /* Dc */
246: { termp_dq_pre, termp_dq_post }, /* Do */
247: { termp_dq_pre, termp_dq_post }, /* Dq */
248: { NULL, NULL }, /* Ec */
249: { NULL, NULL }, /* Ef */
250: { termp_em_pre, NULL }, /* Em */
251: { NULL, NULL }, /* Eo */
1.26 kristaps 252: { termp_xx_pre, NULL }, /* Fx */
1.1 kristaps 253: { termp_ms_pre, NULL }, /* Ms */
254: { NULL, NULL }, /* No */
255: { termp_ns_pre, NULL }, /* Ns */
1.26 kristaps 256: { termp_xx_pre, NULL }, /* Nx */
257: { termp_xx_pre, NULL }, /* Ox */
1.1 kristaps 258: { NULL, NULL }, /* Pc */
259: { termp_pf_pre, termp_pf_post }, /* Pf */
260: { termp_pq_pre, termp_pq_post }, /* Po */
261: { termp_pq_pre, termp_pq_post }, /* Pq */
262: { NULL, NULL }, /* Qc */
263: { termp_sq_pre, termp_sq_post }, /* Ql */
264: { termp_qq_pre, termp_qq_post }, /* Qo */
265: { termp_qq_pre, termp_qq_post }, /* Qq */
266: { NULL, NULL }, /* Re */
267: { termp_rs_pre, NULL }, /* Rs */
268: { NULL, NULL }, /* Sc */
269: { termp_sq_pre, termp_sq_post }, /* So */
270: { termp_sq_pre, termp_sq_post }, /* Sq */
271: { termp_sm_pre, NULL }, /* Sm */
272: { termp_sx_pre, NULL }, /* Sx */
273: { termp_sy_pre, NULL }, /* Sy */
274: { NULL, NULL }, /* Tn */
1.26 kristaps 275: { termp_xx_pre, NULL }, /* Ux */
1.1 kristaps 276: { NULL, NULL }, /* Xc */
277: { NULL, NULL }, /* Xo */
278: { termp_fo_pre, termp_fo_post }, /* Fo */
279: { NULL, NULL }, /* Fc */
280: { termp_op_pre, termp_op_post }, /* Oo */
281: { NULL, NULL }, /* Oc */
282: { NULL, NULL }, /* Bk */
283: { NULL, NULL }, /* Ek */
284: { termp_bt_pre, NULL }, /* Bt */
285: { NULL, NULL }, /* Hf */
286: { NULL, NULL }, /* Fr */
287: { termp_ud_pre, NULL }, /* Ud */
1.37 kristaps 288: { NULL, termp_lb_post }, /* Lb */
1.14 kristaps 289: { termp_pp_pre, NULL }, /* Lp */
1.1 kristaps 290: { termp_lk_pre, NULL }, /* Lk */
291: { termp_mt_pre, NULL }, /* Mt */
292: { termp_brq_pre, termp_brq_post }, /* Brq */
293: { termp_brq_pre, termp_brq_post }, /* Bro */
294: { NULL, NULL }, /* Brc */
295: { NULL, NULL }, /* %C */
296: { NULL, NULL }, /* Es */
297: { NULL, NULL }, /* En */
1.26 kristaps 298: { termp_xx_pre, NULL }, /* Dx */
1.1 kristaps 299: { NULL, NULL }, /* %Q */
1.44 kristaps 300: { termp_br_pre, NULL }, /* br */
1.45 kristaps 301: { termp_sp_pre, NULL }, /* sp */
1.1 kristaps 302: };
303:
1.2 kristaps 304: #ifdef __linux__
1.9 kristaps 305: extern size_t strlcpy(char *, const char *, size_t);
306: extern size_t strlcat(char *, const char *, size_t);
1.2 kristaps 307: #endif
308:
1.1 kristaps 309: static int arg_hasattr(int, const struct mdoc_node *);
310: static int arg_getattrs(const int *, int *, size_t,
311: const struct mdoc_node *);
312: static int arg_getattr(int, const struct mdoc_node *);
313: static size_t arg_offset(const struct mdoc_argv *);
314: static size_t arg_width(const struct mdoc_argv *, int);
315: static int arg_listtype(const struct mdoc_node *);
1.54 kristaps 316: static void fmt_block_vspace(struct termp *,
1.1 kristaps 317: const struct mdoc_node *,
318: const struct mdoc_node *);
1.3 kristaps 319: static void print_node(DECL_ARGS);
320: static void print_head(struct termp *,
1.1 kristaps 321: const struct mdoc_meta *);
1.3 kristaps 322: static void print_body(DECL_ARGS);
323: static void print_foot(struct termp *,
1.1 kristaps 324: const struct mdoc_meta *);
325:
326:
327: int
328: mdoc_run(struct termp *p, const struct mdoc *m)
329: {
1.9 kristaps 330: /*
331: * Main output function. When this is called, assume that the
332: * tree is properly formed.
333: */
1.3 kristaps 334: print_head(p, mdoc_meta(m));
1.14 kristaps 335: assert(mdoc_node(m));
336: assert(MDOC_ROOT == mdoc_node(m)->type);
337: if (mdoc_node(m)->child)
338: print_body(p, NULL, mdoc_meta(m), mdoc_node(m)->child);
1.3 kristaps 339: print_foot(p, mdoc_meta(m));
340: return(1);
1.1 kristaps 341: }
342:
343:
1.3 kristaps 344: static void
1.1 kristaps 345: print_body(DECL_ARGS)
346: {
347:
1.3 kristaps 348: print_node(p, pair, meta, node);
1.1 kristaps 349: if ( ! node->next)
1.3 kristaps 350: return;
351: print_body(p, pair, meta, node->next);
1.1 kristaps 352: }
353:
354:
1.3 kristaps 355: static void
1.1 kristaps 356: print_node(DECL_ARGS)
357: {
358: int dochild;
359: struct termpair npair;
1.30 kristaps 360: size_t offset, rmargin;
1.1 kristaps 361:
362: dochild = 1;
1.29 kristaps 363: offset = p->offset;
1.30 kristaps 364: rmargin = p->rmargin;
1.29 kristaps 365:
1.1 kristaps 366: npair.ppair = pair;
367: npair.flag = 0;
368: npair.count = 0;
369:
1.46 kristaps 370: /*
371: * Note on termpair. This allows a pre function to set a termp
372: * flag that is automatically unset after the body, but before
373: * the post function. Thus, if a pre uses a termpair flag, it
374: * must be reapplied in the post for use.
375: */
376:
1.1 kristaps 377: if (MDOC_TEXT != node->type) {
378: if (termacts[node->tok].pre)
379: if ( ! (*termacts[node->tok].pre)(p, &npair, meta, node))
380: dochild = 0;
381: } else /* MDOC_TEXT == node->type */
382: term_word(p, node->string);
383:
384: /* Children. */
385:
1.28 kristaps 386: p->flags |= npair.flag;
1.1 kristaps 387:
388: if (dochild && node->child)
389: print_body(p, &npair, meta, node->child);
390:
1.46 kristaps 391: p->flags &= ~npair.flag;
392:
1.1 kristaps 393: /* Post-processing. */
394:
395: if (MDOC_TEXT != node->type)
396: if (termacts[node->tok].post)
397: (*termacts[node->tok].post)(p, &npair, meta, node);
1.29 kristaps 398:
399: p->offset = offset;
1.30 kristaps 400: p->rmargin = rmargin;
1.1 kristaps 401: }
402:
403:
1.3 kristaps 404: static void
1.1 kristaps 405: print_foot(struct termp *p, const struct mdoc_meta *meta)
406: {
407: struct tm *tm;
408: char *buf, *os;
409:
1.9 kristaps 410: /*
411: * Output the footer in new-groff style, that is, three columns
412: * with the middle being the manual date and flanking columns
413: * being the operating system:
414: *
415: * SYSTEM DATE SYSTEM
416: */
417:
1.1 kristaps 418: if (NULL == (buf = malloc(p->rmargin)))
419: err(1, "malloc");
420: if (NULL == (os = malloc(p->rmargin)))
421: err(1, "malloc");
422:
423: tm = localtime(&meta->date);
424:
1.42 kristaps 425: if (0 == strftime(buf, p->rmargin, "%B %e, %Y", tm))
1.1 kristaps 426: err(1, "strftime");
427:
428: (void)strlcpy(os, meta->os, p->rmargin);
429:
430: term_vspace(p);
431:
1.9 kristaps 432: p->offset = 0;
433: p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2;
1.1 kristaps 434: p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
435:
436: term_word(p, os);
437: term_flushln(p);
438:
1.9 kristaps 439: p->offset = p->rmargin;
440: p->rmargin = p->maxrmargin - strlen(os);
1.1 kristaps 441: p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
1.9 kristaps 442:
443: term_word(p, buf);
444: term_flushln(p);
445:
1.1 kristaps 446: p->offset = p->rmargin;
447: p->rmargin = p->maxrmargin;
448: p->flags &= ~TERMP_NOBREAK;
1.9 kristaps 449: p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
1.1 kristaps 450:
1.9 kristaps 451: term_word(p, os);
1.1 kristaps 452: term_flushln(p);
453:
1.9 kristaps 454: p->offset = 0;
455: p->rmargin = p->maxrmargin;
456: p->flags = 0;
457:
1.1 kristaps 458: free(buf);
459: free(os);
460: }
461:
462:
1.3 kristaps 463: static void
1.1 kristaps 464: print_head(struct termp *p, const struct mdoc_meta *meta)
465: {
466: char *buf, *title;
467:
468: p->rmargin = p->maxrmargin;
469: p->offset = 0;
470:
471: if (NULL == (buf = malloc(p->rmargin)))
472: err(1, "malloc");
473: if (NULL == (title = malloc(p->rmargin)))
474: err(1, "malloc");
475:
476: /*
477: * The header is strange. It has three components, which are
478: * really two with the first duplicated. It goes like this:
479: *
480: * IDENTIFIER TITLE IDENTIFIER
481: *
482: * The IDENTIFIER is NAME(SECTION), which is the command-name
483: * (if given, or "unknown" if not) followed by the manual page
484: * section. These are given in `Dt'. The TITLE is a free-form
485: * string depending on the manual volume. If not specified, it
486: * switches on the manual section.
487: */
488:
489: assert(meta->vol);
490: (void)strlcpy(buf, meta->vol, p->rmargin);
491:
492: if (meta->arch) {
493: (void)strlcat(buf, " (", p->rmargin);
494: (void)strlcat(buf, meta->arch, p->rmargin);
495: (void)strlcat(buf, ")", p->rmargin);
496: }
497:
498: (void)snprintf(title, p->rmargin, "%s(%d)",
499: meta->title, meta->msec);
500:
501: p->offset = 0;
1.8 kristaps 502: p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2;
1.1 kristaps 503: p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
504:
505: term_word(p, title);
506: term_flushln(p);
507:
508: p->offset = p->rmargin;
509: p->rmargin = p->maxrmargin - strlen(title);
1.9 kristaps 510: p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
1.1 kristaps 511:
512: term_word(p, buf);
513: term_flushln(p);
514:
515: p->offset = p->rmargin;
516: p->rmargin = p->maxrmargin;
517: p->flags &= ~TERMP_NOBREAK;
518: p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
519:
520: term_word(p, title);
521: term_flushln(p);
522:
1.9 kristaps 523: p->offset = 0;
1.1 kristaps 524: p->rmargin = p->maxrmargin;
525: p->flags &= ~TERMP_NOSPACE;
526:
527: free(title);
528: free(buf);
529: }
530:
531:
532: static size_t
533: arg_width(const struct mdoc_argv *arg, int pos)
534: {
535: int i, len;
1.40 kristaps 536: const char *p;
1.1 kristaps 537:
538: assert(pos < (int)arg->sz && pos >= 0);
539: assert(arg->value[pos]);
540:
1.40 kristaps 541: p = arg->value[pos];
542:
543: if (0 == (len = (int)strlen(p)))
1.1 kristaps 544: return(0);
545:
546: for (i = 0; i < len - 1; i++)
1.40 kristaps 547: if ( ! isdigit((u_char)p[i]))
1.1 kristaps 548: break;
549:
1.40 kristaps 550: if (i == len - 1)
551: if ('n' == p[len - 1] || 'm' == p[len - 1])
552: return((size_t)atoi(p) + 2);
1.1 kristaps 553:
1.40 kristaps 554: return((size_t)len + 2);
1.1 kristaps 555: }
556:
557:
558: static int
559: arg_listtype(const struct mdoc_node *n)
560: {
561: int i, len;
562:
563: assert(MDOC_BLOCK == n->type);
564:
565: len = (int)(n->args ? n->args->argc : 0);
566:
567: for (i = 0; i < len; i++)
568: switch (n->args->argv[i].arg) {
569: case (MDOC_Bullet):
570: /* FALLTHROUGH */
571: case (MDOC_Dash):
572: /* FALLTHROUGH */
573: case (MDOC_Enum):
574: /* FALLTHROUGH */
575: case (MDOC_Hyphen):
576: /* FALLTHROUGH */
577: case (MDOC_Tag):
578: /* FALLTHROUGH */
579: case (MDOC_Inset):
580: /* FALLTHROUGH */
581: case (MDOC_Diag):
582: /* FALLTHROUGH */
583: case (MDOC_Item):
584: /* FALLTHROUGH */
585: case (MDOC_Column):
586: /* FALLTHROUGH */
1.38 kristaps 587: case (MDOC_Hang):
588: /* FALLTHROUGH */
1.1 kristaps 589: case (MDOC_Ohang):
590: return(n->args->argv[i].arg);
591: default:
592: break;
593: }
594:
1.38 kristaps 595: return(-1);
1.1 kristaps 596: }
597:
598:
599: static size_t
600: arg_offset(const struct mdoc_argv *arg)
601: {
1.40 kristaps 602: int len, i;
603: const char *p;
1.1 kristaps 604:
605: assert(*arg->value);
1.40 kristaps 606: p = *arg->value;
607:
608: if (0 == strcmp(p, "left"))
1.19 kristaps 609: return(0);
1.40 kristaps 610: if (0 == strcmp(p, "indent"))
1.16 kristaps 611: return(INDENT + 1);
1.40 kristaps 612: if (0 == strcmp(p, "indent-two"))
1.20 kristaps 613: return((INDENT + 1) * 2);
1.10 kristaps 614:
1.40 kristaps 615: if (0 == (len = (int)strlen(p)))
616: return(0);
617:
618: for (i = 0; i < len - 1; i++)
619: if ( ! isdigit((u_char)p[i]))
620: break;
621:
622: if (i == len - 1)
623: if ('n' == p[len - 1] || 'm' == p[len - 1])
624: return((size_t)atoi(p));
1.11 kristaps 625:
1.40 kristaps 626: return((size_t)len);
1.1 kristaps 627: }
628:
629:
630: static int
631: arg_hasattr(int arg, const struct mdoc_node *n)
632: {
633:
634: return(-1 != arg_getattr(arg, n));
635: }
636:
637:
638: static int
639: arg_getattr(int v, const struct mdoc_node *n)
640: {
641: int val;
642:
643: return(arg_getattrs(&v, &val, 1, n) ? val : -1);
644: }
645:
646:
647: static int
648: arg_getattrs(const int *keys, int *vals,
649: size_t sz, const struct mdoc_node *n)
650: {
651: int i, j, k;
652:
653: if (NULL == n->args)
654: return(0);
655:
656: for (k = i = 0; i < (int)n->args->argc; i++)
657: for (j = 0; j < (int)sz; j++)
658: if (n->args->argv[i].arg == keys[j]) {
659: vals[j] = i;
660: k++;
661: }
662: return(k);
663: }
664:
665:
666: /* ARGSUSED */
1.54 kristaps 667: static void
1.1 kristaps 668: fmt_block_vspace(struct termp *p,
669: const struct mdoc_node *bl,
670: const struct mdoc_node *node)
671: {
672: const struct mdoc_node *n;
673:
674: term_newln(p);
675:
1.59 kristaps 676: if (MDOC_Bl == bl->tok && arg_hasattr(MDOC_Compact, bl))
1.54 kristaps 677: return;
1.63 kristaps 678: assert(node);
1.54 kristaps 679:
680: /*
681: * Search through our prior nodes. If we follow a `Ss' or `Sh',
682: * then don't vspace.
683: */
1.1 kristaps 684:
685: for (n = node; n; n = n->parent) {
686: if (MDOC_BLOCK != n->type)
687: continue;
688: if (MDOC_Ss == n->tok)
1.54 kristaps 689: return;
1.1 kristaps 690: if (MDOC_Sh == n->tok)
1.54 kristaps 691: return;
1.1 kristaps 692: if (NULL == n->prev)
693: continue;
694: break;
695: }
696:
1.54 kristaps 697: /*
1.55 kristaps 698: * XXX - not documented: a `-column' does not ever assert vspace
699: * within the list.
1.54 kristaps 700: */
701:
1.59 kristaps 702: if (MDOC_Bl == bl->tok && arg_hasattr(MDOC_Column, bl))
1.54 kristaps 703: if (node->prev && MDOC_It == node->prev->tok)
704: return;
705:
1.55 kristaps 706: /*
707: * XXX - not documented: a `-diag' without a body does not
708: * assert a vspace prior to the next element.
709: */
1.59 kristaps 710: if (MDOC_Bl == bl->tok && arg_hasattr(MDOC_Diag, bl))
1.55 kristaps 711: if (node->prev && MDOC_It == node->prev->tok) {
712: assert(node->prev->body);
713: if (NULL == node->prev->body->child)
714: return;
715: }
716:
1.54 kristaps 717: term_vspace(p);
1.1 kristaps 718: }
719:
720:
721: /* ARGSUSED */
722: static int
723: termp_dq_pre(DECL_ARGS)
724: {
725:
726: if (MDOC_BODY != node->type)
727: return(1);
728:
729: term_word(p, "\\(lq");
730: p->flags |= TERMP_NOSPACE;
731: return(1);
732: }
733:
734:
735: /* ARGSUSED */
736: static void
737: termp_dq_post(DECL_ARGS)
738: {
739:
740: if (MDOC_BODY != node->type)
741: return;
742:
743: p->flags |= TERMP_NOSPACE;
744: term_word(p, "\\(rq");
745: }
746:
747:
748: /* ARGSUSED */
749: static int
750: termp_it_pre(DECL_ARGS)
751: {
752: const struct mdoc_node *bl, *n;
753: char buf[7];
1.39 kristaps 754: int i, type, keys[3], vals[3];
1.1 kristaps 755: size_t width, offset;
756:
1.54 kristaps 757: if (MDOC_BLOCK == node->type) {
758: fmt_block_vspace(p, node->parent->parent, node);
759: return(1);
760: }
1.1 kristaps 761:
762: bl = node->parent->parent->parent;
763:
764: /* Save parent attributes. */
765:
766: pair->flag = p->flags;
767:
768: /* Get list width and offset. */
769:
770: keys[0] = MDOC_Width;
771: keys[1] = MDOC_Offset;
772: keys[2] = MDOC_Column;
773:
774: vals[0] = vals[1] = vals[2] = -1;
775:
776: width = offset = 0;
777:
778: (void)arg_getattrs(keys, vals, 3, bl);
779:
780: type = arg_listtype(bl);
1.38 kristaps 781: assert(-1 != type);
1.1 kristaps 782:
783: /* Calculate real width and offset. */
784:
785: switch (type) {
786: case (MDOC_Column):
787: if (MDOC_BODY == node->type)
788: break;
1.58 kristaps 789: /*
790: * Work around groff's column handling. The offset is
791: * equal to the sum of all widths leading to the current
792: * column (plus the -offset value). If this column
793: * exceeds the stated number of columns, the width is
794: * set as 0, else it's the stated column width (later
795: * the 0 will be adjusted to default 10 or, if in the
796: * last column case, set to stretch to the margin).
797: */
798: for (i = 0, n = node->prev; n && n &&
799: i < (int)bl->args[vals[2]].argv->sz;
800: n = n->prev, i++)
1.1 kristaps 801: offset += arg_width
802: (&bl->args->argv[vals[2]], i);
1.58 kristaps 803:
804: /* Whether exceeds maximum column. */
805: if (i < (int)bl->args[vals[2]].argv->sz)
806: width = arg_width(&bl->args->argv[vals[2]], i);
807: else
808: width = 0;
809:
1.1 kristaps 810: if (vals[1] >= 0)
811: offset += arg_offset(&bl->args->argv[vals[1]]);
812: break;
813: default:
814: if (vals[0] >= 0)
815: width = arg_width(&bl->args->argv[vals[0]], 0);
816: if (vals[1] >= 0)
1.19 kristaps 817: offset += arg_offset(&bl->args->argv[vals[1]]);
1.1 kristaps 818: break;
819: }
820:
821: /*
822: * List-type can override the width in the case of fixed-head
823: * values (bullet, dash/hyphen, enum). Tags need a non-zero
1.67 ! kristaps 824: * offset.
1.1 kristaps 825: */
826:
827: switch (type) {
828: case (MDOC_Bullet):
829: /* FALLTHROUGH */
830: case (MDOC_Dash):
831: /* FALLTHROUGH */
832: case (MDOC_Hyphen):
833: if (width < 4)
834: width = 4;
835: break;
1.17 kristaps 836: case (MDOC_Enum):
837: if (width < 5)
838: width = 5;
839: break;
1.38 kristaps 840: case (MDOC_Hang):
1.39 kristaps 841: if (0 == width)
842: width = 8;
843: break;
1.49 kristaps 844: case (MDOC_Column):
845: /* FALLTHROUGH */
1.1 kristaps 846: case (MDOC_Tag):
847: if (0 == width)
848: width = 10;
849: break;
850: default:
851: break;
852: }
853:
854: /*
1.17 kristaps 855: * Whitespace control. Inset bodies need an initial space,
856: * while diagonal bodies need two.
1.1 kristaps 857: */
858:
1.51 kristaps 859: p->flags |= TERMP_NOSPACE;
860:
1.1 kristaps 861: switch (type) {
1.51 kristaps 862: case (MDOC_Diag):
1.62 kristaps 863: if (MDOC_BODY == node->type)
864: term_word(p, "\\ \\ ");
1.51 kristaps 865: break;
1.1 kristaps 866: case (MDOC_Inset):
867: if (MDOC_BODY == node->type)
1.51 kristaps 868: term_word(p, "\\ ");
1.1 kristaps 869: break;
870: default:
871: break;
872: }
873:
1.51 kristaps 874: p->flags |= TERMP_NOSPACE;
875:
1.1 kristaps 876: /*
877: * Style flags. Diagnostic heads need TTYPE_DIAG.
878: */
879:
880: switch (type) {
881: case (MDOC_Diag):
882: if (MDOC_HEAD == node->type)
883: p->flags |= ttypes[TTYPE_DIAG];
884: break;
885: default:
886: break;
887: }
888:
889: /*
890: * Pad and break control. This is the tricker part. Lists with
891: * set right-margins for the head get TERMP_NOBREAK because, if
892: * they overrun the margin, they wrap to the new margin.
893: * Correspondingly, the body for these types don't left-pad, as
894: * the head will pad out to to the right.
895: */
896:
897: switch (type) {
898: case (MDOC_Bullet):
899: /* FALLTHROUGH */
900: case (MDOC_Dash):
901: /* FALLTHROUGH */
902: case (MDOC_Enum):
903: /* FALLTHROUGH */
904: case (MDOC_Hyphen):
1.39 kristaps 905: if (MDOC_HEAD == node->type)
906: p->flags |= TERMP_NOBREAK;
907: else
908: p->flags |= TERMP_NOLPAD;
909: break;
1.38 kristaps 910: case (MDOC_Hang):
1.39 kristaps 911: if (MDOC_HEAD == node->type)
912: p->flags |= TERMP_NOBREAK;
913: else
914: p->flags |= TERMP_NOLPAD;
915:
1.59 kristaps 916: if (MDOC_HEAD != node->type)
917: break;
918:
919: /*
920: * This is ugly. If `-hang' is specified and the body
921: * is a `Bl' or `Bd', then we want basically to nullify
922: * the "overstep" effect in term_flushln() and treat
923: * this as a `-ohang' list instead.
924: */
925: if (node->next->child &&
926: (MDOC_Bl == node->next->child->tok ||
927: MDOC_Bd == node->next->child->tok)) {
928: p->flags &= ~TERMP_NOBREAK;
929: p->flags &= ~TERMP_NOLPAD;
930: } else
1.39 kristaps 931: p->flags |= TERMP_HANG;
932: break;
1.1 kristaps 933: case (MDOC_Tag):
934: if (MDOC_HEAD == node->type)
1.51 kristaps 935: p->flags |= TERMP_NOBREAK | TERMP_TWOSPACE;
1.1 kristaps 936: else
937: p->flags |= TERMP_NOLPAD;
1.38 kristaps 938:
1.39 kristaps 939: if (MDOC_HEAD != node->type)
940: break;
941: if (NULL == node->next || NULL == node->next->child)
942: p->flags |= TERMP_DANGLE;
1.1 kristaps 943: break;
944: case (MDOC_Column):
945: if (MDOC_HEAD == node->type) {
946: assert(node->next);
947: if (MDOC_BODY == node->next->type)
948: p->flags &= ~TERMP_NOBREAK;
949: else
950: p->flags |= TERMP_NOBREAK;
951: if (node->prev)
952: p->flags |= TERMP_NOLPAD;
953: }
954: break;
955: case (MDOC_Diag):
956: if (MDOC_HEAD == node->type)
957: p->flags |= TERMP_NOBREAK;
958: break;
959: default:
960: break;
961: }
962:
963: /*
964: * Margin control. Set-head-width lists have their right
965: * margins shortened. The body for these lists has the offset
966: * necessarily lengthened. Everybody gets the offset.
967: */
968:
969: p->offset += offset;
970:
971: switch (type) {
1.59 kristaps 972: case (MDOC_Hang):
973: /*
974: * Same stipulation as above, regarding `-hang'. We
975: * don't want to recalculate rmargin and offsets when
976: * using `Bd' or `Bl' within `-hang' overstep lists.
977: */
978: if (MDOC_HEAD == node->type && node->next->child &&
979: (MDOC_Bl == node->next->child->tok ||
980: MDOC_Bd == node->next->child->tok))
981: break;
982: /* FALLTHROUGH */
1.1 kristaps 983: case (MDOC_Bullet):
984: /* FALLTHROUGH */
985: case (MDOC_Dash):
986: /* FALLTHROUGH */
987: case (MDOC_Enum):
988: /* FALLTHROUGH */
989: case (MDOC_Hyphen):
990: /* FALLTHROUGH */
991: case (MDOC_Tag):
1.49 kristaps 992: assert(width);
1.1 kristaps 993: if (MDOC_HEAD == node->type)
994: p->rmargin = p->offset + width;
995: else
996: p->offset += width;
997: break;
998: case (MDOC_Column):
1.49 kristaps 999: assert(width);
1.1 kristaps 1000: p->rmargin = p->offset + width;
1.50 kristaps 1001: /*
1002: * XXX - this behaviour is not documented: the
1003: * right-most column is filled to the right margin.
1004: */
1005: if (MDOC_HEAD == node->type &&
1006: MDOC_BODY == node->next->type)
1007: p->rmargin = p->maxrmargin;
1.1 kristaps 1008: break;
1009: default:
1010: break;
1011: }
1012:
1013: /*
1014: * The dash, hyphen, bullet and enum lists all have a special
1.15 kristaps 1015: * HEAD character (temporarily bold, in some cases).
1.1 kristaps 1016: */
1017:
1018: if (MDOC_HEAD == node->type)
1019: switch (type) {
1020: case (MDOC_Bullet):
1.15 kristaps 1021: p->flags |= TERMP_BOLD;
1.1 kristaps 1022: term_word(p, "\\[bu]");
1.39 kristaps 1023: p->flags &= ~TERMP_BOLD;
1.1 kristaps 1024: break;
1025: case (MDOC_Dash):
1026: /* FALLTHROUGH */
1027: case (MDOC_Hyphen):
1.15 kristaps 1028: p->flags |= TERMP_BOLD;
1.27 kristaps 1029: term_word(p, "\\(hy");
1.39 kristaps 1030: p->flags &= ~TERMP_BOLD;
1.1 kristaps 1031: break;
1032: case (MDOC_Enum):
1033: (pair->ppair->ppair->count)++;
1034: (void)snprintf(buf, sizeof(buf), "%d.",
1035: pair->ppair->ppair->count);
1036: term_word(p, buf);
1037: break;
1038: default:
1039: break;
1040: }
1041:
1042: /*
1043: * If we're not going to process our children, indicate so here.
1044: */
1045:
1046: switch (type) {
1047: case (MDOC_Bullet):
1048: /* FALLTHROUGH */
1049: case (MDOC_Item):
1050: /* FALLTHROUGH */
1051: case (MDOC_Dash):
1052: /* FALLTHROUGH */
1053: case (MDOC_Hyphen):
1054: /* FALLTHROUGH */
1055: case (MDOC_Enum):
1056: if (MDOC_HEAD == node->type)
1057: return(0);
1058: break;
1059: case (MDOC_Column):
1060: if (MDOC_BODY == node->type)
1061: return(0);
1062: break;
1063: default:
1064: break;
1065: }
1066:
1067: return(1);
1068: }
1069:
1070:
1071: /* ARGSUSED */
1072: static void
1073: termp_it_post(DECL_ARGS)
1074: {
1075: int type;
1076:
1077: if (MDOC_BODY != node->type && MDOC_HEAD != node->type)
1078: return;
1079:
1080: type = arg_listtype(node->parent->parent->parent);
1.38 kristaps 1081: assert(-1 != type);
1.1 kristaps 1082:
1083: switch (type) {
1084: case (MDOC_Item):
1085: /* FALLTHROUGH */
1.53 kristaps 1086: case (MDOC_Diag):
1087: /* FALLTHROUGH */
1.1 kristaps 1088: case (MDOC_Inset):
1089: if (MDOC_BODY == node->type)
1090: term_flushln(p);
1091: break;
1092: case (MDOC_Column):
1093: if (MDOC_HEAD == node->type)
1094: term_flushln(p);
1095: break;
1096: default:
1097: term_flushln(p);
1098: break;
1099: }
1100:
1101: p->flags = pair->flag;
1102: }
1103:
1104:
1105: /* ARGSUSED */
1106: static int
1107: termp_nm_pre(DECL_ARGS)
1108: {
1109:
1110: if (SEC_SYNOPSIS == node->sec)
1111: term_newln(p);
1112:
1.28 kristaps 1113: pair->flag |= ttypes[TTYPE_PROG];
1114: p->flags |= ttypes[TTYPE_PROG];
1115:
1.1 kristaps 1116: if (NULL == node->child)
1117: term_word(p, meta->name);
1118:
1119: return(1);
1120: }
1121:
1122:
1123: /* ARGSUSED */
1124: static int
1125: termp_fl_pre(DECL_ARGS)
1126: {
1127:
1.28 kristaps 1128: pair->flag |= ttypes[TTYPE_CMD_FLAG];
1129: p->flags |= ttypes[TTYPE_CMD_FLAG];
1.1 kristaps 1130: term_word(p, "\\-");
1131: p->flags |= TERMP_NOSPACE;
1132: return(1);
1133: }
1134:
1135:
1136: /* ARGSUSED */
1137: static int
1.61 kristaps 1138: termp_an_pre(DECL_ARGS)
1139: {
1140:
1141: if (NULL == node->child)
1142: return(1);
1143:
1144: /*
1145: * XXX: this is poorly documented. If not in the AUTHORS
1146: * section, `An -split' will cause newlines to occur before the
1147: * author name. If in the AUTHORS section, by default, the
1148: * first `An' invocation is nosplit, then all subsequent ones,
1149: * regardless of whether interspersed with other macros/text,
1150: * are split. -split, in this case, will override the condition
1151: * of the implied first -nosplit.
1152: */
1153:
1154: if (node->sec == SEC_AUTHORS) {
1155: if ( ! (TERMP_ANPREC & p->flags)) {
1156: if (TERMP_SPLIT & p->flags)
1157: term_newln(p);
1158: return(1);
1159: }
1160: if (TERMP_NOSPLIT & p->flags)
1161: return(1);
1162: term_newln(p);
1163: return(1);
1164: }
1165:
1166: if (TERMP_SPLIT & p->flags)
1167: term_newln(p);
1168:
1169: return(1);
1170: }
1171:
1172:
1173: /* ARGSUSED */
1174: static void
1175: termp_an_post(DECL_ARGS)
1176: {
1177:
1178: if (node->child) {
1179: if (SEC_AUTHORS == node->sec)
1180: p->flags |= TERMP_ANPREC;
1181: return;
1182: }
1183:
1184: if (arg_getattr(MDOC_Split, node) > -1) {
1185: p->flags &= ~TERMP_NOSPLIT;
1186: p->flags |= TERMP_SPLIT;
1187: } else {
1188: p->flags &= ~TERMP_SPLIT;
1189: p->flags |= TERMP_NOSPLIT;
1190: }
1191:
1192: }
1193:
1194:
1195: /* ARGSUSED */
1196: static int
1.1 kristaps 1197: termp_ar_pre(DECL_ARGS)
1198: {
1199:
1.28 kristaps 1200: pair->flag |= ttypes[TTYPE_CMD_ARG];
1.1 kristaps 1201: return(1);
1202: }
1203:
1204:
1205: /* ARGSUSED */
1206: static int
1207: termp_ns_pre(DECL_ARGS)
1208: {
1209:
1210: p->flags |= TERMP_NOSPACE;
1211: return(1);
1212: }
1213:
1214:
1215: /* ARGSUSED */
1216: static int
1217: termp_pp_pre(DECL_ARGS)
1218: {
1219:
1220: term_vspace(p);
1221: return(1);
1222: }
1223:
1224:
1225: /* ARGSUSED */
1226: static int
1227: termp_rs_pre(DECL_ARGS)
1228: {
1229:
1230: if (MDOC_BLOCK == node->type && node->prev)
1231: term_vspace(p);
1232: return(1);
1233: }
1234:
1235:
1236: /* ARGSUSED */
1237: static int
1238: termp_rv_pre(DECL_ARGS)
1239: {
1240: int i;
1241:
1.34 kristaps 1242: i = arg_getattr(MDOC_Std, node);
1243: assert(-1 != i);
1244: assert(node->args->argv[i].sz);
1.1 kristaps 1245:
1246: term_newln(p);
1247: term_word(p, "The");
1248:
1249: p->flags |= ttypes[TTYPE_FUNC_NAME];
1250: term_word(p, *node->args->argv[i].value);
1251: p->flags &= ~ttypes[TTYPE_FUNC_NAME];
1252: p->flags |= TERMP_NOSPACE;
1253:
1254: term_word(p, "() function returns the value 0 if successful;");
1255: term_word(p, "otherwise the value -1 is returned and the");
1256: term_word(p, "global variable");
1257:
1258: p->flags |= ttypes[TTYPE_VAR_DECL];
1259: term_word(p, "errno");
1260: p->flags &= ~ttypes[TTYPE_VAR_DECL];
1261:
1262: term_word(p, "is set to indicate the error.");
1263:
1264: return(1);
1265: }
1266:
1267:
1268: /* ARGSUSED */
1269: static int
1270: termp_ex_pre(DECL_ARGS)
1271: {
1272: int i;
1273:
1.34 kristaps 1274: i = arg_getattr(MDOC_Std, node);
1275: assert(-1 != i);
1276: assert(node->args->argv[i].sz);
1.1 kristaps 1277:
1278: term_word(p, "The");
1279: p->flags |= ttypes[TTYPE_PROG];
1280: term_word(p, *node->args->argv[i].value);
1281: p->flags &= ~ttypes[TTYPE_PROG];
1282: term_word(p, "utility exits 0 on success, and >0 if an error occurs.");
1283:
1284: return(1);
1285: }
1286:
1287:
1288: /* ARGSUSED */
1289: static int
1290: termp_nd_pre(DECL_ARGS)
1291: {
1.25 kristaps 1292:
1293: if (MDOC_BODY != node->type)
1294: return(1);
1.30 kristaps 1295:
1.27 kristaps 1296: #if defined(__OpenBSD__) || defined(__linux__)
1.41 kristaps 1297: term_word(p, "\\(en");
1.23 kristaps 1298: #else
1299: term_word(p, "\\(em");
1300: #endif
1.1 kristaps 1301: return(1);
1302: }
1303:
1304:
1305: /* ARGSUSED */
1306: static void
1307: termp_bl_post(DECL_ARGS)
1308: {
1309:
1310: if (MDOC_BLOCK == node->type)
1311: term_newln(p);
1312: }
1313:
1314:
1315: /* ARGSUSED */
1316: static void
1317: termp_op_post(DECL_ARGS)
1318: {
1319:
1320: if (MDOC_BODY != node->type)
1321: return;
1322: p->flags |= TERMP_NOSPACE;
1323: term_word(p, "\\(rB");
1324: }
1325:
1326:
1327: /* ARGSUSED */
1328: static int
1329: termp_xr_pre(DECL_ARGS)
1330: {
1331: const struct mdoc_node *n;
1332:
1.11 kristaps 1333: assert(node->child && MDOC_TEXT == node->child->type);
1334: n = node->child;
1335:
1.1 kristaps 1336: term_word(p, n->string);
1337: if (NULL == (n = n->next))
1338: return(0);
1339: p->flags |= TERMP_NOSPACE;
1340: term_word(p, "(");
1341: p->flags |= TERMP_NOSPACE;
1342: term_word(p, n->string);
1343: p->flags |= TERMP_NOSPACE;
1344: term_word(p, ")");
1345: return(0);
1346: }
1347:
1348:
1349: /* ARGSUSED */
1350: static int
1351: termp_vt_pre(DECL_ARGS)
1352: {
1353:
1354: /* FIXME: this can be "type name". */
1.29 kristaps 1355: pair->flag |= ttypes[TTYPE_VAR_DECL];
1.1 kristaps 1356: return(1);
1357: }
1358:
1359:
1360: /* ARGSUSED */
1361: static void
1362: termp_vt_post(DECL_ARGS)
1363: {
1364:
1.32 kristaps 1365: if (node->sec != SEC_SYNOPSIS)
1366: return;
1367: if (node->next && MDOC_Vt == node->next->tok)
1368: term_newln(p);
1369: else if (node->next)
1.1 kristaps 1370: term_vspace(p);
1371: }
1372:
1373:
1374: /* ARGSUSED */
1375: static int
1376: termp_fd_pre(DECL_ARGS)
1377: {
1378:
1.29 kristaps 1379: pair->flag |= ttypes[TTYPE_FUNC_DECL];
1.1 kristaps 1380: return(1);
1381: }
1382:
1383:
1384: /* ARGSUSED */
1385: static void
1386: termp_fd_post(DECL_ARGS)
1387: {
1388:
1389: if (node->sec != SEC_SYNOPSIS)
1390: return;
1.29 kristaps 1391:
1.1 kristaps 1392: term_newln(p);
1393: if (node->next && MDOC_Fd != node->next->tok)
1394: term_vspace(p);
1395: }
1396:
1397:
1398: /* ARGSUSED */
1399: static int
1400: termp_sh_pre(DECL_ARGS)
1401: {
1.64 kristaps 1402: /*
1.65 kristaps 1403: * XXX: undocumented: using two `Sh' macros in sequence has no
1404: * vspace between calls, only a newline.
1.64 kristaps 1405: */
1.1 kristaps 1406: switch (node->type) {
1.65 kristaps 1407: case (MDOC_BLOCK):
1408: if (node->prev && MDOC_Sh == node->prev->tok)
1409: if (NULL == node->prev->body->child)
1410: break;
1411: term_vspace(p);
1412: break;
1.1 kristaps 1413: case (MDOC_HEAD):
1.28 kristaps 1414: pair->flag |= ttypes[TTYPE_SECTION];
1.1 kristaps 1415: break;
1416: case (MDOC_BODY):
1417: p->offset = INDENT;
1418: break;
1419: default:
1420: break;
1421: }
1422: return(1);
1423: }
1424:
1425:
1426: /* ARGSUSED */
1427: static void
1428: termp_sh_post(DECL_ARGS)
1429: {
1430:
1431: switch (node->type) {
1432: case (MDOC_HEAD):
1433: term_newln(p);
1434: break;
1435: case (MDOC_BODY):
1436: term_newln(p);
1437: p->offset = 0;
1438: break;
1439: default:
1440: break;
1441: }
1442: }
1443:
1444:
1445: /* ARGSUSED */
1446: static int
1447: termp_op_pre(DECL_ARGS)
1448: {
1449:
1450: switch (node->type) {
1451: case (MDOC_BODY):
1452: term_word(p, "\\(lB");
1453: p->flags |= TERMP_NOSPACE;
1454: break;
1455: default:
1456: break;
1457: }
1458: return(1);
1459: }
1460:
1461:
1462: /* ARGSUSED */
1463: static int
1464: termp_bt_pre(DECL_ARGS)
1465: {
1466:
1467: term_word(p, "is currently in beta test.");
1468: return(1);
1469: }
1470:
1471:
1472: /* ARGSUSED */
1473: static void
1474: termp_lb_post(DECL_ARGS)
1475: {
1476:
1477: term_newln(p);
1478: }
1479:
1480:
1481: /* ARGSUSED */
1482: static int
1483: termp_ud_pre(DECL_ARGS)
1484: {
1485:
1486: term_word(p, "currently under development.");
1487: return(1);
1488: }
1489:
1490:
1491: /* ARGSUSED */
1492: static int
1493: termp_d1_pre(DECL_ARGS)
1494: {
1495:
1.4 kristaps 1496: if (MDOC_BLOCK != node->type)
1.1 kristaps 1497: return(1);
1498: term_newln(p);
1.29 kristaps 1499: p->offset += (INDENT + 1);
1.1 kristaps 1500: return(1);
1501: }
1502:
1503:
1504: /* ARGSUSED */
1505: static void
1506: termp_d1_post(DECL_ARGS)
1507: {
1508:
1.4 kristaps 1509: if (MDOC_BLOCK != node->type)
1.1 kristaps 1510: return;
1511: term_newln(p);
1512: }
1513:
1514:
1515: /* ARGSUSED */
1516: static int
1517: termp_aq_pre(DECL_ARGS)
1518: {
1519:
1520: if (MDOC_BODY != node->type)
1521: return(1);
1522: term_word(p, "\\(la");
1523: p->flags |= TERMP_NOSPACE;
1524: return(1);
1525: }
1526:
1527:
1528: /* ARGSUSED */
1529: static void
1530: termp_aq_post(DECL_ARGS)
1531: {
1532:
1533: if (MDOC_BODY != node->type)
1534: return;
1535: p->flags |= TERMP_NOSPACE;
1536: term_word(p, "\\(ra");
1537: }
1538:
1539:
1540: /* ARGSUSED */
1541: static int
1542: termp_ft_pre(DECL_ARGS)
1543: {
1544:
1545: if (SEC_SYNOPSIS == node->sec)
1546: if (node->prev && MDOC_Fo == node->prev->tok)
1547: term_vspace(p);
1.28 kristaps 1548: pair->flag |= ttypes[TTYPE_FUNC_TYPE];
1.1 kristaps 1549: return(1);
1550: }
1551:
1552:
1553: /* ARGSUSED */
1554: static void
1555: termp_ft_post(DECL_ARGS)
1556: {
1557:
1558: if (SEC_SYNOPSIS == node->sec)
1559: term_newln(p);
1560: }
1561:
1562:
1563: /* ARGSUSED */
1564: static int
1565: termp_fn_pre(DECL_ARGS)
1566: {
1567: const struct mdoc_node *n;
1568:
1.11 kristaps 1569: assert(node->child && MDOC_TEXT == node->child->type);
1.1 kristaps 1570:
1571: /* FIXME: can be "type funcname" "type varname"... */
1572:
1573: p->flags |= ttypes[TTYPE_FUNC_NAME];
1574: term_word(p, node->child->string);
1575: p->flags &= ~ttypes[TTYPE_FUNC_NAME];
1576:
1577: p->flags |= TERMP_NOSPACE;
1578: term_word(p, "(");
1579:
1580: for (n = node->child->next; n; n = n->next) {
1581: p->flags |= ttypes[TTYPE_FUNC_ARG];
1582: term_word(p, n->string);
1583: p->flags &= ~ttypes[TTYPE_FUNC_ARG];
1584: if (n->next)
1585: term_word(p, ",");
1586: }
1587:
1588: term_word(p, ")");
1589:
1590: if (SEC_SYNOPSIS == node->sec)
1591: term_word(p, ";");
1592:
1593: return(0);
1594: }
1595:
1596:
1597: /* ARGSUSED */
1598: static void
1599: termp_fn_post(DECL_ARGS)
1600: {
1601:
1602: if (node->sec == SEC_SYNOPSIS && node->next)
1603: term_vspace(p);
1604: }
1605:
1606:
1607: /* ARGSUSED */
1608: static int
1609: termp_sx_pre(DECL_ARGS)
1610: {
1611:
1.28 kristaps 1612: pair->flag |= ttypes[TTYPE_LINK];
1.1 kristaps 1613: return(1);
1614: }
1615:
1616:
1617: /* ARGSUSED */
1618: static int
1619: termp_fa_pre(DECL_ARGS)
1620: {
1621: struct mdoc_node *n;
1622:
1623: if (node->parent->tok != MDOC_Fo) {
1.28 kristaps 1624: pair->flag |= ttypes[TTYPE_FUNC_ARG];
1.1 kristaps 1625: return(1);
1626: }
1627:
1628: for (n = node->child; n; n = n->next) {
1629: p->flags |= ttypes[TTYPE_FUNC_ARG];
1630: term_word(p, n->string);
1631: p->flags &= ~ttypes[TTYPE_FUNC_ARG];
1632: if (n->next)
1633: term_word(p, ",");
1634: }
1635:
1636: if (node->child && node->next && node->next->tok == MDOC_Fa)
1637: term_word(p, ",");
1638:
1639: return(0);
1640: }
1641:
1642:
1643: /* ARGSUSED */
1644: static int
1645: termp_va_pre(DECL_ARGS)
1646: {
1647:
1.28 kristaps 1648: pair->flag |= ttypes[TTYPE_VAR_DECL];
1.1 kristaps 1649: return(1);
1650: }
1651:
1652:
1653: /* ARGSUSED */
1654: static int
1655: termp_bd_pre(DECL_ARGS)
1656: {
1.60 kristaps 1657: int i, type;
1.1 kristaps 1658:
1659: /*
1660: * This is fairly tricky due primarily to crappy documentation.
1661: * If -ragged or -filled are specified, the block does nothing
1662: * but change the indentation.
1663: *
1664: * If, on the other hand, -unfilled or -literal are specified,
1665: * then the game changes. Text is printed exactly as entered in
1666: * the display: if a macro line, a newline is appended to the
1667: * line. Blank lines are allowed.
1668: */
1669:
1.54 kristaps 1670: if (MDOC_BLOCK == node->type) {
1671: fmt_block_vspace(p, node, node);
1672: return(1);
1673: } else if (MDOC_BODY != node->type)
1.1 kristaps 1674: return(1);
1675:
1.60 kristaps 1676: assert(node->parent->args);
1.11 kristaps 1677:
1.60 kristaps 1678: for (type = -1, i = 0; -1 == type &&
1.1 kristaps 1679: i < (int)node->parent->args->argc; i++) {
1680: switch (node->parent->args->argv[i].arg) {
1681: case (MDOC_Ragged):
1682: /* FALLTHROUGH */
1683: case (MDOC_Filled):
1684: /* FALLTHROUGH */
1685: case (MDOC_Unfilled):
1686: /* FALLTHROUGH */
1687: case (MDOC_Literal):
1688: type = node->parent->args->argv[i].arg;
1689: break;
1690: default:
1691: break;
1692: }
1693: }
1.60 kristaps 1694:
1695: assert(type > -1);
1.1 kristaps 1696:
1697: i = arg_getattr(MDOC_Offset, node->parent);
1.60 kristaps 1698: if (-1 != i)
1.1 kristaps 1699: p->offset += arg_offset(&node->parent->args->argv[i]);
1700:
1701: switch (type) {
1702: case (MDOC_Literal):
1703: /* FALLTHROUGH */
1704: case (MDOC_Unfilled):
1705: break;
1706: default:
1707: return(1);
1708: }
1709:
1710: for (node = node->child; node; node = node->next) {
1.60 kristaps 1711: p->flags |= TERMP_NOSPACE;
1712: print_node(p, pair, meta, node);
1713: if (node->next)
1.1 kristaps 1714: term_flushln(p);
1715: }
1716:
1717: return(0);
1718: }
1719:
1720:
1721: /* ARGSUSED */
1722: static void
1723: termp_bd_post(DECL_ARGS)
1724: {
1725:
1726: if (MDOC_BODY != node->type)
1727: return;
1.60 kristaps 1728: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1729: term_flushln(p);
1730: }
1731:
1732:
1733: /* ARGSUSED */
1734: static int
1735: termp_qq_pre(DECL_ARGS)
1736: {
1737:
1738: if (MDOC_BODY != node->type)
1739: return(1);
1740: term_word(p, "\"");
1741: p->flags |= TERMP_NOSPACE;
1742: return(1);
1743: }
1744:
1745:
1746: /* ARGSUSED */
1747: static void
1748: termp_qq_post(DECL_ARGS)
1749: {
1750:
1751: if (MDOC_BODY != node->type)
1752: return;
1753: p->flags |= TERMP_NOSPACE;
1754: term_word(p, "\"");
1755: }
1756:
1757:
1758: /* ARGSUSED */
1759: static void
1760: termp_bx_post(DECL_ARGS)
1761: {
1762:
1763: if (node->child)
1764: p->flags |= TERMP_NOSPACE;
1765: term_word(p, "BSD");
1766: }
1767:
1768:
1769: /* ARGSUSED */
1770: static int
1.26 kristaps 1771: termp_xx_pre(DECL_ARGS)
1.1 kristaps 1772: {
1.26 kristaps 1773: const char *pp;
1.1 kristaps 1774:
1.26 kristaps 1775: pp = NULL;
1776: switch (node->tok) {
1777: case (MDOC_Bsx):
1778: pp = "BSDI BSD/OS";
1779: break;
1780: case (MDOC_Dx):
1781: pp = "DragonFlyBSD";
1782: break;
1783: case (MDOC_Fx):
1784: pp = "FreeBSD";
1785: break;
1786: case (MDOC_Nx):
1787: pp = "NetBSD";
1788: break;
1789: case (MDOC_Ox):
1790: pp = "OpenBSD";
1791: break;
1792: case (MDOC_Ux):
1793: pp = "UNIX";
1794: break;
1795: default:
1796: break;
1797: }
1.1 kristaps 1798:
1.26 kristaps 1799: assert(pp);
1800: term_word(p, pp);
1.1 kristaps 1801: return(1);
1802: }
1803:
1804:
1805: /* ARGSUSED */
1806: static int
1807: termp_sq_pre(DECL_ARGS)
1808: {
1809:
1810: if (MDOC_BODY != node->type)
1811: return(1);
1812: term_word(p, "\\(oq");
1813: p->flags |= TERMP_NOSPACE;
1814: return(1);
1815: }
1816:
1817:
1818: /* ARGSUSED */
1819: static void
1820: termp_sq_post(DECL_ARGS)
1821: {
1822:
1823: if (MDOC_BODY != node->type)
1824: return;
1825: p->flags |= TERMP_NOSPACE;
1826: term_word(p, "\\(aq");
1827: }
1828:
1829:
1830: /* ARGSUSED */
1831: static int
1.57 kristaps 1832: termp_pa_pre(DECL_ARGS)
1833: {
1834:
1835: pair->flag |= ttypes[TTYPE_FILE];
1836: return(1);
1837: }
1838:
1839:
1840: /* ARGSUSED */
1841: static int
1.1 kristaps 1842: termp_pf_pre(DECL_ARGS)
1843: {
1844:
1845: p->flags |= TERMP_IGNDELIM;
1846: return(1);
1847: }
1848:
1849:
1850: /* ARGSUSED */
1851: static void
1852: termp_pf_post(DECL_ARGS)
1853: {
1854:
1855: p->flags &= ~TERMP_IGNDELIM;
1856: p->flags |= TERMP_NOSPACE;
1857: }
1858:
1859:
1860: /* ARGSUSED */
1861: static int
1862: termp_ss_pre(DECL_ARGS)
1863: {
1864:
1865: switch (node->type) {
1866: case (MDOC_BLOCK):
1867: term_newln(p);
1868: if (node->prev)
1869: term_vspace(p);
1870: break;
1871: case (MDOC_HEAD):
1.28 kristaps 1872: pair->flag |= ttypes[TTYPE_SSECTION];
1.5 kristaps 1873: p->offset = HALFINDENT;
1.1 kristaps 1874: break;
1875: default:
1876: break;
1877: }
1878:
1879: return(1);
1880: }
1881:
1882:
1883: /* ARGSUSED */
1884: static void
1885: termp_ss_post(DECL_ARGS)
1886: {
1887:
1.29 kristaps 1888: if (MDOC_HEAD == node->type)
1.1 kristaps 1889: term_newln(p);
1890: }
1891:
1892:
1893: /* ARGSUSED */
1894: static int
1895: termp_em_pre(DECL_ARGS)
1896: {
1897:
1.28 kristaps 1898: pair->flag |= ttypes[TTYPE_EMPH];
1.1 kristaps 1899: return(1);
1900: }
1901:
1902:
1903: /* ARGSUSED */
1904: static int
1905: termp_cd_pre(DECL_ARGS)
1906: {
1907:
1.28 kristaps 1908: pair->flag |= ttypes[TTYPE_CONFIG];
1.1 kristaps 1909: term_newln(p);
1910: return(1);
1911: }
1912:
1913:
1914: /* ARGSUSED */
1915: static int
1916: termp_cm_pre(DECL_ARGS)
1917: {
1918:
1.28 kristaps 1919: pair->flag |= ttypes[TTYPE_CMD_FLAG];
1.1 kristaps 1920: return(1);
1921: }
1922:
1923:
1924: /* ARGSUSED */
1925: static int
1926: termp_ic_pre(DECL_ARGS)
1927: {
1928:
1.28 kristaps 1929: pair->flag |= ttypes[TTYPE_CMD];
1.1 kristaps 1930: return(1);
1931: }
1932:
1933:
1934: /* ARGSUSED */
1935: static int
1936: termp_in_pre(DECL_ARGS)
1937: {
1938:
1.28 kristaps 1939: pair->flag |= ttypes[TTYPE_INCLUDE];
1940: p->flags |= ttypes[TTYPE_INCLUDE];
1.22 kristaps 1941:
1942: if (SEC_SYNOPSIS == node->sec)
1943: term_word(p, "#include");
1944:
1.1 kristaps 1945: term_word(p, "<");
1946: p->flags |= TERMP_NOSPACE;
1947: return(1);
1948: }
1949:
1950:
1951: /* ARGSUSED */
1952: static void
1953: termp_in_post(DECL_ARGS)
1954: {
1955:
1.46 kristaps 1956: p->flags |= TERMP_NOSPACE | ttypes[TTYPE_INCLUDE];
1.1 kristaps 1957: term_word(p, ">");
1.46 kristaps 1958: p->flags &= ~ttypes[TTYPE_INCLUDE];
1.1 kristaps 1959:
1960: if (SEC_SYNOPSIS != node->sec)
1961: return;
1.22 kristaps 1962:
1963: term_newln(p);
1964: /*
1965: * XXX Not entirely correct. If `.In foo bar' is specified in
1966: * the SYNOPSIS section, then it produces a single break after
1967: * the <foo>; mandoc asserts a vertical space. Since this
1968: * construction is rarely used, I think it's fine.
1969: */
1.1 kristaps 1970: if (node->next && MDOC_In != node->next->tok)
1971: term_vspace(p);
1972: }
1973:
1974:
1975: /* ARGSUSED */
1976: static int
1.45 kristaps 1977: termp_sp_pre(DECL_ARGS)
1978: {
1979: int i, len;
1980:
1981: if (NULL == node->child) {
1982: term_vspace(p);
1983: return(0);
1984: }
1985:
1986: len = atoi(node->child->string);
1987: if (0 == len)
1988: term_newln(p);
1989: for (i = 0; i < len; i++)
1990: term_vspace(p);
1991:
1992: return(0);
1993: }
1994:
1995:
1996: /* ARGSUSED */
1997: static int
1.44 kristaps 1998: termp_br_pre(DECL_ARGS)
1999: {
2000:
2001: term_newln(p);
2002: return(1);
2003: }
2004:
2005:
2006: /* ARGSUSED */
2007: static int
1.1 kristaps 2008: termp_brq_pre(DECL_ARGS)
2009: {
2010:
2011: if (MDOC_BODY != node->type)
2012: return(1);
2013: term_word(p, "\\(lC");
2014: p->flags |= TERMP_NOSPACE;
2015: return(1);
2016: }
2017:
2018:
2019: /* ARGSUSED */
2020: static void
2021: termp_brq_post(DECL_ARGS)
2022: {
2023:
2024: if (MDOC_BODY != node->type)
2025: return;
2026: p->flags |= TERMP_NOSPACE;
2027: term_word(p, "\\(rC");
2028: }
2029:
2030:
2031: /* ARGSUSED */
2032: static int
2033: termp_bq_pre(DECL_ARGS)
2034: {
2035:
2036: if (MDOC_BODY != node->type)
2037: return(1);
2038: term_word(p, "\\(lB");
2039: p->flags |= TERMP_NOSPACE;
2040: return(1);
2041: }
2042:
2043:
2044: /* ARGSUSED */
2045: static void
2046: termp_bq_post(DECL_ARGS)
2047: {
2048:
2049: if (MDOC_BODY != node->type)
2050: return;
2051: p->flags |= TERMP_NOSPACE;
2052: term_word(p, "\\(rB");
2053: }
2054:
2055:
2056: /* ARGSUSED */
2057: static int
2058: termp_pq_pre(DECL_ARGS)
2059: {
2060:
2061: if (MDOC_BODY != node->type)
2062: return(1);
2063: term_word(p, "\\&(");
2064: p->flags |= TERMP_NOSPACE;
2065: return(1);
2066: }
2067:
2068:
2069: /* ARGSUSED */
2070: static void
2071: termp_pq_post(DECL_ARGS)
2072: {
2073:
2074: if (MDOC_BODY != node->type)
2075: return;
2076: term_word(p, ")");
2077: }
2078:
2079:
2080: /* ARGSUSED */
2081: static int
2082: termp_fo_pre(DECL_ARGS)
2083: {
2084: const struct mdoc_node *n;
2085:
2086: if (MDOC_BODY == node->type) {
1.33 kristaps 2087: p->flags |= TERMP_NOSPACE;
1.1 kristaps 2088: term_word(p, "(");
2089: p->flags |= TERMP_NOSPACE;
2090: return(1);
2091: } else if (MDOC_HEAD != node->type)
2092: return(1);
2093:
2094: p->flags |= ttypes[TTYPE_FUNC_NAME];
2095: for (n = node->child; n; n = n->next) {
1.11 kristaps 2096: assert(MDOC_TEXT == n->type);
1.1 kristaps 2097: term_word(p, n->string);
2098: }
2099: p->flags &= ~ttypes[TTYPE_FUNC_NAME];
2100:
2101: return(0);
2102: }
2103:
2104:
2105: /* ARGSUSED */
2106: static void
2107: termp_fo_post(DECL_ARGS)
2108: {
2109:
2110: if (MDOC_BODY != node->type)
2111: return;
2112: p->flags |= TERMP_NOSPACE;
2113: term_word(p, ")");
2114: p->flags |= TERMP_NOSPACE;
2115: term_word(p, ";");
2116: term_newln(p);
2117: }
2118:
2119:
2120: /* ARGSUSED */
2121: static int
2122: termp_bf_pre(DECL_ARGS)
2123: {
2124: const struct mdoc_node *n;
2125:
1.28 kristaps 2126: if (MDOC_HEAD == node->type)
1.1 kristaps 2127: return(0);
1.28 kristaps 2128: else if (MDOC_BLOCK != node->type)
1.1 kristaps 2129: return(1);
2130:
2131: if (NULL == (n = node->head->child)) {
2132: if (arg_hasattr(MDOC_Emphasis, node))
1.28 kristaps 2133: pair->flag |= ttypes[TTYPE_EMPH];
1.1 kristaps 2134: else if (arg_hasattr(MDOC_Symbolic, node))
1.28 kristaps 2135: pair->flag |= ttypes[TTYPE_SYMB];
1.1 kristaps 2136:
2137: return(1);
2138: }
2139:
1.11 kristaps 2140: assert(MDOC_TEXT == n->type);
1.1 kristaps 2141: if (0 == strcmp("Em", n->string))
1.28 kristaps 2142: pair->flag |= ttypes[TTYPE_EMPH];
1.1 kristaps 2143: else if (0 == strcmp("Sy", n->string))
1.28 kristaps 2144: pair->flag |= ttypes[TTYPE_SYMB];
1.1 kristaps 2145:
2146: return(1);
2147: }
2148:
2149:
2150: /* ARGSUSED */
2151: static int
2152: termp_sy_pre(DECL_ARGS)
2153: {
2154:
1.28 kristaps 2155: pair->flag |= ttypes[TTYPE_SYMB];
1.1 kristaps 2156: return(1);
2157: }
2158:
2159:
2160: /* ARGSUSED */
2161: static int
2162: termp_ms_pre(DECL_ARGS)
2163: {
2164:
1.28 kristaps 2165: pair->flag |= ttypes[TTYPE_SYMBOL];
1.1 kristaps 2166: return(1);
2167: }
2168:
2169:
2170:
2171: /* ARGSUSED */
2172: static int
2173: termp_sm_pre(DECL_ARGS)
2174: {
2175:
1.11 kristaps 2176: assert(node->child && MDOC_TEXT == node->child->type);
1.1 kristaps 2177: if (0 == strcmp("on", node->child->string)) {
2178: p->flags &= ~TERMP_NONOSPACE;
2179: p->flags &= ~TERMP_NOSPACE;
2180: } else
2181: p->flags |= TERMP_NONOSPACE;
2182:
2183: return(0);
2184: }
2185:
2186:
2187: /* ARGSUSED */
2188: static int
2189: termp_ap_pre(DECL_ARGS)
2190: {
2191:
2192: p->flags |= TERMP_NOSPACE;
2193: term_word(p, "\\(aq");
2194: p->flags |= TERMP_NOSPACE;
2195: return(1);
2196: }
2197:
2198:
2199: /* ARGSUSED */
2200: static int
2201: termp__j_pre(DECL_ARGS)
2202: {
2203:
1.28 kristaps 2204: pair->flag |= ttypes[TTYPE_REF_JOURNAL];
1.1 kristaps 2205: return(1);
2206: }
2207:
2208:
2209: /* ARGSUSED */
2210: static int
2211: termp__t_pre(DECL_ARGS)
2212: {
2213:
1.56 kristaps 2214: pair->flag |= ttypes[TTYPE_REF_TITLE];
1.1 kristaps 2215: return(1);
2216: }
2217:
2218:
2219: /* ARGSUSED */
2220: static void
2221: termp____post(DECL_ARGS)
2222: {
2223:
2224: p->flags |= TERMP_NOSPACE;
2225: term_word(p, node->next ? "," : ".");
2226: }
2227:
2228:
2229: /* ARGSUSED */
2230: static int
2231: termp_lk_pre(DECL_ARGS)
2232: {
2233: const struct mdoc_node *n;
2234:
1.11 kristaps 2235: assert(node->child);
2236: n = node->child;
1.1 kristaps 2237:
1.12 kristaps 2238: if (NULL == n->next) {
1.28 kristaps 2239: pair->flag |= ttypes[TTYPE_LINK_ANCHOR];
1.12 kristaps 2240: return(1);
2241: }
2242:
1.1 kristaps 2243: p->flags |= ttypes[TTYPE_LINK_ANCHOR];
2244: term_word(p, n->string);
2245: p->flags |= TERMP_NOSPACE;
2246: term_word(p, ":");
1.12 kristaps 2247: p->flags &= ~ttypes[TTYPE_LINK_ANCHOR];
1.1 kristaps 2248:
2249: p->flags |= ttypes[TTYPE_LINK_TEXT];
1.12 kristaps 2250: for (n = n->next; n; n = n->next)
1.1 kristaps 2251: term_word(p, n->string);
1.12 kristaps 2252:
1.1 kristaps 2253: p->flags &= ~ttypes[TTYPE_LINK_TEXT];
2254: return(0);
2255: }
2256:
2257:
2258: /* ARGSUSED */
2259: static int
2260: termp_mt_pre(DECL_ARGS)
2261: {
2262:
1.28 kristaps 2263: pair->flag |= ttypes[TTYPE_LINK_ANCHOR];
1.1 kristaps 2264: return(1);
2265: }
2266:
2267:
CVSweb