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
This commit is contained in:
Carsten Haitzler 2007-09-08 09:35:41 +00:00
parent bb89d5a5ab
commit 0655006f42
6 changed files with 282 additions and 3 deletions

View File

@ -131,6 +131,7 @@ eet.pc
eet.c
src/Makefile
src/lib/Makefile
src/bin/Makefile
README
eet.spec
debian/changelog

View File

@ -1,3 +1,3 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS = lib
SUBDIRS = lib bin

View File

@ -0,0 +1,12 @@
## Process this file with automake to produce Makefile.in
AM_CFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/bin \
-I$(top_srcdir)/src/lib
bin_PROGRAMS = eet
eet_SOURCES = eet_main.c
eet_LDADD = $(top_builddir)/src/lib/libeet.la
eet_DEPENDENCIES = $(top_builddir)/src/lib/libeet.la

View File

@ -0,0 +1,259 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <Eet.h>
static void
do_eet_list(const char *file)
{
int i, num;
char **list;
Eet_File *ef;
ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef)
{
printf("cannot open for reading: %s\n", file);
exit(-1);
}
list = eet_list(ef, "*", &num);
if (list)
{
for (i = 0; i < num; i++)
printf("%s\n",list[i]);
free(list);
}
eet_close(ef);
}
static void
do_eet_extract(const char *file, const char *key, const char *out)
{
Eet_File *ef;
void *data;
int size = 0;
FILE *f;
ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef)
{
printf("cannot open for reading: %s\n", file);
exit(-1);
}
data = eet_read(ef, key, &size);
if (!data)
{
printf("cannot read key %s\n", key);
exit(-1);
}
f = fopen(out, "w");
if (!f)
{
printf("cannot open %s\n", out);
exit(-1);
}
if (fwrite(data, size, 1, f) != 1)
{
printf("cannot write to %s\n", out);
exit(-1);
}
fclose(f);
free(data);
eet_close(ef);
}
static void
do_eet_decode_dump(void *data, const char *str)
{
fputs(str, (FILE *)data);
}
static void
do_eet_decode(const char *file, const char *key, const char *out)
{
Eet_File *ef;
void *data;
int size = 0;
FILE *f;
ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef)
{
printf("cannot open for reading: %s\n", file);
exit(-1);
}
data = eet_read(ef, key, &size);
if (!data)
{
printf("cannot read key %s\n", key);
exit(-1);
}
f = fopen(out, "w");
if (!f)
{
printf("cannot open %s\n", out);
exit(-1);
}
if (!eet_data_text_dump(data, size, do_eet_decode_dump, f))
{
printf("cannot write to %s\n", out);
exit(-1);
}
fclose(f);
free(data);
eet_close(ef);
}
static void
do_eet_insert(const char *file, const char *key, const char *out, int compress)
{
Eet_File *ef;
void *data;
int size = 0;
FILE *f;
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef)
ef = eet_open(file, EET_FILE_MODE_WRITE);
if (!ef)
{
printf("cannot open for read+write: %s\n", file);
exit(-1);
}
f = fopen(out, "r");
if (!f)
{
printf("cannot open %s\n", out);
exit(-1);
}
fseek(f, 0, SEEK_END);
size = ftell(f);
rewind(f);
data = malloc(size);
if (!data)
{
printf("cannot allocate %i bytes\n", size);
exit(-1);
}
if (fread(data, size, 1, f) != 1)
{
printf("cannot read file %s\n", out);
exit(-1);
}
fclose(f);
eet_write(ef, key, data, size, compress);
free(data);
eet_close(ef);
}
static void
do_eet_encode(const char *file, const char *key, const char *out, int compress)
{
Eet_File *ef;
char *text;
int textlen = 0;
void *data;
int size = 0;
FILE *f;
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef)
ef = eet_open(file, EET_FILE_MODE_WRITE);
if (!ef)
{
printf("cannot open for read+write: %s\n", file);
exit(-1);
}
f = fopen(out, "r");
if (!f)
{
printf("cannot open %s\n", out);
exit(-1);
}
fseek(f, 0, SEEK_END);
textlen = ftell(f);
rewind(f);
text = malloc(textlen);
if (!text)
{
printf("cannot allocate %i bytes\n", size);
exit(-1);
}
if (fread(text, textlen, 1, f) != 1)
{
printf("cannot read file %s\n", out);
exit(-1);
}
fclose(f);
data = eet_data_text_undump(text, textlen, &size);
if (!data)
{
printf("cannot parse %s\n", out);
exit(-1);
}
eet_write(ef, key, data, size, compress);
free(text);
free(data);
eet_close(ef);
}
static void
do_eet_remove(const char *file, const char *key)
{
Eet_File *ef;
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef)
{
printf("cannot open for read+write: %s\n", file);
exit(-1);
}
eet_delete(ef, key);
eet_close(ef);
}
int
main(int argc, char **argv)
{
eet_init();
if (argc < 2)
{
printf("Usage:\n"
" eet -l FILE.EET list all keys in FILE.EET\n"
" eet -x FILE.EET KEY OUT-FILE extract data stored in KEY in FILE.EET and write to OUT-FILE\n"
" eet -d FILE.EET KEY OUT-FILE extract and decode data stored in KEY in FILE.EET and write to OUT-FILE\n"
" 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"
" 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"
" eet -r FILE.EET KEY remove KEY in FILE.EET\n"
);
eet_shutdown();
return 0;
}
if ((!strcmp(argv[1], "-l")) && (argc > 2))
{
do_eet_list(argv[2]);
}
else if ((!strcmp(argv[1], "-x")) && (argc > 4))
{
do_eet_extract(argv[2], argv[3], argv[4]);
}
else if ((!strcmp(argv[1], "-d")) && (argc > 4))
{
do_eet_decode(argv[2], argv[3], argv[4]);
}
else if ((!strcmp(argv[1], "-i")) && (argc > 5))
{
do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]));
}
else if ((!strcmp(argv[1], "-e")) && (argc > 5))
{
do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]));
}
else if ((!strcmp(argv[1], "-r")) && (argc > 3))
{
do_eet_remove(argv[2], argv[3]);
}
eet_shutdown();
return 0;
}

View File

@ -212,6 +212,7 @@ eet_data_get_char(void *src, void *src_end, void *dst)
if (((char *)src + sizeof(char)) > (char *)src_end) return -1;
s = (char *)src;
d = (char *)dst;
if (*s == 0) return NULL;
*d = *s;
CONV8(*d);
return sizeof(char);
@ -225,6 +226,7 @@ eet_data_put_char(const void *src, int *size_ret)
d = (char *)malloc(sizeof(char));
if (!d) return NULL;
s = (char *)src;
if (*s == 0) return NULL;
*d = *s;
CONV8(*d);
*size_ret = sizeof(char);
@ -252,6 +254,7 @@ eet_data_put_short(const void *src, int *size_ret)
d = (short *)malloc(sizeof(short));
if (!d) return NULL;
s = (short *)src;
if (*s == 0) return NULL;
*d = *s;
CONV16(*d);
*size_ret = sizeof(short);
@ -279,6 +282,7 @@ eet_data_put_int(const void *src, int *size_ret)
d = (int *)malloc(sizeof(int));
if (!d) return NULL;
s = (int *)src;
if (*s == 0) return NULL;
*d = *s;
CONV32(*d);
*size_ret = sizeof(int);
@ -306,6 +310,7 @@ eet_data_put_long_long(const void *src, int *size_ret)
d = (unsigned long long *)malloc(sizeof(unsigned long long));
if (!d) return NULL;
s = (unsigned long long *)src;
if (*s == 0) return NULL;
*d = *s;
CONV64(*d);
*size_ret = sizeof(unsigned long long);
@ -390,6 +395,7 @@ eet_data_put_float(const void *src, int *size_ret)
int len;
s = (float *)src;
if (*s == 0.0) return NULL;
prev_locale = setlocale(LC_NUMERIC, "C");
snprintf(buf, sizeof(buf), "%a", (double)(*s));
if (prev_locale) setlocale(LC_NUMERIC, prev_locale);
@ -437,6 +443,7 @@ eet_data_put_double(const void *src, int *size_ret)
int len;
s = (double *)src;
if (*s == 0.0) return NULL;
prev_locale = setlocale(LC_NUMERIC, "C");
snprintf(buf, sizeof(buf), "%a", (double)(*s));
if (prev_locale) setlocale(LC_NUMERIC, prev_locale);

View File

@ -629,8 +629,8 @@ eet_open(const char *file, Eet_File_Mode mode)
EXTRACT_INT(byte_entries, ef->data, index);
/* we cant have <= 0 values here - invalid */
if (eet_test_close((num_entries <= 0) || (byte_entries <= 0), ef))
return NULL;
// if (eet_test_close((num_entries <= 0) || (byte_entries <= 0), ef))
// return NULL;
/* we can't have more entires than minimum bytes for those! invalid! */
if (eet_test_close((num_entries * 20) > byte_entries, ef))