[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    cfp_match(3) manual page Table of Contents

Name

cfp_match - find best match of name in list

Synopsis


#include <cfht/cfht.h>int cfp_match(name, addrs)char *name;char **addrs;
libcfht.a

Description

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.

Return Value

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.

Errors

Possible errors for cfp_match:
[ENOENT]
Entry not found.
[EIO]
A collision occurred do to common leading substrings.

Example

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 */

See Also

cfp(4) .

Warnings


Table of Contents