diff options
Diffstat (limited to 'coreutils/cal.c')
-rw-r--r-- | coreutils/cal.c | 28 |
1 files changed, 22 insertions, 6 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]; |