coreutils
[Top][All Lists]
Advanced

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

Re: numfmt (=print 'human' sizes) updates


From: Pádraig Brady
Subject: Re: numfmt (=print 'human' sizes) updates
Date: Fri, 01 Feb 2013 19:14:15 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

On 01/31/2013 05:01 PM, Pádraig Brady wrote:

I'm still a bit worried about the numbers rejected by numfmt.
These (ordered in my opinon of importance) will all give errors:

$ numfmt --ignore-errors -- -1 1.2 1e2 1,234 0xf 0xf.a
numfmt: invalid number: '-1'
-1
numfmt: cannot process decimal-point value without scaling: '1.2' (consider 
using --from)
1.2
numfmt: invalid suffix in input: '1e2'
1e2
numfmt: invalid suffix in input: '1,234'
1,234
numfmt: invalid suffix in input: '0xf'
0xf
numfmt: invalid suffix in input: '0xf.ap2'
0xf.ap2

I'm thinking perhaps strtold could be used as
the base conversion function rather than trying
to parse everything ourselves.
I would consider the first two numbers above to
be very important to support in any case.

Other things I noticed ....

Without --field it might be better to convert all numbers,
rather than just the first field (consider df output).

We may be able to remove --grouping and --padding
in preference to specifying those in the --format string.
Note the format string has the advantage of auto accounting
for the grouping chars and precision in the width if using
printf to generate the base number.

I've updated the patch set again at:
http://www.pixelbeat.org/patches/coreutils/numfmt.14.patch.xz
to address the first 2 number formats not supported above.
I'm getting ready to push it soon, after squashing the commits.
Changes since patch 13 are:


    numfmt: Don't process fields in command args by default

    * src/numfmt.c (main): Not doing so will allow more natural processing
    of command line args as a single number, which is significant with
    spaces between number and suffix for example.


    numfmt: support a space between the number and suffix

    This is a common format and easily supported.

    * src/numfmt.c (simple_strtod_human): Skip blanks.
    * tests/misc/numfmt.pl: Add a test.


    numfmt: support floating point numbers without a suffix

    Store a precision to use based on the input number.
    Reset the precision to 0 if there is a a scaling suffix used.

    * src/numfmt.c: Add a size_t precision pointer for update
    by the number parsing functions.
    (double_to_human): Use the precision for non scaled output.
    * tests/misc/numfmt.pl: Add/adjust tests.


    numfmt: always use exit status 2 for input errors

    Also change --ignore-errors to the more flexible
    --invalid={abort. fail, warn, ignore}

    * src/numfmt.c: Always use EXIT_CONVERSION_WARNINGS for input errors,
    rather than using EXIT_FAILURE sometimes.  Also allow suppressing
    diagnostic messages and the exit status with --invalid={....}
    * doc/coreutils.texi (numfmt invocation): Adjust accordingly.
    * tests/misc/numfmt.pl: Likewise.


    numfmt: support negative numbers

    * src/numfmt.c (simple_strtod_int): Process a leading '-'
    as a negative number.
    * tests/misc/numfmt.pl: Add basica tests for negative numbers.

thanks,
Pádraig.



reply via email to

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