diff options
author | Paolo Bonzini <bonzini@gnu.org> | 2012-01-03 08:52:28 +0100 |
---|---|---|
committer | Paolo Bonzini <bonzini@gnu.org> | 2012-01-03 08:54:29 +0100 |
commit | 3f99160691ffee1356ff3757d91a389564270578 (patch) | |
tree | a136a1b4e9cf6114442f9662fd2347da9c36ec5a | |
parent | bda9087261b3c9b2fcea68d7bf195b8a3d85d736 (diff) | |
download | grep-3f99160691ffee1356ff3757d91a389564270578.tar.gz |
colorize: use isatty module
* bootstrap.conf: Add isatty module.
* gnulib: Update to latest.
* lib/colorize.h: Remove argument from should_colorize.
* lib/ms/colorize.h: Likewise.
* lib/colorize-impl.c: Factor isatty call out of here...
* lib/ms/colorize-impl.c: ... and here...
* src/main.c: ... into here.
-rw-r--r-- | bootstrap.conf | 1 | ||||
m--------- | gnulib | 0 | ||||
-rw-r--r-- | lib/colorize-impl.c | 11 | ||||
-rw-r--r-- | lib/colorize.h | 2 | ||||
-rw-r--r-- | lib/ms/colorize-impl.c | 22 | ||||
-rw-r--r-- | lib/ms/colorize.h | 2 | ||||
-rw-r--r-- | src/main.c | 2 |
7 files changed, 14 insertions, 26 deletions
diff --git a/bootstrap.conf b/bootstrap.conf index b02c26b5..4aee59a0 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -41,6 +41,7 @@ gnupload hard-locale ignore-value intprops +isatty isblank isdir iswctype diff --git a/gnulib b/gnulib -Subproject 55c6e4b6fe65fdfd5154228209a5c9828bb8ec9 +Subproject 464f9e7b25ea50440cd453931e18329844023fe diff --git a/lib/colorize-impl.c b/lib/colorize-impl.c index b7c0a3ff..e9d5c730 100644 --- a/lib/colorize-impl.c +++ b/lib/colorize-impl.c @@ -27,13 +27,8 @@ /* Return non-zero if we should highlight matches in output to file descriptor FD. */ int -should_colorize (int fd) +should_colorize (void) { - if (! isatty (fd)) - return 0; - else - { - char const *t = getenv ("TERM"); - return t && strcmp (t, "dumb") != 0; - } + char const *t = getenv ("TERM"); + return t && strcmp (t, "dumb") != 0; } diff --git a/lib/colorize.h b/lib/colorize.h index 104f7a03..93f3b10f 100644 --- a/lib/colorize.h +++ b/lib/colorize.h @@ -19,7 +19,7 @@ #include <stdio.h> static inline void init_colorize (void) { } -extern int should_colorize (int); +extern int should_colorize (void); /* Start a colorized text attribute on stdout using the SGR_START format; the attribute is specified by SGR_SEQ. */ diff --git a/lib/ms/colorize-impl.c b/lib/ms/colorize-impl.c index d9d9b959..7341fe20 100644 --- a/lib/ms/colorize-impl.c +++ b/lib/ms/colorize-impl.c @@ -49,22 +49,14 @@ init_colorize (void) /* Return non-zero if we should highlight matches in output. */ int -should_colorize (int fd) +should_colorize (void) { - if (! isatty (fd)) - return 0; - /* Windows isatty returns non-zero for the null device too. */ - else if (lseek (fd, SEEK_CUR, 0) != -1) - return 0; - else - { - /* $TERM is not normally defined on DOS/Windows, so don't require - it for highlighting. But some programs, like Emacs, do define - it when running Grep as a subprocess, so make sure they don't - set TERM=dumb. */ - char const *t = getenv ("TERM"); - return ! (t && strcmp (t, "dumb") == 0); - } + /* $TERM is not normally defined on DOS/Windows, so don't require + it for highlighting. But some programs, like Emacs, do define + it when running Grep as a subprocess, so make sure they don't + set TERM=dumb. */ + char const *t = getenv ("TERM"); + return ! (t && strcmp (t, "dumb") == 0); } /* Convert a color spec, a semi-colon separated list of the form diff --git a/lib/ms/colorize.h b/lib/ms/colorize.h index c49657d6..bb94e763 100644 --- a/lib/ms/colorize.h +++ b/lib/ms/colorize.h @@ -1,4 +1,4 @@ extern void colorize_init (void); -extern int should_colorize (int); +extern int should_colorize (void); extern void print_start_colorize (char const *, char const *); extern void print_end_colorize (char const *); @@ -2132,7 +2132,7 @@ main (int argc, char **argv) } if (color_option == 2) - color_option = should_colorize (STDOUT_FILENO); + color_option = isatty (STDOUT_FILENO) && should_colorize (); init_colorize (); /* POSIX.2 says that -q overrides -l, which in turn overrides the |