现在做了一个解释器,逐行获取文本里的内容并执行,使用call命令来调用它并传递两个参数,第一个参数是文件的路径(不包含文件本身名称),第二个参数是目标文件的名称,它还会读取文件路径下的config.ldt和doskey.ldt,其中config.ldt内容最后多了一个分号,后面跟着一个选项是用来决定是否显示加载中的文字和加载时间的,如果它为true,那么加载中提示和加载时间显示将会被关闭。现在它不能正常运行,会闪退,麻烦大家再帮我看看,代码如下:- @echo off
- SetLocal EnableDelayedExpansion
- for /f "delims=; tokens=5" %%q in (%1\config.ldt) do if %%q equ true goto noecho
- rem time
- set "t=%time%"
- rem code
- rem time
- set "tx=%time%"
- rem code
- for /f "delims=; tokens=1" %%o in (%1\config.ldt) do set conls=%%o
- for /f "delims=' tokens=1" %%z in ("%conls%") do set modc=%%z
- for /f "delims=' tokens=2" %%e in ("%conls%") do set modl=%%e
- for /f "delims=; tokens=2" %%i in (%1\config.ldt) do set dbg=%%i
- for /f "delims=; tokens=3" %%t in (%1\config.ldt) do set dk=%%t
- for /f "delims=; tokens=4" %%b in (%1\config.ldt) do set color=%%b
- if %dbg% equ true (set dbgx=a) else (if %dbg% equ false (set dbgx=b) else (goto configerr))
- if %dk% equ true (set dkif=a) else (if %dk% equ false (set dkif=b) else (goto configerr))
- for %%i in (01,02,03,04,05,06,07,08,09,0a,0b,0c,0d,0e,0f,10,12,16,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f,20,21,23,24,25,26,27,28,29,2a,2b,2c,2d,2e,2f,30,31,32,34,35,36,37,38,39,3a,3b,3c,3d,3e,3f,40,41,42,43,45,46,47,48,49,4a,4b,4c,4d,4e,4f50,51,52,53,54,56,57,58,59,5a,5b,5c,5d,5e,5f,60,61,62,63,64,65,67,68,69,6a,6b,6c,6d,6e,6f,70,71,72,73,74,75,76,77,78,79,7a,7b,7c,7d,7e,7f,80,81,82,83,84,85,86,87,89,8a,8b,8c,8d,8e,8f,90,91,92,93,94,95,96,97,98,9a,9b,9c,9d,9e,9f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,ab,ac,ab,ac,ad,ae,af,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,ba,bc,bd,be,bf,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,ca,cb,cd,ce,cf,d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,da,db,dc,de,df,e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,ea,eb,ec,ed,ef,f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe) do if %color% equ %%i goto colok
- goto configerr
- :colok
- rem time
- set "t1x=%time%"
- if "%t1x:~,2%" lss "%tx:~,2%" set "add=+24"
- set /a "timesx=(%t1x:~,2%-%tx:~,2%%add%)*360000+(1%t1x:~3,2%%%100-1%tx:~3,2%%%100)*6000+(1%t1x:~6,2%%%100-1%tx:~6,2%%%100)*100+(1%t1x:~-2%%%100-1%tx:~-2%%%100)" ,"ssx=(timesx/100)%%60","mmx=(timesx/6000)%%60","hhx=timesx/360000","msx=timesx%%100"
- rem endtime
- if %dkif% equ b goto nodk
- rem time
- set "tn=%time%"
- rem code
- for /f "delims=" %%a in (%cd%\doskey.ldt) do doskey %%a
- rem time
- set "t1n=%time%"
- if "%t1n:~,2%" lss "%tn:~,2%" set "add=+24"
- set /a "timesn=(%t1n:~,2%-%tn:~,2%%add%)*360000+(1%t1n:~3,2%%%100-1%tn:~3,2%%%100)*6000+(1%t1n:~6,2%%%100-1%tn:~6,2%%%100)*100+(1%t1n:~-2%%%100-1%tn:~-2%%%100)" ,"ssn=(timesn/100)%%60","mmn=(timesn/6000)%%60","hhn=timesn/360000","msn=timesn%%100"
- :nodk
- rem time
- set "t1=%time%"
- if "%t1:~,2%" lss "%t:~,2%" set "add=+24"
- set /a "times=(%t1:~,2%-%t:~,2%%add%)*360000+(1%t1:~3,2%%%100-1%t:~3,2%%%100)*6000+(1%t1:~6,2%%%100-1%t:~6,2%%%100)*100+(1%t1:~-2%%%100-1%t:~-2%%%100)" ,"ss=(times/100)%%60","mm=(times/6000)%%60","hh=times/360000","ms=times%%100"
- color %color%
- mode con cols=%modc% lines=%modl%
- if %dbgx% equ a goto dbg
- echo 加载文件:
- echo 加载配置文件...
- echo 完成 用时%hhx%:%mmx%:%ssx%.%msx%(时:分:秒.毫秒)
- echo 加载宏命令...
- echo 完成 用时%hhn%:%mmn%:%ssn%.%msn%(时:分:秒.毫秒)
- echo 加载完成 总用时%hh%:%mm%:%ss%.%ms%(时:分:秒.毫秒)
- echo.
- echo BetterCommand Interpreter development version 0.1a
- echo.
- for /f "delims=" %%r in (%1\%2) do (set /p !com!=<%1\%2
- if "!com!" equ help %cd%\help.txt
- if "!com!" equ exit exit
- if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
- if "!shutyn!" equ y shutdown /s /t 0 /f)
- !com!)
- exit
- :configerr
- echo 配置文件可能存在问题,加载失败,请检查config.ldt。
- pause
- exit
- :dbg
- @echo on
- for /f "delims=" %%w in (%1\%2) do (set /p com=<%1\%2
- if "!com!" equ help %cd%\help.txt
- if "!com!" equ exit exit
- if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
- if "!shutyn!" equ y shutdown /s /t 0 /f)
- !com!)
- exit
- exit
- pause
- :noecho
- for /f "delims=; tokens=1" %%o in (%1\config.ldt) do set conls=%%o
- for /f "delims=' tokens=1" %%z in ("%conls%") do set modc=%%z
- for /f "delims=' tokens=2" %%e in ("%conls%") do set modl=%%e
- for /f "delims=; tokens=2" %%i in (%1\config.ldt) do set dbg=%%i
- for /f "delims=; tokens=3" %%t in (%1\config.ldt) do set dk=%%t
- for /f "delims=; tokens=4" %%b in (%1\config.ldt) do set color=%%b
- if %dbg% equ true (set dbgx=a) else (if %dbg% equ false (set dbgx=b) else (goto configerr))
- if %dk% equ true (set dkif=a) else (if %dk% equ false (set dkif=b) else (goto configerr))
- for %%i in (01,02,03,04,05,06,07,08,09,0a,0b,0c,0d,0e,0f,10,12,16,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f,20,21,23,24,25,26,27,28,29,2a,2b,2c,2d,2e,2f,30,31,32,34,35,36,37,38,39,3a,3b,3c,3d,3e,3f,40,41,42,43,45,46,47,48,49,4a,4b,4c,4d,4e,4f50,51,52,53,54,56,57,58,59,5a,5b,5c,5d,5e,5f,60,61,62,63,64,65,67,68,69,6a,6b,6c,6d,6e,6f,70,71,72,73,74,75,76,77,78,79,7a,7b,7c,7d,7e,7f,80,81,82,83,84,85,86,87,89,8a,8b,8c,8d,8e,8f,90,91,92,93,94,95,96,97,98,9a,9b,9c,9d,9e,9f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,ab,ac,ab,ac,ad,ae,af,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,ba,bc,bd,be,bf,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,ca,cb,cd,ce,cf,d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,da,db,dc,de,df,e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,ea,eb,ec,ed,ef,f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe) do if %color% equ %%i goto colok
- goto configerr
- :colokn
- if %dkif% equ b goto nodk
- for /f "delims=" %%a in (%1\doskey.ldt) do doskey %%a
- :nodkn
- for /f "delims=" %%y in (%1\%2) do (set /p com=<%1\%2
- if "!com!" equ help %cd%\help.txt
- if "!com!" equ exit exit
- if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
- if "!shutyn!" equ y shutdown /s /t 0 /f)
- !com!)
- exit
- :configerrn
- echo 配置文件可能存在问题,加载失败,请检查config.ldt。
- pause
- exit
- :dbgn
- @echo on
- for /f "delims=" %%u in (%1\%2) do (set /p com=<%1\%2
- if "!com!" equ help %1\%2
- if "!com1" equ exit exit
- if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
- if "!shutyn!" equ y shutdown /s /t 0 /f)
- !com!
- pause)
- exit
复制代码
|