Add:Core:Added svn version in navit -v output
[navit-package] / navit / osm2navit.c
index 21525d1..67e272d 100644 (file)
@@ -172,6 +172,7 @@ static char *attrmap={
        "w      highway=path,bicycle=designated cycleway\n"
        "w      highway=footway         footway\n"
        "w      piste:type=nordic       piste_nordic\n"
+       "w      highway=footway,piste:type=nordic       footway_and_piste_nordic\n"
        "w      route=ski       piste_nordic\n"
        "w      piste:type=downhill,piste:difficulty=novice     piste_downhill_novice\n"
        "w      piste:type=downhill,piste:difficulty=easy       piste_downhill_easy\n"
@@ -354,18 +355,19 @@ struct country_table {
        int count;
        struct rect r;
 } country_table[] = {
-       { 40,"Austria,�sterreich,AUT"}, 
-       {124,"Canada"}, 
-       {208,"Denmark,Danmark,DK"}, 
-       {246,"Finland,Suomi"}, 
-       {250,"France,R�publique fran�aise,FR"}, 
-       {276,"Germany,Deutschland,Bundesrepublik Deutschland"}, 
-       {380,"Italy,Italia"}, 
-       {578,"Norway,Norge,Noreg,NO"}, 
-       {752,"Sweden,Sverige,Konungariket Sverige,SE"}, 
-       {528,"Nederland,The Netherlands,Niederlande,NL"}, 
-       {724,"Spain,Espana,Espana,Reino de Espana"}, 
+       { 40,"Austria,�sterreich,AUT"},
+       {124,"Canada"},
+       {208,"Denmark,Danmark,DK"},
+       {246,"Finland,Suomi"},
+       {250,"France,R�publique fran�aise,FR"},
+       {276,"Germany,Deutschland,Bundesrepublik Deutschland"},
+       {380,"Italy,Italia"},
+       {528,"Nederland,The Netherlands,Niederlande,NL"},
+       {578,"Norway,Norge,Noreg,NO"},
+       {724,"Spain,Espana,Espana,Reino de Espana"},
+       {752,"Sweden,Sverige,Konungariket Sverige,SE"},
        {756,"Schweiz"}, 
+       {826,"United Kingdom,UK"},
        {840,"USA"} 
 };
 
@@ -962,6 +964,46 @@ parse_relation(char *p)
 }
 
 static void
+item_buffer_set_type(char *buffer, enum item_type type)
+{
+       struct item_bin *ib=(struct item_bin *) buffer;
+       ib->clen=0;
+       ib->len=2;
+       ib->type=type;
+}
+
+static void
+item_buffer_add_coord(char *buffer, struct coord *c, int count)
+{
+       struct item_bin *ib=(struct item_bin *) buffer;
+       struct coord *c2=(struct coord *)(ib+1);
+       c2+=ib->clen/2;
+       memcpy(c2, c, count*sizeof(struct coord));
+       ib->clen+=count*2;
+       ib->len+=count*2;
+}
+
+static void
+item_buffer_add_attr(char *buffer, struct attr *attr)
+{
+       struct item_bin *ib=(struct item_bin *) buffer;
+       struct attr_bin *ab=(struct attr_bin *)((int *)ib+ib->len+1);
+       if (attr->type >= attr_type_string_begin && attr->type <= attr_type_string_end) {
+               ab->type=attr->type;
+               strcpy((char *)(ab+1),attr->u.str);
+               pad_text_attr(ab, (char *)(ab+1));
+               ib->len+=ab->len+1;
+       }
+}
+
+static void
+item_buffer_write(char *buffer, FILE *out)
+{
+       struct item_bin *ib=(struct item_bin *) buffer;
+       fwrite(buffer, (ib->len+1)*4, 1, out);
+}
+
+static void
 write_attr(FILE *out, struct attr_bin *attr, void *buffer)
 {
        if (attr->len) {
@@ -1467,7 +1509,34 @@ phase1_db(char *dbstr, FILE *out_ways, FILE *out_nodes)
 }
 #endif
 
-static char buffer[150000];
+static char buffer[200000];
+
+static void
+phase1_map(struct map *map, FILE *out_ways, FILE *out_nodes)
+{
+       struct map_rect *mr=map_rect_new(map, NULL);
+       struct item *item;
+       int count,max=16384;
+       struct coord ca[max];
+       struct item_bin ib;
+       struct attr attr;
+       FILE *file;
+
+       while ((item = map_rect_get_item(mr))) {
+               count=item_coord_get(item, ca, item->type < type_line ? 1: max);
+               item_buffer_set_type(buffer, item->type);
+               item_buffer_add_coord(buffer, ca, count);
+               while (item_attr_get(item, attr_any, &attr)) {
+                       item_buffer_add_attr(buffer, &attr);
+               }
+                if (item->type >= type_line) 
+                       item_buffer_write(buffer, out_ways);
+               else
+                       item_buffer_write(buffer, out_nodes);
+       }
+       map_rect_destroy(mr);
+}
+
 
 int bytes_read=0;
 
@@ -1480,7 +1549,7 @@ read_item(FILE *in)
        if (r != 1)
                return NULL;
        bytes_read+=r;
-       assert((ib->len+1) < sizeof(buffer));
+       assert((ib->len+1)*4 < sizeof(buffer));
        s=(ib->len+1)*4-sizeof(*ib);
        r=fread(ib+1, s, 1, in);
        if (r != 1)
@@ -1752,7 +1821,6 @@ write_item(char *tile, struct item_bin *ib)
        }
 }
 
-
 static void
 write_item_part(FILE *out, struct item_bin *orig, int first, int last)
 {
@@ -2371,6 +2439,7 @@ write_zipmember(FILE *out, FILE *dir_out, char *name, int filelen, char *data, i
 
        crc=crc32(0, NULL, 0);
        crc=crc32(crc, (unsigned char *)data, data_size);
+#ifdef HAVE_ZLIB
        if (compression_level) {
                error=compress2_int((Byte *)compbuffer, &destlen, (Bytef *)data, data_size, compression_level);
                if (error == Z_OK) {
@@ -2382,6 +2451,7 @@ write_zipmember(FILE *out, FILE *dir_out, char *name, int filelen, char *data, i
                        fprintf(stderr,"compress2 returned %d\n", error);
                }
        }
+#endif
        lfh.zipcrc=crc;
        lfh.zipsize=comp_size;
        lfh.zipuncmp=data_size;
@@ -2572,13 +2642,18 @@ int main(int argc, char **argv)
        int i,c,start=1,end=4,dump_coordinates=0;
        int keep_tmpfiles=0;
        int process_nodes=1, process_ways=1;
+#ifdef HAVE_ZLIB
        int compression_level=9;
+#else
+       int compression_level=0;
+#endif
        int output=0;
        int input=0;
        char *result,*dbstr=NULL;
        FILE* input_file = stdin;
        struct plugins *plugins=NULL;
        struct attr **attrs;
+       struct map *map_handle=NULL;
 
        while (1) {
 #if 0
@@ -2595,6 +2670,7 @@ int main(int argc, char **argv)
 #endif
                        {"dedupe-ways", 0, 0, 'w'},
                        {"dump", 0, 0, 'D'},
+                       {"dump-coordinates", 0, 0, 'c'},
                        {"end", 1, 0, 'e'},
                        {"help", 0, 0, 'h'},
                        {"keep-tmpfiles", 0, 0, 'k'},
@@ -2611,7 +2687,7 @@ int main(int argc, char **argv)
 #ifdef HAVE_POSTGRESQL
                                              "d:"
 #endif
-                                             "e:hi:knm:ps:w", long_options, &option_index);
+                                             "e:hi:knm:p:s:w", long_options, &option_index);
                if (c == -1)
                        break;
                switch (c) {
@@ -2649,7 +2725,7 @@ int main(int argc, char **argv)
                                &(struct attr){attr_type,{"textfile"}},
                                &(struct attr){attr_data,{"bookmark.txt"}},
                                NULL};
-                       map_new(attrs);
+                       map_handle=map_new(attrs);
                        fprintf(stderr,"optarg=%s\n", optarg);
                        break;  
                case 'n':
@@ -2666,6 +2742,7 @@ int main(int argc, char **argv)
                case 'p':
                        if (! plugins)
                                plugins=plugins_new();
+                       fprintf(stderr,"optarg=%s\n",optarg);
                        attrs=(struct attr*[]){&(struct attr){attr_path,{optarg}},NULL};
                        plugins_add_path(plugins, attrs);       
                        break;
@@ -2683,9 +2760,11 @@ int main(int argc, char **argv)
                            exit( -1 );
                        }
                        break;
+#ifdef HAVE_ZLIB
                case 'z':
                        compression_level=atoi(optarg);
                        break;
+#endif
                case '?':
                        usage(stderr);
                        break;
@@ -2718,6 +2797,11 @@ int main(int argc, char **argv)
                        phase1_db(dbstr,ways,nodes);
                else
 #endif
+               if (map_handle) {
+                       phase1_map(map_handle,ways,nodes);
+                       map_destroy(map_handle);
+               }
+               else
                        phase1(input_file,ways,nodes);
                if (ways)
                        fclose(ways);