#include "asn-config.h"
#include "asn-list.h"
void
AsnListFree PARAMS ((list),
AsnList *list)
{
AsnListNode *node, *next;
node = list->first;
while (node)
{
next = node->next;
Asn1Free (node);
node = next;
}
Asn1Free (list);
}
void
AsnListRemove PARAMS ((list),
AsnList *list)
{
AsnListNode *node;
if (list->curr)
{
if (list->curr->next)
list->curr->next->prev = list->curr->prev;
else
list->last = list->curr->prev;
if (list->curr->prev)
list->curr->prev->next = list->curr->next;
else
list->first = list->curr->next;
node = list->curr;
list->curr = list->curr->next;
list->count--;
Asn1Free (node);
}
}
void*
AsnListAdd PARAMS ((list),
AsnList *list)
{
AsnListNode *newNode;
void *dataAddr;
if (list->curr)
{
newNode = (AsnListNode *) Asn1Alloc (sizeof (AsnListNode) + list->dataSize);
dataAddr = (void *) &(newNode->data);
newNode->next = list->curr->next;
newNode->prev = list->curr;
if (list->curr->next)
list->curr->next->prev = newNode;
else
list->last = newNode;
list->curr->next = newNode;
list->curr = newNode;
list->count++;
}
else
dataAddr = NULL;
return dataAddr;
}
void*
AsnListInsert PARAMS ((list),
AsnList *list)
{
AsnListNode *newNode;
void *dataAddr;
if (list->curr)
{
newNode = (AsnListNode *) Asn1Alloc (sizeof (AsnListNode) + list->dataSize);
dataAddr = (void *) &(newNode->data);
newNode->next = list->curr;
newNode->prev = list->curr->prev;
if (list->curr->prev)
list->curr->prev->next = newNode;
else
list->first = newNode;
list->curr->prev = newNode;
list->curr = newNode;
list->count++;
}
else
dataAddr = NULL;
return dataAddr;
}
void
AsnListInit PARAMS ((list, dataSize),
AsnList *list _AND_
int dataSize)
{
list->first = list->last = list->curr = NULL;
list->count = 0;
list->dataSize = dataSize;
}
AsnList*
AsnListNew PARAMS ((dataSize),
int dataSize)
{
AsnList *list;
list = (AsnList *) Asn1Alloc (sizeof (AsnList));
list->first = list->last = list->curr = NULL;
list->count = 0;
list->dataSize = dataSize;
return list;
}
void*
AsnListPrev PARAMS ((list),
AsnList *list)
{
void *retVal;
if (list->curr == NULL)
list->curr = list->last;
else
list->curr = list->curr->prev;
if (list->curr == NULL)
retVal = NULL;
else
retVal = (void *) &(list->curr->data);
return retVal;
}
void*
AsnListNext PARAMS ((list),
AsnList *list)
{
void *retVal;
if (list->curr == NULL)
list->curr = list->first;
else
list->curr = list->curr->next;
if (list->curr == NULL)
retVal = NULL;
else
retVal = (void *) &(list->curr->data);
return retVal;
}
void*
AsnListLast PARAMS ((list),
AsnList *list)
{
void *retVal;
list->curr = list->last;
if (list->curr == NULL)
retVal = NULL;
else
retVal = (void *) &(list->curr->data);
return retVal;
}
void*
AsnListFirst PARAMS ((list),
AsnList *list)
{
void *retVal;
list->curr = list->first;
if (list->curr == NULL)
retVal = NULL;
else
retVal = (void *) &(list->curr->data);
return retVal;
}
void*
AsnListPrepend PARAMS ((list),
AsnList *list)
{
AsnListNode *newNode;
void *dataAddr;
newNode = (AsnListNode *) Asn1Alloc (sizeof (AsnListNode) + list->dataSize);
dataAddr = (void *) &(newNode->data);
newNode->prev = NULL;
if (list->first == NULL)
{
newNode->next = NULL;
list->first = list->last = newNode;
}
else
{
newNode->next = list->first;
list->first->prev = newNode;
list->first = newNode;
}
list->curr = newNode;
list->count++;
return dataAddr;
}
void*
AsnListAppend PARAMS ((list),
AsnList *list)
{
AsnListNode *newNode;
void *dataAddr;
newNode = (AsnListNode *) Asn1Alloc (sizeof (AsnListNode) + list->dataSize);
dataAddr = (void *) &(newNode->data);
newNode->next = NULL;
if (list->last == NULL)
{
newNode->prev = NULL;
list->first = list->last = newNode;
}
else
{
newNode->prev = list->last;
list->last->next = newNode;
list->last = newNode;
}
list->curr = newNode;
list->count++;
return dataAddr;
}
void*
AsnListCurr PARAMS ((list),
AsnList *list)
{
void *retVal;
if (list->curr)
retVal = (void *) &(list->curr->data);
else
retVal = NULL;
return retVal;
}
int
AsnListCount PARAMS ((list),
AsnList *list)
{
return list->count;
}
AsnList*
AsnListConcat PARAMS ((l1,l2),
AsnList *l1 _AND_
AsnList *l2)
{
if (l2->count == 0)
return l1;
if (l1->count == 0)
{
l1->count = l2->count;
l1->last = l2->last;
l1->first = l2->first;
l1->curr = l1->first;
}
else
{
l1->count += l2->count;
l1->last->next = l2->first;
l2->first->prev = l1->last;
l1->last = l2->last;
}
return l1;
}
long int
GetAsnListElmtIndex PARAMS ((elmt, list),
void *elmt _AND_
AsnList *list)
{
void *tmp;
void *tmpElmt;
long int index;
index = 0;
tmp = (void*) CURR_LIST_NODE (list);
FOR_EACH_LIST_ELMT (tmpElmt, list)
{
if (tmpElmt == elmt)
{
SET_CURR_LIST_NODE (list, tmp);
return index;
}
else
index++;
}
SET_CURR_LIST_NODE (list, tmp);
return -1;
}
#if TTBL
void*
GetAsnListElmt PARAMS ((list, index),
AsnList *list _AND_
unsigned int index)
{
void *tmp;
void *tmpElmt;
long int currIndex;
if (index > LIST_COUNT (list))
return NULL;
currIndex = 0;
tmp = (void*) CURR_LIST_NODE (list);
FOR_EACH_LIST_ELMT (tmpElmt, list)
{
if (currIndex == index)
{
SET_CURR_LIST_NODE (list, tmp);
return tmpElmt;
}
currIndex++;
}
SET_CURR_LIST_NODE (list, tmp);
return NULL;
}
#endif