From d46f0a42ec0fe8188f36de1acbf02eee165cdb10 Mon Sep 17 00:00:00 2001 From: mfranz Date: Tue, 11 Nov 2008 18:51:01 +0000 Subject: [PATCH] add propmerge utility, which merges XML files. Writes result to the given output file if specified, or prints it to stdout otherwise. Usage: $ propmerge [-o ] --- utils/propmerge/Makefile.am | 4 ++ utils/propmerge/propmerge.cxx | 70 +++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 utils/propmerge/Makefile.am create mode 100644 utils/propmerge/propmerge.cxx diff --git a/utils/propmerge/Makefile.am b/utils/propmerge/Makefile.am new file mode 100644 index 000000000..e68c2abe6 --- /dev/null +++ b/utils/propmerge/Makefile.am @@ -0,0 +1,4 @@ +noinst_PROGRAMS = propmerge + +propmerge_SOURCES = propmerge.cxx +propmerge_LDADD = -lsgprops -lsgxml -lsgio -lsgmisc -lsgdebug -lsgstructure diff --git a/utils/propmerge/propmerge.cxx b/utils/propmerge/propmerge.cxx new file mode 100644 index 000000000..61eb5b3bd --- /dev/null +++ b/utils/propmerge/propmerge.cxx @@ -0,0 +1,70 @@ +#include +#include + +#include +#include +#include + +using namespace std; + + +void usage() +{ + cerr << "Usage: propmerge [-o ] " << endl; +} + + +int main(int argc, char *argv[]) +{ + if (argc < 2) { + usage(); + return -1; + } + + int numfiles = 0; + string out; + SGPropertyNode root; + + for (int i = 1; i < argc; i++) { + string s = argv[i]; + if (s == "-h" || s == "--help") { + usage(); + return 0; + } + + if (s == "-o" || s == "--output") { + if (i + 1 == argc) + break; + out = argv[++i]; + continue; + } + + try { + readProperties(s, &root); + numfiles++; + } catch (const sg_exception &e) { + cerr << "Error: " << e.getFormattedMessage() << endl; + return -2; + } + } + + if (!numfiles) { + cerr << "Error: Nothing to merge." << endl; + return -3; + } + + try { + if (out.empty()) + writeProperties(cout, &root, true); + else + writeProperties(out, &root, true); + + } catch (const sg_exception &e) { + cerr << "Error: " << e.getFormattedMessage() << endl; + return -4; + } + + return 0; +} + + -- 2.39.5