coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/8] split: remove short-named -f option; improve diagnostics


From: Jim Meyering
Subject: [PATCH 2/8] split: remove short-named -f option; improve diagnostics
Date: Sat, 30 Apr 2011 15:31:03 +0200

From: Jim Meyering <address@hidden>

* src/split.c (FILTER_OPTION): New anonymous enum member.
(longopts): Use it in place of 'f'.
(main): Likewise.
(create): Use "failed to ...", rather than "cannot ..." in diagnostics.
Include the full command in diagnostic when it fails to run.
---
 src/split.c |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/split.c b/src/split.c
index 7aab357..59473c5 100644
--- a/src/split.c
+++ b/src/split.c
@@ -108,6 +108,7 @@ enum Split_type
 enum
 {
   VERBOSE_OPTION = CHAR_MAX + 1,
+  FILTER_OPTION,
   IO_BLKSIZE_OPTION
 };

@@ -121,7 +122,7 @@ static struct option const longopts[] =
   {"unbuffered", no_argument, NULL, 'u'},
   {"suffix-length", required_argument, NULL, 'a'},
   {"numeric-suffixes", no_argument, NULL, 'd'},
-  {"filter", required_argument, NULL, 'f'},
+  {"filter", required_argument, NULL, FILTER_OPTION},
   {"verbose", no_argument, NULL, VERBOSE_OPTION},
   {"-io-blksize", required_argument, NULL,
    IO_BLKSIZE_OPTION}, /* do not document */
@@ -189,7 +190,7 @@ Mandatory arguments to long options are mandatory for short 
options too.\n\
   -C, --line-bytes=SIZE   put at most SIZE bytes of lines per output file\n\
   -d, --numeric-suffixes  use numeric suffixes instead of alphabetic\n\
   -e, --elide-empty-files  do not generate empty output files with `-n'\n\
-  -f, --filter=COMMAND    write to shell COMMAND; file name is $FILE\n\
+      --filter=COMMAND    write to shell COMMAND; file name is $FILE\n\
   -l, --lines=NUMBER      put NUMBER lines per output file\n\
   -n, --number=CHUNKS     generate CHUNKS output files.  See below\n\
   -u, --unbuffered        immediately copy input to output with `-n r/...'\n\
@@ -291,11 +292,11 @@ create (const char *name)
       if (shell_prog == NULL)
         shell_prog = "/bin/sh";
       if (setenv ("FILE", name, 1) != 0)
-        error (EXIT_FAILURE, errno, "cannot set environment variable");
+        error (EXIT_FAILURE, errno, "failed to set FILE environment variable");
       if (verbose)
         fprintf (stdout, _("executing with FILE=%s\n"), quote (name));
       if (pipe (fd_pair) != 0)
-        error (EXIT_FAILURE, errno, _("cannot create pipe"));
+        error (EXIT_FAILURE, errno, _("failed to create pipe"));
       child_pid = fork ();
       if (child_pid == 0)
         {
@@ -322,12 +323,13 @@ create (const char *name)
           sigprocmask (SIG_SETMASK, &oldblocked, NULL);
           execl (shell_prog, last_component (shell_prog), "-c",
                  filter_command, (char *) NULL);
-          error (EXIT_FAILURE, errno, "%s", shell_prog);
+          error (EXIT_FAILURE, errno, _("failed to run command: \"%s -c %s\""),
+                 shell_prog, filter_command);
         }
       if (child_pid == -1)
-        error (EXIT_FAILURE, errno, _("cannot spawn new process"));
+        error (EXIT_FAILURE, errno, _("fork system call failed"));
       if (close (fd_pair[0]) != 0)
-        error (EXIT_FAILURE, errno, _("closing input pipe"));
+        error (EXIT_FAILURE, errno, _("failed to close input pipe"));
       filter_pid = child_pid;
       if (n_open_pipes == open_pipes_alloc)
         open_pipes = x2nrealloc (open_pipes, &open_pipes_alloc,
@@ -971,7 +973,7 @@ main (int argc, char **argv)
       int this_optind = optind ? optind : 1;
       char *slash;

-      c = getopt_long (argc, argv, "0123456789C:a:b:def:l:n:u",
+      c = getopt_long (argc, argv, "0123456789C:a:b:del:n:u",
                        longopts, NULL);
       if (c == -1)
         break;
@@ -1103,7 +1105,7 @@ main (int argc, char **argv)
           elide_empty_files = true;
           break;

-        case 'f':
+        case FILTER_OPTION:
           filter_command = optarg;
           break;

-- 
1.7.5.134.g1c08b




reply via email to

[Prev in Thread] Current Thread [Next in Thread]