hush: add support for #/% parameter substitution

Mike Frysinger vapier at gentoo.org
Mon Apr 6 06:24:17 UTC 2009


this code is based on the stuff in ash.  i started to go the route of the math 
code and split it out into a library to share code, but after getting my head 
around the ash interface, i found the implementation sucks in that:
 - it's tied to the ash parser in terms of variable meaning
 - the pattern must follow the variable contents in memory
	i.e. "foo=aba; echo ${foo#a*};" creates "aba\0a*"
 - the functions (unnecessarily imo) rely on ash's method for escaping chars

as such, i split out the scanleft and scanright funcs into shell/match.c and 
then simplified them greatly to follow a more natural form based on what the 
functions are doing: matching a pattern against a string.  however, i did not 
go back and try to merge things back with the ash shell.  i'm not terribly 
concerned there.

the attached diff allows hush to pass ash's posix tests for these forms (btw, 
we should probably look at trying to unify these test trees ...).  while the 
hunk against hush.c looks like i didnt indent code in expand_vars_to_list, i 
actually did, but i generated the diff with -w to make it more readable.  
indenting the expansion block added noise and makes it harder to digest the 
changes.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hush-param-sub.patch
Type: text/x-patch
Size: 6470 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20090406/bce987c4/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20090406/bce987c4/attachment-0001.pgp>


More information about the busybox mailing list