aboutsummaryrefslogtreecommitdiff
path: root/bin/expr/expr.y
diff options
context:
space:
mode:
authorJ.T. Conklin <jtc@FreeBSD.org>1993-09-14 22:49:52 +0000
committerJ.T. Conklin <jtc@FreeBSD.org>1993-09-14 22:49:52 +0000
commit4cf61aba292a2954c39505c93c2ed48f8f2731c5 (patch)
tree8bb29816af975d51014410bf7a08d8aa612a6aa7 /bin/expr/expr.y
parent7de54fdffeae6ac3a35e63582e948e118b01d377 (diff)
downloadsrc-4cf61aba292a2954c39505c93c2ed48f8f2731c5.tar.gz
src-4cf61aba292a2954c39505c93c2ed48f8f2731c5.zip
Fix grammar to eliminate support for unary minus expressions -- they
weren't supported, they aren't standard, and they caused expr to dump core.
Notes
Notes: svn path=/head/; revision=468
Diffstat (limited to 'bin/expr/expr.y')
-rw-r--r--bin/expr/expr.y17
1 files changed, 8 insertions, 9 deletions
diff --git a/bin/expr/expr.y b/bin/expr/expr.y
index b22bffbbe29f..e7a0a5a7c47e 100644
--- a/bin/expr/expr.y
+++ b/bin/expr/expr.y
@@ -4,11 +4,13 @@
*
* Largely rewritten by J.T. Conklin (jtc@wimsey.com)
*
- * $Header: /b/source/CVS/src/bin/expr/expr.y,v 1.11 1993/08/17 16:01:23 jtc Exp $
+ * $Id : /b/source/CVS/src/bin/expr/expr.y,v 1.11 1993/08/17 16:01:23 jtc Exp $
*/
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <locale.h>
#include <ctype.h>
#include <err.h>
@@ -79,7 +81,6 @@ expr: TOKEN
| expr '/' expr { $$ = op_div ($1, $3); }
| expr '%' expr { $$ = op_rem ($1, $3); }
| expr ':' expr { $$ = op_colon ($1, $3); }
- | '-' expr %prec UNARY { $$ = op_minus (NULL, $2); }
;
@@ -232,6 +233,8 @@ main (argc, argv)
int argc;
char **argv;
{
+ setlocale (LC_ALL, "");
+
av = argv + 1;
yyparse ();
@@ -241,10 +244,7 @@ char **argv;
else
printf ("%s\n", result->u.s);
- if (is_zero_or_null (result))
- exit (1);
- else
- exit (0);
+ exit (is_zero_or_null (result));
}
int
@@ -485,14 +485,13 @@ struct val *a, *b;
}
#include <regex.h>
-#define SE_MAX 30
struct val *
op_colon (a, b)
struct val *a, *b;
{
regex_t rp;
- regmatch_t rm[SE_MAX];
+ regmatch_t rm[2];
char errbuf[256];
int eval;
struct val *v;
@@ -515,7 +514,7 @@ struct val *a, *b;
free (newpat);
/* compare string against pattern */
- if (regexec(&rp, a->u.s, SE_MAX, rm, 0) == 0) {
+ if (regexec(&rp, a->u.s, 2, rm, 0) == 0) {
if (rm[1].rm_so >= 0) {
*(a->u.s + rm[1].rm_eo) = '\0';
v = make_str (a->u.s + rm[1].rm_so);