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 the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the University of California, Berkeley. The name of the 14 * University may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 */ 20 21 #ifndef lint 22 static char sccsid[] = "@(#)lstFindFrom.c 5.2 (Berkeley) 03/11/90"; 23 #endif /* not lint */ 24 25 /*- 26 * LstFindFrom.c -- 27 * Find a node on a list from a given starting point. Used by Lst_Find. 28 */ 29 30 #include "lstInt.h" 31 32 /*- 33 *----------------------------------------------------------------------- 34 * Lst_FindFrom -- 35 * Search for a node starting and ending with the given one on the 36 * given list using the passed datum and comparison function to 37 * determine when it has been found. 38 * 39 * Results: 40 * The found node or NILLNODE 41 * 42 * Side Effects: 43 * None. 44 * 45 *----------------------------------------------------------------------- 46 */ 47 LstNode 48 Lst_FindFrom (l, ln, d, cProc) 49 Lst l; 50 register LstNode ln; 51 register ClientData d; 52 register int (*cProc)(); 53 { 54 register ListNode tln; 55 Boolean found = FALSE; 56 57 if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) { 58 return (NILLNODE); 59 } 60 61 tln = (ListNode)ln; 62 63 do { 64 if ((*cProc) (tln->datum, d) == 0) { 65 found = TRUE; 66 break; 67 } else { 68 tln = tln->nextPtr; 69 } 70 } while (tln != (ListNode)ln && tln != NilListNode); 71 72 if (found) { 73 return ((LstNode)tln); 74 } else { 75 return (NILLNODE); 76 } 77 } 78 79