GNU bug report logs - #14913
csplit: add -i/--initial-value=N option

Previous Next

Package: coreutils;

Reported by: Jeremy Wright <JWright <at> agjunction.com>

Date: Fri, 19 Jul 2013 20:04:01 UTC

Severity: wishlist

Tags: patch

To reply to this bug, email your comments to 14913 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#14913; Package coreutils. (Fri, 19 Jul 2013 20:04:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jeremy Wright <JWright <at> agjunction.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Fri, 19 Jul 2013 20:04:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jeremy Wright <JWright <at> agjunction.com>
To: "bug-coreutils <at> gnu.org" <bug-coreutils <at> gnu.org>
Subject: [PATCH] :2013-07-19    Jeremy Wright   <jwright <at> agjunction.com>
Date: Fri, 19 Jul 2013 19:56:48 +0000
* 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);
-- 
1.8.1.2




Information forwarded to bug-coreutils <at> gnu.org:
bug#14913; Package coreutils. (Fri, 19 Jul 2013 21:23:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Casey Kelso <CKelso <at> agjunction.com>
To: Jeremy Wright <JWright <at> agjunction.com>, "bug-coreutils <at> gnu.org"
 <bug-coreutils <at> gnu.org>
Subject: RE: [PATCH] :2013-07-19    Jeremy Wright   <jwright <at> agjunction.com>
Date: Fri, 19 Jul 2013 20:33:27 +0000
Cool. Where do you store the initial seed value between boots?

Casey Kelso
Software Manager | Ag Junction
480-348-6310 | ckelso <at> agjunction.com | http://www.agjunction.com


________________________________________
From: Jeremy Wright
Sent: Friday, July 19, 2013 12:56 PM
To: bug-coreutils <at> gnu.org
Subject: [PATCH] :2013-07-19    Jeremy Wright   <jwright <at> agjunction.com>

* 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);
--
1.8.1.2




Information forwarded to bug-coreutils <at> gnu.org:
bug#14913; Package coreutils. (Sat, 20 Jul 2013 09:27:01 GMT) Full text and rfc822 format available.

Message #11 received at 14913 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Jeremy Wright <JWright <at> agjunction.com>
Cc: 14913 <at> debbugs.gnu.org
Subject: Re: bug#14913: [PATCH] :2013-07-19 Jeremy Wright
 <jwright <at> agjunction.com>
Date: Sat, 20 Jul 2013 10:26:28 +0100
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.





Changed bug title to 'csplit: add -i/--initial-value=N option' from '[PATCH] :2013-07-19 Jeremy Wright <jwright <at> agjunction.com>' Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 09 Oct 2018 21:48:02 GMT) Full text and rfc822 format available.

Severity set to 'wishlist' from 'normal' Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 19 Oct 2018 00:49:02 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 188 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.