]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blame - procps/patches/procps-3.2.8-watch_unicode-2.patch
Move all packages to root.
[people/ms/ipfire-3.x.git] / procps / patches / procps-3.2.8-watch_unicode-2.patch
CommitLineData
3de0614c
MT
1Submitted By: Matt Burgess <matthew_at_linuxfromscratch_dot_org>
2Date: 2009-05-11
3Initial Package Version: 3.2.8
4Upstream Status: Submitted
5Origin: http://wiki.linuxfromscratch.org/lfs/ticket/2113
6Description: Fixes a unicode related bug in the watch program
7
8diff -Naur procps-3.2.8.orig/Makefile procps-3.2.8/Makefile
9--- procps-3.2.8.orig/Makefile 2009-05-10 18:50:48.000000000 +0000
10+++ procps-3.2.8/Makefile 2009-05-12 19:06:50.000000000 +0000
11@@ -67,7 +67,7 @@
12 # plus the top-level Makefile to make it work stand-alone.
13 _TARFILES := Makefile
14
15-CURSES := -lncurses
16+CURSES := -lncursesw
17
18 # This seems about right for the dynamic library stuff.
19 # Something like this is probably needed to make the SE Linux
20diff -Naur procps-3.2.8.orig/watch.c procps-3.2.8/watch.c
21--- procps-3.2.8.orig/watch.c 2007-05-28 03:13:23.000000000 +0000
22+++ procps-3.2.8/watch.c 2009-05-12 19:17:25.000000000 +0000
23@@ -25,6 +25,8 @@
24 #include <termios.h>
25 #include <locale.h>
26 #include "proc/procps.h"
27+#include <wchar.h>
28+#include <wctype.h>
29
30 #ifdef FORCE_8BIT
31 #undef isprint
32@@ -134,6 +136,27 @@
33 }
34 }
35
36+static wint_t
37+readwc(FILE *stream, mbstate_t *mbs)
38+{
39+ for (;;) {
40+ int chr;
41+ char c;
42+ wchar_t wc;
43+ size_t len;
44+
45+ chr = getc(stream);
46+ if (chr == EOF)
47+ return WEOF;
48+ c = chr;
49+ len = mbrtowc(&wc, &c, 1, mbs);
50+ if (len == (size_t)-1)
51+ memset(mbs, 0, sizeof(*mbs));
52+ else if (len != (size_t)-2)
53+ return wc;
54+ }
55+}
56+
57 int
58 main(int argc, char *argv[])
59 {
60@@ -239,6 +262,7 @@
61 FILE *p;
62 int x, y;
63 int oldeolseen = 1;
64+ mbstate_t mbs;
65
66 if (screen_size_changed) {
67 get_terminal_size();
68@@ -266,49 +290,65 @@
69 do_exit(2);
70 }
71
72+ memset(&mbs, 0, sizeof(mbs));
73 for (y = show_title; y < height; y++) {
74 int eolseen = 0, tabpending = 0;
75 for (x = 0; x < width; x++) {
76- int c = ' ';
77- int attr = 0;
78+ wint_t c = L' ';
79+ int attr = 0, c_width;
80+ cchar_t cc;
81+ wchar_t wstr[2];
82
83 if (!eolseen) {
84 /* if there is a tab pending, just spit spaces until the
85 next stop instead of reading characters */
86 if (!tabpending)
87 do
88- c = getc(p);
89- while (c != EOF && !isprint(c)
90- && c != '\n'
91- && c != '\t');
92- if (c == '\n')
93+ c = readwc(p, &mbs);
94+ while (c != WEOF && !iswprint(c)
95+ && c != L'\n'
96+ && c != L'\t');
97+ if (c == L'\n')
98 if (!oldeolseen && x == 0) {
99 x = -1;
100 continue;
101 } else
102 eolseen = 1;
103- else if (c == '\t')
104+ else if (c == L'\t')
105 tabpending = 1;
106- if (c == EOF || c == '\n' || c == '\t')
107- c = ' ';
108+ if (c == WEOF || c == L'\n' || c == L'\t')
109+ c = L' ';
110 if (tabpending && (((x + 1) % 8) == 0))
111 tabpending = 0;
112 }
113+ wstr[0] = c;
114+ wstr[1] = 0;
115+ setcchar (&cc, wstr, 0, 0, NULL);
116 move(y, x);
117 if (option_differences) {
118- chtype oldch = inch();
119- char oldc = oldch & A_CHARTEXT;
120+ cchar_t oldc;
121+ wchar_t oldwstr[2];
122+ attr_t attrs;
123+ short colors;
124+
125+ in_wch(&oldc);
126+ getcchar(&oldc, oldwstr, &attrs, &colors, NULL);
127 attr = !first_screen
128- && ((char)c != oldc
129+ && (wstr[0] != oldwstr[0]
130 ||
131 (option_differences_cumulative
132- && (oldch & A_ATTRIBUTES)));
133+ && attrs));
134 }
135 if (attr)
136 standout();
137- addch(c);
138+ add_wch(&cc);
139+
140 if (attr)
141 standend();
142+ c_width = wcwidth(c);
143+ if (c_width > 1)
144+ x += c_width - 1;
145+
146 }
147 oldeolseen = eolseen;
148 }