version 1.7, 2009/10/07 12:35:23 |
version 1.15, 2009/10/27 04:50:15 |
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/queue.h> |
|
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
|
|
#include "out.h" |
#include "out.h" |
#include "html.h" |
#include "html.h" |
#include "man.h" |
#include "man.h" |
|
#include "main.h" |
|
|
/* TODO: preserve ident widths. */ |
/* TODO: preserve ident widths. */ |
|
/* FIXME: have PD set the default vspace width. */ |
|
|
#define INDENT 5 |
#define INDENT 5 |
#define HALFINDENT 3 |
#define HALFINDENT 3 |
Line 50 static void print_man_node(MAN_ARGS); |
|
Line 51 static void print_man_node(MAN_ARGS); |
|
static int a2width(const struct man_node *, |
static int a2width(const struct man_node *, |
struct roffsu *); |
struct roffsu *); |
|
|
|
static int man_alt_pre(MAN_ARGS); |
static int man_br_pre(MAN_ARGS); |
static int man_br_pre(MAN_ARGS); |
|
static int man_ign_pre(MAN_ARGS); |
|
static void man_root_post(MAN_ARGS); |
|
static int man_root_pre(MAN_ARGS); |
|
static int man_B_pre(MAN_ARGS); |
static int man_HP_pre(MAN_ARGS); |
static int man_HP_pre(MAN_ARGS); |
|
static int man_I_pre(MAN_ARGS); |
static int man_IP_pre(MAN_ARGS); |
static int man_IP_pre(MAN_ARGS); |
static int man_PP_pre(MAN_ARGS); |
static int man_PP_pre(MAN_ARGS); |
static void man_root_post(MAN_ARGS); |
static int man_RS_pre(MAN_ARGS); |
static int man_root_pre(MAN_ARGS); |
static int man_SB_pre(MAN_ARGS); |
static int man_SH_pre(MAN_ARGS); |
static int man_SH_pre(MAN_ARGS); |
|
static int man_SM_pre(MAN_ARGS); |
static int man_SS_pre(MAN_ARGS); |
static int man_SS_pre(MAN_ARGS); |
|
|
#ifdef __linux__ |
#ifdef __linux__ |
Line 75 static const struct htmlman mans[MAN_MAX] = { |
|
Line 83 static const struct htmlman mans[MAN_MAX] = { |
|
{ man_PP_pre, NULL }, /* P */ |
{ man_PP_pre, NULL }, /* P */ |
{ man_IP_pre, NULL }, /* IP */ |
{ man_IP_pre, NULL }, /* IP */ |
{ man_HP_pre, NULL }, /* HP */ |
{ man_HP_pre, NULL }, /* HP */ |
{ NULL, NULL }, /* SM */ |
{ man_SM_pre, NULL }, /* SM */ |
{ NULL, NULL }, /* SB */ |
{ man_SB_pre, NULL }, /* SB */ |
{ NULL, NULL }, /* BI */ |
{ man_alt_pre, NULL }, /* BI */ |
{ NULL, NULL }, /* IB */ |
{ man_alt_pre, NULL }, /* IB */ |
{ NULL, NULL }, /* BR */ |
{ man_alt_pre, NULL }, /* BR */ |
{ NULL, NULL }, /* RB */ |
{ man_alt_pre, NULL }, /* RB */ |
{ NULL, NULL }, /* R */ |
{ NULL, NULL }, /* R */ |
{ NULL, NULL }, /* B */ |
{ man_B_pre, NULL }, /* B */ |
{ NULL, NULL }, /* I */ |
{ man_I_pre, NULL }, /* I */ |
{ NULL, NULL }, /* IR */ |
{ man_alt_pre, NULL }, /* IR */ |
{ NULL, NULL }, /* RI */ |
{ man_alt_pre, NULL }, /* RI */ |
{ NULL, NULL }, /* na */ |
{ NULL, NULL }, /* na */ |
{ NULL, NULL }, /* i */ |
{ NULL, NULL }, /* i */ |
{ man_br_pre, NULL }, /* sp */ |
{ man_br_pre, NULL }, /* sp */ |
Line 93 static const struct htmlman mans[MAN_MAX] = { |
|
Line 101 static const struct htmlman mans[MAN_MAX] = { |
|
{ NULL, NULL }, /* fi */ |
{ NULL, NULL }, /* fi */ |
{ NULL, NULL }, /* r */ |
{ NULL, NULL }, /* r */ |
{ NULL, NULL }, /* RE */ |
{ NULL, NULL }, /* RE */ |
{ NULL, NULL }, /* RS */ |
{ man_RS_pre, NULL }, /* RS */ |
{ NULL, NULL }, /* DT */ |
{ man_ign_pre, NULL }, /* DT */ |
{ NULL, NULL }, /* UC */ |
{ man_ign_pre, NULL }, /* UC */ |
|
{ man_ign_pre, NULL }, /* PD */ |
}; |
}; |
|
|
|
|
Line 170 print_man_node(MAN_ARGS) |
|
Line 179 print_man_node(MAN_ARGS) |
|
struct tag *t; |
struct tag *t; |
|
|
child = 1; |
child = 1; |
t = SLIST_FIRST(&h->tags); |
t = h->tags.head; |
|
|
bufinit(h); |
bufinit(h); |
|
|
Line 214 a2width(const struct man_node *n, struct roffsu *su) |
|
Line 223 a2width(const struct man_node *n, struct roffsu *su) |
|
|
|
if (MAN_TEXT != n->type) |
if (MAN_TEXT != n->type) |
return(0); |
return(0); |
if (a2roffsu(n->string, su)) |
if (a2roffsu(n->string, su, SCALE_BU)) |
return(1); |
return(1); |
|
|
return(0); |
return(0); |
Line 225 a2width(const struct man_node *n, struct roffsu *su) |
|
Line 234 a2width(const struct man_node *n, struct roffsu *su) |
|
static int |
static int |
man_root_pre(MAN_ARGS) |
man_root_pre(MAN_ARGS) |
{ |
{ |
struct htmlpair tag[2]; |
struct htmlpair tag[3]; |
struct tag *t, *tt; |
struct tag *t, *tt; |
char b[BUFSIZ], title[BUFSIZ]; |
char b[BUFSIZ], title[BUFSIZ]; |
|
|
Line 239 man_root_pre(MAN_ARGS) |
|
Line 248 man_root_pre(MAN_ARGS) |
|
PAIR_CLASS_INIT(&tag[0], "header"); |
PAIR_CLASS_INIT(&tag[0], "header"); |
bufcat_style(h, "width", "100%"); |
bufcat_style(h, "width", "100%"); |
PAIR_STYLE_INIT(&tag[1], h); |
PAIR_STYLE_INIT(&tag[1], h); |
t = print_otag(h, TAG_TABLE, 2, tag); |
PAIR_SUMMARY_INIT(&tag[2], "header"); |
|
|
|
t = print_otag(h, TAG_TABLE, 3, tag); |
tt = print_otag(h, TAG_TR, 0, NULL); |
tt = print_otag(h, TAG_TR, 0, NULL); |
|
|
bufinit(h); |
bufinit(h); |
Line 273 man_root_pre(MAN_ARGS) |
|
Line 284 man_root_pre(MAN_ARGS) |
|
static void |
static void |
man_root_post(MAN_ARGS) |
man_root_post(MAN_ARGS) |
{ |
{ |
struct tm tm; |
struct htmlpair tag[3]; |
struct htmlpair tag[2]; |
|
struct tag *t, *tt; |
struct tag *t, *tt; |
char b[BUFSIZ]; |
char b[DATESIZ]; |
|
|
(void)localtime_r(&m->date, &tm); |
time2a(m->date, b, DATESIZ); |
|
|
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); |
t = print_otag(h, TAG_TABLE, 2, tag); |
PAIR_SUMMARY_INIT(&tag[2], "footer"); |
|
|
|
t = print_otag(h, TAG_TABLE, 3, tag); |
tt = print_otag(h, TAG_TR, 0, NULL); |
tt = print_otag(h, TAG_TR, 0, NULL); |
|
|
bufinit(h); |
bufinit(h); |
Line 317 man_br_pre(MAN_ARGS) |
|
Line 326 man_br_pre(MAN_ARGS) |
|
|
|
SCALE_VS_INIT(&su, 1); |
SCALE_VS_INIT(&su, 1); |
|
|
if (MAN_sp == n->tok) { |
if (MAN_sp == n->tok && n->child) |
su.scale = 1; |
a2roffsu(n->child->string, &su, SCALE_VS); |
if (n->child) |
else if (MAN_br == n->tok) |
a2roffsu(n->child->string, &su); |
|
} else if (MAN_br == n->tok) |
|
su.scale = 0; |
su.scale = 0; |
|
|
bufcat_su(h, "height", &su); |
bufcat_su(h, "height", &su); |
Line 370 man_SH_pre(MAN_ARGS) |
|
Line 377 man_SH_pre(MAN_ARGS) |
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static int |
static int |
|
man_alt_pre(MAN_ARGS) |
|
{ |
|
const struct man_node *nn; |
|
struct tag *t; |
|
int i; |
|
struct htmlpair tagi, tagb, *tagp; |
|
|
|
PAIR_CLASS_INIT(&tagi, "italic"); |
|
PAIR_CLASS_INIT(&tagb, "bold"); |
|
|
|
for (i = 0, nn = n->child; nn; nn = nn->next, i++) { |
|
switch (n->tok) { |
|
case (MAN_BI): |
|
tagp = i % 2 ? &tagi : &tagb; |
|
break; |
|
case (MAN_IB): |
|
tagp = i % 2 ? &tagb : &tagi; |
|
break; |
|
case (MAN_RI): |
|
tagp = i % 2 ? &tagi : NULL; |
|
break; |
|
case (MAN_IR): |
|
tagp = i % 2 ? NULL : &tagi; |
|
break; |
|
case (MAN_BR): |
|
tagp = i % 2 ? NULL : &tagb; |
|
break; |
|
case (MAN_RB): |
|
tagp = i % 2 ? &tagb : NULL; |
|
break; |
|
default: |
|
abort(); |
|
/* NOTREACHED */ |
|
} |
|
|
|
if (i) |
|
h->flags |= HTML_NOSPACE; |
|
|
|
if (tagp) { |
|
t = print_otag(h, TAG_SPAN, 1, tagp); |
|
print_man_node(m, nn, h); |
|
print_tagq(h, t); |
|
} else |
|
print_man_node(m, nn, h); |
|
} |
|
|
|
return(0); |
|
} |
|
|
|
|
|
/* ARGSUSED */ |
|
static int |
|
man_SB_pre(MAN_ARGS) |
|
{ |
|
struct htmlpair tag; |
|
|
|
PAIR_CLASS_INIT(&tag, "small bold"); |
|
print_otag(h, TAG_SPAN, 1, &tag); |
|
return(1); |
|
} |
|
|
|
|
|
/* ARGSUSED */ |
|
static int |
|
man_SM_pre(MAN_ARGS) |
|
{ |
|
struct htmlpair tag; |
|
|
|
PAIR_CLASS_INIT(&tag, "small"); |
|
print_otag(h, TAG_SPAN, 1, &tag); |
|
return(1); |
|
} |
|
|
|
|
|
/* ARGSUSED */ |
|
static int |
man_SS_pre(MAN_ARGS) |
man_SS_pre(MAN_ARGS) |
{ |
{ |
struct htmlpair tag[3]; |
struct htmlpair tag[3]; |
Line 483 man_IP_pre(MAN_ARGS) |
|
Line 566 man_IP_pre(MAN_ARGS) |
|
|
|
if (MAN_BLOCK == n->type) { |
if (MAN_BLOCK == n->type) { |
bufcat_su(h, "margin-left", &su); |
bufcat_su(h, "margin-left", &su); |
|
SCALE_VS_INIT(&su, 1); |
|
bufcat_su(h, "margin-top", &su); |
bufcat_style(h, "clear", "both"); |
bufcat_style(h, "clear", "both"); |
PAIR_STYLE_INIT(&tag, h); |
PAIR_STYLE_INIT(&tag, h); |
print_otag(h, TAG_DIV, 1, &tag); |
print_otag(h, TAG_DIV, 1, &tag); |
Line 539 man_HP_pre(MAN_ARGS) |
|
Line 624 man_HP_pre(MAN_ARGS) |
|
|
|
if (MAN_BLOCK == n->type) { |
if (MAN_BLOCK == n->type) { |
bufcat_su(h, "margin-left", &su); |
bufcat_su(h, "margin-left", &su); |
|
SCALE_VS_INIT(&su, 1); |
|
bufcat_su(h, "margin-top", &su); |
bufcat_style(h, "clear", "both"); |
bufcat_style(h, "clear", "both"); |
PAIR_STYLE_INIT(&tag, h); |
PAIR_STYLE_INIT(&tag, h); |
print_otag(h, TAG_DIV, 1, &tag); |
print_otag(h, TAG_DIV, 1, &tag); |
Line 554 man_HP_pre(MAN_ARGS) |
|
Line 641 man_HP_pre(MAN_ARGS) |
|
return(1); |
return(1); |
} |
} |
|
|
|
|
|
/* ARGSUSED */ |
|
static int |
|
man_B_pre(MAN_ARGS) |
|
{ |
|
struct htmlpair tag; |
|
|
|
PAIR_CLASS_INIT(&tag, "bold"); |
|
print_otag(h, TAG_SPAN, 1, &tag); |
|
return(1); |
|
} |
|
|
|
|
|
/* ARGSUSED */ |
|
static int |
|
man_I_pre(MAN_ARGS) |
|
{ |
|
struct htmlpair tag; |
|
|
|
PAIR_CLASS_INIT(&tag, "italic"); |
|
print_otag(h, TAG_SPAN, 1, &tag); |
|
return(1); |
|
} |
|
|
|
|
|
/* ARGSUSED */ |
|
static int |
|
man_ign_pre(MAN_ARGS) |
|
{ |
|
|
|
return(0); |
|
} |
|
|
|
|
|
/* ARGSUSED */ |
|
static int |
|
man_RS_pre(MAN_ARGS) |
|
{ |
|
struct htmlpair tag; |
|
struct roffsu su; |
|
|
|
if (MAN_HEAD == n->type) |
|
return(0); |
|
else if (MAN_BODY == n->type) |
|
return(1); |
|
|
|
SCALE_HS_INIT(&su, INDENT); |
|
bufcat_su(h, "margin-left", &su); |
|
|
|
if (n->head->child) { |
|
SCALE_VS_INIT(&su, 1); |
|
a2width(n->head->child, &su); |
|
bufcat_su(h, "margin-top", &su); |
|
} |
|
|
|
PAIR_STYLE_INIT(&tag, h); |
|
print_otag(h, TAG_DIV, 1, &tag); |
|
return(1); |
|
} |