[netcf-devel] Replace aug_submatch?

Jonas Eriksson jonas.j.eriksson at ericsson.com
Mon Jul 20 12:52:09 UTC 2009


Hi,

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.

I would however suggest a more general approach, in the lines of:
  r = aug_printf{get,match}(ncf, {&var or NULL}, {format}, ..);
(or with a less bloated name, like for example aug_pf{get,match})

This means that this:
  nmatches = aug_submatch(ncf, intf[i], "*", &matches);
  ERR_COND_BAIL(nmatches < 0, ncf, EOTHER);

Will be replaced by this:
  nmatches = aug_printfmatch(ncf, &matches, "%s/%s", intf[i], "*");
  ERR_BAIL(ncf);
..which is slightly more code, but easier to follow without
looking up what the function realy does. 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, as aug_submatch is used
4 times currently, and aug_printfmatch could be used in about 5
cases (excluding the uses of aug_submatch today).

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.

Regards,
Jonas

--
Jonas Eriksson
Consultant at AS/EAB/FLJ/IL
Combitech AB
Älvsjö, Sweden


More information about the netcf-devel mailing list