From e95867e6cc2f21c039f039e845982cdb87cd2cad Mon Sep 17 00:00:00 2001 From: Micah Cowan Date: Wed, 6 Feb 2008 18:10:24 -0800 Subject: [PATCH] Deal with progress bars in environs lacking mbtowc or wcwidth. --- configure.ac | 2 +- src/progress.c | 14 ++++++++++---- src/utils.c | 6 ++++++ src/wget.h | 13 +++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 5e7e7a2f..a49de3cd 100644 --- a/configure.ac +++ b/configure.ac @@ -197,7 +197,7 @@ AC_FUNC_ALLOCA AC_FUNC_MMAP AC_FUNC_FSEEKO AC_CHECK_FUNCS(strptime timegm snprintf vsnprintf vasprintf drand48) -AC_CHECK_FUNCS(strtoll usleep ftello sigblock sigsetjmp memrchr wcwidth) +AC_CHECK_FUNCS(strtoll usleep ftello sigblock sigsetjmp memrchr wcwidth mbtowc) if test x"$ENABLE_OPIE" = xyes; then AC_LIBOBJ([ftp-opie]) diff --git a/src/progress.c b/src/progress.c index 2db82fda..80dab04a 100644 --- a/src/progress.c +++ b/src/progress.c @@ -767,10 +767,7 @@ update_speed_ring (struct bar_progress *bp, wgint howmuch, double dltime) #endif } -#if ! HAVE_WCWIDTH -#define wcwidth(wc) (1) -#endif - +#if HAVE_MBTOWC && HAVE_WCWIDTH int count_cols (const char *mbs) { @@ -796,6 +793,11 @@ count_cols (const char *mbs) } return cols; } +#else +# define count_cols(mbs) ((int)(strlen(mbs))) +# undef wcwidth +# define wcwidth(wc) (1) +#endif /* Translation note: "ETA" is English-centric, but this must be short, ideally 3 chars. Abbreviate if necessary. */ @@ -811,7 +813,11 @@ get_eta (void) int nbytes; int ncols; +#if HAVE_WCWIDTH && HAVE_MBTOWC 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 diff --git a/src/utils.c b/src/utils.c index 5be8ddcf..920f3b54 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1221,6 +1221,12 @@ get_grouping_data (const char **sep, const char **grouping) struct lconv *lconv = localeconv (); cached_sep = lconv->thousands_sep; cached_grouping = lconv->grouping; +#if ! USE_NLS_PROGRESS_BAR + /* We can't count column widths, so ensure that the separator + * is single-byte only (let check below determine what byte). */ + if (strlen(cached_sep) > 1) + cached_sep = ""; +#endif if (!*cached_sep) { /* Many locales (such as "C" or "hr_HR") don't specify diff --git a/src/wget.h b/src/wget.h index 566c8ae4..08d8d837 100644 --- a/src/wget.h +++ b/src/wget.h @@ -67,6 +67,19 @@ as that of the covered work. */ variables. -- explanation partly taken from GNU make. */ #define N_(string) string +#if ! ENABLE_NLS +# undef HAVE_WCHAR_H +# undef HAVE_WCWIDTH +# undef HAVE_MBTOWC +#endif /* not ENABLE_NLS */ + +#if HAVE_WCWIDTH && HAVE_MBTOWC +# define USE_NLS_PROGRESS_BAR 1 +#else +/* Just to be a little paranoid about it. */ +# undef USE_NLS_PROGRESS_BAR +#endif + /* I18N NOTE: You will notice that none of the DEBUGP messages are marked as translatable. This is intentional, for a few reasons: