1 2/*-------------------------------------------------------------------------*/ 3/** 4 @file dictionary.h 5 @author N. Devillard 6 @date Sep 2007 7 @brief Implements a dictionary for string variables. 8 9 This module implements a simple dictionary object, i.e. a list 10 of string/string associations. This object is useful to store e.g. 11 informations retrieved from a configuration file (ini files). 12*/ 13/*--------------------------------------------------------------------------*/ 14 15/* 16 $Author: ndevilla $ 17 $Date: 2007-11-23 21:37:00 $ 18*/ 19 20#ifndef _DICTIONARY_H_ 21#define _DICTIONARY_H_ 22 23/*--------------------------------------------------------------------------- 24 Includes 25 ---------------------------------------------------------------------------*/ 26 27#include <stdio.h> 28#include <stdlib.h> 29#include <string.h> 30#include <unistd.h> 31 32/*--------------------------------------------------------------------------- 33 New types 34 ---------------------------------------------------------------------------*/ 35 36 37/*-------------------------------------------------------------------------*/ 38/** 39 @brief Dictionary object 40 41 This object contains a list of string/string associations. Each 42 association is identified by a unique string key. Looking up values 43 in the dictionary is speeded up by the use of a (hopefully collision-free) 44 hash function. 45 */ 46/*-------------------------------------------------------------------------*/ 47typedef struct _dictionary_ { 48 int n ; /** Number of entries in dictionary */ 49 int size ; /** Storage size */ 50 char ** val ; /** List of string values */ 51 char ** key ; /** List of string keys */ 52 unsigned * hash ; /** List of hash values for keys */ 53} dictionary ; 54 55 56/*--------------------------------------------------------------------------- 57 Function prototypes 58 ---------------------------------------------------------------------------*/ 59 60unsigned atalkdict_hash (char * key); 61dictionary *atalkdict_new (int size); 62void atalkdict_del (dictionary * vd); 63const char *atalkdict_get (const dictionary * d, const char *section, const char * key, const char * def); 64int atalkdict_set (dictionary * vd, char *section, char * key, char * val); 65void atalkdict_unset (dictionary * d, char *section, char * key); 66void atalkdict_dump (dictionary * d, FILE * out); 67 68#endif 69