flight doesn't work yet. fixed 0x0a -> 0x0b.

This commit is contained in:
Neil 2023-01-24 22:15:04 -08:00
parent 0b03301269
commit 7923a9e0f6
5 changed files with 240 additions and 11 deletions

View File

@ -29,7 +29,7 @@ else
CF += -g
endif
projects := bin/test-text bin/test-kjv bin/test-journal bin/kjv
projects := bin/test-text bin/test-kjv bin/test-journal bin/kjv bin/flight
#docs := $(patsubst test/test_%.c, doc/%.md, $(wildcard test/test_*.c))
default: $(projects)
@ -39,6 +39,7 @@ bin/test-text: build/text.o build/test_text.o
bin/test-kjv: build/text.o build/kjv.o build/test_kjv.o
bin/test-journal: build/text.o build/journal.o build/test_journal.o
bin/kjv: build/text.o build/journal.o build/kjv.o build/scan_kjv.o
bin/flight: build/text.o build/journal.o build/scan_flight.o
bin/%:
@echo "\033[1;36mlinking $@\033[0m"

62
src/flight.h Normal file
View File

@ -0,0 +1,62 @@
#ifndef OMIT_BASE /* <!-- base */
#define LAUNCH_TYPE \
X(MotorCarTow),\
X(Winch),\
X(AeroTow)
#define X(type) type
enum launch_type { LAUNCH_TYPE };
#undef X
#define X(type) #type
static const char *launch_type_string[] = { LAUNCH_TYPE };
#undef X
#undef LAUNCH_TYPE
#define FLIGHT_TYPE \
X(Glider),\
X(Power)
#define X(type) type
enum flight_type { FLIGHT_TYPE };
#undef X
#define X(type) #type
static const char *flight_type_string[] = { FLIGHT_TYPE };
#undef X
#undef FLIGHT_TYPE
/*void kjvcite_to_string(const union kjvcite, char (*)[12]);*/
#else /* base --><!-- !base */
#undef OMIT_BASE
#endif /* !base --> */
#ifndef OMIT_VERSES /* <!-- verses: For external inclusion. */
struct table_kjvset_bucket;
struct kjvset_table {
struct table_kjvset_bucket *buckets;
uint32_t log_capacity, size, top;
};
struct table_verse_bucket;
struct verse_table {
struct table_verse_bucket *buckets;
uint32_t log_capacity, size, top;
};
#else /* verses --><!-- !verses */
#undef OMIT_VERSES
#endif /* !verses --> */
#ifndef OMIT_PROTO /* <!-- proto */
#include <stddef.h>
struct flights {
struct kjvset_table set;
struct verse_table verses;
struct { size_t total, cumulative, set, verse; } words;
};
struct kjv kjv(void);
void kjv_(struct kjv *);
int kjv_is_valid(const struct kjv *const kjv);
int kjv_add(struct kjv *const kjv, const union kjvcite cite);
const char *kjv_to_string(const struct kjv *const kjv);
const char *kjv_set_to_string(const struct kjv *const kjv);
#else /* proto --><!-- !proto */
#undef OMIT_PROTO
#endif /* !proto --> */

View File

@ -205,7 +205,9 @@ struct journal journal(void) {
/*if(*y == 1993) break;*/
}
if(chdir("..") == -1 || !day_tree_bulk_finish(&j.days)) goto catch;
/* Structure is now stable. */
/* Structure is now stable because we aren't going to move it;
convert all of offsets to pointers. */
it = day_tree_begin(&j.days); while(day_tree_next(&it, 0, &v)) {
/*printf("%zu\n", v->offset);*/
v->text = j.backing.a.data + v->offset;

171
src/scan_flight.re.c Normal file
View File

@ -0,0 +1,171 @@
/** @license 2022 Neil Edelman, distributed under the terms of the
[MIT License](https://opensource.org/licenses/MIT).
Scan journal entries for kjv references. */
#include "../src/journal.h"
#include "../src/helper.h"
#include <inttypes.h> /* C99 */
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <limits.h>
struct substring { const char *str; int len; };
/** type, reg, launch, how, height, landing, pilot_min, dual_min, instr_min,
remarks */
struct glider {
struct substring type, reg, launch;
enum launch how;
unsigned height_ft, pilot_min, dual_min, instr_min;
struct substring remarks;
};
/** type, reg, launch -- landing, pilot, copilot, dual_min, pilot_min,
ifrsim_min, ifr_min, remarks */
struct power {
struct substring type, reg, launch, landing, pilot, copilot;
unsigned dual_min, pilot_min, ifrsim_min, ifr_min;
struct substring remarks;
};
/** Could be a glider or power. */
struct flight {
enum { GLIDER, POWER } type;
union { struct glider glider; struct power power; };
};
struct flights {
};
/*!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;
uint32_t chapter = 0, verse = 0, verse_end = 0;
enum YYCONDTYPE condition = yycline;
size_t line = 1;
char datestr[12] = {0};
const char *why = "unexpected";
assert(buffer && kj);
YYCURSOR = YYMARKER = yyt1 = buffer;
/*!re2c /**/
re2c:define:YYCTYPE = char;
re2c:yyfill:enable = 0;
re2c:define:YYGETCONDITION = "condition";
re2c:define:YYSETCONDITION = "condition = @@;";
re2c:define:YYGETCONDITION:naked = 1;
re2c:define:YYSETCONDITION:naked = 1;
unix_control = [\x01-\x08\x0b-\x1f\x7f];
ws = [ \t];
glyph = [^] \ ("\x00" | "\n" | unix_control | ws);
natural = [1-9][0-9]*;
lookat = ws* natural ":" natural [ab]? ("-" natural [ab]?)? engage;
*/
for( ; ; ) { /*!re2c /**/
<skip> [^\n\x00] { continue; }
<skip> "\x00" { why = "no newline at end of file"; goto catch; }
<skip> "\n" => line { line++; continue; }
<line> "\x00" { return 1; }
<line> "\n" { line++; continue; }
<line> * :=> skip /* Guess it can't be simplified? */
<line> "[glider]" :=> glider
<line> "[flight]" :=> flight
/* "M" - Motor Car Tow
"W" - Winch
"A" - Aero Tow */
/* type; registration; launch -- landing; pic; sic;
single engine day dual; pilot; instrument simulated; actual; remarks */
<book> * { why = "default unrecognized"; goto catch; }
/* 19:15a, just ignore the a. */
<book> ws+ @s0 natural @s1 ":" @t0 natural @t1 [ab]? {
if(chapter || verse || verse_end)
{ why = "reference unrecognized"; goto catch; }
if(!helper_natural(s0, s1, &chapter)
|| !helper_natural(t0, t1, &verse))
{ why = "reference numerical error"; goto catch; }
continue;
}
<book> "-" @s0 natural @s1 [ab]? { /* Verse range. */
if(!chapter || !verse || verse_end)
{ why = "range unrecognized"; goto catch; }
if(!helper_natural(s0, s1, &verse_end))
{ why = "range numerical error"; goto catch; }
continue;
}
<book> engage => skip {
char citestr[12];
if(!chapter || !verse) { why = "missing information"; goto catch; }
if(verse_end && verse_end <= verse)
{ why = "interval error"; goto catch; }
union kjvcite cite
= { .book = book, .chapter = chapter, .verse = verse };
if(!datestr[0]) date32_to_string(date, &datestr); /* Only once. */
kjvcite_to_string(cite, &citestr);
for( ; ; verse++, cite.verse++) {
if(!kjv_add(kj, cite)) { why = "add to set"; goto catch; }
if(!verse_end || verse_end <= verse) break;
}
printf("%s\t%zu\t%zu\t%zu\t# ",
datestr, kj->words.verse, kj->words.set, kj->words.cumulative);
if(verse_end) {
printf("%s-%" PRIu32 "\n", citestr, verse_end);
} else {
printf("%s\n", citestr);
}
book = Revelation, chapter = 0, verse = 0, verse_end = 0;
continue;
}
*/ }
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);
return 0;
}
int main(void) {
int success = EXIT_SUCCESS;
struct journal j;
struct journal_iterator it;
struct kjv kj = kjv();
union date32 k;
union load *v;
size_t i;
j = journal();
if(!journal_is_valid(&j)) goto catch;
fprintf(stderr, "Journal: %s.\n", journal_to_string(&j));
printf("set term postscript eps enhanced\n"
"set output \"kjv.eps\"\n"
"$Data <<EOD\n"
"# date\tverse\tset\tcumulative / %zu\n", kj.words.total);
it = journal_begin(&j), i = 0; while(journal_next(&it, &k, &v))
if(!scan(k, v->text, &kj)) goto catch;
printf("EOD\n"
"set monochrome\n"
"set xdata time\n"
"set timefmt \"%%Y-%%m-%%d\"\n"
"set xtics format \"%%Y-%%m-%%d\" rotate by -30\n"
"set ylabel \"words in KJV\"\n"
"set format y \"%%g%%%%\"\n"
"set key top left\n"
"set grid\n"
"unset border\n"
"#set style fill solid 0.1 #pattern 5 (better, but restarts)\n"
"plot $Data using 1:($3)*100/%zu with fillsteps lw 2 title \"set\", \\\n"
"$Data using 1:($4)*100/%zu with steps lw 1 title \"cumulative\"\n",
kj.words.total, kj.words.total);
goto finally;
catch:
success = EXIT_FAILURE;
perror("journal");
finally:
journal_(&j);
return success;
}

View File

@ -33,7 +33,7 @@ static int scan(union date32 date, const char *const buffer,
re2c:define:YYGETCONDITION:naked = 1;
re2c:define:YYSETCONDITION:naked = 1;
unix_control = [\x01-\x08\x0a-\x1f\x7f];
unix_control = [\x01-\x08\x0b-\x1f\x7f];
ws = [ \t];
glyph = [^] \ ("\x00" | "\n" | unix_control | ws);
natural = [1-9][0-9]*;
@ -185,11 +185,6 @@ int main(void) {
union date32 k;
union load *v;
size_t i;
/*scan((union date32){.year=2000, .month=1, .day=1}, "\n\n\n"
"Romans 3:23 -- ``For all have sinned, "
"and come short of the glory of God.''\n", &kj);*/
/* FIXME: have a column with the number so we can see how much uniqueness
makes a difference. */
j = journal();
if(!journal_is_valid(&j)) goto catch;
fprintf(stderr, "Journal: %s.\n", journal_to_string(&j));
@ -197,10 +192,8 @@ int main(void) {
"set output \"kjv.eps\"\n"
"$Data <<EOD\n"
"# date\tverse\tset\tcumulative / %zu\n", kj.words.total);
it = journal_begin(&j), i = 0; while(journal_next(&it, &k, &v)) {
it = journal_begin(&j), i = 0; while(journal_next(&it, &k, &v))
if(!scan(k, v->text, &kj)) goto catch;
/*if(++i > 32) break;*/
}
printf("EOD\n"
"set monochrome\n"
"set xdata time\n"