Wolfgang Denk 855f18ea0e setexpr: add regex substring matching and substitution
Add "setexpr name gsub r s [t]" and "setexpr name sub r s [t]"
commands which implement substring matching for the regular
expression <r> in the string <t>, and substitution of the string <s>.
The result is assigned to the environment variable <name>.  If <t> is
not supplied, the previous value of <name> is used instead.  "gsub"
performs global substitution, while "sub" will replace only the first
substring.

Both commands are closely modeled after the gawk functions with the
same names.

Examples:

- Generate broadcast address by substituting the last two numbers of
  the IP address by "255.255":

  	=> print ipaddr
	ipaddr=192.168.1.104
	=> setexpr broadcast sub "(.*\\.).*\\..*" "\\1255.255" $ipaddr
	broadcast=192.168.255.255

- Depending on keyboard configuration (German vs. US keyboard) a
  barcode scanner may initialize the MAC address as C0:E5:4E:02:06:DC
  or as C0>E5>4E>02>06>DC.  Make sure we always have a correct value:

	=> print ethaddr
	ethaddr=C0>E5>4E>02>06>DC
	=> setexpr ethaddr gsub > :
	ethaddr=C0:E5:4E:02:06:DC

- Do the same, but substitute one step at a time in a loop until no
  futher matches:

	=> setenv ethaddr C0>E5>4E>02>06>DC
	=> while setexpr ethaddr sub > :
	> do
	> echo -----
	> done
	ethaddr=C0:E5>4E>02>06>DC
	-----
	ethaddr=C0:E5:4E>02>06>DC
	-----
	ethaddr=C0:E5:4E:02>06>DC
	-----
	ethaddr=C0:E5:4E:02:06>DC
	-----
	ethaddr=C0:E5:4E:02:06:DC
	-----
	C0:E5:4E:02:06:DC: No match
	=> print ethaddr
	ethaddr=C0:E5:4E:02:06:DC

etc.

To enable this feature, the CONFIG_REGEX option has to be defined in
the board config file.

Signed-off-by: Wolfgang Denk <wd@denx.de>
2013-05-01 16:24:01 -04:00
..
2013-04-01 16:33:52 -04:00
2013-04-01 16:33:52 -04:00
2012-11-04 11:00:35 -07:00
2013-03-27 15:30:11 -04:00
2012-10-03 16:01:22 -07:00
2012-11-04 11:00:35 -07:00
2012-11-04 11:00:35 -07:00
2013-03-12 17:06:22 +09:00
2012-11-04 11:00:35 -07:00
2013-02-20 08:52:29 -05:00
2012-11-04 11:00:35 -07:00
2012-11-04 11:00:34 -07:00
2013-04-01 16:33:52 -04:00
2012-11-04 11:00:35 -07:00
2012-11-04 11:00:34 -07:00
2012-12-11 13:17:33 -07:00
2013-02-20 08:52:41 -05:00
2013-03-12 23:28:40 +01:00
2012-11-04 11:00:35 -07:00
2012-11-04 11:00:35 -07:00
2011-04-08 00:44:27 -04:00
2011-07-28 16:41:06 +02:00
2012-11-04 11:00:35 -07:00
2012-11-04 11:00:35 -07:00
2012-11-04 11:00:35 -07:00
2012-11-04 11:00:35 -07:00
2012-11-04 11:00:35 -07:00
2013-04-01 16:33:52 -04:00
2013-01-08 10:54:33 +09:00
2013-05-01 11:17:21 -04:00
2013-04-12 14:13:13 -07:00
2013-04-11 15:52:54 -04:00
2012-08-09 23:39:18 +02:00
2012-12-13 11:46:56 -07:00
2013-04-01 16:33:52 -04:00
2013-04-01 16:33:52 -04:00
2012-12-11 13:17:34 -07:00
2011-12-07 08:41:22 +01:00
2013-03-29 20:10:42 +09:00
2011-02-02 22:36:10 +01:00
2013-03-27 15:30:11 -04:00
2010-01-18 00:23:00 +01:00
2013-03-29 14:29:39 +01:00
2011-10-22 01:13:35 +02:00
2013-04-11 15:52:55 -04:00
2002-08-17 09:36:01 +00:00
2012-11-04 11:00:36 -07:00
2012-11-04 11:00:35 -07:00