/*
* Hic Est Leo -- OSM XML Parser
*
- * (c) 2014 Martin Mares <mj@ucw.cz>
+ * (c) 2014--2015 Martin Mares <mj@ucw.cz>
*/
-#include <ucw/lib.h>
+#undef LOCAL_DEBUG
+
+#include "leo.h"
+#include "osm.h"
+
#include <ucw/fastbuf.h>
-#include <xml/xml.h>
+#include <ucw-xml/xml.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
-#include "leo.h"
-#include "osm.h"
-
static void parse_tag(struct xml_context *ctx, struct osm_object *o, struct xml_node *t)
{
char *tag_k = xml_attr_value(ctx, t, "k");
static void parse_element(struct xml_context *ctx, struct xml_node *e)
{
+ // JOSM marks deleted, but not uploaded, objects
+ char *action = xml_attr_value(ctx, e, "action");
+ if (action && !strcmp(action, "delete"))
+ return;
+
if (!strcmp(e->name, "node"))
parse_node(ctx, e);
else if (!strcmp(e->name, "way"))
void osm_xml_parse(const char *name)
{
- struct xml_context ctx;
- xml_init(&ctx);
- ctx.h_warn = ctx.h_error = ctx.h_fatal = h_error;
- xml_push_fastbuf(&ctx, bopen_file(name, O_RDONLY, NULL));
+ struct xml_context xml_ctx, *ctx = &xml_ctx;
+ xml_init(ctx);
+ ctx->h_warn = ctx->h_error = ctx->h_fatal = h_error;
+ xml_push_fastbuf(ctx, bopen_file(name, O_RDONLY, NULL));
uint state;
- while (state = xml_next_state(&ctx, XML_PULL_STAG))
- switch (state)
+ while (state = xml_next_state(ctx, XML_PULL_STAG))
+ if (state == XML_STATE_STAG)
{
- case XML_STATE_STAG:
- // printf("STAG %s\n", ctx.node->name);
- if (strcmp(ctx.node->name, "osm"))
+ DBG("Level 1 tag <%s>", ctx->node->name);
+ if (!strcmp(ctx->node->name, "osm"))
{
- ctx.flags |= XML_ALLOC_CHARS | XML_ALLOC_TAGS;
- if (xml_skip_element(&ctx) == XML_STATE_ETAG)
+ DBG("Switched to level 2");
+ while ((state = xml_next_state(ctx, XML_PULL_STAG | XML_PULL_ETAG)) == XML_STATE_STAG)
{
- // printf("ETAG %s\n", ctx.node->name);
- parse_element(&ctx, ctx.node);
+ ctx->flags |= XML_ALLOC_CHARS | XML_ALLOC_TAGS;
+ if (xml_skip_element(ctx) == XML_STATE_ETAG)
+ {
+ DBG("Level 2 tag <%s>", ctx->node->name);
+ parse_element(ctx, ctx->node);
+ }
}
+ DBG("Exited level 2 in state %u", state);
}
+ else
+ xml_skip_element(ctx);
}
- if (ctx.err_code)
+ if (ctx->err_code)
die("Fatal error in XML parser");
- xml_cleanup(&ctx);
+ xml_cleanup(ctx);
}