1236769Sobrien/* $NetBSD: lstInt.h,v 1.20 2009/01/24 14:43:29 dsl Exp $ */ 2236769Sobrien 3236769Sobrien/* 4236769Sobrien * Copyright (c) 1988, 1989, 1990, 1993 5236769Sobrien * The Regents of the University of California. All rights reserved. 6236769Sobrien * 7236769Sobrien * This code is derived from software contributed to Berkeley by 8236769Sobrien * Adam de Boor. 9236769Sobrien * 10236769Sobrien * Redistribution and use in source and binary forms, with or without 11236769Sobrien * modification, are permitted provided that the following conditions 12236769Sobrien * are met: 13236769Sobrien * 1. Redistributions of source code must retain the above copyright 14236769Sobrien * notice, this list of conditions and the following disclaimer. 15236769Sobrien * 2. Redistributions in binary form must reproduce the above copyright 16236769Sobrien * notice, this list of conditions and the following disclaimer in the 17236769Sobrien * documentation and/or other materials provided with the distribution. 18236769Sobrien * 3. Neither the name of the University nor the names of its contributors 19236769Sobrien * may be used to endorse or promote products derived from this software 20236769Sobrien * without specific prior written permission. 21236769Sobrien * 22236769Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23236769Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24236769Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25236769Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26236769Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27236769Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28236769Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29236769Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30236769Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31236769Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32236769Sobrien * SUCH DAMAGE. 33236769Sobrien * 34236769Sobrien * from: @(#)lstInt.h 8.1 (Berkeley) 6/6/93 35236769Sobrien */ 36236769Sobrien 37236769Sobrien/*- 38236769Sobrien * lstInt.h -- 39236769Sobrien * Internals for the list library 40236769Sobrien */ 41236769Sobrien#ifndef _LSTINT_H_ 42236769Sobrien#define _LSTINT_H_ 43236769Sobrien 44236769Sobrien#include "../lst.h" 45236769Sobrien#include "../make_malloc.h" 46236769Sobrien 47236769Sobrientypedef struct ListNode { 48236769Sobrien struct ListNode *prevPtr; /* previous element in list */ 49236769Sobrien struct ListNode *nextPtr; /* next in list */ 50236769Sobrien unsigned int useCount:8, /* Count of functions using the node. 51236769Sobrien * node may not be deleted until count 52236769Sobrien * goes to 0 */ 53236769Sobrien flags:8; /* Node status flags */ 54236769Sobrien void *datum; /* datum associated with this element */ 55236769Sobrien} *ListNode; 56236769Sobrien/* 57236769Sobrien * Flags required for synchronization 58236769Sobrien */ 59236769Sobrien#define LN_DELETED 0x0001 /* List node should be removed when done */ 60236769Sobrien 61236769Sobrientypedef enum { 62236769Sobrien Head, Middle, Tail, Unknown 63236769Sobrien} Where; 64236769Sobrien 65236769Sobrientypedef struct List { 66236769Sobrien ListNode firstPtr; /* first node in list */ 67236769Sobrien ListNode lastPtr; /* last node in list */ 68236769Sobrien Boolean isCirc; /* true if the list should be considered 69236769Sobrien * circular */ 70236769Sobrien/* 71236769Sobrien * fields for sequential access 72236769Sobrien */ 73236769Sobrien Where atEnd; /* Where in the list the last access was */ 74236769Sobrien Boolean isOpen; /* true if list has been Lst_Open'ed */ 75236769Sobrien ListNode curPtr; /* current node, if open. NULL if 76236769Sobrien * *just* opened */ 77236769Sobrien ListNode prevPtr; /* Previous node, if open. Used by 78236769Sobrien * Lst_Remove */ 79236769Sobrien} *List; 80236769Sobrien 81236769Sobrien/* 82236769Sobrien * PAlloc (var, ptype) -- 83236769Sobrien * Allocate a pointer-typedef structure 'ptype' into the variable 'var' 84236769Sobrien */ 85236769Sobrien#define PAlloc(var,ptype) var = (ptype) bmake_malloc(sizeof *(var)) 86236769Sobrien 87236769Sobrien/* 88236769Sobrien * LstValid (l) -- 89236769Sobrien * Return TRUE if the list l is valid 90236769Sobrien */ 91236769Sobrien#define LstValid(l) ((Lst)(l) != NULL) 92236769Sobrien 93236769Sobrien/* 94236769Sobrien * LstNodeValid (ln, l) -- 95236769Sobrien * Return TRUE if the LstNode ln is valid with respect to l 96236769Sobrien */ 97236769Sobrien#define LstNodeValid(ln, l) ((ln) != NULL) 98236769Sobrien 99236769Sobrien/* 100236769Sobrien * LstIsEmpty (l) -- 101236769Sobrien * TRUE if the list l is empty. 102236769Sobrien */ 103236769Sobrien#define LstIsEmpty(l) (((List)(l))->firstPtr == NULL) 104236769Sobrien 105236769Sobrien#endif /* _LSTINT_H_ */ 106