diff options
author | Benoit Foucher <benoit@zeroc.com> | 2002-10-29 17:36:01 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2002-10-29 17:36:01 +0000 |
commit | 6c8b1db065f4cb87d490e047a89e2cbad8a6d152 (patch) | |
tree | df2bebe0fbadb2eb3b03cc6fe61242f2da30f111 /cpp | |
parent | removed AbortException from IcePatch. Fixed exception cleanup code in (diff) | |
download | ice-6c8b1db065f4cb87d490e047a89e2cbad8a6d152.tar.bz2 ice-6c8b1db065f4cb87d490e047a89e2cbad8a6d152.tar.xz ice-6c8b1db065f4cb87d490e047a89e2cbad8a6d152.zip |
Fixed the translators to use the icecpp C preprocessor.
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/Slice/Preprocessor.h | 47 | ||||
-rw-r--r-- | cpp/src/Ice/.depend | 2 | ||||
-rw-r--r-- | cpp/src/Slice/.depend | 1 | ||||
-rw-r--r-- | cpp/src/Slice/Makefile | 3 | ||||
-rw-r--r-- | cpp/src/Slice/Preprocessor.cpp | 193 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Main.cpp | 77 | ||||
-rw-r--r-- | cpp/src/slice2docbook/Main.cpp | 55 | ||||
-rw-r--r-- | cpp/src/slice2freeze/Main.cpp | 58 | ||||
-rw-r--r-- | cpp/src/slice2freezej/Main.cpp | 75 | ||||
-rw-r--r-- | cpp/src/slice2java/Main.cpp | 76 | ||||
-rw-r--r-- | cpp/src/slice2wsdl/Main.cpp | 59 | ||||
-rw-r--r-- | cpp/src/slice2xsd/Main.cpp | 61 |
12 files changed, 354 insertions, 353 deletions
diff --git a/cpp/include/Slice/Preprocessor.h b/cpp/include/Slice/Preprocessor.h new file mode 100644 index 00000000000..e5ae9c737c9 --- /dev/null +++ b/cpp/include/Slice/Preprocessor.h @@ -0,0 +1,47 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// ZeroC, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef PREPROCESSOR_H +#define PREPROCESSOR_H + +#include <IceUtil/Config.h> + +namespace Slice +{ + +class Preprocessor +{ +public: + + Preprocessor(const std::string&, const std::string&, const std::string&); + ~Preprocessor(); + + FILE* preprocess(bool); + bool close(); + + void printMakefileDependencies(); + + std::string getBaseName(); + +private: + + bool checkInputFile(); + std::string searchIceCpp(); + + const std::string _path; + const std::string _fileName; + const std::string _args; + FILE* _cppHandle; + +}; + +} + +#endif diff --git a/cpp/src/Ice/.depend b/cpp/src/Ice/.depend index e3f7a063a16..b57764e0b8f 100644 --- a/cpp/src/Ice/.depend +++ b/cpp/src/Ice/.depend @@ -39,7 +39,7 @@ Facet.o: Facet.cpp ../../include/Ice/Facet.h ../../include/Ice/LocalObjectF.h .. Current.o: Current.cpp ../../include/Ice/Current.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/BasicStream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Stream.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/BuiltinSequences.h Router.o: Router.cpp ../../include/Ice/Router.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/BasicStream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactory.h ../../include/Ice/Stream.h ../../include/Ice/BuiltinSequences.h RouterInfo.o: RouterInfo.cpp ../Ice/RouterInfo.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/IceUtil/Exception.h ../Ice/RouterInfoF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/Ice/Config.h ../../include/Ice/RouterF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/Ice/StreamF.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/BasicStream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/RoutingTableF.h ../../include/Ice/Router.h ../../include/Ice/RoutingTable.h ../../include/Ice/LocalException.h ../../include/Ice/Functional.h ../../include/IceUtil/Functional.h -RoutingTable.o: RoutingTable.cpp ../../include/Ice/RoutingTable.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/IceUtil/Exception.h ../../include/Ice/RoutingTableF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/Ice/StreamF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h +RoutingTable.o: RoutingTable.cpp ../../include/Ice/RoutingTable.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/IceUtil/Exception.h ../../include/Ice/RoutingTableF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Identity.h ../../include/Ice/LocalObjectF.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/Ice/StreamF.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Facet.h Connection.o: Connection.cpp ../Ice/Connection.h ../../include/IceUtil/RecMutex.h ../../include/IceUtil/Config.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/IceUtil/Exception.h ../../include/Ice/ConnectionF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/Ice/Config.h ../../include/Ice/ConnectionFactoryF.h ../../include/Ice/InstanceF.h ../Ice/TransceiverF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/EndpointF.h ../Ice/ThreadPoolF.h ../../include/Ice/LoggerF.h ../Ice/TraceLevelsF.h ../Ice/DefaultsAndOverridesF.h ../Ice/EventHandler.h ../Ice/EventHandlerF.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/ObjectFactoryF.h ../Ice/Instance.h ../../include/IceUtil/Mutex.h ../../include/Ice/CommunicatorF.h ../../include/Ice/PropertiesF.h ../Ice/RouterInfoF.h ../Ice/LocatorInfoF.h ../Ice/ReferenceFactoryF.h ../../include/Ice/ProxyFactoryF.h ../Ice/ObjectFactoryManagerF.h ../Ice/UserExceptionFactoryManagerF.h ../../include/Ice/ObjectAdapterFactoryF.h ../Ice/EndpointFactoryManagerF.h ../../include/Ice/DynamicLibraryF.h ../../include/Ice/PluginF.h ../../include/Ice/LoggerUtil.h ../../include/Ice/Properties.h ../../include/Ice/Proxy.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/BuiltinSequences.h ../Ice/TraceUtil.h ../Ice/DefaultsAndOverrides.h ../Ice/Transceiver.h ../Ice/ThreadPool.h ../../include/IceUtil/Thread.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/RouterF.h ../../include/Ice/LocatorF.h ../Ice/Endpoint.h ../Ice/ConnectorF.h ../Ice/AcceptorF.h ../../include/Ice/LocalException.h ../Ice/Protocol.h ConnectionFactory.o: ConnectionFactory.cpp ../Ice/ConnectionFactory.h ../../include/IceUtil/RecMutex.h ../../include/IceUtil/Config.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/IceUtil/Exception.h ../../include/Ice/ConnectionFactoryF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/Ice/Config.h ../../include/Ice/ConnectionF.h ../../include/Ice/InstanceF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/EndpointF.h ../Ice/AcceptorF.h ../Ice/TransceiverF.h ../../include/Ice/RouterF.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Facet.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/IceUtil/Time.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../Ice/EventHandler.h ../Ice/EventHandlerF.h ../Ice/ThreadPoolF.h ../Ice/Connection.h ../../include/Ice/LoggerF.h ../Ice/TraceLevelsF.h ../Ice/DefaultsAndOverridesF.h ../Ice/Instance.h ../../include/Ice/CommunicatorF.h ../../include/Ice/PropertiesF.h ../Ice/RouterInfoF.h ../Ice/LocatorInfoF.h ../Ice/ReferenceFactoryF.h ../Ice/ObjectFactoryManagerF.h ../Ice/UserExceptionFactoryManagerF.h ../../include/Ice/ObjectAdapterFactoryF.h ../Ice/EndpointFactoryManagerF.h ../../include/Ice/DynamicLibraryF.h ../../include/Ice/PluginF.h ../../include/Ice/LoggerUtil.h ../Ice/TraceLevels.h ../Ice/DefaultsAndOverrides.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../Ice/Transceiver.h ../Ice/Connector.h ../Ice/ConnectorF.h ../Ice/Acceptor.h ../Ice/ThreadPool.h ../../include/IceUtil/Thread.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/LocatorF.h ../Ice/Reference.h ../Ice/Endpoint.h ../Ice/RouterInfo.h ../../include/Ice/RoutingTableF.h ../../include/Ice/LocalException.h ../../include/Ice/Functional.h ../../include/IceUtil/Functional.h LocalObject.o: LocalObject.cpp ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/Ice/Config.h ../../include/Ice/StreamF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h diff --git a/cpp/src/Slice/.depend b/cpp/src/Slice/.depend index 1ccf27275fd..fef8392c303 100644 --- a/cpp/src/Slice/.depend +++ b/cpp/src/Slice/.depend @@ -3,3 +3,4 @@ Grammar.o: Grammar.cpp ../Slice/GrammarUtil.h ../../include/Slice/Parser.h ../.. Parser.o: Parser.cpp ../../include/IceUtil/Functional.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/IceUtil/InputUtil.h CPlusPlusUtil.o: CPlusPlusUtil.cpp ../../include/Slice/CPlusPlusUtil.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/InputUtil.h ../../include/IceUtil/OutputUtil.h JavaUtil.o: JavaUtil.cpp ../../include/Slice/JavaUtil.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/InputUtil.h ../../include/IceUtil/OutputUtil.h ../../include/IceUtil/Functional.h +Preprocessor.o: Preprocessor.cpp ../../include/Slice/Preprocessor.h ../../include/IceUtil/Config.h diff --git a/cpp/src/Slice/Makefile b/cpp/src/Slice/Makefile index 9788f4caf57..d70cda23f7d 100644 --- a/cpp/src/Slice/Makefile +++ b/cpp/src/Slice/Makefile @@ -26,7 +26,8 @@ OBJS = Scanner.o \ Grammar.o \ Parser.o \ CPlusPlusUtil.o \ - JavaUtil.o + JavaUtil.o \ + Preprocessor.o SRCS = $(OBJS:.o=.cpp) diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp new file mode 100644 index 00000000000..532ed8be9d6 --- /dev/null +++ b/cpp/src/Slice/Preprocessor.cpp @@ -0,0 +1,193 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// ZeroC, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Slice/Preprocessor.h> + +#include <algorithm> +#include <fstream> + +#include <sys/types.h> +#include <sys/stat.h> + +#ifndef _WIN32 +# include <sys/wait.h> +#endif + +using namespace std; +using namespace Slice; + +Slice::Preprocessor::Preprocessor(const string& path, const string& fileName, const string& args) : + _path(path), + _fileName(fileName), + _args(args), + _cppHandle(0) +{ +} + +Slice::Preprocessor::~Preprocessor() +{ + if(_cppHandle) + { + close(); + } +} + +string +Slice::Preprocessor::getBaseName() +{ + string base(_fileName); + string suffix; + string::size_type pos = base.rfind('.'); + if(pos != string::npos) + { + base.erase(pos); + } + return base; +} + +FILE* +Slice::Preprocessor::preprocess(bool keepComments) +{ + if(!checkInputFile()) + { + return 0; + } + + string cmd = searchIceCpp(); + + if(cmd.empty()) + { + return 0; + } + + if(keepComments) + { + cmd += " -C"; + } + + cmd += " " + _args + " " + _fileName; + + // + // Open a pipe for reading to redirect icecpp output to _cppHandle. + // +#ifdef _WIN32 + _cppHandle = _popen(cmd.c_str(), "r"); +#else + _cppHandle = popen(cmd.c_str(), "r"); +#endif + return _cppHandle; +} + +void +Slice::Preprocessor::printMakefileDependencies() +{ + if(!checkInputFile()) + { + return; + } + + string cmd = searchIceCpp(); + + if(cmd.empty()) + { + return; + } + + cmd += " -M " + _args + " " +_fileName; + + // + // Open a pipe for writing to redirect icecpp output to the standard output. + // +#ifndef _WIN32 + FILE* cppHandle = popen(cmd.c_str(), "w"); + pclose(cppHandle); +#else + FILE* cppHandle = _popen(cmd.c_str(), "w"); + _pclose(cppHandle); +#endif +} + +bool +Slice::Preprocessor::close() +{ + assert(_cppHandle); + +#ifndef WIN32 + int status = pclose(_cppHandle); + _cppHandle = 0; + + if(WIFEXITED(status) && WEXITSTATUS(status) != 0) + { + return false; + } +#else + int status = _pclose(_cppHandle); + _cppHandle = 0; + + if(status != 0) + { + return false; + } +#endif + + return true; +} + +bool +Slice::Preprocessor::checkInputFile() +{ + string base(_fileName); + 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 << _path << ": input files must end with `.ice'" << endl; + return false; + } + + ifstream test(_fileName.c_str()); + if(!test) + { + cerr << _path << ": can't open `" << _fileName << "' for reading: " << strerror(errno) << endl; + return false; + } + test.close(); + + return true; +} + +string +Slice::Preprocessor::searchIceCpp() +{ + const char* icecpp = "icecpp"; + + string::size_type pos = _path.find_last_of("/\\"); + if(pos != string::npos) + { + string path = _path.substr(0, pos + 1); + path += icecpp; + + struct stat st; + if(stat(path.c_str(), &st) == 0) + { + if(st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) + { + return path; + } + } + } + + return icecpp; +} 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(); 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 <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 -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) 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) diff --git a/cpp/src/slice2freezej/Main.cpp b/cpp/src/slice2freezej/Main.cpp index 711fa75e43b..4103881a840 100644 --- a/cpp/src/slice2freezej/Main.cpp +++ b/cpp/src/slice2freezej/Main.cpp @@ -12,8 +12,8 @@ // // ********************************************************************** +#include <Slice/Preprocessor.h> #include <Slice/JavaUtil.h> -#include <fstream> using namespace std; using namespace Slice; @@ -435,7 +435,7 @@ usage(const char* n) int main(int argc, char* argv[]) { - string cpp("cpp"); + string cppArgs; vector<string> includePaths; string include; bool binary = false; @@ -451,8 +451,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()) @@ -468,8 +468,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) { @@ -643,74 +643,33 @@ main(int argc, char* argv[]) UnitPtr unit = Unit::createUnit(true, false, ice, caseSensitive); - StringList includes; - int status = EXIT_SUCCESS; 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; - } - - 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); - } - - string cmd = cpp + " -M " + argv[idx]; - -#ifdef _WIN32 - FILE* cppHandle = _popen(cmd.c_str(), "w"); - _pclose(cppHandle); -#else - 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]; -#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(false); + 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; + } } } diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index 41a2fe7a8db..dc357904791 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -12,8 +12,8 @@ // // ********************************************************************** +#include <Slice/Preprocessor.h> #include <Gen.h> -#include <fstream> using namespace std; using namespace Slice; @@ -45,7 +45,7 @@ usage(const char* n) int main(int argc, char* argv[]) { - string cpp("cpp"); + string cppArgs; vector<string> includePaths; string output; string package; @@ -62,8 +62,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()) @@ -80,8 +80,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) { @@ -230,78 +230,36 @@ 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); - } - - string cmd = cpp + " -M " + argv[idx]; - -#ifdef _WIN32 - FILE* cppHandle = _popen(cmd.c_str(), "w"); - _pclose(cppHandle); -#else - 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]; -#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(false); + 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()) + { + return EXIT_FAILURE; + } + if(parseStatus == EXIT_FAILURE) { status = EXIT_FAILURE; } else { - Gen gen(argv[0], base, includePaths, package, output); + Gen gen(argv[0], icecpp.getBaseName(), includePaths, package, output); if(!gen) { unit->destroy(); 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) { 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(); |