testing uncrustify on eet. this shall be standard efl formatting from

now on. you may run indent on code and convert to your own formatting
if you want.. but all code MUST be "uncrustified" before being
cxommitted to svn or before generating patches. time to get the
formatting monster under control.



SVN revision: 50563
This commit is contained in:
Carsten Haitzler 2010-07-28 01:45:57 +00:00
parent ba10bce434
commit 926db95c54
16 changed files with 10555 additions and 7874 deletions

View File

@ -58,20 +58,25 @@ do_eet_list(const char *file)
if (!ef) if (!ef)
{ {
ERR("cannot open for reading: %s\n", file); ERR("cannot open for reading: %s\n", file);
exit(-1); exit(-1);
} }
list = eet_list(ef, "*", &num); list = eet_list(ef, "*", &num);
if (list) if (list)
{ {
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
printf("%s\n",list[i]); printf("%s\n",list[i]);
free(list); free(list);
} }
eet_close(ef); eet_close(ef);
} }
static void static void
do_eet_extract(const char *file, const char *key, const char *out, const char *crypto_key) do_eet_extract(const char *file,
const char *key,
const char *out,
const char *crypto_key)
{ {
Eet_File *ef; Eet_File *ef;
void *data; void *data;
@ -81,26 +86,30 @@ do_eet_extract(const char *file, const char *key, const char *out, const char *c
ef = eet_open(file, EET_FILE_MODE_READ); ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef) if (!ef)
{ {
ERR("cannot open for reading: %s\n", file); ERR("cannot open for reading: %s\n", file);
exit(-1); exit(-1);
} }
data = eet_read_cipher(ef, key, &size, crypto_key); data = eet_read_cipher(ef, key, &size, crypto_key);
if (!data) if (!data)
{ {
ERR("cannot read key %s\n", key); ERR("cannot read key %s\n", key);
exit(-1); exit(-1);
} }
f = fopen(out, "wb"); f = fopen(out, "wb");
if (!f) if (!f)
{ {
ERR("cannot open %s\n", out); ERR("cannot open %s\n", out);
exit(-1); exit(-1);
} }
if (fwrite(data, size, 1, f) != 1) if (fwrite(data, size, 1, f) != 1)
{ {
ERR("cannot write to %s\n", out); ERR("cannot write to %s\n", out);
exit(-1); exit(-1);
} }
fclose(f); fclose(f);
free(data); free(data);
eet_close(ef); eet_close(ef);
@ -113,7 +122,10 @@ do_eet_decode_dump(void *data, const char *str)
} }
static void static void
do_eet_decode(const char *file, const char *key, const char *out, const char *crypto_key) do_eet_decode(const char *file,
const char *key,
const char *out,
const char *crypto_key)
{ {
Eet_File *ef; Eet_File *ef;
FILE *f; FILE *f;
@ -121,26 +133,33 @@ do_eet_decode(const char *file, const char *key, const char *out, const char *cr
ef = eet_open(file, EET_FILE_MODE_READ); ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef) if (!ef)
{ {
ERR("cannot open for reading: %s\n", file); ERR("cannot open for reading: %s\n", file);
exit(-1); exit(-1);
} }
f = fopen(out, "wb"); f = fopen(out, "wb");
if (!f) if (!f)
{ {
ERR("cannot open %s\n", out); ERR("cannot open %s\n", out);
exit(-1); exit(-1);
} }
if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f)) if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f))
{ {
ERR("cannot write to %s\n", out); ERR("cannot write to %s\n", out);
exit(-1); exit(-1);
} }
fclose(f); fclose(f);
eet_close(ef); eet_close(ef);
} }
static void static void
do_eet_insert(const char *file, const char *key, const char *out, int compress, const char *crypto_key) do_eet_insert(const char *file,
const char *key,
const char *out,
int compress,
const char *crypto_key)
{ {
Eet_File *ef; Eet_File *ef;
void *data; void *data;
@ -149,32 +168,37 @@ do_eet_insert(const char *file, const char *key, const char *out, int compress,
ef = eet_open(file, EET_FILE_MODE_READ_WRITE); ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef) if (!ef)
ef = eet_open(file, EET_FILE_MODE_WRITE); ef = eet_open(file, EET_FILE_MODE_WRITE);
if (!ef) if (!ef)
{ {
ERR("cannot open for read+write: %s\n", file); ERR("cannot open for read+write: %s\n", file);
exit(-1); exit(-1);
} }
f = fopen(out, "rb"); f = fopen(out, "rb");
if (!f) if (!f)
{ {
ERR("cannot open %s\n", out); ERR("cannot open %s\n", out);
exit(-1); exit(-1);
} }
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
size = ftell(f); size = ftell(f);
rewind(f); rewind(f);
data = malloc(size); data = malloc(size);
if (!data) if (!data)
{ {
ERR("cannot allocate %i bytes\n", size); ERR("cannot allocate %i bytes\n", size);
exit(-1); exit(-1);
} }
if (fread(data, size, 1, f) != 1) if (fread(data, size, 1, f) != 1)
{ {
ERR("cannot read file %s\n", out); ERR("cannot read file %s\n", out);
exit(-1); exit(-1);
} }
fclose(f); fclose(f);
eet_write_cipher(ef, key, data, size, compress, crypto_key); eet_write_cipher(ef, key, data, size, compress, crypto_key);
free(data); free(data);
@ -182,7 +206,11 @@ do_eet_insert(const char *file, const char *key, const char *out, int compress,
} }
static void static void
do_eet_encode(const char *file, const char *key, const char *out, int compress, const char *crypto_key) do_eet_encode(const char *file,
const char *key,
const char *out,
int compress,
const char *crypto_key)
{ {
Eet_File *ef; Eet_File *ef;
char *text; char *text;
@ -192,38 +220,44 @@ do_eet_encode(const char *file, const char *key, const char *out, int compress,
ef = eet_open(file, EET_FILE_MODE_READ_WRITE); ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef) if (!ef)
ef = eet_open(file, EET_FILE_MODE_WRITE); ef = eet_open(file, EET_FILE_MODE_WRITE);
if (!ef) if (!ef)
{ {
ERR("cannot open for read+write: %s\n", file); ERR("cannot open for read+write: %s\n", file);
exit(-1); exit(-1);
} }
f = fopen(out, "rb"); f = fopen(out, "rb");
if (!f) if (!f)
{ {
ERR("cannot open %s\n", out); ERR("cannot open %s\n", out);
exit(-1); exit(-1);
} }
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
textlen = ftell(f); textlen = ftell(f);
rewind(f); rewind(f);
text = malloc(textlen); text = malloc(textlen);
if (!text) if (!text)
{ {
ERR("cannot allocate %i bytes\n", size); ERR("cannot allocate %i bytes\n", size);
exit(-1); exit(-1);
} }
if (fread(text, textlen, 1, f) != 1) if (fread(text, textlen, 1, f) != 1)
{ {
ERR("cannot read file %s\n", out); ERR("cannot read file %s\n", out);
exit(-1); exit(-1);
} }
fclose(f); fclose(f);
if (!eet_data_undump_cipher(ef, key, crypto_key, text, textlen, compress)) if (!eet_data_undump_cipher(ef, key, crypto_key, text, textlen, compress))
{ {
ERR("cannot parse %s\n", out); ERR("cannot parse %s\n", out);
exit(-1); exit(-1);
} }
free(text); free(text);
eet_close(ef); eet_close(ef);
} }
@ -236,9 +270,10 @@ do_eet_remove(const char *file, const char *key)
ef = eet_open(file, EET_FILE_MODE_READ_WRITE); ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef) if (!ef)
{ {
ERR("cannot open for read+write: %s\n", file); ERR("cannot open for read+write: %s\n", file);
exit(-1); exit(-1);
} }
eet_delete(ef, key); eet_delete(ef, key);
eet_close(ef); eet_close(ef);
} }
@ -254,8 +289,8 @@ do_eet_check(const char *file)
ef = eet_open(file, EET_FILE_MODE_READ); ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef) if (!ef)
{ {
ERR("checking signature of `%s` failed\n", file); ERR("checking signature of `%s` failed\n", file);
exit(-1); exit(-1);
} }
der = eet_identity_x509(ef, &der_length); der = eet_identity_x509(ef, &der_length);
@ -278,15 +313,15 @@ do_eet_sign(const char *file, const char *private_key, const char *public_key)
ef = eet_open(file, EET_FILE_MODE_READ_WRITE); ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
if (!ef) if (!ef)
{ {
ERR("cannot open for read+write: %s.\n", file); ERR("cannot open for read+write: %s.\n", file);
exit(-1); exit(-1);
} }
key = eet_identity_open(public_key, private_key, NULL); key = eet_identity_open(public_key, private_key, NULL);
if (!key) if (!key)
{ {
ERR("cannot open key '%s:%s'.\n", public_key, private_key); ERR("cannot open key '%s:%s'.\n", public_key, private_key);
exit(-1); exit(-1);
} }
fprintf(stdout, "Using the following key to sign `%s`.\n", file); fprintf(stdout, "Using the following key to sign `%s`.\n", file);
@ -301,83 +336,75 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
if (!eet_init()) if (!eet_init())
return -1; return -1;
_eet_main_log_dom = eina_log_domain_register("Eet_Main",EINA_COLOR_CYAN); _eet_main_log_dom = eina_log_domain_register("Eet_Main",EINA_COLOR_CYAN);
if(_eet_main_log_dom < -1) if(_eet_main_log_dom < -1)
{ {
EINA_LOG_ERR("Impossible to create a log domain for eet_main.\n"); EINA_LOG_ERR("Impossible to create a log domain for eet_main.\n");
eet_shutdown(); eet_shutdown();
return(-1); return(-1);
} }
if (argc < 2) if (argc < 2)
{ {
help: help:
printf("Usage:\n" printf(
" eet -l FILE.EET list all keys in FILE.EET\n" "Usage:\n"
" eet -x FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE\n" " eet -l FILE.EET list all keys in FILE.EET\n"
" eet -d FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract and decode data stored in KEY in FILE.EET and write to OUT-FILE\n" " eet -x FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE\n"
" eet -i FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert data to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n" " eet -d FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract and decode data stored in KEY in FILE.EET and write to OUT-FILE\n"
" eet -e FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert and encode to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n" " eet -i FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert data 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 -e FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert and encode to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
" eet -c FILE.EET report and check the signature information of an eet file\n" " eet -r FILE.EET KEY remove KEY in FILE.EET\n"
" eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n" " eet -c FILE.EET report and check the signature information of an eet file\n"
); " eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n"
eet_shutdown(); );
return -1; eet_shutdown();
return -1;
} }
if ((!strncmp(argv[1], "-h", 2))) if ((!strncmp(argv[1], "-h", 2)))
{ goto help;
goto help;
}
else if ((!strcmp(argv[1], "-l")) && (argc > 2)) else if ((!strcmp(argv[1], "-l")) && (argc > 2))
{ do_eet_list(argv[2]);
do_eet_list(argv[2]);
}
else if ((!strcmp(argv[1], "-x")) && (argc > 4)) else if ((!strcmp(argv[1], "-x")) && (argc > 4))
{ {
if (argc > 5) if (argc > 5)
do_eet_extract(argv[2], argv[3], argv[4], argv[5]); do_eet_extract(argv[2], argv[3], argv[4], argv[5]);
else else
do_eet_extract(argv[2], argv[3], argv[4], NULL); do_eet_extract(argv[2], argv[3], argv[4], NULL);
} }
else if ((!strcmp(argv[1], "-d")) && (argc > 4)) else if ((!strcmp(argv[1], "-d")) && (argc > 4))
{ {
if (argc > 5) if (argc > 5)
do_eet_decode(argv[2], argv[3], argv[4], argv[5]); do_eet_decode(argv[2], argv[3], argv[4], argv[5]);
else else
do_eet_decode(argv[2], argv[3], argv[4], NULL); do_eet_decode(argv[2], argv[3], argv[4], NULL);
} }
else if ((!strcmp(argv[1], "-i")) && (argc > 5)) else if ((!strcmp(argv[1], "-i")) && (argc > 5))
{ {
if (argc > 6) if (argc > 6)
do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]); do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
else else
do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), NULL); do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
} }
else if ((!strcmp(argv[1], "-e")) && (argc > 5)) else if ((!strcmp(argv[1], "-e")) && (argc > 5))
{ {
if (argc > 6) if (argc > 6)
do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]); do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
else else
do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), NULL); do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
} }
else if ((!strcmp(argv[1], "-r")) && (argc > 3)) else if ((!strcmp(argv[1], "-r")) && (argc > 3))
{ do_eet_remove(argv[2], argv[3]);
do_eet_remove(argv[2], argv[3]);
}
else if ((!strcmp(argv[1], "-c")) && (argc > 2)) else if ((!strcmp(argv[1], "-c")) && (argc > 2))
{ do_eet_check(argv[2]);
do_eet_check(argv[2]);
}
else if ((!strcmp(argv[1], "-s")) && (argc > 4)) else if ((!strcmp(argv[1], "-s")) && (argc > 4))
{ do_eet_sign(argv[2], argv[3], argv[4]);
do_eet_sign(argv[2], argv[3], argv[4]);
}
else else
{ goto help;
goto help;
}
eina_log_domain_unregister(_eet_main_log_dom); eina_log_domain_unregister(_eet_main_log_dom);
eet_shutdown(); eet_shutdown();
return 0; return 0;

View File

@ -7,7 +7,8 @@
#include <unistd.h> #include <unistd.h>
// complex real-world structures based on elmdentica database // complex real-world structures based on elmdentica database
typedef struct { typedef struct
{
const char *screen_name; const char *screen_name;
const char *name; const char *name;
const char *message; const char *message;
@ -17,19 +18,22 @@ typedef struct {
unsigned int timeline; unsigned int timeline;
} My_Message; } My_Message;
typedef struct { typedef struct
{
const char *dm_to; const char *dm_to;
const char *message; const char *message;
} My_Post; } My_Post;
typedef struct { typedef struct
{
unsigned int id; unsigned int id;
const char *name; const char *name;
Eina_List *messages; Eina_List *messages;
Eina_List *posts; Eina_List *posts;
} My_Account; } My_Account;
typedef struct { typedef struct
{
unsigned int version; // it is recommended to use versioned configuration! unsigned int version; // it is recommended to use versioned configuration!
Eina_List *accounts; Eina_List *accounts;
} My_Cache; } My_Cache;
@ -74,47 +78,47 @@ _my_cache_descriptor_init(void)
// Describe the members to be saved: // Describe the members to be saved:
// Use a temporary macro so we don't type a lot, also avoid errors: // Use a temporary macro so we don't type a lot, also avoid errors:
#define ADD_BASIC(member, eet_type) \ #define ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_message_descriptor, My_Message, #member, member, eet_type) (_my_message_descriptor, My_Message, # member, member, eet_type)
ADD_BASIC(screen_name, EET_T_STRING); ADD_BASIC(screen_name, EET_T_STRING);
ADD_BASIC(name, EET_T_STRING); ADD_BASIC(name, EET_T_STRING);
ADD_BASIC(message, EET_T_STRING); ADD_BASIC(message, EET_T_STRING);
ADD_BASIC(id, EET_T_UINT); ADD_BASIC(id, EET_T_UINT);
ADD_BASIC(status_id, EET_T_UINT); ADD_BASIC(status_id, EET_T_UINT);
ADD_BASIC(date, EET_T_UINT); ADD_BASIC(date, EET_T_UINT);
ADD_BASIC(timeline, EET_T_UINT); ADD_BASIC(timeline, EET_T_UINT);
#undef ADD_BASIC #undef ADD_BASIC
#define ADD_BASIC(member, eet_type) \ #define ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_post_descriptor, My_Post, #member, member, eet_type) (_my_post_descriptor, My_Post, # member, member, eet_type)
ADD_BASIC(dm_to, EET_T_STRING); ADD_BASIC(dm_to, EET_T_STRING);
ADD_BASIC(message, EET_T_STRING); ADD_BASIC(message, EET_T_STRING);
#undef ADD_BASIC #undef ADD_BASIC
#define ADD_BASIC(member, eet_type) \ #define ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_account_descriptor, My_Account, #member, member, eet_type) (_my_account_descriptor, My_Account, # member, member, eet_type)
ADD_BASIC(name, EET_T_STRING); ADD_BASIC(name, EET_T_STRING);
ADD_BASIC(id, EET_T_UINT); ADD_BASIC(id, EET_T_UINT);
#undef ADD_BASIC #undef ADD_BASIC
EET_DATA_DESCRIPTOR_ADD_LIST EET_DATA_DESCRIPTOR_ADD_LIST
(_my_account_descriptor, My_Account, "messages", messages, (_my_account_descriptor, My_Account, "messages", messages,
_my_message_descriptor); _my_message_descriptor);
EET_DATA_DESCRIPTOR_ADD_LIST EET_DATA_DESCRIPTOR_ADD_LIST
(_my_account_descriptor, My_Account, "posts", posts, (_my_account_descriptor, My_Account, "posts", posts,
_my_post_descriptor); _my_post_descriptor);
#define ADD_BASIC(member, eet_type) \ #define ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_cache_descriptor, My_Cache, #member, member, eet_type) (_my_cache_descriptor, My_Cache, # member, member, eet_type)
ADD_BASIC(version, EET_T_UINT); ADD_BASIC(version, EET_T_UINT);
#undef ADD_BASIC #undef ADD_BASIC
EET_DATA_DESCRIPTOR_ADD_LIST EET_DATA_DESCRIPTOR_ADD_LIST
(_my_cache_descriptor, My_Cache, "accounts", accounts, (_my_cache_descriptor, My_Cache, "accounts", accounts,
_my_account_descriptor); _my_account_descriptor);
} }
@ -133,9 +137,11 @@ static void
_eet_string_free(const char *str) _eet_string_free(const char *str)
{ {
if (!str) if (!str)
return; return;
if ((_my_cache_dict) && (eet_dictionary_string_check(_my_cache_dict, str))) if ((_my_cache_dict) && (eet_dictionary_string_check(_my_cache_dict, str)))
return; return;
eina_stringshare_del(str); eina_stringshare_del(str);
} }
@ -145,9 +151,10 @@ _my_message_new(const char *message)
My_Message *msg = calloc(1, sizeof(My_Message)); My_Message *msg = calloc(1, sizeof(My_Message));
if (!msg) if (!msg)
{ {
fprintf(stderr, "ERROR: could not calloc My_Message\n"); fprintf(stderr, "ERROR: could not calloc My_Message\n");
return NULL; return NULL;
} }
msg->message = eina_stringshare_add(message); msg->message = eina_stringshare_add(message);
return msg; return msg;
} }
@ -167,9 +174,10 @@ _my_post_new(const char *message)
My_Post *post = calloc(1, sizeof(My_Post)); My_Post *post = calloc(1, sizeof(My_Post));
if (!post) if (!post)
{ {
fprintf(stderr, "ERROR: could not calloc My_Post\n"); fprintf(stderr, "ERROR: could not calloc My_Post\n");
return NULL; return NULL;
} }
post->message = eina_stringshare_add(message); post->message = eina_stringshare_add(message);
return post; return post;
} }
@ -188,9 +196,10 @@ _my_account_new(const char *name)
My_Account *acc = calloc(1, sizeof(My_Account)); My_Account *acc = calloc(1, sizeof(My_Account));
if (!acc) if (!acc)
{ {
fprintf(stderr, "ERROR: could not calloc My_Account\n"); fprintf(stderr, "ERROR: could not calloc My_Account\n");
return NULL; return NULL;
} }
acc->name = eina_stringshare_add(name); acc->name = eina_stringshare_add(name);
return acc; return acc;
} }
@ -204,10 +213,10 @@ _my_account_free(My_Account *acc)
_eet_string_free(acc->name); _eet_string_free(acc->name);
EINA_LIST_FREE(acc->messages, m) EINA_LIST_FREE(acc->messages, m)
_my_message_free(m); _my_message_free(m);
EINA_LIST_FREE(acc->posts, p) EINA_LIST_FREE(acc->posts, p)
_my_post_free(p); _my_post_free(p);
free(acc); free(acc);
} }
@ -218,8 +227,8 @@ _my_cache_new(void)
My_Cache *my_cache = calloc(1, sizeof(My_Cache)); My_Cache *my_cache = calloc(1, sizeof(My_Cache));
if (!my_cache) if (!my_cache)
{ {
fprintf(stderr, "ERROR: could not calloc My_Cache\n"); fprintf(stderr, "ERROR: could not calloc My_Cache\n");
return NULL; return NULL;
} }
my_cache->version = 1; my_cache->version = 1;
@ -231,7 +240,7 @@ _my_cache_free(My_Cache *my_cache)
{ {
My_Account *acc; My_Account *acc;
EINA_LIST_FREE(my_cache->accounts, acc) EINA_LIST_FREE(my_cache->accounts, acc)
_my_account_free(acc); _my_account_free(acc);
free(my_cache); free(my_cache);
} }
@ -241,8 +250,9 @@ _my_cache_account_find(My_Cache *my_cache, const char *name)
My_Account *acc; My_Account *acc;
Eina_List *l; Eina_List *l;
EINA_LIST_FOREACH(my_cache->accounts, l, acc) EINA_LIST_FOREACH(my_cache->accounts, l, acc)
if (strcmp(acc->name, name) == 0) if (strcmp(acc->name, name) == 0)
return acc; return acc;
return NULL; return NULL;
} }
@ -253,28 +263,29 @@ _my_cache_load(const char *filename)
Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
if (!ef) if (!ef)
{ {
fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
return NULL; return NULL;
} }
my_cache = eet_data_read(ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY); my_cache = eet_data_read(ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY);
if (!my_cache) if (!my_cache)
{ {
eet_close(ef); eet_close(ef);
return NULL; return NULL;
} }
if (my_cache->version < 1) if (my_cache->version < 1)
{ {
fprintf(stderr, fprintf(stderr,
"WARNING: version %#x was too old, upgrading it to %#x\n", "WARNING: version %#x was too old, upgrading it to %#x\n",
my_cache->version, 1); my_cache->version, 1);
my_cache->version = 1; my_cache->version = 1;
} }
if (_my_cache_file) if (_my_cache_file)
eet_close(_my_cache_file); eet_close(_my_cache_file);
_my_cache_file = ef; _my_cache_file = ef;
_my_cache_dict = eet_dictionary_get(ef); _my_cache_dict = eet_dictionary_get(ef);
@ -293,27 +304,27 @@ _my_cache_save(const My_Cache *my_cache, const char *filename)
len = eina_strlcpy(tmp, filename, sizeof(tmp)); len = eina_strlcpy(tmp, filename, sizeof(tmp));
if (len + 12 >= (int)sizeof(tmp)) if (len + 12 >= (int)sizeof(tmp))
{ {
fprintf(stderr, "ERROR: file name is too big: %s\n", filename); fprintf(stderr, "ERROR: file name is too big: %s\n", filename);
return EINA_FALSE; return EINA_FALSE;
} }
i = 0; i = 0;
do do
{ {
snprintf(tmp + len, 12, ".%u", i); snprintf(tmp + len, 12, ".%u", i);
i++; i++;
} }
while (stat(tmp, &st) == 0); while (stat(tmp, &st) == 0);
ef = eet_open(tmp, EET_FILE_MODE_WRITE); ef = eet_open(tmp, EET_FILE_MODE_WRITE);
if (!ef) if (!ef)
{ {
fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp); fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp);
return EINA_FALSE; return EINA_FALSE;
} }
ret = eet_data_write ret = eet_data_write
(ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY, my_cache, EINA_TRUE); (ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY, my_cache, EINA_TRUE);
// VERY IMPORTANT NOTE: // VERY IMPORTANT NOTE:
// after eet_close(), all strings mmaped from file will be GONE, invalid! // after eet_close(), all strings mmaped from file will be GONE, invalid!
@ -327,8 +338,8 @@ _my_cache_save(const My_Cache *my_cache, const char *filename)
if (ret) if (ret)
{ {
unlink(filename); unlink(filename);
rename(tmp, filename); rename(tmp, filename);
} }
return ret; return ret;
@ -343,15 +354,15 @@ int main(int argc, char *argv[])
if (argc < 3) if (argc < 3)
{ {
fprintf(stderr, fprintf(stderr,
"Usage:\n\t%s <input> <output> [action] [action-params]\n\n" "Usage:\n\t%s <input> <output> [action] [action-params]\n\n"
"Where actions and their parameters:\n" "Where actions and their parameters:\n"
"\tacc <name>\n" "\tacc <name>\n"
"\tpost <account-name> <message>\n" "\tpost <account-name> <message>\n"
"\tmessage <account-name> <message>\n" "\tmessage <account-name> <message>\n"
"\n", "\n",
argv[0]); argv[0]);
return -1; return -1;
} }
eina_init(); eina_init();
@ -361,127 +372,131 @@ int main(int argc, char *argv[])
my_cache = _my_cache_load(argv[1]); my_cache = _my_cache_load(argv[1]);
if (!my_cache) if (!my_cache)
{ {
printf("creating new cache.\n"); printf("creating new cache.\n");
my_cache = _my_cache_new(); my_cache = _my_cache_new();
if (!my_cache) if (!my_cache)
{ {
ret = -2; ret = -2;
goto end; goto end;
} }
} }
if (argc > 3) if (argc > 3)
{ {
if (strcmp(argv[3], "acc") == 0) if (strcmp(argv[3], "acc") == 0)
{ {
if (argc == 5) if (argc == 5)
{ {
My_Account *acc = _my_cache_account_find(my_cache, argv[4]); My_Account *acc = _my_cache_account_find(my_cache, argv[4]);
if (!acc) if (!acc)
{ {
acc = _my_account_new(argv[4]); acc = _my_account_new(argv[4]);
my_cache->accounts = eina_list_append my_cache->accounts = eina_list_append
(my_cache->accounts, acc); (my_cache->accounts, acc);
} }
else else
fprintf(stderr, "ERROR: account '%s' already exists.\n", fprintf(stderr, "ERROR: account '%s' already exists.\n",
argv[4]); argv[4]);
} }
else else
fprintf(stderr, "ERROR: wrong number of parameters (%d).\n", fprintf(stderr,
argc); "ERROR: wrong number of parameters (%d).\n",
} argc);
else if (strcmp(argv[3], "post") == 0) }
{ else if (strcmp(argv[3], "post") == 0)
if (argc == 6) {
{ if (argc == 6)
My_Account *acc = _my_cache_account_find(my_cache, argv[4]); {
if (acc) My_Account *acc = _my_cache_account_find(my_cache, argv[4]);
{ if (acc)
My_Post *post = _my_post_new(argv[5]); {
acc->posts = eina_list_append(acc->posts, post); My_Post *post = _my_post_new(argv[5]);
} acc->posts = eina_list_append(acc->posts, post);
else }
fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); else
} fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
else }
fprintf(stderr, "ERROR: wrong number of parameters (%d).\n", else
argc); fprintf(stderr,
} "ERROR: wrong number of parameters (%d).\n",
else if (strcmp(argv[3], "message") == 0) argc);
{ }
if (argc == 6) else if (strcmp(argv[3], "message") == 0)
{ {
My_Account *acc = _my_cache_account_find(my_cache, argv[4]); if (argc == 6)
if (acc) {
{ My_Account *acc = _my_cache_account_find(my_cache, argv[4]);
My_Message *msg = _my_message_new(argv[5]); if (acc)
acc->messages = eina_list_append(acc->messages, msg); {
} My_Message *msg = _my_message_new(argv[5]);
else acc->messages = eina_list_append(acc->messages, msg);
fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); }
} else
else fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
fprintf(stderr, "ERROR: wrong number of parameters (%d).\n", }
argc); else
} fprintf(stderr,
else "ERROR: wrong number of parameters (%d).\n",
fprintf(stderr, "ERROR: unknown action '%s'\n", argv[2]); argc);
}
else
fprintf(stderr, "ERROR: unknown action '%s'\n", argv[2]);
} }
printf("My_Cache:\n" printf("My_Cache:\n"
"\tversion.: %#x\n" "\tversion.: %#x\n"
"\taccounts: %u\n", "\taccounts: %u\n",
my_cache->version, my_cache->version,
eina_list_count(my_cache->accounts)); eina_list_count(my_cache->accounts));
EINA_LIST_FOREACH(my_cache->accounts, l_acc, acc) EINA_LIST_FOREACH(my_cache->accounts, l_acc, acc)
{ {
const My_Post *post; const My_Post *post;
printf("\t > %-#8x '%.20s' stats: m=%u, p=%u\n", printf("\t > %-#8x '%.20s' stats: m=%u, p=%u\n",
acc->id, acc->name ? acc->name : "", acc->id, acc->name ? acc->name : "",
eina_list_count(acc->messages), eina_list_count(acc->messages),
eina_list_count(acc->posts)); eina_list_count(acc->posts));
if (eina_list_count(acc->messages)) if (eina_list_count(acc->messages))
{ {
const Eina_List *l; const Eina_List *l;
const My_Message *msg; const My_Message *msg;
printf("\t |messages:\n"); printf("\t |messages:\n");
EINA_LIST_FOREACH(acc->messages, l, msg) EINA_LIST_FOREACH(acc->messages, l, msg)
{ {
printf("\t | %-8x '%s' [%s]: '%.20s'\n", printf("\t | %-8x '%s' [%s]: '%.20s'\n",
msg->id, msg->id,
msg->name ? msg->name : "", msg->name ? msg->name : "",
msg->screen_name ? msg->screen_name : "", msg->screen_name ? msg->screen_name : "",
msg->message ? msg->message : ""); msg->message ? msg->message : "");
} }
} }
if (eina_list_count(acc->posts)) if (eina_list_count(acc->posts))
{ {
const Eina_List *l; const Eina_List *l;
const My_Post *post; const My_Post *post;
printf("\t |posts:\n"); printf("\t |posts:\n");
EINA_LIST_FOREACH(acc->posts, l, post) EINA_LIST_FOREACH(acc->posts, l, post)
{ {
if (post->dm_to) if (post->dm_to)
printf("\t | @%s: '%.20s'\n", post->dm_to, post->message); printf("\t | @%s: '%.20s'\n", post->dm_to, post->message);
else else
printf("\t | '%.20s'\n", post->message); printf("\t | '%.20s'\n", post->message);
} }
} }
printf("\n");
} printf("\n");
}
if (!_my_cache_save(my_cache, argv[2])) if (!_my_cache_save(my_cache, argv[2]))
ret = -3; ret = -3;
_my_cache_free(my_cache); _my_cache_free(my_cache);
end: end:
_my_cache_descriptor_shutdown(); _my_cache_descriptor_shutdown();
eet_shutdown(); eet_shutdown();
eina_shutdown(); eina_shutdown();

View File

@ -11,7 +11,8 @@
// will be automatically handled. The other members will have their // will be automatically handled. The other members will have their
// space reserved and zeroed (as it uses calloc()), but not // space reserved and zeroed (as it uses calloc()), but not
// saved or loaded from eet files. // saved or loaded from eet files.
typedef struct { typedef struct
{
unsigned int version; // it is recommended to use versioned configuration! unsigned int version; // it is recommended to use versioned configuration!
const char *name; const char *name;
int id; int id;
@ -20,7 +21,8 @@ typedef struct {
Eina_List *subs; Eina_List *subs;
} My_Conf_Type; } My_Conf_Type;
typedef struct { typedef struct
{
const char *server; const char *server;
int port; int port;
} My_Conf_Subtype; } My_Conf_Subtype;
@ -62,24 +64,24 @@ _my_conf_descriptor_init(void)
// Describe the members to be saved: // Describe the members to be saved:
// Use a temporary macro so we don't type a lot, also avoid errors: // Use a temporary macro so we don't type a lot, also avoid errors:
#define MY_CONF_ADD_BASIC(member, eet_type) \ #define MY_CONF_ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_conf_descriptor, My_Conf_Type, #member, member, eet_type) (_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
#define MY_CONF_SUB_ADD_BASIC(member, eet_type) \ #define MY_CONF_SUB_ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_conf_sub_descriptor, My_Conf_Subtype, #member, member, eet_type) (_my_conf_sub_descriptor, My_Conf_Subtype, # member, member, eet_type)
MY_CONF_SUB_ADD_BASIC(server, EET_T_STRING); MY_CONF_SUB_ADD_BASIC(server, EET_T_STRING);
MY_CONF_SUB_ADD_BASIC(port, EET_T_INT); MY_CONF_SUB_ADD_BASIC(port, EET_T_INT);
MY_CONF_ADD_BASIC(version, EET_T_UINT); MY_CONF_ADD_BASIC(version, EET_T_UINT);
MY_CONF_ADD_BASIC(name, EET_T_STRING); MY_CONF_ADD_BASIC(name, EET_T_STRING);
MY_CONF_ADD_BASIC(id, EET_T_INT); MY_CONF_ADD_BASIC(id, EET_T_INT);
MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR); MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR);
// And add the sub descriptor as a linked list at 'subs' in the main struct // And add the sub descriptor as a linked list at 'subs' in the main struct
EET_DATA_DESCRIPTOR_ADD_LIST EET_DATA_DESCRIPTOR_ADD_LIST
(_my_conf_descriptor, My_Conf_Type, "subs", subs, _my_conf_sub_descriptor); (_my_conf_descriptor, My_Conf_Type, "subs", subs, _my_conf_sub_descriptor);
#undef MY_CONF_ADD_BASIC #undef MY_CONF_ADD_BASIC
#undef MY_CONF_SUB_ADD_BASIC #undef MY_CONF_SUB_ADD_BASIC
@ -99,8 +101,8 @@ _my_conf_new(void)
My_Conf_Subtype *sub; My_Conf_Subtype *sub;
if (!my_conf) if (!my_conf)
{ {
fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n"); fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n");
return NULL; return NULL;
} }
my_conf->version = 0x112233; my_conf->version = 0x112233;
@ -109,9 +111,9 @@ _my_conf_new(void)
sub = calloc(1, sizeof(My_Conf_Subtype)); sub = calloc(1, sizeof(My_Conf_Subtype));
if (sub) if (sub)
{ {
sub->server = eina_stringshare_add("my-server.com"); sub->server = eina_stringshare_add("my-server.com");
sub->port = 1234; sub->port = 1234;
my_conf->subs = eina_list_append(my_conf->subs, sub); my_conf->subs = eina_list_append(my_conf->subs, sub);
} }
return my_conf; return my_conf;
@ -122,10 +124,10 @@ _my_conf_free(My_Conf_Type *my_conf)
{ {
My_Conf_Subtype *sub; My_Conf_Subtype *sub;
EINA_LIST_FREE(my_conf->subs, sub) EINA_LIST_FREE(my_conf->subs, sub)
{ {
eina_stringshare_del(sub->server); eina_stringshare_del(sub->server);
free(sub); free(sub);
} }
eina_stringshare_del(my_conf->name); eina_stringshare_del(my_conf->name);
free(my_conf); free(my_conf);
@ -138,25 +140,25 @@ _my_conf_load(const char *filename)
Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
if (!ef) if (!ef)
{ {
fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
return NULL; return NULL;
} }
my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY); my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY);
if (!my_conf) if (!my_conf)
goto end; goto end;
if (my_conf->version < 0x112233) if (my_conf->version < 0x112233)
{ {
fprintf(stderr, fprintf(stderr,
"WARNING: version %#x was too old, upgrading it to %#x\n", "WARNING: version %#x was too old, upgrading it to %#x\n",
my_conf->version, 0x112233); my_conf->version, 0x112233);
my_conf->version = 0x112233; my_conf->version = 0x112233;
my_conf->enabled = EINA_TRUE; my_conf->enabled = EINA_TRUE;
} }
end: end:
eet_close(ef); eet_close(ef);
return my_conf; return my_conf;
} }
@ -173,33 +175,33 @@ _my_conf_save(const My_Conf_Type *my_conf, const char *filename)
len = eina_strlcpy(tmp, filename, sizeof(tmp)); len = eina_strlcpy(tmp, filename, sizeof(tmp));
if (len + 12 >= (int)sizeof(tmp)) if (len + 12 >= (int)sizeof(tmp))
{ {
fprintf(stderr, "ERROR: file name is too big: %s\n", filename); fprintf(stderr, "ERROR: file name is too big: %s\n", filename);
return EINA_FALSE; return EINA_FALSE;
} }
i = 0; i = 0;
do do
{ {
snprintf(tmp + len, 12, ".%u", i); snprintf(tmp + len, 12, ".%u", i);
i++; i++;
} }
while (stat(tmp, &st) == 0); while (stat(tmp, &st) == 0);
ef = eet_open(tmp, EET_FILE_MODE_WRITE); ef = eet_open(tmp, EET_FILE_MODE_WRITE);
if (!ef) if (!ef)
{ {
fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp); fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp);
return EINA_FALSE; return EINA_FALSE;
} }
ret = eet_data_write ret = eet_data_write
(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE); (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE);
eet_close(ef); eet_close(ef);
if (ret) if (ret)
{ {
unlink(filename); unlink(filename);
rename(tmp, filename); rename(tmp, filename);
} }
return ret; return ret;
@ -214,8 +216,8 @@ int main(int argc, char *argv[])
if (argc != 3) if (argc != 3)
{ {
fprintf(stderr, "Usage:\n\t%s <input> <output>\n\n", argv[0]); fprintf(stderr, "Usage:\n\t%s <input> <output>\n\n", argv[0]);
return -1; return -1;
} }
eina_init(); eina_init();
@ -225,37 +227,37 @@ int main(int argc, char *argv[])
my_conf = _my_conf_load(argv[1]); my_conf = _my_conf_load(argv[1]);
if (!my_conf) if (!my_conf)
{ {
printf("creating new configuration.\n"); printf("creating new configuration.\n");
my_conf = _my_conf_new(); my_conf = _my_conf_new();
if (!my_conf) if (!my_conf)
{ {
ret = -2; ret = -2;
goto end; goto end;
} }
} }
printf("My_Conf_Type:\n" printf("My_Conf_Type:\n"
"\tversion: %#x\n" "\tversion: %#x\n"
"\tname...: '%s'\n" "\tname...: '%s'\n"
"\tid.....: %d\n" "\tid.....: %d\n"
"\tenabled: %hhu\n" "\tenabled: %hhu\n"
"\tsubs...:\n", "\tsubs...:\n",
my_conf->version, my_conf->version,
my_conf->name ? my_conf->name : "", my_conf->name ? my_conf->name : "",
my_conf->id, my_conf->id,
my_conf->enabled); my_conf->enabled);
EINA_LIST_FOREACH(my_conf->subs, l, sub) EINA_LIST_FOREACH(my_conf->subs, l, sub)
printf("\t\tserver: '%s', port: %d\n", printf("\t\tserver: '%s', port: %d\n",
sub->server ? sub->server : "", sub->server ? sub->server : "",
sub->port); sub->port);
if (!_my_conf_save(my_conf, argv[2])) if (!_my_conf_save(my_conf, argv[2]))
ret = -3; ret = -3;
_my_conf_free(my_conf); _my_conf_free(my_conf);
end: end:
_my_conf_descriptor_shutdown(); _my_conf_descriptor_shutdown();
eet_shutdown(); eet_shutdown();
eina_shutdown(); eina_shutdown();

View File

@ -11,7 +11,8 @@
// will be automatically handled. The other members will have their // will be automatically handled. The other members will have their
// space reserved and zeroed (as it uses calloc()), but not // space reserved and zeroed (as it uses calloc()), but not
// saved or loaded from eet files. // saved or loaded from eet files.
typedef struct { typedef struct
{
unsigned int version; // it is recommended to use versioned configuration! unsigned int version; // it is recommended to use versioned configuration!
const char *name; const char *name;
int id; int id;
@ -52,13 +53,13 @@ _my_conf_descriptor_init(void)
// Describe the members to be saved: // Describe the members to be saved:
// Use a temporary macro so we don't type a lot, also avoid errors: // Use a temporary macro so we don't type a lot, also avoid errors:
#define MY_CONF_ADD_BASIC(member, eet_type) \ #define MY_CONF_ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \ EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_conf_descriptor, My_Conf_Type, #member, member, eet_type) (_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
MY_CONF_ADD_BASIC(version, EET_T_UINT); MY_CONF_ADD_BASIC(version, EET_T_UINT);
MY_CONF_ADD_BASIC(name, EET_T_STRING); MY_CONF_ADD_BASIC(name, EET_T_STRING);
MY_CONF_ADD_BASIC(id, EET_T_INT); MY_CONF_ADD_BASIC(id, EET_T_INT);
MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR); MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR);
#undef MY_CONF_ADD_BASIC #undef MY_CONF_ADD_BASIC
@ -76,8 +77,8 @@ _my_conf_new(void)
My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type)); My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type));
if (!my_conf) if (!my_conf)
{ {
fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n"); fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n");
return NULL; return NULL;
} }
my_conf->version = 0x112233; my_conf->version = 0x112233;
@ -99,25 +100,25 @@ _my_conf_load(const char *filename)
Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
if (!ef) if (!ef)
{ {
fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
return NULL; return NULL;
} }
my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY); my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY);
if (!my_conf) if (!my_conf)
goto end; goto end;
if (my_conf->version < 0x112233) if (my_conf->version < 0x112233)
{ {
fprintf(stderr, fprintf(stderr,
"WARNING: version %#x was too old, upgrading it to %#x\n", "WARNING: version %#x was too old, upgrading it to %#x\n",
my_conf->version, 0x112233); my_conf->version, 0x112233);
my_conf->version = 0x112233; my_conf->version = 0x112233;
my_conf->enabled = EINA_TRUE; my_conf->enabled = EINA_TRUE;
} }
end: end:
eet_close(ef); eet_close(ef);
return my_conf; return my_conf;
} }
@ -134,33 +135,33 @@ _my_conf_save(const My_Conf_Type *my_conf, const char *filename)
len = eina_strlcpy(tmp, filename, sizeof(tmp)); len = eina_strlcpy(tmp, filename, sizeof(tmp));
if (len + 12 >= (int)sizeof(tmp)) if (len + 12 >= (int)sizeof(tmp))
{ {
fprintf(stderr, "ERROR: file name is too big: %s\n", filename); fprintf(stderr, "ERROR: file name is too big: %s\n", filename);
return EINA_FALSE; return EINA_FALSE;
} }
i = 0; i = 0;
do do
{ {
snprintf(tmp + len, 12, ".%u", i); snprintf(tmp + len, 12, ".%u", i);
i++; i++;
} }
while (stat(tmp, &st) == 0); while (stat(tmp, &st) == 0);
ef = eet_open(tmp, EET_FILE_MODE_WRITE); ef = eet_open(tmp, EET_FILE_MODE_WRITE);
if (!ef) if (!ef)
{ {
fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp); fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp);
return EINA_FALSE; return EINA_FALSE;
} }
ret = eet_data_write ret = eet_data_write
(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE); (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE);
eet_close(ef); eet_close(ef);
if (ret) if (ret)
{ {
unlink(filename); unlink(filename);
rename(tmp, filename); rename(tmp, filename);
} }
return ret; return ret;
@ -173,8 +174,8 @@ int main(int argc, char *argv[])
if (argc != 3) if (argc != 3)
{ {
fprintf(stderr, "Usage:\n\t%s <input> <output>\n\n", argv[0]); fprintf(stderr, "Usage:\n\t%s <input> <output>\n\n", argv[0]);
return -1; return -1;
} }
eina_init(); eina_init();
@ -184,31 +185,31 @@ int main(int argc, char *argv[])
my_conf = _my_conf_load(argv[1]); my_conf = _my_conf_load(argv[1]);
if (!my_conf) if (!my_conf)
{ {
printf("creating new configuration.\n"); printf("creating new configuration.\n");
my_conf = _my_conf_new(); my_conf = _my_conf_new();
if (!my_conf) if (!my_conf)
{ {
ret = -2; ret = -2;
goto end; goto end;
} }
} }
printf("My_Conf_Type:\n" printf("My_Conf_Type:\n"
"\tversion: %#x\n" "\tversion: %#x\n"
"\tname...: '%s'\n" "\tname...: '%s'\n"
"\tid.....: %d\n" "\tid.....: %d\n"
"\tenabled: %hhu\n", "\tenabled: %hhu\n",
my_conf->version, my_conf->version,
my_conf->name ? my_conf->name : "", my_conf->name ? my_conf->name : "",
my_conf->id, my_conf->id,
my_conf->enabled); my_conf->enabled);
if (!_my_conf_save(my_conf, argv[2])) if (!_my_conf_save(my_conf, argv[2]))
ret = -3; ret = -3;
_my_conf_free(my_conf); _my_conf_free(my_conf);
end: end:
_my_conf_descriptor_shutdown(); _my_conf_descriptor_shutdown();
eet_shutdown(); eet_shutdown();
eina_shutdown(); eina_shutdown();

File diff suppressed because it is too large Load Diff

View File

@ -11,56 +11,56 @@ typedef enum _Eet_Convert_Type Eet_Convert_Type;
enum _Eet_Convert_Type enum _Eet_Convert_Type
{ {
EET_D_NOT_CONVERTED = 0, EET_D_NOT_CONVERTED = 0,
EET_D_FLOAT = 1 << 1, EET_D_FLOAT = 1 << 1,
EET_D_DOUBLE = 1 << 2, EET_D_DOUBLE = 1 << 2,
EET_D_FIXED_POINT = 1 << 4 EET_D_FIXED_POINT = 1 << 4
}; };
typedef struct _Eet_String Eet_String; typedef struct _Eet_String Eet_String;
struct _Eet_String struct _Eet_String
{ {
const char *mmap; const char *mmap;
char *str; char *str;
int hash; int hash;
int len; int len;
int next; int next;
int prev; int prev;
float f; float f;
double d; double d;
Eina_F32p32 fp; Eina_F32p32 fp;
Eet_Convert_Type type; Eet_Convert_Type type;
}; };
struct _Eet_Dictionary struct _Eet_Dictionary
{ {
Eet_String *all; Eet_String *all;
int size; int size;
int offset; int offset;
int hash[256]; int hash[256];
int count; int count;
int total; int total;
const char *start; const char *start;
const char *end; const char *end;
}; };
struct _Eet_Node struct _Eet_Node
{ {
int type; int type;
int count; int count;
const char *name; const char *name;
const char *key; const char *key;
Eet_Node *values; Eet_Node *values;
Eet_Node *next; Eet_Node *next;
Eet_Node *parent; Eet_Node *parent;
Eet_Node_Data data; Eet_Node_Data data;
}; };
@ -99,44 +99,69 @@ extern int _eet_log_dom_global;
#endif #endif
#define CRIT(...) EINA_LOG_DOM_CRIT(_eet_log_dom_global, __VA_ARGS__) #define CRIT(...) EINA_LOG_DOM_CRIT(_eet_log_dom_global, __VA_ARGS__)
Eet_Dictionary *eet_dictionary_add(void); Eet_Dictionary *eet_dictionary_add(void);
void eet_dictionary_free(Eet_Dictionary *ed); void eet_dictionary_free(Eet_Dictionary *ed);
int eet_dictionary_string_add(Eet_Dictionary *ed, const char *string); int eet_dictionary_string_add(Eet_Dictionary *ed,
int eet_dictionary_string_get_size(const Eet_Dictionary *ed, int index); const char *string);
const char *eet_dictionary_string_get_char(const Eet_Dictionary *ed, int index); int eet_dictionary_string_get_size(const Eet_Dictionary *ed,
Eina_Bool eet_dictionary_string_get_float(const Eet_Dictionary *ed, int index, float *result); int index);
Eina_Bool eet_dictionary_string_get_double(const Eet_Dictionary *ed, int index, double *result); const char * eet_dictionary_string_get_char(const Eet_Dictionary *ed,
Eina_Bool eet_dictionary_string_get_fp(const Eet_Dictionary *ed, int index, Eina_F32p32 *result); int index);
int eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int index); Eina_Bool eet_dictionary_string_get_float(const Eet_Dictionary *ed,
int index,
float *result);
Eina_Bool eet_dictionary_string_get_double(const Eet_Dictionary *ed,
int index,
double *result);
Eina_Bool eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
int index,
Eina_F32p32 *result);
int eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
int index);
int _eet_hash_gen(const char *key, int hash_size); int _eet_hash_gen(const char *key, int hash_size);
const void* eet_identity_check(const void *data_base, unsigned int data_length, const void * eet_identity_check(const void *data_base,
void **sha1, int *sha1_length, unsigned int data_length,
const void *signature_base, unsigned int signature_length, void **sha1,
const void **raw_signature_base, unsigned int *raw_signature_length, int *sha1_length,
int *x509_length); const void *signature_base,
void *eet_identity_compute_sha1(const void *data_base, unsigned int data_length, unsigned int signature_length,
int *sha1_length); const void **raw_signature_base,
Eet_Error eet_cipher(const void *data, unsigned int size, const char *key, unsigned int length, void **result, unsigned int *result_length); unsigned int *raw_signature_length,
Eet_Error eet_decipher(const void *data, unsigned int size, const char *key, unsigned int length, void **result, unsigned int *result_length); int *x509_length);
void * eet_identity_compute_sha1(const void *data_base,
unsigned int data_length,
int *sha1_length);
Eet_Error eet_cipher(const void *data,
unsigned int size,
const char *key,
unsigned int length,
void **result,
unsigned int *result_length);
Eet_Error eet_decipher(const void *data,
unsigned int size,
const char *key,
unsigned int length,
void **result,
unsigned int *result_length);
Eet_Error eet_identity_sign(FILE *fp, Eet_Key *key); Eet_Error eet_identity_sign(FILE *fp, Eet_Key *key);
void eet_identity_unref(Eet_Key *key); void eet_identity_unref(Eet_Key *key);
void eet_identity_ref(Eet_Key *key); void eet_identity_ref(Eet_Key *key);
void eet_node_shutdown(void); void eet_node_shutdown(void);
int eet_node_init(void); int eet_node_init(void);
Eet_Node *eet_node_new(void); Eet_Node *eet_node_new(void);
void eet_node_free(Eet_Node *node); void eet_node_free(Eet_Node *node);
#ifndef PATH_MAX #ifndef PATH_MAX
# define PATH_MAX 4096 # define PATH_MAX 4096
#endif #endif
#ifdef DNDEBUG #ifdef DNDEBUG
# define EET_ASSERT(Test, Do) if (Test == 0) Do; # define EET_ASSERT(Test, Do) if (Test == 0) {Do; }
#else #else
# define EET_ASSERT(Test, Do) if (Test == 0) abort(); # define EET_ASSERT(Test, Do) if (Test == 0) {abort(); }
#endif #endif
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,8 @@ void *alloca (size_t);
#define MAGIC_EET_DATA_PACKET 0x4270ACE1 #define MAGIC_EET_DATA_PACKET 0x4270ACE1
typedef struct _Eet_Message Eet_Message; typedef struct _Eet_Message Eet_Message;
struct _Eet_Message { struct _Eet_Message
{
int magic; int magic;
int size; int size;
}; };
@ -62,21 +63,21 @@ struct _Eet_Connection
EAPI Eet_Connection * EAPI Eet_Connection *
eet_connection_new(Eet_Read_Cb *eet_read_cb, eet_connection_new(Eet_Read_Cb *eet_read_cb,
Eet_Write_Cb *eet_write_cb, Eet_Write_Cb *eet_write_cb,
const void *user_data) const void *user_data)
{ {
Eet_Connection *conn; Eet_Connection *conn;
if (!eet_read_cb || !eet_write_cb) if (!eet_read_cb || !eet_write_cb)
return NULL; return NULL;
conn = calloc(1, sizeof (Eet_Connection)); conn = calloc(1, sizeof (Eet_Connection));
if (!conn) if (!conn)
return NULL; return NULL;
conn->eet_read_cb = eet_read_cb; conn->eet_read_cb = eet_read_cb;
conn->eet_write_cb = eet_write_cb; conn->eet_write_cb = eet_write_cb;
conn->user_data = (void*) user_data; conn->user_data = (void *)user_data;
return conn; return conn;
} }
@ -85,83 +86,85 @@ EAPI int
eet_connection_received(Eet_Connection *conn, const void *data, size_t size) eet_connection_received(Eet_Connection *conn, const void *data, size_t size)
{ {
if (!conn || !data || !size) if (!conn || !data || !size)
return size; return size;
do { do {
size_t copy_size; size_t copy_size;
if (conn->size == 0) if (conn->size == 0)
{ {
const Eet_Message *msg; const Eet_Message *msg;
size_t packet_size; size_t packet_size;
if (size < sizeof (Eet_Message)) if (size < sizeof (Eet_Message))
break; break;
msg = data; msg = data;
/* Check the magic */ /* Check the magic */
if (ntohl(msg->magic) != MAGIC_EET_DATA_PACKET) if (ntohl(msg->magic) != MAGIC_EET_DATA_PACKET)
break; break;
packet_size = ntohl(msg->size); packet_size = ntohl(msg->size);
/* Message should always be under 64K */ /* Message should always be under 64K */
if (packet_size > 64 * 1024) if (packet_size > 64 * 1024)
break; break;
data = (void*) (msg + 1); data = (void *)(msg + 1);
size -= sizeof (msg); size -= sizeof (msg);
if ((size_t) packet_size <= size) if ((size_t)packet_size <= size)
{ {
/* Not a partial receive, go the quick way. */ /* Not a partial receive, go the quick way. */
if (!conn->eet_read_cb(data, packet_size, conn->user_data)) if (!conn->eet_read_cb(data, packet_size, conn->user_data))
break; break;
data = (void*) ((char *) data + packet_size); data = (void *)((char *)data + packet_size);
size -= packet_size; size -= packet_size;
conn->received = 0; conn->received = 0;
continue; continue;
} }
conn->size = packet_size; conn->size = packet_size;
if (conn->allocated < conn->size) if (conn->allocated < conn->size)
{ {
void *tmp; void *tmp;
tmp = realloc(conn->buffer, conn->size); tmp = realloc(conn->buffer, conn->size);
if (!tmp) if (!tmp)
break; break;
conn->buffer = tmp; conn->buffer = tmp;
conn->allocated = conn->size; conn->allocated = conn->size;
} }
} }
/* Partial receive */ /* Partial receive */
copy_size = (conn->size - conn->received >= size) ? size : conn->size - conn->received; copy_size =
memcpy((char*) conn->buffer + conn->received, data, copy_size); (conn->size - conn->received >=
size) ? size : conn->size - conn->received;
memcpy((char *)conn->buffer + conn->received, data, copy_size);
conn->received += copy_size; conn->received += copy_size;
data = (void*)((char *) data + copy_size); data = (void *)((char *)data + copy_size);
size -= copy_size; size -= copy_size;
if (conn->received == conn->size) if (conn->received == conn->size)
{ {
size_t data_size; size_t data_size;
data_size = conn->size; data_size = conn->size;
conn->size = 0; conn->size = 0;
conn->received = 0; conn->received = 0;
/* Completed a packet. */ /* Completed a packet. */
if (!conn->eet_read_cb(conn->buffer, data_size, conn->user_data)) if (!conn->eet_read_cb(conn->buffer, data_size, conn->user_data))
{ {
/* Something goes wrong. Stop now. */ /* Something goes wrong. Stop now. */
size += data_size; size += data_size;
break; break;
} }
} }
} while (size > 0); } while (size > 0);
return size; return size;
} }
@ -173,38 +176,48 @@ _eet_connection_raw_send(Eet_Connection *conn, void *data, int data_size)
/* Message should never be above 64K */ /* Message should never be above 64K */
if (data_size > 64 * 1024) if (data_size > 64 * 1024)
return EINA_FALSE; return EINA_FALSE;
message = alloca(data_size + sizeof (Eet_Message)); message = alloca(data_size + sizeof (Eet_Message));
message->magic = htonl(MAGIC_EET_DATA_PACKET); message->magic = htonl(MAGIC_EET_DATA_PACKET);
message->size = htonl(data_size); message->size = htonl(data_size);
memcpy(message + 1, data, data_size); memcpy(message + 1, data, data_size);
conn->eet_write_cb(message, data_size + sizeof (Eet_Message), conn->user_data); conn->eet_write_cb(message,
data_size + sizeof (Eet_Message),
conn->user_data);
return EINA_TRUE; return EINA_TRUE;
} }
EAPI Eina_Bool EAPI Eina_Bool
eet_connection_send(Eet_Connection *conn, Eet_Data_Descriptor *edd, const void *data_in, const char *cipher_key) eet_connection_send(Eet_Connection *conn,
Eet_Data_Descriptor *edd,
const void *data_in,
const char *cipher_key)
{ {
void *flat_data; void *flat_data;
int data_size; int data_size;
Eina_Bool ret = EINA_FALSE; Eina_Bool ret = EINA_FALSE;
flat_data = eet_data_descriptor_encode_cipher(edd, data_in, cipher_key, &data_size); flat_data = eet_data_descriptor_encode_cipher(edd,
data_in,
cipher_key,
&data_size);
if (!flat_data) if (!flat_data)
return EINA_FALSE; return EINA_FALSE;
if (_eet_connection_raw_send(conn, flat_data, data_size)) if (_eet_connection_raw_send(conn, flat_data, data_size))
ret = EINA_TRUE; ret = EINA_TRUE;
free(flat_data); free(flat_data);
return ret; return ret;
} }
EAPI Eina_Bool EAPI Eina_Bool
eet_connection_node_send(Eet_Connection *conn, Eet_Node *node, const char *cipher_key) eet_connection_node_send(Eet_Connection *conn,
Eet_Node *node,
const char *cipher_key)
{ {
void *data; void *data;
int data_size; int data_size;
@ -212,10 +225,10 @@ eet_connection_node_send(Eet_Connection *conn, Eet_Node *node, const char *ciphe
data = eet_data_node_encode_cipher(node, cipher_key, &data_size); data = eet_data_node_encode_cipher(node, cipher_key, &data_size);
if (!data) if (!data)
return EINA_FALSE; return EINA_FALSE;
if (_eet_connection_raw_send(conn, data, data_size)) if (_eet_connection_raw_send(conn, data, data_size))
ret = EINA_TRUE; ret = EINA_TRUE;
free(data); free(data);
return ret; return ret;
@ -227,10 +240,10 @@ eet_connection_close(Eet_Connection *conn, Eina_Bool *on_going)
void *user_data; void *user_data;
if (!conn) if (!conn)
return NULL; return NULL;
if (on_going) if (on_going)
*on_going = conn->received == 0 ? EINA_FALSE : EINA_TRUE; *on_going = conn->received == 0 ? EINA_FALSE : EINA_TRUE;
user_data = conn->user_data; user_data = conn->user_data;

File diff suppressed because it is too large Load Diff

View File

@ -18,11 +18,11 @@
Eet_Dictionary * Eet_Dictionary *
eet_dictionary_add(void) eet_dictionary_add(void)
{ {
Eet_Dictionary *new; Eet_Dictionary *new;
new = calloc(1, sizeof (Eet_Dictionary)); new = calloc(1, sizeof (Eet_Dictionary));
if (!new) if (!new)
return NULL; return NULL;
memset(new->hash, -1, sizeof (int) * 256); memset(new->hash, -1, sizeof (int) * 256);
@ -34,43 +34,43 @@ eet_dictionary_free(Eet_Dictionary *ed)
{ {
if (ed) if (ed)
{ {
int i; int i;
for (i = 0; i < ed->count; ++i) for (i = 0; i < ed->count; ++i)
if (ed->all[i].str) if (ed->all[i].str)
free(ed->all[i].str); free(ed->all[i].str);
if (ed->all) free(ed->all);
free(ed); if (ed->all)
free(ed->all);
free(ed);
} }
} }
static int static int
_eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int hash) _eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int hash)
{ {
int prev = -1; int prev = -1;
int current; int current;
current = ed->hash[hash]; current = ed->hash[hash];
while (current != -1) while (current != -1)
{ {
if (ed->all[current].str) if (ed->all[current].str)
{ if (strcmp(ed->all[current].str, string) >= 0)
if (strcmp(ed->all[current].str, string) >= 0) break;
break ;
}
if (ed->all[current].mmap) if (ed->all[current].mmap)
{ if (strcmp(ed->all[current].mmap, string) >= 0)
if (strcmp(ed->all[current].mmap, string) >= 0) break;
break ;
}
prev = current; prev = current;
current = ed->all[current].next; current = ed->all[current].next;
} }
if (current == -1) if (current == -1)
return prev; return prev;
return current; return current;
} }
@ -78,14 +78,14 @@ _eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int hash)
int int
eet_dictionary_string_add(Eet_Dictionary *ed, const char *string) eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
{ {
Eet_String *current; Eet_String *current;
char *str; char *str;
int hash; int hash;
int idx; int idx;
int len; int len;
if (!ed) if (!ed)
return -1; return -1;
hash = _eet_hash_gen(string, 8); hash = _eet_hash_gen(string, 8);
@ -94,27 +94,25 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
if (idx != -1) if (idx != -1)
{ {
if (ed->all[idx].str) if (ed->all[idx].str)
{ if (strcmp(ed->all[idx].str, string) == 0)
if (strcmp(ed->all[idx].str, string) == 0) return idx;
return idx;
}
if (ed->all[idx].mmap) if (ed->all[idx].mmap)
{ if (strcmp(ed->all[idx].mmap, string) == 0)
if (strcmp(ed->all[idx].mmap, string) == 0) return idx;
return idx;
}
} }
if (ed->total == ed->count) if (ed->total == ed->count)
{ {
Eet_String *new; Eet_String *new;
int total; int total;
total = ed->total + 8; total = ed->total + 8;
new = realloc(ed->all, sizeof (Eet_String) * total); new = realloc(ed->all, sizeof (Eet_String) * total);
if (new == NULL) if (new == NULL)
return -1; return -1;
ed->all = new; ed->all = new;
ed->total = total; ed->total = total;
@ -123,7 +121,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
len = strlen(string) + 1; len = strlen(string) + 1;
str = strdup(string); str = strdup(string);
if (str == NULL) if (str == NULL)
return -1; return -1;
current = ed->all + ed->count; current = ed->all + ed->count;
@ -147,11 +145,12 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
current->prev = ed->all[idx].prev; current->prev = ed->all[idx].prev;
if (current->next != -1) if (current->next != -1)
ed->all[current->next].prev = ed->count; ed->all[current->next].prev = ed->count;
if (current->prev != -1) if (current->prev != -1)
ed->all[current->prev].next = ed->count; ed->all[current->prev].next = ed->count;
else else
ed->hash[hash] = ed->count; ed->hash[hash] = ed->count;
} }
return ed->count++; return ed->count++;
@ -160,48 +159,68 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
int int
eet_dictionary_string_get_size(const Eet_Dictionary *ed, int idx) eet_dictionary_string_get_size(const Eet_Dictionary *ed, int idx)
{ {
if (!ed) return 0; if (!ed)
if (idx < 0) return 0; return 0;
if (idx < 0)
return 0;
if (idx < ed->count) if (idx < ed->count)
return ed->all[idx].len; return ed->all[idx].len;
return 0; return 0;
} }
int int
eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int idx) eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int idx)
{ {
if (!ed) return -1; if (!ed)
if (idx < 0) return -1; return -1;
if (idx < 0)
return -1;
if (idx < ed->count) if (idx < ed->count)
return ed->all[idx].hash; return ed->all[idx].hash;
return -1; return -1;
} }
const char * const char *
eet_dictionary_string_get_char(const Eet_Dictionary *ed, int idx) eet_dictionary_string_get_char(const Eet_Dictionary *ed, int idx)
{ {
if (!ed) return NULL; if (!ed)
if (idx < 0) return NULL; return NULL;
if (idx < 0)
return NULL;
if (idx < ed->count) if (idx < ed->count)
{ {
#ifdef _WIN32 #ifdef _WIN32
/* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */ /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
if (ed->all[idx].str == NULL) if (ed->all[idx].str == NULL)
{ {
ed->all[idx].str = strdup(ed->all[idx].mmap); ed->all[idx].str = strdup(ed->all[idx].mmap);
ed->all[idx].mmap = NULL; ed->all[idx].mmap = NULL;
} }
#else #else
if (ed->all[idx].mmap) if (ed->all[idx].mmap)
return ed->all[idx].mmap; return ed->all[idx].mmap;
#endif #endif
return ed->all[idx].str; return ed->all[idx].str;
} }
return NULL; return NULL;
} }
static inline Eina_Bool static inline Eina_Bool
_eet_dictionary_string_get_me_cache(const char *s, int len, int *mantisse, int *exponent) _eet_dictionary_string_get_me_cache(const char *s,
int len,
int *mantisse,
int *exponent)
{ {
if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p')) if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
{ {
@ -210,74 +229,94 @@ _eet_dictionary_string_get_me_cache(const char *s, int len, int *mantisse, int *
return EINA_TRUE; return EINA_TRUE;
} }
return EINA_FALSE; return EINA_FALSE;
} }
static inline Eina_Bool static inline Eina_Bool
_eet_dictionary_string_get_float_cache(const char *s, int len, float *result) _eet_dictionary_string_get_float_cache(const char *s, int len, float *result)
{ {
int mantisse; int mantisse;
int exponent; int exponent;
if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent)) if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
{ {
if (s[4] == '+') *result = (float) (mantisse << exponent); if (s[4] == '+')
else *result = (float) mantisse / (float) (1 << exponent); *result = (float)(mantisse << exponent);
else
*result = (float)mantisse / (float)(1 << exponent);
return EINA_TRUE; return EINA_TRUE;
} }
return EINA_FALSE; return EINA_FALSE;
} }
static inline Eina_Bool static inline Eina_Bool
_eet_dictionary_string_get_double_cache(const char *s, int len, double *result) _eet_dictionary_string_get_double_cache(const char *s, int len, double *result)
{ {
int mantisse; int mantisse;
int exponent; int exponent;
if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent)) if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
{ {
if (s[4] == '+') *result = (double) (mantisse << exponent); if (s[4] == '+')
else *result = (double) mantisse / (float) (1 << exponent); *result = (double)(mantisse << exponent);
else
*result = (double)mantisse / (float)(1 << exponent);
return EINA_TRUE; return EINA_TRUE;
} }
return EINA_FALSE; return EINA_FALSE;
} }
static inline Eina_Bool static inline Eina_Bool
_eet_dictionary_test(const Eet_Dictionary *ed, int idx, void *result) _eet_dictionary_test(const Eet_Dictionary *ed, int idx, void *result)
{ {
if (!result) return EINA_FALSE; if (!result)
if (!ed) return EINA_FALSE; return EINA_FALSE;
if (idx < 0) return EINA_FALSE;
if (!(idx < ed->count)) return EINA_FALSE; if (!ed)
return EINA_FALSE;
if (idx < 0)
return EINA_FALSE;
if (!(idx < ed->count))
return EINA_FALSE;
return EINA_TRUE; return EINA_TRUE;
} }
Eina_Bool Eina_Bool
eet_dictionary_string_get_float(const Eet_Dictionary *ed, int idx, float *result) eet_dictionary_string_get_float(const Eet_Dictionary *ed,
int idx,
float *result)
{ {
if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE; if (!_eet_dictionary_test(ed, idx, result))
return EINA_FALSE;
if (!(ed->all[idx].type & EET_D_FLOAT)) if (!(ed->all[idx].type & EET_D_FLOAT))
{ {
const char *str; const char *str;
str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap; str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len, &ed->all[idx].f)) if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
{ &ed->all[idx].f))
long long mantisse = 0; {
long exponent = 0; long long mantisse = 0;
long exponent = 0;
if (eina_convert_atod(str, ed->all[idx].len, &mantisse, &exponent) == EINA_FALSE) if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
return EINA_FALSE; &exponent) == EINA_FALSE)
return EINA_FALSE;
ed->all[idx].f = ldexpf((float) mantisse, exponent); ed->all[idx].f = ldexpf((float)mantisse, exponent);
} }
ed->all[idx].type |= EET_D_FLOAT; ed->all[idx].type |= EET_D_FLOAT;
} }
*result = ed->all[idx].f; *result = ed->all[idx].f;
@ -285,28 +324,33 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed, int idx, float *result
} }
Eina_Bool Eina_Bool
eet_dictionary_string_get_double(const Eet_Dictionary *ed, int idx, double *result) eet_dictionary_string_get_double(const Eet_Dictionary *ed,
int idx,
double *result)
{ {
if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE; if (!_eet_dictionary_test(ed, idx, result))
return EINA_FALSE;
if (!(ed->all[idx].type & EET_D_DOUBLE)) if (!(ed->all[idx].type & EET_D_DOUBLE))
{ {
const char *str; const char *str;
str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap; str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len, &ed->all[idx].d)) if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
{ &ed->all[idx].d))
long long mantisse = 0; {
long exponent = 0; long long mantisse = 0;
long exponent = 0;
if (eina_convert_atod(str, ed->all[idx].len, &mantisse, &exponent) == EINA_FALSE) if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
return EINA_FALSE; &exponent) == EINA_FALSE)
return EINA_FALSE;
ed->all[idx].d = ldexp((double) mantisse, exponent); ed->all[idx].d = ldexp((double)mantisse, exponent);
} }
ed->all[idx].type |= EET_D_DOUBLE; ed->all[idx].type |= EET_D_DOUBLE;
} }
*result = ed->all[idx].d; *result = ed->all[idx].d;
@ -314,22 +358,25 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed, int idx, double *resu
} }
Eina_Bool Eina_Bool
eet_dictionary_string_get_fp(const Eet_Dictionary *ed, int idx, Eina_F32p32 *result) eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
int idx,
Eina_F32p32 *result)
{ {
if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE; if (!_eet_dictionary_test(ed, idx, result))
return EINA_FALSE;
if (!(ed->all[idx].type & EET_D_FIXED_POINT)) if (!(ed->all[idx].type & EET_D_FIXED_POINT))
{ {
const char *str; const char *str;
Eina_F32p32 fp; Eina_F32p32 fp;
str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap; str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
if (!eina_convert_atofp(str, ed->all[idx].len, &fp)) if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
return EINA_FALSE; return EINA_FALSE;
ed->all[idx].fp = fp; ed->all[idx].fp = fp;
ed->all[idx].type |= EET_D_FIXED_POINT; ed->all[idx].type |= EET_D_FIXED_POINT;
} }
*result = ed->all[idx].fp; *result = ed->all[idx].fp;
@ -339,19 +386,19 @@ eet_dictionary_string_get_fp(const Eet_Dictionary *ed, int idx, Eina_F32p32 *res
EAPI int EAPI int
eet_dictionary_string_check(Eet_Dictionary *ed, const char *string) eet_dictionary_string_check(Eet_Dictionary *ed, const char *string)
{ {
int i; int i;
if (ed == NULL if (ed == NULL
|| string == NULL) || string == NULL)
return 0; return 0;
if (ed->start <= string if (ed->start <= string
&& string < ed->end) && string < ed->end)
return 1; return 1;
for (i = 0; i < ed->count; ++i) for (i = 0; i < ed->count; ++i)
if (ed->all[i].str == string) if (ed->all[i].str == string)
return 1; return 1;
return 0; return 0;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -27,7 +27,7 @@ eet_node_new(void)
result = eina_mempool_malloc(_eet_node_mp, sizeof (Eet_Node)); result = eina_mempool_malloc(_eet_node_mp, sizeof (Eet_Node));
if (!result) if (!result)
return NULL; return NULL;
memset(result, 0, sizeof (Eet_Node)); memset(result, 0, sizeof (Eet_Node));
return result; return result;
@ -45,7 +45,8 @@ _eet_node_new(const char *name, int type)
Eet_Node *n; Eet_Node *n;
n = eet_node_new(); n = eet_node_new();
if (!n) return NULL; if (!n)
return NULL;
n->type = type; n->type = type;
n->name = eina_stringshare_add(name); n->name = eina_stringshare_add(name);
@ -60,51 +61,51 @@ _eet_node_append(Eet_Node *n, Eina_List *nodes)
Eina_List *l; Eina_List *l;
EINA_LIST_REVERSE_FOREACH(nodes, l, value) EINA_LIST_REVERSE_FOREACH(nodes, l, value)
{ {
value->next = n->values; value->next = n->values;
n->values = value; n->values = value;
} }
} }
#define EET_NODE_NEW(Eet_type, Name, Value, Type) \ #define EET_NODE_NEW(Eet_type, Name, Value, Type) \
EAPI Eet_Node * \ EAPI Eet_Node * \
eet_node_##Name##_new(const char *name, Type Value) \ eet_node_ ## Name ## _new(const char *name, Type Value) \
{ \ { \
Eet_Node *n; \ Eet_Node *n; \
\ \
n = _eet_node_new(name, Eet_type); \ n = _eet_node_new(name, Eet_type); \
if (!n) return NULL; \ if (!n) { return NULL; } \
\ \
n->data.value.Value = Value; \ n->data.value.Value = Value; \
\ \
return n; \ return n; \
} }
#define EET_NODE_STR_NEW(Eet_type, Name, Value, Type) \ #define EET_NODE_STR_NEW(Eet_type, Name, Value, Type) \
EAPI Eet_Node * \ EAPI Eet_Node * \
eet_node_##Name##_new(const char *name, Type Value) \ eet_node_ ## Name ## _new(const char *name, Type Value) \
{ \ { \
Eet_Node *n; \ Eet_Node *n; \
\ \
n = _eet_node_new(name, Eet_type); \ n = _eet_node_new(name, Eet_type); \
if (!n) return NULL; \ if (!n) { return NULL; } \
\ \
n->data.value.Value = eina_stringshare_add(Value); \ n->data.value.Value = eina_stringshare_add(Value); \
\ \
return n; \ return n; \
} }
EET_NODE_NEW(EET_T_CHAR, char, c, char) EET_NODE_NEW(EET_T_CHAR, char, c, char)
EET_NODE_NEW(EET_T_SHORT, short, s, short) EET_NODE_NEW(EET_T_SHORT, short, s, short)
EET_NODE_NEW(EET_T_INT, int, i, int) EET_NODE_NEW(EET_T_INT, int, i, int)
EET_NODE_NEW(EET_T_LONG_LONG, long_long, l, long long) EET_NODE_NEW(EET_T_LONG_LONG, long_long, l, long long)
EET_NODE_NEW(EET_T_FLOAT, float, f, float) EET_NODE_NEW(EET_T_FLOAT, float, f, float)
EET_NODE_NEW(EET_T_DOUBLE, double, d, double) EET_NODE_NEW(EET_T_DOUBLE, double, d, double)
EET_NODE_NEW(EET_T_UCHAR, unsigned_char, uc, unsigned char) EET_NODE_NEW(EET_T_UCHAR, unsigned_char, uc, unsigned char)
EET_NODE_NEW(EET_T_USHORT, unsigned_short, us, unsigned short) EET_NODE_NEW(EET_T_USHORT, unsigned_short, us, unsigned short)
EET_NODE_NEW(EET_T_UINT, unsigned_int, ui, unsigned int) EET_NODE_NEW(EET_T_UINT, unsigned_int, ui, unsigned int)
EET_NODE_NEW(EET_T_ULONG_LONG, unsigned_long_long, ul, unsigned long long) EET_NODE_NEW(EET_T_ULONG_LONG, unsigned_long_long, ul, unsigned long long)
EET_NODE_STR_NEW(EET_T_STRING, string, str, const char *) EET_NODE_STR_NEW(EET_T_STRING, string, str, const char *)
EET_NODE_STR_NEW(EET_T_INLINED_STRING, inlined_string, str, const char *) EET_NODE_STR_NEW(EET_T_INLINED_STRING, inlined_string, str, const char *)
Eet_Node * Eet_Node *
@ -113,7 +114,8 @@ eet_node_null_new(const char *name)
Eet_Node *n; Eet_Node *n;
n = _eet_node_new(name, EET_T_NULL); n = _eet_node_new(name, EET_T_NULL);
if (!n) return NULL; if (!n)
return NULL;
n->data.value.str = NULL; n->data.value.str = NULL;
@ -126,7 +128,8 @@ eet_node_list_new(const char *name, Eina_List *nodes)
Eet_Node *n; Eet_Node *n;
n = _eet_node_new(name, EET_G_LIST); n = _eet_node_new(name, EET_G_LIST);
if (!n) return NULL; if (!n)
return NULL;
_eet_node_append(n, nodes); _eet_node_append(n, nodes);
@ -139,7 +142,8 @@ eet_node_array_new(const char *name, int count, Eina_List *nodes)
Eet_Node *n; Eet_Node *n;
n = _eet_node_new(name, EET_G_ARRAY); n = _eet_node_new(name, EET_G_ARRAY);
if (!n) return NULL; if (!n)
return NULL;
n->count = count; n->count = count;
@ -154,7 +158,8 @@ eet_node_var_array_new(const char *name, Eina_List *nodes)
Eet_Node *n; Eet_Node *n;
n = _eet_node_new(name, EET_G_VAR_ARRAY); n = _eet_node_new(name, EET_G_VAR_ARRAY);
if (!n) return NULL; if (!n)
return NULL;
n->count = eina_list_count(nodes); n->count = eina_list_count(nodes);
@ -169,10 +174,12 @@ eet_node_hash_new(const char *name, const char *key, Eet_Node *node)
Eina_List *nodes; Eina_List *nodes;
Eet_Node *n; Eet_Node *n;
if (!node) return NULL; if (!node)
return NULL;
n = _eet_node_new(name, EET_G_HASH); n = _eet_node_new(name, EET_G_HASH);
if (!n) return NULL; if (!n)
return NULL;
n->key = eina_stringshare_add(key); n->key = eina_stringshare_add(key);
nodes = eina_list_append(NULL, node); nodes = eina_list_append(NULL, node);
@ -188,7 +195,8 @@ eet_node_struct_new(const char *name, Eina_List *nodes)
Eet_Node *n; Eet_Node *n;
n = _eet_node_new(name, EET_G_UNKNOWN); n = _eet_node_new(name, EET_G_UNKNOWN);
if (!n) return NULL; if (!n)
return NULL;
_eet_node_append(n, nodes); _eet_node_append(n, nodes);
@ -201,10 +209,11 @@ eet_node_struct_child_new(const char *parent, Eet_Node *child)
Eet_Node *n; Eet_Node *n;
if (child->type != EET_G_UNKNOWN) if (child->type != EET_G_UNKNOWN)
return child; return child;
n = _eet_node_new(parent, EET_G_UNKNOWN); n = _eet_node_new(parent, EET_G_UNKNOWN);
if (!n) return NULL; if (!n)
return NULL;
_eet_node_append(n, eina_list_prepend(NULL, child)); _eet_node_append(n, eina_list_prepend(NULL, child));
@ -220,23 +229,25 @@ eet_node_list_append(Eet_Node *parent, const char *name, Eet_Node *child)
tmp = eina_stringshare_add(name); tmp = eina_stringshare_add(name);
for (nn = parent->values; nn; nn = nn->next) for (nn = parent->values; nn; nn = nn->next)
if (nn->name == tmp && nn->type == EET_G_LIST) if (nn->name == tmp && nn->type == EET_G_LIST)
{ {
Eet_Node *n; Eet_Node *n;
if (!nn->values) nn->values = child; if (!nn->values)
else nn->values = child;
{ else
for (n = nn->values; n->next; n = n->next) {
; for (n = nn->values; n->next; n = n->next)
n->next = child; ;
} n->next = child;
child->next = NULL; }
eina_stringshare_del(tmp); child->next = NULL;
return ; eina_stringshare_del(tmp);
}
return;
}
/* No list found, so create it. */ /* No list found, so create it. */
nn = eet_node_list_new(tmp, eina_list_append(NULL, child)); nn = eet_node_list_new(tmp, eina_list_append(NULL, child));
@ -245,7 +256,7 @@ eet_node_list_append(Eet_Node *parent, const char *name, Eet_Node *child)
nn->next = parent->values; nn->next = parent->values;
parent->values = nn; parent->values = nn;
eina_stringshare_del(tmp); eina_stringshare_del(tmp);
} }
void void
@ -257,41 +268,48 @@ eet_node_struct_append(Eet_Node *parent, const char *name, Eet_Node *child)
if (parent->type != EET_G_UNKNOWN) if (parent->type != EET_G_UNKNOWN)
{ {
ERR("[%s] is not a structure. Will not insert [%s] in it", parent->name, name); ERR("[%s] is not a structure. Will not insert [%s] in it",
eet_node_del(child); parent->name,
return ; name);
eet_node_del(child);
return;
} }
tmp = eina_stringshare_add(name); tmp = eina_stringshare_add(name);
for (prev = NULL, nn = parent->values; nn; prev = nn, nn = nn->next) for (prev = NULL, nn = parent->values; nn; prev = nn, nn = nn->next)
if (nn->name == tmp && nn->type == child->type) if (nn->name == tmp && nn->type == child->type)
{ {
if (prev) prev->next = nn->next; if (prev)
else parent->values = nn->next; prev->next = nn->next;
else
parent->values = nn->next;
nn->next = NULL; nn->next = NULL;
eet_node_del(nn); eet_node_del(nn);
break; break;
} }
if (prev) if (prev)
{ {
prev->next = child; prev->next = child;
child->next = NULL; child->next = NULL;
} }
else else
{ {
child->next = NULL; child->next = NULL;
parent->values = child; parent->values = child;
} }
eina_stringshare_del(tmp); eina_stringshare_del(tmp);
} }
void void
eet_node_hash_add(Eet_Node *parent, const char *name, const char *key, Eet_Node *child) eet_node_hash_add(Eet_Node *parent,
const char *name,
const char *key,
Eet_Node *child)
{ {
Eet_Node *nn; Eet_Node *nn;
@ -309,27 +327,31 @@ eet_node_del(Eet_Node *n)
Eet_Node *nn; Eet_Node *nn;
Eet_Node *tmp; Eet_Node *tmp;
if (!n) return ; if (!n)
return;
switch (n->type) switch (n->type)
{ {
case EET_G_HASH: case EET_G_HASH:
eina_stringshare_del(n->key); eina_stringshare_del(n->key);
case EET_G_UNKNOWN: case EET_G_UNKNOWN:
case EET_G_VAR_ARRAY: case EET_G_VAR_ARRAY:
case EET_G_ARRAY: case EET_G_ARRAY:
case EET_G_LIST: case EET_G_LIST:
for (nn = n->values; nn; ) for (nn = n->values; nn; )
{ {
tmp = nn; tmp = nn;
nn = nn->next; nn = nn->next;
eet_node_del(tmp); eet_node_del(tmp);
} }
break; break;
case EET_T_STRING: case EET_T_STRING:
case EET_T_INLINED_STRING: case EET_T_INLINED_STRING:
eina_stringshare_del(n->data.value.str); eina_stringshare_del(n->data.value.str);
break; break;
case EET_T_CHAR: case EET_T_CHAR:
case EET_T_SHORT: case EET_T_SHORT:
case EET_T_INT: case EET_T_INT:
@ -339,39 +361,41 @@ eet_node_del(Eet_Node *n)
case EET_T_UCHAR: case EET_T_UCHAR:
case EET_T_USHORT: case EET_T_USHORT:
case EET_T_UINT: case EET_T_UINT:
break; break;
} }
eina_stringshare_del(n->name); eina_stringshare_del(n->name);
eet_node_free(n); eet_node_free(n);
} }
static const char *eet_node_dump_g_name[6] = { static const char *eet_node_dump_g_name[6] = {
"struct", "struct",
"array", "array",
"var_array", "var_array",
"list", "list",
"hash", "hash",
"???" "???"
}; };
static const char *eet_node_dump_t_name[14][2] = { static const char *eet_node_dump_t_name[14][2] = {
{ "???: ", "???" }, { "???: ", "???" },
{ "char: ", "%hhi" }, { "char: ", "%hhi" },
{ "short: ", "%hi" }, { "short: ", "%hi" },
{ "int: ", "%i" }, { "int: ", "%i" },
{ "long_long: ", "%lli" }, { "long_long: ", "%lli" },
{ "float: ", "%1.25f" }, { "float: ", "%1.25f" },
{ "double: ", "%1.25f" }, { "double: ", "%1.25f" },
{ "uchar: ", "%hhu" }, { "uchar: ", "%hhu" },
{ "ushort: ", "%i" }, { "ushort: ", "%i" },
{ "uint: ", "%u" }, { "uint: ", "%u" },
{ "ulong_long: ", "%llu" }, { "ulong_long: ", "%llu" },
{ "null", "" } { "null", "" }
}; };
static void static void
eet_node_dump_level(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata) eet_node_dump_level(int level, void (*dumpfunc)(void *data,
const char *str),
void *dumpdata)
{ {
int i; int i;
@ -387,36 +411,48 @@ eet_node_string_escape(const char *str)
for (strp = str; *strp; strp++) for (strp = str; *strp; strp++)
{ {
if (*strp == '\"') sz += 2; if (*strp == '\"')
else if (*strp == '\\') sz += 2; sz += 2;
else if (*strp == '\n') sz += 2; else if (*strp == '\\')
else sz += 1; sz += 2;
else if (*strp == '\n')
sz += 2;
else
sz += 1;
} }
s = malloc(sz + 1); s = malloc(sz + 1);
if (!s) return NULL; if (!s)
return NULL;
for (strp = str, sp = s; *strp; strp++, sp++) for (strp = str, sp = s; *strp; strp++, sp++)
{ {
if (*strp == '\"' if (*strp == '\"'
|| *strp == '\\' || *strp == '\\'
|| *strp == '\n') || *strp == '\n')
{ {
*sp = '\\'; *sp = '\\';
sp++; sp++;
} }
if (*strp == '\n') *sp = 'n';
else *sp = *strp; if (*strp == '\n')
*sp = 'n';
else
*sp = *strp;
} }
*sp = 0; *sp = 0;
return s; return s;
} }
static void static void
eet_node_dump_string_escape(void *dumpdata, void dumpfunc(void *data, const char *str), const char *str) eet_node_dump_string_escape(void *dumpdata, void dumpfunc(void *data,
const char *str),
const char *str)
{ {
char *s; char *s;
s = eet_node_string_escape(str); s = eet_node_string_escape(str);
if (!s) return ; if (!s)
return;
dumpfunc(dumpdata, s); dumpfunc(dumpdata, s);
free(s); free(s);
@ -424,7 +460,8 @@ eet_node_dump_string_escape(void *dumpdata, void dumpfunc(void *data, const char
static void static void
eet_node_dump_simple_type(Eet_Node *n, int level, eet_node_dump_simple_type(Eet_Node *n, int level,
void (*dumpfunc) (void *data, const char *str), void *dumpdata) void (*dumpfunc)(void *data,
const char *str), void *dumpdata)
{ {
const char *type_name = NULL; const char *type_name = NULL;
char tbuf[256]; char tbuf[256];
@ -432,84 +469,99 @@ eet_node_dump_simple_type(Eet_Node *n, int level,
eet_node_dump_level(level, dumpfunc, dumpdata); eet_node_dump_level(level, dumpfunc, dumpdata);
dumpfunc(dumpdata, "value \""); dumpfunc(dumpdata, "value \"");
eet_node_dump_string_escape(dumpdata, dumpfunc, n->name); eet_node_dump_string_escape(dumpdata, dumpfunc, n->name);
dumpfunc(dumpdata, "\" "); dumpfunc(dumpdata, "\" ");
#ifdef EET_T_TYPE #ifdef EET_T_TYPE
# undef EET_T_TYPE # undef EET_T_TYPE
#endif #endif
#define EET_T_TYPE(Eet_Type, Type) \ #define EET_T_TYPE(Eet_Type, Type) \
case Eet_Type: \ case Eet_Type: \
{ \ { \
dumpfunc(dumpdata, eet_node_dump_t_name[Eet_Type][0]); \ dumpfunc(dumpdata, eet_node_dump_t_name[Eet_Type][0]); \
snprintf(tbuf, sizeof (tbuf), eet_node_dump_t_name[Eet_Type][1], n->data.value.Type); \ snprintf(tbuf, \
dumpfunc(dumpdata, tbuf); \ sizeof (tbuf), \
break; \ eet_node_dump_t_name[Eet_Type][1], \
} n->data.value.Type); \
dumpfunc(dumpdata, tbuf); \
break; \
}
switch (n->type) switch (n->type)
{ {
EET_T_TYPE(EET_T_CHAR, c); EET_T_TYPE(EET_T_CHAR, c);
EET_T_TYPE(EET_T_SHORT, s); EET_T_TYPE(EET_T_SHORT, s);
EET_T_TYPE(EET_T_INT, i); EET_T_TYPE(EET_T_INT, i);
EET_T_TYPE(EET_T_LONG_LONG, l); EET_T_TYPE(EET_T_LONG_LONG, l);
EET_T_TYPE(EET_T_FLOAT, f); EET_T_TYPE(EET_T_FLOAT, f);
EET_T_TYPE(EET_T_DOUBLE, d); EET_T_TYPE(EET_T_DOUBLE, d);
EET_T_TYPE(EET_T_UCHAR, uc); EET_T_TYPE(EET_T_UCHAR, uc);
EET_T_TYPE(EET_T_USHORT, us); EET_T_TYPE(EET_T_USHORT, us);
EET_T_TYPE(EET_T_UINT, ui); EET_T_TYPE(EET_T_UINT, ui);
EET_T_TYPE(EET_T_ULONG_LONG, ul); EET_T_TYPE(EET_T_ULONG_LONG, ul);
case EET_T_INLINED_STRING:
type_name = "inlined: \""; case EET_T_INLINED_STRING:
case EET_T_STRING: type_name = "inlined: \"";
if (!type_name) type_name = "string: \"";
case EET_T_STRING:
if (!type_name)
type_name = "string: \"";
dumpfunc(dumpdata, type_name);
eet_node_dump_string_escape(dumpdata, dumpfunc, n->data.value.str);
dumpfunc(dumpdata, "\"");
break;
dumpfunc(dumpdata, type_name);
eet_node_dump_string_escape(dumpdata, dumpfunc, n->data.value.str);
dumpfunc(dumpdata, "\"");
break;
case EET_T_NULL: case EET_T_NULL:
dumpfunc(dumpdata, "null"); dumpfunc(dumpdata, "null");
break; break;
default: default:
dumpfunc(dumpdata, "???: ???"); dumpfunc(dumpdata, "???: ???");
break; break;
} }
dumpfunc(dumpdata, ";\n"); dumpfunc(dumpdata, ";\n");
} }
static void static void
eet_node_dump_group_start(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, eet_node_dump_group_start(int level, void (*dumpfunc)(void *data,
int group_type, const char *name) const char *str),
void *dumpdata,
int group_type, const char *name)
{ {
int chnk_type; int chnk_type;
chnk_type = (group_type >= EET_G_UNKNOWN && group_type <= EET_G_HASH) ? chnk_type = (group_type >= EET_G_UNKNOWN && group_type <= EET_G_HASH) ?
group_type : EET_G_LAST; group_type : EET_G_LAST;
eet_node_dump_level(level, dumpfunc, dumpdata); eet_node_dump_level(level, dumpfunc, dumpdata);
dumpfunc(dumpdata, "group \""); dumpfunc(dumpdata, "group \"");
eet_node_dump_string_escape(dumpdata, dumpfunc, name); eet_node_dump_string_escape(dumpdata, dumpfunc, name);
dumpfunc(dumpdata, "\" "); dumpfunc(dumpdata, "\" ");
dumpfunc(dumpdata, eet_node_dump_g_name[chnk_type - EET_G_UNKNOWN]); dumpfunc(dumpdata, eet_node_dump_g_name[chnk_type - EET_G_UNKNOWN]);
dumpfunc(dumpdata, " {\n"); dumpfunc(dumpdata, " {\n");
} }
static void static void
eet_node_dump_group_end(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata) eet_node_dump_group_end(int level, void (*dumpfunc)(void *data,
const char *str),
void *dumpdata)
{ {
eet_node_dump_level(level, dumpfunc, dumpdata); eet_node_dump_level(level, dumpfunc, dumpdata);
dumpfunc(dumpdata, "}\n"); dumpfunc(dumpdata, "}\n");
} }
void void
eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc) (void *data, const char *str), void *dumpdata) eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc)(void *data,
const char *str),
void *dumpdata)
{ {
Eet_Node *it; Eet_Node *it;
if (!n) return ; if (!n)
return;
switch (n->type) switch (n->type)
{ {
@ -518,32 +570,37 @@ eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc) (void *data, const ch
case EET_G_UNKNOWN: case EET_G_UNKNOWN:
case EET_G_HASH: case EET_G_HASH:
case EET_G_LIST: case EET_G_LIST:
eet_node_dump_group_start(dumplevel, dumpfunc, dumpdata, n->type, n->name); eet_node_dump_group_start(dumplevel,
dumpfunc,
dumpdata,
n->type,
n->name);
if (n->type == EET_G_VAR_ARRAY if (n->type == EET_G_VAR_ARRAY
|| n->type == EET_G_ARRAY) || n->type == EET_G_ARRAY)
{ {
char tbuf[256]; char tbuf[256];
eet_node_dump_level(dumplevel, dumpfunc, dumpdata); eet_node_dump_level(dumplevel, dumpfunc, dumpdata);
dumpfunc(dumpdata, " count "); dumpfunc(dumpdata, " count ");
eina_convert_itoa(n->count, tbuf); eina_convert_itoa(n->count, tbuf);
dumpfunc(dumpdata, tbuf); dumpfunc(dumpdata, tbuf);
dumpfunc(dumpdata, ";\n"); dumpfunc(dumpdata, ";\n");
} }
else if (n->type == EET_G_HASH) else if (n->type == EET_G_HASH)
{ {
eet_node_dump_level(dumplevel, dumpfunc, dumpdata); eet_node_dump_level(dumplevel, dumpfunc, dumpdata);
dumpfunc(dumpdata, " key \""); dumpfunc(dumpdata, " key \"");
eet_node_dump_string_escape(dumpdata, dumpfunc, n->key); eet_node_dump_string_escape(dumpdata, dumpfunc, n->key);
dumpfunc(dumpdata, "\";\n"); dumpfunc(dumpdata, "\";\n");
} }
for (it = n->values; it != NULL; it = it->next) for (it = n->values; it != NULL; it = it->next)
eet_node_dump(it, dumplevel + 2, dumpfunc, dumpdata); eet_node_dump(it, dumplevel + 2, dumpfunc, dumpdata);
eet_node_dump_group_end(dumplevel, dumpfunc, dumpdata);
break;
eet_node_dump_group_end(dumplevel, dumpfunc, dumpdata);
break;
case EET_T_STRING: case EET_T_STRING:
case EET_T_INLINED_STRING: case EET_T_INLINED_STRING:
case EET_T_CHAR: case EET_T_CHAR:
@ -556,13 +613,17 @@ eet_node_dump(Eet_Node *n, int dumplevel, void (*dumpfunc) (void *data, const ch
case EET_T_USHORT: case EET_T_USHORT:
case EET_T_UINT: case EET_T_UINT:
case EET_T_ULONG_LONG: case EET_T_ULONG_LONG:
eet_node_dump_simple_type(n, dumplevel, dumpfunc, dumpdata); eet_node_dump_simple_type(n, dumplevel, dumpfunc, dumpdata);
break; break;
} }
} }
void* void *
eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb, void *user_data) eet_node_walk(void *parent,
const char *name,
Eet_Node *root,
Eet_Node_Walk *cb,
void *user_data)
{ {
Eet_Node *it; Eet_Node *it;
void *me = NULL; void *me = NULL;
@ -570,39 +631,59 @@ eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb,
if (!root) if (!root)
{ {
if (parent) cb->struct_add(parent, name, NULL, user_data); if (parent)
return NULL; cb->struct_add(parent, name, NULL, user_data);
return NULL;
} }
switch (root->type) switch (root->type)
{ {
case EET_G_UNKNOWN: case EET_G_UNKNOWN:
me = cb->struct_alloc(root->name, user_data); me = cb->struct_alloc(root->name, user_data);
for (it = root->values; it != NULL; it = it->next) for (it = root->values; it != NULL; it = it->next)
eet_node_walk(me, it->name, it, cb, user_data); eet_node_walk(me, it->name, it, cb, user_data);
break;
break;
case EET_G_VAR_ARRAY: case EET_G_VAR_ARRAY:
case EET_G_ARRAY: case EET_G_ARRAY:
me = cb->array(root->type == EET_G_VAR_ARRAY ? EINA_TRUE : EINA_FALSE, me = cb->array(root->type == EET_G_VAR_ARRAY ? EINA_TRUE : EINA_FALSE,
root->name, root->count, user_data); root->name, root->count, user_data);
for (i = 0, it = root->values; it != NULL; it = it->next) for (i = 0, it = root->values; it != NULL; it = it->next)
cb->insert(me, i++, eet_node_walk(NULL, NULL, it, cb, user_data), user_data); cb->insert(me, i++, eet_node_walk(NULL,
NULL,
it,
cb,
user_data), user_data);
break;
break;
case EET_G_LIST: case EET_G_LIST:
me = cb->list(root->name, user_data); me = cb->list(root->name, user_data);
for (it = root->values; it != NULL; it = it->next) for (it = root->values; it != NULL; it = it->next)
cb->append(me, eet_node_walk(NULL, NULL, it, cb, user_data), user_data); cb->append(me, eet_node_walk(NULL,
NULL,
it,
cb,
user_data), user_data);
break;
break;
case EET_G_HASH: case EET_G_HASH:
if (!parent) return NULL; if (!parent)
return NULL;
return cb->hash(parent, root->name, root->key,
eet_node_walk(NULL,
NULL,
root->values,
cb,
user_data), user_data);
return cb->hash(parent, root->name, root->key, eet_node_walk(NULL, NULL, root->values, cb, user_data), user_data);
case EET_T_STRING: case EET_T_STRING:
case EET_T_INLINED_STRING: case EET_T_INLINED_STRING:
case EET_T_CHAR: case EET_T_CHAR:
@ -615,11 +696,13 @@ eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb,
case EET_T_USHORT: case EET_T_USHORT:
case EET_T_UINT: case EET_T_UINT:
case EET_T_ULONG_LONG: case EET_T_ULONG_LONG:
me = cb->simple(root->type, &root->data, user_data); me = cb->simple(root->type, &root->data, user_data);
break; break;
} }
if (parent) cb->struct_add(parent, name, me, user_data); if (parent)
cb->struct_add(parent, name, me, user_data);
return me; return me;
} }
@ -632,9 +715,10 @@ eet_node_init(void)
choice = "chained_mempool"; choice = "chained_mempool";
tmp = getenv("EET_MEMPOOL"); tmp = getenv("EET_MEMPOOL");
if (tmp && tmp[0]) if (tmp && tmp[0])
choice = tmp; choice = tmp;
_eet_node_mp = eina_mempool_add(choice, "eet-node-alloc", NULL, sizeof(Eet_Node), 1024); _eet_node_mp =
eina_mempool_add(choice, "eet-node-alloc", NULL, sizeof(Eet_Node), 1024);
return _eet_node_mp ? 1 : 0; return _eet_node_mp ? 1 : 0;
} }

View File

@ -15,19 +15,20 @@
int int
_eet_hash_gen(const char *key, int hash_size) _eet_hash_gen(const char *key, int hash_size)
{ {
int hash_num = 0; int hash_num = 0;
int value, i; int value, i;
int mask; int mask;
unsigned char *ptr; unsigned char *ptr;
/* no string - index 0 */ /* no string - index 0 */
if (!key) return 0; if (!key)
return 0;
/* calc hash num */ /* calc hash num */
for (i = 0, ptr = (unsigned char *)key, value = (int)(*ptr); for (i = 0, ptr = (unsigned char *)key, value = (int)(*ptr);
value; value;
ptr++, i++, value = (int)(*ptr)) ptr++, i++, value = (int)(*ptr))
hash_num ^= (value | (value << 8)) >> (i & 0x7); hash_num ^= (value | (value << 8)) >> (i & 0x7);
/* mask it */ /* mask it */
mask = (1 << hash_size) - 1; mask = (1 << hash_size) - 1;

View File

@ -5,31 +5,35 @@
#include "eet_suite.h" #include "eet_suite.h"
static char* static char *
_eet_str_direct_alloc(const char *str) _eet_str_direct_alloc(const char *str)
{ {
return (char*) str; return (char *)str;
} }
static void static void
_eet_str_direct_free(const char *str) _eet_str_direct_free(const char *str)
{ {
/* FIXME: Use attribute unused */ /* FIXME: Use attribute unused */
(void) str; (void)str;
} }
static void static void
_eet_eina_hash_foreach(void *hash, Eina_Hash_Foreach cb, void *fdata) _eet_eina_hash_foreach(void *hash, Eina_Hash_Foreach cb, void *fdata)
{ {
if (hash) eina_hash_foreach(hash, cb, fdata); if (hash)
eina_hash_foreach(hash, cb, fdata);
} }
/* Internal wrapper for eina_hash */ /* Internal wrapper for eina_hash */
static Eina_Hash* static Eina_Hash *
_eet_eina_hash_add(Eina_Hash *hash, const char *key, const void *data) _eet_eina_hash_add(Eina_Hash *hash, const char *key, const void *data)
{ {
if (!hash) hash = eina_hash_string_superfast_new(NULL); if (!hash)
if (!hash) return NULL; hash = eina_hash_string_superfast_new(NULL);
if (!hash)
return NULL;
eina_hash_add(hash, key, data); eina_hash_add(hash, key, data);
return hash; return hash;
@ -38,7 +42,8 @@ _eet_eina_hash_add(Eina_Hash *hash, const char *key, const void *data)
static void static void
_eet_eina_hash_free(Eina_Hash *hash) _eet_eina_hash_free(Eina_Hash *hash)
{ {
if (hash) eina_hash_free(hash); if (hash)
eina_hash_free(hash);
} }
void void
@ -49,14 +54,14 @@ eet_test_setup_eddc(Eet_Data_Descriptor_Class *eddc)
eddc->func.mem_free = NULL; eddc->func.mem_free = NULL;
eddc->func.str_alloc = NULL; eddc->func.str_alloc = NULL;
eddc->func.str_free = NULL; eddc->func.str_free = NULL;
eddc->func.list_next = (void*) eina_list_next; eddc->func.list_next = (void *)eina_list_next;
eddc->func.list_append = (void*) eina_list_append; eddc->func.list_append = (void *)eina_list_append;
eddc->func.list_data = (void*) eina_list_data_get; eddc->func.list_data = (void *)eina_list_data_get;
eddc->func.list_free = (void*) eina_list_free; eddc->func.list_free = (void *)eina_list_free;
eddc->func.hash_foreach = (void*) _eet_eina_hash_foreach; eddc->func.hash_foreach = (void *)_eet_eina_hash_foreach;
eddc->func.hash_add = (void*) _eet_eina_hash_add; eddc->func.hash_add = (void *)_eet_eina_hash_add;
eddc->func.hash_free = (void*) _eet_eina_hash_free; eddc->func.hash_free = (void *)_eet_eina_hash_free;
eddc->func.str_direct_alloc = (void*) _eet_str_direct_alloc; eddc->func.str_direct_alloc = (void *)_eet_str_direct_alloc;
eddc->func.str_direct_free = (void*) _eet_str_direct_free; eddc->func.str_direct_free = (void *)_eet_str_direct_free;
} }

File diff suppressed because it is too large Load Diff