1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1982-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* David Korn <dgk@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A
1N/A/*
1N/A * tables for the test builin [[...]] and [...]
1N/A */
1N/A
1N/A#include <ast.h>
1N/A
1N/A#include "shtable.h"
1N/A#include "test.h"
1N/A
1N/A/*
1N/A * This is the list of binary test and [[...]] operators
1N/A */
1N/A
1N/Aconst Shtable_t shtab_testops[] =
1N/A{
1N/A "!=", TEST_SNE,
1N/A "-a", TEST_AND,
1N/A "-ef", TEST_EF,
1N/A "-eq", TEST_EQ,
1N/A "-ge", TEST_GE,
1N/A "-gt", TEST_GT,
1N/A "-le", TEST_LE,
1N/A "-lt", TEST_LT,
1N/A "-ne", TEST_NE,
1N/A "-nt", TEST_NT,
1N/A "-o", TEST_OR,
1N/A "-ot", TEST_OT,
1N/A "=", TEST_SEQ,
1N/A "==", TEST_SEQ,
1N/A "=~", TEST_REP,
1N/A "<", TEST_SLT,
1N/A ">", TEST_SGT,
1N/A "]]", TEST_END,
1N/A "", 0
1N/A};
1N/A
1N/Aconst char sh_opttest[] =
1N/A"[-1c?\n@(#)$Id: test (AT&T Research) 2003-03-18 $\n]"
1N/AUSAGE_LICENSE
1N/A"[+NAME?test - evaluate expression]"
1N/A"[+DESCRIPTION?\btest\b evaluates expressions and indicates its "
1N/A "results based on the exit status. Option parsing is not "
1N/A "performed so that all arguments, including \b--\b are processed "
1N/A " as operands. The evaluation of the "
1N/A "expression depends on the number of operands as follows:]{"
1N/A "[+0?Evaluates to false.]"
1N/A "[+1?True if argument is not an empty string.]"
1N/A "[+2?If first operand is \b!\b, the result is True if the second "
1N/A "operand an empty string. Otherwise, it is evaluated "
1N/A "as one of the unary expressions defined below. If the "
1N/A "unary operator is invalid and the second argument is \b--\b,"
1N/A "then the first argument is processed as an option argument.]"
1N/A "[+3?If first operand is \b!\b, the result is True if the second "
1N/A "and third operand evaluated as a unary expression is False. "
1N/A "Otherwise, the three operands are evaluaged as one of the "
1N/A "binary expressions listed below.]"
1N/A "[+4?If first operand is \b!\b, the result is True if the next "
1N/A "three operands are a valid binary expression that is False.]"
1N/A"}"
1N/A"[If any \afile\a is of the form \b/dev/fd/\b\an\a, then file descriptor "
1N/A "\an\a is checked.]"
1N/A"[+?Unary expressions can be one of the following:]{"
1N/A "[+-a \afile\a?True if \afile\a exists, obsolete.]"
1N/A "[+-b \afile\a?True if \afile\a exists and is a block special file.]"
1N/A "[+-c \afile\a?True if \afile\a exists and is a character special "
1N/A "file.]"
1N/A "[+-d \afile\a?True if \afile\a exists and is a directory.]"
1N/A "[+-e \afile\a?True if \afile\a exists.]"
1N/A "[+-f \afile\a?True if \afile\a exists and is a regular file.]"
1N/A "[+-g \afile\a?True if \afile\a exists and has its set-group-id bit "
1N/A "set.]"
1N/A "[+-h \afile\a?True if \afile\a exists and is a symbolic link.]"
1N/A "[+-k \afile\a?True if \afile\a exists and has its sticky bit on.]"
1N/A#if SHOPT_TEST_L
1N/A "[+-l \afile\a?True if \afile\a exists and is a symbolic link.]"
1N/A#endif
1N/A "[+-n \astring\a?True if length of \astring\a is non-zero.]"
1N/A "[+-o \aoption\a?True if the shell option \aoption\a is enabled.]"
1N/A "[+-p \afile\a?True if \afile\a exists and is a pipe or fifo.]"
1N/A "[+-r \afile\a?True if \afile\a exists and is readable.]"
1N/A "[+-s \afile\a?True if \afile\a exists and has size > 0.]"
1N/A "[+-t \afildes\a?True if file descriptor number \afildes\a is "
1N/A "open and is associated with a terminal device.]"
1N/A "[+-u \afile\a?True if \afile\a exists and has its set-user-id bit "
1N/A "set.]"
1N/A "[+-v \avarname\a?True if \avarname\a is a valid variable name that is set.]"
1N/A "[+-w \afile\a?True if \afile\a exists and is writable.]"
1N/A "[+-x \afile\a?True if \afile\a exists and is executable. For a "
1N/A "directory it means that it can be searched.]"
1N/A "[+-z \astring\a?True if \astring\a is a zero length string.]"
1N/A "[+-G \afile\a?True if \afile\a exists and group is the effective "
1N/A "group id of the current process.]"
1N/A "[+-L \afile\a?True if \afile\a exists and is a symbolic link.]"
1N/A "[+-N \afile\a?True if \afile\a exists and has been modified since "
1N/A "it was last read.]"
1N/A "[+-O \afile\a?True if \afile\a exists and owner is the effective "
1N/A "user id of the current process.]"
1N/A "[+-R \avarname\a?True if \avarname\a is a name reference.]"
1N/A "[+-S \afile\a?True if \afile\a exists and is a socket.]"
1N/A#if SHOPT_FS_3D
1N/A "[+-V \afile\a?True if \afile\a exists and is a version "
1N/A "directory.]"
1N/A#endif /* SHOPT_FS_3D */
1N/A"}"
1N/A"[+?Binary expressions can be one of the following:]{"
1N/A "[+\astring1\a = \astring2\a?True if \astring1\a is equal to "
1N/A "\astring2\a.]"
1N/A "[+\astring1\a == \astring2\a?True if \astring1\a is equal to "
1N/A "\astring2\a.]"
1N/A "[+\astring1\a != \astring2\a?True if \astring1\a is not equal to "
1N/A "\astring2\a.]"
1N/A "[+\anum1\a -eq \anum2\a?True if numerical value of \anum1\a is "
1N/A "equal to \anum2\a.]"
1N/A "[+\anum1\a -ne \anum2\a?True if numerical value of \anum1\a is not "
1N/A "equal to \anum2\a.]"
1N/A "[+\anum1\a -lt \anum2\a?True if numerical value of \anum1\a is less "
1N/A "than \anum2\a.]"
1N/A "[+\anum1\a -le \anum2\a?True if numerical value of \anum1\a is less "
1N/A "than or equal to \anum2\a.]"
1N/A "[+\anum1\a -gt \anum2\a?True if numerical value of \anum1\a is "
1N/A "greater than \anum2\a.]"
1N/A "[+\anum1\a -ge \anum2\a?True if numerical value of \anum1\a is "
1N/A "greater than or equal to \anum2\a.]"
1N/A "[+\afile1\a -nt \afile2\a?True if \afile1\a is newer than \afile2\a "
1N/A "or \afile2\a does not exist.]"
1N/A "[+\afile1\a -ot \afile2\a?True if \afile1\a is older than \afile2\a "
1N/A "or \afile2\a does not exist.]"
1N/A "[+\afile1\a -ef \afile2\a?True if \afile1\a is another name for "
1N/A "\afile2\a. This will be true if \afile1\a is a hard link "
1N/A "or a symbolic link to \afile2\a.]"
1N/A"}"
1N/A"\n"
1N/A"\n[expression]\n"
1N/A"\n"
1N/A"[+EXIT STATUS?]{"
1N/A "[+0?Indicates that the specified expression is True.]"
1N/A "[+1?Indicates that the specified expression is False.]"
1N/A "[+>1?An error occurred.]"
1N/A"}"
1N/A
1N/A"[+SEE ALSO?\blet\b(1), \bexpr\b(1)]"
1N/A;
1N/A
1N/Aconst char test_opchars[] = "HLNRSVOGCaeohrwxdcbfugkv"
1N/A#if SHOPT_TEST_L
1N/A "l"
1N/A#endif
1N/A "psnzt";
1N/Aconst char e_argument[] = "argument expected";
1N/Aconst char e_missing[] = "%s missing";
1N/Aconst char e_badop[] = "%s: unknown operator";
1N/Aconst char e_tstbegin[] = "[[ ! ";
1N/Aconst char e_tstend[] = " ]]\n";