/* Numerical suffix start value. */
static const char *numeric_suffix_start;
+/* Additional suffix to append to output file names. */
+static char const *additional_suffix;
+
/* Name of input file. May be "-". */
static char *infile;
{
VERBOSE_OPTION = CHAR_MAX + 1,
FILTER_OPTION,
- IO_BLKSIZE_OPTION
+ IO_BLKSIZE_OPTION,
+ ADDITIONAL_SUFFIX_OPTION
};
static struct option const longopts[] =
{"elide-empty-files", no_argument, NULL, 'e'},
{"unbuffered", no_argument, NULL, 'u'},
{"suffix-length", required_argument, NULL, 'a'},
+ {"additional-suffix", required_argument, NULL,
+ ADDITIONAL_SUFFIX_OPTION},
{"numeric-suffixes", optional_argument, NULL, 'd'},
{"filter", required_argument, NULL, FILTER_OPTION},
{"verbose", no_argument, NULL, VERBOSE_OPTION},
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\
+ -a, --suffix-length=N generate suffixes of length N (default %d)\n\
+ --additional-suffix=SUFFIX append an additional SUFFIX to file names.\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[=FROM] use numeric suffixes instead of alphabetic.\n\
/* Allocate and initialize the first file name. */
size_t outbase_length = strlen (outbase);
- size_t outfile_length = outbase_length + suffix_length;
+ size_t addsuf_length = additional_suffix ? strlen (additional_suffix) : 0;
+ size_t outfile_length = outbase_length + suffix_length + addsuf_length;
if (outfile_length + 1 < outbase_length)
xalloc_die ();
outfile = xmalloc (outfile_length + 1);
outfile_mid = outfile + outbase_length;
memcpy (outfile, outbase, outbase_length);
memset (outfile_mid, suffix_alphabet[0], suffix_length);
+ if (additional_suffix)
+ memcpy (outfile_mid + suffix_length, additional_suffix, addsuf_length);
outfile[outfile_length] = 0;
sufindex = xcalloc (suffix_length, sizeof *sufindex);
}
break;
+ case ADDITIONAL_SUFFIX_OPTION:
+ if (last_component (optarg) != optarg)
+ {
+ error (0, 0,
+ _("invalid suffix %s, contains directory separator"),
+ quote (optarg));
+ usage (EXIT_FAILURE);
+ }
+ additional_suffix = optarg;
+ break;
+
case 'b':
if (split_type != type_undef)
FAIL_ONLY_ONE_WAY ();
--- /dev/null
+#!/bin/sh
+# show that 'split --additional-suffix=SUFFIX' works.
+
+# Copyright (C) 2012 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+print_ver_ split
+
+printf '1\n2\n3\n4\n5\n' > in || framework_failure_
+
+split --lines=2 --additional-suffix=.txt in > out || fail=1
+cat <<\EOF > exp-1
+1
+2
+EOF
+cat <<\EOF > exp-2
+3
+4
+EOF
+cat <<\EOF > exp-3
+5
+EOF
+
+compare exp-1 xaa.txt || fail=1
+compare exp-2 xab.txt || fail=1
+compare exp-3 xac.txt || fail=1
+
+# Additional suffix must not contain slash
+split --lines=2 --additional-suffix=a/b in 2>/dev/null > out && fail=1
+
+Exit $fail