1
0
Fork 0

add propmerge utility, which merges <PropertyList> XML files. Writes

result to the given output file if specified, or prints it to stdout
otherwise. Usage:

  $ propmerge [-o <outfile>] <list-of-infiles>
This commit is contained in:
mfranz 2008-11-11 18:51:01 +00:00
parent fbe1a51d38
commit d46f0a42ec
2 changed files with 74 additions and 0 deletions

View file

@ -0,0 +1,4 @@
noinst_PROGRAMS = propmerge
propmerge_SOURCES = propmerge.cxx
propmerge_LDADD = -lsgprops -lsgxml -lsgio -lsgmisc -lsgdebug -lsgstructure

View file

@ -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;
}