summaryrefslogtreecommitdiff
path: root/cpp/src/slice2xsd/Main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2xsd/Main.cpp')
-rw-r--r--cpp/src/slice2xsd/Main.cpp61
1 files changed, 16 insertions, 45 deletions
diff --git a/cpp/src/slice2xsd/Main.cpp b/cpp/src/slice2xsd/Main.cpp
index 6fe7e772f2e..90ef3dec10f 100644
--- a/cpp/src/slice2xsd/Main.cpp
+++ b/cpp/src/slice2xsd/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)
{
@@ -170,51 +170,22 @@ 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;
- unit->destroy();
- 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();
-
- string cmd = cpp + " " + argv[idx];
-#ifdef _WIN32
- FILE* cppHandle = _popen(cmd.c_str(), "r");
-#else
- FILE* cppHandle = popen(cmd.c_str(), "r");
-#endif
+ Preprocessor icecpp(argv[0], argv[idx], 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)
{
@@ -222,7 +193,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(!gen)
{
unit->destroy();