![]() |
ZenWINX Architecture - Reference Manual - Guides |
|
00001 /* 00002 * ZenWINX - WIndows Native eXtended library. 00003 * Copyright (c) 2007-2010 by Dmitri Arkhangelski (dmitriar@gmail.com). 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00027 #include "ntndk.h" 00028 #include "zenwinx.h" 00029 00043 list_entry * __stdcall winx_list_insert_item(list_entry **phead,list_entry *prev,long size) 00044 { 00045 list_entry *new_item = (list_entry *)winx_heap_alloc(size); 00046 if(new_item == NULL) return NULL; 00047 00048 /* is list empty? */ 00049 if(*phead == NULL){ 00050 *phead = new_item; 00051 new_item->p = new_item->n = new_item; 00052 return new_item; 00053 } 00054 00055 /* insert as a new head? */ 00056 if(prev == NULL){ 00057 prev = (*phead)->p; 00058 *phead = new_item; 00059 } 00060 00061 /* insert after an item specified by prev argument */ 00062 new_item->p = prev; 00063 new_item->n = prev->n; 00064 new_item->p->n = new_item; 00065 new_item->n->p = new_item; 00066 return new_item; 00067 } 00068 00077 void __stdcall winx_list_remove_item(list_entry **phead,list_entry *item) 00078 { 00079 /* validate an item */ 00080 if(item == NULL) return; 00081 00082 /* is list empty? */ 00083 if(*phead == NULL) return; 00084 00085 /* remove alone first item? */ 00086 if(item == *phead && item->n == *phead){ 00087 winx_heap_free(item); 00088 *phead = NULL; 00089 return; 00090 } 00091 00092 /* remove first item? */ 00093 if(item == *phead){ 00094 *phead = (*phead)->n; 00095 } 00096 item->p->n = item->n; 00097 item->n->p = item->p; 00098 winx_heap_free(item); 00099 } 00100 00107 void __stdcall winx_list_destroy(list_entry **phead) 00108 { 00109 list_entry *item, *next, *head; 00110 00111 /* is list empty? */ 00112 if(*phead == NULL) return; 00113 00114 head = *phead; 00115 item = head; 00116 00117 do { 00118 next = item->n; 00119 winx_heap_free(item); 00120 item = next; 00121 } while (next != head); 00122 00123 *phead = NULL; 00124 } 00125