1*40411Sbostic /*-
2*40411Sbostic  * lstIndex.c --
3*40411Sbostic  *	Function to return the index of a datum in a Lst.
4*40411Sbostic  *
5*40411Sbostic  * Copyright (c) 1988 by the Regents of the University of California
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.  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  *
16*40411Sbostic  */
17*40411Sbostic #ifndef lint
18*40411Sbostic static char *rcsid =
19*40411Sbostic "$Id: lstIndex.c,v 1.2 88/11/17 20:52:54 adam Exp $ SPRITE (Berkeley)";
20*40411Sbostic #endif lint
21*40411Sbostic 
22*40411Sbostic #include    "lstInt.h"
23*40411Sbostic 
24*40411Sbostic /*-
25*40411Sbostic  *-----------------------------------------------------------------------
26*40411Sbostic  * Lst_Index --
27*40411Sbostic  *	Return the index of a datum in a Lst. Indices start at 0.
28*40411Sbostic  *
29*40411Sbostic  * Results:
30*40411Sbostic  *	Returns -1 if the datum isn't in the Lst, or the index of
31*40411Sbostic  *	the datum if it is.
32*40411Sbostic  *
33*40411Sbostic  * Side Effects:
34*40411Sbostic  *	None.
35*40411Sbostic  *
36*40411Sbostic  *-----------------------------------------------------------------------
37*40411Sbostic  */
38*40411Sbostic int
39*40411Sbostic Lst_Index(l, d)
40*40411Sbostic     Lst	    	  	l;
41*40411Sbostic     ClientData	  	d;
42*40411Sbostic {
43*40411Sbostic     List    	  	list = (List)l;
44*40411Sbostic     register ListNode	lNode;
45*40411Sbostic     register int  	index;
46*40411Sbostic 
47*40411Sbostic     lNode = list->firstPtr;
48*40411Sbostic 
49*40411Sbostic     if (lNode == NilListNode) {
50*40411Sbostic 	return(-1);
51*40411Sbostic     }
52*40411Sbostic 
53*40411Sbostic     index = 0;
54*40411Sbostic 
55*40411Sbostic     do {
56*40411Sbostic 	if (lNode->datum == d) {
57*40411Sbostic 	    return(index);
58*40411Sbostic 	} else {
59*40411Sbostic 	    lNode = lNode->nextPtr;
60*40411Sbostic 	    index += 1;
61*40411Sbostic 	}
62*40411Sbostic     } while (lNode != NilListNode && lNode != list->firstPtr);
63*40411Sbostic     return(-1);
64*40411Sbostic }
65