* [PATCH] __DATE__ & __TIME expansion v2
@ 2007-05-20 23:39 Damien Lespiau
2007-05-21 0:40 ` Josh Triplett
0 siblings, 1 reply; 2+ messages in thread
From: Damien Lespiau @ 2007-05-20 23:39 UTC (permalink / raw)
To: linux-sparse; +Cc: Damien Lespiau
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@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-05-21 0:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-20 23:39 [PATCH] __DATE__ & __TIME expansion v2 Damien Lespiau
2007-05-21 0:40 ` Josh Triplett
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).