From 5465c95134d20ee5eb8921102584b251788d242c Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 21 Aug 2014 11:21:47 +0100 Subject: [PATCH] [era/xml format] bring in line with the Ruby library --- era/xml_format.cc | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/era/xml_format.cc b/era/xml_format.cc index 0112aae..876356b 100644 --- a/era/xml_format.cc +++ b/era/xml_format.cc @@ -49,7 +49,7 @@ namespace { void writeset_bit(uint32_t bit, bool value) { out_.indent(); // FIXME: collect all the bits, then uuencode - out_ << "" << endl; + out_ << "" << endl; } void end_writeset() { @@ -67,7 +67,7 @@ namespace { void era(pd::block_address block, uint32_t era) { out_.indent(); out_ << "" << endl; + << "\" era=\"" << era << "\"/>" << endl; } void end_era_array() { @@ -83,6 +83,20 @@ namespace { //-------------------------------- // Parser //-------------------------------- + void parse_bit(attributes const &a, emitter *e) { + bool value; + + string txt = get_attr(a, "value"); + if (txt == "true") + value = true; + else if (txt == "false") + value = false; + else + throw runtime_error("invalid boolean"); + + e->writeset_bit(get_attr(a, "block"), value); + } + void start_tag(void *data, char const *el, char const **attr) { emitter *e = static_cast(data); attributes a; @@ -100,8 +114,7 @@ namespace { get_attr(a, "nr_bits")); else if (!strcmp(el, "bit")) - e->writeset_bit(get_attr(a, "bit"), - get_attr(a, "value")); + parse_bit(a, e); else if (!strcmp(el, "era_array")) e->begin_era_array(); @@ -126,6 +139,14 @@ namespace { else if (!strcmp(el, "era_array")) e->end_era_array(); + else if (!strcmp(el, "era")) + /* do nothing */ + ; + + else if (!strcmp(el, "bit")) + /* do nothing */ + ; + else throw runtime_error("unknown tag type"); }