diff options
Diffstat (limited to 'cpp/src/slice2wsdl/Main.cpp')
-rw-r--r-- | cpp/src/slice2wsdl/Main.cpp | 59 |
1 files changed, 15 insertions, 44 deletions
diff --git a/cpp/src/slice2wsdl/Main.cpp b/cpp/src/slice2wsdl/Main.cpp index 0277edec144..825315b6c50 100644 --- a/cpp/src/slice2wsdl/Main.cpp +++ b/cpp/src/slice2wsdl/Main.cpp @@ -12,8 +12,8 @@ // // ********************************************************************** +#include <Slice/Preprocessor.h> #include <Gen.h> -#include <fstream> using namespace std; using namespace Slice; @@ -39,7 +39,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; @@ -52,8 +52,8 @@ main(int argc, char* argv[]) { if(strncmp(argv[idx], "-I", 2) == 0) { - cpp += ' '; - cpp += argv[idx]; + cppArgs += ' '; + cppArgs += argv[idx]; string path = argv[idx] + 2; if(path.length()) @@ -69,8 +69,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) { @@ -169,51 +169,22 @@ main(int argc, char* argv[]) int status = EXIT_SUCCESS; - string base(sourceFile); - string suffix; - string::size_type pos = base.rfind('.'); - if(pos != string::npos) - { - suffix = base.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; - } - base.erase(pos); - - ifstream test(sourceFile.c_str()); - if(!test) - { - cerr << argv[0] << ": can't open `" << sourceFile << "' for reading: " << strerror(errno) << endl; - return EXIT_FAILURE; - } - test.close(); - - string cmd = cpp + " " + sourceFile; -#ifdef _WIN32 - FILE* cppHandle = _popen(cmd.c_str(), "r"); -#else - FILE* cppHandle = popen(cmd.c_str(), "r"); -#endif + Preprocessor icecpp(argv[0], sourceFile, cppArgs); + FILE* cppHandle = icecpp.preprocess(true); + if(cppHandle == 0) { - cerr << argv[0] << ": can't run C++ preprocessor: " << strerror(errno) << endl; - unit->destroy(); return EXIT_FAILURE; } UnitPtr unit = Unit::createUnit(false, false, ice, caseSensitive); int parseStatus = unit->parse(cppHandle, debug); -#ifdef _WIN32 - _pclose(cppHandle); -#else - pclose(cppHandle); -#endif + if(!icecpp.close()) + { + unit->destroy(); + return EXIT_FAILURE; + } if(parseStatus == EXIT_FAILURE) { @@ -221,7 +192,7 @@ main(int argc, char* argv[]) } else { - Gen gen(argv[0], base, include, includePaths, output); + Gen gen(argv[0], icecpp.getBaseName(), include, includePaths, output); if(argc > 2) { |