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