#include "bomber.h" #include "list.h" #include "utils.h" /* doesn't use prev link */ static genericlistitem *things=0; static listhead *free_things; void allocthings(void) { int i; const int num = MAXTHINGS; if (!things) { things = calloc(sizeof(genericlistitem), num); } else { memset(things, 0, sizeof(genericlistitem)*num); } if(!things) nomem("Trying to allocate thing memory"); for(i=0;inext; memset(entry, 0, sizeof(genericlistitem)); } return entry; } static void freeentry(void *_entry) { listhead *entry = _entry; entry->next = free_things; entry->prev = NULL; free_things = entry; } void _addtail(listhead *head, listhead *entry) { entry->next = head; entry->prev = head->prev; head->prev->next = entry; head->prev = entry; } listhead* delinkhead(listhead *entry) { listhead *result = entry->prev; entry->next->prev = entry->prev; entry->prev->next = entry->next; freeentry(entry); return result; } void initheader(listhead *head) { head->next = head; head->prev = head; }