void-packages/srcpkgs/mouseemu/patches/003-usage.patch
q66 b004d06c23 New package: mouseemu-0.15
This is a daemon which allows you to emulate middle and right
click as well as a mouse wheel. It was originally written for
Apple PowerPC laptops with a single button, but can be used on
any hardware.
2020-02-09 03:10:27 +01:00

143 lines
4 KiB
Diff

Author: <gaudenz@debian.org>
Description: print usage message to stderr for wrong arguments
--- a/mouseemu.c
+++ b/mouseemu.c
@@ -517,6 +517,31 @@
}
+/* print usage message to stdout/stderr */
+void usage(FILE *stream, char *argv[]) {
+ fprintf(stream, "usage: %s \n"
+ "\t[-middle B2_MOD B2_KEY]\n"
+ "\t[-right B3_MOD B3_KEY]\n"
+ "\t[-scroll SCROLL_MOD]\n"
+ "\t[-typing-block DELAY]\n"
+ "\t[-device UINPUT_DEVICE]\n"
+ "\t[-nofork]\n",
+ argv[0]);
+ fprintf(stream, "All modifier and button key arguments are\n"
+ "key scancodes. They can be found in \n"
+ "/usr/src/linux/include/linux/input.h,\n"
+ "or by using `showkey` in a console.\n"
+ "Use decimal values. BTN_LEFT(272) is usable as "
+ "B2_KEY or B3_KEY.\n\n");
+ fprintf(stream, "Default uinput device: " DEFAULT_UINPUT ".\n");
+ fprintf(stream, "Default keys:\n"
+ "\tMiddle click : F10 (0 68)\n"
+ "\tRight click : F11 (0 87)\n"
+ "\tScroll mod. : Alt (56)\n"
+ "\tDefault blocking time while typing: 300ms\n");
+
+ exit(0);
+}
int main(int argc, char *argv[])
{
@@ -535,72 +560,59 @@
if (argc > 1) {
int i = 0;
if (!strcmp(argv[1],"-help")) {
-err:
- printf("usage: %s \n"
- "\t[-middle B2_MOD B2_KEY]\n"
- "\t[-right B3_MOD B3_KEY]\n"
- "\t[-scroll SCROLL_MOD]\n"
- "\t[-typing-block DELAY]\n"
- "\t[-device UINPUT_DEVICE]\n"
- "\t[-nofork]\n",
- argv[0]);
- printf("Key codes can be found in "
- "/usr/src/linux/include/linux/input.h,\n"
- "or by using `showkey` in console.\n"
- "Use decimal values. BTN_LEFT(272) is usable as "
- "B2_KEY or B3_KEY.\n\n");
- printf("Default uinput device: " DEFAULT_UINPUT ".\n");
- printf("Default keys:\n"
- "\tMiddle click : F10 (0 68)\n"
- "\tRight click : F11 (0 87)\n"
- "\tScroll mod. : Alt (56)\n"
- "\tDefault blocking time while typing: 300ms\n");
-
- exit(0);
+ usage(stdout, argv);
} else {
- for (i = 1; i < argc; i++) {
- int j = i+1;
+ i = 1;
+ while (i < argc) {
if (!strcmp(argv[i], "-middle")) {
- if (argc > j+1) {
- b2_mod = atoi(argv[j]);
- b2_key = atoi(argv[j+1]);
+ if (argc > i+2) {
+ b2_mod = atoi(argv[i+1]);
+ b2_key = atoi(argv[i+2]);
+ i += 3;
} else
- goto err;
+ usage(stderr, argv);
continue;
}
- if (!strcmp(argv[i], "-right")) {
- if (argc > j+1) {
- b3_mod = atoi(argv[j]);
- b3_key = atoi(argv[j+1]);
+ else if (!strcmp(argv[i], "-right")) {
+ if (argc > i+2) {
+ b3_mod = atoi(argv[i+1]);
+ b3_key = atoi(argv[i+2]);
+ i += 3;
} else
- goto err;
+ usage(stderr, argv);
continue;
}
- if (!strcmp(argv[i], "-scroll")) {
- if (argc > j) {
- scroll_mod = atoi(argv[j]);
+ else if (!strcmp(argv[i], "-scroll")) {
+ if (argc > i+1) {
+ scroll_mod = atoi(argv[i+1]);
+ i += 2;
} else
- goto err;
+ usage(stderr, argv);
continue;
}
- if (!strcmp(argv[i], "-typing-block")) {
- if (argc > j) {
- typing_block_delay = atoi(argv[j]);
+ else if (!strcmp(argv[i], "-typing-block")) {
+ if (argc > i+1) {
+ typing_block_delay = atoi(argv[i+1]);
+ i += 2;
} else
- goto err;
+ usage(stderr, argv);
continue;
}
- if (!strcmp(argv[i], "-device")) {
- if (argc > j) {
- uinputdev = argv[j];
+ else if (!strcmp(argv[i], "-device")) {
+ if (argc > i+1) {
+ uinputdev = argv[i+1];
+ i += 2;
} else
- goto err;
+ usage(stderr, argv);
continue;
}
- if (!strcmp(argv[i], "-nofork")) {
+ else if (!strcmp(argv[i], "-nofork")) {
nofork=1;
+ i += 1;
continue;
- }
+ } else {
+ usage(stderr, argv);
+ }
}
}
}