1 /*
2  * Copyright (c) 1988, 1989, 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Adam de Boor.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)lstFindFrom.c	8.2 (Berkeley) 04/28/95";
13 #endif /* not lint */
14 
15 /*-
16  * LstFindFrom.c --
17  *	Find a node on a list from a given starting point. Used by Lst_Find.
18  */
19 
20 #include	"lstInt.h"
21 
22 /*-
23  *-----------------------------------------------------------------------
24  * Lst_FindFrom --
25  *	Search for a node starting and ending with the given one on the
26  *	given list using the passed datum and comparison function to
27  *	determine when it has been found.
28  *
29  * Results:
30  *	The found node or NILLNODE
31  *
32  * Side Effects:
33  *	None.
34  *
35  *-----------------------------------------------------------------------
36  */
37 LstNode
Lst_FindFrom(l,ln,d,cProc)38 Lst_FindFrom (l, ln, d, cProc)
39     Lst		      	l;
40     register LstNode    ln;
41     register ClientData d;
42     register int	(*cProc) __P((ClientData, ClientData));
43 {
44     register ListNode	tln;
45     Boolean		found = FALSE;
46 
47     if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) {
48 	return (NILLNODE);
49     }
50 
51     tln = (ListNode)ln;
52 
53     do {
54 	if ((*cProc) (tln->datum, d) == 0) {
55 	    found = TRUE;
56 	    break;
57 	} else {
58 	    tln = tln->nextPtr;
59 	}
60     } while (tln != (ListNode)ln && tln != NilListNode);
61 
62     if (found) {
63 	return ((LstNode)tln);
64     } else {
65 	return (NILLNODE);
66     }
67 }
68 
69