# # # patch "cmd_automate.cc" # from [fdad3e113ea4f077db08c1e789c1f2bf39abe2c0] # to [dccef66a766c3c04ebd183daafb83d55cc1deff7] # # patch "sanity.cc" # from [d3c9ad4e290d48f5df7ed588ae883986e3ca0e8b] # to [392f1d3b1f8c9915ccb00933782985843b69b03e] # # patch "sanity.hh" # from [67a009db0bbdd3565a7021f61e5b1e4a7194f480] # to [dcf2a754227ec3554e16ef3aa856d503698d433f] # ============================================================ --- cmd_automate.cc fdad3e113ea4f077db08c1e789c1f2bf39abe2c0 +++ cmd_automate.cc dccef66a766c3c04ebd183daafb83d55cc1deff7 @@ -301,6 +301,20 @@ public: out->flush(); } } + void write_out_of_band(char type, std::string const& data) + { + unsigned chunksize = _bufsize; + size_t length = data.size(), offset = 0; + do + { + if (offset+chunksize>length) + chunksize = length-offset; + (*out) << cmdnum << ':' << err << ':' << type << ':' + << chunksize << ':' << data.substr(offset, chunksize); + offset+= chunksize; + } while (offsetflush(); + } int_type overflow(int_type c = traits_type::eof()) { @@ -333,6 +347,11 @@ struct automate_ostream : public std::os { _M_autobuf.end_cmd(); } }; +static void out_of_band_to_automate_streambuf(char channel, std::string const& text, void *opaque) +{ + reinterpret_cast(opaque)->write_out_of_band(channel, text); +} + CMD_AUTOMATE(stdio, "", N_("Automates several commands in one run"), "", @@ -351,6 +370,7 @@ CMD_AUTOMATE(stdio, "", automate_reader ar(std::cin); vector > params; vector cmdline; + global_sanity.set_out_of_band_handler(&out_of_band_to_automate_streambuf, &os._M_autobuf); while(ar.get_command(params, cmdline))//while(!EOF) { args_vector args; ============================================================ --- sanity.cc d3c9ad4e290d48f5df7ed588ae883986e3ca0e8b +++ sanity.cc 392f1d3b1f8c9915ccb00933782985843b69b03e @@ -46,6 +46,9 @@ struct sanity::impl std::string gasp_dump; bool already_dumping; std::vector musings; + + void (*out_of_band_function)(char channel, std::string const& text, void *opaque); + void *out_of_band_opaque; impl() : debug(false), quiet(false), reallyquiet(false), logbuf(0xffff), @@ -140,7 +143,7 @@ sanity::set_debug() inform_log((*i) + "\n"); } -void +void sanity::set_quiet() { I(imp); @@ -238,6 +241,12 @@ sanity::progress(i18n_format const & i18 { string str = do_format(i18nfmt, file, line); + if (imp->out_of_band_function) + { + (*imp->out_of_band_function)('p', str, imp->out_of_band_opaque); + return; + } + if (str.size() > constants::log_line_sz) { str.resize(constants::log_line_sz); @@ -257,6 +266,12 @@ sanity::warning(i18n_format const & i18n { string str = do_format(i18nfmt, file, line); + if (imp->out_of_band_function) + { + (*imp->out_of_band_function)('w', str, imp->out_of_band_opaque); + return; + } + if (str.size() > constants::log_line_sz) { str.resize(constants::log_line_sz); @@ -405,6 +420,12 @@ sanity::gasp() imp->already_dumping = false; } +void sanity::set_out_of_band_handler(void (*out_of_band_function)(char, std::string const&, void *), void *opaque_data) +{ + imp->out_of_band_function= out_of_band_function; + imp->out_of_band_opaque= opaque_data; +} + template <> void dump(string const & obj, string & out) { ============================================================ --- sanity.hh 67a009db0bbdd3565a7021f61e5b1e4a7194f480 +++ sanity.hh dcf2a754227ec3554e16ef3aa856d503698d433f @@ -50,6 +50,9 @@ struct sanity { // This takes a bare std::string because we don't want to expose vocab.hh // or paths.hh here. void set_dump_path(std::string const & path); + + // set out of band handler (e.g. for automate stdio) + void set_out_of_band_handler(void (*out_of_band_function)(char channel, std::string const& text, void *opaque)=NULL, void *opaque_data=NULL); // A couple of places need to look at the debug flag to avoid doing // expensive logging if it's off.