]> git.itanic.dy.fi Git - glucose/blob - options.c
utils: Add sanitize_ascii()
[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         };
14         char short_options[] = "d:v";
15
16         memset(opts, 0, sizeof(*opts));
17
18         while (1) {
19                 c = getopt_long(argc, argv, short_options, long_options,
20                                 &option_index);
21
22                 if (c == -1)
23                         break;
24
25                 switch (c) {
26                 case 'd':
27                         opts->usbdev = optarg;
28                         break;
29                 case 'v':
30                         if (optarg)
31                                 opts->trace_level = atoi(optarg);
32                         else
33                                 opts->trace_level++;
34                 case '?':
35                         return -1;
36                 }
37         }
38
39         while (optind < argc) {
40                 /*
41                  * Some day we do something useful here with the rest
42                  * of the options.. Maybe
43                  */
44                 optind++;
45         }
46
47         return 0;
48 }