/* ftree.h   by Michael Thorpe   2000-07-21 */

#ifndef FTREE_VALUETYPE
#define FTREE_VALUETYPE int
#endif

/***********************************************************************/
/* If you set TREE_WILDCARD to '\0', wildcard support will be disabled */
/***********************************************************************/
#ifndef FTREE_WILDCARD
#define FTREE_WILDCARD '*'
#endif

typedef struct ftree ftree;

/***************************************************************************/
/* ftree_open() opens a file ftree (open(2) flags), or returns 0 for error */
/***************************************************************************/
ftree *ftree_open(const char *file,int flags);

/********************************************************************/
/* ftree_close() closes an open file ftree, and returns !0 on error */
/********************************************************************/
int ftree_close(ftree *ftree);

/******************************************************************************/
/* ftree_del() removes a string from a ftree and returns its value (0==error) */
/******************************************************************************/
FTREE_VALUETYPE ftree_del(ftree *ftree,const char *s);

/***********************************************/
/* ftree_getsize() returns the size of a ftree */
/***********************************************/
size_t ftree_getsize(ftree *ftree);

/********************************************************/
/* ftree_add() adds a string to a ftree, and assigning  */
/* it a value if appropriate; returns non-zero on error */
/********************************************************/
int ftree_add(ftree *ftree,const char *s,FTREE_VALUETYPE value);

/*********************************************************/
/* ftree_match() returns the value of a given string (1  */
/* if FTREE_VALUETYPE is not defined), or 0 if not found */
/*********************************************************/
FTREE_VALUETYPE ftree_match(ftree *ftree,const char *s);

/***********************************************************/
/* ftree_change() changes the value of a given string, and */
/* returns the old value of the string (0 if not found)    */
/***********************************************************/
FTREE_VALUETYPE ftree_change(ftree *ftree,const char *s,FTREE_VALUETYPE newvalue);

/*************************************************************/
/* ftree_dump() calls func() for each node in the ftree with */
/* its string, depth, and value (0 for non-endnodes). If you */
/* want to print whole strings, then for non-zero values     */
/* you'll need to print the last of each lower depth first   */
/*************************************************************/
int ftree_dump(ftree *ftree,int (*func)(const char *,int,FTREE_VALUETYPE));

/***************************************************/
/* ftree_dumpfull() calls func() for each string   */
/* in the ftree, which basically takes care of the */
/* usual work associated with ftree_dump for you   */
/***************************************************/
int ftree_dumpfull(ftree *ftree,int (*func)(const char *,FTREE_VALUETYPE));

/**********************************************************************/
/* ftree_{read|write}[un]lock allow you to manually lock the tree for */
/* extended periods of time; usually a good idea if you have a lot of */
/* adds or matches to do in a short period of time and you don't mind */
/* making other people block (if appropriate) during that time.       */
/**********************************************************************/
int ftree_readlock(ftree *ftree);
int ftree_writelock(ftree *ftree);
int ftree_readunlock(ftree *ftree);
int ftree_writeunlock(ftree *ftree);

