#include "long-options.h"
#include "dirname.h"
#include "error.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "basename"
++argv;
}
- if (argc <= 1 || argc > 3)
+ if (argc < 2)
{
- error (0, 0, (argc <= 1 ? _("too few arguments")
- : _("too many arguments")));
+ error (0, 0, _("missing operand"));
+ usage (EXIT_FAILURE);
+ }
+
+ if (3 < argc)
+ {
+ error (0, 0, _("extra operand %s"), quote (argv[3]));
usage (EXIT_FAILURE);
}
chopt.affect_symlink_referent = (dereference != 0);
}
- if (argc - optind + (reference_file ? 1 : 0) <= 1)
+ if (argc - optind < (reference_file ? 1 : 2))
{
- error (0, 0, _("too few arguments"));
+ if (argc <= optind)
+ error (0, 0, _("missing operand"));
+ else
+ error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
usage (EXIT_FAILURE);
}
if (optind >= argc)
{
- error (0, 0, _("too few arguments"));
+ if (modeind == 0 || modeind != argc - 1)
+ error (0, 0, _("missing operand"));
+ else
+ error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
usage (EXIT_FAILURE);
}
chopt.affect_symlink_referent = (dereference != 0);
}
- if (argc - optind + (reference_file ? 1 : 0) <= 1)
+ if (argc - optind < (reference_file ? 1 : 2))
{
- error (0, 0, _("too few arguments"));
+ if (argc <= optind)
+ error (0, 0, _("missing operand"));
+ else
+ error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
usage (EXIT_FAILURE);
}
if (argc <= 1)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAIL);
}
#include "linebuffer.h"
#include "error.h"
#include "hard-locale.h"
+#include "quote.h"
#include "xmemcoll.h"
/* The official name of this program (e.g., no `g' prefix). */
usage (EXIT_FAILURE);
}
- if (optind + 2 != argc)
+ if (argc - optind < 2)
{
- error (0, 0, _("too few arguments"));
+ if (argc <= optind)
+ error (0, 0, _("missing operand"));
+ else
+ error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
+ usage (EXIT_FAILURE);
+ }
+
+ if (2 < argc - optind)
+ {
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 2]));
usage (EXIT_FAILURE);
}
#include "error.h"
#include "inttostr.h"
#include "safe-read.h"
+#include "quote.h"
#include "xstrtol.h"
#ifndef SA_NOCLDSTOP
if (argc - optind < 2)
{
- error (0, 0, _("too few arguments"));
+ if (argc <= optind)
+ error (0, 0, _("missing operand"));
+ else
+ error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
usage (EXIT_FAILURE);
}
if (n_args > 1)
{
- error (0, 0, _("too many non-option arguments: %s%s"),
- argv[optind + 1], n_args == 2 ? "" : " ...");
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
usage (EXIT_FAILURE);
}
usage (EXIT_FAILURE);
}
- if (print_database && argc > 0)
+ if (!print_database < argc)
{
- error (0, 0,
- _("no FILE arguments may be used with the option to output\n\
-dircolors' internal database"));
- usage (EXIT_FAILURE);
- }
-
- if (!print_database && argc > 1)
- {
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[!print_database]));
+ if (print_database)
+ fprintf (stderr, "%s\n",
+ _("File operands cannot be combined with "
+ "--print-database (-p)."));
usage (EXIT_FAILURE);
}
#include "long-options.h"
#include "error.h"
#include "dirname.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "dirname"
++argv;
}
- if (argc != 2)
+ if (argc < 2)
{
- error (0, 0, argc < 2 ? _("too few arguments")
- : _("too many arguments"));
+ error (0, 0, _("missing operand"));
+ usage (EXIT_FAILURE);
+ }
+
+ if (2 < argc)
+ {
+ error (0, 0, _("extra operand %s"), quote (argv[2]));
usage (EXIT_FAILURE);
}
/* When using --files0-from=F, you may not specify any files
on the command-line. */
if (optind < argc)
- error (EXIT_FAILURE, 0,
- _("%s: you may not specify command-line arguments with\
- --files0-from"), quotearg_colon (argv[optind]));
+ {
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
+ fprintf (stderr, "%s\n",
+ _("File operands cannot be combined with --files0-from."));
+ usage (EXIT_FAILURE);
+ }
istream = (STREQ (files_from, "-") ? stdin : fopen (files_from, "r"));
if (istream == NULL)
if (argc <= 1)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXPR_INVALID);
}
#include "system.h"
#include "long-options.h"
#include "error.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "hostid"
if (argc > 1)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[1]));
usage (EXIT_FAILURE);
}
#include "system.h"
#include "long-options.h"
#include "error.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "hostname"
}
else
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[2]));
usage (EXIT_FAILURE);
}
#include "system.h"
#include "error.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "id"
_("cannot print only names or real IDs in default format"));
if (argc - optind > 1)
- usage (EXIT_FAILURE);
+ {
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
+ usage (EXIT_FAILURE);
+ }
if (argc - optind == 1)
{
if (argc <= optind || (n_files == 1 && !dir_arg))
{
- error (0, 0, _("too few arguments"));
+ if (argc <= optind)
+ error (0, 0, _("missing operand"));
+ else
+ error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
usage (EXIT_FAILURE);
}
if (argc < 3)
{
- error (0, 0, _("too few arguments"));
+ if (argc < 2)
+ error (0, 0, _("missing operand"));
+ else
+ error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
usage (EXIT_FAILURE);
}
if (3 < argc)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[3]));
usage (EXIT_FAILURE);
}
if (argc <= optind)
{
- error (0, 0, _("missing file argument"));
+ error (0, 0, _("missing file operand"));
usage (EXIT_FAILURE);
}
#include "system.h"
#include "error.h"
#include "long-options.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "logname"
if (optind < argc)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
usage (EXIT_FAILURE);
}
#include "checksum.h"
#include "getline.h"
#include "error.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME (algorithm == ALG_MD5 ? "md5sum" : "sha1sum")
if (optind < argc)
{
- error (0, 0, _("no files may be specified when using --string"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
+ fprintf (stderr, "%s\n",
+ _("File operands cannot be combined with --string."));
usage (EXIT_FAILURE);
}
for (i = 0; i < n_strings; ++i)
{
if (optind + 1 < argc)
{
- error (0, 0,
- _("only one argument may be specified when using --check"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
+ fprintf (stderr, "%s\n",
+ _("Only one operand may be specified when using --check."));
usage (EXIT_FAILURE);
}
if (optind == argc)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
if (optind == argc)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
struct mode_change *change;
const char *specified_mode;
int optc;
+ int expected_operands;
mode_t node_type;
initialize_main (&argc, &argv);
newmode = mode_adjust (newmode, change);
}
- if (argc - optind != 2 && argc - optind != 4)
+ expected_operands = (argv[optind + 1][0] == 'p' ? 2 : 4);
+
+ if (argc - optind < expected_operands)
{
- const char *msg;
- if (argc - optind < 2)
- msg = _("too few arguments");
- else if (argc - optind > 4)
- msg = _("too many arguments");
+ if (argc <= optind)
+ error (0, 0, _("missing operand"));
else
- msg = _("wrong number of arguments");
- error (0, 0, "%s", msg);
+ error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
+ if (expected_operands == 4 && argc - optind == 2)
+ fprintf (stderr, "%s\n",
+ _("Special files require major and minor device numbers."));
+ usage (EXIT_FAILURE);
+ }
+
+ if (expected_operands < argc - optind)
+ {
+ error (0, 0, _("extra operand %s"),
+ quote (argv[optind + expected_operands]));
+ if (expected_operands == 2 && argc - optind == 4)
+ fprintf (stderr,
+ _("Fifos do not have major and minor device numbers."));
usage (EXIT_FAILURE);
}
goto block_or_character;
block_or_character:
- if (argc - optind != 4)
- {
- error (0, 0, _("\
-when creating special files, major and minor device\n\
-numbers must be specified"));
- usage (EXIT_FAILURE);
- }
-
{
char const *s_major = argv[optind + 2];
char const *s_minor = argv[optind + 3];
#ifndef S_ISFIFO
error (EXIT_FAILURE, 0, _("fifo files not supported"));
#else
- if (argc - optind != 2)
- {
- error (0, 0, _("\
-major and minor device numbers may not be specified for fifo files"));
- usage (EXIT_FAILURE);
- }
if (mkfifo (argv[optind], newmode))
error (EXIT_FAILURE, errno, "%s", quote (argv[optind]));
#endif
if (n_files == 0 || (n_files == 1 && !target_directory_specified))
{
- error (0, 0, _("missing file argument"));
+ if (n_files == 0)
+ error (0, 0, _("missing file operand"));
+ else
+ error (0, 0, _("missing file operand after %s"),
+ quote (argv[argc - 1]));
usage (EXIT_FAILURE);
}
if (argc <= 1)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (NOHUP_FAILURE);
}
#include "system.h"
#include "error.h"
#include "posixver.h"
+#include "quote.h"
#include "xstrtol.h"
/* The official name of this program (e.g., no `g' prefix). */
}
else if (n_files > 3)
{
- error (0, 0,
- _("compatibility mode supports at most three arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 3]));
+ fprintf (stderr, "%s\n",
+ _("Compatibility mode supports at most three operands."));
usage (EXIT_FAILURE);
}
if (optind == argc)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
#include "argmatch.h"
#include "diacrit.h"
#include "error.h"
+#include "quote.h"
#include "quotearg.h"
#include "regex.h"
#include "xstrtol.h"
/* Diagnose any other argument as an error. */
if (optind < argc)
- usage (EXIT_FAILURE);
+ {
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
+ usage (EXIT_FAILURE);
+ }
}
/* If the output format has not been explicitly selected, choose dumb
if (optind >= argc)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
if (optind < argc)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
usage (EXIT_FAILURE);
}
exit (EXIT_SUCCESS);
else
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
}
if (optind == argc)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
#include "system.h"
#include "c-strtod.h"
#include "error.h"
+#include "quote.h"
#include "xstrtol.h"
#include "xstrtod.h"
if (argc - optind < 1)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
if (3 < argc - optind)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 3]));
usage (EXIT_FAILURE);
}
if (argc <= 2)
{
- error (0, 0, _("too few arguments"));
+ if (argc < 2)
+ error (0, 0, _("missing operand"));
+ else
+ error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
usage (SETUIDGID_FAILURE);
}
if (n_files == 0)
{
- error (0, 0, _("missing file argument"));
+ error (0, 0, _("missing file operand"));
usage (EXIT_FAILURE);
}
if (argc == 1)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
#include "long-options.h"
#include "physmem.h"
#include "posixver.h"
+#include "quote.h"
#include "stdio-safer.h"
#include "xmemcoll.h"
#include "xstrtol.h"
if (checkonly)
{
if (nfiles > 1)
- error (SORT_FAILURE, 0, _("extra operand `%s' not allowed with -c"),
- files[1]);
+ {
+ error (0, 0, _("extra operand %s not allowed with -c"),
+ quote (files[1]));
+ usage (SORT_FAILURE);
+ }
/* POSIX requires that sort return 1 IFF invoked with -c and the
input is not properly sorted. */
#include "full-write.h"
#include "inttostr.h"
#include "posixver.h"
+#include "quote.h"
#include "safe-read.h"
#include "xstrtol.h"
if (optind < argc)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
usage (EXIT_FAILURE);
}
if (argc == optind)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
if (optind == argc)
{
- error (0, 0, _("file arguments missing"));
+ error (0, 0, _("missing file operand"));
usage (EXIT_FAILURE);
}
#include "system.h"
#include "error.h"
+#include "quote.h"
#include "safe-read.h"
#include "xstrtol.h"
{
int c;
int non_option_args;
+ int min_operands;
+ int max_operands;
struct Spec_list buf1, buf2;
struct Spec_list *s1 = &buf1;
struct Spec_list *s2 = &buf2;
non_option_args = argc - optind;
translating = (non_option_args == 2 && !delete);
+ min_operands = 1 + (delete == squeeze_repeats);
+ max_operands = 1 + (delete <= squeeze_repeats);
- /* Change this test if it is valid to give tr no options and
- no args at all. POSIX doesn't specifically say anything
- either way, but it looks like they implied it's invalid
- by omission. If you want to make tr do a slow imitation
- of `cat' use `tr a a'. */
- if (non_option_args > 2)
+ if (non_option_args < min_operands)
{
- error (0, 0, _("too many arguments"));
+ if (non_option_args == 0)
+ error (0, 0, _("missing operand"));
+ else
+ {
+ error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
+ fprintf (stderr, "%s\n",
+ _(squeeze_repeats
+ ? ("Two strings must be given when "
+ "both deleting and squeezing repeats.")
+ : "Two strings must be given when translating."));
+ }
usage (EXIT_FAILURE);
}
- if (!delete && !squeeze_repeats && non_option_args != 2)
- error (EXIT_FAILURE, 0, _("two strings must be given when translating"));
-
- if (delete && squeeze_repeats && non_option_args != 2)
- error (EXIT_FAILURE, 0, _("two strings must be given when both \
-deleting and squeezing repeats"));
-
- /* If --delete is given without --squeeze-repeats, then
- only one string argument may be specified. */
- if ((delete && !squeeze_repeats) && non_option_args != 1)
- error (EXIT_FAILURE, 0,
- _("only one string may be given when deleting \
-without squeezing repeats"));
-
- if (squeeze_repeats && non_option_args == 0)
- error (EXIT_FAILURE, 0,
- _("at least one string must be given when squeezing repeats"));
+ if (max_operands < non_option_args)
+ {
+ error (0, 0, _("extra operand %s"), quote (argv[optind + max_operands]));
+ if (non_option_args == 2)
+ fprintf (stderr, "%s\n",
+ _("Only one string may be given when "
+ "deleting without squeezing repeats."));
+ usage (EXIT_FAILURE);
+ }
spec_init (s1);
if (!parse_str (argv[optind], s1))
#include "system.h"
#include "long-options.h"
#include "error.h"
+#include "quote.h"
#include "readtokens.h"
/* The official name of this program (e.g., no `g' prefix). */
if (1 < argc - optind)
{
- error (0, 0, _("only one argument may be specified"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
usage (EXIT_FAILURE);
}
#include "system.h"
#include "error.h"
+#include "quote.h"
/* Exit statuses. */
enum
}
if (optind < argc)
- error (0, 0, _("ignoring all arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
tty = ttyname (0);
if (!silent)
#include "system.h"
#include "error.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "uname"
if (argc != optind)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
usage (EXIT_FAILURE);
}
#include "error.h"
#include "hard-locale.h"
#include "posixver.h"
+#include "quote.h"
#include "xmemcoll.h"
#include "xstrtol.h"
#include "memcasecmp.h"
break;
if (nfiles == 2)
{
- error (0, 0, _("extra operand `%s'"), argv[optind]);
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
usage (EXIT_FAILURE);
}
file[nfiles++] = argv[optind++];
skip_chars = size;
else if (nfiles == 2)
{
- error (0, 0, _("extra operand `%s'"), optarg);
+ error (0, 0, _("extra operand %s"), quote (optarg));
usage (EXIT_FAILURE);
}
else
if (argc < 2)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
if (2 < argc)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[2]));
usage (EXIT_FAILURE);
}
#include "error.h"
#include "long-options.h"
+#include "quote.h"
#include "readutmp.h"
/* The official name of this program (e.g., no `g' prefix). */
break;
default: /* lose */
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
usage (EXIT_FAILURE);
}
#include "error.h"
#include "long-options.h"
+#include "quote.h"
#include "readutmp.h"
/* The official name of this program (e.g., no `g' prefix). */
break;
default: /* lose */
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
usage (EXIT_FAILURE);
}
#include "readutmp.h"
#include "error.h"
#include "inttostr.h"
+#include "quote.h"
#include "vasprintf.h"
/* The official name of this program (e.g., no `g' prefix). */
break;
default: /* lose */
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 2]));
usage (EXIT_FAILURE);
}
#include <getopt.h>
#include "system.h"
+#include "error.h"
#include "long-options.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "whoami"
}
if (optind != argc)
- usage (EXIT_FAILURE);
+ {
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
+ usage (EXIT_FAILURE);
+ }
uid = geteuid ();
pw = getpwuid (uid);