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;
/************************************************************************/
-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);
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);
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
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);