/* SccsId = "@(#)diction.cls 4.2 (TU-Delft) 06/11/91" */
/**********************************************************

Name/Version      : sls_mkdb/4.2

Language          : C
Operating system  : UNIX SYSTEM V
Host machine      : HP9000

Author(s)         : A.C. de Graaf
Creation date     : 10-Jul-1986
Modified by       : S. de Graaf
Modification date : 10-Jul-1986


        Delft University of Technology
        Department of Electrical Engineering
        Network Theory Section
        Mekelweg 4 - P.O.Box 5031
        2600 GA DELFT
        The Netherlands

        Phone : 015 - 786234

        COPYRIGHT (C) 1986 , All rights reserved
**********************************************************/
static int counter = 0;

void dictionary.new() {
        char *tempval;
        char *template;
	char *mktemp ();

	template = new char [24];

	sprintf (template, "/usr/tmp/x%dXXXXXX", counter);
        counter++;

        tempval = mktemp (template);
	db = dbOpen (tempval);
#ifdef DMEM
    dict_nbyte += sizeof(class dictionary);
    dict_maxnbyte = dict_nbyte > dict_maxnbyte ? dict_nbyte:dict_maxnbyte;
#endif
}

void dictionary.delete() {
#ifdef DMEM
    dict_nbyte -= sizeof(class dictionary);
#endif
    if(db)
	dbClose(&db);
}

void dictionary.store(char *item_key, char *item_data) {
    key.dptr = item_key;
    key.dsize= strlen(item_key) + 1;
    data.dptr = (char *) &item_data;
    data.dsize= sizeof(int);
    dbstore(db, key, data);
}

char *dictionary.fetch(char *item_key) {
    int *n;
    datum dbfetch();

    key.dptr = item_key;
    key.dsize= strlen(item_key) + 1;
    data = dbfetch(db, key);
    if(data.dptr == NULL)
	return(NULL);
    bmove(&n, data.dptr, data.dsize);
    return (char *) n;
}

void dictionary.print() {
	datum dbfetch();
	int *n;

	for(key = firstkey(db); key.dptr != NULL; key = nextkey(db, key))
	{
	    data = dbfetch(db, key);
	    bmove(&n, data.dptr, data.dsize);
	    fprintf(stderr,"key: %s, data: %x\n",key.dptr, n);
	}
}
