Just some cosmetic code cleanup

This commit is contained in:
Vatiken
2012-06-19 21:11:14 +00:00
parent 12c506c89a
commit 58ec913b46
12 changed files with 230 additions and 254 deletions

View File

@@ -33,19 +33,19 @@ struct list_data * create_list(void)
else
first_list = FALSE;
return (pNewList);
return (pNewList);
}
struct item_data * create_item(void)
{
struct item_data *pNewItem;
CREATE(pNewItem, struct item_data, 1);
pNewItem->pNextItem = NULL;
pNewItem->pPrevItem = NULL;
pNewItem->pContent = NULL;
return (pNewItem);
}
@@ -76,15 +76,15 @@ void add_to_list(void * pContent, struct list_data * pList)
/* Allocate our memory */
pNewItem = create_item();
/* Place the contents in the item */
pNewItem->pContent = pContent;
pNewItem->pNextItem = NULL;
/* If we are the first entry in the list, mark us as such */
if (pList->pFirstItem == NULL)
pList->pFirstItem = pNewItem;
/* Grab our last item from the list and attach it to our new item */
if (pList->pLastItem) {
pLastItem = pList->pLastItem;
@@ -94,39 +94,37 @@ void add_to_list(void * pContent, struct list_data * pList)
/* Make our new item our last item in the list */
pList->pLastItem = pNewItem;
pList->iSize++;
}
void remove_from_list(void * pContent, struct list_data * pList)
{
struct item_data *pRemovedItem;
if ((pRemovedItem = find_in_list(pContent, pList)) == NULL) {
mudlog(CMP, LVL_GOD, TRUE, "SYSERR: Attempting to remove contents that don't exist in list.");
return;
}
if (pRemovedItem == pList->pFirstItem)
pList->pFirstItem = pRemovedItem->pNextItem;
if (pRemovedItem == pList->pLastItem)
pList->pLastItem = pRemovedItem->pPrevItem;
if (pRemovedItem->pPrevItem)
pRemovedItem->pPrevItem->pNextItem = pRemovedItem->pNextItem;
if (pRemovedItem->pNextItem)
pRemovedItem->pNextItem->pPrevItem = pRemovedItem->pPrevItem;
pList->iSize--;
if (pList->iSize == 0) {
pList->pFirstItem = NULL;
pList->pLastItem = NULL;
}
free(pRemovedItem);
free(pRemovedItem);
}
/** Merges an iterator with a list
@@ -136,7 +134,7 @@ void remove_from_list(void * pContent, struct list_data * pList)
void * merge_iterator(struct iterator_data * pIterator, struct list_data * pList)
{
void * pContent;
if (pList == NULL) {
mudlog(NRM, LVL_GOD, TRUE, "SYSERR: Attempting to merge iterator to NULL list.");
pIterator->pList = NULL;
@@ -149,13 +147,13 @@ void * merge_iterator(struct iterator_data * pIterator, struct list_data * pList
pIterator->pItem = NULL;
return NULL;
}
pList->iIterators++;
pIterator->pList = pList;
pIterator->pItem = pList->pFirstItem;
pContent = pIterator->pItem ? pIterator->pItem->pContent : NULL;
return (pContent);
}
@@ -163,9 +161,9 @@ void remove_iterator(struct iterator_data * pIterator)
{
if (pIterator->pList == NULL) {
mudlog(NRM, LVL_GOD, TRUE, "SYSERR: Attempting to remove iterator from NULL list.");
return;
return;
}
pIterator->pList->iIterators--;
pIterator->pList = NULL;
pIterator->pItem = NULL;
@@ -179,19 +177,19 @@ void * next_in_list(struct iterator_data * pIterator)
{
void * pContent;
struct item_data * pTempItem;
if (pIterator->pList == NULL) {
mudlog(NRM, LVL_GOD, TRUE, "SYSERR: Attempting to get content from iterator with NULL list.");
return NULL;
}
/* Cycle down the list */
pTempItem = pIterator->pItem->pNextItem;
pIterator->pItem = pTempItem;
/* Grab the content */
pContent = pIterator->pItem ? pIterator->pItem->pContent : NULL;
return (pContent);
}
@@ -206,21 +204,21 @@ struct item_data * find_in_list(void * pContent, struct list_data * pList)
void * pFoundItem;
struct item_data *pItem = NULL;
bool found;
pFoundItem = merge_iterator(&Iterator, pList);
for (found = FALSE; pFoundItem != NULL; pFoundItem = next_in_list(&Iterator)) {
if (pFoundItem == pContent) {
found = TRUE;
break;
}
}
if (found)
pItem = Iterator.pItem;
remove_iterator(&Iterator);
if (found)
return (pItem);
else
@@ -245,18 +243,18 @@ void * simple_list(struct list_data * pList)
static bool loop = FALSE;
static struct list_data *pLastList = NULL;
void * pContent;
/* Reset List */
if (pList == NULL) {
loop = FALSE;
pLastList = NULL;
return NULL;
}
/* Reset List */
if (pList == NULL) {
loop = FALSE;
pLastList = NULL;
return NULL;
}
if (!loop || pLastList != pList) {
if (loop && pLastList != pList)
mudlog(CMP, LVL_GRGOD, TRUE, "SYSERR: simple_list() forced to reset itself.");
pContent = merge_iterator(&Iterator, pList);
if (pContent != NULL) {
pLastList = pList;
@@ -268,7 +266,7 @@ void * simple_list(struct list_data * pList)
if ((pContent = next_in_list(&Iterator)) != NULL)
return (pContent);
remove_iterator(&Iterator);
loop = FALSE;
return NULL;
@@ -281,23 +279,23 @@ void * random_from_list(struct list_data * pList)
bool found;
int number;
int count = 1;
if (pList->iSize <= 0)
return NULL;
else
number = rand_number(1, pList->iSize);
pFoundItem = merge_iterator(&Iterator, pList);
for (found = FALSE; pFoundItem != NULL; pFoundItem = next_in_list(&Iterator), count++) {
if (count == number) {
found = TRUE;
break;
}
}
remove_iterator(&Iterator);
if (found)
return (pFoundItem);
else