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