Hello,
The attached patch adds -t or --target-directory support for split, specifying
in which directory the split files should go into.
The usecase for this when receiving a big file over a network, but you don't
have diskspace for the file itself and its splitted version. Now, you can do
things like this:
cat some_big_file | ssh [EMAIL PROTECTED] split -t /home/bram/tmp/
in order to have some_big_file split out immediately.
Kind regards,
--
Bram Schoenmakers
What is mind? No matter. What is matter? Never mind.
(Punch, 1855)
diff --git a/src/split.c b/src/split.c
index 1142b61..0568194 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 put 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
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils