version 1.29, 2009/10/13 10:57:25 |
version 1.39, 2009/10/26 08:18:16 |
|
|
*/ |
*/ |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/queue.h> |
|
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
Line 254 static const struct htmlmdoc mdocs[MDOC_MAX] = { |
|
Line 253 static const struct htmlmdoc mdocs[MDOC_MAX] = { |
|
{mdoc__x_pre, mdoc__x_post}, /* %Q */ |
{mdoc__x_pre, mdoc__x_post}, /* %Q */ |
{mdoc_sp_pre, NULL}, /* br */ |
{mdoc_sp_pre, NULL}, /* br */ |
{mdoc_sp_pre, NULL}, /* sp */ |
{mdoc_sp_pre, NULL}, /* sp */ |
|
{mdoc__x_pre, mdoc__x_post}, /* %U */ |
}; |
}; |
|
|
|
|
|
|
a2width(const char *p, struct roffsu *su) |
a2width(const char *p, struct roffsu *su) |
{ |
{ |
|
|
if (a2roffsu(p, su)) |
if ( ! a2roffsu(p, su, SCALE_MAX)) { |
return; |
su->unit = SCALE_EM; |
su->unit = SCALE_EM; |
su->scale = (int)strlen(p); |
su->scale = (int)strlen(p); |
} |
} |
} |
|
|
|
|
|
|
a2offs(const char *p, struct roffsu *su) |
a2offs(const char *p, struct roffsu *su) |
{ |
{ |
|
|
|
/* FIXME: "right"? */ |
|
|
if (0 == strcmp(p, "left")) |
if (0 == strcmp(p, "left")) |
SCALE_HS_INIT(su, 0); |
SCALE_HS_INIT(su, 0); |
else if (0 == strcmp(p, "indent")) |
else if (0 == strcmp(p, "indent")) |
SCALE_HS_INIT(su, INDENT); |
SCALE_HS_INIT(su, INDENT); |
else if (0 == strcmp(p, "indent-two")) |
else if (0 == strcmp(p, "indent-two")) |
SCALE_HS_INIT(su, INDENT * 2); |
SCALE_HS_INIT(su, INDENT * 2); |
else if ( ! a2roffsu(p, su)) { |
else if ( ! a2roffsu(p, su, SCALE_MAX)) { |
su->unit = SCALE_EM; |
su->unit = SCALE_EM; |
su->scale = (int)strlen(p); |
su->scale = (int)strlen(p); |
} |
} |
Line 414 print_mdoc_node(MDOC_ARGS) |
|
Line 416 print_mdoc_node(MDOC_ARGS) |
|
struct tag *t; |
struct tag *t; |
|
|
child = 1; |
child = 1; |
t = SLIST_FIRST(&h->tags); |
t = h->tags.head; |
|
|
bufinit(h); |
bufinit(h); |
switch (n->type) { |
switch (n->type) { |
Line 454 print_mdoc_node(MDOC_ARGS) |
|
Line 456 print_mdoc_node(MDOC_ARGS) |
|
static void |
static void |
mdoc_root_post(MDOC_ARGS) |
mdoc_root_post(MDOC_ARGS) |
{ |
{ |
struct tm tm; |
|
struct htmlpair tag[2]; |
struct htmlpair tag[2]; |
struct tag *t, *tt; |
struct tag *t, *tt; |
char b[BUFSIZ]; |
char b[DATESIZ]; |
|
|
|
time2a(m->date, b, DATESIZ); |
|
|
/* |
/* |
* XXX: this should use divs, but in Firefox, divs with nested |
* XXX: this should use divs, but in Firefox, divs with nested |
* divs for some reason puke when trying to put a border line |
* divs for some reason puke when trying to put a border line |
* below. So I use tables, instead. |
* below. So I use tables, instead. |
*/ |
*/ |
|
|
(void)localtime_r(&m->date, &tm); |
|
|
|
if (0 == strftime(b, BUFSIZ - 1, "%B %e, %Y", &tm)) |
|
err(EXIT_FAILURE, "strftime"); |
|
|
|
PAIR_CLASS_INIT(&tag[0], "footer"); |
PAIR_CLASS_INIT(&tag[0], "footer"); |
bufcat_style(h, "width", "100%"); |
bufcat_style(h, "width", "100%"); |
PAIR_STYLE_INIT(&tag[1], h); |
PAIR_STYLE_INIT(&tag[1], h); |
Line 982 mdoc_it_head_pre(MDOC_ARGS, int type, struct roffsu *w |
|
Line 980 mdoc_it_head_pre(MDOC_ARGS, int type, struct roffsu *w |
|
print_otag(h, TAG_SPAN, 1, &tag); |
print_otag(h, TAG_SPAN, 1, &tag); |
break; |
break; |
case (MDOC_Enum): |
case (MDOC_Enum): |
ord = SLIST_FIRST(&h->ords); |
ord = h->ords.head; |
assert(ord); |
assert(ord); |
nbuf[BUFSIZ - 1] = 0; |
nbuf[BUFSIZ - 1] = 0; |
(void)snprintf(nbuf, BUFSIZ - 1, "%d.", ord->pos++); |
(void)snprintf(nbuf, BUFSIZ - 1, "%d.", ord->pos++); |
Line 1066 mdoc_it_pre(MDOC_ARGS) |
|
Line 1064 mdoc_it_pre(MDOC_ARGS) |
|
/* Override width in some cases. */ |
/* Override width in some cases. */ |
|
|
switch (type) { |
switch (type) { |
|
case (MDOC_Item): |
|
/* FALLTHROUGH */ |
case (MDOC_Inset): |
case (MDOC_Inset): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (MDOC_Diag): |
case (MDOC_Diag): |
Line 1115 mdoc_bl_pre(MDOC_ARGS) |
|
Line 1115 mdoc_bl_pre(MDOC_ARGS) |
|
err(EXIT_FAILURE, "malloc"); |
err(EXIT_FAILURE, "malloc"); |
ord->cookie = n; |
ord->cookie = n; |
ord->pos = 1; |
ord->pos = 1; |
SLIST_INSERT_HEAD(&h->ords, ord, entry); |
ord->next = h->ords.head; |
|
h->ords.head = ord; |
return(1); |
return(1); |
} |
} |
|
|
Line 1131 mdoc_bl_post(MDOC_ARGS) |
|
Line 1132 mdoc_bl_post(MDOC_ARGS) |
|
if (MDOC_Enum != a2list(n)) |
if (MDOC_Enum != a2list(n)) |
return; |
return; |
|
|
ord = SLIST_FIRST(&h->ords); |
ord = h->ords.head; |
assert(ord); |
assert(ord); |
SLIST_REMOVE_HEAD(&h->ords, entry); |
h->ords.head = ord->next; |
free(ord); |
free(ord); |
} |
} |
|
|
Line 1270 mdoc_d1_pre(MDOC_ARGS) |
|
Line 1271 mdoc_d1_pre(MDOC_ARGS) |
|
if (MDOC_BLOCK != n->type) |
if (MDOC_BLOCK != n->type) |
return(1); |
return(1); |
|
|
|
/* FIXME: D1 shouldn't be literal. */ |
|
|
SCALE_VS_INIT(&su, INDENT - 2); |
SCALE_VS_INIT(&su, INDENT - 2); |
bufcat_su(h, "margin-left", &su); |
bufcat_su(h, "margin-left", &su); |
PAIR_CLASS_INIT(&tag[0], "lit"); |
PAIR_CLASS_INIT(&tag[0], "lit"); |
Line 1285 mdoc_sx_pre(MDOC_ARGS) |
|
Line 1288 mdoc_sx_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]; |
|
|
/* FIXME: duplicates? */ |
/* FIXME: duplicates? */ |
|
|
(void)strlcpy(lbuf, "#", BUFSIZ); |
(void)strlcpy(buf, "#", BUFSIZ); |
for (nn = n->child; nn; nn = nn->next) { |
for (nn = n->child; nn; nn = nn->next) { |
(void)strlcat(lbuf, nn->string, BUFSIZ); |
(void)strlcat(buf, nn->string, BUFSIZ); |
if (nn->next) |
if (nn->next) |
(void)strlcat(lbuf, "_", BUFSIZ); |
(void)strlcat(buf, "_", BUFSIZ); |
} |
} |
|
|
PAIR_CLASS_INIT(&tag[0], "link-sec"); |
PAIR_CLASS_INIT(&tag[0], "link-sec"); |
tag[1].key = ATTR_HREF; |
tag[1].key = ATTR_HREF; |
tag[1].val = lbuf; |
tag[1].val = buf; |
|
|
print_otag(h, TAG_A, 2, tag); |
print_otag(h, TAG_A, 2, tag); |
return(1); |
return(1); |
Line 1357 mdoc_bd_pre(MDOC_ARGS) |
|
Line 1360 mdoc_bd_pre(MDOC_ARGS) |
|
case (MDOC_Compact): |
case (MDOC_Compact): |
comp = 1; |
comp = 1; |
break; |
break; |
|
case (MDOC_Centred): |
|
/* FALLTHROUGH */ |
case (MDOC_Ragged): |
case (MDOC_Ragged): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (MDOC_Filled): |
case (MDOC_Filled): |
Line 1366 mdoc_bd_pre(MDOC_ARGS) |
|
Line 1371 mdoc_bd_pre(MDOC_ARGS) |
|
case (MDOC_Literal): |
case (MDOC_Literal): |
type = bl->args->argv[i].arg; |
type = bl->args->argv[i].arg; |
break; |
break; |
|
default: |
|
break; |
} |
} |
|
|
|
/* FIXME: -centered, etc. formatting. */ |
|
|
if (MDOC_BLOCK == n->type) { |
if (MDOC_BLOCK == n->type) { |
bufcat_su(h, "margin-left", &su); |
bufcat_su(h, "margin-left", &su); |
for (nn = n; nn && ! comp; nn = nn->parent) { |
for (nn = n; nn && ! comp; nn = nn->parent) { |
Line 1748 mdoc_lk_pre(MDOC_ARGS) |
|
Line 1757 mdoc_lk_pre(MDOC_ARGS) |
|
tag[1].val = 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) |
|
return(1); |
|
|
for (nn = nn->next; nn; nn = nn->next) |
for (nn = nn->next; nn; nn = nn->next) |
print_text(h, nn->string); |
print_text(h, nn->string); |
|
|
Line 1832 mdoc_in_pre(MDOC_ARGS) |
|
Line 1844 mdoc_in_pre(MDOC_ARGS) |
|
print_otag(h, TAG_DIV, 0, NULL); |
print_otag(h, TAG_DIV, 0, NULL); |
} |
} |
|
|
|
/* FIXME: there's a buffer bug in here somewhere. */ |
|
|
PAIR_CLASS_INIT(&tag[0], "includes"); |
PAIR_CLASS_INIT(&tag[0], "includes"); |
print_otag(h, TAG_SPAN, 1, tag); |
print_otag(h, TAG_SPAN, 1, tag); |
|
|
Line 2136 mdoc_lb_pre(MDOC_ARGS) |
|
Line 2150 mdoc_lb_pre(MDOC_ARGS) |
|
static int |
static int |
mdoc__x_pre(MDOC_ARGS) |
mdoc__x_pre(MDOC_ARGS) |
{ |
{ |
struct htmlpair tag; |
struct htmlpair tag[2]; |
|
|
switch (n->tok) { |
switch (n->tok) { |
case(MDOC__A): |
case(MDOC__A): |
PAIR_CLASS_INIT(&tag, "ref-auth"); |
PAIR_CLASS_INIT(&tag[0], "ref-auth"); |
break; |
break; |
case(MDOC__B): |
case(MDOC__B): |
PAIR_CLASS_INIT(&tag, "ref-book"); |
PAIR_CLASS_INIT(&tag[0], "ref-book"); |
break; |
break; |
case(MDOC__C): |
case(MDOC__C): |
PAIR_CLASS_INIT(&tag, "ref-city"); |
PAIR_CLASS_INIT(&tag[0], "ref-city"); |
break; |
break; |
case(MDOC__D): |
case(MDOC__D): |
PAIR_CLASS_INIT(&tag, "ref-date"); |
PAIR_CLASS_INIT(&tag[0], "ref-date"); |
break; |
break; |
case(MDOC__I): |
case(MDOC__I): |
PAIR_CLASS_INIT(&tag, "ref-issue"); |
PAIR_CLASS_INIT(&tag[0], "ref-issue"); |
break; |
break; |
case(MDOC__J): |
case(MDOC__J): |
PAIR_CLASS_INIT(&tag, "ref-jrnl"); |
PAIR_CLASS_INIT(&tag[0], "ref-jrnl"); |
break; |
break; |
case(MDOC__N): |
case(MDOC__N): |
PAIR_CLASS_INIT(&tag, "ref-num"); |
PAIR_CLASS_INIT(&tag[0], "ref-num"); |
break; |
break; |
case(MDOC__O): |
case(MDOC__O): |
PAIR_CLASS_INIT(&tag, "ref-opt"); |
PAIR_CLASS_INIT(&tag[0], "ref-opt"); |
break; |
break; |
case(MDOC__P): |
case(MDOC__P): |
PAIR_CLASS_INIT(&tag, "ref-page"); |
PAIR_CLASS_INIT(&tag[0], "ref-page"); |
break; |
break; |
case(MDOC__Q): |
case(MDOC__Q): |
PAIR_CLASS_INIT(&tag, "ref-corp"); |
PAIR_CLASS_INIT(&tag[0], "ref-corp"); |
break; |
break; |
case(MDOC__R): |
case(MDOC__R): |
PAIR_CLASS_INIT(&tag, "ref-rep"); |
PAIR_CLASS_INIT(&tag[0], "ref-rep"); |
break; |
break; |
case(MDOC__T): |
case(MDOC__T): |
PAIR_CLASS_INIT(&tag, "ref-title"); |
PAIR_CLASS_INIT(&tag[0], "ref-title"); |
print_text(h, "\\(lq"); |
print_text(h, "\\(lq"); |
h->flags |= HTML_NOSPACE; |
h->flags |= HTML_NOSPACE; |
break; |
break; |
|
case(MDOC__U): |
|
PAIR_CLASS_INIT(&tag[0], "link-ref"); |
|
break; |
case(MDOC__V): |
case(MDOC__V): |
PAIR_CLASS_INIT(&tag, "ref-vol"); |
PAIR_CLASS_INIT(&tag[0], "ref-vol"); |
break; |
break; |
default: |
default: |
abort(); |
abort(); |
/* NOTREACHED */ |
/* NOTREACHED */ |
} |
} |
|
|
print_otag(h, TAG_SPAN, 1, &tag); |
if (MDOC__U != n->tok) { |
|
print_otag(h, TAG_SPAN, 1, tag); |
|
return(1); |
|
} |
|
|
|
PAIR_HREF_INIT(&tag[1], n->child->string); |
|
print_otag(h, TAG_A, 2, tag); |
return(1); |
return(1); |
} |
} |
|
|