Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

ll_iter.c

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu>
00003 **
00004 ** This library is free software; you can redistribute it and/or
00005 ** modify it under the terms of the GNU Library General Public
00006 ** License as published by the Free Software Foundation; either
00007 ** version 2 of the License, or (at your option) any later version.
00008 **
00009 ** This library is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 ** Library General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU Library General Public
00015 ** License along with this library; if not, write to the Free
00016 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00017 ** MA 02111-1307, USA
00018 **
00019 ** @(#)$Id: ll_iter.c,v 1.6 2006/07/13 05:36:16 klmitch Exp $
00020 */
00028 #include "dbprim.h"
00029 #include "dbprim_int.h"
00030 
00031 RCSTAG("@(#)$Id: ll_iter.c,v 1.6 2006/07/13 05:36:16 klmitch Exp $");
00032 
00033 unsigned long
00034 ll_iter(link_head_t *list, link_elem_t *start,
00035         link_iter_t iter_func, void *extra, unsigned long flags)
00036 {
00037   unsigned long retval;
00038   link_elem_t *elem, *next = 0;
00039 
00040   initialize_dbpr_error_table(); /* initialize error table */
00041 
00042   /* verify arguments */
00043   if (!ll_verify(list) || (start && !le_verify(start)) || !iter_func)
00044     return DB_ERR_BADARGS;
00045 
00046   /* If the start element is specified, check that it's in this list... */
00047   if (start && list != start->le_head)
00048     return DB_ERR_WRONGTABLE;
00049 
00050   /* select the starting element */
00051   if (!start)
00052     start = (flags & DB_FLAG_REVERSE) ? list->lh_last : list->lh_first;
00053 
00054   /* Walk through list and return first non-zero return value */
00055   for (elem = start; elem; elem = next) {
00056     next = (flags & DB_FLAG_REVERSE) ? elem->le_prev : elem->le_next;
00057     if ((retval = (*iter_func)(list, elem, extra)))
00058       return retval;
00059   }
00060 
00061   return 0;
00062 }

Generated on Sat Jul 15 14:10:33 2006 for DatabasePrimitivesLibrary by  doxygen 1.4.4