Commit 79307d76 authored by David Gobbi's avatar David Gobbi Committed by Marcus D. Hanwell
Browse files

ENH: Add a --special option to vtkParse, change calling convention

The old calling convention for vtkParse still works, but the new
convention is as follows:

vtkWrapPython [options] input_file output_file\n"
options:
  --concrete      concrete class (default)
  --abstract      abstract class
  --vtkobject     vtkObjectBase-derived class (default)
  --special       non-vtkObjectBase class
  --hints <file>  hints file
parent 7da8adeb
...@@ -60,11 +60,18 @@ MACRO(VTK_WRAP_PYTHON3 TARGET SRC_LIST_NAME SOURCES) ...@@ -60,11 +60,18 @@ MACRO(VTK_WRAP_PYTHON3 TARGET SRC_LIST_NAME SOURCES)
# is it abstract? # is it abstract?
GET_SOURCE_FILE_PROPERTY(TMP_ABSTRACT ${FILE} ABSTRACT) GET_SOURCE_FILE_PROPERTY(TMP_ABSTRACT ${FILE} ABSTRACT)
IF (TMP_ABSTRACT) IF (TMP_ABSTRACT)
SET(TMP_CONCRETE 0) SET(TMP_CONCRETE "--abstract")
ELSE (TMP_ABSTRACT) ELSE (TMP_ABSTRACT)
SET(TMP_CONCRETE 1) SET(TMP_CONCRETE "--concrete")
ENDIF (TMP_ABSTRACT) ENDIF (TMP_ABSTRACT)
# is it special?
IF (TMP_WRAP_SPECIAL)
SET(TMP_SPECIAL "--special")
ELSE (TMP_WRAP_SPECIAL)
SET(TMP_SPECIAL "--vtkobject")
ENDIF (TMP_WRAP_SPECIAL)
# add the info to the init file # add the info to the init file
SET(VTK_WRAPPER_INIT_DATA SET(VTK_WRAPPER_INIT_DATA
"${VTK_WRAPPER_INIT_DATA}\n${TMP_FILENAME}") "${VTK_WRAPPER_INIT_DATA}\n${TMP_FILENAME}")
...@@ -79,9 +86,10 @@ MACRO(VTK_WRAP_PYTHON3 TARGET SRC_LIST_NAME SOURCES) ...@@ -79,9 +86,10 @@ MACRO(VTK_WRAP_PYTHON3 TARGET SRC_LIST_NAME SOURCES)
DEPENDS ${VTK_WRAP_PYTHON_EXE} ${VTK_WRAP_HINTS} ${TMP_INPUT} DEPENDS ${VTK_WRAP_PYTHON_EXE} ${VTK_WRAP_HINTS} ${TMP_INPUT}
COMMAND ${VTK_WRAP_PYTHON_EXE} COMMAND ${VTK_WRAP_PYTHON_EXE}
ARGS ARGS
"${quote}${TMP_INPUT}${quote}"
"${quote}${VTK_WRAP_HINTS}${quote}"
${TMP_CONCRETE} ${TMP_CONCRETE}
${TMP_SPECIAL}
"--hints" "${quote}${VTK_WRAP_HINTS}${quote}"
"${quote}${TMP_INPUT}${quote}"
"${quote}${CMAKE_CURRENT_BINARY_DIR}/${TMP_FILENAME}Python.cxx${quote}" "${quote}${CMAKE_CURRENT_BINARY_DIR}/${TMP_FILENAME}Python.cxx${quote}"
COMMENT "Python Wrapping - generating ${TMP_FILENAME}Python.cxx" COMMENT "Python Wrapping - generating ${TMP_FILENAME}Python.cxx"
${verbatim} ${verbatim}
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
int HasDelete; int HasDelete;
int IsAbstract; int IsAbstract;
int IsConcrete; int IsConcrete;
int IsVTKObject;
char *ClassName; char *ClassName;
char *FileName; char *FileName;
char *OutputFileName; char *OutputFileName;
......
This diff is collapsed.
...@@ -117,6 +117,7 @@ FileInfo data; ...@@ -117,6 +117,7 @@ FileInfo data;
FunctionInfo throwAwayFunction; FunctionInfo throwAwayFunction;
FunctionInfo *currentFunction; FunctionInfo *currentFunction;
char *hintFileName;
FILE *fhint; FILE *fhint;
char temps[2048]; char temps[2048];
int in_public; int in_public;
...@@ -1960,34 +1961,86 @@ void outputGetVectorMacro( ...@@ -1960,34 +1961,86 @@ void outputGetVectorMacro(
extern void vtkParseOutput(FILE *,FileInfo *); extern void vtkParseOutput(FILE *,FileInfo *);
int main(int argc,char *argv[]) int check_options(int argc, char *argv[])
{
int i;
data.IsConcrete = 1;
data.IsVTKObject = 1;
hintFileName = 0;
for (i = 1; i < argc && argv[i][0] == '-'; i++)
{
if (strcmp(argv[i], "--concrete") == 0)
{
data.IsConcrete = 1;
}
else if (strcmp(argv[i], "--abstract") == 0)
{
data.IsConcrete = 0;
}
else if (strcmp(argv[i], "--vtkobject") == 0)
{
data.IsVTKObject = 1;
}
else if (strcmp(argv[i], "--special") == 0)
{
data.IsVTKObject = 0;
}
else if (strcmp(argv[i], "--hints") == 0)
{
i++;
if (i >= argc || argv[i][0] == '-')
{
return -1;
}
hintFileName = argv[i];
}
}
return i;
}
int main(int argc, char *argv[])
{ {
int i, j; int i, j;
int argi;
int has_options = 0;
FILE *fin; FILE *fin;
int ret; int ret;
FILE *fout; FILE *fout;
if (argc < 4 || argc > 5) argi = check_options(argc, argv);
if (argi > 1 && argc - argi == 2)
{ {
fprintf(stderr, has_options = 1;
"Usage: %s input_file <hint_file> is_concrete output_file\n",argv[0]);
exit(1);
} }
else if (argi < 0 || argc < 4 || argc > 5)
if (!(fin = fopen(argv[1],"r")))
{ {
fprintf(stderr,"Error opening input file %s\n",argv[1]); fprintf(stderr,
"Usage: %s [options] input_file output_file\n"
" --concrete concrete class (default)\n"
" --abstract abstract class\n"
" --vtkobject vtkObjectBase-derived class (default)\n"
" --special non-vtkObjectBase class\n"
" --hints <file> hints file\n",
argv[0]);
exit(1); exit(1);
} }
fhint = 0; data.FileName = argv[argi++];
data.FileName = argv[1];
data.NameComment = NULL; data.NameComment = NULL;
data.Description = NULL; data.Description = NULL;
data.Caveats = NULL; data.Caveats = NULL;
data.SeeAlso = NULL; data.SeeAlso = NULL;
CommentState = 0; CommentState = 0;
if (!(fin = fopen(data.FileName, "r")))
{
fprintf(stderr,"Error opening input file %s\n", data.FileName);
exit(1);
}
/* The class name should be the file name */ /* The class name should be the file name */
i = strlen(data.FileName); i = strlen(data.FileName);
j = i; j = i;
...@@ -2013,18 +2066,19 @@ int main(int argc,char *argv[]) ...@@ -2013,18 +2066,19 @@ int main(int argc,char *argv[])
currentFunction = &throwAwayFunction; currentFunction = &throwAwayFunction;
if (argc == 5) if (!has_options)
{ {
if (!(fhint = fopen(argv[2],"r"))) if (argc == 5)
{ {
fprintf(stderr,"Error opening hint file %s\n",argv[2]); hintFileName = argv[argi++];
exit(1);
} }
data.IsConcrete = atoi(argv[3]); data.IsConcrete = atoi(argv[argi++]);
} }
else
if (!(fhint = fopen(hintFileName, "r")))
{ {
data.IsConcrete = atoi(argv[2]); fprintf(stderr, "Error opening hint file %s\n", hintFileName);
exit(1);
} }
yyin = fin; yyin = fin;
...@@ -2033,29 +2087,22 @@ int main(int argc,char *argv[]) ...@@ -2033,29 +2087,22 @@ int main(int argc,char *argv[])
if (ret) if (ret)
{ {
fprintf(stdout, fprintf(stdout,
"*** SYNTAX ERROR found in parsing the header file %s before line %d ***\n", "*** SYNTAX ERROR found in parsing the header file %s "
argv[1], yylineno); "before line %d ***\n",
data.FileName, yylineno);
return ret; return ret;
} }
if (argc == 5) data.OutputFileName = argv[argi++];
{ fout = fopen(data.OutputFileName, "w");
fout = fopen(argv[4],"w");
data.OutputFileName = argv[4];
}
else
{
fout = fopen(argv[3],"w");
data.OutputFileName = argv[3];
}
if (!fout) if (!fout)
{ {
fprintf(stderr,"Error opening output file %s\n",argv[3]); fprintf(stderr, "Error opening output file %s\n", data.OutputFileName);
exit(1); exit(1);
} }
vtkParseOutput(fout,&data); vtkParseOutput(fout, &data);
fclose (fout); fclose(fout);
return 0; return 0;
} }
......
...@@ -3223,11 +3223,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data) ...@@ -3223,11 +3223,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
data->ClassName); data->ClassName);
/* is this isn't a vtkObjectBase-derived object, then it is special */ /* is this isn't a vtkObjectBase-derived object, then it is special */
if (strcmp(data->ClassName,"vtkObjectBase") != 0 && is_vtkobject = data->IsVTKObject;
data->NumberOfSuperClasses == 0)
{
is_vtkobject = 0;
}
/* add sstream header for special objects and vtkObjectBase*/ /* add sstream header for special objects and vtkObjectBase*/
if (strcmp(data->ClassName, "vtkObjectBase") == 0 || if (strcmp(data->ClassName, "vtkObjectBase") == 0 ||
...@@ -3258,14 +3254,11 @@ void vtkParseOutput(FILE *fp, FileInfo *data) ...@@ -3258,14 +3254,11 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
} }
/* prototype for the docstring function */ /* prototype for the docstring function */
if (data->NumberOfSuperClasses || !data->IsAbstract)
{
fprintf(fp, fprintf(fp,
"\n" "\n"
"static const char **%sDoc();\n" "static const char **%sDoc();\n"
"\n", "\n",
data->ClassName); data->ClassName);
}
/* check for New() function */ /* check for New() function */
for (i = 0; i < data->NumberOfFunctions; i++) for (i = 0; i < data->NumberOfFunctions; i++)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment