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

@ -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;