From 5a31ea04c9ee5544fbb70ad7597ea4b294840eab Mon Sep 17 00:00:00 2001 From: Wolfgang Denk Date: Sat, 23 Mar 2013 23:50:29 +0000 Subject: "env grep" - reimplement command using hexport_r() Also drop hstrstr_r() which is not needed any more. The new code is way more flexible. Signed-off-by: Wolfgang Denk --- common/cmd_nvedit.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'common') diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 49b9d74..a4b71f8 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -164,31 +164,25 @@ static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc, static int do_env_grep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - ENTRY *match; - unsigned char matched[env_htab.size / 8]; - int rcode = 1, arg = 1, idx; + char *res = NULL; + int len; if (argc < 2) return CMD_RET_USAGE; - memset(matched, 0, env_htab.size / 8); + len = hexport_r(&env_htab, '\n', + flag | H_MATCH_BOTH | H_MATCH_SUBSTR, + &res, 0, argc, argv); - while (arg <= argc) { - idx = 0; - while ((idx = hstrstr_r(argv[arg], idx, &match, &env_htab))) { - if (!(matched[idx / 8] & (1 << (idx & 7)))) { - puts(match->key); - puts("="); - puts(match->data); - puts("\n"); - } - matched[idx / 8] |= 1 << (idx & 7); - rcode = 0; - } - arg++; + if (len > 0) { + puts(res); + free(res); } - return rcode; + if (len < 2) + return 1; + + return 0; } #endif #endif /* CONFIG_SPL_BUILD */ -- cgit v1.1