
\begin{DoxyCodeInclude}
1 \textcolor{comment}{//Compile with:}
2 \textcolor{comment}{// gcc -o eet-file eet-file.c `pkg-config --cflags --libs eet`}
3 
4 \textcolor{preprocessor}{#include <\hyperlink{Eet_8h}{Eet.h}>}
5 \textcolor{preprocessor}{#include <stdio.h>}
6 \textcolor{preprocessor}{#include <string.h>}
7 
8 \textcolor{keyword}{static} \textcolor{keywordtype}{int}
9 create\_eet\_file(\textcolor{keywordtype}{void})
10 \{
11    \hyperlink{group__Eet__File__Group_ga8d9779184a9870c1a225f1f40c76e8a7}{Eet\_File} *ef;
12    \textcolor{keywordtype}{char} buf[1024], *ptr;
13    \textcolor{keywordtype}{int} size, len, i;
14    \textcolor{keyword}{const} \textcolor{keywordtype}{char} *some\_strings[] = \{
15       \textcolor{stringliteral}{"And some more strings"},
16       \textcolor{stringliteral}{"spread across several"},
17       \textcolor{stringliteral}{"elements of an array!"}
18    \};
19    \textcolor{keyword}{const} \textcolor{keywordtype}{char} some\_data[] =
20      \textcolor{stringliteral}{"\(\backslash\)x1e\(\backslash\)xe7\(\backslash\)x0f\(\backslash\)x42\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x01\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x35"}
21      \textcolor{stringliteral}{"\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)xa0\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)xa0\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x24\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x11"}
22      \textcolor{stringliteral}{"\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x00\(\backslash\)x2f\(\backslash\)x6d\(\backslash\)x69\(\backslash\)x73\(\backslash\)x74\(\backslash\)x65\(\backslash\)x72\(\backslash\)x69\(\backslash\)x6f\(\backslash\)x75\(\backslash\)x73\(\backslash\)x2f"}
23      \textcolor{stringliteral}{"\(\backslash\)x64\(\backslash\)x61\(\backslash\)x74\(\backslash\)x61\(\backslash\)x00\(\backslash\)x41\(\backslash\)x6e\(\backslash\)x20\(\backslash\)x45\(\backslash\)x45\(\backslash\)x54\(\backslash\)x20\(\backslash\)x69\(\backslash\)x6e\(\backslash\)x73\(\backslash\)x69"}
24      \textcolor{stringliteral}{"\(\backslash\)x64\(\backslash\)x65\(\backslash\)x20\(\backslash\)x6f\(\backslash\)x66\(\backslash\)x20\(\backslash\)x61\(\backslash\)x6e\(\backslash\)x20\(\backslash\)x45\(\backslash\)x45\(\backslash\)x54\(\backslash\)x21\(\backslash\)x0a\(\backslash\)x54\(\backslash\)x68"}
25      \textcolor{stringliteral}{"\(\backslash\)x69\(\backslash\)x73\(\backslash\)x20\(\backslash\)x77\(\backslash\)x61\(\backslash\)x73\(\backslash\)x6e\(\backslash\)x27\(\backslash\)x74\(\backslash\)x20\(\backslash\)x72\(\backslash\)x65\(\backslash\)x61\(\backslash\)x6c\(\backslash\)x6c\(\backslash\)x79"}
26      \textcolor{stringliteral}{"\(\backslash\)x20\(\backslash\)x75\(\backslash\)x73\(\backslash\)x65\(\backslash\)x66\(\backslash\)x75\(\backslash\)x6c\(\backslash\)x20\(\backslash\)x62\(\backslash\)x75\(\backslash\)x74\(\backslash\)x20\(\backslash\)x69\(\backslash\)x74\(\backslash\)x20\(\backslash\)x68"}
27      \textcolor{stringliteral}{"\(\backslash\)x65\(\backslash\)x6c\(\backslash\)x70\(\backslash\)x65\(\backslash\)x64\(\backslash\)x20\(\backslash\)x74\(\backslash\)x6f\(\backslash\)x20\(\backslash\)x73\(\backslash\)x68\(\backslash\)x6f\(\backslash\)x77\(\backslash\)x20\(\backslash\)x68\(\backslash\)x6f"}
28      \textcolor{stringliteral}{"\(\backslash\)x77\(\backslash\)x0a\(\backslash\)x74\(\backslash\)x6f\(\backslash\)x20\(\backslash\)x75\(\backslash\)x73\(\backslash\)x65\(\backslash\)x20\(\backslash\)x65\(\backslash\)x65\(\backslash\)x74\(\backslash\)x5f\(\backslash\)x6d\(\backslash\)x65\(\backslash\)x6d"}
29      \textcolor{stringliteral}{"\(\backslash\)x6f\(\backslash\)x70\(\backslash\)x65\(\backslash\)x6e\(\backslash\)x5f\(\backslash\)x72\(\backslash\)x65\(\backslash\)x61\(\backslash\)x64\(\backslash\)x28\(\backslash\)x29\(\backslash\)x20\(\backslash\)x74\(\backslash\)x6f\(\backslash\)x20\(\backslash\)x6f"}
30      \textcolor{stringliteral}{"\(\backslash\)x70\(\backslash\)x65\(\backslash\)x6e\(\backslash\)x20\(\backslash\)x61\(\backslash\)x6e\(\backslash\)x20\(\backslash\)x65\(\backslash\)x65\(\backslash\)x74\(\backslash\)x20\(\backslash\)x66\(\backslash\)x69\(\backslash\)x6c\(\backslash\)x65\(\backslash\)x20"}
31      \textcolor{stringliteral}{"\(\backslash\)x66\(\backslash\)x72\(\backslash\)x6f\(\backslash\)x6d\(\backslash\)x0a\(\backslash\)x64\(\backslash\)x61\(\backslash\)x74\(\backslash\)x61\(\backslash\)x20\(\backslash\)x61\(\backslash\)x6c\(\backslash\)x72\(\backslash\)x65\(\backslash\)x61\(\backslash\)x64"}
32      \textcolor{stringliteral}{"\(\backslash\)x79\(\backslash\)x20\(\backslash\)x6c\(\backslash\)x6f\(\backslash\)x61\(\backslash\)x64\(\backslash\)x65\(\backslash\)x64\(\backslash\)x20\(\backslash\)x69\(\backslash\)x6e\(\backslash\)x20\(\backslash\)x6d\(\backslash\)x65\(\backslash\)x6d\(\backslash\)x6f"}
33      \textcolor{stringliteral}{"\(\backslash\)x72\(\backslash\)x79\(\backslash\)x2e\(\backslash\)x0a\(\backslash\)x00"};
34 
35    ef = \hyperlink{group__Eet__File__Group_ga5f55956b860aa2c77af9b1a880c4c256}{eet\_open}(\textcolor{stringliteral}{"/tmp/my\_file.eet"}, \hyperlink{group__Eet__File__Group_ggaa8e1a7af50fefaf15eb2f69543d24998a8f395f56fba48be007c65be51d799ee9}{EET\_FILE\_MODE\_WRITE});
36    \textcolor{keywordflow}{if} (!ef) \textcolor{keywordflow}{return} 0;
37 
38    strcpy(buf, \textcolor{stringliteral}{"Here is a string of data to save!"});
39    size = \hyperlink{group__Eet__File__Group_ga682d04715f0e11380c460814c4a9bd21}{eet\_write}(ef, \textcolor{stringliteral}{"/key/to\_store/at"}, buf, \textcolor{keyword}{sizeof}(buf), 1);
40    \textcolor{keywordflow}{if} (!size)
41      \{
42         fprintf(stderr, \textcolor{stringliteral}{"Error writing data!\(\backslash\)n"});
43         \hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}(ef);
44         \textcolor{keywordflow}{return} 0;
45      \}
46    len = strlen(buf);
47    printf(\textcolor{stringliteral}{"strlen() = %d, eet\_write() = %d\(\backslash\)n"}, len, size);
48 
49    ptr = buf;
50    \textcolor{keywordflow}{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    \hyperlink{group__Eet__File__Group_ga682d04715f0e11380c460814c4a9bd21}{eet\_write}(ef, \textcolor{stringliteral}{"/several/strings"}, buf, \textcolor{keyword}{sizeof}(buf), 1);
57    \hyperlink{group__Eet__File__Group_gaf343f344180955ed898aa86b90ebefda}{eet\_sync}(ef);
58 
59    \hyperlink{group__Eet__File__Group_ga682d04715f0e11380c460814c4a9bd21}{eet\_write}(ef, \textcolor{stringliteral}{"/some/mysterious/data"}, some\_data, \textcolor{keyword}{sizeof}(some\_data) - 1, 1);
60 
61    \hyperlink{group__Eet__File__Group_gaa8a980d684123dfbaf12e7efefdb57f5}{eet\_delete}(ef, \textcolor{stringliteral}{"/several/strings"});
62 
63    \textcolor{keywordflow}{return} \hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}(ef) == \hyperlink{group__Eet__Group_ggaa9142d865094701672375485d4a6284da2e3af24c66d0decf7c97fe4e5a7f75d4}{EET\_ERROR\_NONE};
64 \}
65 
66 \textcolor{keywordtype}{int}
67 main(\textcolor{keywordtype}{void})
68 \{
69    \hyperlink{group__Eet__File__Group_ga8d9779184a9870c1a225f1f40c76e8a7}{Eet\_File} *ef;
70    \textcolor{keywordtype}{char} *ret, **list;
71    \textcolor{keywordtype}{int} size, num, i;
72 
73    \hyperlink{group__Eet__Group_ga9903687bfa20fe9a9e59d4c1d213e89a}{eet\_init}();
74 
75    \textcolor{keywordflow}{if} (!create\_eet\_file())
76      \textcolor{keywordflow}{return} -1;
77 
78    ef = \hyperlink{group__Eet__File__Group_ga5f55956b860aa2c77af9b1a880c4c256}{eet\_open}(\textcolor{stringliteral}{"/tmp/my\_file.eet"}, \hyperlink{group__Eet__File__Group_ggaa8e1a7af50fefaf15eb2f69543d24998a416f7e9a76b8131a44bbeedb13060c81}{EET\_FILE\_MODE\_READ});
79    \textcolor{keywordflow}{if} (!ef) \textcolor{keywordflow}{return} -1;
80 
81    list = \hyperlink{group__Eet__File__Group_ga6700a425f59086e7c8a945d6923874d3}{eet\_list}(ef, \textcolor{stringliteral}{"*"}, &num);
82    \textcolor{keywordflow}{if} (list)
83      \{
84         \textcolor{keywordflow}{for} (i = 0; i < num; i++)
85           printf(\textcolor{stringliteral}{"Key stored: %s\(\backslash\)n"}, list[i]);
86         free(list);
87      \}
88 
89    ret = \hyperlink{group__Eet__File__Group_gac13cdf7782d1e513f5b1abcc529962f4}{eet\_read}(ef, \textcolor{stringliteral}{"/key/to\_store/at"}, &size);
90    \textcolor{keywordflow}{if} (ret)
91      \{
92         printf(\textcolor{stringliteral}{"Data read (%i bytes):\(\backslash\)n%s\(\backslash\)n"}, size, ret);
93         free(ret);
94      \}
95 
96    ret = \hyperlink{group__Eet__File__Group_gac13cdf7782d1e513f5b1abcc529962f4}{eet\_read}(ef, \textcolor{stringliteral}{"/several/strings"}, &size);
97    \textcolor{keywordflow}{if} (ret)
98      \{
99         printf(\textcolor{stringliteral}{"More data read (%i bytes):\(\backslash\)n%s\(\backslash\)n"}, size, ret);
100         free(ret);
101      \}
102 
103    ret = \hyperlink{group__Eet__File__Group_gac13cdf7782d1e513f5b1abcc529962f4}{eet\_read}(ef, \textcolor{stringliteral}{"/some/mysterious/data"}, &size);
104    \textcolor{keywordflow}{if} (ret)
105      \{
106         \hyperlink{group__Eet__File__Group_ga8d9779184a9870c1a225f1f40c76e8a7}{Eet\_File} *ef2;
107 
108         ef2 = \hyperlink{group__Eet__File__Group_gac514fa1812cfe27f0b7c0ff5fc13af45}{eet\_memopen\_read}(ret, size);
109 
110         num = \hyperlink{group__Eet__File__Group_ga53bf1cf96267787aa93a99a0fe7ba8f7}{eet\_num\_entries}(ef2);
111         printf(\textcolor{stringliteral}{"Mysterious data has %d entries\(\backslash\)n"}, num);
112 
113         printf(\textcolor{stringliteral}{"Mysterious data:\(\backslash\)n%s\(\backslash\)n"},
114                (\textcolor{keywordtype}{char} *)\hyperlink{group__Eet__File__Group_ga73852ab3d1276c2913715b3716cf4a04}{eet\_read\_direct}(ef2, \textcolor{stringliteral}{"/mysterious/data"}, NULL));
115 
116         \hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}(ef2);
117 
118         free(ret);
119      \}
120 
121    \hyperlink{group__Eet__File__Group_ga1675fef1f6012c1e02ae313d13dc3e03}{eet\_close}(ef);
122 
123    \hyperlink{group__Eet__Group_gacbc7583179399d3b3e7b003e911f866f}{eet\_shutdown}();
124 
125    \textcolor{keywordflow}{return} 0;
126 \}
127 
\end{DoxyCodeInclude}
 