1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-22 06:38:37 -05:00

uxserver.c: 'longoptnoarg' matching function.

Replaces a couple of existing strcmp, and does just slightly better
because as well as matching "--verbose" (say) it also matches
"--verbose=foo" and gives a comprehensible error message about it.
This commit is contained in:
Simon Tatham 2019-03-30 07:27:57 +00:00
parent 75fccc5d58
commit 4bb1867788

View File

@ -353,6 +353,21 @@ static bool longoptarg(const char *arg, const char *expected,
return false; return false;
} }
static bool longoptnoarg(const char *arg, const char *expected)
{
int len = strlen(expected);
if (memcmp(arg, expected, len))
return false;
if (arg[len] == '=') {
fprintf(stderr, "%s: option %s expects no argument\n",
appname, expected);
exit(1);
} else if (arg[len] == '\0') {
return true;
}
return false;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int *fdlist; int *fdlist;
@ -395,9 +410,9 @@ int main(int argc, char **argv)
if (!strcmp(arg, "--help")) { if (!strcmp(arg, "--help")) {
show_help(stdout); show_help(stdout);
exit(0); exit(0);
} else if (!strcmp(arg, "--version")) { } else if (longoptnoarg(arg, "--version")) {
show_version_and_exit(); show_version_and_exit();
} else if (!strcmp(arg, "--verbose") || !strcmp(arg, "-v")) { } else if (longoptnoarg(arg, "--verbose") || !strcmp(arg, "-v")) {
verbose = true; verbose = true;
} else if (longoptarg(arg, "--hostkey", &val, &argc, &argv)) { } else if (longoptarg(arg, "--hostkey", &val, &argc, &argv)) {
Filename *keyfile; Filename *keyfile;