very nice!

one problem, ifmt can crash with the argument -f %g.
fomatting %g will mean that !running to be true when
calling ifmt, thus ifmt will try to va_arg a double cast to
vlong when formatting an integer:

/sys/src/libc/fmt/fltfmt.c:136:                 sprint(s1+NSIGNIF, "e%d", 
e-NSIGNIF+1);
/sys/src/libc/fmt/fltfmt.c:142:                         sprint(s1+NSIGNIF, 
"e%d", e-NSIGNIF+1);
/sys/src/libc/fmt/fltfmt.c:155:                 sprint(s1+NSIGNIF, "e%d", 
e-NSIGNIF+1);

(actually, on testing, this version spins rather than crashes
on plan 9:
; ps -a | grep 1308769
quanstro    1308769    1:30   0:00       28K Running  8.seqrsc -f %g 1 5
)

using awk is still faster, and more
fundamentally, avoids crashing on bogus
formats like %g%g.

(also, -w doesn't work with either version
with a %x format because 'e' is a valid hex
digit and not an exponent.)

- erik

Reply via email to