Annotation of mandoc/mdoc_html.c, Revision 1.50
1.50 ! kristaps 1: /* $Id: mdoc_html.c,v 1.49 2009/12/02 10:16:55 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);
1.48 kristaps 427: return;
1.1 kristaps 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: default:
445: if (mdocs[n->tok].post)
446: (*mdocs[n->tok].post)(m, n, h);
447: break;
448: }
449: }
450:
451:
452: /* ARGSUSED */
453: static void
454: mdoc_root_post(MDOC_ARGS)
455: {
1.40 kristaps 456: struct htmlpair tag[3];
1.1 kristaps 457: struct tag *t, *tt;
1.36 kristaps 458: char b[DATESIZ];
459:
460: time2a(m->date, b, DATESIZ);
1.1 kristaps 461:
1.23 kristaps 462: /*
463: * XXX: this should use divs, but in Firefox, divs with nested
464: * divs for some reason puke when trying to put a border line
465: * below. So I use tables, instead.
466: */
467:
468: PAIR_CLASS_INIT(&tag[0], "footer");
469: bufcat_style(h, "width", "100%");
470: PAIR_STYLE_INIT(&tag[1], h);
1.40 kristaps 471: PAIR_SUMMARY_INIT(&tag[2], "footer");
472:
473: t = print_otag(h, TAG_TABLE, 3, tag);
1.1 kristaps 474: tt = print_otag(h, TAG_TR, 0, NULL);
475:
1.23 kristaps 476: bufinit(h);
477: bufcat_style(h, "width", "50%");
478: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 479: print_otag(h, TAG_TD, 1, tag);
480: print_text(h, b);
481: print_stagq(h, tt);
482:
1.23 kristaps 483: bufinit(h);
484: bufcat_style(h, "width", "50%");
485: bufcat_style(h, "text-align", "right");
486: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 487: print_otag(h, TAG_TD, 1, tag);
488: print_text(h, m->os);
489: print_tagq(h, t);
490: }
491:
492:
493: /* ARGSUSED */
494: static int
495: mdoc_root_pre(MDOC_ARGS)
496: {
1.40 kristaps 497: struct htmlpair tag[3];
1.1 kristaps 498: struct tag *t, *tt;
499: char b[BUFSIZ], title[BUFSIZ];
500:
501: (void)strlcpy(b, m->vol, BUFSIZ);
502:
503: if (m->arch) {
504: (void)strlcat(b, " (", BUFSIZ);
505: (void)strlcat(b, m->arch, BUFSIZ);
506: (void)strlcat(b, ")", BUFSIZ);
507: }
508:
509: (void)snprintf(title, BUFSIZ - 1,
510: "%s(%d)", m->title, m->msec);
511:
1.23 kristaps 512: /* XXX: see note in mdoc_root_post() about divs. */
513:
514: PAIR_CLASS_INIT(&tag[0], "header");
515: bufcat_style(h, "width", "100%");
516: PAIR_STYLE_INIT(&tag[1], h);
1.40 kristaps 517: PAIR_SUMMARY_INIT(&tag[2], "header");
518:
519: t = print_otag(h, TAG_TABLE, 3, tag);
520:
1.1 kristaps 521: tt = print_otag(h, TAG_TR, 0, NULL);
522:
1.23 kristaps 523: bufinit(h);
524: bufcat_style(h, "width", "10%");
525: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 526: print_otag(h, TAG_TD, 1, tag);
1.2 kristaps 527: print_text(h, title);
1.1 kristaps 528: print_stagq(h, tt);
529:
1.23 kristaps 530: bufinit(h);
531: bufcat_style(h, "text-align", "center");
532: bufcat_style(h, "white-space", "nowrap");
533: bufcat_style(h, "width", "80%");
534: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 535: print_otag(h, TAG_TD, 1, tag);
1.2 kristaps 536: print_text(h, b);
1.1 kristaps 537: print_stagq(h, tt);
538:
1.23 kristaps 539: bufinit(h);
540: bufcat_style(h, "text-align", "right");
541: bufcat_style(h, "width", "10%");
542: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 543: print_otag(h, TAG_TD, 1, tag);
1.2 kristaps 544: print_text(h, title);
1.1 kristaps 545: print_tagq(h, t);
546: return(1);
547: }
548:
549:
550: /* ARGSUSED */
551: static int
552: mdoc_sh_pre(MDOC_ARGS)
553: {
554: struct htmlpair tag[2];
555: const struct mdoc_node *nn;
1.41 kristaps 556: char buf[BUFSIZ];
1.23 kristaps 557: struct roffsu su;
1.21 kristaps 558:
559: if (MDOC_BODY == n->type) {
1.23 kristaps 560: SCALE_HS_INIT(&su, INDENT);
561: bufcat_su(h, "margin-left", &su);
562: PAIR_CLASS_INIT(&tag[0], "sec-body");
563: PAIR_STYLE_INIT(&tag[1], h);
1.21 kristaps 564: print_otag(h, TAG_DIV, 2, tag);
1.1 kristaps 565: return(1);
566: } else if (MDOC_BLOCK == n->type) {
1.23 kristaps 567: PAIR_CLASS_INIT(&tag[0], "sec-block");
1.1 kristaps 568: if (n->prev && NULL == n->prev->body->child) {
569: print_otag(h, TAG_DIV, 1, tag);
570: return(1);
571: }
1.23 kristaps 572:
573: SCALE_VS_INIT(&su, 1);
574: bufcat_su(h, "margin-top", &su);
1.1 kristaps 575: if (NULL == n->next)
1.23 kristaps 576: bufcat_su(h, "margin-bottom", &su);
1.1 kristaps 577:
1.23 kristaps 578: PAIR_STYLE_INIT(&tag[1], h);
1.1 kristaps 579: print_otag(h, TAG_DIV, 2, tag);
580: return(1);
581: }
582:
1.42 kristaps 583: buf[0] = '\0';
1.21 kristaps 584: for (nn = n->child; nn; nn = nn->next) {
1.41 kristaps 585: html_idcat(buf, nn->string, BUFSIZ);
1.21 kristaps 586: if (nn->next)
1.42 kristaps 587: html_idcat(buf, " ", BUFSIZ);
1.21 kristaps 588: }
589:
1.23 kristaps 590: /*
591: * TODO: make sure there are no duplicates, as HTML does not
592: * allow for multiple `id' tags of the same name.
593: */
1.22 kristaps 594:
1.23 kristaps 595: PAIR_CLASS_INIT(&tag[0], "sec-head");
1.21 kristaps 596: tag[1].key = ATTR_ID;
1.41 kristaps 597: tag[1].val = buf;
1.1 kristaps 598: print_otag(h, TAG_DIV, 2, tag);
599: return(1);
600: }
601:
602:
603: /* ARGSUSED */
604: static int
605: mdoc_ss_pre(MDOC_ARGS)
606: {
1.21 kristaps 607: struct htmlpair tag[3];
1.1 kristaps 608: const struct mdoc_node *nn;
1.41 kristaps 609: char buf[BUFSIZ];
1.23 kristaps 610: struct roffsu su;
1.1 kristaps 611:
1.23 kristaps 612: SCALE_VS_INIT(&su, 1);
1.1 kristaps 613:
614: if (MDOC_BODY == n->type) {
1.23 kristaps 615: PAIR_CLASS_INIT(&tag[0], "ssec-body");
1.1 kristaps 616: if (n->parent->next && n->child) {
1.23 kristaps 617: bufcat_su(h, "margin-bottom", &su);
618: PAIR_STYLE_INIT(&tag[1], h);
619: print_otag(h, TAG_DIV, 2, tag);
620: } else
621: print_otag(h, TAG_DIV, 1, tag);
1.1 kristaps 622: return(1);
623: } else if (MDOC_BLOCK == n->type) {
1.23 kristaps 624: PAIR_CLASS_INIT(&tag[0], "ssec-block");
1.1 kristaps 625: if (n->prev) {
1.23 kristaps 626: bufcat_su(h, "margin-top", &su);
627: PAIR_STYLE_INIT(&tag[1], h);
628: print_otag(h, TAG_DIV, 2, tag);
629: } else
630: print_otag(h, TAG_DIV, 1, tag);
1.1 kristaps 631: return(1);
632: }
633:
1.23 kristaps 634: /* TODO: see note in mdoc_sh_pre() about duplicates. */
635:
1.42 kristaps 636: buf[0] = '\0';
1.21 kristaps 637: for (nn = n->child; nn; nn = nn->next) {
1.41 kristaps 638: html_idcat(buf, nn->string, BUFSIZ);
1.21 kristaps 639: if (nn->next)
1.42 kristaps 640: html_idcat(buf, " ", BUFSIZ);
1.21 kristaps 641: }
642:
1.23 kristaps 643: SCALE_HS_INIT(&su, INDENT - HALFINDENT);
644: su.scale = -su.scale;
645: bufcat_su(h, "margin-left", &su);
1.22 kristaps 646:
1.23 kristaps 647: PAIR_CLASS_INIT(&tag[0], "ssec-head");
648: PAIR_STYLE_INIT(&tag[1], h);
1.21 kristaps 649: tag[2].key = ATTR_ID;
1.41 kristaps 650: tag[2].val = buf;
1.21 kristaps 651: print_otag(h, TAG_DIV, 3, tag);
1.1 kristaps 652: return(1);
653: }
654:
655:
656: /* ARGSUSED */
657: static int
658: mdoc_fl_pre(MDOC_ARGS)
659: {
660: struct htmlpair tag;
661:
1.50 ! kristaps 662: /* `Cm' has no leading hyphen. */
! 663:
! 664: if (MDOC_Cm == n->tok) {
! 665: PAIR_CLASS_INIT(&tag, "flag");
! 666: print_otag(h, TAG_SPAN, 1, &tag);
! 667: return(1);
! 668: }
! 669:
! 670: /* A zero-length child shouldn't get a dash. */
! 671:
! 672: if (n->child) {
! 673: assert(MDOC_TEXT == n->child->type);
! 674: assert(n->child->string);
! 675: if ('\0' == *n->child->string)
! 676: return(0);
! 677: }
! 678:
1.23 kristaps 679: PAIR_CLASS_INIT(&tag, "flag");
1.1 kristaps 680: print_otag(h, TAG_SPAN, 1, &tag);
1.50 ! kristaps 681:
! 682: print_text(h, "\\-");
! 683:
! 684: /* A blank `Fl' should incur a subsequent space. */
! 685:
! 686: if (n->child)
1.1 kristaps 687: h->flags |= HTML_NOSPACE;
1.50 ! kristaps 688:
1.1 kristaps 689: return(1);
690: }
691:
692:
693: /* ARGSUSED */
694: static int
695: mdoc_nd_pre(MDOC_ARGS)
696: {
697: struct htmlpair tag;
698:
699: if (MDOC_BODY != n->type)
700: return(1);
701:
1.24 kristaps 702: /* XXX: this tag in theory can contain block elements. */
703:
1.1 kristaps 704: print_text(h, "\\(em");
1.23 kristaps 705: PAIR_CLASS_INIT(&tag, "desc-body");
1.1 kristaps 706: print_otag(h, TAG_SPAN, 1, &tag);
707: return(1);
708: }
709:
710:
711: /* ARGSUSED */
712: static int
713: mdoc_op_pre(MDOC_ARGS)
714: {
715: struct htmlpair tag;
716:
717: if (MDOC_BODY != n->type)
718: return(1);
719:
1.24 kristaps 720: /* XXX: this tag in theory can contain block elements. */
721:
1.1 kristaps 722: print_text(h, "\\(lB");
723: h->flags |= HTML_NOSPACE;
1.23 kristaps 724: PAIR_CLASS_INIT(&tag, "opt");
1.1 kristaps 725: print_otag(h, TAG_SPAN, 1, &tag);
726: return(1);
727: }
728:
729:
730: /* ARGSUSED */
731: static void
732: mdoc_op_post(MDOC_ARGS)
733: {
734:
735: if (MDOC_BODY != n->type)
736: return;
737: h->flags |= HTML_NOSPACE;
738: print_text(h, "\\(rB");
739: }
740:
741:
742: static int
743: mdoc_nm_pre(MDOC_ARGS)
744: {
745: struct htmlpair tag;
746:
1.47 kristaps 747: if (SEC_SYNOPSIS == n->sec && n->prev) {
748: bufcat_style(h, "clear", "both");
749: PAIR_STYLE_INIT(&tag, h);
750: print_otag(h, TAG_BR, 1, &tag);
751: }
1.1 kristaps 752:
1.23 kristaps 753: PAIR_CLASS_INIT(&tag, "name");
1.1 kristaps 754: print_otag(h, TAG_SPAN, 1, &tag);
755: if (NULL == n->child)
756: print_text(h, m->name);
757:
758: return(1);
759: }
760:
761:
762: /* ARGSUSED */
763: static int
764: mdoc_xr_pre(MDOC_ARGS)
765: {
766: struct htmlpair tag[2];
767: const struct mdoc_node *nn;
1.17 kristaps 768:
1.23 kristaps 769: PAIR_CLASS_INIT(&tag[0], "link-man");
1.1 kristaps 770:
1.17 kristaps 771: if (h->base_man) {
1.23 kristaps 772: buffmt_man(h, n->child->string,
773: n->child->next ?
1.17 kristaps 774: n->child->next->string : NULL);
1.23 kristaps 775: tag[1].key = ATTR_HREF;
776: tag[1].val = h->buf;
777: print_otag(h, TAG_A, 2, tag);
778: } else
779: print_otag(h, TAG_A, 1, tag);
1.1 kristaps 780:
781: nn = n->child;
782: print_text(h, nn->string);
1.16 kristaps 783:
1.1 kristaps 784: if (NULL == (nn = nn->next))
785: return(0);
786:
787: h->flags |= HTML_NOSPACE;
788: print_text(h, "(");
789: h->flags |= HTML_NOSPACE;
790: print_text(h, nn->string);
791: h->flags |= HTML_NOSPACE;
792: print_text(h, ")");
793: return(0);
794: }
795:
796:
797: /* ARGSUSED */
798: static int
799: mdoc_ns_pre(MDOC_ARGS)
800: {
801:
802: h->flags |= HTML_NOSPACE;
803: return(1);
804: }
805:
806:
807: /* ARGSUSED */
808: static int
809: mdoc_ar_pre(MDOC_ARGS)
810: {
811: struct htmlpair tag;
812:
1.23 kristaps 813: PAIR_CLASS_INIT(&tag, "arg");
1.1 kristaps 814: print_otag(h, TAG_SPAN, 1, &tag);
815: return(1);
816: }
817:
818:
819: /* ARGSUSED */
820: static int
821: mdoc_xx_pre(MDOC_ARGS)
822: {
823: const char *pp;
824: struct htmlpair tag;
825:
826: switch (n->tok) {
827: case (MDOC_Bsx):
828: pp = "BSDI BSD/OS";
829: break;
830: case (MDOC_Dx):
1.45 kristaps 831: pp = "DragonFly";
1.1 kristaps 832: break;
833: case (MDOC_Fx):
834: pp = "FreeBSD";
835: break;
836: case (MDOC_Nx):
837: pp = "NetBSD";
838: break;
839: case (MDOC_Ox):
840: pp = "OpenBSD";
841: break;
842: case (MDOC_Ux):
843: pp = "UNIX";
844: break;
845: default:
846: return(1);
847: }
848:
1.23 kristaps 849: PAIR_CLASS_INIT(&tag, "unix");
1.1 kristaps 850: print_otag(h, TAG_SPAN, 1, &tag);
851: print_text(h, pp);
852: return(1);
853: }
854:
855:
856: /* ARGSUSED */
857: static int
1.4 kristaps 858: mdoc_bx_pre(MDOC_ARGS)
859: {
860: const struct mdoc_node *nn;
861: struct htmlpair tag;
862:
1.23 kristaps 863: PAIR_CLASS_INIT(&tag, "unix");
1.4 kristaps 864: print_otag(h, TAG_SPAN, 1, &tag);
865:
866: for (nn = n->child; nn; nn = nn->next)
867: print_mdoc_node(m, nn, h);
868:
869: if (n->child)
870: h->flags |= HTML_NOSPACE;
871:
872: print_text(h, "BSD");
873: return(0);
874: }
875:
876:
877: /* ARGSUSED */
878: static int
1.27 kristaps 879: mdoc_it_block_pre(MDOC_ARGS, int type, int comp,
880: struct roffsu *offs, struct roffsu *width)
1.1 kristaps 881: {
1.14 kristaps 882: struct htmlpair tag;
883: const struct mdoc_node *nn;
1.23 kristaps 884: struct roffsu su;
885:
886: nn = n->parent->parent;
887: assert(nn->args);
888:
1.24 kristaps 889: /* XXX: see notes in mdoc_it_pre(). */
890:
891: if (MDOC_Column == type) {
892: /* Don't width-pad on the left. */
893: SCALE_HS_INIT(width, 0);
894: /* Also disallow non-compact. */
895: comp = 1;
896: }
1.23 kristaps 897: if (MDOC_Diag == type)
1.24 kristaps 898: /* Mandate non-compact with empty prior. */
1.23 kristaps 899: if (n->prev && NULL == n->prev->body->child)
900: comp = 1;
901:
1.24 kristaps 902: bufcat_style(h, "clear", "both");
1.23 kristaps 903: if (offs->scale > 0)
904: bufcat_su(h, "margin-left", offs);
905: if (width->scale > 0)
906: bufcat_su(h, "padding-left", width);
1.1 kristaps 907:
1.23 kristaps 908: PAIR_STYLE_INIT(&tag, h);
909:
1.24 kristaps 910: /* Mandate compact following `Ss' and `Sh' starts. */
911:
1.23 kristaps 912: for (nn = n; nn && ! comp; nn = nn->parent) {
913: if (MDOC_BLOCK != nn->type)
914: continue;
915: if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
916: comp = 1;
917: if (nn->prev)
918: break;
1.1 kristaps 919: }
920:
1.23 kristaps 921: if ( ! comp) {
922: SCALE_VS_INIT(&su, 1);
923: bufcat_su(h, "padding-top", &su);
1.1 kristaps 924: }
925:
1.23 kristaps 926: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 927: print_otag(h, TAG_DIV, 1, &tag);
928: return(1);
929: }
930:
931:
1.25 kristaps 932: /* ARGSUSED */
1.1 kristaps 933: static int
1.23 kristaps 934: mdoc_it_body_pre(MDOC_ARGS, int type)
1.1 kristaps 935: {
1.23 kristaps 936: struct htmlpair tag;
937: struct roffsu su;
938:
939: switch (type) {
940: case (MDOC_Item):
941: /* FALLTHROUGH */
942: case (MDOC_Ohang):
943: /* FALLTHROUGH */
944: case (MDOC_Column):
945: break;
946: default:
1.24 kristaps 947: /*
948: * XXX: this tricks CSS into aligning the bodies with
949: * the right-padding in the head.
950: */
1.23 kristaps 951: SCALE_HS_INIT(&su, 2);
952: bufcat_su(h, "margin-left", &su);
953: PAIR_STYLE_INIT(&tag, h);
954: print_otag(h, TAG_DIV, 1, &tag);
955: break;
956: }
1.1 kristaps 957:
958: return(1);
959: }
960:
961:
1.25 kristaps 962: /* ARGSUSED */
1.1 kristaps 963: static int
1.23 kristaps 964: mdoc_it_head_pre(MDOC_ARGS, int type, struct roffsu *width)
1.1 kristaps 965: {
966: struct htmlpair tag;
967: struct ord *ord;
968: char nbuf[BUFSIZ];
969:
1.23 kristaps 970: switch (type) {
1.1 kristaps 971: case (MDOC_Item):
1.46 kristaps 972: return(0);
1.1 kristaps 973: case (MDOC_Ohang):
1.46 kristaps 974: print_otag(h, TAG_DIV, 0, &tag);
975: return(1);
1.1 kristaps 976: case (MDOC_Column):
1.23 kristaps 977: bufcat_su(h, "min-width", width);
978: bufcat_style(h, "clear", "none");
1.1 kristaps 979: if (n->next && MDOC_HEAD == n->next->type)
1.23 kristaps 980: bufcat_style(h, "float", "left");
981: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 982: print_otag(h, TAG_DIV, 1, &tag);
983: break;
984: default:
1.23 kristaps 985: bufcat_su(h, "min-width", width);
986: SCALE_INVERT(width);
987: bufcat_su(h, "margin-left", width);
1.2 kristaps 988: if (n->next && n->next->child)
1.23 kristaps 989: bufcat_style(h, "float", "left");
1.24 kristaps 990:
991: /* XXX: buffer if we run into body. */
1.23 kristaps 992: SCALE_HS_INIT(width, 1);
993: bufcat_su(h, "margin-right", width);
994: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 995: print_otag(h, TAG_DIV, 1, &tag);
996: break;
997: }
998:
1.23 kristaps 999: switch (type) {
1.1 kristaps 1000: case (MDOC_Diag):
1.23 kristaps 1001: PAIR_CLASS_INIT(&tag, "diag");
1.1 kristaps 1002: print_otag(h, TAG_SPAN, 1, &tag);
1003: break;
1004: case (MDOC_Enum):
1.39 kristaps 1005: ord = h->ords.head;
1.1 kristaps 1006: assert(ord);
1007: nbuf[BUFSIZ - 1] = 0;
1008: (void)snprintf(nbuf, BUFSIZ - 1, "%d.", ord->pos++);
1009: print_text(h, nbuf);
1010: return(0);
1011: case (MDOC_Dash):
1012: print_text(h, "\\(en");
1013: return(0);
1014: case (MDOC_Hyphen):
1.4 kristaps 1015: print_text(h, "\\(hy");
1.1 kristaps 1016: return(0);
1017: case (MDOC_Bullet):
1018: print_text(h, "\\(bu");
1019: return(0);
1020: default:
1021: break;
1022: }
1023:
1024: return(1);
1025: }
1026:
1027:
1028: static int
1.23 kristaps 1029: mdoc_it_pre(MDOC_ARGS)
1.1 kristaps 1030: {
1.23 kristaps 1031: int i, type, wp, comp;
1.1 kristaps 1032: const struct mdoc_node *bl, *nn;
1.23 kristaps 1033: struct roffsu width, offs;
1034:
1.24 kristaps 1035: /*
1036: * XXX: be very careful in changing anything, here. Lists in
1037: * mandoc have many peculiarities; furthermore, they don't
1038: * translate well into HTML and require a bit of mangling.
1039: */
1.1 kristaps 1040:
1041: bl = n->parent->parent;
1.23 kristaps 1042: if (MDOC_BLOCK != n->type)
1.1 kristaps 1043: bl = bl->parent;
1044:
1.23 kristaps 1045: type = a2list(bl);
1.1 kristaps 1046:
1.23 kristaps 1047: /* Set default width and offset. */
1.1 kristaps 1048:
1.24 kristaps 1049: SCALE_HS_INIT(&offs, 0);
1050:
1.1 kristaps 1051: switch (type) {
1052: case (MDOC_Enum):
1053: /* FALLTHROUGH */
1054: case (MDOC_Dash):
1055: /* FALLTHROUGH */
1056: case (MDOC_Hyphen):
1057: /* FALLTHROUGH */
1058: case (MDOC_Bullet):
1.23 kristaps 1059: SCALE_HS_INIT(&width, 2);
1.1 kristaps 1060: break;
1.23 kristaps 1061: default:
1062: SCALE_HS_INIT(&width, INDENT);
1063: break;
1064: }
1065:
1066: /* Get width, offset, and compact arguments. */
1067:
1068: for (wp = -1, comp = i = 0; i < (int)bl->args->argc; i++)
1069: switch (bl->args->argv[i].arg) {
1.24 kristaps 1070: case (MDOC_Column):
1071: wp = i; /* Save for later. */
1072: break;
1.23 kristaps 1073: case (MDOC_Width):
1074: a2width(bl->args->argv[i].value[0], &width);
1075: break;
1076: case (MDOC_Offset):
1077: a2offs(bl->args->argv[i].value[0], &offs);
1078: break;
1079: case (MDOC_Compact):
1080: comp = 1;
1081: break;
1082: default:
1083: break;
1084: }
1085:
1086: /* Override width in some cases. */
1087:
1088: switch (type) {
1.46 kristaps 1089: case (MDOC_Ohang):
1090: /* FALLTHROUGH */
1.33 kristaps 1091: case (MDOC_Item):
1092: /* FALLTHROUGH */
1.1 kristaps 1093: case (MDOC_Inset):
1094: /* FALLTHROUGH */
1095: case (MDOC_Diag):
1.23 kristaps 1096: SCALE_HS_INIT(&width, 0);
1.1 kristaps 1097: break;
1098: default:
1.23 kristaps 1099: if (0 == width.scale)
1100: SCALE_HS_INIT(&width, INDENT);
1.1 kristaps 1101: break;
1102: }
1103:
1.23 kristaps 1104: /* Flip to body/block processing. */
1105:
1106: if (MDOC_BODY == n->type)
1107: return(mdoc_it_body_pre(m, n, h, type));
1108: if (MDOC_BLOCK == n->type)
1.27 kristaps 1109: return(mdoc_it_block_pre(m, n, h, type, comp,
1110: &offs, &width));
1.23 kristaps 1111:
1112: /* Override column widths. */
1113:
1114: if (MDOC_Column == type) {
1115: nn = n->parent->child;
1116: for (i = 0; nn && nn != n; nn = nn->next, i++)
1117: /* Counter... */ ;
1.24 kristaps 1118: if (i < (int)bl->args->argv[wp].sz)
1.23 kristaps 1119: a2width(bl->args->argv[wp].value[i], &width);
1.1 kristaps 1120: }
1121:
1.23 kristaps 1122: return(mdoc_it_head_pre(m, n, h, type, &width));
1.1 kristaps 1123: }
1124:
1125:
1126: /* ARGSUSED */
1127: static int
1128: mdoc_bl_pre(MDOC_ARGS)
1129: {
1130: struct ord *ord;
1131:
1132: if (MDOC_BLOCK != n->type)
1133: return(1);
1134: if (MDOC_Enum != a2list(n))
1135: return(1);
1136:
1137: ord = malloc(sizeof(struct ord));
1.43 kristaps 1138: if (NULL == ord) {
1.44 kristaps 1139: perror(NULL);
1.43 kristaps 1140: exit(EXIT_FAILURE);
1141: }
1.1 kristaps 1142: ord->cookie = n;
1143: ord->pos = 1;
1.39 kristaps 1144: ord->next = h->ords.head;
1145: h->ords.head = ord;
1.1 kristaps 1146: return(1);
1147: }
1148:
1149:
1150: /* ARGSUSED */
1151: static void
1152: mdoc_bl_post(MDOC_ARGS)
1153: {
1154: struct ord *ord;
1155:
1156: if (MDOC_BLOCK != n->type)
1157: return;
1158: if (MDOC_Enum != a2list(n))
1159: return;
1160:
1.39 kristaps 1161: ord = h->ords.head;
1.1 kristaps 1162: assert(ord);
1.39 kristaps 1163: h->ords.head = ord->next;
1.1 kristaps 1164: free(ord);
1165: }
1166:
1167:
1168: /* ARGSUSED */
1169: static int
1170: mdoc_ex_pre(MDOC_ARGS)
1171: {
1172: const struct mdoc_node *nn;
1173: struct tag *t;
1174: struct htmlpair tag;
1175:
1.23 kristaps 1176: PAIR_CLASS_INIT(&tag, "utility");
1177:
1.1 kristaps 1178: print_text(h, "The");
1179: for (nn = n->child; nn; nn = nn->next) {
1180: t = print_otag(h, TAG_SPAN, 1, &tag);
1181: print_text(h, nn->string);
1182: print_tagq(h, t);
1183:
1184: h->flags |= HTML_NOSPACE;
1185:
1186: if (nn->next && NULL == nn->next->next)
1187: print_text(h, ", and");
1188: else if (nn->next)
1189: print_text(h, ",");
1190: else
1191: h->flags &= ~HTML_NOSPACE;
1192: }
1193:
1194: if (n->child->next)
1195: print_text(h, "utilities exit");
1196: else
1197: print_text(h, "utility exits");
1198:
1199: print_text(h, "0 on success, and >0 if an error occurs.");
1200: return(0);
1201: }
1202:
1203:
1204: /* ARGSUSED */
1205: static int
1206: mdoc_dq_pre(MDOC_ARGS)
1207: {
1208:
1209: if (MDOC_BODY != n->type)
1210: return(1);
1211: print_text(h, "\\(lq");
1212: h->flags |= HTML_NOSPACE;
1213: return(1);
1214: }
1215:
1216:
1217: /* ARGSUSED */
1218: static void
1219: mdoc_dq_post(MDOC_ARGS)
1220: {
1221:
1222: if (MDOC_BODY != n->type)
1223: return;
1224: h->flags |= HTML_NOSPACE;
1225: print_text(h, "\\(rq");
1226: }
1227:
1228:
1229: /* ARGSUSED */
1230: static int
1231: mdoc_pq_pre(MDOC_ARGS)
1232: {
1233:
1234: if (MDOC_BODY != n->type)
1235: return(1);
1236: print_text(h, "\\&(");
1237: h->flags |= HTML_NOSPACE;
1238: return(1);
1239: }
1240:
1241:
1242: /* ARGSUSED */
1243: static void
1244: mdoc_pq_post(MDOC_ARGS)
1245: {
1246:
1247: if (MDOC_BODY != n->type)
1248: return;
1249: print_text(h, ")");
1250: }
1251:
1252:
1253: /* ARGSUSED */
1254: static int
1255: mdoc_sq_pre(MDOC_ARGS)
1256: {
1257:
1258: if (MDOC_BODY != n->type)
1259: return(1);
1260: print_text(h, "\\(oq");
1261: h->flags |= HTML_NOSPACE;
1262: return(1);
1263: }
1264:
1265:
1266: /* ARGSUSED */
1267: static void
1268: mdoc_sq_post(MDOC_ARGS)
1269: {
1270:
1271: if (MDOC_BODY != n->type)
1272: return;
1273: h->flags |= HTML_NOSPACE;
1274: print_text(h, "\\(aq");
1275: }
1276:
1277:
1278: /* ARGSUSED */
1279: static int
1280: mdoc_em_pre(MDOC_ARGS)
1281: {
1282: struct htmlpair tag;
1283:
1.23 kristaps 1284: PAIR_CLASS_INIT(&tag, "emph");
1.1 kristaps 1285: print_otag(h, TAG_SPAN, 1, &tag);
1286: return(1);
1287: }
1288:
1289:
1290: /* ARGSUSED */
1291: static int
1292: mdoc_d1_pre(MDOC_ARGS)
1293: {
1.23 kristaps 1294: struct htmlpair tag[2];
1295: struct roffsu su;
1.1 kristaps 1296:
1297: if (MDOC_BLOCK != n->type)
1298: return(1);
1299:
1.35 kristaps 1300: /* FIXME: D1 shouldn't be literal. */
1301:
1.23 kristaps 1302: SCALE_VS_INIT(&su, INDENT - 2);
1303: bufcat_su(h, "margin-left", &su);
1304: PAIR_CLASS_INIT(&tag[0], "lit");
1305: PAIR_STYLE_INIT(&tag[1], h);
1.1 kristaps 1306: print_otag(h, TAG_DIV, 2, tag);
1307: return(1);
1308: }
1309:
1310:
1311: /* ARGSUSED */
1312: static int
1313: mdoc_sx_pre(MDOC_ARGS)
1314: {
1.18 kristaps 1315: struct htmlpair tag[2];
1.1 kristaps 1316: const struct mdoc_node *nn;
1.35 kristaps 1317: char buf[BUFSIZ];
1.1 kristaps 1318:
1.23 kristaps 1319: /* FIXME: duplicates? */
1320:
1.41 kristaps 1321: strlcpy(buf, "#", BUFSIZ);
1.1 kristaps 1322: for (nn = n->child; nn; nn = nn->next) {
1.41 kristaps 1323: html_idcat(buf, nn->string, BUFSIZ);
1.1 kristaps 1324: if (nn->next)
1.42 kristaps 1325: html_idcat(buf, " ", BUFSIZ);
1.1 kristaps 1326: }
1327:
1.23 kristaps 1328: PAIR_CLASS_INIT(&tag[0], "link-sec");
1.21 kristaps 1329: tag[1].key = ATTR_HREF;
1.35 kristaps 1330: tag[1].val = buf;
1.1 kristaps 1331:
1.18 kristaps 1332: print_otag(h, TAG_A, 2, tag);
1.1 kristaps 1333: return(1);
1334: }
1335:
1336:
1337: /* ARGSUSED */
1338: static int
1339: mdoc_aq_pre(MDOC_ARGS)
1340: {
1341:
1342: if (MDOC_BODY != n->type)
1343: return(1);
1344: print_text(h, "\\(la");
1345: h->flags |= HTML_NOSPACE;
1346: return(1);
1347: }
1348:
1349:
1350: /* ARGSUSED */
1351: static void
1352: mdoc_aq_post(MDOC_ARGS)
1353: {
1354:
1355: if (MDOC_BODY != n->type)
1356: return;
1357: h->flags |= HTML_NOSPACE;
1358: print_text(h, "\\(ra");
1359: }
1360:
1361:
1362: /* ARGSUSED */
1363: static int
1364: mdoc_bd_pre(MDOC_ARGS)
1365: {
1366: struct htmlpair tag[2];
1.23 kristaps 1367: int type, comp, i;
1.14 kristaps 1368: const struct mdoc_node *bl, *nn;
1.23 kristaps 1369: struct roffsu su;
1.1 kristaps 1370:
1371: if (MDOC_BLOCK == n->type)
1372: bl = n;
1373: else if (MDOC_HEAD == n->type)
1374: return(0);
1375: else
1376: bl = n->parent;
1377:
1.24 kristaps 1378: SCALE_VS_INIT(&su, 0);
1379:
1.23 kristaps 1380: type = comp = 0;
1.1 kristaps 1381: for (i = 0; i < (int)bl->args->argc; i++)
1382: switch (bl->args->argv[i].arg) {
1383: case (MDOC_Offset):
1.23 kristaps 1384: a2offs(bl->args->argv[i].value[0], &su);
1.1 kristaps 1385: break;
1386: case (MDOC_Compact):
1.23 kristaps 1387: comp = 1;
1.1 kristaps 1388: break;
1.30 kristaps 1389: case (MDOC_Centred):
1390: /* FALLTHROUGH */
1.1 kristaps 1391: case (MDOC_Ragged):
1392: /* FALLTHROUGH */
1393: case (MDOC_Filled):
1394: /* FALLTHROUGH */
1395: case (MDOC_Unfilled):
1396: /* FALLTHROUGH */
1397: case (MDOC_Literal):
1.23 kristaps 1398: type = bl->args->argv[i].arg;
1.1 kristaps 1399: break;
1.30 kristaps 1400: default:
1401: break;
1.1 kristaps 1402: }
1403:
1.31 kristaps 1404: /* FIXME: -centered, etc. formatting. */
1405:
1.1 kristaps 1406: if (MDOC_BLOCK == n->type) {
1.24 kristaps 1407: bufcat_su(h, "margin-left", &su);
1.23 kristaps 1408: for (nn = n; nn && ! comp; nn = nn->parent) {
1409: if (MDOC_BLOCK != nn->type)
1410: continue;
1411: if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
1412: comp = 1;
1413: if (nn->prev)
1414: break;
1415: }
1416: if (comp) {
1417: print_otag(h, TAG_DIV, 0, tag);
1418: return(1);
1.14 kristaps 1419: }
1.23 kristaps 1420: SCALE_VS_INIT(&su, 1);
1421: bufcat_su(h, "margin-top", &su);
1422: PAIR_STYLE_INIT(&tag[0], h);
1.1 kristaps 1423: print_otag(h, TAG_DIV, 1, tag);
1424: return(1);
1425: }
1426:
1.23 kristaps 1427: if (MDOC_Unfilled != type && MDOC_Literal != type)
1.1 kristaps 1428: return(1);
1429:
1.23 kristaps 1430: PAIR_CLASS_INIT(&tag[0], "lit");
1431: bufcat_style(h, "white-space", "pre");
1432: PAIR_STYLE_INIT(&tag[1], h);
1.1 kristaps 1433: print_otag(h, TAG_DIV, 2, tag);
1434:
1.14 kristaps 1435: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1436: h->flags |= HTML_NOSPACE;
1.14 kristaps 1437: print_mdoc_node(m, nn, h);
1438: if (NULL == nn->next)
1439: continue;
1440: if (nn->prev && nn->prev->line < nn->line)
1.1 kristaps 1441: print_text(h, "\n");
1.23 kristaps 1442: else if (NULL == nn->prev)
1443: print_text(h, "\n");
1.1 kristaps 1444: }
1445:
1446: return(0);
1447: }
1448:
1449:
1450: /* ARGSUSED */
1451: static int
1452: mdoc_pa_pre(MDOC_ARGS)
1453: {
1454: struct htmlpair tag;
1455:
1.23 kristaps 1456: PAIR_CLASS_INIT(&tag, "file");
1.1 kristaps 1457: print_otag(h, TAG_SPAN, 1, &tag);
1458: return(1);
1459: }
1460:
1461:
1462: /* ARGSUSED */
1463: static int
1464: mdoc_ad_pre(MDOC_ARGS)
1465: {
1466: struct htmlpair tag;
1467:
1.23 kristaps 1468: PAIR_CLASS_INIT(&tag, "addr");
1.1 kristaps 1469: print_otag(h, TAG_SPAN, 1, &tag);
1470: return(1);
1471: }
1472:
1473:
1474: /* ARGSUSED */
1475: static int
1476: mdoc_an_pre(MDOC_ARGS)
1477: {
1478: struct htmlpair tag;
1479:
1.19 kristaps 1480: /* TODO: -split and -nosplit (see termp_an_pre()). */
1481:
1.23 kristaps 1482: PAIR_CLASS_INIT(&tag, "author");
1.1 kristaps 1483: print_otag(h, TAG_SPAN, 1, &tag);
1484: return(1);
1485: }
1486:
1487:
1488: /* ARGSUSED */
1489: static int
1490: mdoc_cd_pre(MDOC_ARGS)
1491: {
1492: struct htmlpair tag;
1493:
1.28 kristaps 1494: print_otag(h, TAG_DIV, 0, NULL);
1.23 kristaps 1495: PAIR_CLASS_INIT(&tag, "config");
1.1 kristaps 1496: print_otag(h, TAG_SPAN, 1, &tag);
1497: return(1);
1498: }
1499:
1500:
1501: /* ARGSUSED */
1502: static int
1503: mdoc_dv_pre(MDOC_ARGS)
1504: {
1505: struct htmlpair tag;
1506:
1.23 kristaps 1507: PAIR_CLASS_INIT(&tag, "define");
1.1 kristaps 1508: print_otag(h, TAG_SPAN, 1, &tag);
1509: return(1);
1510: }
1511:
1512:
1513: /* ARGSUSED */
1514: static int
1515: mdoc_ev_pre(MDOC_ARGS)
1516: {
1517: struct htmlpair tag;
1518:
1.23 kristaps 1519: PAIR_CLASS_INIT(&tag, "env");
1.1 kristaps 1520: print_otag(h, TAG_SPAN, 1, &tag);
1521: return(1);
1522: }
1523:
1524:
1525: /* ARGSUSED */
1526: static int
1527: mdoc_er_pre(MDOC_ARGS)
1528: {
1529: struct htmlpair tag;
1530:
1.23 kristaps 1531: PAIR_CLASS_INIT(&tag, "errno");
1.1 kristaps 1532: print_otag(h, TAG_SPAN, 1, &tag);
1533: return(1);
1534: }
1535:
1536:
1537: /* ARGSUSED */
1538: static int
1539: mdoc_fa_pre(MDOC_ARGS)
1540: {
1541: const struct mdoc_node *nn;
1542: struct htmlpair tag;
1543: struct tag *t;
1544:
1.23 kristaps 1545: PAIR_CLASS_INIT(&tag, "farg");
1.1 kristaps 1546: if (n->parent->tok != MDOC_Fo) {
1547: print_otag(h, TAG_SPAN, 1, &tag);
1548: return(1);
1549: }
1550:
1551: for (nn = n->child; nn; nn = nn->next) {
1552: t = print_otag(h, TAG_SPAN, 1, &tag);
1553: print_text(h, nn->string);
1554: print_tagq(h, t);
1555: if (nn->next)
1556: print_text(h, ",");
1557: }
1558:
1559: if (n->child && n->next && n->next->tok == MDOC_Fa)
1560: print_text(h, ",");
1561:
1562: return(0);
1563: }
1564:
1565:
1566: /* ARGSUSED */
1567: static int
1568: mdoc_fd_pre(MDOC_ARGS)
1569: {
1.23 kristaps 1570: struct htmlpair tag;
1571: struct roffsu su;
1.1 kristaps 1572:
1573: if (SEC_SYNOPSIS == n->sec) {
1574: if (n->next && MDOC_Fd != n->next->tok) {
1.23 kristaps 1575: SCALE_VS_INIT(&su, 1);
1576: bufcat_su(h, "margin-bottom", &su);
1577: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1578: print_otag(h, TAG_DIV, 1, &tag);
1579: } else
1580: print_otag(h, TAG_DIV, 0, NULL);
1581: }
1582:
1.23 kristaps 1583: PAIR_CLASS_INIT(&tag, "macro");
1.1 kristaps 1584: print_otag(h, TAG_SPAN, 1, &tag);
1585: return(1);
1586: }
1587:
1588:
1589: /* ARGSUSED */
1590: static int
1591: mdoc_vt_pre(MDOC_ARGS)
1592: {
1.23 kristaps 1593: struct htmlpair tag;
1594: struct roffsu su;
1.1 kristaps 1595:
1596: if (SEC_SYNOPSIS == n->sec) {
1.49 kristaps 1597: if (n->prev && MDOC_Vt != n->prev->tok) {
1.23 kristaps 1598: SCALE_VS_INIT(&su, 1);
1.49 kristaps 1599: bufcat_su(h, "margin-top", &su);
1.23 kristaps 1600: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1601: print_otag(h, TAG_DIV, 1, &tag);
1602: } else
1603: print_otag(h, TAG_DIV, 0, NULL);
1604: }
1605:
1.23 kristaps 1606: PAIR_CLASS_INIT(&tag, "type");
1.1 kristaps 1607: print_otag(h, TAG_SPAN, 1, &tag);
1608: return(1);
1609: }
1610:
1.2 kristaps 1611:
1.1 kristaps 1612: /* ARGSUSED */
1613: static int
1614: mdoc_ft_pre(MDOC_ARGS)
1615: {
1.23 kristaps 1616: struct htmlpair tag;
1617: struct roffsu su;
1.1 kristaps 1618:
1619: if (SEC_SYNOPSIS == n->sec) {
1620: if (n->prev && MDOC_Fo == n->prev->tok) {
1.23 kristaps 1621: SCALE_VS_INIT(&su, 1);
1622: bufcat_su(h, "margin-top", &su);
1623: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1624: print_otag(h, TAG_DIV, 1, &tag);
1625: } else
1626: print_otag(h, TAG_DIV, 0, NULL);
1627: }
1628:
1.23 kristaps 1629: PAIR_CLASS_INIT(&tag, "ftype");
1.1 kristaps 1630: print_otag(h, TAG_SPAN, 1, &tag);
1631: return(1);
1632: }
1633:
1634:
1635: /* ARGSUSED */
1636: static int
1637: mdoc_fn_pre(MDOC_ARGS)
1638: {
1639: struct tag *t;
1.15 kristaps 1640: struct htmlpair tag[2];
1.1 kristaps 1641: const struct mdoc_node *nn;
1.7 kristaps 1642: char nbuf[BUFSIZ];
1643: const char *sp, *ep;
1.15 kristaps 1644: int sz, i;
1.23 kristaps 1645: struct roffsu su;
1.1 kristaps 1646:
1647: if (SEC_SYNOPSIS == n->sec) {
1.23 kristaps 1648: SCALE_HS_INIT(&su, INDENT);
1649: bufcat_su(h, "margin-left", &su);
1650: su.scale = -su.scale;
1651: bufcat_su(h, "text-indent", &su);
1652: if (n->next) {
1653: SCALE_VS_INIT(&su, 1);
1654: bufcat_su(h, "margin-bottom", &su);
1655: }
1656: PAIR_STYLE_INIT(&tag[0], h);
1.15 kristaps 1657: print_otag(h, TAG_DIV, 1, tag);
1.1 kristaps 1658: }
1659:
1.7 kristaps 1660: /* Split apart into type and name. */
1661: assert(n->child->string);
1662: sp = n->child->string;
1.19 kristaps 1663:
1.26 kristaps 1664: ep = strchr(sp, ' ');
1665: if (NULL != ep) {
1.23 kristaps 1666: PAIR_CLASS_INIT(&tag[0], "ftype");
1.19 kristaps 1667: t = print_otag(h, TAG_SPAN, 1, tag);
1668:
1669: while (ep) {
1670: sz = MIN((int)(ep - sp), BUFSIZ - 1);
1671: (void)memcpy(nbuf, sp, (size_t)sz);
1672: nbuf[sz] = '\0';
1673: print_text(h, nbuf);
1674: sp = ++ep;
1675: ep = strchr(sp, ' ');
1676: }
1677: print_tagq(h, t);
1.7 kristaps 1678: }
1.1 kristaps 1679:
1.23 kristaps 1680: PAIR_CLASS_INIT(&tag[0], "fname");
1.15 kristaps 1681: t = print_otag(h, TAG_SPAN, 1, tag);
1.7 kristaps 1682:
1683: if (sp) {
1684: (void)strlcpy(nbuf, sp, BUFSIZ);
1685: print_text(h, nbuf);
1686: }
1687:
1.1 kristaps 1688: print_tagq(h, t);
1689:
1690: h->flags |= HTML_NOSPACE;
1691: print_text(h, "(");
1692:
1.23 kristaps 1693: bufinit(h);
1694: PAIR_CLASS_INIT(&tag[0], "farg");
1695: bufcat_style(h, "white-space", "nowrap");
1696: PAIR_STYLE_INIT(&tag[1], h);
1697:
1.1 kristaps 1698: for (nn = n->child->next; nn; nn = nn->next) {
1.23 kristaps 1699: i = 1;
1700: if (SEC_SYNOPSIS == n->sec)
1701: i = 2;
1.15 kristaps 1702: t = print_otag(h, TAG_SPAN, i, tag);
1.1 kristaps 1703: print_text(h, nn->string);
1704: print_tagq(h, t);
1705: if (nn->next)
1706: print_text(h, ",");
1707: }
1708:
1709: print_text(h, ")");
1710: if (SEC_SYNOPSIS == n->sec)
1711: print_text(h, ";");
1712:
1713: return(0);
1714: }
1715:
1716:
1717: /* ARGSUSED */
1718: static int
1719: mdoc_sp_pre(MDOC_ARGS)
1720: {
1.23 kristaps 1721: int len;
1722: struct htmlpair tag;
1723: struct roffsu su;
1.1 kristaps 1724:
1725: switch (n->tok) {
1726: case (MDOC_sp):
1.23 kristaps 1727: /* FIXME: can this have a scaling indicator? */
1.1 kristaps 1728: len = n->child ? atoi(n->child->string) : 1;
1729: break;
1730: case (MDOC_br):
1731: len = 0;
1732: break;
1733: default:
1734: len = 1;
1735: break;
1736: }
1737:
1.23 kristaps 1738: SCALE_VS_INIT(&su, len);
1739: bufcat_su(h, "height", &su);
1740: PAIR_STYLE_INIT(&tag, h);
1.1 kristaps 1741: print_otag(h, TAG_DIV, 1, &tag);
1.42 kristaps 1742: /* So the div isn't empty: */
1743: print_text(h, "\\~");
1744:
1745: return(0);
1.1 kristaps 1746:
1747: }
1.2 kristaps 1748:
1749:
1750: /* ARGSUSED */
1751: static int
1752: mdoc_brq_pre(MDOC_ARGS)
1753: {
1754:
1755: if (MDOC_BODY != n->type)
1756: return(1);
1757: print_text(h, "\\(lC");
1758: h->flags |= HTML_NOSPACE;
1759: return(1);
1760: }
1761:
1762:
1763: /* ARGSUSED */
1764: static void
1765: mdoc_brq_post(MDOC_ARGS)
1766: {
1767:
1768: if (MDOC_BODY != n->type)
1769: return;
1770: h->flags |= HTML_NOSPACE;
1771: print_text(h, "\\(rC");
1772: }
1773:
1774:
1775: /* ARGSUSED */
1776: static int
1777: mdoc_lk_pre(MDOC_ARGS)
1778: {
1779: const struct mdoc_node *nn;
1780: struct htmlpair tag[2];
1781:
1782: nn = n->child;
1783:
1.23 kristaps 1784: PAIR_CLASS_INIT(&tag[0], "link-ext");
1.2 kristaps 1785: tag[1].key = ATTR_HREF;
1786: tag[1].val = nn->string;
1787: print_otag(h, TAG_A, 2, tag);
1788:
1.38 kristaps 1789: if (NULL == nn->next)
1790: return(1);
1791:
1.2 kristaps 1792: for (nn = nn->next; nn; nn = nn->next)
1793: print_text(h, nn->string);
1794:
1795: return(0);
1796: }
1797:
1798:
1799: /* ARGSUSED */
1800: static int
1801: mdoc_mt_pre(MDOC_ARGS)
1802: {
1803: struct htmlpair tag[2];
1804: struct tag *t;
1805: const struct mdoc_node *nn;
1806:
1.23 kristaps 1807: PAIR_CLASS_INIT(&tag[0], "link-mail");
1.2 kristaps 1808:
1809: for (nn = n->child; nn; nn = nn->next) {
1.16 kristaps 1810: bufinit(h);
1811: bufcat(h, "mailto:");
1812: bufcat(h, nn->string);
1.23 kristaps 1813: PAIR_STYLE_INIT(&tag[1], h);
1.2 kristaps 1814: t = print_otag(h, TAG_A, 2, tag);
1815: print_text(h, nn->string);
1816: print_tagq(h, t);
1817: }
1818:
1819: return(0);
1820: }
1.4 kristaps 1821:
1822:
1823: /* ARGSUSED */
1824: static int
1825: mdoc_fo_pre(MDOC_ARGS)
1826: {
1827: struct htmlpair tag;
1828:
1829: if (MDOC_BODY == n->type) {
1830: h->flags |= HTML_NOSPACE;
1831: print_text(h, "(");
1832: h->flags |= HTML_NOSPACE;
1833: return(1);
1834: } else if (MDOC_BLOCK == n->type)
1835: return(1);
1836:
1.23 kristaps 1837: PAIR_CLASS_INIT(&tag, "fname");
1.4 kristaps 1838: print_otag(h, TAG_SPAN, 1, &tag);
1839: return(1);
1840: }
1841:
1842:
1843: /* ARGSUSED */
1844: static void
1845: mdoc_fo_post(MDOC_ARGS)
1846: {
1847: if (MDOC_BODY != n->type)
1848: return;
1849: h->flags |= HTML_NOSPACE;
1850: print_text(h, ")");
1851: h->flags |= HTML_NOSPACE;
1852: print_text(h, ";");
1853: }
1854:
1855:
1856: /* ARGSUSED */
1857: static int
1858: mdoc_in_pre(MDOC_ARGS)
1859: {
1860: const struct mdoc_node *nn;
1.23 kristaps 1861: struct tag *t;
1.17 kristaps 1862: struct htmlpair tag[2];
1863: int i;
1.23 kristaps 1864: struct roffsu su;
1.4 kristaps 1865:
1866: if (SEC_SYNOPSIS == n->sec) {
1867: if (n->next && MDOC_In != n->next->tok) {
1.23 kristaps 1868: SCALE_VS_INIT(&su, 1);
1869: bufcat_su(h, "margin-bottom", &su);
1870: PAIR_STYLE_INIT(&tag[0], h);
1.17 kristaps 1871: print_otag(h, TAG_DIV, 1, tag);
1.4 kristaps 1872: } else
1873: print_otag(h, TAG_DIV, 0, NULL);
1874: }
1875:
1.34 kristaps 1876: /* FIXME: there's a buffer bug in here somewhere. */
1877:
1.23 kristaps 1878: PAIR_CLASS_INIT(&tag[0], "includes");
1.17 kristaps 1879: print_otag(h, TAG_SPAN, 1, tag);
1.4 kristaps 1880:
1881: if (SEC_SYNOPSIS == n->sec)
1882: print_text(h, "#include");
1883:
1884: print_text(h, "<");
1885: h->flags |= HTML_NOSPACE;
1886:
1887: /* XXX -- see warning in termp_in_post(). */
1888:
1.17 kristaps 1889: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1890: PAIR_CLASS_INIT(&tag[0], "link-includes");
1891: i = 1;
1.41 kristaps 1892: bufinit(h);
1.17 kristaps 1893: if (h->base_includes) {
1894: buffmt_includes(h, nn->string);
1895: tag[i].key = ATTR_HREF;
1896: tag[i++].val = h->buf;
1897: }
1898: t = print_otag(h, TAG_A, i, tag);
1.4 kristaps 1899: print_mdoc_node(m, nn, h);
1.17 kristaps 1900: print_tagq(h, t);
1901: }
1.4 kristaps 1902:
1903: h->flags |= HTML_NOSPACE;
1904: print_text(h, ">");
1905:
1906: return(0);
1907: }
1908:
1909:
1910: /* ARGSUSED */
1911: static int
1912: mdoc_ic_pre(MDOC_ARGS)
1913: {
1914: struct htmlpair tag;
1915:
1.23 kristaps 1916: PAIR_CLASS_INIT(&tag, "cmd");
1.4 kristaps 1917: print_otag(h, TAG_SPAN, 1, &tag);
1918: return(1);
1919: }
1920:
1921:
1922: /* ARGSUSED */
1923: static int
1924: mdoc_rv_pre(MDOC_ARGS)
1925: {
1926: const struct mdoc_node *nn;
1927: struct htmlpair tag;
1928: struct tag *t;
1929:
1930: print_otag(h, TAG_DIV, 0, NULL);
1931: print_text(h, "The");
1932:
1933: for (nn = n->child; nn; nn = nn->next) {
1.23 kristaps 1934: PAIR_CLASS_INIT(&tag, "fname");
1.4 kristaps 1935: t = print_otag(h, TAG_SPAN, 1, &tag);
1936: print_text(h, nn->string);
1937: print_tagq(h, t);
1938:
1939: h->flags |= HTML_NOSPACE;
1940: if (nn->next && NULL == nn->next->next)
1941: print_text(h, "(), and");
1942: else if (nn->next)
1943: print_text(h, "(),");
1944: else
1945: print_text(h, "()");
1946: }
1947:
1948: if (n->child->next)
1949: print_text(h, "functions return");
1950: else
1951: print_text(h, "function returns");
1952:
1953: print_text(h, "the value 0 if successful; otherwise the value "
1954: "-1 is returned and the global variable");
1955:
1.23 kristaps 1956: PAIR_CLASS_INIT(&tag, "var");
1.4 kristaps 1957: t = print_otag(h, TAG_SPAN, 1, &tag);
1958: print_text(h, "errno");
1959: print_tagq(h, t);
1960: print_text(h, "is set to indicate the error.");
1961: return(0);
1962: }
1963:
1964:
1965: /* ARGSUSED */
1966: static int
1967: mdoc_va_pre(MDOC_ARGS)
1968: {
1969: struct htmlpair tag;
1970:
1.23 kristaps 1971: PAIR_CLASS_INIT(&tag, "var");
1.4 kristaps 1972: print_otag(h, TAG_SPAN, 1, &tag);
1973: return(1);
1974: }
1975:
1976:
1977: /* ARGSUSED */
1978: static int
1979: mdoc_bq_pre(MDOC_ARGS)
1980: {
1981:
1982: if (MDOC_BODY != n->type)
1983: return(1);
1984: print_text(h, "\\(lB");
1985: h->flags |= HTML_NOSPACE;
1986: return(1);
1987: }
1988:
1989:
1990: /* ARGSUSED */
1991: static void
1992: mdoc_bq_post(MDOC_ARGS)
1993: {
1994:
1995: if (MDOC_BODY != n->type)
1996: return;
1997: h->flags |= HTML_NOSPACE;
1998: print_text(h, "\\(rB");
1999: }
1.5 kristaps 2000:
2001:
2002: /* ARGSUSED */
2003: static int
2004: mdoc_ap_pre(MDOC_ARGS)
2005: {
2006:
2007: h->flags |= HTML_NOSPACE;
2008: print_text(h, "\\(aq");
2009: h->flags |= HTML_NOSPACE;
2010: return(1);
2011: }
2012:
2013:
2014: /* ARGSUSED */
2015: static int
2016: mdoc_bf_pre(MDOC_ARGS)
2017: {
1.23 kristaps 2018: int i;
2019: struct htmlpair tag[2];
2020: struct roffsu su;
1.5 kristaps 2021:
2022: if (MDOC_HEAD == n->type)
2023: return(0);
2024: else if (MDOC_BLOCK != n->type)
2025: return(1);
2026:
1.23 kristaps 2027: PAIR_CLASS_INIT(&tag[0], "lit");
1.5 kristaps 2028:
2029: if (n->head->child) {
2030: if ( ! strcmp("Em", n->head->child->string))
1.23 kristaps 2031: PAIR_CLASS_INIT(&tag[0], "emph");
1.5 kristaps 2032: else if ( ! strcmp("Sy", n->head->child->string))
1.23 kristaps 2033: PAIR_CLASS_INIT(&tag[0], "symb");
1.5 kristaps 2034: else if ( ! strcmp("Li", n->head->child->string))
1.23 kristaps 2035: PAIR_CLASS_INIT(&tag[0], "lit");
1.5 kristaps 2036: } else {
2037: assert(n->args);
2038: for (i = 0; i < (int)n->args->argc; i++)
2039: switch (n->args->argv[i].arg) {
2040: case (MDOC_Symbolic):
1.23 kristaps 2041: PAIR_CLASS_INIT(&tag[0], "symb");
1.5 kristaps 2042: break;
2043: case (MDOC_Literal):
1.23 kristaps 2044: PAIR_CLASS_INIT(&tag[0], "lit");
1.5 kristaps 2045: break;
2046: case (MDOC_Emphasis):
1.23 kristaps 2047: PAIR_CLASS_INIT(&tag[0], "emph");
1.5 kristaps 2048: break;
2049: default:
2050: break;
2051: }
2052: }
2053:
2054: /* FIXME: div's have spaces stripped--we want them. */
2055:
1.23 kristaps 2056: bufcat_style(h, "display", "inline");
2057: SCALE_HS_INIT(&su, 1);
2058: bufcat_su(h, "margin-right", &su);
2059: PAIR_STYLE_INIT(&tag[1], h);
1.5 kristaps 2060: print_otag(h, TAG_DIV, 2, tag);
2061: return(1);
2062: }
2063:
2064:
2065: /* ARGSUSED */
2066: static int
2067: mdoc_ms_pre(MDOC_ARGS)
2068: {
2069: struct htmlpair tag;
2070:
1.23 kristaps 2071: PAIR_CLASS_INIT(&tag, "symb");
1.5 kristaps 2072: print_otag(h, TAG_SPAN, 1, &tag);
2073: return(1);
2074: }
2075:
2076:
2077: /* ARGSUSED */
2078: static int
2079: mdoc_pf_pre(MDOC_ARGS)
2080: {
2081:
2082: h->flags |= HTML_IGNDELIM;
2083: return(1);
2084: }
2085:
2086:
2087: /* ARGSUSED */
2088: static void
2089: mdoc_pf_post(MDOC_ARGS)
2090: {
2091:
2092: h->flags &= ~HTML_IGNDELIM;
2093: h->flags |= HTML_NOSPACE;
2094: }
2095:
2096:
2097: /* ARGSUSED */
2098: static int
2099: mdoc_rs_pre(MDOC_ARGS)
2100: {
1.23 kristaps 2101: struct htmlpair tag;
2102: struct roffsu su;
1.5 kristaps 2103:
2104: if (MDOC_BLOCK != n->type)
2105: return(1);
2106:
1.8 kristaps 2107: if (n->prev && SEC_SEE_ALSO == n->sec) {
1.23 kristaps 2108: SCALE_VS_INIT(&su, 1);
2109: bufcat_su(h, "margin-top", &su);
2110: PAIR_STYLE_INIT(&tag, h);
1.8 kristaps 2111: print_otag(h, TAG_DIV, 1, &tag);
1.5 kristaps 2112: }
2113:
1.23 kristaps 2114: PAIR_CLASS_INIT(&tag, "ref");
1.8 kristaps 2115: print_otag(h, TAG_SPAN, 1, &tag);
1.5 kristaps 2116: return(1);
2117: }
1.6 kristaps 2118:
2119:
2120:
2121: /* ARGSUSED */
2122: static int
2123: mdoc_li_pre(MDOC_ARGS)
2124: {
2125: struct htmlpair tag;
2126:
1.23 kristaps 2127: PAIR_CLASS_INIT(&tag, "lit");
1.6 kristaps 2128: print_otag(h, TAG_SPAN, 1, &tag);
2129: return(1);
2130: }
2131:
2132:
2133: /* ARGSUSED */
2134: static int
2135: mdoc_sy_pre(MDOC_ARGS)
2136: {
2137: struct htmlpair tag;
2138:
1.23 kristaps 2139: PAIR_CLASS_INIT(&tag, "symb");
1.6 kristaps 2140: print_otag(h, TAG_SPAN, 1, &tag);
2141: return(1);
2142: }
2143:
2144:
2145: /* ARGSUSED */
2146: static int
2147: mdoc_bt_pre(MDOC_ARGS)
2148: {
2149:
2150: print_text(h, "is currently in beta test.");
2151: return(0);
2152: }
2153:
2154:
2155: /* ARGSUSED */
2156: static int
2157: mdoc_ud_pre(MDOC_ARGS)
2158: {
2159:
2160: print_text(h, "currently under development.");
2161: return(0);
2162: }
2163:
2164:
2165: /* ARGSUSED */
2166: static int
2167: mdoc_lb_pre(MDOC_ARGS)
2168: {
2169: struct htmlpair tag;
2170:
2171: if (SEC_SYNOPSIS == n->sec)
2172: print_otag(h, TAG_DIV, 0, NULL);
1.23 kristaps 2173: PAIR_CLASS_INIT(&tag, "lib");
1.6 kristaps 2174: print_otag(h, TAG_SPAN, 1, &tag);
2175: return(1);
2176: }
1.10 kristaps 2177:
2178:
2179: /* ARGSUSED */
2180: static int
2181: mdoc__x_pre(MDOC_ARGS)
2182: {
1.38 kristaps 2183: struct htmlpair tag[2];
1.37 kristaps 2184:
1.10 kristaps 2185: switch (n->tok) {
2186: case(MDOC__A):
1.38 kristaps 2187: PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.10 kristaps 2188: break;
2189: case(MDOC__B):
1.38 kristaps 2190: PAIR_CLASS_INIT(&tag[0], "ref-book");
1.10 kristaps 2191: break;
2192: case(MDOC__C):
1.38 kristaps 2193: PAIR_CLASS_INIT(&tag[0], "ref-city");
1.10 kristaps 2194: break;
2195: case(MDOC__D):
1.38 kristaps 2196: PAIR_CLASS_INIT(&tag[0], "ref-date");
1.10 kristaps 2197: break;
2198: case(MDOC__I):
1.38 kristaps 2199: PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.10 kristaps 2200: break;
2201: case(MDOC__J):
1.38 kristaps 2202: PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.10 kristaps 2203: break;
2204: case(MDOC__N):
1.38 kristaps 2205: PAIR_CLASS_INIT(&tag[0], "ref-num");
1.10 kristaps 2206: break;
2207: case(MDOC__O):
1.38 kristaps 2208: PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.10 kristaps 2209: break;
2210: case(MDOC__P):
1.38 kristaps 2211: PAIR_CLASS_INIT(&tag[0], "ref-page");
1.10 kristaps 2212: break;
2213: case(MDOC__Q):
1.38 kristaps 2214: PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.10 kristaps 2215: break;
2216: case(MDOC__R):
1.38 kristaps 2217: PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.10 kristaps 2218: break;
2219: case(MDOC__T):
1.38 kristaps 2220: PAIR_CLASS_INIT(&tag[0], "ref-title");
1.10 kristaps 2221: print_text(h, "\\(lq");
2222: h->flags |= HTML_NOSPACE;
2223: break;
1.38 kristaps 2224: case(MDOC__U):
2225: PAIR_CLASS_INIT(&tag[0], "link-ref");
2226: break;
1.10 kristaps 2227: case(MDOC__V):
1.38 kristaps 2228: PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.10 kristaps 2229: break;
2230: default:
2231: abort();
2232: /* NOTREACHED */
2233: }
2234:
1.38 kristaps 2235: if (MDOC__U != n->tok) {
2236: print_otag(h, TAG_SPAN, 1, tag);
2237: return(1);
2238: }
2239:
2240: PAIR_HREF_INIT(&tag[1], n->child->string);
2241: print_otag(h, TAG_A, 2, tag);
1.10 kristaps 2242: return(1);
2243: }
2244:
2245:
2246: /* ARGSUSED */
2247: static void
2248: mdoc__x_post(MDOC_ARGS)
2249: {
2250:
2251: h->flags |= HTML_NOSPACE;
2252: switch (n->tok) {
2253: case (MDOC__T):
2254: print_text(h, "\\(rq");
2255: h->flags |= HTML_NOSPACE;
2256: break;
2257: default:
2258: break;
2259: }
2260: print_text(h, n->next ? "," : ".");
2261: }
CVSweb