diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-10-28 05:08:17 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-10-28 05:08:17 +0000 |
commit | e610e710af132c1cfeed06eb0da987c4ab7af35d (patch) | |
tree | e9cbd38d499e37af7b1048c22dde6a8d2c6efa1e /html.c | |
parent | c6fa100a886693167f543f9b59fbc85e46faa49c (diff) | |
download | mandoc-e610e710af132c1cfeed06eb0da987c4ab7af35d.tar.gz |
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.).
Diffstat (limited to 'html.c')
-rw-r--r-- | html.c | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -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'; +} |