141166Sbostic /*-
2*60740Sbostic * Copyright (c) 1990, 1993
3*60740Sbostic * The Regents of the University of California. All rights reserved.
441166Sbostic *
541166Sbostic * This code is derived from software contributed to Berkeley by
641166Sbostic * Ed James.
741166Sbostic *
841166Sbostic * %sccs.include.redist.c%
941166Sbostic */
1041166Sbostic
1141161Sbostic /*
1241161Sbostic * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
1341161Sbostic *
1441161Sbostic * Copy permission is hereby granted provided that this notice is
1541161Sbostic * retained on all partial or complete copies.
1641161Sbostic *
1741161Sbostic * For more info on this and all of my stuff, mail edjames@berkeley.edu.
1841161Sbostic */
1941161Sbostic
2041166Sbostic #ifndef lint
21*60740Sbostic static char sccsid[] = "@(#)list.c 8.1 (Berkeley) 05/31/93";
2241166Sbostic #endif /* not lint */
2341166Sbostic
2441161Sbostic #include "include.h"
2541161Sbostic
2641161Sbostic PLANE *
newplane()2741161Sbostic newplane()
2841161Sbostic {
2941161Sbostic return ((PLANE *) calloc(1, sizeof (PLANE)));
3041161Sbostic }
3141161Sbostic
append(l,p)3241161Sbostic append(l, p)
3341161Sbostic LIST *l;
3441161Sbostic PLANE *p;
3541161Sbostic {
3641161Sbostic PLANE *q = NULL, *r = NULL;
3741161Sbostic
3841161Sbostic if (l->head == NULL) {
3941161Sbostic p->next = p->prev = NULL;
4041161Sbostic l->head = l->tail = p;
4141161Sbostic } else {
4241161Sbostic q = l -> head;
4341161Sbostic
4441161Sbostic while (q != NULL && q->plane_no < p->plane_no) {
4541161Sbostic r = q;
4641161Sbostic q = q -> next;
4741161Sbostic }
4841161Sbostic
4941161Sbostic if (q) {
5041161Sbostic if (r) {
5141161Sbostic p->prev = r;
5241161Sbostic r->next = p;
5341161Sbostic p->next = q;
5441161Sbostic q->prev = p;
5541161Sbostic } else {
5641161Sbostic p->next = q;
5741161Sbostic p->prev = NULL;
5841161Sbostic q->prev = p;
5941161Sbostic l->head = p;
6041161Sbostic }
6141161Sbostic } else {
6241161Sbostic l->tail->next = p;
6341161Sbostic p->next = NULL;
6441161Sbostic p->prev = l->tail;
6541161Sbostic l->tail = p;
6641161Sbostic }
6741161Sbostic }
6841161Sbostic }
6941161Sbostic
delete(l,p)7041161Sbostic delete(l, p)
7141161Sbostic LIST *l;
7241161Sbostic PLANE *p;
7341161Sbostic {
7441161Sbostic if (l->head == NULL)
7541161Sbostic loser(p, "deleted a non-existant plane! Get help!");
7641161Sbostic
7741161Sbostic if (l->head == p && l->tail == p)
7841161Sbostic l->head = l->tail = NULL;
7941161Sbostic else if (l->head == p) {
8041161Sbostic l->head = p->next;
8141161Sbostic l->head->prev = NULL;
8241161Sbostic } else if (l->tail == p) {
8341161Sbostic l->tail = p->prev;
8441161Sbostic l->tail->next = NULL;
8541161Sbostic } else {
8641161Sbostic p->prev->next = p->next;
8741161Sbostic p->next->prev = p->prev;
8841161Sbostic }
8941161Sbostic }
90