Ejemplo n.º 1
0
/* Command-line argument handler for wrapper tools */
FileInfo *vtkParse_Main(int argc, char *argv[])
{
  int argi;
  int expected_files;
  FILE *ifile;
  FILE *hfile = 0;
  const char *cp;
  char *classname;
  size_t i;
  FileInfo *data;
  StringCache strings;
  int argn;
  char **args;

  /* set the command name for diagnostics */
  vtkParse_SetCommandName(parse_exename(argv[0]));

  /* expand any "@file" args */
  vtkParse_InitStringCache(&strings);
  parse_expand_args(&strings, argc, argv, &argn, &args);

  /* read the args into the static OptionInfo struct */
  argi = parse_check_options(argn, args, 0);

  /* was output file already specified by the "-o" option? */
  expected_files = (options.OutputFileName == NULL ? 2 : 1);

  /* verify number of args, print usage if not valid */
  if (argi == 0)
    {
    free(args);
    exit(0);
    }
  else if (argi < 0 || options.NumberOfFiles != expected_files)
    {
    parse_print_help(stderr, args[0], 0);
    exit(1);
    }

  /* open the input file */
  options.InputFileName = options.Files[0];

  if (!(ifile = fopen(options.InputFileName, "r")))
    {
    fprintf(stderr, "Error opening input file %s\n", options.InputFileName);
    exit(1);
    }

  if (options.OutputFileName == NULL &&
      options.NumberOfFiles > 1)
    {
    /* allow outfile to be given after infile, if "-o" option not used */
    options.OutputFileName = options.Files[1];
    fprintf(stderr, "Deprecated: specify output file with \"-o\".\n");
    }

  /* free the expanded args */
  free(args);

  /* open the hint file, if given on the command line */
  if (options.HintFileName && options.HintFileName[0] != '\0')
    {
    if (!(hfile = fopen(options.HintFileName, "r")))
      {
      fprintf(stderr, "Error opening hint file %s\n", options.HintFileName);
      fclose(ifile);
      exit(1);
      }
    }

  /* make sure than an output file was given on the command line */
  if (options.OutputFileName == NULL)
    {
    fprintf(stderr, "No output file was specified\n");
    fclose(ifile);
    if (hfile)
      {
      fclose(hfile);
      }
    exit(1);
    }

  /* if a hierarchy is was given, then BTX/ETX can be ignored */
  vtkParse_SetIgnoreBTX(0);
  if (options.HierarchyFileName)
    {
    vtkParse_SetIgnoreBTX(1);
    }

  /* parse the input file */
  data = vtkParse_ParseFile(options.InputFileName, ifile, stderr);

  if (!data)
    {
    exit(1);
    }

  /* fill in some blanks by using the hints file */
  if (hfile)
    {
    vtkParse_ReadHints(data, hfile, stderr);
    }

  if (!options.IsSpecialObject && data->MainClass)
    {
    /* mark class as abstract unless it has New() method */
    int nfunc = data->MainClass->NumberOfFunctions;
    int ifunc;
    for (ifunc = 0; ifunc < nfunc; ifunc++)
      {
      FunctionInfo *func = data->MainClass->Functions[ifunc];
      if (func && func->Access == VTK_ACCESS_PUBLIC &&
          func->Name && strcmp(func->Name, "New") == 0 &&
          func->NumberOfParameters == 0)
        {
        break;
        }
      }
    data->MainClass->IsAbstract = ((ifunc == nfunc) ? 1 : 0);
    }

  return data;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
  int argi;
  int has_options = 0;
  FILE *ifile;
  FILE *ofile;
  FILE *hfile = 0;
  const char *cp;
  char *classname;
  size_t i;
  FileInfo *data;

  argi = check_options(argc, argv);
  if (argi > 1 && argc - argi == 2)
    {
    has_options = 1;
    }
  else if (argi < 0 || argc < 3 || argc > 5)
    {
    fprintf(stderr,
            "Usage: %s [options] input_file output_file\n"
            "  --concrete      force concrete class\n"
            "  --abstract      force abstract class\n"
            "  --vtkobject     vtkObjectBase-derived class\n"
            "  --special       non-vtkObjectBase class\n"
            "  --hints <file>  hints file\n"
            "  --types <file>  type hierarchy file\n"
            "  -I <dir>        add an include directory\n"
            "  -D <macro>      define a preprocessor macro\n",
            argv[0]);
    exit(1);
    }

  options.InputFileName = argv[argi++];

  if (!(ifile = fopen(options.InputFileName, "r")))
    {
    fprintf(stderr,"Error opening input file %s\n", options.InputFileName);
    exit(1);
    }

  if (!has_options)
    {
    if (argc == 5)
      {
      options.HintFileName = argv[argi++];
      }
    if (argc >= 4)
      {
      options.IsConcrete = atoi(argv[argi++]);
      options.IsAbstract = !options.IsConcrete;
      }
    }

  if (options.HintFileName && options.HintFileName[0] != '\0')
    {
    if (!(hfile = fopen(options.HintFileName, "r")))
      {
      fprintf(stderr, "Error opening hint file %s\n", options.HintFileName);
      fclose(ifile);
      exit(1);
      }
    }

  options.OutputFileName = argv[argi++];
  ofile = fopen(options.OutputFileName, "w");

  if (!ofile)
    {
    fprintf(stderr, "Error opening output file %s\n", options.OutputFileName);
    fclose(ifile);
    if (hfile)
      {
      fclose(hfile);
      }
    exit(1);
    }

  if (options.IsConcrete)
    {
    cp = options.InputFileName;
    i = strlen(cp);
    classname = (char *)malloc(i+1);
    while (i > 0 &&
           cp[i-1] != '/' && cp[i-1] != '\\' && cp[i-1] != ':') { i--; }
    strcpy(classname, &cp[i]);
    i = 0;
    while (classname[i] != '\0' && classname[i] != '.') { i++; }
    classname[i] = '\0';

    vtkParse_SetClassProperty(classname, "concrete");
    }

  vtkParse_SetIgnoreBTX(0);
  if (options.HierarchyFileName)
    {
    vtkParse_SetIgnoreBTX(1);
    }

  data = vtkParse_ParseFile(options.InputFileName, ifile, stderr);

  if (!data)
    {
    fclose(ifile);
    fclose(ofile);
    if (hfile)
      {
      fclose(hfile);
      }
    exit(1);
    }

  if (hfile)
    {
    vtkParse_ReadHints(data, hfile, stderr);
    }

  if (options.IsConcrete && data->MainClass)
    {
    data->MainClass->IsAbstract = 0;
    }
  else if (options.IsAbstract && data->MainClass)
    {
    data->MainClass->IsAbstract = 1;
    }

  vtkParseOutput(ofile, data);

  fclose(ofile);

  vtkParse_Free(data);

  return 0;
}