From b3fc77efd678333ca5ed0fef50cedb866e484f92 Mon Sep 17 00:00:00 2001
From: Dale Weiler <killfieldengine@gmail.com>
Date: Wed, 24 Apr 2013 04:48:05 +0000
Subject: [PATCH] Implemented __TIME_STAMP__ predef, expands to a timestamp of
 when the __FILE__ was last modified, returned in the format: "Www Mmm dd
 hh:mm:ss yyyy", where Www is the weekday, Mmm the month (in letter), dd the
 day of the month, hh:mm:ss the time, and yyyy the year.

---
 ftepp.c | 26 +++++++++++++++++++++++++-
 gmqcc.h |  4 +++-
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/ftepp.c b/ftepp.c
index 7d5ba3e..28db0d2 100755
--- a/ftepp.c
+++ b/ftepp.c
@@ -22,6 +22,7 @@
  * SOFTWARE.
  */
 #include <time.h>
+#include <sys/stat.h>
 #include "gmqcc.h"
 #include "lexer.h"
 
@@ -174,6 +175,28 @@ char *ftepp_predef_randomlast(lex_file *context) {
     (void)context;
     return value;
 }
+/* __TIMESTAMP__ */
+char *ftepp_predef_timestamp(lex_file *context) {
+    struct stat finfo;
+    char       *find;
+    char       *value;
+    size_t      size;
+    if (stat(context->name, &finfo))
+        return util_strdup("\"<failed to determine timestamp>\"");
+
+    /*
+     * ctime and it's fucking annoying newline char, no worries, we're
+     * professionals here.
+     */   
+    find  = ctime(&finfo.st_mtime);
+    value = (char*)mem_a(strlen(find) + 1);
+    memcpy(&value[1], find, (size = strlen(find)) - 1);
+
+    value[0]    = '"';
+    value[size] = '"';
+
+    return value;
+}
 
 const ftepp_predef_t ftepp_predefs[FTEPP_PREDEF_COUNT] = {
     { "__LINE__",         &ftepp_predef_line        },
@@ -183,7 +206,8 @@ const ftepp_predef_t ftepp_predefs[FTEPP_PREDEF_COUNT] = {
     { "__RANDOM__",       &ftepp_predef_random      },
     { "__RANDOM_LAST__",  &ftepp_predef_randomlast  },
     { "__DATE__",         &ftepp_predef_date        },
-    { "__TIME__",         &ftepp_predef_time        }
+    { "__TIME__",         &ftepp_predef_time        },
+    { "__TIME_STAMP__",   &ftepp_predef_timestamp   }
 };
 
 #define ftepp_tokval(f) ((f)->lex->tok.value)
diff --git a/gmqcc.h b/gmqcc.h
index 6ae52e9..cc95234 100755
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -1012,9 +1012,11 @@ typedef struct {
 
 /*
  * line, file, counter, counter_last, random, random_last, date, time
+ * time_stamp.
+ * 
  * increment when items are added
  */
-#define FTEPP_PREDEF_COUNT 8
+#define FTEPP_PREDEF_COUNT 9
 
 struct ftepp_s *ftepp_create           ();
 bool            ftepp_preprocess_file  (struct ftepp_s *ftepp, const char *filename);