util-linux/util-linux-2.12p-cal-wide.patch

54 lines
1.8 KiB
Diff
Raw Normal View History

--- util-linux-2.12p/misc-utils/cal.c.wide 2004-12-05 20:20:36.000000000 +0100
+++ util-linux-2.12p/misc-utils/cal.c 2006-01-02 15:13:50.000000000 +0100
@@ -368,7 +368,7 @@
int i, wd;
#ifdef ENABLE_WIDECHAR
wchar_t day_headings_wc[22],j_day_headings_wc[29];
- wchar_t wd_wc[10];
+ char *cur_dh = day_headings, *cur_j_dh = j_day_headings;
#endif
strcpy(day_headings,"");
@@ -385,30 +385,25 @@
#endif
for(i = 0 ; i < 7 ; i++ ) {
+ ssize_t space_left;
wd = (i + week1stday) % 7;
#ifdef ENABLE_WIDECHAR
- mbstowcs(wd_wc,weekday(wd),10);
- if (wcswidth(wd_wc,10) < 3)
- wcscat(j_day_headings_wc,L" ");
- if (wcswidth(wd_wc,10) < 2) {
- wcscat(day_headings_wc, L" ");
- wcscat(j_day_headings_wc, L" ");
- }
- wcsncat(day_headings_wc,wd_wc,2);
- wcsncat(j_day_headings_wc,wd_wc,3);
- wcscat(day_headings_wc, L" ");
- wcscat(j_day_headings_wc, L" ");
+ swprintf(day_headings_wc, sizeof(day_headings_wc)/sizeof(day_headings_wc[0]),
+ L"%1.2s ", weekday(wd));
+ swprintf(j_day_headings_wc, sizeof(j_day_headings_wc)/sizeof(j_day_headings_wc[0]),
+ L"%3.3s ", weekday(wd));
+ space_left = sizeof(day_headings)-(cur_dh-day_headings);
+ if(space_left <= 0) break;
+ cur_dh += wcstombs(cur_dh,day_headings_wc, space_left);
+ space_left = sizeof(j_day_headings)-(cur_j_dh-j_day_headings);
+ if(space_left <= 0) break;
+ cur_j_dh += wcstombs(cur_j_dh,j_day_headings_wc, space_left);
#else
sprintf(eos(day_headings), "%2.2s ", weekday(wd));
sprintf(eos(j_day_headings), "%3.3s ", weekday(wd));
#endif
}
-#ifdef ENABLE_WIDECHAR
- wcstombs(day_headings,day_headings_wc,sizeof(day_headings));
- wcstombs(j_day_headings,j_day_headings_wc,sizeof(j_day_headings));
-#endif
-
trim_trailing_spaces(day_headings);
trim_trailing_spaces(j_day_headings);
#undef weekday