]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Implemented __DATE__ for ftepp
authorDale Weiler <killfieldengine@gmail.com>
Wed, 2 Jan 2013 21:51:22 +0000 (21:51 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Wed, 2 Jan 2013 21:51:22 +0000 (21:51 +0000)
ftepp.c

diff --git a/ftepp.c b/ftepp.c
index 426bfc147f84ca624b4f92bc91b71938826aeeaa..a5c50ee85544ad98dc808d44f130eb6f3fe98953 100644 (file)
--- a/ftepp.c
+++ b/ftepp.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
+#include <time.h>
 #include "gmqcc.h"
 #include "lexer.h"
 
@@ -81,6 +82,24 @@ typedef struct {
 static uint32_t ftepp_predef_countval = 0;
 static uint32_t ftepp_predef_randval  = 0;
 
+/* __DATE__ */
+char *ftepp_predef_date(lex_file *context) {
+    struct tm *itime;
+    time_t     rtime;
+    char      *value = mem_a(82);
+    /* 82 is enough for strftime but we also have " " in our string */
+
+    (void)context;
+
+    /* get time */
+    time (&rtime);
+    itime = localtime(&rtime);
+
+    strftime(value, 82, "\"%b %d %Y\"", itime);
+
+    return value;
+}
+
 /* __LINE__ */
 char *ftepp_predef_line(lex_file *context) {
     char   *value;
@@ -138,6 +157,7 @@ static const predef_t ftepp_predefs[] = {
     { "__COUNTER_LAST__", &ftepp_predef_counterlast },
     { "__RANDOM__",       &ftepp_predef_random      },
     { "__RANDOM_LAST__",  &ftepp_predef_randomlast  },
+    { "__DATE__",         &ftepp_predef_date        }
 };
 
 #define ftepp_tokval(f) ((f)->lex->tok.value)