140412Sbostic /*
262085Sbostic * Copyright (c) 1988, 1989, 1990, 1993
362085Sbostic * The Regents of the University of California. All rights reserved.
440411Sbostic *
540412Sbostic * This code is derived from software contributed to Berkeley by
640412Sbostic * Adam de Boor.
740411Sbostic *
842741Sbostic * %sccs.include.redist.c%
940411Sbostic */
1040412Sbostic
1140411Sbostic #ifndef lint
12*69094Schristos static char sccsid[] = "@(#)lstFindFrom.c 8.2 (Berkeley) 04/28/95";
1340412Sbostic #endif /* not lint */
1440411Sbostic
1540412Sbostic /*-
1640412Sbostic * LstFindFrom.c --
1740412Sbostic * Find a node on a list from a given starting point. Used by Lst_Find.
1840412Sbostic */
1940412Sbostic
2040411Sbostic #include "lstInt.h"
2140411Sbostic
2240411Sbostic /*-
2340411Sbostic *-----------------------------------------------------------------------
2440411Sbostic * Lst_FindFrom --
2540411Sbostic * Search for a node starting and ending with the given one on the
2640411Sbostic * given list using the passed datum and comparison function to
2740411Sbostic * determine when it has been found.
2840411Sbostic *
2940411Sbostic * Results:
3040411Sbostic * The found node or NILLNODE
3140411Sbostic *
3240411Sbostic * Side Effects:
3340411Sbostic * None.
3440411Sbostic *
3540411Sbostic *-----------------------------------------------------------------------
3640411Sbostic */
3740411Sbostic LstNode
Lst_FindFrom(l,ln,d,cProc)3840411Sbostic Lst_FindFrom (l, ln, d, cProc)
3940411Sbostic Lst l;
4040411Sbostic register LstNode ln;
4140411Sbostic register ClientData d;
42*69094Schristos register int (*cProc) __P((ClientData, ClientData));
4340411Sbostic {
4440411Sbostic register ListNode tln;
4540411Sbostic Boolean found = FALSE;
4640411Sbostic
4740411Sbostic if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) {
4840411Sbostic return (NILLNODE);
4940411Sbostic }
5040411Sbostic
5140411Sbostic tln = (ListNode)ln;
5240411Sbostic
5340411Sbostic do {
5440411Sbostic if ((*cProc) (tln->datum, d) == 0) {
5540411Sbostic found = TRUE;
5640411Sbostic break;
5740411Sbostic } else {
5840411Sbostic tln = tln->nextPtr;
5940411Sbostic }
6040411Sbostic } while (tln != (ListNode)ln && tln != NilListNode);
6140411Sbostic
6240411Sbostic if (found) {
6340411Sbostic return ((LstNode)tln);
6440411Sbostic } else {
6540411Sbostic return (NILLNODE);
6640411Sbostic }
6740411Sbostic }
6840411Sbostic
69