Unleashed v1.4
[unleashed.git] / bin / mandoc / roff_html.c
blob02b8beea3bdc9d1783435dcd73ddba34b511fede
1 /* $Id: roff_html.c,v 1.19 2019/01/07 07:26:29 schwarze Exp $ */
2 /*
3 * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2017, 2018, 2019 Ingo Schwarze <schwarze@openbsd.org>
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.
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.
18 #include <sys/types.h>
20 #include <assert.h>
21 #include <stdio.h>
22 #include <string.h>
24 #include "mandoc.h"
25 #include "roff.h"
26 #include "out.h"
27 #include "html.h"
29 #define ROFF_HTML_ARGS struct html *h, const struct roff_node *n
31 typedef void (*roff_html_pre_fp)(ROFF_HTML_ARGS);
33 static void roff_html_pre_br(ROFF_HTML_ARGS);
34 static void roff_html_pre_ce(ROFF_HTML_ARGS);
35 static void roff_html_pre_fi(ROFF_HTML_ARGS);
36 static void roff_html_pre_ft(ROFF_HTML_ARGS);
37 static void roff_html_pre_nf(ROFF_HTML_ARGS);
38 static void roff_html_pre_sp(ROFF_HTML_ARGS);
40 static const roff_html_pre_fp roff_html_pre_acts[ROFF_MAX] = {
41 roff_html_pre_br, /* br */
42 roff_html_pre_ce, /* ce */
43 roff_html_pre_fi, /* fi */
44 roff_html_pre_ft, /* ft */
45 NULL, /* ll */
46 NULL, /* mc */
47 roff_html_pre_nf, /* nf */
48 NULL, /* po */
49 roff_html_pre_ce, /* rj */
50 roff_html_pre_sp, /* sp */
51 NULL, /* ta */
52 NULL, /* ti */
56 void
57 roff_html_pre(struct html *h, const struct roff_node *n)
59 assert(n->tok < ROFF_MAX);
60 if (roff_html_pre_acts[n->tok] != NULL)
61 (*roff_html_pre_acts[n->tok])(h, n);
64 static void
65 roff_html_pre_br(ROFF_HTML_ARGS)
67 print_otag(h, TAG_BR, "");
70 static void
71 roff_html_pre_ce(ROFF_HTML_ARGS)
73 for (n = n->child->next; n != NULL; n = n->next) {
74 if (n->type == ROFFT_TEXT) {
75 if (n->flags & NODE_LINE)
76 roff_html_pre_br(h, n);
77 print_text(h, n->string);
78 } else
79 roff_html_pre(h, n);
81 roff_html_pre_br(h, n);
84 static void
85 roff_html_pre_fi(ROFF_HTML_ARGS)
87 if (html_fillmode(h, TOKEN_NONE) == ROFF_fi)
88 print_otag(h, TAG_BR, "");
91 static void
92 roff_html_pre_ft(ROFF_HTML_ARGS)
94 const char *cp;
96 cp = n->child->string;
97 print_metaf(h, mandoc_font(cp, (int)strlen(cp)));
100 static void
101 roff_html_pre_nf(ROFF_HTML_ARGS)
103 if (html_fillmode(h, TOKEN_NONE) == ROFF_nf)
104 print_otag(h, TAG_BR, "");
107 static void
108 roff_html_pre_sp(ROFF_HTML_ARGS)
110 if (html_fillmode(h, TOKEN_NONE) == ROFF_nf) {
111 h->col++;
112 print_endline(h);
113 } else {
114 html_close_paragraph(h);
115 print_otag(h, TAG_P, "c", "Pp");