]> mj.ucw.cz Git - leo.git/commitdiff
Shapefiles: Improved debug output
authorMartin Mares <mj@ucw.cz>
Mon, 1 Jun 2015 14:08:16 +0000 (16:08 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 7 Jun 2015 13:18:37 +0000 (15:18 +0200)
shp.c

diff --git a/shp.c b/shp.c
index 0e0ff54a0cdb6ada76e236a541ab6b2f2e077520..34f9b321721943aba6e3565842d491cffa37eb42 100644 (file)
--- a/shp.c
+++ b/shp.c
@@ -1,7 +1,7 @@
 /*
  *     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.
@@ -86,24 +86,28 @@ void shp_parse(const char *name)
     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);
     }