From 0039d6d297a94b2ea227a3fce675b66ce654cd1a Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 17 Feb 2023 14:06:21 -0800 Subject: [PATCH] jounal_is_valid removed -- check errno --- src/flight.re.c | 3 +-- src/journal.h | 2 +- src/journal.re.c | 13 ++++++------- src/scan_kjv.re.c | 4 +++- src/source.re.c | 3 +-- test/test_journal.c | 4 +++- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/flight.re.c b/src/flight.re.c index d1b97a0..08046c2 100644 --- a/src/flight.re.c +++ b/src/flight.re.c @@ -212,8 +212,7 @@ static int scan(struct flights *const f, catch: if(!errno) errno = EILSEQ; date32_to_string(date, &datestr); - fprintf(stderr, "%s\n" - "%s line %zu: %s.\n", text, datestr, line, why); + fprintf(stderr, "%s line %zu: %s.\n", datestr, line, why); return 0; } /** Dynamic memory allocation for `f` will be zero, will diff --git a/src/journal.h b/src/journal.h index 8fe894a..dd226d9 100644 --- a/src/journal.h +++ b/src/journal.h @@ -35,7 +35,7 @@ struct journal { struct day_tree days; struct text backing; }; struct journal_iterator { struct day_tree_iterator _; }; struct journal journal(void); void journal_(struct journal *); -//int journal_is_valid(const struct journal *); +/*int journal_is_valid(const struct journal *);*/ const char *journal_to_string(const struct journal *); struct journal_iterator journal_iterator(struct journal *const j); int journal_next(struct journal_iterator *, union date32 *, const char **); diff --git a/src/journal.re.c b/src/journal.re.c index 98d95d1..cb81538 100644 --- a/src/journal.re.c +++ b/src/journal.re.c @@ -102,8 +102,7 @@ static unsigned looks_like_day(const char *const a) { #define PROTO #include "../src/journal.h" /* Just prototypes. */ -/** Dynamic memory allocation for `j` will be zero, will - be false. */ +/** Erases memory allocation for `j`. */ void journal_(struct journal *const j) { if(!j) return; day_tree_(&j->days); @@ -176,8 +175,8 @@ struct journal journal(void) { } if(closedir(dir)) { dir = 0; goto catch; } dir = 0; qsort(days.data, days.size, sizeof *days.data, &void_int_cmp); - fprintf(stderr, "Days in <<%s>>: %s.\n", - fn, int_array_to_string(&days)); + /*fprintf(stderr, "Days in <<%s>>: %s.\n", + fn, int_array_to_string(&days)); <- Too much spam. */ for(d = days.data, d_end = d + days.size; d < d_end; d++) { const union date32 d32 = { .year = (uint32_t)*y, @@ -216,7 +215,7 @@ struct journal journal(void) { goto finally; catch: fprintf(stderr, "On date: %s/%d-%.2d-%.2d.\n", - dir_journal, y ? *y : 0, m ? *m : 0, d ? *d : 0 ); + dir_journal, y ? *y : 0, m ? *m : 0, d ? *d : 0); if(intent) fprintf(stderr, "(%s)\n", intent); recatch: journal_(&j); @@ -227,9 +226,9 @@ finally: } /** @return `j` read in some data? */ -int journal_is_valid(const struct journal *const j) { +/*int journal_is_valid(const struct journal *const j) { return j && j->days.root.node && j->backing.a.data; -} +}*/ /** @return `j` as a string. */ const char *journal_to_string(const struct journal *const j) diff --git a/src/scan_kjv.re.c b/src/scan_kjv.re.c index 2d37843..f23c663 100644 --- a/src/scan_kjv.re.c +++ b/src/scan_kjv.re.c @@ -184,13 +184,15 @@ catch: int main(void) { int success = EXIT_SUCCESS; + errno = 0; struct journal j; struct journal_iterator it; struct kjv bible = kjv(); + if(errno) goto catch; union date32 k; const char *v; j = journal(); - if(!journal_is_valid(&j)) goto catch; + if(errno) goto catch; fprintf(stderr, "Journal: %s.\n", journal_to_string(&j)); printf("set term postscript eps enhanced\n" "set output \"kjv.eps\"\n" diff --git a/src/source.re.c b/src/source.re.c index 1e8e016..2518d09 100644 --- a/src/source.re.c +++ b/src/source.re.c @@ -134,8 +134,7 @@ static int scan(union date32 date, const char *const buffer, catch: if(!errno) errno = EILSEQ; date32_to_string(date, &datestr); - fprintf(stderr, "%s\n" - "%s line %zu: %s.\n", buffer, datestr, line, why); + fprintf(stderr, "%s line %zu: %s.\n", datestr, line, why); return 0; } /** Dynamic memory allocation for `s` will be zero. */ diff --git a/test/test_journal.c b/test/test_journal.c index 27edc00..3c42796 100644 --- a/test/test_journal.c +++ b/test/test_journal.c @@ -3,11 +3,13 @@ #include /* C99 */ #include #include +#include int main(void) { + errno = 0; struct journal j = journal(); int success = EXIT_SUCCESS; - if(!journal_is_valid(&j)) goto catch; + if(errno) goto catch; printf("Journal: %s.\n", journal_to_string(&j)); { struct journal_iterator it = journal_iterator(&j);