coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] split: allow hexadecimal suffixes


From: Pádraig Brady
Subject: Re: [PATCH] split: allow hexadecimal suffixes
Date: Sat, 11 Mar 2017 19:24:54 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0

On 11/03/17 04:16, Michael Heimpold wrote:
> I am surprised that nobody has ever needed this before, so here
> is my story: I'm using this to split eMMC disk images into smaller
> chunks which are then flashed by U-Boot bootloader into the target
> devices. And since U-Boot handles almost everything as hexadecimal
> numbers, it's convenient to have the chunks named automatically so
> by split, instead of having an additional loop with renames afterwards.
> ---
> 
> Since this is my first contribution to coreutils, please let me
> know in case I'm doing it wrong. Please also note, that I'm not
> subscribe to the ML.
> 
> Best regards,
> Michael
> 
>  src/split.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/src/split.c b/src/split.c
> index 9662336..e9adee8 100644
> --- a/src/split.c
> +++ b/src/split.c
> @@ -141,6 +141,7 @@ static struct option const longopts[] =
>    {"additional-suffix", required_argument, NULL,
>     ADDITIONAL_SUFFIX_OPTION},
>    {"numeric-suffixes", optional_argument, NULL, 'd'},
> +  {"hexadecimal-suffixes", optional_argument, NULL, 'x'},
>    {"filter", required_argument, NULL, FILTER_OPTION},
>    {"verbose", no_argument, NULL, VERBOSE_OPTION},
>    {"separator", required_argument, NULL, 't'},
> @@ -240,8 +241,9 @@ default size is 1000 lines, and default PREFIX is 'x'.\n\
>    -b, --bytes=SIZE        put SIZE bytes per output file\n\
>    -C, --line-bytes=SIZE   put at most SIZE bytes of records per output 
> file\n\
>    -d                      use numeric suffixes starting at 0, not 
> alphabetic\n\
> -      --numeric-suffixes[=FROM]  same as -d, but allow setting the start 
> value\
> -\n\
> +      --numeric-suffixes[=FROM]  same as -d, but allow setting the start 
> value\n\
> +  -x                      use hexadecimal suffixes starting at 0, not 
> alphabetic\n\
> +      --hexadecimal-suffixes[=FROM]  same as -x, but allow setting the start 
> value\n\
>    -e, --elide-empty-files  do not generate empty output files with '-n'\n\
>        --filter=COMMAND    write to shell COMMAND; file name is $FILE\n\
>    -l, --lines=NUMBER      put NUMBER lines/records per output file\n\
> @@ -1314,7 +1316,7 @@ main (int argc, char **argv)
>        int this_optind = optind ? optind : 1;
>        char *slash;
>  
> -      c = getopt_long (argc, argv, "0123456789C:a:b:del:n:t:u",
> +      c = getopt_long (argc, argv, "0123456789C:a:b:del:n:t:ux",
>                         longopts, NULL);
>        if (c == -1)
>          break;
> @@ -1453,13 +1455,19 @@ main (int argc, char **argv)
>            break;
>  
>          case 'd':
> -          suffix_alphabet = "0123456789";
> +        case 'x':
> +          if (c == 'd')
> +            suffix_alphabet = "0123456789";
> +          else
> +            suffix_alphabet = "0123456789abcdef";
>            if (optarg)
>              {
>                if (strlen (optarg) != strspn (optarg, suffix_alphabet))
>                  {
>                    error (0, 0,
> -                         _("%s: invalid start value for numerical suffix"),
> +                         (c == 'd') ?
> +                           _("%s: invalid start value for numerical suffix") 
> :
> +                           _("%s: invalid start value for hexadecimal 
> suffix"),
>                           quote (optarg));
>                    usage (EXIT_FAILURE);
>                  }
> 

Thanks for the patch. It would need a test and an update to doc/coreutils.texi.
While this is trivial to add, it does seem quite edge case functionality.
I'm 50:50 for adding.

thanks,
Pádraig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]