From e33dcbea67e1fef407a8397661838c29ecbb4bf9 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 22 May 2023 01:26:58 -0700 Subject: [PATCH] plan -> from --- src/scan.h | 7 +++++++ src/scan.re.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/scan.h b/src/scan.h index 1cd9010..00a4dcd 100644 --- a/src/scan.h +++ b/src/scan.h @@ -24,6 +24,12 @@ struct kvpair { struct pair key, value; }; #define TREE_VALUE struct kvpair #define TREE_HEAD #include "../src/tree.h" +struct kvdate { union date32 key; struct pair value; }; +#define TREE_NAME linekvdate +#define TREE_KEY union line64 +#define TREE_VALUE struct kvdate +#define TREE_HEAD +#include "../src/tree.h" enum currency { NONE, CAD, /* Canadian $. */ @@ -142,6 +148,7 @@ struct scan { struct linepair_tree dreams; struct linekvpair_tree contacts, books, tvs, movies, ideas, vaccines, medications, mails, couches; + struct linekvdate_tree froms; 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 4626afa..c7db4b7 100644 --- a/src/scan.re.c +++ b/src/scan.re.c @@ -68,6 +68,19 @@ static int linekvpair_compare(const union line64 a, const union line64 b) #define TREE_DEFAULT {{0,0},{0,0}} #define TREE_BODY #include "../src/tree.h" +static void linekvdate_to_string(const union line64 line, + const struct kvdate *const kv, + char (*const a)[12]) { (void)kv; date32_to_string(line.date, a); } +static int linekvdate_compare(const union line64 a, const union line64 b) + { return a.u64 > b.u64; } +#define TREE_NAME linekvdate +#define TREE_KEY union line64 +#define TREE_VALUE struct kvdate +#define TREE_COMPARE +#define TREE_TO_STRING +#define TREE_DEFAULT {0} +#define TREE_BODY +#include "../src/tree.h" static void linekvmoney_to_string(const union line64 line, const struct kvmoney *const kv, char (*const a)[12]) { (void)kv; date32_to_string(line.date, a); } @@ -246,6 +259,7 @@ static int scan_day(struct scan *const scan, union date32 date, "in: " :=> income "mail: " :=> mail "couch: " :=> couch + "from: " :=> from "- " => input_text { const union line64 key = { { (uint32_t)line, date } }; @@ -486,6 +500,21 @@ static int scan_day(struct scan *const scan, union date32 date, continue; } + * { fail = "from unrecognized"; goto catch; } + "~"? @s0 date "]" => input_text { + const union line64 key = { { (uint32_t)line, date } }; + struct kvdate *pair; + switch(linekvdate_tree_bulk_assign(&scan->froms, key, &pair)) { + case TREE_PRESENT: fail = "duplicate"; case TREE_ERROR: goto catch; + case TREE_ABSENT: break; + } + if(!pair_to_date(s0, &pair->key)) goto catch; + pair->value.a = pair->value.b = 0; + input.future = yycnewline, input.pair = &pair->value; + fprintf(stderr, "%s[%zu]: new from.\n", datestr, line); + continue; + } + * { fail = "place unrecognized"; goto catch; } @s0 parlabel @s1 / "\n" => skip { also_place: { const struct pair keyword = pair(s0, s1); @@ -953,6 +982,7 @@ void scan_(struct scan *const scan) { glider_tree_(&scan->gliders); linekvmoney_tree_(&scan->incomes); linekvmoney_tree_(&scan->taxes); + linekvdate_tree_(&scan->froms); linekvpair_tree_(&scan->couches); linekvpair_tree_(&scan->medications); linekvpair_tree_(&scan->vaccines); @@ -1036,6 +1066,7 @@ struct scan scan(struct journal *const jrnl) { || !linekvpair_tree_bulk_finish(&scan.vaccines) || !linekvpair_tree_bulk_finish(&scan.medications) || !linekvpair_tree_bulk_finish(&scan.couches) + || !linekvdate_tree_bulk_finish(&scan.froms) || !linekvmoney_tree_bulk_finish(&scan.taxes) || !linekvmoney_tree_bulk_finish(&scan.incomes) || !glider_tree_bulk_finish(&scan.gliders)