test_options.c
Go to the documentation of this file.
1 #include "options.h"
2 
3 
4 
5 struct params {
6  int a_int;
7  double a_double;
8  const char * file;
9  int algo;
10 };
11 
12 
13 struct option_alternative alt[4] = {
14  {"PLICP", 3, "a new algorithm"},
15  {"ICP", 4, "the standard"},
16  {"MbICP", 5, "good for rotations"}, {0,0,0}
17 };
18 
19 int main(int argc, const char*argv[]) {
20  options_banner("This is a test program for the options library.");
21 
22  struct params p;
23 
24  struct option* ops = options_allocate(3);
25  options_int (ops, "i", &p.a_int, 42, "An int parameter");
26  options_double (ops, "d", &p.a_double, 0.42, "A double parameter");
27  options_string (ops, "s", &p.file , "Hello", "A file parameter");
28  options_alternative(ops, "algorith", alt, &p.algo, "which algorithm to use" );
29 
30 
31  if(!options_parse_args(ops, argc, argv)) {
32  printf("A simple program.\n\nUsage:\n");
33  options_print_help(ops, stderr);
34  return -1;
35  }
36 
37  printf("i: %d \n", p.a_int);
38  printf("d: %g \n", p.a_double);
39  printf("s: %s \n", p.file);
40 
41  return 0;
42 }
void options_banner(const char *message)
Definition: options.c:33
int algo
Definition: test_options.c:9
void options_double(struct option *, const char *name, double *p, double def_value, const char *desc)
struct option * ops
Definition: rb_sm.c:31
struct option_alternative alt[4]
Definition: test_options.c:13
Definition: options.h:49
int main(int argc, const char *argv[])
Definition: test_options.c:19
struct option * options_allocate(int n)
void options_int(struct option *, const char *name, int *p, int def_value, const char *desc)
const char * file
Definition: test_options.c:8
int a_int
Definition: test_options.c:6
void options_print_help(struct option *options, FILE *f)
Definition: options.c:398
void options_alternative(struct option *, const char *name, struct option_alternative *alt, int *value, const char *desc)
void options_string(struct option *, const char *name, const char **p, const char *def_balue, const char *desc)
double a_double
Definition: test_options.c:7
int options_parse_args(struct option *ops, int argc, const char *argv[])
Definition: options.c:66


csm
Author(s): Andrea Censi
autogenerated on Tue May 11 2021 02:18:23