diff options
author | Vadim Dashevskiy <watcherhd@gmail.com> | 2012-07-28 19:25:08 +0000 |
---|---|---|
committer | Vadim Dashevskiy <watcherhd@gmail.com> | 2012-07-28 19:25:08 +0000 |
commit | 66526765714b08969548a414d3fa87dbe333242d (patch) | |
tree | d3fc2027140f97edfdfc5023e70ff8b4db920c11 /plugins/!NotAdopted/IMO2sProxy/src/common/memlist.c | |
parent | 3ccd712341ed9e76252bd595c5a797d6c8ea8992 (diff) |
"!Deprecated" folders moved from root directory to plugins
git-svn-id: http://svn.miranda-ng.org/main/trunk@1230 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/!NotAdopted/IMO2sProxy/src/common/memlist.c')
-rw-r--r-- | plugins/!NotAdopted/IMO2sProxy/src/common/memlist.c | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/plugins/!NotAdopted/IMO2sProxy/src/common/memlist.c b/plugins/!NotAdopted/IMO2sProxy/src/common/memlist.c new file mode 100644 index 0000000000..137a03eeac --- /dev/null +++ b/plugins/!NotAdopted/IMO2sProxy/src/common/memlist.c @@ -0,0 +1,158 @@ +#include "memlist.h"
+#include <string.h>
+#include <stdlib.h>
+
+struct _tagLIST
+{
+ unsigned int uiCount;
+ unsigned int uiCapacity;
+ void **apStorage;
+};
+
+// -----------------------------------------------------------------------------
+// Interface
+// -----------------------------------------------------------------------------
+
+TYP_LIST *List_Init(unsigned int uiCapacity)
+{
+ TYP_LIST *pstHandle;
+
+ pstHandle = (TYP_LIST *)malloc(sizeof(TYP_LIST));
+
+ if (!pstHandle) return NULL;
+ pstHandle->uiCount = 0;
+ pstHandle->uiCapacity = uiCapacity;
+ if (uiCapacity == 0)
+ pstHandle->apStorage = NULL;
+ else
+ {
+ pstHandle->apStorage = (void **)malloc(sizeof(void *)*uiCapacity);
+ if (!pstHandle->apStorage)
+ {
+ free(pstHandle);
+ return NULL;
+ }
+ }
+ return pstHandle;
+}
+
+// -----------------------------------------------------------------------------
+
+void List_Exit(TYP_LIST *pstHandle)
+{
+ if (pstHandle->apStorage)
+ free (pstHandle->apStorage);
+ free (pstHandle);
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL List_Push(TYP_LIST *pstHandle, void *pItem)
+{
+ return List_InsertElementAt(pstHandle, pItem,pstHandle->uiCount);
+}
+
+// -----------------------------------------------------------------------------
+
+void *List_Pop (TYP_LIST *pstHandle)
+{
+ if (pstHandle->uiCount)
+ return List_RemoveElementAt(pstHandle ,pstHandle->uiCount-1);
+ else return NULL;
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL List_ReplaceElementAt(TYP_LIST *pstHandle, void *pItem, unsigned int uiPos)
+{
+ if (uiPos >= pstHandle->uiCount) return NULL;
+ pstHandle->apStorage[uiPos]=pItem;
+ return TRUE;
+}
+
+// -----------------------------------------------------------------------------
+
+BOOL List_InsertElementAt(TYP_LIST *pstHandle, void *pItem, unsigned int uiPos)
+{
+ unsigned int uiStep;
+ void **apNewStorage;
+
+ if (uiPos > pstHandle->uiCount)
+ uiPos = pstHandle->uiCount;
+
+ if (pstHandle->uiCount >= pstHandle->uiCapacity)
+ {
+ uiStep = pstHandle->uiCount*2;
+ if (uiStep < 8) uiStep = 8;
+
+ if (!pstHandle->apStorage)
+ apNewStorage = (void **)malloc(sizeof(void *)*uiStep);
+ else
+ apNewStorage = realloc (pstHandle->apStorage, sizeof(void *)*uiStep);
+ if (!apNewStorage) return FALSE;
+ pstHandle->apStorage = apNewStorage;
+ pstHandle->uiCapacity = uiStep;
+ }
+
+ if (uiPos<pstHandle->uiCount)
+ memmove(&pstHandle->apStorage[uiPos+1], &pstHandle->apStorage[uiPos], (pstHandle->uiCount-uiPos)*sizeof(void*));
+ pstHandle->apStorage[uiPos] = pItem;
+ pstHandle->uiCount++;
+ return TRUE;
+}
+
+// -----------------------------------------------------------------------------
+
+void *List_RemoveElementAt(TYP_LIST *pstHandle, unsigned int uiPos)
+{
+ void *pRet;
+
+ pRet = pstHandle->apStorage[uiPos];
+ if (uiPos<pstHandle->uiCount-1)
+ memmove (&pstHandle->apStorage[uiPos], &pstHandle->apStorage[uiPos+1], (pstHandle->uiCount-uiPos-1)*sizeof(void*));
+ pstHandle->uiCount--;
+ return pRet;
+}
+
+// -----------------------------------------------------------------------------
+
+unsigned int List_Count(TYP_LIST *pstHandle)
+{
+ return pstHandle->uiCount;
+}
+
+// -----------------------------------------------------------------------------
+
+void *List_ElementAt(TYP_LIST *pstHandle,unsigned int uiPos)
+{
+ if (uiPos >= pstHandle->uiCount) return NULL;
+ return pstHandle->apStorage[uiPos];
+}
+
+// -----------------------------------------------------------------------------
+
+void *List_Top(TYP_LIST *pstHandle)
+{
+ if (pstHandle->uiCount)
+ return List_ElementAt (pstHandle, pstHandle->uiCount-1);
+ else return NULL;
+}
+
+// -----------------------------------------------------------------------------
+
+void List_Sort(TYP_LIST *pstHandle, int (*pFunc)(const void*,const void*))
+{
+ qsort(pstHandle->apStorage,pstHandle->uiCount,sizeof(void *),pFunc);
+}
+
+// -----------------------------------------------------------------------------
+
+void List_FreeElements(TYP_LIST *pstHandle)
+{
+ void *pEntry;
+
+ while (pEntry = List_Pop(pstHandle))
+ free (pEntry);
+}
+
+// -----------------------------------------------------------------------------
|