File: list.h

package info (click to toggle)
cpufreqd 2.4.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 548 kB
  • ctags: 579
  • sloc: ansic: 5,466; makefile: 237; sh: 133
file content (88 lines) | stat: -rw-r--r-- 2,156 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 *  Copyright (C) 2002-2005  Mattia Dongili <malattia@linux.it>
 *                           George Staikos <staikos@0wned.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __LIST_H
#define __LIST_H

#include <stdlib.h>

#define LIST_FOREACH(lst, fun) \
                {\
                  for (struct NODE *n=lst->first; n!=NULL; n=n->next) {\
                    (*fun)(n->content);\
                  }\
                }

#define LIST_FOREACH_NODE(node, list) \
	for (struct NODE *node = (list)->first; node != NULL; node = node->next)

#define LIST_EMPTY(list) ((list)->first==NULL)

/*
 * Doubly linked list
 */
struct LIST {
	struct NODE *first;
	struct NODE *last;
};

/*
 * Node
 */
struct NODE {
	void *content;
	struct NODE *next;
	struct NODE *prev;
};

/*
 * Frees all the elements of the list.
 * Returns the number of freed elements.
 */
extern int list_free_sublist(struct LIST *l, struct NODE *n);

/*
 * Initializes a new string_list and
 * returns a reference to it
 */
extern struct LIST *list_new(void);

/*
 *  Removes the node nd and returns the pointer
 *  to the next node
 */
struct NODE *list_remove_node(struct LIST *l, struct NODE *nd);

/*
 * Initializes a new string_node and
 * returns a reference to it
 */
extern struct NODE *node_new(void *c, size_t s);

/*
 *  Frees a NODE.
 */
extern void node_free(struct NODE *n);

/*
 * Appends a node to the list
 */
extern void list_append(struct LIST *l, struct NODE *n);

#endif