summaryrefslogtreecommitdiff
path: root/bin/expr/expr.y
diff options
context:
space:
mode:
authorcgd <cgd@NetBSD.org>1993-06-05 22:25:44 +0000
committercgd <cgd@NetBSD.org>1993-06-05 22:25:44 +0000
commitac2edf58ea1c16d98f6f1a7e36363d1127ffb680 (patch)
tree9c9873e5fcd14570051b70c7013d9a7500d6af5e /bin/expr/expr.y
parentee6def0bf20dc56aa5cc943775a008b64f2d4f0b (diff)
update for latest version of patches from jtconklin@kaleida.com
Diffstat (limited to 'bin/expr/expr.y')
-rw-r--r--bin/expr/expr.y40
1 files changed, 20 insertions, 20 deletions
diff --git a/bin/expr/expr.y b/bin/expr/expr.y
index 35cdc3b9f8f..33c23b9c54a 100644
--- a/bin/expr/expr.y
+++ b/bin/expr/expr.y
@@ -2,32 +2,24 @@
/* Written by Pace Willisson (pace@blitz.com)
* and placed in the public domain
*
- * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE
- * -------------------- ----- ----------------------
- * CURRENT PATCH LEVEL: 1 00092
- * -------------------- ----- ----------------------
- *
- * 15 Mar 93 J.T. Conklin Added support for parens, string
- * expressions that are numeric, and
- * fixed division by zero.
- * Enhanced performance and memory use.
+ * $Header: /cvsroot/src/bin/expr/expr.y,v 1.5 1993/06/05 22:25:44 cgd Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
-
+
enum valtype {
integer, string
} ;
-
+
struct val {
enum valtype type;
union {
char *s;
int i;
} u;
-};
+} ;
struct val *result;
struct val *op_or ();
@@ -96,7 +88,7 @@ int i;
{
struct val *vp;
- vp = malloc (sizeof (*vp));
+ vp = (struct val *) malloc (sizeof (*vp));
if (vp == NULL) {
fprintf (stderr, "expr: out of memory\n");
exit (2);
@@ -113,7 +105,7 @@ char *s;
{
struct val *vp;
- vp = malloc (sizeof (*vp));
+ vp = (struct val *) malloc (sizeof (*vp));
if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
fprintf (stderr, "expr: out of memory\n");
exit (2);
@@ -227,15 +219,15 @@ int
is_zero_or_null (vp)
struct val *vp;
{
+ /* Like most other versions of expr, this version will return
+ false for a string value of multiple zeros.*/
+
if (vp->type == integer) {
- if (vp->u.i == 0)
- return (1);
+ return (vp->u.i == 0);
} else {
- if (*vp->u.s == 0)
- return (1);
+ return (*vp->u.s == 0 || strcmp (vp->u.s, "0") == 0);
}
-
- return (0);
+ /* NOTREACHED */
}
void
@@ -587,3 +579,11 @@ struct val *a, *b;
return (make_integer (0));
}
}
+
+void
+regerror (s)
+const char *s;
+{
+ fprintf (stderr, "expr: %s\n", s);
+ exit (2);
+}