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[] = "@(#)lstNext.c 8.2 (Berkeley) 04/28/95"; 13 #endif /* not lint */ 14 15 /*- 16 * LstNext.c -- 17 * Return the next node for a list. 18 * The sequential functions access the list in a slightly different way. 19 * CurPtr points to their idea of the current node in the list and they 20 * access the list based on it. Because the list is circular, Lst_Next 21 * and Lst_Prev will go around the list forever. Lst_IsAtEnd must be 22 * used to determine when to stop. 23 */ 24 25 #include "lstInt.h" 26 27 /*- 28 *----------------------------------------------------------------------- 29 * Lst_Next -- 30 * Return the next node for the given list. 31 * 32 * Results: 33 * The next node or NILLNODE if the list has yet to be opened. Also 34 * if the list is non-circular and the end has been reached, NILLNODE 35 * is returned. 36 * 37 * Side Effects: 38 * the curPtr field is updated. 39 * 40 *----------------------------------------------------------------------- 41 */ 42 LstNode 43 Lst_Next (l) 44 Lst l; 45 { 46 register ListNode tln; 47 register List list = (List)l; 48 49 if ((LstValid (l) == FALSE) || 50 (list->isOpen == FALSE)) { 51 return (NILLNODE); 52 } 53 54 list->prevPtr = list->curPtr; 55 56 if (list->curPtr == NilListNode) { 57 if (list->atEnd == Unknown) { 58 /* 59 * If we're just starting out, atEnd will be Unknown. 60 * Then we want to start this thing off in the right 61 * direction -- at the start with atEnd being Middle. 62 */ 63 list->curPtr = tln = list->firstPtr; 64 list->atEnd = Middle; 65 } else { 66 tln = NilListNode; 67 list->atEnd = Tail; 68 } 69 } else { 70 tln = list->curPtr->nextPtr; 71 list->curPtr = tln; 72 73 if (tln == list->firstPtr || tln == NilListNode) { 74 /* 75 * If back at the front, then we've hit the end... 76 */ 77 list->atEnd = Tail; 78 } else { 79 /* 80 * Reset to Middle if gone past first. 81 */ 82 list->atEnd = Middle; 83 } 84 } 85 86 return ((LstNode)tln); 87 } 88 89