summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/Preprocessor.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2008-05-07 22:12:00 -0700
committerMark Spruiell <mes@zeroc.com>2008-05-07 22:12:00 -0700
commit0e945efc6b0a2eb3c6de70375629c0ae225f388d (patch)
treed10525d4ab9f78e60a7a15ab75dcaf255b967b36 /cpp/src/Slice/Preprocessor.cpp
parentbug 3098 - slice2java ant task & stderr (diff)
downloadice-0e945efc6b0a2eb3c6de70375629c0ae225f388d.tar.bz2
ice-0e945efc6b0a2eb3c6de70375629c0ae225f388d.tar.xz
ice-0e945efc6b0a2eb3c6de70375629c0ae225f388d.zip
check return value of mcpp
Diffstat (limited to 'cpp/src/Slice/Preprocessor.cpp')
-rwxr-xr-xcpp/src/Slice/Preprocessor.cpp73
1 files changed, 45 insertions, 28 deletions
diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp
index 089f0938713..f6eb84f5ddb 100755
--- a/cpp/src/Slice/Preprocessor.cpp
+++ b/cpp/src/Slice/Preprocessor.cpp
@@ -156,34 +156,39 @@ Slice::Preprocessor::preprocess(bool keepComments)
// Call mcpp using memory buffer.
//
mcpp_use_mem_buffers(1);
- mcpp_lib_main(static_cast<int>(args.size()) + 1, const_cast<char**>(argv));
+ int status = mcpp_lib_main(static_cast<int>(args.size()) + 1, const_cast<char**>(argv));
delete[] argv;
//
- // Write output to temporary file. Print errors to stderr.
+ // Print errors to stderr.
//
- string result;
- char* buf = mcpp_get_mem_buffer(Out);
-
- _cppFile = ".preprocess." + IceUtil::generateUUID();
- SignalHandler::addFile(_cppFile);
-#ifdef _WIN32
- _cppHandle = ::_wfopen(IceUtil::stringToWstring(_cppFile).c_str(), IceUtil::stringToWstring("w+").c_str());
-#else
- _cppHandle = ::fopen(_cppFile.c_str(), "w+");
-#endif
- if(buf)
- {
- ::fwrite(buf, strlen(buf), 1, _cppHandle);
- }
- ::rewind(_cppHandle);
-
char* err = mcpp_get_mem_buffer(Err);
if(err)
{
::fputs(err, stderr);
}
+ if(status == 0)
+ {
+ //
+ // Write output to temporary file.
+ //
+ char* buf = mcpp_get_mem_buffer(Out);
+
+ _cppFile = ".preprocess." + IceUtil::generateUUID();
+ SignalHandler::addFile(_cppFile);
+#ifdef _WIN32
+ _cppHandle = ::_wfopen(IceUtil::stringToWstring(_cppFile).c_str(), IceUtil::stringToWstring("w+").c_str());
+#else
+ _cppHandle = ::fopen(_cppFile.c_str(), "w+");
+#endif
+ if(buf)
+ {
+ ::fwrite(buf, strlen(buf), 1, _cppHandle);
+ }
+ ::rewind(_cppHandle);
+ }
+
//
// Calling this again causes the memory buffers to be freed.
//
@@ -217,11 +222,29 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin
// Call mcpp using memory buffer.
//
mcpp_use_mem_buffers(1);
- mcpp_lib_main(static_cast<int>(args.size() + 1), const_cast<char**>(argv));
+ int status = mcpp_lib_main(static_cast<int>(args.size() + 1), const_cast<char**>(argv));
delete[] argv;
//
- // Get mcpp output/errors.
+ // Print errors to stderr.
+ //
+ char* err = mcpp_get_mem_buffer(Err);
+ if(err)
+ {
+ ::fputs(err, stderr);
+ }
+
+ if(status != 0)
+ {
+ //
+ // Calling this again causes the memory buffers to be freed.
+ //
+ mcpp_use_mem_buffers(1);
+ return;
+ }
+
+ //
+ // Get mcpp output.
//
string unprocessed;
char* buf = mcpp_get_mem_buffer(Out);
@@ -230,19 +253,13 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin
unprocessed = string(buf);
}
- char* err = mcpp_get_mem_buffer(Err);
- if(err)
- {
- ::fputs(err, stderr);
- }
-
//
// Calling this again causes the memory buffers to be freed.
//
mcpp_use_mem_buffers(1);
//
- // We now need to massage then result to get desire output.
+ // We now need to massage the result to get the desired output.
// First make it a single line.
//
string::size_type pos;
@@ -281,7 +298,7 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin
if(isAbsolute(file))
{
//
- // Transform back full paths generated by mcpp to paths relative to the specificed
+ // Transform back full paths generated by mcpp to paths relative to the specified
// include paths.
//
string newFile = file;