File: arb_2_ascii.cxx

package info (click to toggle)
arb 6.0.2-1
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie-kfreebsd
  • size: 65,852 kB
  • sloc: ansic: 394,903; cpp: 250,252; makefile: 19,635; sh: 15,878; perl: 10,461; fortran: 6,019; ruby: 683; xml: 503; python: 53; awk: 32
file content (77 lines) | stat: -rw-r--r-- 2,542 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// =============================================================== //
//                                                                 //
//   File      : arb_2_ascii.cxx                                   //
//   Purpose   :                                                   //
//                                                                 //
//   Institute of Microbiology (Technical University Munich)       //
//   http://www.arb-home.de/                                       //
//                                                                 //
// =============================================================== //

#include <arbdb.h>
#include <arb_handlers.h>

int ARB_main(int argc, char *argv[]) {
    GB_ERROR error = 0;

    ARB_redirect_handlers_to(stderr, stderr);

    fprintf(stderr, "arb_2_ascii - ARB database binary to ascii converter\n");

    if (argc<2 || strcmp(argv[1], "--help") == 0) {
        fprintf(stderr,
                "\n"
                "Usage:   arb_2_ascii [-r] <source.arb> [<dest.arb>|-]\n"
                "Purpose: Converts a database to ascii format\n"
                "\n"
                "if '-r' (=recovery) is specified, try to fix problems while reading <source.arb>.\n"
                "\n"
                "if <dest.arb> is set, write to <dest.arb>\n"
                "if the second parameter is '-' write to console.\n"
                "else replace <source.arb> by ascii version (backup first)\n"
                "\n"
                );

        if (strcmp(argv[1], "--help") != 0) { error = "Missing arguments"; }
    }
    else {
        bool recovery = false; // try to recover corrupt data ?
        if (strcmp(argv[1], "-r") == 0) {
            recovery = true;
            argv++; argc--;
        }

        const char *in  = argv[1];
        const char *out = NULL;

        const char *readflags = recovery ? "rwR" : "rw";
        const char *saveflags = "a";

        if (argc == 2) {
            out = in;
        }
        else {
            out = argv[2];

            if (!out || strcmp(out, "-") == 0) {
                saveflags = "aS";
            }
        }

        GB_shell  shell;
        GBDATA   *gb_main = GB_open(in, readflags);
        if (!gb_main) {
            error = GB_await_error();
        }
        else {
            error = GB_save(gb_main, out, saveflags);
            GB_close(gb_main);
        }
    }

    if (error) {
        fprintf(stderr, "arb_2_ascii: Error: %s\n", error);
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}