summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChantry Xavier <shiningxc@gmail.com>2008-02-17 23:31:26 +0100
committerDan McGee <dan@archlinux.org>2008-02-18 03:41:23 +0100
commit2374c81e55abc0f7252fad7eb53d2b75bb33f750 (patch)
tree112bb8e591fdb6000114767bb7dec44ada4995de
parent42f5579fd77e9b696024c4bc0eb5398c039c7256 (diff)
downloadpacman-2374c81e55abc0f7252fad7eb53d2b75bb33f750.tar.gz
pacman-2374c81e55abc0f7252fad7eb53d2b75bb33f750.tar.xz
Fix conflict progress bar with UTF-8 chars
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 <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--src/pacman/callback.c32
1 files 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);