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