home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / vsoup128.zip / modifyemxh.cmd < prev    next >
OS/2 REXX Batch file  |  1996-11-12  |  3KB  |  117 lines

  1. /**/
  2.  
  3. if lines() = 0 then do
  4.    say 'Modify os2emx.h / os2.h for multiple inclusion  -  rg160996'
  5.    say ''
  6.    say 'usage:  modifyemxh < input > output'
  7.    say 'can be applied to os2.h & os2emx.h'
  8.    exit( 3 )
  9. end
  10.  
  11. trace('')
  12.  
  13. level       = 0
  14. labelCnt    = 0
  15. labelPrefix = '__HG'
  16. globalIf    = 0
  17. globalLab   = labelPrefix || 'global' || TIME('S')
  18. localIf     = 0
  19. do while lines() \= 0
  20.    orgtext = linein()
  21.    text = strip(orgtext)
  22. IF 0 THEN DO 
  23.    IF POS('RexxStart',text) \= 0 THEN DO  /****/
  24.        SAY 'RexxStart'
  25.        TRACE('i')
  26.    END
  27. end
  28.  
  29.    select
  30.  
  31.       when substr(text,1,3) = '#if' then do
  32.          SELECT
  33.  
  34.             when level = 0 then
  35.                rc = lineout( , '//' orgtext )    /* #if for multiple inclusion of header */
  36.  
  37.             when level = 1 then do
  38.                if pos('INCL_',text) \= 0 then do
  39.                   if globalIf then do
  40.                      rc = lineout( , '#endif /*' globalLab '*/' )
  41.                      rc = lineout( , '' )
  42.                      globalIf = 0
  43.                   end
  44.                   curLabel = labelPrefix || labelCnt
  45.                   labelCnt = labelCnt + 1
  46.                   rc = lineout( , '' )
  47.                   rc = lineout( , '#if !defined (' || curLabel || ')' )
  48.                   rc = lineout( , orgtext )
  49.                   rc = lineout( , '#define' curLabel )
  50.                   localIf = 1
  51.                END
  52.            ELSE DO
  53.            IF globalIf THEN DO
  54.                rc = lineout( , '#endif /*' globalLab '*/' )
  55.                rc = lineout( , '' )
  56.                globalIf = 0
  57.            END
  58.            rc = lineout( , '' )
  59.            rc = lineout( , orgtext );
  60.            localIf = 0
  61.            END
  62.         END
  63.  
  64.             otherwise
  65.                rc = lineout( , orgtext )
  66.          end
  67.          level = level + 1
  68.       end
  69.  
  70.       when substr(text,1,6) = '#endif' then do
  71.          level=level - 1
  72.  
  73.          select
  74.             when level = 0 then
  75.                rc = lineout( , '//' text )
  76.  
  77.             when level = 1 then do
  78.                rc = lineout( , orgtext )
  79.                if localIf then
  80.                   rc = lineout( , '#endif /*' curLabel '*/' )
  81.             end
  82.  
  83.             when level < 0 then do
  84.                say 'illegal nesting of #if/#endif in input file'
  85.                exit( 3 )
  86.             end
  87.  
  88.             otherwise
  89.                rc = lineout( , orgtext )
  90.          end
  91.       END
  92.  
  93.       WHEN (level = 1)  &  (SUBSTR(text,1,7) = '#pragma') THEN DO
  94.       IF globalIf THEN DO
  95.             rc = lineout( , '#endif /*' globalLab '*/' )
  96.             rc = lineout( , '' )
  97.             globalIf = 0
  98.          end
  99.          rc = lineout( , orgtext )
  100.       END
  101.  
  102.       when (level = 1)  &  \globalIf  &  (orgtext \= '') then do
  103.       rc = lineout( , '' )
  104.       rc = lineout( , '#if !defined (' || globalLab || ')' )
  105.       rc = lineout( , orgtext )
  106.       globalIf = 1
  107.       end
  108.  
  109.       otherwise
  110.          rc = lineout( , orgtext )
  111.  
  112.    end
  113. end
  114. rc = lineout( , '#define' globalLab )
  115.  
  116. exit( 0 )
  117.