From beffe953e343dd3798e94dda0923fab704adc23f Mon Sep 17 00:00:00 2001 From: giraffedata Date: Fri, 26 Jul 2013 02:58:45 +0000 Subject: Add %f capability git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1995 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/util/nstring.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'lib/util') diff --git a/lib/util/nstring.c b/lib/util/nstring.c index 9c6b7f27..e95d9824 100644 --- a/lib/util/nstring.c +++ b/lib/util/nstring.c @@ -39,7 +39,7 @@ * IMPLEMENTED CONVERSION SPECIFIERS AND DATA TYPES * * This snprintf implements only the following conversion specifiers: - * s, c, d, u, o, x, X, p (and synonyms: i, D, U, O - see below) + * s, c, d, u, o, x, X, p, f (and synonyms: i, D, U, O - see below) * with flags: '-', '+', ' ', '0' and '#'. * An asterisk is acceptable for field width as well as precision. * @@ -66,7 +66,7 @@ * * The following is specifically NOT implemented: * - flag ' (thousands' grouping character) is recognized but ignored - * - numeric conversion specifiers: f, e, E, g, G and synonym F, + * - numeric conversion specifiers: e, E, g, G and synonym F, * as well as the new a and A conversion specifiers * - length modifier 'L' (long double) and 'q' (quad - use 'll' instead) * - wide character/string conversions: lc, ls, and nonstandard @@ -615,6 +615,21 @@ pm_vsnprintf(char * const str, if (n > 0) number_of_zeros_to_pad += n; } } break; + case 'f': { + char f[10]; + if (precision_specified) + snprintf(f, ARRAY_SIZE(f), "%%%u.%uf", + (unsigned)min_field_width, (unsigned)precision); + else + snprintf(f, ARRAY_SIZE(f), "%%%uf", + (unsigned)min_field_width); + + str_arg_l = sprintf(tmp, f, va_arg(ap, double)); + str_arg = &tmp[0]; + + min_field_width = 0; + zero_padding_insertion_ind = 0; + } break; default: /* Unrecognized conversion specifier. Discard the unrecognized conversion, just keep the unrecognized -- cgit 1.4.1