A bit of code cleanup

This commit is contained in:
rdb 2010-04-09 13:24:02 +00:00
parent f6f0be4b1b
commit 35fa12e2a6

View File

@ -79,8 +79,7 @@ upcase_string(const string &str) {
} }
*/ */
int write_python_table_native(ostream &out) int write_python_table_native(ostream &out) {
{
out << "\n#include \"dtoolbase.h\"\n" out << "\n#include \"dtoolbase.h\"\n"
<< "#include \"interrogate_request.h\"\n\n" << "#include \"interrogate_request.h\"\n\n"
<< "#undef _POSIX_C_SOURCE\n" << "#undef _POSIX_C_SOURCE\n"
@ -88,57 +87,46 @@ int write_python_table_native(ostream &out)
int count = 0; int count = 0;
std::set<std::string > Libraries; std::set<std::string > Libraries;
// out << "extern \"C\" {\n"; // out << "extern \"C\" {\n";
// Walk through all of the Python functions. // Walk through all of the Python functions.
int num_functions = interrogate_number_of_functions(); int num_functions = interrogate_number_of_functions();
int fi; int fi;
for (fi = 0; fi < num_functions; fi++) for (fi = 0; fi < num_functions; fi++) {
{
FunctionIndex function_index = interrogate_get_function(fi); FunctionIndex function_index = interrogate_get_function(fi);
// Consider only those that belong in the module we asked for. // Consider only those that belong in the module we asked for.
if (interrogate_function_has_module_name(function_index) && if (interrogate_function_has_module_name(function_index) &&
module_name == interrogate_function_module_name(function_index)) module_name == interrogate_function_module_name(function_index)) {
{
// if it has a library name add it to set of libraries // if it has a library name add it to set of libraries
if(interrogate_function_has_library_name(function_index)) if(interrogate_function_has_library_name(function_index))
Libraries.insert(interrogate_function_library_name(function_index)); Libraries.insert(interrogate_function_library_name(function_index));
} }
} }
for(int ti = 0; ti < interrogate_number_of_types(); ti++) for(int ti = 0; ti < interrogate_number_of_types(); ti++) {
{
TypeIndex thetype = interrogate_get_type(ti); TypeIndex thetype = interrogate_get_type(ti);
if(interrogate_type_has_module_name(thetype) && module_name == interrogate_type_module_name(thetype)) if(interrogate_type_has_module_name(thetype) && module_name == interrogate_type_module_name(thetype)) {
{
if(interrogate_type_has_library_name(thetype)) if(interrogate_type_has_library_name(thetype))
Libraries.insert(interrogate_type_library_name(thetype)); Libraries.insert(interrogate_type_library_name(thetype));
} }
} }
std::set<std::string >::iterator ii; std::set<std::string >::iterator ii;
for(ii = Libraries.begin(); ii != Libraries.end(); ii++) for(ii = Libraries.begin(); ii != Libraries.end(); ii++) {
{
printf("Referencing Library %s\n",(*ii).c_str()); printf("Referencing Library %s\n",(*ii).c_str());
out << "extern LibrayDef "<< *ii << "_moddef ;\n"; out << "extern LibrayDef "<< *ii << "_moddef ;\n";
} }
out << "#ifdef _WIN32\n"
out << "#ifdef _WIN32\n"
<< "extern \"C\" __declspec(dllexport) void init" << library_name << "();\n" << "extern \"C\" __declspec(dllexport) void init" << library_name << "();\n"
<< "#else\n" << "#else\n"
<< "extern \"C\" void init" << library_name << "();\n" << "extern \"C\" void init" << library_name << "();\n"
<< "#endif\n\n" << "#endif\n\n"
<< "void init" << library_name << "() \n{\n"; << "void init" << library_name << "() \n{\n";
if (track_interpreter) { if (track_interpreter) {
out << " in_interpreter = 1;\n"; out << " in_interpreter = 1;\n";
} }
@ -156,11 +144,7 @@ int write_python_table_native(ostream &out)
return count; return count;
} }
int write_python_table(ostream &out) {
int write_python_table(ostream &out)
{
out << "\n#include \"dtoolbase.h\"\n" out << "\n#include \"dtoolbase.h\"\n"
<< "#include \"interrogate_request.h\"\n\n" << "#include \"interrogate_request.h\"\n\n"
<< "#undef _POSIX_C_SOURCE\n" << "#undef _POSIX_C_SOURCE\n"
@ -256,8 +240,7 @@ int write_python_table(ostream &out)
return count; return count;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[]) {
{
extern char *optarg; extern char *optarg;
extern int optind; extern int optind;
int flag; int flag;
@ -338,12 +321,10 @@ int main(int argc, char *argv[])
} }
// Now output the table. // Now output the table.
if (!output_code_filename.empty()) if (!output_code_filename.empty()) {
{
pofstream output_code; pofstream output_code;
if (!output_code_filename.open_write(output_code)) if (!output_code_filename.open_write(output_code)) {
{
nout << "Unable to write to " << output_code_filename << "\n"; nout << "Unable to write to " << output_code_filename << "\n";
} else { } else {