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

  1. /* seq.c - This is the sequential visit of the database.  This defines two
  2.    user-visable routines that are used together. This is the DBM 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. /* Start the visit of all keys in the database.  This produces something in
  36.    hash order, not in any sorted order.  */
  37.  
  38. datum
  39. firstkey ()
  40. {
  41.   datum ret_val;
  42.  
  43.   /* Free previous dynamic memory, do actual call, and save pointer to new
  44.      memory. */
  45.   ret_val = gdbm_firstkey (_gdbm_file);
  46.   if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr);
  47.   _gdbm_memory = ret_val;
  48.  
  49.   /* Return the new value. */
  50.   return ret_val;
  51. }
  52.  
  53.  
  54. /* Continue visiting all keys.  The next key following KEY is returned. */
  55.  
  56. datum
  57. nextkey (key)
  58.      datum key;
  59. {
  60.   datum ret_val;
  61.  
  62.   /* Make sure we have a valid key. */
  63.   if (key.dptr == NULL)
  64.     return key;
  65.  
  66.   /* Call gdbm nextkey with supplied value. After that, free the old value. */
  67.   ret_val = gdbm_nextkey (_gdbm_file, key);
  68.   if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr);
  69.   _gdbm_memory = ret_val;
  70.  
  71.   /* Return the new value. */
  72.   return ret_val;
  73. }
  74.  
  75.