merge new version of xmlparser (f32a38c45da3bd764f1708600a33bd878cbe8afc) - xml2tsv - a simple xml-to-tsv converter, based on xmlparser
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
(DIR) LICENSE
---
(DIR) commit b416c171bb34297d7f8bc4c027de7136a113d144
(DIR) parent 1e797ce6bffc927a69bc38828b5158dbb68b5950
(HTM) Author: KatolaZ <katolaz@freaknet.org>
Date: Wed, 5 Feb 2020 19:22:30 +0000
merge new version of xmlparser (f32a38c45da3bd764f1708600a33bd878cbe8afc)
Diffstat:
M xml.c | 19 ++++++++-----------
M xml.h | 2 ++
2 files changed, 10 insertions(+), 11 deletions(-)
---
(DIR) diff --git a/xml.c b/xml.c
@@ -1,8 +1,5 @@
-#include <sys/types.h>
-
#include <ctype.h>
#include <errno.h>
-#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -269,7 +266,7 @@ namedentitytostr(const char *e, char *buf, size_t bufsiz)
return 1;
}
}
- return 0;
+ return -1;
}
static int
@@ -286,12 +283,12 @@ numericentitytostr(const char *e, char *buf, size_t bufsiz)
errno = 0;
/* hex (16) or decimal (10) */
if (*e == 'x')
- l = strtoul(e + 1, &end, 16);
+ l = strtol(++e, &end, 16);
else
- l = strtoul(e, &end, 10);
- /* invalid value or not a well-formed entity or too high codepoint */
- if (errno || *end != ';' || l > 0x10FFFF)
- return 0;
+ l = strtol(e, &end, 10);
+ /* invalid value or not a well-formed entity or invalid codepoint */
+ if (errno || e == end || *end != ';' || l < 0 || l > 0x10ffff)
+ return -1;
len = codepointtoutf8(l, buf);
buf[len] = '\0';
@@ -299,13 +296,13 @@ numericentitytostr(const char *e, char *buf, size_t bufsiz)
}
/* convert named- or numeric entity string to buffer string
- * returns byte-length of string. */
+ * returns byte-length of string or -1 on failure. */
int
xml_entitytostr(const char *e, char *buf, size_t bufsiz)
{
/* doesn't start with & */
if (e[0] != '&')
- return 0;
+ return -1;
/* numeric entity */
if (e[1] == '#')
return numericentitytostr(e + 2, buf, bufsiz);
(DIR) diff --git a/xml.h b/xml.h
@@ -1,6 +1,8 @@
#ifndef _XML_H
#define _XML_H
+#include <stdio.h>
+
typedef struct xmlparser {
/* handlers */
void (*xmlattr)(struct xmlparser *, const char *, size_t,