summaryrefslogtreecommitdiffstats
path: root/ml.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2008-12-03 14:39:59 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2008-12-03 14:39:59 +0000
commitac4bc07079be4963163734d67749697140f23b4b (patch)
treeb286cf3805fac09fc13f81d1055c1d879eeaf65d /ml.c
parent947a810f327c5d9b23991b114fea38e5c44aa5ad (diff)
downloadmandoc-ac4bc07079be4963163734d67749697140f23b4b.tar.gz
Abstract ml/mlg/html/xml.
Diffstat (limited to 'ml.c')
-rw-r--r--ml.c162
1 files changed, 33 insertions, 129 deletions
diff --git a/ml.c b/ml.c
index 96302d53..46c1076d 100644
--- a/ml.c
+++ b/ml.c
@@ -21,164 +21,68 @@
#include "libmdocml.h"
#include "private.h"
+#include "ml.h"
+#ifdef __linux__
+extern size_t strlcat(char *, const char *, size_t);
+extern size_t strlcpy(char *, const char *, size_t);
+#endif
-#define MAXINDENT 8
-static ssize_t ml_puts(struct md_mbuf *, const char *);
-static ssize_t ml_putchar(struct md_mbuf *, char);
-static ssize_t ml_putstring(struct md_mbuf *, const char *);
-
-
-static ssize_t
-ml_puts(struct md_mbuf *p, const char *buf)
-{
-
- return(ml_nputs(p, buf, strlen(buf)));
-}
-
-
-static ssize_t
-ml_putchar(struct md_mbuf *p, char buf)
-{
-
- return(ml_nputs(p, &buf, 1));
-}
-
-
-static ssize_t
-ml_putstring(struct md_mbuf *p, const char *buf)
-{
-
- return(ml_nputstring(p, buf, strlen(buf)));
-}
-
-
-ssize_t
-ml_begintag(struct md_mbuf *p, const char *name,
- int *argc, char **argv)
-{
- int i;
- ssize_t res, sz;
-
- res = 0;
-
- if (-1 == (sz = ml_nputs(p, "<", 1)))
- return(-1);
- res += sz;
-
- if (-1 == (sz = ml_puts(p, name)))
- return(-1);
- res += sz;
-
- for (i = 0; ROFF_ARGMAX != argc[i]; i++) {
- if (-1 == (sz = ml_nputs(p, " ", 1)))
- return(-1);
- res += sz;
-
- if (-1 == (sz = ml_puts(p, tokargnames[argc[i]])))
- return(-1);
- res += sz;
-
- if (-1 == (sz = ml_nputs(p, "=\"", 2)))
- return(-1);
- res += sz;
-
- if (-1 == (sz = ml_putstring(p, argv[i] ?
- argv[i] : "true")))
- return(-1);
- res += sz;
-
- if (-1 == (sz = ml_nputs(p, "\"", 1)))
- return(-1);
- res += sz;
- }
-
- if (-1 == (sz = ml_nputs(p, ">", 1)))
- return(-1);
-
- return(res + sz);
-}
-
-
-ssize_t
-ml_endtag(struct md_mbuf *p, const char *tag)
-{
- ssize_t res, sz;
-
- res = 0;
-
- if (-1 == (sz = ml_nputs(p, "</", 2)))
- return(-1);
- res += sz;
-
- if (-1 == (sz = ml_puts(p, tag)))
- return(-1);
- res += sz;
-
- if (-1 == (sz = ml_nputs(p, ">", 1)))
- return(-1);
-
- return(res + sz);
-}
-
-
-ssize_t
-ml_nputstring(struct md_mbuf *p, const char *buf, size_t bufsz)
+int
+ml_nputstring(struct md_mbuf *p,
+ const char *buf, size_t sz, size_t *pos)
{
int i;
- ssize_t res, sz;
- res = 0;
-
- for (i = 0; i < (int)bufsz; i++) {
+ for (i = 0; i < (int)sz; i++) {
switch (buf[i]) {
case ('&'):
- if (-1 == (sz = ml_nputs(p, "&amp;", 5)))
- return(-1);
+ if ( ! ml_nputs(p, "&amp;", 5, pos))
+ return(0);
break;
case ('"'):
- if (-1 == (sz = ml_nputs(p, "&quot;", 6)))
- return(-1);
+ if ( ! ml_nputs(p, "&quot;", 6, pos))
+ return(0);
break;
case ('<'):
- if (-1 == (sz = ml_nputs(p, "&lt;", 4)))
- return(-1);
+ if ( ! ml_nputs(p, "&lt;", 4, pos))
+ return(0);
break;
case ('>'):
- if (-1 == (sz = ml_nputs(p, "&gt;", 4)))
- return(-1);
+ if ( ! ml_nputs(p, "&gt;", 4, pos))
+ return(0);
break;
default:
- if (-1 == (sz = ml_putchar(p, buf[i])))
- return(-1);
+ if ( ! ml_nputs(p, &buf[i], 1, pos))
+ return(0);
break;
}
- res += sz;
}
- return(res);
+ return(1);
}
-ssize_t
-ml_nputs(struct md_mbuf *p, const char *buf, size_t sz)
+int
+ml_nputs(struct md_mbuf *p, const char *buf, size_t sz, size_t *pos)
{
- return(0 == md_buf_puts(p, buf, sz) ? -1 : (ssize_t)sz);
+ if ( ! md_buf_puts(p, buf, sz))
+ return(0);
+
+ *pos += sz;
+ return(1);
}
-ssize_t
-ml_indent(struct md_mbuf *p, int indent)
+int
+ml_putchars(struct md_mbuf *p, char buf, size_t count, size_t *pos)
{
size_t i;
- ssize_t res, sz;
- res = sz 0;
+ for (i = 0; i < count; i++)
+ if ( ! ml_nputs(p, &buf, 1, pos))
+ return(0);
- /* LINTED */
- for (i = 0; i < MIN(indent, MAXINDENT); i++, res += sz)
- if (-1 == (sz = ml_nputs(p, " ", 4)))
- return(-1);
- return(res);
+ return(1);
}