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