]> git.pld-linux.org Git - packages/util-linux.git/blob - util-linux-multibyte.patch
- uniformized configs to use system-auth where possible
[packages/util-linux.git] / util-linux-multibyte.patch
1 - better wide chars usage in the cal command
2 - cal not UTF-8-aware
3 - more(1) doesn't handle UTF-8 correctly.  In particular, underlining is broken.
4
5 --- util-linux-2.13-pre7/include/widechar.h.kzak        2005-08-01 20:18:35.000000000 +0200
6 +++ util-linux-2.13-pre7/include/widechar.h     2006-03-29 19:38:56.000000000 +0200
7 @@ -2,7 +2,7 @@
8  /* This file must be included last because the redefinition of wchar_t may
9     cause conflicts when system include files were included after it. */
10  
11 -#ifdef ENABLE_WIDECHAR
12 +#ifdef HAVE_WIDECHAR
13  
14  # include <wchar.h>
15  # include <wctype.h>
16 --- util-linux-2.13-pre7/misc-utils/cal.c.kzak  2006-03-29 19:40:26.000000000 +0200
17 +++ util-linux-2.13-pre7/misc-utils/cal.c       2006-03-29 19:40:34.000000000 +0200
18 @@ -355,7 +355,7 @@
19         exit(0);
20  }
21  
22 -#ifndef ENABLE_WIDECHAR
23 +#ifndef HAVE_WIDECHAR
24  static char *eos(char *s) {
25         while (s && *s)
26                 s++;
27 @@ -366,14 +366,14 @@
28  void headers_init(void)
29  {
30    int i, wd;
31 -#ifdef ENABLE_WIDECHAR
32 +#ifdef HAVE_WIDECHAR
33    wchar_t day_headings_wc[22],j_day_headings_wc[29];
34 -  wchar_t wd_wc[10];
35 +  char *cur_dh = day_headings, *cur_j_dh = j_day_headings;
36  #endif
37  
38    strcpy(day_headings,"");
39    strcpy(j_day_headings,"");
40 -#ifdef ENABLE_WIDECHAR
41 +#ifdef HAVE_WIDECHAR
42    wcscpy(day_headings_wc,L"");
43    wcscpy(j_day_headings_wc,L"");
44  #endif
45 @@ -385,30 +385,25 @@
46  #endif
47  
48    for(i = 0 ; i < 7 ; i++ ) {
49 +     ssize_t space_left;
50       wd = (i + week1stday) % 7;
51 -#ifdef ENABLE_WIDECHAR
52 +#ifdef HAVE_WIDECHAR
53 -     mbstowcs(wd_wc,weekday(wd),10);
54 -     if (wcswidth(wd_wc,10) < 3)
55 -            wcscat(j_day_headings_wc,L" ");
56 -     if (wcswidth(wd_wc,10) < 2) {
57 -            wcscat(day_headings_wc, L" ");
58 -            wcscat(j_day_headings_wc, L" ");
59 -     }
60 -     wcsncat(day_headings_wc,wd_wc,2);
61 -     wcsncat(j_day_headings_wc,wd_wc,3);
62 -     wcscat(day_headings_wc, L" ");
63 -     wcscat(j_day_headings_wc, L" ");
64 +     swprintf(day_headings_wc, sizeof(day_headings_wc)/sizeof(day_headings_wc[0]),
65 +               L"%1.2s ", weekday(wd));
66 +     swprintf(j_day_headings_wc, sizeof(j_day_headings_wc)/sizeof(j_day_headings_wc[0]),
67 +               L"%3.3s ", weekday(wd));
68 +     space_left = sizeof(day_headings)-(cur_dh-day_headings);
69 +     if(space_left <= 0) break;
70 +     cur_dh += wcstombs(cur_dh,day_headings_wc, space_left);
71 +     space_left = sizeof(j_day_headings)-(cur_j_dh-j_day_headings);
72 +     if(space_left <= 0) break;
73 +     cur_j_dh +=  wcstombs(cur_j_dh,j_day_headings_wc, space_left);
74  #else
75       sprintf(eos(day_headings), "%2.2s ", weekday(wd));
76       sprintf(eos(j_day_headings), "%3.3s ", weekday(wd));
77  #endif
78    }
79  
80 -#ifdef ENABLE_WIDECHAR
81 -  wcstombs(day_headings,day_headings_wc,sizeof(day_headings));
82 -  wcstombs(j_day_headings,j_day_headings_wc,sizeof(j_day_headings));
83 -#endif
84 -
85    trim_trailing_spaces(day_headings);
86    trim_trailing_spaces(j_day_headings);
87  #undef weekday
88 @@ -718,7 +718,7 @@
89  void
90  center_str(const char* src, char* dest, size_t dest_size, int width)
91  {
92 -#ifdef ENABLE_WIDECHAR
93 +#ifdef HAVE_WIDECHAR
94         wchar_t str_wc[FMT_ST_CHARS];
95  #endif
96         char str[FMT_ST_CHARS];
97 @@ -727,7 +727,7 @@
98  
99         len = strlen(src);
100  
101 -#ifdef ENABLE_WIDECHAR
102 +#ifdef HAVE_WIDECHAR
103         if (mbstowcs(str_wc, src, FMT_ST_CHARS) > 0) {
104                 wide_char_enabled = 1;
105                 len = wcswidth(str_wc, SIZE(str_wc));
106 @@ -736,7 +736,7 @@
107         if (len > width) {
108                 str_to_print=str;
109                 if (wide_char_enabled) {
110 -#ifdef ENABLE_WIDECHAR
111 +#ifdef HAVE_WIDECHAR
112                         str_wc[width]=L'\0';
113                         wcstombs(str, str_wc, SIZE(str));
114  #endif
115 --- util-linux-2.13-pre7/text-utils/column.c.kzak       2006-03-29 19:41:20.000000000 +0200
116 +++ util-linux-2.13-pre7/text-utils/column.c    2006-03-29 19:41:25.000000000 +0200
117 @@ -52,7 +52,7 @@
118  
119  #include "widechar.h"
120  
121 -#ifdef ENABLE_WIDECHAR
122 +#ifdef HAVE_WIDECHAR
123  #define wcs_width(s) wcswidth(s,wcslen(s))
124  static wchar_t *mbs_to_wcs(const char *);
125  #else
126 @@ -312,7 +312,7 @@
127         }
128  }
129  
130 -#ifdef ENABLE_WIDECHAR
131 +#ifdef HAVE_WIDECHAR
132  static wchar_t *mbs_to_wcs(const char *s)
133  {
134         size_t n;
135 @@ -330,7 +330,7 @@
136  }
137  #endif
138  
139 -#ifndef ENABLE_WIDECHAR
140 +#ifndef HAVE_WIDECHAR
141  static char *mtsafe_strtok(char *str, const char *delim, char **ptr)
142  {
143         if (str == NULL) {
144 --- util-linux-2.13-pre7/text-utils/pg.c.kzak   2006-03-29 19:41:52.000000000 +0200
145 +++ util-linux-2.13-pre7/text-utils/pg.c        2006-03-29 19:41:59.000000000 +0200
146 @@ -255,7 +255,7 @@
147         usage();
148  }
149  
150 -#ifdef ENABLE_WIDECHAR
151 +#ifdef HAVE_WIDECHAR
152  /*
153   * A mbstowcs()-alike function that transparently handles invalid sequences.
154   */
155 @@ -402,7 +402,7 @@
156         return 0;
157  }
158  
159 -#ifdef ENABLE_WIDECHAR
160 +#ifdef HAVE_WIDECHAR
161  /*
162   * Return the last character that will fit on the line at col columns
163   * in case MB_CUR_MAX > 1.
164 @@ -489,7 +489,7 @@
165         unsigned pos = 0;
166         char *t = s;
167  
168 -#ifdef ENABLE_WIDECHAR
169 +#ifdef HAVE_WIDECHAR
170         if (MB_CUR_MAX > 1)
171                 return endline_for_mb(col, s);
172  #endif
173 @@ -776,7 +776,7 @@
174         cmd.count = getcount(cmd.cmdline);
175  }
176  
177 -#ifdef ENABLE_WIDECHAR
178 +#ifdef HAVE_WIDECHAR
179  /*
180   * Remove backspace formatting, for searches
181   * in case MB_CUR_MAX > 1.
182 @@ -817,7 +817,7 @@
183  {
184         char *p = s, *q;
185  
186 -#ifdef ENABLE_WIDECHAR
187 +#ifdef HAVE_WIDECHAR
188         if (MB_CUR_MAX > 1)
189                 return colb_for_mb(s);
190  #endif
191 @@ -836,7 +836,7 @@
192         return s;
193  }
194  
195 -#ifdef ENABLE_WIDECHAR
196 +#ifdef HAVE_WIDECHAR
197  /*
198   * Convert nonprintable characters to spaces
199   * in case MB_CUR_MAX > 1.
200 @@ -867,7 +867,7 @@
201  static void
202  makeprint(char *s, size_t l)
203  {
204 -#ifdef ENABLE_WIDECHAR
205 +#ifdef HAVE_WIDECHAR
206         if (MB_CUR_MAX > 1)
207                 return makeprint_for_mb(s, l);
208  #endif
209 --- util-linux-2.13-pre7/text-utils/more.c.kzak 2006-03-29 19:41:01.000000000 +0200
210 +++ util-linux-2.13-pre7/text-utils/more.c      2006-03-29 19:41:08.000000000 +0200
211 @@ -782,7 +782,7 @@
212      int        column;
213      static int colflg;
214  
215 -#ifdef ENABLE_WIDECHAR
216 +#ifdef HAVE_WIDECHAR
217      int i;
218      wchar_t wc;
219      int wc_width;
220 @@ -805,7 +805,7 @@
221         c = Getc (f);
222      }
223      while (p < &Line[LINSIZ - 1]) {
224 -#ifdef ENABLE_WIDECHAR
225 +#ifdef HAVE_WIDECHAR
226         if (fold_opt && use_mbc_buffer_flag && MB_CUR_MAX > 1) {
227             use_mbc_buffer_flag = 0;
228             state_bak = state;
229 @@ -923,7 +923,7 @@
230             *length = p - Line;
231             return (column);
232         } else {
233 -#ifdef ENABLE_WIDECHAR
234 +#ifdef HAVE_WIDECHAR
235             if (fold_opt && MB_CUR_MAX > 1) {
236                 memset (mbc, '\0', MB_LEN_MAX);
237                 mbc_pos = 0;
238 @@ -1054,7 +1054,23 @@
239                     my_putstring(state ? ULenter : ULexit);
240             }
241             if (c != ' ' || pstate == 0 || state != 0 || ulglitch == 0)
242 +#ifdef HAVE_WIDECHAR
243 +           {
244 +               wchar_t wc;
245 +               size_t mblength;
246 +               mbstate_t state;
247 +               memset (&state, '\0', sizeof (mbstate_t));
248 +               s--; n++;
249 +               mblength = mbrtowc (&wc, s, n, &state);
250 +               if (mblength == (size_t) -2 || mblength == (size_t) -1)
251 +                       mblength = 1;
252 +               while (mblength--)
253 +                       putchar (*s++);
254 +               n += mblength;
255 +           }
256 +#else
257                 putchar(c);
258 +#endif
259             if (state && *chUL) {
260                 pr(chBS);
261                 my_putstring(chUL);
262 @@ -1867,7 +1867,7 @@
263         }
264         else if (((cc_t) c == otty.c_cc[VERASE]) && !slash) {
265             if (sp > buf) {
266 -#ifdef ENABLE_WIDECHAR
267 +#ifdef HAVE_WIDECHAR
268                 if (MB_CUR_MAX > 1)
269                   {
270                     wchar_t wc;
271 --- util-linux-2.13-pre7/text-utils/ul.c.kzak   2006-03-29 19:42:09.000000000 +0200
272 +++ util-linux-2.13-pre7/text-utils/ul.c        2006-03-29 19:42:25.000000000 +0200
273 @@ -50,7 +50,7 @@
274  
275  #include "widechar.h"
276  
277 -#ifdef ENABLE_WIDECHAR
278 +#ifdef HAVE_WIDECHAR
279  static int put1wc(int c) /* Output an ASCII character as a wide character */
280  {
281    if (putwchar(c) == WEOF)
This page took 0.050511 seconds and 3 git commands to generate.