Index: /main/trunk/greenstone3/gs3-setup.bat
===================================================================
--- /main/trunk/greenstone3/gs3-setup.bat	(revision 22068)
+++ /main/trunk/greenstone3/gs3-setup.bat	(revision 22069)
@@ -1,3 +1,5 @@
 @echo off
+
+setlocal enabledelayedexpansion
 
 set java_min_version=1.5.0_00
@@ -11,21 +13,21 @@
 
 :: this is the default
-:: greenstone3 (%GSDL3SRCHOME%)
-:: +-- web (%GSDL3HOME%)
+:: greenstone3 (!GSDL3SRCHOME!)
+:: +-- web (!GSDL3HOME!)
 :: +-- packages
-::      +-- tomcat (%TOMCAT_HOME%)
-::      +-- ant (%ANT_HOME%)
+::      +-- tomcat (!TOMCAT_HOME!)
+::      +-- ant (!ANT_HOME!)
 
 :: set GSDLSRCHOME to the current directory
-cd | winutil\setvar.exe GSDL3SRCHOME > %TMP%\setgsdl3.bat
-call %TMP%\setgsdl3.bat
-del %TMP%\setgsdl3.bat
+cd | winutil\setvar.exe GSDL3SRCHOME > !TMP!\setgsdl3.bat
+call !TMP!\setgsdl3.bat
+del !TMP!\setgsdl3.bat
 
 :: set GSDLHOME to the 'web' subdirectory
-set GSDL3HOME=%GSDL3SRCHOME%\web
+set GSDL3HOME=!GSDL3SRCHOME!\web
 
 :: change if using external tomcat or ant
-set TOMCAT_HOME=%GSDL3SRCHOME%\packages\tomcat
-if exist "%GSDL3SRCHOME%\packages\ant\*.*" set ANT_HOME=%GSDL3SRCHOME%\packages\ant
+set TOMCAT_HOME=!GSDL3SRCHOME!\packages\tomcat
+if exist "!GSDL3SRCHOME!\packages\ant\*.*" set ANT_HOME=!GSDL3SRCHOME!\packages\ant
 
 :: other important environment variables
@@ -33,20 +35,20 @@
 
 :: ---- Set the CLASSPATH and PATH environment variables ----
-if "%GS_CP_SET%" == "yes" goto skipSetCp
-set CLASSPATH=%GSDL3HOME%\WEB-INF\classes;%GSDL3SRCHOME%\resources\java;%GSDL3SRCHOME%\cp.jar;%CLASSPATH%;
-set PATH=%PATH%;%GSDL3SRCHOME%\bin;%GSDL3SRCHOME%\bin\script;%GSDL3SRCHOME%\lib\jni;%ANT_HOME%\bin
+if "!GS_CP_SET!" == "yes" goto skipSetCp
+set CLASSPATH=!GSDL3HOME!\WEB-INF\classes;!GSDL3SRCHOME!\resources\java;!GSDL3SRCHOME!\cp.jar;!CLASSPATH!;
+set PATH=!PATH!;!GSDL3SRCHOME!\bin;!GSDL3SRCHOME!\bin\script;!GSDL3SRCHOME!\lib\jni;!ANT_HOME!\bin
 
 :: Override Imagemagick and Ghostscript paths to the bundled applications shipped with greenstone if they exists otherwise use default environment variables.
-if exist "%GSDL3SRCHOME%\gs2build\bin\windows\ghostscript\bin\gsdll32.dll" set GS_DLL=%GSDL3SRCHOME%\gs2build\bin\windows\ghostscript\bin\gsdll32.dll
-if exist "%GSDL3SRCHOME%\gs2build\bin\windows\ghostscript\lib\*.*" set GS_LIB=%GSDL3SRCHOME%\gs2build\bin\windows\ghostscript\lib
-if exist "%GSDL3SRCHOME%\gs2build\bin\windows\ghostscript\bin\*.*" set PATH=%GSDL3SRCHOME%\gs2build\bin\windows\ghostscript\bin;%PATH%
-if exist "%GSDL3SRCHOME%\gs2build\bin\windows\imagemagick\*.*" set PATH=%GSDL3SRCHOME%\gs2build\bin\windows\imagemagick;%PATH%
+if exist "!GSDL3SRCHOME!\gs2build\bin\windows\ghostscript\bin\gsdll32.dll" set GS_DLL=!GSDL3SRCHOME!\gs2build\bin\windows\ghostscript\bin\gsdll32.dll
+if exist "!GSDL3SRCHOME!\gs2build\bin\windows\ghostscript\lib\*.*" set GS_LIB=!GSDL3SRCHOME!\gs2build\bin\windows\ghostscript\lib
+if exist "!GSDL3SRCHOME!\gs2build\bin\windows\ghostscript\bin\*.*" set PATH=!GSDL3SRCHOME!\gs2build\bin\windows\ghostscript\bin;!PATH!
+if exist "!GSDL3SRCHOME!\gs2build\bin\windows\imagemagick\*.*" set PATH=!GSDL3SRCHOME!\gs2build\bin\windows\imagemagick;!PATH!
 
 :: a little dynamic set cp stuff
-if exist %TMP%\setcp.bat del %TMP%\setcp.bat
-for %%j in ("%TOMCAT_HOME%"\common\endorsed\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> %TMP%\setcp.bat
-for %%j in ("%TOMCAT_HOME%"\lib\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> %TMP%\setcp.bat
-if exist %TMP%\setcp.bat call %TMP%\setcp.bat
-if exist %TMP%\setcp.bat del %TMP%\setcp.bat
+if exist !TMP!\setcp.bat del !TMP!\setcp.bat
+for %%j in (!TOMCAT_HOME!\common\endorsed\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> !TMP!\setcp.bat
+for %%j in (!TOMCAT_HOME!\lib\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> !TMP!\setcp.bat
+if exist !TMP!\setcp.bat call !TMP!\setcp.bat
+if exist !TMP!\setcp.bat del !TMP!\setcp.bat
 
 set GS_CP_SET=yes
@@ -83,14 +85,12 @@
 :: ---- Search for java ----
 set JAVA_MIN_VERSION=1.5.0_00
-set HINT=%CD%\packages\jre
+set HINT=!CD!\packages\jre
 ::if search4j is present, use it
 set FOUNDJAVAHOME=
 set RUNJAVA=
 if exist bin\search4j.exe (
-  for /F "tokens=*" %%r in ('bin\search4j.exe -d -p "%HINT%" -m %JAVA_MIN_VERSION%') do set FOUNDJAVAHOME=%%r
-  for /F "tokens=*" %%r in ('bin\search4j.exe -r -p "%HINT%" -m %JAVA_MIN_VERSION%') do set FOUNDJREHOME=%%r
+  for /F "tokens=*" %%r in ('bin\search4j.exe -d -p "!HINT!" -m !JAVA_MIN_VERSION!') do set FOUNDJAVAHOME=%%r
+  for /F "tokens=*" %%r in ('bin\search4j.exe -r -p "!HINT!" -m !JAVA_MIN_VERSION!') do set FOUNDJREHOME=%%r
 )
-
-setlocal enabledelayedexpansion
 
 if DEFINED FOUNDJAVAHOME  (
@@ -108,15 +108,15 @@
 )
 
-if exist "%HINT%\bin\java.exe" (
-  set JAVA_HOME=%HINT%
-  set PATH=%JAVA_HOME%\bin;%PATH%
-  set RUNJAVA=%JAVA_HOME%\bin\java.exe
+if exist "!HINT!\bin\java.exe" (
+  set JAVA_HOME=!HINT!
+  set PATH=!JAVA_HOME!\bin;!PATH!
+  set RUNJAVA=!JAVA_HOME!\bin\java.exe
   goto summaryThenEnd
 )
 
-if exist "%JAVA_HOME%\bin\java.exe" (
-  set PATH=%JAVA_HOME%\bin;%PATH%
-  set RUNJAVA=%JAVA_HOME%\bin\java.exe
-  echo Using java at %JAVA_HOME%
+if exist "!JAVA_HOME!\bin\java.exe" (
+  set PATH=!JAVA_HOME!\bin;!PATH!
+  set RUNJAVA=!JAVA_HOME!\bin\java.exe
+  echo Using java at !JAVA_HOME!
   echo WARNING: Greenstone has not checked the version number of this java installation
   echo          The source distribution of Greenstone3 requires java 1.5 or greater
@@ -125,8 +125,8 @@
 )
 
-if exist "%JRE_HOME%\bin\java.exe" (
-  set PATH=%JRE_HOME%\bin;%PATH%
-  set RUNJAVA=%JRE_HOME%\bin\java.exe
-  echo Using java at %JRE_HOME%
+if exist "!JRE_HOME!\bin\java.exe" (
+  set PATH=!JRE_HOME!\bin;!PATH!
+  set RUNJAVA=!JRE_HOME!\bin\java.exe
+  echo Using java at !JRE_HOME!
   echo WARNING: Greenstone has not checked the version number of this java installation
   echo          The source distribution of Greenstone3 requires java 1.5 or greater
@@ -141,7 +141,7 @@
 :summaryThenEnd
 
-echo GSDL3SRCHOME : %GSDL3SRCHOME%
-echo GSDL3HOME    : %GSDL3HOME%
-echo JAVA         : %RUNJAVA%
+echo GSDL3SRCHOME : !GSDL3SRCHOME!
+echo GSDL3HOME    : !GSDL3HOME!
+echo JAVA         : !RUNJAVA!
 if "!ANT_HOME!" == "" (
    echo.
@@ -155,5 +155,8 @@
 echo.
 
-endlocal
+:: End localisation of variables that started with the set local/set enabledelayedexpansion command
+:: Restore global variables that would otherwise be lost at script's end due to their having been initialised in a 
+:: set local/set enabledelayedexpansion section. See http://ss64.com/nt/endlocal.html
+endlocal & set RUNJAVA=%RUNJAVA%
 
 set PATH=%PATH%
@@ -163,4 +166,5 @@
 set JRE_HOME=%JRE_HOME%
 set ANT_HOME=%ANT_HOME%
+set RUNJAVA=%RUNJAVA%
 
 :end
