From 5e2948eda99d3efbb172cfb29251a3fa5075e8b6 Mon Sep 17 00:00:00 2001 From: kichik Date: Tue, 25 Nov 2003 06:25:31 +0000 Subject: [PATCH] Added support for reading environmental variables on compile time - $%envVarName%. git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3205 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/script.cpp | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/Source/script.cpp b/Source/script.cpp index 6fa6c09a..745ab7e3 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -417,9 +417,9 @@ void CEXEBuild::ps_addtoline(const char *str, GrowBuf &linedata, StringList &his void CEXEBuild::ps_addtoline(const char *str, GrowBuf &linedata, StringList &hist) #endif { - // convert $\r, $\n to their literals - // preprocessor replace ${VAR} with whatever value - // note that if VAR does not exist, ${VAR} will go through unmodified + // convert $\r, $\n to their literals + // preprocessor replace ${VAR} and $%VAR% with whatever value + // note that if VAR does not exist, ${VAR} or $%VAR% will go through unmodified const char *in=str; while (*in) { @@ -485,7 +485,39 @@ void CEXEBuild::ps_addtoline(const char *str, GrowBuf &linedata, StringList &his add=0; hist.add((char*)defname.get(),0); #ifdef NSIS_FIX_DEFINES_IN_STRINGS - ps_addtoline(t,linedata,hist, true); + ps_addtoline(t,linedata,hist,true); +#else + ps_addtoline(t,linedata,hist); +#endif + hist.delbypos(hist.find((char*)defname.get(),0)); + } + } + free(s); + } + else if (in[0] == '%') + { + char *s=strdup(in+1); + char *t=s; + while (*t) + { + if (*t == '%') break; + t=CharNext(t); + } + if (*t && t!=s) + { + *t=0; + // check for defines inside the define name - ${bla${blo}} + GrowBuf defname; + ps_addtoline(s,defname,hist); + defname.add("",1); + t=getenv((char*)defname.get()); + if (t && hist.find((char*)defname.get(),0)<0) + { + in+=strlen(s)+2; + add=0; + hist.add((char*)defname.get(),0); +#ifdef NSIS_FIX_DEFINES_IN_STRINGS + ps_addtoline(t,linedata,hist,true); #else ps_addtoline(t,linedata,hist); #endif @@ -495,9 +527,9 @@ void CEXEBuild::ps_addtoline(const char *str, GrowBuf &linedata, StringList &his free(s); } #ifdef NSIS_FIX_DEFINES_IN_STRINGS - else if (in[0] == '$' ) + else if (in[0] == '$') { - if ( in[1] == '{' ) // Found $$ before - Don't replace this define + if (in[1] == '{') // Found $$ before - Don't replace this define { char *s=strdup(in+2); char *t=s; @@ -508,7 +540,7 @@ void CEXEBuild::ps_addtoline(const char *str, GrowBuf &linedata, StringList &his if (*t == '}' && bn-- == 0) break; t=CharNext(t); } - if (*t && t!=s ) + if (*t && t!=s) { *t=0; // add text unchanged