projects
/
oweals
/
u-boot.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
armv8/ls2085a_simu: enable eSDHC
[oweals/u-boot.git]
/
common
/
cmd_test.c
diff --git
a/common/cmd_test.c
b/common/cmd_test.c
index 69b1b4cee69aa71a68d0ea70b2f984453c11d4f2..7285f75469fb15f7cf0daa1e9541ca6b3c887834 100644
(file)
--- a/
common/cmd_test.c
+++ b/
common/cmd_test.c
@@
-5,19
+5,12
@@
* SPDX-License-Identifier: GPL-2.0+
*/
* SPDX-License-Identifier: GPL-2.0+
*/
-/*
- * Define _STDBOOL_H here to avoid macro expansion of true and false.
- * If the future code requires macro true or false, remove this define
- * and undef true and false before U_BOOT_CMD. This define and comment
- * shall be removed if change to U_BOOT_CMD is made to take string
- * instead of stringifying it.
- */
-#define _STDBOOL_H
-
#include <common.h>
#include <command.h>
#include <common.h>
#include <command.h>
+#include <fs.h>
#define OP_INVALID 0
#define OP_INVALID 0
+#define OP_NOT 1
#define OP_OR 2
#define OP_AND 3
#define OP_STR_EMPTY 4
#define OP_OR 2
#define OP_AND 3
#define OP_STR_EMPTY 4
@@
-32,6
+25,7
@@
#define OP_INT_LE 13
#define OP_INT_GT 14
#define OP_INT_GE 15
#define OP_INT_LE 13
#define OP_INT_GT 14
#define OP_INT_GE 15
+#define OP_FILE_EXISTS 16
const struct {
int arg;
const struct {
int arg;
@@
-39,10
+33,6
@@
const struct {
int op;
int adv;
} op_adv[] = {
int op;
int adv;
} op_adv[] = {
- {0, "-o", OP_OR, 1},
- {0, "-a", OP_AND, 1},
- {0, "-z", OP_STR_EMPTY, 2},
- {0, "-n", OP_STR_NEMPTY, 2},
{1, "=", OP_STR_EQ, 3},
{1, "!=", OP_STR_NEQ, 3},
{1, "<", OP_STR_LT, 3},
{1, "=", OP_STR_EQ, 3},
{1, "!=", OP_STR_NEQ, 3},
{1, "<", OP_STR_LT, 3},
@@
-53,12
+43,18
@@
const struct {
{1, "-le", OP_INT_LE, 3},
{1, "-gt", OP_INT_GT, 3},
{1, "-ge", OP_INT_GE, 3},
{1, "-le", OP_INT_LE, 3},
{1, "-gt", OP_INT_GT, 3},
{1, "-ge", OP_INT_GE, 3},
+ {0, "!", OP_NOT, 1},
+ {0, "-o", OP_OR, 1},
+ {0, "-a", OP_AND, 1},
+ {0, "-z", OP_STR_EMPTY, 2},
+ {0, "-n", OP_STR_NEMPTY, 2},
+ {0, "-e", OP_FILE_EXISTS, 4},
};
static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char * const *ap;
};
static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char * const *ap;
- int i, op, left, adv, expr, last_expr,
neg, last_cm
p;
+ int i, op, left, adv, expr, last_expr,
last_unop, last_bino
p;
/* args? */
if (argc < 3)
/* args? */
if (argc < 3)
@@
-73,17
+69,11
@@
static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
#endif
}
#endif
- last_expr = 0;
- left = argc - 1; ap = argv + 1;
- if (left > 0 && strcmp(ap[0], "!") == 0) {
- neg = 1;
- ap++;
- left--;
- } else
- neg = 0;
-
- expr = -1;
- last_cmp = OP_INVALID;
+ left = argc - 1;
+ ap = argv + 1;
+ expr = 0;
+ last_unop = OP_INVALID;
+ last_binop = OP_INVALID;
last_expr = -1;
while (left > 0) {
for (i = 0; i < ARRAY_SIZE(op_adv); i++) {
last_expr = -1;
while (left > 0) {
for (i = 0; i < ARRAY_SIZE(op_adv); i++) {
@@
-147,32
+137,44
@@
static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
expr = simple_strtol(ap[0], NULL, 10) >=
simple_strtol(ap[2], NULL, 10);
break;
expr = simple_strtol(ap[0], NULL, 10) >=
simple_strtol(ap[2], NULL, 10);
break;
+ case OP_FILE_EXISTS:
+ expr = file_exists(ap[1], ap[2], ap[3], FS_TYPE_ANY);
+ break;
}
switch (op) {
case OP_OR:
last_expr = expr;
}
switch (op) {
case OP_OR:
last_expr = expr;
- last_
cm
p = OP_OR;
+ last_
bino
p = OP_OR;
break;
case OP_AND:
last_expr = expr;
break;
case OP_AND:
last_expr = expr;
- last_cmp = OP_AND;
+ last_binop = OP_AND;
+ break;
+ case OP_NOT:
+ if (last_unop == OP_NOT)
+ last_unop = OP_INVALID;
+ else
+ last_unop = OP_NOT;
break;
default:
break;
default:
- if (last_cmp == OP_OR)
+ if (last_unop == OP_NOT) {
+ expr = !expr;
+ last_unop = OP_INVALID;
+ }
+
+ if (last_binop == OP_OR)
expr = last_expr || expr;
expr = last_expr || expr;
- else if (last_
cm
p == OP_AND)
+ else if (last_
bino
p == OP_AND)
expr = last_expr && expr;
expr = last_expr && expr;
- last_cmp = OP_INVALID;
+ last_binop = OP_INVALID;
+
break;
}
ap += adv; left -= adv;
}
break;
}
ap += adv; left -= adv;
}
- if (neg)
- expr = !expr;
-
expr = !expr;
debug (": returns %d\n", expr);
expr = !expr;
debug (": returns %d\n", expr);
@@
-180,6
+182,9
@@
static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return expr;
}
return expr;
}
+#undef true
+#undef false
+
U_BOOT_CMD(
test, CONFIG_SYS_MAXARGS, 1, do_test,
"minimal test like /bin/sh",
U_BOOT_CMD(
test, CONFIG_SYS_MAXARGS, 1, do_test,
"minimal test like /bin/sh",