1 | /* dbmseq.c - Visit all elements in the database. This is the NDBM
|
---|
2 | interface. */
|
---|
3 |
|
---|
4 | /* This file is part of GDBM, the GNU data base manager, by Philip A. Nelson.
|
---|
5 | Copyright (C) 1990, 1991, 1993 Free Software Foundation, Inc.
|
---|
6 |
|
---|
7 | GDBM is free software; you can redistribute it and/or modify
|
---|
8 | it under the terms of the GNU General Public License as published by
|
---|
9 | the Free Software Foundation; either version 2, or (at your option)
|
---|
10 | any later version.
|
---|
11 |
|
---|
12 | GDBM is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with GDBM; see the file COPYING. If not, write to
|
---|
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
20 |
|
---|
21 | You may contact the author by:
|
---|
22 | e-mail: [email protected]
|
---|
23 | us-mail: Philip A. Nelson
|
---|
24 | Computer Science Department
|
---|
25 | Western Washington University
|
---|
26 | Bellingham, WA 98226
|
---|
27 |
|
---|
28 | *************************************************************************/
|
---|
29 |
|
---|
30 |
|
---|
31 | /* include system configuration before all else. */
|
---|
32 | #include "autoconf.h"
|
---|
33 |
|
---|
34 | #include "gdbmdefs.h"
|
---|
35 | #include "extern.h"
|
---|
36 |
|
---|
37 |
|
---|
38 | /* NDBM Start the visit of all keys in the database. This produces
|
---|
39 | something in hash order, not in any sorted order. DBF is the dbm file
|
---|
40 | information pointer. */
|
---|
41 |
|
---|
42 | datum
|
---|
43 | dbm_firstkey (dbf)
|
---|
44 | gdbm_file_info *dbf;
|
---|
45 | {
|
---|
46 | datum ret_val;
|
---|
47 |
|
---|
48 | /* Free previous dynamic memory, do actual call, and save pointer to new
|
---|
49 | memory. */
|
---|
50 | ret_val = gdbm_firstkey (dbf);
|
---|
51 | if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr);
|
---|
52 | _gdbm_memory = ret_val;
|
---|
53 |
|
---|
54 | /* Return the new value. */
|
---|
55 | return ret_val;
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | /* NDBM Continue visiting all keys. The next key in the sequence is returned.
|
---|
60 | DBF is the file information pointer. */
|
---|
61 |
|
---|
62 | datum
|
---|
63 | dbm_nextkey (dbf)
|
---|
64 | gdbm_file_info *dbf;
|
---|
65 | {
|
---|
66 | datum ret_val;
|
---|
67 |
|
---|
68 | /* Make sure we have a valid key. */
|
---|
69 | if (_gdbm_memory.dptr == NULL)
|
---|
70 | return _gdbm_memory;
|
---|
71 |
|
---|
72 | /* Call gdbm nextkey with the old value. After that, free the old value. */
|
---|
73 | ret_val = gdbm_nextkey (dbf,_gdbm_memory);
|
---|
74 | if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr);
|
---|
75 | _gdbm_memory = ret_val;
|
---|
76 |
|
---|
77 | /* Return the new value. */
|
---|
78 | return ret_val;
|
---|
79 | }
|
---|
80 |
|
---|