Updated with Tizen:Base source codes
[external/procps.git] / packaging / procps-3.2.7-watch-unicode.patch
1 diff -u procps-3.2.7/Makefile procps/Makefile
2 --- procps-3.2.7/Makefile       2007-01-16 17:24:49.000000000 +0100
3 +++ procps/Makefile     2007-01-16 17:29:27.000000000 +0100
4 @@ -67,7 +67,7 @@
5  # plus the top-level Makefile to make it work stand-alone.
6  _TARFILES := Makefile
7  
8 -CURSES := -lncurses
9 +CURSES := -lncursesw
10  
11  # This seems about right for the dynamic library stuff.
12  # Something like this is probably needed to make the SE Linux
13 diff -u procps-3.2.7/watch.c procps/watch.c
14 --- procps-3.2.7/watch.c        2007-01-16 17:24:49.000000000 +0100
15 +++ procps/watch.c      2007-01-16 18:06:57.000000000 +0100
16 @@ -15,7 +15,7 @@
17  #include <ctype.h>
18  #include <getopt.h>
19  #include <signal.h>
20 -#include <ncurses.h>
21 +#include <ncursesw/ncurses.h>
22  #include <stdio.h>
23  #include <stdlib.h>
24  #include <string.h>
25 @@ -28,6 +28,8 @@
26  #include <sys/types.h>
27  #include <sys/stat.h>
28  #include <fcntl.h>
29 +#include <wchar.h>
30 +#include <wctype.h>
31  
32  #ifdef FORCE_8BIT
33  #undef isprint
34 @@ -137,6 +139,27 @@
35         }
36  }
37  
38 +static wint_t
39 +readwc(FILE *stream, mbstate_t *mbs)
40 +{
41 +       for (;;) {
42 +               int chr;
43 +               char c;
44 +               wchar_t wc;
45 +               size_t len;
46 +
47 +               chr = getc(stream);
48 +               if (chr == EOF)
49 +                       return WEOF;
50 +               c = chr;
51 +               len = mbrtowc(&wc, &c, 1, mbs);
52 +               if (len == (size_t)-1)
53 +                       memset(mbs, 0, sizeof(*mbs));
54 +               else if (len != (size_t)-2)
55 +                       return wc;
56 +       }
57 +}
58 +
59  int
60  main(int argc, char *argv[])
61  {
62 @@ -243,6 +266,7 @@
63                 FILE *p;
64                 int x, y;
65                 int oldeolseen = 1;
66 +               mbstate_t mbs;
67  
68                 if (screen_size_changed) {
69                         get_terminal_size();
70 @@ -276,49 +300,63 @@
71                         do_exit(2);
72                 }
73  
74 +               memset(&mbs, 0, sizeof(mbs));
75                 for (y = show_title; y < height; y++) {
76                         int eolseen = 0, tabpending = 0;
77                         for (x = 0; x < width; x++) {
78 -                               int c = ' ';
79 -                               int attr = 0;
80 +                               wint_t c = L' ';
81 +                               int attr = 0, c_width;
82 +                               cchar_t cc;
83 +                               wchar_t wstr[2];
84  
85                                 if (!eolseen) {
86                                         /* if there is a tab pending, just spit spaces until the
87                                            next stop instead of reading characters */
88                                         if (!tabpending)
89                                                 do
90 -                                                       c = getc(p);
91 -                                               while (c != EOF && !isprint(c)
92 -                                                      && c != '\n'
93 -                                                      && c != '\t');
94 -                                       if (c == '\n')
95 +                                                       c = readwc(p, &mbs);
96 +                                               while (c != WEOF && !iswprint(c)
97 +                                                      && c != L'\n'
98 +                                                      && c != L'\t');
99 +                                       if (c == L'\n')
100                                                 if (!oldeolseen && x == 0) {
101                                                         x = -1;
102                                                         continue;
103                                                 } else
104                                                         eolseen = 1;
105 -                                       else if (c == '\t')
106 +                                       else if (c == L'\t')
107                                                 tabpending = 1;
108 -                                       if (c == EOF || c == '\n' || c == '\t')
109 -                                               c = ' ';
110 +                                       if (c == WEOF || c == L'\n' || c == L'\t')
111 +                                               c = L' ';
112                                         if (tabpending && (((x + 1) % 8) == 0))
113                                                 tabpending = 0;
114                                 }
115 +                               wstr[0] = c;
116 +                               wstr[1] = 0;
117 +                               setcchar (&cc, wstr, 0, 0, NULL);
118                                 move(y, x);
119                                 if (option_differences) {
120 -                                       chtype oldch = inch();
121 -                                       char oldc = oldch & A_CHARTEXT;
122 +                                       cchar_t oldc;
123 +                                       wchar_t oldwstr[2];
124 +                                       attr_t attrs;
125 +                                       short colors;
126 +
127 +                                       in_wch(&oldc);
128 +                                       getcchar(&oldc, oldwstr, &attrs, &colors, NULL);
129                                         attr = !first_screen
130 -                                           && ((char)c != oldc
131 +                                           && (wstr[0] != oldwstr[0]
132                                                 ||
133                                                 (option_differences_cumulative
134 -                                                && (oldch & A_ATTRIBUTES)));
135 +                                                && attrs));
136                                 }
137                                 if (attr)
138                                         standout();
139 -                               addch(c);
140 +                               add_wch(&cc);
141                                 if (attr)
142                                         standend();
143 +                               c_width = wcwidth(c);
144 +                               if (c_width > 1)
145 +                                       x += c_width - 1;
146                         }
147                         oldeolseen = eolseen;
148                 }