Hello,

Attached is a working version of numfmt.

The following are implemented:
===
Usage: ./src/numfmt [OPTIONS] [NUMBER]
Reformats NUMBER(s) to/from human-readable values.
Numbers can be processed either from stdin or command arguments.

  --from=UNIT     Auto-scale input numbers to UNITs. Default is 'none'.
                  See UNIT below.
  --from-unit=N   Specify the input unit size (instead of the default 1).
  --to=UNIT       Auto-scale output numbers to UNITs.
                  See UNIT below.
  --to-unit=N     Specify the output unit size (instead of the default 1).
  --round=METHOD  Round input numbers. METHOD can be:
                  ceiling (the default), floor, nearest
  --suffix=SUFFIX Add SUFFIX to output numbers, and accept optional SUFFIX
                  in input numbers.
  --padding=N     Pad the output to N characters.
                  Default is right-aligned. Negative N will left-align.
                  Note: if N is too small, the output will be truncated,
                  and a warning will be printed to stderr.
  --grouping      Group digits together (e.g. 1,000,000).
                  Uses the locale-defined grouping (i.e. have no effect
                  in C/POSIX locales).
  --field N       Replace the number in input field N (default is 1)
  -d, --delimiter=X  use X instead of whitespace for field delimiter
===

Also included in the patch is a test file, testing all sorts of combination of 
the parameters (hopefully catches most of the corner cases).

There's also an undocumented option "--debug" that will show what's going on:
===
$ /src/numfmt --debug --field 2 --suffix=Foo --from=SI --to=IEC "Hello 70MFoo 
World"
Extracting Fields:
  input: 'Hello 70MFoo World'
  field: 2
  prefix: 'Hello'
  number: '70MFoo'
  suffix: 'World'
Trimming suffix 'Foo'
Parsing number:
  input string: '70M'
  remaining characters: ''
  numeric value: 70000000
Formatting output:
  value: 70000000
  humanized: '67M'
Hello 67MFoo World
===

Comments are welcomed,
 -gordon

Attachment: numfmt3.patch.gz
Description: GNU Zip compressed data

Reply via email to