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