1*40412Sbostic /*
2*40412Sbostic  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
3*40412Sbostic  * All rights reserved.
440411Sbostic  *
5*40412Sbostic  * This code is derived from software contributed to Berkeley by
6*40412Sbostic  * Adam de Boor.
740411Sbostic  *
8*40412Sbostic  * Redistribution and use in source and binary forms are permitted
9*40412Sbostic  * provided that the above copyright notice and this paragraph are
10*40412Sbostic  * duplicated in all such forms and that any documentation,
11*40412Sbostic  * advertising materials, and other materials related to such
12*40412Sbostic  * distribution and use acknowledge that the software was developed
13*40412Sbostic  * by the University of California, Berkeley.  The name of the
14*40412Sbostic  * University may not be used to endorse or promote products derived
15*40412Sbostic  * from this software without specific prior written permission.
16*40412Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17*40412Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18*40412Sbostic  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1940411Sbostic  */
20*40412Sbostic 
2140411Sbostic #ifndef lint
22*40412Sbostic static char sccsid[] = "@(#)lstFindFrom.c	5.2 (Berkeley) 03/11/90";
23*40412Sbostic #endif /* not lint */
2440411Sbostic 
25*40412Sbostic /*-
26*40412Sbostic  * LstFindFrom.c --
27*40412Sbostic  *	Find a node on a list from a given starting point. Used by Lst_Find.
28*40412Sbostic  */
29*40412Sbostic 
3040411Sbostic #include	"lstInt.h"
3140411Sbostic 
3240411Sbostic /*-
3340411Sbostic  *-----------------------------------------------------------------------
3440411Sbostic  * Lst_FindFrom --
3540411Sbostic  *	Search for a node starting and ending with the given one on the
3640411Sbostic  *	given list using the passed datum and comparison function to
3740411Sbostic  *	determine when it has been found.
3840411Sbostic  *
3940411Sbostic  * Results:
4040411Sbostic  *	The found node or NILLNODE
4140411Sbostic  *
4240411Sbostic  * Side Effects:
4340411Sbostic  *	None.
4440411Sbostic  *
4540411Sbostic  *-----------------------------------------------------------------------
4640411Sbostic  */
4740411Sbostic LstNode
4840411Sbostic Lst_FindFrom (l, ln, d, cProc)
4940411Sbostic     Lst		      	l;
5040411Sbostic     register LstNode    ln;
5140411Sbostic     register ClientData d;
5240411Sbostic     register int	(*cProc)();
5340411Sbostic {
5440411Sbostic     register ListNode	tln;
5540411Sbostic     Boolean		found = FALSE;
5640411Sbostic 
5740411Sbostic     if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) {
5840411Sbostic 	return (NILLNODE);
5940411Sbostic     }
6040411Sbostic 
6140411Sbostic     tln = (ListNode)ln;
6240411Sbostic 
6340411Sbostic     do {
6440411Sbostic 	if ((*cProc) (tln->datum, d) == 0) {
6540411Sbostic 	    found = TRUE;
6640411Sbostic 	    break;
6740411Sbostic 	} else {
6840411Sbostic 	    tln = tln->nextPtr;
6940411Sbostic 	}
7040411Sbostic     } while (tln != (ListNode)ln && tln != NilListNode);
7140411Sbostic 
7240411Sbostic     if (found) {
7340411Sbostic 	return ((LstNode)tln);
7440411Sbostic     } else {
7540411Sbostic 	return (NILLNODE);
7640411Sbostic     }
7740411Sbostic }
7840411Sbostic 
79