diff options
Diffstat (limited to 'common/eurephia_values.c')
-rw-r--r-- | common/eurephia_values.c | 44 |
1 files changed, 44 insertions, 0 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; + } +} |