aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/test.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/coreutils/test.c b/coreutils/test.c
index fca55551e..ed708c6d3 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -894,18 +894,48 @@ int test_main(int argc, char **argv)
894 res = (argv[0][0] == '\0'); 894 res = (argv[0][0] == '\0');
895 goto ret_special; 895 goto ret_special;
896 } 896 }
897 if (argv[2] && !argv[3]) { 897 if (argv[2]) {
898 check_operator(argv[1]); 898 if (!argv[3]) {
899 if (last_operator->op_type == BINOP) { 899 /*
900 /* "test [!] arg1 <binary_op> arg2" */ 900 * http://pubs.opengroup.org/onlinepubs/009695399/utilities/test.html
901 args = argv; 901 * """ 3 arguments:
902 res = (binop() == 0); 902 * If $2 is a binary primary, perform the binary test of $1 and $3.
903 * """
904 */
905 check_operator(argv[1]);
906 if (last_operator->op_type == BINOP) {
907 /* "test [!] arg1 <binary_op> arg2" */
908 args = argv;
909 res = (binop() == 0);
903 ret_special: 910 ret_special:
904 /* If there was leading "!" op... */ 911 /* If there was leading "!" op... */
905 res ^= negate; 912 res ^= negate;
906 goto ret; 913 goto ret;
914 }
915 /* """If $1 is '(' and $3 is ')', perform the unary test of $2."""
916 * Looks like this works without additional coding.
917 */
918 goto check_negate;
919 }
920 /* argv[3] exists (at least 4 args), is it exactly 4 args? */
921 if (!argv[4]) {
922 /*
923 * """ 4 arguments:
924 * If $1 is '!', negate the three-argument test of $2, $3, and $4.
925 * If $1 is '(' and $4 is ')', perform the two-argument test of $2 and $3.
926 * """
927 * Example why code below is necessary: test '(' ! -e ')'
928 */
929 if (LONE_CHAR(argv[0], '(')
930 && LONE_CHAR(argv[3], ')')
931 ) {
932 /* "test [!] ( x y )" */
933 argv[3] = NULL;
934 argv++;
935 }
907 } 936 }
908 } 937 }
938 check_negate:
909 if (LONE_CHAR(argv[0], '!')) { 939 if (LONE_CHAR(argv[0], '!')) {
910 argv++; 940 argv++;
911 negate ^= 1; 941 negate ^= 1;