aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/examples/eina_inlist_02.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/eina/src/examples/eina_inlist_02.c')
-rw-r--r--libraries/eina/src/examples/eina_inlist_02.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/libraries/eina/src/examples/eina_inlist_02.c b/libraries/eina/src/examples/eina_inlist_02.c
new file mode 100644
index 0000000..7d23f13
--- /dev/null
+++ b/libraries/eina/src/examples/eina_inlist_02.c
@@ -0,0 +1,64 @@
1// Compile with:
2// gcc -g `pkg-config --cflags --libs eina` eina_inlist_01.c -o eina_inlist_01
3#include <Eina.h>
4#include <stdio.h>
5
6struct my_struct {
7 EINA_INLIST;
8 int a, b;
9};
10
11int
12main(void)
13{
14 struct my_struct *d, *cur;
15 int i;
16
17 Eina_Inlist *inlist = NULL;
18 Eina_List *list = NULL, *l_itr, *l_next;
19
20 eina_init();
21
22 for (i = 0; i < 100; i++)
23 {
24 d = malloc(sizeof(*d));
25 d->a = i;
26 d->b = i * 10;
27 inlist = eina_inlist_append(inlist, EINA_INLIST_GET(d));
28 if ((i % 2) == 0)
29 list = eina_list_prepend(list, d);
30 }
31
32 printf("inlist=%p\n", inlist);
33 EINA_INLIST_FOREACH(inlist, cur)
34 printf("\ta=%d, b=%d\n", cur->a, cur->b);
35
36 printf("list=%p\n", list);
37 EINA_LIST_FOREACH(list, l_itr, cur)
38 printf("\ta=%d, b=%d\n", cur->a, cur->b);
39
40 printf("inlist count=%d\n", eina_inlist_count(inlist));
41 printf("list count=%d\n\n", eina_list_count(list));
42
43 EINA_LIST_FOREACH_SAFE(list, l_itr, l_next, cur)
44 {
45 if ((cur->a % 3) == 0)
46 list = eina_list_remove_list(list, l_itr);
47 }
48
49 printf("inlist count=%d\n", eina_inlist_count(inlist));
50 printf("list count=%d\n\n", eina_list_count(list));
51
52 eina_list_free(list);
53
54 while (inlist)
55 {
56 Eina_Inlist *aux = inlist;
57 inlist = eina_inlist_remove(inlist, inlist);
58 free(aux);
59 }
60
61 eina_shutdown();
62
63 return 0;
64}