version 1.42, 2009/10/28 08:00:18 |
version 1.61, 2010/04/08 08:17:55 |
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
|
#ifdef HAVE_CONFIG_H |
|
#include "config.h" |
|
#endif |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/param.h> |
|
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <err.h> |
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
|
const struct mdoc_node *n, \ |
const struct mdoc_node *n, \ |
struct html *h |
struct html *h |
|
|
|
#ifndef MIN |
|
#define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b)) |
|
#endif |
|
|
struct htmlmdoc { |
struct htmlmdoc { |
int (*pre)(MDOC_ARGS); |
int (*pre)(MDOC_ARGS); |
void (*post)(MDOC_ARGS); |
void (*post)(MDOC_ARGS); |
Line 127 static int mdoc_vt_pre(MDOC_ARGS); |
|
Line 133 static int mdoc_vt_pre(MDOC_ARGS); |
|
static int mdoc_xr_pre(MDOC_ARGS); |
static int mdoc_xr_pre(MDOC_ARGS); |
static int mdoc_xx_pre(MDOC_ARGS); |
static int mdoc_xx_pre(MDOC_ARGS); |
|
|
#ifdef __linux__ |
|
extern size_t strlcpy(char *, const char *, size_t); |
|
extern size_t strlcat(char *, const char *, size_t); |
|
#endif |
|
|
|
static const struct htmlmdoc mdocs[MDOC_MAX] = { |
static const struct htmlmdoc mdocs[MDOC_MAX] = { |
{mdoc_ap_pre, NULL}, /* Ap */ |
{mdoc_ap_pre, NULL}, /* Ap */ |
{NULL, NULL}, /* Dd */ |
{NULL, NULL}, /* Dd */ |
Line 199 static const struct htmlmdoc mdocs[MDOC_MAX] = { |
|
Line 200 static const struct htmlmdoc mdocs[MDOC_MAX] = { |
|
{NULL, NULL}, /* Dc */ |
{NULL, NULL}, /* Dc */ |
{mdoc_dq_pre, mdoc_dq_post}, /* Do */ |
{mdoc_dq_pre, mdoc_dq_post}, /* Do */ |
{mdoc_dq_pre, mdoc_dq_post}, /* Dq */ |
{mdoc_dq_pre, mdoc_dq_post}, /* Dq */ |
{NULL, NULL}, /* Ec */ |
{NULL, NULL}, /* Ec */ /* FIXME: no space */ |
{NULL, NULL}, /* Ef */ |
{NULL, NULL}, /* Ef */ |
{mdoc_em_pre, NULL}, /* Em */ |
{mdoc_em_pre, NULL}, /* Em */ |
{NULL, NULL}, /* Eo */ |
{NULL, NULL}, /* Eo */ |
Line 265 html_mdoc(void *arg, const struct mdoc *m) |
|
Line 266 html_mdoc(void *arg, const struct mdoc *m) |
|
|
|
h = (struct html *)arg; |
h = (struct html *)arg; |
|
|
print_gen_doctype(h); |
print_gen_decls(h); |
t = print_otag(h, TAG_HTML, 0, NULL); |
t = print_otag(h, TAG_HTML, 0, NULL); |
print_mdoc(mdoc_meta(m), mdoc_node(m), h); |
print_mdoc(mdoc_meta(m), mdoc_node(m), h); |
print_tagq(h, t); |
print_tagq(h, t); |
Line 425 print_mdoc_node(MDOC_ARGS) |
|
Line 426 print_mdoc_node(MDOC_ARGS) |
|
break; |
break; |
case (MDOC_TEXT): |
case (MDOC_TEXT): |
print_text(h, n->string); |
print_text(h, n->string); |
break; |
return; |
default: |
default: |
if (mdocs[n->tok].pre) |
if (mdocs[n->tok].pre) |
child = (*mdocs[n->tok].pre)(m, n, h); |
child = (*mdocs[n->tok].pre)(m, n, h); |
Line 442 print_mdoc_node(MDOC_ARGS) |
|
Line 443 print_mdoc_node(MDOC_ARGS) |
|
case (MDOC_ROOT): |
case (MDOC_ROOT): |
mdoc_root_post(m, n, h); |
mdoc_root_post(m, n, h); |
break; |
break; |
case (MDOC_TEXT): |
|
break; |
|
default: |
default: |
if (mdocs[n->tok].post) |
if (mdocs[n->tok].post) |
(*mdocs[n->tok].post)(m, n, h); |
(*mdocs[n->tok].post)(m, n, h); |
Line 590 mdoc_sh_pre(MDOC_ARGS) |
|
Line 589 mdoc_sh_pre(MDOC_ARGS) |
|
html_idcat(buf, " ", BUFSIZ); |
html_idcat(buf, " ", BUFSIZ); |
} |
} |
|
|
/* |
|
* TODO: make sure there are no duplicates, as HTML does not |
|
* allow for multiple `id' tags of the same name. |
|
*/ |
|
|
|
PAIR_CLASS_INIT(&tag[0], "sec-head"); |
PAIR_CLASS_INIT(&tag[0], "sec-head"); |
tag[1].key = ATTR_ID; |
PAIR_ID_INIT(&tag[1], buf); |
tag[1].val = buf; |
|
print_otag(h, TAG_DIV, 2, tag); |
print_otag(h, TAG_DIV, 2, tag); |
return(1); |
return(1); |
} |
} |
Line 649 mdoc_ss_pre(MDOC_ARGS) |
|
Line 643 mdoc_ss_pre(MDOC_ARGS) |
|
|
|
PAIR_CLASS_INIT(&tag[0], "ssec-head"); |
PAIR_CLASS_INIT(&tag[0], "ssec-head"); |
PAIR_STYLE_INIT(&tag[1], h); |
PAIR_STYLE_INIT(&tag[1], h); |
tag[2].key = ATTR_ID; |
PAIR_ID_INIT(&tag[2], buf); |
tag[2].val = buf; |
|
print_otag(h, TAG_DIV, 3, tag); |
print_otag(h, TAG_DIV, 3, tag); |
return(1); |
return(1); |
} |
} |
Line 664 mdoc_fl_pre(MDOC_ARGS) |
|
Line 658 mdoc_fl_pre(MDOC_ARGS) |
|
|
|
PAIR_CLASS_INIT(&tag, "flag"); |
PAIR_CLASS_INIT(&tag, "flag"); |
print_otag(h, TAG_SPAN, 1, &tag); |
print_otag(h, TAG_SPAN, 1, &tag); |
if (MDOC_Fl == n->tok) { |
|
print_text(h, "\\-"); |
/* `Cm' has no leading hyphen. */ |
|
|
|
if (MDOC_Cm == n->tok) |
|
return(1); |
|
|
|
print_text(h, "\\-"); |
|
|
|
if (n->child) |
h->flags |= HTML_NOSPACE; |
h->flags |= HTML_NOSPACE; |
} |
else if (n->next && n->next->line == n->line) |
|
h->flags |= HTML_NOSPACE; |
|
|
return(1); |
return(1); |
} |
} |
|
|
Line 726 mdoc_nm_pre(MDOC_ARGS) |
|
Line 729 mdoc_nm_pre(MDOC_ARGS) |
|
{ |
{ |
struct htmlpair tag; |
struct htmlpair tag; |
|
|
if ( ! (HTML_NEWLINE & h->flags)) |
if (SEC_SYNOPSIS == n->sec && n->prev) { |
if (SEC_SYNOPSIS == n->sec) { |
bufcat_style(h, "clear", "both"); |
bufcat_style(h, "clear", "both"); |
PAIR_STYLE_INIT(&tag, h); |
PAIR_STYLE_INIT(&tag, h); |
print_otag(h, TAG_BR, 1, &tag); |
print_otag(h, TAG_BR, 1, &tag); |
} |
} |
|
|
|
PAIR_CLASS_INIT(&tag, "name"); |
PAIR_CLASS_INIT(&tag, "name"); |
print_otag(h, TAG_SPAN, 1, &tag); |
print_otag(h, TAG_SPAN, 1, &tag); |
Line 749 mdoc_xr_pre(MDOC_ARGS) |
|
Line 751 mdoc_xr_pre(MDOC_ARGS) |
|
struct htmlpair tag[2]; |
struct htmlpair tag[2]; |
const struct mdoc_node *nn; |
const struct mdoc_node *nn; |
|
|
|
if (NULL == n->child) |
|
return(0); |
|
|
PAIR_CLASS_INIT(&tag[0], "link-man"); |
PAIR_CLASS_INIT(&tag[0], "link-man"); |
|
|
if (h->base_man) { |
if (h->base_man) { |
buffmt_man(h, n->child->string, |
buffmt_man(h, n->child->string, |
n->child->next ? |
n->child->next ? |
n->child->next->string : NULL); |
n->child->next->string : NULL); |
tag[1].key = ATTR_HREF; |
PAIR_HREF_INIT(&tag[1], h->buf); |
tag[1].val = h->buf; |
|
print_otag(h, TAG_A, 2, tag); |
print_otag(h, TAG_A, 2, tag); |
} else |
} else |
print_otag(h, TAG_A, 1, tag); |
print_otag(h, TAG_A, 1, tag); |
Line 811 mdoc_xx_pre(MDOC_ARGS) |
|
Line 815 mdoc_xx_pre(MDOC_ARGS) |
|
pp = "BSDI BSD/OS"; |
pp = "BSDI BSD/OS"; |
break; |
break; |
case (MDOC_Dx): |
case (MDOC_Dx): |
pp = "DragonFlyBSD"; |
pp = "DragonFly"; |
break; |
break; |
case (MDOC_Fx): |
case (MDOC_Fx): |
pp = "FreeBSD"; |
pp = "FreeBSD"; |
Line 952 mdoc_it_head_pre(MDOC_ARGS, int type, struct roffsu *w |
|
Line 956 mdoc_it_head_pre(MDOC_ARGS, int type, struct roffsu *w |
|
|
|
switch (type) { |
switch (type) { |
case (MDOC_Item): |
case (MDOC_Item): |
/* FALLTHROUGH */ |
|
case (MDOC_Ohang): |
|
return(0); |
return(0); |
|
case (MDOC_Ohang): |
|
print_otag(h, TAG_DIV, 0, &tag); |
|
return(1); |
case (MDOC_Column): |
case (MDOC_Column): |
bufcat_su(h, "min-width", width); |
bufcat_su(h, "min-width", width); |
bufcat_style(h, "clear", "none"); |
bufcat_style(h, "clear", "none"); |
Line 1068 mdoc_it_pre(MDOC_ARGS) |
|
Line 1073 mdoc_it_pre(MDOC_ARGS) |
|
/* Override width in some cases. */ |
/* Override width in some cases. */ |
|
|
switch (type) { |
switch (type) { |
|
case (MDOC_Ohang): |
|
/* FALLTHROUGH */ |
case (MDOC_Item): |
case (MDOC_Item): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (MDOC_Inset): |
case (MDOC_Inset): |
Line 1109 mdoc_bl_pre(MDOC_ARGS) |
|
Line 1116 mdoc_bl_pre(MDOC_ARGS) |
|
{ |
{ |
struct ord *ord; |
struct ord *ord; |
|
|
|
if (MDOC_HEAD == n->type) |
|
return(0); |
if (MDOC_BLOCK != n->type) |
if (MDOC_BLOCK != n->type) |
return(1); |
return(1); |
if (MDOC_Enum != a2list(n)) |
if (MDOC_Enum != a2list(n)) |
return(1); |
return(1); |
|
|
ord = malloc(sizeof(struct ord)); |
ord = malloc(sizeof(struct ord)); |
if (NULL == ord) |
if (NULL == ord) { |
err(EXIT_FAILURE, "malloc"); |
perror(NULL); |
|
exit(EXIT_FAILURE); |
|
} |
ord->cookie = n; |
ord->cookie = n; |
ord->pos = 1; |
ord->pos = 1; |
ord->next = h->ords.head; |
ord->next = h->ords.head; |
Line 1294 mdoc_sx_pre(MDOC_ARGS) |
|
Line 1305 mdoc_sx_pre(MDOC_ARGS) |
|
const struct mdoc_node *nn; |
const struct mdoc_node *nn; |
char buf[BUFSIZ]; |
char buf[BUFSIZ]; |
|
|
/* FIXME: duplicates? */ |
|
|
|
strlcpy(buf, "#", BUFSIZ); |
strlcpy(buf, "#", BUFSIZ); |
for (nn = n->child; nn; nn = nn->next) { |
for (nn = n->child; nn; nn = nn->next) { |
html_idcat(buf, nn->string, BUFSIZ); |
html_idcat(buf, nn->string, BUFSIZ); |
Line 1304 mdoc_sx_pre(MDOC_ARGS) |
|
Line 1313 mdoc_sx_pre(MDOC_ARGS) |
|
} |
} |
|
|
PAIR_CLASS_INIT(&tag[0], "link-sec"); |
PAIR_CLASS_INIT(&tag[0], "link-sec"); |
tag[1].key = ATTR_HREF; |
PAIR_HREF_INIT(&tag[1], buf); |
tag[1].val = buf; |
|
|
|
print_otag(h, TAG_A, 2, tag); |
print_otag(h, TAG_A, 2, tag); |
return(1); |
return(1); |
Line 1380 mdoc_bd_pre(MDOC_ARGS) |
|
Line 1388 mdoc_bd_pre(MDOC_ARGS) |
|
} |
} |
|
|
/* FIXME: -centered, etc. formatting. */ |
/* FIXME: -centered, etc. formatting. */ |
|
/* FIXME: does not respect -offset ??? */ |
|
|
if (MDOC_BLOCK == n->type) { |
if (MDOC_BLOCK == n->type) { |
bufcat_su(h, "margin-left", &su); |
bufcat_su(h, "margin-left", &su); |
Line 1571 mdoc_vt_pre(MDOC_ARGS) |
|
Line 1580 mdoc_vt_pre(MDOC_ARGS) |
|
struct htmlpair tag; |
struct htmlpair tag; |
struct roffsu su; |
struct roffsu su; |
|
|
if (SEC_SYNOPSIS == n->sec) { |
if (SEC_SYNOPSIS == n->sec && MDOC_BLOCK == n->type) { |
if (n->next && MDOC_Vt != n->next->tok) { |
if (n->next && MDOC_Vt != n->next->tok) { |
SCALE_VS_INIT(&su, 1); |
SCALE_VS_INIT(&su, 1); |
bufcat_su(h, "margin-bottom", &su); |
bufcat_su(h, "margin-bottom", &su); |
Line 1579 mdoc_vt_pre(MDOC_ARGS) |
|
Line 1588 mdoc_vt_pre(MDOC_ARGS) |
|
print_otag(h, TAG_DIV, 1, &tag); |
print_otag(h, TAG_DIV, 1, &tag); |
} else |
} else |
print_otag(h, TAG_DIV, 0, NULL); |
print_otag(h, TAG_DIV, 0, NULL); |
} |
|
|
return(1); |
|
} else if (MDOC_HEAD == n->type) |
|
return(0); |
|
|
PAIR_CLASS_INIT(&tag, "type"); |
PAIR_CLASS_INIT(&tag, "type"); |
print_otag(h, TAG_SPAN, 1, &tag); |
print_otag(h, TAG_SPAN, 1, &tag); |
|
|
mdoc_ft_pre(MDOC_ARGS) |
mdoc_ft_pre(MDOC_ARGS) |
{ |
{ |
struct htmlpair tag; |
struct htmlpair tag; |
struct roffsu su; |
|
|
|
if (SEC_SYNOPSIS == n->sec) { |
if (SEC_SYNOPSIS == n->sec) |
if (n->prev && MDOC_Fo == n->prev->tok) { |
print_otag(h, TAG_DIV, 0, NULL); |
SCALE_VS_INIT(&su, 1); |
|
bufcat_su(h, "margin-top", &su); |
|
PAIR_STYLE_INIT(&tag, h); |
|
print_otag(h, TAG_DIV, 1, &tag); |
|
} else |
|
print_otag(h, TAG_DIV, 0, NULL); |
|
} |
|
|
|
PAIR_CLASS_INIT(&tag, "ftype"); |
PAIR_CLASS_INIT(&tag, "ftype"); |
print_otag(h, TAG_SPAN, 1, &tag); |
print_otag(h, TAG_SPAN, 1, &tag); |
Line 1656 mdoc_fn_pre(MDOC_ARGS) |
|
Line 1660 mdoc_fn_pre(MDOC_ARGS) |
|
} |
} |
|
|
PAIR_CLASS_INIT(&tag[0], "fname"); |
PAIR_CLASS_INIT(&tag[0], "fname"); |
|
|
|
/* |
|
* FIXME: only refer to IDs that we know exist. |
|
*/ |
|
|
|
#if 0 |
|
if (SEC_SYNOPSIS == n->sec) { |
|
nbuf[0] = '\0'; |
|
html_idcat(nbuf, sp, BUFSIZ); |
|
PAIR_ID_INIT(&tag[1], nbuf); |
|
} else { |
|
strlcpy(nbuf, "#", BUFSIZ); |
|
html_idcat(nbuf, sp, BUFSIZ); |
|
PAIR_HREF_INIT(&tag[1], nbuf); |
|
} |
|
#endif |
|
|
t = print_otag(h, TAG_SPAN, 1, tag); |
t = print_otag(h, TAG_SPAN, 1, tag); |
|
|
if (sp) { |
if (sp) { |
(void)strlcpy(nbuf, sp, BUFSIZ); |
strlcpy(nbuf, sp, BUFSIZ); |
print_text(h, nbuf); |
print_text(h, nbuf); |
} |
} |
|
|
Line 1760 mdoc_lk_pre(MDOC_ARGS) |
|
Line 1781 mdoc_lk_pre(MDOC_ARGS) |
|
nn = n->child; |
nn = n->child; |
|
|
PAIR_CLASS_INIT(&tag[0], "link-ext"); |
PAIR_CLASS_INIT(&tag[0], "link-ext"); |
tag[1].key = ATTR_HREF; |
PAIR_HREF_INIT(&tag[1], nn->string); |
tag[1].val = nn->string; |
|
print_otag(h, TAG_A, 2, tag); |
print_otag(h, TAG_A, 2, tag); |
|
|
if (NULL == nn->next) |
if (NULL == nn->next) |
Line 1788 mdoc_mt_pre(MDOC_ARGS) |
|
Line 1808 mdoc_mt_pre(MDOC_ARGS) |
|
bufinit(h); |
bufinit(h); |
bufcat(h, "mailto:"); |
bufcat(h, "mailto:"); |
bufcat(h, nn->string); |
bufcat(h, nn->string); |
PAIR_STYLE_INIT(&tag[1], h); |
PAIR_HREF_INIT(&tag[1], h->buf); |
t = print_otag(h, TAG_A, 2, tag); |
t = print_otag(h, TAG_A, 2, tag); |
print_text(h, nn->string); |
print_text(h, nn->string); |
print_tagq(h, t); |
print_tagq(h, t); |
|
|
mdoc_fo_pre(MDOC_ARGS) |
mdoc_fo_pre(MDOC_ARGS) |
{ |
{ |
struct htmlpair tag; |
struct htmlpair tag; |
|
struct roffsu su; |
|
|
if (MDOC_BODY == n->type) { |
if (MDOC_BODY == n->type) { |
h->flags |= HTML_NOSPACE; |
h->flags |= HTML_NOSPACE; |
print_text(h, "("); |
print_text(h, "("); |
h->flags |= HTML_NOSPACE; |
h->flags |= HTML_NOSPACE; |
return(1); |
return(1); |
} else if (MDOC_BLOCK == n->type) |
} else if (MDOC_BLOCK == n->type && n->next) { |
|
SCALE_VS_INIT(&su, 1); |
|
bufcat_su(h, "margin-bottom", &su); |
|
PAIR_STYLE_INIT(&tag, h); |
|
print_otag(h, TAG_DIV, 1, &tag); |
return(1); |
return(1); |
|
} |
|
|
PAIR_CLASS_INIT(&tag, "fname"); |
PAIR_CLASS_INIT(&tag, "fname"); |
print_otag(h, TAG_SPAN, 1, &tag); |
print_otag(h, TAG_SPAN, 1, &tag); |
Line 1870 mdoc_in_pre(MDOC_ARGS) |
|
Line 1896 mdoc_in_pre(MDOC_ARGS) |
|
bufinit(h); |
bufinit(h); |
if (h->base_includes) { |
if (h->base_includes) { |
buffmt_includes(h, nn->string); |
buffmt_includes(h, nn->string); |
tag[i].key = ATTR_HREF; |
PAIR_HREF_INIT(&tag[i], h->buf); |
tag[i++].val = h->buf; |
i++; |
} |
} |
t = print_otag(h, TAG_A, i, tag); |
t = print_otag(h, TAG_A, i, tag); |
print_mdoc_node(m, nn, h); |
print_mdoc_node(m, nn, h); |
Line 2196 mdoc__x_pre(MDOC_ARGS) |
|
Line 2222 mdoc__x_pre(MDOC_ARGS) |
|
break; |
break; |
case(MDOC__T): |
case(MDOC__T): |
PAIR_CLASS_INIT(&tag[0], "ref-title"); |
PAIR_CLASS_INIT(&tag[0], "ref-title"); |
print_text(h, "\\(lq"); |
|
h->flags |= HTML_NOSPACE; |
|
break; |
break; |
case(MDOC__U): |
case(MDOC__U): |
PAIR_CLASS_INIT(&tag[0], "link-ref"); |
PAIR_CLASS_INIT(&tag[0], "link-ref"); |
|
|
mdoc__x_post(MDOC_ARGS) |
mdoc__x_post(MDOC_ARGS) |
{ |
{ |
|
|
|
/* TODO: %U */ |
|
|
h->flags |= HTML_NOSPACE; |
h->flags |= HTML_NOSPACE; |
switch (n->tok) { |
|
case (MDOC__T): |
|
print_text(h, "\\(rq"); |
|
h->flags |= HTML_NOSPACE; |
|
break; |
|
default: |
|
break; |
|
} |
|
print_text(h, n->next ? "," : "."); |
print_text(h, n->next ? "," : "."); |
} |
} |