2005-03-03 12:38:40 +03:00
|
|
|
@echo off
|
|
|
|
:: usage: ifchange target temporary
|
|
|
|
|
2021-01-04 08:31:18 +03:00
|
|
|
for %%I in (%0) do set progname=%%~nI
|
2008-10-17 14:46:23 +04:00
|
|
|
set timestamp=
|
2013-10-16 18:39:53 +04:00
|
|
|
set keepsuffix=
|
2013-11-03 16:40:24 +04:00
|
|
|
set empty=
|
2018-02-08 05:08:26 +03:00
|
|
|
set color=auto
|
2009-03-16 06:30:01 +03:00
|
|
|
:optloop
|
|
|
|
for %%I in (%1) do set opt=%%~I
|
2021-01-04 08:31:18 +03:00
|
|
|
if "%opt%" == "--" (
|
|
|
|
shift
|
|
|
|
) else if "%opt%" == "--timestamp" (
|
2009-03-16 06:30:01 +03:00
|
|
|
set timestamp=.
|
|
|
|
shift
|
|
|
|
goto :optloop
|
|
|
|
) else if "%opt:~0,12%" == "--timestamp=" (
|
|
|
|
set timestamp=%opt:~12%
|
2008-10-17 14:46:23 +04:00
|
|
|
shift
|
2009-03-16 06:30:01 +03:00
|
|
|
goto :optloop
|
2013-10-16 18:39:53 +04:00
|
|
|
) else if "%opt%" == "--keep" (
|
|
|
|
set keepsuffix=.old
|
|
|
|
shift
|
|
|
|
goto :optloop
|
|
|
|
) else if "%opt:~0,7%" == "--keep=" (
|
|
|
|
set keepsuffix=%opt:~7%
|
|
|
|
shift
|
|
|
|
goto :optloop
|
2013-11-03 16:40:24 +04:00
|
|
|
) else if "%opt%" == "--empty" (
|
|
|
|
set empty=yes
|
|
|
|
shift
|
|
|
|
goto :optloop
|
2018-02-08 05:08:26 +03:00
|
|
|
) else if "%opt%" == "--color" (
|
|
|
|
set color=always
|
|
|
|
shift
|
|
|
|
goto :optloop
|
|
|
|
) else if "%opt:~0,8%" == "--color=" (
|
|
|
|
set color=%opt:~8%
|
|
|
|
shift
|
|
|
|
goto :optloop
|
2018-02-08 05:08:27 +03:00
|
|
|
) else if "%opt%" == "--debug" (
|
|
|
|
shift
|
|
|
|
echo on
|
|
|
|
goto :optloop
|
2021-01-04 08:31:18 +03:00
|
|
|
) else if "%opt%" == "--help" (
|
|
|
|
call :help
|
|
|
|
exit /b
|
|
|
|
) else if "%opt:~0,2%" == "--" (
|
|
|
|
echo %progname%: unknown option: %1 1>&2
|
|
|
|
exit /b 1
|
|
|
|
)
|
|
|
|
|
|
|
|
if "%2" == "" (
|
|
|
|
call :help 1>&2
|
|
|
|
exit /b 1
|
2008-10-17 14:46:23 +04:00
|
|
|
)
|
2009-03-16 06:30:01 +03:00
|
|
|
|
2008-01-25 12:27:30 +03:00
|
|
|
set dest=%1
|
|
|
|
set src=%2
|
|
|
|
set dest=%dest:/=\%
|
|
|
|
set src=%src:/=\%
|
|
|
|
|
2016-06-09 09:31:11 +03:00
|
|
|
goto :nt
|
2005-03-03 12:38:40 +03:00
|
|
|
|
|
|
|
:unchange
|
|
|
|
echo %1 unchanged.
|
|
|
|
del %2
|
|
|
|
goto :end
|
|
|
|
|
|
|
|
:update
|
|
|
|
echo %1 updated.
|
2008-01-25 12:27:30 +03:00
|
|
|
:: if exist %1 del %1
|
|
|
|
dir /b %2
|
2013-10-16 18:39:53 +04:00
|
|
|
if "%keepsuffix%" != "" %1 %1%keepsuffix%
|
2008-01-25 12:27:30 +03:00
|
|
|
copy %2 %1
|
|
|
|
del %2
|
|
|
|
goto :end
|
|
|
|
|
|
|
|
:nt
|
|
|
|
if exist %dest% (
|
2013-11-03 16:40:24 +04:00
|
|
|
if not exist %src% goto :nt_unchanged1
|
|
|
|
if "%empty%" == "" for %%I in (%src%) do if %%~zI == 0 goto :nt_unchanged
|
2008-01-25 12:27:30 +03:00
|
|
|
fc.exe %dest% %src% > nul && (
|
2013-11-03 16:40:24 +04:00
|
|
|
:nt_unchanged
|
2008-01-25 12:27:30 +03:00
|
|
|
del %src%
|
2013-11-03 16:40:24 +04:00
|
|
|
:nt_unchanged1
|
|
|
|
for %%I in (%1) do echo %%~I unchanged
|
2008-10-17 14:46:23 +04:00
|
|
|
goto :nt_end
|
2008-01-25 12:27:30 +03:00
|
|
|
)
|
|
|
|
)
|
2013-11-03 16:40:24 +04:00
|
|
|
for %%I in (%1) do echo %%~I updated
|
2022-09-17 15:16:06 +03:00
|
|
|
del /f %dest%
|
2008-01-25 12:27:30 +03:00
|
|
|
copy %src% %dest% > nul
|
|
|
|
del %src%
|
|
|
|
|
2008-10-17 14:46:23 +04:00
|
|
|
:nt_end
|
|
|
|
if "%timestamp%" == "" goto :end
|
2009-03-16 06:30:01 +03:00
|
|
|
if "%timestamp%" == "." (
|
|
|
|
for %%I in ("%dest%") do set timestamp=%%~dpI.time.%%~nxI
|
|
|
|
)
|
|
|
|
goto :end > "%timestamp%"
|
2021-01-04 08:31:18 +03:00
|
|
|
|
|
|
|
:help
|
|
|
|
for %%I in (
|
|
|
|
"usage: %progname% [options] target new-file"
|
|
|
|
"options:"
|
|
|
|
" --timestamp[=file] touch timestamp file. (default: prefixed with '.time')"
|
|
|
|
" under the directory of the target)"
|
|
|
|
" --keep[=suffix] keep old file with suffix. (default: '.old')"
|
|
|
|
" --empty assume unchanged if the new file is empty."
|
|
|
|
" --color[=always|auto|never] colorize output."
|
|
|
|
) do echo.%%~I
|
|
|
|
goto :eof
|
|
|
|
|
2005-03-03 12:38:40 +03:00
|
|
|
:end
|