::# Usage : PrivateProfile.cmd /I:inifile /S:section /K:key [/V:value]::# /I: inifile specifies the name of the initialization file.::# /S: section specifying the name of the section in the initialization file. ::# /K: key specifying the name of the key whose associated string is to be retrieved. ::# ::# /V: value specifying a string to be written to the file. If this parameter is NULL, ::# the key pointed to by the key parameter is deleted. ::# ::# ::# ::# Version History and Revision List:::# Date Version Auther Description::# ----------------------------------------------------------------------::# 2010/12/31 V1.0.0 perry initial version.::# ::############################################################################################::# Reference external variables for this script file:::#::# Name of Variable Access Control Remark::# --------------------------------------------------------::# $cc_folder_compiler R::# $cc_folder_root R+W::# $cc_file_config R::# $cc_tool_subst R::#:script_init @setlocal enabledelayedexpansion @title PrivateProfile @echo off ::Clear all argument variables for /f "tokens=1 delims==" %%i in ('set $arg_ 2^>nul') do set %%i= set $rc=1 set $argKey= set $argPart= set $argRaw=%* set $argVal= set $arg_input=/I: set $arg_section=/S: set $arg_key=/K: set $arg_value=/V::script_begin:: :: The parsing function of the command line for this script.:: switch options: /I /S /K /V:: /I: inifile == specifies the name of the initialization file.:: /S: section == specifying the name of the section in the initialization file. :: /K: key == specifying the name of the key whose associated string is to be retrieved. :: /V: value == specifying a string to be written to the file. If this parameter is NULL, :: the key pointed to by the key parameter is deleted. :: the switch flag can be - or /.:::script_args_begin for /l %%i in (0, 1, 896) do ( set $argVal=!$argRaw:~%%i!::find the end of the string, exit! if "!$argVal!" == "" goto :script_args_finished if "!$argVal:~0,1!" == "/" ( for /f "tokens=1 delims==" %%j in ('set $arg_') do (::find all the defined keywords. The name prefix of these variables must be [$ arg_]. set $argKey=!%%~j! set $argPart=!$argVal:~0,3! if "!$argPart!" == "!$argKey!" (::call the function [TrimParamString] to obtain the correct parameters. call :TrimParamString "%%~j", !$argVal:~3!)))):script_args_finished set $arg_ :script_end exit /b %$rc% goto :eof ::# --function description--::# trim a string leading and trailing spaces or double quotes("").::#::# Input Parameters:::# P1: a string that specifies the name of output variable.::# P2: a string for argument analysis.::#::# Note: each parameters must be included in double quotes("").::#::# Output:::# ERRORLEVEL::# if the function saved is successfully, the errorlevel is ::# zero. Otherwise, the errorlevel is non-zero.::#::# Examples:::# call :TrimParamString "output", "input"::#::# --function begin--:TrimParamString:: set $text=%* set $char= set $hasQuotes=no set $trimLeading=yes set $charStartIndex=0 call set $text=%%$text:%1,=%% ::If the string is not available, so we will not do anything. if not defined $text exit /b 1 :Label1 call set $char=%%$text:~%$charStartIndex%,1%% ::If find a space character, We will ignore it until find a non-space character. set /a $charStartIndex=$charStartIndex + 1 if "%$char%%$char%" == " " ( goto :Label1) ::If find a double quote, We think it is an start symbol of the argument. if "%$char%%$char%" == """" ( set /a $charStartIndex=$charStartIndex + 1 set $hasQuotes=yes)::If find a slash, We think it is an invalid argument. if "%$char%%$char%" == "//" ( if "%$hasQuotes%" == "no" ( exit /b 1)) set /a $charStartIndex=$charStartIndex - 1 ::If the effective length of the argument is 0.::Stop the string analysis. call set $char=%%$text:~%$charStartIndex%,1%% if "%$char%%$char%" == "" ( exit /b 1) ::Truncate the string from the start symbol, and then start ::from first characters to search the end symbol in this string call set $text=%%$text:~%$charStartIndex%%% set $charStartIndex=0 :Label2 call set $char=%%$text:~%$charStartIndex%,1%% set /a $charStartIndex=$charStartIndex + 1::Here is to avoid unterminated string causes an endless loop.::exit loop if detected a invalid character in the string. if "%$char%%$char%" == "" ( goto :Label3)::If find a space character, and the leading of the string is not a double quote.::We think this is the end of a parameter. if "%$char%%$char%" == " " ( if "%$hasQuotes%" == "no" ( goto :Label3))::If find a slash, and the leading of the string is not a double quote.::We think that this slash is the leading of the next switch. ::So stop the string analysis. if "%$char%%$char%" == "//" ( if "%$hasQuotes%" == "no" ( goto :Label3))::If find a double quote, and the leading of the string aslo is a double quote.::Now we can think this is a qualified string. if "%$char%%$char%" == """" ( if "%$hasQuotes%" == "yes" ( goto :Label3)) goto :Label2:Label3 if %$charStartIndex% EQU 1 exit /b 1 set /a $charStartIndex=$charStartIndex - 1 call set %~1=%%$text:~0,%$charStartIndex%%%::# function is exit normal, the returned code is zero. exit /b 0 ::# --function end--