diff --git a/src/scan.h b/src/scan.h index 961cbdf..cefc448 100644 --- a/src/scan.h +++ b/src/scan.h @@ -7,6 +7,11 @@ #define TREE_VALUE size_t #define TREE_HEAD #include "../src/tree.h" +#define TREE_NAME linepair +#define TREE_KEY union line64 +#define TREE_VALUE struct pair +#define TREE_HEAD +#include "../src/tree.h" /* Eg, source array. */ struct kvpair { struct pair key, value; }; @@ -134,8 +139,9 @@ struct scan { struct pairmap_table map; struct linemap_tree dates; } edits; - struct linekvpair_tree contacts, books, tvs, movies, ideas, vaccines, - medications; + struct linepair_tree dreams; + struct linekvpair_tree contacts, books, tvs, movies, ideas, + vaccines, medications; struct linekvmoney_tree taxes, incomes; struct glider_tree gliders; struct flight_tree flights; diff --git a/src/scan.re.c b/src/scan.re.c index 901d629..00a1416 100644 --- a/src/scan.re.c +++ b/src/scan.re.c @@ -33,6 +33,20 @@ static void pair_to_string(const struct pair *const p, *y = '\0'; } +static void linepair_to_string(const union line64 line, + const struct pair *const pair, + char (*const a)[12]) { (void)pair; date32_to_string(line.date, a); } +static int linepair_compare(const union line64 a, const union line64 b) + { return a.u64 > b.u64; } +#define TREE_NAME linepair +#define TREE_KEY union line64 +#define TREE_VALUE struct pair +#define TREE_COMPARE +#define TREE_TO_STRING +#define TREE_DEFAULT {0,0} +#define TREE_BODY +#include "../src/tree.h" + /* Array of kvpair. */ static void kvpair_to_string(const struct kvpair *const s, char (*const z)[12]) { pair_to_string(&s->key, z); } @@ -232,6 +246,19 @@ static int scan_day(struct scan *const scan, union date32 date, "in: " :=> income "mail: " :=> mail + "- " => input_text { + const union line64 key = { { (uint32_t)line, date } }; + struct pair *pair; + switch(linepair_tree_bulk_assign(&scan->dreams, key, &pair)) { + case TREE_PRESENT: fail = "duplicate"; case TREE_ERROR: goto catch; + case TREE_ABSENT: break; + } + pair->a = pair->b = 0; + input.future = yycnewline, input.pair = pair; + fprintf(stderr, "%s[%zu]: new dream.\n", datestr, line); + continue; + } + /* Whatsapp messages ignored. [11-03, 04:19] Contact: massage Hopefully they don't have a ':' in their name. */ [0-1][0-9] "-" [0-3][0-9] ", " [0-2][0-9] ":" [0-5][0-9] "] " @@ -916,6 +943,7 @@ void scan_(struct scan *const scan) { linekvpair_tree_(&scan->tvs); linekvpair_tree_(&scan->books); linekvpair_tree_(&scan->contacts); + linepair_tree_(&scan->dreams); linemap_tree_(&scan->scores.dates); pair_map_table_(&scan->scores.map); @@ -981,6 +1009,7 @@ struct scan scan(struct journal *const jrnl) { || !linemap_tree_bulk_finish(&scan.places.dates) || !linemap_tree_bulk_finish(&scan.scores.dates) || !linemap_tree_bulk_finish(&scan.edits.dates) + || !linepair_tree_bulk_finish(&scan.dreams) || !linekvpair_tree_bulk_finish(&scan.contacts) || !linekvpair_tree_bulk_finish(&scan.books) || !linekvpair_tree_bulk_finish(&scan.tvs)