version 1.140, 2011/05/17 10:48:06 |
version 1.150, 2011/10/05 21:35:17 |
Line 107 static const char *const roffscales[SCALE_MAX] = { |
|
Line 107 static const char *const roffscales[SCALE_MAX] = { |
|
"ex", /* SCALE_FS */ |
"ex", /* SCALE_FS */ |
}; |
}; |
|
|
static void print_num(struct html *, const char *, size_t); |
static void bufncat(struct html *, const char *, size_t); |
static void print_spec(struct html *, const char *, size_t); |
static void print_ctag(struct html *, enum htmltag); |
static void print_res(struct html *, const char *, size_t); |
static int print_encode(struct html *, const char *, int); |
static void print_ctag(struct html *, enum htmltag); |
static void print_metaf(struct html *, enum mandoc_esc); |
static void print_doctype(struct html *); |
static void print_attr(struct html *, const char *, const char *); |
static void print_xmltype(struct html *); |
static void *ml_alloc(char *, enum htmltype); |
static int print_encode(struct html *, const char *, int); |
|
static void print_metaf(struct html *, enum mandoc_esc); |
|
static void print_attr(struct html *, |
|
const char *, const char *); |
|
static void *ml_alloc(char *, enum htmltype); |
|
|
|
|
|
static void * |
static void * |
ml_alloc(char *outopts, enum htmltype type) |
ml_alloc(char *outopts, enum htmltype type) |
{ |
{ |
struct html *h; |
struct html *h; |
const char *toks[4]; |
const char *toks[5]; |
char *v; |
char *v; |
|
|
toks[0] = "style"; |
toks[0] = "style"; |
toks[1] = "man"; |
toks[1] = "man"; |
toks[2] = "includes"; |
toks[2] = "includes"; |
toks[3] = NULL; |
toks[3] = "fragment"; |
|
toks[4] = NULL; |
|
|
h = mandoc_calloc(1, sizeof(struct html)); |
h = mandoc_calloc(1, sizeof(struct html)); |
|
|
Line 149 ml_alloc(char *outopts, enum htmltype type) |
|
Line 144 ml_alloc(char *outopts, enum htmltype type) |
|
case (2): |
case (2): |
h->base_includes = v; |
h->base_includes = v; |
break; |
break; |
|
case (3): |
|
h->oflags |= HTML_FRAGMENT; |
|
break; |
default: |
default: |
break; |
break; |
} |
} |
Line 222 print_gen_head(struct html *h) |
|
Line 220 print_gen_head(struct html *h) |
|
} |
} |
} |
} |
|
|
/* ARGSUSED */ |
|
static void |
static void |
print_num(struct html *h, const char *p, size_t len) |
|
{ |
|
char c; |
|
|
|
if ('\0' != (c = mchars_num2char(p, len))) |
|
putchar((int)c); |
|
} |
|
|
|
static void |
|
print_spec(struct html *h, const char *p, size_t len) |
|
{ |
|
int cp; |
|
const char *rhs; |
|
size_t sz; |
|
|
|
if ((cp = mchars_spec2cp(h->symtab, p, len)) > 0) { |
|
printf("&#%d;", cp); |
|
return; |
|
} else if (-1 == cp && 1 == len) { |
|
fwrite(p, 1, len, stdout); |
|
return; |
|
} else if (-1 == cp) |
|
return; |
|
|
|
if (NULL != (rhs = mchars_spec2str(h->symtab, p, len, &sz))) |
|
fwrite(rhs, 1, sz, stdout); |
|
} |
|
|
|
|
|
static void |
|
print_res(struct html *h, const char *p, size_t len) |
|
{ |
|
int cp; |
|
const char *rhs; |
|
size_t sz; |
|
|
|
if ((cp = mchars_res2cp(h->symtab, p, len)) > 0) { |
|
printf("&#%d;", cp); |
|
return; |
|
} else if (-1 == cp) |
|
return; |
|
|
|
if (NULL != (rhs = mchars_res2str(h->symtab, p, len, &sz))) |
|
fwrite(rhs, 1, sz, stdout); |
|
} |
|
|
|
|
|
static void |
|
print_metaf(struct html *h, enum mandoc_esc deco) |
print_metaf(struct html *h, enum mandoc_esc deco) |
{ |
{ |
enum htmlfont font; |
enum htmlfont font; |
Line 286 print_metaf(struct html *h, enum mandoc_esc deco) |
|
Line 235 print_metaf(struct html *h, enum mandoc_esc deco) |
|
case (ESCAPE_FONTBOLD): |
case (ESCAPE_FONTBOLD): |
font = HTMLFONT_BOLD; |
font = HTMLFONT_BOLD; |
break; |
break; |
|
case (ESCAPE_FONT): |
|
/* FALLTHROUGH */ |
case (ESCAPE_FONTROMAN): |
case (ESCAPE_FONTROMAN): |
font = HTMLFONT_NONE; |
font = HTMLFONT_NONE; |
break; |
break; |
Line 329 html_strlen(const char *cp) |
|
Line 280 html_strlen(const char *cp) |
|
switch (mandoc_escape(&cp, &seq, &ssz)) { |
switch (mandoc_escape(&cp, &seq, &ssz)) { |
case (ESCAPE_ERROR): |
case (ESCAPE_ERROR): |
return(sz); |
return(sz); |
|
case (ESCAPE_UNICODE): |
|
/* FALLTHROUGH */ |
case (ESCAPE_NUMBERED): |
case (ESCAPE_NUMBERED): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ESCAPE_PREDEF): |
|
/* FALLTHROUGH */ |
|
case (ESCAPE_SPECIAL): |
case (ESCAPE_SPECIAL): |
sz++; |
sz++; |
break; |
break; |
|
|
print_encode(struct html *h, const char *p, int norecurse) |
print_encode(struct html *h, const char *p, int norecurse) |
{ |
{ |
size_t sz; |
size_t sz; |
int len, nospace; |
int c, len, nospace; |
const char *seq; |
const char *seq; |
enum mandoc_esc esc; |
enum mandoc_esc esc; |
static const char rejs[6] = { '\\', '<', '>', '&', ASCII_HYPH, '\0' }; |
static const char rejs[6] = { '\\', '<', '>', '&', ASCII_HYPH, '\0' }; |
Line 387 print_encode(struct html *h, const char *p, int norecu |
|
Line 338 print_encode(struct html *h, const char *p, int norecu |
|
break; |
break; |
|
|
switch (esc) { |
switch (esc) { |
|
case (ESCAPE_UNICODE): |
|
/* Skip passed "u" header. */ |
|
c = mchars_num2uc(seq + 1, len - 1); |
|
if ('\0' != c) |
|
printf("&#x%x;", c); |
|
break; |
case (ESCAPE_NUMBERED): |
case (ESCAPE_NUMBERED): |
print_num(h, seq, len); |
c = mchars_num2char(seq, len); |
|
if ('\0' != c) |
|
putchar(c); |
break; |
break; |
case (ESCAPE_PREDEF): |
|
print_res(h, seq, len); |
|
break; |
|
case (ESCAPE_SPECIAL): |
case (ESCAPE_SPECIAL): |
print_spec(h, seq, len); |
c = mchars_spec2cp(h->symtab, seq, len); |
|
if (c > 0) |
|
printf("&#%d;", c); |
|
else if (-1 == c && 1 == len) |
|
putchar((int)*seq); |
break; |
break; |
|
case (ESCAPE_FONT): |
|
/* FALLTHROUGH */ |
case (ESCAPE_FONTPREV): |
case (ESCAPE_FONTPREV): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ESCAPE_FONTBOLD): |
case (ESCAPE_FONTBOLD): |
Line 509 print_ctag(struct html *h, enum htmltag tag) |
|
Line 471 print_ctag(struct html *h, enum htmltag tag) |
|
} |
} |
} |
} |
|
|
|
|
void |
void |
print_gen_decls(struct html *h) |
print_gen_decls(struct html *h) |
{ |
{ |
|
|
print_xmltype(h); |
|
print_doctype(h); |
|
} |
|
|
|
|
|
static void |
|
print_xmltype(struct html *h) |
|
{ |
|
|
|
if (HTML_XHTML_1_0_STRICT == h->type) |
|
puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
|
} |
|
|
|
|
|
static void |
|
print_doctype(struct html *h) |
|
{ |
|
const char *doctype; |
const char *doctype; |
const char *dtd; |
const char *dtd; |
const char *name; |
const char *name; |
Line 542 print_doctype(struct html *h) |
|
Line 485 print_doctype(struct html *h) |
|
dtd = "http://www.w3.org/TR/html4/strict.dtd"; |
dtd = "http://www.w3.org/TR/html4/strict.dtd"; |
break; |
break; |
default: |
default: |
|
puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
name = "html"; |
name = "html"; |
doctype = "-//W3C//DTD XHTML 1.0 Strict//EN"; |
doctype = "-//W3C//DTD XHTML 1.0 Strict//EN"; |
dtd = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; |
dtd = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; |
Line 573 print_text(struct html *h, const char *word) |
|
Line 517 print_text(struct html *h, const char *word) |
|
print_otag(h, TAG_I, 0, NULL); |
print_otag(h, TAG_I, 0, NULL); |
|
|
assert(word); |
assert(word); |
if ( ! print_encode(h, word, 0)) |
if ( ! print_encode(h, word, 0)) { |
if ( ! (h->flags & HTML_NONOSPACE)) |
if ( ! (h->flags & HTML_NONOSPACE)) |
h->flags &= ~HTML_NOSPACE; |
h->flags &= ~HTML_NOSPACE; |
|
} else |
|
h->flags |= HTML_NOSPACE; |
|
|
if (h->metaf) { |
if (h->metaf) { |
print_tagq(h, h->metaf); |
print_tagq(h, h->metaf); |
Line 631 print_stagq(struct html *h, const struct tag *suntil) |
|
Line 577 print_stagq(struct html *h, const struct tag *suntil) |
|
} |
} |
} |
} |
|
|
|
|
void |
void |
bufinit(struct html *h) |
bufinit(struct html *h) |
{ |
{ |
Line 640 bufinit(struct html *h) |
|
Line 585 bufinit(struct html *h) |
|
h->buflen = 0; |
h->buflen = 0; |
} |
} |
|
|
|
|
void |
void |
bufcat_style(struct html *h, const char *key, const char *val) |
bufcat_style(struct html *h, const char *key, const char *val) |
{ |
{ |
|
|
bufcat(h, key); |
bufcat(h, key); |
bufncat(h, ":", 1); |
bufcat(h, ":"); |
bufcat(h, val); |
bufcat(h, val); |
bufncat(h, ";", 1); |
bufcat(h, ";"); |
} |
} |
|
|
|
|
void |
void |
bufcat(struct html *h, const char *p) |
bufcat(struct html *h, const char *p) |
{ |
{ |
|
|
bufncat(h, p, strlen(p)); |
h->buflen = strlcat(h->buf, p, BUFSIZ); |
|
assert(h->buflen < BUFSIZ); |
} |
} |
|
|
|
|
void |
void |
buffmt(struct html *h, const char *fmt, ...) |
bufcat_fmt(struct html *h, const char *fmt, ...) |
{ |
{ |
va_list ap; |
va_list ap; |
|
|
Line 672 buffmt(struct html *h, const char *fmt, ...) |
|
Line 615 buffmt(struct html *h, const char *fmt, ...) |
|
h->buflen = strlen(h->buf); |
h->buflen = strlen(h->buf); |
} |
} |
|
|
|
static void |
void |
|
bufncat(struct html *h, const char *p, size_t sz) |
bufncat(struct html *h, const char *p, size_t sz) |
{ |
{ |
|
|
if (h->buflen + sz > BUFSIZ - 1) |
assert(h->buflen + sz + 1 < BUFSIZ); |
sz = BUFSIZ - 1 - h->buflen; |
strncat(h->buf, p, sz); |
|
|
(void)strncat(h->buf, p, sz); |
|
h->buflen += sz; |
h->buflen += sz; |
} |
} |
|
|
|
|
void |
void |
buffmt_includes(struct html *h, const char *name) |
buffmt_includes(struct html *h, const char *name) |
{ |
{ |
Line 692 buffmt_includes(struct html *h, const char *name) |
|
Line 631 buffmt_includes(struct html *h, const char *name) |
|
|
|
pp = h->base_includes; |
pp = h->base_includes; |
|
|
|
bufinit(h); |
while (NULL != (p = strchr(pp, '%'))) { |
while (NULL != (p = strchr(pp, '%'))) { |
bufncat(h, pp, (size_t)(p - pp)); |
bufncat(h, pp, (size_t)(p - pp)); |
switch (*(p + 1)) { |
switch (*(p + 1)) { |
Line 708 buffmt_includes(struct html *h, const char *name) |
|
Line 648 buffmt_includes(struct html *h, const char *name) |
|
bufcat(h, pp); |
bufcat(h, pp); |
} |
} |
|
|
|
|
void |
void |
buffmt_man(struct html *h, |
buffmt_man(struct html *h, |
const char *name, const char *sec) |
const char *name, const char *sec) |
Line 717 buffmt_man(struct html *h, |
|
Line 656 buffmt_man(struct html *h, |
|
|
|
pp = h->base_man; |
pp = h->base_man; |
|
|
/* LINTED */ |
bufinit(h); |
while (NULL != (p = strchr(pp, '%'))) { |
while (NULL != (p = strchr(pp, '%'))) { |
bufncat(h, pp, (size_t)(p - pp)); |
bufncat(h, pp, (size_t)(p - pp)); |
switch (*(p + 1)) { |
switch (*(p + 1)) { |
Line 725 buffmt_man(struct html *h, |
|
Line 664 buffmt_man(struct html *h, |
|
bufcat(h, sec ? sec : "1"); |
bufcat(h, sec ? sec : "1"); |
break; |
break; |
case('N'): |
case('N'): |
buffmt(h, name); |
bufcat_fmt(h, name); |
break; |
break; |
default: |
default: |
bufncat(h, p, 2); |
bufncat(h, p, 2); |
Line 737 buffmt_man(struct html *h, |
|
Line 676 buffmt_man(struct html *h, |
|
bufcat(h, pp); |
bufcat(h, pp); |
} |
} |
|
|
|
|
void |
void |
bufcat_su(struct html *h, const char *p, const struct roffsu *su) |
bufcat_su(struct html *h, const char *p, const struct roffsu *su) |
{ |
{ |
Line 747 bufcat_su(struct html *h, const char *p, const struct |
|
Line 685 bufcat_su(struct html *h, const char *p, const struct |
|
if (SCALE_MM == su->unit && 0.0 == (v /= 100.0)) |
if (SCALE_MM == su->unit && 0.0 == (v /= 100.0)) |
v = 1.0; |
v = 1.0; |
|
|
buffmt(h, "%s: %.2f%s;", p, v, roffscales[su->unit]); |
bufcat_fmt(h, "%s: %.2f%s;", p, v, roffscales[su->unit]); |
} |
} |
|
|
|
|
void |
void |
html_idcat(char *dst, const char *src, int sz) |
bufcat_id(struct html *h, const char *src) |
{ |
{ |
int ssz; |
|
|
|
assert(sz > 2); |
|
|
|
/* Cf. <http://www.w3.org/TR/html4/types.html#h-6.2>. */ |
/* Cf. <http://www.w3.org/TR/html4/types.html#h-6.2>. */ |
|
|
/* We can't start with a number (bah). */ |
while ('\0' != *src) |
|
bufcat_fmt(h, "%.2x", *src++); |
if ('#' == *dst) { |
|
dst++; |
|
sz--; |
|
} |
|
if ('\0' == *dst) { |
|
*dst++ = 'x'; |
|
*dst = '\0'; |
|
sz--; |
|
} |
|
|
|
for ( ; *dst != '\0' && sz; dst++, sz--) |
|
/* Jump to end. */ ; |
|
|
|
for ( ; *src != '\0' && sz > 1; src++) { |
|
ssz = snprintf(dst, (size_t)sz, "%.2x", *src); |
|
sz -= ssz; |
|
dst += ssz; |
|
} |
|
} |
} |