On Jan 15, 2010, at 2:27 PM, Mike Frysinger wrote:

> 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

Fixed.

> btw, this doesnt quite handle:
> /a/b/c/.././

Resolved in the latest version.

> how about this (largely untested) sed:
> sed -r -e 's:/+[.]/+:/:g' -e 's:(^|/+[^/]*)/+[.][.]/+:/:g' -e 's:/+$::'

I'm not sure if it's just me, but I prefer awk to sed because the regular 
expressions and operations are a lot easier to follow than sed'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

Sure -- I was looking for the possibility of testcases with spaces in them, but 
with the number of testcases, it may be a good idea to just move to another 
method of defining the testcase, like with python [// nose?].

Thanks!
-Garrett
------------------------------------------------------------------------------
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

Reply via email to