source: tags/arb_5.0/TOOLS/arb_2_ascii.cxx

Last change on this file was 5894, checked in by westram, 15 years ago
  • reactivated original GB_close
  • removed GB_exit (use GB_close)
  • gb_delete_entry now takes and invalidates a GBDATA (to avoid further undetected usage)
  • gb_do_callback_list called with GB_MAIN_TYPE (instead of possibly already deleted gb_main)
  • added some missing transactions
  • moved declaration of GBDATA into arbdb_base.h (and include where needed)
  • GB_MAIN_TYPE is no longer void
  • AW_default is no longer void
  • replaced the 3 differing ways to exit EDIT4 by ED4_exit()
  • added AW_root::unlink_awars_from_DB() and call in arb_ntree, arb_dist, arb_edit4, arb_pars and arb_phylo
  • rewrote arb_2_ascii, arb_2_bin, arb_perf_test, arb_read_tree (single exit point, error handling)
  • unlinked AWARs now return "" not "?????"
  • AW_awar::read_string works only with awars of type AW_STRING. Added assertion + fixed one wrong usage.
  • inlined AW_awar::get()
  • added AW_awar::remove_all_callbacks() and AW_awar::remove_all_target_vars()
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.8 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <arbdb.h>
5
6static void to_stderr(const char *msg) {
7    fprintf(stderr, "arb_2_ascii: %s\n", msg);
8}
9
10int main(int argc, char **argv) {
11    GB_ERROR error = 0;
12
13    fprintf(stderr, "arb_2_ascii - ARB database binary to ascii converter\n");
14
15    if (argc<2 || strcmp(argv[1], "--help") == 0) {
16        fprintf(stderr,
17                "\n"
18                "Usage:   arb_2_ascii <source.arb> [<dest.arb>|-]\n"
19                "Purpose: Converts a database to ascii format\n"
20                "\n"
21                "if <dest.arb> is set, try to fix problems of <source.arb> and write to <dest.arb>\n"
22                "if the second parameter is '-' print to console.\n"
23                "else replace <source.arb> by ascii version (backup first)\n"
24                "\n"
25                );
26
27        if (strcmp(argv[1], "--help") != 0) { error = "Missing arguments"; }
28    }
29    else {
30        char *in  = argv[1];
31        char *out = NULL;
32   
33        const char *readflags = "rw";
34        const char *saveflags = "a";
35
36        if (argc == 2) {
37            out = in;
38        }
39        else {
40            readflags = "rwR";      /* try to recover corrupt data */
41            out       = argv[2];
42
43            if (!out || strcmp(out, "-") == 0) {
44                saveflags      = "aS";
45                GB_install_information(to_stderr);
46                GB_install_warning(to_stderr);
47            }
48        }
49
50        GBDATA   *gb_main = GB_open(in,readflags);
51        if (!gb_main) {
52            error = GB_await_error();
53        }
54        else {
55            error = GB_save(gb_main,out, saveflags);
56        }
57
58        GB_close(gb_main);
59    }
60   
61    if (error) {
62        fprintf(stderr, "arb_2_ascii: Error: %s\n", error);
63        return EXIT_FAILURE;
64    }
65    return EXIT_SUCCESS;
66}
Note: See TracBrowser for help on using the repository browser.