cfp_match(3) manual page
Table of Contents
cfp_match - find best match of name in list
#include <cfht/cfht.h>int cfp_match(name, addrs)char *name;char **addrs;
libcfht.a
Name
is the input string to be matched. If name begins with ’-’, then the ’-’ will
be skipped. Addrs is an array of null terminated strings. Note that the last
entry is a zero length string.
The return value is the index
into addrs of the best match. If name contains only a ’-’, then the index
of the zero length string will be returned. However, if an error occurs,
cfp_match will return FAIL.
Possible errors for cfp_match:
- [ENOENT]
- Entry
not found.
- [EIO]
- A collision occurred do to common leading substrings.
Addrs
is generally initialized statically as follows:
char *addrs[] = {
"cat",
"food",
"fever",
""
};
With the above array the following table shows expected results:
name return errno
"-cat" 0 unchanged
"c" 0 unchanged
"fo" 1 unchanged
"f" -1 EIO
"dog" -1 ENOENT
"-" 3 unchanged
Typical usage would look as follows:
if ((index = cfp_match(name, addrs)) == FAIL)
{
char c[2];
/* look for a series of single letter matches */
c[1] = 0;
for (i = strlen(name) - 1; i >= 0; i--)
{
c[0] = name[i];
if ((index = cfp_match(c, addrs)) == FAIL)
... /* error out */
... /* process single letter match */
}
}
else
... /* process full name match */
cfp(4)
.
Table of Contents