]> git.itanic.dy.fi Git - glucose/blob - options.c
Add copyright notices
[glucose] / options.c
1 /*
2  * Copyright (C) 2012 Timo Kokkonen <timo.t.kokkonen@iki.fi>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA
18  */
19
20 #include <getopt.h>
21 #include <string.h>
22 #include <stdlib.h>
23
24 #include "options.h"
25
26 int read_args(int argc, char *argv[], struct user_options *opts)
27 {
28         int option_index = 0, c;
29         static struct option long_options[] = {
30                 { .val = 'd', .name = "device", .has_arg = 1, },
31                 { .val = 'v', .name = "verbose", .has_arg = 2 },
32                 { .val = 'o', .name = "output", .has_arg = 1 },
33         };
34         char short_options[] = "d:v:o:";
35
36         memset(opts, 0, sizeof(*opts));
37
38         while (1) {
39                 c = getopt_long(argc, argv, short_options, long_options,
40                                 &option_index);
41
42                 if (c == -1)
43                         break;
44
45                 switch (c) {
46                 case 'd':
47                         opts->usbdev = optarg;
48                         break;
49                 case 'v':
50                         if (optarg)
51                                 opts->trace_level = atoi(optarg);
52                         else
53                                 opts->trace_level++;
54                 case 'o':
55                         opts->output_path = optarg;
56                         break;
57                 case '?':
58                         return -1;
59                 }
60         }
61
62         while (optind < argc) {
63                 /*
64                  * Some day we do something useful here with the rest
65                  * of the options.. Maybe
66                  */
67                 optind++;
68         }
69
70         return 0;
71 }