Reject unknown options.

This commit is contained in:
Paul Eggert
2004-09-21 22:05:52 +00:00
parent 6c9dc0efd9
commit aa1ed28185
2 changed files with 13 additions and 25 deletions
+7 -13
View File
@@ -73,29 +73,23 @@ main (int argc, char **argv)
parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
usage, AUTHORS, (char const *) NULL);
if (getopt (argc, argv, "") != -1)
usage (EXIT_FAILURE);
/* The above handles --help and --version.
Since there is no other invocation of getopt, handle `--' here. */
if (1 < argc && STREQ (argv[1], "--"))
{
--argc;
++argv;
}
if (argc < 2)
if (argc < optind + 1)
{
error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
if (2 < argc)
if (optind + 1 < argc)
{
error (0, 0, _("extra operand %s"), quote (argv[2]));
error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
usage (EXIT_FAILURE);
}
if (unlink (argv[1]) != 0)
error (EXIT_FAILURE, errno, _("cannot unlink %s"), quote (argv[1]));
if (unlink (argv[optind]) != 0)
error (EXIT_FAILURE, errno, _("cannot unlink %s"), quote (argv[optind]));
exit (EXIT_SUCCESS);
}
+6 -12
View File
@@ -73,25 +73,19 @@ main (int argc, char **argv)
parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
usage, AUTHORS, (char const *) NULL);
if (getopt (argc, argv, "+") != -1)
usage (EXIT_FAILURE);
/* The above handles --help and --version.
Since there is no other invocation of getopt, handle `--' here. */
if (1 < argc && STREQ (argv[1], "--"))
if (argc <= optind)
{
--argc;
++argv;
}
if (argc == 1)
{
argv[1] = "y";
argc = 2;
optind = argc;
argv[argc++] = "y";
}
for (;;)
{
int i;
for (i = 1; i < argc; i++)
for (i = optind; i < argc; i++)
if (fputs (argv[i], stdout) == EOF
|| putchar (i == argc - 1 ? '\n' : ' ') == EOF)
{