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