home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PPIPFC.ZIP / PPIPFC.CMD next >
OS/2 REXX Batch file  |  1991-03-21  |  6KB  |  147 lines

  1. /*-- REXX ------------------------------------------------------------*/
  2. /*                                                                    */
  3. /* Module name: PPIPFC.CMP                                            */
  4. /*                                                                    */
  5. /* Function:    Takes as its primary input an ipf file with 'res=xxx' */
  6. /*              parameters on ':h' tags and replaces the 'xxx' parm   */
  7. /*              with the appropriate '#define' from the definitions   */
  8. /*              file.                                                 */
  9. /*                                                                    */
  10. /* Author:      W. David Ashley                                       */
  11. /*                                                                    */
  12. /* Date:        21 March 1991                                         */
  13. /*                                                                    */
  14. /* (C) W. David Ashley 1991                                           */
  15. /*                                                                    */
  16. /* Notes and Program Limitations:                                     */
  17. /*                                                                    */
  18. /*   1. All :h tags in the input file must start in column 1.         */
  19. /*                                                                    */
  20. /*   2. :h tags that do not contain res= parms are not modified.      */
  21. /*                                                                    */
  22. /*   3. The input and output files must not be the same. This is so   */
  23. /*      that the input file can be modified repeatedly if necessary.  */
  24. /*                                                                    */
  25. /*   4. The definitions file can contain text other than #define      */
  26. /*      statements, but the program could have problems creating      */
  27. /*      a REXX statement that can be properly interpreted from the    */
  28. /*      input. The best way to handle this problem is to create a     */
  29. /*      seperate .h that contains only help identifer #define         */
  30. /*      statements.                                                   */
  31. /*                                                                    */
  32. /*   5. It is possible for #define statements to define REXX variables*/
  33. /*      which conflict with this program's variables. A list of all   */
  34. /*      the known conflicts follows:                                  */
  35. /*                                                                    */
  36. /*        inname     outname     defname      notready                */
  37. /*        fileopen   text        define       rest                    */
  38. /*        statement  name        i            j                       */
  39. /*        k          id          value                                */
  40. /*                                                                    */
  41. /*      Do not #define these names or programm errors will result.    */
  42. /*                                                                    */
  43. /*                                                                    */
  44. /* Modifications:                                                     */
  45. /* --------  ---  --------------------------------------------------- */
  46. /* 03/21/91  WDA  Initial Release                                     */
  47. /*                                                                    */
  48. /*--------------------------------------------------------------------*/
  49.  
  50. if arg() = 0 | arg() > 1 then do
  51.   say 'Incorrect input parms.'
  52.   say 'Invocation example:'
  53.   say '   ppipfc infile.txt outfile.ipf deffile.h'
  54.   say
  55.   exit
  56.   end
  57.  
  58. parse arg inname outname defname
  59. if length(inname) = 0 | length(outname) = 0 | length(defname) = 0 then do
  60.   say 'Incorrect input parms.'
  61.   say 'Invocation example:'
  62.   say '   ppipfc infile.txt outfile.ipf deffile.h'
  63.   say
  64.   exit
  65.   end
  66.  
  67. if inname = outname then do
  68.   say 'Incorrect input parms.'
  69.   say 'Input and Output files cannot be the same.'
  70.   say 'Invocation example:'
  71.   say '   ppipfc infile.txt outfile.ipf deffile.h'
  72.   say
  73.   exit
  74.   end
  75.  
  76. say 'Input file:      ' inname
  77. say 'Output file:     ' outname
  78. say 'Definitions file:' defname
  79. say
  80.  
  81. /* read .h file and assign defined variables */
  82. call on notready
  83. fileopen = 1
  84. text = linein(defname)
  85. say 'Beginning parse of definitions file' defname'.'
  86. say
  87. do while fileopen
  88.    parse var text define rest
  89.    if define = '#define' then do
  90.       parse var rest name value rest
  91.       if rest = '' then do
  92.          statement = name || '=' || value /* create rexx statement */
  93.          say statement /* echo assignment */
  94.          interpret statement /* execute rexx statement */
  95.          end
  96.       end
  97.    text = linein(defname)
  98.    end
  99. call lineout defname /* close file */
  100. say
  101. say 'Parsing of the definitions file complete.'
  102. say
  103.  
  104. /* must delete the output file because REXX output files are not      */
  105. /* truncated on close and the output file will probably be smaller    */
  106. '@del' outname
  107.  
  108. /* read input file, replace res=values, and write text to output file */
  109. call lineout outname, , 1 /* open output file */
  110. fileopen = 1
  111. text = linein(inname)
  112. say 'Beginning parse of input file' inname'.'
  113. say
  114. do while fileopen
  115.    if length(text) > 8 then do
  116.       select
  117.          when translate(substr(text, 1, 2)) = ':H' then do
  118.             i = pos('res=', text) /* find beginning of clause */
  119.             if i > 0 then do
  120.                j = pos(' ', text, i) /* find possible end of clause */
  121.                k = pos('.', text, i) /* find possible end of clause */
  122.                if k < j then j = k /* find real end of clause */
  123.                if j <> 0 then do
  124.                   id = substr(text, i+4, j-i-4) /* get res identifier */
  125.                   interpret 'id='id /* get res value */
  126.                   /* substitute value for identifer */
  127.                   text = substr(text, 1, i+3) || id || substr(text, j)
  128.                   say text /* echo changed line */
  129.                   end
  130.                end
  131.             end
  132.          otherwise
  133.          end
  134.       end
  135.    call lineout outname, text
  136.    text = linein(inname)
  137.    end
  138. call lineout outname /* close file */
  139. call lineout inname  /* close file */
  140. say
  141. say 'Parsing of the input file complete.'
  142. exit
  143.  
  144. notready:
  145. fileopen = 0
  146. return
  147.