confuse-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFG_XXX_LIST_CB() [Was: Re: [Confuse-devel] libconfuse help (several


From: Martin Hedenfalk
Subject: Re: CFG_XXX_LIST_CB() [Was: Re: [Confuse-devel] libconfuse help (several questions)]
Date: Tue, 29 Apr 2003 10:31:01 +0200

On Mon, 28 Apr 2003 23:53:45 -0300
"Ademar de Souza Reis Jr." <address@hidden> wrote:

> On Mon, Apr 28, 2003 at 09:47:19AM +0200, Martin Hedenfalk wrote:
> > > 2. Is there a callback for values different than int? The
> > > docs/example mention the callback to set int values (CFG_INT_CB),
> > > but what I need is a callback to parse string values.
> > > Ex.: I have statements like:
> > > 
> > > foobar {
> > >   fake_mac_address = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
> > >   fake_dest_ip_addr = "192.168.1.200"
> > > }
> > > 
> > > And I would like to set a callback to check if the values have
> > > valid syntax and are inside the valid range.
> > 
> > Yes, there and CFG_STR_CB, and CFG_XXX_CB for all other supported
> > types. They work in the same way as the int example.
> 
> Ok, I don't know why I haven't found them before :)
> 
> But I have a question regarding "CFG_INT_LIST_CB": Do I have to mess
> with all internal libconfuse structures to fill "void *result"? In
> STR_CB and INT_CB it's easy, but I have no idea about what to do when
> parsing a list.

Look at the cfgtest.c example. the same value parsing callback
(cb_verify_ask) is used for both the CFG_INT_CB and CFG_INT_LIST_CB
options. In the LIST case, the callback is called for each value found
in the list. The library takes care of allocating and storing the value
in the list, the "void *result" just points to different memory each
time a value is found. All your callback function needs to do is to
parse each individual value.

In your MAC address case, you probably also wants to make sure the user
doesn't enter more than 6 values. You can call cfg_size() function for
this (or just look at the opt->nvalues variable), from within the
callback function. You can't check that there are less than 6 values
from within the callback, you'll have to do that when the parsing is
completed.

HTH / martin

> I like a list because it really easies my work when parsing an
> ethernet mac address, but if I have to parse it manually before it
> turns into a list, then there's no point in using a list... What am I
> missing here? :)
> 
> Thanks.
> 
> -- 
> Ademar de Souza Reis Jr. <address@hidden>
> http://www.ademar.org
> 
> ^[:wq!
> 

-- 
Martin Hedenfalk <address@hidden>
Systemutvecklare - Esplanad Business Solutions AB




reply via email to

[Prev in Thread] Current Thread [Next in Thread]