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