Devin Hussey <[email protected]> wrote:
> From: Devin Hussey <[email protected]>
> 
> I added the seq builtin.
> 
> usage: seq [-w] [-f format] [-s string] [-t string] [first [incr]] last
> 
> Some notes:
>    - 100% from scratch, aside from the small num_width algorithm I took from
>      StackOverflow and credited accordingly.
>    - I optimize the math by using integer math if we don't have any decimals,
>      intmax_t is large enough to support the number range, and if the user
>      didn't specify a custom format. GNU Coreutils also does this.
>      - If we use integers, we precalculate the width and snprintf a format
>        specifer from that for the -w option.
>    - I reuse some of the printf code to act as the validator for the format
>      string. I want to separate this more for the best possible const
>      correctness, though (I use a cast), and so the conditionals are a little
>      more clear.
>    - It functionally matches the one supplied with macOS and presumably BSD,
>      but it's faster: It is reliably slightly faster on my system (a wimpy
>      2009 MacBook) to call this
>          ./dash -c 'seq 1 10000'
>      than it is to call
>          seq 1 10000
>      directly, even multiple times, from a bash shell.
> 
> Other changes:
>    - I fixed a few silly gotos in the file, replacing them with negated
>      conditional blocks or early returns.
>    - I isolated the printf parsing into its own function so we can reuse it.
>    - I reordered the static functions to go above the main functions. This
>      makes it easier to follow.
>    - I changed conv_escape to return the number of characters read instead
>      of the string itself so it can accept a constant string without any
>      ugly casting.
> 
> Signed-off-by: Devin Hussey <[email protected]>

Sorry, I'm not adding this builtin to dash as this conflicts with
the goal of dash trying to be minimal.  Perhaps bash or mksh would
be a better option?

Thanks,
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Reply via email to