From: Kaj-Michael Lang Date: Fri, 27 Jul 2007 12:04:25 +0000 (+0300) Subject: Preparations for integration to Mapper itself. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=501264b847acb9f93563f230ef50ff1718614de2;p=mapper Preparations for integration to Mapper itself. Move xml parse init to it's own function. Add function to free parser. Add function to parse a given buffer. (for parsing while downloading). --- diff --git a/src/osm.c b/src/osm.c index 913759e..ce5b1bb 100644 --- a/src/osm.c +++ b/src/osm.c @@ -29,6 +29,8 @@ static gint dbnode_cnt=0; static gint dbnoded_cnt=0; static gint dbway_cnt=0; +static XML_Parser xp; + typedef struct _node_data node_data; struct _node_data { gchar *name; @@ -1170,18 +1172,28 @@ switch (t) { /************************************************************************/ -gint osm_planet_parse_file(gchar *pfile) +gboolean +osm_planet_parse_init(void) +{ +xp=XML_ParserCreate(NULL); +XML_SetElementHandler(xp, _osm_tag_start, _osm_tag_end); +} + +void +osm_planet_parse_deinit(void) +{ +XML_ParserFree(xp); +} + +gboolean +osm_planet_parse_file(gchar *pfile) { -int f, r, res; +int f, r; gchar buffer[FILE_BUFFER]; -XML_Parser xp; +gboolean res=TRUE; f=open(pfile, O_RDONLY); -if (f==-1) return 1; -res=0; - -xp=XML_ParserCreate(NULL); -XML_SetElementHandler(xp, _osm_tag_start, _osm_tag_end); +if (f==-1) return FALSE; do { r=read(f, buffer, FILE_BUFFER); @@ -1189,7 +1201,7 @@ do { g_printerr("Parse error at line %d:\n%s\n", XML_GetCurrentLineNumber(xp), XML_ErrorString(XML_GetErrorCode(xp))); - res=2; + res=FALSE; goto end; } } while (r>0); @@ -1200,6 +1212,19 @@ close(f); return res; } +gboolean +osm_planet_parse_buffer(gchar *buffer, size_t r) +{ +if (XML_Parse(xp, buffer, r, r>0 ? 0:1) == XML_STATUS_ERROR) { + g_printerr("Parse error at line %d:\n%s\n", + XML_GetCurrentLineNumber(xp), + XML_ErrorString(XML_GetErrorCode(xp))); + return FALSE; +} + +return TRUE; +} + /************************************************************************/ static gint @@ -1281,7 +1306,9 @@ print_memory_usage(); storage_init(); +osm_planet_parse_init(); osm_planet_parse_file(argv[1]); +osm_planet_parse_deinit(); g_printf("Planet loaded.\nTotal nodes %d, POIs: %d, Segments %d and Ways %d.\n", node_cnt, noded_cnt, seg_cnt, way_cnt);