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
This commit is contained in:
parent
38ba938cee
commit
5acba7ec75
3 changed files with 43 additions and 6 deletions
|
@ -10,11 +10,15 @@ Define/conditional compilation related commands:
|
||||||
|
|
||||||
\S1{define} !define
|
\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).
|
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 VERSION 1.2
|
||||||
|
\c !define /date NOW "%H:%M:%S %d %b, %Y"
|
||||||
|
|
||||||
\S1{undef} !undef
|
\S1{undef} !undef
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "dirreader.h"
|
#include "dirreader.h"
|
||||||
#include "exehead/resource.h"
|
#include "exehead/resource.h"
|
||||||
#include <cassert> // for assert(3)
|
#include <cassert> // for assert(3)
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -18,7 +19,6 @@ using namespace std;
|
||||||
# include <direct.h>
|
# include <direct.h>
|
||||||
#else
|
#else
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
# include <time.h>
|
|
||||||
# include <glob.h>
|
# include <glob.h>
|
||||||
# include <fcntl.h> // for O_RDONLY
|
# include <fcntl.h> // for O_RDONLY
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
@ -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)
|
// preprocessor-ish (ifdef/ifndef/else/endif are handled one step out from here)
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
case TOK_P_DEFINE:
|
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;
|
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;
|
return PS_OK;
|
||||||
case TOK_P_UNDEF:
|
case TOK_P_UNDEF:
|
||||||
if (definedlist.del(line.gettoken_str(1)))
|
if (definedlist.del(line.gettoken_str(1)))
|
||||||
|
|
|
@ -225,7 +225,7 @@ static tokenType tokenlist[TOK__LAST] =
|
||||||
{TOK_P_IFDEF,"!ifdef",1,-1,"symbol [| symbol2 [& symbol3 [...]]]",TP_ALL},
|
{TOK_P_IFDEF,"!ifdef",1,-1,"symbol [| symbol2 [& symbol3 [...]]]",TP_ALL},
|
||||||
{TOK_P_IFNDEF,"!ifndef",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_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_UNDEF,"!undef",1,1,"symbol [value]",TP_ALL},
|
||||||
{TOK_P_ELSE,"!else",0,-1,"[ifdef|ifndef symbol [|symbol2 [& symbol3 [...]]]]",TP_ALL},
|
{TOK_P_ELSE,"!else",0,-1,"[ifdef|ifndef symbol [|symbol2 [& symbol3 [...]]]]",TP_ALL},
|
||||||
{TOK_P_ECHO,"!echo",1,0,"message",TP_ALL},
|
{TOK_P_ECHO,"!echo",1,0,"message",TP_ALL},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue