First work on a binary driver
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 3 Oct 2007 20:15:57 +0000 (20:15 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 3 Oct 2007 20:15:57 +0000 (20:15 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@438 ffa7fe5e-494d-0410-b361-a75ebd5db220

configure.in
po/Makefile.am
src/Makefile.am
src/attr.c
src/data/Makefile.am
src/data/binfile/Makefile.am [new file with mode: 0644]
src/data/binfile/binfile.c [new file with mode: 0644]

index dab25a9..8a30b2a 100644 (file)
@@ -252,6 +252,7 @@ src/binding/python/Makefile
 src/data/Makefile
 src/data/mg/Makefile
 src/data/textfile/Makefile
+src/data/binfile/Makefile
 src/data/garmin_img/Makefile
 src/data/poi_geodownload/Makefile
 src/data/poi_geodownload/libmdb/Makefile
index 2f50109..0f9c5f9 100644 (file)
@@ -61,3 +61,14 @@ uninstall-local:
                        rm -f $(DESTDIR)$(datadir)/locale/$$l/LC_MESSAGES/navit.mo; \
                fi; \
        done
+
+distclean-local:
+       for n in $(CATALOGS) __DuMmY ; do \
+               if test "$$n" -a "$$n" != "__DuMmY" ; then \
+                       l=`basename $$n .mo`; \
+                       rm -f ../locale/$$l/LC_MESSAGES/navit.mo; \
+                       if test "$(top_srcdir)" != "$(top_builddir)"; then \
+                               rm -f $$l.po; \
+                       fi;\
+               fi; \
+       done
index 9bfd63a..3e538af 100644 (file)
@@ -37,3 +37,5 @@ maps/$(SAMPLE_MAP).txt: maps/$(SAMPLE_MAP).osm $(top_srcdir)/src/script/osm2navi
        $(top_srcdir)/src/script/osm2navit <maps/$(SAMPLE_MAP).osm >maps/$(SAMPLE_MAP).txt.tmp
        mv maps/$(SAMPLE_MAP).txt.tmp maps/$(SAMPLE_MAP).txt
 
+distclean-local:
+       rm -f maps/$(SAMPLE_MAP).osm
index 52b408e..676244c 100644 (file)
@@ -87,6 +87,40 @@ attr_search(struct attr **attrs, struct attr *last, enum attr_type attr)
        return NULL;
 }
 
+int
+attr_data_size(struct attr *attr)
+{
+       if (attr->type >= attr_type_string_begin && attr->type <= attr_type_string_end) {
+               return strlen(attr->u.str)+1;
+       }
+       if (attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) {
+               return sizeof(attr->u.num);
+       }
+       return 0;
+}
+
+void *
+attr_data_get(struct attr *attr)
+{
+       if (attr->type >= attr_type_string_begin && attr->type <= attr_type_string_end) {
+               return attr->u.str;
+       }
+       if (attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) {
+               return &attr->u.num;
+       }
+}
+
+void
+attr_data_set(struct attr *attr, void *data)
+{
+       if (attr->type >= attr_type_string_begin && attr->type <= attr_type_string_end) {
+               attr->u.str=data;
+       }
+       if (attr->type >= attr_type_int_begin && attr->type <= attr_type_int_end) {
+               attr->u.num=*((int *)data);
+       }
+}
+
 void
 attr_free(struct attr *attr)
 {
index 8f7999b..6649e06 100644 (file)
@@ -1 +1 @@
-SUBDIRS=mg textfile garmin_img poi_geodownload
+SUBDIRS=mg textfile garmin_img poi_geodownload binfile
diff --git a/src/data/binfile/Makefile.am b/src/data/binfile/Makefile.am
new file mode 100644 (file)
index 0000000..2978452
--- /dev/null
@@ -0,0 +1,4 @@
+include $(top_srcdir)/Makefile.inc
+AM_CPPFLAGS = @NAVIT_CFLAGS@ -I$(top_srcdir)/src -DMODULE=\"data_binfile\"
+moduledata_LTLIBRARIES = libdata_binfile.la
+libdata_binfile_la_SOURCES = binfile.c binfile.h
diff --git a/src/data/binfile/binfile.c b/src/data/binfile/binfile.c
new file mode 100644 (file)
index 0000000..3387832
--- /dev/null
@@ -0,0 +1,218 @@
+#include <glib.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "debug.h"
+#include "plugin.h"
+#include "projection.h"
+#include "map.h"
+#include "maptype.h"
+#include "item.h"
+#include "attr.h"
+#include "coord.h"
+#include "transform.h"
+#include "file.h"
+
+static int map_id;
+
+struct map_priv {
+       int id;
+       char *filename;
+       struct file *f;
+};
+
+struct map_rect_priv {
+       int *start;
+       int *pos;
+       int *pos_coord_start;
+       int *pos_coord;
+       int *pos_attr_start;
+       int *pos_attr;
+       int *pos_next;
+       int *end;
+       enum attr_type attr_last;
+        struct map_selection *sel;
+        struct map_priv *m;
+        struct item item;
+};
+
+
+static void
+map_destroy_binfile(struct map_priv *m)
+{
+       dbg(1,"map_destroy_binfile\n");
+       g_free(m);
+}
+
+static void
+binfile_coord_rewind(void *priv_data)
+{
+       struct map_rect_priv *mr=priv_data;
+       mr->pos_coord=mr->pos_coord_start;
+}
+
+static int
+binfile_coord_get(void *priv_data, struct coord *c, int count)
+{
+       struct map_rect_priv *mr=priv_data;
+       int ret=0;
+       dbg(1,"binfile_coord_get %d\n",count);
+       while (count--) {
+               dbg(1,"%p vs %p\n", mr->pos_coord, mr->pos_attr_start);
+               if (mr->pos_coord >= mr->pos_attr_start)
+                       break;
+               c->x=*(mr->pos_coord++);
+               c->y=*(mr->pos_coord++);
+               c++;
+               ret++;
+       }
+       return ret;
+}
+
+static void
+binfile_attr_rewind(void *priv_data)
+{
+       struct map_rect_priv *mr=priv_data;
+       mr->pos_attr=mr->pos_attr_start;
+       
+}
+
+static int
+binfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
+{      
+       struct map_rect_priv *mr=priv_data;
+       enum attr_type type;
+       int size;
+
+       if (attr_type != mr->attr_last) {
+               mr->pos_attr=mr->pos_attr_start;
+               mr->attr_last=attr_type;
+       }
+       while (mr->pos_attr < mr->pos_next) {
+               size=*(mr->pos_attr++);
+               type=mr->pos_attr[0];
+               if (type == attr_type || attr_type == attr_any) {
+                       if (attr_type == attr_any) {
+                               dbg(0,"pos %p attr %s size %d\n", mr->pos_attr-1, attr_to_name(type), size);
+                       }
+                       attr->type=type;
+                       attr_data_set(attr, mr->pos_attr+1);
+                       mr->pos_attr+=size;
+                       return 1;
+               } else {
+                       mr->pos_attr+=size;
+               }
+       }
+       return 0;
+}
+
+static struct item_methods methods_binfile = {
+        binfile_coord_rewind,
+        binfile_coord_get,
+        binfile_attr_rewind,
+        binfile_attr_get,
+};
+
+static struct map_rect_priv *
+map_rect_new_binfile(struct map_priv *map, struct map_selection *sel)
+{
+       struct map_rect_priv *mr;
+
+       dbg(1,"map_rect_new_binfile\n");
+       mr=g_new0(struct map_rect_priv, 1);
+       mr->m=map;
+       mr->sel=sel;
+       mr->start=mr->pos=mr->pos_next=map->f->begin;
+       mr->end=map->f->end;
+       mr->item.id_hi=0;
+       mr->item.id_lo=0;
+       mr->item.meth=&methods_binfile;
+       mr->item.priv_data=mr;
+       return mr;
+}
+
+
+static void
+map_rect_destroy_binfile(struct map_rect_priv *mr)
+{
+        g_free(mr);
+}
+
+static void
+setup_pos(struct map_rect_priv *mr)
+{
+       int size,coord_size;
+       size=*(mr->pos++);
+       mr->pos_next=mr->pos+size;
+       mr->item.type=*(mr->pos++);
+       coord_size=*(mr->pos++);
+       mr->pos_coord_start=mr->pos_coord=mr->pos;
+       mr->pos_attr_start=mr->pos_attr=mr->pos_coord+coord_size;
+}
+
+
+
+static struct item *
+map_rect_get_item_binfile(struct map_rect_priv *mr)
+{
+       mr->pos=mr->pos_next;
+       if (mr->pos >= mr->end)
+               return NULL;
+       mr->item.id_hi=0;
+       mr->item.id_lo=mr->pos-mr->start;
+       setup_pos(mr);
+       return &mr->item;
+}
+
+static struct item *
+map_rect_get_item_byid_binfile(struct map_rect_priv *mr, int id_hi, int id_lo)
+{
+       mr->pos=mr->start+id_lo;
+       mr->item.id_hi=id_hi;
+       mr->item.id_lo=id_lo;
+       setup_pos(mr);
+       return &mr->item;
+}
+
+static struct map_methods map_methods_binfile = {
+       projection_mg,
+       "utf-8",
+       map_destroy_binfile,
+       map_rect_new_binfile,
+       map_rect_destroy_binfile,
+       map_rect_get_item_binfile,
+       map_rect_get_item_byid_binfile,
+};
+
+static struct map_priv *
+map_new_binfile(struct map_methods *meth, struct attr **attrs)
+{
+       struct map_priv *m;
+       struct attr *data=attr_search(attrs, NULL, attr_data);
+       struct file_wordexp *wexp;
+       char **wexp_data;
+       if (! data)
+               return NULL;
+
+       wexp=file_wordexp_new(data->u.str);
+       wexp_data=file_wordexp_get_array(wexp);
+       dbg(1,"map_new_binfile %s\n", data->u.str);     
+       *meth=map_methods_binfile;
+
+       m=g_new0(struct map_priv, 1);
+       m->id=++map_id;
+       m->filename=g_strdup(wexp_data[0]);
+       dbg(0,"file_create %s\n", m->filename);
+       m->f=file_create(m->filename);
+       file_wordexp_destroy(wexp);
+       return m;
+}
+
+void
+plugin_init(void)
+{
+       dbg(1,"binfile: plugin_init\n");
+       plugin_register_map_type("binfile", map_new_binfile);
+}
+