X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=sherlock%2Fxml%2Fcommon.c;h=aca3435395caba5d612254bd75c286d9e8ef5d05;hb=7462f9e27978542b37e1745b9a8fa80fb07dab3d;hp=d3155ed8082c933748700ebeb162bba6c8e7593c;hpb=da05d6244dd826a76a5cacfa6dcd77dc9fd0c28e;p=libucw.git diff --git a/sherlock/xml/common.c b/sherlock/xml/common.c index d3155ed8..aca34353 100644 --- a/sherlock/xml/common.c +++ b/sherlock/xml/common.c @@ -12,7 +12,7 @@ #include "sherlock/sherlock.h" #include "sherlock/xml/xml.h" #include "sherlock/xml/dtd.h" -#include "sherlock/xml/common.h" +#include "sherlock/xml/internals.h" #include "lib/stkstring.h" #include "lib/ff-unicode.h" @@ -83,56 +83,29 @@ xml_hash_new(struct mempool *pool, uns size) return tab + XML_HASH_HDR_SIZE; } -static void -xml_chars_spout(struct fastbuf *fb) -{ - if (fb->bptr >= fb->bufend) - { - struct xml_context *ctx = SKIP_BACK(struct xml_context, chars, fb); - struct mempool *pool = ctx->pool; - if (fb->bufend != fb->buffer) - { - uns len = fb->bufend - fb->buffer; - TRACE(ctx, "grow_chars"); - fb->buffer = mp_expand(pool); - fb->bufend = fb->buffer + mp_avail(pool); - fb->bstop = fb->buffer; - fb->bptr = fb->buffer + len; - } - else - { - TRACE(ctx, "push_chars"); - struct xml_node *n = xml_push_dom(ctx); - n->type = XML_NODE_CHARS; - xml_start_chars(ctx); - } - } -} - -static void -xml_init_chars(struct xml_context *ctx) -{ - struct fastbuf *fb = &ctx->chars; - fb->name = ""; - fb->spout = xml_chars_spout; - fb->can_overwrite_buffer = 1; - fb->bptr = fb->bstop = fb->buffer = fb->bufend = NULL; -} - /*** Initialization ***/ +static struct xml_context xml_defaults = { + .flags = XML_SRC_EOF | XML_REPORT_ALL, + .state = XML_STATE_START, + .h_resolve_entity = xml_def_resolve_entity, + .chars = { + .name = "", + .spout = xml_spout_chars, + .can_overwrite_buffer = 1, + }, +}; + static void xml_do_init(struct xml_context *ctx) { - ctx->flags = XML_REPORT_ALL; - xml_init_chars(ctx); xml_attrs_table_init(ctx); } void xml_init(struct xml_context *ctx) { - bzero(ctx, sizeof(*ctx)); + *ctx = xml_defaults; ctx->pool = mp_new(65536); ctx->stack = mp_new(65536); xml_do_init(ctx); @@ -160,7 +133,7 @@ xml_reset(struct xml_context *ctx) xml_sources_cleanup(ctx); mp_flush(pool); mp_flush(stack); - bzero(ctx, sizeof(*ctx)); + *ctx = xml_defaults; ctx->pool = pool; ctx->stack = stack; xml_do_init(ctx);