From db6bc3bd00a148c1ea955faa7846369b8da9245d Mon Sep 17 00:00:00 2001 From: joost Date: Sun, 20 Feb 2011 00:04:20 +0000 Subject: [PATCH] * Replace environment variables placed between dollar signs in fpc.cfg with the value of the environment variable. git-svn-id: trunk@16945 - --- compiler/globals.pas | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/compiler/globals.pas b/compiler/globals.pas index 7475d34022..5dda1b5f3c 100644 --- a/compiler/globals.pas +++ b/compiler/globals.pas @@ -719,6 +719,10 @@ implementation ****************************************************************************} procedure DefaultReplacements(var s:ansistring); + var + envstr: string; + envvalue: pchar; + i: integer; begin { Replace some macros } Replace(s,'$FPCVERSION',version_string); @@ -730,6 +734,29 @@ implementation Replace(s,'$FPCTARGET',target_os_string) else Replace(s,'$FPCTARGET',target_full_string); + { Replace environment variables between dollar signs } + i := pos('$',s); + while i>0 do + begin + envstr:=copy(s,i+1,length(s)-i); + i:=pos('$',envstr); + if i>0 then + begin + envstr := copy(envstr,1,i-1); + envvalue := GetEnvPChar(envstr); + if assigned(envvalue) then + begin + Replace(s,'$'+envstr+'$',envvalue); + // Look if there is another env.var in the string + i:=pos('$',s); + end + else + // if the env.var is not set, do not replace the env.variable + // and stop looking for more env.var within the string + i := 0; + FreeEnvPChar(envvalue); + end; + end; end;