summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-02-23 06:47:03 +0100
committerDan McGee <dan@archlinux.org>2008-02-23 06:47:03 +0100
commit4c14dcc5804aa6736616d35aac4db1ea3b29985e (patch)
tree75a0378a5c82eb6927ef9f635ac7a33ee6171d55 /src
parenta6470956bc2db5acb821485e590822953966586a (diff)
downloadpacman-4c14dcc5804aa6736616d35aac4db1ea3b29985e.tar.gz
pacman-4c14dcc5804aa6736616d35aac4db1ea3b29985e.tar.xz
A few more wide character output fixes
Fix up the indentprint and list printing functions so they work properly. This output can be seen in places such as -Ss, -Si, -Qs, and -Qi. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/package.c15
-rw-r--r--src/pacman/util.c62
2 files changed, 55 insertions, 22 deletions
diff --git a/src/pacman/package.c b/src/pacman/package.c
index cc4be139..7019e7e6 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <limits.h>
#include <sys/stat.h>
+#include <wchar.h>
#include <alpm.h>
#include <alpm_list.h>
@@ -48,6 +49,8 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
char bdatestr[50] = "", idatestr[50] = "";
const alpm_list_t *i;
alpm_list_t *requiredby = NULL, *depstrings = NULL;
+ wchar_t *wcstr;
+ int len;
if(pkg == NULL) {
return;
@@ -86,8 +89,6 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
requiredby = alpm_pkg_compute_requiredby(pkg);
}
- descheader = _("Description : ");
-
/* actual output */
if(level == 0) {
string_display(_("Filename :"), alpm_pkg_get_filename(pkg));
@@ -136,8 +137,16 @@ void dump_pkg_full(pmpkg_t *pkg, int level)
}
/* printed using a variable to make i18n safe */
+ descheader = _("Description : ");
+ /* len goes from # bytes -> # chars -> # cols */
+ len = strlen(descheader) + 1;
+ wcstr = calloc(len, sizeof(wchar_t));
+ len = mbstowcs(wcstr, descheader, len);
+ len = wcswidth(wcstr, len);
+ free(wcstr);
+ /* we can finally print the darn thing */
printf("%s", descheader);
- indentprint(alpm_pkg_get_desc(pkg), mbstowcs(NULL, descheader, 0));
+ indentprint(alpm_pkg_get_desc(pkg), len);
printf("\n\n");
/* Print additional package info if info flag passed more than once */
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 20f4c072..42436e26 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -34,6 +34,7 @@
#include <dirent.h>
#include <unistd.h>
#include <limits.h>
+#include <wchar.h>
#include <alpm.h>
#include <alpm_list.h>
@@ -219,37 +220,46 @@ char *mdirname(const char *path)
*/
void indentprint(const char *str, int indent)
{
- const char *p = str;
- int cidx = indent;
+ wchar_t *wcstr;
+ const wchar_t *p;
+ int len, cidx;
+
+ len = strlen(str) + 1;
+ wcstr = calloc(len, sizeof(wchar_t));
+ len = mbstowcs(wcstr, str, len);
+ p = wcstr;
+ cidx = indent;
while(*p) {
- if(*p == ' ') {
- const char *next = NULL;
- int len;
+ if(*p == L' ') {
+ const wchar_t *q, *next;
p++;
- if(p == NULL || *p == ' ') continue;
- next = strchr(p, ' ');
+ if(p == NULL || *p == L' ') continue;
+ next = wcschr(p, L' ');
if(next == NULL) {
- next = p + mbstowcs(NULL, p, 0);
+ next = p + wcslen(p);
+ }
+ /* len captures # cols */
+ len = 0;
+ q = p;
+ while(q < next) {
+ len += wcwidth(*q++);
}
- len = next - p;
if(len > (getcols() - cidx - 1)) {
- /* newline */
- int i;
- fprintf(stdout, "\n");
- for(i = 0; i < indent; i++) {
- fprintf(stdout, " ");
- }
+ /* wrap to a newline and reindent */
+ fprintf(stdout, "\n%-*s", indent, "");
cidx = indent;
} else {
printf(" ");
cidx++;
}
+ continue;
}
- fprintf(stdout, "%c", *p);
+ fprintf(stdout, "%lc", (wint_t)*p);
+ cidx += wcwidth(*p);
p++;
- cidx++;
}
+ free(wcstr);
}
/* Convert a string to uppercase
@@ -389,14 +399,28 @@ void list_display(const char *title, const alpm_list_t *list)
{
const alpm_list_t *i;
int cols, len;
+ wchar_t *wcstr;
+
+ /* len goes from # bytes -> # chars -> # cols */
+ len = strlen(title) + 1;
+ wcstr = calloc(len, sizeof(wchar_t));
+ len = mbstowcs(wcstr, title, len);
+ len = wcswidth(wcstr, len);
+ free(wcstr);
- len = mbstowcs(NULL, title, 0);
printf("%s ", title);
if(list) {
for(i = list, cols = len; i; i = alpm_list_next(i)) {
char *str = alpm_list_getdata(i);
- int s = mbstowcs(NULL, str, 0) + 2;
+ /* s goes from # bytes -> # chars -> # cols */
+ int s = strlen(str) + 1;
+ wcstr = calloc(s, sizeof(wchar_t));
+ s = mbstowcs(wcstr, str, s);
+ s = wcswidth(wcstr, s);
+ free(wcstr);
+ /* two additional spaces are added to the length */
+ s += 2;
int maxcols = getcols();
if(s + cols >= maxcols) {
int i;