From e24c22e308f3dfc0642a542ff2fd7158af489fd0 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 3 Mar 2007 09:43:16 +0000 Subject: * A little more hacking with wchar_t output, but nothing really changed in it. Eventually we'll make progress. * Rewrote the _alpm_splitdep function to behave more like all our other function calls. Use heap instead of stack allocation for the depend struct, so now it needs to be freed by the caller. --- src/pacman/trans.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/pacman/trans.c b/src/pacman/trans.c index 4af0aa41..55b40413 100644 --- a/src/pacman/trans.c +++ b/src/pacman/trans.c @@ -27,6 +27,7 @@ #include #include #include +#include #include /* pacman */ @@ -284,8 +285,9 @@ 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 i, digits, textlen, pkglen; + int tmp, digits, oprlen, textlen, pkglen; char *opr = NULL; + wchar_t *wcopr = NULL; if(config->noprogressbar) { return; @@ -318,6 +320,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, } prevpercent=percent; + /* set text of message to display */ switch (event) { case PM_TRANS_PROGRESS_ADD_START: opr = _("installing"); @@ -332,26 +335,31 @@ 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 = (wchar_t*)calloc(oprlen, sizeof(wchar_t)); + if(!wcopr) { + fprintf(stderr, "malloc failure: could not allocate %d bytes\n", + strlen(opr) * sizeof(wchar_t)); + } + oprlen = mbstowcs(wcopr, opr, oprlen); /* find # of digits in package counts to scale output */ digits = 1; - i = howmany; - while((i /= 10)) { + tmp = howmany; + while((tmp /= 10)) { ++digits; } /* determine room left for non-digits text [not ( 1/12) part] */ textlen = infolen - 3 - (2 * digits); /* room left for package name */ - pkglen = textlen - mbstowcs(NULL, opr, 0) - 1; + pkglen = textlen - oprlen - 1; switch (event) { case PM_TRANS_PROGRESS_ADD_START: case PM_TRANS_PROGRESS_UPGRADE_START: case PM_TRANS_PROGRESS_REMOVE_START: - /* TODO clean up so digits and pkglen aren't passed twice */ - /* TODO we may need some sort of wchar_t wprintf output here in order - * to get the lengths right, prinf works on bytes and not chars */ printf("(%2$*1$d/%3$*1$d) %4$s %6$-*5$.*5$s", digits, remain, howmany, opr, pkglen, pkgname); break; @@ -361,6 +369,8 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, break; } + free(wcopr); + /* call refactored fill progress function */ fill_progress(percent, getcols() - infolen); -- cgit v1.2.3-70-g09d2