Ticket #2113: procps-3.2.7-watch_fix.patch

File procps-3.2.7-watch_fix.patch, 3.6 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 <sys/types.h>
     29#include <sys/stat.h>
     30#include <fcntl.h>
     31#include <wchar.h>
     32#include <wctype.h>
    2833
    2934#ifdef FORCE_8BIT
    3035#undef isprint
     
    134139        }
    135140}
    136141
     142static wint_t
     143readwc(FILE *stream, mbstate_t *mbs)
     144{
     145        for (;;) {
     146                int chr;
     147                char c;
     148                wchar_t wc;
     149                size_t len;
     150
     151                chr = getc(stream);
     152                if (chr == EOF)
     153                        return WEOF;
     154                c = chr;
     155                len = mbrtowc(&wc, &c, 1, mbs);
     156                if (len == (size_t)-1)
     157                        memset(mbs, 0, sizeof(*mbs));
     158                else if (len != (size_t)-2)
     159                        return wc;
     160        }
     161}
     162
    137163int
    138164main(int argc, char *argv[])
    139165{
    140166        int optc;
     167        int fd;
    141168        int option_differences = 0,
    142169            option_differences_cumulative = 0,
    143170            option_help = 0, option_version = 0;
     
    239266                FILE *p;
    240267                int x, y;
    241268                int oldeolseen = 1;
     269                mbstate_t mbs;
    242270
    243271                if (screen_size_changed) {
    244272                        get_terminal_size();
     
    260288                        mvaddstr(0, width - tsl + 1, ts);
    261289                        free(header);
    262290                }
    263 
     291                close(0);
     292                fd=open("/dev/null",O_RDWR);
     293                if (fd!=0) {
     294                  perror("open");
     295                  do_exit(2);
     296                }
     297               
    264298                if (!(p = popen(command, "r"))) {
    265299                        perror("popen");
    266300                        do_exit(2);
    267301                }
    268302
     303                memset(&mbs, 0, sizeof(mbs));
    269304                for (y = show_title; y < height; y++) {
    270305                        int eolseen = 0, tabpending = 0;
    271306                        for (x = 0; x < width; x++) {
    272                                 int c = ' ';
    273                                 int attr = 0;
     307                                wint_t c = L' ';
     308                                int attr = 0, c_width;
     309                                cchar_t cc;
     310                                wchar_t wstr[2];
    274311
    275312                                if (!eolseen) {
    276313                                        /* if there is a tab pending, just spit spaces until the
    277314                                           next stop instead of reading characters */
    278315                                        if (!tabpending)
    279316                                                do
    280                                                         c = getc(p);
    281                                                 while (c != EOF && !isprint(c)
    282                                                        && c != '\n'
    283                                                        && c != '\t');
    284                                         if (c == '\n')
     317                                                        c = readwc(p, &mbs);
     318                                                while (c != WEOF && !iswprint(c)
     319                                                       && c != L'\n'
     320                                                       && c != L'\t');
     321                                        if (c == L'\n')
    285322                                                if (!oldeolseen && x == 0) {
    286323                                                        x = -1;
    287324                                                        continue;
    288325                                                } else
    289326                                                        eolseen = 1;
    290                                         else if (c == '\t')
     327                                        else if (c == L'\t')
    291328                                                tabpending = 1;
    292                                         if (c == EOF || c == '\n' || c == '\t')
    293                                                 c = ' ';
     329                                        if (c == WEOF || c == L'\n' || c == L'\t')
     330                                                c = L' ';
    294331                                        if (tabpending && (((x + 1) % 8) == 0))
    295332                                                tabpending = 0;
    296333                                }
     334                                wstr[0] = c;
     335                                wstr[1] = 0;
     336                                setcchar (&cc, wstr, 0, 0, NULL);
    297337                                move(y, x);
    298338                                if (option_differences) {
    299                                         int oldch = inch();
    300                                         char oldc = oldch & A_CHARTEXT;
     339                                        cchar_t oldc;
     340                                        wchar_t oldwstr[2];
     341                                        attr_t attrs;
     342                                        short colors;
     343
     344                                        in_wch(&oldc);
     345                                        getcchar(&oldc, oldwstr, &attrs, &colors, NULL);
    301346                                        attr = !first_screen
    302                                             && (c != oldc
     347                                            && (wstr[0] != oldwstr[0]
    303348                                                ||
    304349                                                (option_differences_cumulative
    305                                                  && (oldch & A_ATTRIBUTES)));
     350                                                 && attrs));
    306351                                }
    307352                                if (attr)
    308353                                        standout();
    309                                 addch(c);
     354                                add_wch(&cc);
    310355                                if (attr)
    311356                                        standend();
     357                                c_width = wcwidth(c);
     358                                if (c_width > 1)
     359                                        x += c_width - 1;
    312360                        }
    313361                        oldeolseen = eolseen;
    314362                }