On Fri, Sep 7, 2012 at 2:27 AM, Roland Mainz <roland.ma...@nrubsig.org> wrote:
> On Mon, Aug 27, 2012 at 11:01 AM, Roland Mainz <roland.ma...@nrubsig.org> 
> wrote:
>> Below is another testcase for .sh.match and typeset -m:
>> -- snip --
>>
>> function parse_attr
>> {
>>         typeset move_mode=$1
>>         typeset attrdata="$2"
>>         integer i
>>
>>         typeset dummy="${attrdata//~(Ex-p)(?:
>>         [[:space:]]+
>>         ( # four different types of name=value syntax
>>                 (?:([:_[:alnum:]-]+)=([^\"\'[:space:]]+?))|
>>                 (?:([:_[:alnum:]-]+)=\"([^\"]*?)\")|
>>                 (?:([:_[:alnum:]-]+)=\'([^\']*?)\')|
>>                 (?:([:_[:alnum:]-]+))
>>         )
>>         )/D}"
>>
>>         case ${move_mode} in
>>                 'plain')
>>                         nameref m=.sh.match
>>                         ;;
>>                 'move')
>>                         typeset -m m=.sh.match
>>                         ;;
>>                 'move_to_compound')
>>                         compound mc
>>                         typeset -m mc.m=.sh.match
>>                         nameref m=mc.m
>>                         ;;
>>                 'move_to_nameref_compound')
>>                         compound mc
>>                         nameref mcn=mc
>>                         typeset -m mcn.m=.sh.match
>>                         nameref m=mcn.m
>>                         ;;
>>                 *)
>>                         print -u2 -f '# wrong move_mode=%q\n' "${move_mode}"
>>                         return 1
>>                         ;;
>>         esac
>>
>>         for (( i=0 ; i < fmax(1, ${#m[0][@]}) ; i++ )) ; do
>>                 [[ -v m[2][i] && -v m[3][i] ]] && printf '%q=%q\n' 
>> "${m[2][i]}" "${m[3][i]}"
>>                 [[ -v m[4][i] && -v m[5][i] ]] && printf '%q=%q\n' 
>> "${m[4][i]}" "${m[5][i]}"
>>                 [[ -v m[6][i] && -v m[7][i] ]] && printf '%q=%q\n' 
>> "${m[6][i]}" "${m[7][i]}"
>>         done
>>         print "Nummatches=${#m[0][@]}"
>>         return 0
>> }
>>
>> for s in 'plain' 'move' 'move_to_compound' 'move_to_nameref_compound' ; do
>>         parse_attr "$s" $' aname=avalue x=y'
>> done
>> -- snip --
>> ... in theory it should print:
>> -- snip --
>> aname=a
>> x=y
>> Nummatches=2
>> aname=a
>> x=y
>> Nummatches=2
>> aname=a
>> x=y
>> Nummatches=2
>> aname=a
>> x=y
>> Nummatches=2
>> -- snip --
>> ... but ast-ksh.2012-08-24 currently prints this:
>> -- snip --
>> aname=a
>> x=y
>> Nummatches=2
>> ' aname=a'=' aname=a'
>> ' x=y'=' x=y'
>> Nummatches=2
>> ' aname=a'=' aname=a'
>> ' x=y'=' x=y'
>> Nummatches=2
>> ' aname=a'=' aname=a'
>> ' x=y'=' x=y'
>> Nummatches=2
>> -- snip --
>
> ... this testcase still doesn't work in ast-ksh.2012-08-31 (main issue
> seems to be that "typeset -m ..." and nameref's bite each other... ;-(

It's still not working as expected in ast-ksh.2012-09-11...
... here is a modified testcase to demonstrate the problem:
-- snip --
function parse_attr
{
        typeset move_mode=$1
        typeset attrdata="$2"
        integer i

        typeset dummy="${attrdata//~(Ex-p)(?:
        [[:space:]]+
        ( # four different types of name=value syntax
                (?:([:_[:alnum:]-]+)=([^\"\'[:space:]]+?))|
                (?:([:_[:alnum:]-]+)=\"([^\"]*?)\")|
                (?:([:_[:alnum:]-]+)=\'([^\']*?)\')|
                (?:([:_[:alnum:]-]+))
        )
        )/D}"

        case ${move_mode} in
                'plain')
                        nameref m=.sh.match
                        ;;
                'move')
                        typeset -m m=.sh.match
                        ;;
                'move_to_compound')
                        compound mc
                        typeset -m mc.m=.sh.match
                        nameref m=mc.m
                        ;;
                'move_to_nameref_compound')
                        compound mc
                        nameref mcn=mc
                        typeset -m mcn.m=.sh.match
                        nameref m=mcn.m
                        ;;
                *)
                        print -u2 -f '# wrong move_mode=%q\n' "${move_mode}"
                        return 1
                        ;;
        esac
#print -v m
        for (( i=0 ; i < ${#m[0][@]} ; i++ )) ; do
                [[ -v m[2][i] && -v m[3][i] ]] && printf '%q=%q, '
"${m[2][i]}" "${m[3][i]}"
                [[ -v m[4][i] && -v m[5][i] ]] && printf '%q=%q, '
"${m[4][i]}" "${m[5][i]}"
                [[ -v m[6][i] && -v m[7][i] ]] && printf '%q=%q, '
"${m[6][i]}" "${m[7][i]}"
        done
        print "Nummatches=${#m[0][@]}"
        return 0
}

for s in 'plain' 'move' 'move_to_compound' 'move_to_nameref_compound' ; do
        parse_attr "$s" $' aname="avalue" x=\'y\' '
done
-- snip --

The output should look like this:
-- snip --
aname=avalue, x=y, Nummatches=2
aname=avalue, x=y, Nummatches=2
aname=avalue, x=y, Nummatches=2
aname=avalue, x=y, Nummatches=2
-- snip --
... but ast-ksh.2012-09-11 prints:
-- snip --
aname=avalue, x=y, Nummatches=2
aname=avalue, Nummatches=2
aname=avalue, Nummatches=2
aname=avalue, Nummatches=2
-- snip --

The problem seems to be the [i] in this code block:
-- snip --
[[ -v m[2][i] && -v m[3][i] ]] && printf '%q=%q, ' "${m[2][i]}" "${m[3][i]}"
[[ -v m[4][i] && -v m[5][i] ]] && printf '%q=%q, ' "${m[4][i]}" "${m[5][i]}"
[[ -v m[6][i] && -v m[7][i] ]] && printf '%q=%q, ' "${m[6][i]}" "${m[7][i]}"
-- snip --
... if I replace [i] with [$i] i get the correct results...

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) roland.ma...@nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
_______________________________________________
ast-developers mailing list
ast-developers@research.att.com
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to