[PATCH] __DATE__ & __TIME expansion v2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Makes __DATE__expand to a character string literal of
the form "Mmm dd yyyy" where the names of the months
are the same as those generated by the asctime function,
and the first character of dd is a space character if the
value is less than 10.
Makes __TIME__ expand to a a character string literal of
the form "hh:mm:ss" as in the time generated by the
asctime function.

Signed-off-by: Damien Lespiau <damien.lespiau@xxxxxxxxx>
---
 ident-list.h  |    2 ++
 lib.c         |    2 --
 pre-process.c |   13 +++++++++++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/ident-list.h b/ident-list.h
index 7633a2f..dad22ef 100644
--- a/ident-list.h
+++ b/ident-list.h
@@ -75,6 +75,8 @@ __IDENT(pragma_ident, "__pragma__", 0);
 __IDENT(__VA_ARGS___ident, "__VA_ARGS__", 0);
 __IDENT(__LINE___ident, "__LINE__", 0);
 __IDENT(__FILE___ident, "__FILE__", 0);
+__IDENT(__DATE___ident, "__DATE__", 0);
+__IDENT(__TIME___ident, "__TIME__", 0);
 __IDENT(__func___ident, "__func__", 0);
 __IDENT(__FUNCTION___ident, "__FUNCTION__", 0);
 __IDENT(__PRETTY_FUNCTION___ident, "__PRETTY_FUNCTION__", 0);
diff --git a/lib.c b/lib.c
index 2162007..b678990 100644
--- a/lib.c
+++ b/lib.c
@@ -602,8 +602,6 @@ void create_builtin_stream(void)
 
 	/* FIXME! We need to do these as special magic macros at expansion time! */
 	add_pre_buffer("#define __BASE_FILE__ \"base_file.c\"\n");
-	add_pre_buffer("#define __DATE__ \"??? ?? ????\"\n");
-	add_pre_buffer("#define __TIME__ \"??:??:??\"\n");
 
 	if (optimize)
 		add_pre_buffer("#define __OPTIMIZE__ 1\n");
diff --git a/pre-process.c b/pre-process.c
index afae77a..2b9cecc 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -18,6 +18,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <time.h>
 
 #include "pre-process.h"
 #include "lib.h"
@@ -141,6 +142,8 @@ static int expand_one_symbol(struct token **list)
 {
 	struct token *token = *list;
 	struct symbol *sym;
+	static char buffer[12]; /* __DATE__: 3 + ' ' + 2 + ' ' + 4 + '\0' */
+	static time_t t = 0;
 
 	if (token->pos.noexpand)
 		return 1;
@@ -154,6 +157,16 @@ static int expand_one_symbol(struct token **list)
 		replace_with_integer(token, token->pos.line);
 	} else if (token->ident == &__FILE___ident) {
 		replace_with_string(token, stream_name(token->pos.stream));
+	} else if (token->ident == &__DATE___ident) {
+		if (!t)
+			time(&t);
+		strftime(buffer, 12, "%b %e %Y", localtime(&t));
+		replace_with_string(token, buffer);
+	} else if (token->ident == &__TIME___ident) {
+		if (!t)
+			time(&t);
+		strftime(buffer, 9, "%T", localtime(&t));
+		replace_with_string(token, buffer);
 	}
 	return 1;
 }
-- 
1.5.2.rc3.87.g404fd


-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux