]> sjero.net Git - wget/blobdiff - src/progress.c
Use Gnulib's alloc functions throughout the source.
[wget] / src / progress.c
index a06f73d39c0b66ab8c3d218e6299307597683e9d..62e8d87dad544453e2d9b3b37b6c7da600ced6a1 100644 (file)
@@ -28,6 +28,8 @@ Corresponding Source for a non-source form of such a combination
 shall include the source code for the parts of OpenSSL used as well
 as that of the covered work.  */
 
+#define USE_GNULIB_ALLOC
+
 #include "wget.h"
 
 #include <stdio.h>
@@ -38,6 +40,9 @@ as that of the covered work.  */
 # include <unistd.h>
 #endif
 #include <signal.h>
+#ifdef HAVE_WCHAR_H
+# include <wchar.h>
+#endif
 
 #include "progress.h"
 #include "utils.h"
@@ -450,8 +455,8 @@ dot_set_params (const char *params)
     }
   else
     fprintf (stderr,
-             _("Invalid dot style specification `%s'; leaving unchanged.\n"),
-             params);
+             _("Invalid dot style specification %s; leaving unchanged.\n"),
+             quote (params));
 }
 \f
 /* "Thermometer" (bar) progress. */
@@ -764,6 +769,7 @@ update_speed_ring (struct bar_progress *bp, wgint howmuch, double dltime)
 #endif
 }
 
+#if USE_NLS_PROGRESS_BAR
 int
 count_cols (const char *mbs)
 {
@@ -771,16 +777,27 @@ count_cols (const char *mbs)
   int     bytes;
   int     remaining = strlen(mbs);
   int     cols = 0;
+  int     wccols;
 
   while (*mbs != '\0')
     {
       bytes = mbtowc (&wc, mbs, remaining);
+      assert (bytes != 0);  /* Only happens when *mbs == '\0' */
+      if (bytes == -1)
+        {
+          /* Invalid sequence. We'll just have to fudge it. */
+          return cols + remaining;
+        }
       mbs += bytes;
       remaining -= bytes;
-      cols += wcwidth(wc);
+      wccols = wcwidth(wc);
+      cols += (wccols == -1? 1 : wccols);
     }
   return cols;
 }
+#else
+# define count_cols(mbs) ((int)(strlen(mbs)))
+#endif
 
 /* Translation note: "ETA" is English-centric, but this must
    be short, ideally 3 chars.  Abbreviate if necessary.  */
@@ -796,7 +813,11 @@ get_eta (void)
       int nbytes;
       int ncols;
 
+#if USE_NLS_PROGRESS_BAR
       eta_trans = _(eta_str);
+#else
+      eta_trans = eta_str;
+#endif
 
       /* Determine the number of bytes used in the translated string,
        * versus the number of columns used. This is to figure out how
@@ -855,12 +876,12 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
      "[]"              - progress bar decorations - 2 chars
      " nnn,nnn,nnn"    - downloaded bytes         - 12 chars or very rarely more
      " 12.5K/s"        - download rate             - 8 chars
-     "  eta 36m 51s"   - ETA                      - 13 chars
+     "  eta 36m 51s"   - ETA                      - 14 chars
 
      "=====>..."       - progress bar             - the rest
   */
   int dlbytes_size = 1 + MAX (size_grouped_len, 11);
-  int progress_size = bp->width - (4 + 2 + dlbytes_size + 8 + 13);
+  int progress_size = bp->width - (4 + 2 + dlbytes_size + 8 + 14);
 
   if (progress_size < 5)
     progress_size = 0;
@@ -1028,8 +1049,6 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
       move_to_end (p);
     }
 
-  assert (p - bp->buffer - bytes_cols_diff - size_grouped_diff <= bp->width);
-
   while (p - bp->buffer - bytes_cols_diff - size_grouped_diff < bp->width)
     *p++ = ' ';
   *p = '\0';