13 /* just some sample code on how to use encoder/decoders */
49 Eet_Data_Descriptor *edd, *edd2, *edd3;
55 edd3 = eet_data_descriptor_new("blah3", sizeof(Blah3),
61 EET_DATA_DESCRIPTOR_ADD_BASIC(edd3, Blah3, "string3", string, EET_T_STRING);
63 edd2 = eet_data_descriptor_new("blah2", sizeof(Blah2),
69 EET_DATA_DESCRIPTOR_ADD_BASIC(edd2, Blah2, "string2", string, EET_T_STRING);
71 edd = eet_data_descriptor_new("blah", sizeof(Blah),
77 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "character", character, EET_T_CHAR);
78 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "sixteen", sixteen, EET_T_SHORT);
79 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "integer", integer, EET_T_INT);
80 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "lots", lots, EET_T_LONG_LONG);
81 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "floating", floating, EET_T_FLOAT);
82 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "floating_lots", floating_lots, EET_T_DOUBLE);
83 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Blah, "string", string, EET_T_STRING);
84 EET_DATA_DESCRIPTOR_ADD_SUB (edd, Blah, "blah2", blah2, edd2);
85 EET_DATA_DESCRIPTOR_ADD_LIST (edd, Blah, "blah3", blah3, edd3);
89 blah2.string="subtype string here!";
93 blah.integer=0xc0def00d;
94 blah.lots=0xdeadbeef31337777;
95 blah.floating=3.141592654;
96 blah.floating_lots=0.777777777777777;
97 blah.string="bite me like a turnip";
99 blah.blah3 = evas_list_append(NULL, &blah3);
100 blah.blah3 = evas_list_append(blah.blah3, &blah3);
101 blah.blah3 = evas_list_append(blah.blah3, &blah3);
102 blah.blah3 = evas_list_append(blah.blah3, &blah3);
103 blah.blah3 = evas_list_append(blah.blah3, &blah3);
104 blah.blah3 = evas_list_append(blah.blah3, &blah3);
105 blah.blah3 = evas_list_append(blah.blah3, &blah3);
107 data = eet_data_descriptor_encode(edd, &blah, &size);
108 f = fopen("out", "w");
111 fwrite(data, size, 1, f);
114 printf("-----DECODING\n");
115 blah_in = eet_data_descriptor_decode(edd, data, size);
116 printf("-----DECODED!\n");
117 printf("%c\n", blah_in->character);
118 printf("%x\n", (int)blah_in->sixteen);
119 printf("%x\n", blah_in->integer);
120 printf("%lx\n", blah_in->lots);
121 printf("%f\n", (double)blah_in->floating);
122 printf("%f\n", (double)blah_in->floating_lots);
123 printf("%s\n", blah_in->string);
124 printf("%p\n", blah_in->blah2);
125 printf(" %s\n", blah_in->blah2->string);
129 for (l = blah_in->blah3; l; l = l->next)
134 printf("%p\n", blah3_in);
135 printf(" %s\n", blah3_in->string);
138 eet_data_descriptor_free(edd);
139 eet_data_descriptor_free(edd2);
140 eet_data_descriptor_free(edd3);
146 int eet_mkdir(char *dir);
147 void eet_mkdirs(char *s);
149 void depak_file(Eet_File *ef, char *file);
150 void depack(char *pak_file);
152 void list(char *pak_file);
154 void pak_file(Eet_File *ef, char *file, char **noz, int noz_num);
155 void pak_dir(Eet_File *ef, char *dir, char **noz, int noz_num);
156 void pack(char *pak_file, char **files, int count, char **noz, int noz_num);
158 static mode_t default_mode =
159 S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
164 if (mkdir(dir, default_mode) < 0) return 0;
180 if (s[i] == '/') eet_mkdir(ss);
186 depak_file(Eet_File *ef, char *file)
192 data = eet_read(ef, file, &size);
199 last = strrchr(buf, '/');
206 f = fopen(file, "w");
209 fwrite(data, 1, size, f);
211 printf("exported: %s\n", file);
214 printf("error exporting: %s\n", file);
219 printf("error reading: %s\n", file);
224 depack(char *pak_file)
230 ef = eet_open(pak_file, EET_FILE_MODE_READ);
233 printf("cannot open for reading: %s\n", pak_file);
236 list = eet_list(ef, "*", &num);
239 for (i = 0; i < num; i++)
240 depak_file(ef, list[i]);
253 ef = eet_open(pak_file, EET_FILE_MODE_READ);
256 printf("cannot open for reading: %s\n", pak_file);
259 list = eet_list(ef, "*", &num);
262 for (i = 0; i < num; i++)
263 printf("%s\n",list[i]);
270 pak_file(Eet_File *ef, char *file, char **noz, int noz_num)
274 if (stat(file, &st) >= 0)
278 buf = malloc(st.st_size);
283 f = fopen(file, "r");
289 for (i = 0; i < noz_num; i++)
291 if (!fnmatch(noz[i], file, 0))
297 fread(buf, 1, st.st_size, f);
298 if (!eet_write(ef, file, buf, st.st_size, compress))
299 printf("error importing: %s\n", file);
303 printf("compress: %s\n", file);
305 printf("imported: %s\n", file);
315 pak_dir(Eet_File *ef, char *dir, char **noz, int noz_num)
322 pak_file(ef, dir, noz, noz_num);
325 while ((dp = readdir(dirp)))
329 if ((!strcmp(".", dp->d_name)) || (!strcmp("..", dp->d_name)))
334 snprintf(buf, sizeof(buf), "%s/%s", dir, dp->d_name);
335 pak_dir(ef, buf, noz, noz_num);
342 pack(char *pak_file, char **files, int count, char **noz, int noz_num)
347 ef = eet_open(pak_file, EET_FILE_MODE_WRITE);
350 printf("cannot open for writing: %s\n", pak_file);
353 for (i = 0; i < count; i++) pak_dir(ef, files[i], noz, noz_num);
359 main(int argc, char **argv)
363 if (!strcmp(argv[1], "-d"))
368 else if (!strcmp(argv[1], "-l"))
379 if (!strcmp(argv[1], "-c"))
383 for (i = 3; i < argc; i++)
385 if (!strcmp(argv[i], "-nz"))
391 noz = realloc(noz, noz_num * sizeof(char *));
392 noz[noz_num - 1] = argv[i];
398 pack(argv[2], &(argv[i]), argc - i, noz, noz_num);
405 " %s -c out_file [-nz glob [-nz glob ...]] dir_file1 [dir_file2 ...]\n"
408 " -l in_file list contents of eet file\n"
409 " -d in_file unpack eet file\n"
410 " -c out_file pack up eet file\n"
411 " -nz match don't compress files matching match glob\n"
414 " %s -c out.eet -nz \"*.jpg\" things/\n"
417 argv[0], argv[0], argv[0],
418 argv[0], argv[0], argv[0]);