summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-06-21 15:03:35 +0000
committerJim Meyering <jim@meyering.net>2004-06-21 15:03:35 +0000
commit1ce7b61d0ea270b0c463198afca1cd0e214192fb (patch)
tree947f954d8a82091744d3809da651319e9d82001d
parent110be46897450cd5fa90e3a955ab9092db128cea (diff)
downloadcoreutils-1ce7b61d0ea270b0c463198afca1cd0e214192fb.tar.xz
(main): Standardize on the diagnostics given when someone gives
too few operands ("missing operand after `xxx'") or too many operands ("extra operand `xxx'"). Include "quote.h" and/or "error.h" if it wasn't already being included.
-rw-r--r--src/basename.c12
-rw-r--r--src/chgrp.c7
-rw-r--r--src/chmod.c5
-rw-r--r--src/chown.c7
-rw-r--r--src/chroot.c2
-rw-r--r--src/comm.c14
-rw-r--r--src/csplit.c6
-rw-r--r--src/date.c3
-rw-r--r--src/dircolors.c16
-rw-r--r--src/dirname.c12
-rw-r--r--src/du.c9
-rw-r--r--src/expr.c2
-rw-r--r--src/hostid.c3
-rw-r--r--src/hostname.c3
-rw-r--r--src/id.c6
-rw-r--r--src/install.c5
-rw-r--r--src/link.c7
-rw-r--r--src/ln.c2
-rw-r--r--src/logname.c3
-rw-r--r--src/md5sum.c10
-rw-r--r--src/mkdir.c2
-rw-r--r--src/mkfifo.c2
-rw-r--r--src/mknod.c42
-rw-r--r--src/mv.c6
-rw-r--r--src/nohup.c2
-rw-r--r--src/od.c6
-rw-r--r--src/pathchk.c2
-rw-r--r--src/ptx.c6
-rw-r--r--src/readlink.c4
-rw-r--r--src/rm.c2
-rw-r--r--src/rmdir.c2
-rw-r--r--src/seq.c5
-rw-r--r--src/setuidgid.c5
-rw-r--r--src/shred.c2
-rw-r--r--src/sleep.c2
-rw-r--r--src/sort.c8
-rw-r--r--src/split.c3
-rw-r--r--src/stat.c2
-rw-r--r--src/touch.c2
-rw-r--r--src/tr.c50
-rw-r--r--src/tsort.c3
-rw-r--r--src/tty.c3
-rw-r--r--src/uname.c3
-rw-r--r--src/uniq.c5
-rw-r--r--src/unlink.c4
-rw-r--r--src/uptime.c3
-rw-r--r--src/users.c3
-rw-r--r--src/who.c3
-rw-r--r--src/whoami.c7
49 files changed, 202 insertions, 121 deletions
diff --git a/src/basename.c b/src/basename.c
index df6d33731..261200206 100644
--- a/src/basename.c
+++ b/src/basename.c
@@ -33,6 +33,7 @@
#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"
@@ -109,10 +110,15 @@ main (int argc, char **argv)
++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);
}
diff --git a/src/chgrp.c b/src/chgrp.c
index e8c410066..6cc22cf7a 100644
--- a/src/chgrp.c
+++ b/src/chgrp.c
@@ -269,9 +269,12 @@ main (int argc, char **argv)
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);
}
diff --git a/src/chmod.c b/src/chmod.c
index 24450647a..7dea0a24b 100644
--- a/src/chmod.c
+++ b/src/chmod.c
@@ -425,7 +425,10 @@ main (int argc, char **argv)
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);
}
diff --git a/src/chown.c b/src/chown.c
index 8a943604e..47a8e95f3 100644
--- a/src/chown.c
+++ b/src/chown.c
@@ -285,9 +285,12 @@ main (int argc, char **argv)
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);
}
diff --git a/src/chroot.c b/src/chroot.c
index 3d196af6e..37e749c96 100644
--- a/src/chroot.c
+++ b/src/chroot.c
@@ -86,7 +86,7 @@ main (int argc, char **argv)
if (argc <= 1)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAIL);
}
diff --git a/src/comm.c b/src/comm.c
index e7acf3393..c854b8c70 100644
--- a/src/comm.c
+++ b/src/comm.c
@@ -26,6 +26,7 @@
#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). */
@@ -283,9 +284,18 @@ main (int argc, char **argv)
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);
}
diff --git a/src/csplit.c b/src/csplit.c
index d1bc0ff8a..c26486f08 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -32,6 +32,7 @@
#include "error.h"
#include "inttostr.h"
#include "safe-read.h"
+#include "quote.h"
#include "xstrtol.h"
#ifndef SA_NOCLDSTOP
@@ -1374,7 +1375,10 @@ main (int argc, char **argv)
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);
}
diff --git a/src/date.c b/src/date.c
index 5cb891bcd..118a045e7 100644
--- a/src/date.c
+++ b/src/date.c
@@ -373,8 +373,7 @@ main (int argc, char **argv)
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);
}
diff --git a/src/dircolors.c b/src/dircolors.c
index ac8582cf5..f17dc0a43 100644
--- a/src/dircolors.c
+++ b/src/dircolors.c
@@ -462,17 +462,13 @@ to select a shell syntax are mutually exclusive"));
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);
}
diff --git a/src/dirname.c b/src/dirname.c
index 3e3b6eb6a..552b6da0d 100644
--- a/src/dirname.c
+++ b/src/dirname.c
@@ -25,6 +25,7 @@
#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"
@@ -84,10 +85,15 @@ main (int argc, char **argv)
++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);
}
diff --git a/src/du.c b/src/du.c
index b8fe68c73..a4c9c03ef 100644
--- a/src/du.c
+++ b/src/du.c
@@ -735,9 +735,12 @@ main (int argc, char **argv)
/* 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)
diff --git a/src/expr.c b/src/expr.c
index d1500380c..a6f54774e 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -196,7 +196,7 @@ main (int argc, char **argv)
if (argc <= 1)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXPR_INVALID);
}
diff --git a/src/hostid.c b/src/hostid.c
index a262e7874..1ca34bb89 100644
--- a/src/hostid.c
+++ b/src/hostid.c
@@ -26,6 +26,7 @@
#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"
@@ -83,7 +84,7 @@ main (int argc, char **argv)
if (argc > 1)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[1]));
usage (EXIT_FAILURE);
}
diff --git a/src/hostname.c b/src/hostname.c
index ff7b4e4cc..69aedac12 100644
--- a/src/hostname.c
+++ b/src/hostname.c
@@ -24,6 +24,7 @@
#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"
@@ -131,7 +132,7 @@ main (int argc, char **argv)
}
else
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[2]));
usage (EXIT_FAILURE);
}
diff --git a/src/id.c b/src/id.c
index a3682f3a6..eb331c254 100644
--- a/src/id.c
+++ b/src/id.c
@@ -28,6 +28,7 @@
#include "system.h"
#include "error.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "id"
@@ -166,7 +167,10 @@ main (int argc, char **argv)
_("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)
{
diff --git a/src/install.c b/src/install.c
index 6f447b214..cdb80f283 100644
--- a/src/install.c
+++ b/src/install.c
@@ -283,7 +283,10 @@ main (int argc, char **argv)
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);
}
diff --git a/src/link.c b/src/link.c
index 9d4628026..1e3754dee 100644
--- a/src/link.c
+++ b/src/link.c
@@ -85,13 +85,16 @@ main (int argc, char **argv)
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);
}
diff --git a/src/ln.c b/src/ln.c
index 48a1fafb6..b1a929a32 100644
--- a/src/ln.c
+++ b/src/ln.c
@@ -493,7 +493,7 @@ main (int argc, char **argv)
if (argc <= optind)
{
- error (0, 0, _("missing file argument"));
+ error (0, 0, _("missing file operand"));
usage (EXIT_FAILURE);
}
diff --git a/src/logname.c b/src/logname.c
index 1c9bc8d4b..e1201b1fb 100644
--- a/src/logname.c
+++ b/src/logname.c
@@ -23,6 +23,7 @@
#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"
@@ -88,7 +89,7 @@ main (int argc, char **argv)
if (optind < argc)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
usage (EXIT_FAILURE);
}
diff --git a/src/md5sum.c b/src/md5sum.c
index d37a06def..da4a7caf5 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -30,6 +30,7 @@
#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")
@@ -644,7 +645,9 @@ verifying checksums"));
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)
@@ -665,8 +668,9 @@ verifying checksums"));
{
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);
}
diff --git a/src/mkdir.c b/src/mkdir.c
index d248962fb..2b4b64932 100644
--- a/src/mkdir.c
+++ b/src/mkdir.c
@@ -122,7 +122,7 @@ main (int argc, char **argv)
if (optind == argc)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
diff --git a/src/mkfifo.c b/src/mkfifo.c
index ff9410837..cc58f0843 100644
--- a/src/mkfifo.c
+++ b/src/mkfifo.c
@@ -111,7 +111,7 @@ main (int argc, char **argv)
if (optind == argc)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
diff --git a/src/mknod.c b/src/mknod.c
index fdf2b0ebe..58f12f9b2 100644
--- a/src/mknod.c
+++ b/src/mknod.c
@@ -91,6 +91,7 @@ main (int argc, char **argv)
struct mode_change *change;
const char *specified_mode;
int optc;
+ int expected_operands;
mode_t node_type;
initialize_main (&argc, &argv);
@@ -131,16 +132,27 @@ main (int argc, char **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);
}
@@ -167,14 +179,6 @@ main (int argc, char **argv)
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];
@@ -206,12 +210,6 @@ numbers must be specified"));
#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
diff --git a/src/mv.c b/src/mv.c
index 240beb31b..4a73ae95f 100644
--- a/src/mv.c
+++ b/src/mv.c
@@ -457,7 +457,11 @@ main (int argc, char **argv)
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);
}
diff --git a/src/nohup.c b/src/nohup.c
index c2b83c90e..88deba4d5 100644
--- a/src/nohup.c
+++ b/src/nohup.c
@@ -97,7 +97,7 @@ main (int argc, char **argv)
if (argc <= 1)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (NOHUP_FAILURE);
}
diff --git a/src/od.c b/src/od.c
index 4a288b4df..452e16b90 100644
--- a/src/od.c
+++ b/src/od.c
@@ -26,6 +26,7 @@
#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). */
@@ -1873,8 +1874,9 @@ it must be one character from [doxn]"),
}
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);
}
diff --git a/src/pathchk.c b/src/pathchk.c
index 024240c36..7da0c0afe 100644
--- a/src/pathchk.c
+++ b/src/pathchk.c
@@ -186,7 +186,7 @@ main (int argc, char **argv)
if (optind == argc)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
diff --git a/src/ptx.c b/src/ptx.c
index 0697019c4..28f6f4148 100644
--- a/src/ptx.c
+++ b/src/ptx.c
@@ -27,6 +27,7 @@
#include "argmatch.h"
#include "diacrit.h"
#include "error.h"
+#include "quote.h"
#include "quotearg.h"
#include "regex.h"
#include "xstrtol.h"
@@ -2162,7 +2163,10 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"),
/* 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
diff --git a/src/readlink.c b/src/readlink.c
index 8c9350a5e..dd9e5afe2 100644
--- a/src/readlink.c
+++ b/src/readlink.c
@@ -125,7 +125,7 @@ main (int argc, char *const argv[])
if (optind >= argc)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
@@ -133,7 +133,7 @@ main (int argc, char *const argv[])
if (optind < argc)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
usage (EXIT_FAILURE);
}
diff --git a/src/rm.c b/src/rm.c
index e7db1cc24..24d705d5a 100644
--- a/src/rm.c
+++ b/src/rm.c
@@ -231,7 +231,7 @@ main (int argc, char **argv)
exit (EXIT_SUCCESS);
else
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
}
diff --git a/src/rmdir.c b/src/rmdir.c
index 1c29700b6..e34951f92 100644
--- a/src/rmdir.c
+++ b/src/rmdir.c
@@ -205,7 +205,7 @@ main (int argc, char **argv)
if (optind == argc)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
diff --git a/src/seq.c b/src/seq.c
index 45ba5a58d..18b1f7af1 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -26,6 +26,7 @@
#include "system.h"
#include "c-strtod.h"
#include "error.h"
+#include "quote.h"
#include "xstrtol.h"
#include "xstrtod.h"
@@ -371,13 +372,13 @@ main (int argc, char **argv)
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);
}
diff --git a/src/setuidgid.c b/src/setuidgid.c
index fd5348a13..96f4ef4b0 100644
--- a/src/setuidgid.c
+++ b/src/setuidgid.c
@@ -96,7 +96,10 @@ main (int argc, char **argv)
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);
}
diff --git a/src/shred.c b/src/shred.c
index 92962b9ed..486f554b9 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -1685,7 +1685,7 @@ main (int argc, char **argv)
if (n_files == 0)
{
- error (0, 0, _("missing file argument"));
+ error (0, 0, _("missing file operand"));
usage (EXIT_FAILURE);
}
diff --git a/src/sleep.c b/src/sleep.c
index 7027ab9fc..43ff8e8c4 100644
--- a/src/sleep.c
+++ b/src/sleep.c
@@ -137,7 +137,7 @@ main (int argc, char **argv)
if (argc == 1)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
diff --git a/src/sort.c b/src/sort.c
index 522b799bc..27c297d60 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -34,6 +34,7 @@
#include "long-options.h"
#include "physmem.h"
#include "posixver.h"
+#include "quote.h"
#include "stdio-safer.h"
#include "xmemcoll.h"
#include "xstrtol.h"
@@ -2511,8 +2512,11 @@ main (int argc, char **argv)
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. */
diff --git a/src/split.c b/src/split.c
index f47a2615d..324f15d1d 100644
--- a/src/split.c
+++ b/src/split.c
@@ -35,6 +35,7 @@
#include "full-write.h"
#include "inttostr.h"
#include "posixver.h"
+#include "quote.h"
#include "safe-read.h"
#include "xstrtol.h"
@@ -532,7 +533,7 @@ main (int argc, char **argv)
if (optind < argc)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
usage (EXIT_FAILURE);
}
diff --git a/src/stat.c b/src/stat.c
index c4593fee3..5f6d95b63 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -821,7 +821,7 @@ main (int argc, char *argv[])
if (argc == optind)
{
- error (0, 0, _("too few arguments"));
+ error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
}
diff --git a/src/touch.c b/src/touch.c
index 5e7899950..9b988036b 100644
--- a/src/touch.c
+++ b/src/touch.c
@@ -409,7 +409,7 @@ main (int argc, char **argv)
if (optind == argc)
{
- error (0, 0, _("file arguments missing"));
+ error (0, 0, _("missing file operand"));
usage (EXIT_FAILURE);
}
diff --git a/src/tr.c b/src/tr.c
index fe47aad7b..45aad1a93 100644
--- a/src/tr.c
+++ b/src/tr.c
@@ -26,6 +26,7 @@
#include "system.h"
#include "error.h"
+#include "quote.h"
#include "safe-read.h"
#include "xstrtol.h"
@@ -1671,6 +1672,8 @@ main (int argc, char **argv)
{
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;
@@ -1719,35 +1722,34 @@ main (int argc, char **argv)
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))
diff --git a/src/tsort.c b/src/tsort.c
index 3ef6cb080..07a077062 100644
--- a/src/tsort.c
+++ b/src/tsort.c
@@ -31,6 +31,7 @@
#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). */
@@ -573,7 +574,7 @@ main (int argc, char **argv)
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);
}
diff --git a/src/tty.c b/src/tty.c
index 0e555182f..83411dcb6 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -29,6 +29,7 @@
#include "system.h"
#include "error.h"
+#include "quote.h"
/* Exit statuses. */
enum
@@ -116,7 +117,7 @@ main (int argc, char **argv)
}
if (optind < argc)
- error (0, 0, _("ignoring all arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
tty = ttyname (0);
if (!silent)
diff --git a/src/uname.c b/src/uname.c
index 4edd4e011..fa2f68ba9 100644
--- a/src/uname.c
+++ b/src/uname.c
@@ -46,6 +46,7 @@
#include "system.h"
#include "error.h"
+#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "uname"
@@ -212,7 +213,7 @@ main (int argc, char **argv)
if (argc != optind)
{
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
usage (EXIT_FAILURE);
}
diff --git a/src/uniq.c b/src/uniq.c
index a1ebf3148..c352bd524 100644
--- a/src/uniq.c
+++ b/src/uniq.c
@@ -29,6 +29,7 @@
#include "error.h"
#include "hard-locale.h"
#include "posixver.h"
+#include "quote.h"
#include "xmemcoll.h"
#include "xstrtol.h"
#include "memcasecmp.h"
@@ -435,7 +436,7 @@ main (int argc, char **argv)
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++];
@@ -452,7 +453,7 @@ main (int argc, char **argv)
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
diff --git a/src/unlink.c b/src/unlink.c
index 30ac2152f..079c169be 100644
--- a/src/unlink.c
+++ b/src/unlink.c
@@ -84,13 +84,13 @@ main (int argc, char **argv)
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);
}
diff --git a/src/uptime.c b/src/uptime.c
index 3c746f57b..72621bfa6 100644
--- a/src/uptime.c
+++ b/src/uptime.c
@@ -30,6 +30,7 @@
#include "error.h"
#include "long-options.h"
+#include "quote.h"
#include "readutmp.h"
/* The official name of this program (e.g., no `g' prefix). */
@@ -244,7 +245,7 @@ main (int argc, char **argv)
break;
default: /* lose */
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
usage (EXIT_FAILURE);
}
diff --git a/src/users.c b/src/users.c
index e1772d914..da9a54642 100644
--- a/src/users.c
+++ b/src/users.c
@@ -26,6 +26,7 @@
#include "error.h"
#include "long-options.h"
+#include "quote.h"
#include "readutmp.h"
/* The official name of this program (e.g., no `g' prefix). */
@@ -168,7 +169,7 @@ main (int argc, char **argv)
break;
default: /* lose */
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
usage (EXIT_FAILURE);
}
diff --git a/src/who.c b/src/who.c
index 6dd1203e6..f8da4737e 100644
--- a/src/who.c
+++ b/src/who.c
@@ -34,6 +34,7 @@
#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). */
@@ -812,7 +813,7 @@ main (int argc, char **argv)
break;
default: /* lose */
- error (0, 0, _("too many arguments"));
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 2]));
usage (EXIT_FAILURE);
}
diff --git a/src/whoami.c b/src/whoami.c
index f666a677a..482f7fbd0 100644
--- a/src/whoami.c
+++ b/src/whoami.c
@@ -27,7 +27,9 @@
#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"
@@ -94,7 +96,10 @@ main (int argc, char **argv)
}
if (optind != argc)
- usage (EXIT_FAILURE);
+ {
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
+ usage (EXIT_FAILURE);
+ }
uid = geteuid ();
pw = getpwuid (uid);