aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/examples/eina_inlist_03.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-04 18:41:13 +1000
committerDavid Walter Seikel2012-01-04 18:41:13 +1000
commitdd7595a3475407a7fa96a97393bae8c5220e8762 (patch)
treee341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/eina/src/examples/eina_inlist_03.c
parentAdd the skeleton. (diff)
downloadSledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/eina/src/examples/eina_inlist_03.c')
-rw-r--r--libraries/eina/src/examples/eina_inlist_03.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/libraries/eina/src/examples/eina_inlist_03.c b/libraries/eina/src/examples/eina_inlist_03.c
new file mode 100644
index 0000000..a39a784
--- /dev/null
+++ b/libraries/eina/src/examples/eina_inlist_03.c
@@ -0,0 +1,73 @@
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 Eina_Inlist even;
9 int a, b;
10};
11
12#define EVEN_INLIST_GET(Inlist) (& ((Inlist)->even))
13
14#define EVEN_INLIST_CONTAINER_GET(ptr, type) \
15 ((type *)((char *)ptr - offsetof(type, even)))
16
17int
18main(void)
19{
20 struct my_struct *d, *cur;
21 int i;
22
23 Eina_Inlist *list = NULL, *list_even = NULL, *itr;
24
25 eina_init();
26
27 for (i = 0; i < 100; i++)
28 {
29 d = malloc(sizeof(*d));
30 d->a = i;
31 d->b = i * 10;
32 list = eina_inlist_append(list, EINA_INLIST_GET(d));
33 if ((i % 2) == 0)
34 list_even = eina_inlist_prepend(list_even, EVEN_INLIST_GET(d));
35 }
36
37 printf("list=%p\n", list);
38 EINA_INLIST_FOREACH(list, cur)
39 printf("\ta=%d, b=%d\n", cur->a, cur->b);
40
41 printf("list_even=%p\n", list_even);
42 for (itr = list_even; itr != NULL; itr = itr->next)
43 {
44 cur = EVEN_INLIST_CONTAINER_GET(itr, struct my_struct);
45 printf("\ta=%d, b=%d\n", cur->a, cur->b);
46 }
47
48 printf("list count=%d\n", eina_inlist_count(list));
49 printf("list_even count=%d\n\n", eina_inlist_count(list_even));
50
51 itr = list_even;
52 while (itr)
53 {
54 Eina_Inlist *next = itr->next;
55 cur = EVEN_INLIST_CONTAINER_GET(itr, struct my_struct);
56 if ((cur->a % 3) == 0)
57 list_even = eina_inlist_remove(list_even, itr);
58 itr = next;
59 }
60 printf("list count=%d\n", eina_inlist_count(list));
61 printf("list_even count=%d\n\n", eina_inlist_count(list_even));
62
63 while (list)
64 {
65 Eina_Inlist *aux = list;
66 list = eina_inlist_remove(list, list);
67 free(aux);
68 }
69
70 eina_shutdown();
71
72 return 0;
73}