summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-09-14 19:42:12 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-09-14 19:45:34 +0200
commit4fac4f2b5af3d46d39d1ab36f38f10862544c783 (patch)
treeeeaaedf5d28e32ab9fd245f1552760116f20e5bd /common
parent538ce0e3537dd5bc9038d0541f3931769c0a8159 (diff)
downloadeurephia-4fac4f2b5af3d46d39d1ab36f38f10862544c783.tar.gz
eurephia-4fac4f2b5af3d46d39d1ab36f38f10862544c783.tar.xz
eurephia-4fac4f2b5af3d46d39d1ab36f38f10862544c783.zip
Added eRemove_value() function, to remove a key/value pair from an eurephiaVALUES chain
Diffstat (limited to 'common')
-rw-r--r--common/eurephia_values.c44
-rw-r--r--common/eurephia_values.h7
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_ */