Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
6.5 KiB

  1. @if "%_ECHO%"=="" @echo off
  2. setlocal
  3. set PROG=IDHEADER
  4. goto Start
  5. rem ********************************
  6. :Usage
  7. echo Usage: %PROG% source-file helpid-out-file helpstr-out-file helpstr-resource [-NoIncludePath]
  8. echo Converts an .ID file to three output files: 1) a help
  9. echo context number .H file, 2) a help string .H file, and
  10. echo 3) a resource .RC file
  11. echo.
  12. echo -NoIncludePath prevents the path of helpid-out-file from being added to
  13. echo the #include statement at the beginning of helpstr-resource
  14. goto end
  15. rem ********************************
  16. :Start
  17. set FILE_ID=%1
  18. set FILE_DEST1=%2
  19. set FILE_DEST2=%3
  20. set FILE_DEST3=%4
  21. if "%FILE_ID%"=="" goto Usage
  22. if "%FILE_DEST1%"=="" goto Usage
  23. if "%FILE_DEST2%"=="" goto Usage
  24. if "%FILE_DEST3%"=="" goto Usage
  25. if "%5" == "-NoIncludePath" (
  26. set IncludedFile=%~n2%~x2
  27. ) else if "%5"=="" (
  28. set IncludedFile=%2
  29. ) else (
  30. goto Usage
  31. )
  32. if not exist %FILE_ID% goto NoSource
  33. rem Check for required tools
  34. set SED=%THUNDER55%\%TOOLS%\bin\SED.EXE
  35. set GREP=%THUNDER55%\%TOOLS%\bin\GREP.EXE
  36. if not exist %SED% goto NoTool
  37. if not exist %GREP% goto NoTool
  38. rem Delete the destination file
  39. if exist %FILE_DEST1% del %FILE_DEST1%
  40. if exist %FILE_DEST1% goto ReadOnly1
  41. if exist %FILE_DEST2% del %FILE_DEST2%
  42. if exist %FILE_DEST2% goto ReadOnly2
  43. if exist %FILE_DEST3% del %FILE_DEST3%
  44. if exist %FILE_DEST3% goto ReadOnly3
  45. set FILE_TMP1=%PROG%.T1
  46. set FILE_TMP2=%PROG%.T2
  47. if exist %FILE_TMP1% del %FILE_TMP1%
  48. if exist %FILE_TMP2% del %FILE_TMP2%
  49. rem -------------------------------
  50. rem Add a warning to the first
  51. rem temporary file that the file
  52. rem is auto generated.
  53. echo //******************************* >> %FILE_TMP1%
  54. echo //******************************* >> %FILE_TMP1%
  55. echo //* >> %FILE_TMP1%
  56. echo //* THIS FILE IS AUTOMATICALLY GENERATED! >> %FILE_TMP1%
  57. echo //* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! >> %FILE_TMP1%
  58. echo //* >> %FILE_TMP1%
  59. echo //* >> %FILE_TMP1%
  60. echo //* This file was generated by processing >> %FILE_TMP1%
  61. echo //* the following file: >> %FILE_TMP1%
  62. echo //* >> %FILE_TMP1%
  63. echo //* %FILE_ID% >> %FILE_TMP1%
  64. echo //* >> %FILE_TMP1%
  65. echo //* Please look there for possible instructions. >> %FILE_TMP1%
  66. echo //* >> %FILE_TMP1%
  67. echo //* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! >> %FILE_TMP1%
  68. echo //* THIS FILE IS AUTOMATICALLY GENERATED! >> %FILE_TMP1%
  69. echo //* >> %FILE_TMP1%
  70. echo //******************************* >> %FILE_TMP1%
  71. echo //******************************* >> %FILE_TMP1%
  72. rem Now copy that warning to the second
  73. rem temporary file
  74. copy %FILE_TMP1% %FILE_TMP2%
  75. rem -------------------------------
  76. rem Set up the pattern. We are
  77. rem expecting a file in the format:
  78. rem
  79. rem devstring devcontext# helpstring
  80. rem
  81. rem For example,
  82. rem
  83. rem comctls 2000001 "Microsoft Windows Common Controls"
  84. rem
  85. rem Blank lines are acceptable, as
  86. rem are lines beginning with the C++
  87. rem single-line comment characters (//)
  88. set ALPHANUM=[A-Za-z_0-9]
  89. set ALPHA=[A-Za-z_]
  90. set IDENTIFIER=%ALPHA%%ALPHANUM%*
  91. set INTEGER=[0-9][0-9]*
  92. set WS=[ ][ ]*
  93. set WSOKAY=[ ]*
  94. set ANY=.*
  95. set HID_LINE=%WSOKAY%\(%IDENTIFIER%\)%WS%\(%INTEGER%\)%WS%\"\(%ANY%\)\"%WSOKAY%
  96. rem -------------------------------
  97. rem Okay, have SED change the above format
  98. rem into the following formats (one format
  99. rem for each output file
  100. rem
  101. rem #define HID_devstring devcontext#
  102. rem #define BS_devstring "helpstring"
  103. rem
  104. rem Example:
  105. rem
  106. rem #define HID_comctls]] 2000001
  107. rem #define BS_comctls "Microsoft Windows Common Controls"
  108. rem
  109. rem This format is needed by VBIDE.SRC and WIZARD.SRC as well
  110. rem as all OLE controls.
  111. rem
  112. rem Note that comment lines at the beginning of a line
  113. rem are carried through to the destination. This is
  114. rem quite intentional.
  115. rem Remove comments that don't begin a line
  116. %SED% "s#^\(..*\)//.*$#\1#g" < %FILE_ID% >> %FILE_TMP1%
  117. rem
  118. rem Add the STRINGTABLE section to the .RC file
  119. rem
  120. echo #include "%IncludedFile%" >> %FILE_DEST3%
  121. echo STRINGTABLE DISCARDABLE >> %FILE_DEST3%
  122. echo BEGIN >> %FILE_DEST3%
  123. rem Okay, go ahead and make the transformations
  124. %SED% "s/^%HID_LINE%$/#define HID_\1 \2/g" < %FILE_TMP1% >> %FILE_DEST1%
  125. %SED% "s/^%HID_LINE%$/#define BS_\1 \"\3\"/g" < %FILE_TMP1% >> %FILE_DEST2%
  126. %SED% "s/^%HID_LINE%$/ HID_\1 \& 65535 \"\3\"/g" < %FILE_TMP1% >> %FILE_DEST3%
  127. echo END >> %FILE_DEST3%
  128. rem -------------------------------
  129. rem Time for some error checking
  130. if not exist %FILE_DEST1% goto NoDestCreated1
  131. if not exist %FILE_DEST2% goto NoDestCreated2
  132. if not exist %FILE_DEST3% goto NoDestCreated3
  133. rem Are there any lines that were not in the correct
  134. rem format and are not comments?
  135. rem Remove all comments so we can check
  136. rem the format of the lines.
  137. rem Note that we need only check one
  138. rem of the output files in order to
  139. rem test the format of the input file.
  140. if exist %FILE_TMP1% del %FILE_TMP1%
  141. if exist %FILE_TMP2% del %FILE_TMP2%
  142. %SED% "s#%WSOKAY%//.*$##g" < %FILE_DEST1% > %FILE_TMP1%
  143. set FILE_BAD=%FILE_DEST1%.ERR
  144. if exist %FILE_BAD% del %FILE_BAD%
  145. rem Now remove blank lines
  146. %GREP% -v "^$" %FILE_TMP1% > %FILE_TMP2%
  147. rem Now find any lines in an incorrect format
  148. %GREP% -v "#define " %FILE_TMP2% > %FILE_BAD%
  149. rem Did grep write any lines to %FILE_BAD%?
  150. if not errorlevel 1 goto BadFormat
  151. rem Remove empty error file
  152. if exist %FILE_BAD% del %FILE_BAD%
  153. rem ------------------------------
  154. rem Remove temporary files
  155. if exist %FILE_TMP1% del %FILE_TMP1%
  156. if exist %FILE_TMP2% del %FILE_TMP2%
  157. goto end
  158. :NoSource
  159. echo %PROG%: The source file %FILE_ID% could not be found.
  160. goto end
  161. :ReadOnly1
  162. echo %PROG%: Error: Could not delete destination file %FILE_DEST1%
  163. goto end
  164. :ReadOnly2
  165. echo %PROG%: Error: Could not delete destination file %FILE_DEST2%
  166. goto end
  167. :Readonly3
  168. echo %PROG%: Error: Could not delete destination file %FILE_DEST3%
  169. goto end
  170. :NoDestCreated1
  171. echo %PROG%: Error: Something went wrong, %FILE_DEST1% was not created.
  172. echo You might try setting _ECHO=1 and then running again to see what
  173. echo failed.
  174. goto end
  175. :NoDestCreated1
  176. echo %PROG%: Error: Something went wrong, %FILE_DEST2% was not created.
  177. echo You might try setting _ECHO=1 and then running again to see what
  178. echo failed.
  179. echo Note that SED.EXE and GREP.EXE are required by this batch file.
  180. goto end
  181. :BadFormat
  182. echo %PROG%: Error: Some lines in %FILE_ID% are in an incorrect format.
  183. echo These are listed in %FILE_BAD%.
  184. goto end
  185. :NoTool
  186. echo %PROG%: Error: One of the following tools could not be located:
  187. echo %SED%
  188. echo %GREP%
  189. goto end
  190. :end
  191. endlocal