home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-01-19 | 56.4 KB | 1,996 lines |
- diff -cb orig/bucket.c gdbm/bucket.c
- *** orig/bucket.c Sun Jan 19 14:44:14 1992
- --- gdbm/bucket.c Sun Jan 19 14:43:18 1992
- ***************
- *** 59,65 ****
- is already in memory. If not, a bucket may be tossed to read the new
- bucket. In any case, the requested bucket is make the "current" bucket
- and dbf->bucket points to the correct bucket. */
- ! int
- _gdbm_get_bucket (dbf, dir_index)
- gdbm_file_info *dbf;
- long dir_index;
- --- 59,65 ----
- is already in memory. If not, a bucket may be tossed to read the new
- bucket. In any case, the requested bucket is make the "current" bucket
- and dbf->bucket points to the correct bucket. */
- ! void
- _gdbm_get_bucket (dbf, dir_index)
- gdbm_file_info *dbf;
- long dir_index;
- ***************
- *** 114,120 ****
- void
- _gdbm_split_bucket (dbf, next_insert)
- gdbm_file_info *dbf;
- ! int next_insert;
- {
- hash_bucket *bucket[2]; /* Pointers to the new buckets. */
-
- --- 114,120 ----
- void
- _gdbm_split_bucket (dbf, next_insert)
- gdbm_file_info *dbf;
- ! long next_insert;
- {
- hash_bucket *bucket[2]; /* Pointers to the new buckets. */
-
- ***************
- *** 184,190 ****
- dir_adr = _gdbm_alloc (dbf, dir_size);
- new_dir = (long *) malloc (dir_size);
- if (new_dir == NULL) _gdbm_fatal (dbf, "malloc error");
- ! for (index = 0; index < dbf->header->dir_size/sizeof (int); index++)
- {
- new_dir[2*index] = dbf->dir[index];
- new_dir[2*index+1] = dbf->dir[index];
- --- 184,190 ----
- dir_adr = _gdbm_alloc (dbf, dir_size);
- new_dir = (long *) malloc (dir_size);
- if (new_dir == NULL) _gdbm_fatal (dbf, "malloc error");
- ! for (index = 0; index < dbf->header->dir_size/sizeof (long); index++)
- {
- new_dir[2*index] = dbf->dir[index];
- new_dir[2*index+1] = dbf->dir[index];
- ***************
- *** 209,216 ****
- for (index = 0; index < dbf->header->bucket_elems; index++)
- {
- old_el = & (dbf->bucket->h_table[index]);
- ! select = (old_el->hash_value >> (31-new_bits)) & 1;
- ! elem_loc = old_el->hash_value % dbf->header->bucket_elems;
- while (bucket[select]->h_table[elem_loc].hash_value != -1)
- elem_loc = (elem_loc + 1) % dbf->header->bucket_elems;
- bucket[select]->h_table[elem_loc] = *old_el;
- --- 209,216 ----
- for (index = 0; index < dbf->header->bucket_elems; index++)
- {
- old_el = & (dbf->bucket->h_table[index]);
- ! select = (int) (old_el->hash_value >> (31-new_bits)) & 1;
- ! elem_loc = (int) (old_el->hash_value % dbf->header->bucket_elems);
- while (bucket[select]->h_table[elem_loc].hash_value != -1)
- elem_loc = (elem_loc + 1) % dbf->header->bucket_elems;
- bucket[select]->h_table[elem_loc] = *old_el;
- ***************
- *** 260,266 ****
- dbf->second_changed = TRUE;
-
- /* Update the cache! */
- ! dbf->bucket_dir = next_insert >> (31-dbf->header->dir_bits);
-
- /* Invalidate old cache entry. */
- old_bucket.av_adr = dbf->cache_entry->ca_adr;
- --- 260,266 ----
- dbf->second_changed = TRUE;
-
- /* Update the cache! */
- ! dbf->bucket_dir = (int) (next_insert >> (31-dbf->header->dir_bits));
-
- /* Invalidate old cache entry. */
- old_bucket.av_adr = dbf->cache_entry->ca_adr;
- ***************
- *** 296,302 ****
-
- /* The only place where a bucket is written. CA_ENTRY is the
- cache entry containing the bucket to be written. */
- !
- _gdbm_write_bucket (dbf, ca_entry)
- gdbm_file_info *dbf;
- cache_elem *ca_entry;
- --- 296,302 ----
-
- /* The only place where a bucket is written. CA_ENTRY is the
- cache entry containing the bucket to be written. */
- ! void
- _gdbm_write_bucket (dbf, ca_entry)
- gdbm_file_info *dbf;
- cache_elem *ca_entry;
- diff -cb orig/dbm.h gdbm/dbm.h
- *** orig/dbm.h Sun Jan 19 14:44:14 1992
- --- gdbm/dbm.h Thu May 23 19:26:30 1991
- ***************
- *** 34,55 ****
- } datum;
-
-
- - /* These are the routines in dbm. */
-
- ! extern int dbminit ();
-
- extern datum fetch ();
- -
- extern int store ();
- -
- extern int delete ();
- -
- - extern int delete ();
- -
- extern datum firstkey ();
- -
- extern datum nextkey ();
- !
- ! /* To make some versions work we need the following define. */
- !
- ! #define dbmclose()
- --- 34,56 ----
- } datum;
-
-
-
- ! /* To make some versions work we need the following define. */
-
- + #define dbmclose()
- + /* These are the routines in dbm. */
- + #ifdef __STDC__
- + extern int dbminit (char *file);
- + extern datum fetch(datum key);
- + extern int store (datum key, datum content);
- + extern int delete (datum key);
- + extern datum firstkey (void);
- + extern datum nextkey (datum key);
- + #else /* not __STDC__ */
- + extern int dbminit ();
- extern datum fetch ();
- extern int store ();
- extern int delete ();
- extern datum firstkey ();
- extern datum nextkey ();
- ! #endif /* not __STDC__ */
- diff -cb orig/dbminit.c gdbm/dbminit.c
- *** orig/dbminit.c Sun Jan 19 14:44:14 1992
- --- gdbm/dbminit.c Sun Jan 19 14:43:18 1992
- ***************
- *** 87,93 ****
- --- 87,97 ----
- if (stat (dir_file, &dir_stat) == 0)
- {
- if (dir_stat.st_size == 0)
- + #ifdef OS2
- + if ( 0 /* open (dir_file, O_RDWR|O_TRUNC, S_IREAD|S_IWRITE) < 0 */ )
- + #else /* not OS2 */
- if (unlink (dir_file) != 0 || link (pag_file, dir_file) != 0)
- + #endif /* not OS2 */
- {
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
- gdbm_close (_gdbm_file);
- ***************
- *** 98,104 ****
- --- 102,112 ----
- {
- /* Since we can't stat it, we assume it is not there and try
- to link the dir_file to the pag_file. */
- + #ifdef OS2
- + if ( 0 /* open (dir_file, O_RDWR|O_CREAT, S_IREAD|S_IWRITE) < 0 */ )
- + #else /* not OS2 */
- if (link (pag_file, dir_file) != 0)
- + #endif /* not OS2 */
- {
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
- gdbm_close (_gdbm_file);
- diff -cb orig/dbmopen.c gdbm/dbmopen.c
- *** orig/dbmopen.c Sun Jan 19 14:44:16 1992
- --- gdbm/dbmopen.c Sun Jan 19 14:43:18 1992
- ***************
- *** 105,111 ****
- --- 105,115 ----
- if (stat (dir_file, &dir_stat) == 0)
- {
- if (dir_stat.st_size == 0)
- + #ifdef OS2
- + if ( 0 /* open (dir_file, O_RDWR|O_TRUNC, S_IREAD|S_IWRITE) < 0 */ )
- + #else /* not OS2 */
- if (unlink (dir_file) != 0 || link (pag_file, dir_file) != 0)
- + #endif /* not OS2 */
- {
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
- gdbm_close (temp_dbf);
- ***************
- *** 116,122 ****
- --- 120,130 ----
- {
- /* Since we can't stat it, we assume it is not there and try
- to link the dir_file to the pag_file. */
- + #ifdef OS2
- + if ( 0 /* open (dir_file, O_RDWR|O_CREAT, S_IREAD|S_IWRITE) < 0 */ )
- + #else /* not OS2 */
- if (link (pag_file, dir_file) != 0)
- + #endif /* not OS2 */
- {
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
- gdbm_close (temp_dbf);
- diff -cb orig/extern.h gdbm/extern.h
- *** orig/extern.h Sun Jan 19 14:44:18 1992
- --- gdbm/extern.h Thu May 23 19:26:52 1991
- ***************
- *** 37,53 ****
-
-
- /* External routines used. */
- !
- extern gdbm_file_info *gdbm_open ();
- -
- extern datum gdbm_fetch ();
- -
- extern datum gdbm_firstkey ();
- -
- extern datum gdbm_nextkey ();
- -
- extern int gdbm_delete ();
- -
- extern int gdbm_store ();
-
- extern void gdbm_close ();
- --- 37,56 ----
-
-
- /* External routines used. */
- ! #ifdef __STDC__
- ! extern gdbm_file_info *gdbm_open (char *file, int block_size, int read_write, int mode, void (*fatal_func)());
- ! extern datum gdbm_fetch (gdbm_file_info *dbf, datum key);
- ! extern datum gdbm_firstkey (gdbm_file_info *dbf);
- ! extern datum gdbm_nextkey (gdbm_file_info *dbf, datum key);
- ! extern int gdbm_delete (gdbm_file_info *dbf, datum key);
- ! extern int gdbm_reorganize (gdbm_file_info *dbf);
- ! #else /* not __STDC__ */
- extern gdbm_file_info *gdbm_open ();
- extern datum gdbm_fetch ();
- extern datum gdbm_firstkey ();
- extern datum gdbm_nextkey ();
- extern int gdbm_delete ();
- extern int gdbm_store ();
- + #endif /* not __STDC__ */
-
- extern void gdbm_close ();
- diff -cb orig/falloc.c gdbm/falloc.c
- *** orig/falloc.c Sun Jan 19 14:44:18 1992
- --- gdbm/falloc.c Sun Jan 19 14:43:18 1992
- ***************
- *** 33,43 ****
- --- 33,51 ----
- /* The forward definitions for this file. See the functions for
- the definition of the function. */
-
- + #ifdef __STDC__
- + static avail_elem get_elem (int size, avail_elem *av_table, int *av_count);
- + static avail_elem get_block (int size, gdbm_file_info *dbf);
- + static void push_avail_block (gdbm_file_info *dbf);
- + static void pop_avail_block (gdbm_file_info *dbf);
- + static void adjust_bucket_avail (gdbm_file_info *dbf);
- + #else /* not __STDC__ */
- static avail_elem get_elem ();
- static avail_elem get_block ();
- static push_avail_block ();
- static pop_avail_block ();
- static adjust_bucket_avail ();
- + #endif /* not __STDC__ */
-
- /* Allocate space in the file DBF for a block NUM_BYTES in length. Return
- the file address of the start of the block.
- ***************
- *** 100,105 ****
- --- 108,114 ----
- avail structure. The value TRUE is returned if there were errors. If no
- errors occured, the value FALSE is returned. */
-
- + int
- _gdbm_free (dbf, file_adr, num_bytes)
- gdbm_file_info *dbf;
- long file_adr;
- ***************
- *** 109,115 ****
-
- /* Is it too small to worry about? */
- if (num_bytes <= IGNORE_SIZE)
- ! return;
-
- /* Initialize the avail element. */
- temp.av_size = num_bytes;
- --- 118,124 ----
-
- /* Is it too small to worry about? */
- if (num_bytes <= IGNORE_SIZE)
- ! return TRUE; /* is that correct (was "return;")? -tho */
-
- /* Initialize the avail element. */
- temp.av_size = num_bytes;
- ***************
- *** 148,154 ****
- adjust_bucket_avail (dbf);
-
- /* All work is done. */
- ! return;
- }
-
-
- --- 157,163 ----
- adjust_bucket_avail (dbf);
-
- /* All work is done. */
- ! return TRUE; /* is that correct (was "return;")? -tho */
- }
-
-
- ***************
- *** 159,165 ****
- /* Gets the avail block at the top of the stack and loads it into the
- active avail block. It does a "free" for itself! */
-
- ! static
- pop_avail_block (dbf)
- gdbm_file_info *dbf;
- {
- --- 168,174 ----
- /* Gets the avail block at the top of the stack and loads it into the
- active avail block. It does a "free" for itself! */
-
- ! static void
- pop_avail_block (dbf)
- gdbm_file_info *dbf;
- {
- ***************
- *** 189,201 ****
-
- /* Splits the header avail block and pushes half onto the avail stack. */
-
- ! static
- push_avail_block (dbf)
- gdbm_file_info *dbf;
- {
- int num_bytes;
- int av_size;
- ! int av_adr;
- int index;
- long file_pos;
- avail_block *temp;
- --- 198,210 ----
-
- /* Splits the header avail block and pushes half onto the avail stack. */
-
- ! static void
- push_avail_block (dbf)
- gdbm_file_info *dbf;
- {
- int num_bytes;
- int av_size;
- ! long av_adr;
- int index;
- long file_pos;
- avail_block *temp;
- ***************
- *** 216,221 ****
- --- 225,237 ----
-
- /* Split the header block. */
- temp = (avail_block *) alloca (av_size);
- + #ifdef OS2
- + if (temp == (avail_block *) 0)
- + {
- + fprintf (stderr, "Error: alloca() failed in gdbm (%s).\n", __FILE__);
- + exit (-2);
- + }
- + #endif /* OS2 */
- /* Set the size to be correct AFTER the pop_avail_block. */
- temp->size = dbf->header->avail.size;
- temp->count = 0;
- ***************
- *** 293,298 ****
- --- 309,315 ----
- /* This routine inserts a single NEW_EL into the AV_TABLE block in
- sorted order. This routine does no I/O. */
-
- + int
- _gdbm_put_av_elem (new_el, av_table, av_count)
- avail_elem new_el;
- avail_elem av_table[];
- ***************
- *** 366,372 ****
-
- /* When the header already needs writing, we can make sure the current
- bucket has its avail block as close to 1/2 full as possible. */
- ! static
- adjust_bucket_avail (dbf)
- gdbm_file_info *dbf;
- {
- --- 383,389 ----
-
- /* When the header already needs writing, we can make sure the current
- bucket has its avail block as close to 1/2 full as possible. */
- ! static void
- adjust_bucket_avail (dbf)
- gdbm_file_info *dbf;
- {
- diff -cb orig/findkey.c gdbm/findkey.c
- *** orig/findkey.c Sun Jan 19 14:44:20 1992
- --- gdbm/findkey.c Sun Jan 19 14:43:18 1992
- ***************
- *** 100,106 ****
-
- /* Compute hash value and load proper bucket. */
- *new_hash_val = _gdbm_hash (key);
- ! _gdbm_get_bucket (dbf, *new_hash_val>> (31-dbf->header->dir_bits));
-
- /* Is the element the last one found for this bucket? */
- if (*new_hash_val == dbf->cache_entry->ca_data.hash_val
- --- 100,106 ----
-
- /* Compute hash value and load proper bucket. */
- *new_hash_val = _gdbm_hash (key);
- ! _gdbm_get_bucket (dbf, (int) (*new_hash_val>> (31-dbf->header->dir_bits)));
-
- /* Is the element the last one found for this bucket? */
- if (*new_hash_val == dbf->cache_entry->ca_data.hash_val
- ***************
- *** 114,120 ****
- }
-
- /* It is not the cached value, search for element in the bucket. */
- ! elem_loc = *new_hash_val % dbf->header->bucket_elems;
- home_loc = elem_loc;
- bucket_hash_val = dbf->bucket->h_table[elem_loc].hash_value;
- while (bucket_hash_val != -1)
- --- 114,120 ----
- }
-
- /* It is not the cached value, search for element in the bucket. */
- ! elem_loc = (int) (*new_hash_val % dbf->header->bucket_elems);
- home_loc = elem_loc;
- bucket_hash_val = dbf->bucket->h_table[elem_loc].hash_value;
- while (bucket_hash_val != -1)
- diff -cb orig/gdbm.proto gdbm/gdbm.proto
- *** orig/gdbm.proto Sun Jan 19 14:44:20 1992
- --- gdbm/gdbm.proto Thu May 23 21:57:34 1991
- ***************
- *** 53,72 ****
-
- /* These are the routines! */
-
- extern GDBM_FILE gdbm_open ();
- -
- extern void gdbm_close ();
- -
- extern datum gdbm_fetch ();
- -
- extern int gdbm_store ();
- -
- extern int gdbm_delete ();
- -
- extern datum gdbm_firstkey ();
- -
- extern datum gdbm_nextkey ();
- -
- extern int gdbm_reorganize ();
- !
- !
- --- 53,74 ----
-
- /* These are the routines! */
-
- + #ifdef __STDC__
- + extern GDBM_FILE gdbm_open (char *, int, int, int, void (*) ());
- + extern void gdbm_close (gdbm_file_info *);
- + extern datum gdbm_fetch (gdbm_file_info *, datum);
- + extern int gdbm_store (gdbm_file_info *, datum, datum, int);
- + extern int gdbm_delete (gdbm_file_info *, datum);
- + extern datum gdbm_firstkey (gdbm_file_info *);
- + extern datum gdbm_nextkey (gdbm_file_info *, datum);
- + extern int gdbm_reorganize (gdbm_file_info *);
- + #else
- extern GDBM_FILE gdbm_open ();
- extern void gdbm_close ();
- extern datum gdbm_fetch ();
- extern int gdbm_store ();
- extern int gdbm_delete ();
- extern datum gdbm_firstkey ();
- extern datum gdbm_nextkey ();
- extern int gdbm_reorganize ();
- ! #endif
- diff -cb orig/gdbmdefs.h gdbm/gdbmdefs.h
- *** orig/gdbmdefs.h Sun Jan 19 14:44:22 1992
- --- gdbm/gdbmdefs.h Sun Jan 19 14:37:08 1992
- ***************
- *** 26,36 ****
- --- 26,43 ----
- phone: (206) 676-3035
- *************************************************************************/
-
- + #ifdef __STDC__
- + #include <stdio.h>
- + #include <stdlib.h>
- + #include <string.h>
- + #endif /*not __STDC__ */
-
- /* Include the standard include files needed for gdbm. */
- #include <stdio.h>
- #include <sys/types.h>
- + #ifndef OS2
- #include <sys/file.h>
- + #endif
- #include <sys/stat.h>
- #include "gdbmconst.h"
- #include "systems.h"
- ***************
- *** 198,200 ****
- --- 205,247 ----
- } gdbm_file_info;
-
-
- + #ifdef __STDC__
- + extern void gdbm_close (gdbm_file_info *dbf);
- + extern int gdbm_delete (gdbm_file_info *dbf, datum key);
- + extern datum gdbm_fetch (gdbm_file_info *dbf, datum key);
- + extern gdbm_file_info *gdbm_open (char *file, int block_size, int read_write, int mode, void (*fatal_func)());
- + extern int gdbm_reorganize (gdbm_file_info *dbf);
- + extern datum gdbm_firstkey (gdbm_file_info *dbf);
- + extern datum gdbm_nextkey (gdbm_file_info *dbf, datum key);
- + extern int gdbm_store (gdbm_file_info *dbf, datum key, datum content, int flags);
- +
- + extern void _gdbm_new_bucket (gdbm_file_info *dbf, hash_bucket *bucket, int bits);
- + extern void _gdbm_get_bucket (gdbm_file_info *dbf, long dir_index);
- + extern void _gdbm_split_bucket (gdbm_file_info *dbf, long next_insert);
- + extern void _gdbm_write_bucket (gdbm_file_info *dbf, cache_elem *ca_entry);
- + extern long _gdbm_alloc (gdbm_file_info *dbf, int num_bytes);
- + extern int _gdbm_free (gdbm_file_info *dbf, long file_adr, int num_bytes);
- + extern int _gdbm_put_av_elem (avail_elem new_el, avail_elem *av_table, int *av_count);
- + extern char *_gdbm_read_entry (gdbm_file_info *dbf, int elem_loc);
- + extern int _gdbm_findkey (gdbm_file_info *dbf, datum key, char **dptr, long *new_hash_val);
- + extern long _gdbm_hash (datum key);
- + extern void _gdbm_end_update (gdbm_file_info *dbf);
- + extern void _gdbm_fatal (gdbm_file_info *dbf, char *val);
- +
- + extern int dbminit (char *file);
- + extern datum fetch(datum key);
- + extern int store (datum key, datum content);
- + extern int delete (datum key);
- + extern datum firstkey (void);
- + extern datum nextkey (datum key);
- +
- + extern gdbm_file_info *dbm_open (char *file, int flags, int mode);
- + extern void dbm_close (gdbm_file_info *dbf);
- + extern datum dbm_fetch (gdbm_file_info *dbf, datum key);
- + extern int dbm_store (gdbm_file_info *dbf, datum key, datum content, int flags);
- + extern int dbm_delete (gdbm_file_info *dbf, datum key);
- + extern datum dbm_firstkey (gdbm_file_info *dbf);
- + extern datum dbm_nextkey (gdbm_file_info *dbf);
- + extern int dbm_dirfno (gdbm_file_info *dbf);
- + extern int dbm_pagfno (gdbm_file_info *dbf);
- + #endif /* __STDC__ */
- diff -cb orig/gdbmdelete.c gdbm/gdbmdelete.c
- *** orig/gdbmdelete.c Sun Jan 19 14:44:22 1992
- --- gdbm/gdbmdelete.c Sun Jan 19 14:43:18 1992
- ***************
- *** 79,86 ****
- while (elem_loc != last_loc
- && dbf->bucket->h_table[elem_loc].hash_value != -1)
- {
- ! home = dbf->bucket->h_table[elem_loc].hash_value
- ! % dbf->header->bucket_elems;
- if ( (last_loc < elem_loc && (home <= last_loc || home > elem_loc))
- || (last_loc > elem_loc && home <= last_loc && home > elem_loc))
-
- --- 79,86 ----
- while (elem_loc != last_loc
- && dbf->bucket->h_table[elem_loc].hash_value != -1)
- {
- ! home = (int) (dbf->bucket->h_table[elem_loc].hash_value
- ! % dbf->header->bucket_elems);
- if ( (last_loc < elem_loc && (home <= last_loc || home > elem_loc))
- || (last_loc > elem_loc && home <= last_loc && home > elem_loc))
-
- diff -cb orig/gdbmopen.c gdbm/gdbmopen.c
- *** orig/gdbmopen.c Sun Jan 19 14:44:24 1992
- --- gdbm/gdbmopen.c Sun Jan 19 14:43:20 1992
- ***************
- *** 110,130 ****
- need_trunc = FALSE;
- if (read_write == GDBM_READER)
- {
- ! dbf->desc = open (dbf->name, O_RDONLY, 0);
- }
- else if (read_write == GDBM_WRITER)
- {
- ! dbf->desc = open (dbf->name, O_RDWR, 0);
- }
- else if (read_write == GDBM_NEWDB)
- {
- ! dbf->desc = open (dbf->name, O_RDWR|O_CREAT, mode);
- read_write = GDBM_WRITER;
- need_trunc = TRUE;
- }
- else
- {
- ! dbf->desc = open (dbf->name, O_RDWR|O_CREAT, mode);
- read_write = GDBM_WRITER;
- }
- if (dbf->desc < 0)
- --- 110,130 ----
- need_trunc = FALSE;
- if (read_write == GDBM_READER)
- {
- ! dbf->desc = open (dbf->name, O_RDONLY|O_BINARY, 0);
- }
- else if (read_write == GDBM_WRITER)
- {
- ! dbf->desc = open (dbf->name, O_RDWR|O_BINARY, 0);
- }
- else if (read_write == GDBM_NEWDB)
- {
- ! dbf->desc = open (dbf->name, O_RDWR|O_CREAT|O_BINARY, mode);
- read_write = GDBM_WRITER;
- need_trunc = TRUE;
- }
- else
- {
- ! dbf->desc = open (dbf->name, O_RDWR|O_CREAT|O_BINARY, mode);
- read_write = GDBM_WRITER;
- }
- if (dbf->desc < 0)
- ***************
- *** 206,212 ****
- dbf->header->block_size = file_block_size;
-
- /* Create the initial hash table directory. */
- ! dbf->header->dir_size = 8 * sizeof (int);
- dbf->header->dir_bits = 3;
- while (dbf->header->dir_size < dbf->header->block_size)
- {
- --- 206,212 ----
- dbf->header->block_size = file_block_size;
-
- /* Create the initial hash table directory. */
- ! dbf->header->dir_size = 8 * sizeof (long);
- dbf->header->dir_bits = 3;
- while (dbf->header->dir_size < dbf->header->block_size)
- {
- ***************
- *** 223,229 ****
- }
-
- /* Allocate the space for the directory. */
- ! dbf->dir = (int *) malloc (dbf->header->dir_size);
- if (dbf->dir == NULL)
- {
- gdbm_close (dbf);
- --- 223,229 ----
- }
-
- /* Allocate the space for the directory. */
- ! dbf->dir = (long *) malloc (dbf->header->dir_size);
- if (dbf->dir == NULL)
- {
- gdbm_close (dbf);
- ***************
- *** 250,256 ****
- dbf->bucket->bucket_avail[0].av_size = dbf->header->block_size;
-
- /* Set table entries to point to hash buckets. */
- ! for (index = 0; index < dbf->header->dir_size / sizeof (int); index++)
- dbf->dir[index] = 2*dbf->header->block_size;
-
- /* Initialize the active avail block. */
- --- 250,256 ----
- dbf->bucket->bucket_avail[0].av_size = dbf->header->block_size;
-
- /* Set table entries to point to hash buckets. */
- ! for (index = 0; index < dbf->header->dir_size / sizeof (long); index++)
- dbf->dir[index] = 2*dbf->header->block_size;
-
- /* Initialize the active avail block. */
- ***************
- *** 310,316 ****
- }
-
- /* Is the magic number good? */
- ! if (partial_header.header_magic != 0x13579ace)
- {
- gdbm_close (dbf);
- gdbm_errno = GDBM_BAD_MAGIC_NUMBER;
- --- 310,316 ----
- }
-
- /* Is the magic number good? */
- ! if (partial_header.header_magic != 0x13579ACEL)
- {
- gdbm_close (dbf);
- gdbm_errno = GDBM_BAD_MAGIC_NUMBER;
- ***************
- *** 336,342 ****
- }
-
- /* Allocate space for the hash table directory. */
- ! dbf->dir = (int *) malloc (dbf->header->dir_size);
- if (dbf->dir == NULL)
- {
- gdbm_close (dbf);
- --- 336,342 ----
- }
-
- /* Allocate space for the hash table directory. */
- ! dbf->dir = (long *) malloc (dbf->header->dir_size);
- if (dbf->dir == NULL)
- {
- gdbm_close (dbf);
- diff -cb orig/gdbmreorg.c gdbm/gdbmreorg.c
- *** orig/gdbmreorg.c Sun Jan 19 14:44:26 1992
- --- gdbm/gdbmreorg.c Sun Jan 19 14:43:20 1992
- ***************
- *** 74,79 ****
- --- 74,80 ----
- gdbm_file_info *new_dbf; /* The new file. */
- char *new_name; /* A temporary name. */
- int len; /* Used in new_name construction. */
- + int new_desc; /* Used to avoid walking file desc */
- datum key, nextkey, data; /* For the sequential sweep. */
- struct stat fileinfo; /* Information about the file. */
- int index; /* Use in moving the bucket cache. */
- ***************
- *** 131,139 ****
- gdbm_close (new_dbf);
- gdbm_errno = GDBM_REORGANIZE_FAILED;
- unlink (new_name);
- return -1;
- - };
- }
- else
- {
- /* ERROR! Abort and don't finish reorganize. */
- --- 132,141 ----
- gdbm_close (new_dbf);
- gdbm_errno = GDBM_REORGANIZE_FAILED;
- unlink (new_name);
- + free(new_name);
- return -1;
- }
- + }
- else
- {
- /* ERROR! Abort and don't finish reorganize. */
- ***************
- *** 140,164 ****
- gdbm_close (new_dbf);
- gdbm_errno = GDBM_REORGANIZE_FAILED;
- unlink (new_name);
- return -1;
- }
- nextkey = gdbm_nextkey (dbf, key);
- free (key.dptr);
- key = nextkey;
- }
-
- /* Move the new file to old name. */
-
- if (rename (new_name, dbf->name) != 0)
- {
- gdbm_errno = GDBM_REORGANIZE_FAILED;
- gdbm_close (new_dbf);
- return -1;
- }
-
- /* Fix up DBF to have the correct information for the new file. */
- UNLOCK_FILE(dbf);
- ! close (dbf->desc);
- free (dbf->header);
- free (dbf->dir);
- for (index = 0; index < CACHE_SIZE; index++)
- --- 142,186 ----
- gdbm_close (new_dbf);
- gdbm_errno = GDBM_REORGANIZE_FAILED;
- unlink (new_name);
- + free(new_name);
- return -1;
- }
- nextkey = gdbm_nextkey (dbf, key);
- free (key.dptr);
- + free (data.dptr);
- key = nextkey;
- }
-
- /* Move the new file to old name. */
-
- + #ifdef OS2
- + if (close (new_dbf->desc)
- + || unlink (dbf->name)
- + || rename (new_name, dbf->name)
- + || (new_dbf->desc = open (dbf->name, O_RDWR|O_BINARY)) < 0)
- + #else /* not OS2 */
- if (rename (new_name, dbf->name) != 0)
- + #endif /* not OS2 */
- {
- gdbm_errno = GDBM_REORGANIZE_FAILED;
- gdbm_close (new_dbf);
- + unlink (new_name);
- + free(new_name);
- return -1;
- }
-
- /* Fix up DBF to have the correct information for the new file. */
- UNLOCK_FILE(dbf);
- ! /* close (dbf->desc); */
- ! if ((new_desc = dup2(new_dbf->desc, dbf->desc)) < 0)
- ! {
- ! gdbm_close(new_dbf);
- ! gdbm_errno = GDBM_REORGANIZE_FAILED;
- ! unlink (new_name);
- ! free(new_name);
- ! return -1;
- ! }
- ! dbf->desc = new_desc;
- free (dbf->header);
- free (dbf->dir);
- for (index = 0; index < CACHE_SIZE; index++)
- ***************
- *** 169,180 ****
- free (dbf->bucket_cache[index].ca_data.dptr);
- }
-
- ! dbf->desc = new_dbf->desc;
- dbf->header = new_dbf->header;
- dbf->dir = new_dbf->dir;
- dbf->bucket = new_dbf->bucket;
- dbf->bucket_dir = new_dbf->bucket_dir;
- ! dbf->cache_entry = new_dbf->cache_entry;
- dbf->last_read = new_dbf->last_read;
- for (index = 0; index < CACHE_SIZE; index++)
- dbf->bucket_cache[index] = new_dbf->bucket_cache[index];
- --- 191,203 ----
- free (dbf->bucket_cache[index].ca_data.dptr);
- }
-
- ! /* dbf->desc = new_dbf->desc; */
- dbf->header = new_dbf->header;
- dbf->dir = new_dbf->dir;
- dbf->bucket = new_dbf->bucket;
- dbf->bucket_dir = new_dbf->bucket_dir;
- ! /* dbf->cache_entry = new_dbf->cache_entry; */
- ! dbf->cache_entry = &dbf->bucket_cache[new_dbf->last_read];
- dbf->last_read = new_dbf->last_read;
- for (index = 0; index < CACHE_SIZE; index++)
- dbf->bucket_cache[index] = new_dbf->bucket_cache[index];
- ***************
- *** 187,192 ****
- --- 210,217 ----
-
- /* Make sure the new database is all on disk. */
- fsync (dbf->desc);
- +
- + free(new_name);
-
- return 0;
- }
- diff -cb orig/gdbmseq.c gdbm/gdbmseq.c
- *** orig/gdbmseq.c Sun Jan 19 14:44:26 1992
- --- gdbm/gdbmseq.c Thu May 23 19:54:52 1991
- ***************
- *** 30,35 ****
- --- 30,41 ----
-
- #include "gdbmdefs.h"
-
- +
- + #ifdef __STDC__
- + static void get_next_key (gdbm_file_info *dbf, int elem_loc, datum *return_val);
- + #endif /* not __STDC__ */
- +
- +
- /* Special extern for this file. */
- extern char *_gdbm_read_entry ();
-
- ***************
- *** 60,71 ****
-
- /* Find the next bucket. It is possible several entries in
- the bucket directory point to the same bucket. */
- ! while (dbf->bucket_dir < dbf->header->dir_size / sizeof (int)
- && dbf->cache_entry->ca_adr == dbf->dir[dbf->bucket_dir])
- dbf->bucket_dir++;
-
- /* Check to see if there was a next bucket. */
- ! if (dbf->bucket_dir < dbf->header->dir_size / sizeof (int))
- _gdbm_get_bucket (dbf, dbf->bucket_dir);
- else
- /* No next key, just return. */
- --- 66,77 ----
-
- /* Find the next bucket. It is possible several entries in
- the bucket directory point to the same bucket. */
- ! while (dbf->bucket_dir < dbf->header->dir_size / sizeof (long)
- && dbf->cache_entry->ca_adr == dbf->dir[dbf->bucket_dir])
- dbf->bucket_dir++;
-
- /* Check to see if there was a next bucket. */
- ! if (dbf->bucket_dir < dbf->header->dir_size / sizeof (long))
- _gdbm_get_bucket (dbf, dbf->bucket_dir);
- else
- /* No next key, just return. */
- diff -cb orig/gdbmstore.c gdbm/gdbmstore.c
- *** orig/gdbmstore.c Sun Jan 19 14:44:28 1992
- --- gdbm/gdbmstore.c Sun Jan 19 14:43:20 1992
- ***************
- *** 123,129 ****
- }
-
- /* Find space to insert into bucket and set elem_loc to that place. */
- ! elem_loc = new_hash_val % dbf->header->bucket_elems;
- while (dbf->bucket->h_table[elem_loc].hash_value != -1)
- { elem_loc = (elem_loc + 1) % dbf->header->bucket_elems; }
-
- --- 123,129 ----
- }
-
- /* Find space to insert into bucket and set elem_loc to that place. */
- ! elem_loc = (int) (new_hash_val % dbf->header->bucket_elems);
- while (dbf->bucket->h_table[elem_loc].hash_value != -1)
- { elem_loc = (elem_loc + 1) % dbf->header->bucket_elems; }
-
- ***************
- *** 142,147 ****
- --- 142,154 ----
-
- /* Prepare write_data. The key is written first. */
- write_data = (char *) alloca (key.dsize+content.dsize);
- + #ifdef OS2
- + if (write_data == (char *) 0)
- + {
- + fprintf (stderr, "Error: alloca() failed in gdbm (%s).\n", __FILE__);
- + exit (-2);
- + }
- + #endif /* OS2 */
- dst = write_data;
- src = key.dptr;
- for (cnt=0; cnt < key.dsize; cnt++)
- diff -cb orig/getopt.c gdbm/getopt.c
- *** orig/getopt.c Sun Dec 09 23:59:50 1990
- --- gdbm/getopt.c Sun Jan 19 14:43:20 1992
- ***************
- *** 15,26 ****
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- ! #if defined(__STDC__) || defined(MSDOS)
- #define CONST const
- #else
- #define CONST
- #endif
- ! #ifdef MSDOS
- #define STDC_HEADERS
- #endif
-
- --- 15,26 ----
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- ! #if defined(__STDC__) || defined(OS2)
- #define CONST const
- #else
- #define CONST
- #endif
- ! #ifdef OS2
- #define STDC_HEADERS
- #endif
-
- ***************
- *** 47,53 ****
- #ifdef sparc
- #include <alloca.h>
- #else
- ! #ifdef MSDOS
- #include <malloc.h>
- #else
- char *alloca ();
- --- 47,53 ----
- #ifdef sparc
- #include <alloca.h>
- #else
- ! #ifdef OS2
- #include <malloc.h>
- #else
- char *alloca ();
- diff -cb orig/getopt.h gdbm/getopt.h
- *** orig/getopt.h Sun Oct 28 10:50:34 1990
- --- gdbm/getopt.h Sun Jan 19 14:37:08 1992
- ***************
- *** 73,79 ****
- int val;
- };
-
- ! #if defined(__STDC__) || defined(MSDOS)
- extern const struct option *_getopt_long_options;
- #else
- extern struct option *_getopt_long_options;
- --- 73,79 ----
- int val;
- };
-
- ! #if defined(__STDC__) || defined(OS2)
- extern const struct option *_getopt_long_options;
- #else
- extern struct option *_getopt_long_options;
- ***************
- *** 90,96 ****
-
- extern int option_index;
-
- ! #if defined(__STDC__) || defined(MSDOS)
- int getopt (int argc, char **argv, const char *shortopts);
- int getopt_long (int argc, char **argv, const char *shortopts,
- const struct option *longopts, int *longind);
- --- 90,96 ----
-
- extern int option_index;
-
- ! #if defined(__STDC__) || defined(OS2)
- int getopt (int argc, char **argv, const char *shortopts);
- int getopt_long (int argc, char **argv, const char *shortopts,
- const struct option *longopts, int *longind);
- diff -cb orig/getopt1.c gdbm/getopt1.c
- *** orig/getopt1.c Sun Dec 09 23:59:50 1990
- --- gdbm/getopt1.c Sun Jan 19 14:43:20 1992
- ***************
- *** 17,23 ****
-
- #include "getopt.h"
-
- ! #if defined(__STDC__) || defined(MSDOS)
- #define CONST const
- #else
- #define CONST
- --- 17,23 ----
-
- #include "getopt.h"
-
- ! #if defined(__STDC__) || defined(OS2)
- #define CONST const
- #else
- #define CONST
- diff -cb orig/global.c gdbm/global.c
- *** orig/global.c Sun Jan 19 14:44:28 1992
- --- gdbm/global.c Sun Jan 19 14:43:20 1992
- ***************
- *** 41,44 ****
- char *_gdbm_fetch_val = NULL; /* Used by fetch. */
-
- /* The dbm error number is placed in the variable GDBM_ERRNO. */
- ! gdbm_error gdbm_errno;
- --- 41,45 ----
- char *_gdbm_fetch_val = NULL; /* Used by fetch. */
-
- /* The dbm error number is placed in the variable GDBM_ERRNO. */
- ! /* won't go into library if not initialized! */
- ! gdbm_error gdbm_errno = GDBM_NO_ERROR;
- diff -cb orig/ndbm.h gdbm/ndbm.h
- *** orig/ndbm.h Sun Jan 19 14:44:30 1992
- --- gdbm/ndbm.h Thu May 23 19:27:24 1991
- ***************
- *** 33,70 ****
-
-
- /* The data and key structure. This structure is defined for compatibility. */
- typedef struct {
- char *dptr;
- int dsize;
- } datum;
-
- -
- /* The file information header. This is good enough for most applications. */
- typedef struct {int dummy[10];} DBM;
- !
-
- /* These are the routines (with some macros defining them!) */
-
- extern DBM *dbm_open ();
- -
- extern void dbm_close ();
- -
- extern datum dbm_fetch ();
- -
- extern int dbm_store ();
- -
- - extern int dbm_delete ();
- -
- extern int dbm_delete ();
- -
- extern datum dbm_firstkey ();
- -
- extern datum dbm_nextkey ();
-
- #define dbm_error(dbf) 0
- -
- #define dbm_clearerr(dbf)
-
- - extern int dbm_dirfno ();
-
- - extern int dbm_pagfno ();
- --- 33,79 ----
-
-
- /* The data and key structure. This structure is defined for compatibility. */
- + #ifdef __STDC__
- + #include "gdbmdefs.h"
- + #else /* not __STDC__ */
- typedef struct {
- char *dptr;
- int dsize;
- } datum;
- + #endif /* not __STDC__ */
-
- /* The file information header. This is good enough for most applications. */
- + #ifdef __STDC__
- + #define DBM gdbm_file_info
- + #else /* not __STDC__ */
- typedef struct {int dummy[10];} DBM;
- ! #endif /* not __STDC__ */
-
- /* These are the routines (with some macros defining them!) */
-
- + #ifdef __STDC__
- + extern DBM *dbm_open (char *file, int flags, int mode);
- + extern void dbm_close (DBM *dbf);
- + extern datum dbm_fetch (DBM *dbf, datum key);
- + extern int dbm_store (DBM *dbf, datum key, datum content, int flags);
- + extern int dbm_delete (DBM *dbf, datum key);
- + extern datum dbm_firstkey (DBM *dbf);
- + extern datum dbm_nextkey (DBM *dbf);
- + extern int dbm_dirfno (DBM *dbf);
- + extern int dbm_pagfno (DBM *dbf);
- + #else /* not __STDC__ */
- extern DBM *dbm_open ();
- extern void dbm_close ();
- extern datum dbm_fetch ();
- extern int dbm_store ();
- extern int dbm_delete ();
- extern datum dbm_firstkey ();
- extern datum dbm_nextkey ();
- + extern int dbm_dirfno ();
- + extern int dbm_pagfno ();
- + #endif /* not __STDC__ */
-
- #define dbm_error(dbf) 0
- #define dbm_clearerr(dbf)
-
-
- diff -cb orig/readme gdbm/readme
- *** orig/readme Sun Jan 19 14:44:32 1992
- --- gdbm/readme Thu May 23 21:55:46 1991
- ***************
- *** 1,3 ****
- --- 1,26 ----
- + /*
- + * MS-DOS port (c) 1990 by Thorsten Ohl, td12@@ddagsi3.bitnet
- + *
- + * To this port, the same copying conditions apply as to the
- + * original release.
- + *
- + * IMPORTANT:
- + * These files are not identical to the original GNU release!
- + * You should have received this code as patch to the official
- + * GNU release.
- + *
- + * MORE IMPORTANT:
- + * This port comes with ABSOLUTELY NO WARRANTY.
- + */
- +
- + Note: This port was done for 1.4.
- + I have applied a part of it to 1.5 and made some minor further changes
- +
- + Kai Uwe Rommel
- + rommel@lan.informatik.tu-muenchen.dbp.de
- + -----------
- +
- +
- This is release 1.5 of GNU dbm. Better documentation will be written
- soon. For now, this file briefly describes the contents of this
- release and how to use it.
- diff -cb orig/systems.h gdbm/systems.h
- *** orig/systems.h Sun Jan 19 14:44:32 1992
- --- gdbm/systems.h Sun Jan 19 14:37:08 1992
- ***************
- *** 27,33 ****
-
- *************************************************************************/
-
- !
-
- /* System V changes and defines. */
- /**************************************************/
- --- 27,37 ----
-
- *************************************************************************/
-
- ! #ifdef OS2
- ! #ifndef SYSV
- ! #define SYSV
- ! #endif
- ! #endif
-
- /* System V changes and defines. */
- /**************************************************/
- ***************
- *** 35,45 ****
- --- 39,59 ----
- #ifdef SYSV
-
- /* File seeking needs L_SET defined .*/
- + #ifdef OS2
- + #include <malloc.h>
- + #include <io.h>
- + #else /* not OS2 */
- #include <unistd.h>
- + #endif /* not OS2 */
- #define L_SET SEEK_SET
-
- /* Some files need fcntl.h for locking. */
- #include <fcntl.h>
- + #ifdef OS2
- + #define UNLOCK_FILE(dbf) /* later !!! */
- + #define READLOCK_FILE(dbf) lock_val = 0;
- + #define WRITELOCK_FILE(dbf) lock_val = 0;
- + #else /* not OS2 */
- #define UNLOCK_FILE(dbf) \
- { \
- struct flock flock; \
- ***************
- *** 64,69 ****
- --- 78,84 ----
- flock.l_start = flock.l_len = 0L; \
- lock_val = fcntl (dbf->desc, F_SETLK, &flock); \
- }
- + #endif /* not OS2 */
-
- /* Send bcmp to the right place. */
- #include <memory.h>
- ***************
- *** 71,83 ****
- --- 86,104 ----
- #define bcopy(d1, d2, n) memcpy(d2, d1, n)
-
- /* Sys V does not have fsync. */
- + #ifdef OS2
- + #define fsync(f)
- + #else /* not OS2 */
- #define fsync(f) sync(); sync()
- + #endif /* not OS2 */
-
- /* Stat does not have a st_blksize field. */
- #define STATBLKSIZE 512
-
- /* Does not have rename(). */
- + #ifndef OS2
- #define NEED_RENAME
- + #endif /* not OS2 */
-
- /* Get string definitions. */
- #include <string.h>
- ***************
- *** 92,98 ****
- /**************************************************/
-
-
- !
- /* Alloca is builtin in gcc. Use the builtin alloca if compiled with gcc. */
- #ifdef __GNUC__
- #define BUILTIN_ALLOCA
- --- 113,119 ----
- /**************************************************/
-
-
- ! #ifndef OS2
- /* Alloca is builtin in gcc. Use the builtin alloca if compiled with gcc. */
- #ifdef __GNUC__
- #define BUILTIN_ALLOCA
- ***************
- *** 114,119 ****
- --- 135,141 ----
-
- /* Malloc definition. */
- extern char *malloc();
- + #endif /* not OS2 */
-
- /* String definitions. */
- #ifndef _HAVE_STRING
- diff -cb orig/testdbm.c gdbm/testdbm.c
- *** orig/testdbm.c Sun Jan 19 14:44:34 1992
- --- gdbm/testdbm.c Sun Jan 19 14:43:20 1992
- ***************
- *** 30,41 ****
- --- 30,48 ----
-
- #include <stdio.h>
- #include <sys/types.h>
- + #ifndef OS2
- #include <sys/file.h>
- + #endif /* not OS2 */
- #include <sys/stat.h>
-
- #define TRUE 1
- #define FALSE 0
-
- + #ifdef __STDC__
- + #include <stdlib.h>
- + #include <string.h>
- + #include "dbm.h"
- + #else /* not __STDC__ */
- typedef struct {
- char *dptr;
- int dsize;
- ***************
- *** 44,49 ****
- --- 51,57 ----
- extern datum fetch ();
- extern datum firstkey ();
- extern datum nextkey ();
- + #endif /* not __STDC__ */
-
- /* The test program allows one to call all the routines plus the hash function.
- The commands are single letter commands. The user is prompted for all other
- ***************
- *** 50,61 ****
- information. The commands are q (quit), f (fetch), s (store), d (delete),
- 1 (firstkey), n (nextkey) and h (hash function). */
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
-
- ! char cmd_ch;
-
- datum key_data;
- datum data_data;
- --- 58,70 ----
- information. The commands are q (quit), f (fetch), s (store), d (delete),
- 1 (firstkey), n (nextkey) and h (hash function). */
-
- + void
- main (argc, argv)
- int argc;
- char *argv[];
- {
-
- ! int cmd_ch;
-
- datum key_data;
- datum data_data;
- diff -cb orig/testgdbm.c gdbm/testgdbm.c
- *** orig/testgdbm.c Sun Jan 19 14:44:38 1992
- --- gdbm/testgdbm.c Sun Jan 19 14:43:20 1992
- ***************
- *** 43,49 ****
- --- 43,132 ----
-
- gdbm_file_info *gdbm_file;
-
- + #ifdef __STDC__
- + void _gdbm_print_bucket_cache (gdbm_file_info *dbf);
- + static void print_bucket (hash_bucket *bucket, char *mesg);
- + static void _gdbm_print_avail_list (gdbm_file_info *dbf);
- + void main (int argc, char **argv);
- + void usage (char *s);
- + void gdbm_perror (char *msg);
- + extern int getopt (int argc, char **argv, const char *shortopts);
- + #endif /* __STDC__ */
- +
- +
- + /* access GDBM_ERRNO. [tho] */
- +
- + void
- + gdbm_perror (char *msg)
- + {
- + char *err_msg;
- +
- + switch (gdbm_errno)
- + {
- + case GDBM_NO_ERROR:
- + err_msg = "no error";
- + break;
- + case GDBM_MALLOC_ERROR:
- + err_msg = "can't malloc";
- + break;
- + case GDBM_BLOCK_SIZE_ERROR:
- + err_msg = "bad block size";
- + break;
- + case GDBM_FILE_OPEN_ERROR:
- + err_msg = "can't open file";
- + break;
- + case GDBM_FILE_WRITE_ERROR:
- + err_msg = "can't write file";
- + break;
- + case GDBM_FILE_SEEK_ERROR:
- + err_msg = "can't seek file";
- + break;
- + case GDBM_FILE_READ_ERROR:
- + err_msg = "can't read file";
- + break;
- + case GDBM_BAD_MAGIC_NUMBER:
- + err_msg = "bad magic number";
- + break;
- + case GDBM_EMPTY_DATABASE:
- + err_msg = "empty database";
- + break;
- + case GDBM_CANT_BE_READER:
- + err_msg = "can't be reader";
- + break;
- + case GDBM_CANT_BE_WRITER:
- + err_msg = "can't be writer";
- + break;
- + case GDBM_READER_CANT_DELETE:
- + err_msg = "can't delete";
- + break;
- + case GDBM_READER_CANT_STORE:
- + err_msg = "can't store";
- + break;
- + case GDBM_READER_CANT_REORGANIZE:
- + err_msg = "can't reorganize";
- + break;
- + case GDBM_UNKNOWN_UPDATE:
- + err_msg = "unkown update";
- + break;
- + case GDBM_ITEM_NOT_FOUND:
- + err_msg = "item not found";
- + break;
- + case GDBM_REORGANIZE_FAILED:
- + err_msg = "reorganization failed";
- + break;
- + case GDBM_CANNOT_REPLACE:
- + err_msg = "can't replace";
- + break;
- + default:
- + err_msg = "unknown error";
- + }
- +
- + fprintf (stderr, "%s (GDBM error: %s)\n", msg, err_msg);
- + }
- +
- +
- /* Debug procedure to print the contents of the current hash bucket. */
- + void
- print_bucket (bucket, mesg)
- hash_bucket *bucket;
- char *mesg;
- ***************
- *** 54,78 ****
- mesg, bucket->bucket_bits, bucket->count);
- printf (" # hash value key size data size data adr home\n");
- for (index = 0; index < gdbm_file->header->bucket_elems; index++)
- ! printf (" %4d %12x %11d %11d %11d %5d\n", index,
- bucket->h_table[index].hash_value,
- bucket->h_table[index].key_size,
- bucket->h_table[index].data_size,
- bucket->h_table[index].data_pointer,
- ! bucket->h_table[index].hash_value % gdbm_file->header->bucket_elems);
-
- printf ("\nAvail count = %1d\n", bucket->av_count);
- printf ("Avail adr size\n");
- for (index = 0; index < bucket->av_count; index++)
- ! printf ("%9d%9d\n", bucket->bucket_avail[index].av_adr,
- bucket->bucket_avail[index].av_size);
- }
-
-
- _gdbm_print_avail_list (dbf)
- gdbm_file_info *dbf;
- {
- ! int temp;
- int size;
- avail_block *av_stk;
-
- --- 137,162 ----
- mesg, bucket->bucket_bits, bucket->count);
- printf (" # hash value key size data size data adr home\n");
- for (index = 0; index < gdbm_file->header->bucket_elems; index++)
- ! printf (" %4d %12lx %11d %11d %11ld %5d\n", index,
- bucket->h_table[index].hash_value,
- bucket->h_table[index].key_size,
- bucket->h_table[index].data_size,
- bucket->h_table[index].data_pointer,
- ! (int) (bucket->h_table[index].hash_value % gdbm_file->header->bucket_elems));
-
- printf ("\nAvail count = %1d\n", bucket->av_count);
- printf ("Avail adr size\n");
- for (index = 0; index < bucket->av_count; index++)
- ! printf ("%9ld%9d\n", bucket->bucket_avail[index].av_adr,
- bucket->bucket_avail[index].av_size);
- }
-
-
- + void
- _gdbm_print_avail_list (dbf)
- gdbm_file_info *dbf;
- {
- ! long temp;
- int size;
- avail_block *av_stk;
-
- ***************
- *** 81,87 ****
- dbf->header->avail.size, dbf->header->avail.count);
- for (temp = 0; temp < dbf->header->avail.count; temp++)
- {
- ! printf (" %15d %10d \n", dbf->header->avail.av_table[temp].av_size,
- dbf->header->avail.av_table[temp].av_adr);
- }
-
- --- 165,171 ----
- dbf->header->avail.size, dbf->header->avail.count);
- for (temp = 0; temp < dbf->header->avail.count; temp++)
- {
- ! printf (" %15d %10ld \n", dbf->header->avail.av_table[temp].av_size,
- dbf->header->avail.av_table[temp].av_adr);
- }
-
- ***************
- *** 90,95 ****
- --- 174,186 ----
- size = ( ( (dbf->header->avail.size * sizeof (avail_elem)) >> 1)
- + sizeof (avail_block));
- av_stk = (avail_block *) alloca (size);
- + #ifdef OS2
- + if (av_stk == (avail_block *) 0)
- + {
- + fprintf (stderr, "Error: alloca() failed in gdbm (%s).\n", __FILE__);
- + exit (-2);
- + }
- + #endif /* OS2 */
-
- /* Print the stack. */
- while (FALSE)
- ***************
- *** 102,108 ****
- av_stk->size, av_stk->count);
- for (temp = 0; temp < av_stk->count; temp++)
- {
- ! printf (" %15d %10d \n", av_stk->av_table[temp].av_size,
- av_stk->av_table[temp].av_adr);
- }
- temp = av_stk->next_block;
- --- 193,199 ----
- av_stk->size, av_stk->count);
- for (temp = 0; temp < av_stk->count; temp++)
- {
- ! printf (" %15d %10ld \n", av_stk->av_table[temp].av_size,
- av_stk->av_table[temp].av_adr);
- }
- temp = av_stk->next_block;
- ***************
- *** 109,115 ****
- }
- }
-
- ! _gdbm_print_bucket_cache (dbf)
- gdbm_file_info *dbf;
- {
- int index;
- --- 200,206 ----
- }
- }
-
- ! void _gdbm_print_bucket_cache (dbf)
- gdbm_file_info *dbf;
- {
- int index;
- ***************
- *** 119,125 ****
- for (index=0; index < CACHE_SIZE; index++)
- {
- changed = dbf->bucket_cache[index].ca_changed;
- ! printf (" %5d: %7d %7s %x\n",
- index,
- dbf->bucket_cache[index].ca_adr,
- (changed ? "True" : "False"),
- --- 210,216 ----
- for (index=0; index < CACHE_SIZE; index++)
- {
- changed = dbf->bucket_cache[index].ca_changed;
- ! printf (" %5d: %7ld %7s %lx\n",
- index,
- dbf->bucket_cache[index].ca_adr,
- (changed ? "True" : "False"),
- ***************
- *** 139,144 ****
- --- 230,236 ----
- The commands are single letter commands. The user is prompted for all other
- information. See the help command (?) for a list of all commands. */
-
- + void
- main (argc, argv)
- int argc;
- char *argv[];
- ***************
- *** 145,151 ****
-
- {
-
- ! char cmd_ch;
-
- datum key_data;
- datum data_data;
- --- 237,244 ----
-
- {
-
- ! int cmd_ch;
- ! int opt;
-
- datum key_data;
- datum data_data;
- ***************
- *** 155,161 ****
- char data_line[1000];
-
- char done = FALSE;
- - char opt;
- char reader = FALSE;
- char newdb = FALSE;
-
- --- 248,253 ----
- ***************
- *** 180,186 ****
- --- 272,282 ----
- }
- else
- {
- + #ifdef OS2
- + file_name = "junk.gdb";
- + #else
- file_name = "junk.gdbm";
- + #endif
- }
-
- /* Initialize variables. */
- ***************
- *** 195,204 ****
- gdbm_file = gdbm_open (file_name, 512, GDBM_WRCREAT, 00664, NULL);
- if (gdbm_file == NULL)
- {
- ! if (gdbm_errno != GDBM_CANT_BE_WRITER)
- ! printf ("gdbm_open failed.\n");
- ! else
- ! printf ("Can't open as a writer. \n");
- exit (2);
- }
-
- --- 291,297 ----
- gdbm_file = gdbm_open (file_name, 512, GDBM_WRCREAT, 00664, NULL);
- if (gdbm_file == NULL)
- {
- ! gdbm_perror ("gdbm_open failed");
- exit (2);
- }
-
- ***************
- *** 208,219 ****
- while (!done)
- {
- printf ("com -> ");
- ! cmd_ch = getchar ();
- if (cmd_ch != '\n')
- {
- char temp;
- do
- ! temp = getchar ();
- while (temp != '\n' && temp != EOF);
- }
- if (cmd_ch == EOF) cmd_ch = 'q';
- --- 301,312 ----
- while (!done)
- {
- printf ("com -> ");
- ! cmd_ch = (char) getchar ();
- if (cmd_ch != '\n')
- {
- char temp;
- do
- ! temp = (char) getchar ();
- while (temp != '\n' && temp != EOF);
- }
- if (cmd_ch == EOF) cmd_ch = 'q';
- ***************
- *** 250,256 ****
- key_data.dptr = key_line;
- key_data.dsize = strlen (key_line)+1;
- if (gdbm_delete (gdbm_file, key_data) != 0)
- ! printf ("Item not found or deleted\n");
- printf ("\n");
- key_data.dptr = NULL;
- break;
- --- 343,349 ----
- key_data.dptr = key_line;
- key_data.dsize = strlen (key_line)+1;
- if (gdbm_delete (gdbm_file, key_data) != 0)
- ! gdbm_perror ("Item not found or deleted");
- printf ("\n");
- key_data.dptr = NULL;
- break;
- ***************
- *** 289,295 ****
- }
- else
- {
- ! printf ("No such item found.\n\n");
- key_data.dptr = NULL;
- }
- break;
- --- 382,388 ----
- }
- else
- {
- ! gdbm_perror ("No such item found");
- key_data.dptr = NULL;
- }
- break;
- ***************
- *** 308,314 ****
- gets (data_line);
- data_data.dsize = strlen (data_line)+1;
- if (gdbm_store (gdbm_file, key_data, data_data, GDBM_REPLACE) != 0)
- ! printf ("Item not inserted. \n");
- printf ("\n");
- key_data.dptr = NULL;
- break;
- --- 401,407 ----
- gets (data_line);
- data_data.dsize = strlen (data_line)+1;
- if (gdbm_store (gdbm_file, key_data, data_data, GDBM_REPLACE) != 0)
- ! gdbm_perror ("Item not inserted");
- printf ("\n");
- key_data.dptr = NULL;
- break;
- ***************
- *** 324,330 ****
- free (return_data.dptr);
- }
- else
- ! printf ("No such item found.\n\n");
- break;
-
- case '2':
- --- 417,423 ----
- free (return_data.dptr);
- }
- else
- ! gdbm_perror ("No such item found");
- break;
-
- case '2':
- ***************
- *** 339,345 ****
- free (return_data.dptr);
- }
- else
- ! printf ("No such item found.\n\n");
- break;
-
-
- --- 432,438 ----
- free (return_data.dptr);
- }
- else
- ! gdbm_perror ("No such item found");
- break;
-
-
- ***************
- *** 347,353 ****
- case 'r':
- {
- if (gdbm_reorganize (gdbm_file))
- ! printf ("Reorganization failed. \n\n");
- else
- printf ("Reorganization succeeded. \n\n");
- }
- --- 440,446 ----
- case 'r':
- {
- if (gdbm_reorganize (gdbm_file))
- ! gdbm_perror ("Reorganization failed");
- else
- printf ("Reorganization succeeded. \n\n");
- }
- ***************
- *** 369,375 ****
-
- if (temp >= gdbm_file->header->dir_size /4)
- {
- ! printf ("Not a bucket. \n\n");
- break;
- }
- _gdbm_get_bucket (gdbm_file, temp);
- --- 462,468 ----
-
- if (temp >= gdbm_file->header->dir_size /4)
- {
- ! gdbm_perror ("Not a bucket");
- break;
- }
- _gdbm_get_bucket (gdbm_file, temp);
- ***************
- *** 379,385 ****
- case 'C':
- print_bucket (gdbm_file->bucket, "Current bucket");
- printf ("\n current directory entry = %d.\n", gdbm_file->bucket_dir);
- ! printf (" current bucket address = %d.\n\n",
- gdbm_file->cache_entry->ca_adr);
- break;
-
- --- 472,478 ----
- case 'C':
- print_bucket (gdbm_file->bucket, "Current bucket");
- printf ("\n current directory entry = %d.\n", gdbm_file->bucket_dir);
- ! printf (" current bucket address = %ld.\n\n",
- gdbm_file->cache_entry->ca_adr);
- break;
-
- ***************
- *** 392,398 ****
-
- for (temp = 0; temp < gdbm_file->header->dir_size / 4; temp++)
- {
- ! printf (" %10d: %12d\n", temp, gdbm_file->dir[temp]);
- if ( (temp+1) % 20 == 0 && isatty (0))
- {
- printf ("*** CR to continue: ");
- --- 485,491 ----
-
- for (temp = 0; temp < gdbm_file->header->dir_size / 4; temp++)
- {
- ! printf (" %10d: %12ld\n", temp, gdbm_file->dir[temp]);
- if ( (temp+1) % 20 == 0 && isatty (0))
- {
- printf ("*** CR to continue: ");
- ***************
- *** 406,418 ****
- case 'F':
- {
- printf ("\nFile Header: \n\n");
- ! printf (" table = %d\n", gdbm_file->header->dir);
- printf (" table size = %d\n", gdbm_file->header->dir_size);
- printf (" table bits = %d\n", gdbm_file->header->dir_bits);
- printf (" block size = %d\n", gdbm_file->header->block_size);
- printf (" bucket elems = %d\n", gdbm_file->header->bucket_elems);
- printf (" bucket size = %d\n", gdbm_file->header->bucket_size);
- ! printf (" header magic = %x\n", gdbm_file->header->header_magic);
- printf (" next block = %d\n", gdbm_file->header->next_block);
- printf (" avail size = %d\n", gdbm_file->header->avail.size);
- printf (" avail count = %d\n", gdbm_file->header->avail.count);
- --- 499,511 ----
- case 'F':
- {
- printf ("\nFile Header: \n\n");
- ! printf (" table = %ld\n", gdbm_file->header->dir);
- printf (" table size = %d\n", gdbm_file->header->dir_size);
- printf (" table bits = %d\n", gdbm_file->header->dir_bits);
- printf (" block size = %d\n", gdbm_file->header->block_size);
- printf (" bucket elems = %d\n", gdbm_file->header->bucket_elems);
- printf (" bucket size = %d\n", gdbm_file->header->bucket_size);
- ! printf (" header magic = %lx\n", gdbm_file->header->header_magic);
- printf (" next block = %d\n", gdbm_file->header->next_block);
- printf (" avail size = %d\n", gdbm_file->header->avail.size);
- printf (" avail count = %d\n", gdbm_file->header->avail.count);
- ***************
- *** 427,433 ****
- gets (key_line);
- key_data.dptr = key_line;
- key_data.dsize = strlen (key_line)+1;
- ! printf ("hash value = %x. \n\n", _gdbm_hash (key_data));
- key_data.dptr = NULL;
- break;
-
- --- 520,526 ----
- gets (key_line);
- key_data.dptr = key_line;
- key_data.dsize = strlen (key_line)+1;
- ! printf ("hash value = %lx. \n\n", _gdbm_hash (key_data));
- key_data.dptr = NULL;
- break;
-
- diff -cb orig/testndbm.c gdbm/testndbm.c
- *** orig/testndbm.c Sun Jan 19 14:44:38 1992
- --- gdbm/testndbm.c Sun Jan 19 14:43:20 1992
- ***************
- *** 30,36 ****
- --- 30,38 ----
-
- #include <stdio.h>
- #include <sys/types.h>
- + #ifndef OS2
- #include <sys/file.h>
- + #endif /* not OS2 */
- #include <sys/stat.h>
- #ifdef SYSV
- #include <fcntl.h>
- ***************
- *** 50,61 ****
- information. The commands are q (quit), f (fetch), s (store), d (delete),
- 1 (firstkey), n (nextkey) and h (hash function). */
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
-
- ! char cmd_ch;
-
- datum key_data;
- datum data_data;
- --- 52,64 ----
- information. The commands are q (quit), f (fetch), s (store), d (delete),
- 1 (firstkey), n (nextkey) and h (hash function). */
-
- + void
- main (argc, argv)
- int argc;
- char *argv[];
- {
-
- ! int cmd_ch;
-
- datum key_data;
- datum data_data;
- diff -cb orig/update.c gdbm/update.c
- *** orig/update.c Sun Jan 19 14:44:40 1992
- --- gdbm/update.c Thu May 23 20:01:20 1991
- ***************
- *** 31,39 ****
- #include "gdbmdefs.h"
-
-
- /* This procedure writes the header back to the file described by DBF. */
-
- ! static
- write_header (dbf)
- gdbm_file_info *dbf;
- {
- --- 31,44 ----
- #include "gdbmdefs.h"
-
-
- + #ifdef __STDC__
- + static void write_header (gdbm_file_info *dbf);
- + #endif /* __STDC__ */
- +
- +
- /* This procedure writes the header back to the file described by DBF. */
-
- ! static void
- write_header (dbf)
- gdbm_file_info *dbf;
- {
- ***************
- *** 53,58 ****
- --- 58,64 ----
-
- /* After all changes have been made in memory, we now write them
- all to disk. */
- + void
- _gdbm_end_update (dbf)
- gdbm_file_info *dbf;
- {
- ***************
- *** 103,108 ****
- --- 109,115 ----
-
- /* If a fatal error is detected, come here and exit. VAL tells which fatal
- error occured. */
- + void
- _gdbm_fatal (dbf, val)
- gdbm_file_info *dbf;
- char *val;
-