- handle signs on integers properly,
- make sure error messages for bad integers are moderately sensible - handle test ! "abc" -o "abc" (This should evaluate to true) (and similar cases) ie: and/or operator test added to POSIX special case processing. - more test cases added. Based on: Work done on 1.x's test(1) by Andrew Moore and Adam David.
This commit is contained in:
parent
65273efbc6
commit
5fafa20681
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=2664
@ -135,3 +135,17 @@ echo 't 700 -le 1000 -a -n "1" -a "20" = "20"'
|
||||
t 700 -le 1000 -a -n "1" -a "20" = "20"
|
||||
echo 't ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
|
||||
t ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)
|
||||
|
||||
echo 't -5 -eq 5'
|
||||
t -5 -eq 5
|
||||
|
||||
|
||||
echo 't foo -a ""'
|
||||
t foo -a ""
|
||||
echo 't "" -a foo'
|
||||
t "" -a foo
|
||||
echo 't "" -a ""'
|
||||
t "" -a ""
|
||||
echo 't "" -o ""'
|
||||
t "" -o ""
|
||||
|
||||
|
@ -81,6 +81,16 @@ const char *const binary_op[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *const andor_op[] = {
|
||||
"-o",
|
||||
"|",
|
||||
"-a",
|
||||
"&",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
|
||||
const char op_priority[] = {
|
||||
3,
|
||||
12,
|
||||
|
@ -73,5 +73,6 @@
|
||||
|
||||
extern const char *const unary_op[];
|
||||
extern const char *const binary_op[];
|
||||
extern const char *const andor_op[];
|
||||
extern const char op_priority[];
|
||||
extern const char op_argflag[];
|
||||
|
@ -161,7 +161,7 @@ main(argc, argv)
|
||||
}
|
||||
break;
|
||||
case 4: /* % test ! arg1 op arg2 */
|
||||
if (IS_BANG(argv[1])) {
|
||||
if (IS_BANG(argv[1]) && lookup_op(argv[3], andor_op) < 0 ) {
|
||||
ret_val = posix_binary_op(&argv[2]);
|
||||
if (ret_val >= 0)
|
||||
return (!ret_val);
|
||||
@ -528,7 +528,8 @@ get_int(v, lp)
|
||||
char *ep;
|
||||
|
||||
for (; *v && isspace(*v); ++v);
|
||||
if (isdigit(*v)) {
|
||||
|
||||
if (isdigit(*v) || ((*v == '-' || *v == '+') && isdigit(*(v+1)))) {
|
||||
errno = 0;
|
||||
val = strtol(v, &ep, 10);
|
||||
if (*ep != '\0')
|
||||
|
Loading…
Reference in New Issue
Block a user