home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bbmak.zip / BOBSMAKE.CMD next >
OS/2 REXX Batch file  |  1996-01-20  |  12KB  |  390 lines

  1. /* This REXX Procedure processes my own type of make file
  2.    because the NMAKE command is too screwed up
  3. */
  4.  
  5. SAY 'This is an unregistered copy of BobsMake.cmd'
  6.  
  7. Verbose = 'No'
  8. IterateUntilDone = 'No'
  9.  
  10.  /* These lines are inserted in the generated REXX Command */
  11.  
  12. REXXProcLine = '/* This REXX Proce, BMAKETMP.CMD, is used by BOBSMAKE */'
  13. PullArgLine = 'ARG TargetFile TargetDrive TargetPath TargetFullName TargetName TargetSuffix'
  14. REXXCommentLine = '/* End of Automatic REXX, Remainder From MakeFile */'
  15.  
  16.  /* Get the make file name */
  17. parse ARG MakeFile
  18.  
  19. If MakeFile = '' then Do
  20.     SAY 'Make File Name Not Specified'
  21.     SAY 'Using Default MakeFile name of "BobsMake.MAK"'
  22.     end
  23.  
  24. If LINES(MakeFile) = 0 then Do
  25.     SAY MakeFile ' Does Not Exist'
  26.     Return
  27.     end
  28.  
  29. /*  Get the currrent directory and drive information */
  30.  
  31. StartingDirectory = DIRECTORY()
  32.  
  33. If Verbose = 'Yes' then SAY 'Current Directory = ' StartingDirectory
  34.  
  35. StartingDrive = FILESPEC("drive",StartingDirectory)
  36.  
  37. If Verbose = 'Yes' then SAY 'Current Drive     = ' StartingDrive
  38.  
  39. /*  Load in all of the REXX System Support Functions */
  40.  
  41. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  42. Call SysLoadFuncs
  43.  
  44. IF RxFuncQuery('HLLAPI') THEN
  45.    CALL RxFuncAdd 'HLLAPI','SAAHLAPI','HLLAPISRV';
  46.  
  47. IF RxFuncQuery('SQLDBS') THEN
  48.    CALL RxFuncAdd 'SQLDBS','SQLAR','SQLDBS';
  49.  
  50. IF RxFuncQuery('SQLEXEC') THEN
  51.    CALL RxFuncAdd 'SQLEXEC','SQLAR','SQLEXEC';
  52.  
  53. If RxFuncQuery('SQLDBS') <> 0 then
  54.    rcy = RxFuncAdd( 'SQLDBS',  'DB2AR', 'SQLDBS'  )
  55.  
  56. If RxFuncQuery('SQLEXEC') <> 0 then
  57.    rcy = RxFuncAdd( 'SQLEXEC', 'DB2AR', 'SQLEXEC' )
  58.  
  59. SAY 'Rexx Functions Loaded'
  60.  
  61. TookAction = 'Starting'
  62. SetVar.0 = 0
  63. Pass = 0
  64. Do While (TookAction <> 'No')
  65.     Pass = Pass + 1
  66.     SAY 'Starting Pass ' Pass
  67.     TookAction = 'No'
  68.     Do while (LINES(MakeFile) = 1)
  69.         CurrentLine = LINEIN(MakeFile)
  70.         If Verbose = 'Yes' then SAY 'Processing Line = ' CurrentLine
  71.         PARSE UPPER VAR CurrentLine CommandName RemainderOfLine
  72.         If Verbose = 'Yes' then SAY 'CommandName = ' CommandName
  73.         If CommandName = 'SETDIR'  then Call SetAndGetDirectory
  74.           Else
  75.             If CommandName = 'IFCOND'  then Call ProcessIfCondition
  76.           Else
  77.             If CommandName = 'SETLIST' then Call ProcessSetList
  78.           Else
  79.             If WORDS(CurrentLine) > 0 then Do
  80.                 ExecutionLines = STRIP(CurrentLine)
  81.                 If Verbose = 'Yes' then SAY 'ExecutionLines = ' ExecutionLines
  82.                 INTERPRET ExecutionLines
  83.                 end
  84.  
  85.           If IterateUntilDone = 'No' then TookAction = 'No'
  86.  
  87.         End
  88.     rc = STREAM(MakeFile, 'C', 'CLOSE')
  89.     End
  90.  
  91. SAY 'Finished Passing The Make File'
  92.  
  93. ADDRESS CMD StartingDrive
  94. ADDRESS CMD 'CD ' StartingDirectory
  95. Return
  96.  
  97. SetAndGetDirectory:
  98.     If Verbose = 'Yes' then SAY 'Entered SetAndGetDirectory'
  99.  
  100. /* The format of this command is :
  101.  
  102.     "SETDIR = directoryname"
  103.  
  104.     Technically this command is not required because the
  105.     user can code their own drive and CD commands in the
  106.     makefile
  107.  
  108. */
  109.  
  110.  
  111.     If WORD(CurrentLine,2) <> '=' then Return
  112.     Directory = WORD(CurrentLine,3)
  113.     If LENGTH(Directory) = 0 then Return
  114.  
  115.     If SUBSTR(Directory, LENGTH(Directory), 1) ¬= '\' then Directory = Directory || '\'
  116.  
  117.     Drive    = FILESPEC("drive",Directory)
  118.     NewPath  = FILESPEC("path",Directory)
  119.  
  120.     If Verbose = 'Yes' then SAY 'NewPath = ' NewPath
  121.  
  122.     NewPath = SUBSTR(NewPath, 1, LENGTH(NewPath) - 1)
  123.     If Verbose = 'Yes' then SAY 'NewPath = ' NewPath
  124.  
  125.     ADDRESS CMD Drive
  126.     ADDRESS CMD 'CD ' NewPath
  127.     Return
  128.  
  129.  
  130. ProcessIfCondition:
  131.     If Verbose = 'Yes' then SAY 'Entered ProcessIfCondition'
  132.  
  133. /* The format of this command is :
  134.  
  135.     "IFCOND targetname < sourcename then DOCOND
  136.          your REXX commands
  137.          ENDCOND"
  138.  
  139.     Although the '<' and 'then DOCOND' are not explicitly parsed
  140.     they are required parameters. This is so that the command
  141.     can be enhanced later.
  142. */
  143.  
  144.     If Verbose = 'Yes' then SAY 'Number of words in line = ' WORDS(CurrentLine)
  145.     If WORDS(CurrentLine) < 4 then DO
  146.         If Verbose = 'Yes' then SAY 'Returning because there are less then 4 words'
  147.         Return
  148.         End
  149.  
  150.     DROP TargetFiles
  151.     DROP TargetFilesDates
  152.     DROP SourceFiles
  153.     DROP SourceFilesDates
  154.     
  155.     TargetFile = WORD(CurrentLine,2)
  156.     rc = SysFileTree(TargetFile, TargetFiles, 'FT' )
  157.  
  158.     If Verbose = 'Yes' then SAY 'Number of Target files = ' TargetFiles.0
  159.     TargetFilesDates.0 = TargetFiles.0
  160.     Do I = 1 to TargetFiles.0
  161.         If Verbose = 'Yes' then SAY 'TargetFiles.'||I|| ' = ' || TargetFiles.I
  162.         SourceFileWorkLine = TargetFiles.I
  163.         Call GetSourceFileCreationDate
  164.         TargetFilesDates.I = FileCreationDate
  165.         end
  166.  
  167.     TempSourceFile = WORD(CurrentLine, 4)
  168.     PARSE UPPER VAR TempSourceFile SourceFile SourceFileRemainder
  169.  
  170.     If Verbose = 'Yes' then SAY 'SourceFile = ' SourceFile
  171.  
  172. /* Check the SourceFile to see if it is a ListName */
  173.  
  174.     SourceFileCount = 0
  175.  
  176.     If Verbose = 'Yes' then SAY 'ListNames to review = ' SetVar.0
  177.  
  178.     If SetVar.0 > 0 then Do I = 1 to SetVar.0
  179.  
  180.         If Verbose = 'Yes' then SAY 'Checking for a match on ' WORD(SetVar.I, 1)
  181.  
  182.         If SourceFile = WORD(SetVar.I, 1) then Do
  183.  
  184.             SourceFileCount = WORD(SetVar.I, 2)
  185.             Do J = 1 to SourceFileCount
  186.  
  187.                 If Verbose = 'Yes' then SAY 'Adding file to end = ' WORD(SetVar.I, 2 + J)
  188.  
  189.                 SourceFileName.J = WORD(SetVar.I, 2 + J)
  190.                 End
  191.             If SourceFileCount > 0 then Leave
  192.             End
  193.         End
  194.       Else Do
  195.  
  196.         If Verbose = 'Yes' then SAY 'Processing Only 1 File Name'
  197.  
  198.         SourceFileCount = 1
  199.         SourceFileName.1 = SourceFile
  200.         End
  201.  
  202. /*
  203.    Now iterate through the list of names, retrieving the tree information
  204.    for each entry and building a 'SUPER' tree containing all of the files
  205. */
  206.  
  207.     SourceFiles.0 = 0
  208.     Do I = 1 to SourceFileCount
  209.         If Verbose = 'Yes' then SAY 'Getting the file tree for ' SourceFileName.I
  210.         rc = SysFileTree(SourceFileName.I, TempFiles, 'FT')
  211.         If Verbose = 'Yes' then SAY 'Found ' TempFiles.0 ' Files to check'
  212.         Do J = 1 to TempFiles.0
  213.             If Verbose = 'Yes' then SAY 'Adding ' TempFiles.J ' To SourceFiles'
  214.             SourceFiles.0 = SourceFiles.0 + 1
  215.             K = SourceFiles.0
  216.             SourceFiles.K = TempFiles.J
  217.             If Verbose = 'Yes' then SAY 'Number of Source Files = ' SourceFiles.0
  218.             End
  219.         End
  220.  
  221.     If Verbose = 'Yes' then SAY 'Number of Source files = ' SourceFiles.0
  222.     SourceFilesDates.0 = SourceFiles.0
  223.     Do I = 1 to SourceFiles.0
  224.         If Verbose = 'Yes' then SAY 'SourceFiles.'||I|| ' = ' || SourceFiles.I
  225.         SourceFileWorkLine = SourceFiles.I
  226.         Call GetSourceFileCreationDate
  227.         SourceFilesDates.I = FileCreationDate
  228.         end
  229.  
  230.     'DEL BMAKEF.CMD'
  231.  
  232.     rc = LINEOUT('BMAKEF.CMD', REXXProcLine)
  233.     rc = LINEOUT('BMAKEF.CMD', PullArgLine)
  234.     rc = LINEOUT('BMAKEF.CMD', REXXCommentLine)
  235.  
  236.     Continue = 'Yes'
  237.     Do While ((Continue = 'Yes') & (LINES(MakeFile) = 1))
  238.         IfLine = LINEIN(MakeFile)
  239.         PARSE UPPER VAR IfLine IfCommand IfRemainder
  240.         If IfCommand = 'ENDCOND' then Do
  241.             Continue = 'No'
  242.             Iterate
  243.             End
  244.           Else Do
  245.             If Verbose = 'Yes' then SAY 'IFCommand = '
  246.             rc = LINEOUT('BMAKEF.CMD', IfLine)
  247.             End
  248.         end
  249.  
  250.     rc = STREAM('BMAKEF.CMD','C','CLOSE')
  251.  
  252.  /*  Iterate through the TargetFiles and execute the users commands */
  253.  
  254.     Do I = 1 to TargetFiles.0
  255.         If Verbose = 'Yes' then SAY 'Processing Target File ' I ' file = ' TargetFiles.I
  256.         ActivateREXXProc = 'No'
  257.         Do J = 1 to SourceFiles.0
  258.             If Verbose = 'Yes' then SAY 'Checking Source File ' I ' file = ' SourceFiles.I
  259.             If Verbose = 'Yes' then SAY 'Target Date = ' TargetFilesDates.I 'Source Date = ' SourceFilesDates.J
  260.             If SourceFilesDates.J > TargetFilesDates.I then ActivateREXXProc = 'Yes'
  261.             end
  262.         If ActivateREXXProc = 'Yes' Then Do
  263.              TempTargetFile = WORD(TargetFiles.I, 4)
  264.              TempTargetDrive     = FILESPEC("drive", TempTargetFile)
  265.              TempTargetPath      = FILESPEC("path",  TempTargetFile)
  266.              TempTargetFullName  = FILESPEC("name",  TempTargetFile)
  267.              FirstPeriod = POS('.', TempTargetFullName)
  268.              TempTargetName = SUBSTR(TempTargetFullName, 1, FirstPeriod - 1)
  269.              TempTargetSuffix = SUBSTR(TempTargetFullName, FirstPeriod + 1, LENGTH(TempTargetFullName) - FirstPeriod)
  270.  
  271.              If Verbose = 'Yes' then SAY 'Target file parms = ' TempTargetFile TempTargetName TempTargetSuffix
  272.  
  273.             'CALL BMAKEF.CMD' TempTargetFile TempTargetDrive TempTargetPath TempTargetFullName TempTargetName TempTargetSuffix
  274.             End
  275.         end
  276.  
  277.     DROP TargetFiles
  278.     DROP TargetFilesDates
  279.     DROP SourceFiles
  280.     DROP SourceFilesDates
  281.     
  282.     Return
  283.  
  284.  
  285. ProcessSetList:
  286.     If Verbose = 'Yes' then SAY 'Entered ProcessSetList'
  287.  
  288.  
  289. /* The format of this command is :
  290.  
  291.     "SETLIST listname = (name1, name2, ..., namen)"
  292.  
  293.     Although the '='is not explicitly parsed it is a required
  294.     parameter. This is so that the command can be enhanced later.
  295.  
  296. */
  297.  
  298.     SetVar.0 = SetVar.0 + 1
  299.     NumberOfSetVars = SetVar.0
  300.  
  301. /*  take the command apart. First extract the list name, then extract the
  302.     names from the list. Combine them again in the following form:
  303.  
  304.     ListName NumberOfNames Name1 Name2 Name3 ... NameN
  305.  
  306.     Then place them into the setvar structure as one string.
  307. */
  308.  
  309.     WorkLine = STRIP(CurrentLine)
  310.  
  311. /* Remove the SETLIST and any trailing blanks */
  312.  
  313.     WorkLine = STRIP(SUBSTR(WorkLine, 9, LENGTH(WorkLine)-8))
  314.  
  315.     If Verbose = 'Yes' then SAY 'Stripped SETLIST Command = ' WorkLine
  316.  
  317. /* Find the End of the ListName by searching for the '=' */
  318.  
  319.     EqualPosition = POS('=', WorkLine)
  320.  
  321. /* Extract the ListName */
  322.  
  323.     WorkListName = STRIP(SUBSTR(WorkLine, 1, EqualPosition - 1))
  324.  
  325.     PARSE UPPER VAR WorkListName ListName LNRemainder
  326.  
  327.  
  328.     If Verbose = 'Yes' then SAY 'ListName = ' ListName
  329.  
  330. /* Point to the first character of the list of variables */
  331.  
  332.     WorkLine = STRIP(SUBSTR(WorkLine, EqualPosition + 1, LENGTH(WorkLine) - EqualPosition))
  333.  
  334. /* Look for a left paren. If one exists then process a list, if one does not exist
  335.    process a single variable
  336. */
  337.  
  338.     If Verbose = 'Yes' then SAY 'Name List = ' WorkLine
  339.  
  340.     If SUBSTR(WorkLine, 1, 1) = '(' then do
  341.  
  342. /*
  343.     Names must be separated by spaces, so if commas are being use
  344.     then replace them with spaces so that the parsing can be by word.
  345.     Also remove the parens.
  346. */
  347.  
  348.         WorkLine = SUBSTR(WorkLine, 2, LENGTH(WorkLine) - 2) /*remove the parens*/
  349.  
  350.         If Verbose = 'Yes' then SAY 'Name List without Parens = ' WorkLine
  351.  
  352.         CommaPosition = POS(',', WorkLine)                   /* remove the commas */
  353.         Do While (CommaPosition > 0)
  354.  
  355.             If Verbose = 'Yes' then SAY 'Comma Position = ' CommaPosition
  356.  
  357.             WorkLine = OVERLAY(' ', WorkLine, CommaPosition, 1)
  358.  
  359.             If Verbose = 'Yes' then SAY 'New Name List = ' WorkLine
  360.  
  361.             CommaPosition = POS(',', WorkLine)
  362.             End
  363.  
  364.         NumberOfNames = WORDS(WorkLine)
  365.         NameString = WorkLine
  366.  
  367.         End
  368.       Else Do
  369.         NumberOfNames = 1
  370.         NamesString = WORD(WorkLine, 1)
  371.         End
  372.  
  373.     If Verbose = 'Yes' then SAY 'Number Of Names = ' NumberOfNames
  374.     If Verbose = 'Yes' then SAY 'NameString = ' NameString
  375.  
  376.     SetVar.NumberOfSetVars = ListName NumberOfNames NameString
  377.  
  378.     If Verbose = 'Yes' then SAY 'Number of ListNames = ' SetVar.0
  379.     If Verbose = 'Yes' then SAY 'ListName string = ' SetVar.NumberOfSetVars
  380.  
  381.     Return
  382.  
  383. GetSourceFileCreationDate:
  384.     If Verbose = 'Yes' then Say 'Entered GetSourceFileCreationDate'
  385.  
  386.     FileCreationDate = WORD(SourceFileWorkLine, 1)
  387.  
  388.     Return
  389.  
  390.