/** @license 2022 Neil Edelman, distributed under the terms of the [MIT License](https://opensource.org/licenses/MIT). Scan journal entries for kjv references. */ #include "../src/journal.h" #include "../src/kjv.h" #include "../src/helper.h" #include /* C99 */ #include #include #include #include /*!conditions:re2c*/ static int scan(union date32 date, const char *const buffer, struct kjv *const kj) { const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *yyt3, *s0, *s1, *t0, *t1; enum kjv_book book = Revelation; uint32_t chapter = 0, verse = 0, verse_end = 0; enum YYCONDTYPE condition = yycline; size_t line = 1; char datestr[12] = {0}; const char *why = "unexpected"; assert(buffer && kj); YYCURSOR = YYMARKER = yyt1 = buffer; /*!re2c /**/ re2c:define:YYCTYPE = char; re2c:yyfill:enable = 0; re2c:define:YYGETCONDITION = "condition"; re2c:define:YYSETCONDITION = "condition = @@;"; re2c:define:YYGETCONDITION:naked = 1; re2c:define:YYSETCONDITION:naked = 1; unix_control = [\x01-\x08\x0a-\x1f\x7f]; ws = [ \t]; glyph = [^] \ ("\x00" | "\n" | unix_control | ws); natural = [1-9][0-9]*; engage = ws+ "--" ws+; /* (natural ":")? Don't use for memorizing and use for reading, I think? */ /*("``"|"\"") This is not in the next book. */ lookat = ws* natural ":" natural [ab]? ("-" natural [ab]?)? engage; first = ("I" | "1") " "?; second = ("II" | "2") " "?; third = ("III" | "3") " "?; */ for( ; ; ) { /*!re2c /**/ [^\n\x00] { continue; } "\x00" { why = "no newline at end of file"; goto catch; } "\n" => line { line++; continue; } "\x00" { return 1; } "\n" { line++; continue; } * :=> skip /* Guess it can't be simplified? */ "Genesis" / lookat => book { book = Genesis; continue; } "Exodus" / lookat => book { book = Exodus; continue; } "Leviticus" / lookat => book { book = Leviticus; continue; } "Numbers" / lookat => book { book = Numbers; continue; } "Deuteronomy" / lookat => book { book = Deuteronomy; continue; } "Joshua" / lookat => book { book = Joshua; continue; } "Judges" / lookat => book { book = Judges; continue; } "Ruth" / lookat => book { book = Ruth; continue; } first "Samuel" / lookat => book { book = ISamuel; continue; } second "Samuel" / lookat => book { book = IISamuel; continue; } first "Kings" / lookat => book { book = IKings; continue; } second "Kings" / lookat => book { book = IIKings; continue; } first "Chronicles" / lookat => book { book = IChronicles; continue; } second "Chronicles" / lookat => book { book = IIChronicles; continue; } "Ezra" / lookat => book { book = Ezra; continue; } "Nehemiah" / lookat => book { book = Nehemiah; continue; } "Esther" / lookat => book { book = Esther; continue; } "Job" / lookat => book { book = Job; continue; } "Psalms" / lookat => book { book = Psalms; continue; } "Proverbs" / lookat => book { book = Proverbs; continue; } "Ecclesiastes" / lookat => book { book = Ecclesiastes; continue; } "Song of Solomon" / lookat => book { book = Song_of_Solomon; continue; } "Isaiah" / lookat => book { book = Isaiah; continue; } "Jeremiah" / lookat => book { book = Jeremiah; continue; } "Lamentations" / lookat => book { book = Lamentations; continue; } "Ezekiel" / lookat => book { book = Ezekiel; continue; } "Daniel" / lookat => book { book = Daniel; continue; } "Hosea" / lookat => book { book = Hosea; continue; } "Joel" / lookat => book { book = Joel; continue; } "Amos" / lookat => book { book = Amos; continue; } "Obadiah" / lookat => book { book = Obadiah; continue; } "Jonah" / lookat => book { book = Jonah; continue; } "Micah" / lookat => book { book = Micah; continue; } "Nahum" / lookat => book { book = Nahum; continue; } "Habakkuk" / lookat => book { book = Habakkuk; continue; } "Zephaniah" / lookat => book { book = Zephaniah; continue; } "Haggai" / lookat => book { book = Haggai; continue; } "Zechariah" / lookat => book { book = Zechariah; continue; } "Malachi" / lookat => book { book = Malachi; continue; } "Matthew" / lookat => book { book = Matthew; continue; } "Mark" / lookat => book { book = Mark; continue; } "Luke" / lookat => book { book = Luke; continue; } "John" / lookat => book { book = John; continue; } "Acts" / lookat => book { book = Acts; continue; } "Romans" / lookat => book { book = Romans; continue; } first "Corinthians" / lookat => book { book = ICorinthians; continue; } second "Corinthians" / lookat => book { book = IICorinthians; continue; } "Galatians" / lookat => book { book = Galatians; continue; } "Ephesians" / lookat => book { book = Ephesians; continue; } "Philippians" / lookat => book { book = Philippians; continue; } "Colossians" / lookat => book { book = Colossians; continue; } first "Thessalonians" / lookat => book { book = IThessalonians; continue; } second "Thessalonians" / lookat => book { book = IIThessalonians; continue; } first "Timothy" / lookat => book { book = ITimothy; continue; } second "Timothy" / lookat => book { book = IITimothy; continue; } "Titus" / lookat => book { book = Titus; continue; } "Philemon" / lookat => book { book = Philemon; continue; } "Hebrews" / lookat => book { book = Hebrews; continue; } "James" / lookat => book { book = James; continue; } first "Peter" / lookat => book { book = IPeter; continue; } second "Peter" / lookat => book { book = IIPeter; continue; } first "John" / lookat => book { book = IJohn; continue; } second "John" / lookat => book { book = IIJohn; continue; } third "John" / lookat => book { book = IIIJohn; continue; } "Jude" / lookat => book { book = Jude; continue; } "Revelation" / lookat => book { book = Revelation; continue; } * { why = "default unrecognized"; goto catch; } /* 19:15a, just ignore the a. */ ws+ @s0 natural @s1 ":" @t0 natural @t1 [ab]? { if(chapter || verse || verse_end) { why = "reference unrecognized"; goto catch; } if(!helper_natural(s0, s1, &chapter) || !helper_natural(t0, t1, &verse)) { why = "reference numerical error"; goto catch; } continue; } "-" @s0 natural @s1 [ab]? { /* Verse range. */ if(!chapter || !verse || verse_end) { why = "range unrecognized"; goto catch; } if(!helper_natural(s0, s1, &verse_end)) { why = "range numerical error"; goto catch; } continue; } engage => skip { const size_t old_set_words = kj->words.set; char citestr[12]; if(!chapter || !verse) { why = "missing information"; goto catch; } if(verse_end && verse_end <= verse) { why = "interval error"; goto catch; } union kjvcite cite = { .book = book, .chapter = chapter, .verse = verse }; if(!datestr[0]) date32_to_string(date, &datestr); /* Only once. */ kjvcite_to_string(cite, &citestr); for( ; ; verse++, cite.verse++) { if(!kjv_add(kj, cite)) { why = "add to set"; goto catch; } if(!verse_end || verse_end <= verse) break; } if(verse_end) { printf("%s\t%zu\t%zu\t# %s-%" PRIu32 "\n", datestr, old_set_words, kj->words.set, citestr, verse_end); } else { printf("%s\t%zu\t%zu\t# %s\n", datestr, old_set_words, kj->words.set, citestr); } book = Revelation, chapter = 0, verse = 0, verse_end = 0; continue; } */ } assert(0); /* Never gets here. */ catch: if(!errno) errno = EILSEQ; date32_to_string(date, &datestr); fprintf(stderr, "%s\n" "%s line %zu: %s.\n", buffer, datestr, line, why); return 0; } int main(void) { int success = EXIT_SUCCESS; struct journal j; struct journal_iterator it; struct kjv kj = kjv(); union date32 k; union load *v; size_t i; /*scan((union date32){.year=2000, .month=1, .day=1}, "\n\n\n" "Romans 3:23 -- ``For all have sinned, " "and come short of the glory of God.''\n", &kj);*/ /* FIXME: have a column with the number so we can see how much uniqueness makes a difference. */ j = journal(); if(!journal_is_valid(&j)) goto catch; fprintf(stderr, "Journal: %s.\n", journal_to_string(&j)); printf("set term postscript eps enhanced\n" "set output \"kjv.eps\"\n" "$Data <text, &kj)) goto catch; /*if(++i > 32) break;*/ } printf("EOD\n" "set monochrome\n" "set xdata time\n" "set timefmt \"%%Y-%%m-%%d\"\n" "set xtics format \"%%Y-%%m-%%d\" rotate by -30\n" "set ylabel \"words\"\n" "set format y \"%%g%%%%\"\n" "unset key #set key bottom right\n" "set grid\n" "unset border\n" "plot $Data using 1:($3-$2)*100/%zu smooth cumulative " "with steps lw 2\n", kj.words.total); goto finally; catch: success = EXIT_FAILURE; perror("journal"); finally: journal_(&j); return success; }