From 5acba7ec754c42fef28b1427166a2fe3c639b71b Mon Sep 17 00:00:00 2001 From: kichik Date: Fri, 26 Nov 2004 18:49:50 +0000 Subject: [PATCH] added /date switch to !define for definition of date and time constants git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3785 212acab6-be3b-0410-9dea-997c60f758d6 --- Docs/src/defines.but | 6 +++++- Source/script.cpp | 41 +++++++++++++++++++++++++++++++++++++---- Source/tokens.cpp | 2 +- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Docs/src/defines.but b/Docs/src/defines.but index 21e33c5d..8142bd2b 100644 --- a/Docs/src/defines.but +++ b/Docs/src/defines.but @@ -10,11 +10,15 @@ Define/conditional compilation related commands: \S1{define} !define -\c gflag [value] +\c [/date] gflag [value] This command will add 'gflag' to the global define list. This will have a similar effect as using the /D switch on the command line (only the define only becomes effective after the !define command). +If \e{/date} is used, \e{value} will be passed into strftime and the result will be used as the value of \e{gflag}. strftime converts special symbols into certain parts of the current time or date. For example, %H will be converted into the current hour in 24-hour format. For a complete list of available symbols, search for strftime on \W{http://msdn.microsoft.com/}{MSDN}. On POSIX, you can get the list by using \c{man strftime}. + +\c !define USE_SOMETHING \c !define VERSION 1.2 +\c !define /date NOW "%H:%M:%S %d %b, %Y" \S1{undef} !undef diff --git a/Source/script.cpp b/Source/script.cpp index 25f1d4e0..d1389f29 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -11,6 +11,7 @@ #include "dirreader.h" #include "exehead/resource.h" #include // for assert(3) +#include using namespace std; @@ -18,7 +19,6 @@ using namespace std; # include #else # include -# include # include # include // for O_RDONLY # include @@ -2532,12 +2532,45 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) // preprocessor-ish (ifdef/ifndef/else/endif are handled one step out from here) /////////////////////////////////////////////////////////////////////////////// case TOK_P_DEFINE: - if (definedlist.add(line.gettoken_str(1),line.gettoken_str(2))) + { + char *define=line.gettoken_str(1); + char *value; + char datebuf[256]; + bool date=false; + + if (!stricmp(define,"/date")) { + if (line.getnumtokens()!=4) PRINTHELP() + + define=line.gettoken_str(2); + value=line.gettoken_str(3); + + time_t rawtime; + time(&rawtime); + + datebuf[0]=0; + size_t s=strftime(datebuf,sizeof(datebuf),value,localtime(&rawtime)); + + if (s < 0) + datebuf[0]=0; + else + datebuf[max(s,sizeof(datebuf)-1)]=0; + + value=datebuf; + + date=true; + } else { + if (line.getnumtokens()==4) PRINTHELP() + + value=line.gettoken_str(2); + } + + if (definedlist.add(define,value)) { - ERROR_MSG("!define: \"%s\" already defined!\n",line.gettoken_str(1)); + ERROR_MSG("!define: \"%s\" already defined!\n",define); return PS_ERROR; } - SCRIPT_MSG("!define: \"%s\"=\"%s\"\n",line.gettoken_str(1),line.gettoken_str(2)); + SCRIPT_MSG("!define: %s\"%s\"=\"%s\"\n",date?"/date ":"",define,date?line.gettoken_str(3):value); + } return PS_OK; case TOK_P_UNDEF: if (definedlist.del(line.gettoken_str(1))) diff --git a/Source/tokens.cpp b/Source/tokens.cpp index a73c5a57..40744d22 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -225,7 +225,7 @@ static tokenType tokenlist[TOK__LAST] = {TOK_P_IFDEF,"!ifdef",1,-1,"symbol [| symbol2 [& symbol3 [...]]]",TP_ALL}, {TOK_P_IFNDEF,"!ifndef",1,-1,"symbol [| symbol2 [& symbol3 [...]]]",TP_ALL}, {TOK_P_ENDIF,"!endif",0,0,"",TP_ALL}, -{TOK_P_DEFINE,"!define",1,1,"symbol [value]",TP_ALL}, +{TOK_P_DEFINE,"!define",1,2,"[/date] symbol [value]",TP_ALL}, {TOK_P_UNDEF,"!undef",1,1,"symbol [value]",TP_ALL}, {TOK_P_ELSE,"!else",0,-1,"[ifdef|ifndef symbol [|symbol2 [& symbol3 [...]]]]",TP_ALL}, {TOK_P_ECHO,"!echo",1,0,"message",TP_ALL},