1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02110-1301, USA.
21 * Modified by the GLib Team and others 1997-1999. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
29 #include "fluid_sys.h"
30 #include "fluid_list.h"
37 list = (fluid_list_t *) FLUID_MALLOC(sizeof(fluid_list_t));
44 delete_fluid_list(fluid_list_t *list)
47 fluid_return_if_fail(list != NULL);
58 delete1_fluid_list(fluid_list_t *list)
64 fluid_list_append(fluid_list_t *list, void *data)
66 fluid_list_t *new_list;
69 new_list = new_fluid_list();
70 new_list->data = data;
74 last = fluid_list_last(list);
75 /* g_assert (last != NULL); */
76 last->next = new_list;
87 fluid_list_prepend(fluid_list_t *list, void *data)
89 fluid_list_t *new_list;
91 new_list = new_fluid_list();
92 new_list->data = data;
93 new_list->next = list;
99 fluid_list_nth(fluid_list_t *list, int n)
101 while((n-- > 0) && list)
110 fluid_list_remove(fluid_list_t *list, void *data)
120 if(tmp->data == data)
124 prev->next = tmp->next;
133 delete_fluid_list(tmp);
146 fluid_list_remove_link(fluid_list_t *list, fluid_list_t *link)
160 prev->next = tmp->next;
179 static fluid_list_t *
180 fluid_list_sort_merge(fluid_list_t *l1, fluid_list_t *l2, fluid_compare_func_t compare_func)
182 fluid_list_t list, *l;
188 if(compare_func(l1->data, l2->data) < 0)
200 l->next = l1 ? l1 : l2;
206 fluid_list_sort(fluid_list_t *list, fluid_compare_func_t compare_func)
208 fluid_list_t *l1, *l2;
223 while((l2 = l2->next) != NULL)
225 if((l2 = l2->next) == NULL)
236 return fluid_list_sort_merge(fluid_list_sort(list, compare_func),
237 fluid_list_sort(l2, compare_func),
243 fluid_list_last(fluid_list_t *list)
257 fluid_list_size(fluid_list_t *list)
270 fluid_list_t *fluid_list_insert_at(fluid_list_t *list, int n, void *data)
272 fluid_list_t *new_list;
274 fluid_list_t *prev = NULL;
276 new_list = new_fluid_list();
277 new_list->data = data;
281 while((n-- > 0) && cur)
287 new_list->next = cur;
291 prev->next = new_list;
300 /* Compare function to sort strings alphabetically,
301 * for use with fluid_list_sort(). */
303 fluid_list_str_compare_func(void *a, void *b)
307 return FLUID_STRCMP((char *)a, (char *)b);