doc: typo
[barvinok.git] / summate.cc
blob516903fd1f147f22f6a7f687c3e6936801305dab
1 #include <iostream>
2 #include <barvinok/evalue.h>
3 #include <barvinok/options.h>
4 #include <barvinok/util.h>
5 #include "argp.h"
6 #include "progname.h"
7 #include "evalue_convert.h"
8 #include "evalue_read.h"
10 using std::cout;
11 using std::cerr;
12 using std::endl;
14 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
16 #define OPT_VARS (BV_OPT_LAST+1)
18 struct argp_option argp_options[] = {
19 { "variables", OPT_VARS, "list", 0,
20 "comma separated list of variables over which to maximize" },
21 { "verbose", 'v', 0, 0, },
22 { 0 }
25 struct options {
26 struct convert_options convert;
27 struct barvinok_options *barvinok;
28 char* var_list;
29 int verbose;
32 static error_t parse_opt(int key, char *arg, struct argp_state *state)
34 struct options *options = (struct options*) state->input;
36 switch (key) {
37 case ARGP_KEY_INIT:
38 state->child_inputs[0] = &options->convert;
39 state->child_inputs[1] = &options->barvinok;
40 options->var_list = NULL;
41 options->verbose = 0;
42 break;
43 case 'v':
44 options->verbose = 1;
45 break;
46 case OPT_VARS:
47 options->var_list = strdup(arg);
48 break;
49 default:
50 return ARGP_ERR_UNKNOWN;
52 return 0;
55 int main(int argc, char **argv)
57 evalue *EP;
58 char **all_vars = NULL;
59 unsigned nvar;
60 unsigned nparam;
61 struct options options;
62 struct barvinok_options *bv_options = barvinok_options_new_with_defaults();
63 static struct argp_child argp_children[] = {
64 { &convert_argp, 0, "input conversion", 1 },
65 { &barvinok_argp, 0, "barvinok options", 3 },
66 { 0 }
68 static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children };
69 int result = 0;
71 options.barvinok = bv_options;
72 set_program_name(argv[0]);
73 argp_parse(&argp, argc, argv, 0, 0, &options);
75 EP = evalue_read_from_file(stdin, options.var_list, &all_vars,
76 &nvar, &nparam, bv_options->MaxRays);
77 assert(EP);
79 evalue_convert(EP, &options.convert, options.verbose, nparam, all_vars);
81 if (EVALUE_IS_ZERO(*EP))
82 print_evalue(stdout, EP, all_vars);
83 else {
84 evalue *sum = esum(EP, nvar);
85 print_evalue(stdout, sum, all_vars+nvar);
86 free_evalue_refs(sum);
87 free(sum);
90 free_evalue_refs(EP);
91 free(EP);
93 if (options.var_list)
94 free(options.var_list);
95 Free_ParamNames(all_vars, nvar+nparam);
96 barvinok_options_free(bv_options);
97 return result;