Advertisement
Aacini

T2H - HelpToTextToHtml.bat

Dec 9th, 2013
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3.  
  4. rem HelpToTextToHtml.bat: Create a web page with help on Windows-DOS commands
  5. rem Antonio Perez Ayala
  6.  
  7. rem Load the list of commands from Help command
  8. for /F "skip=2 tokens=1* delims=:" %%a in ('help ^| findstr /N "^"') do (
  9.    set "line=%%b"
  10.    if not defined line goto endHelp
  11.    if "!line:~0,3!" neq "   " (
  12.       for /F "tokens=1*" %%c in ("!line!") do (
  13.          set "help[%%c]=%%d"
  14.          set "com=%%c"
  15.       )
  16.    ) else (
  17.       for %%c in (!com!) do for /F "tokens=*" %%d in ("!line!") do set "help[%%c]=!help[%%c]! %%d"
  18.    )
  19. )
  20. :endHelp
  21.  
  22. rem Delete synonyms and problematic commands from the list
  23. for %%a in (ERASE RENAME  CHDIR MKDIR RMDIR  SC DISKPART GRAFTABL) do set "help[%%a]="
  24.  
  25. rem Process the help definition file
  26. set /P "fileName=" < HelpToTextToHtml.txt
  27. setlocal DisableDelayedExpansion
  28. ( rem Start of redirected block to Stdout and Stderr
  29. echo = =
  30. echo [hr]>&2
  31. set "codeSeg="
  32. set "footer="
  33. for /F "tokens=1* delims=:" %%a in ('findstr /N "^" HelpToTextToHtml.txt') do if %%a neq 1 (
  34.    set "line=%%b"
  35.    setlocal EnableDelayedExpansion
  36.  
  37.    if defined codeSeg (
  38.       echo(!line!>&2
  39.       if "!line:~0,7!" equ "[/code]" (endlocal & set "codeSeg=") else endlocal
  40.    ) else if /I "!line:~0,6!" equ "[code]" (
  41.       echo !line!>&2
  42.       for %%c in (!line:~6!) do endlocal & set codeSeg=Y & set "select[%%c]=%%c"
  43.    ) else if "!line:~0,1!" equ "=" (
  44.       rem Subdivision: just copy it
  45.       echo !line! > CON
  46.       echo !line!
  47.       if "!line:~2,1!" neq "=" for /F "delims=|" %%c in ("!line:~2!") do set "footer=!footer! %%c"
  48.       for /F "delims=" %%c in ("footer=!footer!") do endlocal & set %%c
  49.    ) else (
  50.       rem Process commands in not-subdivision line
  51.       set "com="
  52.       echo [list]
  53.       for %%c in ("!line: =" "!") do (
  54.          if defined help[%%~c] (
  55.             help %%~c > help.txt
  56.             if /I "%%~c" equ "PAUSE" echo/>> help.txt
  57.          ) else (
  58.             %%~c /? > help.txt 2>NUL
  59.          )
  60.          for /F %%d in ('find /V /C "" ^< help.txt') do set /A height=%%d-1
  61.          if !height! gtr 0 (
  62.             echo Command: %%c > CON
  63.             echo [*][url=#%%~c]%%~c[/url] - !help[%%~c]!
  64.             set /A height=height*12/10+1
  65.             if !height! gtr 30 (set "height= height:30.5em;") else set "height="
  66.             echo [code!height!]%%~c>&2
  67.             type help.txt>&2
  68.             echo [/code]>&2
  69.             set "com=!com! %%~c"
  70.          )
  71.       )
  72.       echo [/list]
  73.       echo [br][hr]>&2
  74.       for %%c in (once !com!) do if %%c equ once (endlocal) else set "help[%%c]=" & set "select[%%c]=%%c"
  75.    )
  76. )
  77.  
  78. rem Process the rest of commands displayed by help command
  79. setlocal EnableDelayedExpansion
  80. echo [list]
  81. for /F "tokens=2 delims=[]" %%c in ('set help[') do (
  82.    help %%c > help.txt
  83.    for /F %%d in ('find /V /C "" ^< help.txt') do set /A height=%%d-1
  84.    echo Command: "%%c" > CON
  85.    echo [*][url=#%%c]%%c[/url] - !help[%%c]!
  86.    set /A height=height*12/10+1
  87.    if !height! gtr 30 (set "height= height:30.5em;") else set "height="
  88.    echo [code!height!]%%c>&2
  89.    type help.txt>&2
  90.    echo [/code]>&2
  91.    set "select[%%c]=%%c"
  92. )
  93. echo [/list]
  94. echo =
  95. echo [br][hr]>&2
  96.  
  97. rem Create the footer
  98. echo [list=C:3]>&2
  99. (for %%a in (!footer!) do echo [*][url=#%%a]plain:[color="#666666" size="-1"]%%a[/color][/url]) >&2
  100. echo [/list]>&2
  101.  
  102. ) > TOCData.txt  2> bodyData.txt
  103. del help.txt
  104.  
  105. rem Create the alphabetical index and assemble the final file
  106. < NUL (
  107.    set /P "=[style="float:right"]Index: [select][url]Pick command[/url]"
  108.    set "group="
  109.    for /F "tokens=2 delims=[]" %%a in ('set select[') do (
  110.       if "!select[%%a]:~0,1!" neq "!group!" (
  111.          set "group=!select[%%a]:~0,1!"
  112.          set /P "=[url]group:!group![/url]"
  113.       )
  114.       set /P "=[url=#%%a]%%a[/url]"
  115.    )
  116.    echo [/select][/style]
  117.    type TOCData.txt
  118.    type bodyData.txt
  119. ) > "%filename%.txt"
  120. del TOCData.txt
  121. del bodyData.txt
  122.  
  123. rem Convert the file to Html
  124. echo/
  125. echo ------------------------------------------
  126. echo/
  127. TextToHtml.bat "%filename%.txt" "maxUrlTagsInSelect=120"
  128. echo ERROR: TextToHtml.bat conversion program not found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement