LD = ld
CFLAGS = -Wall -O2 -g
-GLUCOSE_OBJS = main.o hiddev.o utils.o
+GLUCOSE_OBJS = main.o hiddev.o utils.o options.o
ALL_OBJS = $(GLUCOSE_OBJS)
ALL_DEBS = $(shell echo " "$(ALL_OBJS) | sed -e "s,[^ ]*\.a,,g" -e \
#include "hiddev.h"
#include "utils.h"
+#include "options.h"
struct msg {
int main(int argc, char *argv[])
{
int fd, usage_code;
+ struct user_options opts;
- fd = hiddev_open(argv[1], &usage_code);
+ read_args(argc, argv, &opts);
+
+ if (opts.usbdev == NULL) {
+ trace(0, "USB dev name needs to be give with '-d' parameter\n");
+ return 1;
+ }
+
+ fd = hiddev_open(opts.usbdev, &usage_code);
if (fd < 0)
return 1;
--- /dev/null
+#include <getopt.h>
+#include <string.h>
+
+#include "options.h"
+
+int read_args(int argc, char *argv[], struct user_options *opts)
+{
+ int option_index = 0, c;
+ static struct option long_options[] = {
+ { .val = 'd', .name = "device", .has_arg = 1, },
+ { .val = 'v', .name = "verbose", },
+ };
+ char short_options[] = "d:v";
+
+ memset(opts, 0, sizeof(*opts));
+
+ while (1) {
+ c = getopt_long(argc, argv, short_options, long_options,
+ &option_index);
+
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'd':
+ opts->usbdev = optarg;
+ break;
+ case 'v':
+ opts->trace_level++;
+ case '?':
+ return -1;
+ }
+ }
+
+ while (optind < argc) {
+ /*
+ * Some day we do something useful here with the rest
+ * of the options.. Maybe
+ */
+ optind++;
+ }
+
+ return 0;
+}