xref: /original-bsd/usr.bin/make/lst.lib/lstOpen.c (revision 27393bdf)
1 /*
2  * Copyright (c) 1988, 1989, 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Adam de Boor.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)lstOpen.c	8.2 (Berkeley) 04/28/95";
13 #endif /* not lint */
14 
15 /*-
16  * LstOpen.c --
17  *	Open a list for sequential access. The sequential functions access the
18  *	list in a slightly different way. CurPtr points to their idea of the
19  *	current node in the list and they access the list based on it.
20  *	If the list is circular, Lst_Next and Lst_Prev will go around
21  *	the list forever. Lst_IsAtEnd must be used to determine when to stop.
22  */
23 
24 #include	"lstInt.h"
25 
26 /*-
27  *-----------------------------------------------------------------------
28  * Lst_Open --
29  *	Open a list for sequential access. A list can still be searched,
30  *	etc., without confusing these functions.
31  *
32  * Results:
33  *	SUCCESS or FAILURE.
34  *
35  * Side Effects:
36  *	isOpen is set TRUE and curPtr is set to NilListNode so the
37  *	other sequential functions no it was just opened and can choose
38  *	the first element accessed based on this.
39  *
40  *-----------------------------------------------------------------------
41  */
42 ReturnStatus
43 Lst_Open (l)
44 	register Lst	l;
45 {
46 	if (LstValid (l) == FALSE) {
47 		return (FAILURE);
48 	}
49 	((List) l)->isOpen = TRUE;
50 	((List) l)->atEnd = LstIsEmpty (l) ? Head : Unknown;
51 	((List) l)->curPtr = NilListNode;
52 
53 	return (SUCCESS);
54 }
55 
56