#include <glib/gstdio.h>
#include <sqlite3.h>
#include <expat.h>
+#include <bzlib.h>
#include "osm.h"
#include "latlon.h"
gint wsegcnt;
-node *osm_find_node(guint32 nid);
+inline node *osm_find_node(guint32 nid);
void osm_free_way_data(way *w);
void print_way(way *w);
gboolean db_open(void);
/********************************************************************/
-void dump_array(const gchar **p)
-{
-char **d;
-
-d=p;
-while (*d!=NULL) {
- g_printf("[%s]", *d);
- d++;
-}
-g_print("\n");
-}
-
gchar *get_attr_key_value(const gchar **p, gchar *key)
{
char **d;
/********************************************************************/
static void
-print_node (node *n)
+node_print (node *n)
{
g_assert(n);
if (n->data) {
g_printf("N: %d [%f:%f]\n",
n->id, n->lat, n->lon);
}
+}
+
+#ifdef DEBUG
+static void
+dump_array(const gchar **p)
+{
+char **d;
+d=p;
+while (*d!=NULL) {
+ g_printf("[%s]", *d);
+ d++;
+}
+g_print("\n");
}
+#endif
static inline gboolean
osm_node_check_box(gdouble nlat, gdouble nlon)
void
osm_free_node_data(node *n)
{
+g_assert(n);
+g_assert(n->data);
if (n->data->name)
g_free(n->data->name);
g_slice_free(node_data, n->data);
static void
print_segment(segment *s)
{
+g_assert(s);
g_printf("Segment %d %d-%d:\n", s->id, s->from, s->to);
}
void
print_way(way *w)
{
+g_assert(w);
g_printf("Way #%d(%d/%d): %s [%s:%s:%s]\n",
w->id,
g_slist_length(w->nodes),
storage_free();
}
+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;
+}
+
gboolean
osm_planet_parse_file(gchar *pfile)
{
-int f, r;
+FILE *f;
+BZFILE *b;
+int bzerror;
+int r;
gchar buffer[FILE_BUFFER];
gboolean res=TRUE;
-f=open(pfile, O_RDONLY);
-if (f==-1) return FALSE;
+f=fopen(pfile, "r");
+if (!f)
+ return FALSE;
+
+b=BZ2_bzReadOpen(&bzerror, f, 0, 0, NULL, 0);
+if (bzerror != BZ_OK) {
+ BZ2_bzReadClose(&bzerror, b);
+ return FALSE;
+}
do {
- r=read(f, buffer, FILE_BUFFER);
- 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)));
+ r=BZ2_bzRead(&bzerror, b, buffer, FILE_BUFFER);
+ if ((bzerror!=BZ_STREAM_END) && (bzerror!=BZ_OK)) {
res=FALSE;
- goto end;
+ break;
}
-} while (r>0);
-
-end:;
+ if (!osm_planet_parse_buffer(buffer, r)) {
+ res=FALSE;
+ break;
+ }
+} while (bzerror==BZ_OK);
-close(f);
+BZ2_bzReadClose(&bzerror, b);
+fclose(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
int main (int argc, char **argv)
{
if (argc<2) {
- return print_fail("No planet XML file given", 1);
+ return print_fail("Give bzip2 compressed planet XML file as argument", 1);
} else {
g_printf("Using file: %s\n", argv[1]);
}
if (argc==6) {
use_bbox=TRUE;
-
bbox.lat_min=atof(argv[2]);
bbox.lon_min=atof(argv[3]);
bbox.lat_max=atof(argv[4]);