- @echo off
- del "%temp%\~line*.tmp" >nul 2>nul
-
- if "%~1" neq "" goto LTrimInit
- for /f "eol= tokens=* delims= " %%a in ('"%~f0" LTrimInit') do (
- if "%%a"=="" (
- for %%i in ("%temp%\~line.tmp") do (
- for /f "usebackq delims=" %%A in (%%i) do if %%~zi gtr 60 (
- set var=%%A
- set size=%%~zi
- call :split
- ) else (del "%temp%\~line.tmp" & echo=%%A)
- )
- echo;
- ) else (
- if not exist "%temp%\~line.tmp" (set /p=" %%a"<nul>>"%temp%\~line.tmp"
- ) else set /p= %%a<nul>>"%temp%\~line.tmp"
- )
- )
- rem 最后一段后面没有空行的情况
- if exist "%temp%\~line*.tmp" (
- for %%i in ("%temp%\~line.tmp") do (
- if %%~zi gtr 60 (
- set size=%%~zi
- for /f "usebackq delims=" %%A in (%%i) do set var=%%A
- call :split
- ) else echo= %%a
- )
- )
-
- pause&exit/b
-
- :LTrimInit
- set "tab= "
- for /f "delims=" %%a in ('findstr /n .* a.bat') do (
- set var=%%a
- setlocal enableDelayedExpansion
- set var=!var:%tab%= !
- set var=!var:*:= !
- echo=!var!
- endlocal
- )
- goto :eof
-
- :split
- set offset=0
- setlocal enableDelayedExpansion
- fsutil file createnew "%temp%\~line2.tmp" !size! >nul
- for /f "tokens=2 delims=: " %%a in ('fc /b "%temp%\~line.tmp" "%temp%\~line2.tmp" ^| more +1') do (
- set /a n+=1, n%%=60
- if 0x%%a geq 128 (set /a byte+=1) else set /a byte+=2
- if !n!==0 (
- if 0x%%a geq 128 (
- if 0x!prev! lss 128 (set /a "len=(byte-1)>>1", byte=1, n=1) else set /a "len=byte>>1", byte=0
- ) else (
- set /a "len=byte>>1", byte=0
- )
- for /f "tokens=1,2" %%i in ("!offset! !len!") do echo=!var:~%%i,%%j!
- set /a offset+=len
- )
- set prev=%%a
- )
- if %n% neq 0 echo=!var:~%offset%!
- del "%temp%\~line*.tmp"
- goto :eof
复制代码 针对题目新要求做了改动,还需要完善。
[ 本帖最后由 zqz0012005 于 2009-8-18 22:50 编辑 ] |