Added AList_RemoveString

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2703 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
mcmartin
2007-02-09 02:23:56 +00:00
parent d2b3b711c1
commit e9089a4498
3 changed files with 44 additions and 0 deletions
+1
View File
@@ -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
+40
View File
@@ -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)
{
+3
View File
@@ -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. */