general cleanups.
This commit is contained in:
parent
95bc1d587f
commit
09adb5ee05
3 changed files with 40 additions and 23 deletions
|
@ -57,7 +57,6 @@ typedef struct
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
#ifndef XML_NONVALIDATING
|
#ifndef XML_NONVALIDATING
|
||||||
#include "xml.h"
|
#include "xml.h"
|
||||||
|
|
||||||
|
@ -1305,10 +1304,11 @@ static const char *__xml_error_str[XML_MAX_ERROR] =
|
||||||
"no error.",
|
"no error.",
|
||||||
"unable to allocate enough memory.",
|
"unable to allocate enough memory.",
|
||||||
"unable to open file for reading.",
|
"unable to open file for reading.",
|
||||||
|
"requested node name is invalid.",
|
||||||
|
"unexpected end of section.",
|
||||||
"buffer too small to hold all data, truncating.",
|
"buffer too small to hold all data, truncating.",
|
||||||
"incorrect comment section.",
|
"incorrect comment section.",
|
||||||
"bad information block.",
|
"bad information block.",
|
||||||
"unexpected end of section.",
|
|
||||||
"incompatible opening tag for element.",
|
"incompatible opening tag for element.",
|
||||||
"missing or invalid closing tag for element.",
|
"missing or invalid closing tag for element.",
|
||||||
"missing or invalid opening quote for attribute.",
|
"missing or invalid opening quote for attribute.",
|
||||||
|
@ -1398,24 +1398,29 @@ __xmlNodeGetPath(const char *start, size_t *len, char **name, size_t *plen)
|
||||||
char *
|
char *
|
||||||
__xmlNodeGet(const char *start, size_t *len, char **name, size_t *rlen, size_t *nodenum)
|
__xmlNodeGet(const char *start, size_t *len, char **name, size_t *rlen, size_t *nodenum)
|
||||||
{
|
{
|
||||||
char *open_element = *name;
|
char *cdata, *open_element = *name;
|
||||||
char *element, *start_tag=0;
|
char *element, *start_tag=0;
|
||||||
char *new, *cur, *ne, *ret = 0;
|
char *new, *cur, *ne, *ret = 0;
|
||||||
size_t restlen, elementlen;
|
size_t restlen, elementlen;
|
||||||
size_t open_len = *rlen;
|
size_t open_len = *rlen;
|
||||||
size_t return_len = 0;
|
size_t return_len = 0;
|
||||||
int found, cdata, num;
|
int found, num;
|
||||||
|
|
||||||
assert(start != 0);
|
assert(start != 0);
|
||||||
assert(len != 0);
|
assert(len != 0);
|
||||||
assert(*len != 0);
|
|
||||||
assert(name != 0);
|
assert(name != 0);
|
||||||
assert(*name != 0);
|
|
||||||
assert(rlen != 0);
|
assert(rlen != 0);
|
||||||
assert(*rlen != 0);
|
|
||||||
assert(nodenum != 0);
|
assert(nodenum != 0);
|
||||||
|
|
||||||
cdata = 0;
|
if (open_len == 0 || *name == 0)
|
||||||
|
{
|
||||||
|
*rlen = 0;
|
||||||
|
*name = (char *)start;
|
||||||
|
*len = XML_INVALID_NODE_NAME;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cdata = (char *)start;
|
||||||
if (*rlen > *len)
|
if (*rlen > *len)
|
||||||
{
|
{
|
||||||
*rlen = 0;
|
*rlen = 0;
|
||||||
|
@ -1446,17 +1451,12 @@ __xmlNodeGet(const char *start, size_t *len, char **name, size_t *rlen, size_t *
|
||||||
restlen -= new-cur;
|
restlen -= new-cur;
|
||||||
cur = new;
|
cur = new;
|
||||||
|
|
||||||
if (*cur == '!') /* comment, or CDATA */
|
if (*cur == '!') /* comment */
|
||||||
{
|
{
|
||||||
size_t blocklen = restlen;
|
size_t blocklen = restlen;
|
||||||
char *start = cur;
|
char *start = cur;
|
||||||
new = __xmlProcessCDATA(&start, &blocklen);
|
new = __xmlCommentSkip(cur, restlen);
|
||||||
if (new && start && ret) /* CDATA */
|
if (!new)
|
||||||
{
|
|
||||||
ret += 9;
|
|
||||||
cdata = 1;
|
|
||||||
}
|
|
||||||
else if (!new)
|
|
||||||
{
|
{
|
||||||
*rlen = 0;
|
*rlen = 0;
|
||||||
*name = cur;
|
*name = cur;
|
||||||
|
@ -1551,10 +1551,9 @@ __xmlNodeGet(const char *start, size_t *len, char **name, size_t *rlen, size_t *
|
||||||
size_t blocklen = restlen;
|
size_t blocklen = restlen;
|
||||||
char *start = cur;
|
char *start = cur;
|
||||||
new = __xmlProcessCDATA(&start, &blocklen);
|
new = __xmlProcessCDATA(&start, &blocklen);
|
||||||
if (new && start && ret) /* CDATA */
|
if (new && start && open_len) /* CDATA */
|
||||||
{
|
{
|
||||||
ret += 9;
|
cdata = ret;
|
||||||
cdata = 1;
|
|
||||||
}
|
}
|
||||||
else if (!new)
|
else if (!new)
|
||||||
{
|
{
|
||||||
|
@ -1650,8 +1649,14 @@ __xmlNodeGet(const char *start, size_t *len, char **name, size_t *rlen, size_t *
|
||||||
if (start_tag)
|
if (start_tag)
|
||||||
{
|
{
|
||||||
*len = new-ret-1;
|
*len = new-ret-1;
|
||||||
if (cdata) *len -= 3;
|
if (cdata == ret)
|
||||||
|
{
|
||||||
|
ret += 9; /* ![CDATA[[ */
|
||||||
|
*len -= 12; /* ![CDATA[[ ]]> */
|
||||||
|
}
|
||||||
open_element = start_tag;
|
open_element = start_tag;
|
||||||
|
cdata = (char *)start;
|
||||||
|
start_tag = 0;
|
||||||
}
|
}
|
||||||
else /* report error */
|
else /* report error */
|
||||||
{
|
{
|
||||||
|
@ -1734,13 +1739,19 @@ __xmlProcessCDATA(char **start, size_t *len)
|
||||||
{
|
{
|
||||||
if ((restlen > 3) && (memcmp(new, "]]>", 3) == 0))
|
if ((restlen > 3) && (memcmp(new, "]]>", 3) == 0))
|
||||||
{
|
{
|
||||||
new += 3;
|
*start = cur;
|
||||||
|
*len = new-cur;
|
||||||
restlen -= 3;
|
restlen -= 3;
|
||||||
|
new += 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cur = new+1;
|
cur = new+1;
|
||||||
}
|
}
|
||||||
else break;
|
else
|
||||||
|
{
|
||||||
|
*len = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (new && (restlen > 2));
|
while (new && (restlen > 2));
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,10 +33,11 @@ enum
|
||||||
XML_NO_ERROR = 0,
|
XML_NO_ERROR = 0,
|
||||||
XML_OUT_OF_MEMORY,
|
XML_OUT_OF_MEMORY,
|
||||||
XML_FILE_NOT_FOUND,
|
XML_FILE_NOT_FOUND,
|
||||||
|
XML_INVALID_NODE_NAME,
|
||||||
|
XML_UNEXPECTED_EOF,
|
||||||
XML_TRUNCATE_RESULT,
|
XML_TRUNCATE_RESULT,
|
||||||
XML_INVALID_COMMENT,
|
XML_INVALID_COMMENT,
|
||||||
XML_INVALID_INFO_BLOCK,
|
XML_INVALID_INFO_BLOCK,
|
||||||
XML_UNEXPECTED_EOF,
|
|
||||||
XML_ELEMENT_NO_OPENING_TAG,
|
XML_ELEMENT_NO_OPENING_TAG,
|
||||||
XML_ELEMENT_NO_CLOSING_TAG,
|
XML_ELEMENT_NO_CLOSING_TAG,
|
||||||
XML_ATTRIB_NO_OPENING_QUOTE,
|
XML_ATTRIB_NO_OPENING_QUOTE,
|
||||||
|
|
|
@ -121,6 +121,7 @@ parse_option(char **args, int n, int max)
|
||||||
{
|
{
|
||||||
if (arg == 0) SHOW_NOVAL(opt);
|
if (arg == 0) SHOW_NOVAL(opt);
|
||||||
alen = strlen(arg)+1;
|
alen = strlen(arg)+1;
|
||||||
|
if (_root) free(_root);
|
||||||
_root = malloc(alen);
|
_root = malloc(alen);
|
||||||
memcpy(_root, arg, alen);
|
memcpy(_root, arg, alen);
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -129,6 +130,7 @@ parse_option(char **args, int n, int max)
|
||||||
{
|
{
|
||||||
if (arg == 0) SHOW_NOVAL(opt);
|
if (arg == 0) SHOW_NOVAL(opt);
|
||||||
alen = strlen(arg)+1;
|
alen = strlen(arg)+1;
|
||||||
|
if (_element) free(_element);
|
||||||
_element = malloc(alen);
|
_element = malloc(alen);
|
||||||
memcpy(_element, arg, alen);
|
memcpy(_element, arg, alen);
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -137,6 +139,7 @@ parse_option(char **args, int n, int max)
|
||||||
{
|
{
|
||||||
if (arg == 0) SHOW_NOVAL(opt);
|
if (arg == 0) SHOW_NOVAL(opt);
|
||||||
alen = strlen(arg)+1;
|
alen = strlen(arg)+1;
|
||||||
|
if (_value) free(_value);
|
||||||
_value = malloc(alen);
|
_value = malloc(alen);
|
||||||
memcpy(_value, arg, alen);
|
memcpy(_value, arg, alen);
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -145,6 +148,7 @@ parse_option(char **args, int n, int max)
|
||||||
{
|
{
|
||||||
if (arg == 0) SHOW_NOVAL(opt);
|
if (arg == 0) SHOW_NOVAL(opt);
|
||||||
alen = strlen(arg)+1;
|
alen = strlen(arg)+1;
|
||||||
|
if (_print) free(_print);
|
||||||
_print = malloc(alen);
|
_print = malloc(alen);
|
||||||
memcpy(_print, arg, alen);
|
memcpy(_print, arg, alen);
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -153,6 +157,7 @@ parse_option(char **args, int n, int max)
|
||||||
{
|
{
|
||||||
if (arg == 0) SHOW_NOVAL(opt);
|
if (arg == 0) SHOW_NOVAL(opt);
|
||||||
alen = strlen(arg)+1;
|
alen = strlen(arg)+1;
|
||||||
|
if (_attribute) free(_attribute);
|
||||||
_attribute = malloc(alen);
|
_attribute = malloc(alen);
|
||||||
memcpy(_attribute, arg, alen);
|
memcpy(_attribute, arg, alen);
|
||||||
return 2;
|
return 2;
|
||||||
|
|
Loading…
Reference in a new issue