=================================================================== RCS file: /cvs/mandoc/mdoc_html.c,v retrieving revision 1.15 retrieving revision 1.20 diff -u -p -r1.15 -r1.20 --- mandoc/mdoc_html.c 2009/09/26 18:31:36 1.15 +++ mandoc/mdoc_html.c 2009/10/03 19:57:53 1.20 @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.15 2009/09/26 18:31:36 kristaps Exp $ */ +/* $Id: mdoc_html.c,v 1.20 2009/10/03 19:57:53 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -35,9 +35,6 @@ #define MDOC_ARGS const struct mdoc_meta *m, \ const struct mdoc_node *n, \ struct html *h -#define MAN_ARGS const struct man_meta *m, \ - const struct man_node *n, \ - struct html *h struct htmlmdoc { int (*pre)(MDOC_ARGS); @@ -255,12 +252,7 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = { {mdoc_sp_pre, NULL}, /* sp */ }; -static char buf[BUFSIZ]; /* XXX */ -#define bufcat(x) (void)strlcat(buf, (x), BUFSIZ) -#define bufinit() buf[0] = 0 -#define buffmt(...) (void)snprintf(buf, BUFSIZ - 1, __VA_ARGS__) - void html_mdoc(void *arg, const struct mdoc *m) { @@ -390,21 +382,19 @@ print_mdoc(MDOC_ARGS) static void print_mdoc_head(MDOC_ARGS) { - char b[BUFSIZ]; print_gen_head(h); + bufinit(h); + buffmt(h, "%s(%d)", m->title, m->msec); - (void)snprintf(b, BUFSIZ - 1, - "%s(%d)", m->title, m->msec); - if (m->arch) { - (void)strlcat(b, " (", BUFSIZ); - (void)strlcat(b, m->arch, BUFSIZ); - (void)strlcat(b, ")", BUFSIZ); + bufcat(h, " ("); + bufcat(h, m->arch); + bufcat(h, ")"); } print_otag(h, TAG_TITLE, 0, NULL); - print_text(h, b); + print_text(h, h->buf); } @@ -427,7 +417,7 @@ print_mdoc_node(MDOC_ARGS) child = 1; t = SLIST_FIRST(&h->tags); - bufinit(); + bufinit(h); switch (n->type) { case (MDOC_ROOT): @@ -447,7 +437,7 @@ print_mdoc_node(MDOC_ARGS) print_stagq(h, t); - bufinit(); + bufinit(h); switch (n->type) { case (MDOC_ROOT): @@ -560,12 +550,12 @@ mdoc_sh_pre(MDOC_ARGS) print_otag(h, TAG_SPAN, 1, tag); for (nn = n->child; nn; nn = nn->next) { - bufcat(nn->string); + bufcat(h, nn->string); if (nn->next) - bufcat(" "); + bufncat(h, " ", 1); } tag[0].key = ATTR_NAME; - tag[0].val = buf; + tag[0].val = h->buf; print_otag(h, TAG_A, 1, tag); return(1); } else if (MDOC_BLOCK == n->type) { @@ -577,23 +567,23 @@ mdoc_sh_pre(MDOC_ARGS) return(1); } - bufcat("margin-top: 1em;"); + bufcat(h, "margin-top: 1em;"); if (NULL == n->next) - bufcat("margin-bottom: 1em;"); + bufcat(h, "margin-bottom: 1em;"); tag[1].key = ATTR_STYLE; - tag[1].val = buf; + tag[1].val = h->buf; print_otag(h, TAG_DIV, 2, tag); return(1); } - buffmt("margin-left: %dem;", INDENT); + buffmt(h, "margin-left: %dem;", INDENT); tag[0].key = ATTR_CLASS; tag[0].val = "sec-body"; tag[1].key = ATTR_STYLE; - tag[1].val = buf; + tag[1].val = h->buf; print_otag(h, TAG_DIV, 2, tag); return(1); @@ -614,9 +604,9 @@ mdoc_ss_pre(MDOC_ARGS) tag[i].key = ATTR_CLASS; tag[i++].val = "ssec-body"; if (n->parent->next && n->child) { - bufcat("margin-bottom: 1em;"); + bufcat(h, "margin-bottom: 1em;"); tag[i].key = ATTR_STYLE; - tag[i++].val = buf; + tag[i++].val = h->buf; } print_otag(h, TAG_DIV, i, tag); return(1); @@ -624,32 +614,32 @@ mdoc_ss_pre(MDOC_ARGS) tag[i].key = ATTR_CLASS; tag[i++].val = "ssec-block"; if (n->prev) { - bufcat("margin-top: 1em;"); + bufcat(h, "margin-top: 1em;"); tag[i].key = ATTR_STYLE; - tag[i++].val = buf; + tag[i++].val = h->buf; } print_otag(h, TAG_DIV, i, tag); return(1); } - buffmt("margin-left: -%dem;", INDENT - HALFINDENT); + buffmt(h, "margin-left: -%dem;", INDENT - HALFINDENT); tag[0].key = ATTR_CLASS; tag[0].val = "ssec-head"; tag[1].key = ATTR_STYLE; - tag[1].val = buf; + tag[1].val = h->buf; print_otag(h, TAG_DIV, 2, tag); print_otag(h, TAG_SPAN, 1, tag); - bufinit(); + bufinit(h); for (nn = n->child; nn; nn = nn->next) { - bufcat(nn->string); + bufcat(h, nn->string); if (nn->next) - bufcat(" "); + bufcat(h, " "); } tag[0].key = ATTR_NAME; - tag[0].val = buf; + tag[0].val = h->buf; print_otag(h, TAG_A, 1, tag); return(1); @@ -751,24 +741,25 @@ static int mdoc_xr_pre(MDOC_ARGS) { struct htmlpair tag[2]; - const char *name, *sec; const struct mdoc_node *nn; + int i; - nn = n->child; - name = nn && nn->string ? nn->string : ""; - nn = nn ? nn->next : NULL; - sec = nn && nn->string ? nn->string : ""; + i = 0; + tag[i].key = ATTR_CLASS; + tag[i++].val = "link-man"; - buffmt("%s%s%s.html", name, name && sec ? "." : "", sec); + if (h->base_man) { + buffmt_man(h, n->child->string, n->child->next ? + n->child->next->string : NULL); + tag[i].key = ATTR_HREF; + tag[i++].val = h->buf; + } - tag[0].key = ATTR_CLASS; - tag[0].val = "link-man"; - tag[1].key = ATTR_HREF; - tag[1].val = buf; - print_otag(h, TAG_A, 2, tag); + print_otag(h, TAG_A, i, tag); nn = n->child; print_text(h, nn->string); + if (NULL == (nn = nn->next)) return(0); @@ -882,10 +873,10 @@ mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int case (MDOC_Item): /* FALLTHROUGH */ case (MDOC_Ohang): - buffmt("margin-left: %dem; clear: both;", o); + buffmt(h, "margin-left: %dem; clear: both;", o); break; default: - buffmt("margin-left: %dem; clear: both;", w + o); + buffmt(h, "margin-left: %dem; clear: both;", w + o); break; } @@ -909,11 +900,11 @@ mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int if (NULL == n->prev->body->child) c = 1; if ( ! c) - bufcat("padding-top: 1em;"); + bufcat(h, "padding-top: 1em;"); } tag.key = ATTR_STYLE; - tag.val = buf; + tag.val = h->buf; print_otag(h, TAG_DIV, 1, &tag); return(1); } @@ -944,23 +935,23 @@ mdoc_tbl_head_pre(MDOC_ARGS, int t, int w) print_otag(h, TAG_DIV, 0, NULL); break; case (MDOC_Column): - buffmt("min-width: %dem;", w); - bufcat("clear: none;"); + buffmt(h, "min-width: %dem;", w); + bufcat(h, "clear: none;"); if (n->next && MDOC_HEAD == n->next->type) - bufcat("float: left;"); + bufcat(h, "float: left;"); tag.key = ATTR_STYLE; - tag.val = buf; + tag.val = h->buf; print_otag(h, TAG_DIV, 1, &tag); break; default: - buffmt("margin-left: -%dem; min-width: %dem;", + buffmt(h, "margin-left: -%dem; min-width: %dem;", w, w ? w - 1 : 0); - bufcat("clear: left;"); + bufcat(h, "clear: left;"); if (n->next && n->next->child) - bufcat("float: left;"); - bufcat("padding-right: 1em;"); + bufcat(h, "float: left;"); + bufcat(h, "padding-right: 1em;"); tag.key = ATTR_STYLE; - tag.val = buf; + tag.val = h->buf; print_otag(h, TAG_DIV, 1, &tag); break; } @@ -1260,12 +1251,12 @@ mdoc_d1_pre(MDOC_ARGS) if (MDOC_BLOCK != n->type) return(1); - buffmt("margin-left: %dem;", INDENT); + buffmt(h, "margin-left: %dem;", INDENT); tag[0].key = ATTR_CLASS; tag[0].val = "lit"; tag[1].key = ATTR_STYLE; - tag[1].val = buf; + tag[1].val = h->buf; print_otag(h, TAG_DIV, 2, tag); return(1); @@ -1279,15 +1270,15 @@ mdoc_sx_pre(MDOC_ARGS) struct htmlpair tag[2]; const struct mdoc_node *nn; - bufcat("#"); + bufcat(h, "#"); for (nn = n->child; nn; nn = nn->next) { - bufcat(nn->string); + bufcat(h, nn->string); if (nn->next) - bufcat(" "); + bufcat(h, " "); } tag[0].key = ATTR_HREF; - tag[0].val = buf; + tag[0].val = h->buf; tag[1].key = ATTR_CLASS; tag[1].val = "link-sec"; @@ -1360,7 +1351,7 @@ mdoc_bd_pre(MDOC_ARGS) if (MDOC_BLOCK == n->type) { if (o) - buffmt("margin-left: %dem;", o); + buffmt(h, "margin-left: %dem;", o); if ( ! c) { for (nn = n; nn; nn = nn->parent) { if (MDOC_BLOCK != nn->type) @@ -1378,10 +1369,10 @@ mdoc_bd_pre(MDOC_ARGS) break; } if ( ! c) - bufcat("margin-top: 1em;"); + bufcat(h, "margin-top: 1em;"); } tag[0].key = ATTR_STYLE; - tag[0].val = buf; + tag[0].val = h->buf; print_otag(h, TAG_DIV, 1, tag); return(1); } @@ -1389,9 +1380,9 @@ mdoc_bd_pre(MDOC_ARGS) if (MDOC_Unfilled != t && MDOC_Literal != t) return(1); - bufcat("white-space: pre;"); + bufcat(h, "white-space: pre;"); tag[0].key = ATTR_STYLE; - tag[0].val = buf; + tag[0].val = h->buf; tag[1].key = ATTR_CLASS; tag[1].val = "lit"; @@ -1442,6 +1433,8 @@ mdoc_an_pre(MDOC_ARGS) { struct htmlpair tag; + /* TODO: -split and -nosplit (see termp_an_pre()). */ + tag.key = ATTR_CLASS; tag.val = "author"; print_otag(h, TAG_SPAN, 1, &tag); @@ -1610,33 +1603,36 @@ mdoc_fn_pre(MDOC_ARGS) int sz, i; if (SEC_SYNOPSIS == n->sec) { - bufcat("margin-left: 6em;"); - bufcat("text-indent: -6em;"); + bufcat(h, "margin-left: 6em;"); + bufcat(h, "text-indent: -6em;"); if (n->next) - bufcat("margin-bottom: 1em;"); + bufcat(h, "margin-bottom: 1em;"); tag[0].key = ATTR_STYLE; - tag[0].val = buf; + tag[0].val = h->buf; print_otag(h, TAG_DIV, 1, tag); } /* Split apart into type and name. */ - - tag[0].key = ATTR_CLASS; - tag[0].val = "ftype"; - t = print_otag(h, TAG_SPAN, 1, tag); - assert(n->child->string); sp = n->child->string; - while (NULL != (ep = strchr(sp, ' '))) { - sz = MIN((int)(ep - sp), BUFSIZ - 1); - (void)memcpy(nbuf, sp, (size_t)sz); - nbuf[sz] = '\0'; - print_text(h, nbuf); - sp = ++ep; + + if ((ep = strchr(sp, ' '))) { + tag[0].key = ATTR_CLASS; + tag[0].val = "ftype"; + + t = print_otag(h, TAG_SPAN, 1, tag); + + while (ep) { + sz = MIN((int)(ep - sp), BUFSIZ - 1); + (void)memcpy(nbuf, sp, (size_t)sz); + nbuf[sz] = '\0'; + print_text(h, nbuf); + sp = ++ep; + ep = strchr(sp, ' '); + } + print_tagq(h, t); } - print_tagq(h, t); - tag[0].key = ATTR_CLASS; tag[0].val = "fname"; t = print_otag(h, TAG_SPAN, 1, tag); @@ -1695,9 +1691,9 @@ mdoc_sp_pre(MDOC_ARGS) break; } - buffmt("height: %dem", len); + buffmt(h, "height: %dem", len); tag.key = ATTR_STYLE; - tag.val = buf; + tag.val = h->buf; print_otag(h, TAG_DIV, 1, &tag); return(1); @@ -1767,12 +1763,12 @@ mdoc_mt_pre(MDOC_ARGS) tag[0].val = "link-mail"; for (nn = n->child; nn; nn = nn->next) { - bufinit(); - bufcat("mailto:"); - bufcat(nn->string); + bufinit(h); + bufcat(h, "mailto:"); + bufcat(h, nn->string); tag[1].key = ATTR_HREF; - tag[1].val = buf; + tag[1].val = h->buf; t = print_otag(h, TAG_A, 2, tag); print_text(h, nn->string); @@ -1822,21 +1818,23 @@ static int mdoc_in_pre(MDOC_ARGS) { const struct mdoc_node *nn; - struct htmlpair tag; + struct htmlpair tag[2]; + struct tag *t; + int i; if (SEC_SYNOPSIS == n->sec) { if (n->next && MDOC_In != n->next->tok) { - tag.key = ATTR_STYLE; - tag.val = "margin-bottom: 1em;"; - print_otag(h, TAG_DIV, 1, &tag); + tag[0].key = ATTR_STYLE; + tag[0].val = "margin-bottom: 1em;"; + print_otag(h, TAG_DIV, 1, tag); } else print_otag(h, TAG_DIV, 0, NULL); } - tag.key = ATTR_CLASS; - tag.val = "includes"; + tag[0].key = ATTR_CLASS; + tag[0].val = "includes"; - print_otag(h, TAG_SPAN, 1, &tag); + print_otag(h, TAG_SPAN, 1, tag); if (SEC_SYNOPSIS == n->sec) print_text(h, "#include"); @@ -1846,8 +1844,20 @@ mdoc_in_pre(MDOC_ARGS) /* XXX -- see warning in termp_in_post(). */ - for (nn = n->child; nn; nn = nn->next) + for (nn = n->child; nn; nn = nn->next) { + assert(MDOC_TEXT == nn->type); + i = 0; + tag[i].key = ATTR_CLASS; + tag[i++].val = "link-includes"; + if (h->base_includes) { + buffmt_includes(h, nn->string); + tag[i].key = ATTR_HREF; + tag[i++].val = h->buf; + } + t = print_otag(h, TAG_A, i, tag); print_mdoc_node(m, nn, h); + print_tagq(h, t); + } h->flags |= HTML_NOSPACE; print_text(h, ">");