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