summaryrefslogtreecommitdiff
path: root/legacy/eet/src/bin
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2007-09-08 09:35:41 +0000
committerCarsten Haitzler <raster@rasterman.com>2007-09-08 09:35:41 +0000
commit0655006f422f073e117a4b439583660949c517c3 (patch)
tree48c332270fad716939f1b847ab08889707d5f3fd /legacy/eet/src/bin
parentbb89d5a5ab95f5a8e0e5d62fed471c00340acb55 (diff)
and now we have a small tool that can extract, import, list, decode, encode
etc. data from eet files. just run eet for usage. SVN revision: 31651
Diffstat (limited to 'legacy/eet/src/bin')
-rw-r--r--legacy/eet/src/bin/Makefile.am12
-rw-r--r--legacy/eet/src/bin/eet_main.c259
2 files changed, 271 insertions, 0 deletions
diff --git a/legacy/eet/src/bin/Makefile.am b/legacy/eet/src/bin/Makefile.am
new file mode 100644
index 0000000000..051db2b638
--- /dev/null
+++ b/legacy/eet/src/bin/Makefile.am
@@ -0,0 +1,12 @@
1## Process this file with automake to produce Makefile.in
2
3AM_CFLAGS = \
4-I$(top_srcdir) \
5-I$(top_srcdir)/bin \
6-I$(top_srcdir)/src/lib
7
8bin_PROGRAMS = eet
9
10eet_SOURCES = eet_main.c
11eet_LDADD = $(top_builddir)/src/lib/libeet.la
12eet_DEPENDENCIES = $(top_builddir)/src/lib/libeet.la
diff --git a/legacy/eet/src/bin/eet_main.c b/legacy/eet/src/bin/eet_main.c
new file mode 100644
index 0000000000..8e01f5e542
--- /dev/null
+++ b/legacy/eet/src/bin/eet_main.c
@@ -0,0 +1,259 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <string.h>
5#include <Eet.h>
6
7static void
8do_eet_list(const char *file)
9{
10 int i, num;
11 char **list;
12 Eet_File *ef;
13
14 ef = eet_open(file, EET_FILE_MODE_READ);
15 if (!ef)
16 {
17 printf("cannot open for reading: %s\n", file);
18 exit(-1);
19 }
20 list = eet_list(ef, "*", &num);
21 if (list)
22 {
23 for (i = 0; i < num; i++)
24 printf("%s\n",list[i]);
25 free(list);
26 }
27 eet_close(ef);
28}
29
30static void
31do_eet_extract(const char *file, const char *key, const char *out)
32{
33 Eet_File *ef;
34 void *data;
35 int size = 0;
36 FILE *f;
37
38 ef = eet_open(file, EET_FILE_MODE_READ);
39 if (!ef)
40 {
41 printf("cannot open for reading: %s\n", file);
42 exit(-1);
43 }
44 data = eet_read(ef, key, &size);
45 if (!data)
46 {
47 printf("cannot read key %s\n", key);
48 exit(-1);
49 }
50 f = fopen(out, "w");
51 if (!f)
52 {
53 printf("cannot open %s\n", out);
54 exit(-1);
55 }
56 if (fwrite(data, size, 1, f) != 1)
57 {
58 printf("cannot write to %s\n", out);
59 exit(-1);
60 }
61 fclose(f);
62 free(data);
63 eet_close(ef);
64}
65
66static void
67do_eet_decode_dump(void *data, const char *str)
68{
69 fputs(str, (FILE *)data);
70}
71
72static void
73do_eet_decode(const char *file, const char *key, const char *out)
74{
75 Eet_File *ef;
76 void *data;
77 int size = 0;
78 FILE *f;
79
80 ef = eet_open(file, EET_FILE_MODE_READ);
81 if (!ef)
82 {
83 printf("cannot open for reading: %s\n", file);
84 exit(-1);
85 }
86 data = eet_read(ef, key, &size);
87 if (!data)
88 {
89 printf("cannot read key %s\n", key);
90 exit(-1);
91 }
92 f = fopen(out, "w");
93 if (!f)
94 {
95 printf("cannot open %s\n", out);
96 exit(-1);
97 }
98 if (!eet_data_text_dump(data, size, do_eet_decode_dump, f))
99 {
100 printf("cannot write to %s\n", out);
101 exit(-1);
102 }
103 fclose(f);
104 free(data);
105 eet_close(ef);
106}
107
108static void
109do_eet_insert(const char *file, const char *key, const char *out, int compress)
110{
111 Eet_File *ef;
112 void *data;
113 int size = 0;
114 FILE *f;
115
116 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
117 if (!ef)
118 ef = eet_open(file, EET_FILE_MODE_WRITE);
119 if (!ef)
120 {
121 printf("cannot open for read+write: %s\n", file);
122 exit(-1);
123 }
124 f = fopen(out, "r");
125 if (!f)
126 {
127 printf("cannot open %s\n", out);
128 exit(-1);
129 }
130 fseek(f, 0, SEEK_END);
131 size = ftell(f);
132 rewind(f);
133 data = malloc(size);
134 if (!data)
135 {
136 printf("cannot allocate %i bytes\n", size);
137 exit(-1);
138 }
139 if (fread(data, size, 1, f) != 1)
140 {
141 printf("cannot read file %s\n", out);
142 exit(-1);
143 }
144 fclose(f);
145 eet_write(ef, key, data, size, compress);
146 free(data);
147 eet_close(ef);
148}
149
150static void
151do_eet_encode(const char *file, const char *key, const char *out, int compress)
152{
153 Eet_File *ef;
154 char *text;
155 int textlen = 0;
156 void *data;
157 int size = 0;
158 FILE *f;
159
160 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
161 if (!ef)
162 ef = eet_open(file, EET_FILE_MODE_WRITE);
163 if (!ef)
164 {
165 printf("cannot open for read+write: %s\n", file);
166 exit(-1);
167 }
168 f = fopen(out, "r");
169 if (!f)
170 {
171 printf("cannot open %s\n", out);
172 exit(-1);
173 }
174 fseek(f, 0, SEEK_END);
175 textlen = ftell(f);
176 rewind(f);
177 text = malloc(textlen);
178 if (!text)
179 {
180 printf("cannot allocate %i bytes\n", size);
181 exit(-1);
182 }
183 if (fread(text, textlen, 1, f) != 1)
184 {
185 printf("cannot read file %s\n", out);
186 exit(-1);
187 }
188 fclose(f);
189 data = eet_data_text_undump(text, textlen, &size);
190 if (!data)
191 {
192 printf("cannot parse %s\n", out);
193 exit(-1);
194 }
195 eet_write(ef, key, data, size, compress);
196 free(text);
197 free(data);
198 eet_close(ef);
199}
200
201static void
202do_eet_remove(const char *file, const char *key)
203{
204 Eet_File *ef;
205
206 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
207 if (!ef)
208 {
209 printf("cannot open for read+write: %s\n", file);
210 exit(-1);
211 }
212 eet_delete(ef, key);
213 eet_close(ef);
214}
215
216int
217main(int argc, char **argv)
218{
219 eet_init();
220 if (argc < 2)
221 {
222 printf("Usage:\n"
223 " eet -l FILE.EET list all keys in FILE.EET\n"
224 " eet -x FILE.EET KEY OUT-FILE extract data stored in KEY in FILE.EET and write to OUT-FILE\n"
225 " eet -d FILE.EET KEY OUT-FILE extract and decode data stored in KEY in FILE.EET and write to OUT-FILE\n"
226 " eet -i FILE.EET KEY IN-FILE COMPRESS insert data to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
227 " eet -e FILE.EET KEY IN-FILE COMPRESS insert and encode to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
228 " eet -r FILE.EET KEY remove KEY in FILE.EET\n"
229 );
230 eet_shutdown();
231 return 0;
232 }
233 if ((!strcmp(argv[1], "-l")) && (argc > 2))
234 {
235 do_eet_list(argv[2]);
236 }
237 else if ((!strcmp(argv[1], "-x")) && (argc > 4))
238 {
239 do_eet_extract(argv[2], argv[3], argv[4]);
240 }
241 else if ((!strcmp(argv[1], "-d")) && (argc > 4))
242 {
243 do_eet_decode(argv[2], argv[3], argv[4]);
244 }
245 else if ((!strcmp(argv[1], "-i")) && (argc > 5))
246 {
247 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]));
248 }
249 else if ((!strcmp(argv[1], "-e")) && (argc > 5))
250 {
251 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]));
252 }
253 else if ((!strcmp(argv[1], "-r")) && (argc > 3))
254 {
255 do_eet_remove(argv[2], argv[3]);
256 }
257 eet_shutdown();
258 return 0;
259}