diff options
| author | Tomas Chvatal (scarabeus) <tomas.chvatal@gmail.com> | 2008-10-22 22:50:54 +0200 |
|---|---|---|
| committer | Tomas Chvatal (scarabeus) <tomas.chvatal@gmail.com> | 2008-10-22 22:50:54 +0200 |
| commit | e12753d2ec9db83ec08bb9db63902a82fb245cdd (patch) | |
| tree | 6e4a63b790d6335f969f88b797a927e0fb25f37a /src/base/storage.c | |
| parent | 0b4d9821c7333b8c4bdf7e0eeb750aef502a1137 (diff) | |
X
Diffstat (limited to 'src/base/storage.c')
| -rw-r--r-- | src/base/storage.c | 182 |
1 files changed, 95 insertions, 87 deletions
diff --git a/src/base/storage.c b/src/base/storage.c index 7a7ee91..54c5e9b 100644 --- a/src/base/storage.c +++ b/src/base/storage.c @@ -9,117 +9,125 @@ typedef struct struct_storage_item { - char *name; - char *group; - void *data; + char *name; + char *group; + void *data; } storage_item_t; -list_t* newStorage() +list_t * +newStorage() { - return newList(); + return newList(); } -static storage_item_t* newStorageItem(char *group, char *name, void *data) +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; + 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) +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 (*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) +void +addItemToStorage(list_t * list, char *group, char *name, void *data) { - assert(list != NULL); - assert(group != NULL); - assert(name != NULL); - addList(list, newStorageItem(group, name, data) ); + assert(list != NULL); + assert(group != NULL); + assert(name != NULL); + addList(list, newStorageItem(group, name, data)); } -void* getItemFromStorage(list_t *list, char *group, char *name) +void * +getItemFromStorage(list_t * list, char *group, char *name) { - storage_item_t *this; - int i; - - assert(list != NULL); - 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; - } + storage_item_t *this; + int i; + + assert(list != NULL); + 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; + } #ifdef DEBUG - printf(_("%s %s was not found in storage!\n"), group, name); + printf(_("%s %s was not found in storage!\n"), group, name); #endif - return NULL; + return NULL; } -void delItemFromStorage(list_t *list, char *group, char *name, void *f) +void +delItemFromStorage(list_t * list, char *group, char *name, void *f) { - storage_item_t *this; - int i; - - assert(list != NULL); - 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; + storage_item_t *this; + int i; + + assert(list != NULL); + 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) +void +delAllItemFromStorage(list_t * list, char *group, void *f) { - storage_item_t *this; - int i; - - assert(list != NULL); - 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--; - } - } + storage_item_t *this; + int i; + + assert(list != NULL); + 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) +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); + 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); } |