Annotation of mandoc/mdoc_html.c, Revision 1.150
1.150 ! kristaps 1: /* $Id: mdoc_html.c,v 1.149 2011/01/29 14:49:44 kristaps Exp $ */
1.1 kristaps 2: /*
1.96 schwarze 3: * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
1.1 kristaps 4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
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.
16: */
1.52 kristaps 17: #ifdef HAVE_CONFIG_H
18: #include "config.h"
19: #endif
20:
1.1 kristaps 21: #include <sys/types.h>
22:
23: #include <assert.h>
24: #include <ctype.h>
25: #include <stdio.h>
26: #include <stdlib.h>
27: #include <string.h>
28: #include <unistd.h>
29:
1.65 kristaps 30: #include "mandoc.h"
1.23 kristaps 31: #include "out.h"
1.1 kristaps 32: #include "html.h"
33: #include "mdoc.h"
1.29 kristaps 34: #include "main.h"
1.1 kristaps 35:
36: #define INDENT 5
37: #define HALFINDENT 3
38:
39: #define MDOC_ARGS const struct mdoc_meta *m, \
40: const struct mdoc_node *n, \
41: struct html *h
42:
1.52 kristaps 43: #ifndef MIN
44: #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
45: #endif
46:
1.1 kristaps 47: struct htmlmdoc {
48: int (*pre)(MDOC_ARGS);
49: void (*post)(MDOC_ARGS);
50: };
51:
52: static void print_mdoc(MDOC_ARGS);
53: static void print_mdoc_head(MDOC_ARGS);
54: static void print_mdoc_node(MDOC_ARGS);
55: static void print_mdoc_nodelist(MDOC_ARGS);
1.78 kristaps 56: static void synopsis_pre(struct html *,
57: const struct mdoc_node *);
1.1 kristaps 58:
1.23 kristaps 59: static void a2width(const char *, struct roffsu *);
60: static void a2offs(const char *, struct roffsu *);
1.27 kristaps 61:
1.1 kristaps 62: static void mdoc_root_post(MDOC_ARGS);
63: static int mdoc_root_pre(MDOC_ARGS);
64:
1.10 kristaps 65: static void mdoc__x_post(MDOC_ARGS);
66: static int mdoc__x_pre(MDOC_ARGS);
1.1 kristaps 67: static int mdoc_ad_pre(MDOC_ARGS);
68: static int mdoc_an_pre(MDOC_ARGS);
1.5 kristaps 69: static int mdoc_ap_pre(MDOC_ARGS);
1.1 kristaps 70: static int mdoc_ar_pre(MDOC_ARGS);
71: static int mdoc_bd_pre(MDOC_ARGS);
1.5 kristaps 72: static int mdoc_bf_pre(MDOC_ARGS);
1.94 kristaps 73: static void mdoc_bk_post(MDOC_ARGS);
74: static int mdoc_bk_pre(MDOC_ARGS);
1.1 kristaps 75: static int mdoc_bl_pre(MDOC_ARGS);
1.6 kristaps 76: static int mdoc_bt_pre(MDOC_ARGS);
1.4 kristaps 77: static int mdoc_bx_pre(MDOC_ARGS);
1.1 kristaps 78: static int mdoc_cd_pre(MDOC_ARGS);
79: static int mdoc_d1_pre(MDOC_ARGS);
80: static int mdoc_dv_pre(MDOC_ARGS);
81: static int mdoc_fa_pre(MDOC_ARGS);
82: static int mdoc_fd_pre(MDOC_ARGS);
83: static int mdoc_fl_pre(MDOC_ARGS);
84: static int mdoc_fn_pre(MDOC_ARGS);
85: static int mdoc_ft_pre(MDOC_ARGS);
86: static int mdoc_em_pre(MDOC_ARGS);
87: static int mdoc_er_pre(MDOC_ARGS);
88: static int mdoc_ev_pre(MDOC_ARGS);
89: static int mdoc_ex_pre(MDOC_ARGS);
1.4 kristaps 90: static void mdoc_fo_post(MDOC_ARGS);
91: static int mdoc_fo_pre(MDOC_ARGS);
92: static int mdoc_ic_pre(MDOC_ARGS);
1.110 schwarze 93: static int mdoc_igndelim_pre(MDOC_ARGS);
1.4 kristaps 94: static int mdoc_in_pre(MDOC_ARGS);
1.1 kristaps 95: static int mdoc_it_pre(MDOC_ARGS);
1.6 kristaps 96: static int mdoc_lb_pre(MDOC_ARGS);
97: static int mdoc_li_pre(MDOC_ARGS);
1.2 kristaps 98: static int mdoc_lk_pre(MDOC_ARGS);
99: static int mdoc_mt_pre(MDOC_ARGS);
1.5 kristaps 100: static int mdoc_ms_pre(MDOC_ARGS);
1.1 kristaps 101: static int mdoc_nd_pre(MDOC_ARGS);
102: static int mdoc_nm_pre(MDOC_ARGS);
103: static int mdoc_ns_pre(MDOC_ARGS);
104: static int mdoc_pa_pre(MDOC_ARGS);
1.5 kristaps 105: static void mdoc_pf_post(MDOC_ARGS);
1.120 kristaps 106: static int mdoc_pp_pre(MDOC_ARGS);
1.107 kristaps 107: static void mdoc_quote_post(MDOC_ARGS);
108: static int mdoc_quote_pre(MDOC_ARGS);
1.5 kristaps 109: static int mdoc_rs_pre(MDOC_ARGS);
1.4 kristaps 110: static int mdoc_rv_pre(MDOC_ARGS);
1.1 kristaps 111: static int mdoc_sh_pre(MDOC_ARGS);
1.99 kristaps 112: static int mdoc_sm_pre(MDOC_ARGS);
1.1 kristaps 113: static int mdoc_sp_pre(MDOC_ARGS);
114: static int mdoc_ss_pre(MDOC_ARGS);
115: static int mdoc_sx_pre(MDOC_ARGS);
1.6 kristaps 116: static int mdoc_sy_pre(MDOC_ARGS);
117: static int mdoc_ud_pre(MDOC_ARGS);
1.4 kristaps 118: static int mdoc_va_pre(MDOC_ARGS);
1.1 kristaps 119: static int mdoc_vt_pre(MDOC_ARGS);
120: static int mdoc_xr_pre(MDOC_ARGS);
121: static int mdoc_xx_pre(MDOC_ARGS);
122:
123: static const struct htmlmdoc mdocs[MDOC_MAX] = {
1.5 kristaps 124: {mdoc_ap_pre, NULL}, /* Ap */
1.1 kristaps 125: {NULL, NULL}, /* Dd */
126: {NULL, NULL}, /* Dt */
127: {NULL, NULL}, /* Os */
128: {mdoc_sh_pre, NULL }, /* Sh */
129: {mdoc_ss_pre, NULL }, /* Ss */
1.120 kristaps 130: {mdoc_pp_pre, NULL}, /* Pp */
1.1 kristaps 131: {mdoc_d1_pre, NULL}, /* D1 */
132: {mdoc_d1_pre, NULL}, /* Dl */
133: {mdoc_bd_pre, NULL}, /* Bd */
134: {NULL, NULL}, /* Ed */
1.115 kristaps 135: {mdoc_bl_pre, NULL}, /* Bl */
1.1 kristaps 136: {NULL, NULL}, /* El */
137: {mdoc_it_pre, NULL}, /* It */
138: {mdoc_ad_pre, NULL}, /* Ad */
139: {mdoc_an_pre, NULL}, /* An */
140: {mdoc_ar_pre, NULL}, /* Ar */
141: {mdoc_cd_pre, NULL}, /* Cd */
142: {mdoc_fl_pre, NULL}, /* Cm */
143: {mdoc_dv_pre, NULL}, /* Dv */
144: {mdoc_er_pre, NULL}, /* Er */
145: {mdoc_ev_pre, NULL}, /* Ev */
146: {mdoc_ex_pre, NULL}, /* Ex */
147: {mdoc_fa_pre, NULL}, /* Fa */
1.78 kristaps 148: {mdoc_fd_pre, NULL}, /* Fd */
1.1 kristaps 149: {mdoc_fl_pre, NULL}, /* Fl */
150: {mdoc_fn_pre, NULL}, /* Fn */
151: {mdoc_ft_pre, NULL}, /* Ft */
1.4 kristaps 152: {mdoc_ic_pre, NULL}, /* Ic */
153: {mdoc_in_pre, NULL}, /* In */
1.6 kristaps 154: {mdoc_li_pre, NULL}, /* Li */
1.1 kristaps 155: {mdoc_nd_pre, NULL}, /* Nd */
156: {mdoc_nm_pre, NULL}, /* Nm */
1.107 kristaps 157: {mdoc_quote_pre, mdoc_quote_post}, /* Op */
1.1 kristaps 158: {NULL, NULL}, /* Ot */
159: {mdoc_pa_pre, NULL}, /* Pa */
1.4 kristaps 160: {mdoc_rv_pre, NULL}, /* Rv */
1.1 kristaps 161: {NULL, NULL}, /* St */
1.4 kristaps 162: {mdoc_va_pre, NULL}, /* Va */
1.1 kristaps 163: {mdoc_vt_pre, NULL}, /* Vt */
164: {mdoc_xr_pre, NULL}, /* Xr */
1.10 kristaps 165: {mdoc__x_pre, mdoc__x_post}, /* %A */
166: {mdoc__x_pre, mdoc__x_post}, /* %B */
167: {mdoc__x_pre, mdoc__x_post}, /* %D */
168: {mdoc__x_pre, mdoc__x_post}, /* %I */
169: {mdoc__x_pre, mdoc__x_post}, /* %J */
170: {mdoc__x_pre, mdoc__x_post}, /* %N */
171: {mdoc__x_pre, mdoc__x_post}, /* %O */
172: {mdoc__x_pre, mdoc__x_post}, /* %P */
173: {mdoc__x_pre, mdoc__x_post}, /* %R */
174: {mdoc__x_pre, mdoc__x_post}, /* %T */
175: {mdoc__x_pre, mdoc__x_post}, /* %V */
1.1 kristaps 176: {NULL, NULL}, /* Ac */
1.107 kristaps 177: {mdoc_quote_pre, mdoc_quote_post}, /* Ao */
178: {mdoc_quote_pre, mdoc_quote_post}, /* Aq */
1.1 kristaps 179: {NULL, NULL}, /* At */
180: {NULL, NULL}, /* Bc */
1.5 kristaps 181: {mdoc_bf_pre, NULL}, /* Bf */
1.107 kristaps 182: {mdoc_quote_pre, mdoc_quote_post}, /* Bo */
183: {mdoc_quote_pre, mdoc_quote_post}, /* Bq */
1.1 kristaps 184: {mdoc_xx_pre, NULL}, /* Bsx */
1.4 kristaps 185: {mdoc_bx_pre, NULL}, /* Bx */
1.1 kristaps 186: {NULL, NULL}, /* Db */
187: {NULL, NULL}, /* Dc */
1.107 kristaps 188: {mdoc_quote_pre, mdoc_quote_post}, /* Do */
189: {mdoc_quote_pre, mdoc_quote_post}, /* Dq */
1.55 kristaps 190: {NULL, NULL}, /* Ec */ /* FIXME: no space */
1.1 kristaps 191: {NULL, NULL}, /* Ef */
192: {mdoc_em_pre, NULL}, /* Em */
193: {NULL, NULL}, /* Eo */
194: {mdoc_xx_pre, NULL}, /* Fx */
1.98 kristaps 195: {mdoc_ms_pre, NULL}, /* Ms */
1.110 schwarze 196: {mdoc_igndelim_pre, NULL}, /* No */
1.1 kristaps 197: {mdoc_ns_pre, NULL}, /* Ns */
198: {mdoc_xx_pre, NULL}, /* Nx */
199: {mdoc_xx_pre, NULL}, /* Ox */
200: {NULL, NULL}, /* Pc */
1.110 schwarze 201: {mdoc_igndelim_pre, mdoc_pf_post}, /* Pf */
1.107 kristaps 202: {mdoc_quote_pre, mdoc_quote_post}, /* Po */
203: {mdoc_quote_pre, mdoc_quote_post}, /* Pq */
1.1 kristaps 204: {NULL, NULL}, /* Qc */
1.107 kristaps 205: {mdoc_quote_pre, mdoc_quote_post}, /* Ql */
206: {mdoc_quote_pre, mdoc_quote_post}, /* Qo */
207: {mdoc_quote_pre, mdoc_quote_post}, /* Qq */
1.1 kristaps 208: {NULL, NULL}, /* Re */
1.5 kristaps 209: {mdoc_rs_pre, NULL}, /* Rs */
1.1 kristaps 210: {NULL, NULL}, /* Sc */
1.107 kristaps 211: {mdoc_quote_pre, mdoc_quote_post}, /* So */
212: {mdoc_quote_pre, mdoc_quote_post}, /* Sq */
1.99 kristaps 213: {mdoc_sm_pre, NULL}, /* Sm */
1.1 kristaps 214: {mdoc_sx_pre, NULL}, /* Sx */
1.6 kristaps 215: {mdoc_sy_pre, NULL}, /* Sy */
1.1 kristaps 216: {NULL, NULL}, /* Tn */
217: {mdoc_xx_pre, NULL}, /* Ux */
218: {NULL, NULL}, /* Xc */
219: {NULL, NULL}, /* Xo */
1.4 kristaps 220: {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
1.1 kristaps 221: {NULL, NULL}, /* Fc */
1.107 kristaps 222: {mdoc_quote_pre, mdoc_quote_post}, /* Oo */
1.1 kristaps 223: {NULL, NULL}, /* Oc */
1.94 kristaps 224: {mdoc_bk_pre, mdoc_bk_post}, /* Bk */
1.1 kristaps 225: {NULL, NULL}, /* Ek */
1.6 kristaps 226: {mdoc_bt_pre, NULL}, /* Bt */
1.1 kristaps 227: {NULL, NULL}, /* Hf */
228: {NULL, NULL}, /* Fr */
1.6 kristaps 229: {mdoc_ud_pre, NULL}, /* Ud */
230: {mdoc_lb_pre, NULL}, /* Lb */
1.120 kristaps 231: {mdoc_pp_pre, NULL}, /* Lp */
1.2 kristaps 232: {mdoc_lk_pre, NULL}, /* Lk */
233: {mdoc_mt_pre, NULL}, /* Mt */
1.107 kristaps 234: {mdoc_quote_pre, mdoc_quote_post}, /* Brq */
235: {mdoc_quote_pre, mdoc_quote_post}, /* Bro */
1.1 kristaps 236: {NULL, NULL}, /* Brc */
1.10 kristaps 237: {mdoc__x_pre, mdoc__x_post}, /* %C */
1.2 kristaps 238: {NULL, NULL}, /* Es */ /* TODO */
239: {NULL, NULL}, /* En */ /* TODO */
1.1 kristaps 240: {mdoc_xx_pre, NULL}, /* Dx */
1.10 kristaps 241: {mdoc__x_pre, mdoc__x_post}, /* %Q */
1.1 kristaps 242: {mdoc_sp_pre, NULL}, /* br */
243: {mdoc_sp_pre, NULL}, /* sp */
1.37 kristaps 244: {mdoc__x_pre, mdoc__x_post}, /* %U */
1.71 kristaps 245: {NULL, NULL}, /* Ta */
1.1 kristaps 246: };
247:
1.115 kristaps 248: static const char * const lists[LIST_MAX] = {
249: NULL,
1.116 kristaps 250: "list-bul",
251: "list-col",
1.115 kristaps 252: "list-dash",
253: "list-diag",
254: "list-enum",
255: "list-hang",
1.116 kristaps 256: "list-hyph",
1.115 kristaps 257: "list-inset",
258: "list-item",
259: "list-ohang",
260: "list-tag"
261: };
1.1 kristaps 262:
263: void
264: html_mdoc(void *arg, const struct mdoc *m)
265: {
266: struct html *h;
267: struct tag *t;
268:
269: h = (struct html *)arg;
270:
1.53 kristaps 271: print_gen_decls(h);
1.1 kristaps 272: t = print_otag(h, TAG_HTML, 0, NULL);
273: print_mdoc(mdoc_meta(m), mdoc_node(m), h);
274: print_tagq(h, t);
275:
276: printf("\n");
277: }
278:
279:
1.23 kristaps 280: /*
281: * Calculate the scaling unit passed in a `-width' argument. This uses
282: * either a native scaling unit (e.g., 1i, 2m) or the string length of
283: * the value.
284: */
285: static void
286: a2width(const char *p, struct roffsu *su)
1.1 kristaps 287: {
288:
1.32 kristaps 289: if ( ! a2roffsu(p, su, SCALE_MAX)) {
1.130 kristaps 290: su->unit = SCALE_BU;
1.32 kristaps 291: su->scale = (int)strlen(p);
292: }
1.1 kristaps 293: }
294:
295:
1.23 kristaps 296: /*
1.78 kristaps 297: * See the same function in mdoc_term.c for documentation.
298: */
299: static void
300: synopsis_pre(struct html *h, const struct mdoc_node *n)
301: {
302:
1.87 kristaps 303: if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
1.78 kristaps 304: return;
305:
306: if (n->prev->tok == n->tok &&
307: MDOC_Fo != n->tok &&
308: MDOC_Ft != n->tok &&
309: MDOC_Fn != n->tok) {
1.125 kristaps 310: print_otag(h, TAG_BR, 0, NULL);
1.78 kristaps 311: return;
312: }
313:
314: switch (n->prev->tok) {
315: case (MDOC_Fd):
316: /* FALLTHROUGH */
317: case (MDOC_Fn):
318: /* FALLTHROUGH */
319: case (MDOC_Fo):
320: /* FALLTHROUGH */
321: case (MDOC_In):
322: /* FALLTHROUGH */
323: case (MDOC_Vt):
1.125 kristaps 324: print_otag(h, TAG_P, 0, NULL);
1.78 kristaps 325: break;
326: case (MDOC_Ft):
327: if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
1.125 kristaps 328: print_otag(h, TAG_P, 0, NULL);
1.78 kristaps 329: break;
330: }
331: /* FALLTHROUGH */
332: default:
1.125 kristaps 333: print_otag(h, TAG_BR, 0, NULL);
1.78 kristaps 334: break;
335: }
336: }
337:
338:
339: /*
1.23 kristaps 340: * Calculate the scaling unit passed in an `-offset' argument. This
341: * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
342: * predefined strings (indent, etc.), or the string length of the value.
343: */
344: static void
345: a2offs(const char *p, struct roffsu *su)
1.1 kristaps 346: {
347:
1.31 kristaps 348: /* FIXME: "right"? */
349:
1.1 kristaps 350: if (0 == strcmp(p, "left"))
1.23 kristaps 351: SCALE_HS_INIT(su, 0);
352: else if (0 == strcmp(p, "indent"))
353: SCALE_HS_INIT(su, INDENT);
354: else if (0 == strcmp(p, "indent-two"))
355: SCALE_HS_INIT(su, INDENT * 2);
1.32 kristaps 356: else if ( ! a2roffsu(p, su, SCALE_MAX)) {
1.130 kristaps 357: su->unit = SCALE_BU;
1.24 kristaps 358: su->scale = (int)strlen(p);
359: }
1.1 kristaps 360: }
361:
362:
363: static void
364: print_mdoc(MDOC_ARGS)
365: {
366: struct tag *t;
367:
368: t = print_otag(h, TAG_HEAD, 0, NULL);
369: print_mdoc_head(m, n, h);
370: print_tagq(h, t);
371:
372: t = print_otag(h, TAG_BODY, 0, NULL);
373: print_mdoc_nodelist(m, n, h);
374: print_tagq(h, t);
375: }
376:
377:
378: /* ARGSUSED */
379: static void
380: print_mdoc_head(MDOC_ARGS)
381: {
382:
383: print_gen_head(h);
1.20 kristaps 384: bufinit(h);
1.63 kristaps 385: buffmt(h, "%s(%s)", m->title, m->msec);
1.1 kristaps 386:
387: if (m->arch) {
1.20 kristaps 388: bufcat(h, " (");
389: bufcat(h, m->arch);
390: bufcat(h, ")");
1.1 kristaps 391: }
392:
393: print_otag(h, TAG_TITLE, 0, NULL);
1.20 kristaps 394: print_text(h, h->buf);
1.1 kristaps 395: }
396:
397:
398: static void
399: print_mdoc_nodelist(MDOC_ARGS)
400: {
401:
402: print_mdoc_node(m, n, h);
403: if (n->next)
404: print_mdoc_nodelist(m, n->next, h);
405: }
406:
407:
408: static void
409: print_mdoc_node(MDOC_ARGS)
410: {
411: int child;
412: struct tag *t;
413:
414: child = 1;
1.39 kristaps 415: t = h->tags.head;
1.1 kristaps 416:
1.16 kristaps 417: bufinit(h);
1.1 kristaps 418: switch (n->type) {
419: case (MDOC_ROOT):
420: child = mdoc_root_pre(m, n, h);
421: break;
422: case (MDOC_TEXT):
1.144 kristaps 423: /* No tables in this mode... */
424: assert(NULL == h->tblt);
1.149 kristaps 425:
426: /*
427: * Make sure that if we're in a literal mode already
428: * (i.e., within a <PRE>) don't print the newline.
429: */
1.143 kristaps 430: if (' ' == *n->string && MDOC_LINE & n->flags)
1.149 kristaps 431: if ( ! (HTML_LITERAL & h->flags))
432: print_otag(h, TAG_BR, 0, NULL);
1.1 kristaps 433: print_text(h, n->string);
1.140 kristaps 434: return;
435: case (MDOC_TBL):
1.144 kristaps 436: /*
437: * This will take care of initialising all of the table
438: * state data for the first table, then tearing it down
439: * for the last one.
440: */
1.141 kristaps 441: print_tbl(h, n->span);
1.144 kristaps 442: return;
1.1 kristaps 443: default:
1.144 kristaps 444: /*
445: * Close out the current table, if it's open, and unset
446: * the "meta" table state. This will be reopened on the
447: * next table element.
448: */
449: if (h->tblt) {
450: print_tblclose(h);
451: t = h->tags.head;
452: }
453:
454: assert(NULL == h->tblt);
1.89 kristaps 455: if (mdocs[n->tok].pre && ENDBODY_NOT == n->end)
1.1 kristaps 456: child = (*mdocs[n->tok].pre)(m, n, h);
457: break;
458: }
459:
1.94 kristaps 460: if (HTML_KEEP & h->flags) {
461: if (n->prev && n->prev->line != n->line) {
462: h->flags &= ~HTML_KEEP;
463: h->flags |= HTML_PREKEEP;
464: } else if (NULL == n->prev) {
465: if (n->parent && n->parent->line != n->line) {
466: h->flags &= ~HTML_KEEP;
467: h->flags |= HTML_PREKEEP;
468: }
469: }
470: }
471:
1.1 kristaps 472: if (child && n->child)
473: print_mdoc_nodelist(m, n->child, h);
474:
475: print_stagq(h, t);
476:
1.16 kristaps 477: bufinit(h);
1.1 kristaps 478: switch (n->type) {
479: case (MDOC_ROOT):
480: mdoc_root_post(m, n, h);
481: break;
482: default:
1.89 kristaps 483: if (mdocs[n->tok].post && ENDBODY_NOT == n->end)
1.1 kristaps 484: (*mdocs[n->tok].post)(m, n, h);
485: break;
486: }
487: }
488:
489: /* ARGSUSED */
490: static void
491: mdoc_root_post(MDOC_ARGS)
492: {
1.132 kristaps 493: struct htmlpair tag[3];
1.1 kristaps 494: struct tag *t, *tt;
1.36 kristaps 495: char b[DATESIZ];
496:
497: time2a(m->date, b, DATESIZ);
1.1 kristaps 498:
1.132 kristaps 499: PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
500: PAIR_CLASS_INIT(&tag[1], "foot");
501: if (NULL == h->style) {
1.135 kristaps 502: PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
503: t = print_otag(h, TAG_TABLE, 3, tag);
1.132 kristaps 504: PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
505: print_otag(h, TAG_COL, 1, tag);
506: print_otag(h, TAG_COL, 1, tag);
507: } else
508: t = print_otag(h, TAG_TABLE, 2, tag);
509:
510: t = print_otag(h, TAG_TBODY, 0, NULL);
1.40 kristaps 511:
1.1 kristaps 512: tt = print_otag(h, TAG_TR, 0, NULL);
513:
1.125 kristaps 514: PAIR_CLASS_INIT(&tag[0], "foot-date");
1.1 kristaps 515: print_otag(h, TAG_TD, 1, tag);
1.125 kristaps 516:
1.1 kristaps 517: print_text(h, b);
518: print_stagq(h, tt);
519:
1.125 kristaps 520: PAIR_CLASS_INIT(&tag[0], "foot-os");
1.132 kristaps 521: if (NULL == h->style) {
522: PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
523: print_otag(h, TAG_TD, 2, tag);
524: } else
525: print_otag(h, TAG_TD, 1, tag);
1.125 kristaps 526:
1.1 kristaps 527: print_text(h, m->os);
528: print_tagq(h, t);
529: }
530:
531:
532: /* ARGSUSED */
533: static int
534: mdoc_root_pre(MDOC_ARGS)
535: {
1.40 kristaps 536: struct htmlpair tag[3];
1.1 kristaps 537: struct tag *t, *tt;
538: char b[BUFSIZ], title[BUFSIZ];
539:
1.119 kristaps 540: strlcpy(b, m->vol, BUFSIZ);
1.1 kristaps 541:
542: if (m->arch) {
1.119 kristaps 543: strlcat(b, " (", BUFSIZ);
544: strlcat(b, m->arch, BUFSIZ);
545: strlcat(b, ")", BUFSIZ);
1.1 kristaps 546: }
547:
1.119 kristaps 548: snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
1.23 kristaps 549:
1.132 kristaps 550: PAIR_SUMMARY_INIT(&tag[0], "Document Header");
551: PAIR_CLASS_INIT(&tag[1], "head");
552: if (NULL == h->style) {
553: PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
554: t = print_otag(h, TAG_TABLE, 3, tag);
555: PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
556: print_otag(h, TAG_COL, 1, tag);
557: print_otag(h, TAG_COL, 1, tag);
558: print_otag(h, TAG_COL, 1, tag);
559: } else
560: t = print_otag(h, TAG_TABLE, 2, tag);
561:
562: print_otag(h, TAG_TBODY, 0, NULL);
1.40 kristaps 563:
1.1 kristaps 564: tt = print_otag(h, TAG_TR, 0, NULL);
565:
1.125 kristaps 566: PAIR_CLASS_INIT(&tag[0], "head-ltitle");
1.1 kristaps 567: print_otag(h, TAG_TD, 1, tag);
1.125 kristaps 568:
1.2 kristaps 569: print_text(h, title);
1.1 kristaps 570: print_stagq(h, tt);
571:
1.125 kristaps 572: PAIR_CLASS_INIT(&tag[0], "head-vol");
1.132 kristaps 573: if (NULL == h->style) {
574: PAIR_INIT(&tag[1], ATTR_ALIGN, "center");
575: print_otag(h, TAG_TD, 2, tag);
576: } else
577: print_otag(h, TAG_TD, 1, tag);
1.125 kristaps 578:
1.2 kristaps 579: print_text(h, b);
1.1 kristaps 580: print_stagq(h, tt);
581:
1.125 kristaps 582: PAIR_CLASS_INIT(&tag[0], "head-rtitle");
1.132 kristaps 583: if (NULL == h->style) {
584: PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
585: print_otag(h, TAG_TD, 2, tag);
586: } else
587: print_otag(h, TAG_TD, 1, tag);
1.125 kristaps 588:
1.2 kristaps 589: print_text(h, title);
1.1 kristaps 590: print_tagq(h, t);
591: return(1);
592: }
593:
594:
595: /* ARGSUSED */
596: static int
597: mdoc_sh_pre(MDOC_ARGS)
598: {
1.123 kristaps 599: struct htmlpair tag;
600: char buf[BUFSIZ];
601:
602: if (MDOC_BLOCK == n->type) {
603: PAIR_CLASS_INIT(&tag, "section");
604: print_otag(h, TAG_DIV, 1, &tag);
1.1 kristaps 605: return(1);
1.123 kristaps 606: } else if (MDOC_BODY == n->type)
1.1 kristaps 607: return(1);
608:
1.42 kristaps 609: buf[0] = '\0';
1.123 kristaps 610: for (n = n->child; n; n = n->next) {
611: html_idcat(buf, n->string, BUFSIZ);
612: if (n->next)
1.42 kristaps 613: html_idcat(buf, " ", BUFSIZ);
1.21 kristaps 614: }
615:
1.123 kristaps 616: PAIR_ID_INIT(&tag, buf);
617: print_otag(h, TAG_H1, 1, &tag);
1.1 kristaps 618: return(1);
619: }
620:
621:
622: /* ARGSUSED */
623: static int
624: mdoc_ss_pre(MDOC_ARGS)
625: {
1.123 kristaps 626: struct htmlpair tag;
627: char buf[BUFSIZ];
1.1 kristaps 628:
1.123 kristaps 629: if (MDOC_BLOCK == n->type) {
630: PAIR_CLASS_INIT(&tag, "subsection");
631: print_otag(h, TAG_DIV, 1, &tag);
1.1 kristaps 632: return(1);
1.123 kristaps 633: } else if (MDOC_BODY == n->type)
1.1 kristaps 634: return(1);
1.23 kristaps 635:
1.42 kristaps 636: buf[0] = '\0';
1.123 kristaps 637: for (n = n->child; n; n = n->next) {
638: html_idcat(buf, n->string, BUFSIZ);
639: if (n->next)
1.42 kristaps 640: html_idcat(buf, " ", BUFSIZ);
1.21 kristaps 641: }
642:
1.123 kristaps 643: PAIR_ID_INIT(&tag, buf);
644: print_otag(h, TAG_H2, 1, &tag);
1.1 kristaps 645: return(1);
646: }
647:
648:
649: /* ARGSUSED */
650: static int
651: mdoc_fl_pre(MDOC_ARGS)
652: {
653: struct htmlpair tag;
654:
1.51 kristaps 655: PAIR_CLASS_INIT(&tag, "flag");
1.132 kristaps 656: print_otag(h, TAG_B, 1, &tag);
1.51 kristaps 657:
1.50 kristaps 658: /* `Cm' has no leading hyphen. */
659:
1.51 kristaps 660: if (MDOC_Cm == n->tok)
1.50 kristaps 661: return(1);
662:
663: print_text(h, "\\-");
664:
665: if (n->child)
1.58 kristaps 666: h->flags |= HTML_NOSPACE;
667: else if (n->next && n->next->line == n->line)
1.1 kristaps 668: h->flags |= HTML_NOSPACE;
1.50 kristaps 669:
1.1 kristaps 670: return(1);
671: }
672:
673:
674: /* ARGSUSED */
675: static int
676: mdoc_nd_pre(MDOC_ARGS)
677: {
678: struct htmlpair tag;
679:
680: if (MDOC_BODY != n->type)
681: return(1);
682:
1.24 kristaps 683: /* XXX: this tag in theory can contain block elements. */
684:
1.1 kristaps 685: print_text(h, "\\(em");
1.124 kristaps 686: PAIR_CLASS_INIT(&tag, "desc");
1.1 kristaps 687: print_otag(h, TAG_SPAN, 1, &tag);
688: return(1);
689: }
690:
691:
692: static int
693: mdoc_nm_pre(MDOC_ARGS)
694: {
1.91 kristaps 695: struct htmlpair tag;
696: struct roffsu su;
1.124 kristaps 697: size_t len;
1.91 kristaps 698:
1.124 kristaps 699: switch (n->type) {
700: case (MDOC_ELEM):
1.91 kristaps 701: synopsis_pre(h, n);
702: PAIR_CLASS_INIT(&tag, "name");
1.132 kristaps 703: print_otag(h, TAG_B, 1, &tag);
1.124 kristaps 704: if (NULL == n->child && m->name)
705: print_text(h, m->name);
706: return(1);
707: case (MDOC_HEAD):
708: print_otag(h, TAG_TD, 0, NULL);
709: if (NULL == n->child && m->name)
1.91 kristaps 710: print_text(h, m->name);
1.124 kristaps 711: return(1);
712: case (MDOC_BODY):
713: print_otag(h, TAG_TD, 0, NULL);
714: return(1);
715: default:
716: break;
717: }
1.91 kristaps 718:
1.124 kristaps 719: synopsis_pre(h, n);
720: PAIR_CLASS_INIT(&tag, "synopsis");
721: print_otag(h, TAG_TABLE, 1, &tag);
722:
723: for (len = 0, n = n->child; n; n = n->next)
724: if (MDOC_TEXT == n->type)
725: len += strlen(n->string);
1.91 kristaps 726:
1.124 kristaps 727: if (0 == len && m->name)
728: len = strlen(m->name);
1.1 kristaps 729:
1.124 kristaps 730: SCALE_HS_INIT(&su, (double)len);
731: bufcat_su(h, "width", &su);
732: PAIR_STYLE_INIT(&tag, h);
733: print_otag(h, TAG_COL, 1, &tag);
734: print_otag(h, TAG_COL, 0, NULL);
735: print_otag(h, TAG_TBODY, 0, NULL);
736: print_otag(h, TAG_TR, 0, NULL);
1.1 kristaps 737: return(1);
738: }
739:
740:
741: /* ARGSUSED */
742: static int
743: mdoc_xr_pre(MDOC_ARGS)
744: {
745: struct htmlpair tag[2];
746: const struct mdoc_node *nn;
1.56 kristaps 747:
748: if (NULL == n->child)
749: return(0);
1.17 kristaps 750:
1.23 kristaps 751: PAIR_CLASS_INIT(&tag[0], "link-man");
1.1 kristaps 752:
1.17 kristaps 753: if (h->base_man) {
1.23 kristaps 754: buffmt_man(h, n->child->string,
755: n->child->next ?
1.17 kristaps 756: n->child->next->string : NULL);
1.57 kristaps 757: PAIR_HREF_INIT(&tag[1], h->buf);
1.23 kristaps 758: print_otag(h, TAG_A, 2, tag);
759: } else
760: print_otag(h, TAG_A, 1, tag);
1.1 kristaps 761:
762: nn = n->child;
763: print_text(h, nn->string);
1.16 kristaps 764:
1.1 kristaps 765: if (NULL == (nn = nn->next))
766: return(0);
767:
768: h->flags |= HTML_NOSPACE;
769: print_text(h, "(");
770: h->flags |= HTML_NOSPACE;
771: print_text(h, nn->string);
772: h->flags |= HTML_NOSPACE;
773: print_text(h, ")");
774: return(0);
775: }
776:
777:
778: /* ARGSUSED */
779: static int
780: mdoc_ns_pre(MDOC_ARGS)
781: {
782:
1.150 ! kristaps 783: if ( ! (MDOC_LINE & n->flags))
! 784: h->flags |= HTML_NOSPACE;
1.1 kristaps 785: return(1);
786: }
787:
788:
789: /* ARGSUSED */
790: static int
791: mdoc_ar_pre(MDOC_ARGS)
792: {
793: struct htmlpair tag;
794:
1.23 kristaps 795: PAIR_CLASS_INIT(&tag, "arg");
1.133 kristaps 796: print_otag(h, TAG_I, 1, &tag);
1.1 kristaps 797: return(1);
798: }
799:
800:
801: /* ARGSUSED */
802: static int
803: mdoc_xx_pre(MDOC_ARGS)
804: {
805: const char *pp;
806: struct htmlpair tag;
807:
808: switch (n->tok) {
809: case (MDOC_Bsx):
1.112 schwarze 810: pp = "BSD/OS";
1.1 kristaps 811: break;
812: case (MDOC_Dx):
1.45 kristaps 813: pp = "DragonFly";
1.1 kristaps 814: break;
815: case (MDOC_Fx):
816: pp = "FreeBSD";
817: break;
818: case (MDOC_Nx):
819: pp = "NetBSD";
820: break;
821: case (MDOC_Ox):
822: pp = "OpenBSD";
823: break;
824: case (MDOC_Ux):
825: pp = "UNIX";
826: break;
827: default:
828: return(1);
829: }
830:
1.23 kristaps 831: PAIR_CLASS_INIT(&tag, "unix");
1.1 kristaps 832: print_otag(h, TAG_SPAN, 1, &tag);
1.148 kristaps 833:
1.1 kristaps 834: print_text(h, pp);
1.148 kristaps 835: if (n->child) {
836: h->flags |= HTML_KEEP;
837: print_text(h, n->child->string);
838: h->flags &= ~HTML_KEEP;
839: }
840: return(0);
1.1 kristaps 841: }
842:
843:
844: /* ARGSUSED */
845: static int
1.4 kristaps 846: mdoc_bx_pre(MDOC_ARGS)
847: {
1.146 kristaps 848: struct htmlpair tag;
1.4 kristaps 849:
1.23 kristaps 850: PAIR_CLASS_INIT(&tag, "unix");
1.4 kristaps 851: print_otag(h, TAG_SPAN, 1, &tag);
852:
1.145 kristaps 853: if (NULL != (n = n->child)) {
854: print_text(h, n->string);
855: h->flags |= HTML_NOSPACE;
856: print_text(h, "BSD");
857: } else {
858: print_text(h, "BSD");
859: return(0);
860: }
1.4 kristaps 861:
1.145 kristaps 862: if (NULL != (n = n->next)) {
863: h->flags |= HTML_NOSPACE;
1.147 kristaps 864: print_text(h, "-");
1.4 kristaps 865: h->flags |= HTML_NOSPACE;
1.147 kristaps 866: print_text(h, n->string);
1.145 kristaps 867: }
1.4 kristaps 868:
869: return(0);
870: }
871:
1.142 kristaps 872: /* ARGSUSED */
1.4 kristaps 873: static int
1.115 kristaps 874: mdoc_it_pre(MDOC_ARGS)
1.1 kristaps 875: {
1.115 kristaps 876: struct roffsu su;
877: enum mdoc_list type;
1.116 kristaps 878: struct htmlpair tag[2];
1.115 kristaps 879: const struct mdoc_node *bl;
880:
881: bl = n->parent;
882: while (bl && MDOC_Bl != bl->tok)
883: bl = bl->parent;
1.23 kristaps 884:
1.115 kristaps 885: assert(bl);
1.23 kristaps 886:
1.137 kristaps 887: type = bl->norm->Bl.type;
1.24 kristaps 888:
1.116 kristaps 889: assert(lists[type]);
890: PAIR_CLASS_INIT(&tag[0], lists[type]);
1.1 kristaps 891:
1.115 kristaps 892: if (MDOC_HEAD == n->type) {
893: switch (type) {
894: case(LIST_bullet):
895: /* FALLTHROUGH */
896: case(LIST_dash):
897: /* FALLTHROUGH */
898: case(LIST_item):
899: /* FALLTHROUGH */
900: case(LIST_hyphen):
901: /* FALLTHROUGH */
902: case(LIST_enum):
903: return(0);
904: case(LIST_diag):
905: /* FALLTHROUGH */
906: case(LIST_hang):
907: /* FALLTHROUGH */
908: case(LIST_inset):
909: /* FALLTHROUGH */
910: case(LIST_ohang):
911: /* FALLTHROUGH */
912: case(LIST_tag):
1.137 kristaps 913: SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.122 kristaps 914: bufcat_su(h, "margin-top", &su);
915: PAIR_STYLE_INIT(&tag[1], h);
1.116 kristaps 916: print_otag(h, TAG_DT, 2, tag);
1.134 kristaps 917: if (LIST_diag != type)
918: break;
919: PAIR_CLASS_INIT(&tag[0], "diag");
920: print_otag(h, TAG_B, 1, tag);
1.115 kristaps 921: break;
922: case(LIST_column):
923: break;
924: default:
925: break;
926: }
927: } else if (MDOC_BODY == n->type) {
928: switch (type) {
929: case(LIST_bullet):
930: /* FALLTHROUGH */
931: case(LIST_hyphen):
932: /* FALLTHROUGH */
933: case(LIST_dash):
934: /* FALLTHROUGH */
935: case(LIST_enum):
936: /* FALLTHROUGH */
937: case(LIST_item):
1.137 kristaps 938: SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.122 kristaps 939: bufcat_su(h, "margin-top", &su);
940: PAIR_STYLE_INIT(&tag[1], h);
1.116 kristaps 941: print_otag(h, TAG_LI, 2, tag);
1.115 kristaps 942: break;
943: case(LIST_diag):
944: /* FALLTHROUGH */
945: case(LIST_hang):
946: /* FALLTHROUGH */
947: case(LIST_inset):
948: /* FALLTHROUGH */
949: case(LIST_ohang):
950: /* FALLTHROUGH */
951: case(LIST_tag):
1.137 kristaps 952: if (NULL == bl->norm->Bl.width) {
1.122 kristaps 953: print_otag(h, TAG_DD, 1, tag);
954: break;
955: }
1.137 kristaps 956: a2width(bl->norm->Bl.width, &su);
1.122 kristaps 957: bufcat_su(h, "margin-left", &su);
958: PAIR_STYLE_INIT(&tag[1], h);
959: print_otag(h, TAG_DD, 2, tag);
1.115 kristaps 960: break;
961: case(LIST_column):
1.137 kristaps 962: SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.122 kristaps 963: bufcat_su(h, "margin-top", &su);
964: PAIR_STYLE_INIT(&tag[1], h);
1.116 kristaps 965: print_otag(h, TAG_TD, 2, tag);
1.115 kristaps 966: break;
967: default:
968: break;
969: }
970: } else {
971: switch (type) {
972: case (LIST_column):
1.116 kristaps 973: print_otag(h, TAG_TR, 1, tag);
1.115 kristaps 974: break;
975: default:
1.23 kristaps 976: break;
1.115 kristaps 977: }
1.1 kristaps 978: }
979:
980: return(1);
981: }
982:
1.25 kristaps 983: /* ARGSUSED */
1.1 kristaps 984: static int
1.115 kristaps 985: mdoc_bl_pre(MDOC_ARGS)
1.1 kristaps 986: {
1.142 kristaps 987: int i;
1.119 kristaps 988: struct htmlpair tag[3];
1.23 kristaps 989: struct roffsu su;
1.134 kristaps 990: char buf[BUFSIZ];
1.23 kristaps 991:
1.115 kristaps 992: if (MDOC_BODY == n->type) {
1.137 kristaps 993: if (LIST_column == n->norm->Bl.type)
1.115 kristaps 994: print_otag(h, TAG_TBODY, 0, NULL);
995: return(1);
1.23 kristaps 996: }
1.1 kristaps 997:
1.115 kristaps 998: if (MDOC_HEAD == n->type) {
1.137 kristaps 999: if (LIST_column != n->norm->Bl.type)
1.115 kristaps 1000: return(0);
1001:
1002: /*
1003: * For each column, print out the <COL> tag with our
1004: * suggested width. The last column gets min-width, as
1005: * in terminal mode it auto-sizes to the width of the
1006: * screen and we want to preserve that behaviour.
1007: */
1.1 kristaps 1008:
1.142 kristaps 1009: for (i = 0; i < (int)n->norm->Bl.ncols; i++) {
1.137 kristaps 1010: a2width(n->norm->Bl.cols[i], &su);
1.115 kristaps 1011: bufinit(h);
1.142 kristaps 1012: if (i < (int)n->norm->Bl.ncols - 1)
1.115 kristaps 1013: bufcat_su(h, "width", &su);
1014: else
1015: bufcat_su(h, "min-width", &su);
1016: PAIR_STYLE_INIT(&tag[0], h);
1017: print_otag(h, TAG_COL, 1, tag);
1018: }
1.1 kristaps 1019:
1020: return(0);
1021: }
1022:
1.119 kristaps 1023: SCALE_VS_INIT(&su, 0);
1024: bufcat_su(h, "margin-top", &su);
1025: bufcat_su(h, "margin-bottom", &su);
1026: PAIR_STYLE_INIT(&tag[0], h);
1027:
1.137 kristaps 1028: assert(lists[n->norm->Bl.type]);
1.134 kristaps 1029: strlcpy(buf, "list ", BUFSIZ);
1.137 kristaps 1030: strlcat(buf, lists[n->norm->Bl.type], BUFSIZ);
1.134 kristaps 1031: PAIR_INIT(&tag[1], ATTR_CLASS, buf);
1.1 kristaps 1032:
1.115 kristaps 1033: /* Set the block's left-hand margin. */
1.1 kristaps 1034:
1.137 kristaps 1035: if (n->norm->Bl.offs) {
1036: a2offs(n->norm->Bl.offs, &su);
1.115 kristaps 1037: bufcat_su(h, "margin-left", &su);
1038: }
1.1 kristaps 1039:
1.137 kristaps 1040: switch (n->norm->Bl.type) {
1.115 kristaps 1041: case(LIST_bullet):
1.1 kristaps 1042: /* FALLTHROUGH */
1.115 kristaps 1043: case(LIST_dash):
1.1 kristaps 1044: /* FALLTHROUGH */
1.115 kristaps 1045: case(LIST_hyphen):
1.1 kristaps 1046: /* FALLTHROUGH */
1.115 kristaps 1047: case(LIST_item):
1.134 kristaps 1048: print_otag(h, TAG_UL, 2, tag);
1.1 kristaps 1049: break;
1.115 kristaps 1050: case(LIST_enum):
1.134 kristaps 1051: print_otag(h, TAG_OL, 2, tag);
1.23 kristaps 1052: break;
1.115 kristaps 1053: case(LIST_diag):
1054: /* FALLTHROUGH */
1055: case(LIST_hang):
1.46 kristaps 1056: /* FALLTHROUGH */
1.115 kristaps 1057: case(LIST_inset):
1.33 kristaps 1058: /* FALLTHROUGH */
1.115 kristaps 1059: case(LIST_ohang):
1.1 kristaps 1060: /* FALLTHROUGH */
1.115 kristaps 1061: case(LIST_tag):
1.134 kristaps 1062: print_otag(h, TAG_DL, 2, tag);
1.115 kristaps 1063: break;
1064: case(LIST_column):
1.134 kristaps 1065: print_otag(h, TAG_TABLE, 2, tag);
1.1 kristaps 1066: break;
1067: default:
1.115 kristaps 1068: abort();
1069: /* NOTREACHED */
1.1 kristaps 1070: }
1071:
1072: return(1);
1073: }
1074:
1075: /* ARGSUSED */
1076: static int
1077: mdoc_ex_pre(MDOC_ARGS)
1078: {
1079: const struct mdoc_node *nn;
1080: struct tag *t;
1081: struct htmlpair tag;
1082:
1.127 kristaps 1083: if (n->prev)
1084: print_otag(h, TAG_BR, 0, NULL);
1085:
1.23 kristaps 1086: PAIR_CLASS_INIT(&tag, "utility");
1087:
1.1 kristaps 1088: print_text(h, "The");
1089: for (nn = n->child; nn; nn = nn->next) {
1.132 kristaps 1090: t = print_otag(h, TAG_B, 1, &tag);
1.1 kristaps 1091: print_text(h, nn->string);
1092: print_tagq(h, t);
1093:
1094: h->flags |= HTML_NOSPACE;
1095:
1096: if (nn->next && NULL == nn->next->next)
1097: print_text(h, ", and");
1098: else if (nn->next)
1099: print_text(h, ",");
1100: else
1101: h->flags &= ~HTML_NOSPACE;
1102: }
1103:
1.65 kristaps 1104: if (n->child && n->child->next)
1.1 kristaps 1105: print_text(h, "utilities exit");
1106: else
1107: print_text(h, "utility exits");
1108:
1109: print_text(h, "0 on success, and >0 if an error occurs.");
1110: return(0);
1111: }
1112:
1113:
1114: /* ARGSUSED */
1115: static int
1116: mdoc_em_pre(MDOC_ARGS)
1117: {
1118: struct htmlpair tag;
1119:
1.23 kristaps 1120: PAIR_CLASS_INIT(&tag, "emph");
1.1 kristaps 1121: print_otag(h, TAG_SPAN, 1, &tag);
1122: return(1);
1123: }
1124:
1125:
1126: /* ARGSUSED */
1127: static int
1128: mdoc_d1_pre(MDOC_ARGS)
1129: {
1.23 kristaps 1130: struct htmlpair tag[2];
1131: struct roffsu su;
1.1 kristaps 1132:
1133: if (MDOC_BLOCK != n->type)
1134: return(1);
1135:
1.118 kristaps 1136: SCALE_VS_INIT(&su, 0);
1137: bufcat_su(h, "margin-top", &su);
1138: bufcat_su(h, "margin-bottom", &su);
1139: PAIR_STYLE_INIT(&tag[0], h);
1.120 kristaps 1140: print_otag(h, TAG_BLOCKQUOTE, 1, tag);
1141:
1142: /* BLOCKQUOTE needs a block body. */
1.118 kristaps 1143:
1.136 kristaps 1144: PAIR_CLASS_INIT(&tag[0], "display");
1145: print_otag(h, TAG_DIV, 1, tag);
1146:
1.135 kristaps 1147: if (MDOC_Dl == n->tok) {
1.136 kristaps 1148: PAIR_CLASS_INIT(&tag[0], "lit");
1.135 kristaps 1149: print_otag(h, TAG_CODE, 1, tag);
1.136 kristaps 1150: }
1.35 kristaps 1151:
1.1 kristaps 1152: return(1);
1153: }
1154:
1155:
1156: /* ARGSUSED */
1157: static int
1158: mdoc_sx_pre(MDOC_ARGS)
1159: {
1.18 kristaps 1160: struct htmlpair tag[2];
1.1 kristaps 1161: const struct mdoc_node *nn;
1.35 kristaps 1162: char buf[BUFSIZ];
1.1 kristaps 1163:
1.41 kristaps 1164: strlcpy(buf, "#", BUFSIZ);
1.1 kristaps 1165: for (nn = n->child; nn; nn = nn->next) {
1.41 kristaps 1166: html_idcat(buf, nn->string, BUFSIZ);
1.1 kristaps 1167: if (nn->next)
1.42 kristaps 1168: html_idcat(buf, " ", BUFSIZ);
1.1 kristaps 1169: }
1170:
1.23 kristaps 1171: PAIR_CLASS_INIT(&tag[0], "link-sec");
1.57 kristaps 1172: PAIR_HREF_INIT(&tag[1], buf);
1.1 kristaps 1173:
1.134 kristaps 1174: print_otag(h, TAG_I, 1, tag);
1.18 kristaps 1175: print_otag(h, TAG_A, 2, tag);
1.1 kristaps 1176: return(1);
1177: }
1178:
1179:
1180: /* ARGSUSED */
1181: static int
1182: mdoc_bd_pre(MDOC_ARGS)
1183: {
1184: struct htmlpair tag[2];
1.149 kristaps 1185: int comp, sv;
1.80 kristaps 1186: const struct mdoc_node *nn;
1.23 kristaps 1187: struct roffsu su;
1.1 kristaps 1188:
1.80 kristaps 1189: if (MDOC_HEAD == n->type)
1.1 kristaps 1190: return(0);
1191:
1192: if (MDOC_BLOCK == n->type) {
1.137 kristaps 1193: comp = n->norm->Bd.comp;
1.23 kristaps 1194: for (nn = n; nn && ! comp; nn = nn->parent) {
1195: if (MDOC_BLOCK != nn->type)
1196: continue;
1197: if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
1198: comp = 1;
1199: if (nn->prev)
1200: break;
1201: }
1.126 kristaps 1202: if ( ! comp)
1203: print_otag(h, TAG_P, 0, NULL);
1.1 kristaps 1204: return(1);
1205: }
1206:
1.126 kristaps 1207: SCALE_HS_INIT(&su, 0);
1.137 kristaps 1208: if (n->norm->Bd.offs)
1209: a2offs(n->norm->Bd.offs, &su);
1.126 kristaps 1210:
1211: bufcat_su(h, "margin-left", &su);
1212: PAIR_STYLE_INIT(&tag[0], h);
1213:
1.137 kristaps 1214: if (DISP_unfilled != n->norm->Bd.type &&
1215: DISP_literal != n->norm->Bd.type) {
1.126 kristaps 1216: PAIR_CLASS_INIT(&tag[1], "display");
1217: print_otag(h, TAG_DIV, 2, tag);
1.1 kristaps 1218: return(1);
1.126 kristaps 1219: }
1.1 kristaps 1220:
1.126 kristaps 1221: PAIR_CLASS_INIT(&tag[1], "lit display");
1222: print_otag(h, TAG_PRE, 2, tag);
1.1 kristaps 1223:
1.149 kristaps 1224: /* This can be recursive: save & set our literal state. */
1225:
1226: sv = h->flags & HTML_LITERAL;
1227: h->flags |= HTML_LITERAL;
1228:
1.14 kristaps 1229: for (nn = n->child; nn; nn = nn->next) {
1230: print_mdoc_node(m, nn, h);
1.108 kristaps 1231: /*
1232: * If the printed node flushes its own line, then we
1233: * needn't do it here as well. This is hacky, but the
1234: * notion of selective eoln whitespace is pretty dumb
1235: * anyway, so don't sweat it.
1236: */
1237: switch (nn->tok) {
1.111 kristaps 1238: case (MDOC_Sm):
1239: /* FALLTHROUGH */
1.108 kristaps 1240: case (MDOC_br):
1241: /* FALLTHROUGH */
1242: case (MDOC_sp):
1243: /* FALLTHROUGH */
1244: case (MDOC_Bl):
1.114 kristaps 1245: /* FALLTHROUGH */
1246: case (MDOC_D1):
1247: /* FALLTHROUGH */
1248: case (MDOC_Dl):
1.108 kristaps 1249: /* FALLTHROUGH */
1250: case (MDOC_Lp):
1251: /* FALLTHROUGH */
1252: case (MDOC_Pp):
1253: continue;
1254: default:
1255: break;
1256: }
1.101 schwarze 1257: if (nn->next && nn->next->line == nn->line)
1258: continue;
1.126 kristaps 1259: else if (nn->next)
1260: print_text(h, "\n");
1.125 kristaps 1261:
1.101 schwarze 1262: h->flags |= HTML_NOSPACE;
1.1 kristaps 1263: }
1.149 kristaps 1264:
1265: if (0 == sv)
1266: h->flags &= ~HTML_LITERAL;
1.1 kristaps 1267:
1268: return(0);
1269: }
1270:
1271:
1272: /* ARGSUSED */
1273: static int
1274: mdoc_pa_pre(MDOC_ARGS)
1275: {
1276: struct htmlpair tag;
1277:
1.23 kristaps 1278: PAIR_CLASS_INIT(&tag, "file");
1.133 kristaps 1279: print_otag(h, TAG_I, 1, &tag);
1.1 kristaps 1280: return(1);
1281: }
1282:
1283:
1284: /* ARGSUSED */
1285: static int
1286: mdoc_ad_pre(MDOC_ARGS)
1287: {
1288: struct htmlpair tag;
1289:
1.23 kristaps 1290: PAIR_CLASS_INIT(&tag, "addr");
1.133 kristaps 1291: print_otag(h, TAG_I, 1, &tag);
1.1 kristaps 1292: return(1);
1293: }
1294:
1295:
1296: /* ARGSUSED */
1297: static int
1298: mdoc_an_pre(MDOC_ARGS)
1299: {
1300: struct htmlpair tag;
1301:
1.19 kristaps 1302: /* TODO: -split and -nosplit (see termp_an_pre()). */
1303:
1.23 kristaps 1304: PAIR_CLASS_INIT(&tag, "author");
1.1 kristaps 1305: print_otag(h, TAG_SPAN, 1, &tag);
1306: return(1);
1307: }
1308:
1309:
1310: /* ARGSUSED */
1311: static int
1312: mdoc_cd_pre(MDOC_ARGS)
1313: {
1314: struct htmlpair tag;
1315:
1.78 kristaps 1316: synopsis_pre(h, n);
1.23 kristaps 1317: PAIR_CLASS_INIT(&tag, "config");
1.132 kristaps 1318: print_otag(h, TAG_B, 1, &tag);
1.1 kristaps 1319: return(1);
1320: }
1321:
1322:
1323: /* ARGSUSED */
1324: static int
1325: mdoc_dv_pre(MDOC_ARGS)
1326: {
1327: struct htmlpair tag;
1328:
1.23 kristaps 1329: PAIR_CLASS_INIT(&tag, "define");
1.1 kristaps 1330: print_otag(h, TAG_SPAN, 1, &tag);
1331: return(1);
1332: }
1333:
1334:
1335: /* ARGSUSED */
1336: static int
1337: mdoc_ev_pre(MDOC_ARGS)
1338: {
1339: struct htmlpair tag;
1340:
1.23 kristaps 1341: PAIR_CLASS_INIT(&tag, "env");
1.1 kristaps 1342: print_otag(h, TAG_SPAN, 1, &tag);
1343: return(1);
1344: }
1345:
1346:
1347: /* ARGSUSED */
1348: static int
1349: mdoc_er_pre(MDOC_ARGS)
1350: {
1351: struct htmlpair tag;
1352:
1.23 kristaps 1353: PAIR_CLASS_INIT(&tag, "errno");
1.1 kristaps 1354: print_otag(h, TAG_SPAN, 1, &tag);
1355: return(1);
1356: }
1357:
1358:
1359: /* ARGSUSED */
1360: static int
1361: mdoc_fa_pre(MDOC_ARGS)
1362: {
1363: const struct mdoc_node *nn;
1364: struct htmlpair tag;
1365: struct tag *t;
1366:
1.23 kristaps 1367: PAIR_CLASS_INIT(&tag, "farg");
1.1 kristaps 1368: if (n->parent->tok != MDOC_Fo) {
1.133 kristaps 1369: print_otag(h, TAG_I, 1, &tag);
1.1 kristaps 1370: return(1);
1371: }
1372:
1373: for (nn = n->child; nn; nn = nn->next) {
1.133 kristaps 1374: t = print_otag(h, TAG_I, 1, &tag);
1.1 kristaps 1375: print_text(h, nn->string);
1376: print_tagq(h, t);
1377: if (nn->next)
1378: print_text(h, ",");
1379: }
1380:
1381: if (n->child && n->next && n->next->tok == MDOC_Fa)
1382: print_text(h, ",");
1383:
1384: return(0);
1385: }
1386:
1387:
1388: /* ARGSUSED */
1389: static int
1390: mdoc_fd_pre(MDOC_ARGS)
1391: {
1.23 kristaps 1392: struct htmlpair tag;
1.1 kristaps 1393:
1.78 kristaps 1394: synopsis_pre(h, n);
1395:
1.23 kristaps 1396: PAIR_CLASS_INIT(&tag, "macro");
1.132 kristaps 1397: print_otag(h, TAG_B, 1, &tag);
1.1 kristaps 1398: return(1);
1399: }
1400:
1401:
1402: /* ARGSUSED */
1403: static int
1404: mdoc_vt_pre(MDOC_ARGS)
1405: {
1.23 kristaps 1406: struct htmlpair tag;
1.1 kristaps 1407:
1.78 kristaps 1408: if (MDOC_BLOCK == n->type) {
1409: synopsis_pre(h, n);
1.54 kristaps 1410: return(1);
1.78 kristaps 1411: } else if (MDOC_ELEM == n->type) {
1412: synopsis_pre(h, n);
1.54 kristaps 1413: } else if (MDOC_HEAD == n->type)
1414: return(0);
1.1 kristaps 1415:
1.23 kristaps 1416: PAIR_CLASS_INIT(&tag, "type");
1.1 kristaps 1417: print_otag(h, TAG_SPAN, 1, &tag);
1418: return(1);
1419: }
1420:
1.2 kristaps 1421:
1.1 kristaps 1422: /* ARGSUSED */
1423: static int
1424: mdoc_ft_pre(MDOC_ARGS)
1425: {
1.23 kristaps 1426: struct htmlpair tag;
1.1 kristaps 1427:
1.78 kristaps 1428: synopsis_pre(h, n);
1.23 kristaps 1429: PAIR_CLASS_INIT(&tag, "ftype");
1.133 kristaps 1430: print_otag(h, TAG_I, 1, &tag);
1.1 kristaps 1431: return(1);
1432: }
1433:
1434:
1435: /* ARGSUSED */
1436: static int
1437: mdoc_fn_pre(MDOC_ARGS)
1438: {
1439: struct tag *t;
1.15 kristaps 1440: struct htmlpair tag[2];
1.1 kristaps 1441: const struct mdoc_node *nn;
1.7 kristaps 1442: char nbuf[BUFSIZ];
1443: const char *sp, *ep;
1.15 kristaps 1444: int sz, i;
1.1 kristaps 1445:
1.78 kristaps 1446: synopsis_pre(h, n);
1.1 kristaps 1447:
1.7 kristaps 1448: /* Split apart into type and name. */
1449: assert(n->child->string);
1450: sp = n->child->string;
1.19 kristaps 1451:
1.26 kristaps 1452: ep = strchr(sp, ' ');
1453: if (NULL != ep) {
1.23 kristaps 1454: PAIR_CLASS_INIT(&tag[0], "ftype");
1.133 kristaps 1455: t = print_otag(h, TAG_I, 1, tag);
1.19 kristaps 1456:
1457: while (ep) {
1458: sz = MIN((int)(ep - sp), BUFSIZ - 1);
1459: (void)memcpy(nbuf, sp, (size_t)sz);
1460: nbuf[sz] = '\0';
1461: print_text(h, nbuf);
1462: sp = ++ep;
1463: ep = strchr(sp, ' ');
1464: }
1465: print_tagq(h, t);
1.7 kristaps 1466: }
1.1 kristaps 1467:
1.23 kristaps 1468: PAIR_CLASS_INIT(&tag[0], "fname");
1.57 kristaps 1469:
1470: /*
1471: * FIXME: only refer to IDs that we know exist.
1472: */
1473:
1474: #if 0
1.87 kristaps 1475: if (MDOC_SYNPRETTY & n->flags) {
1.57 kristaps 1476: nbuf[0] = '\0';
1477: html_idcat(nbuf, sp, BUFSIZ);
1478: PAIR_ID_INIT(&tag[1], nbuf);
1479: } else {
1480: strlcpy(nbuf, "#", BUFSIZ);
1481: html_idcat(nbuf, sp, BUFSIZ);
1482: PAIR_HREF_INIT(&tag[1], nbuf);
1483: }
1484: #endif
1485:
1.132 kristaps 1486: t = print_otag(h, TAG_B, 1, tag);
1.7 kristaps 1487:
1488: if (sp) {
1.57 kristaps 1489: strlcpy(nbuf, sp, BUFSIZ);
1.7 kristaps 1490: print_text(h, nbuf);
1491: }
1492:
1.1 kristaps 1493: print_tagq(h, t);
1494:
1495: h->flags |= HTML_NOSPACE;
1496: print_text(h, "(");
1497:
1.23 kristaps 1498: bufinit(h);
1499: PAIR_CLASS_INIT(&tag[0], "farg");
1500: bufcat_style(h, "white-space", "nowrap");
1501: PAIR_STYLE_INIT(&tag[1], h);
1502:
1.1 kristaps 1503: for (nn = n->child->next; nn; nn = nn->next) {
1.23 kristaps 1504: i = 1;
1.87 kristaps 1505: if (MDOC_SYNPRETTY & n->flags)
1.23 kristaps 1506: i = 2;
1.133 kristaps 1507: t = print_otag(h, TAG_I, i, tag);
1.1 kristaps 1508: print_text(h, nn->string);
1509: print_tagq(h, t);
1510: if (nn->next)
1511: print_text(h, ",");
1512: }
1513:
1514: print_text(h, ")");
1.87 kristaps 1515: if (MDOC_SYNPRETTY & n->flags)
1.1 kristaps 1516: print_text(h, ";");
1.99 kristaps 1517:
1518: return(0);
1519: }
1520:
1521:
1522: /* ARGSUSED */
1523: static int
1524: mdoc_sm_pre(MDOC_ARGS)
1525: {
1526:
1527: assert(n->child && MDOC_TEXT == n->child->type);
1528: if (0 == strcmp("on", n->child->string)) {
1.111 kristaps 1529: /*
1530: * FIXME: no p->col to check. Thus, if we have
1531: * .Bd -literal
1532: * .Sm off
1533: * 1 2
1534: * .Sm on
1535: * 3
1536: * .Ed
1537: * the "3" is preceded by a space.
1538: */
1.99 kristaps 1539: h->flags &= ~HTML_NOSPACE;
1540: h->flags &= ~HTML_NONOSPACE;
1541: } else
1542: h->flags |= HTML_NONOSPACE;
1.1 kristaps 1543:
1544: return(0);
1545: }
1546:
1.120 kristaps 1547: /* ARGSUSED */
1548: static int
1549: mdoc_pp_pre(MDOC_ARGS)
1550: {
1551:
1552: print_otag(h, TAG_P, 0, NULL);
1553: return(0);
1554:
1555: }
1.1 kristaps 1556:
1557: /* ARGSUSED */
1558: static int
1559: mdoc_sp_pre(MDOC_ARGS)
1560: {
1.120 kristaps 1561: struct roffsu su;
1.23 kristaps 1562: struct htmlpair tag;
1.1 kristaps 1563:
1.120 kristaps 1564: SCALE_VS_INIT(&su, 1);
1565:
1566: if (MDOC_sp == n->tok) {
1567: if (n->child)
1568: a2roffsu(n->child->string, &su, SCALE_VS);
1569: } else
1570: su.scale = 0;
1.1 kristaps 1571:
1.23 kristaps 1572: bufcat_su(h, "height", &su);
1573: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1574: print_otag(h, TAG_DIV, 1, &tag);
1.120 kristaps 1575:
1.42 kristaps 1576: /* So the div isn't empty: */
1577: print_text(h, "\\~");
1578:
1579: return(0);
1.1 kristaps 1580:
1581: }
1.2 kristaps 1582:
1583: /* ARGSUSED */
1584: static int
1585: mdoc_lk_pre(MDOC_ARGS)
1586: {
1587: const struct mdoc_node *nn;
1588: struct htmlpair tag[2];
1589:
1590: nn = n->child;
1591:
1.23 kristaps 1592: PAIR_CLASS_INIT(&tag[0], "link-ext");
1.57 kristaps 1593: PAIR_HREF_INIT(&tag[1], nn->string);
1.2 kristaps 1594: print_otag(h, TAG_A, 2, tag);
1595:
1.113 kristaps 1596: if (NULL == nn || NULL == nn->next)
1.38 kristaps 1597: return(1);
1598:
1.2 kristaps 1599: for (nn = nn->next; nn; nn = nn->next)
1600: print_text(h, nn->string);
1601:
1602: return(0);
1603: }
1604:
1605:
1606: /* ARGSUSED */
1607: static int
1608: mdoc_mt_pre(MDOC_ARGS)
1609: {
1610: struct htmlpair tag[2];
1611: struct tag *t;
1612: const struct mdoc_node *nn;
1613:
1.23 kristaps 1614: PAIR_CLASS_INIT(&tag[0], "link-mail");
1.2 kristaps 1615:
1616: for (nn = n->child; nn; nn = nn->next) {
1.16 kristaps 1617: bufinit(h);
1618: bufcat(h, "mailto:");
1619: bufcat(h, nn->string);
1.57 kristaps 1620: PAIR_HREF_INIT(&tag[1], h->buf);
1.2 kristaps 1621: t = print_otag(h, TAG_A, 2, tag);
1622: print_text(h, nn->string);
1623: print_tagq(h, t);
1624: }
1625:
1626: return(0);
1627: }
1.4 kristaps 1628:
1629:
1630: /* ARGSUSED */
1631: static int
1632: mdoc_fo_pre(MDOC_ARGS)
1633: {
1.77 kristaps 1634: struct htmlpair tag;
1635: struct tag *t;
1.4 kristaps 1636:
1637: if (MDOC_BODY == n->type) {
1638: h->flags |= HTML_NOSPACE;
1639: print_text(h, "(");
1640: h->flags |= HTML_NOSPACE;
1641: return(1);
1.77 kristaps 1642: } else if (MDOC_BLOCK == n->type) {
1.78 kristaps 1643: synopsis_pre(h, n);
1.4 kristaps 1644: return(1);
1.57 kristaps 1645: }
1.4 kristaps 1646:
1.77 kristaps 1647: /* XXX: we drop non-initial arguments as per groff. */
1648:
1649: assert(n->child);
1650: assert(n->child->string);
1651:
1.23 kristaps 1652: PAIR_CLASS_INIT(&tag, "fname");
1.139 kristaps 1653: t = print_otag(h, TAG_B, 1, &tag);
1.77 kristaps 1654: print_text(h, n->child->string);
1655: print_tagq(h, t);
1656: return(0);
1.4 kristaps 1657: }
1658:
1659:
1660: /* ARGSUSED */
1661: static void
1662: mdoc_fo_post(MDOC_ARGS)
1663: {
1.78 kristaps 1664:
1.4 kristaps 1665: if (MDOC_BODY != n->type)
1666: return;
1667: print_text(h, ")");
1668: print_text(h, ";");
1669: }
1670:
1671:
1672: /* ARGSUSED */
1673: static int
1674: mdoc_in_pre(MDOC_ARGS)
1675: {
1676: const struct mdoc_node *nn;
1.23 kristaps 1677: struct tag *t;
1.17 kristaps 1678: struct htmlpair tag[2];
1679: int i;
1.34 kristaps 1680:
1.78 kristaps 1681: synopsis_pre(h, n);
1682:
1.23 kristaps 1683: PAIR_CLASS_INIT(&tag[0], "includes");
1.132 kristaps 1684: print_otag(h, TAG_B, 1, tag);
1.4 kristaps 1685:
1.87 kristaps 1686: if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
1.4 kristaps 1687: print_text(h, "#include");
1688:
1689: print_text(h, "<");
1690: h->flags |= HTML_NOSPACE;
1691:
1.17 kristaps 1692: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1693: PAIR_CLASS_INIT(&tag[0], "link-includes");
1694: i = 1;
1.41 kristaps 1695: bufinit(h);
1.17 kristaps 1696: if (h->base_includes) {
1697: buffmt_includes(h, nn->string);
1.57 kristaps 1698: PAIR_HREF_INIT(&tag[i], h->buf);
1699: i++;
1.17 kristaps 1700: }
1701: t = print_otag(h, TAG_A, i, tag);
1.4 kristaps 1702: print_mdoc_node(m, nn, h);
1.17 kristaps 1703: print_tagq(h, t);
1704: }
1.4 kristaps 1705:
1706: h->flags |= HTML_NOSPACE;
1707: print_text(h, ">");
1708:
1709: return(0);
1710: }
1711:
1712:
1713: /* ARGSUSED */
1714: static int
1715: mdoc_ic_pre(MDOC_ARGS)
1716: {
1717: struct htmlpair tag;
1718:
1.23 kristaps 1719: PAIR_CLASS_INIT(&tag, "cmd");
1.132 kristaps 1720: print_otag(h, TAG_B, 1, &tag);
1.4 kristaps 1721: return(1);
1722: }
1723:
1724:
1725: /* ARGSUSED */
1726: static int
1727: mdoc_rv_pre(MDOC_ARGS)
1728: {
1729: const struct mdoc_node *nn;
1730: struct htmlpair tag;
1731: struct tag *t;
1732:
1.127 kristaps 1733: if (n->prev)
1734: print_otag(h, TAG_BR, 0, NULL);
1735:
1.4 kristaps 1736: print_text(h, "The");
1737:
1738: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1739: PAIR_CLASS_INIT(&tag, "fname");
1.139 kristaps 1740: t = print_otag(h, TAG_B, 1, &tag);
1.4 kristaps 1741: print_text(h, nn->string);
1742: print_tagq(h, t);
1743:
1744: h->flags |= HTML_NOSPACE;
1745: if (nn->next && NULL == nn->next->next)
1746: print_text(h, "(), and");
1747: else if (nn->next)
1748: print_text(h, "(),");
1749: else
1750: print_text(h, "()");
1751: }
1752:
1.65 kristaps 1753: if (n->child && n->child->next)
1.4 kristaps 1754: print_text(h, "functions return");
1755: else
1756: print_text(h, "function returns");
1757:
1758: print_text(h, "the value 0 if successful; otherwise the value "
1759: "-1 is returned and the global variable");
1760:
1.23 kristaps 1761: PAIR_CLASS_INIT(&tag, "var");
1.132 kristaps 1762: t = print_otag(h, TAG_B, 1, &tag);
1.4 kristaps 1763: print_text(h, "errno");
1764: print_tagq(h, t);
1765: print_text(h, "is set to indicate the error.");
1766: return(0);
1767: }
1768:
1769:
1770: /* ARGSUSED */
1771: static int
1772: mdoc_va_pre(MDOC_ARGS)
1773: {
1774: struct htmlpair tag;
1775:
1.23 kristaps 1776: PAIR_CLASS_INIT(&tag, "var");
1.132 kristaps 1777: print_otag(h, TAG_B, 1, &tag);
1.4 kristaps 1778: return(1);
1779: }
1780:
1781:
1782: /* ARGSUSED */
1783: static int
1.5 kristaps 1784: mdoc_ap_pre(MDOC_ARGS)
1785: {
1786:
1787: h->flags |= HTML_NOSPACE;
1788: print_text(h, "\\(aq");
1789: h->flags |= HTML_NOSPACE;
1790: return(1);
1791: }
1792:
1793:
1794: /* ARGSUSED */
1795: static int
1796: mdoc_bf_pre(MDOC_ARGS)
1797: {
1.23 kristaps 1798: struct htmlpair tag[2];
1799: struct roffsu su;
1.5 kristaps 1800:
1801: if (MDOC_HEAD == n->type)
1802: return(0);
1.92 kristaps 1803: else if (MDOC_BODY != n->type)
1.5 kristaps 1804: return(1);
1805:
1.137 kristaps 1806: if (FONT_Em == n->norm->Bf.font)
1.92 kristaps 1807: PAIR_CLASS_INIT(&tag[0], "emph");
1.137 kristaps 1808: else if (FONT_Sy == n->norm->Bf.font)
1.92 kristaps 1809: PAIR_CLASS_INIT(&tag[0], "symb");
1.137 kristaps 1810: else if (FONT_Li == n->norm->Bf.font)
1.92 kristaps 1811: PAIR_CLASS_INIT(&tag[0], "lit");
1812: else
1813: PAIR_CLASS_INIT(&tag[0], "none");
1.5 kristaps 1814:
1.92 kristaps 1815: /*
1816: * We want this to be inline-formatted, but needs to be div to
1817: * accept block children.
1818: */
1.23 kristaps 1819: bufcat_style(h, "display", "inline");
1820: SCALE_HS_INIT(&su, 1);
1.92 kristaps 1821: /* Needs a left-margin for spacing. */
1822: bufcat_su(h, "margin-left", &su);
1.23 kristaps 1823: PAIR_STYLE_INIT(&tag[1], h);
1.5 kristaps 1824: print_otag(h, TAG_DIV, 2, tag);
1825: return(1);
1826: }
1827:
1828:
1829: /* ARGSUSED */
1830: static int
1831: mdoc_ms_pre(MDOC_ARGS)
1832: {
1833: struct htmlpair tag;
1834:
1.23 kristaps 1835: PAIR_CLASS_INIT(&tag, "symb");
1.5 kristaps 1836: print_otag(h, TAG_SPAN, 1, &tag);
1837: return(1);
1838: }
1839:
1840:
1841: /* ARGSUSED */
1842: static int
1.110 schwarze 1843: mdoc_igndelim_pre(MDOC_ARGS)
1.5 kristaps 1844: {
1845:
1846: h->flags |= HTML_IGNDELIM;
1847: return(1);
1848: }
1849:
1850:
1851: /* ARGSUSED */
1852: static void
1853: mdoc_pf_post(MDOC_ARGS)
1854: {
1855:
1856: h->flags |= HTML_NOSPACE;
1857: }
1858:
1859:
1860: /* ARGSUSED */
1861: static int
1862: mdoc_rs_pre(MDOC_ARGS)
1863: {
1.23 kristaps 1864: struct htmlpair tag;
1.5 kristaps 1865:
1866: if (MDOC_BLOCK != n->type)
1867: return(1);
1868:
1.120 kristaps 1869: if (n->prev && SEC_SEE_ALSO == n->sec)
1870: print_otag(h, TAG_P, 0, NULL);
1.5 kristaps 1871:
1.23 kristaps 1872: PAIR_CLASS_INIT(&tag, "ref");
1.8 kristaps 1873: print_otag(h, TAG_SPAN, 1, &tag);
1.5 kristaps 1874: return(1);
1875: }
1.6 kristaps 1876:
1877:
1878:
1879: /* ARGSUSED */
1880: static int
1881: mdoc_li_pre(MDOC_ARGS)
1882: {
1883: struct htmlpair tag;
1884:
1.23 kristaps 1885: PAIR_CLASS_INIT(&tag, "lit");
1.6 kristaps 1886: print_otag(h, TAG_SPAN, 1, &tag);
1887: return(1);
1888: }
1889:
1890:
1891: /* ARGSUSED */
1892: static int
1893: mdoc_sy_pre(MDOC_ARGS)
1894: {
1895: struct htmlpair tag;
1896:
1.23 kristaps 1897: PAIR_CLASS_INIT(&tag, "symb");
1.6 kristaps 1898: print_otag(h, TAG_SPAN, 1, &tag);
1899: return(1);
1900: }
1901:
1902:
1903: /* ARGSUSED */
1904: static int
1905: mdoc_bt_pre(MDOC_ARGS)
1906: {
1907:
1908: print_text(h, "is currently in beta test.");
1909: return(0);
1910: }
1911:
1912:
1913: /* ARGSUSED */
1914: static int
1915: mdoc_ud_pre(MDOC_ARGS)
1916: {
1917:
1918: print_text(h, "currently under development.");
1919: return(0);
1920: }
1921:
1922:
1923: /* ARGSUSED */
1924: static int
1925: mdoc_lb_pre(MDOC_ARGS)
1926: {
1927: struct htmlpair tag;
1928:
1.127 kristaps 1929: if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags && n->prev)
1930: print_otag(h, TAG_BR, 0, NULL);
1931:
1.23 kristaps 1932: PAIR_CLASS_INIT(&tag, "lib");
1.6 kristaps 1933: print_otag(h, TAG_SPAN, 1, &tag);
1934: return(1);
1935: }
1.10 kristaps 1936:
1937:
1938: /* ARGSUSED */
1939: static int
1940: mdoc__x_pre(MDOC_ARGS)
1941: {
1.38 kristaps 1942: struct htmlpair tag[2];
1.133 kristaps 1943: enum htmltag t;
1944:
1945: t = TAG_SPAN;
1.37 kristaps 1946:
1.10 kristaps 1947: switch (n->tok) {
1948: case(MDOC__A):
1.38 kristaps 1949: PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.103 kristaps 1950: if (n->prev && MDOC__A == n->prev->tok)
1951: if (NULL == n->next || MDOC__A != n->next->tok)
1952: print_text(h, "and");
1.10 kristaps 1953: break;
1954: case(MDOC__B):
1.38 kristaps 1955: PAIR_CLASS_INIT(&tag[0], "ref-book");
1.133 kristaps 1956: t = TAG_I;
1.10 kristaps 1957: break;
1958: case(MDOC__C):
1.38 kristaps 1959: PAIR_CLASS_INIT(&tag[0], "ref-city");
1.10 kristaps 1960: break;
1961: case(MDOC__D):
1.38 kristaps 1962: PAIR_CLASS_INIT(&tag[0], "ref-date");
1.10 kristaps 1963: break;
1964: case(MDOC__I):
1.38 kristaps 1965: PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.133 kristaps 1966: t = TAG_I;
1.10 kristaps 1967: break;
1968: case(MDOC__J):
1.38 kristaps 1969: PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.133 kristaps 1970: t = TAG_I;
1.10 kristaps 1971: break;
1972: case(MDOC__N):
1.38 kristaps 1973: PAIR_CLASS_INIT(&tag[0], "ref-num");
1.10 kristaps 1974: break;
1975: case(MDOC__O):
1.38 kristaps 1976: PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.10 kristaps 1977: break;
1978: case(MDOC__P):
1.38 kristaps 1979: PAIR_CLASS_INIT(&tag[0], "ref-page");
1.10 kristaps 1980: break;
1981: case(MDOC__Q):
1.38 kristaps 1982: PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.10 kristaps 1983: break;
1984: case(MDOC__R):
1.38 kristaps 1985: PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.10 kristaps 1986: break;
1987: case(MDOC__T):
1.38 kristaps 1988: PAIR_CLASS_INIT(&tag[0], "ref-title");
1.10 kristaps 1989: break;
1.38 kristaps 1990: case(MDOC__U):
1991: PAIR_CLASS_INIT(&tag[0], "link-ref");
1992: break;
1.10 kristaps 1993: case(MDOC__V):
1.38 kristaps 1994: PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.10 kristaps 1995: break;
1996: default:
1997: abort();
1998: /* NOTREACHED */
1999: }
2000:
1.38 kristaps 2001: if (MDOC__U != n->tok) {
1.133 kristaps 2002: print_otag(h, t, 1, tag);
1.38 kristaps 2003: return(1);
2004: }
2005:
2006: PAIR_HREF_INIT(&tag[1], n->child->string);
2007: print_otag(h, TAG_A, 2, tag);
1.103 kristaps 2008:
1.10 kristaps 2009: return(1);
2010: }
2011:
2012:
2013: /* ARGSUSED */
2014: static void
2015: mdoc__x_post(MDOC_ARGS)
2016: {
1.103 kristaps 2017:
2018: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
2019: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
2020: if (NULL == n->prev || MDOC__A != n->prev->tok)
2021: return;
1.10 kristaps 2022:
1.61 kristaps 2023: /* TODO: %U */
2024:
1.106 kristaps 2025: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
2026: return;
2027:
1.10 kristaps 2028: print_text(h, n->next ? "," : ".");
1.94 kristaps 2029: }
2030:
2031:
2032: /* ARGSUSED */
2033: static int
2034: mdoc_bk_pre(MDOC_ARGS)
2035: {
2036:
2037: switch (n->type) {
2038: case (MDOC_BLOCK):
2039: break;
2040: case (MDOC_HEAD):
2041: return(0);
2042: case (MDOC_BODY):
1.131 kristaps 2043: if (n->parent->args || 0 == n->prev->nchild)
2044: h->flags |= HTML_PREKEEP;
1.94 kristaps 2045: break;
2046: default:
2047: abort();
2048: /* NOTREACHED */
2049: }
2050:
2051: return(1);
2052: }
2053:
2054:
2055: /* ARGSUSED */
2056: static void
2057: mdoc_bk_post(MDOC_ARGS)
2058: {
2059:
2060: if (MDOC_BODY == n->type)
2061: h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1.10 kristaps 2062: }
1.107 kristaps 2063:
2064:
2065: /* ARGSUSED */
2066: static int
2067: mdoc_quote_pre(MDOC_ARGS)
2068: {
2069: struct htmlpair tag;
2070:
2071: if (MDOC_BODY != n->type)
2072: return(1);
2073:
2074: switch (n->tok) {
2075: case (MDOC_Ao):
2076: /* FALLTHROUGH */
2077: case (MDOC_Aq):
2078: print_text(h, "\\(la");
2079: break;
2080: case (MDOC_Bro):
2081: /* FALLTHROUGH */
2082: case (MDOC_Brq):
2083: print_text(h, "\\(lC");
2084: break;
2085: case (MDOC_Bo):
2086: /* FALLTHROUGH */
2087: case (MDOC_Bq):
2088: print_text(h, "\\(lB");
2089: break;
2090: case (MDOC_Oo):
2091: /* FALLTHROUGH */
2092: case (MDOC_Op):
2093: print_text(h, "\\(lB");
1.109 kristaps 2094: h->flags |= HTML_NOSPACE;
1.107 kristaps 2095: PAIR_CLASS_INIT(&tag, "opt");
2096: print_otag(h, TAG_SPAN, 1, &tag);
2097: break;
2098: case (MDOC_Do):
2099: /* FALLTHROUGH */
2100: case (MDOC_Dq):
2101: /* FALLTHROUGH */
2102: case (MDOC_Qo):
2103: /* FALLTHROUGH */
2104: case (MDOC_Qq):
2105: print_text(h, "\\(lq");
2106: break;
2107: case (MDOC_Po):
2108: /* FALLTHROUGH */
2109: case (MDOC_Pq):
2110: print_text(h, "(");
2111: break;
2112: case (MDOC_Ql):
2113: /* FALLTHROUGH */
2114: case (MDOC_So):
2115: /* FALLTHROUGH */
2116: case (MDOC_Sq):
2117: print_text(h, "\\(oq");
2118: break;
2119: default:
2120: abort();
2121: /* NOTREACHED */
2122: }
2123:
2124: h->flags |= HTML_NOSPACE;
2125: return(1);
2126: }
2127:
2128:
2129: /* ARGSUSED */
2130: static void
2131: mdoc_quote_post(MDOC_ARGS)
2132: {
2133:
2134: if (MDOC_BODY != n->type)
2135: return;
2136:
2137: h->flags |= HTML_NOSPACE;
2138:
2139: switch (n->tok) {
2140: case (MDOC_Ao):
2141: /* FALLTHROUGH */
2142: case (MDOC_Aq):
2143: print_text(h, "\\(ra");
2144: break;
2145: case (MDOC_Bro):
2146: /* FALLTHROUGH */
2147: case (MDOC_Brq):
2148: print_text(h, "\\(rC");
2149: break;
2150: case (MDOC_Oo):
2151: /* FALLTHROUGH */
2152: case (MDOC_Op):
2153: /* FALLTHROUGH */
2154: case (MDOC_Bo):
2155: /* FALLTHROUGH */
2156: case (MDOC_Bq):
2157: print_text(h, "\\(rB");
2158: break;
2159: case (MDOC_Qo):
2160: /* FALLTHROUGH */
2161: case (MDOC_Qq):
2162: /* FALLTHROUGH */
2163: case (MDOC_Do):
2164: /* FALLTHROUGH */
2165: case (MDOC_Dq):
2166: print_text(h, "\\(rq");
2167: break;
2168: case (MDOC_Po):
2169: /* FALLTHROUGH */
2170: case (MDOC_Pq):
2171: print_text(h, ")");
2172: break;
2173: case (MDOC_Ql):
2174: /* FALLTHROUGH */
2175: case (MDOC_So):
2176: /* FALLTHROUGH */
2177: case (MDOC_Sq):
2178: print_text(h, "\\(aq");
2179: break;
2180: default:
2181: abort();
2182: /* NOTREACHED */
2183: }
2184: }
2185:
2186:
CVSweb