Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for allhelp.bat

(view source code of allhelp.bat as plain text)

  1. @ECHO OFF
  2. IF "%OS%"=="Windows_NT" SETLOCAL DISABLEDELAYEDEXPANSION
  3.  
  4. :: Version number for this batch file
  5. SET MyVer=1.40
  6.  
  7. :: Display "about"
  8. ECHO.
  9. ECHO AllHelp.bat,  Version %MyVer% for Windows NT 4 / 2000 / XP
  10. ECHO Generate an HTML help file for "all" available commands
  11. ECHO.
  12. ECHO Note:
  13. ECHO This batch file uses the redirected output of the HELP command to generate the
  14. ECHO HTML file. Because some commands use "special" characters like ^&, ^<, and ^> in
  15. ECHO their help screen, not all output is displayed correctly in the browser.
  16. ECHO Known issues: skipped ^<space^> "tag" in CMD's special character list and skipped
  17. ECHO \^<xyz and xyz\^> word position references in FINDSTR's output.
  18. ECHO.
  19. ECHO Written by Rob van der Woude
  20. ECHO http://www.robvanderwoude.com
  21. ECHO.
  22. ECHO Improved white space handling by Johan Parlevliet
  23. ECHO Further improvements for NT 4 by Ulf Lindb„ck
  24. ECHO.
  25. ECHO.
  26. ECHO.
  27.  
  28. IF NOT "%OS%"=="Windows_NT" SET MyVer=
  29. IF NOT "%OS%"=="Windows_NT" GOTO End
  30.  
  31. :: Store current code page and then set code page for European languages
  32. FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%A) DO SET CHCP=%%B
  33. CHCP 1252 >NUL 2>&1
  34.  
  35. :: Start writing HTML file
  36. ECHO Writing HTML header . . .
  37. > allhelp.htm ECHO ^<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"^>
  38. >>allhelp.htm ECHO ^<HTML^>
  39. >>allhelp.htm ECHO ^<HEAD^>
  40. :: Read Windows version using VER command
  41. FOR /F "tokens=1 delims=[" %%A IN ('VER') DO SET Ver=%%A
  42. FOR /F "tokens=1* delims= " %%A IN ('ECHO.%Ver%') DO SET Ver=%%B
  43. :: Read latest Service Pack from registry
  44. CALL :GetSP
  45. >>allhelp.htm ECHO ^<TITLE^>Help for all %Ver%%SP% commands^</TITLE^>
  46. >>allhelp.htm ECHO ^<META NAME="generator" CONTENT="AllHelp.bat, Version %MyVer%, by Rob van der Woude"^>
  47. >>allhelp.htm ECHO ^</HEAD^>
  48. >>allhelp.htm ECHO.
  49. >>allhelp.htm ECHO ^<BODY^>
  50. >>allhelp.htm ECHO.
  51. >>allhelp.htm ECHO ^<A NAME="Top"^>^</A^>
  52. >>allhelp.htm ECHO.
  53. >>allhelp.htm ECHO ^<CENTER^>
  54. >>allhelp.htm ECHO ^<H1^>%Ver%%SP% commands^</H1^>
  55. FOR /F "tokens=* delims=" %%A IN ('VER') DO SET Ver=%%A
  56. >>allhelp.htm ECHO ^<H3^>%Ver%^</H3^>
  57. >>allhelp.htm ECHO ^</CENTER^>
  58. >>allhelp.htm ECHO.
  59. >>allhelp.htm ECHO ^<P^>^&nbsp;^</P^>
  60. >>allhelp.htm ECHO.
  61.  
  62. ECHO Creating command index table . . .
  63. SET FirstCell=1
  64. >>allhelp.htm ECHO ^<TABLE BORDER="0"^>
  65. :: Skip 1 or 2 lines of HELP command's header
  66. FOR /F "tokens=1 delims=[]" %%A IN ('HELP ^| FIND /N "."') DO IF %%A LEQ 2 SET Skip=+%%A
  67. :: MORE's /T switch translates tabs to a fixed number of spaces; tip by Johan Parlevliet
  68. :: In NT 4, MORE's /E switch may be necessary; tip by Ulf Lindb„ck
  69. :: %Skip% skips 1 or 2 lines of HELP command's header
  70. FOR /F "tokens=* delims=" %%A IN ('HELP ^| MORE /E %Skip% /T8') DO CALL :DispLine "%%A"
  71. >>allhelp.htm ECHO ^</TD^>^</TR^>
  72. >>allhelp.htm ECHO ^</TABLE^>
  73. >>allhelp.htm ECHO.
  74. >>allhelp.htm ECHO ^<P^>^&nbsp;^</P^>
  75. >>allhelp.htm ECHO.
  76.  
  77. ECHO Writing help for each command:
  78. :: MORE's /T switch translates tabs to a fixed number of spaces; tip by Johan Parlevliet
  79. :: In NT 4, MORE's /E switch may be necessary; tip by Ulf Lindb„ck
  80. FOR /F "tokens=* delims=" %%A IN ('HELP ^| MORE /E %Skip% /T8') DO CALL :DispFull "%%A"
  81.  
  82. ECHO Closing HTML file
  83. >>allhelp.htm ECHO.
  84. >>allhelp.htm ECHO ^<DIV ALIGN="Center"^>
  85. >>allhelp.htm ECHO ^<P^>This HTML file was generated by:^<BR^>
  86. >>allhelp.htm ECHO ^<B^>AllHelp.bat^</B^>, Version %MyVer%
  87. >>allhelp.htm ECHO for Windows NT^&nbsp;4^&nbsp;/^&nbsp;2000^&nbsp;/^&nbsp;XP^<BR^>
  88. >>allhelp.htm ECHO Written by Rob van der Woude^<BR^>
  89. >>allhelp.htm ECHO ^<A HREF="http://www.robvanderwoude.com"^>http://www.robvanderwoude.com^</A^>^</P^>
  90. >>allhelp.htm ECHO ^</DIV^>
  91. >>allhelp.htm ECHO.
  92. >>allhelp.htm ECHO ^</BODY^>
  93. >>allhelp.htm ECHO ^</HTML^>
  94.  
  95. ECHO.
  96. ECHO An HTML help file "allhelp.htm" has been created and stored in the current
  97. ECHO directory.
  98. ECHO.
  99. ECHO Now starting display of "allhelp.htm" . . .
  100. START "AllHelp" allhelp.htm
  101.  
  102. :: End of main batch program
  103. CHCP %CHCP% >NUL 2>&1
  104. ENDLOCAL
  105. GOTO:EOF
  106.  
  107.  
  108. :: Subroutines
  109.  
  110.  
  111. :DispLine
  112. SET Line=%1
  113. SET Line=%Line:(=^(%
  114. SET Line=%Line:)=^)%
  115. SET Line=%Line:"=%
  116. SET Command=%Line:~0,8%
  117. SET Command=%Command: =%
  118. IF DEFINED Command CALL :DispCmdLine %Command%
  119. FOR /F "tokens=1* delims= " %%a IN ('ECHO.%*') DO SET Descr=%%b
  120. SET Descr=%Descr:"=%
  121. >>allhelp.htm ECHO.%Descr%
  122. GOTO:EOF
  123.  
  124.  
  125. :DispCmdLine
  126. IF "%FirstCell%"=="0" IF DEFINED Command (>>allhelp.htm ECHO ^</TD^>^</TR^>)
  127. SET Command=%1
  128. IF DEFINED Command (>>allhelp.htm ECHO ^<TR^>^<TH ALIGN="left" VALIGN="top"^>^<A HREF="#%Command%"^>%Command%^</A^>^</TH^>^<TD^>^&nbsp;^&nbsp;^&nbsp;^</TD^>^<TD^>)
  129. SET FirstCell=0
  130. SET Command=
  131. GOTO:EOF
  132.  
  133.  
  134. :DispFull
  135. SET Line=%1
  136. SET Command=%Line:~1,8%
  137. SET Command=%Command: =%
  138. IF DEFINED Command CALL :WriteFull %Command%
  139. SET Command=
  140. GOTO:EOF
  141.  
  142.  
  143. :GetSP
  144. SET SP=
  145. :: Export registry tree to temporary file
  146. START /WAIT REGEDIT.EXE /E "%Temp%.\%~n0.dat" "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
  147. IF NOT EXIST "%Temp%.\%~n0.dat" GOTO:EOF
  148. :: Read value of "CSDVersion" from temporary file
  149. FOR /F "tokens=2 delims==" %%A IN ('TYPE "%Temp%.\%~n0.dat" ^| FIND /I "CSDVersion"') DO SET SP=%%~A
  150. :: Check if value is valid
  151. ECHO.%SP% | FIND /I "Service Pack" >NUL
  152. IF ERRORLEVEL 1 SET SP=
  153. DEL "%Temp%.\%~n0.dat"
  154. :: Use a shorter notation
  155. IF DEFINED SP SET SP=%SP:Service Pack=SP%
  156. GOTO:EOF
  157.  
  158.  
  159. :WriteFull
  160. ECHO.  %1 . . .
  161. >>allhelp.htm ECHO.
  162. >>allhelp.htm ECHO ^<A NAME="%~1"^>^</A^>
  163. >>allhelp.htm ECHO.
  164. >>allhelp.htm ECHO ^<H2^>%1^</H2^>
  165. >>allhelp.htm ECHO.
  166. >>allhelp.htm ECHO ^<PRE^>
  167. >>allhelp.htm HELP %1
  168. >>allhelp.htm ECHO ^</PRE^>
  169. >>allhelp.htm ECHO.
  170. >>allhelp.htm ECHO ^<A HREF="#Top"^>Back to the top of this page^</A^>
  171. >>allhelp.htm ECHO.
  172. >>allhelp.htm ECHO ^<P^>^&nbsp;^</P^>
  173. >>allhelp.htm ECHO.
  174. GOTO:EOF
  175.  
  176. :End
  177.  

page last modified: 2024-04-16; loaded in 0.0133 seconds