]> git.itanic.dy.fi Git - glucose/blob - options.c
Read options from command line
[glucose] / options.c
1 #include <getopt.h>
2 #include <string.h>
3
4 #include "options.h"
5
6 int read_args(int argc, char *argv[], struct user_options *opts)
7 {
8         int option_index = 0, c;
9         static struct option long_options[] = {
10                 { .val = 'd', .name = "device", .has_arg = 1, },
11                 { .val = 'v', .name = "verbose", },
12         };
13         char short_options[] = "d:v";
14
15         memset(opts, 0, sizeof(*opts));
16
17         while (1) {
18                 c = getopt_long(argc, argv, short_options, long_options,
19                                 &option_index);
20
21                 if (c == -1)
22                         break;
23
24                 switch (c) {
25                 case 'd':
26                         opts->usbdev = optarg;
27                         break;
28                 case 'v':
29                         opts->trace_level++;
30                 case '?':
31                         return -1;
32                 }
33         }
34
35         while (optind < argc) {
36                 /*
37                  * Some day we do something useful here with the rest
38                  * of the options.. Maybe
39                  */
40                 optind++;
41         }
42
43         return 0;
44 }