150276Speter/* $NetBSD: lstOpen.c,v 1.12 2008/12/13 15:19:29 dsl Exp $ */ 2166124Srafan 350276Speter/* 450276Speter * Copyright (c) 1988, 1989, 1990, 1993 550276Speter * The Regents of the University of California. All rights reserved. 650276Speter * 750276Speter * This code is derived from software contributed to Berkeley by 850276Speter * Adam de Boor. 950276Speter * 1050276Speter * Redistribution and use in source and binary forms, with or without 1150276Speter * modification, are permitted provided that the following conditions 1250276Speter * are met: 1350276Speter * 1. Redistributions of source code must retain the above copyright 1450276Speter * notice, this list of conditions and the following disclaimer. 1550276Speter * 2. Redistributions in binary form must reproduce the above copyright 1650276Speter * notice, this list of conditions and the following disclaimer in the 1750276Speter * documentation and/or other materials provided with the distribution. 1850276Speter * 3. Neither the name of the University nor the names of its contributors 1950276Speter * may be used to endorse or promote products derived from this software 2050276Speter * without specific prior written permission. 2150276Speter * 2250276Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2350276Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2450276Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2550276Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2650276Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2750276Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2850276Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2950276Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30166124Srafan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3150276Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3250276Speter * SUCH DAMAGE. 3350276Speter */ 3450276Speter 35166124Srafan#ifndef MAKE_NATIVE 3650276Speterstatic char rcsid[] = "$NetBSD: lstOpen.c,v 1.12 2008/12/13 15:19:29 dsl Exp $"; 3750276Speter#else 3850276Speter#include <sys/cdefs.h> 3950276Speter#ifndef lint 4050276Speter#if 0 4150276Speterstatic char sccsid[] = "@(#)lstOpen.c 8.1 (Berkeley) 6/6/93"; 4250276Speter#else 4350276Speter__RCSID("$NetBSD: lstOpen.c,v 1.12 2008/12/13 15:19:29 dsl Exp $"); 4450276Speter#endif 4550276Speter#endif /* not lint */ 4676726Speter#endif 47166124Srafan 4850276Speter/*- 49166124Srafan * LstOpen.c -- 50166124Srafan * Open a list for sequential access. The sequential functions access the 51166124Srafan * list in a slightly different way. CurPtr points to their idea of the 5250276Speter * current node in the list and they access the list based on it. 5350276Speter * If the list is circular, Lst_Next and Lst_Prev will go around 5450276Speter * the list forever. Lst_IsAtEnd must be used to determine when to stop. 5550276Speter */ 5650276Speter 5750276Speter#include "lstInt.h" 5850276Speter 5950276Speter/*- 6050276Speter *----------------------------------------------------------------------- 6150276Speter * Lst_Open -- 6250276Speter * Open a list for sequential access. A list can still be searched, 6350276Speter * etc., without confusing these functions. 6450276Speter * 6576726Speter * Results: 66166124Srafan * SUCCESS or FAILURE. 6750276Speter * 68166124Srafan * Side Effects: 69166124Srafan * isOpen is set TRUE and curPtr is set to NULL so the 7050276Speter * other sequential functions no it was just opened and can choose 7150276Speter * the first element accessed based on this. 7250276Speter * 73 *----------------------------------------------------------------------- 74 */ 75ReturnStatus 76Lst_Open(Lst l) 77{ 78 if (LstValid (l) == FALSE) { 79 return (FAILURE); 80 } 81 (l)->isOpen = TRUE; 82 (l)->atEnd = LstIsEmpty (l) ? Head : Unknown; 83 (l)->curPtr = NULL; 84 85 return (SUCCESS); 86} 87 88