commit 60b6209

zzo38  ·  2023-06-14 22:53:40 +0000 UTC
parent 7654122
Correct the -T switch.
2 files changed,  +33, -9
M main.c
+12, -2
 1@@ -32,13 +32,23 @@
 2   time it is read. If you put less numbers than expected, then zero will
 3   be used for the remaining values; however, some programs will use these
 4   values to seed a random number generator and will not work correctly if
 5-  they are zero.
 6+  they are zero. (Note that the month number is zero-based, while the day
 7+  number is one-based.)
 8+
 9+-T @unixtime
10+  Use a fixed value for the date/time like the other -T does, but treat
11+  the argument as UNIX time if the argument starts with a at sign; it will
12+  be converted to the corresponding date/time in the Gregorian calendar.
13+  In this case, the presence or absence of the -Z switch does matter,
14+  since it will convert it to local time if the -Z switch is not specified
15+  or to UTC if the -Z switch is specified.
16 
17 -Y
18   Enable file system access including writing.
19 
20 -Z
21-  Use UTC instead of local time. (Has no effect in combination with -T.)
22+  Use UTC instead of local time. (Has no effect in combination with -T,
23+  unless the UNIX time variant of -T is used.)
24 
25 -a #
26   Set audio. See the below section about audio for details. If both -a and
M main.c
+21, -7
 1@@ -1363,13 +1363,28 @@ static int stdin_thread_fn(void*unused) {
 2 
 3 static void set_datetime(char*s) {
 4   int i=2;
 5-  i=strtol(s,&s,10);
 6-  PUT16(device[12].d,i);
 7-  if(*s) s++;
 8-  i=2;
 9-  while(*s && i<15) {
10-    device[12].d[i++]=strtol(s,&s,10);
11+  if(*s=='@') {
12+    struct tm r;
13+    time_t t=strtoll(s+1,0,10);
14+    if(use_utc) gmtime_r(&t,&r); else localtime_r(&t,&r);
15+    PUT16(device[12].d,r.tm_year+1900);
16+    device[12].d[2]=r.tm_mon;
17+    device[12].d[3]=r.tm_mday;
18+    device[12].d[4]=r.tm_hour;
19+    device[12].d[5]=r.tm_min;
20+    device[12].d[6]=r.tm_sec;
21+    device[12].d[7]=r.tm_wday;
22+    PUT16(device[12].d+8,r.tm_yday);
23+    device[12].d[10]=r.tm_isdst;
24+  } else {
25+    i=strtol(s,&s,10);
26+    PUT16(device[12].d,i);
27     if(*s) s++;
28+    i=2;
29+    while(*s && i<15) {
30+      device[12].d[i++]=strtol(s,&s,10);
31+      if(*s) s++;
32+    }
33   }
34 }
35 
36@@ -1553,7 +1568,6 @@ int main(int argc,char**argv) {
37     }
38   }
39   if(use_console) device[1].out=console_out;
40-  if(device[12].d[15]) device[12].d[15]=0; else device[12].in=datetime_in;
41   if(optind+1<argc) strncpy(uxnfile0.name,argv[optind+1],4095);
42   if(optind+2<argc) strncpy(uxnfile1.name,argv[optind+2],4095);
43   restart: