From 170d1bc4db5f7efabab6aed46f0a45e5dc3c2505 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 8 Apr 2007 16:51:12 +0200 Subject: [PATCH] options.c: separate polynomial approximation related options --- barvinok/options.h | 3 ++ barvinok_enumerate.cc | 4 +-- barvinok_enumerate_e.cc | 4 +-- options.c | 90 ++++++++++++++++++++++++++++++++----------------- 4 files changed, 66 insertions(+), 35 deletions(-) diff --git a/barvinok/options.h b/barvinok/options.h index d932d1e..07a01d9 100644 --- a/barvinok/options.h +++ b/barvinok/options.h @@ -88,6 +88,9 @@ void barvinok_options_free(struct barvinok_options *options); #define BV_OPT_SCALE 263 #define BV_OPT_LAST 263 +#define BV_GRP_APPROX 1 +#define BV_GRP_LAST 1 + struct argp; extern struct argp barvinok_argp; diff --git a/barvinok_enumerate.cc b/barvinok_enumerate.cc index 69db7b5..4b99fcf 100644 --- a/barvinok_enumerate.cc +++ b/barvinok_enumerate.cc @@ -467,8 +467,8 @@ int main(int argc, char **argv) struct arguments options; static struct argp_child argp_children[] = { { &barvinok_argp, 0, 0, 0 }, - { &verify_argp, 0, "verification", 1 }, - { &convert_argp, 0, "output conversion", 2 }, + { &verify_argp, 0, "verification", BV_GRP_LAST+1 }, + { &convert_argp, 0, "output conversion", BV_GRP_LAST+2 }, { 0 } }; static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; diff --git a/barvinok_enumerate_e.cc b/barvinok_enumerate_e.cc index 8155c11..ffb9271 100644 --- a/barvinok_enumerate_e.cc +++ b/barvinok_enumerate_e.cc @@ -114,8 +114,8 @@ int main(int argc, char **argv) struct arguments arguments; static struct argp_child argp_children[] = { { &barvinok_argp, 0, 0, 0 }, - { &verify_argp, 0, "verification", 1 }, - { &convert_argp, 0, "output conversion", 2 }, + { &verify_argp, 0, "verification", BV_GRP_LAST+1 }, + { &convert_argp, 0, "output conversion", BV_GRP_LAST+2 }, { 0 } }; static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; diff --git a/options.c b/options.c index 37abd9f..1fc7552 100644 --- a/options.c +++ b/options.c @@ -109,52 +109,32 @@ const char *scale_opts[] = { NULL }; -struct argp_option barvinok_argp_options[] = { +static struct argp_option approx_argp_options[] = { + { "polynomial-approximation", BV_OPT_POLAPPROX, "lower|upper", 1 }, + { "approximation-method", BV_OPT_APPROX, "scale|drop|volume", 0, + "method to use in polynomial approximation [default: drop]" }, + { "scale-options", BV_OPT_SCALE, "fast|slow,narrow|narrow2", 0 }, + { 0 } +}; + +static struct argp_option barvinok_argp_options[] = { { "index", BV_OPT_MAXINDEX, "int", 0, "maximal index of simple cones in decomposition" }, { "primal", BV_OPT_PRIMAL, 0, 0 }, { "table", BV_OPT_TABLE, 0, 0 }, { "specialization", BV_OPT_SPECIALIZATION, "[bf|df|random]", 0 }, - { "polynomial-approximation", BV_OPT_POLAPPROX, "lower|upper", 1 }, - { "approximation-method", BV_OPT_APPROX, "scale|drop|volume", 0, - "method to use in polynomial approximation [default: drop]" }, - { "scale-options", BV_OPT_SCALE, "fast|slow,narrow|narrow2", 0 }, { "gbr", BV_OPT_GBR, "[cdd]", 0, "solver to use for basis reduction" }, { "version", 'V', 0, 0 }, { 0 } }; -error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state) +static error_t approx_parse_opt(int key, char *arg, struct argp_state *state) { struct barvinok_options *options = state->input; char *subopt; switch (key) { - case 'V': - printf(barvinok_version()); - exit(0); - case BV_OPT_SPECIALIZATION: - if (!strcmp(arg, "bf")) - options->incremental_specialization = BV_SPECIALIZATION_BF; - else if (!strcmp(arg, "df")) - options->incremental_specialization = BV_SPECIALIZATION_DF; - else if (!strcmp(arg, "random")) - options->incremental_specialization = BV_SPECIALIZATION_RANDOM; - break; - case BV_OPT_PRIMAL: - options->primal = 1; - break; - case BV_OPT_TABLE: - options->lookup_table = 1; - break; - case BV_OPT_GBR: - if (!strcmp(arg, "cdd")) - options->gbr_lp_solver = BV_GBR_CDD; - break; - case BV_OPT_MAXINDEX: - options->max_index = strtoul(arg, NULL, 0); - break; case BV_OPT_POLAPPROX: if (!arg) { options->polynomial_approximation = BV_APPROX_SIGN_APPROX; @@ -215,6 +195,54 @@ error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state) return 0; } +static error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state) +{ + struct barvinok_options *options = state->input; + char *subopt; + + switch (key) { + case ARGP_KEY_INIT: + state->child_inputs[0] = options; + break; + case 'V': + printf(barvinok_version()); + exit(0); + case BV_OPT_SPECIALIZATION: + if (!strcmp(arg, "bf")) + options->incremental_specialization = BV_SPECIALIZATION_BF; + else if (!strcmp(arg, "df")) + options->incremental_specialization = BV_SPECIALIZATION_DF; + else if (!strcmp(arg, "random")) + options->incremental_specialization = BV_SPECIALIZATION_RANDOM; + break; + case BV_OPT_PRIMAL: + options->primal = 1; + break; + case BV_OPT_TABLE: + options->lookup_table = 1; + break; + case BV_OPT_GBR: + if (!strcmp(arg, "cdd")) + options->gbr_lp_solver = BV_GBR_CDD; + break; + case BV_OPT_MAXINDEX: + options->max_index = strtoul(arg, NULL, 0); + break; + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +static struct argp approx_argp = { + approx_argp_options, approx_parse_opt, 0, 0 +}; + +static struct argp_child barvinok_children[] = { + { &approx_argp, 0, "polynomial approximation", BV_GRP_APPROX }, + { 0 } +}; + struct argp barvinok_argp = { - barvinok_argp_options, barvinok_parse_opt, 0, 0 + barvinok_argp_options, barvinok_parse_opt, 0, 0, barvinok_children }; -- 2.11.4.GIT