diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2022-02-03 16:18:46 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2022-02-03 16:20:12 -0500 |
commit | 9bd02f75c1e1508e5acce884b7a5c80efce529c7 (patch) | |
tree | 3df949aacb912c8aefac48203c24ca4218257d48 /main.c | |
parent | 56814c85dff9c497892a76cb43a65380880945cf (diff) | |
download | weekly-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(...)
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -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); |