1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Fixes for more robust handling of command-line parse errors.

[originally from svn r2236]
This commit is contained in:
Simon Tatham 2002-11-20 20:09:02 +00:00
parent 75ebfa28f0
commit 0c110dcd10
5 changed files with 35 additions and 9 deletions

View File

@ -256,6 +256,7 @@ int main(int argc, char **argv)
int skcount, sksize;
int connopen;
int exitcode;
int errors;
ssh_get_line = console_get_line;
@ -275,6 +276,7 @@ int main(int argc, char **argv)
do_defaults(NULL, &cfg);
default_protocol = cfg.protocol;
default_port = cfg.port;
errors = 0;
{
/*
* Override the default protocol if PLINK_PROTOCOL is set.
@ -299,12 +301,16 @@ int main(int argc, char **argv)
if (ret == -2) {
fprintf(stderr,
"plink: option \"%s\" requires an argument\n", p);
errors = 1;
} else if (ret == 2) {
--argc, ++argv;
} else if (ret == 1) {
continue;
} else if (!strcmp(p, "-batch")) {
console_batch_mode = 1;
} else {
fprintf(stderr, "plink: unknown option \"%s\"\n", p);
errors = 1;
}
} else if (*p) {
if (!*cfg.host) {
@ -426,6 +432,9 @@ int main(int argc, char **argv)
}
}
if (errors)
return 1;
if (!*cfg.host) {
usage();
}

View File

@ -1844,11 +1844,11 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
void cmdline_error(char *p, ...)
{
va_list ap;
fprintf(stderr, "pscp: ");
fprintf(stderr, "psftp: ");
va_start(ap, p);
vfprintf(stderr, p, ap);
va_end(ap);
fputc('\n', stderr);
fprintf(stderr, "\n try typing \"psftp -h\" for help\n");
exit(1);
}
@ -1863,6 +1863,7 @@ int main(int argc, char *argv[])
int mode = 0;
int modeflags = 0;
char *batchfile = NULL;
int errors = 0;
flags = FLAG_STDERR | FLAG_INTERACTIVE;
cmdline_tooltype = TOOLTYPE_FILETRANSFER;
@ -1872,6 +1873,7 @@ int main(int argc, char *argv[])
userhost = user = NULL;
errors = 0;
for (i = 1; i < argc; i++) {
int ret;
if (argv[i][0] != '-') {
@ -1906,7 +1908,7 @@ int main(int argc, char *argv[])
i++;
break;
} else {
usage();
cmdline_error("unknown option \"%s\"", argv[i]);
}
}
argc -= i;

7
scp.c
View File

@ -2166,7 +2166,7 @@ void cmdline_error(char *p, ...)
va_start(ap, p);
vfprintf(stderr, p, ap);
va_end(ap);
fputc('\n', stderr);
fprintf(stderr, "\n try typing just \"pscp\" for help\n");
exit(1);
}
@ -2219,8 +2219,9 @@ int main(int argc, char *argv[])
} else if (strcmp(argv[i], "--") == 0) {
i++;
break;
} else
usage();
} else {
cmdline_error("unknown option \"%s\"", argv[i]);
}
}
argc -= i;
argv += i;

View File

@ -186,6 +186,7 @@ int main(int argc, char **argv)
int i, skcount, sksize, socketstate;
int connopen;
int exitcode;
int errors;
void *ldisc;
ssh_get_line = console_get_line;
@ -206,6 +207,7 @@ int main(int argc, char **argv)
do_defaults(NULL, &cfg);
default_protocol = cfg.protocol;
default_port = cfg.port;
errors = 0;
{
/*
* Override the default protocol if PLINK_PROTOCOL is set.
@ -230,6 +232,7 @@ int main(int argc, char **argv)
if (ret == -2) {
fprintf(stderr,
"plink: option \"%s\" requires an argument\n", p);
errors = 1;
} else if (ret == 2) {
--argc, ++argv;
} else if (ret == 1) {
@ -237,11 +240,17 @@ int main(int argc, char **argv)
} else if (!strcmp(p, "-batch")) {
console_batch_mode = 1;
} else if (!strcmp(p, "-o")) {
if (argc <= 1)
if (argc <= 1) {
fprintf(stderr,
"plink: option \"-o\" requires an argument\n");
else
--argc, provide_xrm_string(*++argv);
errors = 1;
} else {
--argc;
provide_xrm_string(*++argv);
}
} else {
fprintf(stderr, "plink: unknown option \"%s\"\n", p);
errors = 1;
}
} else if (*p) {
if (!*cfg.host) {
@ -366,6 +375,9 @@ int main(int argc, char **argv)
}
}
if (errors)
return 1;
if (!*cfg.host) {
usage();
}

View File

@ -406,6 +406,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
cfg.host[sizeof(cfg.host) - 1] = '\0';
got_host = 1;
}
} else {
cmdline_error("unknown option \"%s\"", p);
}
}
}