mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-03-22 02:31:28 +00:00
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.
This commit is contained in:
parent
35988b6191
commit
b3fc77efd6
2 changed files with 28 additions and 2 deletions
26
ftepp.c
26
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)
|
||||
|
|
4
gmqcc.h
4
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);
|
||||
|
|
Loading…
Reference in a new issue