On Friday 15 January 2010 17:07:48 Garrett Cooper wrote: > Shortly after I sent out this email, I received some helpful replies > as to why my code wasn't working. It turns out that the curly bracket > regexp quantifier operators available in many other popular > implementations of regexps (perl, python, tcl) isn't supported in awk. > Here's the new patch with less bloat.
the patch itself is word wrapped in the e-mail though :(
> +_abspath() {
> + echo "$@" | awk '{ sub(/\/$/, ""); while (gsub(/\/\//, "/")) { };
> while (gsub(/\/[^\/]+\/\.\.\/?/, "/")) { }; while (gsub(/\/\.\//,
> "/")) { } print }'
> +}
it's easy to line wrap awk scripts, and this sucker really needs it
btw, this doesnt quite handle:
/a/b/c/.././
how about this (largely untested) sed:
sed -r -e 's:/+[.]/+:/:g' -e 's:(^|/+[^/]*)/+[.][.]/+:/:g' -e 's:/+$::'
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ tests/test_abspath.sh 15 Jan 2010 22:04:59 -0000
> +# NOTE (garrcoop): I usually don't use bashisms, but it was just easier to
> +# express these values as an array of values instead of one whacky long
> +# string.
> +test_strings=( foo/bar /foo/bar /foo/../bar /foo/bar/../baz
> /foo/bar/../baz/ /foo/../bar/ /foo/../bar/.. /foo/../bar/../
> /foo/bar/../baz /foo/./bar /./foo/./bar /foo//bar //foo/bar
> //////foo/bar /foo/////bar )
> +expected_strings=( foo/bar /foo/bar /bar /foo/baz
> /foo/baz /bar / / /foo/baz
> /foo/bar /foo/bar /foo/bar /foo/bar /foo/bar
> /foo/bar )
probably be good if the source were better wrapped
however, two parallel arrays makes it hard to correlate the input/expected
values. how about something like:
set -- \
foo/bar:foo/bar \
/foo/bar:/foo/bar \
/foo/../bar:/bar \
...........
then you can easily do:
for test in "$@" ; do
input=${test%:*}
expect=${test#*:}
...
done
this should be POSIX and avoid /bin/bash
-mike
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------------ Throughout its 18-year history, RSA Conference consistently attracts the world's best and brightest in the field, creating opportunities for Conference attendees to learn about information security's most important issues through interactions with peers, luminaries and emerging and established companies. http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
