1 /**
2 * Journal-tools weekly simplifies writing weekly journal entries
3 * Copyright (C) 2023 Aaron Ball, nullspoon@oper.io
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include <stdio.h>
19 #include <string.h>
20
21 #include "path.h"
22 #include "edit.h"
23
24 void path_set(struct path* path) {
25 // Only resolve these once
26 if(path->base[0] == 0)
27 path_get_weekly_journaldir("WEEKLYJOURNAL_DIR", path->base, sizeof(path->base));
28 if(path->ext[0] == 0)
29 path_get_ext("WEEKLYJOURNAL_EXT", path->ext, sizeof(path->ext));
30
31 path_date_fmt_filename("%Gw%V", path->offset, path->name, sizeof(path->name));
32 }
33
34
35 int main(int argc, char* argv[]) {
36 int argoffset = 0;
37 struct path path;
38
39 memset(&path, 0, sizeof(struct path)); // Zero mem
40
41 // Read week offset if provided
42 if(argc > 1) {
43 argoffset = strtol(argv[1], NULL, 10);
44 path.offset = argoffset * 7 * 24 * 60 * 60;
45 }
46
47 if(argoffset < 0) {
48 void (*namecb)() = &path_set;
49 if(path_find_timepast(argoffset, 52 * 2, namecb, &path) == -1) {
50 fputs("Could not find notes within past two years\n", stderr);
51 return 1;
52 }
53 } else {
54 path_set(&path);
55 }
56
57 // For debugging
58 //printf("Opening %s/%s.%s\n", path.base, path.name, path.ext);
59 edit_exec(path.base, path.name, path.ext);
60 return 0;
61 }
|