From: Kaj-Michael Lang Date: Mon, 18 Feb 2008 21:59:31 +0000 (+0200) Subject: Free the way if it's not used. Add proper return values to some functions. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0239e028c405e4e323979285aa7884c9aecba76;p=mapper Free the way if it's not used. Add proper return values to some functions. Misc other changes. --- diff --git a/src/osm-db-import.c b/src/osm-db-import.c index c71c421..df9aac8 100644 --- a/src/osm-db-import.c +++ b/src/osm-db-import.c @@ -342,12 +342,12 @@ static struct sql_stmt sql; static struct map_bbox bbox; static gboolean use_bbox; -void osm_free_way_data(way *w); -void print_way(way *w); +static void osm_free_way_data(way *w); +static void print_way(way *w); -void db_prepare(sqlite3 *db); -gboolean db_insert_node(node *n); -guint32 osm_find_way_place(way *w, node_type_t nt); +static void db_prepare(sqlite3 *db); +static gboolean db_insert_node(node *n); +static guint32 osm_find_way_place(way *w, node_type_t nt); /****************************************************/ /* Functions */ @@ -583,14 +583,14 @@ return TRUE; /** * Insert way ref and int_ref */ -static void +static gboolean db_insert_way_ref(way *w) { if (!w->data) - return; + return TRUE; if (!w->data->ref && !w->data->int_ref) - return; + return TRUE; way_refs++; @@ -600,21 +600,21 @@ if (w->data->ref) if (w->data->int_ref) sqlite3_bind_text(sql.insert_way_ref, 3, w->data->int_ref, -1, SQLITE_TRANSIENT); -db_exec(db,sql.insert_way_ref); +return db_exec(db,sql.insert_way_ref); } /** * Insert way name */ -static void +static gboolean db_insert_way_name(way *w) { gchar *norm; if (!w->data) - return; + return TRUE; if (!w->data->name) - return; + return TRUE; way_names++; @@ -630,35 +630,35 @@ if (norm) g_free(norm); #endif -db_exec(db,sql.insert_way_name); +return db_exec(db,sql.insert_way_name); } -static void +static gboolean db_delete_way_names_nls(way *w) { sqlite3_bind_int(sql.delete_way_names_nls, 1, w->id); -db_exec(db,sql.delete_way_names_nls); +return db_exec(db,sql.delete_way_names_nls); } -static void +static gboolean db_insert_way_pc(way *w) { if (!w->data) - return; + return TRUE; if (!w->data->postal_code) - return; + return TRUE; sqlite3_bind_int(sql.insert_way_pc, 1, w->id); sqlite3_bind_text(sql.insert_way_pc, 2, w->data->postal_code, -1, SQLITE_TRANSIENT); -db_exec(db,sql.insert_way_pc); +return db_exec(db,sql.insert_way_pc); } -static void +static gboolean db_delete_way_pc(way *w) { sqlite3_bind_int(sql.delete_way_pc, 1, w->id); -db_exec(db,sql.delete_way_pc); +return db_exec(db,sql.delete_way_pc); } static void @@ -731,13 +731,6 @@ if (w->data) { print_way(w); -/* Get middle node, use it as way location */ -ncnt=g_slist_length(w->nodes); -if (ncnt>1) - wmn=g_slist_nth_data(w->nodes, ncnt/2); -else - wmn=0; - sqlite3_bind_int(sql.insert_way_data, 1, w->id); sqlite3_bind_int(sql.insert_way_data, 2, w->ncnt); sqlite3_bind_int(sql.insert_way_data, 3, w->type); @@ -747,11 +740,17 @@ if (w->data) { sqlite3_bind_int(sql.insert_way_data, 6, w->data->isin_c); sqlite3_bind_int(sql.insert_way_data, 7, w->data->isin_p); } -if (wmn) { - sqlite3_bind_double(sql.insert_way_data, 8, wmn->lat); - sqlite3_bind_double(sql.insert_way_data, 9, wmn->lon); -} else { - g_printerr("Failed to get way location node!\n"); + +/* Get middle node, use it as a rough way location */ +ncnt=g_slist_length(w->nodes); +if (ncnt>1) { + wmn=g_slist_nth_data(w->nodes, ncnt/2); + if (wmn) { + sqlite3_bind_double(sql.insert_way_data, 8, wmn->lat); + sqlite3_bind_double(sql.insert_way_data, 9, wmn->lon); + } else { + g_printerr("Failed to get way middlepoint node for location information!\n"); + } } db_exec(db,sql.insert_way_data); @@ -926,12 +925,7 @@ osm_find_node(guint32 nid) node *n; g_assert(osm_nodes); -n=g_hash_table_lookup(osm_nodes, GINT_TO_POINTER(nid)); -#if 0 -if (!n) - g_printerr("ERROR: Node %d not found!\n", nid); -#endif -return n; +return g_hash_table_lookup(osm_nodes, GINT_TO_POINTER(nid)); } static void @@ -986,6 +980,14 @@ w->flags=0; return w; } +static void +osm_free_way(way *w) +{ +if (w->nodes) + g_slist_free(w->nodes); +g_slice_free(way, w); +} + static void osm_way_add_to_list(way *w) { @@ -1188,7 +1190,7 @@ sqlite3_step(sql.delete_nodes); static gboolean osm_planet_save_nodes(void) { -g_print("Storing nodes\n"); +g_print("Storing nodes...\n"); db_transaction_begin(db); g_hash_table_foreach(osm_nodes, osm_node_save_node, NULL); return db_transaction_commit(db); @@ -1564,6 +1566,8 @@ switch (t) { if (cway->id!=0) osm_way_add_to_list(cway); + else + osm_free_way(cway); cway=NULL; g_hash_table_destroy(osm_way_tags); @@ -1699,6 +1703,10 @@ fclose(f); return res; } +/** + * Set up bounding box for import. + * + */ void osm_import_set_bbox(gboolean use_bb, gdouble latmin, gdouble lonmin, gdouble latmax, gdouble lonmax) { @@ -1711,6 +1719,10 @@ g_printf("Skipping data outside of box: %f,%f - %f,%f\n", bbox.lat_min, bbox.lon_min, bbox.lat_max, bbox.lon_max); } +/** + * Simple helper to do all preparations and importing from planet -> database + * + */ gboolean osm_import(const gchar *planet, const gchar *database) {