plan -> from

This commit is contained in:
Neil 2023-05-22 01:26:58 -07:00
parent 66a3c1752f
commit e33dcbea67
2 changed files with 38 additions and 0 deletions

View File

@ -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;

View File

@ -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,
<bracket> "in: " :=> income
<bracket> "mail: " :=> mail
<bracket> "couch: " :=> couch
<bracket> "from: " :=> from
<line> "- " => 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;
}
<from> * { fail = "from unrecognized"; goto catch; }
<from> "~"? @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;
}
<place> * { fail = "place unrecognized"; goto catch; }
<place> @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)