Op zondag 11 november 2007, schreef Eric Blake:

Hello,

> Thanks for the patch.  However, to be complete, you also need to mention
> it in NEWS, and update the documentation in doc/coreutils.texi.

There you go.

> Also, 
> since this is not a trivial patch, we would need copyright assignment
> before incorporating it.

I tried to understand how to obtain one, but it's not really clear to me. Can 
you, or someone else, give me a little push in the right direction, please?

Kind regards,

-- 
Bram Schoenmakers

What is mind? No matter. What is matter? Never mind.
  (Punch, 1855)
diff --git a/NEWS b/NEWS
index a8434c5..20062fb 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   (though the word count will have no real meaning) rather than many
   error messages.
 
+  split accepts a new option: --target-directory (-t). It will write
+  output file to the specified directory.
+
 ** New build options
 
   By default, "make install" no longer attempts to install (or even build) su.
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 4c08378..bde3aae 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -2833,6 +2833,12 @@ option.
 @opindex --numeric-suffixes
 Use digits in suffixes rather than lower-case letters.
 
[EMAIL PROTECTED] -t @var{directory}
[EMAIL PROTECTED] --target-directory
[EMAIL PROTECTED] -t
[EMAIL PROTECTED] --target-directory
+Put each output file in a specified @var{directory}
+
 @itemx --verbose
 @opindex --verbose
 Write a diagnostic to standard error just before each output file is opened.
diff --git a/src/split.c b/src/split.c
index 1142b61..814d6a0 100644
--- a/src/split.c
+++ b/src/split.c
@@ -13,7 +13,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
+
 /* By [EMAIL PROTECTED], with rms.
 
    To do:
@@ -88,6 +88,7 @@ static struct option const longopts[] =
   {"line-bytes", required_argument, NULL, 'C'},
   {"suffix-length", required_argument, NULL, 'a'},
   {"numeric-suffixes", no_argument, NULL, 'd'},
+  {"target-directory", required_argument, NULL, 't'},
   {"verbose", no_argument, NULL, VERBOSE_OPTION},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
@@ -116,11 +117,12 @@ is -, read standard input.\n\
 Mandatory arguments to long options are mandatory for short options too.\n\
 "), stdout);
       fprintf (stdout, _("\
-  -a, --suffix-length=N   use suffixes of length N (default %d)\n\
-  -b, --bytes=SIZE        put SIZE bytes per output file\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\
-  -l, --lines=NUMBER      put NUMBER lines per output file\n\
+  -a, --suffix-length=N      use suffixes of length N (default %d)\n\
+  -b, --bytes=SIZE           put SIZE bytes per output file\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\
+  -l, --lines=NUMBER         put NUMBER lines per output file\n\
+  -t, --target-directory=DIR  write output files in DIR\n\
 "), DEFAULT_SUFFIX_LENGTH);
       fputs (_("\
       --verbose           print a diagnostic to standard error just\n\
@@ -311,7 +313,7 @@ lines_split (uintmax_t n_lines, char *buf, size_t bufsize)
     }
   while (n_read == bufsize);
 }
-
+
 /* Split into pieces that are as large as possible while still not more
    than N_BYTES bytes, and are split on line boundaries except
    where lines longer than N_BYTES bytes occur.
@@ -392,6 +394,7 @@ main (int argc, char **argv)
   static char const multipliers[] = "bEGKkMmPTYZ0";
   int c;
   int digits_optind = 0;
+  char *target_directory = NULL;
 
   initialize_main (&argc, &argv);
   program_name = argv[0];
@@ -411,7 +414,7 @@ main (int argc, char **argv)
       /* This is the argv-index of the option we will read next.  */
       int this_optind = optind ? optind : 1;
 
-      c = getopt_long (argc, argv, "0123456789C:a:b:dl:", longopts, NULL);
+      c = getopt_long (argc, argv, "0123456789C:a:b:dl:t:", longopts, NULL);
       if (c == -1)
 	break;
 
@@ -499,6 +502,21 @@ main (int argc, char **argv)
 	  suffix_alphabet = "0123456789";
 	  break;
 
+	case 't':
+	  if (target_directory)
+		  error (EXIT_FAILURE, 0, _("multiple target directories specified"));
+	  else
+	    {
+	      struct stat st;
+	      if (stat (optarg, &st) != 0)
+		error (EXIT_FAILURE, errno, _("accessing %s"), quote (optarg));
+	      if (! S_ISDIR (st.st_mode))
+		error (EXIT_FAILURE, 0, _("target %s is not a directory"),
+		       quote (optarg));
+	    }
+	  target_directory = optarg;
+		break;
+
 	case VERBOSE_OPTION:
 	  verbose = true;
 	  break;
@@ -533,6 +551,11 @@ main (int argc, char **argv)
   if (optind < argc)
     outbase = argv[optind++];
 
+  if (target_directory)
+  {
+    outbase = strcat( strcat( target_directory, "/" ), outbase );
+  }
+
   if (optind < argc)
     {
       error (0, 0, _("extra operand %s"), quote (argv[optind]));
_______________________________________________
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to