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