From 7923a9e0f6da9795157e8b946381f3c58d32ba98 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 24 Jan 2023 22:15:04 -0800 Subject: [PATCH] flight doesn't work yet. fixed 0x0a -> 0x0b. --- Makefile | 3 +- src/flight.h | 62 ++++++++++++++++ src/journal.re.c | 4 +- src/scan_flight.re.c | 171 +++++++++++++++++++++++++++++++++++++++++++ src/scan_kjv.re.c | 11 +-- 5 files changed, 240 insertions(+), 11 deletions(-) create mode 100644 src/flight.h create mode 100644 src/scan_flight.re.c diff --git a/Makefile b/Makefile index 4ff5afd..a9d26c3 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ else CF += -g endif -projects := bin/test-text bin/test-kjv bin/test-journal bin/kjv +projects := bin/test-text bin/test-kjv bin/test-journal bin/kjv bin/flight #docs := $(patsubst test/test_%.c, doc/%.md, $(wildcard test/test_*.c)) default: $(projects) @@ -39,6 +39,7 @@ bin/test-text: build/text.o build/test_text.o bin/test-kjv: build/text.o build/kjv.o build/test_kjv.o bin/test-journal: build/text.o build/journal.o build/test_journal.o bin/kjv: build/text.o build/journal.o build/kjv.o build/scan_kjv.o +bin/flight: build/text.o build/journal.o build/scan_flight.o bin/%: @echo "\033[1;36mlinking $@\033[0m" diff --git a/src/flight.h b/src/flight.h new file mode 100644 index 0000000..8f77f6d --- /dev/null +++ b/src/flight.h @@ -0,0 +1,62 @@ +#ifndef OMIT_BASE /* */ + + +#ifndef OMIT_VERSES /* */ + + +#ifndef OMIT_PROTO /* */ diff --git a/src/journal.re.c b/src/journal.re.c index fa70c0d..9cc9e6f 100644 --- a/src/journal.re.c +++ b/src/journal.re.c @@ -205,7 +205,9 @@ struct journal journal(void) { /*if(*y == 1993) break;*/ } if(chdir("..") == -1 || !day_tree_bulk_finish(&j.days)) goto catch; - /* Structure is now stable. */ + + /* Structure is now stable because we aren't going to move it; + convert all of offsets to pointers. */ it = day_tree_begin(&j.days); while(day_tree_next(&it, 0, &v)) { /*printf("%zu\n", v->offset);*/ v->text = j.backing.a.data + v->offset; diff --git a/src/scan_flight.re.c b/src/scan_flight.re.c new file mode 100644 index 0000000..a145b4b --- /dev/null +++ b/src/scan_flight.re.c @@ -0,0 +1,171 @@ +/** @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/helper.h" +#include /* C99 */ +#include +#include +#include +#include + +struct substring { const char *str; int len; }; + +/** type, reg, launch, how, height, landing, pilot_min, dual_min, instr_min, + remarks */ +struct glider { + struct substring type, reg, launch; + enum launch how; + unsigned height_ft, pilot_min, dual_min, instr_min; + struct substring remarks; +}; + +/** type, reg, launch -- landing, pilot, copilot, dual_min, pilot_min, + ifrsim_min, ifr_min, remarks */ +struct power { + struct substring type, reg, launch, landing, pilot, copilot; + unsigned dual_min, pilot_min, ifrsim_min, ifr_min; + struct substring remarks; +}; + +/** Could be a glider or power. */ +struct flight { + enum { GLIDER, POWER } type; + union { struct glider glider; struct power power; }; +}; + +struct flights { +}; + +/*!conditions:re2c*/ + +static int scan(union date32 date, const char *const buffer, + struct flights *const f) { + const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *yyt3, *s0, *s1, *t0, *t1; + enum flight_type type = Glider; + 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\x0b-\x1f\x7f]; + ws = [ \t]; + glyph = [^] \ ("\x00" | "\n" | unix_control | ws); + natural = [1-9][0-9]*; + lookat = ws* natural ":" natural [ab]? ("-" natural [ab]?)? engage; + */ + 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? */ + "[glider]" :=> glider + "[flight]" :=> flight + /* "M" - Motor Car Tow + "W" - Winch + "A" - Aero Tow */ + /* type; registration; launch -- landing; pic; sic; + single engine day dual; pilot; instrument simulated; actual; remarks */ + * { 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 { + 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; + } + 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); + } + 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; + 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; + 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 in KJV\"\n" + "set format y \"%%g%%%%\"\n" + "set key top left\n" + "set grid\n" + "unset border\n" + "#set style fill solid 0.1 #pattern 5 (better, but restarts)\n" + "plot $Data using 1:($3)*100/%zu with fillsteps lw 2 title \"set\", \\\n" + "$Data using 1:($4)*100/%zu with steps lw 1 title \"cumulative\"\n", + kj.words.total, kj.words.total); + goto finally; +catch: + success = EXIT_FAILURE; + perror("journal"); +finally: + journal_(&j); + return success; +} diff --git a/src/scan_kjv.re.c b/src/scan_kjv.re.c index 2c7b689..a99ea77 100644 --- a/src/scan_kjv.re.c +++ b/src/scan_kjv.re.c @@ -33,7 +33,7 @@ static int scan(union date32 date, const char *const buffer, re2c:define:YYGETCONDITION:naked = 1; re2c:define:YYSETCONDITION:naked = 1; - unix_control = [\x01-\x08\x0a-\x1f\x7f]; + unix_control = [\x01-\x08\x0b-\x1f\x7f]; ws = [ \t]; glyph = [^] \ ("\x00" | "\n" | unix_control | ws); natural = [1-9][0-9]*; @@ -185,11 +185,6 @@ int main(void) { 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)); @@ -197,10 +192,8 @@ int main(void) { "set output \"kjv.eps\"\n" "$Data <text, &kj)) goto catch; - /*if(++i > 32) break;*/ - } printf("EOD\n" "set monochrome\n" "set xdata time\n"