/*** Basic parsing ***/
void NONRET
-xml_fatal_expected(struct xml_context *ctx, uns c)
+xml_fatal_expected(struct xml_context *ctx, uint c)
{
if (c >= 32 && c < 128)
xml_fatal(ctx, "Expected '%c'", c);
/*** Names and nmtokens ***/
static char *
-xml_parse_string(struct xml_context *ctx, struct mempool *pool, uns first_cat, uns next_cat, char *err)
+xml_parse_string(struct xml_context *ctx, struct mempool *pool, uint first_cat, uint next_cat, char *err)
{
char *p = mp_start_noalign(pool, 1);
if (unlikely(!(xml_peek_cat(ctx) & first_cat)))
}
static void
-xml_skip_string(struct xml_context *ctx, uns first_cat, uns next_cat, char *err)
+xml_skip_string(struct xml_context *ctx, uint first_cat, uint next_cat, char *err)
{
if (unlikely(!(xml_get_cat(ctx) & first_cat)))
xml_fatal(ctx, "%s", err);
{
/* SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'") */
char *p = mp_start_noalign(pool, 1);
- uns q = xml_parse_quote(ctx), c;
+ uint q = xml_parse_quote(ctx), c;
while ((c = xml_get_char(ctx)) != q)
{
p = mp_spread(pool, p, 5);
{
/* PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'" */
char *p = mp_start_noalign(pool, 1);
- uns q = xml_parse_quote(ctx), c;
+ uint q = xml_parse_quote(ctx), c;
while ((c = xml_get_char(ctx)) != q)
{
if (unlikely(!(xml_last_cat(ctx) & XML_CHAR_PUBID)))
/*** Character references ***/
-uns
+uint
xml_parse_char_ref(struct xml_context *ctx)
{
TRACE(ctx, "parse_char_ref");
/* CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'
* Already parsed: '&#' */
- uns v = 0;
+ uint v = 0;
if (xml_get_char(ctx) == 'x')
{
if (!(xml_get_cat(ctx) & XML_CHAR_XDIGIT))
}
while (v < 0x110000 && (xml_get_cat(ctx) & XML_CHAR_DIGIT));
}
- uns cat = xml_char_cat(v);
+ uint cat = xml_char_cat(v);
if (!(cat & ctx->cat_unrestricted))
{
xml_error(ctx, "Character reference out of range");
if (fb->bufend != fb->buffer)
{
TRACE(ctx, "growing chars");
- uns len = fb->bufend - fb->buffer;
- uns reported = fb->bstop - fb->buffer;
+ uint len = fb->bufend - fb->buffer;
+ uint reported = fb->bstop - fb->buffer;
fb->buffer = mp_expand(pool);
fb->bufend = fb->buffer + mp_avail(pool);
fb->bptr = fb->buffer + len;
}
}
-static inline uns
+static inline uint
xml_end_chars(struct xml_context *ctx, char **out)
{
struct fastbuf *fb = &ctx->chars;
- uns len = fb->bptr - fb->buffer;
+ uint len = fb->bptr - fb->buffer;
if (len)
{
TRACE(ctx, "ending chars");
return len;
}
-static inline uns
+static inline uint
xml_report_chars(struct xml_context *ctx, char **out)
{
struct fastbuf *fb = &ctx->chars;
- uns len = fb->bptr - fb->buffer;
+ uint len = fb->bptr - fb->buffer;
if (len)
{
*fb->bptr = 0;
return len;
}
-static inline uns
+static inline uint
xml_flush_chars(struct xml_context *ctx)
{
char *text, *rtext;
- uns len = xml_end_chars(ctx, &text), rlen;
+ uint len = xml_end_chars(ctx, &text), rlen;
if (len)
{
if (ctx->flags & XML_NO_CHARS)
}
xml_parse_seq(ctx, "CDATA[");
struct fastbuf *out = &ctx->chars;
- uns rlen;
+ uint rlen;
char *rtext;
if ((ctx->flags & XML_REPORT_CHARS) && ctx->h_block && (rlen = xml_report_chars(ctx, &rtext)))
ctx->h_block(ctx, rtext, rlen);
/* AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'" */
/* FIXME: -- check value constrains / normalize leading/trailing WS and repeated WS */
struct mempool_state state;
- uns quote = xml_parse_quote(ctx);
+ uint quote = xml_parse_quote(ctx);
mp_save(ctx->stack, &state);
struct fastbuf *out = &ctx->chars;
struct xml_source *src = ctx->src;
while (1)
{
- uns c = xml_get_char(ctx);
+ uint c = xml_get_char(ctx);
if (c == '&')
{
xml_inc(ctx);
return xml_end_chars(ctx, &text) ? text : "";
}
-uns
+uint
xml_normalize_white(struct xml_context *ctx UNUSED, char *text)
{
char *s = text, *d = text;
struct xml_attrs_table;
-static inline uns
+static inline uint
xml_attrs_hash(struct xml_attrs_table *t UNUSED, struct xml_node *e, char *n)
{
return hash_pointer(e) ^ hash_string(n);
/*** Elements ***/
-static uns
+static uint
xml_validate_element(struct xml_dtd_elem_node *root, struct xml_dtd_elem *elem)
{
if (root->elem)
}
while (1)
{
- uns white = xml_parse_white(ctx, 0);
- uns c = xml_get_char(ctx);
+ uint white = xml_parse_white(ctx, 0);
+ uint c = xml_get_char(ctx);
if (c == '/')
{
xml_parse_char(ctx, '>');
if ((ctx->flags & XML_REPORT_TAGS) && ctx->h_etag)
ctx->h_etag(ctx);
struct xml_node *e = ctx->node;
- uns free = !(ctx->flags & XML_ALLOC_TAGS);
+ uint free = !(ctx->flags & XML_ALLOC_TAGS);
if (free)
{
if (!e->parent)
char *n = e->name;
while (*n)
{
- uns c;
+ uint c;
n = utf8_32_get(n, &c);
if (xml_get_char(ctx) != c)
goto recover;
xml_parse_white(ctx, 1);
ctx->doctype = xml_parse_name(ctx, ctx->pool);
TRACE(ctx, "doctype=%s", ctx->doctype);
- uns c;
+ uint c;
if (xml_parse_white(ctx, 0) && ((c = xml_peek_char(ctx)) == 'S' || c == 'P'))
{
if (c == 'S')
/* DTD: Internal subset */
static void
-xml_parse_subset(struct xml_context *ctx, uns external)
+xml_parse_subset(struct xml_context *ctx, uint external)
{
// FIXME:
// -- comments/pi have no parent
while (1)
{
xml_parse_white(ctx, 0);
- uns c = xml_get_char(ctx);
+ uint c = xml_get_char(ctx);
xml_inc(ctx);
if (c == '<')
if ((c = xml_get_char(ctx)) == '!')
/*** The State Machine ***/
-uns
+uint
xml_next(struct xml_context *ctx)
{
/* A nasty state machine */
TRACE(ctx, "raised fatal error");
return ctx->state = XML_STATE_EOF;
}
- uns c;
+ uint c;
switch (ctx->state)
{
case XML_STATE_START:
ASSERT(0);
}
-uns
-xml_next_state(struct xml_context *ctx, uns pull)
+uint
+xml_next_state(struct xml_context *ctx, uint pull)
{
- uns saved = ctx->pull;
+ uint saved = ctx->pull;
ctx->pull = pull;
- uns res = xml_next(ctx);
+ uint res = xml_next(ctx);
ctx->pull = saved;
return res;
}
-uns
+uint
xml_skip_element(struct xml_context *ctx)
{
ASSERT(ctx->state == XML_STATE_STAG);
struct xml_node *node = ctx->node;
- uns saved = ctx->pull, res;
+ uint saved = ctx->pull, res;
ctx->pull = XML_PULL_ETAG;
while ((res = xml_next(ctx)) && ctx->node != node);
ctx->pull = saved;
return res;
}
-uns
+uint
xml_parse(struct xml_context *ctx)
{
/* This cycle should run only once unless the user overrides the value of ctx->pull in a SAX handler */