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/eet/src/examples/eet-file.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 'libraries/eet/src/examples/eet-file.c')
-rw-r--r-- | libraries/eet/src/examples/eet-file.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/libraries/eet/src/examples/eet-file.c b/libraries/eet/src/examples/eet-file.c new file mode 100644 index 0000000..740c179 --- /dev/null +++ b/libraries/eet/src/examples/eet-file.c | |||
@@ -0,0 +1,127 @@ | |||
1 | /* | ||
2 | * build: gcc -o eet_file eet-file.c `pkg-config --cflags --libs eet` | ||
3 | */ | ||
4 | #include <Eet.h> | ||
5 | #include <stdio.h> | ||
6 | #include <string.h> | ||
7 | |||
8 | static int | ||
9 | create_eet_file(void) | ||
10 | { | ||
11 | Eet_File *ef; | ||
12 | char buf[1024], *ptr; | ||
13 | int size, len, i; | ||
14 | const char *some_strings[] = { | ||
15 | "And some more strings", | ||
16 | "spread across several", | ||
17 | "elements of an array!" | ||
18 | }; | ||
19 | const char some_data[] = | ||
20 | "\x1e\xe7\x0f\x42\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x35" | ||
21 | "\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x00\x00\x24\x00\x00\x00\x11" | ||
22 | "\x00\x00\x00\x00\x2f\x6d\x69\x73\x74\x65\x72\x69\x6f\x75\x73\x2f" | ||
23 | "\x64\x61\x74\x61\x00\x41\x6e\x20\x45\x45\x54\x20\x69\x6e\x73\x69" | ||
24 | "\x64\x65\x20\x6f\x66\x20\x61\x6e\x20\x45\x45\x54\x21\x0a\x54\x68" | ||
25 | "\x69\x73\x20\x77\x61\x73\x6e\x27\x74\x20\x72\x65\x61\x6c\x6c\x79" | ||
26 | "\x20\x75\x73\x65\x66\x75\x6c\x20\x62\x75\x74\x20\x69\x74\x20\x68" | ||
27 | "\x65\x6c\x70\x65\x64\x20\x74\x6f\x20\x73\x68\x6f\x77\x20\x68\x6f" | ||
28 | "\x77\x0a\x74\x6f\x20\x75\x73\x65\x20\x65\x65\x74\x5f\x6d\x65\x6d" | ||
29 | "\x6f\x70\x65\x6e\x5f\x72\x65\x61\x64\x28\x29\x20\x74\x6f\x20\x6f" | ||
30 | "\x70\x65\x6e\x20\x61\x6e\x20\x65\x65\x74\x20\x66\x69\x6c\x65\x20" | ||
31 | "\x66\x72\x6f\x6d\x0a\x64\x61\x74\x61\x20\x61\x6c\x72\x65\x61\x64" | ||
32 | "\x79\x20\x6c\x6f\x61\x64\x65\x64\x20\x69\x6e\x20\x6d\x65\x6d\x6f" | ||
33 | "\x72\x79\x2e\x0a\x00"; | ||
34 | |||
35 | ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_WRITE); | ||
36 | if (!ef) return 0; | ||
37 | |||
38 | strcpy(buf, "Here is a string of data to save!"); | ||
39 | size = eet_write(ef, "/key/to_store/at", buf, sizeof(buf), 1); | ||
40 | if (!size) | ||
41 | { | ||
42 | fprintf(stderr, "Error writing data!\n"); | ||
43 | eet_close(ef); | ||
44 | return 0; | ||
45 | } | ||
46 | len = strlen(buf); | ||
47 | printf("strlen() = %d, eet_write() = %d\n", len, size); | ||
48 | |||
49 | ptr = buf; | ||
50 | for (i = 0; i < 3; i++) | ||
51 | { | ||
52 | len = strlen(some_strings[i]) + 1; | ||
53 | memcpy(ptr, some_strings[i], len); | ||
54 | ptr += len; | ||
55 | } | ||
56 | eet_write(ef, "/several/strings", buf, sizeof(buf), 1); | ||
57 | eet_sync(ef); | ||
58 | |||
59 | eet_write(ef, "/some/mysterious/data", some_data, sizeof(some_data) - 1, 1); | ||
60 | |||
61 | eet_delete(ef, "/several/strings"); | ||
62 | |||
63 | return eet_close(ef) == EET_ERROR_NONE; | ||
64 | } | ||
65 | |||
66 | int | ||
67 | main(void) | ||
68 | { | ||
69 | Eet_File *ef; | ||
70 | char *ret, **list; | ||
71 | int size, num, i; | ||
72 | |||
73 | eet_init(); | ||
74 | |||
75 | if (!create_eet_file()) | ||
76 | return -1; | ||
77 | |||
78 | ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_READ); | ||
79 | if (!ef) return -1; | ||
80 | |||
81 | list = eet_list(ef, "*", &num); | ||
82 | if (list) | ||
83 | { | ||
84 | for (i = 0; i < num; i++) | ||
85 | printf("Key stored: %s\n", list[i]); | ||
86 | free(list); | ||
87 | } | ||
88 | |||
89 | ret = eet_read(ef, "/key/to_store/at", &size); | ||
90 | if (ret) | ||
91 | { | ||
92 | printf("Data read (%i bytes):\n%s\n", size, ret); | ||
93 | free(ret); | ||
94 | } | ||
95 | |||
96 | ret = eet_read(ef, "/several/strings", &size); | ||
97 | if (ret) | ||
98 | { | ||
99 | printf("More data read (%i bytes):\n%s\n", size, ret); | ||
100 | free(ret); | ||
101 | } | ||
102 | |||
103 | ret = eet_read(ef, "/some/mysterious/data", &size); | ||
104 | if (ret) | ||
105 | { | ||
106 | Eet_File *ef2; | ||
107 | |||
108 | ef2 = eet_memopen_read(ret, size); | ||
109 | |||
110 | num = eet_num_entries(ef2); | ||
111 | printf("Mysterious data has %d entries\n", num); | ||
112 | |||
113 | printf("Mysterious data:\n%s\n", | ||
114 | (char *)eet_read_direct(ef2, "/mysterious/data", NULL)); | ||
115 | |||
116 | eet_close(ef2); | ||
117 | |||
118 | free(ret); | ||
119 | } | ||
120 | |||
121 | eet_close(ef); | ||
122 | |||
123 | eet_shutdown(); | ||
124 | |||
125 | return 0; | ||
126 | } | ||
127 | |||