[U-Boot] [PATCH 0/9] Add Regular Expressions Support

Wolfgang Denk wd at denx.de
Fri Mar 22 22:44:50 CET 2013


The following patch series adds the SLRE "Super Light Regular
Expression" library and uses this to add regex support for 
the "env grep" (aka "grepenv") command, and new functions (or
operators?) "gsub" and "sub" to the "setexpr" command.

The rework to "env grep" also fixed a few bugs (which cuased it to
dump always _all_ environment varioables on some systems), and adds
the capability to grep in either the variable name, or the value, or
in both (the old version olways did the latter).  Instead of special
functions we now use common code (i. e. hexport_r()) for the variable
lookup, which gives us sorted output as a free additional benefit.

This allows to do things like

- 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)

- 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

etc.

	
Regex support can be enabled by defining  CONFIG_REGEX  in the board
config file.


Wolfgang Denk (9):
  hashtable: preparations to use hexport_r() for "env grep"
  "env grep" - reimplement command using hexport_r()
  "env grep" - add options to grep in name, value, or both.
  Add SLRE - Super Light Regular Expression library
  "env grep" - add support for regular expression matches
  setexpr: simplify code, improve help message
  setexpr: add regex substring matching and substitution
  m28evk: enable "env grep" and regexp support
  amcc-common.h: enable support for "env grep", "setexpr", and regex.

 README                        |   7 +
 common/cmd_nvedit.c           |  87 +++--
 common/cmd_setexpr.c          | 296 ++++++++++++++++-
 include/configs/amcc-common.h |   9 +-
 include/configs/m28evk.h      |   3 +
 include/search.h              |  15 +-
 include/slre.h                | 100 ++++++
 lib/Makefile                  |   1 +
 lib/hashtable.c               |  93 ++++--
 lib/slre.c                    | 724 ++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 1263 insertions(+), 72 deletions(-)
 create mode 100644 include/slre.h
 create mode 100644 lib/slre.c

-- 
1.8.1.4



More information about the U-Boot mailing list