comparison arogue7/list.c @ 219:f9ef86cf22b2

Advanced Rogue 7: convert to ANSI-style function declarations. Almost 1500 lines of compiler warnings remain, and the GCC developers are already working on a new version with even more warnings turned on by default.
author John "Elwin" Edwards
date Fri, 19 Feb 2016 21:02:28 -0500
parents adfa37e67084
children 0250220d8cdd
comparison
equal deleted inserted replaced
218:56e748983fa8 219:f9ef86cf22b2
19 19
20 #include "curses.h" 20 #include "curses.h"
21 #include <stdlib.h> 21 #include <stdlib.h>
22 #include "rogue.h" 22 #include "rogue.h"
23 23
24 void r_discard(struct linked_list *item);
25 void t_discard(struct linked_list *item);
26
24 /* 27 /*
25 * detach: 28 * detach:
26 * Takes an item out of whatever linked list it might be in 29 * Takes an item out of whatever linked list it might be in
27 */ 30 */
28 31
29 _detach(list, item) 32 void
30 register struct linked_list **list, *item; 33 _detach(struct linked_list **list, struct linked_list *item)
31 { 34 {
32 if (*list == item) 35 if (*list == item)
33 *list = next(item); 36 *list = next(item);
34 if (prev(item) != NULL) item->l_prev->l_next = next(item); 37 if (prev(item) != NULL) item->l_prev->l_next = next(item);
35 if (next(item) != NULL) item->l_next->l_prev = prev(item); 38 if (next(item) != NULL) item->l_next->l_prev = prev(item);
40 /* 43 /*
41 * _attach: 44 * _attach:
42 * add an item to the head of a list 45 * add an item to the head of a list
43 */ 46 */
44 47
45 _attach(list, item) 48 void
46 register struct linked_list **list, *item; 49 _attach(struct linked_list **list, struct linked_list *item)
47 { 50 {
48 if (*list != NULL) 51 if (*list != NULL)
49 { 52 {
50 item->l_next = *list; 53 item->l_next = *list;
51 (*list)->l_prev = item; 54 (*list)->l_prev = item;
63 /* 66 /*
64 * o_free_list: 67 * o_free_list:
65 * Throw the whole object list away 68 * Throw the whole object list away
66 */ 69 */
67 70
68 _o_free_list(ptr) 71 void
69 register struct linked_list **ptr; 72 _o_free_list(struct linked_list **ptr)
70 { 73 {
71 register struct linked_list *item; 74 register struct linked_list *item;
72 75
73 while (*ptr != NULL) 76 while (*ptr != NULL)
74 { 77 {
81 /* 84 /*
82 * o_discard: 85 * o_discard:
83 * free up an item and its object(and maybe contents) 86 * free up an item and its object(and maybe contents)
84 */ 87 */
85 88
86 o_discard(item) 89 void
87 register struct linked_list *item; 90 o_discard(struct linked_list *item)
88 { 91 {
89 register struct object *obj; 92 register struct object *obj;
90 93
91 obj = OBJPTR(item); 94 obj = OBJPTR(item);
92 if (obj->contents != NULL) 95 if (obj->contents != NULL)
99 /* 102 /*
100 * r_free_list: 103 * r_free_list:
101 * Throw the whole list of room exits away 104 * Throw the whole list of room exits away
102 */ 105 */
103 106
104 _r_free_list(ptr) 107 void
105 register struct linked_list **ptr; 108 _r_free_list(struct linked_list **ptr)
106 { 109 {
107 register struct linked_list *item; 110 register struct linked_list *item;
108 111
109 while (*ptr != NULL) 112 while (*ptr != NULL)
110 { 113 {
117 /* 120 /*
118 * r_discard: 121 * r_discard:
119 * free up an item and its room 122 * free up an item and its room
120 */ 123 */
121 124
122 r_discard(item) 125 void
123 register struct linked_list *item; 126 r_discard(struct linked_list *item)
124 { 127 {
125 total -= 2; 128 total -= 2;
126 FREE(DOORPTR(item)); 129 FREE(DOORPTR(item));
127 FREE(item); 130 FREE(item);
128 } 131 }
130 /* 133 /*
131 * t_free_list: 134 * t_free_list:
132 * Throw the whole thing list away 135 * Throw the whole thing list away
133 */ 136 */
134 137
135 _t_free_list(ptr) 138 void
136 register struct linked_list **ptr; 139 _t_free_list(struct linked_list **ptr)
137 { 140 {
138 register struct linked_list *item; 141 register struct linked_list *item;
139 142
140 while (*ptr != NULL) 143 while (*ptr != NULL)
141 { 144 {
148 /* 151 /*
149 * t_discard: 152 * t_discard:
150 * free up an item and its thing 153 * free up an item and its thing
151 */ 154 */
152 155
153 t_discard(item) 156 void
154 register struct linked_list *item; 157 t_discard(struct linked_list *item)
155 { 158 {
156 register struct thing *tp; 159 register struct thing *tp;
157 160
158 total -= 2; 161 total -= 2;
159 tp = THINGPTR(item); 162 tp = THINGPTR(item);
165 /* 168 /*
166 * destroy_item: 169 * destroy_item:
167 * get rid of an item structure -- don't worry about contents 170 * get rid of an item structure -- don't worry about contents
168 */ 171 */
169 172
170 destroy_item(item) 173 void
171 register struct linked_list *item; 174 destroy_item(struct linked_list *item)
172 { 175 {
173 total--; 176 total--;
174 FREE(item); 177 FREE(item);
175 } 178 }
176 179
178 * new_item 181 * new_item
179 * get a new item with a specified size 182 * get a new item with a specified size
180 */ 183 */
181 184
182 struct linked_list * 185 struct linked_list *
183 new_item(size) 186 new_item(int size)
184 int size;
185 { 187 {
186 register struct linked_list *item; 188 register struct linked_list *item;
187 189
188 if ((item = (struct linked_list *) new(sizeof *item)) == NULL) 190 if ((item = (struct linked_list *) new(sizeof *item)) == NULL)
189 msg("Ran out of memory for header after %d items", total); 191 msg("Ran out of memory for header after %d items", total);
197 * creat_item: 199 * creat_item:
198 * Create just an item structure -- don't make any contents 200 * Create just an item structure -- don't make any contents
199 */ 201 */
200 202
201 struct linked_list * 203 struct linked_list *
202 creat_item() 204 creat_item(void)
203 { 205 {
204 register struct linked_list *item; 206 register struct linked_list *item;
205 207
206 if ((item = (struct linked_list *) new(sizeof *item)) == NULL) 208 if ((item = (struct linked_list *) new(sizeof *item)) == NULL)
207 msg("Ran out of memory for header after %d items", total); 209 msg("Ran out of memory for header after %d items", total);
208 item->l_next = item->l_prev = NULL; 210 item->l_next = item->l_prev = NULL;
209 return item; 211 return item;
210 } 212 }
211 213
212 char * 214 char *
213 new(size) 215 new(int size)
214 int size;
215 { 216 {
216 register char *space = ALLOC(size); 217 register char *space = ALLOC(size);
217 static char errbuf[LINELEN]; 218 static char errbuf[LINELEN];
218 219
219 if (space == NULL) { 220 if (space == NULL) {