]> err.no Git - mapper/commitdiff
Use g_slice_new0 instead of manuly setting things to zero. Add a helper macro to...
authorKaj-Michael Lang <milang@tal.org>
Fri, 25 Apr 2008 10:23:04 +0000 (13:23 +0300)
committerKaj-Michael Lang <milang@tal.org>
Fri, 25 Apr 2008 10:23:04 +0000 (13:23 +0300)
src/osm-db-import.c

index 1ad250e2c1770bba36aff1347036e829da5b2a19..b2576f7f36bbd4226137f908a95931313a85da19 100644 (file)
@@ -880,11 +880,7 @@ if (n==NULL)
        return;
 if (n->data!=NULL) 
        return;
-n->data=g_slice_new(node_data);
-n->data->name=NULL;
-n->data->url=NULL;
-n->data->desc=NULL;
-n->data->postal_code=NULL;
+n->data=g_slice_new0(node_data);
 n->type=NODE_PLAIN;
 noded_cnt++;
 }
@@ -912,12 +908,11 @@ osm_new_node(gint id, gdouble lat, gdouble lon)
 {
 node *n=NULL;
 
-n=g_slice_new(node);
+n=g_slice_new0(node);
 g_assert(n);
 n->id=id;
 n->lat=lat;
 n->lon=lon;
-n->data=(node_data *)NULL;
 return n;
 }
 
@@ -945,14 +940,7 @@ if (w==NULL)
 if (w->data!=NULL) 
        return;
 
-w->data=g_slice_new(way_data);
-w->data->name=NULL;
-w->data->names=NULL;
-w->data->ref=NULL;
-w->data->int_ref=NULL;
-w->data->postal_code=NULL;
-w->data->layer=0;
-w->data->speed=0;
+w->data=g_slice_new0(way_data);
 }
 
 static void
@@ -976,14 +964,10 @@ osm_new_way(gint id)
 {
 way *w;
 
-w=g_slice_new(way);
+w=g_slice_new0(way);
 g_assert(w);
 w->id=id;
-w->nodes=NULL;
 w->type=WAY_UNWAYED;
-w->data=NULL;
-w->ncnt=0;
-w->flags=0;
 
 /* Add to list of ways */
 return w;
@@ -1371,6 +1355,23 @@ switch (t) {
 }
 }
 
+#define GET_NODE_KEY(key, nfield) { \
+       gchar *_kv; \
+       _kv=g_hash_table_lookup(osm_node_tags, key); \
+       if (_kv) { \
+               if (!nfield) { \
+                       nfield=g_strstrip(g_utf8_normalize(_kv, -1, G_NORMALIZE_ALL_COMPOSE)); \
+               } else { \
+                       gchar *_tmp=nfield; \
+                       gchar *_norm=g_utf8_normalize(_kv, -1, G_NORMALIZE_ALL_COMPOSE); \
+                       nfield=g_strdup_printf("%s %s", _tmp, g_strstrip(_norm)); \
+                       g_free(_tmp); \
+                       g_free(_norm); \
+               } \
+       } \
+}
+       
+
 static void
 _osm_tag_end(void *userData, const char *name)
 {
@@ -1406,8 +1407,7 @@ switch (t) {
                 * - Places (for is_in)
                 * - ...
                 */
-               if ((osm_node_check_box(cnode->lat, cnode->lon)==FALSE) && 
-                               (cnode->type<NODE_PLACE_START)) {
+               if ((osm_node_check_box(cnode->lat, cnode->lon)==FALSE) && (cnode->type<NODE_PLACE_START)) {
                        osm_free_node_data(cnode);
                        osm_free_node(cnode);
                        g_hash_table_destroy(osm_node_tags);
@@ -1422,12 +1422,11 @@ switch (t) {
                        v=g_hash_table_lookup(osm_node_tags, "name");
                        if (v)
                                cnode->data->name=g_strstrip(g_utf8_normalize(v, -1, G_NORMALIZE_ALL_COMPOSE));
-                       v=g_hash_table_lookup(osm_node_tags, "note");
-                       if (v)
-                               cnode->data->desc=g_strstrip(g_strdup(v));
-                       v=g_hash_table_lookup(osm_node_tags, "postal_code");
-                       if (v)
-                               cnode->data->postal_code=g_strstrip(g_strdup(v));
+
+                       GET_NODE_KEY("description", cnode->data->desc);
+                       GET_NODE_KEY("note", cnode->data->desc);
+                       GET_NODE_KEY("postal_code", cnode->data->postal_code);
+                       GET_NODE_KEY("address", cnode->data->desc);
 
                        /* Links */
                        v=g_hash_table_lookup(osm_node_tags, "url");