diff --git a/src/api/api_parsers.cpp b/src/api/api_parsers.cpp index 3a1fe7af1..ec594dcd3 100644 --- a/src/api/api_parsers.cpp +++ b/src/api/api_parsers.cpp @@ -242,6 +242,7 @@ extern "C" { std::istringstream is(s); ctx->set_regular_stream(ous); ctx->set_diagnostic_stream(ous); + cmd_context::scoped_redirect _redirect(*ctx); try { if (!parse_smt2_commands(*ctx.get(), is)) { SET_ERROR_CODE(Z3_PARSER_ERROR, ous.str()); diff --git a/src/cmd_context/cmd_context.h b/src/cmd_context/cmd_context.h index d54a90143..a51820ac1 100644 --- a/src/cmd_context/cmd_context.h +++ b/src/cmd_context/cmd_context.h @@ -191,6 +191,22 @@ public: ~scoped_watch() { m_ctx.m_watch.stop(); } }; + struct scoped_redirect { + cmd_context& m_ctx; + std::ostream& m_verbose; + std::ostream* m_warning; + + scoped_redirect(cmd_context& ctx): m_ctx(ctx), m_verbose(verbose_stream()), m_warning(warning_stream()) { + set_warning_stream(&(*m_ctx.m_diagnostic)); + set_verbose_stream(m_ctx.diagnostic_stream()); + } + + ~scoped_redirect() { + set_verbose_stream(m_verbose); + set_warning_stream(m_warning); + } + }; + protected: diff --git a/src/util/warning.cpp b/src/util/warning.cpp index 1bc91fbfa..033c93780 100644 --- a/src/util/warning.cpp +++ b/src/util/warning.cpp @@ -83,6 +83,10 @@ void set_warning_stream(std::ostream* strm) { g_warning_stream = strm; } +std::ostream* warning_stream() { + return g_warning_stream; +} + void format2ostream(std::ostream & out, char const* msg, va_list args) { svector buff; BEGIN_ERR_HANDLER(); diff --git a/src/util/warning.h b/src/util/warning.h index 5a74ebd2d..9f71d74b3 100644 --- a/src/util/warning.h +++ b/src/util/warning.h @@ -28,6 +28,8 @@ void set_error_stream(std::ostream* strm); void set_warning_stream(std::ostream* strm); +std::ostream* warning_stream(); + void warning_msg(const char * msg, ...); void format2ostream(std::ostream& out, char const* fmt, va_list args);