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 }
option_alternative
Definition: options.h:80
p
struct @0 p
alt
struct option_alternative alt[4]
Definition: test_options.c:13
options.h
options_double
void options_double(struct option *, const char *name, double *p, double def_value, const char *desc)
Definition: options_interface.c:62
options_allocate
struct option * options_allocate(int n)
Definition: options_interface.c:16
options_int
void options_int(struct option *, const char *name, int *p, int def_value, const char *desc)
Definition: options_interface.c:39
params::file
const char * file
Definition: test_options.c:8
ops
struct option * ops
Definition: rb_sm.c:31
main
int main(int argc, const char *argv[])
Definition: test_options.c:19
params::algo
int algo
Definition: test_options.c:9
option
Definition: options.h:49
options_print_help
void options_print_help(struct option *options, FILE *f)
Definition: options.c:398
options_alternative
void options_alternative(struct option *, const char *name, struct option_alternative *alt, int *value, const char *desc)
Definition: options_interface.c:49
params::a_int
int a_int
Definition: test_options.c:6
params::a_double
double a_double
Definition: test_options.c:7
options_string
void options_string(struct option *, const char *name, const char **p, const char *def_balue, const char *desc)
Definition: options_interface.c:72
options_parse_args
int options_parse_args(struct option *ops, int argc, const char *argv[])
Definition: options.c:66
options_banner
void options_banner(const char *message)
Definition: options.c:33
params
Definition: carmen2pdf.c:20


csm
Author(s): Andrea Censi
autogenerated on Wed Aug 17 2022 02:50:34