- better wide chars usage in the cal command - cal not UTF-8-aware - more(1) doesn't handle UTF-8 correctly. In particular, underlining is broken. --- util-linux-2.13-pre7/include/widechar.h.kzak 2005-08-01 20:18:35.000000000 +0200 +++ util-linux-2.13-pre7/include/widechar.h 2006-03-29 19:38:56.000000000 +0200 @@ -2,7 +2,7 @@ /* This file must be included last because the redefinition of wchar_t may cause conflicts when system include files were included after it. */ -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR # include # include --- util-linux-2.13-pre7/misc-utils/cal.c.kzak 2006-03-29 19:40:26.000000000 +0200 +++ util-linux-2.13-pre7/misc-utils/cal.c 2006-03-29 19:40:34.000000000 +0200 @@ -355,7 +355,7 @@ exit(0); } -#ifndef ENABLE_WIDECHAR +#ifndef HAVE_WIDECHAR static char *eos(char *s) { while (s && *s) s++; @@ -366,14 +366,14 @@ void headers_init(void) { int i, wd; -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_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,""); strcpy(j_day_headings,""); -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR wcscpy(day_headings_wc,L""); wcscpy(j_day_headings_wc,L""); #endif @@ -385,30 +385,25 @@ #endif for(i = 0 ; i < 7 ; i++ ) { + ssize_t space_left; wd = (i + week1stday) % 7; -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_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 @@ -718,7 +718,7 @@ void center_str(const char* src, char* dest, size_t dest_size, int width) { -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR wchar_t str_wc[FMT_ST_CHARS]; #endif char str[FMT_ST_CHARS]; @@ -727,7 +727,7 @@ len = strlen(src); -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR if (mbstowcs(str_wc, src, FMT_ST_CHARS) > 0) { wide_char_enabled = 1; len = wcswidth(str_wc, SIZE(str_wc)); @@ -736,7 +736,7 @@ if (len > width) { str_to_print=str; if (wide_char_enabled) { -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR str_wc[width]=L'\0'; wcstombs(str, str_wc, SIZE(str)); #endif --- util-linux-2.13-pre7/text-utils/column.c.kzak 2006-03-29 19:41:20.000000000 +0200 +++ util-linux-2.13-pre7/text-utils/column.c 2006-03-29 19:41:25.000000000 +0200 @@ -52,7 +52,7 @@ #include "widechar.h" -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR #define wcs_width(s) wcswidth(s,wcslen(s)) static wchar_t *mbs_to_wcs(const char *); #else @@ -312,7 +312,7 @@ } } -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR static wchar_t *mbs_to_wcs(const char *s) { size_t n; @@ -330,7 +330,7 @@ } #endif -#ifndef ENABLE_WIDECHAR +#ifndef HAVE_WIDECHAR static char *mtsafe_strtok(char *str, const char *delim, char **ptr) { if (str == NULL) { --- util-linux-2.13-pre7/text-utils/pg.c.kzak 2006-03-29 19:41:52.000000000 +0200 +++ util-linux-2.13-pre7/text-utils/pg.c 2006-03-29 19:41:59.000000000 +0200 @@ -255,7 +255,7 @@ usage(); } -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR /* * A mbstowcs()-alike function that transparently handles invalid sequences. */ @@ -402,7 +402,7 @@ return 0; } -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR /* * Return the last character that will fit on the line at col columns * in case MB_CUR_MAX > 1. @@ -489,7 +489,7 @@ unsigned pos = 0; char *t = s; -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR if (MB_CUR_MAX > 1) return endline_for_mb(col, s); #endif @@ -776,7 +776,7 @@ cmd.count = getcount(cmd.cmdline); } -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR /* * Remove backspace formatting, for searches * in case MB_CUR_MAX > 1. @@ -817,7 +817,7 @@ { char *p = s, *q; -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR if (MB_CUR_MAX > 1) return colb_for_mb(s); #endif @@ -836,7 +836,7 @@ return s; } -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR /* * Convert nonprintable characters to spaces * in case MB_CUR_MAX > 1. @@ -867,7 +867,7 @@ static void makeprint(char *s, size_t l) { -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR if (MB_CUR_MAX > 1) return makeprint_for_mb(s, l); #endif --- util-linux-2.13-pre7/text-utils/more.c.kzak 2006-03-29 19:41:01.000000000 +0200 +++ util-linux-2.13-pre7/text-utils/more.c 2006-03-29 19:41:08.000000000 +0200 @@ -782,7 +782,7 @@ int column; static int colflg; -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR int i; wchar_t wc; int wc_width; @@ -805,7 +805,7 @@ c = Getc (f); } while (p < &Line[LINSIZ - 1]) { -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR if (fold_opt && use_mbc_buffer_flag && MB_CUR_MAX > 1) { use_mbc_buffer_flag = 0; state_bak = state; @@ -923,7 +923,7 @@ *length = p - Line; return (column); } else { -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR if (fold_opt && MB_CUR_MAX > 1) { memset (mbc, '\0', MB_LEN_MAX); mbc_pos = 0; @@ -1054,7 +1054,23 @@ my_putstring(state ? ULenter : ULexit); } if (c != ' ' || pstate == 0 || state != 0 || ulglitch == 0) +#ifdef HAVE_WIDECHAR + { + wchar_t wc; + size_t mblength; + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); + s--; n++; + mblength = mbrtowc (&wc, s, n, &state); + if (mblength == (size_t) -2 || mblength == (size_t) -1) + mblength = 1; + while (mblength--) + putchar (*s++); + n += mblength; + } +#else putchar(c); +#endif if (state && *chUL) { pr(chBS); my_putstring(chUL); @@ -1867,7 +1867,7 @@ } else if (((cc_t) c == otty.c_cc[VERASE]) && !slash) { if (sp > buf) { -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR if (MB_CUR_MAX > 1) { wchar_t wc; --- util-linux-2.13-pre7/text-utils/ul.c.kzak 2006-03-29 19:42:09.000000000 +0200 +++ util-linux-2.13-pre7/text-utils/ul.c 2006-03-29 19:42:25.000000000 +0200 @@ -50,7 +50,7 @@ #include "widechar.h" -#ifdef ENABLE_WIDECHAR +#ifdef HAVE_WIDECHAR static int put1wc(int c) /* Output an ASCII character as a wide character */ { if (putwchar(c) == WEOF)