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