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: Thu, 31 Jan 2013 17:01:45 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

I've updated the patch set at:
  http://www.pixelbeat.org/patches/coreutils/numfmt.13.patch.xz
including these changes:

    numfmt: suppress the trailing '\n' if not present in stdin

    * src/numfmt.c (main): Determine if there is a trailing newline
    in stdin, and don't output if missing.


    numfmt: remove the 16K line length limitation

    * src/numfmt.c (main): Use getline() to efficiently get long lines.
    (chomp): Remove this function which is no longer needed as we can
    more efficiently terminate, give the line length fro getline().


    numfmt: improve/standardize the comments


    numfmt: disallow --to-unit=0 or --from-unit=0

    Such units are nonsensical and can cause further
    issues like conversion of values to "inf" etc.

    * src/numfmt.c (unit_to_umax): Rename this function from the
    too generally named string_to_integer.  Also validate that
    '0' is not specified.
    * tests/misc/numfmt.pl: Add associated test cases.


    numfmt: protect expld() from infinite loop

    * src/numfmt.c (expld): This could happen if 'inf' is supported
    as the value in future, or currently if --to-unit=0 is used.


    numfmt: print the note about mandatory args for short options

    * src/numfmt (usage): Emit the standard note, specifically
    for the '-d' option.


    numfmt: use a more concise and general command description

    * src/numfmt.c (usage): Don't restrict the discription to
    the "human" subset of the functionality.


    numfmt: fix mispellings

    * src/numfmt.c: Fix spellings in some comments.


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.

thanks,
Pádraig.



reply via email to

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