about summary refs log tree commit diff
path: root/lib/util/nstring.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2013-07-26 02:58:45 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2013-07-26 02:58:45 +0000
commitbeffe953e343dd3798e94dda0923fab704adc23f (patch)
tree04dc49398ec27de2b76981d3ea32c45b720baa67 /lib/util/nstring.c
parentf30acda48fceb2f3382bd85827077a11b09ef6b6 (diff)
downloadnetpbm-mirror-beffe953e343dd3798e94dda0923fab704adc23f.tar.gz
netpbm-mirror-beffe953e343dd3798e94dda0923fab704adc23f.tar.xz
netpbm-mirror-beffe953e343dd3798e94dda0923fab704adc23f.zip
Add %f capability
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1995 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/util/nstring.c')
-rw-r--r--lib/util/nstring.c19
1 files changed, 17 insertions, 2 deletions
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