From 6c8b1db065f4cb87d490e047a89e2cbad8a6d152 Mon Sep 17 00:00:00 2001 From: Benoit Foucher Date: Tue, 29 Oct 2002 17:36:01 +0000 Subject: Fixed the translators to use the icecpp C preprocessor. --- cpp/src/slice2docbook/Main.cpp | 55 ++++++++++-------------------------------- 1 file changed, 13 insertions(+), 42 deletions(-) (limited to 'cpp/src/slice2docbook/Main.cpp') diff --git a/cpp/src/slice2docbook/Main.cpp b/cpp/src/slice2docbook/Main.cpp index 7073be2d328..d16d7d3afc4 100644 --- a/cpp/src/slice2docbook/Main.cpp +++ b/cpp/src/slice2docbook/Main.cpp @@ -12,8 +12,8 @@ // // ********************************************************************** +#include #include -#include using namespace std; using namespace Slice; @@ -44,7 +44,7 @@ usage(const char* n) int main(int argc, char* argv[]) { - string cpp("cpp -C"); + string cppArgs; bool debug = false; bool ice = false; bool caseSensitive = false; @@ -57,8 +57,8 @@ main(int argc, char* argv[]) { if(strncmp(argv[idx], "-I", 2) == 0) { - cpp += ' '; - cpp += argv[idx]; + cppArgs += ' '; + cppArgs += argv[idx]; for(int i = idx ; i + 1 < argc ; ++i) { @@ -68,8 +68,8 @@ main(int argc, char* argv[]) } else if(strncmp(argv[idx], "-D", 2) == 0 || strncmp(argv[idx], "-U", 2) == 0) { - cpp += ' '; - cpp += argv[idx]; + cppArgs += ' '; + cppArgs += argv[idx]; for(int i = idx ; i + 1 < argc ; ++i) { @@ -187,51 +187,22 @@ main(int argc, char* argv[]) for(idx = 2 ; idx < argc ; ++idx) { - string file(argv[idx]); - string suffix; - string::size_type pos = file.rfind('.'); - if(pos != string::npos) - { - suffix = file.substr(pos); - transform(suffix.begin(), suffix.end(), suffix.begin(), ::tolower); - } - if(suffix != ".ice") - { - cerr << argv[0] << ": input files must end with `.ice'" << endl; - unit->destroy(); - return EXIT_FAILURE; - } + Preprocessor icecpp(argv[0], argv[idx], cppArgs); + FILE* cppHandle = icecpp.preprocess(true); - ifstream test(argv[idx]); - if(!test) + if(cppHandle == 0) { - cerr << argv[0] << ": can't open `" << argv[idx] << "' for reading: " << strerror(errno) << endl; unit->destroy(); return EXIT_FAILURE; } - test.close(); - - string cmd = cpp + " " + argv[idx]; -#ifdef _WIN32 - FILE* cppHandle = _popen(cmd.c_str(), "r"); -#else - FILE* cppHandle = popen(cmd.c_str(), "r"); -#endif - if(cppHandle == 0) + + status = unit->parse(cppHandle, debug); + + if(!icecpp.close()) { - cerr << argv[0] << ": can't run C++ preprocessor: " << strerror(errno) << endl; unit->destroy(); return EXIT_FAILURE; } - - status = unit->parse(cppHandle, debug); - -#ifdef _WIN32 - _pclose(cppHandle); -#else - pclose(cppHandle); -#endif - } if(status == EXIT_SUCCESS) -- cgit v1.2.3