home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / rspg12.zip / RSPGEN.CMD next >
OS/2 REXX Batch file  |  1994-08-26  |  10KB  |  226 lines

  1. /*--------------------------------------------------------------------------*/
  2. /* RSPGEN.CMD                                              25th July 1994   */
  3. /*                                            Last update: 26th August 1994 */
  4. /*                                                                          */
  5. /* Winterthur Insurance, Switzerland, R. Schnyder                           */
  6. /*--------------------------------------------------------------------------*/
  7. /* This procedure creates a new response file using an already existing     */
  8. /* one.                                                                     */
  9. /* The entries in the source file which should be changed have to be marked */
  10. /* with keywords. A keyword can be any name with a leading and trailing %.  */
  11. /* If a keyword has been found in the source file it will be replaced with  */
  12. /* specific value from the ini file.                                        */
  13. /*                                                                          */
  14. /* The ini file contains variables and response file directories.           */
  15. /* The variables are placed in the VARS section and the response file       */
  16. /* to generate in the RSPFILES section.                                     */
  17. /*                                                                          */
  18. /* The target response files will be determined using the keyword TARGETRSP */
  19. /* from the ini file.                                                       */
  20. /*                                                                          */
  21. /* If the ini includes lines which begins with an * this lines will be      */
  22. /* ignored (Remarks!)                                                       */
  23. /*                                                                          */
  24. /*--------------------------------------------------------------------------*/
  25. /* RSPGEN Syntax: RSPGEN inifile                                            */
  26. /*                                                                          */
  27. /*--------------------------------------------------------------------------*/
  28. /* Inifile example:                                                         */
  29. /*                                                                          */
  30. /* [VARS]                                                                   */
  31. /* * This is a silly remark                                                 */
  32. /* TargetRSP = XYZ                                                          */
  33. /* TRAddress = 400000000000                                                 */
  34. /* [RSPFILES]                                                               */
  35. /* G:\CID\IMG\LAPS\RSPGEN.RSP                                               */
  36. /*                                                                          */
  37. /*--------------------------------------------------------------------------*/
  38. /* Generation example:                                                      */
  39. /* RSPGEN.RSP                Generation        XYZ.RSP                      */
  40. /*                                                                          */
  41. /* UPDATEMODE = 1           -> RSPGEN ->       UPDATEMODE = 1               */
  42. /* ADDRESS = %TRAddress%                       ADDRESS = 400000000000       */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. PARSE ARG IniFile .
  47.  
  48. /*--------------------------------------------------------------------------*/
  49. /* Variables                                                                */
  50. /*--------------------------------------------------------------------------*/
  51.  
  52. Version   = '1.2a'
  53. KeyWords  = 0                    /* Counter for keywords       */
  54. RSPFiles  = 0                    /* Counter for response files */
  55. Section   = ''                   /* Current section            */
  56. TargetRSP = ''                   /* Target response file name  */
  57.  
  58. /*--------------------------------------------------------------------------*/
  59. /* Copyright                                                                */
  60. /*--------------------------------------------------------------------------*/
  61.  
  62. say 'Response File Generator, Version' Version
  63. say '(C) 1994 Winterthur Insurance, R. Schnyder'
  64. say ''
  65.  
  66. /*--------------------------------------------------------------------------*/
  67. /* Check parameters                                                         */
  68. /*--------------------------------------------------------------------------*/
  69. if IniFile = '' then do
  70.   say 'Syntax: RSPGEN IniFile'
  71.   exit 1
  72. end
  73.  
  74. /*--------------------------------------------------------------------------*/
  75. /* Does the file exists?                                                    */
  76. /*--------------------------------------------------------------------------*/
  77. if stream(IniFile,'C','QUERY EXISTS') == '' then do
  78.   say 'Error: File' IniFile 'is missing!'
  79.   exit 1
  80. end
  81.  
  82. /*--------------------------------------------------------------------------*/
  83. /* Read the inifile                                                         */
  84. /*--------------------------------------------------------------------------*/
  85. say 'Reading' IniFile '...'
  86.  
  87. do while lines(IniFile)
  88.   IniLine = linein(IniFile)
  89.  
  90.   /**********************/
  91.   /* Determine section  */
  92.   /**********************/
  93.   select 
  94.     /* Remarks or empty line */
  95.     when left(IniLine,1) == '*' | strip(IniLine,'Trailing',' ') == '' then
  96.       nop
  97.     /* VARS */
  98.     when left(translate(IniLine),6) = '[VARS]' then 
  99.       Section = 'V'
  100.     /* RSPFILES */
  101.     when left(translate(IniLine),10) = '[RSPFILES]' then
  102.       Section = 'R'
  103.     otherwise
  104.       select
  105.         /****************************/
  106.         /* In section of variables? */
  107.         /****************************/
  108.         when Section == 'V' then do
  109.           /* Add the keyword to the array */
  110.           /* Element 0 = name             */
  111.           /* Element 1 = value            */
  112.           KeyWords = KeyWords +1
  113.           DelimPos = pos('=',IniLine)
  114.           if DelimPos == 0 then do
  115.             say 'Error: Unrecognized line "'IniLine'"'
  116.             exit 1
  117.           end
  118.           ArrKeyWord.KeyWords.0 = strip(substr(translate(IniLine),1,DelimPos -1),'Both',' ')
  119.           ArrKeyWord.KeyWords.1 = strip(substr(IniLine,DelimPos +1),'Both',' ')
  120.         end
  121.         /****************************/
  122.         /* In section of rsp files? */
  123.         /****************************/
  124.         when Section == 'R' then do
  125.           /* Add the response file to the array */
  126.           RSPFiles = RSPFiles +1
  127.           ArrRSPFile.RSPFiles = translate(strip(IniLine,'t',' '))
  128.           /* Append .RSP if necessary */
  129.           if pos('.',right(ArrRSPFile.RSPFiles,4)) == 0 then
  130.             ArrRSPFile.RSPFiles = ArrRSPFile.RSPFiles || '.RSP'
  131.         end
  132.         otherwise
  133.       end
  134.   end
  135. end
  136. /* Close ini file */
  137. call stream IniFile,'C','CLOSE'
  138.  
  139. /*--------------------------------------------------------------------------*/
  140. /* Check the ini entries                                                    */
  141. /*--------------------------------------------------------------------------*/
  142. if KeyWords == 0 then do
  143.   say 'Error: Missing key words!'
  144.   exit 1
  145. end
  146. if RSPFiles == 0 then do
  147.   say 'Error: Missing response file entries!'
  148.   exit 1
  149. end
  150.  
  151. /*--------------------------------------------------------------------------*/
  152. /* Determine target response file name                                      */
  153. /*--------------------------------------------------------------------------*/
  154. do i = 1 to KeyWords
  155.   /* Target response file? */
  156.   if ArrKeyWord.i.0 == 'TARGETRSP' then do
  157.     TargetRSP = ArrKeyWord.i.1
  158.     if right(TargetRSP,4) <> '.RSP' then
  159.       TargetRSP = TargetRSP || '.RSP'
  160.   end
  161. end
  162.  
  163. /*--------------------------------------------------------------------------*/
  164. /* Does the target response file name is supported?                         */
  165. /*--------------------------------------------------------------------------*/
  166. if TargetRSP == '' then do
  167.   say 'Error: Entry "TargetRSP" is missing!'
  168.   exit 1
  169. end
  170.  
  171. /*--------------------------------------------------------------------------*/
  172. /* Create response files                                                    */
  173. /*--------------------------------------------------------------------------*/
  174.  
  175. do i = 1 to RSPFiles
  176.   CurrSource = ArrRSPFile.i
  177.   CurrTarget = substr(ArrRSPFile.i,1,lastpos('\',ArrRSPFile.i)) || TargetRSP
  178.   '@if exist' CurrTarget 'del' CurrTarget
  179.  
  180.   say 'Reading response file' CurrSource'...'
  181.   if stream(CurrSource,'C','QUERY EXISTS') == '' then do
  182.     say 'Error: File' CurrSource 'is missing!'
  183.     exit 1
  184.   end
  185.  
  186.   say 'Generating response file' CurrTarget'...'
  187.   /********************************************/
  188.   /* Parse all the source response file lines */
  189.   /********************************************/
  190.   do while lines(CurrSource)
  191.     RSPLine    = linein(CurrSource)    /* Input           */
  192.     RSPUpLine  = translate(RSPLine)    /* Input uppercase */
  193.     NewRSPLine = RSPLine        /* Output          */
  194.  
  195.     /***********************************/
  196.     /* Check all the keywords per Line */
  197.     /* -> %KEYWORD% in response file   */
  198.     /***********************************/
  199.     do KeySearch = 1 to KeyWords
  200.       KeyPos = pos('%' || ArrKeyWord.KeySearch.0 || '%',RSPUpLine)
  201.       if KeyPos > 0 then do
  202.         NewRSPLine = substr(RSPLine,1,KeyPos -1)
  203.         NewRSPLine = NewRSPLine || ArrKeyWord.KeySearch.1
  204.         NewRSPLine = NewRSPLine || substr(RSPLine,KeyPos + length(ArrKeyWord.KeySearch.0) +2)
  205.         /* Only one keyword per line! */
  206.         leave
  207.       end
  208.     end
  209.     /***********************/
  210.     /* Write to the output */
  211.     /***********************/
  212.     if lineout(CurrTarget,NewRSPLine) <> 0 then do
  213.       say 'Error: Could not successfully write to' TargetRSP'!'
  214.       exit 1
  215.     end
  216.   end
  217.   /* Close files */
  218.   call stream CurrTarget,'C','CLOSE'
  219.   call stream CurrSource,'C','CLOSE'
  220. end
  221.  
  222. say ''
  223. say 'All response files have been created.'
  224.  
  225. exit 0
  226.