summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-05-15 15:44:50 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-05-15 15:44:50 +0000
commita9a0a433e2409eb514234bedb1a4132dcb221a55 (patch)
treefa66bed268a51c1fef518f540319e32d16c55ff6
parent12f6b62c2a1546769c5e04c5c388a46e13005b28 (diff)
downloadnavit-a9a0a433e2409eb514234bedb1a4132dcb221a55.tar.gz
Fix:maptool:Beginning of cleaning of buffer handling
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@3251 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/maptool/Makefile.am2
-rw-r--r--navit/maptool/itembin.c30
-rw-r--r--navit/maptool/itembin_buffer.c43
-rw-r--r--navit/maptool/maptool.h7
-rw-r--r--navit/maptool/tile.c8
5 files changed, 53 insertions, 37 deletions
diff --git a/navit/maptool/Makefile.am b/navit/maptool/Makefile.am
index 4688ab449..5f2f1e752 100644
--- a/navit/maptool/Makefile.am
+++ b/navit/maptool/Makefile.am
@@ -5,6 +5,6 @@ if !SUPPORT_ANDROID
endif
AM_CPPFLAGS = @NAVIT_CFLAGS@ -I$(top_srcdir)/navit @ZLIB_CFLAGS@ @POSTGRESQL_CFLAGS@ -DMODULE=maptool
-libmaptool_la_SOURCES = buffer.c ch.c coastline.c geom.c itembin.c misc.c osm.c sourcesink.c tempfile.c tile.c zip.c maptool.h
+libmaptool_la_SOURCES = buffer.c ch.c coastline.c geom.c itembin.c itembin_buffer.c misc.c osm.c sourcesink.c tempfile.c tile.c zip.c maptool.h
maptool_SOURCES = maptool.c
maptool_LDADD = libmaptool.la ../libnavit.la @NAVIT_LIBS@ @WORDEXP_LIBS@ @ZLIB_LIBS@ @POSTGRESQL_LIBS@ @CRYPTO_LIBS@ @INTLLIBS@ @LIBC_LIBS@
diff --git a/navit/maptool/itembin.c b/navit/maptool/itembin.c
index 7af570006..b40231a30 100644
--- a/navit/maptool/itembin.c
+++ b/navit/maptool/itembin.c
@@ -7,36 +7,6 @@
-struct item_bin *
-read_item(FILE *in)
-{
- struct item_bin *ib=(struct item_bin *) buffer;
- int r,s;
- r=fread(ib, sizeof(*ib), 1, in);
- if (r != 1)
- return NULL;
- bytes_read+=r;
- dbg_assert((ib->len+1)*4 < sizeof(buffer));
- s=(ib->len+1)*4-sizeof(*ib);
- r=fread(ib+1, s, 1, in);
- if (r != 1)
- return NULL;
- bytes_read+=r;
- return ib;
-}
-
-struct item_bin *
-read_item_range(FILE *in, int *min, int *max)
-{
- struct range r;
-
- if (fread(&r, sizeof(r), 1, in) != 1)
- return NULL;
- *min=r.min;
- *max=r.max;
- return read_item(in);
-}
-
int
item_bin_read(struct item_bin *ib, FILE *in)
{
diff --git a/navit/maptool/itembin_buffer.c b/navit/maptool/itembin_buffer.c
new file mode 100644
index 000000000..0c654653f
--- /dev/null
+++ b/navit/maptool/itembin_buffer.c
@@ -0,0 +1,43 @@
+#include <string.h>
+#include <stdlib.h>
+#include "maptool.h"
+#include "debug.h"
+
+struct item_bin *
+read_item(FILE *in)
+{
+ struct item_bin *ib=(struct item_bin *) buffer;
+ int r,s;
+ r=fread(ib, sizeof(*ib), 1, in);
+ if (r != 1)
+ return NULL;
+ bytes_read+=r;
+ dbg_assert((ib->len+1)*4 < sizeof(buffer));
+ s=(ib->len+1)*4-sizeof(*ib);
+ r=fread(ib+1, s, 1, in);
+ if (r != 1)
+ return NULL;
+ bytes_read+=r;
+ return ib;
+}
+
+struct item_bin *
+read_item_range(FILE *in, int *min, int *max)
+{
+ struct range r;
+
+ if (fread(&r, sizeof(r), 1, in) != 1)
+ return NULL;
+ *min=r.min;
+ *max=r.max;
+ return read_item(in);
+}
+
+struct item_bin *
+init_item(enum item_type type)
+{
+ struct item_bin *ib=(struct item_bin *) buffer;
+
+ item_bin_init(ib, type);
+ return ib;
+}
diff --git a/navit/maptool/maptool.h b/navit/maptool/maptool.h
index 6de41b16e..da4a99bd2 100644
--- a/navit/maptool/maptool.h
+++ b/navit/maptool/maptool.h
@@ -142,8 +142,6 @@ void clip_polygon(struct item_bin *ib, struct rect *r, struct tile_parameter *pa
/* itembin.c */
-struct item_bin *read_item(FILE *in);
-struct item_bin *read_item_range(FILE *in, int *min, int *max);
int item_bin_read(struct item_bin *ib, FILE *in);
void item_bin_set_type(struct item_bin *ib, enum item_type type);
void item_bin_init(struct item_bin *ib, enum item_type type);
@@ -170,7 +168,10 @@ void item_bin_set_type_by_population(struct item_bin *ib, int population);
void item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, FILE *out);
int item_bin_sort_file(char *in_file, char *out_file, struct rect *r, int *size);
-
+/* itembin_buffer.c */
+struct item_bin *read_item(FILE *in);
+struct item_bin *read_item_range(FILE *in, int *min, int *max);
+struct item_bin *init_item(enum item_type type);
/* maptool.c */
diff --git a/navit/maptool/tile.c b/navit/maptool/tile.c
index 4e5d2b85e..810164490 100644
--- a/navit/maptool/tile.c
+++ b/navit/maptool/tile.c
@@ -511,7 +511,7 @@ write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out)
len--;
}
if (info->suffix[0] && info->write) {
- item_bin_init(item_bin, type_submap);
+ struct item_bin *item_bin=init_item(type_submap);
item_bin_add_coord_rect(item_bin, &world_bbox);
item_bin_add_attr_range(item_bin, attr_order, 0, 255);
item_bin_add_attr_int(item_bin, attr_zipfile_ref, zip_info->zipnum-1);
@@ -593,7 +593,8 @@ merge_tiles(struct tile_info *info)
void
index_init(struct zip_info *info, int version)
{
- item_bin_init(item_bin, type_map_information);
+ struct item_bin *item_bin;
+ item_bin=init_item(type_map_information);
item_bin_add_attr_int(item_bin, attr_version, version);
item_bin_write(item_bin, info->index);
}
@@ -605,6 +606,7 @@ index_submap_add(struct tile_info *info, struct tile_head *th)
int len=tlen;
char index_tile[len+1+strlen(info->suffix)];
struct rect r;
+ struct item_bin *item_bin;
strcpy(index_tile, th->name);
if (len > 6)
@@ -615,7 +617,7 @@ index_submap_add(struct tile_info *info, struct tile_head *th)
strcat(index_tile, info->suffix);
tile_bbox(th->name, &r, overlap);
- item_bin_init(item_bin, type_submap);
+ item_bin=init_item(type_submap);
item_bin_add_coord_rect(item_bin, &r);
item_bin_add_attr_range(item_bin, attr_order, (tlen > 4)?tlen-4 : 0, 255);
item_bin_add_attr_int(item_bin, attr_zipfile_ref, th->zipnum);