/*
* Hic Est Leo -- Reading ESRI Shape Files
*
- * (c) 2014 Martin Mares <mj@ucw.cz>
+ * (c) 2014--2015 Martin Mares <mj@ucw.cz>
*
* FIXME: Currently, this parser handles only the subset
* of shape file syntax which is used by gdal_contours.
#undef LOCAL_DEBUG
-#include <ucw/lib.h>
+#include "leo.h"
+#include "osm.h"
+#include "map.h"
+#include "shp.h"
+
#include <ucw/conf.h>
#include <ucw/fastbuf.h>
#include <ucw/gary.h>
#include <fcntl.h>
#include <stdio.h>
-#include "leo.h"
-#include "osm.h"
-#include "map.h"
-#include "shp.h"
-
static osm_id_t shp_id_counter;
static double shp_get_double(byte *p)
die("Unsupported shape file type %u", type);
u32 last_recno = 0;
- while (len = bread(fb, buf, 8))
+ for (;;)
{
+ u64 pos = btell(fb);
+ uns len = bread(fb, buf, 8);
+ if (!len)
+ break;
if (len != 8)
- die("Truncated record header");
+ die("Truncated record header at %ju", (uintmax_t) pos);
u32 recno = get_u32_be(buf);
u32 reclen = get_u32_be(buf+4) * 2;
- DBG("@%ju: recno %u len %u", (uintmax_t) btell(fb) - 8, recno, reclen);
if (recno != ++last_recno)
- die("Unexpected record #%u, should be #%u", recno, last_recno);
+ die("Unexpected record #%u (should be #%u) at %ju", recno, last_recno, (uintmax_t) pos);
if (reclen > GARY_SIZE(buf))
GARY_RESIZE(buf, reclen);
len = bread(fb, buf, reclen);
if (len != reclen)
- die("Truncated record: %u < %u", len, reclen);
+ die("Truncated record: %u < %u at %ju", len, reclen, (uintmax_t) pos);
if (len < 4)
- die("Record too short: %u bytes", reclen);
+ die("Record too short: %u bytes at %ju", reclen, (uintmax_t) pos);
u32 rectype = get_u32_le(buf);
+ DBG("@%ju: recno=%u len=%u type=%u", (uintmax_t) pos, recno, reclen, rectype);
if (rectype == 3)
shp_record_polyline(buf, len);
}