# # patch "ChangeLog" # from [997f81daaf6be0afdfdbff4c47c999f91fd318fc] # to [b843612462795d107c977b122158407084608f36] # # patch "basic_io.cc" # from [08fb82e004b12795e66bf122762729c1bb5e5209] # to [ea2ba2673c3cddd98f61cb44d774ee5da630f8e6] # # patch "basic_io.hh" # from [b61d8da0f80ba7017e11e68e91809c95f4415b43] # to [af1b7d67af27f456715562990c290e04172925df] # # patch "cset.cc" # from [fdc08baa63e7adc9530717970a499e57981a8efb] # to [9cad7c1bca5a2bfa8f43851240d784a5223b26ed] # =============================================== --- ChangeLog 997f81daaf6be0afdfdbff4c47c999f91fd318fc +++ ChangeLog b843612462795d107c977b122158407084608f36 @@ -1,3 +1,8 @@ +2005-07-23 graydon hoare + + * basic_io.{cc,hh} (basic_io::stanza::push_str_triple): New method. + * cset.cc ({parse,print,read,write}_mfest): New methods. + 2005-07-18 graydon hoare * cset.cc: More bugfixing, passes first unit test. =============================================== --- basic_io.cc 08fb82e004b12795e66bf122762729c1bb5e5209 +++ basic_io.cc ea2ba2673c3cddd98f61cb44d774ee5da630f8e6 @@ -84,7 +84,19 @@ indent = k.size(); } +void basic_io::stanza::push_str_triple(std::string const & k, + std::string const & n, + std::string const & v) +{ + for (std::string::const_iterator i = k.begin(); i != k.end(); ++i) + I(std::isalnum(*i) || *i == '_'); + entries.push_back(std::make_pair(k, escape(n) + " " + escape(v))); + if (k.size() > indent) + indent = k.size(); +} + + basic_io::printer::printer(std::ostream & ost) : empty_output(true), out(ost) {} =============================================== --- basic_io.hh b61d8da0f80ba7017e11e68e91809c95f4415b43 +++ basic_io.hh af1b7d67af27f456715562990c290e04172925df @@ -151,6 +151,7 @@ std::vector > entries; void push_hex_pair(std::string const & k, std::string const & v); void push_str_pair(std::string const & k, std::string const & v); + void push_str_triple(std::string const & k, std::string const & n, std::string const & v); }; struct =============================================== --- cset.cc fdc08baa63e7adc9530717970a499e57981a8efb +++ cset.cc 9cad7c1bca5a2bfa8f43851240d784a5223b26ed @@ -2199,6 +2199,12 @@ { namespace syms { + // mfest symbols + std::string const dir("dir"); + std::string const file("file"); + std::string const content("content"); + + // cset symbols std::string const set_heir("set_heir"); std::string const delete_node("delete"); std::string const rename_node("rename"); @@ -2442,9 +2448,94 @@ dat = data(oss.str()); } +void +parse_mfest(basic_io::parser & p, + mfest & m) +{ + cset c; + std::string pth, n, v; + while (p.symp()) + { + if (p.symp(syms::dir)) + { + p.sym(); + p.str(pth); + c.add_dir(file_path(pth)); + } + else if (p.symp(syms::file)) + { + p.sym(); + p.str(pth); + c.add_file(file_path(pth)); + } + else break; + // if we got here, we read either a dir or file + while (p.symp(syms::attr)) + { + p.sym(); + p.str(n); + p.str(v); + c.set_attr(file_path(pth), n, v); + } + } + // now store the results into the provided mfest + m.reset(c.new_mfest); +} +void +print_mfest(basic_io::printer & p, + mfest const & m) +{ + for (dfs_iter i(m.root); !i.finished(); ++i) + { + node_t curr = *i; + basic_io::stanza st; + if (is_dir_t(curr)) + st.push_str_pair(syms::dir, curr->name->val); + else + { + file_t ftmp = downcast_to_file_t(curr); + st.push_str_pair(syms::file, curr->name->val); + st.push_hex_pair(syms::content, ftmp->content.inner()()); + } + if (curr->has_attrs()) + { + for (map::const_iterator j = curr->fancy->attrs.begin(); + j != curr->fancy->attrs.end(); ++j) + st.push_str_triple(syms::attr, j->first, j->second); + } + } + +} + +void +read_mfest(data const & dat, + mfest & mf) +{ + std::istringstream iss(dat()); + basic_io::input_source src(iss, "mfest"); + basic_io::tokenizer tok(src); + basic_io::parser pars(tok); + parse_mfest(pars, mf); + I(src.lookahead == EOF); + mf.check_sane(); +} + +void +write_mfest(mfest const & mf, + data & dat) +{ + mf.check_sane(); + std::ostringstream oss; + basic_io::printer pr(oss); + print_mfest(pr, mf); + dat = data(oss.str()); +} + + + #ifdef BUILD_UNIT_TESTS #include "unit_tests.hh" #include "sanity.hh" @@ -2456,10 +2547,27 @@ file_id null_file_id; static void +spin_mfest(mfest const & m) +{ + data tmp; + mfest m1, m2; + m1.reset(m); + for (unsigned i = 0; i < 5; ++i) + { + write_mfest(m1, tmp); + read_mfest(tmp, m2); + I(m1 == m2); + m1.reset(m2); + } +} + +static void spin_cset(cset const & cs) { data tmp1; cset cs1; + spin_mfest(cs.old_mfest); + spin_mfest(cs.new_mfest); write_cset(cs, tmp1); read_cset(tmp1, cs1); for (int i = 0; i < 5; ++i) @@ -2470,8 +2578,10 @@ BOOST_CHECK(tmp1 == tmp2); read_cset(tmp2, cs2); BOOST_CHECK(cs1 == cs2); - cs1 = cs2; - } + cs1 = cs2; + spin_mfest(cs2.old_mfest); + spin_mfest(cs2.new_mfest); + } } static void