Added support for standard predefines ala C++, i.e., __DATE__, __TIME__, __TIMESTAMP__, __FILE__, __LINE__

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2634 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
icemank 2003-06-12 15:09:27 +00:00
parent 1ea2160310
commit 3b0cc4f1c4
4 changed files with 183 additions and 0 deletions

View file

@ -217,6 +217,31 @@ CEXEBuild::CEXEBuild()
include_dirs.add(szNSISDir,0);
}
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003
{
time_t etime;
struct tm * ltime;
SYSTEMTIME stime;
char datebuf[32];
char timebuf[32];
time(&etime);
ltime = localtime(&etime);
stime.wYear = ltime->tm_year+1900;
stime.wMonth = ltime->tm_mon + 1;
stime.wDay = ltime->tm_mday;
stime.wHour= ltime->tm_hour;
stime.wMinute= ltime->tm_min;
stime.wSecond= ltime->tm_sec;
stime.wMilliseconds= 0;
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stime, NULL, datebuf, sizeof(datebuf));
definedlist.add("__DATE__",(char *)datebuf);
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, timebuf, sizeof(timebuf));
definedlist.add("__TIME__",(char *)timebuf);
}
#endif
db_opt_save=db_comp_save=db_full_size=db_opt_save_u=db_comp_save_u=db_full_size_u=0;
// Added by Amir Szekely 31st July 2002

View file

@ -15,6 +15,13 @@ using namespace std;
#include "exehead/fileform.h"
#include "exehead/config.h"
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#endif
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
// Changed by Amir Szekely 31st July 2002
#include "compressor.h"
@ -96,6 +103,15 @@ class CEXEBuild {
int get_commandtoken(char *s, int *np, int *op);
// script.cpp
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003
char* set_file_predefine(char *);
void restore_file_predefine(char *);
char* set_timestamp_predefine(char *);
void restore_timestamp_predefine(char *);
char* set_line_predefine(int);
void restore_line_predefine(char *);
#endif
int parseScript();
void ps_addtoline(const char *str, GrowBuf &linedata, StringList &hist);
int doParse(const char *str);

View file

@ -348,6 +348,15 @@
#error NSIS_MAX_INST_TYPES > 32
#endif
#ifndef INVALID_FILE_ATTRIBUTES
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
#endif
// Added by Sunil Kamath 11 June 2003
#ifndef NSIS_SUPPORT_STANDARD_PREDEFINES
#define NSIS_SUPPORT_STANDARD_PREDEFINES
#endif
#endif//!APSTUDIO_INVOKED
#endif // NSIS_CONFIG_H

View file

@ -19,6 +19,85 @@
#define MAX_INCLUDEDEPTH 10
#define MAX_LINELENGTH 4096
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003
char *CEXEBuild::set_file_predefine(char *filename)
{
char *oldfilename = strdup(definedlist.find("__FILE__"));
if(oldfilename) definedlist.del("__FILE__");
char *p = strrchr(filename,'\\');
if(p) {
p++;
}
else {
p = curfilename;
}
p = strdup(p);
definedlist.add("__FILE__",p);
return oldfilename;
}
void CEXEBuild::restore_file_predefine(char *oldfilename)
{
definedlist.del("__FILE__");
if(oldfilename) definedlist.add("__FILE__",oldfilename);
}
char *CEXEBuild::set_timestamp_predefine(char *filename)
{
char *oldtimestamp = strdup(definedlist.find("__TIMESTAMP__"));
if(oldtimestamp) definedlist.del("__TIMESTAMP__");
char *timestampbuf = (char *)malloc(100);
char datebuf[80];
char timebuf[16];
struct stat fs;
struct tm * ltime;
SYSTEMTIME stime;
stat(filename, &fs);
ltime = localtime(&fs.st_mtime);
stime.wYear = ltime->tm_year+1900;
stime.wMonth = ltime->tm_mon + 1;
stime.wDay = ltime->tm_mday;
stime.wHour= ltime->tm_hour;
stime.wMinute= ltime->tm_min;
stime.wSecond= ltime->tm_sec;
stime.wMilliseconds= 0;
GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &stime, NULL, datebuf, sizeof(datebuf));
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, timebuf, sizeof(timebuf));
wsprintf(timestampbuf,"%s %s",datebuf,timebuf);
definedlist.add("__TIMESTAMP__",timestampbuf);
return oldtimestamp;
}
void CEXEBuild::restore_timestamp_predefine(char *oldtimestamp)
{
definedlist.del("__TIMESTAMP__");
if(oldtimestamp) definedlist.add("__TIMESTAMP__",oldtimestamp);
}
char *CEXEBuild::set_line_predefine(int linecnt)
{
char *linebuf = (char *)malloc(8);
wsprintf(linebuf,"%d",linecnt);
char *oldline = (char *)strdup(definedlist.find("__LINE__"));
if(oldline) definedlist.del("__LINE__");
definedlist.add("__LINE__",linebuf);
return oldline;
}
void CEXEBuild::restore_line_predefine(char *oldline)
{
definedlist.del("__LINE__");
if(oldline) definedlist.add("__LINE__",oldline);
}
#endif
int CEXEBuild::process_script(FILE *filepointer, char *filename)
{
@ -31,8 +110,21 @@ int CEXEBuild::process_script(FILE *filepointer, char *filename)
ERROR_MSG("Error (process_script): write_output already called, can't continue\n");
return PS_ERROR;
}
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003
char *oldfilename = set_file_predefine(curfilename);
char *oldtimestamp = set_timestamp_predefine(curfilename);
#endif
int ret=parseScript();
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003
restore_file_predefine(oldfilename);
restore_timestamp_predefine(oldtimestamp);
#endif
fp = 0;
curfilename = 0;
@ -322,9 +414,21 @@ int CEXEBuild::parseScript()
StringList hist;
GrowBuf linedata;
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003
char *oldline = set_line_predefine(linecnt);
#endif
ps_addtoline(str,linedata,hist);
linedata.add((void*)"",1);
int ret=doParse((char*)linedata.get());
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003
restore_line_predefine(oldline);
#endif
if (ret != PS_OK) return ret;
}
@ -340,7 +444,23 @@ int CEXEBuild::process_oneline(char *line, char *filename, int linenum)
StringList hist;
GrowBuf linedata;
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003
char *oldfilename = set_file_predefine(curfilename);
char *oldtimestamp = set_timestamp_predefine(curfilename);
char *oldline = set_line_predefine(linecnt);
#endif
ps_addtoline(line,linedata,hist);
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003
restore_file_predefine(oldfilename);
restore_timestamp_predefine(oldtimestamp);
restore_line_predefine(oldline);
#endif
linedata.add((void*)"",1);
int ret=doParse((char*)linedata.get());
@ -2103,8 +2223,21 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
FILE *last_fp=fp;
fp=incfp;
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003
char *oldfilename = set_file_predefine(curfilename);
char *oldtimestamp = set_timestamp_predefine(curfilename);
#endif
int r=parseScript();
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES
// Added by Sunil Kamath 11 June 2003
restore_file_predefine(oldfilename);
restore_timestamp_predefine(oldtimestamp);
#endif
int errlinecnt=linecnt;
linecnt=last_linecnt;