Berkeley headers, SCCS id's
[unix-history] / usr / src / games / atc / list.c
CommitLineData
e04f5cf8
KB
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Ed James.
7 *
8 * %sccs.include.redist.c%
9 */
10
c195377c
KB
11/*
12 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
13 *
14 * Copy permission is hereby granted provided that this notice is
15 * retained on all partial or complete copies.
16 *
17 * For more info on this and all of my stuff, mail edjames@berkeley.edu.
18 */
e04f5cf8
KB
19
20#ifndef lint
21static char sccsid[] = "@(#)list.c 5.2 (Berkeley) %G%";
22#endif /* not lint */
c195377c
KB
23
24#include "include.h"
25
26PLANE *
27newplane()
28{
29 return ((PLANE *) calloc(1, sizeof (PLANE)));
30}
31
32append(l, p)
33 LIST *l;
34 PLANE *p;
35{
36 PLANE *q = NULL, *r = NULL;
37
38 if (l->head == NULL) {
39 p->next = p->prev = NULL;
40 l->head = l->tail = p;
41 } else {
42 q = l -> head;
43
44 while (q != NULL && q->plane_no < p->plane_no) {
45 r = q;
46 q = q -> next;
47 }
48
49 if (q) {
50 if (r) {
51 p->prev = r;
52 r->next = p;
53 p->next = q;
54 q->prev = p;
55 } else {
56 p->next = q;
57 p->prev = NULL;
58 q->prev = p;
59 l->head = p;
60 }
61 } else {
62 l->tail->next = p;
63 p->next = NULL;
64 p->prev = l->tail;
65 l->tail = p;
66 }
67 }
68}
69
70delete(l, p)
71 LIST *l;
72 PLANE *p;
73{
74 if (l->head == NULL)
75 loser(p, "deleted a non-existant plane! Get help!");
76
77 if (l->head == p && l->tail == p)
78 l->head = l->tail = NULL;
79 else if (l->head == p) {
80 l->head = p->next;
81 l->head->prev = NULL;
82 } else if (l->tail == p) {
83 l->tail = p->prev;
84 l->tail->next = NULL;
85 } else {
86 p->prev->next = p->next;
87 p->next->prev = p->prev;
88 }
89}