]> git.mxchange.org Git - flightgear.git/blob - utils/propmerge/propmerge.cxx
61eb5b3bd7fdc51670e4bce90b938ed046207ac8
[flightgear.git] / utils / propmerge / propmerge.cxx
1 #include <iostream>
2 #include <string>
3
4 #include <simgear/props/props.hxx>
5 #include <simgear/props/props_io.hxx>
6 #include <simgear/structure/exception.hxx>
7
8 using namespace std;
9
10
11 void usage()
12 {
13         cerr << "Usage:  propmerge [-o <outfile>] <infiles>" << endl;
14 }
15
16
17 int main(int argc, char *argv[])
18 {
19         if (argc < 2) {
20                 usage();
21                 return -1;
22         }
23
24         int numfiles = 0;
25         string out;
26         SGPropertyNode root;
27
28         for (int i = 1; i < argc; i++) {
29                 string s = argv[i];
30                 if (s == "-h" || s == "--help") {
31                         usage();
32                         return 0;
33                 }
34
35                 if (s == "-o" || s == "--output") {
36                         if (i + 1 == argc)
37                                 break;
38                         out = argv[++i];
39                         continue;
40                 }
41
42                 try {
43                         readProperties(s, &root);
44                         numfiles++;
45                 } catch (const sg_exception &e) {
46                         cerr << "Error: " << e.getFormattedMessage() << endl;
47                         return -2;
48                 }
49         }
50
51         if (!numfiles) {
52                 cerr << "Error: Nothing to merge." << endl;
53                 return -3;
54         }
55
56         try {
57                 if (out.empty())
58                         writeProperties(cout, &root, true);
59                 else
60                         writeProperties(out, &root, true);
61
62         } catch (const sg_exception &e) {
63                 cerr << "Error: " << e.getFormattedMessage() << endl;
64                 return -4;
65         }
66
67         return 0;
68 }
69
70