From 2468224d0aaacd8b0e7478af55142bcd831d2b77 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Wed, 29 Jul 2026 09:55:22 +0200 Subject: feat: standalone calendar overrides (calendar.h) + document customization Add a compile-time override table for MINOR local calendar changes, standalone (no lectio, no toolchain): edit calendar.h (copied from calendar.def.h), add a { month, day, colour, "name" } row, make. It replaces a fixed date's name and colour, every year, in both single-day and --month output. Limits (no engine): fixed dates only; name/colour only, not readings or rank/precedence; an override wins unconditionally. README gains a "Customize the calendar" section documenting both tiers with their limits: the standalone override above, and -- for readings, ranks and movable feasts -- regenerating gen/ from a lectio calendar layer via clectio-gen (-caldir/-use), then rebuilding with CORPUS= to repack any newly cited verses, with a git-checkout revert note. Both forms build clean under -Wall -Wextra; binary unchanged at 666 KB; default (empty override table) output is unchanged. Claude-Session: https://claude.ai/code/session_01S1CD1u3tgSS4xNu6WHfp5a --- clectio.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'clectio.c') diff --git a/clectio.c b/clectio.c index 1839ade..469d074 100644 --- a/clectio.c +++ b/clectio.c @@ -30,6 +30,21 @@ static int usecolor; static const char *const colname[] = { "green", "white", "red", "violet", "rose", "black" }; static const char *const colansi[] = { "\033[32m", "\033[37m", "\033[31m", "\033[35m", "\033[95m", "\033[90m" }; +/* Local calendar overrides: replace one fixed date's name + colour. The colour + * names below match colname[]/colansi[] above (index order). The user table + * lives in calendar.h (copied from calendar.def.h); see it for the limits. */ +enum { GREEN, WHITE, RED, VIOLET, ROSE, BLACK }; +typedef struct { int mon, day, colour; const char *name; } Override; +#include "calendar.h" /* static const Override overrides[]; ends with a {0,...} row */ + +static const Override *find_override(int mon, int day) { + const Override *o; + for (o = overrides; o->mon; o++) + if (o->mon == mon && o->day == day) + return o; + return NULL; +} + /* Days since the civil epoch 1970-01-01 (Howard Hinnant's algorithm). */ static long days_from_civil(long y, unsigned m, unsigned d) { y -= m <= 2; @@ -131,12 +146,15 @@ static int print_month(int y, int mon) { for (day = 1; day <= dim; day++) { long civ = civ1 + (day - 1); const Day *d = &days[cal[off1 + (day - 1)]]; + const Override *ov = find_override(mon, day); + const char *dname = ov ? ov->name : names[d->name]; + int dcol = ov ? ov->colour : d->colour; int w = (int)((civ + 4) % 7); /* 1970-01-01 was Thursday; 0 = Sunday */ - printf("%s %02d %-6s ", wd[w], day, colname[d->colour]); + printf("%s %02d %-6s ", wd[w], day, colname[dcol]); if (usecolor) - printf("%s%s\033[0m\n", colansi[d->colour], names[d->name]); + printf("%s%s\033[0m\n", colansi[dcol], dname); else - printf("%s\n", names[d->name]); + printf("%s\n", dname); } return 0; } @@ -165,14 +183,17 @@ static int run_month(const char *spec) { return print_month(y, mon); } -static void print_day(long off, const char *datestr, int gospel, int wrap) { +static void print_day(long off, const char *datestr, int mon, int day, int gospel, int wrap) { const Day *d = &days[cal[off]]; + const Override *ov = find_override(mon, day); + const char *dname = ov ? ov->name : names[d->name]; + int dcol = ov ? ov->colour : d->colour; unsigned ri; int n; if (usecolor) - printf("%s%s\033[0m\n", colansi[d->colour], names[d->name]); + printf("%s%s\033[0m\n", colansi[dcol], dname); else - printf("%s \xc2\xb7 %s\n", names[d->name], colname[d->colour]); + printf("%s \xc2\xb7 %s\n", dname, colname[dcol]); n = printf("%s for %s\n", FORMNAME, datestr) - 1; /* underline that line */ while (n-- > 0) putchar('='); @@ -263,6 +284,6 @@ int main(int argc, char **argv) { wrap = istty ? termwidth() : 0; load_text(); - print_day(off, datestr, gospel, wrap); + print_day(off, datestr, m, dd, gospel, wrap); return 0; } -- cgit v1.3