1 /* $NetBSD: list.c,v 1.5 2001/06/19 13:42:08 wiz Exp $ */ 2 3 /*- 4 * Copyright (c) 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Ed James. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39 /* 40 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved. 41 * 42 * Copy permission is hereby granted provided that this notice is 43 * retained on all partial or complete copies. 44 * 45 * For more info on this and all of my stuff, mail edjames@berkeley.edu. 46 */ 47 48 #include <sys/cdefs.h> 49 #ifndef lint 50 #if 0 51 static char sccsid[] = "@(#)list.c 8.1 (Berkeley) 5/31/93"; 52 #else 53 __RCSID("$NetBSD: list.c,v 1.5 2001/06/19 13:42:08 wiz Exp $"); 54 #endif 55 #endif /* not lint */ 56 57 #include "include.h" 58 59 PLANE * 60 newplane() 61 { 62 return ((PLANE *) calloc(1, sizeof (PLANE))); 63 } 64 65 void 66 append(l, p) 67 LIST *l; 68 PLANE *p; 69 { 70 PLANE *q = NULL, *r = NULL; 71 72 if (l->head == NULL) { 73 p->next = p->prev = NULL; 74 l->head = l->tail = p; 75 } else { 76 q = l -> head; 77 78 while (q != NULL && q->plane_no < p->plane_no) { 79 r = q; 80 q = q -> next; 81 } 82 83 if (q) { 84 if (r) { 85 p->prev = r; 86 r->next = p; 87 p->next = q; 88 q->prev = p; 89 } else { 90 p->next = q; 91 p->prev = NULL; 92 q->prev = p; 93 l->head = p; 94 } 95 } else { 96 l->tail->next = p; 97 p->next = NULL; 98 p->prev = l->tail; 99 l->tail = p; 100 } 101 } 102 } 103 104 void 105 delete(l, p) 106 LIST *l; 107 PLANE *p; 108 { 109 if (l->head == NULL) 110 loser(p, "deleted a non-existent plane! Get help!"); 111 112 if (l->head == p && l->tail == p) 113 l->head = l->tail = NULL; 114 else if (l->head == p) { 115 l->head = p->next; 116 l->head->prev = NULL; 117 } else if (l->tail == p) { 118 l->tail = p->prev; 119 l->tail->next = NULL; 120 } else { 121 p->prev->next = p->next; 122 p->next->prev = p->prev; 123 } 124 } 125