Windows-Server-2003/tools/postbuildscripts/splitlist.cmd

250 lines
7.1 KiB
Batchfile

@echo off
if defined _echo echo on
if defined verbose echo on
setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
REM Splits lists into a number of lists equal to number or processors
REM Argumnent is input list. Output list is %tmp%\%lang%\filename.
REM -------------------------------------------------------------------------------------------
REM Template for the postbuild scripts:
REM SD Location: %sdxroot%\tools\postbuildscripts
REM
REM (1) Code section description:
REM PreMain - Developer adaptable code. Use this model and add your script params
REM Main - Developer code section. This is where your work gets done.
REM PostMain - Logging support code. No changes should be made here.
REM
REM (2) GetParams.pm - Usage
REM run perl.exe GetParams.pm /? for complete usage
REM
REM (3) Reserved Variables -
REM lang - The specified language. Defaults to USA.
REM logfile - The path and filename of the logs file.
REM logfile_bak - The path and filename of the logfile.
REM errfile - The path and filename of the error file.
REM tmpfile - The path and filename of the temp file.
REM errors - The scripts errorlevel.
REM script_name - The script name.
REM script_args - The arguments passed to the script.
REM CMD_LINE - The script name plus arguments passed to the script.
REM _NTPostBld - Abstracts the language from the files path that
REM postbuild operates on.
REM _NTPostBld_Bak - Reserved support var.
REM _temp_bak - Reserved support var.
REM _logs_bak - Reserved support var.
REM
REM (4) Reserved Subs -
REM Usage - Use this sub to discribe the scripts usage.
REM ValidateParams - Use this sub to verify the parameters passed to the script.
REM
REM
REM (8) Do not turn echo off, copy the 3 lines from the beginning of the template
REM instead.
REM
REM (9) Use setlocal/endlocal as in this template.
REM
REM (10)Have your changes reviewed by a member of the US build team (ntbusa) and
REM by a member of the international build team (ntbintl).
REM
REM -------------------------------------------------------------------------------------------
REM PreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMain
REM Begin PreProcessing Section - Adapt this section but do not remove support
REM scripts or reorder section.
REM PreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMainPreMain
:PreMain
REM
REM Define SCRIPT_NAME. Used by the logging scripts.
REM Define CMD_LINE. Used by the logging scripts.
REM Define SCRIPT_ARGS. Used by the logging scripts.
REM
set SCRIPT_NAME=%~nx0
set CMD_LINE=%script_name% %*
set SCRIPT_ARGS=%*
REM
REM Parse the command line arguments - Add your scripts command line arguments
REM as indicated by brackets.
REM For complete usage run: perl.exe GetParams.pm /?
REM
for %%h in (./ .- .) do if ".%SCRIPT_ARGS%." == "%%h?." goto Usage
REM call :GetParams -n <add required prams> -o l:<add optional params> -p "lang <add variable names>" %SCRIPT_ARGS%
call :GetParams -n s: -o l: -p "srcfile lang" %SCRIPT_ARGS%
if errorlevel 1 goto :End
REM
REM Set up the local enviroment extensions.
REM
call :LocalEnvEx -i
if errorlevel 1 goto :End
REM
REM Validate the command line parameters.
REM
call :ValidateParams
if errorlevel 1 goto :End
REM
REM Execute Main
REM
call :Main
:End_PreMain
goto PostMain
REM /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
REM Begin Main code section
REM /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
REM (5) Call other executables or command scripts by using:
REM call ExecuteCmd.cmd "<command>"
REM Check for errors by using:
REM if errorlevel 1 ...
REM Note that the executable/script you're calling with ExecuteCmd must return a
REM non-zero value on errors to make the error checking mechanism work.
REM
REM Example
REM call ExecuteCmd.cmd "xcopy /f foo1 foo2"
REM if errorlevel 1 (
REM set errors=%errorlevel%
REM goto end
REM )
REM
REM (6) Log non-error information by using:
REM call logmsg.cmd "<log message>"
REM and log error information by using:
REM call errmsg.cmd "<error message>"
REM
REM (7) Exit from the option routines with
REM set errors=%errorlevel%
REM goto end
REM if errors found during execution and with
REM goto end
REM otherwise.
:Main
REM Main code section
REM <Start your script's code here>
REM If uniproc, skip altogether.
if "%NUMBER_OF_PROCESSORS%" == "1" goto End
set /a Count=0
set FilePath=%srcfile%
for %%j in (%FilePath%) do set FileName=%%~nj
for /l %%j in (1,1,%NUMBER_OF_PROCESSORS%) do (
if exist %tmp%\%FileName%.%%j del /f %tmp%\%FileName%.%%j
)
for /f "tokens=1,2" %%j in (%FilePath%) do (
if !Count! == %NUMBER_OF_PROCESSORS% set Count=0
set /a Count=!Count! + 1
echo %%j %%k>>%tmp%\%FileName%.!Count!
)
goto end
:ValidateParams
REM
REM Validate the option given as parameter.
REM
goto end
:Usage
REM Usage of the script
REM If errors, goto errend
echo Splits lists into a number of lists equal to number or processors
echo Argumnent is input list. Output list is %tmp%\filename.#
echo Usage: %script_name% -s srcfile [-l lang][-?]
echo -s source path and filename
echo -l lang 2-3 letter language identifier
echo -? Displays usage
set ERRORS=1
goto end
REM /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
REM End Main code section
REM /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
:End_Main
goto PostMain
REM SupportSubsSupportSubsSupportSubsSupportSubsSupportSubsSupportSubsSupportSubs
REM Support Subs - Do not touch this section!
REM SupportSubsSupportSubsSupportSubsSupportSubsSupportSubsSupportSubsSupportSubs
:GetParams
REM
REM Parse the command line arguments
REM
set ERRORS=0
for %%h in (./ .- .) do if ".%SCRIPT_ARGS%." == "%%h?." goto Usage
pushd %RazzleToolPath%\PostBuildScripts
set ERRORS=0
for /f "tokens=1 delims=;" %%c in ('perl.exe GetParams.pm %*') do (
set commandline=%%c
set commandtest=!commandline:~0,3!
if /i "!commandtest!" neq "set" (
if /i "!commandtest!" neq "ech" (
echo %%c
) else (
%%c
)
) else (
%%c
)
)
if "%errorlevel%" neq "0" (
set ERRORS=%errorlevel%
goto end
)
popd
goto end
:LocalEnvEx
REM
REM Manage local script environment extensions
REM
pushd %RazzleToolPath%\PostBuildScripts
for /f "tokens=1 delims=;" %%c in ('perl.exe LocalEnvEx.pm %1') do (
set commandline=%%c
set commandtest=!commandline:~0,3!
if /i "!commandtest!" neq "set" (
if /i "!commandtest!" neq "ech" (
echo %%c
) else (
%%c
)
) else (
%%c
)
)
if "%errorlevel%" neq "0" (
set errors=%errorlevel%
goto end
)
popd
goto end
:end
seterror.exe "%errors%"& goto :EOF
REM PostMainPostMainPostMainPostMainPostMainPostMainPostMainPostMainPostMain
REM Begin PostProcessing - Do not touch this section!
REM PostMainPostMainPostMainPostMainPostMainPostMainPostMainPostMainPostMain
:PostMain
REM
REM End the local environment extensions.
REM
call :LocalEnvEx -e
REM
REM Check for errors
REM
endlocal& seterror.exe "%errors%"