home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / dbmseq.c < prev    next >
C/C++ Source or Header  |  1991-05-23  |  2KB  |  79 lines

  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  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 1, 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:  phil@cs.wwu.edu
  23.       us-mail:  Philip A. Nelson
  24.                 Computer Science Department
  25.                 Western Washington University
  26.                 Bellingham, WA 98226
  27.         phone:  (206) 676-3035
  28.  
  29. *************************************************************************/
  30.  
  31.  
  32. #include "gdbmdefs.h"
  33. #include "extern.h"
  34.  
  35.  
  36. /* NDBM Start the visit of all keys in the database.  This produces
  37.    something in hash order, not in any sorted order.  DBF is the dbm file
  38.    information pointer. */
  39.  
  40. datum
  41. dbm_firstkey (dbf)
  42.      gdbm_file_info *dbf;
  43. {
  44.   datum ret_val;
  45.  
  46.   /* Free previous dynamic memory, do actual call, and save pointer to new
  47.      memory. */
  48.   ret_val = gdbm_firstkey (dbf);
  49.   if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr);
  50.   _gdbm_memory = ret_val;
  51.  
  52.   /* Return the new value. */
  53.   return ret_val;
  54. }
  55.  
  56.  
  57. /* NDBM Continue visiting all keys.  The next key in the sequence is returned.
  58.    DBF is the file information pointer. */
  59.  
  60. datum
  61. dbm_nextkey (dbf)
  62.      gdbm_file_info *dbf;
  63. {
  64.   datum ret_val;
  65.  
  66.   /* Make sure we have a valid key. */
  67.   if (_gdbm_memory.dptr == NULL)
  68.     return _gdbm_memory;
  69.  
  70.   /* Call gdbm nextkey with the old value. After that, free the old value. */
  71.   ret_val = gdbm_nextkey (dbf,_gdbm_memory);
  72.   if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr);
  73.   _gdbm_memory = ret_val;
  74.  
  75.   /* Return the new value. */
  76.   return ret_val;
  77. }
  78.  
  79.