home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lx2v103.zip / BuildLevel.cmd < prev    next >
OS/2 REXX Batch file  |  2000-02-17  |  15KB  |  287 lines

  1. /***********************************************************************\
  2.  *                           BuildLevel.cmd                            *
  3.  *             Copyright (C) by Stangl Roman, 1996, 1999               *
  4.  *                                                                     *
  5.  * This Code may be freely distributed, provided the Copyright isn't   *
  6.  * removed.                                                            *
  7.  *                                                                     *
  8.  * BuildLevel.cmd                                                      *
  9.  *              Batch file to replace the DESCRIPTION statement in a   *
  10.  *              module's (EXE or DLL) with one the OS/2 BLDLEVEL       *
  11.  *              command is able to read.                               *
  12.  *              Syntax: BuildLevel ModuleDefinitionFile Headerfile     *
  13.  *              e.g. BuildLevel PC2.def PC2.h                          *
  14.  *                                                                     *
  15. \***********************************************************************/
  16.  
  17. /* static char     _VERSION_[]="BuildLevel.cmd - V2.20"; */
  18.  
  19.  
  20. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  21. Call SysLoadFuncs
  22.                                         /* Trap CTRL+BRK processing to avoid data corruption */
  23. Signal On HALT NAME SignalHandler
  24.  
  25.                                         /* OS/2 returncode */
  26. ReturnCode=1
  27.                                         /* 1st commandline argument (1 *.DEF file) */
  28. DefinitionFile=""
  29.                                         /* As the contents of the 1st commandline argument
  30.                                            file get changed, we make a temporary copy to read
  31.                                            from and write the new contents to the original file */
  32. DefinitionCopy="$Temp$"
  33.                                         /* 2nd commandline argument (1 *.H* file) */
  34. HeaderFile=""
  35.                                         /* Name of the binary module which gets filled from
  36.                                            the NAME (for *.EXE) or LIBRARY (for *.DLL) statement */
  37. ModuleName=""
  38.                                         /* Description statement which gets constructed from the
  39.                                            header (*.H*) file to replace/add the DESCRIPTION
  40.                                            statement in the *.DEF file */
  41. Description=""
  42. Description_Header="Description '"
  43. Description_Trailer="'"
  44.                                         /* The build level part of the DESCRIPTION statement is built 
  45.                                            from the following substrings */
  46. BldLevel=""
  47. BldLevel_Header="$@#"
  48. BldLevel_Vendor=""
  49. BldLevel_Version=""
  50. BldLevel_Info=""
  51. BldLevel_Trailer="@#"
  52.  
  53. /*--------------------------------------------------------------------------------------*\
  54.  * Main entry point.                                                                    *
  55.  * Req:                                                                                 *
  56.  *      none                                                                            *
  57.  * Returns:                                                                             *
  58.  *      ReturnCode .... Error code (0 if no error)                                      *
  59. \*--------------------------------------------------------------------------------------*/
  60.                                         /* Get the DefinitionFile (*.DEF) we want to check
  61.                                            the BLDLEVEL and the Headerfile (*.H*) where
  62.                                            the required BLDLEVEL data is defined in */
  63. Parse Arg DefinitionFile HeaderFile .
  64.                                         /* If no arguments are specified, display syntax */
  65. If DefinitionFile="" | HeaderFile="" Then
  66.     Do
  67.     Say
  68.     Say 'Syntax: BUILDLEVEL module.def header.h'
  69.     Say
  70.     Say 'Where: module.def ... Module definition file where the BLDLEVEL information'
  71.     Say '                      will be written at the DESCRIPTION statement.'
  72.     Say '       header.h ..... Header file where the macros BLDLEVEL_VENDOR,'
  73.     Say '                      BLDLEVEL_VERSION and BLDLEVEL_INFO will be taken from.'
  74.     Say
  75.     Say 'Error '||ReturnCode||' incorrect commandline arguments specified.'
  76.     Say
  77. cmd='dir'
  78. cmd
  79.     Exit
  80.     End
  81. Do While (DefinitionFile\="" & HeaderFile\="")
  82.                                         /* We have valid commandline arguments, so first see
  83.                                            if the Headerfile contents are ok for us */
  84.     ReturnCode=ParseHeaderFile()
  85.     If ReturnCode\=0 Then Leave
  86.                                         /* Parse the definition file (*.DEF) for the module
  87.                                            name, to see if we got a valid file */
  88.     ReturnCode=ParseDefinitionFile()
  89.     If ReturnCode\=0 Then Leave
  90.                                         /* Copy the definition file, because we're going to
  91.                                            change the original */
  92.     Command="@copy "||DefinitionFile||" "||DefinitionCopy||" /v >NUL"
  93.     Command
  94.     Command="@del "||DefinitionFile||" >NUL 2>&1"
  95.     Command
  96.     If (rc\=0) Then Do
  97.         ReturnCode=2
  98.         Leave
  99.     End
  100.                                         /* Build DESCRIPTION statement for *.DEF file */
  101.     BldLevel=BldLevel_Header||BldLevel_Vendor||":"||BldLevel_Version||" ("||ModuleName||")#@"||BldLevel_Info
  102.     Description=Description_Header||BldLevel||Description_Trailer
  103.                                         /* Copy the module definition file to be able to change
  104.                                            the contents of the original one. In case of an error
  105.                                            copy back the original one */
  106.     ReturnCode=ModifyDefinitionFile()
  107.     If ReturnCode\=0 Then Do
  108.         Command="@copy "||DefinitionCopy||" "||DefinitionFile||" /v >NUL"
  109.         Command
  110.         Command="@del "||DefinitionCopy||" >NUL 2>&1"
  111.         Command
  112.         Leave
  113.     End
  114.  
  115.                                         /* Exit with success */
  116.     Command="@del "||DefinitionCopy||" >NUL 2>&1"
  117.     Command
  118.     ReturnCode=0
  119.     Leave
  120. End
  121.                                         /* Exit to commandline */
  122. If (ReturnCode\=0) Then Do
  123.     Say ""
  124.     Say "Error "||ReturnCode||" modifying "||DefinitionFile||", no changes made"
  125.     Say ""
  126. End
  127. Else Do
  128.     Say ""
  129.     Say "Module definition file "||DefinitionFile||" successfully modified"
  130.     Say ""
  131. End
  132. Return ReturnCode 
  133.  
  134. /*--------------------------------------------------------------------------------------*\
  135.  * Parse a C/C++ header file to test that the macros we build the BLDLEVEL information  *
  136.  * from (BLDLEVEL_VENDOR, BLDLEVEL_VERSION, BLDLEVEL_INFO) are defined.                 *
  137.  * Req:                                                                                 *
  138.  *      none                                                                            *
  139.  * Returns:                                                                             *
  140.  *      ReturnCode .... Error code (0 if no error)                                      *
  141. \*--------------------------------------------------------------------------------------*/
  142. ParseHeaderFile: 
  143.     LinesLeft=2
  144.                                         /* Read ahead 1st line */
  145.     CurrentLine=LineIn(HeaderFile, 1, 1)
  146.                                         /* Do while there are lines in the file */
  147.     Do While(LinesLeft>0)
  148.                                         /* Parse for constructs of the form:
  149.                                            #define BLDLEVEL_Macro "Value" Comment */
  150.                                         /* Kill that ... tabs */
  151.         CurrentLine=Translate(CurrentLine, ' ', X2C(9))
  152.         Parse Var CurrentLine Define Macro '"' Value '"' .
  153.         Parse Upper Var Define Define
  154.         Define=Space(Define, 0)
  155.         Parse Upper Var Macro Macro
  156.         Macro=Space(Macro, 0)
  157.                                         /* Test for the macros we expect */
  158.         If (Define="#DEFINE") Then Do
  159.             Select
  160.             When (Macro="BLDLEVEL_VENDOR") Then Do
  161.                 BldLevel_Vendor=Value
  162.             End
  163.             When (Macro="BLDLEVEL_VERSION") Then Do
  164.                 BldLevel_Version=Value
  165.             End
  166.             When (Macro="BLDLEVEL_INFO") Then Do
  167.                 BldLevel_Info=Value
  168.             End
  169.             Otherwise
  170.             End
  171.         End
  172.         CurrentLine=LineIn(HeaderFile)
  173.                                         /* As Lines() returns 0 after having read the last line
  174.                                            we have to ensure that this last line will be processed too */
  175.         If (Lines(HeaderFile)=0) Then
  176.             LinesLeft=LinesLeft-1
  177.     End
  178.     If (BldLevel_Vendor\="" & BldLevel_Version\="" & BldLevel_Info\="") Then
  179.         Return 0
  180.     Else
  181.         Return 10
  182.  
  183. /*--------------------------------------------------------------------------------------*\
  184.  * Parse a C/C++ module definition file to test if this file is used to build a OS/2    *
  185.  * EXE or DLL file and if it contains a DESCRIPTION line.                               *
  186.  * Req:                                                                                 *
  187.  *      none                                                                            *
  188.  * Returns:                                                                             *
  189.  *      ReturnCode .... Error code (0 if no error)                                      *
  190. \*--------------------------------------------------------------------------------------*/
  191. ParseDefinitionFile:
  192.                                         /* Read ahead 1st line */
  193.     Command=Stream(DefinitionFile, 'C', 'OPEN READ')
  194.     LinesLeft=2
  195.     CurrentLine=LineIn(DefinitionFile)
  196.                                         /* Do while there are lines in the file */
  197.     Do While(LinesLeft>0)
  198.                                         /* Parse for constructs of the form:
  199.                                            NAME/LIBRARY ModuleName Options */
  200.                                         /* Kill that ... tabs */
  201.         CurrentLine=Translate(CurrentLine, ' ', X2C(9))
  202.         Parse Var CurrentLine Statement Module Options
  203.         Parse Upper Var Statement Statement
  204.         Statement=Space(Statement, 0)
  205.         Module=Space(Module, 0)
  206.         If (Module\="") Then Do
  207.             If (Statement="NAME") Then 
  208.                 ModuleName=Module||".exe"
  209.             If (Statement="LIBRARY") Then
  210.                 ModuleName=Module||".dll"
  211.         End
  212.                                         /* See if there is a DESCRIPTION statement */
  213.         Parse Var CurrentLine Statement Options
  214.         Parse Upper Var Statement Statement
  215.         Statement=Space(Statement, 0)
  216.         If (Statement="DESCRIPTION") Then
  217.             DescriptionStatement=Options
  218.         CurrentLine=LineIn(DefinitionFile)
  219.                                         /* As Lines() returns 0 after having read the last line
  220.                                            we have to ensure that this last line will be processed too */
  221.         If (Lines(DefinitionFile)=0) Then
  222.             LinesLeft=LinesLeft-1
  223.     End
  224.                                         /* Close the stream */
  225.     Command=Stream(DefinitionFile, 'C', 'CLOSE')
  226.     If (ModuleName\="" & DescriptionStatement\="") Then
  227.         Return 0
  228.     Else
  229.         Return 20
  230.  
  231. /*--------------------------------------------------------------------------------------*\
  232.  * Parse a C/C++ module definition file to modify the DESCRIPTION statement into a form *
  233.  * that is readable by BLDLEVEL (the original gets discarded).                          *
  234.  * Req:                                                                                 *
  235.  *      none                                                                            *
  236.  * Returns:                                                                             *
  237.  *      ReturnCode .... Error code (0 if no error)                                      *
  238. \*--------------------------------------------------------------------------------------*/
  239. ModifyDefinitionFile:
  240.                                         /* Read and write ahead 1st line */
  241.     Command=Stream(DefinitionFile, 'C', 'OPEN WRITE')
  242.     If (Command="ERROR") Then 
  243.         Return 30
  244.     Command=Stream(DefinitionCopy, 'C', 'OPEN READ')
  245.     If (Command="ERROR") Then 
  246.         Return 31
  247.     LinesLeft=2
  248.     CurrentLine=LineIn(DefinitionCopy)
  249.                                         /* Do while there are lines in the file */
  250.     Do While(LinesLeft>0)
  251.                                         /* Parse for constructs of the form:
  252.                                            DESCRIPTION Options */
  253.                                         /* Kill that ... tabs */
  254.         CurrentLine=Translate(CurrentLine, ' ', X2C(9))
  255.         Parse Var CurrentLine Statement Options
  256.         Parse Upper Var Statement Statement
  257.         Statement=Space(Statement, 0)
  258.         If (Statement="DESCRIPTION") Then Do
  259.             Command=LineOut(DefinitionFile, Description)
  260.         End
  261.         Else Do
  262.             Command=LineOut(DefinitionFile, CurrentLine)
  263.         End
  264.         CurrentLine=LineIn(DefinitionCopy)
  265.                                         /* As Lines() returns 0 after having read the last line
  266.                                            we have to ensure that this last line will be processed too */
  267.         If (Lines(DefinitionCopy)=0) Then
  268.             LinesLeft=LinesLeft-1
  269.     End
  270.                                         /* Close the streams */
  271.     Command=Stream(DefinitionFile, 'C', 'CLOSE')
  272.     Command=Stream(DefinitionCopy, 'C', 'CLOSE')
  273.     Return 0
  274.  
  275. /*--------------------------------------------------------------------------------------*\
  276.  * Signal Handler that avoids interruption and just tells user that CTRL+BRK is not     *
  277.  * allowed currently.                                                                   *
  278.  * Req:                                                                                 *
  279.  *      none                                                                            *
  280.  * Returns:                                                                             *
  281.  *      none                                                                            *
  282. \*--------------------------------------------------------------------------------------*/
  283. SignalHandler:
  284.     Say "    CTRL+BRK currently disabled"
  285.     Return 0
  286.  
  287.