updated on Thu Jan 19 20:01:47 UTC 2012
[aur-mirror.git] / selinux-procps / procps-3.2.7-watch-unicode.patch
blob1b3d97488d9a64a4c0cdf08102cd56e0c0f61826
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
8 -CURSES := -lncurses
9 +CURSES := -lncursesw
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 @@ -28,6 +28,8 @@
17 #include <termios.h>
18 #include <locale.h>
19 #include "proc/procps.h"
20 +#include <wchar.h>
21 +#include <wctype.h>
23 #ifdef FORCE_8BIT
24 #undef isprint
25 @@ -137,6 +139,27 @@
29 +static wint_t
30 +readwc(FILE *stream, mbstate_t *mbs)
32 + for (;;) {
33 + int chr;
34 + char c;
35 + wchar_t wc;
36 + size_t len;
38 + chr = getc(stream);
39 + if (chr == EOF)
40 + return WEOF;
41 + c = chr;
42 + len = mbrtowc(&wc, &c, 1, mbs);
43 + if (len == (size_t)-1)
44 + memset(mbs, 0, sizeof(*mbs));
45 + else if (len != (size_t)-2)
46 + return wc;
47 + }
50 int
51 main(int argc, char *argv[])
53 @@ -243,6 +266,7 @@
54 FILE *p;
55 int x, y;
56 int oldeolseen = 1;
57 + mbstate_t mbs;
59 if (screen_size_changed) {
60 get_terminal_size();
61 @@ -276,49 +300,63 @@
62 do_exit(2);
65 + memset(&mbs, 0, sizeof(mbs));
66 for (y = show_title; y < height; y++) {
67 int eolseen = 0, tabpending = 0;
68 for (x = 0; x < width; x++) {
69 - int c = ' ';
70 - int attr = 0;
71 + wint_t c = L' ';
72 + int attr = 0, c_width;
73 + cchar_t cc;
74 + wchar_t wstr[2];
76 if (!eolseen) {
77 /* if there is a tab pending, just spit spaces until the
78 next stop instead of reading characters */
79 if (!tabpending)
81 - c = getc(p);
82 - while (c != EOF && !isprint(c)
83 - && c != '\n'
84 - && c != '\t');
85 - if (c == '\n')
86 + c = readwc(p, &mbs);
87 + while (c != WEOF && !iswprint(c)
88 + && c != L'\n'
89 + && c != L'\t');
90 + if (c == L'\n')
91 if (!oldeolseen && x == 0) {
92 x = -1;
93 continue;
94 } else
95 eolseen = 1;
96 - else if (c == '\t')
97 + else if (c == L'\t')
98 tabpending = 1;
99 - if (c == EOF || c == '\n' || c == '\t')
100 - c = ' ';
101 + if (c == WEOF || c == L'\n' || c == L'\t')
102 + c = L' ';
103 if (tabpending && (((x + 1) % 8) == 0))
104 tabpending = 0;
106 + wstr[0] = c;
107 + wstr[1] = 0;
108 + setcchar (&cc, wstr, 0, 0, NULL);
109 move(y, x);
110 if (option_differences) {
111 - chtype oldch = inch();
112 - char oldc = oldch & A_CHARTEXT;
113 + cchar_t oldc;
114 + wchar_t oldwstr[2];
115 + attr_t attrs;
116 + short colors;
118 + in_wch(&oldc);
119 + getcchar(&oldc, oldwstr, &attrs, &colors, NULL);
120 attr = !first_screen
121 - && ((char)c != oldc
122 + && (wstr[0] != oldwstr[0]
124 (option_differences_cumulative
125 - && (oldch & A_ATTRIBUTES)));
126 + && attrs));
128 if (attr)
129 standout();
130 - addch(c);
131 + add_wch(&cc);
132 if (attr)
133 standend();
134 + c_width = wcwidth(c);
135 + if (c_width > 1)
136 + x += c_width - 1;
138 oldeolseen = eolseen;