* src/vm/properties.c (properties_add): Replace entry if it already
authortwisti <none@none>
Fri, 17 Nov 2006 15:47:28 +0000 (15:47 +0000)
committertwisti <none@none>
Fri, 17 Nov 2006 15:47:28 +0000 (15:47 +0000)
exists.

src/vm/properties.c

index 69582ec24cc3903f92d50ed9f94b972159da4c5e..762696fc004cecfc27f093719a3fd35e0f227f64 100644 (file)
@@ -26,7 +26,7 @@
 
    Authors: Christian Thalinger
 
-   $Id: properties.c 5991 2006-11-15 18:26:40Z twisti $
+   $Id: properties.c 6014 2006-11-17 15:47:28Z twisti $
 
 */
 
@@ -315,20 +315,36 @@ bool properties_postinit(void)
 
 /* properties_add **************************************************************
 
-   Adds a property entry to the internal property list.
+   Adds a property entry to the internal property list.  If there's
+   already an entry with the same key, replace it.
 
 *******************************************************************************/
 
 void properties_add(char *key, char *value)
 {
-       list_properties_entry *p;
+       list_properties_entry *pe;
+
+       /* search for the entry */
+
+       for (pe = list_first(list_properties); pe != NULL;
+                pe = list_next(list_properties, pe)) {
+               if (strcmp(pe->key, key) == 0) {
+                       /* entry was found, replace the value */
+
+                       pe->value = value;
+
+                       return;
+               }
+       }
+
+       /* entry was not found, insert a new one */
 
-       p = NEW(list_properties_entry);
+       pe = NEW(list_properties_entry);
 
-       p->key   = key;
-       p->value = value;
+       pe->key   = key;
+       pe->value = value;
 
-       list_add_last_unsynced(list_properties, p);
+       list_add_last_unsynced(list_properties, pe);
 }