summaryrefslogtreecommitdiff
path: root/cpp/src/slice2freeze/Main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2freeze/Main.cpp')
-rw-r--r--cpp/src/slice2freeze/Main.cpp58
1 files changed, 16 insertions, 42 deletions
diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp
index cf538e1d0ce..c03730403d5 100644
--- a/cpp/src/slice2freeze/Main.cpp
+++ b/cpp/src/slice2freeze/Main.cpp
@@ -12,9 +12,9 @@
//
// **********************************************************************
+#include <Slice/Preprocessor.h>
#include <Slice/CPlusPlusUtil.h>
#include <IceUtil/OutputUtil.h>
-#include <fstream>
using namespace std;
using namespace IceUtil;
@@ -233,7 +233,7 @@ writeCodecs(const string& n, UnitPtr& unit, const Dict& dict, Output& H, Output&
int
main(int argc, char* argv[])
{
- string cpp("cpp");
+ string cppArgs;
vector<string> includePaths;
string include;
string dllExport;
@@ -249,8 +249,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())
@@ -266,8 +266,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)
{
@@ -471,51 +471,25 @@ main(int argc, char* argv[])
for(idx = 2 ; 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);
+ Preprocessor icecpp(argv[0], argv[idx], cppArgs);
- includes.push_back(base + ".h");
+ includes.push_back(icecpp.getBaseName() + ".h");
+
+ FILE* cppHandle = icecpp.preprocess(false);
- ifstream test(argv[idx]);
- if(!test)
- {
- cerr << argv[0] << ": can't open `" << argv[idx] << "' for reading: " << strerror(errno) << endl;
- 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)
{
- 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(!icecpp.close())
+ {
+ unit->destroy();
+ return EXIT_FAILURE;
+ }
}
if(status == EXIT_SUCCESS)