aboutsummaryrefslogtreecommitdiffstats
path: root/set.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2013-02-21 18:37:06 +0000
committerWilmer van der Gaast <wilmer@gaast.net>2013-02-21 18:37:06 +0000
commit03886fc7d06f1414a55b918247ba0310ab16e41c (patch)
tree45605f62a5eb6b0ebb73f518036357b805a47d1d /set.c
parenta5c6ebd43dd69a7c4c2648ed09a7ebaf53cfc1b0 (diff)
Keep settings lists sorted. It's already sorted somewhat, but in unclearly
divided fragments. The lists are getting long enough in places that having sections would help. That's more work, just sorting is a good start.
Diffstat (limited to 'set.c')
-rw-r--r--set.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/set.c b/set.c
index a1eb9f03..537143f7 100644
--- a/set.c
+++ b/set.c
@@ -1,7 +1,7 @@
/********************************************************************\
* BitlBee -- An IRC to other IM-networks gateway *
* *
- * Copyright 2002-2005 Wilmer van der Gaast and others *
+ * Copyright 2002-2013 Wilmer van der Gaast and others *
\********************************************************************/
/* Some stuff to register, handle and save user preferences */
@@ -22,6 +22,7 @@
if not, write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA
*/
+
#define BITLBEE_CORE
#include "bitlbee.h"
@@ -38,9 +39,22 @@ set_t *set_add( set_t **head, const char *key, const char *def, set_eval eval, v
{
if( ( s = *head ) )
{
- while( s->next ) s = s->next;
- s->next = g_new0( set_t, 1 );
- s = s->next;
+ /* Sorted insertion. Special-case insertion at the start. */
+ if( strcmp( key, s->key ) < 0 )
+ {
+ s = g_new0( set_t, 1 );
+ s->next = *head;
+ *head = s;
+ }
+ else
+ {
+ while( s->next && strcmp( key, s->next->key ) > 0 )
+ s = s->next;
+ set_t *last_next = s->next;
+ s->next = g_new0( set_t, 1 );
+ s = s->next;
+ s->next = last_next;
+ }
}
else
{