Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/test Operator precedence consistency; from "Andrew_L. Mo...
details: https://anonhg.NetBSD.org/src/rev/190d3ef2f417
branches: trunk
changeset: 471600:190d3ef2f417
user: kleink <kleink%NetBSD.org@localhost>
date: Mon Apr 05 09:48:38 1999 +0000
description:
Operator precedence consistency; from "Andrew_L. Moore" <alm%SlewSys.Org@localhost>
in PR bin/7015.
diffstat:
bin/test/test.c | 68 ++++++++++++++++++++++++++------------------------------
1 files changed, 32 insertions(+), 36 deletions(-)
diffs (125 lines):
diff -r 72cdd1fe3fd8 -r 190d3ef2f417 bin/test/test.c
--- a/bin/test/test.c Mon Apr 05 08:04:48 1999 +0000
+++ b/bin/test/test.c Mon Apr 05 09:48:38 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: test.c,v 1.20 1998/11/04 20:12:12 christos Exp $ */
+/* $NetBSD: test.c,v 1.21 1999/04/05 09:48:38 kleink Exp $ */
/*
* test(1); version 7-like -- author Erik Baalbergen
@@ -12,7 +12,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: test.c,v 1.20 1998/11/04 20:12:12 christos Exp $");
+__RCSID("$NetBSD: test.c,v 1.21 1999/04/05 09:48:38 kleink Exp $");
#endif
#include <sys/types.h>
@@ -150,6 +150,7 @@
static int binop __P((void));
static int filstat __P((char *, enum token));
static enum token t_lex __P((char *));
+static int isoperand __P((void));
static int getn __P((const char *));
static int newerf __P((const char *, const char *));
static int olderf __P((const char *, const char *));
@@ -170,42 +171,11 @@
argv[argc] = NULL;
}
- /* Implement special cases from POSIX.2, section 4.62.4 */
- switch (argc) {
- case 1:
- return 1;
- case 2:
- return (*argv[1] == '\0');
- case 3:
- if (argv[1][0] == '!' && argv[1][1] == '\0') {
- return !(*argv[2] == '\0');
- }
- break;
- case 4:
- if (argv[1][0] != '!' || argv[1][1] != '\0') {
- if (t_lex(argv[2]),
- t_wp_op && t_wp_op->op_type == BINOP) {
- t_wp = &argv[1];
- return (binop() == 0);
- }
- }
- break;
- case 5:
- if (argv[1][0] == '!' && argv[1][1] == '\0') {
- if (t_lex(argv[3]),
- t_wp_op && t_wp_op->op_type == BINOP) {
- t_wp = &argv[2];
- return !(binop() == 0);
- }
- }
- break;
- }
-
t_wp = &argv[1];
res = !oexpr(t_lex(*t_wp));
if (*t_wp != NULL && *++t_wp != NULL)
- syntax(*t_wp, "unknown operand");
+ syntax(*t_wp, "unexpected operator");
return res;
}
@@ -260,12 +230,15 @@
primary(n)
enum token n;
{
+ enum token nn;
int res;
if (n == EOI)
- syntax(NULL, "argument expected");
+ return 0; /* missing expression */
if (n == LPAREN) {
- res = oexpr(t_lex(*++t_wp));
+ if ((nn = t_lex(*++t_wp)) == RPAREN)
+ return 0; /* missing expression */
+ res = oexpr(nn);
if (t_lex(*++t_wp) != RPAREN)
syntax(NULL, "closing paren expected");
return res;
@@ -401,6 +374,9 @@
}
while (op->op_text) {
if (strcmp(s, op->op_text) == 0) {
+ if ((op->op_type == UNOP && isoperand()) ||
+ (op->op_num == LPAREN && *(t_wp+1) == 0))
+ break;
t_wp_op = op;
return op->op_num;
}
@@ -410,6 +386,26 @@
return OPERAND;
}
+static int
+isoperand()
+{
+ struct t_op const *op = ops;
+ char *s;
+ char *t;
+
+ if ((s = *(t_wp+1)) == 0)
+ return 1;
+ if ((t = *(t_wp+2)) == 0)
+ return 0;
+ while (op->op_text) {
+ if (strcmp(s, op->op_text) == 0)
+ return op->op_type == BINOP &&
+ (t[0] != ')' || t[1] != '\0');
+ op++;
+ }
+ return 0;
+}
+
/* atoi with error detection */
static int
getn(s)
Home |
Main Index |
Thread Index |
Old Index