1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : arb_2_ascii.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #include <arbdb.h> |
---|
12 | #include <arb_handlers.h> |
---|
13 | |
---|
14 | int ARB_main(int argc, char *argv[]) { |
---|
15 | GB_ERROR error = 0; |
---|
16 | |
---|
17 | ARB_redirect_handlers_to(stderr, stderr); |
---|
18 | |
---|
19 | fprintf(stderr, "arb_2_ascii - ARB database binary to ascii converter\n"); |
---|
20 | |
---|
21 | if (argc<2 || strcmp(argv[1], "--help") == 0) { |
---|
22 | fprintf(stderr, |
---|
23 | "\n" |
---|
24 | "Usage: arb_2_ascii [-r] <source.arb> [<dest.arb>|-]\n" |
---|
25 | "Purpose: Converts a database to ascii format\n" |
---|
26 | "\n" |
---|
27 | "if '-r' (=recovery) is specified, try to fix problems while reading <source.arb>.\n" |
---|
28 | "\n" |
---|
29 | "if <dest.arb> is set, write to <dest.arb>\n" |
---|
30 | "if the second parameter is '-' write to console.\n" |
---|
31 | "else replace <source.arb> by ascii version (backup first)\n" |
---|
32 | "\n" |
---|
33 | ); |
---|
34 | |
---|
35 | if (strcmp(argv[1], "--help") != 0) { error = "Missing arguments"; } |
---|
36 | } |
---|
37 | else { |
---|
38 | bool recovery = false; // try to recover corrupt data ? |
---|
39 | if (strcmp(argv[1], "-r") == 0) { |
---|
40 | recovery = true; |
---|
41 | argv++; argc--; |
---|
42 | } |
---|
43 | |
---|
44 | const char *in = argv[1]; |
---|
45 | const char *out = NULL; |
---|
46 | |
---|
47 | const char *readflags = recovery ? "rwR" : "rw"; |
---|
48 | const char *saveflags = "a"; |
---|
49 | |
---|
50 | if (argc == 2) { |
---|
51 | out = in; |
---|
52 | } |
---|
53 | else { |
---|
54 | out = argv[2]; |
---|
55 | |
---|
56 | if (!out || strcmp(out, "-") == 0) { |
---|
57 | saveflags = "aS"; |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | GB_shell shell; |
---|
62 | GBDATA *gb_main = GB_open(in, readflags); |
---|
63 | if (!gb_main) { |
---|
64 | error = GB_await_error(); |
---|
65 | } |
---|
66 | else { |
---|
67 | error = GB_save(gb_main, out, saveflags); |
---|
68 | GB_close(gb_main); |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | if (error) { |
---|
73 | fprintf(stderr, "arb_2_ascii: Error: %s\n", error); |
---|
74 | return EXIT_FAILURE; |
---|
75 | } |
---|
76 | return EXIT_SUCCESS; |
---|
77 | } |
---|