author | ecalot
<ecalot> 2006-01-17 14:16:24 UTC |
committer | ecalot
<ecalot> 2006-01-17 14:16:24 UTC |
parent | 92b0766bd282dcd0032c8cefbf78f9de76099b57 |
PR/src/lib/layers/list.c | +29 | -0 |
PR/src/lib/layers/reslist.c | +31 | -11 |
diff --git a/PR/src/lib/layers/list.c b/PR/src/lib/layers/list.c index d1b6fab..c8f7eb6 100644 --- a/PR/src/lib/layers/list.c +++ b/PR/src/lib/layers/list.c @@ -125,3 +125,32 @@ void* list_getCursor(tList* list) { return list->cursor->data; } +void list_reorder(tList* list,int dataCmp(const void*,const void*)) { + tList newList; + tListNode* aux; + + /* create a new list with the new dataCmp function */ + newList.size=list->size; + newList.cmp=dataCmp; + newList.free=list->free; + newList.cursor=NULL; + newList.first=NULL; + + /* copy and drop the old list */ + list->cursor=list->first; + while (list->cursor) { + aux=list->cursor->next; + + list_insert(&newList,list->cursor->data); + + free(list->cursor->data); + free(list->cursor); + list->cursor=aux; + } + + /* overwrite the deprecated old list with the new one */ + *list=newList; + + /* move the cursor to the first place to re initialize the new list */ + list_firstCursor(list); +} diff --git a/PR/src/lib/layers/reslist.c b/PR/src/lib/layers/reslist.c index bd4f7b5..9c6a1b5 100644 --- a/PR/src/lib/layers/reslist.c +++ b/PR/src/lib/layers/reslist.c @@ -39,21 +39,41 @@ reslist.c: Princed Resources : Resource list layer implementation /* resource list layer (that uses the abstract list layer primitives) */ + +#define byIndex \ + c=strncmp(a.index,b.index,5);\ + if (c>0) return GT;\ + if (c<0) return LT + +#define byOrder \ + if (a.order>b.order) return GT;\ + if (a.order<b.order) return LT + +#define byValue \ + if (a.value>b.value) return GT;\ + if (a.value<b.value) return LT + +#define byEqual \ + return EQ + int resourceListCompareId(const tResourceId a,const tResourceId b) { - /* the index has the priority */ - int c=strncmp(a.index,b.index,5); - if (c>0) return GT; - if (c<0) return LT; + int c; - /* at this point, the indexes are the same, so let's compare the order */ - if (a.order>b.order) return GT; - if (a.order<b.order) return LT; + /* order priorities */ + byIndex; + byValue; + byOrder; + byEqual; +} - /* at this point, indexes and order are the same, but this is not enough, we'll use value to be sure it's unique */ - if (a.value>b.value) return GT; - if (a.value<b.value) return LT; +int resourceListCompareId_OIV(const tResourceId a,const tResourceId b) { + int c; - return EQ; + /* order priorities */ + byOrder; + byIndex; + byValue; + byEqual; } int reslist_compare(const void* a,const void* b) {