[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#14913: [PATCH] :2013-07-19 Jeremy Wright <address@hidden>
From: |
Pádraig Brady |
Subject: |
bug#14913: [PATCH] :2013-07-19 Jeremy Wright <address@hidden> |
Date: |
Sat, 20 Jul 2013 10:26:28 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 |
On 07/19/2013 08:56 PM, Jeremy Wright wrote:
> * src/csplit.c (make_filename): Added initial value (-i) option
> to start output file counter at a specific given value.
> ---
> src/csplit.c | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/src/csplit.c b/src/csplit.c
> index 7a36e67..c97790e 100644
> --- a/src/csplit.c
> +++ b/src/csplit.c
> @@ -169,6 +169,10 @@ static bool elide_empty_files;
> /* If true, suppress the lines that match the PATTERN */
> static bool suppress_matched;
>
> +/* Number to start output file name count */
> +static unsigned int initial_file_number = 0;
> +
> +
> /* The compiled pattern arguments, which determine how to split
> the input file. */
> static struct control *controls;
> @@ -195,6 +199,7 @@ static struct option const longopts[] =
> {"elide-empty-files", no_argument, NULL, 'z'},
> {"prefix", required_argument, NULL, 'f'},
> {"suffix-format", required_argument, NULL, 'b'},
> + {"initial-value", required_argument, NULL, 'i'},
> {"suppress-matched", no_argument, NULL, SUPPRESS_MATCHED_OPTION},
> {GETOPT_HELP_OPTION_DECL},
> {GETOPT_VERSION_OPTION_DECL},
> @@ -930,9 +935,9 @@ make_filename (unsigned int num)
> {
> strcpy (filename_space, prefix);
> if (suffix)
> - sprintf (filename_space + strlen (prefix), suffix, num);
> + sprintf (filename_space + strlen (prefix), suffix,
> num+initial_file_number);
> else
> - sprintf (filename_space + strlen (prefix), "%0*u", digits, num);
> + sprintf (filename_space + strlen (prefix), "%0*u", digits,
> num+initial_file_number);
> return filename_space;
> }
>
> @@ -1349,7 +1354,7 @@ main (int argc, char **argv)
> suppress_matched = false;
> prefix = DEFAULT_PREFIX;
>
> - while ((optc = getopt_long (argc, argv, "f:b:kn:sqz", longopts, NULL)) !=
> -1)
> + while ((optc = getopt_long (argc, argv, "f:b:kni:sqz", longopts, NULL)) !=
> -1)
> switch (optc)
> {
> case 'f':
> @@ -1379,9 +1384,11 @@ main (int argc, char **argv)
> case 'z':
> elide_empty_files = true;
> break;
> -
> - case SUPPRESS_MATCHED_OPTION:
> - suppress_matched = true;
> + case 'i':
> + if (xstrtoul (optarg, NULL, 10, &val, "") != LONGINT_OK
> + || MIN (INT_MAX, SIZE_MAX) < val)
> + error (EXIT_FAILURE, 0, _("%s: invalid number"), optarg);
> + initial_file_number = val;
> break;
>
> case_GETOPT_HELP_CHAR;
> @@ -1498,6 +1505,7 @@ and output byte counts of each piece to standard
> output.\n\
> -n, --digits=DIGITS use specified number of digits instead of 2\n\
> -s, --quiet, --silent do not print counts of output file sizes\n\
> -z, --elide-empty-files remove empty output files\n\
> + -i, --initial-value starting value for the output files\n\
> "), stdout);
> fputs (HELP_OPTION_DESCRIPTION, stdout);
> fputs (VERSION_OPTION_DESCRIPTION, stdout);
>
I like this, and it mirrors a recent addition to split(1):
http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commit;h=d55d3dd5
Could you detail your use case for this.
thanks,
Pádraig.