summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2015-10-27 18:38:08 +0100
committerYorhel <git@yorhel.nl>2015-10-27 18:38:08 +0100
commit10f968b0e78b9aeee357d0de81a46b445c3fb27b (patch)
tree493f6a1246d9e0c23dc555ddfb321764e6add8a3
parent05f8de1ea776419b1532d382737ca09df08dcae2 (diff)
Use yxml_ret_t internally wherever that makes sense
-rwxr-xr-xyxml-gen.pl9
-rw-r--r--yxml.c56
-rw-r--r--yxml.c.in56
3 files changed, 59 insertions, 62 deletions
diff --git a/yxml-gen.pl b/yxml-gen.pl
index 2f6c3c7..589a445 100755
--- a/yxml-gen.pl
+++ b/yxml-gen.pl
@@ -44,10 +44,6 @@ sub condtoc {
sub acttoc {
my $next = shift;
my(@c, @r);
- # XXX: Return values of function calls are or'ed together to create the
- # return value of yxml_parse(). This only works when the function do not
- # return an error code. Functions that may return an error should NOT be
- # called in the same state as other functions.
for(@_) {
push @r, "yxml_$1(x, ch)" if /^([a-z0-9_]+)$/;
push @c, "x->$1 = ch" if /^\$(.+)$/;
@@ -60,9 +56,10 @@ sub acttoc {
}
push @c, "x->nextstate = YXMLS_$_" if s/^@//;
}
+ die "Can't call multiple functions in a single state." if @r > 1;
(
map("$_;", @c),
- 'return ' . (@r ? join('|', @r) : 'YXML_OK') . ';'
+ 'return ' . ($r[0] || 'YXML_OK') . ';'
)
}
@@ -98,7 +95,7 @@ sub readmachine {
s/^ //;
s/ $//;
next if !$_ || /^#/;
- die "Unrecognized line: $_\n" and next if !/^([a-z0-9]+) (.+)$/;
+ die("Unrecognized line: $_\n"), next if !/^([a-z0-9]+) (.+)$/;
my($state, @desc) = ($1, split / *; */, $2);
die "State '$state' specified more than once.\n" if $states{$state};
$states{$state} = gencode $state, @desc;
diff --git a/yxml.c b/yxml.c
index 04dcd95..282b478 100644
--- a/yxml.c
+++ b/yxml.c
@@ -147,21 +147,21 @@ static void yxml_setutf8(char *dest, unsigned ch) {
}
-static inline int yxml_datacontent(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_datacontent(yxml_t *x, unsigned ch) {
yxml_setchar(x->data, ch);
x->data[1] = 0;
return YXML_CONTENT;
}
-static inline int yxml_datapi1(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_datapi1(yxml_t *x, unsigned ch) {
yxml_setchar(x->data, ch);
x->data[1] = 0;
return YXML_PICONTENT;
}
-static inline int yxml_datapi2(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_datapi2(yxml_t *x, unsigned ch) {
x->data[0] = '?';
yxml_setchar(x->data+1, ch);
x->data[2] = 0;
@@ -169,7 +169,7 @@ static inline int yxml_datapi2(yxml_t *x, unsigned ch) {
}
-static inline int yxml_datacd1(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_datacd1(yxml_t *x, unsigned ch) {
x->data[0] = ']';
yxml_setchar(x->data+1, ch);
x->data[2] = 0;
@@ -177,7 +177,7 @@ static inline int yxml_datacd1(yxml_t *x, unsigned ch) {
}
-static inline int yxml_datacd2(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_datacd2(yxml_t *x, unsigned ch) {
x->data[0] = ']';
x->data[1] = ']';
yxml_setchar(x->data+2, ch);
@@ -186,7 +186,7 @@ static inline int yxml_datacd2(yxml_t *x, unsigned ch) {
}
-static inline int yxml_dataattr(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_dataattr(yxml_t *x, unsigned ch) {
/* Normalize attribute values according to the XML spec section 3.3.3. */
yxml_setchar(x->data, ch == 0x9 || ch == 0xa ? 0x20 : ch);
x->data[1] = 0;
@@ -194,7 +194,7 @@ static inline int yxml_dataattr(yxml_t *x, unsigned ch) {
}
-static int yxml_pushstack(yxml_t *x, char **res, unsigned ch) {
+static yxml_ret_t yxml_pushstack(yxml_t *x, char **res, unsigned ch) {
if(x->stacklen+2 >= x->stacksize)
return YXML_ESTACK;
x->stacklen++;
@@ -206,7 +206,7 @@ static int yxml_pushstack(yxml_t *x, char **res, unsigned ch) {
}
-static int yxml_pushstackc(yxml_t *x, unsigned ch) {
+static yxml_ret_t yxml_pushstackc(yxml_t *x, unsigned ch) {
if(x->stacklen+1 >= x->stacksize)
return YXML_ESTACK;
x->stack[x->stacklen] = ch;
@@ -223,14 +223,14 @@ static void yxml_popstack(yxml_t *x) {
}
-static inline int yxml_elemstart (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->elem, ch); }
-static inline int yxml_elemname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
-static inline int yxml_elemnameend(yxml_t *x, unsigned ch) { return YXML_ELEMSTART; }
+static inline yxml_ret_t yxml_elemstart (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->elem, ch); }
+static inline yxml_ret_t yxml_elemname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
+static inline yxml_ret_t yxml_elemnameend(yxml_t *x, unsigned ch) { return YXML_ELEMSTART; }
/* Also used in yxml_elemcloseend(), since this function just removes the last
* element from the stack and returns ELEMEND. */
-static int yxml_selfclose(yxml_t *x, unsigned ch) {
+static yxml_ret_t yxml_selfclose(yxml_t *x, unsigned ch) {
yxml_popstack(x);
if(x->stacklen) {
x->elem = (char *)x->stack+x->stacklen-1;
@@ -244,7 +244,7 @@ static int yxml_selfclose(yxml_t *x, unsigned ch) {
}
-static inline int yxml_elemclose(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_elemclose(yxml_t *x, unsigned ch) {
if(*((unsigned char *)x->elem) != ch)
return YXML_ECLOSE;
x->elem++;
@@ -252,36 +252,36 @@ static inline int yxml_elemclose(yxml_t *x, unsigned ch) {
}
-static inline int yxml_elemcloseend(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_elemcloseend(yxml_t *x, unsigned ch) {
if(*x->elem)
return YXML_ECLOSE;
return yxml_selfclose(x, ch);
}
-static inline int yxml_attrstart (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->attr, ch); }
-static inline int yxml_attrname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
-static inline int yxml_attrnameend(yxml_t *x, unsigned ch) { return YXML_ATTRSTART; }
-static inline int yxml_attrvalend (yxml_t *x, unsigned ch) { yxml_popstack(x); return YXML_ATTREND; }
+static inline yxml_ret_t yxml_attrstart (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->attr, ch); }
+static inline yxml_ret_t yxml_attrname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
+static inline yxml_ret_t yxml_attrnameend(yxml_t *x, unsigned ch) { return YXML_ATTRSTART; }
+static inline yxml_ret_t yxml_attrvalend (yxml_t *x, unsigned ch) { yxml_popstack(x); return YXML_ATTREND; }
-static inline int yxml_pistart (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->pi, ch); }
-static inline int yxml_piname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
-static inline int yxml_piabort (yxml_t *x, unsigned ch) { yxml_popstack(x); return YXML_OK; }
-static inline int yxml_pinameend(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_pistart (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->pi, ch); }
+static inline yxml_ret_t yxml_piname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
+static inline yxml_ret_t yxml_piabort (yxml_t *x, unsigned ch) { yxml_popstack(x); return YXML_OK; }
+static inline yxml_ret_t yxml_pinameend(yxml_t *x, unsigned ch) {
return (x->pi[0]|32) == 'x' && (x->pi[1]|32) == 'm' && (x->pi[2]|32) == 'l' && !x->pi[3] ? YXML_ESYN : YXML_PISTART;
}
-static inline int yxml_pivalend (yxml_t *x, unsigned ch) { yxml_popstack(x); x->pi = (char *)x->stack; return YXML_PIEND; }
+static inline yxml_ret_t yxml_pivalend (yxml_t *x, unsigned ch) { yxml_popstack(x); x->pi = (char *)x->stack; return YXML_PIEND; }
-static inline int yxml_refstart(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_refstart(yxml_t *x, unsigned ch) {
memset(x->data, 0, sizeof(x->data));
x->reflen = 0;
return YXML_OK;
}
-static int yxml_ref(yxml_t *x, unsigned ch) {
+static yxml_ret_t yxml_ref(yxml_t *x, unsigned ch) {
if(x->reflen >= sizeof(x->data)-1)
return YXML_EREF;
yxml_setchar(x->data+x->reflen, ch);
@@ -290,7 +290,7 @@ static int yxml_ref(yxml_t *x, unsigned ch) {
}
-static int yxml_refend(yxml_t *x, int ret) {
+static yxml_ret_t yxml_refend(yxml_t *x, yxml_ret_t ret) {
unsigned char *r = (unsigned char *)x->data;
unsigned ch = 0;
if(*r == '#') {
@@ -320,8 +320,8 @@ static int yxml_refend(yxml_t *x, int ret) {
}
-static inline int yxml_refcontent(yxml_t *x, unsigned ch) { return yxml_refend(x, YXML_CONTENT); }
-static inline int yxml_refattrval(yxml_t *x, unsigned ch) { return yxml_refend(x, YXML_ATTRVAL); }
+static inline yxml_ret_t yxml_refcontent(yxml_t *x, unsigned ch) { return yxml_refend(x, YXML_CONTENT); }
+static inline yxml_ret_t yxml_refattrval(yxml_t *x, unsigned ch) { return yxml_refend(x, YXML_ATTRVAL); }
void yxml_init(yxml_t *x, void *stack, size_t stacksize) {
diff --git a/yxml.c.in b/yxml.c.in
index 3ce0b0f..ab89b16 100644
--- a/yxml.c.in
+++ b/yxml.c.in
@@ -81,21 +81,21 @@ static void yxml_setutf8(char *dest, unsigned ch) {
}
-static inline int yxml_datacontent(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_datacontent(yxml_t *x, unsigned ch) {
yxml_setchar(x->data, ch);
x->data[1] = 0;
return YXML_CONTENT;
}
-static inline int yxml_datapi1(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_datapi1(yxml_t *x, unsigned ch) {
yxml_setchar(x->data, ch);
x->data[1] = 0;
return YXML_PICONTENT;
}
-static inline int yxml_datapi2(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_datapi2(yxml_t *x, unsigned ch) {
x->data[0] = '?';
yxml_setchar(x->data+1, ch);
x->data[2] = 0;
@@ -103,7 +103,7 @@ static inline int yxml_datapi2(yxml_t *x, unsigned ch) {
}
-static inline int yxml_datacd1(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_datacd1(yxml_t *x, unsigned ch) {
x->data[0] = ']';
yxml_setchar(x->data+1, ch);
x->data[2] = 0;
@@ -111,7 +111,7 @@ static inline int yxml_datacd1(yxml_t *x, unsigned ch) {
}
-static inline int yxml_datacd2(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_datacd2(yxml_t *x, unsigned ch) {
x->data[0] = ']';
x->data[1] = ']';
yxml_setchar(x->data+2, ch);
@@ -120,7 +120,7 @@ static inline int yxml_datacd2(yxml_t *x, unsigned ch) {
}
-static inline int yxml_dataattr(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_dataattr(yxml_t *x, unsigned ch) {
/* Normalize attribute values according to the XML spec section 3.3.3. */
yxml_setchar(x->data, ch == 0x9 || ch == 0xa ? 0x20 : ch);
x->data[1] = 0;
@@ -128,7 +128,7 @@ static inline int yxml_dataattr(yxml_t *x, unsigned ch) {
}
-static int yxml_pushstack(yxml_t *x, char **res, unsigned ch) {
+static yxml_ret_t yxml_pushstack(yxml_t *x, char **res, unsigned ch) {
if(x->stacklen+2 >= x->stacksize)
return YXML_ESTACK;
x->stacklen++;
@@ -140,7 +140,7 @@ static int yxml_pushstack(yxml_t *x, char **res, unsigned ch) {
}
-static int yxml_pushstackc(yxml_t *x, unsigned ch) {
+static yxml_ret_t yxml_pushstackc(yxml_t *x, unsigned ch) {
if(x->stacklen+1 >= x->stacksize)
return YXML_ESTACK;
x->stack[x->stacklen] = ch;
@@ -157,14 +157,14 @@ static void yxml_popstack(yxml_t *x) {
}
-static inline int yxml_elemstart (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->elem, ch); }
-static inline int yxml_elemname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
-static inline int yxml_elemnameend(yxml_t *x, unsigned ch) { return YXML_ELEMSTART; }
+static inline yxml_ret_t yxml_elemstart (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->elem, ch); }
+static inline yxml_ret_t yxml_elemname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
+static inline yxml_ret_t yxml_elemnameend(yxml_t *x, unsigned ch) { return YXML_ELEMSTART; }
/* Also used in yxml_elemcloseend(), since this function just removes the last
* element from the stack and returns ELEMEND. */
-static int yxml_selfclose(yxml_t *x, unsigned ch) {
+static yxml_ret_t yxml_selfclose(yxml_t *x, unsigned ch) {
yxml_popstack(x);
if(x->stacklen) {
x->elem = (char *)x->stack+x->stacklen-1;
@@ -178,7 +178,7 @@ static int yxml_selfclose(yxml_t *x, unsigned ch) {
}
-static inline int yxml_elemclose(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_elemclose(yxml_t *x, unsigned ch) {
if(*((unsigned char *)x->elem) != ch)
return YXML_ECLOSE;
x->elem++;
@@ -186,36 +186,36 @@ static inline int yxml_elemclose(yxml_t *x, unsigned ch) {
}
-static inline int yxml_elemcloseend(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_elemcloseend(yxml_t *x, unsigned ch) {
if(*x->elem)
return YXML_ECLOSE;
return yxml_selfclose(x, ch);
}
-static inline int yxml_attrstart (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->attr, ch); }
-static inline int yxml_attrname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
-static inline int yxml_attrnameend(yxml_t *x, unsigned ch) { return YXML_ATTRSTART; }
-static inline int yxml_attrvalend (yxml_t *x, unsigned ch) { yxml_popstack(x); return YXML_ATTREND; }
+static inline yxml_ret_t yxml_attrstart (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->attr, ch); }
+static inline yxml_ret_t yxml_attrname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
+static inline yxml_ret_t yxml_attrnameend(yxml_t *x, unsigned ch) { return YXML_ATTRSTART; }
+static inline yxml_ret_t yxml_attrvalend (yxml_t *x, unsigned ch) { yxml_popstack(x); return YXML_ATTREND; }
-static inline int yxml_pistart (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->pi, ch); }
-static inline int yxml_piname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
-static inline int yxml_piabort (yxml_t *x, unsigned ch) { yxml_popstack(x); return YXML_OK; }
-static inline int yxml_pinameend(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_pistart (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->pi, ch); }
+static inline yxml_ret_t yxml_piname (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
+static inline yxml_ret_t yxml_piabort (yxml_t *x, unsigned ch) { yxml_popstack(x); return YXML_OK; }
+static inline yxml_ret_t yxml_pinameend(yxml_t *x, unsigned ch) {
return (x->pi[0]|32) == 'x' && (x->pi[1]|32) == 'm' && (x->pi[2]|32) == 'l' && !x->pi[3] ? YXML_ESYN : YXML_PISTART;
}
-static inline int yxml_pivalend (yxml_t *x, unsigned ch) { yxml_popstack(x); x->pi = (char *)x->stack; return YXML_PIEND; }
+static inline yxml_ret_t yxml_pivalend (yxml_t *x, unsigned ch) { yxml_popstack(x); x->pi = (char *)x->stack; return YXML_PIEND; }
-static inline int yxml_refstart(yxml_t *x, unsigned ch) {
+static inline yxml_ret_t yxml_refstart(yxml_t *x, unsigned ch) {
memset(x->data, 0, sizeof(x->data));
x->reflen = 0;
return YXML_OK;
}
-static int yxml_ref(yxml_t *x, unsigned ch) {
+static yxml_ret_t yxml_ref(yxml_t *x, unsigned ch) {
if(x->reflen >= sizeof(x->data)-1)
return YXML_EREF;
yxml_setchar(x->data+x->reflen, ch);
@@ -224,7 +224,7 @@ static int yxml_ref(yxml_t *x, unsigned ch) {
}
-static int yxml_refend(yxml_t *x, int ret) {
+static yxml_ret_t yxml_refend(yxml_t *x, yxml_ret_t ret) {
unsigned char *r = (unsigned char *)x->data;
unsigned ch = 0;
if(*r == '#') {
@@ -254,8 +254,8 @@ static int yxml_refend(yxml_t *x, int ret) {
}
-static inline int yxml_refcontent(yxml_t *x, unsigned ch) { return yxml_refend(x, YXML_CONTENT); }
-static inline int yxml_refattrval(yxml_t *x, unsigned ch) { return yxml_refend(x, YXML_ATTRVAL); }
+static inline yxml_ret_t yxml_refcontent(yxml_t *x, unsigned ch) { return yxml_refend(x, YXML_CONTENT); }
+static inline yxml_ret_t yxml_refattrval(yxml_t *x, unsigned ch) { return yxml_refend(x, YXML_ATTRVAL); }
void yxml_init(yxml_t *x, void *stack, size_t stacksize) {