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