Subject: Re: [ast-users] Seeking C code example for "${!myli...@]}"
--------


> Are there any examples which show how I can use libshell to access all
> members of an indexed or associative array? For example I'd like to
> create a shell via sh_init, use sh_trap to run shell code and then use
> C code to get the index names of all elements in array 'mylist', i.e.
> a C version of "${!myli...@]}"
> Does anyone have a related code example?
> 
> Wendy
> 

===============cut here========================
#include        <nval.h>

int outname(Sfio_t *out, Namval_t* np)
{
        int i, n=0, assoc=(nv_aindex(np)<0);
        nv_putsub(np, (char*)0, ARRAY_SCAN);
        do
        {
                if(assoc)
                        sfputr(out, nv_getsub(np),'\n');
                else
                        sfprintf(out, %d\n",i);
                n++;
        }
        while(nv_nextsub(np));
        return(n);
}
===============cut here========================

David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to