Bug#240989: procps/watch Unicode patch
tags 240989 + patch thanks Hi Jarrod, hi bts. On Tue, Nov 03, 2009 at 07:24:27PM +, Jarrod Lowe wrote: I have written a patch for this issue. I have mangled your patch into a dpatch file which applies after all other dpatch patches included in the current Debian package. Seems to work for me, but no guaranties... greetings, Uli diff -urN procps-3.2.8/debian/changelog procps-3.2.8~utf8/debian/changelog --- procps-3.2.8/debian/changelog 2010-01-08 12:49:03.0 +0100 +++ procps-3.2.8~utf8/debian/changelog 2010-01-08 12:46:53.0 +0100 @@ -1,3 +1,10 @@ +procps (1:3.2.8-2.1) UNRELEASED; urgency=low + + * No upload at all, not even an NMU... + * added watch-unicode patch by Jarrod Lowe Closes: #240989 + + -- Uli Martens u...@youam.net Fri, 08 Jan 2010 10:12:07 +0100 + procps (1:3.2.8-2) unstable; urgency=low * ps displays supplementary groups Closes: #506303 diff -urN procps-3.2.8/debian/control procps-3.2.8~utf8/debian/control --- procps-3.2.8/debian/control 2010-01-08 12:49:03.0 +0100 +++ procps-3.2.8~utf8/debian/control2010-01-11 09:51:30.0 +0100 @@ -2,7 +2,7 @@ Section: admin Priority: required Maintainer: Craig Small csm...@debian.org -Build-Depends: debhelper (= 7), libncurses5-dev, make (= 3.78.1-8), dpatch +Build-Depends: debhelper (= 7), libncurses5-dev, libncursesw5-dev, make (= 3.78.1-8), dpatch Standards-Version: 3.8.3 Homepage: http://procps.sf.net/ diff -urN procps-3.2.8/debian/patches/00list procps-3.2.8~utf8/debian/patches/00list --- procps-3.2.8/debian/patches/00list 2010-01-08 12:49:03.0 +0100 +++ procps-3.2.8~utf8/debian/patches/00list 2010-01-08 12:46:53.0 +0100 @@ -51,3 +51,4 @@ 55_top_highlight 60_top_nohz 65_fix_partition_format +70_watch_unicode diff -urN procps-3.2.8/debian/patches/70_watch_unicode.dpatch procps-3.2.8~utf8/debian/patches/70_watch_unicode.dpatch --- procps-3.2.8/debian/patches/70_watch_unicode.dpatch 1970-01-01 01:00:00.0 +0100 +++ procps-3.2.8~utf8/debian/patches/70_watch_unicode.dpatch2010-01-11 09:50:29.0 +0100 @@ -0,0 +1,301 @@ +#! /bin/sh /usr/share/dpatch/dpatch-run +## 70_watch-unicode.dpatch by Jarrod Lowe pro...@rrod.net +## +## All lines beginning with `## DP:' are a description of the patch. +## DP: add support for unicode characters + +...@dpatch@ +diff -urNad procps-3.2.8~/AUTHORS procps-3.2.8/AUTHORS +--- procps-3.2.8~/AUTHORS 2010-01-08 09:55:26.0 +0100 procps-3.2.8/AUTHORS 2010-01-08 09:59:12.0 +0100 +@@ -47,4 +47,5 @@ + watch: + Tony Rems re...@unisoft.com + Mike Coleman m...@acm.org ++Jarrod Lowe pro...@rrod.net + +diff -urNad procps-3.2.8~/Makefile procps-3.2.8/Makefile +--- procps-3.2.8~/Makefile 2010-01-08 09:58:52.0 +0100 procps-3.2.8/Makefile 2010-01-08 10:00:27.0 +0100 +@@ -68,6 +68,7 @@ + _TARFILES := Makefile + + CURSES := -lncurses ++CURSESW := -lncursesw + + # This seems about right for the dynamic library stuff. + # Something like this is probably needed to make the SE Linux +@@ -119,7 +120,7 @@ + # Unlike the kernel one, this check_gcc goes all the way to + # producing an executable. There might be a -m64 that works + # until you go looking for a 64-bit curses library. +-check_gcc = $(shell if $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) dummy.c $(ALL_LDFLAGS) $(1) -o will_this_file_really_exist.tmp $(CURSES) /dev/null 21; then echo $(1); else echo $(2); fi ; rm -f will_this_file_really_exist.tmp) ++check_gcc = $(shell if $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) dummy.c $(ALL_LDFLAGS) $(1) -o will_this_file_really_exist.tmp $(CURSES) $(CURSESW) /dev/null 21; then echo $(1); else echo $(2); fi ; rm -f will_this_file_really_exist.tmp) + + # Be 64-bit if at all possible. In a cross-compiling situation, one may + # do make m64=-m32 lib64=lib to produce 32-bit executables. DO NOT +@@ -250,7 +251,7 @@ + $(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ $(CURSES) + + watch: % : %.o +- $(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ $(CURSES) ++ $(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ $(CURSESW) + + progX -- progY + +diff -urNad procps-3.2.8~/watch.1 procps-3.2.8/watch.1 +--- procps-3.2.8~/watch.1 2010-01-08 09:58:52.0 +0100 procps-3.2.8/watch.1 2010-01-08 10:04:37.0 +0100 +@@ -139,6 +139,16 @@ + Non-printing characters are stripped from program output. Use cat -v as + part of the command pipeline if you want to see them. + .PP ++Combining Characters that are supposed to display on the character at the ++last column on the screen may display one column early, or they may not ++display at all. ++.PP ++Combining Characters never count as different in ++.I --differences ++mode. Only the base character counts. ++.PP ++Blank lines directly after a line which ends in the last column do not ++display. + .I \-\-precise + mode doesn't yet have advanced temporal distortion technology to + compensate for a +@@ -161,6
Bug#240989: procps/watch Unicode patch
I have written a patch for this issue. Logged in Ubuntu: https://bugs.launchpad.net/ubuntu/+source/procps/+bug/318221 I have tried to contact the upstream, but have failed to do so - the email addresses in the man page do not seem to be read, and the mailing list contains only spam. -- Jarrod Lowe diff -du -r procps-3.2.7-orig/AUTHORS procps-3.2.7/AUTHORS --- procps-3.2.7-orig/AUTHORS 2002-10-10 22:14:34.0 +0100 +++ procps-3.2.7/AUTHORS 2008-10-04 14:50:10.0 +0100 @@ -47,4 +47,5 @@ watch: Tony Rems re...@unisoft.com Mike Coleman m...@acm.org +Jarrod Lowe pro...@rrod.net diff -du -r procps-3.2.7-orig/Makefile procps-3.2.7/Makefile --- procps-3.2.7-orig/Makefile 2006-06-24 10:02:25.0 +0100 +++ procps-3.2.7/Makefile 2008-10-04 15:05:50.0 +0100 @@ -68,6 +68,7 @@ _TARFILES := Makefile CURSES := -lncurses +CURSESW := -lncursesw # This seems about right for the dynamic library stuff. # Something like this is probably needed to make the SE Linux @@ -119,7 +120,7 @@ # Unlike the kernel one, this check_gcc goes all the way to # producing an executable. There might be a -m64 that works # until you go looking for a 64-bit curses library. -check_gcc = $(shell if $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) dummy.c $(ALL_LDFLAGS) $(1) -o /dev/null $(CURSES) /dev/null 21; then echo $(1); else echo $(2); fi ;) +check_gcc = $(shell if $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) dummy.c $(ALL_LDFLAGS) $(1) -o /dev/null $(CURSES) $(CURSESW) /dev/null 21; then echo $(1); else echo $(2); fi ;) # Be 64-bit if at all possible. In a cross-compiling situation, one may # do make m64=-m32 lib64=lib to produce 32-bit executables. DO NOT @@ -250,7 +251,7 @@ $(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ $(CURSES) watch: % : %.o - $(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ $(CURSES) + $(CC) $(ALL_CFLAGS) $^ $(ALL_LDFLAGS) -o $@ $(CURSESW) progX -- progY diff -du -r procps-3.2.7-orig/watch.1 procps-3.2.7/watch.1 --- procps-3.2.7-orig/watch.1 2003-02-09 07:05:25.0 + +++ procps-3.2.7/watch.1 2008-10-04 14:46:46.0 +0100 @@ -79,9 +79,21 @@ .PP Non-printing characters are stripped from program output. Use cat -v as part of the command pipeline if you want to see them. +.PP +Combining Characters that are supposed to display on the character at the +last column on the screen may display one column early, or they may not +display at all. +.PP +Combining Characters never count as different in +.I --differences +mode. Only the base character counts. +.PP +Blank lines directly after a line which ends in the last column do not +display. .SH AUTHORS The original .B watch was written by Tony Rems re...@unisoft.com in 1991, with mods and corrections by Francois Pinard. It was reworked and new features added by -Mike Coleman m...@acm.org in 1999. +Mike Coleman m...@acm.org in 1999. Unicode support was added in 2009 +by Jarrod Lowe pro...@rrod.net. diff -du -r procps-3.2.7-orig/watch.c procps-3.2.7/watch.c --- procps-3.2.7-orig/watch.c 2006-06-17 10:18:38.0 +0100 +++ procps-3.2.7/watch.c 2008-10-04 15:06:09.0 +0100 @@ -8,14 +8,17 @@ * Mike Coleman m...@acm.org. * * Changes by Albert Cahalan, 2002-2003. + * + * Unicode Support added by Jarrod Lowe pro...@rrod.net in 2009. */ -#define VERSION 0.2.0 +#define VERSION 0.3.0 +#include wchar.h #include ctype.h #include getopt.h #include signal.h -#include ncurses.h +#include ncursesw/ncurses.h #include stdio.h #include stdlib.h #include string.h @@ -25,6 +28,7 @@ #include termios.h #include locale.h #include proc/procps.h +#include errno.h #ifdef FORCE_8BIT #undef isprint @@ -134,6 +138,32 @@ } } +// read a wide character from a popen'd stream +#define MAX_ENC_BYTES 16 +wint_t my_getwc(FILE *s); +wint_t my_getwc(FILE *s) { + char i[MAX_ENC_BYTES]; //assuming no encoding ever consumes more than 16 bytes + int byte = 0; + int convert; + int x; + wchar_t rval; + while(1) { + i[byte] = getc(s); + if (i[byte]==EOF) { return WEOF; } + byte++; + errno = 0; + mbtowc(NULL, NULL, 0); + convert = mbtowc(rval, i, byte); + x = errno; + if(convert 0) { return rval; } //legal conversion + if(byte == MAX_ENC_BYTES) { + while(byte 1) { ungetc(i[--byte], s); } //at least *try* to fix up + errno = -EILSEQ; + return WEOF; + } + } +} + int main(int argc, char *argv[]) { @@ -143,7 +173,10 @@ option_help = 0, option_version = 0; double interval = 2; char *command; + wchar_t *wcommand = NULL; int command_length = 0; /* not including final \0 */ + int wcommand_columns = 0; /* not including final \0 */ + int wcommand_characters = 0; /* not including final \0 */ setlocale(LC_ALL, ); progname = argv[0]; @@ -216,6 +249,23 @@ command[command_length] = '\0'; } + // convert to wide for printing purposes + //mbstowcs(NULL, NULL, 0); + wcommand_characters = mbstowcs(NULL, command, 0); + if(wcommand_characters 0) { + fprintf(stderr, Unicode Handling Error\n); +