Done glider; working on power.
This commit is contained in:
parent
c62189af44
commit
021c7297f1
|
@ -29,7 +29,7 @@ static int flight_compare(const union line64 a, const union line64 b)
|
||||||
|
|
||||||
static int scan(struct flights *const f,
|
static int scan(struct flights *const f,
|
||||||
union date32 date, const char *const text) {
|
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;
|
enum YYCONDTYPE condition = yycline;
|
||||||
size_t line = 1;
|
size_t line = 1;
|
||||||
char datestr[12] = {0};
|
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
|
glyph = [^\x00-\x20\x7f]; // [^\n\t ] + all the other weird
|
||||||
semitext = glyph \ ";";
|
semitext = glyph \ ";";
|
||||||
natural = [1-9][0-9]*;
|
natural = [1-9][0-9]*;
|
||||||
|
minutes = [0-5][0-9];
|
||||||
airport = [A-Z0-9]{4,4};
|
airport = [A-Z0-9]{4,4};
|
||||||
*/
|
*/
|
||||||
for( ; ; ) { /*!re2c /**/
|
for( ; ; ) { /*!re2c /**/
|
||||||
|
@ -60,15 +61,8 @@ static int scan(struct flights *const f,
|
||||||
<line, skip> "\n" => line { line++; continue; }
|
<line, skip> "\n" => line { line++; continue; }
|
||||||
<line> * :=> skip
|
<line> * :=> skip
|
||||||
|
|
||||||
/* Except these two. */
|
/* Except this . . . */
|
||||||
<line> "[glider]" :=> glider_type
|
<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
|
/* type, reg, launch, how, height, landing, pilot, dual, instr, remarks
|
||||||
eg, [glider] 2-33A; C-GCLK; CYQQ; A; 2000'; CYQQ; ;:13;; Peters D1 */
|
eg, [glider] 2-33A; C-GCLK; CYQQ; A; 2000'; CYQQ; ;:13;; Peters D1 */
|
||||||
<glider_type> * { why = "type unrecognized"; goto catch; }
|
<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_dual> * { why = "dual unrecognized"; goto catch; }
|
||||||
<glider_instr> * { why = "instr unrecognized"; goto catch; }
|
<glider_instr> * { why = "instr unrecognized"; goto catch; }
|
||||||
<glider_remarks> * { why = "remarks 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 {
|
<glider_type> ws* @s0 semitext+ @s1 ws* ";" => glider_reg {
|
||||||
const union line64 key
|
const union line64 key
|
||||||
= {{ (uint32_t)line, {{ date.day, date.month, date.year }} }};
|
= {{ (uint32_t)line, {{ date.day, date.month, date.year }} }};
|
||||||
|
@ -117,7 +110,7 @@ static int scan(struct flights *const f,
|
||||||
continue; }
|
continue; }
|
||||||
<glider_pilot> ws* ";" => glider_dual /* not PIC */
|
<glider_pilot> ws* ";" => glider_dual /* not PIC */
|
||||||
{ flight->glider.pilot_min = 0; continue; }
|
{ 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 {
|
=> glider_dual {
|
||||||
if(!pair_to_minutes(s0, s1, t0, t1, &flight->glider.pilot_min))
|
if(!pair_to_minutes(s0, s1, t0, t1, &flight->glider.pilot_min))
|
||||||
{ why = "pilot time"; goto catch; }
|
{ why = "pilot time"; goto catch; }
|
||||||
|
@ -125,7 +118,7 @@ static int scan(struct flights *const f,
|
||||||
}
|
}
|
||||||
<glider_dual> ws* ";" => glider_instr
|
<glider_dual> ws* ";" => glider_instr
|
||||||
{ flight->glider.dual_min = 0; continue; }
|
{ 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 {
|
=> glider_instr {
|
||||||
if(!pair_to_minutes(s0, s1, t0, t1, &flight->glider.dual_min))
|
if(!pair_to_minutes(s0, s1, t0, t1, &flight->glider.dual_min))
|
||||||
{ why = "dual time"; goto catch; }
|
{ why = "dual time"; goto catch; }
|
||||||
|
@ -133,13 +126,56 @@ static int scan(struct flights *const f,
|
||||||
}
|
}
|
||||||
<glider_instr> ws* ";" => glider_remarks
|
<glider_instr> ws* ";" => glider_remarks
|
||||||
{ flight->glider.instr_min = 0; continue; }
|
{ 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 {
|
=> glider_remarks {
|
||||||
if(!pair_to_minutes(s0, s1, t0, t1, &flight->glider.instr_min))
|
if(!pair_to_minutes(s0, s1, t0, t1, &flight->glider.instr_min))
|
||||||
{ why = "instr time"; goto catch; }
|
{ why = "instr time"; goto catch; }
|
||||||
continue;
|
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. */
|
assert(0); /* Never gets here. */
|
||||||
catch:
|
catch:
|
||||||
|
|
|
@ -207,9 +207,9 @@ struct journal journal(void) {
|
||||||
it = day_tree_iterator(&j.days);
|
it = day_tree_iterator(&j.days);
|
||||||
while(day_tree_next(&it)) {
|
while(day_tree_next(&it)) {
|
||||||
v.text = day_tree_value(&it);
|
v.text = day_tree_value(&it);
|
||||||
printf("[%zu]...", *v.offset);
|
/*printf("[%zu]...", *v.offset);*/
|
||||||
*v.text = j.backing.a.data + *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",
|
/*fprintf(stderr, "Journal has entries: %s\n",
|
||||||
day_tree_to_string(&j.days));*/
|
day_tree_to_string(&j.days));*/
|
||||||
|
|
|
@ -23,7 +23,7 @@ int pair_to_natural(const char *s, const char *const e, uint32_t *const n) {
|
||||||
uint32_t accum = 0;
|
uint32_t accum = 0;
|
||||||
while(s < e) {
|
while(s < e) {
|
||||||
unsigned next = accum * 10 + (unsigned)(*s - '0');
|
unsigned next = accum * 10 + (unsigned)(*s - '0');
|
||||||
if(accum >= next) return errno = ERANGE, 0;
|
if(accum > next) return errno = ERANGE, 0;
|
||||||
accum = next;
|
accum = next;
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
static int scan(union date32 date, const char *const buffer,
|
||||||
struct sources *const s) {
|
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;
|
enum YYCONDTYPE condition = yycline;
|
||||||
size_t line = 1;
|
size_t line = 1;
|
||||||
char datestr[12] = {0};
|
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_ERROR: goto catch;
|
||||||
case TREE_ABSENT: *pi = i; break;
|
case TREE_ABSENT: *pi = i; break;
|
||||||
}
|
}
|
||||||
date32_to_string(date, &datestr);
|
/*date32_to_string(date, &datestr);
|
||||||
printf("%s: <%.*s>\n", datestr, (int)(s1 - s0), s0);
|
printf("%s: <%.*s>\n", datestr, (int)(s1 - s0), s0);*/
|
||||||
continue;
|
continue;
|
||||||
} }
|
} }
|
||||||
/* This is lazy and will pickup trailing spaces. */
|
/* 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);
|
*idx = (size_t)(source - s->list.data);
|
||||||
source->name.a = s0, source->name.b = s1;
|
source->name.a = s0, source->name.b = s1;
|
||||||
source->desc.a = 0, source->desc.b = 0;
|
source->desc.a = 0, source->desc.b = 0;
|
||||||
fprintf(stderr, "New keyword <%.*s> stored in list at %zu.\n",
|
date32_to_string(date, &datestr);
|
||||||
(int)(s1 - s0), s0, *idx);
|
fprintf(stderr, "%s: new source <%.*s> stored in list at %zu.\n",
|
||||||
|
datestr, (int)(s1 - s0), s0, *idx);
|
||||||
goto also_add_to_tree;
|
goto also_add_to_tree;
|
||||||
}
|
}
|
||||||
*/ }
|
*/ }
|
||||||
|
@ -159,10 +160,10 @@ struct sources sources(struct journal *const j) {
|
||||||
}
|
}
|
||||||
it = journal_iterator(j);
|
it = journal_iterator(j);
|
||||||
while(journal_next(&it, &k, &v)) if(!scan(k, v, &s)) goto catch;
|
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"
|
"Mapped to indices: %s.\n"
|
||||||
"Date-line tree: %s.\n", sourcelist_array_to_string(&s.list),
|
"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;
|
goto finally;
|
||||||
catch:
|
catch:
|
||||||
sources_(&s);
|
sources_(&s);
|
||||||
|
|
Loading…
Reference in New Issue