Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/test Allow SMALL (and TINY) builds of test (for SMALL/TI...
details: https://anonhg.NetBSD.org/src/rev/db36e256fb85
branches: trunk
changeset: 433410:db36e256fb85
user: kre <kre%NetBSD.org@localhost>
date: Thu Sep 13 22:00:58 2018 +0000
description:
Allow SMALL (and TINY) builds of test (for SMALL/TINY builds of sh)
which support only the defined modes of operation of test, to allow
the version of sh on small install media be kept as small as possible.
diffstat:
bin/test/test.c | 44 ++++++++++++++++++++++++++++++++++++++------
1 files changed, 38 insertions(+), 6 deletions(-)
diffs (207 lines):
diff -r c724fdcf577d -r db36e256fb85 bin/test/test.c
--- a/bin/test/test.c Thu Sep 13 18:55:01 2018 +0000
+++ b/bin/test/test.c Thu Sep 13 22:00:58 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: test.c,v 1.42 2018/09/12 23:33:31 kre Exp $ */
+/* $NetBSD: test.c,v 1.43 2018/09/13 22:00:58 kre 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.42 2018/09/12 23:33:31 kre Exp $");
+__RCSID("$NetBSD: test.c,v 1.43 2018/09/13 22:00:58 kre Exp $");
#endif
#include <sys/stat.h>
@@ -91,10 +91,13 @@
enum token_types {
UNOP,
- BINOP,
+ BINOP
+#ifndef SMALL
+ ,
BUNOP,
BBINOP,
PAREN
+#endif
};
struct t_op {
@@ -103,9 +106,11 @@
};
static const struct t_op cop[] = {
+#ifndef SMALL
{"!", UNOT, BUNOP},
{"(", LPAREN, PAREN},
{")", RPAREN, PAREN},
+#endif
{"<", STRLT, BINOP},
{"=", STREQ, BINOP},
{">", STRGT, BINOP},
@@ -132,7 +137,9 @@
{"L", FILSYM, UNOP},
{"O", FILUID, UNOP},
{"S", FILSOCK,UNOP},
+#ifndef SMALL
{"a", BAND, BBINOP},
+#endif
{"b", FILBDEV,UNOP},
{"c", FILCDEV,UNOP},
{"d", FILDIR, UNOP},
@@ -142,7 +149,9 @@
{"h", FILSYM, UNOP}, /* for backwards compat */
{"k", FILSTCK,UNOP},
{"n", STRNZ, UNOP},
+#ifndef SMALL
{"o", BOR, BBINOP},
+#endif
{"p", FILFIFO,UNOP},
{"r", FILRD, UNOP},
{"s", FILGZ, UNOP},
@@ -153,22 +162,26 @@
{"z", STREZ, UNOP},
};
+#ifndef SMALL
static char **t_wp;
static struct t_op const *t_wp_op;
+#endif
+#ifndef SMALL
__dead static void syntax(const char *, const char *);
static int oexpr(enum token);
static int aexpr(enum token);
static int nexpr(enum token);
-static struct t_op const *findop(const char *);
static int primary(enum token);
static int binop(void);
+static enum token t_lex(char *);
+static int isoperand(void);
+#endif
+static struct t_op const *findop(const char *);
static int perform_unop(enum token, const char *);
static int perform_binop(enum token, const char *, const char *);
static int test_access(struct stat *, mode_t);
static int filstat(const char *, enum token);
-static enum token t_lex(char *);
-static int isoperand(void);
static long long getn(const char *);
static int newerf(const char *, const char *);
static int olderf(const char *, const char *);
@@ -292,6 +305,10 @@
* operators and operands that happen to look like operators)
*/
+#ifdef SMALL
+ error("SMALL test, no fallback usage");
+#else
+
t_wp = &argv[1];
res = !oexpr(t_lex(*t_wp));
@@ -299,8 +316,10 @@
syntax(*t_wp, "unexpected operator");
return res;
+#endif
}
+#ifndef SMALL
static void
syntax(const char *op, const char *msg)
{
@@ -310,6 +329,7 @@
else
error("%s", msg);
}
+#endif
static int
one_arg(const char *arg)
@@ -333,12 +353,14 @@
if (op != NULL && op->op_type == UNOP)
return !perform_unop(op->op_num, a2);
+#ifndef TINY
/*
* an extension, but as we've entered the realm of the unspecified
* we're allowed... test ( $a ) where a=''
*/
if (a1[0] == '(' && a2[0] == ')' && (a1[1] | a2[1]) == 0)
return 1;
+#endif
return -1;
}
@@ -363,8 +385,10 @@
return res;
}
+#ifndef TINY
if (a1[0] == '(' && a3[0] == ')' && a3[1] == '\0')
return one_arg(a2);
+#endif
return -1;
}
@@ -384,12 +408,15 @@
return res;
}
+#ifndef TINY
if (a1[0] == '(' && a4[0] == ')' && a4[1] == '\0')
return two_arg(a2, a3);
+#endif
return -1;
}
+#ifndef SMALL
static int
oexpr(enum token n)
{
@@ -456,6 +483,7 @@
return strlen(*t_wp) > 0;
}
+#endif /* !SMALL */
static int
perform_unop(enum token n, const char *opnd)
@@ -472,6 +500,7 @@
}
}
+#ifndef SMALL
static int
binop(void)
{
@@ -487,6 +516,7 @@
return perform_binop(op->op_num, opnd1, opnd2);
}
+#endif
static int
perform_binop(enum token op_num, const char *opnd1, const char *opnd2)
@@ -780,6 +810,7 @@
}
}
+#ifndef SMALL
static enum token
t_lex(char *s)
{
@@ -815,6 +846,7 @@
return op->op_type == BINOP && (t[0] != ')' || t[1] != '\0');
return 0;
}
+#endif
/* atoi with error detection */
static long long
Home |
Main Index |
Thread Index |
Old Index