Skip to content

Commit

Permalink
deps: Update yxml
Browse files Browse the repository at this point in the history
  • Loading branch information
Yorhel committed Feb 11, 2014
1 parent 23fc1ca commit 6c34137
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
23 changes: 11 additions & 12 deletions deps/yxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ typedef enum {
* this parser doesn't understand entities with '.', ':', etc, anwyay. */
#define yxml_isRef(c) (yxml_isNum(c) || yxml_isAlpha(c) || c == '#')

#define INTFROM5CHARS(a, b, c, d, e) ((((uint64_t)(a))<<32) | (((uint64_t)(b))<<24) | (((uint64_t)(c))<<16) | (((uint64_t)(d))<<8) | (uint64_t)(e))


/* Set the given char value to ch (0<=ch<=255).
* This can't be done with simple assignment because char may be signed, and
Expand Down Expand Up @@ -298,16 +300,13 @@ static int yxml_refend(yxml_t *x, int ret) {
if(*r)
ch = 0;
} else {
if(r[0] == 'l' && r[1] == 't' && !r[2])
ch = '<';
else if(r[0] == 'g' && r[1] == 't' && !r[2])
ch = '>';
else if(r[0] == 'a' && r[1] == 'm' && r[2] == 'p' && !r[3])
ch = '&';
else if(r[0] == 'a' && r[1] == 'p' && r[2] == 'o' && r[3] == 's' && !r[4])
ch = '\'';
else if(r[0] == 'q' && r[1] == 'u' && r[2] == 'o' && r[3] == 't' && !r[4])
ch = '"';
uint64_t i = INTFROM5CHARS(r[0], r[1], r[2], r[3], r[4]);
ch =
i == INTFROM5CHARS('l','t', 0, 0, 0) ? '<' :
i == INTFROM5CHARS('g','t', 0, 0, 0) ? '>' :
i == INTFROM5CHARS('a','m','p', 0, 0) ? '&' :
i == INTFROM5CHARS('a','p','o','s',0) ? '\'':
i == INTFROM5CHARS('q','u','o','t',0) ? '"' : 0;
}

/* Codepoints not allowed in the XML 1.1 definition of a Char */
Expand All @@ -322,10 +321,10 @@ static inline int yxml_refcontent(yxml_t *x, unsigned ch) { return yxml_refend(x
static inline int yxml_refattrval(yxml_t *x, unsigned ch) { return yxml_refend(x, YXML_ATTRVAL); }


void yxml_init(yxml_t *x, char *stack, size_t stacksize) {
void yxml_init(yxml_t *x, void *stack, size_t stacksize) {
memset(x, 0, sizeof(*x));
x->line = 1;
x->stack = (unsigned char *)stack;
x->stack = stack;
x->stacksize = stacksize;
*x->stack = 0;
x->elem = x->pi = (char *)x->stack;
Expand Down
21 changes: 13 additions & 8 deletions deps/yxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef YXML_H
#define YXML_H

#include <stdint.h>
#include <stddef.h>

/* Full API documentation for this library can be found in the "yxml.pod" file
* in the yxml git repository, or online at http://dev.yorhel.nl/yxml/man */

typedef enum {
YXML_EEOF = -6, /* Unexpected EOF */
YXML_EREF = -5, /* Invalid character or entity reference (&whatever;) */
YXML_ECLOSE = -4, /* Close tag does not match open tag (<Tag> .. </OtherTag>) */
YXML_ESTACK = -3, /* Stack overflow (too deeply nested tags or too long element/attribute name) */
YXML_EATTR = -2, /* Too long attribute name */
YXML_EEOF = -5, /* Unexpected EOF */
YXML_EREF = -4, /* Invalid character or entity reference (&whatever;) */
YXML_ECLOSE = -3, /* Close tag does not match open tag (<Tag> .. </OtherTag>) */
YXML_ESTACK = -2, /* Stack overflow (too deeply nested tags or too long element/attribute name) */
YXML_ESYN = -1, /* Syntax error (unexpected byte) */
YXML_OK = 0, /* Character consumed, no new token present */
YXML_ELEMSTART = 1, /* Start of an element: '<Tag ..' */
Expand Down Expand Up @@ -116,10 +120,10 @@ typedef struct {
} yxml_t;


void yxml_init(yxml_t *x, char *stack, size_t stacksize);
void yxml_init(yxml_t *, void *, size_t);


yxml_ret_t yxml_parse(yxml_t *x, int ch);
yxml_ret_t yxml_parse(yxml_t *, int);


/* May be called after the last character has been given to yxml_parse().
Expand All @@ -128,7 +132,8 @@ yxml_ret_t yxml_parse(yxml_t *x, int ch);
* that don't end correctly. In particular, an error is returned when the XML
* document did not contain a (complete) root element, or when the document
* ended while in a comment or processing instruction. */
yxml_ret_t yxml_eof(yxml_t *x);
yxml_ret_t yxml_eof(yxml_t *);

#endif

/* vim: set noet sw=4 ts=4: */

0 comments on commit 6c34137

Please sign in to comment.