Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal EnableDelayedExpansion
- rem HelpToTextToHtml.bat: Create a web page with help on Windows-DOS commands
- rem Antonio Perez Ayala
- rem Load the list of commands from Help command
- for /F "skip=2 tokens=1* delims=:" %%a in ('help ^| findstr /N "^"') do (
- set "line=%%b"
- if not defined line goto endHelp
- if "!line:~0,3!" neq " " (
- for /F "tokens=1*" %%c in ("!line!") do (
- set "help[%%c]=%%d"
- set "com=%%c"
- )
- ) else (
- for %%c in (!com!) do for /F "tokens=*" %%d in ("!line!") do set "help[%%c]=!help[%%c]! %%d"
- )
- )
- :endHelp
- rem Delete synonyms and problematic commands from the list
- for %%a in (ERASE RENAME CHDIR MKDIR RMDIR SC DISKPART GRAFTABL) do set "help[%%a]="
- rem Process the help definition file
- set /P "fileName=" < HelpToTextToHtml.txt
- setlocal DisableDelayedExpansion
- ( rem Start of redirected block to Stdout and Stderr
- echo = =
- echo [hr]>&2
- set "codeSeg="
- set "footer="
- for /F "tokens=1* delims=:" %%a in ('findstr /N "^" HelpToTextToHtml.txt') do if %%a neq 1 (
- set "line=%%b"
- setlocal EnableDelayedExpansion
- if defined codeSeg (
- echo(!line!>&2
- if "!line:~0,7!" equ "[/code]" (endlocal & set "codeSeg=") else endlocal
- ) else if /I "!line:~0,6!" equ "[code]" (
- echo !line!>&2
- for %%c in (!line:~6!) do endlocal & set codeSeg=Y & set "select[%%c]=%%c"
- ) else if "!line:~0,1!" equ "=" (
- rem Subdivision: just copy it
- echo !line! > CON
- echo !line!
- if "!line:~2,1!" neq "=" for /F "delims=|" %%c in ("!line:~2!") do set "footer=!footer! %%c"
- for /F "delims=" %%c in ("footer=!footer!") do endlocal & set %%c
- ) else (
- rem Process commands in not-subdivision line
- set "com="
- echo [list]
- for %%c in ("!line: =" "!") do (
- if defined help[%%~c] (
- help %%~c > help.txt
- if /I "%%~c" equ "PAUSE" echo/>> help.txt
- ) else (
- %%~c /? > help.txt 2>NUL
- )
- for /F %%d in ('find /V /C "" ^< help.txt') do set /A height=%%d-1
- if !height! gtr 0 (
- echo Command: %%c > CON
- echo [*][url=#%%~c]%%~c[/url] - !help[%%~c]!
- set /A height=height*12/10+1
- if !height! gtr 30 (set "height= height:30.5em;") else set "height="
- echo [code!height!]%%~c>&2
- type help.txt>&2
- echo [/code]>&2
- set "com=!com! %%~c"
- )
- )
- echo [/list]
- echo [br][hr]>&2
- for %%c in (once !com!) do if %%c equ once (endlocal) else set "help[%%c]=" & set "select[%%c]=%%c"
- )
- )
- rem Process the rest of commands displayed by help command
- setlocal EnableDelayedExpansion
- echo [list]
- for /F "tokens=2 delims=[]" %%c in ('set help[') do (
- help %%c > help.txt
- for /F %%d in ('find /V /C "" ^< help.txt') do set /A height=%%d-1
- echo Command: "%%c" > CON
- echo [*][url=#%%c]%%c[/url] - !help[%%c]!
- set /A height=height*12/10+1
- if !height! gtr 30 (set "height= height:30.5em;") else set "height="
- echo [code!height!]%%c>&2
- type help.txt>&2
- echo [/code]>&2
- set "select[%%c]=%%c"
- )
- echo [/list]
- echo =
- echo [br][hr]>&2
- rem Create the footer
- echo [list=C:3]>&2
- (for %%a in (!footer!) do echo [*][url=#%%a]plain:[color="#666666" size="-1"]%%a[/color][/url]) >&2
- echo [/list]>&2
- ) > TOCData.txt 2> bodyData.txt
- del help.txt
- rem Create the alphabetical index and assemble the final file
- < NUL (
- set /P "=[style="float:right"]Index: [select][url]Pick command[/url]"
- set "group="
- for /F "tokens=2 delims=[]" %%a in ('set select[') do (
- if "!select[%%a]:~0,1!" neq "!group!" (
- set "group=!select[%%a]:~0,1!"
- set /P "=[url]group:!group![/url]"
- )
- set /P "=[url=#%%a]%%a[/url]"
- )
- echo [/select][/style]
- type TOCData.txt
- type bodyData.txt
- ) > "%filename%.txt"
- del TOCData.txt
- del bodyData.txt
- rem Convert the file to Html
- echo/
- echo ------------------------------------------
- echo/
- TextToHtml.bat "%filename%.txt" "maxUrlTagsInSelect=120"
- echo ERROR: TextToHtml.bat conversion program not found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement