From 2d776fcd61be168e1ff0ff2e4a5e71835e7cea19 Mon Sep 17 00:00:00 2001 From: oroborus Date: Sat, 28 Jun 2008 16:38:35 +0000 Subject: - prekopanie adresarovej struktury, prva cast git-svn-id: http://opensvn.csie.org/tuxanci_ng@77 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e --- src/storage.c | 138 ---------------------------------------------------------- 1 file changed, 138 deletions(-) delete mode 100644 src/storage.c (limited to 'src/storage.c') diff --git a/src/storage.c b/src/storage.c deleted file mode 100644 index e7afa45..0000000 --- a/src/storage.c +++ /dev/null @@ -1,138 +0,0 @@ - -#include -#include -#include -#include - -#include "main.h" -#include "list.h" - -typedef struct struct_storage_item -{ - char *name; - char *group; - void *data; -} storage_item_t; - -list_t* newStorage() -{ - return newList(); -} - -static storage_item_t* newStorageItem(char *group, char *name, void *data) -{ - storage_item_t *new; - - assert( name != NULL ); - assert( group != NULL ); - assert( data != NULL ); - - new = malloc( sizeof(storage_item_t) ); - new->name = strdup(name); - new->group = strdup(group); - new->data = data; - - return new; -} - -static void destroyStorageItem(storage_item_t *p, void *f) -{ - void(*fce)(void *); - - assert( p != NULL ); - assert( f != NULL ); - - fce = f; - - fce(p->data); - free(p->name); - free(p->group); - free(p); -} - -void addItemToStorage(list_t *list, char *group, char *name, void *data) -{ - addList(list, newStorageItem(group, name, data) ); -} - -void* getItemFromStorage(list_t *list, char *group, char *name) -{ - storage_item_t *this; - int i; - - assert( group != NULL ); - assert( name != NULL ); - - for(i = 0 ; i < list->count; i++) - { - this = (storage_item_t *) list->list[i]; - - if( strcmp(group, this->group) == 0 && strcmp(name, this->name) == 0 ) - { - return this->data; - } - } - - printf("%s %s not found in storage !!!\n", group, name); - return NULL; -} - -void delItemFromStorage(list_t *list, char *group, char *name, void *f) -{ - storage_item_t *this; - int i; - - assert( group != NULL ); - assert( name != NULL ); - - for(i = 0 ; i < list->count; i++) - { - this = (storage_item_t *) list->list[i]; - - if( strcmp(group, this->group) == 0 && strcmp(name, this->name) == 0 ) - { - destroyStorageItem(this, f); - delList(list, i); - return; - } - } - - return; -} - -void delAllItemFromStorage(list_t *list, char *group, void *f) -{ - storage_item_t *this; - int i; - - assert( group != NULL ); - - for(i = 0 ; i < list->count; i++) - { - this = (storage_item_t *) list->list[i]; - - if( strcmp(group, this->group) == 0 ) - { - destroyStorageItem(this, f); - delList(list, i); - i--; - } - } -} - -void destroyStorage(list_t *p, void *f) -{ - storage_item_t *this; - int i; - - assert( p != NULL ); - assert( f != NULL ); - - for( i = 0 ; i < p->count ; i++ ) - { - this = (storage_item_t *)p->list[i]; - destroyStorageItem(this, f); - } - - destroyList(p); -} -- cgit v1.2.3