mirror of
git://git.suckless.org/svkbd
synced 2024-12-18 12:14:46 +00:00
improve command-line parsing, fix crash with -fn without argument
Print the usage information instead of silently continuing. On an invalid argument print the invalid argument and usage.
This commit is contained in:
parent
55de8b5184
commit
d6026943d3
15
svkbd.c
15
svkbd.c
@ -1151,12 +1151,11 @@ main(int argc, char *argv[])
|
|||||||
die("svkbd-"VERSION);
|
die("svkbd-"VERSION);
|
||||||
} else if (!strcmp(argv[i], "-d")) {
|
} else if (!strcmp(argv[i], "-d")) {
|
||||||
isdock = True;
|
isdock = True;
|
||||||
continue;
|
|
||||||
} else if (!strncmp(argv[i], "-g", 2)) {
|
} else if (!strncmp(argv[i], "-g", 2)) {
|
||||||
if (i >= argc - 1)
|
if (i >= argc - 1)
|
||||||
continue;
|
usage(argv[0]);
|
||||||
|
|
||||||
bitm = XParseGeometry(argv[i + 1], &xr, &yr, &wr, &hr);
|
bitm = XParseGeometry(argv[++i], &xr, &yr, &wr, &hr);
|
||||||
if (bitm & XValue)
|
if (bitm & XValue)
|
||||||
wx = xr;
|
wx = xr;
|
||||||
if (bitm & YValue)
|
if (bitm & YValue)
|
||||||
@ -1169,8 +1168,9 @@ main(int argc, char *argv[])
|
|||||||
wx = -1;
|
wx = -1;
|
||||||
if (bitm & YNegative && wy == 0)
|
if (bitm & YNegative && wy == 0)
|
||||||
wy = -1;
|
wy = -1;
|
||||||
i++;
|
|
||||||
} else if (!strcmp(argv[i], "-fn")) { /* font or font set */
|
} else if (!strcmp(argv[i], "-fn")) { /* font or font set */
|
||||||
|
if (i >= argc - 1)
|
||||||
|
usage(argv[0]);
|
||||||
fonts[0] = estrdup(argv[++i]);
|
fonts[0] = estrdup(argv[++i]);
|
||||||
} else if (!strcmp(argv[i], "-D")) {
|
} else if (!strcmp(argv[i], "-D")) {
|
||||||
debug = 1;
|
debug = 1;
|
||||||
@ -1186,19 +1186,20 @@ main(int argc, char *argv[])
|
|||||||
pressonrelease = 0;
|
pressonrelease = 0;
|
||||||
} else if (!strcmp(argv[i], "-l")) {
|
} else if (!strcmp(argv[i], "-l")) {
|
||||||
if (i >= argc - 1)
|
if (i >= argc - 1)
|
||||||
continue;
|
usage(argv[0]);
|
||||||
free(layer_names_list);
|
free(layer_names_list);
|
||||||
layer_names_list = estrdup(argv[++i]);
|
layer_names_list = estrdup(argv[++i]);
|
||||||
} else if (!strcmp(argv[i], "-s")) {
|
} else if (!strcmp(argv[i], "-s")) {
|
||||||
if (i >= argc - 1)
|
if (i >= argc - 1)
|
||||||
continue;
|
usage(argv[0]);
|
||||||
initial_layer_name = argv[++i];
|
initial_layer_name = argv[++i];
|
||||||
} else if (!strcmp(argv[i], "-H")) {
|
} else if (!strcmp(argv[i], "-H")) {
|
||||||
if (i >= argc - 1)
|
if (i >= argc - 1)
|
||||||
continue;
|
usage(argv[0]);
|
||||||
heightfactor = atoi(argv[++i]);
|
heightfactor = atoi(argv[++i]);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Invalid argument: %s\n", argv[i]);
|
fprintf(stderr, "Invalid argument: %s\n", argv[i]);
|
||||||
|
usage(argv[0]);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user