diff options
author | Jim Meyering <jim@meyering.net> | 1997-06-16 17:01:24 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1997-06-16 17:01:24 +0000 |
commit | a6526f2171e57e97a9dac6ba7acc37dabac7ce3d (patch) | |
tree | 0dac6c35d3bad0e73b193034ee6fcde195ce5b17 /src | |
parent | bfc9115ee5f086626ca3903d871b4ed9b21d8b49 (diff) | |
download | coreutils-a6526f2171e57e97a9dac6ba7acc37dabac7ce3d.tar.xz |
(eval6): Accept new unary operator, quote.
From Karl Heuer.
Diffstat (limited to 'src')
-rw-r--r-- | src/expr.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/expr.c b/src/expr.c index 44905b091..81a0169ed 100644 --- a/src/expr.c +++ b/src/expr.c @@ -60,6 +60,10 @@ struct valinfo }; typedef struct valinfo VALUE; +/* Non-zero if the POSIXLY_CORRECT environment variable is set. + The unary operator `quote' is disabled when this variable is zero. */ +static int posixly_correct; + /* The arguments given to the program, minus the program name. */ static char **args; @@ -134,6 +138,8 @@ separates increasing precedence groups. EXPRESSION may be:\n\ substr STRING POS LENGTH substring of STRING, POS counted from 1\n\ index STRING CHARS index in STRING where any CHARS is found, or 0\n\ length STRING length of STRING\n\ + quote TOKEN interpret TOKEN as a string, even if it is a\n\ + keyword like `match' or an operator like `/'\n\ \n\ ( EXPRESSION ) value of EXPRESSION\n\ ")); @@ -159,8 +165,10 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - /* Don't recognize --help or --version if POSIXLY_CORRECT is set. */ - if (getenv ("POSIXLY_CORRECT") == NULL) + posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL); + + /* Recognize --help or --version only if POSIXLY_CORRECT is not set. */ + if (!posixly_correct) parse_long_options (argc, argv, "expr", GNU_PACKAGE, VERSION, usage); if (argc == 1) @@ -494,7 +502,7 @@ eval7 (void) return str_value (*args++); } -/* Handle match, substr, index, and length keywords. */ +/* Handle match, substr, index, length, and quote keywords. */ static VALUE * eval6 (void) @@ -508,7 +516,14 @@ eval6 (void) #ifdef EVAL_TRACE trace ("eval6"); #endif - if (nextarg ("length")) + if (!posixly_correct && nextarg ("quote")) + { + args++; + if (nomoreargs ()) + error (2, 0, _("syntax error")); + return str_value (*args++); + } + else if (nextarg ("length")) { args++; r = eval6 (); |