home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fnb101.zip / fnfeed.cmd < prev    next >
OS/2 REXX Batch file  |  1999-06-28  |  4KB  |  125 lines

  1. extproc python -x %PYTHONHOME%\fnfeed.cmd
  2. #############################################################################
  3. # Copyright (C) DSTC Pty Ltd (ACN 052 372 577) 1997, 1998, 1999
  4. # All Rights Reserved.
  5. #
  6. # The software contained on this media is the property of the DSTC Pty
  7. # Ltd.  Use of this software is strictly in accordance with the
  8. # license agreement in the accompanying LICENSE.HTML file.  If your
  9. # distribution of this software does not contain a LICENSE.HTML file
  10. # then you have no rights to use this software in any manner and
  11. # should contact DSTC at the address below to determine an appropriate
  12. # licensing arrangement.
  13. #      DSTC Pty Ltd
  14. #      Level 7, GP South
  15. #      Staff House Road
  16. #      University of Queensland
  17. #      St Lucia, 4072
  18. #      Australia
  19. #      Tel: +61 7 3365 4310
  20. #      Fax: +61 7 3365 4311
  21. #      Email: enquiries@dstc.edu.au
  22. # This software is being provided "AS IS" without warranty of any
  23. # kind.  In no event shall DSTC Pty Ltd be liable for damage of any
  24. # kind arising out of or in connection with the use or performance of
  25. # this software.
  26. #
  27. # Project:      Distributed Environment
  28. # File:         $Source: /units/arch/src/Fnorb/script/RCS/fnfeed,v $
  29. # Version:      @(#)$RCSfile: fnfeed,v $ $Revision: 1.5 $
  30. #
  31. #############################################################################
  32. """ Parse IDL and feed the definitions into an Interface Repository. """
  33.  
  34.  
  35. # Standard/built-in modules.
  36. import commands, os, string, sys
  37.  
  38. # Fnorb modules.
  39. from Fnorb.orb    import CORBA
  40. from Fnorb.parser import IDLParser
  41. from Fnorb.script import cpp
  42.  
  43.  
  44. def main(argv):
  45.     """ Do it! """
  46.  
  47.     # Initialise the ORB.
  48.     orb = CORBA.ORB_init(argv, CORBA.ORB_ID)
  49.  
  50.     # Get a reference to the IFR.
  51.     ifr = orb.resolve_initial_references('InterfaceRepository')
  52.  
  53.     # We separate arguments for the pre-processor from IDL files.
  54.     cpp_flags = []
  55.     idl_files = []
  56.  
  57.     for arg in argv[1:]:
  58.     # CPP flags.
  59.     if arg[0] == '-':
  60.         cpp_flags.append(arg)
  61.  
  62.     # IDL files.
  63.     elif arg[-4:] == '.idl':
  64.         idl_files.append(arg)
  65.  
  66.     # Ignore anything else (including the spurious last argument '\n' on
  67.     # Windoows 95 ;^).
  68.     else:
  69.         pass
  70.  
  71.     # If no files were specified on the command line, then parse from stdin!
  72.     if len(idl_files) == 0:
  73.     result = main_interactive(ifr)
  74.  
  75.     else:
  76.     result = main_batch(ifr, cpp_flags, idl_files)
  77.  
  78.     return result
  79.  
  80.  
  81. def main_interactive(ifr):
  82.     """ Parse IDL from stdin! """
  83.  
  84.     # Create the parser.
  85.     parser = IDLParser.IDLParser()
  86.  
  87.     # Do the parsing!
  88.     print 'Enter IDL (Ctrl-D to finish)...\n'
  89.     (result, contents) = parser.parse(ifr, 'stdin', sys.stdin)
  90.  
  91.     return result
  92.  
  93.  
  94. def main_batch(ifr, cpp_flags, idl_files):
  95.     """ Parse IDL from files! """
  96.  
  97.     # Create the parser.
  98.     parser = IDLParser.IDLParser()
  99.  
  100.     # Parse each file.
  101.     for idl_file in idl_files:
  102.     # Format the command to run the C/C++ pre-processor.
  103.     cmd = cpp.COMMAND % (string.join(cpp_flags), idl_file)
  104.  
  105.     # Run the pre-processor and use its output as the lexer's input stream.
  106.     yyin = os.popen(cmd, 'r')
  107.  
  108.     # Do the parsing!
  109.     (result, contents) = parser.parse(ifr, idl_file, yyin)
  110.  
  111.     # Close the pipe.
  112.     yyin.close()
  113.  
  114.     return result
  115.  
  116. #############################################################################
  117.  
  118. if __name__ == '__main__':
  119.     # Do it!
  120.     sys.exit(main(sys.argv[1:]))
  121.  
  122. #############################################################################
  123.