1da2e3ebdSchin /*********************************************************************** 2da2e3ebdSchin * * 3da2e3ebdSchin * This software is part of the ast package * 4*3e14f97fSRoger A. Faulkner * Copyright (c) 1982-2010 AT&T Intellectual Property * 5da2e3ebdSchin * and is licensed under the * 6da2e3ebdSchin * Common Public License, Version 1.0 * 77c2fbfb3SApril Chin * by AT&T Intellectual Property * 8da2e3ebdSchin * * 9da2e3ebdSchin * A copy of the License is available at * 10da2e3ebdSchin * http://www.opensource.org/licenses/cpl1.0.txt * 11da2e3ebdSchin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12da2e3ebdSchin * * 13da2e3ebdSchin * Information and Software Systems Research * 14da2e3ebdSchin * AT&T Research * 15da2e3ebdSchin * Florham Park NJ * 16da2e3ebdSchin * * 17da2e3ebdSchin * David Korn <dgk@research.att.com> * 18da2e3ebdSchin * * 19da2e3ebdSchin ***********************************************************************/ 20da2e3ebdSchin #pragma prototyped 21da2e3ebdSchin 22da2e3ebdSchin /* 23da2e3ebdSchin * tables for the test builin [[...]] and [...] 24da2e3ebdSchin */ 25da2e3ebdSchin 26da2e3ebdSchin #include <ast.h> 27da2e3ebdSchin 28da2e3ebdSchin #include "shtable.h" 29da2e3ebdSchin #include "test.h" 30da2e3ebdSchin 31da2e3ebdSchin /* 32da2e3ebdSchin * This is the list of binary test and [[...]] operators 33da2e3ebdSchin */ 34da2e3ebdSchin 35da2e3ebdSchin const Shtable_t shtab_testops[] = 36da2e3ebdSchin { 37da2e3ebdSchin "!=", TEST_SNE, 38da2e3ebdSchin "-a", TEST_AND, 39da2e3ebdSchin "-ef", TEST_EF, 40da2e3ebdSchin "-eq", TEST_EQ, 41da2e3ebdSchin "-ge", TEST_GE, 42da2e3ebdSchin "-gt", TEST_GT, 43da2e3ebdSchin "-le", TEST_LE, 44da2e3ebdSchin "-lt", TEST_LT, 45da2e3ebdSchin "-ne", TEST_NE, 46da2e3ebdSchin "-nt", TEST_NT, 47da2e3ebdSchin "-o", TEST_OR, 48da2e3ebdSchin "-ot", TEST_OT, 49da2e3ebdSchin "=", TEST_SEQ, 50da2e3ebdSchin "==", TEST_SEQ, 51da2e3ebdSchin "=~", TEST_REP, 52da2e3ebdSchin "<", TEST_SLT, 53da2e3ebdSchin ">", TEST_SGT, 54da2e3ebdSchin "]]", TEST_END, 55da2e3ebdSchin "", 0 56da2e3ebdSchin }; 57da2e3ebdSchin 58da2e3ebdSchin const char sh_opttest[] = 59da2e3ebdSchin "[-1c?\n@(#)$Id: test (AT&T Research) 2003-03-18 $\n]" 60da2e3ebdSchin USAGE_LICENSE 61da2e3ebdSchin "[+NAME?test - evaluate expression]" 62da2e3ebdSchin "[+DESCRIPTION?\btest\b evaluates expressions and indicates its " 63da2e3ebdSchin "results based on the exit status. Option parsing is not " 64da2e3ebdSchin "performed so that all arguments, including \b--\b are processed " 65da2e3ebdSchin " as operands. The evaluation of the " 66da2e3ebdSchin "expression depends on the number of operands as follows:]{" 67da2e3ebdSchin "[+0?Evaluates to false.]" 68da2e3ebdSchin "[+1?True if argument is not an empty string.]" 69da2e3ebdSchin "[+2?If first operand is \b!\b, the result is True if the second " 70da2e3ebdSchin "operand an empty string. Otherwise, it is evaluated " 71da2e3ebdSchin "as one of the unary expressions defined below. If the " 72da2e3ebdSchin "unary operator is invalid and the second argument is \b--\b," 73da2e3ebdSchin "then the first argument is processed as an option argument.]" 74da2e3ebdSchin "[+3?If first operand is \b!\b, the result is True if the second " 75da2e3ebdSchin "and third operand evaluated as a unary expression is False. " 76da2e3ebdSchin "Otherwise, the three operands are evaluaged as one of the " 77da2e3ebdSchin "binary expressions listed below.]" 78da2e3ebdSchin "[+4?If first operand is \b!\b, the result is True if the next " 79da2e3ebdSchin "three operands are a valid binary expression that is False.]" 80da2e3ebdSchin "}" 81da2e3ebdSchin "[If any \afile\a is of the form \b/dev/fd/\b\an\a, then file descriptor " 82da2e3ebdSchin "\an\a is checked.]" 83da2e3ebdSchin "[+?Unary expressions can be one of the following:]{" 84da2e3ebdSchin "[+-a \afile\a?True if \afile\a exists, obsolete.]" 85da2e3ebdSchin "[+-b \afile\a?True if \afile\a exists and is a block special file.]" 86da2e3ebdSchin "[+-c \afile\a?True if \afile\a exists and is a character special " 87da2e3ebdSchin "file.]" 88da2e3ebdSchin "[+-d \afile\a?True if \afile\a exists and is a directory.]" 89da2e3ebdSchin "[+-e \afile\a?True if \afile\a exists.]" 90da2e3ebdSchin "[+-f \afile\a?True if \afile\a exists and is a regular file.]" 91da2e3ebdSchin "[+-g \afile\a?True if \afile\a exists and has its set-group-id bit " 92da2e3ebdSchin "set.]" 93da2e3ebdSchin "[+-h \afile\a?True if \afile\a exists and is a symbolic link.]" 94da2e3ebdSchin "[+-k \afile\a?True if \afile\a exists and has its sticky bit on.]" 95da2e3ebdSchin #if SHOPT_TEST_L 96da2e3ebdSchin "[+-l \afile\a?True if \afile\a exists and is a symbolic link.]" 97da2e3ebdSchin #endif 98da2e3ebdSchin "[+-n \astring\a?True if length of \astring\a is non-zero.]" 99da2e3ebdSchin "[+-o \aoption\a?True if the shell option \aoption\a is enabled.]" 100da2e3ebdSchin "[+-p \afile\a?True if \afile\a exists and is a pipe or fifo.]" 101da2e3ebdSchin "[+-r \afile\a?True if \afile\a exists and is readable.]" 102da2e3ebdSchin "[+-s \afile\a?True if \afile\a exists and has size > 0.]" 103da2e3ebdSchin "[+-t \afildes\a?True if file descriptor number \afildes\a is " 104da2e3ebdSchin "open and is associated with a terminal device.]" 105da2e3ebdSchin "[+-u \afile\a?True if \afile\a exists and has its set-user-id bit " 106da2e3ebdSchin "set.]" 10734f9b3eeSRoland Mainz "[+-v \avarname\a?True if \avarname\a is a valid variable name that is set.]" 108da2e3ebdSchin "[+-w \afile\a?True if \afile\a exists and is writable.]" 109da2e3ebdSchin "[+-x \afile\a?True if \afile\a exists and is executable. For a " 110da2e3ebdSchin "directory it means that it can be searched.]" 111da2e3ebdSchin "[+-z \astring\a?True if \astring\a is a zero length string.]" 112da2e3ebdSchin "[+-G \afile\a?True if \afile\a exists and group is the effective " 113da2e3ebdSchin "group id of the current process.]" 114da2e3ebdSchin "[+-L \afile\a?True if \afile\a exists and is a symbolic link.]" 115da2e3ebdSchin "[+-N \afile\a?True if \afile\a exists and has been modified since " 116da2e3ebdSchin "it was last read.]" 117da2e3ebdSchin "[+-O \afile\a?True if \afile\a exists and owner is the effective " 118da2e3ebdSchin "user id of the current process.]" 11934f9b3eeSRoland Mainz "[+-R \avarname\a?True if \avarname\a is a name reference.]" 120da2e3ebdSchin "[+-S \afile\a?True if \afile\a exists and is a socket.]" 12134f9b3eeSRoland Mainz #if SHOPT_FS_3D 12234f9b3eeSRoland Mainz "[+-V \afile\a?True if \afile\a exists and is a version " 12334f9b3eeSRoland Mainz "directory.]" 12434f9b3eeSRoland Mainz #endif /* SHOPT_FS_3D */ 125da2e3ebdSchin "}" 126da2e3ebdSchin "[+?Binary expressions can be one of the following:]{" 127da2e3ebdSchin "[+\astring1\a = \astring2\a?True if \astring1\a is equal to " 128da2e3ebdSchin "\astring2\a.]" 129da2e3ebdSchin "[+\astring1\a == \astring2\a?True if \astring1\a is equal to " 130da2e3ebdSchin "\astring2\a.]" 131da2e3ebdSchin "[+\astring1\a != \astring2\a?True if \astring1\a is not equal to " 132da2e3ebdSchin "\astring2\a.]" 133da2e3ebdSchin "[+\anum1\a -eq \anum2\a?True if numerical value of \anum1\a is " 134da2e3ebdSchin "equal to \anum2\a.]" 135da2e3ebdSchin "[+\anum1\a -ne \anum2\a?True if numerical value of \anum1\a is not " 136da2e3ebdSchin "equal to \anum2\a.]" 137da2e3ebdSchin "[+\anum1\a -lt \anum2\a?True if numerical value of \anum1\a is less " 138da2e3ebdSchin "than \anum2\a.]" 139da2e3ebdSchin "[+\anum1\a -le \anum2\a?True if numerical value of \anum1\a is less " 140da2e3ebdSchin "than or equal to \anum2\a.]" 141da2e3ebdSchin "[+\anum1\a -gt \anum2\a?True if numerical value of \anum1\a is " 142da2e3ebdSchin "greater than \anum2\a.]" 143da2e3ebdSchin "[+\anum1\a -ge \anum2\a?True if numerical value of \anum1\a is " 144da2e3ebdSchin "greater than or equal to \anum2\a.]" 145da2e3ebdSchin "[+\afile1\a -nt \afile2\a?True if \afile1\a is newer than \afile2\a " 146da2e3ebdSchin "or \afile2\a does not exist.]" 147da2e3ebdSchin "[+\afile1\a -ot \afile2\a?True if \afile1\a is older than \afile2\a " 148da2e3ebdSchin "or \afile2\a does not exist.]" 149da2e3ebdSchin "[+\afile1\a -ef \afile2\a?True if \afile1\a is another name for " 150da2e3ebdSchin "\afile2\a. This will be true if \afile1\a is a hard link " 151da2e3ebdSchin "or a symbolic link to \afile2\a.]" 152da2e3ebdSchin "}" 153da2e3ebdSchin "\n" 154da2e3ebdSchin "\n[expression]\n" 155da2e3ebdSchin "\n" 156da2e3ebdSchin "[+EXIT STATUS?]{" 157da2e3ebdSchin "[+0?Indicates that the specified expression is True.]" 158da2e3ebdSchin "[+1?Indicates that the specified expression is False.]" 159da2e3ebdSchin "[+>1?An error occurred.]" 160da2e3ebdSchin "}" 161da2e3ebdSchin 162da2e3ebdSchin "[+SEE ALSO?\blet\b(1), \bexpr\b(1)]" 163da2e3ebdSchin ; 164da2e3ebdSchin 16534f9b3eeSRoland Mainz const char test_opchars[] = "HLNRSVOGCaeohrwxdcbfugkv" 166da2e3ebdSchin #if SHOPT_TEST_L 167da2e3ebdSchin "l" 168da2e3ebdSchin #endif 169da2e3ebdSchin "psnzt"; 170da2e3ebdSchin const char e_argument[] = "argument expected"; 171da2e3ebdSchin const char e_missing[] = "%s missing"; 172da2e3ebdSchin const char e_badop[] = "%s: unknown operator"; 173da2e3ebdSchin const char e_tstbegin[] = "[[ ! "; 174da2e3ebdSchin const char e_tstend[] = " ]]\n"; 175