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