Ticket #2113: procps-3.2.7-watch-unicode.patch

File procps-3.2.7-watch-unicode.patch, 3.2 KB (added by Arthur Demchenkov, 16 years ago)
  • procps-3.2.7

    diff -Naur procps-3.2.7.old/Makefile procps-3.2.7/Makefile
    old new  
    6767# plus the top-level Makefile to make it work stand-alone.
    6868_TARFILES := Makefile
    6969
    70 CURSES := -lncurses
     70CURSES := -lncursesw
    7171
    7272# This seems about right for the dynamic library stuff.
    7373# Something like this is probably needed to make the SE Linux
  • procps-3.2.7

    diff -Naur procps-3.2.7.old/watch.c procps-3.2.7/watch.c
    old new  
    2525#include <termios.h>
    2626#include <locale.h>
    2727#include "proc/procps.h"
     28#include <wchar.h>
     29#include <wctype.h>
    2830
    2931#ifdef FORCE_8BIT
    3032#undef isprint
     
    134136        }
    135137}
    136138
     139static wint_t
     140readwc(FILE *stream, mbstate_t *mbs)
     141{
     142        for (;;) {
     143                int chr;
     144                char c;
     145                wchar_t wc;
     146                size_t len;
     147
     148                chr = getc(stream);
     149                if (chr == EOF)
     150                        return WEOF;
     151                c = chr;
     152                len = mbrtowc(&wc, &c, 1, mbs);
     153                if (len == (size_t)-1)
     154                        memset(mbs, 0, sizeof(*mbs));
     155                else if (len != (size_t)-2)
     156                        return wc;
     157        }
     158}
     159
    137160int
    138161main(int argc, char *argv[])
    139162{
     
    239262                FILE *p;
    240263                int x, y;
    241264                int oldeolseen = 1;
     265                mbstate_t mbs;
    242266
    243267                if (screen_size_changed) {
    244268                        get_terminal_size();
     
    266290                        do_exit(2);
    267291                }
    268292
     293                memset(&mbs, 0, sizeof(mbs));
    269294                for (y = show_title; y < height; y++) {
    270295                        int eolseen = 0, tabpending = 0;
    271296                        for (x = 0; x < width; x++) {
    272                                 int c = ' ';
    273                                 int attr = 0;
     297                                wint_t c = L' ';
     298                                int attr = 0, c_width;
     299                                cchar_t cc;
     300                                wchar_t wstr[2];
    274301
    275302                                if (!eolseen) {
    276303                                        /* if there is a tab pending, just spit spaces until the
    277304                                           next stop instead of reading characters */
    278305                                        if (!tabpending)
    279306                                                do
    280                                                         c = getc(p);
    281                                                 while (c != EOF && !isprint(c)
    282                                                        && c != '\n'
    283                                                        && c != '\t');
    284                                         if (c == '\n')
     307                                                        c = readwc(p, &mbs);
     308                                                while (c != WEOF && !iswprint(c)
     309                                                       && c != L'\n'
     310                                                       && c != L'\t');
     311                                        if (c == L'\n')
    285312                                                if (!oldeolseen && x == 0) {
    286313                                                        x = -1;
    287314                                                        continue;
    288315                                                } else
    289316                                                        eolseen = 1;
    290                                         else if (c == '\t')
     317                                        else if (c == L'\t')
    291318                                                tabpending = 1;
    292                                         if (c == EOF || c == '\n' || c == '\t')
    293                                                 c = ' ';
     319                                        if (c == WEOF || c == L'\n' || c == L'\t')
     320                                                c = L' ';
    294321                                        if (tabpending && (((x + 1) % 8) == 0))
    295322                                                tabpending = 0;
    296323                                }
     324                                wstr[0] = c;
     325                                wstr[1] = 0;
     326                                setcchar (&cc, wstr, 0, 0, NULL);
    297327                                move(y, x);
    298328                                if (option_differences) {
    299                                         int oldch = inch();
    300                                         char oldc = oldch & A_CHARTEXT;
     329                                        cchar_t oldc;
     330                                        wchar_t oldwstr[2];
     331                                        attr_t attrs;
     332                                        short colors;
     333
     334                                        in_wch(&oldc);
     335                                        getcchar(&oldc, oldwstr, &attrs, &colors, NULL);
    301336                                        attr = !first_screen
    302                                             && (c != oldc
     337                                            && (wstr[0] != oldwstr[0]
    303338                                                ||
    304339                                                (option_differences_cumulative
    305                                                  && (oldch & A_ATTRIBUTES)));
     340                                                 && attrs));
    306341                                }
    307342                                if (attr)
    308343                                        standout();
    309                                 addch(c);
     344                                add_wch(&cc);
    310345                                if (attr)
    311346                                        standend();
     347                                c_width = wcwidth(c);
     348                                if (c_width > 1)
     349                                        x += c_width - 1;
    312350                        }
    313351                        oldeolseen = eolseen;
    314352                }