aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2022-02-03 16:18:46 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2022-02-03 16:20:12 -0500
commit9bd02f75c1e1508e5acce884b7a5c80efce529c7 (patch)
tree3df949aacb912c8aefac48203c24ca4218257d48
parent56814c85dff9c497892a76cb43a65380880945cf (diff)
downloadweekly-9bd02f75c1e1508e5acce884b7a5c80efce529c7.tar.gz
Let the user modify the journal storage path with the WEEKLY_JOURNAL_ROOT environment variable.
* Now that the path can be modified at random an existence check was added before calling dump_week(...)
-rw-r--r--main.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/main.c b/main.c
index c9712b6..b1a24ce 100644
--- a/main.c
+++ b/main.c
@@ -13,6 +13,9 @@ const char *FMT_FOOTER = "\x03\x03\x03";
const char *USAGE_STATEMENT = \
"usage: %s [-h] [-V] [-dDys] [-]\n\n"
"Weekly Report Generator v%s\n\n"
+ "Environment Variables:\n"
+ "WEEKLY_JOURNAL_ROOT Override journal destination\n"
+ " (e.g., /shared/weeklies/$USER)\n\n"
"Options:\n"
"--help -h Show this usage statement\n"
"--dump-relative -d Dump records relative to current week\n"
@@ -77,6 +80,7 @@ int main(int argc, char *argv[]) {
int user_week;
char *user_week_error;
int style;
+ char *user_journalroot;
// Set program name
program_name = argv[0];
@@ -127,7 +131,11 @@ int main(int argc, char *argv[]) {
// Populate footer string
strcpy(footer, FMT_FOOTER);
// Populate path(s)
- sprintf(journalroot, "%s%c.weekly", homedir, DIRSEP_C);
+ if ((user_journalroot = getenv("WEEKLY_JOURNAL_ROOT")) != NULL) {
+ strcpy(journalroot, user_journalroot);
+ } else {
+ sprintf(journalroot, "%s%c.weekly", homedir, DIRSEP_C);
+ }
sprintf(intermediates, "%s%ctmp", journalroot, DIRSEP_C);
// Prime argument triggers
@@ -216,6 +224,11 @@ int main(int argc, char *argv[]) {
if (week < 1) {
week = 1;
}
+ if (access(journalroot, F_OK) < 0) {
+ fprintf(stderr, "Unable to read week %d of %d from journal root: %s: %s\n",
+ week, year, strerror(errno), journalroot);
+ exit(1);
+ }
if (dump_week(journalroot, year, week, style) < 0) {
fprintf(stderr, "No entries found for week %d of %d\n", week, year);
exit(1);