=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.57 retrieving revision 1.64 diff -u -p -r1.57 -r1.64 --- mandoc/html.c 2009/10/04 09:02:40 1.57 +++ mandoc/html.c 2009/10/13 10:57:25 1.64 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.57 2009/10/04 09:02:40 kristaps Exp $ */ +/* $Id: html.c,v 1.64 2009/10/13 10:57:25 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -21,18 +21,23 @@ #include #include #include +#include #include #include #include +#include "out.h" #include "chars.h" #include "html.h" +#include "main.h" +#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a)) + #define DOCTYPE "-//W3C//DTD HTML 4.01//EN" #define DTD "http://www.w3.org/TR/html4/strict.dtd" struct htmldata { - char *name; + const char *name; int flags; #define HTML_CLRLINE (1 << 0) #define HTML_NOSTACK (1 << 1) @@ -86,7 +91,8 @@ void * html_alloc(char *outopts) { struct html *h; - char *toks[4], *v; + const char *toks[4]; + char *v; toks[0] = "style"; toks[1] = "man"; @@ -105,7 +111,7 @@ html_alloc(char *outopts) } while (outopts && *outopts) - switch (getsubopt(&outopts, toks, &v)) { + switch (getsubopt(&outopts, UNCONST(toks), &v)) { case (0): h->style = v; break; @@ -499,6 +505,17 @@ bufinit(struct html *h) void +bufcat_style(struct html *h, const char *key, const char *val) +{ + + bufcat(h, key); + bufncat(h, ":", 1); + bufcat(h, val); + bufncat(h, ";", 1); +} + + +void bufcat(struct html *h, const char *p) { @@ -537,7 +554,8 @@ buffmt_includes(struct html *h, const char *name) const char *p, *pp; pp = h->base_includes; - while ((p = strchr(pp, '%'))) { + + while (NULL != (p = strchr(pp, '%'))) { bufncat(h, pp, (size_t)(p - pp)); switch (*(p + 1)) { case('I'): @@ -561,14 +579,16 @@ buffmt_man(struct html *h, const char *p, *pp; pp = h->base_man; - while ((p = strchr(pp, '%'))) { + + /* LINTED */ + while (NULL != (p = strchr(pp, '%'))) { bufncat(h, pp, (size_t)(p - pp)); switch (*(p + 1)) { case('S'): - bufcat(h, sec); + bufcat(h, sec ? sec : "1"); break; case('N'): - buffmt(h, name ? name : "1"); + buffmt(h, name); break; default: bufncat(h, p, 2); @@ -578,4 +598,55 @@ buffmt_man(struct html *h, } if (pp) bufcat(h, pp); +} + + +void +bufcat_su(struct html *h, const char *p, const struct roffsu *su) +{ + double v; + const char *u; + + v = su->scale; + + switch (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; + } + + if (su->pt) + buffmt(h, "%s: %f%s;", p, v, u); + else + /* LINTED */ + buffmt(h, "%s: %d%s;", p, (int)v, u); }