# HG changeset patch # User Matti Hamalainen # Date 1509324785 -7200 # Node ID 7ac4874664568779a7091fc049d4f68864d43375 # Parent daf7dcc635d67fd15d2a96b7bec7ad0be6af1111 Fixes to the block parsing. diff -r daf7dcc635d6 -r 7ac487466456 mapsearch.c --- a/mapsearch.c Mon Oct 30 01:45:23 2017 +0200 +++ b/mapsearch.c Mon Oct 30 02:53:05 2017 +0200 @@ -454,92 +454,55 @@ { size_t offs = 0; int x = 0, x2 = 0; - BOOL flag = TRUE; - *height = 0; - *width = -1; + *width = *height = 0; while (offs < len) { - const unsigned char c = data[offs++]; - if (c == '\n') + const unsigned char ch = data[offs++]; + if (ch == '\n') { - if (x == 0) - return; - if (x > *width) *width = x; + (*height)++; x = x2 = 0; - flag = TRUE; } else { - if (flag) - { - (*height)++; - flag = FALSE; - } x2++; - if (c != ' ') + if (ch != ' ') x = x2; } } + if (x > *width) + *width = x; + if (x > 0) (*height)++; - - if (x > *width) - *width = x; } BOOL mapBlockParse(const unsigned char *data, const size_t len, MapBlock *res) { - unsigned char *dp = res->data; size_t offs = 0; - BOOL flag = FALSE; - int x = 0, y = 0; - - while (offs < len && y < res->height) - { - const unsigned char c = data[offs++]; - if (c == '\n') - { - if (x == 0) - return TRUE; - else - if (x != res->width) - { - THERR("Broken block line #%d width %d != %d!\n", - y, x, res->width); - return FALSE; - } - flag = TRUE; - } - else + for (int yc = 0; yc < res->height; yc++) + { + unsigned char *dp = res->data + (yc * res->scansize); + for (int xc = 0; xc < res->width; xc++) { - if (flag) + if (offs < len) { - x = 0; - y++; - dp = res->data + (y * res->scansize); - flag = FALSE; - } - dp[x++] = c; - - if (x > res->scansize) - { - THERR("Broken block line #%d width %d > scansize %d!\n", - y, x, res->scansize); - - return FALSE; + dp[xc] = data[offs++]; } } + while (offs < len && data[offs] != '\n') + offs++; } - return TRUE; + return offs == len; }