Implemented __TIME_STAMP__ predef, expands to a timestamp of when the __FILE__ was...
authorDale Weiler <killfieldengine@gmail.com>
Wed, 24 Apr 2013 04:48:05 +0000 (04:48 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Wed, 24 Apr 2013 04:48:05 +0000 (04:48 +0000)
ftepp.c
gmqcc.h

diff --git a/ftepp.c b/ftepp.c
index 7d5ba3e7b0e05dc867a9cd448098909ca07c0c70..28db0d2faec818c089d9e5115fce7c328972028f 100755 (executable)
--- 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 6ae52e9dff8579997566f86d7815a42fb3de2edf..cc952345986c7e6ae2578c73fcc48616ccd258a7 100755 (executable)
--- 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);