Merge pull request #30 from Oichkatzelesfrettschen/eirikr/remove-netbsd-files-from-bin/test

This commit is contained in:
Eirikr Hinngart 2025-05-30 22:51:57 -07:00 committed by GitHub
commit be9ec38ded
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 377 additions and 455 deletions

View File

@ -1,5 +1,5 @@
# $NetBSD: Makefile,v 1.11 2007/06/22 03:24:16 simonb Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# Makefile for the test utility
# Derived from 4.4BSD sources
PROG= test
SRCS= test.c

View File

@ -1,4 +1,4 @@
# $NetBSD: TEST.csh,v 1.2 1995/03/21 07:03:59 cgd Exp $
# Test script for the test utility
# @(#)TEST.csh 5.2 (Berkeley) 4/30/93
#alias t '/usr/src/bin/test/obj/test \!*; echo $status'

View File

@ -1,4 +1,4 @@
.\" $NetBSD: test.1,v 1.30 2016/08/12 03:17:41 sevan Exp $
.\" Manual page for the test utility
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.

View File

@ -1,19 +1,16 @@
/* $NetBSD: test.c,v 1.41 2016/09/05 01:00:07 sevan Exp $ */
/* MINIX test utility derived from BSD sources */
/*
* test(1); version 7-like -- author Erik Baalbergen
* modified by Eric Gisin to be used as built-in.
* modified by Arnold Robbins to add SVR3 compatibility
* (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
* modified by J.T. Conklin for NetBSD.
* modified by J.T. Conklin.
*
* This program is in the Public Domain.
*/
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: test.c,v 1.41 2016/09/05 01:00:07 sevan Exp $");
#endif
#include <sys/stat.h>
#include <sys/types.h>
@ -23,11 +20,11 @@ __RCSID("$NetBSD: test.c,v 1.41 2016/09/05 01:00:07 sevan Exp $");
#include <errno.h>
#include <limits.h>
#include <locale.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
/* test(1) accepts the following grammar:
oexpr ::= aexpr | aexpr "-o" oexpr ;
@ -89,13 +86,7 @@ enum token {
OPERAND
};
enum token_types {
UNOP,
BINOP,
BUNOP,
BBINOP,
PAREN
};
enum token_types { UNOP, BINOP, BUNOP, BBINOP, PAREN };
struct t_op {
const char *op_text;
@ -103,12 +94,8 @@ struct t_op {
};
static const struct t_op cop[] = {
{"!", UNOT, BUNOP},
{"(", LPAREN, PAREN},
{")", RPAREN, PAREN},
{"<", STRLT, BINOP},
{"=", STREQ, BINOP},
{">", STRGT, BINOP},
{"!", UNOT, BUNOP}, {"(", LPAREN, PAREN}, {")", RPAREN, PAREN},
{"<", STRLT, BINOP}, {"=", STREQ, BINOP}, {">", STRGT, BINOP},
};
static const struct t_op cop2[] = {
@ -116,40 +103,23 @@ static const struct t_op cop2[] = {
};
static const struct t_op mop3[] = {
{"ef", FILEQ, BINOP},
{"eq", INTEQ, BINOP},
{"ge", INTGE, BINOP},
{"gt", INTGT, BINOP},
{"le", INTLE, BINOP},
{"lt", INTLT, BINOP},
{"ne", INTNE, BINOP},
{"nt", FILNT, BINOP},
{"ot", FILOT, BINOP},
{"ef", FILEQ, BINOP}, {"eq", INTEQ, BINOP}, {"ge", INTGE, BINOP},
{"gt", INTGT, BINOP}, {"le", INTLE, BINOP}, {"lt", INTLT, BINOP},
{"ne", INTNE, BINOP}, {"nt", FILNT, BINOP}, {"ot", FILOT, BINOP},
};
static const struct t_op mop2[] = {
{"G", FILGID, UNOP},
{"L", FILSYM, UNOP},
{"O", FILUID, UNOP},
{"S", FILSOCK,UNOP},
{"a", BAND, BBINOP},
{"b", FILBDEV,UNOP},
{"c", FILCDEV,UNOP},
{"d", FILDIR, UNOP},
{"e", FILEXIST,UNOP},
{"f", FILREG, UNOP},
{"g", FILSGID,UNOP},
{"h", FILSYM, UNOP}, /* for backwards compat */
{"k", FILSTCK,UNOP},
{"n", STRNZ, UNOP},
{"o", BOR, BBINOP},
{"p", FILFIFO,UNOP},
{"r", FILRD, UNOP},
{"s", FILGZ, UNOP},
{"t", FILTT, UNOP},
{"u", FILSUID,UNOP},
{"w", FILWR, UNOP},
{"x", FILEX, UNOP},
{"G", FILGID, UNOP}, {"L", FILSYM, UNOP},
{"O", FILUID, UNOP}, {"S", FILSOCK, UNOP},
{"a", BAND, BBINOP}, {"b", FILBDEV, UNOP},
{"c", FILCDEV, UNOP}, {"d", FILDIR, UNOP},
{"e", FILEXIST, UNOP}, {"f", FILREG, UNOP},
{"g", FILSGID, UNOP}, {"h", FILSYM, UNOP}, /* for backwards compat */
{"k", FILSTCK, UNOP}, {"n", STRNZ, UNOP},
{"o", BOR, BBINOP}, {"p", FILFIFO, UNOP},
{"r", FILRD, UNOP}, {"s", FILGZ, UNOP},
{"t", FILTT, UNOP}, {"u", FILSUID, UNOP},
{"w", FILWR, UNOP}, {"x", FILEX, UNOP},
{"z", STREZ, UNOP},
};
@ -177,9 +147,7 @@ extern void *ckmalloc(size_t);
#else
static void error(const char *, ...) __dead __printflike(1, 2);
static void
error(const char *msg, ...)
{
static void error(const char *msg, ...) {
va_list ap;
va_start(ap, msg);
@ -189,9 +157,7 @@ error(const char *msg, ...)
}
static void *ckmalloc(size_t);
static void *
ckmalloc(size_t nbytes)
{
static void *ckmalloc(size_t nbytes) {
void *p = malloc(nbytes);
if (!p)
@ -203,11 +169,9 @@ ckmalloc(size_t nbytes)
#ifdef SHELL
int testcmd(int, char **);
int
testcmd(int argc, char **argv)
int testcmd(int argc, char **argv)
#else
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
#endif
{
int res;
@ -238,9 +202,7 @@ main(int argc, char *argv[])
return res;
}
static void
syntax(const char *op, const char *msg)
{
static void syntax(const char *op, const char *msg) {
if (op && *op)
error("%s: %s", op, msg);
@ -248,9 +210,7 @@ syntax(const char *op, const char *msg)
error("%s", msg);
}
static int
oexpr(enum token n)
{
static int oexpr(enum token n) {
int res;
res = aexpr(n);
@ -262,9 +222,7 @@ oexpr(enum token n)
return res;
}
static int
aexpr(enum token n)
{
static int aexpr(enum token n) {
int res;
res = nexpr(n);
@ -276,18 +234,14 @@ aexpr(enum token n)
return res;
}
static int
nexpr(enum token n)
{
static int nexpr(enum token n) {
if (n == UNOT)
return !nexpr(t_lex(*++t_wp));
return primary(n);
}
static int
primary(enum token n)
{
static int primary(enum token n) {
enum token nn;
int res;
@ -324,14 +278,12 @@ primary(enum token n)
return strlen(*t_wp) > 0;
}
static int
binop(void)
{
static int binop(void) {
const char *opnd1, *opnd2;
struct t_op const *op;
opnd1 = *t_wp;
(void) t_lex(*++t_wp);
(void)t_lex(*++t_wp);
op = t_wp_op;
if ((opnd2 = *++t_wp) == NULL)
@ -432,9 +384,8 @@ binop(void)
* 1003.2-1992) and it was implemented efficiently with stat() instead of
* open().
*
* This was apparently broken in NetBSD around about 1994/06/30 when the old
* 4.4BSD implementation was replaced with a (arguably much better coded)
* implementation derived from pdksh.
* Earlier implementations diverged from the 4.4BSD version when
* the original code was replaced with one derived from pdksh.
*
* Note that modern pdksh is yet different again, but still not correct, at
* least not w.r.t. 1003.2-1992.
@ -492,9 +443,7 @@ binop(void)
* (euid==uid&&egid==gid), but uses st_mode for '-x' iff running as root.
* i.e. it does strictly conform to 1003.1-2001 (and presumably 1003.2b).
*/
static int
test_access(struct stat *sp, mode_t stmode)
{
static int test_access(struct stat *sp, mode_t stmode) {
gid_t *groups;
register int n;
uid_t euid;
@ -532,9 +481,7 @@ test_access(struct stat *sp, mode_t stmode)
return sp->st_mode & stmode;
}
static int
filstat(char *nm, enum token mode)
{
static int filstat(char *nm, enum token mode) {
struct stat s;
if (mode == FILSYM ? lstat(nm, &s) : stat(nm, &s))
@ -582,18 +529,14 @@ filstat(char *nm, enum token mode)
#define VTOC(x) (const unsigned char *)((const struct t_op *)x)->op_text
static int
compare1(const void *va, const void *vb)
{
static int compare1(const void *va, const void *vb) {
const unsigned char *a = va;
const unsigned char *b = VTOC(vb);
return a[0] - b[0];
}
static int
compare2(const void *va, const void *vb)
{
static int compare2(const void *va, const void *vb) {
const unsigned char *a = va;
const unsigned char *b = VTOC(vb);
int z = a[0] - b[0];
@ -601,24 +544,19 @@ compare2(const void *va, const void *vb)
return z ? z : (a[1] - b[1]);
}
static struct t_op const *
findop(const char *s)
{
static struct t_op const *findop(const char *s) {
if (s[0] == '-') {
if (s[1] == '\0')
return NULL;
if (s[2] == '\0')
return bsearch(s + 1, mop2, __arraycount(mop2),
sizeof(*mop2), compare1);
return bsearch(s + 1, mop2, __arraycount(mop2), sizeof(*mop2), compare1);
else if (s[3] != '\0')
return NULL;
else
return bsearch(s + 1, mop3, __arraycount(mop3),
sizeof(*mop3), compare2);
return bsearch(s + 1, mop3, __arraycount(mop3), sizeof(*mop3), compare2);
} else {
if (s[1] == '\0')
return bsearch(s, cop, __arraycount(cop), sizeof(*cop),
compare1);
return bsearch(s, cop, __arraycount(cop), sizeof(*cop), compare1);
else if (strcmp(s, cop2[0].op_text) == 0)
return cop2;
else
@ -626,9 +564,7 @@ findop(const char *s)
}
}
static enum token
t_lex(char *s)
{
static enum token t_lex(char *s) {
struct t_op const *op;
if (s == NULL) {
@ -638,7 +574,7 @@ t_lex(char *s)
if ((op = findop(s)) != NULL) {
if (!((op->op_type == UNOP && isoperand()) ||
(op->op_num == LPAREN && *(t_wp+1) == 0))) {
(op->op_num == LPAREN && *(t_wp + 1) == 0))) {
t_wp_op = op;
return op->op_num;
}
@ -647,15 +583,13 @@ t_lex(char *s)
return OPERAND;
}
static int
isoperand(void)
{
static int isoperand(void) {
struct t_op const *op;
char *s, *t;
if ((s = *(t_wp+1)) == 0)
if ((s = *(t_wp + 1)) == 0)
return 1;
if ((t = *(t_wp+2)) == 0)
if ((t = *(t_wp + 2)) == 0)
return 0;
if ((op = findop(s)) != NULL)
return op->op_type == BINOP && (t[0] != ')' || t[1] != '\0');
@ -663,9 +597,7 @@ isoperand(void)
}
/* atoi with error detection */
static long long
getn(const char *s)
{
static long long getn(const char *s) {
char *p;
long long r;
@ -685,33 +617,23 @@ getn(const char *s)
return r;
}
static int
newerf(const char *f1, const char *f2)
{
static int newerf(const char *f1, const char *f2) {
struct stat b1, b2;
return (stat(f1, &b1) == 0 &&
stat(f2, &b2) == 0 &&
return (stat(f1, &b1) == 0 && stat(f2, &b2) == 0 &&
timespeccmp(&b1.st_mtim, &b2.st_mtim, >));
}
static int
olderf(const char *f1, const char *f2)
{
static int olderf(const char *f1, const char *f2) {
struct stat b1, b2;
return (stat(f1, &b1) == 0 &&
stat(f2, &b2) == 0 &&
return (stat(f1, &b1) == 0 && stat(f2, &b2) == 0 &&
timespeccmp(&b1.st_mtim, &b2.st_mtim, <));
}
static int
equalf(const char *f1, const char *f2)
{
static int equalf(const char *f1, const char *f2) {
struct stat b1, b2;
return (stat(f1, &b1) == 0 &&
stat(f2, &b2) == 0 &&
b1.st_dev == b2.st_dev &&
return (stat(f1, &b1) == 0 && stat(f2, &b2) == 0 && b1.st_dev == b2.st_dev &&
b1.st_ino == b2.st_ino);
}