1*40411Sbostic /*- 2*40411Sbostic * LstFindFrom.c -- 3*40411Sbostic * Find a node on a list from a given starting point. Used by Lst_Find. 4*40411Sbostic * 5*40411Sbostic * Copyright (c) 1988 by University of California Regents 6*40411Sbostic * 7*40411Sbostic * Permission to use, copy, modify, and distribute this 8*40411Sbostic * software and its documentation for any purpose and without 9*40411Sbostic * fee is hereby granted, provided that the above copyright 10*40411Sbostic * notice appears in all copies. Neither the University of California nor 11*40411Sbostic * Adam de Boor makes any representations about the suitability of this 12*40411Sbostic * software for any purpose. It is provided "as is" without 13*40411Sbostic * express or implied warranty. 14*40411Sbostic */ 15*40411Sbostic #ifndef lint 16*40411Sbostic static char *rcsid = 17*40411Sbostic "$Id: lstFindFrom.c,v 1.6 88/11/17 20:52:37 adam Exp $ SPRITE (Berkeley)"; 18*40411Sbostic #endif lint 19*40411Sbostic 20*40411Sbostic #include "lstInt.h" 21*40411Sbostic 22*40411Sbostic /*- 23*40411Sbostic *----------------------------------------------------------------------- 24*40411Sbostic * Lst_FindFrom -- 25*40411Sbostic * Search for a node starting and ending with the given one on the 26*40411Sbostic * given list using the passed datum and comparison function to 27*40411Sbostic * determine when it has been found. 28*40411Sbostic * 29*40411Sbostic * Results: 30*40411Sbostic * The found node or NILLNODE 31*40411Sbostic * 32*40411Sbostic * Side Effects: 33*40411Sbostic * None. 34*40411Sbostic * 35*40411Sbostic *----------------------------------------------------------------------- 36*40411Sbostic */ 37*40411Sbostic LstNode 38*40411Sbostic Lst_FindFrom (l, ln, d, cProc) 39*40411Sbostic Lst l; 40*40411Sbostic register LstNode ln; 41*40411Sbostic register ClientData d; 42*40411Sbostic register int (*cProc)(); 43*40411Sbostic { 44*40411Sbostic register ListNode tln; 45*40411Sbostic Boolean found = FALSE; 46*40411Sbostic 47*40411Sbostic if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) { 48*40411Sbostic return (NILLNODE); 49*40411Sbostic } 50*40411Sbostic 51*40411Sbostic tln = (ListNode)ln; 52*40411Sbostic 53*40411Sbostic do { 54*40411Sbostic if ((*cProc) (tln->datum, d) == 0) { 55*40411Sbostic found = TRUE; 56*40411Sbostic break; 57*40411Sbostic } else { 58*40411Sbostic tln = tln->nextPtr; 59*40411Sbostic } 60*40411Sbostic } while (tln != (ListNode)ln && tln != NilListNode); 61*40411Sbostic 62*40411Sbostic if (found) { 63*40411Sbostic return ((LstNode)tln); 64*40411Sbostic } else { 65*40411Sbostic return (NILLNODE); 66*40411Sbostic } 67*40411Sbostic } 68*40411Sbostic 69