summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-10-28 05:08:17 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-10-28 05:08:17 +0000
commitbe14751cf8a50d94471f0e2539b0437d0f776c56 (patch)
tree14f2a746f08501dc8659c9bd379b549e403e260e
parent56502d387509c2110dbc7798d17e8a7823573f62 (diff)
downloadmandoc-be14751cf8a50d94471f0e2539b0437d0f776c56.tar.gz
mandoc-be14751cf8a50d94471f0e2539b0437d0f776c56.tar.zst
mandoc-be14751cf8a50d94471f0e2539b0437d0f776c56.zip
Fixed un-reset buffer in `.In', -Thtml, -mdoc.
Added html_id[cat,cpy] for transforming id's into well-formed attribute strings (no %s, etc.).
-rw-r--r--html.c50
-rw-r--r--html.h5
-rw-r--r--mdoc_html.c30
3 files changed, 69 insertions, 16 deletions
diff --git a/html.c b/html.c
index c643efc8..f03d2caf 100644
--- a/html.c
+++ b/html.c
@@ -1,4 +1,4 @@
-/* $Id: html.c,v 1.67 2009/10/27 04:50:14 kristaps Exp $ */
+/* $Id: html.c,v 1.68 2009/10/28 05:08:17 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -17,6 +17,7 @@
#include <sys/types.h>
#include <assert.h>
+#include <ctype.h>
#include <err.h>
#include <stdio.h>
#include <stdarg.h>
@@ -648,3 +649,50 @@ bufcat_su(struct html *h, const char *p, const struct roffsu *su)
buffmt(h, "%s: %d%s;", p, (int)v, u);
}
+
+void
+html_idcpy(char *dst, const char *src, int sz)
+{
+
+ assert(sz);
+ dst[0] = '\0';
+ html_idcat(dst, src, sz);
+}
+
+
+void
+html_idcat(char *dst, const char *src, int sz)
+{
+ int i;
+
+ /* Cf. <http://www.w3.org/TR/html4/types.html#h-6.2>. */
+
+ for (i = 0; *dst != '\0' && i < sz - 1; dst++, i++)
+ /* Jump to end. */ ;
+
+ for ( ; *src != '\0' && i < sz - 1; src++, i++) {
+ if (isalnum((u_char)*src)) {
+ *dst++ = *src;
+ continue;
+ }
+
+ switch (*src) {
+ case (';'):
+ *dst++ = ';';
+ break;
+ case ('-'):
+ *dst++ = '-';
+ break;
+ case (':'):
+ *dst++ = ':';
+ break;
+ case ('_'):
+ /* FALLTHROUGH */
+ default:
+ *dst++ = '_';
+ break;
+ }
+ }
+
+ *dst = '\0';
+}
diff --git a/html.h b/html.h
index b20d08d5..3775edb9 100644
--- a/html.h
+++ b/html.h
@@ -1,4 +1,4 @@
-/* $Id: html.h,v 1.15 2009/10/27 04:50:14 kristaps Exp $ */
+/* $Id: html.h,v 1.16 2009/10/28 05:08:17 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -136,6 +136,9 @@ void bufcat_style(struct html *,
void bufncat(struct html *, const char *, size_t);
void bufinit(struct html *);
+void html_idcat(char *, const char *, int);
+void html_idcpy(char *, const char *, int);
+
__END_DECLS
#endif /*!HTML_H*/
diff --git a/mdoc_html.c b/mdoc_html.c
index 33991795..65f78ea6 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.40 2009/10/27 04:50:15 kristaps Exp $ */
+/* $Id: mdoc_html.c,v 1.41 2009/10/28 05:08:17 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -556,7 +556,7 @@ mdoc_sh_pre(MDOC_ARGS)
{
struct htmlpair tag[2];
const struct mdoc_node *nn;
- char lbuf[BUFSIZ];
+ char buf[BUFSIZ];
struct roffsu su;
if (MDOC_BODY == n->type) {
@@ -583,11 +583,11 @@ mdoc_sh_pre(MDOC_ARGS)
return(1);
}
- lbuf[0] = 0;
+ html_idcpy(buf, "id_", BUFSIZ);
for (nn = n->child; nn; nn = nn->next) {
- (void)strlcat(lbuf, nn->string, BUFSIZ);
+ html_idcat(buf, nn->string, BUFSIZ);
if (nn->next)
- (void)strlcat(lbuf, "_", BUFSIZ);
+ html_idcat(buf, "_", BUFSIZ);
}
/*
@@ -597,7 +597,7 @@ mdoc_sh_pre(MDOC_ARGS)
PAIR_CLASS_INIT(&tag[0], "sec-head");
tag[1].key = ATTR_ID;
- tag[1].val = lbuf;
+ tag[1].val = buf;
print_otag(h, TAG_DIV, 2, tag);
return(1);
}
@@ -609,7 +609,7 @@ mdoc_ss_pre(MDOC_ARGS)
{
struct htmlpair tag[3];
const struct mdoc_node *nn;
- char lbuf[BUFSIZ];
+ char buf[BUFSIZ];
struct roffsu su;
SCALE_VS_INIT(&su, 1);
@@ -636,11 +636,11 @@ mdoc_ss_pre(MDOC_ARGS)
/* TODO: see note in mdoc_sh_pre() about duplicates. */
- lbuf[0] = 0;
+ html_idcpy(buf, "id_", BUFSIZ);
for (nn = n->child; nn; nn = nn->next) {
- (void)strlcat(lbuf, nn->string, BUFSIZ);
+ html_idcat(buf, nn->string, BUFSIZ);
if (nn->next)
- (void)strlcat(lbuf, "_", BUFSIZ);
+ html_idcat(buf, "_", BUFSIZ);
}
SCALE_HS_INIT(&su, INDENT - HALFINDENT);
@@ -650,7 +650,7 @@ mdoc_ss_pre(MDOC_ARGS)
PAIR_CLASS_INIT(&tag[0], "ssec-head");
PAIR_STYLE_INIT(&tag[1], h);
tag[2].key = ATTR_ID;
- tag[2].val = lbuf;
+ tag[2].val = buf;
print_otag(h, TAG_DIV, 3, tag);
return(1);
}
@@ -1297,11 +1297,12 @@ mdoc_sx_pre(MDOC_ARGS)
/* FIXME: duplicates? */
- (void)strlcpy(buf, "#", BUFSIZ);
+ strlcpy(buf, "#", BUFSIZ);
+ html_idcat(buf, "id_", BUFSIZ);
for (nn = n->child; nn; nn = nn->next) {
- (void)strlcat(buf, nn->string, BUFSIZ);
+ html_idcat(buf, nn->string, BUFSIZ);
if (nn->next)
- (void)strlcat(buf, "_", BUFSIZ);
+ html_idcat(buf, "_", BUFSIZ);
}
PAIR_CLASS_INIT(&tag[0], "link-sec");
@@ -1865,6 +1866,7 @@ mdoc_in_pre(MDOC_ARGS)
for (nn = n->child; nn; nn = nn->next) {
PAIR_CLASS_INIT(&tag[0], "link-includes");
i = 1;
+ bufinit(h);
if (h->base_includes) {
buffmt_includes(h, nn->string);
tag[i].key = ATTR_HREF;