list.c revision 1.3 1 /* $NetBSD: list.c,v 1.3 1995/03/21 15:04:18 cgd 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 (at) berkeley.edu.
46 */
47
48 #ifndef lint
49 #if 0
50 static char sccsid[] = "@(#)list.c 8.1 (Berkeley) 5/31/93";
51 #else
52 static char rcsid[] = "$NetBSD: list.c,v 1.3 1995/03/21 15:04:18 cgd Exp $";
53 #endif
54 #endif /* not lint */
55
56 #include "include.h"
57
58 PLANE *
59 newplane()
60 {
61 return ((PLANE *) calloc(1, sizeof (PLANE)));
62 }
63
64 append(l, p)
65 LIST *l;
66 PLANE *p;
67 {
68 PLANE *q = NULL, *r = NULL;
69
70 if (l->head == NULL) {
71 p->next = p->prev = NULL;
72 l->head = l->tail = p;
73 } else {
74 q = l -> head;
75
76 while (q != NULL && q->plane_no < p->plane_no) {
77 r = q;
78 q = q -> next;
79 }
80
81 if (q) {
82 if (r) {
83 p->prev = r;
84 r->next = p;
85 p->next = q;
86 q->prev = p;
87 } else {
88 p->next = q;
89 p->prev = NULL;
90 q->prev = p;
91 l->head = p;
92 }
93 } else {
94 l->tail->next = p;
95 p->next = NULL;
96 p->prev = l->tail;
97 l->tail = p;
98 }
99 }
100 }
101
102 delete(l, p)
103 LIST *l;
104 PLANE *p;
105 {
106 if (l->head == NULL)
107 loser(p, "deleted a non-existant plane! Get help!");
108
109 if (l->head == p && l->tail == p)
110 l->head = l->tail = NULL;
111 else if (l->head == p) {
112 l->head = p->next;
113 l->head->prev = NULL;
114 } else if (l->tail == p) {
115 l->tail = p->prev;
116 l->tail->next = NULL;
117 } else {
118 p->prev->next = p->next;
119 p->next->prev = p->prev;
120 }
121 }
122