}
static enum mode
-parse_options_mode(int argc, char **argv, const char **path)
+parse_options_mode(int argc, char **argv)
{
int c;
int option_index = 0;
if (argc < 2)
return mode;
- while (1) {
+ while (mode == MODE_NONE) {
c = getopt_long(argc, argv, "h", opts, &option_index);
if (c == -1)
break;
}
}
- if (optind >= argc)
+ if (optind >= argc && mode != MODE_HELP)
return MODE_NONE;
- *path = argv[optind];
-
return mode;
}
{
struct libevdev *dev = NULL;
int fd = -1;
- int rc = 1;
+ int rc = EXIT_FAILURE;
enum mode mode;
const char *path;
struct input_absinfo absinfo;
int xres = 0,
yres = 0;
- mode = parse_options_mode(argc, argv, &path);
+ mode = parse_options_mode(argc, argv);
switch (mode) {
case MODE_HELP:
rc = EXIT_SUCCESS;
if (rc != EXIT_SUCCESS)
goto out;
+ if (optind >= argc) {
+ rc = EXIT_FAILURE;
+ usage();
+ goto out;
+ }
+
+ path = argv[optind];
+
fd = open(path, O_RDWR);
if (fd < 0) {
+ rc = EXIT_FAILURE;
perror("Failed to open device");
goto out;
}