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