예제 #1
0
파일: tao_idl.cpp 프로젝트: INMarkus/ATCD
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_Argv_Type_Converter atc (argc, argv);
  try
    {
      if (0 != DRV_init (atc.get_argc (), atc.get_TCHAR_argv ()))
        {
          throw Bailout ();
        }

      // Parse arguments.
      DRV_parse_args (atc.get_argc (), atc.get_ASCII_argv ());

      // If a version message is requested, print it and exit cleanly.
      if (idl_global->compile_flags () & IDL_CF_VERSION)
        {
          DRV_version ();
          DRV_cleanup ();
          return 0;
        }

      // If a usage message is requested, print it and exit cleanly.
      if (idl_global->compile_flags () & IDL_CF_ONLY_USAGE)
        {
          DRV_usage ();
          DRV_cleanup ();
          return 0;
        }

      // If there are no input files, and we are not using the
      // directory recursion option, there's no sense going any further.
      if (0 == DRV_nfiles && 0 == idl_global->recursion_start ())
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("IDL: No input files\n")));

          throw Bailout ();
        }

      AST_Generator *gen = be_util::generator_init ();

      if (0 == gen)
        {
          ACE_ERROR ((
              LM_ERROR,
              ACE_TEXT ("IDL: DRV_generator_init() failed to create ")
              ACE_TEXT ("generator, exiting\n")
            ));

          throw Bailout ();
        }
      else
        {
          idl_global->set_gen (gen);
        }

      // Initialize AST and load predefined types.
      FE_populate ();

      // Does various things in various backends.
      BE_post_init (DRV_files, DRV_nfiles);

      FILE *output_file = 0;

      if (idl_global->multi_file_input ())
        {
          output_file =
            ACE_OS::fopen (idl_global->big_file_name (), "w");
        }

      for (DRV_file_index = 0;
           DRV_file_index < DRV_nfiles;
           ++DRV_file_index)
        {
          if (idl_global->multi_file_input ())
            {
              ACE_OS::fprintf (output_file,
                               "#include \"%s\"\n",
                               DRV_files[DRV_file_index]);
            }
          else
            {
              DRV_drive (DRV_files[DRV_file_index]);
            }
        }

      if (idl_global->multi_file_input ())
        {
          ACE_OS::fclose (output_file);
          DRV_drive (idl_global->big_file_name ());
          ACE_OS::unlink (idl_global->big_file_name ());
        }
    }
  catch (Bailout)
    {
      // Incrementing here may be redundant, but the error count
      // is the exit value, and we want to make sure it isn't 0
      // if there was in fact an error. If a non-zero value is
      // off by 1, it's not so important.
      idl_global->set_err_count (idl_global->err_count () + 1);
    }

  int retval = idl_global->err_count ();
  DRV_cleanup ();

  return retval;
}
예제 #2
0
파일: drv_main.cpp 프로젝트: xrl/opensplice
// IDL compiler main program. Logic as explained in comment at head of file.
int driver_main(int argc, char **argv)
{
    int ret = 0;

#if defined (_WIN32)
    char * cmdstr = DRV_param_copy (argc, argv);
#endif

    // Open front-end library
    DRV_FE_open ();

    // Initialize driver and global variables
    {
        DRV_init ();
    }

    // Open back-end library
    DRV_BE_open ();

    // Parse arguments
    DRV_parse_args (argc, argv);

    // If a version message is requested, print it and exit
    if (idl_global->compile_flags () & IDL_CF_VERSION)
    {
        DRV_version ();
    }
    else
    {
        // If a usage message is requested, give it and exit
        if (idl_global->compile_flags () & IDL_CF_ONLY_USAGE)
        {
            DRV_usage ();
        }
        else
        {
            // Fork off a process for each file to process. Fork only if
            // there is more than one file to process
            if (DRV_nfiles > 1)
            {
                // DRV_fork never returns
#if !defined (_WIN32)
                DRV_fork ();
#else

                char tmp_command[1024];

                for (int tmpcounter = 0; tmpcounter < DRV_nfiles; tmpcounter++)
                {
                    os_sprintf(tmp_command, "%s %s\0", cmdstr, DRV_files[tmpcounter]);

                    _flushall ();

                    if (system (tmp_command))
                    {
                        cerr << "system() failed, errno: " << errno << endl;
                    }
                }
#endif
            }
            else
            {
                // Do the one file we have to parse
                // Check if stdin and handle file name appropriately
                if (DRV_nfiles == 0)
                {
                    DRV_files[0] = "standard input";
                }

                DRV_file_index = 0;
                ret = DRV_drive (DRV_files[DRV_file_index]);
            }
        }
    }

    return ret;
}