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,
27 int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
30 int left, adv, expr, last_expr, neg, last_cmp;
41 printf(" %s", argv[left++]);
46 left = argc - 1; ap = argv + 1;
47 if (left > 0 && strcmp(ap[0], "!") == 0) {
59 if (strcmp(ap[0], "-o") == 0 || strcmp(ap[0], "-a") == 0)
61 else if (strcmp(ap[0], "-z") == 0 || strcmp(ap[0], "-n") == 0)
72 if (strcmp(ap[0], "-o") == 0) {
75 } else if (strcmp(ap[0], "-a") == 0) {
85 if (strcmp(ap[0], "-z") == 0)
86 expr = strlen(ap[1]) == 0 ? 1 : 0;
87 else if (strcmp(ap[0], "-n") == 0)
88 expr = strlen(ap[1]) == 0 ? 0 : 1;
95 expr = last_expr || expr;
96 else if (last_cmp == 1)
97 expr = last_expr && expr;
102 if (strcmp(ap[1], "=") == 0)
103 expr = strcmp(ap[0], ap[2]) == 0;
104 else if (strcmp(ap[1], "!=") == 0)
105 expr = strcmp(ap[0], ap[2]) != 0;
106 else if (strcmp(ap[1], ">") == 0)
107 expr = strcmp(ap[0], ap[2]) > 0;
108 else if (strcmp(ap[1], "<") == 0)
109 expr = strcmp(ap[0], ap[2]) < 0;
110 else if (strcmp(ap[1], "-eq") == 0)
111 expr = simple_strtol(ap[0], NULL, 10) == simple_strtol(ap[2], NULL, 10);
112 else if (strcmp(ap[1], "-ne") == 0)
113 expr = simple_strtol(ap[0], NULL, 10) != simple_strtol(ap[2], NULL, 10);
114 else if (strcmp(ap[1], "-lt") == 0)
115 expr = simple_strtol(ap[0], NULL, 10) < simple_strtol(ap[2], NULL, 10);
116 else if (strcmp(ap[1], "-le") == 0)
117 expr = simple_strtol(ap[0], NULL, 10) <= simple_strtol(ap[2], NULL, 10);
118 else if (strcmp(ap[1], "-gt") == 0)
119 expr = simple_strtol(ap[0], NULL, 10) > simple_strtol(ap[2], NULL, 10);
120 else if (strcmp(ap[1], "-ge") == 0)
121 expr = simple_strtol(ap[0], NULL, 10) >= simple_strtol(ap[2], NULL, 10);
128 expr = last_expr || expr;
129 else if (last_cmp == 1)
130 expr = last_expr && expr;
134 ap += adv; left -= adv;
142 debug (": returns %d\n", expr);
148 test, CONFIG_SYS_MAXARGS, 1, do_test,
149 "minimal test like /bin/sh",
153 int do_false(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
159 false, CONFIG_SYS_MAXARGS, 1, do_false,
160 "do nothing, unsuccessfully",
164 int do_true(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
170 true, CONFIG_SYS_MAXARGS, 1, do_true,
171 "do nothing, successfully",