diff --git a/Makefile.am b/Makefile.am index 3d31da8c..3c5be856 100644 --- a/Makefile.am +++ b/Makefile.am @@ -54,7 +54,7 @@ dist_man_MANS += \ watch.1 slabtop_LDADD = @NCURSES_LIBS@ top_LDADD = @NCURSES_LIBS@ -watch_LDADD = @NCURSES_LIBS@ +watch_LDADD = @WATCH_NCURSES_LIBS@ endif kill_SOURCES = skill.c diff --git a/NEWS b/NEWS index 48936592..52ec6c29 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,36 @@ procps-ng-3.3.1 --> procps-ng-3.3.2 -------------------------------- * Redefined library to use version-info + * Imported a bunch of distribution patches: + watch: support unicode + watch: add precision wait time option -p + watch: interpret ANSI color code sequences + watch: add -exec and -beep flags and has better quoting + w: use environment to set user and from/host column widths + w: use COLUMNS environment if TIOCGWINSZ fails + w: bassman emulation with -o option + vmstat: do not scale si/so just like bi/bo + libprocps-ng: sysinfo.c: truncate the vmstat figure to 32 bits + tload: remote unneeded optarg and optind variables + sysctl: fix up some option processing + skill: kill prints perror + skill: do not treat skill null parameter as 0 + skill: fix too greedy option parser + libprocps-ng: readproc.c: some type conversion help + ps: rename SZ to SIZE + ps: add sorting to %mem for ps + pmap: provide information for -x option + pgrep: distinguish between invalid commandline parameters and '-?' + pgrep: fix compiler warning saved_start_time might be used uninitialized + pgrep: add -c option for counting number of matched proceesses + pwdx & libprocps-ng: Hurd does not have MAX_PATH defined + ps: --sort does not work with time argument + skill: add CR to warning line + contrib: minimal ps: define mips PAGE_SIZE + libproc-ng: prettyfy proc mount messages + ps: add build option to disable ps option warning + libproc-ng: support building without WCHAR support + sysctl: remove index() for buildroot procps-ng-3.3.0 --> procps-ng-3.3.1 -------------------------------- diff --git a/configure.ac b/configure.ac index 7be64c2a..63a3c37a 100644 --- a/configure.ac +++ b/configure.ac @@ -17,6 +17,15 @@ AM_PROG_CC_C_O AC_PROG_INSTALL AC_PROG_LN_S +AC_SUBST([WITH_WATCH8BIT]) +AC_ARG_ENABLE([watch8bit], + AS_HELP_STRING([--enable-watch8bit], [enable watch to be 8bit clean (requires ncursesw)]), + [enable_watch8bit=$enableval], + [enable_watch8bit="no"]) +if test "$enable_watch8bit" = "yes"; then + AC_DEFINE([WITH_WATCH8BIT], [1], [Enable 8 bit clean watch]) +fi + # Checks for header files. AC_HEADER_MAJOR AC_CHECK_HEADERS([\ @@ -106,9 +115,16 @@ else AC_MSG_ERROR([ncurses support missing/incomplete (for partial build use --without-ncurses)]) fi AM_CONDITIONAL(WITH_NCURSES, true) + if test "$enable_watch8bit" = yes; then + AC_CHECK_LIB([ncursesw], [addwstr], [WATCH_NCURSES_LIBS=-lncursesw], + [AC_MSG_ERROR([Cannot find ncurses wide library ncursesw with --enable-watch8bit])]) + else + WATCH_NCURSES_LIBS="-lncurses" + fi NCURSES_LIBS="-lncurses" fi AC_SUBST([NCURSES_LIBS]) +AC_SUBST([WATCH_NCURSES_LIBS]) usrbin_execdir='${exec_prefix}/usr/bin' AC_SUBST([usrbin_execdir]) diff --git a/watch.c b/watch.c index 188bbffe..a20ea4c9 100644 --- a/watch.c +++ b/watch.c @@ -12,10 +12,10 @@ * Unicode Support added by Jarrod Lowe in 2009. */ +#include "config.h" #include #include #include -#include #include #include #include @@ -26,8 +26,13 @@ #include #include #include "proc/procps.h" -#include "config.h" #include +#ifdef WITH_WATCH8BIT +#include +#include +#else +#include +#endif /* WITH_WATCH8BIT */ #ifdef FORCE_8BIT #undef isprint @@ -220,6 +225,7 @@ watch_usec_t get_time_usec() { return USECS_PER_SEC*now.tv_sec + now.tv_usec; } +#ifdef WITH_WATCH8BIT // read a wide character from a popen'd stream #define MAX_ENC_BYTES 16 wint_t my_getwc(FILE *s); @@ -245,6 +251,7 @@ wint_t my_getwc(FILE *s) { } } } +#endif /* WITH_WATCH8BIT */ int main(int argc, char *argv[]) @@ -259,13 +266,16 @@ main(int argc, char *argv[]) option_help = 0, option_version = 0; double interval = 2; char *command; - wchar_t *wcommand = NULL; char **command_argv; int command_length = 0; /* not including final \0 */ - int wcommand_columns = 0; /* not including final \0 */ - int wcommand_characters = 0; /* not including final \0 */ watch_usec_t next_loop; /* next loop time in us, used for precise time keeping only */ +#ifdef WITH_WATCH8BIT + wchar_t *wcommand = NULL; + int wcommand_columns = 0; /* not including final \0 */ + int wcommand_characters = 0; /* not including final \0 */ +#endif /* WITH_WATCH8BIT */ + int pipefd[2]; int status; pid_t child; @@ -362,6 +372,7 @@ main(int argc, char *argv[]) command[command_length] = '\0'; } +#ifdef WITH_WATCH8BIT // convert to wide for printing purposes //mbstowcs(NULL, NULL, 0); wcommand_characters = mbstowcs(NULL, command, 0); @@ -376,7 +387,7 @@ main(int argc, char *argv[]) } mbstowcs(wcommand, command, wcommand_characters+1); wcommand_columns = wcswidth(wcommand, -1); - +#endif /* WITH_WATCH8BIT */ get_terminal_size(); @@ -444,6 +455,7 @@ main(int argc, char *argv[]) if(width < tsl + hlen + 4) { mvaddstr(0, width - tsl - 4, "... "); }else{ +#ifdef WITH_WATCH8BIT if(width < tsl + hlen + wcommand_columns) { // print truncated int avail_columns = width - tsl - hlen; @@ -458,6 +470,9 @@ main(int argc, char *argv[]) }else{ mvaddwstr(0, hlen, wcommand); } +#else + mvaddnstr(0, hlen, command, width - tsl - hlen); +#endif /* WITH_WATCH8BIT */ } } } @@ -520,15 +535,22 @@ main(int argc, char *argv[]) for (y = show_title; y < height; y++) { int eolseen = 0, tabpending = 0; +#ifdef WITH_WATCH8BIT wint_t carry = WEOF; +#endif /* WITH_WATCH8BIT */ for (x = 0; x < width; x++) { +#ifdef WITH_WATCH8BIT wint_t c = ' '; +#else + int c = ' '; +#endif /* WITH_WATCH8BIT */ int attr = 0; if (!eolseen) { /* if there is a tab pending, just spit spaces until the next stop instead of reading characters */ if (!tabpending) +#ifdef WITH_WATCH8BIT do { if(carry == WEOF) { c = my_getwc(p); @@ -541,6 +563,14 @@ main(int argc, char *argv[]) && c != L'\n' && c != L'\t' && (c != L'\033' || option_color != 1)); +#else + do + c = getc(p); + while (c != EOF && !isprint(c) + && c != '\n' + && c != '\t' + && (c != L'\033' || option_color != 1)); +#endif /* WITH_WATCH8BIT */ if (c == L'\033' && option_color == 1) { x--; process_ansi(p); @@ -555,6 +585,7 @@ main(int argc, char *argv[]) eolseen = 1; else if (c == L'\t') tabpending = 1; +#ifdef WITH_WATCH8BIT if (x==width-1 && wcwidth(c)==2) { y++; x = -1; //process this double-width @@ -563,11 +594,16 @@ main(int argc, char *argv[]) } if (c == WEOF || c == L'\n' || c == L'\t') c = L' '; +#else + if (c == EOF || c == '\n' || c == '\t') + c = ' '; +#endif /* WITH_WATCH8BIT */ if (tabpending && (((x + 1) % 8) == 0)) tabpending = 0; } move(y, x); if (option_differences) { +#ifdef WITH_WATCH8BIT cchar_t oldc; in_wch(&oldc); attr = !first_screen @@ -575,14 +611,29 @@ main(int argc, char *argv[]) || (option_differences_cumulative && (oldc.attr & A_ATTRIBUTES))); +#else + chtype oldch = inch(); + unsigned char oldc = oldch & A_CHARTEXT; + attr = !first_screen + && ((unsigned char)c != oldc + || + (option_differences_cumulative + && (oldch & A_ATTRIBUTES))); +#endif /* WITH_WATCH8BIT */ } if (attr) standout(); +#ifdef WITH_WATCH8BIT addnwstr((wchar_t*)&c,1); +#else + addch(c); +#endif /* WITH_WATCH8BIT */ if (attr) standend(); +#ifdef WITH_WATCH8BIT if(wcwidth(c) == 0) { x--; } if(wcwidth(c) == 2) { x++; } +#endif /* WITH_WATCH8BIT */ } oldeolseen = eolseen; }