diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/test.c | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/coreutils/test.c b/coreutils/test.c index d8ac42e22..a8286525a 100644 --- a/coreutils/test.c +++ b/coreutils/test.c | |||
@@ -879,18 +879,48 @@ int test_main(int argc, char **argv) | |||
879 | res = (argv[0][0] == '\0'); | 879 | res = (argv[0][0] == '\0'); |
880 | goto ret_special; | 880 | goto ret_special; |
881 | } | 881 | } |
882 | if (argv[2] && !argv[3]) { | 882 | if (argv[2]) { |
883 | check_operator(argv[1]); | 883 | if (!argv[3]) { |
884 | if (last_operator->op_type == BINOP) { | 884 | /* |
885 | /* "test [!] arg1 <binary_op> arg2" */ | 885 | * http://pubs.opengroup.org/onlinepubs/009695399/utilities/test.html |
886 | args = argv; | 886 | * """ 3 arguments: |
887 | res = (binop() == 0); | 887 | * If $2 is a binary primary, perform the binary test of $1 and $3. |
888 | * """ | ||
889 | */ | ||
890 | check_operator(argv[1]); | ||
891 | if (last_operator->op_type == BINOP) { | ||
892 | /* "test [!] arg1 <binary_op> arg2" */ | ||
893 | args = argv; | ||
894 | res = (binop() == 0); | ||
888 | ret_special: | 895 | ret_special: |
889 | /* If there was leading "!" op... */ | 896 | /* If there was leading "!" op... */ |
890 | res ^= negate; | 897 | res ^= negate; |
891 | goto ret; | 898 | goto ret; |
899 | } | ||
900 | /* """If $1 is '(' and $3 is ')', perform the unary test of $2.""" | ||
901 | * Looks like this works without additional coding. | ||
902 | */ | ||
903 | goto check_negate; | ||
904 | } | ||
905 | /* argv[3] exists (at least 4 args), is it exactly 4 args? */ | ||
906 | if (!argv[4]) { | ||
907 | /* | ||
908 | * """ 4 arguments: | ||
909 | * If $1 is '!', negate the three-argument test of $2, $3, and $4. | ||
910 | * If $1 is '(' and $4 is ')', perform the two-argument test of $2 and $3. | ||
911 | * """ | ||
912 | * Example why code below is necessary: test '(' ! -e ')' | ||
913 | */ | ||
914 | if (LONE_CHAR(argv[0], '(') | ||
915 | && LONE_CHAR(argv[3], ')') | ||
916 | ) { | ||
917 | /* "test [!] ( x y )" */ | ||
918 | argv[3] = NULL; | ||
919 | argv++; | ||
920 | } | ||
892 | } | 921 | } |
893 | } | 922 | } |
923 | check_negate: | ||
894 | if (LONE_CHAR(argv[0], '!')) { | 924 | if (LONE_CHAR(argv[0], '!')) { |
895 | argv++; | 925 | argv++; |
896 | negate ^= 1; | 926 | negate ^= 1; |