print lineno

This commit is contained in:
Love Hornquist Astrand
2009-10-11 12:18:22 -07:00
parent d36402a671
commit 983d0f66f1

View File

@@ -68,7 +68,7 @@ parse_vector(char *buf, uint32_t *v)
} }
static int static int
test(char *buf) test(char *buf, unsigned lineno)
{ {
char *last; char *last;
char *c; char *c;
@@ -95,9 +95,7 @@ test(char *buf)
out_len = parse_vector(c, out); out_len = parse_vector(c, out);
if (strtok_r(NULL, ";", &last) == NULL) if (strtok_r(NULL, ";", &last) == NULL)
return 0; return 0;
c = strtok_r(NULL, ";", &last); c = last;
if (c == NULL)
return 0;
norm_len = MAX_LENGTH_CANON; norm_len = MAX_LENGTH_CANON;
tmp = malloc(norm_len * sizeof(size_t)); tmp = malloc(norm_len * sizeof(size_t));
@@ -110,12 +108,12 @@ test(char *buf)
return 1; return 1;
} }
if (out_len != norm_len) { if (out_len != norm_len) {
printf("wrong out len (%s)\n", c); printf("%u: wrong out len (%s)\n", lineno, c);
free(tmp); free(tmp);
return 1; return 1;
} }
if (memcmp(out, tmp, out_len * sizeof(uint32_t)) != 0) { if (memcmp(out, tmp, out_len * sizeof(uint32_t)) != 0) {
printf("wrong out data (%s)\n", c); printf("%u: wrong out data (%s)\n", lineno, c);
free(tmp); free(tmp);
return 1; return 1;
} }
@@ -130,6 +128,7 @@ main(int argc, char **argv)
char buf[1024]; char buf[1024];
char filename[256] = "NormalizationTest.txt"; char filename[256] = "NormalizationTest.txt";
unsigned failures = 0; unsigned failures = 0;
unsigned lineno = 0;
if (argc > 2) if (argc > 2)
errx(1, "usage: %s [file]", argv[0]); errx(1, "usage: %s [file]", argv[0]);
@@ -148,12 +147,13 @@ main(int argc, char **argv)
err(1, "open %s", filename); err(1, "open %s", filename);
} }
while (fgets(buf, sizeof(buf), f) != NULL) { while (fgets(buf, sizeof(buf), f) != NULL) {
lineno++;
if (buf[0] == '#') if (buf[0] == '#')
continue; continue;
if (buf[0] == '@') { if (buf[0] == '@') {
continue; continue;
} }
failures += test(buf); failures += test(buf, lineno);
} }
fclose(f); fclose(f);
return failures != 0; return failures != 0;