From aec01b255ee176cdaf0d1a7b16d105fea6ba4cf9 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 12 Feb 2023 20:53:15 -0800 Subject: [PATCH] flights got closer to woking --- Makefile | 2 +- src/flight.re.c | 58 ++++++++++++++++++++++++++++++++++------------- src/flighthours.c | 14 ++++++++---- src/pair.c | 7 ++++++ src/pair.h | 5 ++++ 5 files changed, 65 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 559b351..6bd1880 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ 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/kjv.o build/test_kjv.o bin/kjv: build/text.o build/pair.o build/journal.o build/kjv.o build/scan_kjv.o -bin/flight: build/text.o build/pair.o build/journal.o build/flight.o build/flighthours.o +bin/flight: build/text.o build/pair.o build/journal.o build/source.o build/flight.o build/flighthours.o bin/%: @echo "\033[1;36mlinking $@\033[0m" diff --git a/src/flight.re.c b/src/flight.re.c index aa4059d..6d52fe7 100644 --- a/src/flight.re.c +++ b/src/flight.re.c @@ -27,16 +27,16 @@ static int flight_compare(const union line64 a, const union line64 b) /*!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; +static int scan(struct flights *const f, + union date32 date, const char *const text) { + const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *s0, *s1; enum YYCONDTYPE condition = yycline; size_t line = 1; char datestr[12] = {0}; const char *why = "unexpected"; - assert(buffer && f); - YYCURSOR = YYMARKER = yyt1 = buffer; + struct flight *flight = 0; + assert(f && text); + YYCURSOR = YYMARKER = yyt1 = text; /*!re2c /**/ re2c:define:YYCTYPE = char; re2c:yyfill:enable = 0; @@ -45,9 +45,10 @@ static int scan(union date32 date, const char *const buffer, re2c:define:YYGETCONDITION:naked = 1; re2c:define:YYSETCONDITION:naked = 1; - unix_control = [\x01-\x08\x0b-\x1f\x7f]; + //unix_control = [\x01-\x08\x0b-\x1f\x7f]; ws = [ \t]; - glyph = [^] \ ("\x00" | "\n" | unix_control | ws); + glyph = [^\x00-\x20\x7f]; // [^\n\t ] + all the other weird + semitext = glyph \ ";"; natural = [1-9][0-9]*; */ for( ; ; ) { /*!re2c /**/ @@ -59,22 +60,47 @@ static int scan(union date32 date, const char *const buffer, * :=> skip /* Except these two. */ - "[glider]" :=> glider + "[glider]" :=> glider_type "[flight]" :=> flight + /* type; registration; launch -- landing; pic; sic; + single engine day dual; pilot; instrument simulated; actual; remarks */ + + * { why = "default unrecognized"; goto catch; } + * { why = "type unrecognized"; goto catch; } + * { why = "reg unrecognized"; goto catch; } + * { why = "launch unrecognized"; goto catch; } + * { why = "planned"; goto catch; } + + /* type, reg, launch, how, height, landing, pilot, dual, instr, remarks + [glider] 2-33A; C-GCLK; CYQQ; A; 2000'; CYQQ; ;:13;; Peters D1 */ + ws* @s0 semitext+ @s1 ws* ";" => glider_reg { + const union line64 key + = {{ (uint32_t)line, {{ date.day, date.month, date.year }} }}; + assert(!flight); + if(line > UINT32_MAX) { why = "line overflow"; goto catch; } + switch(flight_tree_try(&f->_, key, &flight)) { + case TREE_PRESENT: why = "duplicate key"; + case TREE_ERROR: goto catch; + case TREE_ABSENT: flight->type = GLIDER; break; + } + flight->glider.type.a = s0, flight->glider.type.b = s1; + } + ws* @s0 semitext+ @s1 ws* ";" => glider_launch { + assert(flight && flight->type == GLIDER); + } + ws* @s0 semitext+ @s1 *ws* ";" => glider_err { + } /* "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; } */ } 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); + "%s line %zu: %s.\n", text, datestr, line, why); return 0; } /** Dynamic memory allocation for `f` will be zero, will @@ -87,12 +113,12 @@ void flights_(struct flights *const f) { struct flights flights(/*const*/ struct journal *const j) { struct flights f; struct journal_iterator it; - union date32 k; - const char *v; + union date32 date; + const char *text; assert(j); f._ = flight_tree(); it = journal_iterator(j); - while(journal_next(&it, &k, &v)) if(!scan(k, v, &f)) goto catch; + while(journal_next(&it, &date, &text)) if(!scan(&f, date, text)) goto catch; goto finally; catch: flights_(&f); diff --git a/src/flighthours.c b/src/flighthours.c index 9512857..54152d1 100644 --- a/src/flighthours.c +++ b/src/flighthours.c @@ -5,6 +5,7 @@ #include "journal.h" #include "flight.h" +#include "source.h" #include #include #include @@ -12,15 +13,18 @@ int main(void) { int success = EXIT_SUCCESS; + errno = 0; struct journal j = journal(); - union date32 k; + struct sources s = sources(&j); struct flights f = flights(&j); - 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 \"flighthours.eps\"\n" "$Data < #include diff --git a/src/pair.h b/src/pair.h index 48d9232..8219292 100644 --- a/src/pair.h +++ b/src/pair.h @@ -1,3 +1,6 @@ +#ifndef PAIR_H /* */