xref: /csrg-svn/usr.bin/make/lst.lib/lstPrev.c (revision 40411)
1*40411Sbostic /*-
2*40411Sbostic  * LstPrev.c --
3*40411Sbostic  *	Get the node previous to the current one in the list and make it the
4*40411Sbostic  *	current node.
5*40411Sbostic  *	The sequential functions access the list in a slightly different way.
6*40411Sbostic  *	CurPtr points to their idea of the current node in the list and they
7*40411Sbostic  *	access the list based on it. Because the list is circular, Lst_Next
8*40411Sbostic  *	and Lst_Prev will go around the list forever. Lst_IsAtEnd must be
9*40411Sbostic  *	used to determine when to stop.
10*40411Sbostic  *
11*40411Sbostic  * Copyright (c) 1988 by University of California Regents
12*40411Sbostic  *
13*40411Sbostic  * Permission to use, copy, modify, and distribute this
14*40411Sbostic  * software and its documentation for any purpose and without
15*40411Sbostic  * fee is hereby granted, provided that the above copyright
16*40411Sbostic  * notice appears in all copies.  Neither the University of California nor
17*40411Sbostic  * Adam de Boor makes any representations about the suitability of this
18*40411Sbostic  * software for any purpose.  It is provided "as is" without
19*40411Sbostic  * express or implied warranty.
20*40411Sbostic  */
21*40411Sbostic #ifndef lint
22*40411Sbostic static char *rcsid =
23*40411Sbostic "$Id: lstPrev.c,v 1.8 88/11/17 20:53:54 adam Exp $ SPRITE (Berkeley)";
24*40411Sbostic #endif lint
25*40411Sbostic 
26*40411Sbostic #include	"lstInt.h"
27*40411Sbostic 
28*40411Sbostic /*-
29*40411Sbostic  *-----------------------------------------------------------------------
30*40411Sbostic  * Lst_Prev --
31*40411Sbostic  *	Return the node previous to the current one for the given list.
32*40411Sbostic  *
33*40411Sbostic  * Results:
34*40411Sbostic  *	The previous node or NILLNODE if the list hasn't been opened
35*40411Sbostic  *	yet or the beginning was reached.
36*40411Sbostic  *
37*40411Sbostic  * Side Effects:
38*40411Sbostic  *	the curPtr is changed to reflect reality.
39*40411Sbostic  *
40*40411Sbostic  *-----------------------------------------------------------------------
41*40411Sbostic  */
42*40411Sbostic LstNode
43*40411Sbostic Lst_Prev (l)
44*40411Sbostic     Lst	    	  	l;
45*40411Sbostic {
46*40411Sbostic     register ListNode	tln;
47*40411Sbostic     register List 	list = (List)l;
48*40411Sbostic 
49*40411Sbostic     if ((LstValid (l) == FALSE) ||
50*40411Sbostic 	(list->isOpen == FALSE)) {
51*40411Sbostic 	    return (NILLNODE);
52*40411Sbostic     }
53*40411Sbostic 
54*40411Sbostic     list->prevPtr = list->curPtr;
55*40411Sbostic 
56*40411Sbostic     if (list->curPtr == NilListNode) {
57*40411Sbostic 	if (list->atEnd == Unknown) {
58*40411Sbostic 	    list->curPtr = tln = list->lastPtr;
59*40411Sbostic 	    list->atEnd = Middle;
60*40411Sbostic 	} else {
61*40411Sbostic 	    tln = NilListNode;
62*40411Sbostic 	    list->atEnd = Head;
63*40411Sbostic 	}
64*40411Sbostic     } else {
65*40411Sbostic 	tln = list->curPtr->prevPtr;
66*40411Sbostic 	list->curPtr = tln;
67*40411Sbostic 	if (tln == list->lastPtr || tln == NilListNode) {
68*40411Sbostic 	    list->atEnd = Head;
69*40411Sbostic 	} else {
70*40411Sbostic 	    list->atEnd = Middle;
71*40411Sbostic 	}
72*40411Sbostic     }
73*40411Sbostic 
74*40411Sbostic     return ((LstNode)tln);
75*40411Sbostic }
76*40411Sbostic 
77