flights got closer to woking
This commit is contained in:
parent
fd52dbaf50
commit
aec01b255e
2
Makefile
2
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"
|
||||
|
@ -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,
|
||||
<line> * :=> skip
|
||||
|
||||
/* Except these two. */
|
||||
<line> "[glider]" :=> glider
|
||||
<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; }
|
||||
<glider_type> * { why = "type unrecognized"; goto catch; }
|
||||
<glider_reg> * { why = "reg unrecognized"; goto catch; }
|
||||
<glider_launch> * { why = "launch unrecognized"; goto catch; }
|
||||
<glider_err> * { 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 */
|
||||
<glider_type> 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;
|
||||
}
|
||||
<glider_reg> ws* @s0 semitext+ @s1 ws* ";" => glider_launch {
|
||||
assert(flight && flight->type == GLIDER);
|
||||
}
|
||||
<glider_launch> 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 */
|
||||
<glider, flight> * { 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, <fn:flights_is_valid> 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);
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "journal.h"
|
||||
#include "flight.h"
|
||||
#include "source.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
@ -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 <<EOD\n"
|
||||
"# date\tminutes\tcumulative\n");
|
||||
"# date\tsource\tminutes\tcumulative\n");
|
||||
|
||||
printf("EOD\n"
|
||||
"set monochrome\n"
|
||||
"set xdata time\n"
|
||||
@ -36,8 +40,10 @@ int main(void) {
|
||||
goto finally;
|
||||
catch:
|
||||
success = EXIT_FAILURE;
|
||||
perror("journal");
|
||||
perror("flights");
|
||||
finally:
|
||||
flights_(&f);
|
||||
sources_(&s);
|
||||
journal_(&j);
|
||||
return success;
|
||||
}
|
||||
|
@ -1,3 +1,10 @@
|
||||
/** @license 2023 Neil Edelman, distributed under the terms of the
|
||||
[MIT License](https://opensource.org/licenses/MIT).
|
||||
|
||||
A `pair` is `[a, b)` pair of pointers to char.
|
||||
|
||||
@std C99 */
|
||||
|
||||
#include "pair.h"
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
@ -1,3 +1,6 @@
|
||||
#ifndef PAIR_H /* <!-- guard */
|
||||
#define PAIR_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct pair { const char *a, *b; };
|
||||
@ -6,3 +9,5 @@ int pair_to_natural(const char *, const char *, uint32_t *);
|
||||
int pair_is_equal(struct pair, struct pair);
|
||||
int pair_is_string(struct pair, const char *);
|
||||
uint32_t pair_djb2(const struct pair p);
|
||||
|
||||
#endif /* guard --> */
|
||||
|
Loading…
Reference in New Issue
Block a user