Diff of /trunk/src/osm.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 78 by harbaum, Sun Feb 15 12:07:04 2009 UTC revision 175 by harbaum, Wed Jun 10 09:24:47 2009 UTC
# Line 35  Line 35 
35  #error "Tree not enabled in libxml"  #error "Tree not enabled in libxml"
36  #endif  #endif
37    
 /* determine where a node/way/relation read from the osm file */  
 /* is inserted into the internal database */  
 // #define OSM_SORT_ID  
 #define OSM_SORT_LAST  
 // #define OSM_SORT_FIRST  
   
38  /* ------------------------- bounds handling --------------------- */  /* ------------------------- bounds handling --------------------- */
39    
40  static void osm_bounds_free(bounds_t *bounds) {  static void osm_bounds_free(bounds_t *bounds) {
# Line 233  void osm_node_dump(node_t *node) { Line 227  void osm_node_dump(node_t *node) {
227    char buf[64];    char buf[64];
228    struct tm tm;    struct tm tm;
229    
230    printf("Id:      %lu\n", node->id);    printf("Id:      "ITEM_ID_FORMAT"\n", node->id);
231    printf("User:    %s\n", node->user?node->user->name:"<unspecified>");    printf("User:    %s\n", node->user?node->user->name:"<unspecified>");
232    printf("Visible: %s\n", node->visible?"yes":"no");    printf("Visible: %s\n", node->visible?"yes":"no");
233    
# Line 266  void osm_node_chain_free(node_chain_t *n Line 260  void osm_node_chain_free(node_chain_t *n
260  }  }
261    
262  void osm_way_free(way_t *way) {  void osm_way_free(way_t *way) {
263    //  printf("freeing way #%ld\n", way->id);    //  printf("freeing way #" ITEM_ID_FORMAT "\n", way->id);
264    
265    osm_node_chain_free(way->node_chain);    osm_node_chain_free(way->node_chain);
266    osm_tags_free(way->tag);    osm_tags_free(way->tag);
# Line 311  void osm_way_dump(way_t *way) { Line 305  void osm_way_dump(way_t *way) {
305    char buf[64];    char buf[64];
306    struct tm tm;    struct tm tm;
307    
308    printf("Id:      %lu\n", way->id);    printf("Id:      "ITEM_ID_FORMAT"\n", way->id);
309    printf("User:    %s\n", way->user?way->user->name:"<unspecified>");    printf("User:    %s\n", way->user?way->user->name:"<unspecified>");
310    printf("Visible: %s\n", way->visible?"yes":"no");    printf("Visible: %s\n", way->visible?"yes":"no");
311    node_chain_t *node_chain = way->node_chain;    node_chain_t *node_chain = way->node_chain;
312    while(node_chain) {    while(node_chain) {
313      printf("  Node:  %lu\n", node_chain->node->id);      printf("  Node:  "ITEM_ID_FORMAT"\n", node_chain->node->id);
314      node_chain = node_chain->next;      node_chain = node_chain->next;
315    }    }
316    
# Line 345  node_chain_t *osm_parse_osm_way_nd(osm_t Line 339  node_chain_t *osm_parse_osm_way_nd(osm_t
339    
340      /* search matching node */      /* search matching node */
341      node_chain->node = osm_get_node_by_id(osm, id);      node_chain->node = osm_get_node_by_id(osm, id);
342      if(!node_chain->node) printf("Node id %lu not found\n", id);      if(!node_chain->node) printf("Node id " ITEM_ID_FORMAT " not found\n", id);
343      else                  node_chain->node->ways++;      else                  node_chain->node->ways++;
344    
345      xmlFree(prop);      xmlFree(prop);
# Line 392  void osm_relations_dump(relation_t *rela Line 386  void osm_relations_dump(relation_t *rela
386      char buf[64];      char buf[64];
387      struct tm tm;      struct tm tm;
388    
389      printf("Id:      %lu\n", relation->id);      printf("Id:      "ITEM_ID_FORMAT"\n", relation->id);
390      printf("User:    %s\n",      printf("User:    %s\n",
391             relation->user?relation->user->name:"<unspecified>");             relation->user?relation->user->name:"<unspecified>");
392      printf("Visible: %s\n", relation->visible?"yes":"no");      printf("Visible: %s\n", relation->visible?"yes":"no");
393    
394      member_t *member = relation->member;      member_t *member = relation->member;
395      while(member) {      while(member) {
396        switch(member->type) {        switch(member->object.type) {
397        case ILLEGAL:        case ILLEGAL:
398        case NODE_ID:        case NODE_ID:
399        case WAY_ID:        case WAY_ID:
# Line 407  void osm_relations_dump(relation_t *rela Line 401  void osm_relations_dump(relation_t *rela
401          break;          break;
402    
403        case NODE:        case NODE:
404          if(member->node)          if(member->object.node)
405            printf(" Member: Node, id = %lu, role = %s\n",            printf(" Member: Node, id = " ITEM_ID_FORMAT ", role = %s\n",
406                   member->node->id, member->role);                   member->object.node->id, member->role);
407          break;          break;
408    
409        case WAY:        case WAY:
410          if(member->way)          if(member->object.way)
411          printf(" Member: Way, id = %lu, role = %s\n",            printf(" Member: Way, id = " ITEM_ID_FORMAT ", role = %s\n",
412                 member->way->id, member->role);                   member->object.way->id, member->role);
413          break;          break;
414    
415        case RELATION:        case RELATION:
416          if(member->relation)          if(member->object.relation)
417          printf(" Member: Relation, id = %lu, role = %s\n",            printf(" Member: Relation, id = " ITEM_ID_FORMAT ", role = %s\n",
418                 member->relation->id, member->role);                   member->object.relation->id, member->role);
419          break;          break;
420        }        }
421    
# Line 442  member_t *osm_parse_osm_relation_member( Line 436  member_t *osm_parse_osm_relation_member(
436                            xmlDocPtr doc, xmlNode *a_node) {                            xmlDocPtr doc, xmlNode *a_node) {
437    char *prop;    char *prop;
438    member_t *member = g_new0(member_t, 1);    member_t *member = g_new0(member_t, 1);
439    member->type = ILLEGAL;    member->object.type = ILLEGAL;
440    
441    if((prop = (char*)xmlGetProp(a_node, (unsigned char*)"type"))) {    if((prop = (char*)xmlGetProp(a_node, (unsigned char*)"type"))) {
442      if(strcasecmp(prop, "way") == 0)           member->type = WAY;      if(strcasecmp(prop, "way") == 0)           member->object.type = WAY;
443      else if(strcasecmp(prop, "node") == 0)     member->type = NODE;      else if(strcasecmp(prop, "node") == 0)     member->object.type = NODE;
444      else if(strcasecmp(prop, "relation") == 0) member->type = RELATION;      else if(strcasecmp(prop, "relation") == 0) member->object.type = RELATION;
445      xmlFree(prop);      xmlFree(prop);
446    }    }
447    
448    if((prop = (char*)xmlGetProp(a_node, (unsigned char*)"ref"))) {    if((prop = (char*)xmlGetProp(a_node, (unsigned char*)"ref"))) {
449      item_id_t id = strtoul(prop, NULL, 10);      item_id_t id = strtoul(prop, NULL, 10);
450    
451      switch(member->type) {      switch(member->object.type) {
452      case ILLEGAL:      case ILLEGAL:
453        printf("Unable to store illegal type\n");        printf("Unable to store illegal type\n");
454        break;        break;
455    
456      case WAY:      case WAY:
457        /* search matching way */        /* search matching way */
458        member->way = osm_get_way_by_id(osm, id);        member->object.way = osm_get_way_by_id(osm, id);
459        if(!member->way) {        if(!member->object.way) {
460          member->type = WAY_ID;          member->object.type = WAY_ID;
461          member->id = id;          member->object.id = id;
462        }        }
463        break;        break;
464    
465      case NODE:      case NODE:
466        /* search matching node */        /* search matching node */
467        member->node = osm_get_node_by_id(osm, id);        member->object.node = osm_get_node_by_id(osm, id);
468        if(!member->node) {        if(!member->object.node) {
469          member->type = NODE_ID;          member->object.type = NODE_ID;
470          member->id = id;          member->object.id = id;
471        }        }
472        break;        break;
473    
474      case RELATION:      case RELATION:
475        /* search matching relation */        /* search matching relation */
476        member->relation = osm_get_relation_by_id(osm, id);        member->object.relation = osm_get_relation_by_id(osm, id);
477        if(!member->relation) {        if(!member->object.relation) {
478          member->type = NODE_ID;          member->object.type = NODE_ID;
479          member->id = id;          member->object.id = id;
480        }        }
481        break;        break;
482    
# Line 685  static node_t *process_node(xmlTextReade Line 679  static node_t *process_node(xmlTextReade
679      xmlFree(prop);      xmlFree(prop);
680    }    }
681    
682      /* new in api 0.6: */
683      if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "version"))) {
684        node->version = strtoul(prop, NULL, 10);
685        xmlFree(prop);
686      }
687    
688    if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "lat"))) {    if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "lat"))) {
689      node->pos.lat = g_ascii_strtod(prop, NULL);      node->pos.lat = g_ascii_strtod(prop, NULL);
690      xmlFree(prop);      xmlFree(prop);
# Line 759  static node_chain_t *process_nd(xmlTextR Line 759  static node_chain_t *process_nd(xmlTextR
759    
760      /* search matching node */      /* search matching node */
761      node_chain->node = osm_get_node_by_id(osm, id);      node_chain->node = osm_get_node_by_id(osm, id);
762      if(!node_chain->node) printf("Node id %lu not found\n", id);      if(!node_chain->node) printf("Node id " ITEM_ID_FORMAT " not found\n", id);
763      else                  node_chain->node->ways++;      else                  node_chain->node->ways++;
764    
765      xmlFree(prop);      xmlFree(prop);
# Line 782  static way_t *process_way(xmlTextReaderP Line 782  static way_t *process_way(xmlTextReaderP
782      xmlFree(prop);      xmlFree(prop);
783    }    }
784    
785      /* new in api 0.6: */
786      if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "version"))) {
787        way->version = strtoul(prop, NULL, 10);
788        xmlFree(prop);
789      }
790    
791    if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "user"))) {    if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "user"))) {
792      way->user = osm_user(osm, prop);      way->user = osm_user(osm, prop);
793      xmlFree(prop);      xmlFree(prop);
# Line 842  static way_t *process_way(xmlTextReaderP Line 848  static way_t *process_way(xmlTextReaderP
848  static member_t *process_member(xmlTextReaderPtr reader, osm_t *osm) {  static member_t *process_member(xmlTextReaderPtr reader, osm_t *osm) {
849    char *prop;    char *prop;
850    member_t *member = g_new0(member_t, 1);    member_t *member = g_new0(member_t, 1);
851    member->type = ILLEGAL;    member->object.type = ILLEGAL;
852    
853    if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "type"))) {    if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "type"))) {
854      if(strcasecmp(prop, "way") == 0)           member->type = WAY;      if(strcasecmp(prop, "way") == 0)           member->object.type = WAY;
855      else if(strcasecmp(prop, "node") == 0)     member->type = NODE;      else if(strcasecmp(prop, "node") == 0)     member->object.type = NODE;
856      else if(strcasecmp(prop, "relation") == 0) member->type = RELATION;      else if(strcasecmp(prop, "relation") == 0) member->object.type = RELATION;
857      xmlFree(prop);      xmlFree(prop);
858    }    }
859    
860    if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "ref"))) {    if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "ref"))) {
861      item_id_t id = strtoul(prop, NULL, 10);      item_id_t id = strtoul(prop, NULL, 10);
862    
863      switch(member->type) {      switch(member->object.type) {
864      case ILLEGAL:      case ILLEGAL:
865        printf("Unable to store illegal type\n");        printf("Unable to store illegal type\n");
866        break;        break;
867    
868      case WAY:      case WAY:
869        /* search matching way */        /* search matching way */
870        member->way = osm_get_way_by_id(osm, id);        member->object.way = osm_get_way_by_id(osm, id);
871        if(!member->way) {        if(!member->object.way) {
872          member->type = WAY_ID;          member->object.type = WAY_ID;
873          member->id = id;          member->object.id = id;
874        }        }
875        break;        break;
876    
877      case NODE:      case NODE:
878        /* search matching node */        /* search matching node */
879        member->node = osm_get_node_by_id(osm, id);        member->object.node = osm_get_node_by_id(osm, id);
880        if(!member->node) {        if(!member->object.node) {
881          member->type = NODE_ID;          member->object.type = NODE_ID;
882          member->id = id;          member->object.id = id;
883        }        }
884        break;        break;
885    
886      case RELATION:      case RELATION:
887        /* search matching relation */        /* search matching relation */
888        member->relation = osm_get_relation_by_id(osm, id);        member->object.relation = osm_get_relation_by_id(osm, id);
889        if(!member->relation) {        if(!member->object.relation) {
890          member->type = NODE_ID;          member->object.type = NODE_ID;
891          member->id = id;          member->object.id = id;
892        }        }
893        break;        break;
894    
# Line 913  static relation_t *process_relation(xmlT Line 919  static relation_t *process_relation(xmlT
919      xmlFree(prop);      xmlFree(prop);
920    }    }
921    
922      /* new in api 0.6: */
923      if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "version"))) {
924        relation->version = strtoul(prop, NULL, 10);
925        xmlFree(prop);
926      }
927    
928    if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "user"))) {    if((prop = (char*)xmlTextReaderGetAttribute(reader, BAD_CAST "user"))) {
929      relation->user = osm_user(osm, prop);      relation->user = osm_user(osm, prop);
930      xmlFree(prop);      xmlFree(prop);
# Line 1053  static osm_t *process_file(const char *f Line 1065  static osm_t *process_file(const char *f
1065    
1066  #include <sys/time.h>  #include <sys/time.h>
1067    
1068  osm_t *osm_parse(char *filename) {  osm_t *osm_parse(char *path, char *filename) {
1069    
1070    struct timeval start;    struct timeval start;
1071    gettimeofday(&start, NULL);    gettimeofday(&start, NULL);
# Line 1061  osm_t *osm_parse(char *filename) { Line 1073  osm_t *osm_parse(char *filename) {
1073    LIBXML_TEST_VERSION;    LIBXML_TEST_VERSION;
1074    
1075    // use stream parser    // use stream parser
1076    osm_t *osm = process_file(filename);    osm_t *osm = NULL;
1077      if(filename[0] == '/')
1078        osm = process_file(filename);
1079      else {
1080        char *full = g_strjoin(NULL, path, filename, NULL);
1081        osm = process_file(full);
1082        g_free(full);
1083      }
1084    
1085    xmlCleanupParser();    xmlCleanupParser();
1086    
1087    struct timeval end;    struct timeval end;
# Line 1156  gboolean osm_node_has_value(node_t *node Line 1176  gboolean osm_node_has_value(node_t *node
1176  gboolean osm_node_has_tag(node_t *node) {  gboolean osm_node_has_tag(node_t *node) {
1177    tag_t *tag = node->tag;    tag_t *tag = node->tag;
1178    
1179      /* created_by tags don't count as real tags */
1180    if(tag && strcasecmp(tag->key, "created_by") == 0)    if(tag && strcasecmp(tag->key, "created_by") == 0)
1181      tag = tag->next;      tag = tag->next;
1182    
# Line 1178  static void osm_generate_tags(tag_t *tag Line 1199  static void osm_generate_tags(tag_t *tag
1199    while(tag) {    while(tag) {
1200      /* make sure "created_by" tag contains our id */      /* make sure "created_by" tag contains our id */
1201      if(strcasecmp(tag->key, "created_by") == 0) {      if(strcasecmp(tag->key, "created_by") == 0) {
1202        g_free(tag->value);        if(strcasecmp(tag->value, PACKAGE " v" VERSION) != 0) {
1203        tag->value = g_strdup(PACKAGE " v" VERSION);          g_free(tag->value);
1204            tag->value = g_strdup(PACKAGE " v" VERSION);
1205          }
1206      }      }
1207    
1208      xmlNodePtr tag_node = xmlNewChild(node, NULL, BAD_CAST "tag", NULL);      xmlNodePtr tag_node = xmlNewChild(node, NULL, BAD_CAST "tag", NULL);
# Line 1190  static void osm_generate_tags(tag_t *tag Line 1213  static void osm_generate_tags(tag_t *tag
1213  }  }
1214    
1215  /* build xml representation for a way */  /* build xml representation for a way */
1216  char *osm_generate_xml(osm_t *osm, type_t type, void *item) {  static char *osm_generate_xml(osm_t *osm, item_id_t changeset,
1217                           type_t type, void *item) {
1218    char str[32];    char str[32];
1219    xmlChar *result = NULL;    xmlChar *result = NULL;
1220    int len = 0;    int len = 0;
# Line 1199  char *osm_generate_xml(osm_t *osm, type_ Line 1223  char *osm_generate_xml(osm_t *osm, type_
1223    
1224    xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");    xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
1225    xmlNodePtr root_node = xmlNewNode(NULL, BAD_CAST "osm");    xmlNodePtr root_node = xmlNewNode(NULL, BAD_CAST "osm");
   xmlNewProp(root_node, BAD_CAST "version", BAD_CAST "0.5");  
   xmlNewProp(root_node, BAD_CAST "generator", BAD_CAST PACKAGE " V" VERSION);  
1226    xmlDocSetRootElement(doc, root_node);    xmlDocSetRootElement(doc, root_node);
1227    
1228    switch(type) {    switch(type) {
# Line 1214  char *osm_generate_xml(osm_t *osm, type_ Line 1236  char *osm_generate_xml(osm_t *osm, type_
1236          snprintf(str, sizeof(str), "%u", (unsigned)node->id);          snprintf(str, sizeof(str), "%u", (unsigned)node->id);
1237          xmlNewProp(node_node, BAD_CAST "id", BAD_CAST str);          xmlNewProp(node_node, BAD_CAST "id", BAD_CAST str);
1238        }        }
1239        g_ascii_dtostr(str, sizeof(str), node->pos.lat);        snprintf(str, sizeof(str), "%u", (unsigned)node->version);
1240          xmlNewProp(node_node, BAD_CAST "version", BAD_CAST str);
1241          snprintf(str, sizeof(str), "%u", (unsigned)changeset);
1242          xmlNewProp(node_node, BAD_CAST "changeset", BAD_CAST str);
1243          g_ascii_formatd(str, sizeof(str), LL_FORMAT, node->pos.lat);
1244        xmlNewProp(node_node, BAD_CAST "lat", BAD_CAST str);        xmlNewProp(node_node, BAD_CAST "lat", BAD_CAST str);
1245        g_ascii_dtostr(str, sizeof(str), node->pos.lon);        g_ascii_formatd(str, sizeof(str), LL_FORMAT, node->pos.lon);
1246        xmlNewProp(node_node, BAD_CAST "lon", BAD_CAST str);        xmlNewProp(node_node, BAD_CAST "lon", BAD_CAST str);
1247        osm_generate_tags(node->tag, node_node);        osm_generate_tags(node->tag, node_node);
1248      }      }
# Line 1228  char *osm_generate_xml(osm_t *osm, type_ Line 1254  char *osm_generate_xml(osm_t *osm, type_
1254        xmlNodePtr way_node = xmlNewChild(root_node, NULL, BAD_CAST "way", NULL);        xmlNodePtr way_node = xmlNewChild(root_node, NULL, BAD_CAST "way", NULL);
1255        snprintf(str, sizeof(str), "%u", (unsigned)way->id);        snprintf(str, sizeof(str), "%u", (unsigned)way->id);
1256        xmlNewProp(way_node, BAD_CAST "id", BAD_CAST str);        xmlNewProp(way_node, BAD_CAST "id", BAD_CAST str);
1257          snprintf(str, sizeof(str), "%u", (unsigned)way->version);
1258          xmlNewProp(way_node, BAD_CAST "version", BAD_CAST str);
1259          snprintf(str, sizeof(str), "%u", (unsigned)changeset);
1260          xmlNewProp(way_node, BAD_CAST "changeset", BAD_CAST str);
1261    
1262        node_chain_t *node_chain = way->node_chain;        node_chain_t *node_chain = way->node_chain;
1263        while(node_chain) {        while(node_chain) {
1264          xmlNodePtr nd_node = xmlNewChild(way_node, NULL, BAD_CAST "nd", NULL);          xmlNodePtr nd_node = xmlNewChild(way_node, NULL, BAD_CAST "nd", NULL);
1265          char *str = g_strdup_printf("%ld", node_chain->node->id);          char *str = g_strdup_printf(ITEM_ID_FORMAT, node_chain->node->id);
1266          xmlNewProp(nd_node, BAD_CAST "ref", BAD_CAST str);          xmlNewProp(nd_node, BAD_CAST "ref", BAD_CAST str);
1267          g_free(str);          g_free(str);
1268          node_chain = node_chain->next;          node_chain = node_chain->next;
# Line 1249  char *osm_generate_xml(osm_t *osm, type_ Line 1279  char *osm_generate_xml(osm_t *osm, type_
1279                                          BAD_CAST "relation", NULL);                                          BAD_CAST "relation", NULL);
1280        snprintf(str, sizeof(str), "%u", (unsigned)relation->id);        snprintf(str, sizeof(str), "%u", (unsigned)relation->id);
1281        xmlNewProp(rel_node, BAD_CAST "id", BAD_CAST str);        xmlNewProp(rel_node, BAD_CAST "id", BAD_CAST str);
1282          snprintf(str, sizeof(str), "%u", (unsigned)relation->version);
1283          xmlNewProp(rel_node, BAD_CAST "version", BAD_CAST str);
1284          snprintf(str, sizeof(str), "%u", (unsigned)changeset);
1285          xmlNewProp(rel_node, BAD_CAST "changeset", BAD_CAST str);
1286    
1287        member_t *member = relation->member;        member_t *member = relation->member;
1288        while(member) {        while(member) {
1289          xmlNodePtr m_node = xmlNewChild(rel_node,NULL,BAD_CAST "member", NULL);          xmlNodePtr m_node = xmlNewChild(rel_node,NULL,BAD_CAST "member", NULL);
1290          char *str = NULL;          char *str = NULL;
1291    
1292          switch(member->type) {          switch(member->object.type) {
1293          case NODE:          case NODE:
1294            xmlNewProp(m_node, BAD_CAST "type", BAD_CAST "node");            xmlNewProp(m_node, BAD_CAST "type", BAD_CAST "node");
1295            str = g_strdup_printf("%ld", member->node->id);            str = g_strdup_printf(ITEM_ID_FORMAT, member->object.node->id);
1296            break;            break;
1297    
1298          case WAY:          case WAY:
1299            xmlNewProp(m_node, BAD_CAST "type", BAD_CAST "way");            xmlNewProp(m_node, BAD_CAST "type", BAD_CAST "way");
1300            str = g_strdup_printf("%ld", member->way->id);            str = g_strdup_printf(ITEM_ID_FORMAT, member->object.way->id);
1301            break;            break;
1302    
1303          case RELATION:          case RELATION:
1304            xmlNewProp(m_node, BAD_CAST "type", BAD_CAST "relation");            xmlNewProp(m_node, BAD_CAST "type", BAD_CAST "relation");
1305            str = g_strdup_printf("%ld", member->relation->id);            str = g_strdup_printf(ITEM_ID_FORMAT, member->object.relation->id);
1306            break;            break;
1307    
1308          default:          default:
# Line 1308  char *osm_generate_xml(osm_t *osm, type_ Line 1342  char *osm_generate_xml(osm_t *osm, type_
1342  }  }
1343    
1344  /* build xml representation for a node */  /* build xml representation for a node */
1345  char *osm_generate_xml_node(osm_t *osm, node_t *node) {  char *osm_generate_xml_node(osm_t *osm, item_id_t changeset, node_t *node) {
1346    return osm_generate_xml(osm, NODE, node);    return osm_generate_xml(osm, changeset, NODE, node);
1347  }  }
1348    
1349  /* build xml representation for a way */  /* build xml representation for a way */
1350  char *osm_generate_xml_way(osm_t *osm, way_t *way) {  char *osm_generate_xml_way(osm_t *osm, item_id_t changeset, way_t *way) {
1351    return osm_generate_xml(osm, WAY, way);    return osm_generate_xml(osm, changeset, WAY, way);
1352  }  }
1353    
1354  /* build xml representation for a relation */  /* build xml representation for a relation */
1355  char *osm_generate_xml_relation(osm_t *osm, relation_t *relation) {  char *osm_generate_xml_relation(osm_t *osm, item_id_t changeset,
1356    return osm_generate_xml(osm, RELATION, relation);                                  relation_t *relation) {
1357      return osm_generate_xml(osm, changeset, RELATION, relation);
1358  }  }
1359    
1360    /* build xml representation for a changeset */
1361    char *osm_generate_xml_changeset(osm_t *osm, char *comment) {
1362      xmlChar *result = NULL;
1363      int len = 0;
1364    
1365      /* tags for this changeset */
1366      tag_t tag_comment = {
1367        .key = "comment", .value = comment, .next = NULL };
1368      tag_t tag_creator = {
1369        .key = "created_by", .value = PACKAGE " v" VERSION, .next = &tag_comment };
1370    
1371      LIBXML_TEST_VERSION;
1372    
1373      xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
1374      xmlNodePtr root_node = xmlNewNode(NULL, BAD_CAST "osm");
1375      xmlDocSetRootElement(doc, root_node);
1376    
1377      xmlNodePtr cs_node = xmlNewChild(root_node, NULL, BAD_CAST "changeset", NULL);
1378      osm_generate_tags(&tag_creator, cs_node);
1379    
1380      xmlDocDumpFormatMemoryEnc(doc, &result, &len, "UTF-8", 1);
1381      xmlFreeDoc(doc);
1382      xmlCleanupParser();
1383    
1384      //  puts("xml encoding result:");
1385      //  puts((char*)result);
1386    
1387      return (char*)result;
1388    }
1389    
1390    
1391  /* the following three functions are eating much CPU power */  /* the following three functions are eating much CPU power */
1392  /* as they search the objects lists. Hashing is supposed to help */  /* as they search the objects lists. Hashing is supposed to help */
1393  node_t *osm_get_node_by_id(osm_t *osm, item_id_t id) {  node_t *osm_get_node_by_id(osm_t *osm, item_id_t id) {
# Line 1457  node_t *osm_node_new(osm_t *osm, gint x, Line 1523  node_t *osm_node_new(osm_t *osm, gint x,
1523    printf("Creating new node\n");    printf("Creating new node\n");
1524    
1525    node_t *node = g_new0(node_t, 1);    node_t *node = g_new0(node_t, 1);
1526      node->version = 1;
1527    node->lpos.x = x;    node->lpos.x = x;
1528    node->lpos.y = y;    node->lpos.y = y;
1529    node->visible = TRUE;    node->visible = TRUE;
1530    node->time = time(NULL);    node->time = time(NULL);
1531    
   /* add created_by tag */  
   node->tag = g_new0(tag_t, 1);  
   node->tag->key = g_strdup("created_by");  
   node->tag->value = g_strdup(PACKAGE " v" VERSION);  
   
1532    /* convert screen position back to ll */    /* convert screen position back to ll */
1533    lpos2pos(osm->bounds, &node->lpos, &node->pos);    lpos2pos(osm->bounds, &node->lpos, &node->pos);
1534    
# Line 1502  way_t *osm_way_new(void) { Line 1564  way_t *osm_way_new(void) {
1564    printf("Creating new way\n");    printf("Creating new way\n");
1565    
1566    way_t *way = g_new0(way_t, 1);    way_t *way = g_new0(way_t, 1);
1567      way->version = 1;
1568    way->visible = TRUE;    way->visible = TRUE;
1569    way->flags = OSM_FLAG_NEW;    way->flags = OSM_FLAG_NEW;
1570    way->time = time(NULL);    way->time = time(NULL);
1571    
   /* add created_by tag */  
   way->tag = g_new0(tag_t, 1);  
   way->tag->key = g_strdup("created_by");  
   way->tag->value = g_strdup(PACKAGE " v" VERSION);  
   
1572    return way;    return way;
1573  }  }
1574    
# Line 1534  way_chain_t *osm_node_delete(osm_t *osm, Line 1592  way_chain_t *osm_node_delete(osm_t *osm,
1592    
1593    /* new nodes aren't stored on the server and are just deleted permanently */    /* new nodes aren't stored on the server and are just deleted permanently */
1594    if(node->flags & OSM_FLAG_NEW) {    if(node->flags & OSM_FLAG_NEW) {
1595      printf("About to delete NEW node #%ld -> force permanent delete\n",      printf("About to delete NEW node #" ITEM_ID_FORMAT
1596             node->id);             " -> force permanent delete\n", node->id);
1597      permanently = TRUE;      permanently = TRUE;
1598    }    }
1599    
# Line 1571  way_chain_t *osm_node_delete(osm_t *osm, Line 1629  way_chain_t *osm_node_delete(osm_t *osm,
1629    }    }
1630    
1631    if(!permanently) {    if(!permanently) {
1632      printf("mark node #%ld as deleted\n", node->id);      printf("mark node #" ITEM_ID_FORMAT " as deleted\n", node->id);
1633      node->flags |= OSM_FLAG_DELETED;      node->flags |= OSM_FLAG_DELETED;
1634    } else {    } else {
1635      printf("permanently delete node #%ld\n", node->id);      printf("permanently delete node #" ITEM_ID_FORMAT "\n", node->id);
1636    
1637      /* remove it from the chain */      /* remove it from the chain */
1638      node_t **cnode = &osm->node;      node_t **cnode = &osm->node;
# Line 1615  relation_chain_t *osm_node_to_relation(o Line 1673  relation_chain_t *osm_node_to_relation(o
1673    
1674      member_t *member = relation->member;      member_t *member = relation->member;
1675      while(member) {      while(member) {
1676        switch(member->type) {        switch(member->object.type) {
1677        case NODE:        case NODE:
1678          /* nodes are checked directly */          /* nodes are checked directly */
1679          if(member->node == node)          if(member->object.node == node)
1680            is_member = TRUE;            is_member = TRUE;
1681          break;          break;
1682    
1683        case WAY: {        case WAY: {
1684          /* ways have to be checked for the nodes they consist of */          /* ways have to be checked for the nodes they consist of */
1685          node_chain_t *chain = member->way->node_chain;          node_chain_t *chain = member->object.way->node_chain;
1686          while(chain && !is_member) {          while(chain && !is_member) {
1687            if(chain->node == node)            if(chain->node == node)
1688              is_member = TRUE;              is_member = TRUE;
# Line 1662  relation_chain_t *osm_way_to_relation(os Line 1720  relation_chain_t *osm_way_to_relation(os
1720    
1721      member_t *member = relation->member;      member_t *member = relation->member;
1722      while(member) {      while(member) {
1723        switch(member->type) {        switch(member->object.type) {
1724        case WAY: {        case WAY: {
1725          /* ways can be check directly */          /* ways can be check directly */
1726          if(member->way == way)          if(member->object.way == way)
1727            is_member = TRUE;            is_member = TRUE;
1728        } break;        } break;
1729    
# Line 1727  gboolean osm_position_within_bounds(osm_ Line 1785  gboolean osm_position_within_bounds(osm_
1785  /* be deleted */  /* be deleted */
1786  void osm_node_remove_from_relation(osm_t *osm, node_t *node) {  void osm_node_remove_from_relation(osm_t *osm, node_t *node) {
1787    relation_t *relation = osm->relation;    relation_t *relation = osm->relation;
1788    printf("removing node #%ld from all relations:\n", node->id);    printf("removing node #" ITEM_ID_FORMAT " from all relations:\n", node->id);
1789    
1790    while(relation) {    while(relation) {
1791      member_t **member = &relation->member;      member_t **member = &relation->member;
1792      while(*member) {      while(*member) {
1793        if(((*member)->type == NODE) &&        if(((*member)->object.type == NODE) &&
1794           ((*member)->node == node)) {           ((*member)->object.node == node)) {
1795    
1796          printf("  from relation #%ld\n", relation->id);          printf("  from relation #" ITEM_ID_FORMAT "\n", relation->id);
1797    
1798          member_t *cur = *member;          member_t *cur = *member;
1799          *member = (*member)->next;          *member = (*member)->next;
# Line 1752  void osm_node_remove_from_relation(osm_t Line 1810  void osm_node_remove_from_relation(osm_t
1810  /* remove the given way from all relations */  /* remove the given way from all relations */
1811  void osm_way_remove_from_relation(osm_t *osm, way_t *way) {  void osm_way_remove_from_relation(osm_t *osm, way_t *way) {
1812    relation_t *relation = osm->relation;    relation_t *relation = osm->relation;
1813    printf("removing way #%ld from all relations:\n", way->id);    printf("removing way #" ITEM_ID_FORMAT " from all relations:\n", way->id);
1814    
1815    while(relation) {    while(relation) {
1816      member_t **member = &relation->member;      member_t **member = &relation->member;
1817      while(*member) {      while(*member) {
1818        if(((*member)->type == WAY) &&        if(((*member)->object.type == WAY) &&
1819           ((*member)->way == way)) {           ((*member)->object.way == way)) {
1820    
1821          printf("  from relation #%ld\n", relation->id);          printf("  from relation #" ITEM_ID_FORMAT "\n", relation->id);
1822    
1823          member_t *cur = *member;          member_t *cur = *member;
1824          *member = (*member)->next;          *member = (*member)->next;
# Line 1778  relation_t *osm_relation_new(void) { Line 1836  relation_t *osm_relation_new(void) {
1836    printf("Creating new relation\n");    printf("Creating new relation\n");
1837    
1838    relation_t *relation = g_new0(relation_t, 1);    relation_t *relation = g_new0(relation_t, 1);
1839      relation->version = 1;
1840    relation->visible = TRUE;    relation->visible = TRUE;
1841    relation->flags = OSM_FLAG_NEW;    relation->flags = OSM_FLAG_NEW;
1842    relation->time = time(NULL);    relation->time = time(NULL);
1843    
   /* add created_by tag */  
   relation->tag = g_new0(tag_t, 1);  
   relation->tag->key = g_strdup("created_by");  
   relation->tag->value = g_strdup(PACKAGE " v" VERSION);  
   
1844    return relation;    return relation;
1845  }  }
1846    
# Line 1808  void osm_way_delete(osm_t *osm, icon_t * Line 1862  void osm_way_delete(osm_t *osm, icon_t *
1862    
1863    /* new ways aren't stored on the server and are just deleted permanently */    /* new ways aren't stored on the server and are just deleted permanently */
1864    if(way->flags & OSM_FLAG_NEW) {    if(way->flags & OSM_FLAG_NEW) {
1865      printf("About to delete NEW way #%ld -> force permanent delete\n",      printf("About to delete NEW way #" ITEM_ID_FORMAT
1866             way->id);             " -> force permanent delete\n", way->id);
1867      permanently = TRUE;      permanently = TRUE;
1868    }    }
1869    
# Line 1818  void osm_way_delete(osm_t *osm, icon_t * Line 1872  void osm_way_delete(osm_t *osm, icon_t *
1872    while(*chain) {    while(*chain) {
1873    
1874      (*chain)->node->ways--;      (*chain)->node->ways--;
1875      printf("checking node #%ld (still used by %d)\n",      printf("checking node #" ITEM_ID_FORMAT " (still used by %d)\n",
1876             (*chain)->node->id, (*chain)->node->ways);             (*chain)->node->id, (*chain)->node->ways);
1877    
1878      /* this node must only be part of this way */      /* this node must only be part of this way */
# Line 1844  void osm_way_delete(osm_t *osm, icon_t * Line 1898  void osm_way_delete(osm_t *osm, icon_t *
1898    way->node_chain = NULL;    way->node_chain = NULL;
1899    
1900    if(!permanently) {    if(!permanently) {
1901      printf("mark way #%ld as deleted\n", way->id);      printf("mark way #" ITEM_ID_FORMAT " as deleted\n", way->id);
1902      way->flags |= OSM_FLAG_DELETED;      way->flags |= OSM_FLAG_DELETED;
1903    } else {    } else {
1904      printf("permanently delete way #%ld\n", way->id);      printf("permanently delete way #" ITEM_ID_FORMAT "\n", way->id);
1905    
1906      /* remove it from the chain */      /* remove it from the chain */
1907      way_t **cway = &osm->way;      way_t **cway = &osm->way;
# Line 1872  void osm_relation_delete(osm_t *osm, rel Line 1926  void osm_relation_delete(osm_t *osm, rel
1926    /* new relations aren't stored on the server and are just */    /* new relations aren't stored on the server and are just */
1927    /* deleted permanently */    /* deleted permanently */
1928    if(relation->flags & OSM_FLAG_NEW) {    if(relation->flags & OSM_FLAG_NEW) {
1929      printf("About to delete NEW relation #%ld -> force permanent delete\n",      printf("About to delete NEW relation #" ITEM_ID_FORMAT
1930             relation->id);             " -> force permanent delete\n", relation->id);
1931      permanently = TRUE;      permanently = TRUE;
1932    }    }
1933    
# Line 1881  void osm_relation_delete(osm_t *osm, rel Line 1935  void osm_relation_delete(osm_t *osm, rel
1935    /* don't have any reference to the relation they are part of */    /* don't have any reference to the relation they are part of */
1936    
1937    if(!permanently) {    if(!permanently) {
1938      printf("mark relation #%ld as deleted\n", relation->id);      printf("mark relation #" ITEM_ID_FORMAT " as deleted\n", relation->id);
1939      relation->flags |= OSM_FLAG_DELETED;      relation->flags |= OSM_FLAG_DELETED;
1940    } else {    } else {
1941      printf("permanently delete relation #%ld\n", relation->id);      printf("permanently delete relation #" ITEM_ID_FORMAT "\n", relation->id);
1942    
1943      /* remove it from the chain */      /* remove it from the chain */
1944      relation_t **crelation = &osm->relation;      relation_t **crelation = &osm->relation;
# Line 1903  void osm_relation_delete(osm_t *osm, rel Line 1957  void osm_relation_delete(osm_t *osm, rel
1957    }    }
1958  }  }
1959    
1960  void osm_way_revert(way_t *way) {  void osm_way_reverse(way_t *way) {
1961    node_chain_t *new = NULL;    node_chain_t *new = NULL;
1962    
1963    /* walk old chain first to last */    /* walk old chain first to last */
# Line 1921  void osm_way_revert(way_t *way) { Line 1975  void osm_way_revert(way_t *way) {
1975    way->node_chain = new;    way->node_chain = new;
1976  }  }
1977    
1978    static const char *DS_ONEWAY_FWD = "yes";
1979    static const char *DS_ONEWAY_REV = "-1";
1980    static const char *DS_LEFT_SUFFIX = ":left";
1981    static const char *DS_RIGHT_SUFFIX = ":right";
1982    
1983    /* Reverse direction-sensitive tags like "oneway". Marks the way as dirty if
1984     * anything is changed, and returns the number of flipped tags. */
1985    
1986    guint
1987    osm_way_reverse_direction_sensitive_tags (way_t *way) {
1988      tag_t *tag = way->tag;
1989      guint n_tags_altered = 0;
1990      while (tag != NULL) {
1991        char *lc_key = g_ascii_strdown(tag->key, -1);
1992        char *lc_value = g_ascii_strdown(tag->value, -1);
1993    
1994        if (strcmp(lc_key, "oneway") == 0) {
1995          // oneway={yes/true/1/-1} is unusual.
1996          // Favour "yes" and "-1".
1997          if ((strcmp(lc_value, DS_ONEWAY_FWD) == 0) ||
1998              (strcmp(lc_value, "true") == 0) ||
1999              (strcmp(lc_value, "1") == 0)) {
2000            g_free(tag->value);
2001            tag->value = g_strdup(DS_ONEWAY_REV);
2002            n_tags_altered++;
2003          }
2004          else if (strcmp(lc_value, DS_ONEWAY_REV) == 0) {
2005            g_free(tag->value);
2006            tag->value = g_strdup(DS_ONEWAY_FWD);
2007            n_tags_altered++;
2008          }
2009          else {
2010            printf("warning: unknown tag: %s=%s\n", tag->key, tag->value);
2011          }
2012        }
2013    
2014        // :left and :right suffixes
2015        else if (g_str_has_suffix(lc_key, DS_LEFT_SUFFIX)) {
2016          char *key_old = tag->key;
2017          char *lastcolon = rindex(key_old, ':');
2018          g_assert(lastcolon != NULL);
2019          *lastcolon = '\000';
2020          tag->key = g_strconcat(key_old, DS_RIGHT_SUFFIX, NULL);
2021          *lastcolon = ':';
2022          g_free(key_old);
2023          n_tags_altered++;
2024        }
2025        else if (g_str_has_suffix(lc_key, DS_RIGHT_SUFFIX)) {
2026          char *key_old = tag->key;
2027          char *lastcolon = rindex(key_old, ':');
2028          g_assert(lastcolon != NULL);
2029          *lastcolon = '\000';
2030          tag->key = g_strconcat(key_old, DS_LEFT_SUFFIX, NULL);
2031          *lastcolon = ':';
2032          g_free(key_old);
2033          n_tags_altered++;
2034        }
2035    
2036        g_free(lc_key);
2037        g_free(lc_value);
2038        tag = tag->next;
2039      }
2040      if (n_tags_altered > 0) {
2041        way->flags |= OSM_FLAG_DIRTY;
2042      }
2043      return n_tags_altered;
2044    }
2045    
2046    /* Reverse a way's role within relations where the role is direction-sensitive.
2047     * Returns the number of roles flipped, and marks any relations changed as
2048     * dirty. */
2049    
2050    static const char *DS_ROUTE_FORWARD = "forward";
2051    static const char *DS_ROUTE_REVERSE = "reverse";
2052    
2053    guint
2054    osm_way_reverse_direction_sensitive_roles(osm_t *osm, way_t *way) {
2055      relation_chain_t *rel_chain0, *rel_chain;
2056      rel_chain0 = rel_chain = osm_way_to_relation(osm, way);
2057      guint n_roles_flipped = 0;
2058    
2059      for (; rel_chain != NULL; rel_chain = rel_chain->next) {
2060        char *type = osm_tag_get_by_key(rel_chain->relation->tag, "type");
2061    
2062        // Route relations; http://wiki.openstreetmap.org/wiki/Relation:route
2063        if (strcasecmp(type, "route") == 0) {
2064    
2065          // First find the member corresponding to our way:
2066          member_t *member = rel_chain->relation->member;
2067          for (; member != NULL; member = member->next) {
2068            if (member->object.type == WAY) {
2069              if (member->object.way == way)
2070                break;
2071            }
2072            if (member->object.type == WAY_ID) {
2073              if (member->object.id == way->id)
2074                break;
2075            }
2076          }
2077          g_assert(member);  // osm_way_to_relation() broken?
2078    
2079          // Then flip its role if it's one of the direction-sensitive ones
2080          if (member->role == NULL) {
2081            printf("null role in route relation -> ignore\n");
2082          }
2083          else if (strcasecmp(member->role, DS_ROUTE_FORWARD) == 0) {
2084            g_free(member->role);
2085            member->role = g_strdup(DS_ROUTE_REVERSE);
2086            rel_chain->relation->flags |= OSM_FLAG_DIRTY;
2087            ++n_roles_flipped;
2088          }
2089          else if (strcasecmp(member->role, DS_ROUTE_REVERSE) == 0) {
2090            g_free(member->role);
2091            member->role = g_strdup(DS_ROUTE_FORWARD);
2092            rel_chain->relation->flags |= OSM_FLAG_DIRTY;
2093            ++n_roles_flipped;
2094          }
2095    
2096          // TODO: what about numbered stops? Guess we ignore them; there's no
2097          // consensus about whether they should be placed on the way or to one side
2098          // of it.
2099    
2100        }//if-route
2101    
2102    
2103      }
2104      if (rel_chain0) {
2105        g_free(rel_chain0);
2106      }
2107      return n_roles_flipped;
2108    }
2109    
2110  node_t *osm_way_get_first_node(way_t *way) {  node_t *osm_way_get_first_node(way_t *way) {
2111    node_chain_t *chain = way->node_chain;    node_chain_t *chain = way->node_chain;
2112    if(!chain) return NULL;    if(!chain) return NULL;
# Line 1980  tag_t *osm_tags_copy(tag_t *src_tag, gbo Line 2166  tag_t *osm_tags_copy(tag_t *src_tag, gbo
2166  }  }
2167    
2168  /* return plain text of type */  /* return plain text of type */
2169  char *osm_type_string(type_t type) {  char *osm_object_type_string(object_t *object) {
2170    const struct { type_t type; char *name; } types[] = {    const struct { type_t type; char *name; } types[] = {
2171      { ILLEGAL,     "illegal" },      { ILLEGAL,     "illegal" },
2172      { NODE,        "node" },      { NODE,        "node" },
# Line 1994  char *osm_type_string(type_t type) { Line 2180  char *osm_type_string(type_t type) {
2180    
2181    int i;    int i;
2182    for(i=0;types[i].name;i++)    for(i=0;types[i].name;i++)
2183      if(type == types[i].type)      if(object->type == types[i].type)
2184        return types[i].name;        return types[i].name;
2185    
2186    return NULL;    return NULL;
2187  }  }
2188    
2189  char *osm_object_string(type_t type, void *object) {  char *osm_object_string(object_t *object) {
2190    char *type_str = osm_type_string(type);    char *type_str = osm_object_type_string(object);
2191    
2192    if(!object)    if(!object)
2193      return g_strdup_printf("%s #<invalid>", type_str);      return g_strdup_printf("%s #<invalid>", type_str);
2194    
2195    switch(type) {    switch(object->type) {
2196    case ILLEGAL:    case ILLEGAL:
2197      return g_strdup_printf("%s #<unspec>", type_str);      return g_strdup_printf("%s #<unspec>", type_str);
2198      break;      break;
2199    case NODE:    case NODE:
2200      return g_strdup_printf("%s #%ld", type_str, ((node_t*)object)->id);      return g_strdup_printf("%s #" ITEM_ID_FORMAT, type_str, object->node->id);
2201      break;      break;
2202    case WAY:    case WAY:
2203      return g_strdup_printf("%s #%ld", type_str, ((way_t*)object)->id);      return g_strdup_printf("%s #" ITEM_ID_FORMAT, type_str, object->way->id);
2204      break;      break;
2205    case RELATION:    case RELATION:
2206      return g_strdup_printf("%s #%ld", type_str, ((relation_t*)object)->id);      return g_strdup_printf("%s #" ITEM_ID_FORMAT, type_str,
2207                               object->relation->id);
2208      break;      break;
2209    case NODE_ID:    case NODE_ID:
2210    case WAY_ID:    case WAY_ID:
2211    case RELATION_ID:    case RELATION_ID:
2212      return g_strdup_printf("%s #%ld", type_str, ((item_id_t)object));      return g_strdup_printf("%s #" ITEM_ID_FORMAT, type_str, object->id);
2213      break;      break;
2214    }    }
2215    return NULL;    return NULL;
2216  }  }
2217    
2218  char *osm_id_string(type_t type, void *object) {  char *osm_object_id_string(object_t *object) {
2219    if(!object) return NULL;    if(!object) return NULL;
2220    
2221    switch(type) {    switch(object->type) {
2222    case ILLEGAL:    case ILLEGAL:
2223      return NULL;      return NULL;
2224      break;      break;
2225    case NODE:    case NODE:
2226      return g_strdup_printf("#%ld", ((node_t*)object)->id);      return g_strdup_printf("#"ITEM_ID_FORMAT, object->node->id);
2227      break;      break;
2228    case WAY:    case WAY:
2229      return g_strdup_printf("#%ld", ((way_t*)object)->id);      return g_strdup_printf("#"ITEM_ID_FORMAT, object->way->id);
2230      break;      break;
2231    case RELATION:    case RELATION:
2232      return g_strdup_printf("#%ld", ((relation_t*)object)->id);      return g_strdup_printf("#"ITEM_ID_FORMAT, object->relation->id);
2233      break;      break;
2234    case NODE_ID:    case NODE_ID:
2235    case WAY_ID:    case WAY_ID:
2236    case RELATION_ID:    case RELATION_ID:
2237      return g_strdup_printf("#%ld", ((item_id_t)object));      return g_strdup_printf("#"ITEM_ID_FORMAT, object->id);
2238      break;      break;
2239    }    }
2240    return NULL;    return NULL;
2241  }  }
2242    
2243  tag_t *osm_object_get_tags(type_t type, void *object) {  tag_t *osm_object_get_tags(object_t *object) {
2244    if(!object) return NULL;    if(!object) return NULL;
2245    
2246    switch(type) {    switch(object->type) {
2247    case ILLEGAL:    case ILLEGAL:
2248      return NULL;      return NULL;
2249      break;      break;
2250    case NODE:    case NODE:
2251      return ((node_t*)object)->tag;      return object->node->tag;
2252      break;      break;
2253    case WAY:    case WAY:
2254      return ((way_t*)object)->tag;      return object->way->tag;
2255      break;      break;
2256    case RELATION:    case RELATION:
2257      return ((relation_t*)object)->tag;      return object->relation->tag;
2258      break;      break;
2259    case NODE_ID:    case NODE_ID:
2260    case WAY_ID:    case WAY_ID:
# Line 2089  gint osm_relation_members_num(relation_t Line 2276  gint osm_relation_members_num(relation_t
2276    return num;    return num;
2277  }  }
2278    
2279    void osm_object_set_flags(object_t *object, int set, int clr) {
2280    
2281      switch(object->type) {
2282      case NODE:
2283        object->node->flags |=  set;
2284        object->node->flags &= ~clr;
2285        break;
2286    
2287      case WAY:
2288        object->way->flags |=  set;
2289        object->way->flags &= ~clr;
2290        break;
2291    
2292      case RELATION:
2293        object->relation->flags |=  set;
2294        object->relation->flags &= ~clr;
2295        break;
2296    
2297      default:
2298        g_assert(0);
2299        break;
2300      }
2301    }
2302    
2303  // vim:et:ts=8:sw=2:sts=2:ai  // vim:et:ts=8:sw=2:sts=2:ai

Legend:
Removed from v.78  
changed lines
  Added in v.175