Done glider; working on power.

This commit is contained in:
Neil 2023-02-13 21:32:43 -08:00
parent c62189af44
commit 021c7297f1
4 changed files with 61 additions and 24 deletions

View File

@ -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,
<line, skip> "\n" => line { line++; continue; }
<line> * :=> skip
/* Except these two. */
/* Except this . . . */
<line> "[glider]" :=> glider_type
<line> "[flight]" :=> flight
/* type; registration; launch -- landing; pic; sic;
single engine day dual; pilot; instrument simulated; actual; remarks */
<flight> * { 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 */
<glider_type> * { why = "type unrecognized"; goto catch; }
@ -81,7 +75,6 @@ static int scan(struct flights *const f,
<glider_dual> * { why = "dual unrecognized"; goto catch; }
<glider_instr> * { why = "instr unrecognized"; goto catch; }
<glider_remarks> * { why = "remarks unrecognized"; goto catch; }
<glider_err> * { why = "planned"; goto catch; }
<glider_type> 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; }
<glider_pilot> ws* ";" => glider_dual /* not PIC */
{ flight->glider.pilot_min = 0; continue; }
<glider_pilot> ws* @s0 natural? @s1 ":" @t0 natural @t1 ws* ";"
<glider_pilot> 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,
}
<glider_dual> ws* ";" => glider_instr
{ flight->glider.dual_min = 0; continue; }
<glider_dual> ws* @s0 natural? @s1 ":" @t0 natural @t1 ws* ";"
<glider_dual> 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,
}
<glider_instr> ws* ";" => glider_remarks
{ flight->glider.instr_min = 0; continue; }
<glider_instr> ws* @s0 natural? @s1 ":" @t0 natural @t1 ws* ";"
<glider_instr> 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;
}
// <glider_remarks> ws* @s0 semitext+ ws+ @s1 ws* ??\ "\n"? =>
<glider_remarks> ws* @s0 glyph+ (ws+ glyph+)* @s1 "\n" => line
{ flight->glider.remarks.a = s0, flight->glider.remarks.b = s1;
flight = 0; line++; continue; }
<glider_remarks> ws* "\n" => line
{ flight->glider.remarks.a = flight->glider.remarks.b = 0;
flight = 0; line++; continue; }
/* And this . . . */
<line> "[flight]" :=> flight_type
/* type; registration; launch -- landing; pic; sic;
single engine day dual; pilot; instrument simulated; actual; remarks */
<flight_type> * { why = "type unrecognized"; goto catch; }
<flight_reg> * { why = "reg unrecognized"; goto catch; }
<flight_airports> * { why = "airports unrecognized"; goto catch; }
<flight_pic> * { why = "pic unrecognized"; goto catch; }
<flight_sic> * { why = "sic unrecognized"; goto catch; }
<flight_dual> * { why = "dual unrecognized"; goto catch; }
<flight_pilot> * { why = "pilot unrecognized"; goto catch; }
<flight_ifrsim> * { why = "simulated ifr unrecognized"; goto catch; }
<flight_ifr> * { why = "ifr unrecognized"; goto catch; }
<flight_remarks> * { why = "remarks unrecognized"; goto catch; }
<flight_type> 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;
}
<flight_reg> ws* @s0 semitext+ @s1 ws* ";" => flight_airports
{ flight->power.reg.a = s0, flight->power.reg.b = s1; continue; }
<flight_airports> 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:

View File

@ -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));*/

View File

@ -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++;
}

View File

@ -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);