home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rspgen.zip / RSPGEN.CMD next >
OS/2 REXX Batch file  |  1994-07-25  |  10KB  |  232 lines

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