diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 8b40e5c56..ea367803c 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ Changes towards version 0.7: +- Added ability to remove entries from ALists - Michael - Cleaned up FRAME, CONTEXT, and FONT abstraction layers - Michael - Added Input Frames to pause code to stop infinite loops - Michael - Added more netplay debug code - SvdB diff --git a/sc2/src/sc2code/libs/resource/alist.c b/sc2/src/sc2code/libs/resource/alist.c index 42ac9a4e3..cbdf42b16 100644 --- a/sc2/src/sc2code/libs/resource/alist.c +++ b/sc2/src/sc2code/libs/resource/alist.c @@ -104,6 +104,46 @@ Alist_PutAll (alist *dst, alist *src) } } +/* Remove operation. Returns the old value, or NULL if it didn't exist. */ + +/* NOTE: The actual strings representing the key and the value in the + * stringbank will still stay in the bank, since there's no way to + * ensure they aren't still in use somewhere. In fact, that's the + * only reason returning the value is safe at all. */ + +const char * +Alist_RemoveString (alist *m, const char *key) +{ + alist_entry *todel = NULL; + if (!strcmp (m->first->key, key)) + { + todel = m->first; + m->first = m->first->next; + } + else + { + alist_entry *x = m->first; + while (x->next != NULL) { + if (!strcmp (x->next->key, key)) + { + todel = x->next; + x->next = x->next->next; + break; + } + x = x->next; + } + } + if (todel) + { + const char *result = todel->value; + todel->next = NULL; + AlistEntry_Free (todel); + return result; + } + return NULL; +} + + alist * Alist_New_FromFile (uio_Stream *f) { diff --git a/sc2/src/sc2code/libs/resource/alist.h b/sc2/src/sc2code/libs/resource/alist.h index 729b6e855..c0d5f45ca 100644 --- a/sc2/src/sc2code/libs/resource/alist.h +++ b/sc2/src/sc2code/libs/resource/alist.h @@ -59,6 +59,9 @@ const char *Alist_GetString (alist *m, const char *key); void Alist_PutString (alist *m, const char *key, const char *value); void Alist_PutAll (alist *dest, alist *src); +/* Remove operation. Returns the old value, or NULL if it didn't exist. */ +const char *Alist_RemoveString (alist *m, const char *key); + /* Dump the alist to the specified stream in a form that could be read later by the Alist_New_From* routines. Dump only keys that begin with the prefix; NULL means all keys. */