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