commit a23e5c2

grunfink  ·  2025-09-09 06:44:00 +0000 UTC
parent 4b5e945
Set the scheduled date via the -d argument instead of a envvar.
1 files changed,  +24, -18
M main.c
M main.c
+24, -18
 1@@ -807,34 +807,40 @@ int main(int argc, char *argv[])
 2         xs *attl = xs_list_new();
 3         const char *fn = NULL;
 4         const char *in_reply_to = NULL;
 5-        const char **next = NULL;
 6+        const char **arg_irt = NULL;
 7+        int arg_date = 0;
 8         xs *post_date = NULL;
 9 
10-        const char *env_date = getenv("SNAC_POST_DATE");
11-        if (env_date) {
12-            /* convert to ISO */
13-            time_t t = xs_parse_localtime(env_date, "%Y%m%d%H%M%S");
14-
15-            if (t == 0) {
16-                fprintf(stderr, "Invalid $SNAC_POST_DATE format (must be YYYYmmddHHMMSS)\n");
17-                return 1;
18-            }
19-
20-            post_date = xs_str_iso_date(t);
21-        }
22-
23         /* iterate possible attachments */
24         while ((fn = GET_ARGV())) {
25             FILE *f;
26 
27-            if (next) {
28-                *next = fn;
29-                next = NULL;
30+            if (arg_irt) {
31+                *arg_irt = fn;
32+                arg_irt = NULL;
33+            }
34+            else
35+            if (arg_date) {
36+                /* convert to ISO */
37+                time_t t = xs_parse_localtime(fn, "%Y%m%d%H%M%S");
38+
39+                if (t == 0) {
40+                    fprintf(stderr, "Invalid scheduled date format (must be YYYYmmddHHMMSS)\n");
41+                    return 1;
42+                }
43+
44+                post_date = xs_str_iso_date(t);
45+                arg_date = 0;
46             }
47             else
48             if (strcmp(fn, "-r") == 0) {
49                 /* next argument is an inReplyTo */
50-                next = &in_reply_to;
51+                arg_irt = &in_reply_to;
52+            }
53+            else
54+            if (strcmp(fn, "-d") == 0) {
55+                /* next argument is the schedule date */
56+                arg_date = 1;
57             }
58             else
59             if ((f = fopen(fn, "rb")) != NULL) {