comparison rogue4/list.c @ 225:4f6e056438eb

Merge the GCC5 and build fix branches.
author John "Elwin" Edwards
date Wed, 02 Mar 2016 21:28:34 -0500
parents 1b73a8641b37
children
comparison
equal deleted inserted replaced
224:4d0f53998e8a 225:4f6e056438eb
16 16
17 /* 17 /*
18 * detach: 18 * detach:
19 * Takes an item out of whatever linked list it might be in 19 * Takes an item out of whatever linked list it might be in
20 */ 20 */
21 _detach(list, item) 21 void
22 register THING **list, *item; 22 _detach(THING **list, THING *item)
23 { 23 {
24 if (*list == item) 24 if (*list == item)
25 *list = next(item); 25 *list = next(item);
26 if (prev(item) != NULL) item->l_prev->l_next = next(item); 26 if (prev(item) != NULL) item->l_prev->l_next = next(item);
27 if (next(item) != NULL) item->l_next->l_prev = prev(item); 27 if (next(item) != NULL) item->l_next->l_prev = prev(item);
31 31
32 /* 32 /*
33 * _attach: 33 * _attach:
34 * add an item to the head of a list 34 * add an item to the head of a list
35 */ 35 */
36 _attach(list, item) 36 void
37 register THING **list, *item; 37 _attach(THING **list, THING *item)
38 { 38 {
39 if (*list != NULL) 39 if (*list != NULL)
40 { 40 {
41 item->l_next = *list; 41 item->l_next = *list;
42 (*list)->l_prev = item; 42 (*list)->l_prev = item;
52 52
53 /* 53 /*
54 * _free_list: 54 * _free_list:
55 * Throw the whole blamed thing away 55 * Throw the whole blamed thing away
56 */ 56 */
57 _free_list(ptr) 57 void
58 register THING **ptr; 58 _free_list(THING **ptr)
59 { 59 {
60 register THING *item; 60 register THING *item;
61 61
62 while (*ptr != NULL) 62 while (*ptr != NULL)
63 { 63 {
69 69
70 /* 70 /*
71 * discard: 71 * discard:
72 * Free up an item 72 * Free up an item
73 */ 73 */
74 discard(item) 74 void
75 register THING *item; 75 discard(THING *item)
76 { 76 {
77 total--; 77 total--;
78 free((char *) item); 78 free((char *) item);
79 } 79 }
80 80
81 /* 81 /*
82 * new_item 82 * new_item
83 * Get a new item with a specified size 83 * Get a new item with a specified size
84 */ 84 */
85 THING * 85 THING *
86 new_item() 86 new_item(void)
87 { 87 {
88 register THING *item; 88 register THING *item;
89 89
90 if ((item = calloc(1, sizeof *item)) == NULL) 90 if ((item = calloc(1, sizeof *item)) == NULL)
91 msg("ran out of memory after %d items", total); 91 msg("ran out of memory after %d items", total);