]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(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 df6d3373129b0547393f682b32eba48af5ce10c7..261200206754d55a34563c454e742fdaa94e7aaa 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 e8c4100667944e028bd1634233b7009780c17605..6cc22cf7a5b86421fc52806ebe20ab3f042b6d3f 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 24450647a6c27a13f44c8865c23a627071c7d249..7dea0a24b54195eeaed7ecfe17eddbbea68c49a8 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 8a943604ed6788019c2f9d7c191b7dbaae38aea8..47a8e95f3f4eff9571890ae515cf47eeec9f0dff 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 3d196af6eb2f612c3a99be7446935d1fc459bc65..37e749c964d0a4aa6f2ce6d102ee21ae9fd236c1 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 e7acf33939e599168932f1193e0b808fb072dafd..c854b8c707fa86283950e30e661fbc4917ebb0a4 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 d1bc0ff8a2face2528eda0269c92e12abc5a6cb8..c26486f08d43ba3b5b8bad65ee37f1807735306b 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 5cb891bcd79557417d4c38f107eeadbc059d3680..118a045e7978b4033e3bc1cb9cd15df18508d9c6 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 ac8582cf546c554a90704b27cf7ee9af6e6dc509..f17dc0a43a953079c7960d4a9657439aa9a81641 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 3e3b6eb6ad328f6dfd596741308380110b0b0fe1..552b6da0d8148abdff458af10500c5b9cb0bddd6 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 b8fe68c739a4bf001854cb86bf7615341de70e08..a4c9c03ef2a572ee8ff894551cd9f2802fb11c3b 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 d1500380cf1a9aab9a58bb60ad881a09f5d01826..a6f54774e4933b40d6cccd6056dc73f486c52bee 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 a262e787483b186cb57b4735e9ad4b29c106e115..1ca34bb89d3133162d0beacff95f21b750f587f7 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 ff7b4e4cc031a328e1d466cd8e051f94b41afc5c..69aedac1269070370aa62f3afca6d955126ee88c 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 a3682f3a6848962a447c439defac1daaf5b8dbf5..eb331c254c1edbb9c4f8fceadebdb76993cc1c07 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 6f447b2148898cdff6883cbb0e083d8b4bf56f2b..cdb80f2832346318140fec1513dab4b229a4d7e2 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 9d46280261b4e1fea424a3ce19ec5e2c7cf8e55a..1e3754deec97b279216e20b6d15f94444b0e03f9 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 48a1fafb6e0edc403372622660d83a36ff20ab60..b1a929a32a4abb9a093283fa3df7a250fc68bf30 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 1c9bc8d4b2434ca7dfea5499ce5cf15bdad23a8e..e1201b1fbb7f2b596693f5398edd56a346cf4d5a 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 d37a06def7222fc55b2f7041bd61755a2d0569ec..da4a7caf5df650d139b4c8305aa8852b2b8ec572 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 d248962fbbd2527d33ba4241a609c5ea47af2e01..2b4b649329383bbe27c7a6fbd93c8b0978dcf7f5 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 ff9410837dd5c5dd419f06f7317576e3f9cf35c3..cc58f084356fd2eea488f41955f50d2b5404cec9 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 fdf2b0ebeef80fe2e86991240a1891b040157edd..58f12f9b22a69a25570d1c52dcb86554a27d9869 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 240beb31ba1dd545c491628ae058ae2da0a4713f..4a73ae95fcb104a34c1040b00a3cfe9dc0337a1f 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 c2b83c90e9b00f1aaf4d05ad1c0780dac8d3118b..88deba4d53b25878be8e01d4b27f6ab58d4c574c 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 4a288b4df65d81f0b7bc4c27d3e7f202170b1ada..452e16b907faaa9f14645435c6cbbe66ed09fd0b 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 024240c36bddbd4530cf2c06a126ea7524bc458f..7da0c0afe45ee7ac4c44bce181a93bbf95486e0f 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 0697019c4e2a6e604a0c3d79aa86551097266b87..28f6f41486b9a038c13ea3d522c1a7c9a540c571 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 8c9350a5e78940dbc62e9165f647625d9901b0d7..dd9e5afe2041ed53876e089450dd0f8f04cdfb09 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 e7db1cc2469694010a8d6fdd5c7421420d101269..24d705d5a166de046aacd2ad92bcfdd60c5d7ba7 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 1c29700b65e37d33c516c570fd295c70f9e01a94..e34951f92899fd3bf66051b9d8c4d1882db3f0e4 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 45ba5a58da521a61c9c2f47e188407a18a0c4ad6..18b1f7af144d6ef079788ce1038ae062713df750 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 fd5348a1353ce3cb1f9f3592962a55cc975a4cd2..96f4ef4b000305e2a80057fbafc065c6ff05ba7a 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 92962b9ed3c3f4d98c63fc019708996f6dbe788d..486f554b95b1c9e25dcd5a9646845c75ea417bab 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 7027ab9fcc55cd11af74316c4654c0cde434d5d8..43ff8e8c4a51c9e76a73bfda31bf05ea26458b84 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 522b799bc47950d4340f0f86da3cfb26892bb77d..27c297d604d517c3e4ae5a3d47ee82160f80080d 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 f47a2615d368d76f11408a286c143e0649218fd1..324f15d1d3942b05f4c8fa1e54ac5c041696d865 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 c4593fee3869ebb5ff7da5879090dcc51d8ae8af..5f6d95b63dadebc19799a8679de8121d96e3b947 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 5e78999507a8933b7779eee0be381465a04a9096..9b988036b1201d45ab6461436ed28c2910bbed5c 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 fe47aad7b587f26027819f439b6fabfc57264f92..45aad1a93fdaa64516f69c5d5d723d49ceb61197 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 3ef6cb080069ed50d627491b95b8f08ede33aff1..07a07706289723fd996f821c5f7415849c52a4eb 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 0e555182fef8ce8422e9241fd0e4c0852f4a47bf..83411dcb6fe2264a7a7a4cdb8d9cf0fca0b7d52e 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 4edd4e0111cae68e85d9ce8d7e6d8419e2dd7698..fa2f68ba9313078ad478fa8cbbbe8cf9e24a27d0 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 a1ebf314831b96d0de920fa95a47d10279ea319a..c352bd524f974a3c628c8507dece8a01389a9a42 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 30ac2152f2d9695a61815620c6f6e33359428b0e..079c169bea6953e35e3f94e03bbd37f93a70e6f3 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 3c746f57b24a63387af4fd68bf801f9bcb2d0a8b..72621bfa66f1e7a67b7b57d2f50f0b6c8885ecd8 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 e1772d91419c459d0b4d925c8ff1fbfd7440e25b..da9a54642dfff22314ed88561bf90fc9d5101c8e 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 6dd1203e6c89f5810162ab5b9530bc82a86cf2d6..f8da4737e99c1a08638ab83123d64f7be53540d6 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 f666a677ae4df58b63400eb239de1ae6ed95fae7..482f7fbd002d1116a13484de9f562182197c9d66 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);