From 2374c81e55abc0f7252fad7eb53d2b75bb33f750 Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Sun, 17 Feb 2008 23:31:26 +0100 Subject: Fix conflict progress bar with UTF-8 chars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes FS#6437. Dan already explained the problem in that bug report. Instead of letting printf deal with the length of utf8 strings, we can handle it more explicitly in the case of conflict progress bar, just like we do for add/remove progress bars. We compute the remaining space left for displaying the pkgname in case of add/remove, and an empty string in case of conflict. Before : (1/1) Prüfe auf Dateikonflikte [###################] 100% (1/1) Aktualisiere rxvt-unicode [###################] 100% After : (1/1) Prüfe auf Dateikonflikte [###################] 100% (1/1) Aktualisiere rxvt-unicode [###################] 100% Signed-off-by: Chantry Xavier Signed-off-by: Dan McGee --- src/pacman/callback.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 268a8a7f..cf07a09d 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -329,9 +329,8 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, /* size of line to allocate for text printing (e.g. not progressbar) */ const int infolen = 50; - int tmp, digits, oprlen, textlen, pkglen; + int tmp, digits, oprlen, textlen, remainlen; char *opr = NULL; - wchar_t *wcopr = NULL; if(config->noprogressbar) { return; @@ -373,15 +372,6 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, opr = _("checking for file conflicts"); break; } - /* convert above strings to wide chars */ - oprlen = strlen(opr); - wcopr = calloc(oprlen, sizeof(wchar_t)); - if(!wcopr) { - fprintf(stderr, "malloc failure: could not allocate %zd bytes\n", - strlen(opr) * sizeof(wchar_t)); - return; - } - oprlen = mbstowcs(wcopr, opr, oprlen); /* find # of digits in package counts to scale output */ digits = 1; @@ -392,30 +382,24 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, /* determine room left for non-digits text [not ( 1/12) part] */ textlen = infolen - 3 - (2 * digits); - /* room left for package name */ - pkglen = textlen - oprlen - 1; + + oprlen = mbstowcs(NULL, opr, 0); + /* room left (eg for package name) */ + remainlen = textlen - oprlen - 1; switch (event) { case PM_TRANS_PROGRESS_ADD_START: case PM_TRANS_PROGRESS_UPGRADE_START: case PM_TRANS_PROGRESS_REMOVE_START: - /* old way of doing it, but ISO C does not recognize it - printf("(%2$*1$d/%3$*1$d) %4$s %6$-*5$.*5$s", digits, remain, howmany, - opr, pkglen, pkgname);*/ printf("(%*d/%*d) %s %-*.*s", digits, remain, digits, howmany, - opr, pkglen, pkglen, pkgname); + opr, remainlen, remainlen, pkgname); break; case PM_TRANS_PROGRESS_CONFLICTS_START: - /* old way of doing it, but ISO C does not recognize it - printf("(%2$*1$d/%3$*1$d) %5$-*4$s", digits, remain, howmany, - textlen, opr);*/ - printf("(%*d/%*d) %-*s", digits, remain, digits, howmany, - textlen, opr); + printf("(%*d/%*d) %s %-*s", digits, remain, digits, howmany, + opr, remainlen, ""); break; } - free(wcopr); - /* call refactored fill progress function */ fill_progress(percent, percent, getcols() - infolen); -- cgit v1.2.3-70-g09d2