diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/eina/src/examples/eina_inlist_01.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-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 '')
-rw-r--r-- | libraries/eina/src/examples/eina_inlist_01.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/libraries/eina/src/examples/eina_inlist_01.c b/libraries/eina/src/examples/eina_inlist_01.c new file mode 100644 index 0000000..fa51553 --- /dev/null +++ b/libraries/eina/src/examples/eina_inlist_01.c | |||
@@ -0,0 +1,96 @@ | |||
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 | |||
6 | struct my_struct { | ||
7 | EINA_INLIST; | ||
8 | int a, b; | ||
9 | }; | ||
10 | |||
11 | int | ||
12 | sort_cb(const void *d1, const void *d2) | ||
13 | { | ||
14 | const Eina_Inlist *l1, *l2; | ||
15 | const struct my_struct *x1, *x2; | ||
16 | |||
17 | l1 = d1; | ||
18 | l2 = d2; | ||
19 | |||
20 | x1 = EINA_INLIST_CONTAINER_GET(l1, struct my_struct); | ||
21 | x2 = EINA_INLIST_CONTAINER_GET(l2, struct my_struct); | ||
22 | |||
23 | return x1->a - x2->a; | ||
24 | } | ||
25 | |||
26 | int | ||
27 | main(void) | ||
28 | { | ||
29 | struct my_struct *d, *cur; | ||
30 | Eina_Inlist *list, *itr, *tmp; | ||
31 | |||
32 | eina_init(); | ||
33 | |||
34 | d = malloc(sizeof(*d)); | ||
35 | d->a = 1; | ||
36 | d->b = 10; | ||
37 | list = eina_inlist_append(NULL, EINA_INLIST_GET(d)); | ||
38 | |||
39 | d = malloc(sizeof(*d)); | ||
40 | d->a = 2; | ||
41 | d->b = 20; | ||
42 | list = eina_inlist_append(list, EINA_INLIST_GET(d)); | ||
43 | |||
44 | d = malloc(sizeof(*d)); | ||
45 | d->a = 3; | ||
46 | d->b = 30; | ||
47 | list = eina_inlist_prepend(list, EINA_INLIST_GET(d)); | ||
48 | |||
49 | printf("list=%p\n", list); | ||
50 | EINA_INLIST_FOREACH(list, cur) | ||
51 | printf("\ta=%d, b=%d\n", cur->a, cur->b); | ||
52 | |||
53 | list = eina_inlist_promote(list, EINA_INLIST_GET(d)); | ||
54 | |||
55 | d = malloc(sizeof(*d)); | ||
56 | d->a = 4; | ||
57 | d->b = 40; | ||
58 | list = eina_inlist_append_relative(list, EINA_INLIST_GET(d), list); | ||
59 | |||
60 | list = eina_inlist_demote(list, EINA_INLIST_GET(d)); | ||
61 | |||
62 | list = eina_inlist_sort(list, sort_cb); | ||
63 | |||
64 | printf("list after sort=%p\n", list); | ||
65 | EINA_INLIST_FOREACH(list, cur) | ||
66 | printf("\ta=%d, b=%d\n", cur->a, cur->b); | ||
67 | |||
68 | tmp = eina_inlist_find(list, EINA_INLIST_GET(d)); | ||
69 | if (tmp) | ||
70 | cur = EINA_INLIST_CONTAINER_GET(tmp, struct my_struct); | ||
71 | else | ||
72 | cur = NULL; | ||
73 | |||
74 | if (d != cur) | ||
75 | printf("wrong node! cur=%p\n", cur); | ||
76 | |||
77 | list = eina_inlist_remove(list, EINA_INLIST_GET(d)); | ||
78 | free(d); | ||
79 | printf("list=%p\n", list); | ||
80 | for (itr = list; itr != NULL; itr = itr->next) | ||
81 | { | ||
82 | cur = EINA_INLIST_CONTAINER_GET(itr, struct my_struct); | ||
83 | printf("\ta=%d, b=%d\n", cur->a, cur->b); | ||
84 | } | ||
85 | |||
86 | while (list) | ||
87 | { | ||
88 | Eina_Inlist *aux = list; | ||
89 | list = eina_inlist_remove(list, list); | ||
90 | free(aux); | ||
91 | } | ||
92 | |||
93 | eina_shutdown(); | ||
94 | |||
95 | return 0; | ||
96 | } | ||