version 1.134, 2011/04/30 10:18:24 |
version 1.140, 2011/05/17 10:48:06 |
|
|
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "mandoc.h" |
#include "mandoc.h" |
|
#include "libmandoc.h" |
#include "out.h" |
#include "out.h" |
#include "html.h" |
#include "html.h" |
#include "main.h" |
#include "main.h" |
Line 93 static const char *const htmlattrs[ATTR_MAX] = { |
|
Line 94 static const char *const htmlattrs[ATTR_MAX] = { |
|
"colspan", /* ATTR_COLSPAN */ |
"colspan", /* ATTR_COLSPAN */ |
}; |
}; |
|
|
|
static const char *const roffscales[SCALE_MAX] = { |
|
"cm", /* SCALE_CM */ |
|
"in", /* SCALE_IN */ |
|
"pc", /* SCALE_PC */ |
|
"pt", /* SCALE_PT */ |
|
"em", /* SCALE_EM */ |
|
"em", /* SCALE_MM */ |
|
"ex", /* SCALE_EN */ |
|
"ex", /* SCALE_BU */ |
|
"em", /* SCALE_VS */ |
|
"ex", /* SCALE_FS */ |
|
}; |
|
|
static void print_num(struct html *, const char *, size_t); |
static void print_num(struct html *, const char *, size_t); |
static void print_spec(struct html *, const char *, size_t); |
static void print_spec(struct html *, const char *, size_t); |
static void print_res(struct html *, const char *, size_t); |
static void print_res(struct html *, const char *, size_t); |
Line 122 ml_alloc(char *outopts, enum htmltype type) |
|
Line 136 ml_alloc(char *outopts, enum htmltype type) |
|
|
|
h->type = type; |
h->type = type; |
h->tags.head = NULL; |
h->tags.head = NULL; |
h->symtab = mchars_init(MCHARS_HTML); |
h->symtab = mchars_alloc(); |
|
|
while (outopts && *outopts) |
while (outopts && *outopts) |
switch (getsubopt(&outopts, UNCONST(toks), &v)) { |
switch (getsubopt(&outopts, UNCONST(toks), &v)) { |
Line 212 print_gen_head(struct html *h) |
|
Line 226 print_gen_head(struct html *h) |
|
static void |
static void |
print_num(struct html *h, const char *p, size_t len) |
print_num(struct html *h, const char *p, size_t len) |
{ |
{ |
const char *rhs; |
char c; |
|
|
rhs = mchars_num2char(p, len); |
if ('\0' != (c = mchars_num2char(p, len))) |
if (rhs) |
putchar((int)c); |
putchar((int)*rhs); |
|
} |
} |
|
|
static void |
static void |
Line 295 print_metaf(struct html *h, enum mandoc_esc deco) |
|
Line 308 print_metaf(struct html *h, enum mandoc_esc deco) |
|
print_otag(h, TAG_I, 0, NULL); |
print_otag(h, TAG_I, 0, NULL); |
} |
} |
|
|
|
int |
|
html_strlen(const char *cp) |
|
{ |
|
int ssz, sz; |
|
const char *seq, *p; |
|
|
|
/* |
|
* Account for escaped sequences within string length |
|
* calculations. This follows the logic in term_strlen() as we |
|
* must calculate the width of produced strings. |
|
* Assume that characters are always width of "1". This is |
|
* hacky, but it gets the job done for approximation of widths. |
|
*/ |
|
|
|
sz = 0; |
|
while (NULL != (p = strchr(cp, '\\'))) { |
|
sz += (int)(p - cp); |
|
++cp; |
|
switch (mandoc_escape(&cp, &seq, &ssz)) { |
|
case (ESCAPE_ERROR): |
|
return(sz); |
|
case (ESCAPE_NUMBERED): |
|
/* FALLTHROUGH */ |
|
case (ESCAPE_PREDEF): |
|
/* FALLTHROUGH */ |
|
case (ESCAPE_SPECIAL): |
|
sz++; |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
|
|
|
assert(sz >= 0); |
|
return(sz + strlen(cp)); |
|
} |
|
|
static int |
static int |
print_encode(struct html *h, const char *p, int norecurse) |
print_encode(struct html *h, const char *p, int norecurse) |
{ |
{ |
|
|
bufcat_su(struct html *h, const char *p, const struct roffsu *su) |
bufcat_su(struct html *h, const char *p, const struct roffsu *su) |
{ |
{ |
double v; |
double v; |
const char *u; |
|
|
|
v = su->scale; |
v = su->scale; |
|
if (SCALE_MM == su->unit && 0.0 == (v /= 100.0)) |
|
v = 1.0; |
|
|
switch (su->unit) { |
buffmt(h, "%s: %.2f%s;", p, v, roffscales[su->unit]); |
case (SCALE_CM): |
|
u = "cm"; |
|
break; |
|
case (SCALE_IN): |
|
u = "in"; |
|
break; |
|
case (SCALE_PC): |
|
u = "pc"; |
|
break; |
|
case (SCALE_PT): |
|
u = "pt"; |
|
break; |
|
case (SCALE_EM): |
|
u = "em"; |
|
break; |
|
case (SCALE_MM): |
|
if (0 == (v /= 100)) |
|
v = 1; |
|
u = "em"; |
|
break; |
|
case (SCALE_EN): |
|
u = "ex"; |
|
break; |
|
case (SCALE_BU): |
|
u = "ex"; |
|
break; |
|
case (SCALE_VS): |
|
u = "em"; |
|
break; |
|
default: |
|
u = "ex"; |
|
break; |
|
} |
|
|
|
/* |
|
* XXX: the CSS spec isn't clear as to which types accept |
|
* integer or real numbers, so we just make them all decimals. |
|
*/ |
|
buffmt(h, "%s: %.2f%s;", p, v, u); |
|
} |
} |
|
|
|
|