]> git.mxchange.org Git - flightgear.git/commitdiff
add propmerge utility, which merges <PropertyList> XML files. Writes
authormfranz <mfranz>
Tue, 11 Nov 2008 18:51:01 +0000 (18:51 +0000)
committermfranz <mfranz>
Tue, 11 Nov 2008 18:51:01 +0000 (18:51 +0000)
result to the given output file if specified, or prints it to stdout
otherwise. Usage:

  $ propmerge [-o <outfile>] <list-of-infiles>

utils/propmerge/Makefile.am [new file with mode: 0644]
utils/propmerge/propmerge.cxx [new file with mode: 0644]

diff --git a/utils/propmerge/Makefile.am b/utils/propmerge/Makefile.am
new file mode 100644 (file)
index 0000000..e68c2ab
--- /dev/null
@@ -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 (file)
index 0000000..61eb5b3
--- /dev/null
@@ -0,0 +1,70 @@
+#include <iostream>
+#include <string>
+
+#include <simgear/props/props.hxx>
+#include <simgear/props/props_io.hxx>
+#include <simgear/structure/exception.hxx>
+
+using namespace std;
+
+
+void usage()
+{
+       cerr << "Usage:  propmerge [-o <outfile>] <infiles>" << 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;
+}
+
+