[netcf-devel] Replace aug_submatch?

David Lutterkort lutter at redhat.com
Wed Jul 22 16:28:37 UTC 2009


On Mon, 2009-07-20 at 14:52 +0200, Jonas Eriksson wrote:
> while bringing the suse-driver up to speed, I noted this very
> common pattern with the path variable only used once:
> 
>   r = xasprintf(&pathx, {format}, ..);
>   ERR_COND_BAIL(r < 0, ncf, ENOMEM);
> 
>   nint = aug_get(aug, pathx, {&var or NULL});
>   ERR_COND_BAIL(nint < 0, ncf, EOTHER);
> 
> ..or with other names on the variables, and/or aug_match instead
> of aug_get. This has probably been noticed by David earlier, and
> has lead to the creation of the aug_submatch function to simplify
> the case of path=path1/path2.

Yes, this is a really good idea.

> The option still exist
> to keep aug_submatch, the simplest way would be through a macro
> like:
>   aug_submatch(ncf, p1, p2, m) aug_printfmatch(ncf, m, "%s/%s", p1, p2);
> 
> Although I would recommend to move to the aug_printf-approach
> even for the current use of aug_submatch,

Yes, that's what I would prefer, too.

> The only negative thing I could think about in this approach is
> the signature of aug_printfmatch, which does not adhere to the
> existing aug_*-functions as these place the path variable first
> in all cases.
> 
> Other opinions? I am open to an addition of aug_printfset (or
> aug_pfset), should the need be deemed large enough.

I would only do that if we have a similar sprawl as we have with
xasprintf/aug_{get,match}

As for names, how about aug_fmt_match, aug_fmt_set etc. ?

David




More information about the netcf-devel mailing list