|
|
1.1 root 1: /*
2: * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
3: * Copyright (c) 1988, 1989 by Adam de Boor
4: * Copyright (c) 1989 by Berkeley Softworks
5: * All rights reserved.
6: *
7: * This code is derived from software contributed to Berkeley by
8: * Adam de Boor.
9: *
10: * Redistribution and use in source and binary forms are permitted
11: * provided that: (1) source distributions retain this entire copyright
12: * notice and comment, and (2) distributions including binaries display
13: * the following acknowledgement: ``This product includes software
14: * developed by the University of California, Berkeley and its contributors''
15: * in the documentation or other materials provided with the distribution
16: * and in all advertising materials mentioning features or use of this
17: * software. Neither the name of the University nor the names of its
18: * contributors may be used to endorse or promote products derived
19: * from this software without specific prior written permission.
20: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
21: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
22: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23: */
24:
25: #ifndef lint
26: static char sccsid[] = "@(#)list.c 5.4 (Berkeley) 6/1/90";
27: #endif /* not lint */
28:
29: /* list.c -
30: *
31: * This file contains procedures for manipulating lists.
32: * Structures may be inserted into or deleted from lists, and
33: * they may be moved from one place in a list to another.
34: *
35: * The header file contains macros to help in determining the destination
36: * locations for List_Insert and List_Move. See list.h for details.
37: */
38:
39: #include "sprite.h"
40: #include "list.h"
41:
42:
43: /*
44: * ----------------------------------------------------------------------------
45: *
46: * List_Insert --
47: *
48: * Insert the list element pointed to by itemPtr into a List after
49: * destPtr. Perform a primitive test for self-looping by returning
50: * failure if the list element is being inserted next to itself.
51: *
52: * Results:
53: * None.
54: *
55: * Side effects:
56: * The list containing destPtr is modified to contain itemPtr.
57: *
58: * ----------------------------------------------------------------------------
59: */
60: void
61: List_Insert(itemPtr, destPtr)
62: register List_Links *itemPtr; /* structure to insert */
63: register List_Links *destPtr; /* structure after which to insert it */
64: {
65: if (itemPtr == (List_Links *) NIL || destPtr == (List_Links *) NIL
66: || !itemPtr || !destPtr || (itemPtr == destPtr)) {
67: Punt("List_Insert: inserting this item would create a loop.\n");
68: return;
69: }
70: itemPtr->nextPtr = destPtr->nextPtr;
71: itemPtr->prevPtr = destPtr;
72: destPtr->nextPtr->prevPtr = itemPtr;
73: destPtr->nextPtr = itemPtr;
74: }
75:
76:
77: /*
78: * ----------------------------------------------------------------------------
79: *
80: * List_Remove --
81: *
82: * Remove a list element from the list in which it is contained.
83: *
84: * Results:
85: * None.
86: *
87: * Side effects:
88: * The given structure is removed from its containing list.
89: *
90: * ----------------------------------------------------------------------------
91: */
92: void
93: List_Remove(itemPtr)
94: register List_Links *itemPtr; /* list element to remove */
95: {
96: if (itemPtr == (List_Links *) NIL || itemPtr == itemPtr->nextPtr
97: || !itemPtr) {
98: Punt("List_Remove: invalid item to remove.\n");
99: }
100: itemPtr->prevPtr->nextPtr = itemPtr->nextPtr;
101: itemPtr->nextPtr->prevPtr = itemPtr->prevPtr;
102: }
103:
104:
105: /*
106: * ----------------------------------------------------------------------------
107: *
108: * List_Move --
109: *
110: * Move the list element referenced by itemPtr to follow destPtr.
111: *
112: * Results:
113: * None.
114: *
115: * Side effects:
116: * List ordering is modified.
117: *
118: * ----------------------------------------------------------------------------
119: */
120: void
121: List_Move(itemPtr, destPtr)
122: register List_Links *itemPtr; /* list element to be moved */
123: register List_Links *destPtr; /* element after which it is to be placed */
124: {
125:
126: if (itemPtr == (List_Links *) NIL || destPtr == (List_Links *) NIL
127: || !itemPtr || !destPtr) {
128: Punt("List_Move: One of the list items is NIL.\n");
129: }
130: /*
131: * It is conceivable that someone will try to move a list element to
132: * be after itself.
133: */
134: if (itemPtr != destPtr) {
135: List_Remove(itemPtr);
136: List_Insert(itemPtr, destPtr);
137: }
138: }
139:
140:
141: /*
142: * ----------------------------------------------------------------------------
143: *
144: * List_Init --
145: *
146: * Initialize a header pointer to point to an empty list. The List_Links
147: * structure must already be allocated.
148: *
149: * Results:
150: * None.
151: *
152: * Side effects:
153: * The header's pointers are modified to point to itself.
154: *
155: * ----------------------------------------------------------------------------
156: */
157: void
158: List_Init(headerPtr)
159: register List_Links *headerPtr; /* Pointer to a List_Links structure
160: to be header */
161: {
162: if (headerPtr == (List_Links *) NIL || !headerPtr) {
163: Punt("List_Init: invalid header pointer.\n");
164: }
165: headerPtr->nextPtr = headerPtr;
166: headerPtr->prevPtr = headerPtr;
167: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.