diff options
Diffstat (limited to 'cpp/src/slice2cpp/Main.cpp')
-rw-r--r-- | cpp/src/slice2cpp/Main.cpp | 77 |
1 files changed, 16 insertions, 61 deletions
diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index 298e9ef68fa..33aff2e96a1 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -12,8 +12,8 @@ // // ********************************************************************** +#include <Slice/Preprocessor.h> #include <Gen.h> -#include <fstream> using namespace std; using namespace Slice; @@ -44,7 +44,7 @@ usage(const char* n) int main(int argc, char* argv[]) { - string cpp("cpp"); + string cppArgs; vector<string> includePaths; string include; string output; @@ -60,8 +60,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()) @@ -77,8 +77,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) { @@ -212,74 +212,29 @@ main(int argc, char* argv[]) for(idx = 1 ; idx < argc ; ++idx) { - string base(argv[idx]); - 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; - return EXIT_FAILURE; - } - base.erase(pos); - - ifstream test(argv[idx]); - if(!test) - { - cerr << argv[0] << ": can't open `" << argv[idx] << "' for reading: " << strerror(errno) << endl; - return EXIT_FAILURE; - } - test.close(); - if(depend) { - string::size_type pos = base.rfind('/'); - if(pos != string::npos) - { - base.erase(0, pos + 1); - } - -#ifdef _WIN32 - // - // -MT is not supported by cygwin cpp so we just use the - // default. - // - string cmd = cpp + " -M " + argv[idx]; - FILE* cppHandle = _popen(cmd.c_str(), "w"); - _pclose(cppHandle); -#else - string cmd = cpp + " -M -MT " + base + ".cpp " + argv[idx]; - FILE* cppHandle = popen(cmd.c_str(), "w"); - pclose(cppHandle); -#endif + Preprocessor icecpp(argv[0], argv[idx], cppArgs); + icecpp.printMakefileDependencies(); } else { - string cmd = cpp + " " + argv[idx]; + Preprocessor icecpp(argv[0], argv[idx], cppArgs); + FILE* cppHandle = icecpp.preprocess(false); -#ifdef _WIN32 - FILE* cppHandle = _popen(cmd.c_str(), "r"); -#else - FILE* cppHandle = popen(cmd.c_str(), "r"); -#endif if(cppHandle == 0) { - cerr << argv[0] << ": can't run C++ preprocessor: " << strerror(errno) << endl; 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) { @@ -287,7 +242,7 @@ main(int argc, char* argv[]) } else { - Gen gen(argv[0], base, include, includePaths, dllExport, output, impl); + Gen gen(argv[0], icecpp.getBaseName(), include, includePaths, dllExport, output, impl); if(!gen) { unit->destroy(); |