Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/coreutils/test.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/coreutils/test.c

    r3232 r3621  
    4040//config:     Enable 64-bit support in test.
    4141
    42 /* "test --help" does not print help (POSIX compat), only "[ --help" does.
    43  * We display "<applet> EXPRESSION ]" here (not "<applet> EXPRESSION")
    44  * Unfortunately, it screws up generated BusyBox.html. TODO. */
    45 //usage:#define test_trivial_usage
    46 //usage:       "EXPRESSION ]"
    47 //usage:#define test_full_usage "\n\n"
    48 //usage:       "Check file types, compare values etc. Return a 0/1 exit code\n"
    49 //usage:       "depending on logical value of EXPRESSION"
     42/* "test --help" is special-cased to ignore --help */
     43//usage:#define test_trivial_usage NOUSAGE_STR
     44//usage:#define test_full_usage ""
    5045//usage:
    5146//usage:#define test_example_usage
     
    827822    int res;
    828823    const char *arg0;
    829 //  bool negate = 0;
    830824
    831825    arg0 = bb_basename(argv[0]);
     
    845839        argv[argc] = NULL;
    846840    }
     841    /* argc is unused after this point */
    847842
    848843    /* We must do DEINIT_S() prior to returning */
     
    863858    /*ngroups = 0; - done by INIT_S() */
    864859
    865     //argc--;
    866860    argv++;
    867 
    868     /* Implement special cases from POSIX.2, section 4.62.4 */
    869     if (!argv[0]) { /* "test" */
    870         res = 1;
    871         goto ret;
    872     }
    873 #if 0
    874 // Now it's fixed in the parser and should not be needed
    875     if (LONE_CHAR(argv[0], '!') && argv[1]) {
    876         negate = 1;
    877         //argc--;
    878         argv++;
    879     }
    880     if (!argv[1]) { /* "test [!] arg" */
    881         res = (*argv[0] == '\0');
    882         goto ret;
    883     }
    884     if (argv[2] && !argv[3]) {
    885         check_operator(argv[1]);
    886         if (last_operator->op_type == BINOP) {
    887             /* "test [!] arg1 <binary_op> arg2" */
    888             args = argv;
    889             res = (binop() == 0);
    890             goto ret;
     861    args = argv;
     862
     863    /* Implement special cases from POSIX.2, section 4.62.4.
     864     * Testcase: "test '(' = '('"
     865     * The general parser would misinterpret '(' as group start.
     866     */
     867    if (1) {
     868        int negate = 0;
     869 again:
     870        if (!argv[0]) {
     871            /* "test" */
     872            res = 1;
     873            goto ret_special;
    891874        }
    892     }
    893 
    894     /* Some complex expression. Undo '!' removal */
    895     if (negate) {
    896         negate = 0;
    897         //argc++;
    898         argv--;
    899     }
    900 #endif
    901     args = argv;
     875        if (!argv[1]) {
     876            /* "test [!] arg" */
     877            res = (argv[0][0] == '\0');
     878            goto ret_special;
     879        }
     880        if (argv[2] && !argv[3]) {
     881            check_operator(argv[1]);
     882            if (last_operator->op_type == BINOP) {
     883                /* "test [!] arg1 <binary_op> arg2" */
     884                args = argv;
     885                res = (binop() == 0);
     886 ret_special:
     887                /* If there was leading "!" op... */
     888                res ^= negate;
     889                goto ret;
     890            }
     891        }
     892        if (LONE_CHAR(argv[0], '!')) {
     893            argv++;
     894            negate ^= 1;
     895            goto again;
     896        }
     897    }
     898
    902899    res = !oexpr(check_operator(*args));
    903900
     
    912909 ret:
    913910    DEINIT_S();
    914 //  return negate ? !res : res;
    915911    return res;
    916912}
Note: See TracChangeset for help on using the changeset viewer.