229 lines
6.3 KiB
Batchfile
229 lines
6.3 KiB
Batchfile
@if "%_ECHO%"=="" @echo off
|
|
|
|
setlocal
|
|
set PROG=IDHEADER
|
|
goto Start
|
|
|
|
rem ********************************
|
|
:Usage
|
|
echo Usage: %PROG% source-file helpid-out-file helpstr-out-file helpstr-resource [-NoIncludePath]
|
|
echo Converts an .ID file to three output files: 1) a help
|
|
echo context number .H file, 2) a help string .H file, and
|
|
echo 3) a resource .RC file
|
|
echo.
|
|
echo -NoIncludePath prevents the path of helpid-out-file from being added to
|
|
echo the #include statement at the beginning of helpstr-resource
|
|
goto end
|
|
rem ********************************
|
|
|
|
:Start
|
|
set FILE_ID=%1
|
|
set FILE_DEST1=%2
|
|
set FILE_DEST2=%3
|
|
set FILE_DEST3=%4
|
|
|
|
if "%FILE_ID%"=="" goto Usage
|
|
if "%FILE_DEST1%"=="" goto Usage
|
|
if "%FILE_DEST2%"=="" goto Usage
|
|
if "%FILE_DEST3%"=="" goto Usage
|
|
|
|
if "%5" == "-NoIncludePath" (
|
|
set IncludedFile=%~n2%~x2
|
|
) else if "%5"=="" (
|
|
set IncludedFile=%2
|
|
) else (
|
|
goto Usage
|
|
)
|
|
|
|
if not exist %FILE_ID% goto NoSource
|
|
|
|
rem Check for required tools
|
|
set SED=%THUNDER55%\%TOOLS%\bin\SED.EXE
|
|
set GREP=%THUNDER55%\%TOOLS%\bin\GREP.EXE
|
|
if not exist %SED% goto NoTool
|
|
if not exist %GREP% goto NoTool
|
|
|
|
rem Delete the destination file
|
|
if exist %FILE_DEST1% del %FILE_DEST1%
|
|
if exist %FILE_DEST1% goto ReadOnly1
|
|
if exist %FILE_DEST2% del %FILE_DEST2%
|
|
if exist %FILE_DEST2% goto ReadOnly2
|
|
if exist %FILE_DEST3% del %FILE_DEST3%
|
|
if exist %FILE_DEST3% goto ReadOnly3
|
|
|
|
set FILE_TMP1=%PROG%.T1
|
|
set FILE_TMP2=%PROG%.T2
|
|
if exist %FILE_TMP1% del %FILE_TMP1%
|
|
if exist %FILE_TMP2% del %FILE_TMP2%
|
|
|
|
rem -------------------------------
|
|
rem Add a warning to the first
|
|
rem temporary file that the file
|
|
rem is auto generated.
|
|
echo //******************************* >> %FILE_TMP1%
|
|
echo //******************************* >> %FILE_TMP1%
|
|
echo //* >> %FILE_TMP1%
|
|
echo //* THIS FILE IS AUTOMATICALLY GENERATED! >> %FILE_TMP1%
|
|
echo //* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! >> %FILE_TMP1%
|
|
echo //* >> %FILE_TMP1%
|
|
echo //* >> %FILE_TMP1%
|
|
echo //* This file was generated by processing >> %FILE_TMP1%
|
|
echo //* the following file: >> %FILE_TMP1%
|
|
echo //* >> %FILE_TMP1%
|
|
echo //* %FILE_ID% >> %FILE_TMP1%
|
|
echo //* >> %FILE_TMP1%
|
|
echo //* Please look there for possible instructions. >> %FILE_TMP1%
|
|
echo //* >> %FILE_TMP1%
|
|
echo //* DO NOT EDIT! DO NOT EDIT! DO NOT EDIT! >> %FILE_TMP1%
|
|
echo //* THIS FILE IS AUTOMATICALLY GENERATED! >> %FILE_TMP1%
|
|
echo //* >> %FILE_TMP1%
|
|
echo //******************************* >> %FILE_TMP1%
|
|
echo //******************************* >> %FILE_TMP1%
|
|
|
|
rem Now copy that warning to the second
|
|
rem temporary file
|
|
copy %FILE_TMP1% %FILE_TMP2%
|
|
|
|
rem -------------------------------
|
|
rem Set up the pattern. We are
|
|
rem expecting a file in the format:
|
|
rem
|
|
rem devstring devcontext# helpstring
|
|
rem
|
|
rem For example,
|
|
rem
|
|
rem comctls 2000001 "Microsoft Windows Common Controls"
|
|
rem
|
|
rem Blank lines are acceptable, as
|
|
rem are lines beginning with the C++
|
|
rem single-line comment characters (//)
|
|
|
|
set ALPHANUM=[A-Za-z_0-9]
|
|
set ALPHA=[A-Za-z_]
|
|
set IDENTIFIER=%ALPHA%%ALPHANUM%*
|
|
set INTEGER=[0-9][0-9]*
|
|
set WS=[ ][ ]*
|
|
set WSOKAY=[ ]*
|
|
set ANY=.*
|
|
|
|
set HID_LINE=%WSOKAY%\(%IDENTIFIER%\)%WS%\(%INTEGER%\)%WS%\"\(%ANY%\)\"%WSOKAY%
|
|
|
|
rem -------------------------------
|
|
rem Okay, have SED change the above format
|
|
rem into the following formats (one format
|
|
rem for each output file
|
|
rem
|
|
rem #define HID_devstring devcontext#
|
|
rem #define BS_devstring "helpstring"
|
|
rem
|
|
rem Example:
|
|
rem
|
|
rem #define HID_comctls]] 2000001
|
|
rem #define BS_comctls "Microsoft Windows Common Controls"
|
|
rem
|
|
rem This format is needed by VBIDE.SRC and WIZARD.SRC as well
|
|
rem as all OLE controls.
|
|
rem
|
|
rem Note that comment lines at the beginning of a line
|
|
rem are carried through to the destination. This is
|
|
rem quite intentional.
|
|
|
|
rem Remove comments that don't begin a line
|
|
%SED% "s#^\(..*\)//.*$#\1#g" < %FILE_ID% >> %FILE_TMP1%
|
|
|
|
rem
|
|
rem Add the STRINGTABLE section to the .RC file
|
|
rem
|
|
|
|
echo #include "%IncludedFile%" >> %FILE_DEST3%
|
|
echo STRINGTABLE DISCARDABLE >> %FILE_DEST3%
|
|
echo BEGIN >> %FILE_DEST3%
|
|
|
|
rem Okay, go ahead and make the transformations
|
|
%SED% "s/^%HID_LINE%$/#define HID_\1 \2/g" < %FILE_TMP1% >> %FILE_DEST1%
|
|
%SED% "s/^%HID_LINE%$/#define BS_\1 \"\3\"/g" < %FILE_TMP1% >> %FILE_DEST2%
|
|
%SED% "s/^%HID_LINE%$/ HID_\1 \& 65535 \"\3\"/g" < %FILE_TMP1% >> %FILE_DEST3%
|
|
|
|
echo END >> %FILE_DEST3%
|
|
|
|
rem -------------------------------
|
|
rem Time for some error checking
|
|
|
|
if not exist %FILE_DEST1% goto NoDestCreated1
|
|
if not exist %FILE_DEST2% goto NoDestCreated2
|
|
if not exist %FILE_DEST3% goto NoDestCreated3
|
|
|
|
rem Are there any lines that were not in the correct
|
|
rem format and are not comments?
|
|
|
|
rem Remove all comments so we can check
|
|
rem the format of the lines.
|
|
rem Note that we need only check one
|
|
rem of the output files in order to
|
|
rem test the format of the input file.
|
|
if exist %FILE_TMP1% del %FILE_TMP1%
|
|
if exist %FILE_TMP2% del %FILE_TMP2%
|
|
%SED% "s#%WSOKAY%//.*$##g" < %FILE_DEST1% > %FILE_TMP1%
|
|
|
|
set FILE_BAD=%FILE_DEST1%.ERR
|
|
if exist %FILE_BAD% del %FILE_BAD%
|
|
rem Now remove blank lines
|
|
%GREP% -v "^$" %FILE_TMP1% > %FILE_TMP2%
|
|
rem Now find any lines in an incorrect format
|
|
%GREP% -v "#define " %FILE_TMP2% > %FILE_BAD%
|
|
rem Did grep write any lines to %FILE_BAD%?
|
|
if not errorlevel 1 goto BadFormat
|
|
|
|
rem Remove empty error file
|
|
if exist %FILE_BAD% del %FILE_BAD%
|
|
|
|
rem ------------------------------
|
|
rem Remove temporary files
|
|
if exist %FILE_TMP1% del %FILE_TMP1%
|
|
if exist %FILE_TMP2% del %FILE_TMP2%
|
|
|
|
goto end
|
|
|
|
:NoSource
|
|
echo %PROG%: The source file %FILE_ID% could not be found.
|
|
goto end
|
|
|
|
:ReadOnly1
|
|
echo %PROG%: Error: Could not delete destination file %FILE_DEST1%
|
|
goto end
|
|
|
|
:ReadOnly2
|
|
echo %PROG%: Error: Could not delete destination file %FILE_DEST2%
|
|
goto end
|
|
|
|
:Readonly3
|
|
echo %PROG%: Error: Could not delete destination file %FILE_DEST3%
|
|
goto end
|
|
|
|
:NoDestCreated1
|
|
echo %PROG%: Error: Something went wrong, %FILE_DEST1% was not created.
|
|
echo You might try setting _ECHO=1 and then running again to see what
|
|
echo failed.
|
|
goto end
|
|
|
|
:NoDestCreated1
|
|
echo %PROG%: Error: Something went wrong, %FILE_DEST2% was not created.
|
|
echo You might try setting _ECHO=1 and then running again to see what
|
|
echo failed.
|
|
echo Note that SED.EXE and GREP.EXE are required by this batch file.
|
|
goto end
|
|
|
|
:BadFormat
|
|
echo %PROG%: Error: Some lines in %FILE_ID% are in an incorrect format.
|
|
echo These are listed in %FILE_BAD%.
|
|
goto end
|
|
|
|
:NoTool
|
|
echo %PROG%: Error: One of the following tools could not be located:
|
|
echo %SED%
|
|
echo %GREP%
|
|
goto end
|
|
|
|
:end
|
|
endlocal
|