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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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_list.h"
36 list = (fluid_list_t*) FLUID_MALLOC(sizeof(fluid_list_t));
43 delete_fluid_list(fluid_list_t *list)
54 delete1_fluid_list(fluid_list_t *list)
62 fluid_list_append(fluid_list_t *list, void* data)
64 fluid_list_t *new_list;
67 new_list = new_fluid_list();
68 new_list->data = data;
72 last = fluid_list_last(list);
73 /* g_assert (last != NULL); */
74 last->next = new_list;
83 fluid_list_prepend(fluid_list_t *list, void* data)
85 fluid_list_t *new_list;
87 new_list = new_fluid_list();
88 new_list->data = data;
89 new_list->next = list;
95 fluid_list_nth(fluid_list_t *list, int n)
97 while ((n-- > 0) && list) {
105 fluid_list_remove(fluid_list_t *list, void* data)
114 if (tmp->data == data) {
116 prev->next = tmp->next;
122 delete_fluid_list(tmp);
135 fluid_list_remove_link(fluid_list_t *list, fluid_list_t *link)
146 prev->next = tmp->next;
163 fluid_list_sort_merge(fluid_list_t *l1, fluid_list_t *l2, fluid_compare_func_t compare_func)
165 fluid_list_t list, *l;
170 if (compare_func(l1->data,l2->data) < 0) {
178 l->next= l1 ? l1 : l2;
184 fluid_list_sort(fluid_list_t *list, fluid_compare_func_t compare_func)
186 fluid_list_t *l1, *l2;
198 while ((l2 = l2->next) != NULL) {
199 if ((l2 = l2->next) == NULL)
206 return fluid_list_sort_merge(fluid_list_sort(list, compare_func),
207 fluid_list_sort(l2, compare_func),
213 fluid_list_last(fluid_list_t *list)
224 fluid_list_size(fluid_list_t *list)
234 fluid_list_t* fluid_list_insert_at(fluid_list_t *list, int n, void* data)
236 fluid_list_t *new_list;
238 fluid_list_t *prev = NULL;
240 new_list = new_fluid_list();
241 new_list->data = data;
244 while ((n-- > 0) && cur) {
249 new_list->next = cur;
252 prev->next = new_list;
259 /* Compare function to sort strings alphabetically,
260 * for use with fluid_list_sort(). */
262 fluid_list_str_compare_func (void *a, void *b)
264 if (a && b) return FLUID_STRCMP ((char *)a, (char *)b);
265 if (!a && !b) return 0;