Skip to content

Commit

Permalink
更新Script脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerWordTree committed Dec 30, 2023
1 parent 510b677 commit 0d9ac76
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 28 deletions.
32 changes: 18 additions & 14 deletions Script/Config.FileRead.CMD
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
::@author FB
::@version 0.1.1
::@version 0.2.0

::数据结构为Object
::仅支持一级段
::由%包裹的变量不会被展开
::数据结构为Map
::仅支持一级段, 由%包裹的变量不会被展开

::如果KEY是#开头,什么也不做
::如果KEY是#或;开头,什么也不做
::如果VALUE不为空,保存到变量
::如果KEY被[]包裹,切换当前段

::读取配置文件
:: 参数1: 实例名称
:: 参数2: 配置文件

::Script:Map.New.CMD::
::Script:Map.NewChild.CMD::
::Script:Map.Put.CMD::
::Script:String.Trim.CMD::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

SET "@VAR=%~1" & SET "@SECTION=."
FOR /F "eol=# tokens=1,* usebackq delims==" %%A IN (
`TYPE "%~2" 2^>NUL`
) DO (
SET "@KEY=%%~A"
SET "@VALUE=%%~B"
SET "@VAR=%~1" & SET "@SECTION="
CALL Map.New.CMD "%~1"
FOR /F "tokens=1,* usebackq delims==" %%A IN (`TYPE "%~2" 2^>NUL`) DO (
SET "@KEY=%%~A" & SET "@VALUE=%%~B"
CALL String.Trim.CMD "%%@KEY%%" & CALL SET "@KEY=%%@%%"
CALL String.Trim.CMD "%%@VALUE%%" & CALL SET "@VALUE=%%@%%"
CALL :_PARSE_LINE
Expand All @@ -31,9 +31,13 @@ SET "@VALUE=" & SET "@KEY=" & SET "@SECTION=" & SET "@VAR="
EXIT /B

:_PARSE_LINE
IF NOT "%@KEY:~,1%" == "#" IF NOT "%@VALUE%" == "" (
SET "%@VAR%%@SECTION%%@KEY%=%@VALUE%"
IF "%@KEY%" == "" GOTO :EOF
IF "%@KEY:~,1%" == "#" GOTO :EOF
IF "%@KEY:~,1%" == ";" GOTO :EOF
IF NOT "%@VALUE%" == "" (
CALL Map.Put.CMD "%%@VAR%%%%@SECTION%%" "%%@KEY%%" "%%@VALUE%%"
) ELSE IF "%@KEY:~,1%" == "[" IF "%@KEY:~-1%" == "]" (
SET "@SECTION=.%@KEY:~1,-1%."
SET "@SECTION=.%@KEY:~1,-1%"
CALL Map.NewChild.CMD "%%@VAR%%" "%%@KEY:~1,-1%%"
)
GOTO :EOF
16 changes: 16 additions & 0 deletions Script/Map.Destroy.CMD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
::@author FB
::@version 0.2.0

::Ïú»Ù
:: ²ÎÊý1: ʵÀýÃû³Æ

::Script:Map.Destroy.CMD::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

CALL SET "@=%%%~1.@LIST%%"
FOR %%A IN (%@%) DO SET "%~1.%%~A="
CALL SET "@=%%%~1.@CHILD%%"
FOR %%A IN (%@%) DO CALL Map.Destroy.CMD "%~1.%%~A"
SET "%~1.@LIST=" & SET "%~1.@CHILD="
EXIT /B
23 changes: 23 additions & 0 deletions Script/Map.New.CMD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
::@author FB
::@version 0.2.0

::数据组织: A.XX=* A.YY=* A.ZZ=*
::元素列表: A.@LIST A.B.@LIST A.C.@LIST
::子项列表: A.@CHILD A.B.@CHILD A.C.@CHILD
::数据创建: CALL Map_New.CMD A;
::数据添加: CALL Map_Push.CMD A XX "*";
::数据访问: CALL Map_Get.CMD A XX; CALL :ARRAY_REMOVE A YY;
::数据遍历: CALL Map_List.CMD A "ECHO {0} {1}";
::数据销毁: CALL Map_Destroy.CMD A;

::创建
:: 参数1: 实例名称

::Script:Map.Destroy.CMD::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

CALL Map.Destroy.CMD "%~1"
SET "%~1.@LIST=;"
SET "%~1.@CHILD=;"
EXIT /B
16 changes: 16 additions & 0 deletions Script/Map.NewChild.CMD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
::@author FB
::@version 0.2.0

::创建子项
:: 参数1: 实例名称
:: 参数2: 子项名称

::Script:Map.New.CMD::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

CALL ECHO.%%%~1.@CHILD%% | FIND /I ";%~2;" 1>NUL 2>&1 || (
CALL SET "%~1.@CHILD=%%%~1.@CHILD%%%~2;"
CALL Map.New.CMD "%~1.%~2"
)
EXIT /B
14 changes: 14 additions & 0 deletions Script/Map.Put.CMD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
::@author FB
::@version 0.2.0

::加入
:: 参数1: 实例名称
:: 参数2: 键
:: 参数3: 值

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

SET "%~1.%~2=%~3"
CALL ECHO.%%%~1.@LIST%% | FIND /I ";%~2;" 1>NUL 2>&1 ^
|| CALL SET "%~1.@LIST=%%%~1.@LIST%%%~2;"
EXIT /B
19 changes: 6 additions & 13 deletions Script/String.Trim.CMD
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
::@author FB
::@version 0.2.0
::@version 0.2.1

::使用(SET "@=%*")也可以达到同样目的
::但存在无法使用双引号包裹参数问题, 遇到特殊符号会产生歧义

::已知问题: 无法处理TAB符号

::去首尾空格
:: 参数1: 目标字符串
:: 返回@: 处理后的字符串

::Script:String.TrimStart.CMD::
::Script:String.TrimEnd.CMD::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

SET "@=%~1"
:_TRIM_START
IF NOT "%@%" == "" IF "%@:~,1%" == " " (
SET "@=%@:~1%"
GOTO :_TRIM_START
)
:_TRIM_END
IF NOT "%@%" == "" IF "%@:~-1%" == " " (
SET "@=%@:~,-1%"
GOTO :_TRIM_END
)
CALL String.TrimStart.CMD "%%@%%"
CALL String.TrimEnd.CMD "%%@%%"
EXIT /B
21 changes: 21 additions & 0 deletions Script/String.TrimEnd.CMD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
::@author FB
::@version 0.2.1

::环境变量扩展在变量未定义时, 会造成未知结果

::已知问题: 无法处理TAB符号

::去尾空格
:: 参数1: 目标字符串
:: 返回@: 处理后的字符串

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

SET "@=%~1"
:_TRIM_END
IF "%@%" == "" EXIT /B
IF "%@:~-1%" == " " (
SET "@=%@:~,-1%"
GOTO :_TRIM_END
)
EXIT /B
21 changes: 21 additions & 0 deletions Script/String.TrimStart.CMD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
::@author FB
::@version 0.2.1

::环境变量扩展在变量未定义时, 会造成未知结果

::已知问题: 无法处理TAB符号

::去首空格
:: 参数1: 目标字符串
:: 返回@: 处理后的字符串

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

SET "@=%~1"
:_TRIM_START
IF "%@%" == "" EXIT /B
IF "%@:~,1%" == " " (
SET "@=%@:~1%"
GOTO :_TRIM_START
)
EXIT /B
1 change: 1 addition & 0 deletions ScriptDependents.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
::@version 1.1.0

::Bin:Dumpbin.exe::
::Bin:Link.exe::
::Script:Object.Destroy.CMD::
::Script:Config.FileRead.CMD::

Expand Down
6 changes: 5 additions & 1 deletion ScriptDependents.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
CLEAN=TRUE

[BIN]
SRC=%CYGWIN_HOME%\Bin
SRC=%CYGWIN_HOME%\Bin;%MSYS_HOME%\usr\bin
DST=Target\Bin

[SCRIPT]
SRC=%CD%\..\Script
DST=Target\Script

[OTHER]
SRC=%CD%\..\
DST=Target\Other

0 comments on commit 0d9ac76

Please sign in to comment.