From 5cfa15f963ce58b79ac9a8395bc9553d7313ff8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ni=C3=B1o=20D=C3=ADaz?= Date: Sun, 9 Apr 2017 16:49:34 +0100 Subject: [PATCH] Add equates with ISO 8601 date and time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added `__TIMESTAMP_ISO_8601_LOCAL__` and `__TIMESTAMP_ISO_8601_UTC__`, with the correct ISO 8601 representation of time and date from years to seconds (including local timezone in the local time string). Also, if the current time cannot be obtained from the OS, it will output a warning and the time strings will be filled with '?' instead of numbers and characters. Signed-off-by: Antonio Niño Díaz --- src/asm/symbol.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/asm/symbol.c b/src/asm/symbol.c index db5f5a95..974732d3 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -12,6 +12,7 @@ #include "asm/main.h" #include "asm/mymath.h" #include "asm/output.h" +#include "extern/err.h" struct sSymbol *tHashedSymbols[HASHSIZE]; struct sSymbol *pScope = NULL; @@ -21,6 +22,8 @@ char *currentmacroargs[MAXMACROARGS + 1]; char *newmacroargs[MAXMACROARGS + 1]; char SavedTIME[256]; char SavedDATE[256]; +char SavedTIMESTAMP_ISO8601_LOCAL[256]; +char SavedTIMESTAMP_ISO8601_UTC[256]; bool exportall; SLONG @@ -795,6 +798,8 @@ sym_PrepPass2(void) sym_AddString("__TIME__", SavedTIME); sym_AddString("__DATE__", SavedDATE); + sym_AddString("__TIMESTAMP_ISO_8601_LOCAL__", SavedTIMESTAMP_ISO8601_LOCAL); + sym_AddString("__TIMESTAMP_ISO_8601_UTC__", SavedTIMESTAMP_ISO8601_UTC); sym_AddSet("_RS", 0); sym_AddEqu("_NARG", 0); @@ -811,7 +816,7 @@ void sym_Init(void) { SLONG i; - time_t tod; + time_t now; for (i = 0; i < MAXMACROARGS; i += 1) { currentmacroargs[i] = NULL; @@ -829,15 +834,32 @@ sym_Init(void) sym_AddSet("_RS", 0); - if (time(&tod) != -1) { - struct tm *tptr; + if (time(&now) != -1) { + struct tm *time_local = localtime(&now); - tptr = localtime(&tod); - strftime(SavedTIME, sizeof(SavedTIME), "\"%H:%M:%S\"", tptr); - strftime(SavedDATE, sizeof(SavedDATE), "\"%d %B %Y\"", tptr); - sym_AddString("__TIME__", SavedTIME); - sym_AddString("__DATE__", SavedDATE); + strftime(SavedTIME, sizeof(SavedTIME), "\"%H:%M:%S\"", time_local); + strftime(SavedDATE, sizeof(SavedDATE), "\"%d %B %Y\"", time_local); + strftime(SavedTIMESTAMP_ISO8601_LOCAL, + sizeof(SavedTIMESTAMP_ISO8601_LOCAL), "\"%FT%T%z\"", time_local); + + struct tm *time_utc = gmtime(&now); + strftime(SavedTIMESTAMP_ISO8601_UTC, + sizeof(SavedTIMESTAMP_ISO8601_UTC), "\"%FT%TZ\"", time_utc); + } else { + warnx("Couldn't determine current time."); + /* The '?' have to be escaped or they will be treated as + * trigraphs... */ + strcpy(SavedTIME, "\"\?\?:\?\?:\?\?\""); + strcpy(SavedDATE, "\"\?\? \?\?\? \?\?\?\?\""); + strcpy(SavedTIMESTAMP_ISO8601_LOCAL, "\"\?\?\?\?-\?\?-\?\?T\?\?:\?\?:\?\?+\?\?\?\?\""); + strcpy(SavedTIMESTAMP_ISO8601_UTC, "\"\?\?\?\?-\?\?-\?\?T\?\?:\?\?:\?\?Z\""); } + + sym_AddString("__TIME__", SavedTIME); + sym_AddString("__DATE__", SavedDATE); + sym_AddString("__TIMESTAMP_ISO_8601_LOCAL__", SavedTIMESTAMP_ISO8601_LOCAL); + sym_AddString("__TIMESTAMP_ISO_8601_UTC__", SavedTIMESTAMP_ISO8601_UTC); + pScope = NULL; math_DefinePI();