1 /* $Id: roff_html.c,v 1.8 2017/06/08 12:54:58 schwarze Exp $ */
3 * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2017 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>
27 #define ROFF_HTML_ARGS struct html *h, const struct roff_node *n
29 typedef void (*roff_html_pre_fp
)(ROFF_HTML_ARGS
);
31 static void roff_html_pre_br(ROFF_HTML_ARGS
);
32 static void roff_html_pre_ce(ROFF_HTML_ARGS
);
33 static void roff_html_pre_sp(ROFF_HTML_ARGS
);
35 static const roff_html_pre_fp roff_html_pre_acts
[ROFF_MAX
] = {
36 roff_html_pre_br
, /* br */
37 roff_html_pre_ce
, /* ce */
41 roff_html_pre_sp
, /* sp */
48 roff_html_pre(struct html
*h
, const struct roff_node
*n
)
50 assert(n
->tok
< ROFF_MAX
);
51 if (roff_html_pre_acts
[n
->tok
] != NULL
)
52 (*roff_html_pre_acts
[n
->tok
])(h
, n
);
56 roff_html_pre_br(ROFF_HTML_ARGS
)
60 t
= print_otag(h
, TAG_DIV
, "");
61 print_text(h
, "\\~"); /* So the div isn't empty. */
66 roff_html_pre_ce(ROFF_HTML_ARGS
)
68 for (n
= n
->child
->next
; n
!= NULL
; n
= n
->next
) {
69 if (n
->type
== ROFFT_TEXT
) {
70 if (n
->flags
& NODE_LINE
)
71 roff_html_pre_br(h
, n
);
72 print_text(h
, n
->string
);
76 roff_html_pre_br(h
, n
);
80 roff_html_pre_sp(ROFF_HTML_ARGS
)
84 SCALE_VS_INIT(&su
, 1);
85 if ((n
= n
->child
) != NULL
) {
86 if (a2roffsu(n
->string
, &su
, SCALE_VS
) == NULL
)
88 else if (su
.scale
< 0.0)
91 print_otag(h
, TAG_DIV
, "suh", &su
);
92 print_text(h
, "\\~"); /* So the div isn't empty. */