]> sjero.net Git - wget/commitdiff
[svn] Handle negative numbers in with_thousand_seps.
authorhniksic <devnull@localhost>
Sun, 26 Jun 2005 22:18:01 +0000 (15:18 -0700)
committerhniksic <devnull@localhost>
Sun, 26 Jun 2005 22:18:01 +0000 (15:18 -0700)
src/ChangeLog
src/utils.c

index 0a5ed0ac905ecdad814f83fe9c9c24b32fdaa009..9fca8864032d709f9d7b7faa26d6a06419ce2148 100644 (file)
@@ -1,3 +1,7 @@
+2005-06-27  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * utils.c (with_thousand_seps): Handle negative numbers.
+
 2005-06-26  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * progress.c (create_image): Mark the "eta" string for translation.
index 6461200622e5aa0ebe67fb15467b0ef777ca0f10..96d4767c80f63dc4d52affb018bf31e864d8bdc5 100644 (file)
@@ -1192,7 +1192,6 @@ get_grouping_data (const char **sep, const char **grouping)
   *grouping = cached_grouping;
 }
 
-
 /* Return a printed representation of N with thousand separators.
    This should respect locale settings, with the exception of the "C"
    locale which mandates no separator, but we use one anyway.
@@ -1216,12 +1215,19 @@ with_thousand_seps (wgint n)
   int i = 0, groupsize;
   const char *atgroup;
 
+  bool negative = n < 0;
+
   /* Initialize grouping data. */
   get_grouping_data (&sep, &grouping);
   seplen = strlen (sep);
   atgroup = grouping;
   groupsize = *atgroup++;
 
+  /* This will overflow on WGINT_MIN, but we're not using this to
+     print negative numbers anyway.  */
+  if (negative)
+    n = -n;
+
   /* Write the number into the buffer, backwards, inserting the
      separators as necessary.  */
   *--p = '\0';
@@ -1243,6 +1249,9 @@ with_thousand_seps (wgint n)
            groupsize = *atgroup++;
        }
     }
+  if (negative)
+    *--p = '-';
+
   return p;
 }