aboutsummaryrefslogtreecommitdiff
path: root/coreutils/test.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-10-06 12:50:22 +0100
committerRon Yorston <rmy@pobox.com>2014-10-06 12:50:22 +0100
commitb04d11dcbadda2620743a1dd923938f2f3043a38 (patch)
tree971afe425a81304b79e44122e220c7a69efe2616 /coreutils/test.c
parent124bbf02948b7ac0babb4ead04acd1559db182d3 (diff)
parent760d035699c4a878f9109544c1d35ea0d5f6b76c (diff)
downloadbusybox-w32-b04d11dcbadda2620743a1dd923938f2f3043a38.tar.gz
busybox-w32-b04d11dcbadda2620743a1dd923938f2f3043a38.tar.bz2
busybox-w32-b04d11dcbadda2620743a1dd923938f2f3043a38.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils/test.c')
-rw-r--r--coreutils/test.c69
1 files changed, 35 insertions, 34 deletions
diff --git a/coreutils/test.c b/coreutils/test.c
index ba1dbaa2f..6b16ffeb1 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -845,7 +845,6 @@ int test_main(int argc, char **argv)
845{ 845{
846 int res; 846 int res;
847 const char *arg0; 847 const char *arg0;
848// bool negate = 0;
849 848
850 arg0 = bb_basename(argv[0]); 849 arg0 = bb_basename(argv[0]);
851 if (arg0[0] == '[') { 850 if (arg0[0] == '[') {
@@ -863,6 +862,7 @@ int test_main(int argc, char **argv)
863 } 862 }
864 argv[argc] = NULL; 863 argv[argc] = NULL;
865 } 864 }
865 /* argc is unused after this point */
866 866
867 /* We must do DEINIT_S() prior to returning */ 867 /* We must do DEINIT_S() prior to returning */
868 INIT_S(); 868 INIT_S();
@@ -881,43 +881,45 @@ int test_main(int argc, char **argv)
881 */ 881 */
882 /*ngroups = 0; - done by INIT_S() */ 882 /*ngroups = 0; - done by INIT_S() */
883 883
884 //argc--;
885 argv++; 884 argv++;
885 args = argv;
886 886
887 /* Implement special cases from POSIX.2, section 4.62.4 */ 887 /* Implement special cases from POSIX.2, section 4.62.4.
888 if (!argv[0]) { /* "test" */ 888 * Testcase: "test '(' = '('"
889 res = 1; 889 * The general parser would misinterpret '(' as group start.
890 goto ret; 890 */
891 } 891 if (1) {
892#if 0 892 int negate = 0;
893// Now it's fixed in the parser and should not be needed 893 again:
894 if (LONE_CHAR(argv[0], '!') && argv[1]) { 894 if (!argv[0]) {
895 negate = 1; 895 /* "test" */
896 //argc--; 896 res = 1;
897 argv++; 897 goto ret_special;
898 } 898 }
899 if (!argv[1]) { /* "test [!] arg" */ 899 if (!argv[1]) {
900 res = (*argv[0] == '\0'); 900 /* "test [!] arg" */
901 goto ret; 901 res = (argv[0][0] == '\0');
902 } 902 goto ret_special;
903 if (argv[2] && !argv[3]) { 903 }
904 check_operator(argv[1]); 904 if (argv[2] && !argv[3]) {
905 if (last_operator->op_type == BINOP) { 905 check_operator(argv[1]);
906 /* "test [!] arg1 <binary_op> arg2" */ 906 if (last_operator->op_type == BINOP) {
907 args = argv; 907 /* "test [!] arg1 <binary_op> arg2" */
908 res = (binop() == 0); 908 args = argv;
909 goto ret; 909 res = (binop() == 0);
910 ret_special:
911 /* If there was leading "!" op... */
912 res ^= negate;
913 goto ret;
914 }
915 }
916 if (LONE_CHAR(argv[0], '!')) {
917 argv++;
918 negate ^= 1;
919 goto again;
910 } 920 }
911 } 921 }
912 922
913 /* Some complex expression. Undo '!' removal */
914 if (negate) {
915 negate = 0;
916 //argc++;
917 argv--;
918 }
919#endif
920 args = argv;
921 res = !oexpr(check_operator(*args)); 923 res = !oexpr(check_operator(*args));
922 924
923 if (*args != NULL && *++args != NULL) { 925 if (*args != NULL && *++args != NULL) {
@@ -930,6 +932,5 @@ int test_main(int argc, char **argv)
930 } 932 }
931 ret: 933 ret:
932 DEINIT_S(); 934 DEINIT_S();
933// return negate ? !res : res;
934 return res; 935 return res;
935} 936}