29 #define FIXED_ARGS_WANTED 3
34 static inline const char *getarg(
int& argc,
const char**& argv) {
35 return argc>0 ? (--argc,*argv++) :
NULp;
37 inline const char *expect_arg(
int& argc,
const char**& argv) {
38 const char *arg = getarg(argc, argv);
40 error =
"expected argument missing";
47 "arb_calc_pvp -- calculate positional variability SAI\n"
48 "Usage: arb_calc_pvp [switches] <database> <treename> <aliname>\n"
51 "--savename <dbname> save database with different name\n"
52 " (default is to overwrite input <database>)\n"
53 "--tree-import <treefile> load tree from <treefile> + store in database as <treename>\n"
54 " (default: use tree existing in database)\n"
55 "--tree-delete delete tree <treename> (before saving database)\n"
56 "--sainame <sai> use alternate SAI name (default: POS_VAR_BY_PARSIMONY)\n"
62 void handle_fixed_argument(
const char *arg) {
67 case 0: database = arg;
break;
68 case 1: treename = arg;
break;
69 case 2: aliname = arg;
break;
76 if (!error) ++fixed_args;
80 const char *miss =
NULp;
82 case 0: miss =
"database";
break;
83 case 1: miss =
"treename";
break;
84 case 2: miss =
"aliname";
break;
92 void parse(
int& argc,
const char**& argv) {
93 const char *arg = getarg(argc, argv);
95 if (strcmp(arg,
"--savename") == 0) savename = expect_arg(argc, argv);
96 else if (strcmp(arg,
"--tree-import") == 0) treefile = expect_arg(argc, argv);
97 else if (strcmp(arg,
"--tree-delete") == 0) tree_delete =
true;
98 else if (strcmp(arg,
"--sainame") == 0) sainame = expect_arg(argc, argv);
100 else if (strcmp(arg,
"--help") == 0 || strcmp(arg,
"-h") == 0) helpWanted =
true;
102 else handle_fixed_argument(arg);
107 CLI(
int argc,
const char **argv) :
114 while (!error && argc>0 && !helpWanted) {
117 if (!error && !helpWanted) handle_fixed_argument(
NULp);
129 const char *
get_SAI_name()
const {
return sainame.empty() ?
"POS_VAR_BY_PARSIMONY" : sainame.c_str(); }
169 int main(
int argc,
char **argv) {
171 CLI args(argc, const_cast<const char**>(argv));
184 fprintf(stderr,
"Error in arb_calc_pvp: %s\n", error);
GBDATA * GB_open(const char *path, const char *opent)
const char * get_SAI_name() const
const char * get_treename() const
GB_ERROR TREE_load_to_db(GBDATA *gb_main, const char *treefile, const char *tree_name)
const char * GBS_global_string(const char *templat,...)
GB_ERROR GB_delete(GBDATA *&source)
GB_ERROR GB_await_error()
GB_ERROR GB_save_as(GBDATA *gbd, const char *path, const char *savetype)
#define FIXED_ARGS_WANTED
static void error(const char *msg)
const char * get_database() const
GB_ERROR PVP_calculate(GBDATA *gb_main, const char *ali_name, const char *tree_name, const char *target_SAI_name)
bool shall_delete_tree() const
const char * get_aliname() const
void show_help_if_useful() const
fputs(TRACE_PREFIX, stderr)
const char * get_treeimport_filename() const
const char * get_database_savename() const
CLI(int argc, const char **argv)
int main(int argc, char **argv)
GBDATA * GBT_find_tree(GBDATA *gb_main, const char *tree_name)
GB_transaction ta(gb_var)
bool shall_import_tree() const
static GB_ERROR calc_pvp(const CLI &args)
GB_ERROR get_error() const
void GB_close(GBDATA *gbd)