diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/eurephia_values.c | 44 | ||||
-rw-r--r-- | common/eurephia_values.h | 7 |
2 files changed, 48 insertions, 3 deletions
diff --git a/common/eurephia_values.c b/common/eurephia_values.c index 78f0e6a..5427136 100644 --- a/common/eurephia_values.c +++ b/common/eurephia_values.c @@ -205,3 +205,47 @@ void eAdd_value(eurephiaCTX *ctx, eurephiaVALUES *vls, const char *key, const ch // Add value struct to the chain eAdd_valuestruct(ctx, vls, ptr); } + +/** + * Removes the key/value pair identified by evgid and evid from the given eurephiaVALUES chain + * + * @param ctx eurephiaCTX + * @param vls Pointer to an eurephiaVALUES chain with the data + * @param evgid Group ID of the chain + * @param evid Element ID of the chain element to be removed + * + * @return Returns a pointer to the chain. The pointer is only changed if the first element in the + * chain is deleted + */ +eurephiaVALUES *eRemove_value(eurephiaCTX *ctx, eurephiaVALUES *vls, unsigned int evgid, unsigned int evid) { + eurephiaVALUES *ptr = NULL, *prev_ptr = NULL; + int found = 0; + + DEBUG(ctx, 31, "Function call: eRemove_valuestruct(ctx, vls(%i), %i, %i)", + (vls != NULL ? vls->evgid : -1), evgid, evid); + + // Find the value element + for( ptr = vls; ptr != NULL; ptr = ptr->next ) { + if( (ptr->evgid == evgid) && (ptr->evid == evid) ) { + found = 1; + break; + } + prev_ptr = ptr; + } + + if( !found ) { + return vls; + } + + if( ptr != vls ) { + prev_ptr->next = ptr->next; + ptr->next = NULL; + eFree_values_func(ctx, ptr); + return vls; + } else { + prev_ptr = ptr->next; + ptr->next = NULL; + eFree_values_func(ctx, ptr); + return prev_ptr; + } +} diff --git a/common/eurephia_values.h b/common/eurephia_values.h index dcb81bc..94f6d63 100644 --- a/common/eurephia_values.h +++ b/common/eurephia_values.h @@ -28,8 +28,8 @@ * */ -#ifndef EUREPHIA_VALUES_H_ -# define EUREPHIA_VALUES_H_ +#ifndef EUREPHIA_VALUES_H_ +# define EUREPHIA_VALUES_H_ #include <eurephia_context.h> @@ -40,6 +40,7 @@ eurephiaVALUES *eCreate_value_space(eurephiaCTX *ctx, int evid); void eAdd_valuestruct(eurephiaCTX *ctx, eurephiaVALUES *vls, eurephiaVALUES *newval); void eAdd_value(eurephiaCTX *ctx, eurephiaVALUES *vls, const char *key, const char *val); +eurephiaVALUES *eRemove_value(eurephiaCTX *ctx, eurephiaVALUES *vls, unsigned int evgid, unsigned int evid); /** * Front-end function for eFree_values_func(). Frees eurephiaVALUES pointer chain and @@ -52,4 +53,4 @@ void eAdd_value(eurephiaCTX *ctx, eurephiaVALUES *vls, const char *key, const ch #define eFree_values(c, v) { eFree_values_func(c, v); v = NULL; } void eFree_values_func(eurephiaCTX *ctx, eurephiaVALUES *vls); -#endif /* !EUREPHIA_VALUES_H_ */ +#endif /* !EUREPHIA_VALUES_H_ */ |