1 /**
2  *    _______       _______            __        __
3  *   / ____/ |     / / ___/____  _____/ /_____  / /_
4  *  / / __ | | /| / /\__ \/ __ \/ ___/ //_/ _ \/ __/
5  * / /_/ / | |/ |/ /___/ / /_/ / /__/ ,< /  __/ /_
6  * \____/  |__/|__//____/\____/\___/_/|_|\___/\__/
7  *
8  * The MIT License (MIT)
9  * Copyright (c) 2009-2020 Gerardo Orellana <hello @ goaccess.io>
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a copy
12  * of this software and associated documentation files (the "Software"), to deal
13  * in the Software without restriction, including without limitation the rights
14  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  * copies of the Software, and to permit persons to whom the Software is
16  * furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in all
19  * copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  */
29 
30 #ifndef GSLIST_H_INCLUDED
31 #define GSLIST_H_INCLUDED
32 
33 /* Generic Single linked-list */
34 typedef struct GSLList_ {
35   void *data;
36   struct GSLList_ *next;
37 } GSLList;
38 
39 #define GSLIST_FOREACH(node, data, code) {  \
40   GSLList *__tmp = node;                    \
41   while (__tmp) {                           \
42     (data) = __tmp->data;                   \
43     code;                                   \
44     __tmp = __tmp->next;                    \
45   }}
46 
47 /* single linked-list */
48 GSLList *list_create (void *data);
49 GSLList *list_find (GSLList * node, int (*func) (void *, void *), void *data);
50 GSLList *list_insert_append (GSLList * node, void *data);
51 GSLList *list_insert_prepend (GSLList * list, void *data);
52 GSLList *list_copy (GSLList * node);
53 int list_count (GSLList * list);
54 int list_foreach (GSLList * node, int (*func) (void *, void *), void *user_data);
55 int list_remove_node (GSLList ** list, GSLList * node);
56 int list_remove_nodes (GSLList * list);
57 
58 #endif // for #ifndef GSLIST_H
59