批处理行号是如何加上去的?
http://www.cn-dos.net/forum/viewthread.php?tid=21664
[ Last edited by dosz on 2009-4-11 at 10:26 ]
http://www.cn-dos.net/forum/viewthread.php?tid=21664
dosz发表于: 2009-04-11 21:14
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :: Batch2ubb.cmd -V0.30 -- 批处理转 UBB 代码
- :: 无奈何@cn-dos.net - 更新于:2005-7-30 - CMD & GAWK
- :: 用法:Batch2ubb
- :: 支持文件: - gawk.exe winclip.exe Batch2ubb.awk batch.esy
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- @echo off
- setlocal
- set path=%path%;%cd%;%~dp0
- set error=
- rem 文件完整性检查。
- for %%i in (gawk.exe winclip.exe batch.esy batch2ubb.awk) do (
- @if "%%~$PATH:i" == "" (
- echo 错误:程序所依赖文件 "%%i" 缺失。
- set error=错误:程序文件不完整。
- ) else ( set %%~ni="%%~$PATH:i" )
- )
- if defined error goto error
- rem 测试剪贴板数据类型。
- winclip -i |findstr /r ".*_.*TEXT" >nul
- if ERRORLEVEL 1 set error=错误:剪贴板为空或内容为非文字数据!
- rem 空参数调用获得剪贴板数据,将转换结果复制到剪贴板。
- if "%~1" == "" (
- if defined error goto error
- winclip -p |gawk -v line=1 -f %Batch2ubb% |winclip -c
- goto end
- )
- rem 只有一个参数时尝试作为输入文件处理,当其不存在时作参数处理。
- if "%~2" == "" (
- if exist "%~1" (
- gawk -v line=1 -f %Batch2ubb% "%~1" |winclip -c
- goto end
- )
- )
- set line=1
- set input=
- set out=
- :ParseLoop
- if "%~1" == "" goto Start
- if "%~1" == "/?" goto SwitchH
- rem 参数处理并转到相应标签。
- for %%s in (i I n N o O h H) do if "%~1"=="/%%s" goto Switch%%s
- set error=错误: 参数格式不正确 - "%1"!
- goto error
- :SwitchI
- set "input=%~2"
- if not exist "%input%" set error=警告:文件 "%input%" 不存在。 & goto error
- goto Next2Arg
- :SwitchO
- set "out=%~2"
- if not defined out set error=警告:请指定输出文件。 & goto error
- goto Next2Arg
- :SwitchN
- set line=0
- goto NextArg
- :Next2Arg
- shift
- :NextArg
- shift
- goto ParseLoop
- rem 不同参数分类判断处理。
- :Start
- if defined input (
- if defined out (
- gawk -v line=%line% -f %Batch2ubb% "%input%" >"%out%"
- ) else (
- gawk -v line=%line% -f %Batch2ubb% "%input%" |winclip -c
- )
- ) else (
- if defined out (
- if defined error goto error
- winclip -p |gawk -v line=%line% -f %Batch2ubb% >"%out%"
- ) else (
- if defined error goto error
- winclip -p |gawk -v line=0 -f %Batch2ubb% |winclip -c
- )
- )
- goto end
- :error
- echo.%error%
- echo.
- :SwitchH
- echo.批处理转 UBB 代码。
- echo.Batch2ubb
- echo.
- echo. /i 指定转换的文件,可包含路径,缺省从剪贴板获得。
- echo. /o 指定输出的文件,可包含路径,缺省输出到剪贴板。
- echo. /n 生成无行号的 UBB 代码,缺省带行号。
- echo. /h 显示本简短帮助,等价命令 /?。
- echo. 本程序执行依赖以下文件 gawk.exe winclip.exe Batch2ubb.awk batch.esy。
- echo.
- :end
[ Last edited by dosz on 2009-4-11 at 10:26 ]
