From 31f41f6ced03b86ce6a3dc26a651e779fbdc0c32 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 6 May 2023 22:36:59 -0700 Subject: [PATCH] fixmes generated --- src/journal.re.c | 2 ++ src/scan.h | 15 ++++++++++++++ src/scan.re.c | 51 +++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/journal.re.c b/src/journal.re.c index 3993f78..a86d599 100644 --- a/src/journal.re.c +++ b/src/journal.re.c @@ -201,6 +201,8 @@ struct journal journal(const char *const dir_journal) { /* Because it's in a flat array, the pointers are not stable while we are loading it, and we need to store the offsets. */ *v.offset = (uintptr_t)(contents - j.backing.data); + /* fixme: not representing with int should be a lazy error, + since we use `printf`. */ } d = 0, int_array_clear(&days); if(chdir("..") == -1) goto catch; diff --git a/src/scan.h b/src/scan.h index 8bb3fb1..94bfe70 100644 --- a/src/scan.h +++ b/src/scan.h @@ -33,6 +33,16 @@ struct score { #define ARRAY_HEAD #include "../src/array.h" +/* Edit array. */ +struct edit { + union date32 edit; + struct pair desc; +}; +#define ARRAY_NAME edit +#define ARRAY_TYPE struct edit +#define ARRAY_HEAD +#include "../src/array.h" + /* Glider array. */ #define LAUNCH_TYPE \ @@ -96,6 +106,11 @@ struct scan { struct pairmap_table map; struct linemap_tree dates; } scores; + struct { + struct edit_array array; + struct pairmap_table map; + struct linemap_tree dates; + } edits; struct glider_tree gliders; struct flight_tree flights; struct kjv_tree kjvs; diff --git a/src/scan.re.c b/src/scan.re.c index c983d3d..340758b 100644 --- a/src/scan.re.c +++ b/src/scan.re.c @@ -60,6 +60,15 @@ static void score_to_string(const struct score *const s, #define ARRAY_BODY #include "../src/array.h" +/* Array of edits. */ +static void edit_to_string(const struct edit *const e, + char (*const z)[12]) { pair_to_string(&e->desc, z); } +#define ARRAY_NAME edit +#define ARRAY_TYPE struct edit +#define ARRAY_TO_STRING +#define ARRAY_BODY +#include "../src/array.h" + /* Glider tree. */ static void glider_to_string(const union line64 line, const struct glider *g, char (*const a)[12]) { (void)g; date32_to_string(line.date, a); } @@ -174,10 +183,11 @@ static int scan_day(struct scan *const scan, union date32 date, /* ^"[" ... */ * { fail = "bracket unrecognized"; goto catch; } - "document: " :=> document_title + "document: " :=> document + "ed: " :=> edit //change to "rem" - * { fail = "document title"; goto catch; } - @s0 bralabel @s1 "]" => future { + * { fail = "document title"; goto catch; } + @s0 bralabel @s1 "]" => future { const union line64 key = { { (uint32_t)line, date } }; size_t *pi; struct source *doc; @@ -195,6 +205,27 @@ static int scan_day(struct scan *const scan, union date32 date, continue; } + * { fail = "edit"; goto catch; } + @s0 date "]" => future { + const union line64 key = { { (uint32_t)line, date } }; + size_t *pi; + struct edit *ed; + if(!(ed = edit_array_new(&scan->edits.array))) goto catch; + ed->edit.u32 = 0; + ed->desc.a = 0, ed->desc.b = 0; + assert(!future), future = &ed->desc; + if(!pair_to_date(s0, &ed->edit)) goto catch; + switch(linemap_tree_bulk_assign(&scan->edits.dates, key, &pi)) { + case TREE_PRESENT: fail = "duplicate"; case TREE_ERROR: goto catch; + case TREE_ABSENT: + *pi = (size_t)(ed - scan->edits.array.data); break; + } + fprintf(stderr, "%s[%zu]: new edit from %" + PRIu32 "-%" PRIu32 "-%" PRIu32 " stored at %zu.\n", + datestr, line, ed->edit.year, ed->edit.month, ed->edit.day, *pi); + continue; + } + * { fail = "place unrecognized"; goto catch; } @s0 parlabel @s1 / "\n" => skip { also_place: { const struct pair keyword = pair(s0, s1); @@ -429,8 +460,7 @@ static int scan_day(struct scan *const scan, union date32 date, single engine day dual; pilot; instrument simulated; actual; remarks */ * { fail = "flight type"; goto catch; } ws* @s0 semilabel @s1 ";" => flight_reg { - const union line64 key - = {{ (uint32_t)line, {{ date.day, date.month, date.year }} }}; + const union line64 key = {{ (uint32_t)line, date }}; assert(!new_flight); if(line > UINT32_MAX) { fail = "line overflow"; goto catch; } switch(flight_tree_bulk_assign(&scan->flights, key, &new_flight)) { @@ -623,6 +653,8 @@ static int scan_day(struct scan *const scan, union date32 date, } + /* fixme: This is a cool way of doing things. Avoid repetition, make + all the things this way. */ /* "<<\ntext\n>>" or "text\n" used by several. Must have pointers to future input. */ * { fail = "text input"; goto catch; } @@ -682,6 +714,10 @@ void scan_(struct scan *const scan) { pair_map_table_(&scan->places.map); place_array_(&scan->places.array); + linemap_tree_(&scan->edits.dates); + pair_map_table_(&scan->edits.map); + edit_array_(&scan->edits.array); + linemap_tree_(&scan->documents.dates); pair_map_table_(&scan->documents.map); source_array_(&scan->documents.array); @@ -707,6 +743,11 @@ struct scan scan(struct journal *const jrnl) { if(!(nul = source_array_new(&scan.documents.array))) goto catch; *nul = (struct source){0}; } + { + struct edit *nul; + if(!(nul = edit_array_new(&scan.edits.array))) goto catch; + *nul = (struct edit){0}; + } { struct place *nul; if(!(nul = place_array_new(&scan.places.array))) goto catch;