version 1.40, 2009/10/27 04:50:15 |
version 1.53, 2010/01/29 14:39:38 |
|
|
* 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 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 556 mdoc_sh_pre(MDOC_ARGS) |
|
Line 555 mdoc_sh_pre(MDOC_ARGS) |
|
{ |
{ |
struct htmlpair tag[2]; |
struct htmlpair tag[2]; |
const struct mdoc_node *nn; |
const struct mdoc_node *nn; |
char lbuf[BUFSIZ]; |
char buf[BUFSIZ]; |
struct roffsu su; |
struct roffsu su; |
|
|
if (MDOC_BODY == n->type) { |
if (MDOC_BODY == n->type) { |
Line 583 mdoc_sh_pre(MDOC_ARGS) |
|
Line 582 mdoc_sh_pre(MDOC_ARGS) |
|
return(1); |
return(1); |
} |
} |
|
|
lbuf[0] = 0; |
buf[0] = '\0'; |
for (nn = n->child; nn; nn = nn->next) { |
for (nn = n->child; nn; nn = nn->next) { |
(void)strlcat(lbuf, nn->string, BUFSIZ); |
html_idcat(buf, nn->string, BUFSIZ); |
if (nn->next) |
if (nn->next) |
(void)strlcat(lbuf, "_", BUFSIZ); |
html_idcat(buf, " ", BUFSIZ); |
} |
} |
|
|
/* |
/* |
Line 597 mdoc_sh_pre(MDOC_ARGS) |
|
Line 596 mdoc_sh_pre(MDOC_ARGS) |
|
|
|
PAIR_CLASS_INIT(&tag[0], "sec-head"); |
PAIR_CLASS_INIT(&tag[0], "sec-head"); |
tag[1].key = ATTR_ID; |
tag[1].key = ATTR_ID; |
tag[1].val = lbuf; |
tag[1].val = buf; |
print_otag(h, TAG_DIV, 2, tag); |
print_otag(h, TAG_DIV, 2, tag); |
return(1); |
return(1); |
} |
} |
Line 609 mdoc_ss_pre(MDOC_ARGS) |
|
Line 608 mdoc_ss_pre(MDOC_ARGS) |
|
{ |
{ |
struct htmlpair tag[3]; |
struct htmlpair tag[3]; |
const struct mdoc_node *nn; |
const struct mdoc_node *nn; |
char lbuf[BUFSIZ]; |
char buf[BUFSIZ]; |
struct roffsu su; |
struct roffsu su; |
|
|
SCALE_VS_INIT(&su, 1); |
SCALE_VS_INIT(&su, 1); |
Line 636 mdoc_ss_pre(MDOC_ARGS) |
|
Line 635 mdoc_ss_pre(MDOC_ARGS) |
|
|
|
/* TODO: see note in mdoc_sh_pre() about duplicates. */ |
/* TODO: see note in mdoc_sh_pre() about duplicates. */ |
|
|
lbuf[0] = 0; |
buf[0] = '\0'; |
for (nn = n->child; nn; nn = nn->next) { |
for (nn = n->child; nn; nn = nn->next) { |
(void)strlcat(lbuf, nn->string, BUFSIZ); |
html_idcat(buf, nn->string, BUFSIZ); |
if (nn->next) |
if (nn->next) |
(void)strlcat(lbuf, "_", BUFSIZ); |
html_idcat(buf, " ", BUFSIZ); |
} |
} |
|
|
SCALE_HS_INIT(&su, INDENT - HALFINDENT); |
SCALE_HS_INIT(&su, INDENT - HALFINDENT); |
Line 650 mdoc_ss_pre(MDOC_ARGS) |
|
Line 649 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; |
tag[2].key = ATTR_ID; |
tag[2].val = lbuf; |
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 663 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, "\\-"); |
|
|
|
/* A blank `Fl' should incur a subsequent space. */ |
|
|
|
if (n->child) |
h->flags |= HTML_NOSPACE; |
h->flags |= HTML_NOSPACE; |
} |
|
return(1); |
return(1); |
} |
} |
|
|
Line 726 mdoc_nm_pre(MDOC_ARGS) |
|
Line 734 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 811 mdoc_xx_pre(MDOC_ARGS) |
|
Line 818 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 959 mdoc_it_head_pre(MDOC_ARGS, int type, struct roffsu *w |
|
|
|
switch (type) { |
switch (type) { |
case (MDOC_Item): |
case (MDOC_Item): |
/* FALLTHROUGH */ |
return(0); |
case (MDOC_Ohang): |
case (MDOC_Ohang): |
print_otag(h, TAG_DIV, 0, NULL); |
print_otag(h, TAG_DIV, 0, &tag); |
break; |
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 1069 mdoc_it_pre(MDOC_ARGS) |
|
Line 1076 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 1116 mdoc_bl_pre(MDOC_ARGS) |
|
Line 1125 mdoc_bl_pre(MDOC_ARGS) |
|
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 1297 mdoc_sx_pre(MDOC_ARGS) |
|
Line 1308 mdoc_sx_pre(MDOC_ARGS) |
|
|
|
/* FIXME: duplicates? */ |
/* FIXME: duplicates? */ |
|
|
(void)strlcpy(buf, "#", BUFSIZ); |
strlcpy(buf, "#", BUFSIZ); |
for (nn = n->child; nn; nn = nn->next) { |
for (nn = n->child; nn; nn = nn->next) { |
(void)strlcat(buf, nn->string, BUFSIZ); |
html_idcat(buf, nn->string, BUFSIZ); |
if (nn->next) |
if (nn->next) |
(void)strlcat(buf, "_", BUFSIZ); |
html_idcat(buf, " ", BUFSIZ); |
} |
} |
|
|
PAIR_CLASS_INIT(&tag[0], "link-sec"); |
PAIR_CLASS_INIT(&tag[0], "link-sec"); |
Line 1573 mdoc_vt_pre(MDOC_ARGS) |
|
Line 1584 mdoc_vt_pre(MDOC_ARGS) |
|
struct roffsu su; |
struct roffsu su; |
|
|
if (SEC_SYNOPSIS == n->sec) { |
if (SEC_SYNOPSIS == n->sec) { |
if (n->next && MDOC_Vt != n->next->tok) { |
if (n->prev && MDOC_Vt != n->prev->tok) { |
SCALE_VS_INIT(&su, 1); |
SCALE_VS_INIT(&su, 1); |
bufcat_su(h, "margin-bottom", &su); |
bufcat_su(h, "margin-top", &su); |
PAIR_STYLE_INIT(&tag, h); |
PAIR_STYLE_INIT(&tag, h); |
print_otag(h, TAG_DIV, 1, &tag); |
print_otag(h, TAG_DIV, 1, &tag); |
} else |
} else |
Line 1718 mdoc_sp_pre(MDOC_ARGS) |
|
Line 1729 mdoc_sp_pre(MDOC_ARGS) |
|
bufcat_su(h, "height", &su); |
bufcat_su(h, "height", &su); |
PAIR_STYLE_INIT(&tag, h); |
PAIR_STYLE_INIT(&tag, h); |
print_otag(h, TAG_DIV, 1, &tag); |
print_otag(h, TAG_DIV, 1, &tag); |
return(1); |
/* So the div isn't empty: */ |
|
print_text(h, "\\~"); |
|
|
|
return(0); |
|
|
} |
} |
|
|
|
|
Line 1865 mdoc_in_pre(MDOC_ARGS) |
|
Line 1879 mdoc_in_pre(MDOC_ARGS) |
|
for (nn = n->child; nn; nn = nn->next) { |
for (nn = n->child; nn; nn = nn->next) { |
PAIR_CLASS_INIT(&tag[0], "link-includes"); |
PAIR_CLASS_INIT(&tag[0], "link-includes"); |
i = 1; |
i = 1; |
|
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; |
tag[i].key = ATTR_HREF; |