# # # patch "cmd_automate.cc" # from [1f90ee26385b4db17ef2e12524c8ed8a410d59e4] # to [2e70872fd99d5b90a40c3a55bfa9c645f46b71a0] # # patch "options_list.hh" # from [35f36f423168154a9345e5ffeb35f38bbe09c300] # to [46ade3ce429cfedb5ac40478d9acff7b9e7baef4] # # patch "ui.cc" # from [f1bb749951aa4f9b75298f15d70b28ca98b217fd] # to [1e3a61a2b35bd3d1042660434ef66636a22afaa1] # # patch "ui.hh" # from [ea2c11aaa5de4bc00851ee8bb7a9730f509c93fc] # to [52c29b03c1d3f63c10d2280fab8af9a7b610a033] # ============================================================ --- cmd_automate.cc 1f90ee26385b4db17ef2e12524c8ed8a410d59e4 +++ cmd_automate.cc 2e70872fd99d5b90a40c3a55bfa9c645f46b71a0 @@ -12,6 +12,7 @@ #include #include "cmd.hh" +#include "ui.hh" using std::istream; using std::make_pair; @@ -331,6 +332,10 @@ AUTOMATE(stdio, "", options::opts::autom N(args.size() == 0, F("no arguments needed")); + // overwrite any former --ticker option with 'stdio' + tick_write_stdio * tick_writer = new tick_write_stdio(); + ui.set_tick_writer(tick_writer); + automate_ostream os(output, app.opts.automate_stdio_size); automate_reader ar(std::cin); vector > params; @@ -366,6 +371,7 @@ AUTOMATE(stdio, "", options::opts::autom os<next_cmd(); } } ============================================================ --- options_list.hh 35f36f423168154a9345e5ffeb35f38bbe09c300 +++ options_list.hh 46ade3ce429cfedb5ac40478d9acff7b9e7baef4 @@ -471,7 +471,7 @@ GOPT(ticker, "ticker", std::string, , #endif GOPT(ticker, "ticker", std::string, , - gettext_noop("set ticker style (count|dot|none)")) + gettext_noop("set ticker style (count|dot|stdio|none)")) #ifdef option_bodies { ticker = arg; @@ -481,8 +481,10 @@ GOPT(ticker, "ticker", std::string, , ui.set_tick_writer(new tick_write_dot); else if (ticker == "count") ui.set_tick_writer(new tick_write_count); + else if (ticker == "stdio") + ui.set_tick_writer(new tick_write_stdio); else - throw bad_arg_internal(F("argument must be 'none', 'dot', or 'count'").str()); + throw bad_arg_internal(F("argument must be 'none', 'dot', 'count' or 'stdio'").str()); } #endif ============================================================ --- ui.cc f1bb749951aa4f9b75298f15d70b28ca98b217fd +++ ui.cc 1e3a61a2b35bd3d1042660434ef66636a22afaa1 @@ -391,6 +391,76 @@ void tick_write_dot::clear_line() clog << endl; } + +tick_write_stdio::tick_write_stdio() : + cmdnum(0) +{ +} + +tick_write_stdio::~tick_write_stdio() +{ +} + +void tick_write_stdio::write_ticks() +{ + basic_io::printer pr; + string ticks; + + for (map::const_iterator i = ui.tickers.begin(); + i != ui.tickers.end(); ++i) + { + map::const_iterator old = last_ticks.find(i->first); + ticker * tick = i->second; + + if (!ui.last_write_was_a_tick) + { + basic_io::stanza st; + st.push_str_pair(symbol("shortname"), tick->shortname); + st.push_str_pair(symbol("name"), tick->name); + st.push_str_pair(symbol("mod"), lexical_cast(tick->mod)); + if (tick->use_total) + { + st.push_str_pair( + symbol("total"), + lexical_cast(tick->total) + ); + } + pr.print_stanza(st); + } + + if (old == last_ticks.end() + || ((tick->ticks / tick->mod) > (old->second / tick->mod))) + { + ticks += lexical_cast(cmdnum) + + ":0:t:" + lexical_cast(tick->shortname.size()) + + ":" + tick->shortname + "\n"; + + if (old == last_ticks.end()) + last_ticks.insert(make_pair(i->first, tick->ticks)); + else + last_ticks[i->first] = tick->ticks; + } + } + + if (pr.buf.size() > 0) + { + cout << cmdnum << ":0:h:" << pr.buf.size() << ":" << pr.buf.data(); + } + cout << ticks; + cout.flush(); +} + +void tick_write_stdio::clear_line() +{ +} + +void tick_write_stdio::next_cmd() +{ + // raise the command counter + ++cmdnum; +} + + // user_interface has both constructor/destructor and initialize/ // deinitialize because there's only one of these objects, it's // global, and we don't want global constructors/destructors doing ============================================================ --- ui.hh ea2c11aaa5de4bc00851ee8bb7a9730f509c93fc +++ ui.hh 52c29b03c1d3f63c10d2280fab8af9a7b610a033 @@ -18,6 +18,7 @@ #include #include +#include "basic_io.hh" #include "paths.hh" #include "sanity.hh" @@ -77,6 +78,19 @@ private: unsigned int chars_on_line; }; +struct tick_write_stdio : virtual public tick_writer +{ +public: + tick_write_stdio(); + ~tick_write_stdio(); + void write_ticks(); + void clear_line(); + void next_cmd(); +private: + std::map last_ticks; + int cmdnum; +}; + struct tick_write_nothing : virtual public tick_writer { public: @@ -120,6 +134,7 @@ private: friend struct tick_write_dot; friend struct tick_write_count; + friend struct tick_write_stdio; friend struct ticker; };