]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - common/cmd_test.c
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
9 * Define _STDBOOL_H here to avoid macro expansion of true and false.
10 * If the future code requires macro true or false, remove this define
11 * and undef true and false before U_BOOT_CMD. This define and comment
12 * shall be removed if change to U_BOOT_CMD is made to take string
13 * instead of stringifying it.
20 static int do_test(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
23 int left
, adv
, expr
, last_expr
, neg
, last_cmp
;
31 debug("test(%d):", argc
);
34 debug(" '%s'", argv
[left
++]);
39 left
= argc
- 1; ap
= argv
+ 1;
40 if (left
> 0 && strcmp(ap
[0], "!") == 0) {
52 if (strcmp(ap
[0], "-o") == 0 || strcmp(ap
[0], "-a") == 0)
54 else if (strcmp(ap
[0], "-z") == 0 || strcmp(ap
[0], "-n") == 0)
65 if (strcmp(ap
[0], "-o") == 0) {
68 } else if (strcmp(ap
[0], "-a") == 0) {
78 if (strcmp(ap
[0], "-z") == 0)
79 expr
= strlen(ap
[1]) == 0 ? 1 : 0;
80 else if (strcmp(ap
[0], "-n") == 0)
81 expr
= strlen(ap
[1]) == 0 ? 0 : 1;
88 expr
= last_expr
|| expr
;
89 else if (last_cmp
== 1)
90 expr
= last_expr
&& expr
;
95 if (strcmp(ap
[1], "=") == 0)
96 expr
= strcmp(ap
[0], ap
[2]) == 0;
97 else if (strcmp(ap
[1], "!=") == 0)
98 expr
= strcmp(ap
[0], ap
[2]) != 0;
99 else if (strcmp(ap
[1], ">") == 0)
100 expr
= strcmp(ap
[0], ap
[2]) > 0;
101 else if (strcmp(ap
[1], "<") == 0)
102 expr
= strcmp(ap
[0], ap
[2]) < 0;
103 else if (strcmp(ap
[1], "-eq") == 0)
104 expr
= simple_strtol(ap
[0], NULL
, 10) == simple_strtol(ap
[2], NULL
, 10);
105 else if (strcmp(ap
[1], "-ne") == 0)
106 expr
= simple_strtol(ap
[0], NULL
, 10) != simple_strtol(ap
[2], NULL
, 10);
107 else if (strcmp(ap
[1], "-lt") == 0)
108 expr
= simple_strtol(ap
[0], NULL
, 10) < simple_strtol(ap
[2], NULL
, 10);
109 else if (strcmp(ap
[1], "-le") == 0)
110 expr
= simple_strtol(ap
[0], NULL
, 10) <= simple_strtol(ap
[2], NULL
, 10);
111 else if (strcmp(ap
[1], "-gt") == 0)
112 expr
= simple_strtol(ap
[0], NULL
, 10) > simple_strtol(ap
[2], NULL
, 10);
113 else if (strcmp(ap
[1], "-ge") == 0)
114 expr
= simple_strtol(ap
[0], NULL
, 10) >= simple_strtol(ap
[2], NULL
, 10);
121 expr
= last_expr
|| expr
;
122 else if (last_cmp
== 1)
123 expr
= last_expr
&& expr
;
127 ap
+= adv
; left
-= adv
;
135 debug (": returns %d\n", expr
);
141 test
, CONFIG_SYS_MAXARGS
, 1, do_test
,
142 "minimal test like /bin/sh",
146 static int do_false(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
152 false, CONFIG_SYS_MAXARGS
, 1, do_false
,
153 "do nothing, unsuccessfully",
157 static int do_true(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
163 true, CONFIG_SYS_MAXARGS
, 1, do_true
,
164 "do nothing, successfully",