From patchwork Fri Mar 22 21:44:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfgang Denk X-Patchwork-Id: 230269 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 2D3102C00CF for ; Sat, 23 Mar 2013 08:45:23 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4DD724A278; Fri, 22 Mar 2013 22:45:21 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yWz9vodDHfi3; Fri, 22 Mar 2013 22:45:20 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5805E4A277; Fri, 22 Mar 2013 22:45:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E3D494A259 for ; Fri, 22 Mar 2013 22:45:13 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jjQ3m6P57XbN for ; Fri, 22 Mar 2013 22:45:13 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by theia.denx.de (Postfix) with ESMTPS id 18A074A24D for ; Fri, 22 Mar 2013 22:45:12 +0100 (CET) Received: from frontend1.mail.m-online.net (frontend1.mail.intern.m-online.net [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 3ZXdh80nq2z3hhqM for ; Fri, 22 Mar 2013 22:45:12 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.68]) by mail.m-online.net (Postfix) with ESMTP id 3ZXdh80d1Dzbddx for ; Fri, 22 Mar 2013 22:45:12 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from smtp-auth.mnet-online.de ([192.168.8.180]) by localhost (dynscan1.mail.m-online.net [192.168.6.68]) (amavisd-new, port 10024) with ESMTP id yF-R2WAW9rb2 for ; Fri, 22 Mar 2013 22:45:10 +0100 (CET) X-Auth-Info: JdcwpYP6f9DhuvUDTcoiwvCeoPxbFyoeEj099VgrqHk= Received: from diddl.denx.de (host-80-81-18-216.customer.m-online.net [80.81.18.216]) by smtp-auth.mnet-online.de (Postfix) with ESMTPA for ; Fri, 22 Mar 2013 22:45:10 +0100 (CET) Received: from gemini.denx.de (unknown [10.0.0.2]) by diddl.denx.de (Postfix) with ESMTP id 9AFFB1A7619 for ; Fri, 22 Mar 2013 22:45:09 +0100 (CET) Received: by gemini.denx.de (Postfix, from userid 500) id B54732014D1; Fri, 22 Mar 2013 22:45:08 +0100 (CET) From: Wolfgang Denk To: u-boot@lists.denx.de Date: Fri, 22 Mar 2013 22:44:53 +0100 Message-Id: <1363988699-6410-4-git-send-email-wd@denx.de> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1363988699-6410-1-git-send-email-wd@denx.de> References: <1320609172-3157-1-git-send-email-wd@denx.de>, <1320609326-3259-1-git-send-email-wd@denx.de> <1363988699-6410-1-git-send-email-wd@denx.de> Subject: [U-Boot] [PATCH 3/9] "env grep" - add options to grep in name, value, or both. X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Add options to "env grep" command: -n : search only the envrironment variable names -v : search only their values -b : search both names and values (= default) An option "--" will stop parsing options, so to print variables that contain the striing "- " please use: env grep -- "- " Or to print all environment varioables which have a '-' in their name, use: env grep -n -- - Signed-off-by: Wolfgang Denk --- common/cmd_nvedit.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 40d9f7a..441bf40 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -163,13 +163,39 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char *res = NULL; - int len; + int len, grep_flags; if (argc < 2) return CMD_RET_USAGE; + grep_flags = H_MATCH_BOTH; + + while (argc > 1 && **(argv + 1) == '-') { + char *arg = *++argv; + + --argc; + while (*++arg) { + switch (*arg) { + case 'n': /* grep for name */ + grep_flags = H_MATCH_KEY; + break; + case 'v': /* grep for value */ + grep_flags = H_MATCH_DATA; + break; + case 'b': /* grep for both */ + grep_flags = H_MATCH_BOTH; + break; + case '-': + goto DONE; + default: + return CMD_RET_USAGE; + } + } + } + +DONE: len = hexport_r(&env_htab, '\n', - flag | H_MATCH_BOTH | H_MATCH_SUBSTR, + flag | grep_flags | H_MATCH_SUBSTR, &res, 0, argc, argv); if (len > 0) { @@ -1106,7 +1132,7 @@ static char env_help_text[] = "env flags - print variables that have non-default flags\n" #endif #if defined(CONFIG_CMD_GREPENV) - "env grep string [...] - search environment\n" + "env grep [-n | -v | -b] string [...] - search environment\n" #endif #if defined(CONFIG_CMD_IMPORTENV) "env import [-d] [-t | -b | -c] addr [size] - import environment\n" @@ -1153,8 +1179,10 @@ U_BOOT_CMD_COMPLETE( U_BOOT_CMD_COMPLETE( grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep, "search environment variables", - "string ...\n" - " - list environment name=value pairs matching 'string'", + "[-n | -v | -b] string ...\n" + " - list environment name=value pairs matching 'string'\n" + " \"-n\": search variable names; \"-v\": search values;\n" + " \"-b\": search both names and values (default)", var_complete ); #endif