Annotation of mandoc/mdoc_html.c, Revision 1.149
1.149 ! kristaps 1: /* $Id: mdoc_html.c,v 1.148 2011/01/25 16:20:24 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:
783: h->flags |= HTML_NOSPACE;
784: return(1);
785: }
786:
787:
788: /* ARGSUSED */
789: static int
790: mdoc_ar_pre(MDOC_ARGS)
791: {
792: struct htmlpair tag;
793:
1.23 kristaps 794: PAIR_CLASS_INIT(&tag, "arg");
1.133 kristaps 795: print_otag(h, TAG_I, 1, &tag);
1.1 kristaps 796: return(1);
797: }
798:
799:
800: /* ARGSUSED */
801: static int
802: mdoc_xx_pre(MDOC_ARGS)
803: {
804: const char *pp;
805: struct htmlpair tag;
806:
807: switch (n->tok) {
808: case (MDOC_Bsx):
1.112 schwarze 809: pp = "BSD/OS";
1.1 kristaps 810: break;
811: case (MDOC_Dx):
1.45 kristaps 812: pp = "DragonFly";
1.1 kristaps 813: break;
814: case (MDOC_Fx):
815: pp = "FreeBSD";
816: break;
817: case (MDOC_Nx):
818: pp = "NetBSD";
819: break;
820: case (MDOC_Ox):
821: pp = "OpenBSD";
822: break;
823: case (MDOC_Ux):
824: pp = "UNIX";
825: break;
826: default:
827: return(1);
828: }
829:
1.23 kristaps 830: PAIR_CLASS_INIT(&tag, "unix");
1.1 kristaps 831: print_otag(h, TAG_SPAN, 1, &tag);
1.148 kristaps 832:
1.1 kristaps 833: print_text(h, pp);
1.148 kristaps 834: if (n->child) {
835: h->flags |= HTML_KEEP;
836: print_text(h, n->child->string);
837: h->flags &= ~HTML_KEEP;
838: }
839: return(0);
1.1 kristaps 840: }
841:
842:
843: /* ARGSUSED */
844: static int
1.4 kristaps 845: mdoc_bx_pre(MDOC_ARGS)
846: {
1.146 kristaps 847: struct htmlpair tag;
1.4 kristaps 848:
1.23 kristaps 849: PAIR_CLASS_INIT(&tag, "unix");
1.4 kristaps 850: print_otag(h, TAG_SPAN, 1, &tag);
851:
1.145 kristaps 852: if (NULL != (n = n->child)) {
853: print_text(h, n->string);
854: h->flags |= HTML_NOSPACE;
855: print_text(h, "BSD");
856: } else {
857: print_text(h, "BSD");
858: return(0);
859: }
1.4 kristaps 860:
1.145 kristaps 861: if (NULL != (n = n->next)) {
862: h->flags |= HTML_NOSPACE;
1.147 kristaps 863: print_text(h, "-");
1.4 kristaps 864: h->flags |= HTML_NOSPACE;
1.147 kristaps 865: print_text(h, n->string);
1.145 kristaps 866: }
1.4 kristaps 867:
868: return(0);
869: }
870:
1.142 kristaps 871: /* ARGSUSED */
1.4 kristaps 872: static int
1.115 kristaps 873: mdoc_it_pre(MDOC_ARGS)
1.1 kristaps 874: {
1.115 kristaps 875: struct roffsu su;
876: enum mdoc_list type;
1.116 kristaps 877: struct htmlpair tag[2];
1.115 kristaps 878: const struct mdoc_node *bl;
879:
880: bl = n->parent;
881: while (bl && MDOC_Bl != bl->tok)
882: bl = bl->parent;
1.23 kristaps 883:
1.115 kristaps 884: assert(bl);
1.23 kristaps 885:
1.137 kristaps 886: type = bl->norm->Bl.type;
1.24 kristaps 887:
1.116 kristaps 888: assert(lists[type]);
889: PAIR_CLASS_INIT(&tag[0], lists[type]);
1.1 kristaps 890:
1.115 kristaps 891: if (MDOC_HEAD == n->type) {
892: switch (type) {
893: case(LIST_bullet):
894: /* FALLTHROUGH */
895: case(LIST_dash):
896: /* FALLTHROUGH */
897: case(LIST_item):
898: /* FALLTHROUGH */
899: case(LIST_hyphen):
900: /* FALLTHROUGH */
901: case(LIST_enum):
902: return(0);
903: case(LIST_diag):
904: /* FALLTHROUGH */
905: case(LIST_hang):
906: /* FALLTHROUGH */
907: case(LIST_inset):
908: /* FALLTHROUGH */
909: case(LIST_ohang):
910: /* FALLTHROUGH */
911: case(LIST_tag):
1.137 kristaps 912: SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.122 kristaps 913: bufcat_su(h, "margin-top", &su);
914: PAIR_STYLE_INIT(&tag[1], h);
1.116 kristaps 915: print_otag(h, TAG_DT, 2, tag);
1.134 kristaps 916: if (LIST_diag != type)
917: break;
918: PAIR_CLASS_INIT(&tag[0], "diag");
919: print_otag(h, TAG_B, 1, tag);
1.115 kristaps 920: break;
921: case(LIST_column):
922: break;
923: default:
924: break;
925: }
926: } else if (MDOC_BODY == n->type) {
927: switch (type) {
928: case(LIST_bullet):
929: /* FALLTHROUGH */
930: case(LIST_hyphen):
931: /* FALLTHROUGH */
932: case(LIST_dash):
933: /* FALLTHROUGH */
934: case(LIST_enum):
935: /* FALLTHROUGH */
936: case(LIST_item):
1.137 kristaps 937: SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.122 kristaps 938: bufcat_su(h, "margin-top", &su);
939: PAIR_STYLE_INIT(&tag[1], h);
1.116 kristaps 940: print_otag(h, TAG_LI, 2, tag);
1.115 kristaps 941: break;
942: case(LIST_diag):
943: /* FALLTHROUGH */
944: case(LIST_hang):
945: /* FALLTHROUGH */
946: case(LIST_inset):
947: /* FALLTHROUGH */
948: case(LIST_ohang):
949: /* FALLTHROUGH */
950: case(LIST_tag):
1.137 kristaps 951: if (NULL == bl->norm->Bl.width) {
1.122 kristaps 952: print_otag(h, TAG_DD, 1, tag);
953: break;
954: }
1.137 kristaps 955: a2width(bl->norm->Bl.width, &su);
1.122 kristaps 956: bufcat_su(h, "margin-left", &su);
957: PAIR_STYLE_INIT(&tag[1], h);
958: print_otag(h, TAG_DD, 2, tag);
1.115 kristaps 959: break;
960: case(LIST_column):
1.137 kristaps 961: SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.122 kristaps 962: bufcat_su(h, "margin-top", &su);
963: PAIR_STYLE_INIT(&tag[1], h);
1.116 kristaps 964: print_otag(h, TAG_TD, 2, tag);
1.115 kristaps 965: break;
966: default:
967: break;
968: }
969: } else {
970: switch (type) {
971: case (LIST_column):
1.116 kristaps 972: print_otag(h, TAG_TR, 1, tag);
1.115 kristaps 973: break;
974: default:
1.23 kristaps 975: break;
1.115 kristaps 976: }
1.1 kristaps 977: }
978:
979: return(1);
980: }
981:
1.25 kristaps 982: /* ARGSUSED */
1.1 kristaps 983: static int
1.115 kristaps 984: mdoc_bl_pre(MDOC_ARGS)
1.1 kristaps 985: {
1.142 kristaps 986: int i;
1.119 kristaps 987: struct htmlpair tag[3];
1.23 kristaps 988: struct roffsu su;
1.134 kristaps 989: char buf[BUFSIZ];
1.23 kristaps 990:
1.115 kristaps 991: if (MDOC_BODY == n->type) {
1.137 kristaps 992: if (LIST_column == n->norm->Bl.type)
1.115 kristaps 993: print_otag(h, TAG_TBODY, 0, NULL);
994: return(1);
1.23 kristaps 995: }
1.1 kristaps 996:
1.115 kristaps 997: if (MDOC_HEAD == n->type) {
1.137 kristaps 998: if (LIST_column != n->norm->Bl.type)
1.115 kristaps 999: return(0);
1000:
1001: /*
1002: * For each column, print out the <COL> tag with our
1003: * suggested width. The last column gets min-width, as
1004: * in terminal mode it auto-sizes to the width of the
1005: * screen and we want to preserve that behaviour.
1006: */
1.1 kristaps 1007:
1.142 kristaps 1008: for (i = 0; i < (int)n->norm->Bl.ncols; i++) {
1.137 kristaps 1009: a2width(n->norm->Bl.cols[i], &su);
1.115 kristaps 1010: bufinit(h);
1.142 kristaps 1011: if (i < (int)n->norm->Bl.ncols - 1)
1.115 kristaps 1012: bufcat_su(h, "width", &su);
1013: else
1014: bufcat_su(h, "min-width", &su);
1015: PAIR_STYLE_INIT(&tag[0], h);
1016: print_otag(h, TAG_COL, 1, tag);
1017: }
1.1 kristaps 1018:
1019: return(0);
1020: }
1021:
1.119 kristaps 1022: SCALE_VS_INIT(&su, 0);
1023: bufcat_su(h, "margin-top", &su);
1024: bufcat_su(h, "margin-bottom", &su);
1025: PAIR_STYLE_INIT(&tag[0], h);
1026:
1.137 kristaps 1027: assert(lists[n->norm->Bl.type]);
1.134 kristaps 1028: strlcpy(buf, "list ", BUFSIZ);
1.137 kristaps 1029: strlcat(buf, lists[n->norm->Bl.type], BUFSIZ);
1.134 kristaps 1030: PAIR_INIT(&tag[1], ATTR_CLASS, buf);
1.1 kristaps 1031:
1.115 kristaps 1032: /* Set the block's left-hand margin. */
1.1 kristaps 1033:
1.137 kristaps 1034: if (n->norm->Bl.offs) {
1035: a2offs(n->norm->Bl.offs, &su);
1.115 kristaps 1036: bufcat_su(h, "margin-left", &su);
1037: }
1.1 kristaps 1038:
1.137 kristaps 1039: switch (n->norm->Bl.type) {
1.115 kristaps 1040: case(LIST_bullet):
1.1 kristaps 1041: /* FALLTHROUGH */
1.115 kristaps 1042: case(LIST_dash):
1.1 kristaps 1043: /* FALLTHROUGH */
1.115 kristaps 1044: case(LIST_hyphen):
1.1 kristaps 1045: /* FALLTHROUGH */
1.115 kristaps 1046: case(LIST_item):
1.134 kristaps 1047: print_otag(h, TAG_UL, 2, tag);
1.1 kristaps 1048: break;
1.115 kristaps 1049: case(LIST_enum):
1.134 kristaps 1050: print_otag(h, TAG_OL, 2, tag);
1.23 kristaps 1051: break;
1.115 kristaps 1052: case(LIST_diag):
1053: /* FALLTHROUGH */
1054: case(LIST_hang):
1.46 kristaps 1055: /* FALLTHROUGH */
1.115 kristaps 1056: case(LIST_inset):
1.33 kristaps 1057: /* FALLTHROUGH */
1.115 kristaps 1058: case(LIST_ohang):
1.1 kristaps 1059: /* FALLTHROUGH */
1.115 kristaps 1060: case(LIST_tag):
1.134 kristaps 1061: print_otag(h, TAG_DL, 2, tag);
1.115 kristaps 1062: break;
1063: case(LIST_column):
1.134 kristaps 1064: print_otag(h, TAG_TABLE, 2, tag);
1.1 kristaps 1065: break;
1066: default:
1.115 kristaps 1067: abort();
1068: /* NOTREACHED */
1.1 kristaps 1069: }
1070:
1071: return(1);
1072: }
1073:
1074: /* ARGSUSED */
1075: static int
1076: mdoc_ex_pre(MDOC_ARGS)
1077: {
1078: const struct mdoc_node *nn;
1079: struct tag *t;
1080: struct htmlpair tag;
1081:
1.127 kristaps 1082: if (n->prev)
1083: print_otag(h, TAG_BR, 0, NULL);
1084:
1.23 kristaps 1085: PAIR_CLASS_INIT(&tag, "utility");
1086:
1.1 kristaps 1087: print_text(h, "The");
1088: for (nn = n->child; nn; nn = nn->next) {
1.132 kristaps 1089: t = print_otag(h, TAG_B, 1, &tag);
1.1 kristaps 1090: print_text(h, nn->string);
1091: print_tagq(h, t);
1092:
1093: h->flags |= HTML_NOSPACE;
1094:
1095: if (nn->next && NULL == nn->next->next)
1096: print_text(h, ", and");
1097: else if (nn->next)
1098: print_text(h, ",");
1099: else
1100: h->flags &= ~HTML_NOSPACE;
1101: }
1102:
1.65 kristaps 1103: if (n->child && n->child->next)
1.1 kristaps 1104: print_text(h, "utilities exit");
1105: else
1106: print_text(h, "utility exits");
1107:
1108: print_text(h, "0 on success, and >0 if an error occurs.");
1109: return(0);
1110: }
1111:
1112:
1113: /* ARGSUSED */
1114: static int
1115: mdoc_em_pre(MDOC_ARGS)
1116: {
1117: struct htmlpair tag;
1118:
1.23 kristaps 1119: PAIR_CLASS_INIT(&tag, "emph");
1.1 kristaps 1120: print_otag(h, TAG_SPAN, 1, &tag);
1121: return(1);
1122: }
1123:
1124:
1125: /* ARGSUSED */
1126: static int
1127: mdoc_d1_pre(MDOC_ARGS)
1128: {
1.23 kristaps 1129: struct htmlpair tag[2];
1130: struct roffsu su;
1.1 kristaps 1131:
1132: if (MDOC_BLOCK != n->type)
1133: return(1);
1134:
1.118 kristaps 1135: SCALE_VS_INIT(&su, 0);
1136: bufcat_su(h, "margin-top", &su);
1137: bufcat_su(h, "margin-bottom", &su);
1138: PAIR_STYLE_INIT(&tag[0], h);
1.120 kristaps 1139: print_otag(h, TAG_BLOCKQUOTE, 1, tag);
1140:
1141: /* BLOCKQUOTE needs a block body. */
1.118 kristaps 1142:
1.136 kristaps 1143: PAIR_CLASS_INIT(&tag[0], "display");
1144: print_otag(h, TAG_DIV, 1, tag);
1145:
1.135 kristaps 1146: if (MDOC_Dl == n->tok) {
1.136 kristaps 1147: PAIR_CLASS_INIT(&tag[0], "lit");
1.135 kristaps 1148: print_otag(h, TAG_CODE, 1, tag);
1.136 kristaps 1149: }
1.35 kristaps 1150:
1.1 kristaps 1151: return(1);
1152: }
1153:
1154:
1155: /* ARGSUSED */
1156: static int
1157: mdoc_sx_pre(MDOC_ARGS)
1158: {
1.18 kristaps 1159: struct htmlpair tag[2];
1.1 kristaps 1160: const struct mdoc_node *nn;
1.35 kristaps 1161: char buf[BUFSIZ];
1.1 kristaps 1162:
1.41 kristaps 1163: strlcpy(buf, "#", BUFSIZ);
1.1 kristaps 1164: for (nn = n->child; nn; nn = nn->next) {
1.41 kristaps 1165: html_idcat(buf, nn->string, BUFSIZ);
1.1 kristaps 1166: if (nn->next)
1.42 kristaps 1167: html_idcat(buf, " ", BUFSIZ);
1.1 kristaps 1168: }
1169:
1.23 kristaps 1170: PAIR_CLASS_INIT(&tag[0], "link-sec");
1.57 kristaps 1171: PAIR_HREF_INIT(&tag[1], buf);
1.1 kristaps 1172:
1.134 kristaps 1173: print_otag(h, TAG_I, 1, tag);
1.18 kristaps 1174: print_otag(h, TAG_A, 2, tag);
1.1 kristaps 1175: return(1);
1176: }
1177:
1178:
1179: /* ARGSUSED */
1180: static int
1181: mdoc_bd_pre(MDOC_ARGS)
1182: {
1183: struct htmlpair tag[2];
1.149 ! kristaps 1184: int comp, sv;
1.80 kristaps 1185: const struct mdoc_node *nn;
1.23 kristaps 1186: struct roffsu su;
1.1 kristaps 1187:
1.80 kristaps 1188: if (MDOC_HEAD == n->type)
1.1 kristaps 1189: return(0);
1190:
1191: if (MDOC_BLOCK == n->type) {
1.137 kristaps 1192: comp = n->norm->Bd.comp;
1.23 kristaps 1193: for (nn = n; nn && ! comp; nn = nn->parent) {
1194: if (MDOC_BLOCK != nn->type)
1195: continue;
1196: if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
1197: comp = 1;
1198: if (nn->prev)
1199: break;
1200: }
1.126 kristaps 1201: if ( ! comp)
1202: print_otag(h, TAG_P, 0, NULL);
1.1 kristaps 1203: return(1);
1204: }
1205:
1.126 kristaps 1206: SCALE_HS_INIT(&su, 0);
1.137 kristaps 1207: if (n->norm->Bd.offs)
1208: a2offs(n->norm->Bd.offs, &su);
1.126 kristaps 1209:
1210: bufcat_su(h, "margin-left", &su);
1211: PAIR_STYLE_INIT(&tag[0], h);
1212:
1.137 kristaps 1213: if (DISP_unfilled != n->norm->Bd.type &&
1214: DISP_literal != n->norm->Bd.type) {
1.126 kristaps 1215: PAIR_CLASS_INIT(&tag[1], "display");
1216: print_otag(h, TAG_DIV, 2, tag);
1.1 kristaps 1217: return(1);
1.126 kristaps 1218: }
1.1 kristaps 1219:
1.126 kristaps 1220: PAIR_CLASS_INIT(&tag[1], "lit display");
1221: print_otag(h, TAG_PRE, 2, tag);
1.1 kristaps 1222:
1.149 ! kristaps 1223: /* This can be recursive: save & set our literal state. */
! 1224:
! 1225: sv = h->flags & HTML_LITERAL;
! 1226: h->flags |= HTML_LITERAL;
! 1227:
1.14 kristaps 1228: for (nn = n->child; nn; nn = nn->next) {
1229: print_mdoc_node(m, nn, h);
1.108 kristaps 1230: /*
1231: * If the printed node flushes its own line, then we
1232: * needn't do it here as well. This is hacky, but the
1233: * notion of selective eoln whitespace is pretty dumb
1234: * anyway, so don't sweat it.
1235: */
1236: switch (nn->tok) {
1.111 kristaps 1237: case (MDOC_Sm):
1238: /* FALLTHROUGH */
1.108 kristaps 1239: case (MDOC_br):
1240: /* FALLTHROUGH */
1241: case (MDOC_sp):
1242: /* FALLTHROUGH */
1243: case (MDOC_Bl):
1.114 kristaps 1244: /* FALLTHROUGH */
1245: case (MDOC_D1):
1246: /* FALLTHROUGH */
1247: case (MDOC_Dl):
1.108 kristaps 1248: /* FALLTHROUGH */
1249: case (MDOC_Lp):
1250: /* FALLTHROUGH */
1251: case (MDOC_Pp):
1252: continue;
1253: default:
1254: break;
1255: }
1.101 schwarze 1256: if (nn->next && nn->next->line == nn->line)
1257: continue;
1.126 kristaps 1258: else if (nn->next)
1259: print_text(h, "\n");
1.125 kristaps 1260:
1.101 schwarze 1261: h->flags |= HTML_NOSPACE;
1.1 kristaps 1262: }
1.149 ! kristaps 1263:
! 1264: if (0 == sv)
! 1265: h->flags &= ~HTML_LITERAL;
1.1 kristaps 1266:
1267: return(0);
1268: }
1269:
1270:
1271: /* ARGSUSED */
1272: static int
1273: mdoc_pa_pre(MDOC_ARGS)
1274: {
1275: struct htmlpair tag;
1276:
1.23 kristaps 1277: PAIR_CLASS_INIT(&tag, "file");
1.133 kristaps 1278: print_otag(h, TAG_I, 1, &tag);
1.1 kristaps 1279: return(1);
1280: }
1281:
1282:
1283: /* ARGSUSED */
1284: static int
1285: mdoc_ad_pre(MDOC_ARGS)
1286: {
1287: struct htmlpair tag;
1288:
1.23 kristaps 1289: PAIR_CLASS_INIT(&tag, "addr");
1.133 kristaps 1290: print_otag(h, TAG_I, 1, &tag);
1.1 kristaps 1291: return(1);
1292: }
1293:
1294:
1295: /* ARGSUSED */
1296: static int
1297: mdoc_an_pre(MDOC_ARGS)
1298: {
1299: struct htmlpair tag;
1300:
1.19 kristaps 1301: /* TODO: -split and -nosplit (see termp_an_pre()). */
1302:
1.23 kristaps 1303: PAIR_CLASS_INIT(&tag, "author");
1.1 kristaps 1304: print_otag(h, TAG_SPAN, 1, &tag);
1305: return(1);
1306: }
1307:
1308:
1309: /* ARGSUSED */
1310: static int
1311: mdoc_cd_pre(MDOC_ARGS)
1312: {
1313: struct htmlpair tag;
1314:
1.78 kristaps 1315: synopsis_pre(h, n);
1.23 kristaps 1316: PAIR_CLASS_INIT(&tag, "config");
1.132 kristaps 1317: print_otag(h, TAG_B, 1, &tag);
1.1 kristaps 1318: return(1);
1319: }
1320:
1321:
1322: /* ARGSUSED */
1323: static int
1324: mdoc_dv_pre(MDOC_ARGS)
1325: {
1326: struct htmlpair tag;
1327:
1.23 kristaps 1328: PAIR_CLASS_INIT(&tag, "define");
1.1 kristaps 1329: print_otag(h, TAG_SPAN, 1, &tag);
1330: return(1);
1331: }
1332:
1333:
1334: /* ARGSUSED */
1335: static int
1336: mdoc_ev_pre(MDOC_ARGS)
1337: {
1338: struct htmlpair tag;
1339:
1.23 kristaps 1340: PAIR_CLASS_INIT(&tag, "env");
1.1 kristaps 1341: print_otag(h, TAG_SPAN, 1, &tag);
1342: return(1);
1343: }
1344:
1345:
1346: /* ARGSUSED */
1347: static int
1348: mdoc_er_pre(MDOC_ARGS)
1349: {
1350: struct htmlpair tag;
1351:
1.23 kristaps 1352: PAIR_CLASS_INIT(&tag, "errno");
1.1 kristaps 1353: print_otag(h, TAG_SPAN, 1, &tag);
1354: return(1);
1355: }
1356:
1357:
1358: /* ARGSUSED */
1359: static int
1360: mdoc_fa_pre(MDOC_ARGS)
1361: {
1362: const struct mdoc_node *nn;
1363: struct htmlpair tag;
1364: struct tag *t;
1365:
1.23 kristaps 1366: PAIR_CLASS_INIT(&tag, "farg");
1.1 kristaps 1367: if (n->parent->tok != MDOC_Fo) {
1.133 kristaps 1368: print_otag(h, TAG_I, 1, &tag);
1.1 kristaps 1369: return(1);
1370: }
1371:
1372: for (nn = n->child; nn; nn = nn->next) {
1.133 kristaps 1373: t = print_otag(h, TAG_I, 1, &tag);
1.1 kristaps 1374: print_text(h, nn->string);
1375: print_tagq(h, t);
1376: if (nn->next)
1377: print_text(h, ",");
1378: }
1379:
1380: if (n->child && n->next && n->next->tok == MDOC_Fa)
1381: print_text(h, ",");
1382:
1383: return(0);
1384: }
1385:
1386:
1387: /* ARGSUSED */
1388: static int
1389: mdoc_fd_pre(MDOC_ARGS)
1390: {
1.23 kristaps 1391: struct htmlpair tag;
1.1 kristaps 1392:
1.78 kristaps 1393: synopsis_pre(h, n);
1394:
1.23 kristaps 1395: PAIR_CLASS_INIT(&tag, "macro");
1.132 kristaps 1396: print_otag(h, TAG_B, 1, &tag);
1.1 kristaps 1397: return(1);
1398: }
1399:
1400:
1401: /* ARGSUSED */
1402: static int
1403: mdoc_vt_pre(MDOC_ARGS)
1404: {
1.23 kristaps 1405: struct htmlpair tag;
1.1 kristaps 1406:
1.78 kristaps 1407: if (MDOC_BLOCK == n->type) {
1408: synopsis_pre(h, n);
1.54 kristaps 1409: return(1);
1.78 kristaps 1410: } else if (MDOC_ELEM == n->type) {
1411: synopsis_pre(h, n);
1.54 kristaps 1412: } else if (MDOC_HEAD == n->type)
1413: return(0);
1.1 kristaps 1414:
1.23 kristaps 1415: PAIR_CLASS_INIT(&tag, "type");
1.1 kristaps 1416: print_otag(h, TAG_SPAN, 1, &tag);
1417: return(1);
1418: }
1419:
1.2 kristaps 1420:
1.1 kristaps 1421: /* ARGSUSED */
1422: static int
1423: mdoc_ft_pre(MDOC_ARGS)
1424: {
1.23 kristaps 1425: struct htmlpair tag;
1.1 kristaps 1426:
1.78 kristaps 1427: synopsis_pre(h, n);
1.23 kristaps 1428: PAIR_CLASS_INIT(&tag, "ftype");
1.133 kristaps 1429: print_otag(h, TAG_I, 1, &tag);
1.1 kristaps 1430: return(1);
1431: }
1432:
1433:
1434: /* ARGSUSED */
1435: static int
1436: mdoc_fn_pre(MDOC_ARGS)
1437: {
1438: struct tag *t;
1.15 kristaps 1439: struct htmlpair tag[2];
1.1 kristaps 1440: const struct mdoc_node *nn;
1.7 kristaps 1441: char nbuf[BUFSIZ];
1442: const char *sp, *ep;
1.15 kristaps 1443: int sz, i;
1.1 kristaps 1444:
1.78 kristaps 1445: synopsis_pre(h, n);
1.1 kristaps 1446:
1.7 kristaps 1447: /* Split apart into type and name. */
1448: assert(n->child->string);
1449: sp = n->child->string;
1.19 kristaps 1450:
1.26 kristaps 1451: ep = strchr(sp, ' ');
1452: if (NULL != ep) {
1.23 kristaps 1453: PAIR_CLASS_INIT(&tag[0], "ftype");
1.133 kristaps 1454: t = print_otag(h, TAG_I, 1, tag);
1.19 kristaps 1455:
1456: while (ep) {
1457: sz = MIN((int)(ep - sp), BUFSIZ - 1);
1458: (void)memcpy(nbuf, sp, (size_t)sz);
1459: nbuf[sz] = '\0';
1460: print_text(h, nbuf);
1461: sp = ++ep;
1462: ep = strchr(sp, ' ');
1463: }
1464: print_tagq(h, t);
1.7 kristaps 1465: }
1.1 kristaps 1466:
1.23 kristaps 1467: PAIR_CLASS_INIT(&tag[0], "fname");
1.57 kristaps 1468:
1469: /*
1470: * FIXME: only refer to IDs that we know exist.
1471: */
1472:
1473: #if 0
1.87 kristaps 1474: if (MDOC_SYNPRETTY & n->flags) {
1.57 kristaps 1475: nbuf[0] = '\0';
1476: html_idcat(nbuf, sp, BUFSIZ);
1477: PAIR_ID_INIT(&tag[1], nbuf);
1478: } else {
1479: strlcpy(nbuf, "#", BUFSIZ);
1480: html_idcat(nbuf, sp, BUFSIZ);
1481: PAIR_HREF_INIT(&tag[1], nbuf);
1482: }
1483: #endif
1484:
1.132 kristaps 1485: t = print_otag(h, TAG_B, 1, tag);
1.7 kristaps 1486:
1487: if (sp) {
1.57 kristaps 1488: strlcpy(nbuf, sp, BUFSIZ);
1.7 kristaps 1489: print_text(h, nbuf);
1490: }
1491:
1.1 kristaps 1492: print_tagq(h, t);
1493:
1494: h->flags |= HTML_NOSPACE;
1495: print_text(h, "(");
1496:
1.23 kristaps 1497: bufinit(h);
1498: PAIR_CLASS_INIT(&tag[0], "farg");
1499: bufcat_style(h, "white-space", "nowrap");
1500: PAIR_STYLE_INIT(&tag[1], h);
1501:
1.1 kristaps 1502: for (nn = n->child->next; nn; nn = nn->next) {
1.23 kristaps 1503: i = 1;
1.87 kristaps 1504: if (MDOC_SYNPRETTY & n->flags)
1.23 kristaps 1505: i = 2;
1.133 kristaps 1506: t = print_otag(h, TAG_I, i, tag);
1.1 kristaps 1507: print_text(h, nn->string);
1508: print_tagq(h, t);
1509: if (nn->next)
1510: print_text(h, ",");
1511: }
1512:
1513: print_text(h, ")");
1.87 kristaps 1514: if (MDOC_SYNPRETTY & n->flags)
1.1 kristaps 1515: print_text(h, ";");
1.99 kristaps 1516:
1517: return(0);
1518: }
1519:
1520:
1521: /* ARGSUSED */
1522: static int
1523: mdoc_sm_pre(MDOC_ARGS)
1524: {
1525:
1526: assert(n->child && MDOC_TEXT == n->child->type);
1527: if (0 == strcmp("on", n->child->string)) {
1.111 kristaps 1528: /*
1529: * FIXME: no p->col to check. Thus, if we have
1530: * .Bd -literal
1531: * .Sm off
1532: * 1 2
1533: * .Sm on
1534: * 3
1535: * .Ed
1536: * the "3" is preceded by a space.
1537: */
1.99 kristaps 1538: h->flags &= ~HTML_NOSPACE;
1539: h->flags &= ~HTML_NONOSPACE;
1540: } else
1541: h->flags |= HTML_NONOSPACE;
1.1 kristaps 1542:
1543: return(0);
1544: }
1545:
1.120 kristaps 1546: /* ARGSUSED */
1547: static int
1548: mdoc_pp_pre(MDOC_ARGS)
1549: {
1550:
1551: print_otag(h, TAG_P, 0, NULL);
1552: return(0);
1553:
1554: }
1.1 kristaps 1555:
1556: /* ARGSUSED */
1557: static int
1558: mdoc_sp_pre(MDOC_ARGS)
1559: {
1.120 kristaps 1560: struct roffsu su;
1.23 kristaps 1561: struct htmlpair tag;
1.1 kristaps 1562:
1.120 kristaps 1563: SCALE_VS_INIT(&su, 1);
1564:
1565: if (MDOC_sp == n->tok) {
1566: if (n->child)
1567: a2roffsu(n->child->string, &su, SCALE_VS);
1568: } else
1569: su.scale = 0;
1.1 kristaps 1570:
1.23 kristaps 1571: bufcat_su(h, "height", &su);
1572: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1573: print_otag(h, TAG_DIV, 1, &tag);
1.120 kristaps 1574:
1.42 kristaps 1575: /* So the div isn't empty: */
1576: print_text(h, "\\~");
1577:
1578: return(0);
1.1 kristaps 1579:
1580: }
1.2 kristaps 1581:
1582: /* ARGSUSED */
1583: static int
1584: mdoc_lk_pre(MDOC_ARGS)
1585: {
1586: const struct mdoc_node *nn;
1587: struct htmlpair tag[2];
1588:
1589: nn = n->child;
1590:
1.23 kristaps 1591: PAIR_CLASS_INIT(&tag[0], "link-ext");
1.57 kristaps 1592: PAIR_HREF_INIT(&tag[1], nn->string);
1.2 kristaps 1593: print_otag(h, TAG_A, 2, tag);
1594:
1.113 kristaps 1595: if (NULL == nn || NULL == nn->next)
1.38 kristaps 1596: return(1);
1597:
1.2 kristaps 1598: for (nn = nn->next; nn; nn = nn->next)
1599: print_text(h, nn->string);
1600:
1601: return(0);
1602: }
1603:
1604:
1605: /* ARGSUSED */
1606: static int
1607: mdoc_mt_pre(MDOC_ARGS)
1608: {
1609: struct htmlpair tag[2];
1610: struct tag *t;
1611: const struct mdoc_node *nn;
1612:
1.23 kristaps 1613: PAIR_CLASS_INIT(&tag[0], "link-mail");
1.2 kristaps 1614:
1615: for (nn = n->child; nn; nn = nn->next) {
1.16 kristaps 1616: bufinit(h);
1617: bufcat(h, "mailto:");
1618: bufcat(h, nn->string);
1.57 kristaps 1619: PAIR_HREF_INIT(&tag[1], h->buf);
1.2 kristaps 1620: t = print_otag(h, TAG_A, 2, tag);
1621: print_text(h, nn->string);
1622: print_tagq(h, t);
1623: }
1624:
1625: return(0);
1626: }
1.4 kristaps 1627:
1628:
1629: /* ARGSUSED */
1630: static int
1631: mdoc_fo_pre(MDOC_ARGS)
1632: {
1.77 kristaps 1633: struct htmlpair tag;
1634: struct tag *t;
1.4 kristaps 1635:
1636: if (MDOC_BODY == n->type) {
1637: h->flags |= HTML_NOSPACE;
1638: print_text(h, "(");
1639: h->flags |= HTML_NOSPACE;
1640: return(1);
1.77 kristaps 1641: } else if (MDOC_BLOCK == n->type) {
1.78 kristaps 1642: synopsis_pre(h, n);
1.4 kristaps 1643: return(1);
1.57 kristaps 1644: }
1.4 kristaps 1645:
1.77 kristaps 1646: /* XXX: we drop non-initial arguments as per groff. */
1647:
1648: assert(n->child);
1649: assert(n->child->string);
1650:
1.23 kristaps 1651: PAIR_CLASS_INIT(&tag, "fname");
1.139 kristaps 1652: t = print_otag(h, TAG_B, 1, &tag);
1.77 kristaps 1653: print_text(h, n->child->string);
1654: print_tagq(h, t);
1655: return(0);
1.4 kristaps 1656: }
1657:
1658:
1659: /* ARGSUSED */
1660: static void
1661: mdoc_fo_post(MDOC_ARGS)
1662: {
1.78 kristaps 1663:
1.4 kristaps 1664: if (MDOC_BODY != n->type)
1665: return;
1666: print_text(h, ")");
1667: print_text(h, ";");
1668: }
1669:
1670:
1671: /* ARGSUSED */
1672: static int
1673: mdoc_in_pre(MDOC_ARGS)
1674: {
1675: const struct mdoc_node *nn;
1.23 kristaps 1676: struct tag *t;
1.17 kristaps 1677: struct htmlpair tag[2];
1678: int i;
1.34 kristaps 1679:
1.78 kristaps 1680: synopsis_pre(h, n);
1681:
1.23 kristaps 1682: PAIR_CLASS_INIT(&tag[0], "includes");
1.132 kristaps 1683: print_otag(h, TAG_B, 1, tag);
1.4 kristaps 1684:
1.87 kristaps 1685: if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
1.4 kristaps 1686: print_text(h, "#include");
1687:
1688: print_text(h, "<");
1689: h->flags |= HTML_NOSPACE;
1690:
1.17 kristaps 1691: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1692: PAIR_CLASS_INIT(&tag[0], "link-includes");
1693: i = 1;
1.41 kristaps 1694: bufinit(h);
1.17 kristaps 1695: if (h->base_includes) {
1696: buffmt_includes(h, nn->string);
1.57 kristaps 1697: PAIR_HREF_INIT(&tag[i], h->buf);
1698: i++;
1.17 kristaps 1699: }
1700: t = print_otag(h, TAG_A, i, tag);
1.4 kristaps 1701: print_mdoc_node(m, nn, h);
1.17 kristaps 1702: print_tagq(h, t);
1703: }
1.4 kristaps 1704:
1705: h->flags |= HTML_NOSPACE;
1706: print_text(h, ">");
1707:
1708: return(0);
1709: }
1710:
1711:
1712: /* ARGSUSED */
1713: static int
1714: mdoc_ic_pre(MDOC_ARGS)
1715: {
1716: struct htmlpair tag;
1717:
1.23 kristaps 1718: PAIR_CLASS_INIT(&tag, "cmd");
1.132 kristaps 1719: print_otag(h, TAG_B, 1, &tag);
1.4 kristaps 1720: return(1);
1721: }
1722:
1723:
1724: /* ARGSUSED */
1725: static int
1726: mdoc_rv_pre(MDOC_ARGS)
1727: {
1728: const struct mdoc_node *nn;
1729: struct htmlpair tag;
1730: struct tag *t;
1731:
1.127 kristaps 1732: if (n->prev)
1733: print_otag(h, TAG_BR, 0, NULL);
1734:
1.4 kristaps 1735: print_text(h, "The");
1736:
1737: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1738: PAIR_CLASS_INIT(&tag, "fname");
1.139 kristaps 1739: t = print_otag(h, TAG_B, 1, &tag);
1.4 kristaps 1740: print_text(h, nn->string);
1741: print_tagq(h, t);
1742:
1743: h->flags |= HTML_NOSPACE;
1744: if (nn->next && NULL == nn->next->next)
1745: print_text(h, "(), and");
1746: else if (nn->next)
1747: print_text(h, "(),");
1748: else
1749: print_text(h, "()");
1750: }
1751:
1.65 kristaps 1752: if (n->child && n->child->next)
1.4 kristaps 1753: print_text(h, "functions return");
1754: else
1755: print_text(h, "function returns");
1756:
1757: print_text(h, "the value 0 if successful; otherwise the value "
1758: "-1 is returned and the global variable");
1759:
1.23 kristaps 1760: PAIR_CLASS_INIT(&tag, "var");
1.132 kristaps 1761: t = print_otag(h, TAG_B, 1, &tag);
1.4 kristaps 1762: print_text(h, "errno");
1763: print_tagq(h, t);
1764: print_text(h, "is set to indicate the error.");
1765: return(0);
1766: }
1767:
1768:
1769: /* ARGSUSED */
1770: static int
1771: mdoc_va_pre(MDOC_ARGS)
1772: {
1773: struct htmlpair tag;
1774:
1.23 kristaps 1775: PAIR_CLASS_INIT(&tag, "var");
1.132 kristaps 1776: print_otag(h, TAG_B, 1, &tag);
1.4 kristaps 1777: return(1);
1778: }
1779:
1780:
1781: /* ARGSUSED */
1782: static int
1.5 kristaps 1783: mdoc_ap_pre(MDOC_ARGS)
1784: {
1785:
1786: h->flags |= HTML_NOSPACE;
1787: print_text(h, "\\(aq");
1788: h->flags |= HTML_NOSPACE;
1789: return(1);
1790: }
1791:
1792:
1793: /* ARGSUSED */
1794: static int
1795: mdoc_bf_pre(MDOC_ARGS)
1796: {
1.23 kristaps 1797: struct htmlpair tag[2];
1798: struct roffsu su;
1.5 kristaps 1799:
1800: if (MDOC_HEAD == n->type)
1801: return(0);
1.92 kristaps 1802: else if (MDOC_BODY != n->type)
1.5 kristaps 1803: return(1);
1804:
1.137 kristaps 1805: if (FONT_Em == n->norm->Bf.font)
1.92 kristaps 1806: PAIR_CLASS_INIT(&tag[0], "emph");
1.137 kristaps 1807: else if (FONT_Sy == n->norm->Bf.font)
1.92 kristaps 1808: PAIR_CLASS_INIT(&tag[0], "symb");
1.137 kristaps 1809: else if (FONT_Li == n->norm->Bf.font)
1.92 kristaps 1810: PAIR_CLASS_INIT(&tag[0], "lit");
1811: else
1812: PAIR_CLASS_INIT(&tag[0], "none");
1.5 kristaps 1813:
1.92 kristaps 1814: /*
1815: * We want this to be inline-formatted, but needs to be div to
1816: * accept block children.
1817: */
1.23 kristaps 1818: bufcat_style(h, "display", "inline");
1819: SCALE_HS_INIT(&su, 1);
1.92 kristaps 1820: /* Needs a left-margin for spacing. */
1821: bufcat_su(h, "margin-left", &su);
1.23 kristaps 1822: PAIR_STYLE_INIT(&tag[1], h);
1.5 kristaps 1823: print_otag(h, TAG_DIV, 2, tag);
1824: return(1);
1825: }
1826:
1827:
1828: /* ARGSUSED */
1829: static int
1830: mdoc_ms_pre(MDOC_ARGS)
1831: {
1832: struct htmlpair tag;
1833:
1.23 kristaps 1834: PAIR_CLASS_INIT(&tag, "symb");
1.5 kristaps 1835: print_otag(h, TAG_SPAN, 1, &tag);
1836: return(1);
1837: }
1838:
1839:
1840: /* ARGSUSED */
1841: static int
1.110 schwarze 1842: mdoc_igndelim_pre(MDOC_ARGS)
1.5 kristaps 1843: {
1844:
1845: h->flags |= HTML_IGNDELIM;
1846: return(1);
1847: }
1848:
1849:
1850: /* ARGSUSED */
1851: static void
1852: mdoc_pf_post(MDOC_ARGS)
1853: {
1854:
1855: h->flags |= HTML_NOSPACE;
1856: }
1857:
1858:
1859: /* ARGSUSED */
1860: static int
1861: mdoc_rs_pre(MDOC_ARGS)
1862: {
1.23 kristaps 1863: struct htmlpair tag;
1.5 kristaps 1864:
1865: if (MDOC_BLOCK != n->type)
1866: return(1);
1867:
1.120 kristaps 1868: if (n->prev && SEC_SEE_ALSO == n->sec)
1869: print_otag(h, TAG_P, 0, NULL);
1.5 kristaps 1870:
1.23 kristaps 1871: PAIR_CLASS_INIT(&tag, "ref");
1.8 kristaps 1872: print_otag(h, TAG_SPAN, 1, &tag);
1.5 kristaps 1873: return(1);
1874: }
1.6 kristaps 1875:
1876:
1877:
1878: /* ARGSUSED */
1879: static int
1880: mdoc_li_pre(MDOC_ARGS)
1881: {
1882: struct htmlpair tag;
1883:
1.23 kristaps 1884: PAIR_CLASS_INIT(&tag, "lit");
1.6 kristaps 1885: print_otag(h, TAG_SPAN, 1, &tag);
1886: return(1);
1887: }
1888:
1889:
1890: /* ARGSUSED */
1891: static int
1892: mdoc_sy_pre(MDOC_ARGS)
1893: {
1894: struct htmlpair tag;
1895:
1.23 kristaps 1896: PAIR_CLASS_INIT(&tag, "symb");
1.6 kristaps 1897: print_otag(h, TAG_SPAN, 1, &tag);
1898: return(1);
1899: }
1900:
1901:
1902: /* ARGSUSED */
1903: static int
1904: mdoc_bt_pre(MDOC_ARGS)
1905: {
1906:
1907: print_text(h, "is currently in beta test.");
1908: return(0);
1909: }
1910:
1911:
1912: /* ARGSUSED */
1913: static int
1914: mdoc_ud_pre(MDOC_ARGS)
1915: {
1916:
1917: print_text(h, "currently under development.");
1918: return(0);
1919: }
1920:
1921:
1922: /* ARGSUSED */
1923: static int
1924: mdoc_lb_pre(MDOC_ARGS)
1925: {
1926: struct htmlpair tag;
1927:
1.127 kristaps 1928: if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags && n->prev)
1929: print_otag(h, TAG_BR, 0, NULL);
1930:
1.23 kristaps 1931: PAIR_CLASS_INIT(&tag, "lib");
1.6 kristaps 1932: print_otag(h, TAG_SPAN, 1, &tag);
1933: return(1);
1934: }
1.10 kristaps 1935:
1936:
1937: /* ARGSUSED */
1938: static int
1939: mdoc__x_pre(MDOC_ARGS)
1940: {
1.38 kristaps 1941: struct htmlpair tag[2];
1.133 kristaps 1942: enum htmltag t;
1943:
1944: t = TAG_SPAN;
1.37 kristaps 1945:
1.10 kristaps 1946: switch (n->tok) {
1947: case(MDOC__A):
1.38 kristaps 1948: PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.103 kristaps 1949: if (n->prev && MDOC__A == n->prev->tok)
1950: if (NULL == n->next || MDOC__A != n->next->tok)
1951: print_text(h, "and");
1.10 kristaps 1952: break;
1953: case(MDOC__B):
1.38 kristaps 1954: PAIR_CLASS_INIT(&tag[0], "ref-book");
1.133 kristaps 1955: t = TAG_I;
1.10 kristaps 1956: break;
1957: case(MDOC__C):
1.38 kristaps 1958: PAIR_CLASS_INIT(&tag[0], "ref-city");
1.10 kristaps 1959: break;
1960: case(MDOC__D):
1.38 kristaps 1961: PAIR_CLASS_INIT(&tag[0], "ref-date");
1.10 kristaps 1962: break;
1963: case(MDOC__I):
1.38 kristaps 1964: PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.133 kristaps 1965: t = TAG_I;
1.10 kristaps 1966: break;
1967: case(MDOC__J):
1.38 kristaps 1968: PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.133 kristaps 1969: t = TAG_I;
1.10 kristaps 1970: break;
1971: case(MDOC__N):
1.38 kristaps 1972: PAIR_CLASS_INIT(&tag[0], "ref-num");
1.10 kristaps 1973: break;
1974: case(MDOC__O):
1.38 kristaps 1975: PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.10 kristaps 1976: break;
1977: case(MDOC__P):
1.38 kristaps 1978: PAIR_CLASS_INIT(&tag[0], "ref-page");
1.10 kristaps 1979: break;
1980: case(MDOC__Q):
1.38 kristaps 1981: PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.10 kristaps 1982: break;
1983: case(MDOC__R):
1.38 kristaps 1984: PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.10 kristaps 1985: break;
1986: case(MDOC__T):
1.38 kristaps 1987: PAIR_CLASS_INIT(&tag[0], "ref-title");
1.10 kristaps 1988: break;
1.38 kristaps 1989: case(MDOC__U):
1990: PAIR_CLASS_INIT(&tag[0], "link-ref");
1991: break;
1.10 kristaps 1992: case(MDOC__V):
1.38 kristaps 1993: PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.10 kristaps 1994: break;
1995: default:
1996: abort();
1997: /* NOTREACHED */
1998: }
1999:
1.38 kristaps 2000: if (MDOC__U != n->tok) {
1.133 kristaps 2001: print_otag(h, t, 1, tag);
1.38 kristaps 2002: return(1);
2003: }
2004:
2005: PAIR_HREF_INIT(&tag[1], n->child->string);
2006: print_otag(h, TAG_A, 2, tag);
1.103 kristaps 2007:
1.10 kristaps 2008: return(1);
2009: }
2010:
2011:
2012: /* ARGSUSED */
2013: static void
2014: mdoc__x_post(MDOC_ARGS)
2015: {
1.103 kristaps 2016:
2017: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
2018: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
2019: if (NULL == n->prev || MDOC__A != n->prev->tok)
2020: return;
1.10 kristaps 2021:
1.61 kristaps 2022: /* TODO: %U */
2023:
1.106 kristaps 2024: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
2025: return;
2026:
1.10 kristaps 2027: print_text(h, n->next ? "," : ".");
1.94 kristaps 2028: }
2029:
2030:
2031: /* ARGSUSED */
2032: static int
2033: mdoc_bk_pre(MDOC_ARGS)
2034: {
2035:
2036: switch (n->type) {
2037: case (MDOC_BLOCK):
2038: break;
2039: case (MDOC_HEAD):
2040: return(0);
2041: case (MDOC_BODY):
1.131 kristaps 2042: if (n->parent->args || 0 == n->prev->nchild)
2043: h->flags |= HTML_PREKEEP;
1.94 kristaps 2044: break;
2045: default:
2046: abort();
2047: /* NOTREACHED */
2048: }
2049:
2050: return(1);
2051: }
2052:
2053:
2054: /* ARGSUSED */
2055: static void
2056: mdoc_bk_post(MDOC_ARGS)
2057: {
2058:
2059: if (MDOC_BODY == n->type)
2060: h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1.10 kristaps 2061: }
1.107 kristaps 2062:
2063:
2064: /* ARGSUSED */
2065: static int
2066: mdoc_quote_pre(MDOC_ARGS)
2067: {
2068: struct htmlpair tag;
2069:
2070: if (MDOC_BODY != n->type)
2071: return(1);
2072:
2073: switch (n->tok) {
2074: case (MDOC_Ao):
2075: /* FALLTHROUGH */
2076: case (MDOC_Aq):
2077: print_text(h, "\\(la");
2078: break;
2079: case (MDOC_Bro):
2080: /* FALLTHROUGH */
2081: case (MDOC_Brq):
2082: print_text(h, "\\(lC");
2083: break;
2084: case (MDOC_Bo):
2085: /* FALLTHROUGH */
2086: case (MDOC_Bq):
2087: print_text(h, "\\(lB");
2088: break;
2089: case (MDOC_Oo):
2090: /* FALLTHROUGH */
2091: case (MDOC_Op):
2092: print_text(h, "\\(lB");
1.109 kristaps 2093: h->flags |= HTML_NOSPACE;
1.107 kristaps 2094: PAIR_CLASS_INIT(&tag, "opt");
2095: print_otag(h, TAG_SPAN, 1, &tag);
2096: break;
2097: case (MDOC_Do):
2098: /* FALLTHROUGH */
2099: case (MDOC_Dq):
2100: /* FALLTHROUGH */
2101: case (MDOC_Qo):
2102: /* FALLTHROUGH */
2103: case (MDOC_Qq):
2104: print_text(h, "\\(lq");
2105: break;
2106: case (MDOC_Po):
2107: /* FALLTHROUGH */
2108: case (MDOC_Pq):
2109: print_text(h, "(");
2110: break;
2111: case (MDOC_Ql):
2112: /* FALLTHROUGH */
2113: case (MDOC_So):
2114: /* FALLTHROUGH */
2115: case (MDOC_Sq):
2116: print_text(h, "\\(oq");
2117: break;
2118: default:
2119: abort();
2120: /* NOTREACHED */
2121: }
2122:
2123: h->flags |= HTML_NOSPACE;
2124: return(1);
2125: }
2126:
2127:
2128: /* ARGSUSED */
2129: static void
2130: mdoc_quote_post(MDOC_ARGS)
2131: {
2132:
2133: if (MDOC_BODY != n->type)
2134: return;
2135:
2136: h->flags |= HTML_NOSPACE;
2137:
2138: switch (n->tok) {
2139: case (MDOC_Ao):
2140: /* FALLTHROUGH */
2141: case (MDOC_Aq):
2142: print_text(h, "\\(ra");
2143: break;
2144: case (MDOC_Bro):
2145: /* FALLTHROUGH */
2146: case (MDOC_Brq):
2147: print_text(h, "\\(rC");
2148: break;
2149: case (MDOC_Oo):
2150: /* FALLTHROUGH */
2151: case (MDOC_Op):
2152: /* FALLTHROUGH */
2153: case (MDOC_Bo):
2154: /* FALLTHROUGH */
2155: case (MDOC_Bq):
2156: print_text(h, "\\(rB");
2157: break;
2158: case (MDOC_Qo):
2159: /* FALLTHROUGH */
2160: case (MDOC_Qq):
2161: /* FALLTHROUGH */
2162: case (MDOC_Do):
2163: /* FALLTHROUGH */
2164: case (MDOC_Dq):
2165: print_text(h, "\\(rq");
2166: break;
2167: case (MDOC_Po):
2168: /* FALLTHROUGH */
2169: case (MDOC_Pq):
2170: print_text(h, ")");
2171: break;
2172: case (MDOC_Ql):
2173: /* FALLTHROUGH */
2174: case (MDOC_So):
2175: /* FALLTHROUGH */
2176: case (MDOC_Sq):
2177: print_text(h, "\\(aq");
2178: break;
2179: default:
2180: abort();
2181: /* NOTREACHED */
2182: }
2183: }
2184:
2185:
CVSweb