|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * This code is derived from software contributed to Berkeley by ! 6: * Adam de Boor. ! 7: * ! 8: * Redistribution and use in source and binary forms are permitted ! 9: * provided that: (1) source distributions retain this entire copyright ! 10: * notice and comment, and (2) distributions including binaries display ! 11: * the following acknowledgement: ``This product includes software ! 12: * developed by the University of California, Berkeley and its contributors'' ! 13: * in the documentation or other materials provided with the distribution ! 14: * and in all advertising materials mentioning features or use of this ! 15: * software. Neither the name of the University nor the names of its ! 16: * contributors may be used to endorse or promote products derived ! 17: * from this software without specific prior written permission. ! 18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 19: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 20: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 21: */ ! 22: ! 23: #ifndef lint ! 24: static char sccsid[] = "@(#)lstForEachFrom.c 5.3 (Berkeley) 6/1/90"; ! 25: #endif /* not lint */ ! 26: ! 27: /*- ! 28: * lstForEachFrom.c -- ! 29: * Perform a given function on all elements of a list starting from ! 30: * a given point. ! 31: */ ! 32: ! 33: #include "lstInt.h" ! 34: ! 35: /*- ! 36: *----------------------------------------------------------------------- ! 37: * Lst_ForEachFrom -- ! 38: * Apply the given function to each element of the given list. The ! 39: * function should return 0 if traversal should continue and non- ! 40: * zero if it should abort. ! 41: * ! 42: * Results: ! 43: * None. ! 44: * ! 45: * Side Effects: ! 46: * Only those created by the passed-in function. ! 47: * ! 48: *----------------------------------------------------------------------- ! 49: */ ! 50: /*VARARGS2*/ ! 51: void ! 52: Lst_ForEachFrom (l, ln, proc, d) ! 53: Lst l; ! 54: LstNode ln; ! 55: register int (*proc)(); ! 56: register ClientData d; ! 57: { ! 58: register ListNode tln = (ListNode)ln; ! 59: register List list = (List)l; ! 60: register ListNode next; ! 61: Boolean done; ! 62: int result; ! 63: ! 64: if (!LstValid (list) || LstIsEmpty (list)) { ! 65: return; ! 66: } ! 67: ! 68: do { ! 69: /* ! 70: * Take care of having the current element deleted out from under ! 71: * us. ! 72: */ ! 73: ! 74: next = tln->nextPtr; ! 75: ! 76: tln->useCount++; ! 77: result = (*proc) (tln->datum, d); ! 78: tln->useCount--; ! 79: ! 80: /* ! 81: * We're done with the traversal if ! 82: * - nothing's been added after the current node and ! 83: * - the next node to examine is the first in the queue or ! 84: * doesn't exist. ! 85: */ ! 86: done = (next == tln->nextPtr && ! 87: (next == NilListNode || next == list->firstPtr)); ! 88: ! 89: next = tln->nextPtr; ! 90: ! 91: if (tln->flags & LN_DELETED) { ! 92: free((char *)tln); ! 93: } ! 94: tln = next; ! 95: } while (!result && !LstIsEmpty(list) && !done); ! 96: ! 97: } ! 98:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.