Mercurial > hg > early-roguelike
comparison srogue/list.c @ 217:94a0d9dd5ce1
Super-Rogue: convert to ANSI-style function declarations.
This fixes most of the build warnings.
| author | John "Elwin" Edwards |
|---|---|
| date | Sun, 31 Jan 2016 13:45:07 -0500 |
| parents | d6b7c3fb37ea |
| children | 0250220d8cdd |
comparison
equal
deleted
inserted
replaced
| 216:b24545357d2e | 217:94a0d9dd5ce1 |
|---|---|
| 21 /* | 21 /* |
| 22 * detach: | 22 * detach: |
| 23 * Takes an item out of whatever linked list it might be in | 23 * Takes an item out of whatever linked list it might be in |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 _detach(list, item) | 26 void |
| 27 struct linked_list **list, *item; | 27 _detach(struct linked_list **list, struct linked_list *item) |
| 28 { | 28 { |
| 29 if (*list == item) | 29 if (*list == item) |
| 30 *list = next(item); | 30 *list = next(item); |
| 31 if (prev(item) != NULL) | 31 if (prev(item) != NULL) |
| 32 item->l_prev->l_next = next(item); | 32 item->l_prev->l_next = next(item); |
| 37 } | 37 } |
| 38 | 38 |
| 39 /* | 39 /* |
| 40 * _attach: add an item to the head of a list | 40 * _attach: add an item to the head of a list |
| 41 */ | 41 */ |
| 42 _attach(list, item) | 42 void |
| 43 struct linked_list **list, *item; | 43 _attach(struct linked_list **list, struct linked_list *item) |
| 44 { | 44 { |
| 45 if (*list != NULL) { | 45 if (*list != NULL) { |
| 46 item->l_next = *list; | 46 item->l_next = *list; |
| 47 (*list)->l_prev = item; | 47 (*list)->l_prev = item; |
| 48 item->l_prev = NULL; | 48 item->l_prev = NULL; |
| 55 } | 55 } |
| 56 | 56 |
| 57 /* | 57 /* |
| 58 * _free_list: Throw the whole blamed thing away | 58 * _free_list: Throw the whole blamed thing away |
| 59 */ | 59 */ |
| 60 _free_list(ptr) | 60 void |
| 61 struct linked_list **ptr; | 61 _free_list(struct linked_list **ptr) |
| 62 { | 62 { |
| 63 register struct linked_list *item; | 63 register struct linked_list *item; |
| 64 | 64 |
| 65 while (*ptr != NULL) { | 65 while (*ptr != NULL) { |
| 66 item = *ptr; | 66 item = *ptr; |
| 70 } | 70 } |
| 71 | 71 |
| 72 /* | 72 /* |
| 73 * discard: free up an item | 73 * discard: free up an item |
| 74 */ | 74 */ |
| 75 discard(item) | 75 void |
| 76 struct linked_list *item; | 76 discard(struct linked_list *item) |
| 77 { | 77 { |
| 78 total -= 2; | 78 total -= 2; |
| 79 FREE(item->l_data); | 79 FREE(item->l_data); |
| 80 FREE(item); | 80 FREE(item); |
| 81 } | 81 } |
| 82 | 82 |
| 83 /* | 83 /* |
| 84 * new_item: get a new item with a specified size | 84 * new_item: get a new item with a specified size |
| 85 */ | 85 */ |
| 86 struct linked_list * | 86 struct linked_list * |
| 87 new_item(size) | 87 new_item(int size) |
| 88 int size; | |
| 89 { | 88 { |
| 90 register struct linked_list *item; | 89 register struct linked_list *item; |
| 91 | 90 |
| 92 item = (struct linked_list *) new(sizeof *item); | 91 item = (struct linked_list *) new(sizeof *item); |
| 93 item->l_data = new(size); | 92 item->l_data = new(size); |
| 94 item->l_next = item->l_prev = NULL; | 93 item->l_next = item->l_prev = NULL; |
| 95 return item; | 94 return item; |
| 96 } | 95 } |
| 97 | 96 |
| 98 char * | 97 char * |
| 99 new(size) | 98 new(int size) |
| 100 int size; | |
| 101 { | 99 { |
| 102 register char *space = ALLOC(size); | 100 register char *space = ALLOC(size); |
| 103 | 101 |
| 104 if (space == NULL) { | 102 if (space == NULL) { |
| 105 sprintf(prbuf,"Rogue ran out of memory (%d).", md_memused()); | 103 sprintf(prbuf,"Rogue ran out of memory (%d).", md_memused()); |
