1 /*=========================================================================
3 Program: Visualization Toolkit
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
14 =========================================================================*/
18 This file provides a unified front-end for the wrapper generators.
19 It contains the main() function and argument parsing, and calls
20 the code that parses the header file.
25 #include "vtkParseMain.h"
26 #include "vtkParseInternal.h"
27 #include "vtkConfigure.h" // VTK_VERSION
33 /* This is the struct that contains the options */
36 /* Flags for --help and --version */
37 int vtk_parse_help = 0;
38 int vtk_parse_version = 0;
40 /* This method provides the back-end for the generators */
41 extern void vtkParseOutput(FILE *, FileInfo *);
43 /* Check the options */
44 static int check_options(int argc, char *argv[])
49 options.InputFileName = NULL;
50 options.OutputFileName = NULL;
51 options.IsAbstract = 0;
52 options.IsConcrete = 0;
53 options.IsVTKObject = 0;
54 options.IsSpecialObject = 0;
55 options.HierarchyFileName = 0;
56 options.HintFileName = 0;
58 for (i = 1; i < argc && argv[i][0] == '-'; i++)
60 if (strcmp(argv[i], "--concrete") == 0)
62 options.IsConcrete = 1;
64 else if (strcmp(argv[i], "--abstract") == 0)
66 options.IsAbstract = 1;
68 else if (strcmp(argv[i], "--vtkobject") == 0)
70 options.IsVTKObject = 1;
72 else if (strcmp(argv[i], "--special") == 0)
74 options.IsSpecialObject = 1;
76 else if (strcmp(argv[i], "--hints") == 0)
79 if (i >= argc || argv[i][0] == '-')
83 options.HintFileName = argv[i];
85 else if (strcmp(argv[i], "--types") == 0)
88 if (i >= argc || argv[i][0] == '-')
92 options.HierarchyFileName = argv[i];
94 else if (strcmp(argv[i], "-I") == 0)
97 if (i >= argc || argv[i][0] == '-')
101 vtkParse_IncludeDirectory(argv[i]);
103 else if (strcmp(argv[i], "-D") == 0)
107 if (i >= argc || argv[i][0] == '-')
111 while (argv[i][j] != '\0' && argv[i][j] != '=') { j++; }
112 if (argv[i][j] == '=') { j++; }
113 vtkParse_DefineMacro(argv[i], &argv[i][j]);
115 else if (strcmp(argv[i], "-U") == 0)
118 if (i >= argc || argv[i][0] == '-')
122 vtkParse_UndefineMacro(argv[i]);
124 else if (strcmp(argv[i], "--help") == 0)
128 else if (strcmp(argv[i], "--version") == 0)
130 vtk_parse_version = 1;
137 /* Return a pointer to the static OptionInfo struct */
138 OptionInfo *vtkParse_GetCommandLineOptions()
143 static void vtk_parse_print_help(FILE *stream, const char *cmd)
146 "Usage: %s [options] input_file output_file\n"
147 " --help print this help message\n"
148 " --version print the VTK version\n"
149 " --concrete force concrete class\n"
150 " --abstract force abstract class\n"
151 " --vtkobject vtkObjectBase-derived class\n"
152 " --special non-vtkObjectBase class\n"
153 " --hints <file> the hints file to use\n"
154 " --types <file> the type hierarchy file to use\n"
155 " -I <dir> add an include directory\n"
156 " -D <macro> define a preprocessor macro\n"
157 " -U <macro> undefine a preprocessor macro\n",
161 int main(int argc, char *argv[])
173 argi = check_options(argc, argv);
174 if (argi > 1 && argc - argi == 2)
178 else if (argi < 0 || argc > 5 ||
179 (argc < 3 && !vtk_parse_help && !vtk_parse_version))
181 vtk_parse_print_help(stderr, argv[0]);
185 if (vtk_parse_version)
187 const char *ver = VTK_VERSION;
188 const char *exename = argv[0];
189 /* remove directory part of exe name */
190 for (exename += strlen(exename); exename > argv[0]; --exename)
192 char pc = *(exename - 1);
193 if (pc == ':' || pc == '/' || pc == '\\')
198 fprintf(stdout, "%s %s\n", exename, ver);
203 vtk_parse_print_help(stdout, argv[0]);
207 options.InputFileName = argv[argi++];
209 ifile = fopen(options.InputFileName, "r");
212 fprintf(stderr,"Error opening input file %s\n", options.InputFileName);
220 options.HintFileName = argv[argi++];
224 options.IsConcrete = atoi(argv[argi++]);
225 options.IsAbstract = !options.IsConcrete;
229 if (options.HintFileName && options.HintFileName[0] != '\0')
231 hfile = fopen(options.HintFileName, "r");
234 fprintf(stderr, "Error opening hint file %s\n", options.HintFileName);
240 options.OutputFileName = argv[argi++];
241 ofile = fopen(options.OutputFileName, "w");
245 fprintf(stderr, "Error opening output file %s\n", options.OutputFileName);
254 if (options.IsConcrete)
256 cp = options.InputFileName;
258 classname = (char *)malloc(i+1);
260 cp[i-1] != '/' && cp[i-1] != '\\' && cp[i-1] != ':') { i--; }
261 strcpy(classname, &cp[i]);
263 while (classname[i] != '\0' && classname[i] != '.') { i++; }
266 vtkParse_SetClassProperty(classname, "concrete");
269 vtkParse_SetIgnoreBTX(0);
270 if (options.HierarchyFileName)
272 vtkParse_SetIgnoreBTX(1);
275 data = vtkParse_ParseFile(options.InputFileName, ifile, stderr);
290 vtkParse_ReadHints(data, hfile, stderr);
293 if (options.IsConcrete && data->MainClass)
295 data->MainClass->IsAbstract = 0;
297 else if (options.IsAbstract && data->MainClass)
299 data->MainClass->IsAbstract = 1;
302 vtkParseOutput(ofile, data);