diff options
Diffstat (limited to 'src/journal.c')
-rw-r--r-- | src/journal.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/journal.c b/src/journal.c new file mode 100644 index 0000000..eb38db2 --- /dev/null +++ b/src/journal.c @@ -0,0 +1,63 @@ +/** + * Dailyjournal is an easy tool to log daily activities + * Copyright (C) 2022 Aaron Ball <nullspoon@oper.io> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#define _XOPEN_SOURCE +#include <stdio.h> + +#include "common.h" +#include "config.h" + +int main(int argc, char* argv[]) { + char notepath[256] = {'\0'}; + int i = 0; + struct config c; + + memset(&c, sizeof(struct config), 1); + config_init(&c); + + int days = 0; + if(argc > 1) + days = strtol(argv[1], NULL, 10); + + // If user requests negative days, we want to skip non-existant days. So `-2` + // is really "two entries ago" rather than two days ago, which could yield + // creating an empty historical note if one does not already exist (for + // example: on Monday, opening Friday's entry which is -3 days, but -1 + // entry). + if(days < 0) { + while(days < 0) { + i--; + getpath(c.journaldir, i, notepath, c.extension); + if(fexists(notepath)) + days++; + // Stop traversing after a year to avoid infinite loops when no notes + // exist (or exist very long ago) + if(i < -365) { + fprintf(stderr, "Refusing to search further back than one year\n"); + return 1; + } + } + } else { + getpath(c.journaldir, days, notepath, c.extension); + } + + if(safe_cp(c.templatepath, notepath) == -2) { + printf("No template found at %s\n", c.templatepath); + return 2; + } + return fedit(notepath); +} |