From: zaxl Date: Mon, 29 Oct 2007 09:52:45 +0000 (+0000) Subject: Make built-in garmin types, so you don't have to install garmintypes.txt in the maps... X-Git-Tag: navit-0.5.0.5194svn~4665 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6bf044b9538d59c8370a00e92ce7bdd0ec53bc74;p=profile%2Fivi%2Fnavit.git Make built-in garmin types, so you don't have to install garmintypes.txt in the maps direcotry git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@484 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- diff --git a/navit/src/data/garmin/Makefile.am b/navit/src/data/garmin/Makefile.am index fa1801c..37b88a7 100644 --- a/navit/src/data/garmin/Makefile.am +++ b/navit/src/data/garmin/Makefile.am @@ -5,3 +5,17 @@ INCLUDES=-I$(top_srcdir)/src/data/garmin/libgarmin moduledata_LTLIBRARIES = libdata_garmin.la libdata_garmin_la_SOURCES = garmin.c garmin.h gar2navit.c gar2navit.h libdata_garmin_la_LIBADD = @LIBGARMIN_LIBS@ +nodist_libdata_garmin_la_SOURCES = g2nbuiltin.h + +gar2navit.l$(OBJEXT): g2nbuiltin.h + +CLEANFILES = g2nbuiltin.h + +noinst_PROGRAMS=gentypes +gentypes_SOURCES=gentypes.c + +g2nbuiltin.h: gentypes garmintypes.txt + ./gentypes garmintypes.txt g2nbuiltin.h + +EXTRA_DIST = garmintypes.txt + diff --git a/navit/src/data/garmin/gar2navit.c b/navit/src/data/garmin/gar2navit.c index 5660168..687217d 100644 --- a/navit/src/data/garmin/gar2navit.c +++ b/navit/src/data/garmin/gar2navit.c @@ -287,3 +287,5 @@ int main(int argc, char **argv) return 0; } #endif + +#include "g2nbuiltin.h" diff --git a/navit/src/data/garmin/gar2navit.h b/navit/src/data/garmin/gar2navit.h index 3292b1a..de68298 100644 --- a/navit/src/data/garmin/gar2navit.h +++ b/navit/src/data/garmin/gar2navit.h @@ -28,3 +28,4 @@ struct gar2nav_conv *g2n_conv_load(char *file); enum item_type g2n_get_type(struct gar2nav_conv *c, int type, unsigned short id); char *g2n_get_descr(struct gar2nav_conv *c, int type, unsigned short id); int g2n_get_routable(struct gar2nav_conv *c, int type, unsigned short id); +struct gar2nav_conv *g2n_default_conv(void); diff --git a/navit/src/data/garmin/garmin.c b/navit/src/data/garmin/garmin.c index 3339f7c..b68045b 100644 --- a/navit/src/data/garmin/garmin.c +++ b/navit/src/data/garmin/garmin.c @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include #include "plugin.h" #include "data.h" #include "projection.h" @@ -564,6 +567,8 @@ gmap_rect_new(struct map_priv *map, struct map_selection *sel) struct map_selection *ms = sel; struct map_rect_priv *mr; + if (!map) + return NULL; mr = calloc(1, sizeof(*mr)); if (!mr) return mr; @@ -630,6 +635,7 @@ gmap_new(struct map_methods *meth, struct attr **attrs) struct map_priv *m; struct attr *data; char buf[PATH_MAX]; + struct stat st; data=attr_search(attrs, NULL, attr_data); if (! data) @@ -654,20 +660,15 @@ gmap_new(struct map_methods *meth, struct attr **attrs) g_free(m); return NULL; } + m->conv = NULL; snprintf(buf, sizeof(buf), "%s.types", m->filename); - dlog(1, "Looking for types in %s\n", buf); - m->conv = g2n_conv_load(buf); + if (!stat(buf, &st)) { + dlog(1, "Loading custom types from %s\n", buf); + m->conv = g2n_conv_load(buf); + } if (!m->conv) { - char *cp; - strcpy(buf, m->filename); - cp = strrchr(buf ,'/'); - if (cp) { - cp ++; - *cp = '\0'; - strcat(buf, "garmintypes.txt"); - dlog(1, "Looking for types in %s\n", buf); - m->conv = g2n_conv_load(buf); - } + dlog(1, "Using builtin types\n"); + m->conv = g2n_default_conv(); } if (!m->conv) { dlog(1, "Failed to load map types\n"); diff --git a/navit/src/data/garmin/gentypes.c b/navit/src/data/garmin/gentypes.c new file mode 100644 index 0000000..7a53d7f --- /dev/null +++ b/navit/src/data/garmin/gentypes.c @@ -0,0 +1,193 @@ +/* + Copyright (C) 2007 Alexander Atanasov + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301 USA + + Garmin and MapSource are registered trademarks or trademarks + of Garmin Ltd. or one of its subsidiaries. + +*/ + +/* + Street's are routable by: + ALL - by all + W pedestrian (1<<0) + B bycycle (1<<1) + M motorcycle (1<<2) + C car (1<<3) + T truck (1<<4) + L largetruck (1<<5) +File format is: + +POINT +0x0100 = town_label_1e5, Megapolis (10M +) +0x0200 = town_label_5e4, Megapolis (5-10M) +... +0x1e00-0x1e3f = district_label, District, Province, State Name +... +POLYLINE +0x00 = ALL, street_1_land, Road +0x01 = MCTL, highway_land, Major HWY thick +0x02 = MCTL, street_4_land, Principal HWY-thick +0x03 = MCTL, street_2_land, Principal HWY-medium +.... +POLYGONE +0x01 = town_poly, City (>200k) +0x02 = town_poly, City (<200k) +0x03 = town_poly, Village + + */ + +#include +#include +#include +#include +#include "item.h" +#include "gar2navit.h" + +#define dlog(x, y...) fprintf(stderr, ## y) +/* +static int add_def(struct gar2nav_conv *conv, int type, unsigned short minid, + unsigned short maxid, unsigned int routable, char *ntype, + char *descr) +*/ + +static unsigned int get_rtmask(char *p) +{ + char *cp; + unsigned int mask = 0; + cp = p; + while (*cp) { + if (!strcasecmp(cp, "none")) + return 0; + if (!strcasecmp(cp, "all")) { + mask = ~0; + break; + } if (*cp == 'W') + mask |= RT_PEDESTRIAN; + else if (*cp == 'B') + mask |= RT_BYCYCLE; + else if (*cp == 'M') + mask |= RT_MOTORCYCLE; + else if (*cp == 'C') + mask |= RT_CAR; + else if (*cp == 'T') + mask |= RT_TRUCK; + else if (*cp == 'L') + mask |= RT_LONGTRUCK; + cp++; + } + return mask; +} + +static void print_header(FILE *fp) +{ + fprintf(fp, "// This is autogenerated file -- DO NOT EDIT\n"); + fprintf(fp, "struct gar2nav_conv *g2n_default_conv(void)\n" + "{\n" + "\tstruct gar2nav_conv *conv;\n" + "\n" + "\tconv = calloc(1, sizeof(*conv));\n" + "\tif (!conv)\n" + "\t\treturn conv;\n"); +} + +static int load_types_file(char *file, char *out) +{ + char buf[4096]; + char descr[4096]; + char ntype[4096]; + char rtby[4096]; + FILE *fp; + unsigned int minid, maxid, routable; + int rc; + int type = -1; + FILE *fpout = stdout; + + fp = fopen(file, "r"); + if (!fp) + return -1; + if (out) { + fpout = fopen(out, "w"); + if (!fpout) + return -1; + } + print_header(fpout); + while (fgets(buf, sizeof(buf), fp)) { + if (*buf == '#' || *buf == '\n') + continue; + routable = 0; + if (!strncasecmp(buf, "POINT", 5)) { + type = 1; + continue; + } else if (!strncasecmp(buf, "POI", 3)) { + type = 1; + continue; + } else if (!strncasecmp(buf, "POLYLINE", 8)) { + type = 2; + continue; + } else if (!strncasecmp(buf, "POLYGONE", 8)) { + type = 3; + continue; + } + // assume only lines are routable + if (type == 2) { + rc = sscanf(buf, "0x%04X = %[^\t, ] , %[^\t, ], %[^\n]", + &minid, rtby, ntype, descr); + if (rc != 4) { + dlog(1, "Invalid line rc=%d:[%s]\n",rc, buf); + dlog(1, "minid=%04X ntype=[%s] des=[%s]\n", + minid, ntype, descr); + continue; + } + routable = get_rtmask(rtby); + } else { + rc = sscanf(buf, "0x%04X - 0x%04X = %[^\t , ] , %[^\n]", + &minid, &maxid, ntype, descr); + if (rc != 4) { + maxid = 0; + rc = sscanf(buf, "0x%04X = %[^\t, ], %[^\n]", + &minid, ntype, descr); + if (rc != 3) { + dlog(1, "Invalid line rc=%d:[%s]\n",rc, buf); + dlog(1, "minid=%04X ntype=[%s] des=[%s]\n", + minid, ntype, descr); + continue; + } + } + } + fprintf(fpout, "\tadd_def(conv, %d, %d, %d, %d, \"%s\", \"%s\");\n", + type, minid, maxid, routable, ntype, descr); + + } + fprintf(fpout, "\treturn conv;\n"); + fprintf(fpout, "}\n"); + fclose(fp); + if (out) + fclose(fpout); + return 1; +} + +int main(int argc, char **argv) +{ + if (argc!=3) { + fprintf(stderr, "Usage: %s garmintypes.txt outfile.c\n", + argv[0]); + return -1; + } + if (load_types_file(argv[1], argv[2]) < 0) + unlink(argv[2]); + return 0; +}