diff options
author | Jim Meyering <jim@meyering.net> | 1998-06-28 21:53:05 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1998-06-28 21:53:05 +0000 |
commit | 73ab48d4e7f14690cc783f8b828ca7620e9eb754 (patch) | |
tree | 1253722504aa2904ace328b71b8dce1401d90af1 | |
parent | 73e6d60538bed13d93445cfac25e0726b6bac059 (diff) | |
download | coreutils-73ab48d4e7f14690cc783f8b828ca7620e9eb754.tar.xz |
experimental support for -t [optional fd] -- probably soon to be backed out
-rw-r--r-- | src/test.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/test.c b/src/test.c index 0ea0abb58..1d06348ae 100644 --- a/src/test.c +++ b/src/test.c @@ -134,7 +134,7 @@ test_syntax_error (char *format, char *arg) { fprintf (stderr, "%s: ", argv[0]); fprintf (stderr, format, arg); - fflush (stderr); + FFLUSH (stderr); test_exit (SHELL_BOOLEAN (FALSE)); } @@ -370,7 +370,7 @@ term (void) value = binary_operator (); /* Might be a switch type argument */ - else if ('-' == argv[pos][0] && 0 == argv[pos][2]) + else if ('-' == argv[pos][0] && argv[pos][1] && 0 == argv[pos][2]) { if (unop (argv[pos][1])) value = unary_operator (); @@ -627,7 +627,7 @@ binary_operator (void) static int unary_operator (void) { - long r, value; + long fd, value; struct stat stat_buf; switch (argv[pos][1]) @@ -784,14 +784,19 @@ unary_operator (void) return (TRUE == (0 != (stat_buf.st_mode & S_ISVTX))); #endif - case 't': /* File (fd) is a terminal? (fd) defaults to stdout. */ + case 't': /* File (fd) is a terminal? */ advance (0); - if (pos < argc && isint (argv[pos], &r)) + if (pos < argc) { + if (!isint (argv[pos], &fd)) + integer_expected_error (_("after -t")); advance (0); - return (TRUE == (isatty ((int) r))); } - return (TRUE == (isatty (1))); + else + { + fd = 1; + } + return (TRUE == (isatty ((int) fd))); case 'n': /* True if arg has some length. */ unary_advance (); @@ -874,12 +879,21 @@ unop (int op) } static int +one_argument (const char *s) +{ + if (STREQ (s, "-t")) + return (TRUE == (isatty (1))); + + return strlen (s) != 0; +} + +static int two_arguments (void) { int value; if (STREQ (argv[pos], "!")) - value = strlen (argv[pos+1]) == 0; + value = ! one_argument (argv[pos+1]); else if (argv[pos][0] == '-' && argv[pos][1] != '\0' && argv[pos][2] == '\0') @@ -931,7 +945,7 @@ posixtest (void) break; case 1: - value = strlen (argv[1]) != 0; + value = one_argument (argv[1]); pos = argc; break; |