diff options
author | B. Watson <urchlay@slackware.uk> | 2025-05-12 07:02:39 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2025-05-12 07:02:39 -0400 |
commit | 41d4d3afab82d46e5fe8d2ee2e48e065035c7d88 (patch) | |
tree | 159d916c949acbcd3c0ba6dc04fed404ecb69871 | |
parent | e1c18d7ed3c9e8cfea8176fe4754896cb8bac506 (diff) | |
download | marsond-41d4d3afab82d46e5fe8d2ee2e48e065035c7d88.tar.gz |
tighten up parse_args() some more.
-rw-r--r-- | marsond.8 | 20 | ||||
-rw-r--r-- | marsond.c | 20 | ||||
-rw-r--r-- | marsond.rst | 14 |
3 files changed, 41 insertions, 13 deletions
@@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. -.TH "MARSOND" 8 "2025-05-11" "0.3.0" "Urchlay's Stuff" +.TH "MARSOND" 8 "2025-05-12" "0.3.0" "Urchlay's Stuff" .SH NAME marsond \- Fix Enter key timing on Marson/USBLink/MT606-1 PS/2-USB adaptors .SH SYNOPSIS @@ -59,7 +59,7 @@ Options can be "bundled": \fB\-vf\fP is the same as \fB\-v\fP \fB\-f\fP\&. .TP .BI \-d \ delay\-ms Amount of time in milliseconds to delay the Enter key release events. -Default: 30. +Minimum 1, default 30 (unless changed at compile time; see \fB\-\-help\fP). .UNINDENT .\" delay time for Enter key release. . @@ -75,7 +75,18 @@ daemon. In this mode, \fBmarsond\fP can be killed with \fI^C\fP\&. .TP .BI \-k \ keyboard\-device Input device for the keyboard adaptor. Default: +.INDENT 7.0 +.INDENT 3.5 +.sp +.nf +.ft C /dev/input/by\-id/usb\-Marson_Marson_Keyboard_and_Mouse_Link_Ver:ps2120L\-event\-kbd +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +\&...unless changed at compile time; see \fB\-\-help\fP\&. .UNINDENT .\" keyboard device (usually under /dev/input/by-id/). . @@ -85,7 +96,7 @@ Input device for the keyboard adaptor. Default: Amount of time in milliseconds to pause at startup, before opening the keyboard and uinput devices. May be useful on slow systems, if \fBmarsond\fP won\(aqt consistently start from udev, but works fine -if started manually. Default: 0. +if started manually. Minimum 0, default 0. .UNINDENT .\" pause before opening keyboard/uinput devs (default 0). . @@ -102,7 +113,8 @@ background as a daemon. If you want to debug the event loop, combine .INDENT 0.0 .TP .B \-h\fP,\fB \-\-help -Shows built\-in usage message and exits. +Shows built\-in usage message and exits. This includes the +compiled\-in defaults for the \fB\-d\fP and \fB\-k\fP options. .UNINDENT .\" this help text. . @@ -93,6 +93,17 @@ void version(void) { puts(VERSION); } +int parse_num(const char *num, char opt, int min) { + char *end; + int result; + + result = (int)strtol(num, &end, 10); + if(*end || (result < min)) { + die("%c option expects an integer >= %d, not '%s'", opt, min, num); + } + return result; +} + void parse_args(int argc, char **argv) { int opt; @@ -110,11 +121,11 @@ void parse_args(int argc, char **argv) { while( (opt = getopt(argc, argv, ":d:hfk:p:vV")) != -1) { switch(opt) { - case 'd': delay_ms = atoi(optarg); break; + case 'd': delay_ms = parse_num(optarg, 'd', 1); break; case 'f': foreground++; break; case 'h': print_help(); exit(0); break; case 'k': keyboard_dev = optarg; break; - case 'p': pause_ms = atoi(optarg); break; + case 'p': pause_ms = parse_num(optarg, 'p', 0); break; case 'v': debugging++; break; case 'V': version(); exit(0); break; case ':': die("option -%c requires an argument (try --help)", optopt); break; @@ -122,8 +133,9 @@ void parse_args(int argc, char **argv) { } } - if(delay_ms < 1) die("invalid -d argument"); - if(pause_ms < 0) die("invalid -p argument"); + if(optind < argc) { + die("unknown argument: %s", argv[optind]); + } } /* cleanup() gets called by die() and sighandler() */ diff --git a/marsond.rst b/marsond.rst index 2e705f6..c21554f 100644 --- a/marsond.rst +++ b/marsond.rst @@ -45,7 +45,7 @@ Options can be "bundled": **-vf** is the same as **-v** **-f**. -d delay-ms Amount of time in milliseconds to delay the Enter key release events. - Default: 30. + Minimum 1, default 30 (unless changed at compile time; see **--help**). .. delay time for Enter key release. @@ -56,8 +56,11 @@ Options can be "bundled": **-vf** is the same as **-v** **-f**. .. run in foreground, not as a daemon. -k keyboard-device - Input device for the keyboard adaptor. Default: - /dev/input/by-id/usb-Marson_Marson_Keyboard_and_Mouse_Link_Ver:ps2120L-event-kbd + Input device for the keyboard adaptor. Default:: + + /dev/input/by-id/usb-Marson_Marson_Keyboard_and_Mouse_Link_Ver:ps2120L-event-kbd + + \.\.\.unless changed at compile time; see **--help**. .. keyboard device (usually under /dev/input/by-id/). @@ -65,7 +68,7 @@ Options can be "bundled": **-vf** is the same as **-v** **-f**. Amount of time in milliseconds to pause at startup, before opening the keyboard and uinput devices. May be useful on slow systems, if **marsond** won't consistently start from udev, but works fine - if started manually. Default: 0. + if started manually. Minimum 0, default 0. .. pause before opening keyboard/uinput devs (default 0). @@ -78,7 +81,8 @@ Options can be "bundled": **-vf** is the same as **-v** **-f**. .. verbose debugging. -h, --help - Shows built-in usage message and exits. + Shows built-in usage message and exits. This includes the + compiled-in defaults for the **-d** and **-k** options. .. this help text. |