From d46b5b4d4d255f61c041866942a7d608df2e4a0f Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 12 May 2023 22:25:58 -0700 Subject: [PATCH] Last, next month. Blue. --- src/journal.h | 2 ++ src/journal.re.c | 10 ++++++++++ src/scan.re.c | 9 ++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/journal.h b/src/journal.h index 7186871..5dc9299 100644 --- a/src/journal.h +++ b/src/journal.h @@ -20,6 +20,8 @@ union line64 { #define TREE_HEAD #include "../src/tree.h" +union date32 date32_last_month(union date32 d); +union date32 date32_next_month(union date32 d); #include "text.h" struct journal { struct day_tree days; struct char_array backing; }; struct journal_iterator { struct day_tree_iterator _; }; diff --git a/src/journal.re.c b/src/journal.re.c index d857808..e4340d1 100644 --- a/src/journal.re.c +++ b/src/journal.re.c @@ -17,6 +17,16 @@ #include /* umask (POSIX) */ #include /* opendir readdir closedir */ +union date32 date32_last_month(union date32 d) { + if(d.month <= 1) d.month = 12, d.year--; + else d.month--; + return d; +} +union date32 date32_next_month(union date32 d) { + if(d.month >= 12) d.month = 1, d.year++; + else d.month++; + return d; +} /* Day tree-map from date to pointer; is backed by a huge array of text. */ void date32_to_string(const union date32 d, char (*const a)[12]) { sprintf(*a, "%" PRIu32 "-%2.2" PRIu32 "-%2.2" PRIu32, diff --git a/src/scan.re.c b/src/scan.re.c index ee88601..f90fc40 100644 --- a/src/scan.re.c +++ b/src/scan.re.c @@ -1377,16 +1377,15 @@ void scan_dream_graph(struct scan *const scan) { printf("%" PRIu32 "-%.2" PRIu32 ", %zu\n", accum.date.year, accum.date.month, accum.count); /* If we skip a month, output zero as dummy. */ - union date32 next = { .u32 = accum.date.u32 + 32 }; + const union date32 next = date32_next_month(accum.date); if(next.u32 < now.u32) { printf("%" PRIu32 "-%.2" PRIu32 ", 0\n", next.year, next.month); /* Skip more than a month, place dummy output on both. */ - union date32 last = { .u32 = now.u32 - 32 }; + const union date32 last = date32_last_month(now); if(next.u32 < last.u32) printf("%" PRIu32 "-%.2" PRIu32 ", 0\n", last.year, last.month); - /* fixme: this will not work because it's not packed. */ } } accum.date = now; @@ -1406,8 +1405,8 @@ void scan_dream_graph(struct scan *const scan) { "set timefmt \"%%Y-%%m\"\n" "set format x \"%%Y-%%m\"\n" "set style fill transparent solid 0.3\n" + "set ylabel \"remembered dreams binned by month\"\n" "\n" - "plot $Data using 1:2 with boxes notitle\n" /*lc rgb "blue"?*/); + "plot $Data using 1:2 with boxes notitle lc rgb \"blue\"\n"); fprintf(stderr, "\n"); } -