From 971515ccc91e4a044ecc441a08175247302c9256 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 5 Aug 2007 16:22:41 +0000 Subject: [PATCH] (xundump): Count lines in a saner way: pass line number in and out. Callers changed. --- include/prototypes.h | 2 +- src/lib/common/conftab.c | 10 ++++++---- src/lib/common/xundump.c | 11 +++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/prototypes.h b/include/prototypes.h index f251d424..ef148761 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -348,7 +348,7 @@ extern int demand_update_want(int *, int *, int); extern int demand_check(void); extern int demandupdatecheck(void); /* xundump.c */ -extern int xundump(FILE *, char *, int); +extern int xundump(FILE *, char *, int *, int); /* * src/lib/gen/ *.c diff --git a/src/lib/common/conftab.c b/src/lib/common/conftab.c index 53505e43..0e596d97 100644 --- a/src/lib/common/conftab.c +++ b/src/lib/common/conftab.c @@ -48,7 +48,7 @@ read_builtin_tables(void) { struct empfile *ep; FILE *fp; - int res; + int lineno, res; /* * Need to read config files for tables referenced through @@ -62,7 +62,8 @@ read_builtin_tables(void) ep->file, strerror(errno)); return -1; } - res = xundump(fp, ep->file, ep->uid); + lineno = 1; + res = xundump(fp, ep->file, &lineno, ep->uid); if (res >= 0 && getc(fp) != EOF) { fprintf(stderr, "%s: Junk after the table\n", ep->file); @@ -104,7 +105,7 @@ read_custom_tables(void) static int read_custom_table_file(char *fname) { - int res, n; + int lineno, res, n; FILE *fp; if (!(fp = fopen(fname, "r"))) { @@ -113,7 +114,8 @@ read_custom_table_file(char *fname) return -1; } - for (n = 0; (res = xundump(fp, fname, EF_BAD)) >= 0; n++) + lineno = 1; + for (n = 0; (res = xundump(fp, fname, &lineno, EF_BAD)) >= 0; n++) empfile[res].flags |= EFF_CUSTOM; if (res != EF_BAD && n == 0) fprintf(stderr, "Warning: configuration file %s is empty\n", fname); diff --git a/src/lib/common/xundump.c b/src/lib/common/xundump.c index 44590591..76c6912b 100644 --- a/src/lib/common/xundump.c +++ b/src/lib/common/xundump.c @@ -29,7 +29,7 @@ * * Known contributors to this file: * Ron Koenderink, 2005 - * Markus Armbruster, 2005-2006 + * Markus Armbruster, 2005-2007 */ /* @@ -737,15 +737,13 @@ xutrailer(FILE *fp, int type, int row) } int -xundump(FILE *fp, char *file, int expected_table) +xundump(FILE *fp, char *file, int *plno, int expected_table) { struct castr *ca; int type, nca, nf, i, ch; - if (fname != file) { - fname = file; - lineno = 1; - } + fname = file; + lineno = *plno; if ((type = xuheader(fp, expected_table)) < 0) return type; @@ -779,6 +777,7 @@ xundump(FILE *fp, char *file, int expected_table) lineno++; ungetc(ch, fp); + *plno = lineno; return type; }