| 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 | sglog().setLogLevels(SG_ALL, SG_ALERT); |
| 25 | |
| 26 | int numfiles = 0; |
| 27 | string outfile; |
| 28 | SGPropertyNode root; |
| 29 | |
| 30 | for (int i = 1; i < argc; i++) { |
| 31 | string s = argv[i]; |
| 32 | if (s == "-h" || s == "--help") { |
| 33 | usage(); |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | if (s == "-o" || s == "--output") { |
| 38 | if (i + 1 == argc) |
| 39 | break; |
| 40 | outfile = argv[++i]; |
| 41 | continue; |
| 42 | } |
| 43 | |
| 44 | try { |
| 45 | readProperties(s, &root); |
| 46 | numfiles++; |
| 47 | } catch (const sg_exception &e) { |
| 48 | cerr << "Error: " << e.getFormattedMessage() << endl; |
| 49 | return 2; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if (!numfiles) { |
| 54 | cerr << "Error: Nothing to merge." << endl; |
| 55 | return 3; |
| 56 | } |
| 57 | |
| 58 | try { |
| 59 | if (outfile.empty()) |
| 60 | writeProperties(cout, &root, true); |
| 61 | else |
| 62 | writeProperties(outfile, &root, true); |
| 63 | |
| 64 | } catch (const sg_exception &e) { |
| 65 | cerr << "Error: " << e.getFormattedMessage() << endl; |
| 66 | return 4; |
| 67 | } |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 |