1*40412Sbostic /* 2*40412Sbostic * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 3*40412Sbostic * All rights reserved. 4*40412Sbostic * 5*40412Sbostic * This code is derived from software contributed to Berkeley by 6*40412Sbostic * Adam de Boor. 7*40412Sbostic * 8*40412Sbostic * Redistribution and use in source and binary forms are permitted 9*40412Sbostic * provided that the above copyright notice and this paragraph are 10*40412Sbostic * duplicated in all such forms and that any documentation, 11*40412Sbostic * advertising materials, and other materials related to such 12*40412Sbostic * distribution and use acknowledge that the software was developed 13*40412Sbostic * by the University of California, Berkeley. The name of the 14*40412Sbostic * University may not be used to endorse or promote products derived 15*40412Sbostic * from this software without specific prior written permission. 16*40412Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17*40412Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18*40412Sbostic * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19*40412Sbostic */ 20*40412Sbostic 21*40412Sbostic #ifndef lint 22*40412Sbostic static char sccsid[] = "@(#)lstNext.c 5.2 (Berkeley) 03/11/90"; 23*40412Sbostic #endif /* not lint */ 24*40412Sbostic 2540411Sbostic /*- 2640411Sbostic * LstNext.c -- 2740411Sbostic * Return the next node for a list. 2840411Sbostic * The sequential functions access the list in a slightly different way. 2940411Sbostic * CurPtr points to their idea of the current node in the list and they 3040411Sbostic * access the list based on it. Because the list is circular, Lst_Next 3140411Sbostic * and Lst_Prev will go around the list forever. Lst_IsAtEnd must be 3240411Sbostic * used to determine when to stop. 3340411Sbostic */ 3440411Sbostic 3540411Sbostic #include "lstInt.h" 3640411Sbostic 3740411Sbostic /*- 3840411Sbostic *----------------------------------------------------------------------- 3940411Sbostic * Lst_Next -- 4040411Sbostic * Return the next node for the given list. 4140411Sbostic * 4240411Sbostic * Results: 4340411Sbostic * The next node or NILLNODE if the list has yet to be opened. Also 4440411Sbostic * if the list is non-circular and the end has been reached, NILLNODE 4540411Sbostic * is returned. 4640411Sbostic * 4740411Sbostic * Side Effects: 4840411Sbostic * the curPtr field is updated. 4940411Sbostic * 5040411Sbostic *----------------------------------------------------------------------- 5140411Sbostic */ 5240411Sbostic LstNode 5340411Sbostic Lst_Next (l) 5440411Sbostic Lst l; 5540411Sbostic { 5640411Sbostic register ListNode tln; 5740411Sbostic register List list = (List)l; 5840411Sbostic 5940411Sbostic if ((LstValid (l) == FALSE) || 6040411Sbostic (list->isOpen == FALSE)) { 6140411Sbostic return (NILLNODE); 6240411Sbostic } 6340411Sbostic 6440411Sbostic list->prevPtr = list->curPtr; 6540411Sbostic 6640411Sbostic if (list->curPtr == NilListNode) { 6740411Sbostic if (list->atEnd == Unknown) { 6840411Sbostic /* 6940411Sbostic * If we're just starting out, atEnd will be Unknown. 7040411Sbostic * Then we want to start this thing off in the right 7140411Sbostic * direction -- at the start with atEnd being Middle. 7240411Sbostic */ 7340411Sbostic list->curPtr = tln = list->firstPtr; 7440411Sbostic list->atEnd = Middle; 7540411Sbostic } else { 7640411Sbostic tln = NilListNode; 7740411Sbostic list->atEnd = Tail; 7840411Sbostic } 7940411Sbostic } else { 8040411Sbostic tln = list->curPtr->nextPtr; 8140411Sbostic list->curPtr = tln; 8240411Sbostic 8340411Sbostic if (tln == list->firstPtr || tln == NilListNode) { 8440411Sbostic /* 8540411Sbostic * If back at the front, then we've hit the end... 8640411Sbostic */ 8740411Sbostic list->atEnd = Tail; 8840411Sbostic } else { 8940411Sbostic /* 9040411Sbostic * Reset to Middle if gone past first. 9140411Sbostic */ 9240411Sbostic list->atEnd = Middle; 9340411Sbostic } 9440411Sbostic } 9540411Sbostic 9640411Sbostic return ((LstNode)tln); 9740411Sbostic } 9840411Sbostic 99