From mboxrd@z Thu Jan 1 00:00:00 1970 From: Detlev Zundel Date: Mon, 07 Nov 2011 12:07:42 +0100 Subject: [U-Boot] [PATCH 2/2] env: add regex support for environment variables In-Reply-To: <1320609326-3259-2-git-send-email-wd@denx.de> (Wolfgang Denk's message of "Sun, 6 Nov 2011 20:55:26 +0100") References: <1320609172-3157-1-git-send-email-wd@denx.de> <1320609326-3259-1-git-send-email-wd@denx.de> <1320609326-3259-2-git-send-email-wd@denx.de> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Wolfgang, this really is an interesting addition! > Syntax: env regex [-g] [-s subst] regex name [...] > > The code is based on SLRE (http://slre.sourceforge.net/) > which provides a tiny subset of Perl regular expressions. > > Without options, this will implement regex pattern matching on > environment variables. Variables with matching values will be printd > as with "env print", so this basicly performs a "grep" on the given > list of variables. Ok, this usage looks fine. > With "-s subst", the matching pattern gets replaced with the string > given in "subst". Back references '\0' ... '\9' are allowed, where > '\0' stands for the whole matched string, and '\1', '\2', ... are > replaced with the first, second, ... sub-pattern. > > "-g" allows for global replacement. But IMHO this usage doesn't really belong into the "env" command. It much rather is a further operation of the setexpr command: set environment variable as the result of eval expression", name value1 value2\n" - set environment variable 'name' to the result of the evaluated\n" express specified by . can be &, |, ^, +, -, *, /, %" We could add the erations for regsubst and regsubstg. For actual names for the operations, I'm somewhat unsure. Maybe "function like", i.e. "regsubst(string, pattern, replacement)" and "regsubstg(string, pattern, replacement)"? > Examples: > => setenv foo abcdefghijklmnop > => env reg 'A' '[bdgmo]' foo > => env reg -s 'A' '[bdgmo]' foo > foo=aAcdefghijklmnop > => env reg -g -s 'B' '[bdgmo]' foo > foo=aAcBefBhijklBnBp > => env reg -g -s '\\2--\\1' '(Be).*(kl)' foo > foo=aAckl--BeBnBp So I'd vote for => setenv result regsubst($foo, '[bdgmo]', 'A') What do you think? Cheers Detlev -- To you I'm an atheist; to God, I'm the Loyal Opposition. -- Woody Allen -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de