summaryrefslogtreecommitdiff
path: root/win32/ifchange.bat
diff options
context:
space:
mode:
Diffstat (limited to 'win32/ifchange.bat')
-rwxr-xr-xwin32/ifchange.bat117
1 files changed, 78 insertions, 39 deletions
diff --git a/win32/ifchange.bat b/win32/ifchange.bat
index 1de98f9990..f3fc9ea37c 100755
--- a/win32/ifchange.bat
+++ b/win32/ifchange.bat
@@ -1,54 +1,80 @@
@echo off
:: usage: ifchange target temporary
+@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1
+
+:: @set PROMPT=$T:$S
for %%I in (%0) do set progname=%%~nI
set timestamp=
set keepsuffix=
set empty=
set color=auto
:optloop
+set optarg=
+:optnext
for %%I in (%1) do set opt=%%~I
-if "%opt%" == "--" (
- shift
-) else if "%opt%" == "--timestamp" (
- set timestamp=.
- shift
- goto :optloop
-) else if "%opt:~0,12%" == "--timestamp=" (
- set timestamp=%opt:~12%
- shift
- goto :optloop
-) else if "%opt%" == "--keep" (
- set keepsuffix=.old
- shift
- goto :optloop
-) else if "%opt:~0,7%" == "--keep=" (
- set keepsuffix=%opt:~7%
- shift
- goto :optloop
-) else if "%opt%" == "--empty" (
- set empty=yes
- shift
- goto :optloop
-) else if "%opt%" == "--color" (
- set color=always
- shift
- goto :optloop
-) else if "%opt:~0,8%" == "--color=" (
- set color=%opt:~8%
- shift
- goto :optloop
-) else if "%opt%" == "--debug" (
- shift
- echo on
- goto :optloop
-) else if "%opt%" == "--help" (
- call :help
- exit /b
-) else if "%opt:~0,2%" == "--" (
+ if not "%opt:~0,2%" == "--" (
+ if not "%optarg%" == "" (
+ call set %optarg%=%%opt%%
+ shift
+ goto :optloop
+ )
+ goto :optend
+ )
+ if "%opt%" == "--" (
+ shift
+ goto :optend
+ )
+ if "%opt%" == "--timestamp" (
+ set timestamp=.
+ set optarg=timestamp
+ shift
+ goto :optnext
+ )
+ if "%opt:~0,12%" == "--timestamp=" (
+ set timestamp=%opt:~12%
+ shift
+ goto :optloop
+ )
+ if "%opt%" == "--keep" (
+ set keepsuffix=.old
+ set optarg=keep
+ shift
+ goto :optnext
+ )
+ if "%opt:~0,7%" == "--keep=" (
+ set keepsuffix=%opt:~7%
+ shift
+ goto :optloop
+ )
+ if "%opt%" == "--empty" (
+ set empty=yes
+ shift
+ goto :optloop
+ )
+ if "%opt%" == "--color" (
+ set color=always
+ set optarg=color
+ shift
+ goto :optnext
+ )
+ if "%opt:~0,8%" == "--color=" (
+ set color=%opt:~8%
+ shift
+ goto :optloop
+ )
+ if "%opt%" == "--debug" (
+ shift
+ echo on
+ goto :optloop
+ )
+ if "%opt%" == "--help" (
+ call :help
+ exit /b
+ )
echo %progname%: unknown option: %1 1>&2
exit /b 1
-)
+:optend
if "%2" == "" (
call :help 1>&2
@@ -60,6 +86,19 @@ set src=%2
set dest=%dest:/=\%
set src=%src:/=\%
+if not "%src%" == "-" goto :srcfile
+ if not "%TMPDIR%" == "" (
+ set src=%TMPDIR%\ifchange%RANDOM%.tmp
+ ) else if not "%TEMP%" == "" (
+ set src=%TEMP%\ifchange%RANDOM%.tmp
+ ) else if not "%TMP%" == "" (
+ set src=%TMP%\ifchange%RANDOM%.tmp
+ ) else (
+ set src=.\ifchange%RANDOM%.tmp
+ )
+ findstr -r -c:"^" > "%src%"
+:srcfile
+
if exist %dest% (
if not exist %src% goto :nt_unchanged1
if not "%empty%" == "" for %%I in (%src%) do if %%~zI == 0 goto :nt_unchanged