[U-Boot] [PATCH v2 0/11] Add Regular Expressions Support
Wolfgang Denk
wd at denx.de
Sun Mar 24 10:50:27 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 caused it to
dump always _all_ environment variables on some systems), and adds
the capability to grep in either the variable name, or the value, or
in both (the old version always did the latter). Instead of special
functions we now use common code (i. e. hexport_r()) for the variable
look-up, 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
bar code 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.
Notes:
- This patch series has been compile-tested (and found to be clean
with ELDK v5.3) on all of the following boards:
ARM: m28evk
PPC4xx: acadia bamboo bluestone bubinga canyonlands dlvision-10g
dlvision ebony gdppc440etx icon intip io io64 iocon katmai kilauea
luan makalu neo ocotea redwood sequoia t3corp taihu taishan walnut
yosemite yucca
- Runtime / functional testing has been done mostly on PPC (Sequoia
board).
Changes in v2:
- fixed trailing whitespace errors
- Note 1: The "line over 80 characters" warning will NOT be fixed due
to the "never break user-visible strings" rule.
- Note 2: The "Alignment should match open parenthesis" check will NOT
be fixed due to the "indent by TABs only" rule.
- Fix ERROR: "foo * bar" should be "foo *bar" errors
- Fix trailing whitespace error
- Note: the "Alignment should match open parenthesis" check will not
be fixed due to the "indent always byy TABs" rule.
- no changes; most of this is imported code and is intentionally left
as is
- the "Alignment should match open parenthesis" check is left due to
the "indent only by TABs" rule
- the "line over 80 characters" warning is left due to the "never
break user-visible strings" rule
- Fix trailing whitespace error
- fix "No space is necessary after a cast" checks
- fix "space prohibited before semicolon" and "space required after
that ';'" errors (but I onsider the result less readable :-( )
- Note: the remaining warnings ("line over 80 characters") and checks
("Alignment should match open parenthesis") are intentionally left
as is.
- Do the white space cleanup globally, and as separate patch
Wolfgang Denk (11):
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: white space cleanup
m28evk: enable "env grep" and regexp support
amcc-common.h: minor white space cleanup
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 | 259 +++++++--------
include/search.h | 15 +-
include/slre.h | 100 ++++++
lib/Makefile | 1 +
lib/hashtable.c | 93 ++++--
lib/slre.c | 724 ++++++++++++++++++++++++++++++++++++++++++
10 files changed, 1391 insertions(+), 200 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