1 /* 2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Adam de Boor. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the University of California, Berkeley. The name of the 14 * University may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 */ 20 21 #ifndef lint 22 static char sccsid[] = "@(#)lstOpen.c 5.2 (Berkeley) 03/11/90"; 23 #endif /* not lint */ 24 25 /*- 26 * LstOpen.c -- 27 * Open a list for sequential access. The sequential functions access the 28 * list in a slightly different way. CurPtr points to their idea of the 29 * current node in the list and they access the list based on it. 30 * If the list is circular, Lst_Next and Lst_Prev will go around 31 * the list forever. Lst_IsAtEnd must be used to determine when to stop. 32 */ 33 34 #include "lstInt.h" 35 36 /*- 37 *----------------------------------------------------------------------- 38 * Lst_Open -- 39 * Open a list for sequential access. A list can still be searched, 40 * etc., without confusing these functions. 41 * 42 * Results: 43 * SUCCESS or FAILURE. 44 * 45 * Side Effects: 46 * isOpen is set TRUE and curPtr is set to NilListNode so the 47 * other sequential functions no it was just opened and can choose 48 * the first element accessed based on this. 49 * 50 *----------------------------------------------------------------------- 51 */ 52 ReturnStatus 53 Lst_Open (l) 54 register Lst l; 55 { 56 if (LstValid (l) == FALSE) { 57 return (FAILURE); 58 } 59 ((List) l)->isOpen = TRUE; 60 ((List) l)->atEnd = LstIsEmpty (l) ? Head : Unknown; 61 ((List) l)->curPtr = NilListNode; 62 63 return (SUCCESS); 64 } 65 66