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