Mercurial > hg > early-roguelike
comparison xrogue/list.c @ 220:f54901b9c39b
XRogue: convert to ANSI-style function declarations.
| author | John "Elwin" Edwards |
|---|---|
| date | Wed, 02 Mar 2016 21:13:26 -0500 |
| parents | ce0cf824c192 |
| children | 0250220d8cdd |
comparison
equal
deleted
inserted
replaced
| 219:f9ef86cf22b2 | 220:f54901b9c39b |
|---|---|
| 19 #include <stdlib.h> | 19 #include <stdlib.h> |
| 20 #include <string.h> | 20 #include <string.h> |
| 21 #include <curses.h> | 21 #include <curses.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) |
| 100 r_free_fire_list | 103 r_free_fire_list |
| 101 Throw the whole list of fire monsters away. But don't | 104 Throw the whole list of fire monsters away. But don't |
| 102 discard the item (monster) itself as that belong to mlist. | 105 discard the item (monster) itself as that belong to mlist. |
| 103 */ | 106 */ |
| 104 | 107 |
| 105 _r_free_fire_list(ptr) | 108 void |
| 106 register struct linked_list **ptr; | 109 _r_free_fire_list(struct linked_list **ptr) |
| 107 { | 110 { |
| 108 register struct linked_list *item; | 111 register struct linked_list *item; |
| 109 | 112 |
| 110 while (*ptr != NULL) | 113 while (*ptr != NULL) |
| 111 { | 114 { |
| 117 /* | 120 /* |
| 118 * r_free_list: | 121 * r_free_list: |
| 119 * Throw the whole list of room exits away | 122 * Throw the whole list of room exits away |
| 120 */ | 123 */ |
| 121 | 124 |
| 122 _r_free_list(ptr) | 125 void |
| 123 register struct linked_list **ptr; | 126 _r_free_list(struct linked_list **ptr) |
| 124 { | 127 { |
| 125 register struct linked_list *item; | 128 register struct linked_list *item; |
| 126 | 129 |
| 127 while (*ptr != NULL) | 130 while (*ptr != NULL) |
| 128 { | 131 { |
| 135 /* | 138 /* |
| 136 * r_discard: | 139 * r_discard: |
| 137 * free up an item and its room | 140 * free up an item and its room |
| 138 */ | 141 */ |
| 139 | 142 |
| 140 r_discard(item) | 143 void |
| 141 register struct linked_list *item; | 144 r_discard(struct linked_list *item) |
| 142 { | 145 { |
| 143 total -= 2; | 146 total -= 2; |
| 144 FREE(DOORPTR(item)); | 147 FREE(DOORPTR(item)); |
| 145 FREE(item); | 148 FREE(item); |
| 146 } | 149 } |
| 148 /* | 151 /* |
| 149 * t_free_list: | 152 * t_free_list: |
| 150 * Throw the whole thing list away | 153 * Throw the whole thing list away |
| 151 */ | 154 */ |
| 152 | 155 |
| 153 _t_free_list(ptr) | 156 void |
| 154 register struct linked_list **ptr; | 157 _t_free_list(struct linked_list **ptr) |
| 155 { | 158 { |
| 156 register struct linked_list *item; | 159 register struct linked_list *item; |
| 157 | 160 |
| 158 while (*ptr != NULL) | 161 while (*ptr != NULL) |
| 159 { | 162 { |
| 166 /* | 169 /* |
| 167 * t_discard: | 170 * t_discard: |
| 168 * free up an item and its thing | 171 * free up an item and its thing |
| 169 */ | 172 */ |
| 170 | 173 |
| 171 t_discard(item) | 174 void |
| 172 register struct linked_list *item; | 175 t_discard(struct linked_list *item) |
| 173 { | 176 { |
| 174 register struct thing *tp; | 177 register struct thing *tp; |
| 175 | 178 |
| 176 total -= 2; | 179 total -= 2; |
| 177 tp = THINGPTR(item); | 180 tp = THINGPTR(item); |
| 185 /* | 188 /* |
| 186 * destroy_item: | 189 * destroy_item: |
| 187 * get rid of an item structure -- don't worry about contents | 190 * get rid of an item structure -- don't worry about contents |
| 188 */ | 191 */ |
| 189 | 192 |
| 190 destroy_item(item) | 193 void |
| 191 register struct linked_list *item; | 194 destroy_item(struct linked_list *item) |
| 192 { | 195 { |
| 193 total--; | 196 total--; |
| 194 FREE(item); | 197 FREE(item); |
| 195 } | 198 } |
| 196 | 199 |
| 198 * new_item | 201 * new_item |
| 199 * get a new item with a specified size | 202 * get a new item with a specified size |
| 200 */ | 203 */ |
| 201 | 204 |
| 202 struct linked_list * | 205 struct linked_list * |
| 203 new_item(size) | 206 new_item(int size) |
| 204 int size; | |
| 205 { | 207 { |
| 206 register struct linked_list *item; | 208 register struct linked_list *item; |
| 207 | 209 |
| 208 if ((item = (struct linked_list *) new(sizeof *item)) == NULL) | 210 if ((item = (struct linked_list *) new(sizeof *item)) == NULL) |
| 209 msg("Ran out of memory for header after %d items", total); | 211 msg("Ran out of memory for header after %d items", total); |
| 218 * creat_item: | 220 * creat_item: |
| 219 * Create just an item structure -- don't make any contents | 221 * Create just an item structure -- don't make any contents |
| 220 */ | 222 */ |
| 221 | 223 |
| 222 struct linked_list * | 224 struct linked_list * |
| 223 creat_item() | 225 creat_item(void) |
| 224 { | 226 { |
| 225 register struct linked_list *item; | 227 register struct linked_list *item; |
| 226 | 228 |
| 227 if ((item = (struct linked_list *) new(sizeof *item)) == NULL) | 229 if ((item = (struct linked_list *) new(sizeof *item)) == NULL) |
| 228 msg("Ran out of memory for header after %d items", total); | 230 msg("Ran out of memory for header after %d items", total); |
| 229 item->l_next = item->l_prev = NULL; | 231 item->l_next = item->l_prev = NULL; |
| 230 return item; | 232 return item; |
| 231 } | 233 } |
| 232 | 234 |
| 233 char * | 235 char * |
| 234 new(size) | 236 new(int size) |
| 235 int size; | |
| 236 { | 237 { |
| 237 register char *space = ALLOC(size); | 238 register char *space = ALLOC(size); |
| 238 | 239 |
| 239 if (space == NULL) { | 240 if (space == NULL) { |
| 240 sprintf(prbuf,"Rogue ran out of memory (used = %d, wanted = %d).", | 241 sprintf(prbuf,"Rogue ran out of memory (used = %d, wanted = %d).", |
