aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-24 07:44:03 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-24 07:44:03 +0100
commit9f93d621925966c22ee51fdcb5def8e131596f9b (patch)
treec1024fa92d6f422df6cf0991d5c9c8a4977b8625 /coreutils
parent5da9f96ad85a2d9119d92c7a3d89deca7d904210 (diff)
downloadbusybox-w32-9f93d621925966c22ee51fdcb5def8e131596f9b.tar.gz
busybox-w32-9f93d621925966c22ee51fdcb5def8e131596f9b.tar.bz2
busybox-w32-9f93d621925966c22ee51fdcb5def8e131596f9b.zip
libbb: better unicode width support. Hopefully fixes bug 839.
Also opens up a possibility to make other unicode stuff smaller and more correct later. but: function old new delta static.combining - 516 +516 bb_wcwidth - 328 +328 unicode_cut_nchars - 141 +141 mbstowc_internal - 93 +93 in_table - 78 +78 cal_main 899 961 +62 static.combining0x10000 - 40 +40 unicode_strlen - 31 +31 bb_mbstrlen 31 - -31 bb_mbstowcs 173 102 -71 ------------------------------------------------------------------------------ (add/remove: 7/1 grow/shrink: 1/1 up/down: 1289/-102) Total: 1187 bytes Uses code of Markus Kuhn, which is in public domain: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c "Permission to use, copy, modify, and distribute this software for any purpose and without fee is hereby granted. The author disclaims all warranties with regard to this software." Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cal.c28
-rw-r--r--coreutils/df.c2
-rw-r--r--coreutils/expand.c4
-rw-r--r--coreutils/ls.c6
4 files changed, 28 insertions, 12 deletions
diff --git a/coreutils/cal.c b/coreutils/cal.c
index e6f9af937..5ecb9131d 100644
--- a/coreutils/cal.c
+++ b/coreutils/cal.c
@@ -16,8 +16,8 @@
16 * 16 *
17 * Major size reduction... over 50% (>1.5k) on i386. 17 * Major size reduction... over 50% (>1.5k) on i386.
18 */ 18 */
19
20#include "libbb.h" 19#include "libbb.h"
20#include "unicode.h"
21 21
22/* We often use "unsigned" intead of "int", it's easier to div on most CPUs */ 22/* We often use "unsigned" intead of "int", it's easier to div on most CPUs */
23 23
@@ -83,9 +83,16 @@ int cal_main(int argc UNUSED_PARAM, char **argv)
83 time_t now; 83 time_t now;
84 unsigned month, year, flags, i; 84 unsigned month, year, flags, i;
85 char *month_names[12]; 85 char *month_names[12];
86 char day_headings[28]; /* 28 for julian, 21 for nonjulian */ 86 /* normal heading: */
87 /* "Su Mo Tu We Th Fr Sa" */
88 /* -j heading: */
89 /* " Su Mo Tu We Th Fr Sa" */
90 char day_headings[ENABLE_FEATURE_ASSUME_UNICODE ? 28 * 6 : 28];
91 IF_FEATURE_ASSUME_UNICODE(char *hp = day_headings;)
87 char buf[40]; 92 char buf[40];
88 93
94 init_unicode();
95
89 flags = getopt32(argv, "jy"); 96 flags = getopt32(argv, "jy");
90 /* This sets julian = flags & 1: */ 97 /* This sets julian = flags & 1: */
91 option_mask32 &= 1; 98 option_mask32 &= 1;
@@ -122,15 +129,24 @@ int cal_main(int argc UNUSED_PARAM, char **argv)
122 129
123 if (i < 7) { 130 if (i < 7) {
124 zero_tm.tm_wday = i; 131 zero_tm.tm_wday = i;
125//FIXME: unicode
126//Bug 839:
127//testcase with doublewidth Japanese chars: "LANG=zh_TW.utf8 cal"
128//perhaps use wc[s]width() to probe terminal width
129 /* abbreviated weekday name according to locale */ 132 /* abbreviated weekday name according to locale */
130 strftime(buf, sizeof(buf), "%a", &zero_tm); 133 strftime(buf, sizeof(buf), "%a", &zero_tm);
134#if ENABLE_FEATURE_ASSUME_UNICODE
135 if (julian)
136 *hp++ = ' ';
137 {
138 char *two_wchars = unicode_cut_nchars(2, buf);
139 strcpy(hp, two_wchars);
140 free(two_wchars);
141 }
142 hp += strlen(hp);
143 *hp++ = ' ';
144#else
131 strncpy(day_headings + i * (3+julian) + julian, buf, 2); 145 strncpy(day_headings + i * (3+julian) + julian, buf, 2);
146#endif
132 } 147 }
133 } while (++i < 12); 148 } while (++i < 12);
149 IF_FEATURE_ASSUME_UNICODE(hp[-1] = '\0';)
134 150
135 if (month) { 151 if (month) {
136 unsigned row, len, days[MAXDAYS]; 152 unsigned row, len, days[MAXDAYS];
diff --git a/coreutils/df.c b/coreutils/df.c
index bcde78393..ae68f0831 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -178,7 +178,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
178#endif 178#endif
179 179
180#if ENABLE_FEATURE_ASSUME_UNICODE 180#if ENABLE_FEATURE_ASSUME_UNICODE
181 dev_len = bb_mbstrlen(device); 181 dev_len = unicode_strlen(device);
182 if (dev_len > 20) { 182 if (dev_len > 20) {
183 printf("%s\n%20s", device, ""); 183 printf("%s\n%20s", device, "");
184 } else { 184 } else {
diff --git a/coreutils/expand.c b/coreutils/expand.c
index 649b4c175..2f6a708b5 100644
--- a/coreutils/expand.c
+++ b/coreutils/expand.c
@@ -49,7 +49,7 @@ static void expand(FILE *file, unsigned tab_size, unsigned opt)
49 unsigned len; 49 unsigned len;
50 *ptr = '\0'; 50 *ptr = '\0';
51# if ENABLE_FEATURE_ASSUME_UNICODE 51# if ENABLE_FEATURE_ASSUME_UNICODE
52 len = bb_mbstrlen(ptr_strbeg); 52 len = unicode_strlen(ptr_strbeg);
53# else 53# else
54 len = ptr - ptr_strbeg; 54 len = ptr - ptr_strbeg;
55# endif 55# endif
@@ -105,7 +105,7 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt)
105 char c; 105 char c;
106 c = ptr[n]; 106 c = ptr[n];
107 ptr[n] = '\0'; 107 ptr[n] = '\0';
108 len = bb_mbstrlen(ptr); 108 len = unicode_strlen(ptr);
109 ptr[n] = c; 109 ptr[n] = c;
110 } 110 }
111# else 111# else
diff --git a/coreutils/ls.c b/coreutils/ls.c
index b8da1adbb..e7544474b 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -550,7 +550,7 @@ static void showfiles(struct dnode **dn, unsigned nfiles)
550 } else { 550 } else {
551 /* find the longest file name, use that as the column width */ 551 /* find the longest file name, use that as the column width */
552 for (i = 0; dn[i]; i++) { 552 for (i = 0; dn[i]; i++) {
553 int len = bb_mbstrlen(dn[i]->name); 553 int len = unicode_strlen(dn[i]->name);
554 if (column_width < len) 554 if (column_width < len)
555 column_width = len; 555 column_width = len;
556 } 556 }
@@ -742,7 +742,7 @@ static int print_name(const char *name)
742{ 742{
743 if (option_mask32 & OPT_Q) { 743 if (option_mask32 & OPT_Q) {
744#if ENABLE_FEATURE_ASSUME_UNICODE 744#if ENABLE_FEATURE_ASSUME_UNICODE
745 unsigned len = 2 + bb_mbstrlen(name); 745 unsigned len = 2 + unicode_strlen(name);
746#else 746#else
747 unsigned len = 2; 747 unsigned len = 2;
748#endif 748#endif
@@ -762,7 +762,7 @@ static int print_name(const char *name)
762 /* No -Q: */ 762 /* No -Q: */
763#if ENABLE_FEATURE_ASSUME_UNICODE 763#if ENABLE_FEATURE_ASSUME_UNICODE
764 fputs(name, stdout); 764 fputs(name, stdout);
765 return bb_mbstrlen(name); 765 return unicode_strlen(name);
766#else 766#else
767 return printf("%s", name); 767 return printf("%s", name);
768#endif 768#endif