From 80c95adfe6ae9542f91c069d9f6e871c79453929 Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 15 Mar 2023 20:10:12 -0700 Subject: [PATCH] doesn't work, but compiles --- Makefile | 4 +-- src/kjv.re.c | 92 ++++++++++++++++++++++++++++--------------------- src/kjvcount.h | 3 ++ src/source.h | 1 + src/source.re.c | 3 ++ 5 files changed, 61 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 034a790..2c65f9a 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ bin/test-text: build/text.o build/test_text.o bin/test-journal: build/text.o build/journal.o build/test_journal.o bin/test-source: build/text.o build/pair.o build/journal.o build/source.o build/test_source.o bin/test-kjv: build/text.o build/pair.o build/kjvcount.o build/test_kjv.o -bin/kjv: build/text.o build/pair.o build/journal.o build/kjvcount.o build/kjv.o +bin/kjv: build/text.o build/pair.o build/journal.o build/kjvcount.o build/kjv.o build/source.o bin/flight: build/text.o build/pair.o build/journal.o build/source.o build/flights.o build/flighthours.o bin/%: @@ -71,7 +71,7 @@ build/%.c: src/%.re.c # # https://github.com/neil-edelman/cdoc documentation # -cdoc -o $@ $< -.SECONDARY: build/kjv.c build/journal.c build/source.c build/scan_kjv.c build/flight.c +.SECONDARY: build/kjv.c build/journal.c build/source.c build/scan_kjv.c build/flight.c build/kjvcount.c .PHONY: clean release test test: $(projects) diff --git a/src/kjv.re.c b/src/kjv.re.c index d0c3c11..50318a4 100644 --- a/src/kjv.re.c +++ b/src/kjv.re.c @@ -193,8 +193,9 @@ catch: { char datestr[12]; date32_to_string(date, &datestr); - fprintf(stderr, "%s\n" - "%s line %zu: %s.\n", buffer, datestr, line, why); + fprintf(stderr, "KJV lines: %s.\n" + "%s line %zu: %s.\n", + kjvline_tree_to_string(lines), datestr, line, why); } return 0; } @@ -221,11 +222,11 @@ finally: int kjv_line_is_empty(const struct kjvline_tree *const lines) { return !lines || !lines->root.node; } -const char *kjv_line_to_string(const struct kjvline_tree *const kl) - { return kjvline_tree_to_string(kl); } +const char *kjv_line_to_string(const struct kjvline_tree *const lines) + { return kjvline_tree_to_string(lines); } -struct kjvline_tree_iterator kjv_line_iterator(struct kjvline_tree *const kl) - { return kjvline_tree_iterator(kl); } +struct kjvline_tree_iterator kjv_line_iterator(struct kjvline_tree *const lines) + { return kjvline_tree_iterator(lines); } int kjv_line_next(struct kjvline_tree_iterator *const it, union line64 *const k, const struct kjvrange **const v) { @@ -241,52 +242,63 @@ int kjv_line_next(struct kjvline_tree_iterator *const it, union line64 *const k, -#if 0 -char citestr[12], datestr[12]; -const struct source *src = source_lookup(&s, line); -assert(src); if(!src->name.a) { errno = EDOM; goto catch; } -kjvcite_to_string(cite, &citestr); -for( ; ; cite.verse++) { - if(!kjv_add(kj, cite)) return 0; - if(!verse_end || verse_end <= cite.verse) break; -} -date32_to_string(date, &datestr); -printf("%s\t%zu\t%zu\t%zu\t# ", - datestr, kj->words.verse, kj->words.set, kj->words.cumulative); -if(verse_end) { - printf("%s-%" PRIu32 "\n", citestr, verse_end); -} else { - printf("%s\n", citestr); -} - -#endif +#include "../src/source.h" int main(void) { int success = EXIT_SUCCESS; - const char *reason = "unknown"; + const char *reason = 0; errno = 0; struct kjvcount count = kjvcount(); - if(kjvcount_is_empty(&count)) { reason = "kjv failed to load"; goto catch; } + fprintf(stderr, "KJV count: %s.\n", kjvcount_to_string(&count)); + if(kjvcount_is_empty(&count)) + { reason = "kjv failed to load"; goto catch; } - struct journal j = journal(); - if(journal_is_empty(&j)) { reason = "journal failed to load"; goto catch; } - fprintf(stderr, "Journal: %s.\n", journal_to_string(&j)); + struct journal jrnl = journal(); + fprintf(stderr, "Journal: %s.\n", journal_to_string(&jrnl)); + if(journal_is_empty(&jrnl)) + { reason = "journal failed to load"; goto catch; } - struct kjvline_tree lines = kjv_line(&j); - if(kjv_line_is_empty(&lines)) { reason = "parsing failed"; goto catch; } - fprintf(stderr, "Lines: %s.\n", kjv_line_to_string(&lines)); + struct sources srcs = sources(&jrnl); + //fprintf(stderr, "Sources: %s.\n", sources_to_string(&srcs)); + if(sources_is_empty(&srcs)) + { reason = "sources failed to parse"; goto catch; } - struct journal_iterator it; - union date32 k; - const char *v; + struct kjvline_tree lines = kjv_line(&jrnl); + fprintf(stderr, "KJV lines: %s.\n", kjv_line_to_string(&lines)); + if(kjv_line_is_empty(&lines)) + { reason = "KJV lines parsing failed"; goto catch; } + + struct kjvline_tree_iterator it = kjv_line_iterator(&lines); + union line64 line; + const struct kjvrange *range; printf("set term postscript eps enhanced\n" "set output \"kjv.eps\"\n" "$Data <name.a) { errno = EDOM; goto catch; } + kjvcite_to_string(range->start, &citestr); +#if 0 + //fixme + for( ; ; cite.verse++) { + if(!kjv_add(kj, cite)) return 0; + if(!verse_end || verse_end <= cite.verse) break; + } + date32_to_string(date, &datestr); + printf("%s\t%zu\t%zu\t%zu\t# ", + datestr, kj->words.verse, kj->words.set, kj->words.cumulative); + if(verse_end) { + printf("%s-%" PRIu32 "\n", citestr, verse_end); + } else { + printf("%s\n", citestr); + } + printf("%d-%.2d-%.2d:%u-%u %s\n"); +#endif + } printf("EOD\n" "set monochrome\n" "set xdata time\n" @@ -305,10 +317,10 @@ int main(void) { catch: success = EXIT_FAILURE; perror("journal"); - fprintf(stderr, "Details: %s.\n", reason); + if(reason) fprintf(stderr, "Details: %s.\n", reason); finally: kjv_line_(&lines); kjvcount_(&count); - journal_(&j); + journal_(&jrnl); return success; } diff --git a/src/kjvcount.h b/src/kjvcount.h index bfae61b..2e4eadb 100644 --- a/src/kjvcount.h +++ b/src/kjvcount.h @@ -112,6 +112,9 @@ void kjvcount_(struct kjvcount *); struct kjvcount kjvcount(void); int kjvcount_is_empty(const struct kjvcount *); const char *kjvcount_to_string(const struct kjvcount *); + + +/* FIXME: this should be in something else. */ struct kjvset_table kjv_set(void); void kjv_set_(struct kjvset_table *); int kjv_set_add(struct kjvset_table *const set, diff --git a/src/source.h b/src/source.h index 4b03329..ed72a5f 100644 --- a/src/source.h +++ b/src/source.h @@ -39,6 +39,7 @@ struct sources { struct source *sources_add(struct sources *, const union line64); struct sources sources(struct journal *); void sources_(struct sources *); +int sources_is_empty(const struct sources *); const char *sources_to_string(const struct sources *); const struct source *source_lookup(struct sources *s, const union line64 range); #endif /* proto --> */ diff --git a/src/source.re.c b/src/source.re.c index 2518d09..2659c75 100644 --- a/src/source.re.c +++ b/src/source.re.c @@ -170,6 +170,9 @@ finally: return s; } +int sources_is_empty(const struct sources *const s) + { return !s || !s->dates.root.node; } + /** Lookup the last source in `range` in sources `s`. They are invalidated on adding a source, (probably fine.) */ const struct source *source_lookup(struct sources *const s,