summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorWolfgang Denk <wd@denx.de>2013-03-23 23:50:32 +0000
committerTom Rini <trini@ti.com>2013-05-01 16:24:00 -0400
commitbe29df6a1ac286e6c482828db28ca96e187c7e00 (patch)
treedb89b8eb8ae6bb1baa93e4d778f82cfcd71580be /common
parenta5ecbe62c25c7c9d6ddd0c9eb4d5ec3350642614 (diff)
"env grep" - add support for regular expression matches
When CONFIG_REGEX is enabled, the new option "-e" becomes available which causes regular expression matches to be used. This allows for example things like these: - print all MAC addresses: => env grep -e eth.*addr eth1addr=00:10:ec:80:c5:15 ethaddr=00:10:ec:00:c5:15 - print all variables that have at least 2 colons in their value: => env grep -v -e :.*: addip=setenv bootargs ${bootargs} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}:${netdev}:off panic=1 eth1addr=00:10:ec:80:c5:15 ethaddr=00:10:ec:00:c5:15 ver=U-Boot 2013.04-rc1-00289-g497746b-dirty (Mar 22 2013 - 12:50:25) etc. Signed-off-by: Wolfgang Denk <wd@denx.de>
Diffstat (limited to 'common')
-rw-r--r--common/cmd_nvedit.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 9158b96224..f8dc38e89a 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -165,12 +165,13 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
char *res = NULL;
- int len, grep_flags;
+ int len, grep_how, grep_what;
if (argc < 2)
return CMD_RET_USAGE;
- grep_flags = H_MATCH_BOTH;
+ grep_how = H_MATCH_SUBSTR; /* default: substring search */
+ grep_what = H_MATCH_BOTH; /* default: grep names and values */
while (argc > 1 && **(argv + 1) == '-') {
char *arg = *++argv;
@@ -178,14 +179,19 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
--argc;
while (*++arg) {
switch (*arg) {
+#ifdef CONFIG_REGEX
+ case 'e': /* use regex matching */
+ grep_how = H_MATCH_REGEX;
+ break;
+#endif
case 'n': /* grep for name */
- grep_flags = H_MATCH_KEY;
+ grep_what = H_MATCH_KEY;
break;
case 'v': /* grep for value */
- grep_flags = H_MATCH_DATA;
+ grep_what = H_MATCH_DATA;
break;
case 'b': /* grep for both */
- grep_flags = H_MATCH_BOTH;
+ grep_what = H_MATCH_BOTH;
break;
case '-':
goto DONE;
@@ -197,7 +203,7 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
DONE:
len = hexport_r(&env_htab, '\n',
- flag | grep_flags | H_MATCH_SUBSTR,
+ flag | grep_what | grep_how,
&res, 0, argc, argv);
if (len > 0) {
@@ -1153,8 +1159,12 @@ static char env_help_text[] =
"env flags - print variables that have non-default flags\n"
#endif
#if defined(CONFIG_CMD_GREPENV)
+#ifdef CONFIG_REGEX
+ "env grep [-e] [-n | -v | -b] string [...] - search environment\n"
+#else
"env grep [-n | -v | -b] string [...] - search environment\n"
#endif
+#endif
#if defined(CONFIG_CMD_IMPORTENV)
"env import [-d] [-t | -b | -c] addr [size] - import environment\n"
#endif
@@ -1200,8 +1210,15 @@ U_BOOT_CMD_COMPLETE(
U_BOOT_CMD_COMPLETE(
grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep,
"search environment variables",
+#ifdef CONFIG_REGEX
+ "[-e] [-n | -v | -b] string ...\n"
+#else
"[-n | -v | -b] string ...\n"
+#endif
" - list environment name=value pairs matching 'string'\n"
+#ifdef CONFIG_REGEX
+ " \"-e\": enable regular expressions;\n"
+#endif
" \"-n\": search variable names; \"-v\": search values;\n"
" \"-b\": search both names and values (default)",
var_complete