summaryrefslogtreecommitdiff
path: root/src/daily.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daily.c')
-rw-r--r--src/daily.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/daily.c b/src/daily.c
new file mode 100644
index 0000000..74f41c4
--- /dev/null
+++ b/src/daily.c
@@ -0,0 +1,61 @@
+ /**
+ * Journal-tools daily simplifies writing daily journal entries
+ * Copyright (C) 2023 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/>.
+ */
+#include <stdio.h>
+#include <string.h>
+
+#include "path.h"
+#include "edit.h"
+
+void path_set(struct path* path) {
+ // Only resolve these once
+ if(path->base[0] == 0)
+ path_get_daily_journaldir("DAILYJOURNAL_DIR", path->base, sizeof(path->base));
+ if(path->ext[0] == 0)
+ path_get_ext("DAILYJOURNAL_EXT", path->ext, sizeof(path->ext));
+
+ path_date_fmt_filename("%F", path->offset, path->name, sizeof(path->name));
+}
+
+
+int main(int argc, char* argv[]) {
+ int argoffset = 0;
+ struct path path;
+
+ memset(&path, 0, sizeof(struct path)); // Zero mem
+
+ // Read week offset if provided
+ if(argc > 1) {
+ argoffset = strtol(argv[1], NULL, 10);
+ path.offset = argoffset * 24 * 60 * 60;
+ }
+
+ if(argoffset < 0) {
+ void (*namecb)() = &path_set;
+ if(path_find_timepast(argoffset, 365 * 2, namecb, &path) == -1) {
+ fputs("Could not find notes within past two years\n", stderr);
+ return 1;
+ }
+ } else {
+ path_set(&path);
+ }
+
+ // For debugging
+ printf("Opening %s/%s.%s\n", path.base, path.name, path.ext);
+ edit_exec(path.base, path.name, path.ext);
+ return 0;
+}

Generated by cgit