Fix compiler warnings.
[fvwm.git] / libs / flist.c
blob29b782119f0d1d03c01d8d71535556a3a20e880a
1 /* -*-c-*- */
2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * This module was all original code
19 * by Rob Nation
20 * Copyright 1993, Robert Nation
21 * You may use this code for any purpose, as long as the original
22 * copyright remains in the source code and all documentation
25 /* code for parsing the fvwm style command */
27 /* ---------------------------- included header files ---------------------- */
29 #include "config.h"
30 #include <stdio.h>
32 #include "safemalloc.h"
33 #include "flist.h"
35 /* ---------------------------- local definitions -------------------------- */
37 /* ---------------------------- local macros ------------------------------- */
39 /* ---------------------------- imports ------------------------------------ */
41 /* ---------------------------- included code files ------------------------ */
43 /* ---------------------------- local types -------------------------------- */
45 /* ---------------------------- forward declarations ----------------------- */
47 /* ---------------------------- local variables ---------------------------- */
49 /* ---------------------------- exported variables (globals) --------------- */
51 /* ---------------------------- local functions ---------------------------- */
53 /* ---------------------------- interface functions ------------------------ */
55 flist *flist_append_obj(flist *list, void *object)
57 flist *new = (flist *)safemalloc(sizeof(flist));
58 flist *tl = list;
60 new->object = object;
61 new->next = NULL;
62 new->prev = NULL;
64 if (list == NULL)
66 return new;
68 while(tl->next)
70 tl = tl->next;
72 tl->next = new;
73 new->prev = tl;
75 return list;
78 flist *flist_prepend_obj(flist *list, void *object)
80 flist *new = (flist *)safemalloc(sizeof(flist));
82 new->object = object;
83 new->next = NULL;
84 new->prev = NULL;
86 if (list == NULL)
88 return new;
91 if (list->prev)
93 list->prev->next = new;
94 new->prev = list->prev;
96 list->prev = new;
97 new->next = list;
99 return new;
102 flist *flist_insert_obj(flist *list, void *object, int position)
104 flist *new;
105 flist *tl;
107 if (position < 0)
109 return flist_append_obj(list, object);
111 if (position == 0)
113 return flist_prepend_obj(list, object);
115 tl = list;
116 while(tl && position-- > 0)
118 tl = tl->next;
121 if (!tl)
123 return flist_append_obj(list, object);
126 new = (flist *)safemalloc(sizeof(flist));;
127 new->object = object;
128 new->prev = NULL;
130 if (tl->prev)
132 tl->prev->next = new;
133 new->prev = tl->prev;
135 new->next = tl;
136 tl->prev = new;
138 if (tl == list)
140 return new;
143 return list;
146 flist *flist_remove_obj(flist *list, void *object)
148 flist *tl = list;
150 while (tl && tl->object != object)
152 tl = tl->next;
155 if (tl == NULL)
157 return NULL;
160 if (tl->prev)
162 tl->prev->next = tl->next;
164 if (tl->next)
166 tl->next->prev = tl->prev;
168 if (list == tl)
170 list = list->next;
172 free(tl);
174 return list;
177 flist *flist_free_list(flist *list)
179 flist *tl;
181 while (list)
183 tl = list;
184 list = list->next;
185 free(tl);
187 return NULL;