3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * Define _STDBOOL_H here to avoid macro expansion of true and false.
26 * If the future code requires macro true or false, remove this define
27 * and undef true and false before U_BOOT_CMD. This define and comment
28 * shall be removed if change to U_BOOT_CMD is made to take string
29 * instead of stringifying it.
36 static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
39 int left, adv, expr, last_expr, neg, last_cmp;
47 debug("test(%d):", argc);
50 debug(" '%s'", argv[left++]);
55 left = argc - 1; ap = argv + 1;
56 if (left > 0 && strcmp(ap[0], "!") == 0) {
68 if (strcmp(ap[0], "-o") == 0 || strcmp(ap[0], "-a") == 0)
70 else if (strcmp(ap[0], "-z") == 0 || strcmp(ap[0], "-n") == 0)
81 if (strcmp(ap[0], "-o") == 0) {
84 } else if (strcmp(ap[0], "-a") == 0) {
94 if (strcmp(ap[0], "-z") == 0)
95 expr = strlen(ap[1]) == 0 ? 1 : 0;
96 else if (strcmp(ap[0], "-n") == 0)
97 expr = strlen(ap[1]) == 0 ? 0 : 1;
104 expr = last_expr || expr;
105 else if (last_cmp == 1)
106 expr = last_expr && expr;
111 if (strcmp(ap[1], "=") == 0)
112 expr = strcmp(ap[0], ap[2]) == 0;
113 else if (strcmp(ap[1], "!=") == 0)
114 expr = strcmp(ap[0], ap[2]) != 0;
115 else if (strcmp(ap[1], ">") == 0)
116 expr = strcmp(ap[0], ap[2]) > 0;
117 else if (strcmp(ap[1], "<") == 0)
118 expr = strcmp(ap[0], ap[2]) < 0;
119 else if (strcmp(ap[1], "-eq") == 0)
120 expr = simple_strtol(ap[0], NULL, 10) == simple_strtol(ap[2], NULL, 10);
121 else if (strcmp(ap[1], "-ne") == 0)
122 expr = simple_strtol(ap[0], NULL, 10) != simple_strtol(ap[2], NULL, 10);
123 else if (strcmp(ap[1], "-lt") == 0)
124 expr = simple_strtol(ap[0], NULL, 10) < simple_strtol(ap[2], NULL, 10);
125 else if (strcmp(ap[1], "-le") == 0)
126 expr = simple_strtol(ap[0], NULL, 10) <= simple_strtol(ap[2], NULL, 10);
127 else if (strcmp(ap[1], "-gt") == 0)
128 expr = simple_strtol(ap[0], NULL, 10) > simple_strtol(ap[2], NULL, 10);
129 else if (strcmp(ap[1], "-ge") == 0)
130 expr = simple_strtol(ap[0], NULL, 10) >= simple_strtol(ap[2], NULL, 10);
137 expr = last_expr || expr;
138 else if (last_cmp == 1)
139 expr = last_expr && expr;
143 ap += adv; left -= adv;
151 debug (": returns %d\n", expr);
157 test, CONFIG_SYS_MAXARGS, 1, do_test,
158 "minimal test like /bin/sh",
162 static int do_false(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
168 false, CONFIG_SYS_MAXARGS, 1, do_false,
169 "do nothing, unsuccessfully",
173 static int do_true(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
179 true, CONFIG_SYS_MAXARGS, 1, do_true,
180 "do nothing, successfully",