diff --git a/src/flight.re.c b/src/flight.re.c index 0b04ed2..55000d7 100644 --- a/src/flight.re.c +++ b/src/flight.re.c @@ -29,7 +29,7 @@ static int flight_compare(const union line64 a, const union line64 b) static int scan(struct flights *const f, union date32 date, const char *const text) { - const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *yyt3, *s0, *s1, *t0, *t1; + const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *s0, *s1, *t0, *t1; enum YYCONDTYPE condition = yycline; size_t line = 1; char datestr[12] = {0}; @@ -50,6 +50,7 @@ static int scan(struct flights *const f, glyph = [^\x00-\x20\x7f]; // [^\n\t ] + all the other weird semitext = glyph \ ";"; natural = [1-9][0-9]*; + minutes = [0-5][0-9]; airport = [A-Z0-9]{4,4}; */ for( ; ; ) { /*!re2c /**/ @@ -60,15 +61,8 @@ static int scan(struct flights *const f, "\n" => line { line++; continue; } * :=> skip - /* Except these two. */ + /* Except this . . . */ "[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; } - /* type, reg, launch, how, height, landing, pilot, dual, instr, remarks eg, [glider] 2-33A; C-GCLK; CYQQ; A; 2000'; CYQQ; ;:13;; Peters D1 */ * { why = "type unrecognized"; goto catch; } @@ -81,7 +75,6 @@ static int scan(struct flights *const f, * { why = "dual unrecognized"; goto catch; } * { why = "instr unrecognized"; goto catch; } * { why = "remarks unrecognized"; goto catch; } - * { why = "planned"; goto catch; } ws* @s0 semitext+ @s1 ws* ";" => glider_reg { const union line64 key = {{ (uint32_t)line, {{ date.day, date.month, date.year }} }}; @@ -117,7 +110,7 @@ static int scan(struct flights *const f, continue; } ws* ";" => glider_dual /* not PIC */ { flight->glider.pilot_min = 0; continue; } - ws* @s0 natural? @s1 ":" @t0 natural @t1 ws* ";" + ws* @s0 natural? @s1 ":" @t0 minutes @t1 ws* ";" => glider_dual { if(!pair_to_minutes(s0, s1, t0, t1, &flight->glider.pilot_min)) { why = "pilot time"; goto catch; } @@ -125,7 +118,7 @@ static int scan(struct flights *const f, } ws* ";" => glider_instr { flight->glider.dual_min = 0; continue; } - ws* @s0 natural? @s1 ":" @t0 natural @t1 ws* ";" + ws* @s0 natural? @s1 ":" @t0 minutes @t1 ws* ";" => glider_instr { if(!pair_to_minutes(s0, s1, t0, t1, &flight->glider.dual_min)) { why = "dual time"; goto catch; } @@ -133,13 +126,56 @@ static int scan(struct flights *const f, } ws* ";" => glider_remarks { flight->glider.instr_min = 0; continue; } - ws* @s0 natural? @s1 ":" @t0 natural @t1 ws* ";" + ws* @s0 natural? @s1 ":" @t0 minutes @t1 ws* ";" => glider_remarks { if(!pair_to_minutes(s0, s1, t0, t1, &flight->glider.instr_min)) { why = "instr time"; goto catch; } continue; } - // ws* @s0 semitext+ ws+ @s1 ws* ??\ "\n"? => + ws* @s0 glyph+ (ws+ glyph+)* @s1 "\n" => line + { flight->glider.remarks.a = s0, flight->glider.remarks.b = s1; + flight = 0; line++; continue; } + ws* "\n" => line + { flight->glider.remarks.a = flight->glider.remarks.b = 0; + flight = 0; line++; continue; } + + /* And this . . . */ + "[flight]" :=> flight_type + /* type; registration; launch -- landing; pic; sic; + single engine day dual; pilot; instrument simulated; actual; remarks */ + * { why = "type unrecognized"; goto catch; } + * { why = "reg unrecognized"; goto catch; } + * { why = "airports unrecognized"; goto catch; } + * { why = "pic unrecognized"; goto catch; } + * { why = "sic unrecognized"; goto catch; } + * { why = "dual unrecognized"; goto catch; } + * { why = "pilot unrecognized"; goto catch; } + * { why = "simulated ifr unrecognized"; goto catch; } + * { why = "ifr unrecognized"; goto catch; } + * { why = "remarks unrecognized"; goto catch; } + ws* @s0 semitext+ @s1 ws* ";" => flight_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 = POWER; break; + } + flight->power.type.a = s0, flight->power.type.b = s1; + continue; + } + ws* @s0 semitext+ @s1 ws* ";" => flight_airports + { flight->power.reg.a = s0, flight->power.reg.b = s1; continue; } + ws* @s0 airport @s1 ws* "--" + ws* @t0 airport @t1 ws* ";" => flight_pic { + flight->power.launch.a = s0, flight->power.launch.b = s1; + flight->power.landing.a = t0, flight->power.landing.b = t1; + continue; + } + + */ } assert(0); /* Never gets here. */ catch: diff --git a/src/journal.re.c b/src/journal.re.c index 3479af4..98d95d1 100644 --- a/src/journal.re.c +++ b/src/journal.re.c @@ -207,9 +207,9 @@ struct journal journal(void) { it = day_tree_iterator(&j.days); while(day_tree_next(&it)) { v.text = day_tree_value(&it); - printf("[%zu]...", *v.offset); + /*printf("[%zu]...", *v.offset);*/ *v.text = j.backing.a.data + *v.offset; - printf("<%.32s>\n", *v.text); + /*printf("<%.32s>\n", *v.text);*/ } /*fprintf(stderr, "Journal has entries: %s\n", day_tree_to_string(&j.days));*/ diff --git a/src/pair.c b/src/pair.c index 2d04198..3e5bd16 100644 --- a/src/pair.c +++ b/src/pair.c @@ -23,7 +23,7 @@ int pair_to_natural(const char *s, const char *const e, uint32_t *const n) { uint32_t accum = 0; while(s < e) { unsigned next = accum * 10 + (unsigned)(*s - '0'); - if(accum >= next) return errno = ERANGE, 0; + if(accum > next) return errno = ERANGE, 0; accum = next; s++; } diff --git a/src/source.re.c b/src/source.re.c index f4b5b41..1e8e016 100644 --- a/src/source.re.c +++ b/src/source.re.c @@ -62,7 +62,7 @@ static int source_compare(const union line64 a, const union line64 b) static int scan(union date32 date, const char *const buffer, struct sources *const s) { - const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *s0, *s1, *t0, *t1; + const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *s0, *s1; enum YYCONDTYPE condition = yycline; size_t line = 1; char datestr[12] = {0}; @@ -106,8 +106,8 @@ static int scan(union date32 date, const char *const buffer, case TREE_ERROR: goto catch; case TREE_ABSENT: *pi = i; break; } - date32_to_string(date, &datestr); - printf("%s: <%.*s>\n", datestr, (int)(s1 - s0), s0); + /*date32_to_string(date, &datestr); + printf("%s: <%.*s>\n", datestr, (int)(s1 - s0), s0);*/ continue; } } /* This is lazy and will pickup trailing spaces. */ @@ -124,8 +124,9 @@ static int scan(union date32 date, const char *const buffer, *idx = (size_t)(source - s->list.data); source->name.a = s0, source->name.b = s1; source->desc.a = 0, source->desc.b = 0; - fprintf(stderr, "New keyword <%.*s> stored in list at %zu.\n", - (int)(s1 - s0), s0, *idx); + date32_to_string(date, &datestr); + fprintf(stderr, "%s: new source <%.*s> stored in list at %zu.\n", + datestr, (int)(s1 - s0), s0, *idx); goto also_add_to_tree; } */ } @@ -159,10 +160,10 @@ struct sources sources(struct journal *const j) { } it = journal_iterator(j); while(journal_next(&it, &k, &v)) if(!scan(k, v, &s)) goto catch; - fprintf(stderr, "List of sources: %s.\n" + /*fprintf(stderr, "List of sources: %s.\n" "Mapped to indices: %s.\n" "Date-line tree: %s.\n", sourcelist_array_to_string(&s.list), - sourcemap_table_to_string(&s.map), source_tree_to_string(&s.dates)); + sourcemap_table_to_string(&s.map), source_tree_to_string(&s.dates));*/ goto finally; catch: sources_(&s);