IDF(3)

NAME
init_idf, str2idf, findidf - a namelist module

SYNOPSIS

void init_idf()

struct idf *str2idf(tag, cpy)
char *tag;

struct idf *findidf(tag)
char *tag;

DESCRIPTION
This is a generic namelist module. It provides a fast mechanism for associating information with identifiers. To get an instantiation, the user must provide two files idf.h and idf.c. idf.h could contain the following:

    #define IDF_TYPE struct id_info
    #define IDF_HSIZE 8
    #include <idf_pkg.spec>

and idf.c could contain:

    #include "id_info.h"          /* contains definition for struct id_info */
    #include "idf.h"
    #include <idf_pkg.body>

IDF_TYPE denotes a type containing all information associated with an identifier. If it is not defined, the instantiation will not contain any user-defined information.

IDF_HSIZE denotes the number of significant characters for the hashing function. It's default value is 64. Notice that this value does not denote the number of significant characters, but only the number of characters that are used for hashing.

The user can also define IDF_NAME, to give a name to the selector in the idf-structure. It's default value is id_user.

The routine init_idf initializes the namelist.

The function str2idf searches for the string tag in the namelist, and creates an entry for it if necessary. A pointer to this entry is returned. If cpy is non-zero, a copy of the tag is made, otherwise the tag itself is used. The entry has the following structure, defined in idf_pkg.spec:

struct idf	{
	struct idf *next;             /* links idf-structures together */
	char *id_text;/* string representing the name */
#ifdef IDF_TYPE
	IDF_TYPE IDF_NAME;/* user defined type */
#endif
};

The field id_text will point to a copy of tag, or to the tag itself, depending on cpy. The field next is used for internal information and must not be changed by the user of this module. The user-defined part of the structure is initialized with zeros.

The function findidf searches for the string tag in the namelist, but returns 0 when it is not present.

MODULES USED
alloc(3)

FILES
~em/modules/pkg/idf_pkg.spec
~em/modules/pkg/idf_pkg.body