On Tue, Jul 17, 2012 at 4:13 PM, David Korn <[email protected]> wrote:
> cc: [email protected]
> Subject: Re: [ast-developers] |nv_open()| which automagically handles nameref 
> ?
> --------
>> Is there an easy C code example somewhere which shows how to read
>> compound variable members (or members in a typeded variable) in an
>> array of compound variables (indexed or associative) ... regardless
>> whether the name given (e.g. $ compound -a c ; ... ; mycmd c[4] # or $
>> compound -a c ; ... ; nameref x=c[4] ; mycmd x # and the command
>> should read variable "hello") is a nameref or not ?
>>
>> Right now we use something like this to access the compound variable
>> member variables:
>> -- snip --
>> [snip]
>> Namval_t *nv_open_fmt(Dt_t *dict, int flags, const char *namefmt, ...)
>> {
>>       char    varnamebuff[PATH_MAX];
>>       va_list ap;
>>
>>       va_start(ap, namefmt);
>>       vsnprintf(varnamebuff, sizeof(varnamebuff), namefmt, ap);
>>       va_end(ap);
>>
>>       return nv_open(varnamebuff, dict, flags);
>> }
>>
>> [snip]
>>
>> np = nv_open_fmt(shp->var_tree, NV_NOFAIL|NV_NOADD, "%s[%s].fd",
>> varname, subname);
>> ...
>> -- snip --
>>
>> This seems to work prefectly for indexed and associative arrays but
>> fails if the array is made out of user-defined types or if the array
>> is accessed through a nameref... any idea why this happens ?
>
> I think the problem is that you need NV_VARNAME in flags.  Otherwise
> it looks for the string in the give dict, shp->var_tree.

Thanks... that solved the problem... :-)

----

Bye,
Roland

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

Reply via email to