(main): Standardize on the diagnostics given when someone gives
authorJim Meyering <jim@meyering.net>
Mon, 21 Jun 2004 15:03:35 +0000 (15:03 +0000)
committerJim Meyering <jim@meyering.net>
Mon, 21 Jun 2004 15:03:35 +0000 (15:03 +0000)
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.

49 files changed:
src/basename.c
src/chgrp.c
src/chmod.c
src/chown.c
src/chroot.c
src/comm.c
src/csplit.c
src/date.c
src/dircolors.c
src/dirname.c
src/du.c
src/expr.c
src/hostid.c
src/hostname.c
src/id.c
src/install.c
src/link.c
src/ln.c
src/logname.c
src/md5sum.c
src/mkdir.c
src/mkfifo.c
src/mknod.c
src/mv.c
src/nohup.c
src/od.c
src/pathchk.c
src/ptx.c
src/readlink.c
src/rm.c
src/rmdir.c
src/seq.c
src/setuidgid.c
src/shred.c
src/sleep.c
src/sort.c
src/split.c
src/stat.c
src/touch.c
src/tr.c
src/tsort.c
src/tty.c
src/uname.c
src/uniq.c
src/unlink.c
src/uptime.c
src/users.c
src/who.c
src/whoami.c

index df6d337..2612002 100644 (file)
@@ -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);
     }
 
index e8c4100..6cc22cf 100644 (file)
@@ -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);
     }
 
index 2445064..7dea0a2 100644 (file)
@@ -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);
     }
 
index 8a94360..47a8e95 100644 (file)
@@ -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);
     }
 
index 3d196af..37e749c 100644 (file)
@@ -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);
     }
 
index e7acf33..c854b8c 100644 (file)
@@ -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);
     }
 
index d1bc0ff..c26486f 100644 (file)
@@ -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);
     }
 
index 5cb891b..118a045 100644 (file)
@@ -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);
     }
 
index ac8582c..f17dc0a 100644 (file)
@@ -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);
     }
 
index 3e3b6eb..552b6da 100644 (file)
@@ -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);
     }
 
index b8fe68c..a4c9c03 100644 (file)
--- 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)
index d150038..a6f5477 100644 (file)
@@ -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);
     }
 
index a262e78..1ca34bb 100644 (file)
@@ -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);
     }
 
index ff7b4e4..69aedac 100644 (file)
@@ -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);
     }
 
index a3682f3..eb331c2 100644 (file)
--- 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)
     {
index 6f447b2..cdb80f2 100644 (file)
@@ -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);
     }
 
index 9d46280..1e3754d 100644 (file)
@@ -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);
     }
 
index 48a1faf..b1a929a 100644 (file)
--- 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);
     }
 
index 1c9bc8d..e1201b1 100644 (file)
@@ -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);
     }
 
index d37a06d..da4a7ca 100644 (file)
@@ -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);
        }
 
index d248962..2b4b649 100644 (file)
@@ -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);
     }
 
index ff94108..cc58f08 100644 (file)
@@ -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);
     }
 
index fdf2b0e..58f12f9 100644 (file)
@@ -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
index 240beb3..4a73ae9 100644 (file)
--- 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);
     }
 
index c2b83c9..88deba4 100644 (file)
@@ -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);
     }
 
index 4a288b4..452e16b 100644 (file)
--- 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);
        }
 
index 024240c..7da0c0a 100644 (file)
@@ -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);
     }
 
index 0697019..28f6f41 100644 (file)
--- 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
index 8c9350a..dd9e5af 100644 (file)
@@ -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);
     }
 
index e7db1cc..24d705d 100644 (file)
--- 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);
        }
     }
index 1c29700..e34951f 100644 (file)
@@ -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);
     }
 
index 45ba5a5..18b1f7a 100644 (file)
--- 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);
     }
 
index fd5348a..96f4ef4 100644 (file)
@@ -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);
     }
 
index 92962b9..486f554 100644 (file)
@@ -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);
     }
 
index 7027ab9..43ff8e8 100644 (file)
@@ -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);
     }
 
index 522b799..27c297d 100644 (file)
@@ -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.  */
index f47a261..324f15d 100644 (file)
@@ -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);
     }
 
index c4593fe..5f6d95b 100644 (file)
@@ -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);
     }
 
index 5e78999..9b98803 100644 (file)
@@ -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);
     }
 
index fe47aad..45aad1a 100644 (file)
--- 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))
index 3ef6cb0..07a0770 100644 (file)
@@ -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);
     }
 
index 0e55518..83411dc 100644 (file)
--- 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)
index 4edd4e0..fa2f68b 100644 (file)
@@ -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);
     }
 
index a1ebf31..c352bd5 100644 (file)
@@ -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
index 30ac215..079c169 100644 (file)
@@ -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);
     }
 
index 3c746f5..72621bf 100644 (file)
@@ -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);
     }
 
index e1772d9..da9a546 100644 (file)
@@ -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);
     }
 
index 6dd1203..f8da473 100644 (file)
--- 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);
     }
 
index f666a67..482f7fb 100644 (file)
@@ -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);