int map_collect_data_osm(FILE *in, struct maptool_osm *osm) { int size=BUFFER_SIZE; char buffer[BUFFER_SIZE]; char *p; sig_alrm(0); if (!fgets(buffer, size, in) || !xml_declaration_in_line(buffer)){ fprintf(stderr,"FATAL: First line does not start with XML declaration;\n" "this does not look like a valid OSM file.\n"); exit(EXIT_FAILURE); } while (fgets(buffer, size, in)) { p=strchr(buffer,'<'); if (! p) { fprintf(stderr,"FATAL: wrong line in input data (does not start with '<'): %s\n", buffer); fprintf(stderr,"This does not look like a valid OSM file.\n" "Note that maptool can only process OSM files without wrapped or empty lines.\n"); exit(EXIT_FAILURE); } if (!strncmp(p, "<osm ",5)) { } else if (!strncmp(p, "<bound ",7)) { } else if (!strncmp(p, "<node ",6)) { if (!parse_node(p)) fprintf(stderr,"WARNING: failed to parse %s\n", buffer); processed_nodes++; } else if (!strncmp(p, "<tag ",5)) { if (!parse_tag(p)) fprintf(stderr,"WARNING: failed to parse %s\n", buffer); } else if (!strncmp(p, "<way ",5)) { if (!parse_way(p)) fprintf(stderr,"WARNING: failed to parse %s\n", buffer); processed_ways++; } else if (!strncmp(p, "<nd ",4)) { if (!parse_nd(p)) fprintf(stderr,"WARNING: failed to parse %s\n", buffer); } else if (!strncmp(p, "<relation ",10)) { if (!parse_relation(p)) fprintf(stderr,"WARNING: failed to parse %s\n", buffer); processed_relations++; } else if (!strncmp(p, "<member ",8)) { if (!parse_member(p)) fprintf(stderr,"WARNING: failed to parse %s\n", buffer); } else if (!strncmp(p, "</node>",7)) { osm_end_node(osm); } else if (!strncmp(p, "</way>",6)) { osm_end_way(osm); } else if (!strncmp(p, "</relation>",11)) { osm_end_relation(osm); } else if (!strncmp(p, "</osm>",6)) { } else { fprintf(stderr,"WARNING: unknown tag in %s\n", buffer); } } sig_alrm(0); sig_alrm_end(); return 1; }
/** * maps_osm_parse: * @content: XML data * @length: Length of data * @error: Error handle * Returns: (transfer full): A MapsOSMObject */ MapsOSMObject * maps_osm_parse (const char *content, guint length, GError **error) { xmlDocPtr doc; xmlNodePtr sub_node; MapsOSMObject *object; doc = read_xml_doc (content, length, error); if (!doc) return NULL; sub_node = get_sub_node (doc); if (!sub_node) { *error = g_error_new_literal (MAPS_OSM_ERROR, 0, _("Could not find OSM element")); return NULL; } if (g_str_equal (sub_node->name, "node")) { object = MAPS_OSMOBJECT (parse_node (sub_node, error)); } else if (g_str_equal (sub_node->name, "way")) { object = MAPS_OSMOBJECT (parse_way (sub_node, error)); } else if (g_str_equal (sub_node->name, "relation")) { object = MAPS_OSMOBJECT (parse_relation (sub_node, error)); } xmlFreeNode (sub_node); xmlFreeDoc (doc); return object; }