shithub: rgbds

Download patch

ref: f97e3bad33e654cc0d7fa4f301e6fc22f02d68b6
parent: 64415555f17dc4efd928dceabb9729c0e214c4b1
parent: 947db1e21b93653798af48214b6ea28464f6119f
author: Antonio Niño Díaz <[email protected]>
date: Sat Apr 22 07:36:59 EDT 2017

Merge pull request #171 from NieDzejkob/master

Implement separate time constants

Signed-off-by: Antonio Niño Díaz <[email protected]>

--- a/src/asm/rgbasm.5
+++ b/src/asm/rgbasm.5
@@ -521,6 +521,12 @@
 .It Ic EQUS Ta Ic __TIME__ Ta Ta The current time
 .It Ic EQUS Ta Ic __ISO_8601_LOCAL__ Ta ISO 8601 timestamp (local)
 .It Ic EQUS Ta Ic __ISO_8601_UTC__ Ta ISO 8601 timestamp (UTC)
+.It Ic EQU Ta Ic __UTC_YEAR__ Ta Ta Today's year
+.It Ic EQU Ta Ic __UTC_MONTH__ Ta Ta Today's month number, 1-12
+.It Ic EQU Ta Ic __UTC_DAY__ Ta Ta Today's day of the month, 1-31
+.It Ic EQU Ta Ic __UTC_HOUR__ Ta Ta Current hour, 0-23
+.It Ic EQU Ta Ic __UTC_MINUTE__ Ta Ta Current minute, 0-59
+.It Ic EQU Ta Ic __UTC_SECOND__ Ta Ta Current second, 0-59
 .El
 .Pp
 .Sh DEFINING DATA
--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -24,8 +24,29 @@
 char SavedDATE[256];
 char SavedTIMESTAMP_ISO8601_LOCAL[256];
 char SavedTIMESTAMP_ISO8601_UTC[256];
+char SavedDAY[3];
+char SavedMONTH[3];
+char SavedYEAR[5];
+char SavedHOUR[3];
+char SavedMINUTE[3];
+char SavedSECOND[3];
 bool exportall;
 
+void helper_RemoveLeadingZeros(char * string){
+	char * new_beginning = string;
+
+	while(*new_beginning == '0')
+		new_beginning++;
+
+	if(new_beginning == string)
+		return;
+
+	if(*new_beginning == '\0')
+		new_beginning--;
+
+	memmove(string, new_beginning, strlen(new_beginning) + 1);
+}
+
 SLONG
 Callback_NARG(struct sSymbol * sym)
 {
@@ -800,6 +821,12 @@
 	sym_AddString("__DATE__", SavedDATE);
 	sym_AddString("__ISO_8601_LOCAL__", SavedTIMESTAMP_ISO8601_LOCAL);
 	sym_AddString("__ISO_8601_UTC__", SavedTIMESTAMP_ISO8601_UTC);
+	sym_AddString("__UTC_DAY__", SavedDAY);
+	sym_AddString("__UTC_MONTH__", SavedMONTH);
+	sym_AddString("__UTC_YEAR__", SavedYEAR);
+	sym_AddString("__UTC_HOUR__", SavedHOUR);
+	sym_AddString("__UTC_MINUTE__", SavedMINUTE);
+	sym_AddString("__UTC_SECOND__", SavedSECOND);
 	sym_AddSet("_RS", 0);
 
 	sym_AddEqu("_NARG", 0);
@@ -845,6 +872,19 @@
 		struct tm *time_utc = gmtime(&now);
 		strftime(SavedTIMESTAMP_ISO8601_UTC,
 			sizeof(SavedTIMESTAMP_ISO8601_UTC), "\"%FT%TZ\"", time_utc);
+
+		strftime(SavedDAY, sizeof(SavedDAY), "%d", time_utc);
+		strftime(SavedMONTH, sizeof(SavedMONTH), "%m", time_utc);
+		strftime(SavedYEAR, sizeof(SavedYEAR), "%Y", time_utc);
+		strftime(SavedHOUR, sizeof(SavedHOUR), "%H", time_utc);
+		strftime(SavedMINUTE, sizeof(SavedMINUTE), "%M", time_utc);
+		strftime(SavedSECOND, sizeof(SavedSECOND), "%S", time_utc);
+
+		helper_RemoveLeadingZeros(SavedDAY);
+		helper_RemoveLeadingZeros(SavedMONTH);
+		helper_RemoveLeadingZeros(SavedHOUR);
+		helper_RemoveLeadingZeros(SavedMINUTE);
+		helper_RemoveLeadingZeros(SavedSECOND);
 	} else {
 		warnx("Couldn't determine current time.");
 		/* The '?' have to be escaped or they will be treated as
@@ -853,6 +893,12 @@
 		strcpy(SavedDATE, "\"\?\? \?\?\? \?\?\?\?\"");
 		strcpy(SavedTIMESTAMP_ISO8601_LOCAL, "\"\?\?\?\?-\?\?-\?\?T\?\?:\?\?:\?\?+\?\?\?\?\"");
 		strcpy(SavedTIMESTAMP_ISO8601_UTC, "\"\?\?\?\?-\?\?-\?\?T\?\?:\?\?:\?\?Z\"");
+		strcpy(SavedDAY, "1");
+		strcpy(SavedMONTH, "1");
+		strcpy(SavedYEAR, "1900");
+		strcpy(SavedHOUR, "0");
+		strcpy(SavedMINUTE, "0");
+		strcpy(SavedSECOND, "0");
 	}
 
 	sym_AddString("__TIME__", SavedTIME);
@@ -859,6 +905,12 @@
 	sym_AddString("__DATE__", SavedDATE);
 	sym_AddString("__ISO_8601_LOCAL__", SavedTIMESTAMP_ISO8601_LOCAL);
 	sym_AddString("__ISO_8601_UTC__", SavedTIMESTAMP_ISO8601_UTC);
+	sym_AddString("__UTC_DAY__", SavedDAY);
+	sym_AddString("__UTC_MONTH__", SavedMONTH);
+	sym_AddString("__UTC_YEAR__", SavedYEAR);
+	sym_AddString("__UTC_HOUR__", SavedHOUR);
+	sym_AddString("__UTC_MINUTE__", SavedMINUTE);
+	sym_AddString("__UTC_SECOND__", SavedSECOND);
 
 	pScope = NULL;