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)
{
ERR("cannot open for reading: %s\n", file);
exit(-1);
exit(-1);
}
list = eet_list(ef, "*", &num);
if (list)
{
for (i = 0; i < num; i++)
printf("%s\n",list[i]);
free(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, const char *crypto_key)
do_eet_extract(const char *file,
const char *key,
const char *out,
const char *crypto_key)
{
Eet_File *ef;
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);
if (!ef)
{
ERR("cannot open for reading: %s\n", file);
exit(-1);
ERR("cannot open for reading: %s\n", file);
exit(-1);
}
data = eet_read_cipher(ef, key, &size, crypto_key);
if (!data)
{
ERR("cannot read key %s\n", key);
exit(-1);
ERR("cannot read key %s\n", key);
exit(-1);
}
f = fopen(out, "wb");
if (!f)
{
ERR("cannot open %s\n", out);
exit(-1);
ERR("cannot open %s\n", out);
exit(-1);
}
if (fwrite(data, size, 1, f) != 1)
{
ERR("cannot write to %s\n", out);
exit(-1);
ERR("cannot write to %s\n", out);
exit(-1);
}
fclose(f);
free(data);
eet_close(ef);
@ -113,7 +122,10 @@ do_eet_decode_dump(void *data, const char *str)
}
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;
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);
if (!ef)
{
ERR("cannot open for reading: %s\n", file);
exit(-1);
ERR("cannot open for reading: %s\n", file);
exit(-1);
}
f = fopen(out, "wb");
if (!f)
{
ERR("cannot open %s\n", out);
exit(-1);
ERR("cannot open %s\n", out);
exit(-1);
}
if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f))
{
ERR("cannot write to %s\n", out);
exit(-1);
ERR("cannot write to %s\n", out);
exit(-1);
}
fclose(f);
eet_close(ef);
}
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;
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);
if (!ef)
ef = eet_open(file, EET_FILE_MODE_WRITE);
ef = eet_open(file, EET_FILE_MODE_WRITE);
if (!ef)
{
ERR("cannot open for read+write: %s\n", file);
exit(-1);
ERR("cannot open for read+write: %s\n", file);
exit(-1);
}
f = fopen(out, "rb");
if (!f)
{
ERR("cannot open %s\n", out);
exit(-1);
ERR("cannot open %s\n", out);
exit(-1);
}
fseek(f, 0, SEEK_END);
size = ftell(f);
rewind(f);
data = malloc(size);
if (!data)
{
ERR("cannot allocate %i bytes\n", size);
exit(-1);
ERR("cannot allocate %i bytes\n", size);
exit(-1);
}
if (fread(data, size, 1, f) != 1)
{
ERR("cannot read file %s\n", out);
exit(-1);
ERR("cannot read file %s\n", out);
exit(-1);
}
fclose(f);
eet_write_cipher(ef, key, data, size, compress, crypto_key);
free(data);
@ -182,7 +206,11 @@ do_eet_insert(const char *file, const char *key, const char *out, int compress,
}
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;
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);
if (!ef)
ef = eet_open(file, EET_FILE_MODE_WRITE);
ef = eet_open(file, EET_FILE_MODE_WRITE);
if (!ef)
{
ERR("cannot open for read+write: %s\n", file);
exit(-1);
ERR("cannot open for read+write: %s\n", file);
exit(-1);
}
f = fopen(out, "rb");
if (!f)
{
ERR("cannot open %s\n", out);
exit(-1);
ERR("cannot open %s\n", out);
exit(-1);
}
fseek(f, 0, SEEK_END);
textlen = ftell(f);
rewind(f);
text = malloc(textlen);
if (!text)
{
ERR("cannot allocate %i bytes\n", size);
exit(-1);
ERR("cannot allocate %i bytes\n", size);
exit(-1);
}
if (fread(text, textlen, 1, f) != 1)
{
ERR("cannot read file %s\n", out);
exit(-1);
ERR("cannot read file %s\n", out);
exit(-1);
}
fclose(f);
if (!eet_data_undump_cipher(ef, key, crypto_key, text, textlen, compress))
{
ERR("cannot parse %s\n", out);
exit(-1);
exit(-1);
}
free(text);
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);
if (!ef)
{
ERR("cannot open for read+write: %s\n", file);
exit(-1);
ERR("cannot open for read+write: %s\n", file);
exit(-1);
}
eet_delete(ef, key);
eet_close(ef);
}
@ -254,8 +289,8 @@ do_eet_check(const char *file)
ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef)
{
ERR("checking signature of `%s` failed\n", file);
exit(-1);
ERR("checking signature of `%s` failed\n", file);
exit(-1);
}
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);
if (!ef)
{
ERR("cannot open for read+write: %s.\n", file);
exit(-1);
ERR("cannot open for read+write: %s.\n", file);
exit(-1);
}
key = eet_identity_open(public_key, private_key, NULL);
if (!key)
{
ERR("cannot open key '%s:%s'.\n", public_key, private_key);
exit(-1);
ERR("cannot open key '%s:%s'.\n", public_key, private_key);
exit(-1);
}
fprintf(stdout, "Using the following key to sign `%s`.\n", file);
@ -301,83 +336,75 @@ int
main(int argc, char **argv)
{
if (!eet_init())
return -1;
return -1;
_eet_main_log_dom = eina_log_domain_register("Eet_Main",EINA_COLOR_CYAN);
if(_eet_main_log_dom < -1)
{
EINA_LOG_ERR("Impossible to create a log domain for eet_main.\n");
eet_shutdown();
return(-1);
EINA_LOG_ERR("Impossible to create a log domain for eet_main.\n");
eet_shutdown();
return(-1);
}
if (argc < 2)
{
help:
printf("Usage:\n"
" eet -l FILE.EET list all keys in FILE.EET\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 -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 -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 -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 -r FILE.EET KEY remove KEY in FILE.EET\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;
help:
printf(
"Usage:\n"
" eet -l FILE.EET list all keys in FILE.EET\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 -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 -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 -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 -r FILE.EET KEY remove KEY in FILE.EET\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;
}
if ((!strncmp(argv[1], "-h", 2)))
{
goto help;
}
goto help;
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))
{
if (argc > 5)
do_eet_extract(argv[2], argv[3], argv[4], argv[5]);
else
do_eet_extract(argv[2], argv[3], argv[4], NULL);
do_eet_extract(argv[2], argv[3], argv[4], argv[5]);
else
do_eet_extract(argv[2], argv[3], argv[4], NULL);
}
else if ((!strcmp(argv[1], "-d")) && (argc > 4))
{
if (argc > 5)
do_eet_decode(argv[2], argv[3], argv[4], argv[5]);
else
do_eet_decode(argv[2], argv[3], argv[4], NULL);
do_eet_decode(argv[2], argv[3], argv[4], argv[5]);
else
do_eet_decode(argv[2], argv[3], argv[4], NULL);
}
else if ((!strcmp(argv[1], "-i")) && (argc > 5))
{
if (argc > 6)
do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
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]), argv[6]);
else
do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
}
else if ((!strcmp(argv[1], "-e")) && (argc > 5))
{
if (argc > 6)
do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
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]), argv[6]);
else
do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
}
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))
{
do_eet_check(argv[2]);
}
do_eet_check(argv[2]);
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
{
goto help;
}
goto help;
eina_log_domain_unregister(_eet_main_log_dom);
eet_shutdown();
return 0;

View File

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

View File

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

View File

@ -11,7 +11,8 @@
// will be automatically handled. The other members will have their
// space reserved and zeroed (as it uses calloc()), but not
// saved or loaded from eet files.
typedef struct {
typedef struct
{
unsigned int version; // it is recommended to use versioned configuration!
const char *name;
int id;
@ -52,13 +53,13 @@ _my_conf_descriptor_init(void)
// Describe the members to be saved:
// Use a temporary macro so we don't type a lot, also avoid errors:
#define MY_CONF_ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_conf_descriptor, My_Conf_Type, #member, member, eet_type)
#define MY_CONF_ADD_BASIC(member, eet_type) \
EET_DATA_DESCRIPTOR_ADD_BASIC \
(_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
MY_CONF_ADD_BASIC(version, EET_T_UINT);
MY_CONF_ADD_BASIC(name, EET_T_STRING);
MY_CONF_ADD_BASIC(id, EET_T_INT);
MY_CONF_ADD_BASIC(name, EET_T_STRING);
MY_CONF_ADD_BASIC(id, EET_T_INT);
MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR);
#undef MY_CONF_ADD_BASIC
@ -76,8 +77,8 @@ _my_conf_new(void)
My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type));
if (!my_conf)
{
fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n");
return NULL;
fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n");
return NULL;
}
my_conf->version = 0x112233;
@ -99,25 +100,25 @@ _my_conf_load(const char *filename)
Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
if (!ef)
{
fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
return NULL;
fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
return NULL;
}
my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY);
if (!my_conf)
goto end;
goto end;
if (my_conf->version < 0x112233)
{
fprintf(stderr,
"WARNING: version %#x was too old, upgrading it to %#x\n",
my_conf->version, 0x112233);
fprintf(stderr,
"WARNING: version %#x was too old, upgrading it to %#x\n",
my_conf->version, 0x112233);
my_conf->version = 0x112233;
my_conf->enabled = EINA_TRUE;
my_conf->version = 0x112233;
my_conf->enabled = EINA_TRUE;
}
end:
end:
eet_close(ef);
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));
if (len + 12 >= (int)sizeof(tmp))
{
fprintf(stderr, "ERROR: file name is too big: %s\n", filename);
return EINA_FALSE;
fprintf(stderr, "ERROR: file name is too big: %s\n", filename);
return EINA_FALSE;
}
i = 0;
do
{
snprintf(tmp + len, 12, ".%u", i);
i++;
snprintf(tmp + len, 12, ".%u", i);
i++;
}
while (stat(tmp, &st) == 0);
ef = eet_open(tmp, EET_FILE_MODE_WRITE);
if (!ef)
{
fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp);
return EINA_FALSE;
fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp);
return EINA_FALSE;
}
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);
if (ret)
{
unlink(filename);
rename(tmp, filename);
unlink(filename);
rename(tmp, filename);
}
return ret;
@ -173,8 +174,8 @@ int main(int argc, char *argv[])
if (argc != 3)
{
fprintf(stderr, "Usage:\n\t%s <input> <output>\n\n", argv[0]);
return -1;
fprintf(stderr, "Usage:\n\t%s <input> <output>\n\n", argv[0]);
return -1;
}
eina_init();
@ -184,31 +185,31 @@ int main(int argc, char *argv[])
my_conf = _my_conf_load(argv[1]);
if (!my_conf)
{
printf("creating new configuration.\n");
my_conf = _my_conf_new();
if (!my_conf)
{
ret = -2;
goto end;
}
printf("creating new configuration.\n");
my_conf = _my_conf_new();
if (!my_conf)
{
ret = -2;
goto end;
}
}
printf("My_Conf_Type:\n"
"\tversion: %#x\n"
"\tname...: '%s'\n"
"\tid.....: %d\n"
"\tenabled: %hhu\n",
my_conf->version,
my_conf->name ? my_conf->name : "",
my_conf->id,
my_conf->enabled);
printf("My_Conf_Type:\n"
"\tversion: %#x\n"
"\tname...: '%s'\n"
"\tid.....: %d\n"
"\tenabled: %hhu\n",
my_conf->version,
my_conf->name ? my_conf->name : "",
my_conf->id,
my_conf->enabled);
if (!_my_conf_save(my_conf, argv[2]))
ret = -3;
ret = -3;
_my_conf_free(my_conf);
end:
end:
_my_conf_descriptor_shutdown();
eet_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
{
EET_D_NOT_CONVERTED = 0,
EET_D_FLOAT = 1 << 1,
EET_D_DOUBLE = 1 << 2,
EET_D_FIXED_POINT = 1 << 4
EET_D_NOT_CONVERTED = 0,
EET_D_FLOAT = 1 << 1,
EET_D_DOUBLE = 1 << 2,
EET_D_FIXED_POINT = 1 << 4
};
typedef struct _Eet_String Eet_String;
typedef struct _Eet_String Eet_String;
struct _Eet_String
{
const char *mmap;
char *str;
const char *mmap;
char *str;
int hash;
int len;
int hash;
int len;
int next;
int prev;
int next;
int prev;
float f;
double d;
Eina_F32p32 fp;
float f;
double d;
Eina_F32p32 fp;
Eet_Convert_Type type;
Eet_Convert_Type type;
};
struct _Eet_Dictionary
{
Eet_String *all;
Eet_String *all;
int size;
int offset;
int size;
int offset;
int hash[256];
int hash[256];
int count;
int total;
int count;
int total;
const char *start;
const char *end;
const char *start;
const char *end;
};
struct _Eet_Node
{
int type;
int count;
int type;
int count;
const char *name;
const char *key;
Eet_Node *values;
Eet_Node *next;
Eet_Node *parent;
Eet_Node *values;
Eet_Node *next;
Eet_Node *parent;
Eet_Node_Data data;
};
@ -99,44 +99,69 @@ extern int _eet_log_dom_global;
#endif
#define CRIT(...) EINA_LOG_DOM_CRIT(_eet_log_dom_global, __VA_ARGS__)
Eet_Dictionary *eet_dictionary_add(void);
void eet_dictionary_free(Eet_Dictionary *ed);
int eet_dictionary_string_add(Eet_Dictionary *ed, const char *string);
int eet_dictionary_string_get_size(const Eet_Dictionary *ed, int index);
const char *eet_dictionary_string_get_char(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);
Eet_Dictionary *eet_dictionary_add(void);
void eet_dictionary_free(Eet_Dictionary *ed);
int eet_dictionary_string_add(Eet_Dictionary *ed,
const char *string);
int eet_dictionary_string_get_size(const Eet_Dictionary *ed,
int index);
const char * eet_dictionary_string_get_char(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,
void **sha1, int *sha1_length,
const void *signature_base, unsigned int signature_length,
const void **raw_signature_base, unsigned int *raw_signature_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);
const void * eet_identity_check(const void *data_base,
unsigned int data_length,
void **sha1,
int *sha1_length,
const void *signature_base,
unsigned int signature_length,
const void **raw_signature_base,
unsigned int *raw_signature_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);
void eet_identity_unref(Eet_Key *key);
void eet_identity_ref(Eet_Key *key);
void eet_identity_unref(Eet_Key *key);
void eet_identity_ref(Eet_Key *key);
void eet_node_shutdown(void);
int eet_node_init(void);
void eet_node_shutdown(void);
int eet_node_init(void);
Eet_Node *eet_node_new(void);
void eet_node_free(Eet_Node *node);
void eet_node_free(Eet_Node *node);
#ifndef PATH_MAX
# define PATH_MAX 4096
#endif
#ifdef DNDEBUG
# define EET_ASSERT(Test, Do) if (Test == 0) Do;
# define EET_ASSERT(Test, Do) if (Test == 0) {Do; }
#else
# define EET_ASSERT(Test, Do) if (Test == 0) abort();
# define EET_ASSERT(Test, Do) if (Test == 0) {abort(); }
#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
typedef struct _Eet_Message Eet_Message;
struct _Eet_Message {
struct _Eet_Message
{
int magic;
int size;
};
@ -62,21 +63,21 @@ struct _Eet_Connection
EAPI Eet_Connection *
eet_connection_new(Eet_Read_Cb *eet_read_cb,
Eet_Write_Cb *eet_write_cb,
const void *user_data)
Eet_Write_Cb *eet_write_cb,
const void *user_data)
{
Eet_Connection *conn;
if (!eet_read_cb || !eet_write_cb)
return NULL;
return NULL;
conn = calloc(1, sizeof (Eet_Connection));
if (!conn)
return NULL;
return NULL;
conn->eet_read_cb = eet_read_cb;
conn->eet_write_cb = eet_write_cb;
conn->user_data = (void*) user_data;
conn->user_data = (void *)user_data;
return conn;
}
@ -85,83 +86,85 @@ EAPI int
eet_connection_received(Eet_Connection *conn, const void *data, size_t size)
{
if (!conn || !data || !size)
return size;
return size;
do {
size_t copy_size;
size_t copy_size;
if (conn->size == 0)
{
const Eet_Message *msg;
size_t packet_size;
if (conn->size == 0)
{
const Eet_Message *msg;
size_t packet_size;
if (size < sizeof (Eet_Message))
break;
if (size < sizeof (Eet_Message))
break;
msg = data;
/* Check the magic */
if (ntohl(msg->magic) != MAGIC_EET_DATA_PACKET)
break;
msg = data;
/* Check the magic */
if (ntohl(msg->magic) != MAGIC_EET_DATA_PACKET)
break;
packet_size = ntohl(msg->size);
/* Message should always be under 64K */
if (packet_size > 64 * 1024)
break;
packet_size = ntohl(msg->size);
/* Message should always be under 64K */
if (packet_size > 64 * 1024)
break;
data = (void*) (msg + 1);
size -= sizeof (msg);
if ((size_t) packet_size <= size)
{
/* Not a partial receive, go the quick way. */
if (!conn->eet_read_cb(data, packet_size, conn->user_data))
break;
data = (void *)(msg + 1);
size -= sizeof (msg);
if ((size_t)packet_size <= size)
{
/* Not a partial receive, go the quick way. */
if (!conn->eet_read_cb(data, packet_size, conn->user_data))
break;
data = (void*) ((char *) data + packet_size);
size -= packet_size;
data = (void *)((char *)data + packet_size);
size -= packet_size;
conn->received = 0;
continue;
}
conn->received = 0;
continue;
}
conn->size = packet_size;
if (conn->allocated < conn->size)
{
void *tmp;
conn->size = packet_size;
if (conn->allocated < conn->size)
{
void *tmp;
tmp = realloc(conn->buffer, conn->size);
if (!tmp)
break;
tmp = realloc(conn->buffer, conn->size);
if (!tmp)
break;
conn->buffer = tmp;
conn->allocated = conn->size;
}
}
conn->buffer = tmp;
conn->allocated = conn->size;
}
}
/* Partial receive */
copy_size = (conn->size - conn->received >= size) ? size : conn->size - conn->received;
memcpy((char*) conn->buffer + conn->received, data, copy_size);
/* Partial receive */
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;
data = (void*)((char *) data + copy_size);
size -= copy_size;
conn->received += copy_size;
data = (void *)((char *)data + copy_size);
size -= copy_size;
if (conn->received == conn->size)
{
size_t data_size;
if (conn->received == conn->size)
{
size_t data_size;
data_size = conn->size;
conn->size = 0;
conn->received = 0;
data_size = conn->size;
conn->size = 0;
conn->received = 0;
/* Completed a packet. */
if (!conn->eet_read_cb(conn->buffer, data_size, conn->user_data))
{
/* Something goes wrong. Stop now. */
size += data_size;
break;
}
}
} while (size > 0);
/* Completed a packet. */
if (!conn->eet_read_cb(conn->buffer, data_size, conn->user_data))
{
/* Something goes wrong. Stop now. */
size += data_size;
break;
}
}
} while (size > 0);
return size;
}
@ -173,38 +176,48 @@ _eet_connection_raw_send(Eet_Connection *conn, void *data, int data_size)
/* Message should never be above 64K */
if (data_size > 64 * 1024)
return EINA_FALSE;
return EINA_FALSE;
message = alloca(data_size + sizeof (Eet_Message));
message->magic = htonl(MAGIC_EET_DATA_PACKET);
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;
}
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;
int data_size;
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)
return EINA_FALSE;
return EINA_FALSE;
if (_eet_connection_raw_send(conn, flat_data, data_size))
ret = EINA_TRUE;
ret = EINA_TRUE;
free(flat_data);
return ret;
}
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;
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);
if (!data)
return EINA_FALSE;
return EINA_FALSE;
if (_eet_connection_raw_send(conn, data, data_size))
ret = EINA_TRUE;
ret = EINA_TRUE;
free(data);
return ret;
@ -227,10 +240,10 @@ eet_connection_close(Eet_Connection *conn, Eina_Bool *on_going)
void *user_data;
if (!conn)
return NULL;
return NULL;
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;

File diff suppressed because it is too large Load Diff

View File

@ -18,11 +18,11 @@
Eet_Dictionary *
eet_dictionary_add(void)
{
Eet_Dictionary *new;
Eet_Dictionary *new;
new = calloc(1, sizeof (Eet_Dictionary));
if (!new)
return NULL;
return NULL;
memset(new->hash, -1, sizeof (int) * 256);
@ -34,43 +34,43 @@ eet_dictionary_free(Eet_Dictionary *ed)
{
if (ed)
{
int i;
int i;
for (i = 0; i < ed->count; ++i)
if (ed->all[i].str)
free(ed->all[i].str);
if (ed->all) free(ed->all);
free(ed);
if (ed->all[i].str)
free(ed->all[i].str);
if (ed->all)
free(ed->all);
free(ed);
}
}
static int
_eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int hash)
{
int prev = -1;
int current;
int prev = -1;
int current;
current = ed->hash[hash];
while (current != -1)
{
if (ed->all[current].str)
{
if (strcmp(ed->all[current].str, string) >= 0)
break ;
}
if (strcmp(ed->all[current].str, string) >= 0)
break;
if (ed->all[current].mmap)
{
if (strcmp(ed->all[current].mmap, string) >= 0)
break ;
}
if (strcmp(ed->all[current].mmap, string) >= 0)
break;
prev = current;
current = ed->all[current].next;
}
if (current == -1)
return prev;
return prev;
return current;
}
@ -78,14 +78,14 @@ _eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int hash)
int
eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
{
Eet_String *current;
char *str;
int hash;
int idx;
int len;
Eet_String *current;
char *str;
int hash;
int idx;
int len;
if (!ed)
return -1;
return -1;
hash = _eet_hash_gen(string, 8);
@ -94,27 +94,25 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
if (idx != -1)
{
if (ed->all[idx].str)
{
if (strcmp(ed->all[idx].str, string) == 0)
return idx;
}
if (strcmp(ed->all[idx].str, string) == 0)
return idx;
if (ed->all[idx].mmap)
{
if (strcmp(ed->all[idx].mmap, string) == 0)
return idx;
}
if (strcmp(ed->all[idx].mmap, string) == 0)
return idx;
}
if (ed->total == ed->count)
{
Eet_String *new;
int total;
Eet_String *new;
int total;
total = ed->total + 8;
new = realloc(ed->all, sizeof (Eet_String) * total);
if (new == NULL)
return -1;
return -1;
ed->all = new;
ed->total = total;
@ -123,7 +121,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
len = strlen(string) + 1;
str = strdup(string);
if (str == NULL)
return -1;
return -1;
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;
if (current->next != -1)
ed->all[current->next].prev = ed->count;
ed->all[current->next].prev = ed->count;
if (current->prev != -1)
ed->all[current->prev].next = ed->count;
ed->all[current->prev].next = ed->count;
else
ed->hash[hash] = ed->count;
ed->hash[hash] = ed->count;
}
return ed->count++;
@ -160,48 +159,68 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
int
eet_dictionary_string_get_size(const Eet_Dictionary *ed, int idx)
{
if (!ed) return 0;
if (idx < 0) return 0;
if (!ed)
return 0;
if (idx < 0)
return 0;
if (idx < ed->count)
return ed->all[idx].len;
return ed->all[idx].len;
return 0;
}
int
eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int idx)
{
if (!ed) return -1;
if (idx < 0) return -1;
if (!ed)
return -1;
if (idx < 0)
return -1;
if (idx < ed->count)
return ed->all[idx].hash;
return ed->all[idx].hash;
return -1;
}
const char *
eet_dictionary_string_get_char(const Eet_Dictionary *ed, int idx)
{
if (!ed) return NULL;
if (idx < 0) return NULL;
if (!ed)
return NULL;
if (idx < 0)
return NULL;
if (idx < ed->count)
{
#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. */
if (ed->all[idx].str == NULL)
{
ed->all[idx].str = strdup(ed->all[idx].mmap);
ed->all[idx].mmap = NULL;
}
/* 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)
{
ed->all[idx].str = strdup(ed->all[idx].mmap);
ed->all[idx].mmap = NULL;
}
#else
if (ed->all[idx].mmap)
return ed->all[idx].mmap;
return ed->all[idx].mmap;
#endif
return ed->all[idx].str;
}
return NULL;
}
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'))
{
@ -210,74 +229,94 @@ _eet_dictionary_string_get_me_cache(const char *s, int len, int *mantisse, int *
return EINA_TRUE;
}
return EINA_FALSE;
}
static inline Eina_Bool
_eet_dictionary_string_get_float_cache(const char *s, int len, float *result)
{
int mantisse;
int exponent;
int mantisse;
int exponent;
if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
{
if (s[4] == '+') *result = (float) (mantisse << exponent);
else *result = (float) mantisse / (float) (1 << exponent);
if (s[4] == '+')
*result = (float)(mantisse << exponent);
else
*result = (float)mantisse / (float)(1 << exponent);
return EINA_TRUE;
}
return EINA_FALSE;
}
static inline Eina_Bool
_eet_dictionary_string_get_double_cache(const char *s, int len, double *result)
{
int mantisse;
int exponent;
int mantisse;
int exponent;
if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
{
if (s[4] == '+') *result = (double) (mantisse << exponent);
else *result = (double) mantisse / (float) (1 << exponent);
if (s[4] == '+')
*result = (double)(mantisse << exponent);
else
*result = (double)mantisse / (float)(1 << exponent);
return EINA_TRUE;
}
return EINA_FALSE;
}
static inline Eina_Bool
_eet_dictionary_test(const Eet_Dictionary *ed, int idx, void *result)
{
if (!result) return EINA_FALSE;
if (!ed) return EINA_FALSE;
if (idx < 0) return EINA_FALSE;
if (!(idx < ed->count)) return EINA_FALSE;
if (!result)
return EINA_FALSE;
if (!ed)
return EINA_FALSE;
if (idx < 0)
return EINA_FALSE;
if (!(idx < ed->count))
return EINA_FALSE;
return EINA_TRUE;
}
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))
{
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))
{
long long mantisse = 0;
long exponent = 0;
if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
&ed->all[idx].f))
{
long long mantisse = 0;
long exponent = 0;
if (eina_convert_atod(str, ed->all[idx].len, &mantisse, &exponent) == EINA_FALSE)
return EINA_FALSE;
if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
&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;
@ -285,28 +324,33 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed, int idx, float *result
}
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))
{
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))
{
long long mantisse = 0;
long exponent = 0;
if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
&ed->all[idx].d))
{
long long mantisse = 0;
long exponent = 0;
if (eina_convert_atod(str, ed->all[idx].len, &mantisse, &exponent) == EINA_FALSE)
return EINA_FALSE;
if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
&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;
@ -314,22 +358,25 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed, int idx, double *resu
}
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))
{
const char *str;
Eina_F32p32 fp;
const char *str;
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))
return EINA_FALSE;
if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
return EINA_FALSE;
ed->all[idx].fp = fp;
ed->all[idx].type |= EET_D_FIXED_POINT;
ed->all[idx].fp = fp;
ed->all[idx].type |= EET_D_FIXED_POINT;
}
*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
eet_dictionary_string_check(Eet_Dictionary *ed, const char *string)
{
int i;
int i;
if (ed == NULL
|| string == NULL)
return 0;
return 0;
if (ed->start <= string
&& string < ed->end)
return 1;
return 1;
for (i = 0; i < ed->count; ++i)
if (ed->all[i].str == string)
return 1;
if (ed->all[i].str == string)
return 1;
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));
if (!result)
return NULL;
return NULL;
memset(result, 0, sizeof (Eet_Node));
return result;
@ -45,7 +45,8 @@ _eet_node_new(const char *name, int type)
Eet_Node *n;
n = eet_node_new();
if (!n) return NULL;
if (!n)
return NULL;
n->type = type;
n->name = eina_stringshare_add(name);
@ -60,51 +61,51 @@ _eet_node_append(Eet_Node *n, Eina_List *nodes)
Eina_List *l;
EINA_LIST_REVERSE_FOREACH(nodes, l, value)
{
value->next = n->values;
n->values = value;
}
{
value->next = n->values;
n->values = value;
}
}
#define EET_NODE_NEW(Eet_type, Name, Value, Type) \
EAPI Eet_Node * \
eet_node_##Name##_new(const char *name, Type Value) \
{ \
Eet_Node *n; \
\
n = _eet_node_new(name, Eet_type); \
if (!n) return NULL; \
\
n->data.value.Value = Value; \
\
return n; \
}
#define EET_NODE_NEW(Eet_type, Name, Value, Type) \
EAPI Eet_Node * \
eet_node_ ## Name ## _new(const char *name, Type Value) \
{ \
Eet_Node *n; \
\
n = _eet_node_new(name, Eet_type); \
if (!n) { return NULL; } \
\
n->data.value.Value = Value; \
\
return n; \
}
#define EET_NODE_STR_NEW(Eet_type, Name, Value, Type) \
EAPI Eet_Node * \
eet_node_##Name##_new(const char *name, Type Value) \
{ \
Eet_Node *n; \
\
n = _eet_node_new(name, Eet_type); \
if (!n) return NULL; \
\
n->data.value.Value = eina_stringshare_add(Value); \
\
return n; \
}
#define EET_NODE_STR_NEW(Eet_type, Name, Value, Type) \
EAPI Eet_Node * \
eet_node_ ## Name ## _new(const char *name, Type Value) \
{ \
Eet_Node *n; \
\
n = _eet_node_new(name, Eet_type); \
if (!n) { return NULL; } \
\
n->data.value.Value = eina_stringshare_add(Value); \
\
return n; \
}
EET_NODE_NEW(EET_T_CHAR, char, c, char)
EET_NODE_NEW(EET_T_SHORT, short, s, short)
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_FLOAT, float, f, float)
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_USHORT, unsigned_short, us, unsigned short)
EET_NODE_NEW(EET_T_UINT, unsigned_int, ui, unsigned int)
EET_NODE_NEW(EET_T_CHAR, char, c, char)
EET_NODE_NEW(EET_T_SHORT, short, s, short)
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_FLOAT, float, f, float)
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_USHORT, unsigned_short, us, unsigned short)
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_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 *
@ -113,7 +114,8 @@ eet_node_null_new(const char *name)
Eet_Node *n;
n = _eet_node_new(name, EET_T_NULL);
if (!n) return NULL;
if (!n)
return NULL;
n->data.value.str = NULL;
@ -126,7 +128,8 @@ eet_node_list_new(const char *name, Eina_List *nodes)
Eet_Node *n;
n = _eet_node_new(name, EET_G_LIST);
if (!n) return NULL;
if (!n)
return NULL;
_eet_node_append(n, nodes);
@ -139,7 +142,8 @@ eet_node_array_new(const char *name, int count, Eina_List *nodes)
Eet_Node *n;
n = _eet_node_new(name, EET_G_ARRAY);
if (!n) return NULL;
if (!n)
return NULL;
n->count = count;
@ -154,7 +158,8 @@ eet_node_var_array_new(const char *name, Eina_List *nodes)
Eet_Node *n;
n = _eet_node_new(name, EET_G_VAR_ARRAY);
if (!n) return NULL;
if (!n)
return NULL;
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;
Eet_Node *n;
if (!node) return NULL;
if (!node)
return NULL;
n = _eet_node_new(name, EET_G_HASH);
if (!n) return NULL;
if (!n)
return NULL;
n->key = eina_stringshare_add(key);
nodes = eina_list_append(NULL, node);
@ -188,7 +195,8 @@ eet_node_struct_new(const char *name, Eina_List *nodes)
Eet_Node *n;
n = _eet_node_new(name, EET_G_UNKNOWN);
if (!n) return NULL;
if (!n)
return NULL;
_eet_node_append(n, nodes);
@ -201,10 +209,11 @@ eet_node_struct_child_new(const char *parent, Eet_Node *child)
Eet_Node *n;
if (child->type != EET_G_UNKNOWN)
return child;
return child;
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));
@ -220,23 +229,25 @@ eet_node_list_append(Eet_Node *parent, const char *name, Eet_Node *child)
tmp = eina_stringshare_add(name);
for (nn = parent->values; nn; nn = nn->next)
if (nn->name == tmp && nn->type == EET_G_LIST)
{
Eet_Node *n;
if (nn->name == tmp && nn->type == EET_G_LIST)
{
Eet_Node *n;
if (!nn->values) nn->values = child;
else
{
for (n = nn->values; n->next; n = n->next)
;
n->next = child;
}
child->next = NULL;
if (!nn->values)
nn->values = child;
else
{
for (n = nn->values; n->next; n = n->next)
;
n->next = child;
}
eina_stringshare_del(tmp);
child->next = NULL;
return ;
}
eina_stringshare_del(tmp);
return;
}
/* No list found, so create it. */
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;
parent->values = nn;
eina_stringshare_del(tmp);
eina_stringshare_del(tmp);
}
void
@ -257,41 +268,48 @@ eet_node_struct_append(Eet_Node *parent, const char *name, Eet_Node *child)
if (parent->type != EET_G_UNKNOWN)
{
ERR("[%s] is not a structure. Will not insert [%s] in it", parent->name, name);
eet_node_del(child);
return ;
ERR("[%s] is not a structure. Will not insert [%s] in it",
parent->name,
name);
eet_node_del(child);
return;
}
tmp = eina_stringshare_add(name);
for (prev = NULL, nn = parent->values; nn; prev = nn, nn = nn->next)
if (nn->name == tmp && nn->type == child->type)
{
if (prev) prev->next = nn->next;
else parent->values = nn->next;
if (nn->name == tmp && nn->type == child->type)
{
if (prev)
prev->next = nn->next;
else
parent->values = nn->next;
nn->next = NULL;
eet_node_del(nn);
nn->next = NULL;
eet_node_del(nn);
break;
}
break;
}
if (prev)
{
prev->next = child;
child->next = NULL;
prev->next = child;
child->next = NULL;
}
else
{
child->next = NULL;
parent->values = child;
child->next = NULL;
parent->values = child;
}
eina_stringshare_del(tmp);
eina_stringshare_del(tmp);
}
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;
@ -309,27 +327,31 @@ eet_node_del(Eet_Node *n)
Eet_Node *nn;
Eet_Node *tmp;
if (!n) return ;
if (!n)
return;
switch (n->type)
{
case EET_G_HASH:
eina_stringshare_del(n->key);
eina_stringshare_del(n->key);
case EET_G_UNKNOWN:
case EET_G_VAR_ARRAY:
case EET_G_ARRAY:
case EET_G_LIST:
for (nn = n->values; nn; )
{
tmp = nn;
nn = nn->next;
eet_node_del(tmp);
}
break;
for (nn = n->values; nn; )
{
tmp = nn;
nn = nn->next;
eet_node_del(tmp);
}
break;
case EET_T_STRING:
case EET_T_INLINED_STRING:
eina_stringshare_del(n->data.value.str);
break;
eina_stringshare_del(n->data.value.str);
break;
case EET_T_CHAR:
case EET_T_SHORT:
case EET_T_INT:
@ -339,39 +361,41 @@ eet_node_del(Eet_Node *n)
case EET_T_UCHAR:
case EET_T_USHORT:
case EET_T_UINT:
break;
break;
}
eina_stringshare_del(n->name);
eet_node_free(n);
eina_stringshare_del(n->name);
eet_node_free(n);
}
static const char *eet_node_dump_g_name[6] = {
"struct",
"array",
"var_array",
"list",
"hash",
"???"
"struct",
"array",
"var_array",
"list",
"hash",
"???"
};
static const char *eet_node_dump_t_name[14][2] = {
{ "???: ", "???" },
{ "char: ", "%hhi" },
{ "short: ", "%hi" },
{ "int: ", "%i" },
{ "long_long: ", "%lli" },
{ "float: ", "%1.25f" },
{ "double: ", "%1.25f" },
{ "uchar: ", "%hhu" },
{ "ushort: ", "%i" },
{ "uint: ", "%u" },
{ "ulong_long: ", "%llu" },
{ "null", "" }
{ "???: ", "???" },
{ "char: ", "%hhi" },
{ "short: ", "%hi" },
{ "int: ", "%i" },
{ "long_long: ", "%lli" },
{ "float: ", "%1.25f" },
{ "double: ", "%1.25f" },
{ "uchar: ", "%hhu" },
{ "ushort: ", "%i" },
{ "uint: ", "%u" },
{ "ulong_long: ", "%llu" },
{ "null", "" }
};
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;
@ -387,36 +411,48 @@ eet_node_string_escape(const char *str)
for (strp = str; *strp; strp++)
{
if (*strp == '\"') sz += 2;
else if (*strp == '\\') sz += 2;
else if (*strp == '\n') sz += 2;
else sz += 1;
if (*strp == '\"')
sz += 2;
else if (*strp == '\\')
sz += 2;
else if (*strp == '\n')
sz += 2;
else
sz += 1;
}
s = malloc(sz + 1);
if (!s) return NULL;
if (!s)
return NULL;
for (strp = str, sp = s; *strp; strp++, sp++)
{
if (*strp == '\"'
|| *strp == '\\'
|| *strp == '\n')
{
*sp = '\\';
sp++;
}
if (*strp == '\n') *sp = 'n';
else *sp = *strp;
if (*strp == '\"'
|| *strp == '\\'
|| *strp == '\n')
{
*sp = '\\';
sp++;
}
if (*strp == '\n')
*sp = 'n';
else
*sp = *strp;
}
*sp = 0;
return s;
}
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;
s = eet_node_string_escape(str);
if (!s) return ;
if (!s)
return;
dumpfunc(dumpdata, s);
free(s);
@ -424,7 +460,8 @@ eet_node_dump_string_escape(void *dumpdata, void dumpfunc(void *data, const char
static void
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;
char tbuf[256];
@ -432,84 +469,99 @@ eet_node_dump_simple_type(Eet_Node *n, int level,
eet_node_dump_level(level, dumpfunc, dumpdata);
dumpfunc(dumpdata, "value \"");
eet_node_dump_string_escape(dumpdata, dumpfunc, n->name);
dumpfunc(dumpdata, "\" ");
dumpfunc(dumpdata, "\" ");
#ifdef EET_T_TYPE
# undef EET_T_TYPE
#endif
#define EET_T_TYPE(Eet_Type, Type) \
case Eet_Type: \
{ \
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); \
dumpfunc(dumpdata, tbuf); \
break; \
}
#define EET_T_TYPE(Eet_Type, Type) \
case Eet_Type: \
{ \
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); \
dumpfunc(dumpdata, tbuf); \
break; \
}
switch (n->type)
{
EET_T_TYPE(EET_T_CHAR, c);
EET_T_TYPE(EET_T_SHORT, s);
EET_T_TYPE(EET_T_INT, i);
EET_T_TYPE(EET_T_LONG_LONG, l);
EET_T_TYPE(EET_T_FLOAT, f);
EET_T_TYPE(EET_T_DOUBLE, d);
EET_T_TYPE(EET_T_UCHAR, uc);
EET_T_TYPE(EET_T_USHORT, us);
EET_T_TYPE(EET_T_UINT, ui);
EET_T_TYPE(EET_T_ULONG_LONG, ul);
case EET_T_INLINED_STRING:
type_name = "inlined: \"";
case EET_T_STRING:
if (!type_name) type_name = "string: \"";
EET_T_TYPE(EET_T_CHAR, c);
EET_T_TYPE(EET_T_SHORT, s);
EET_T_TYPE(EET_T_INT, i);
EET_T_TYPE(EET_T_LONG_LONG, l);
EET_T_TYPE(EET_T_FLOAT, f);
EET_T_TYPE(EET_T_DOUBLE, d);
EET_T_TYPE(EET_T_UCHAR, uc);
EET_T_TYPE(EET_T_USHORT, us);
EET_T_TYPE(EET_T_UINT, ui);
EET_T_TYPE(EET_T_ULONG_LONG, ul);
case EET_T_INLINED_STRING:
type_name = "inlined: \"";
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:
dumpfunc(dumpdata, "null");
break;
dumpfunc(dumpdata, "null");
break;
default:
dumpfunc(dumpdata, "???: ???");
break;
dumpfunc(dumpdata, "???: ???");
break;
}
dumpfunc(dumpdata, ";\n");
dumpfunc(dumpdata, ";\n");
}
static void
eet_node_dump_group_start(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
int group_type, const char *name)
eet_node_dump_group_start(int level, void (*dumpfunc)(void *data,
const char *str),
void *dumpdata,
int group_type, const char *name)
{
int chnk_type;
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);
dumpfunc(dumpdata, "group \"");
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, " {\n");
dumpfunc(dumpdata, " {\n");
}
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);
dumpfunc(dumpdata, "}\n");
}
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;
if (!n) return ;
if (!n)
return;
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_HASH:
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
|| n->type == EET_G_ARRAY)
{
char tbuf[256];
if (n->type == EET_G_VAR_ARRAY
|| n->type == EET_G_ARRAY)
{
char tbuf[256];
eet_node_dump_level(dumplevel, dumpfunc, dumpdata);
dumpfunc(dumpdata, " count ");
eina_convert_itoa(n->count, tbuf);
dumpfunc(dumpdata, tbuf);
dumpfunc(dumpdata, ";\n");
}
else if (n->type == EET_G_HASH)
{
eet_node_dump_level(dumplevel, dumpfunc, dumpdata);
dumpfunc(dumpdata, " key \"");
eet_node_dump_string_escape(dumpdata, dumpfunc, n->key);
dumpfunc(dumpdata, "\";\n");
}
eet_node_dump_level(dumplevel, dumpfunc, dumpdata);
dumpfunc(dumpdata, " count ");
eina_convert_itoa(n->count, tbuf);
dumpfunc(dumpdata, tbuf);
dumpfunc(dumpdata, ";\n");
}
else if (n->type == EET_G_HASH)
{
eet_node_dump_level(dumplevel, dumpfunc, dumpdata);
dumpfunc(dumpdata, " key \"");
eet_node_dump_string_escape(dumpdata, dumpfunc, n->key);
dumpfunc(dumpdata, "\";\n");
}
for (it = n->values; it != NULL; it = it->next)
eet_node_dump(it, dumplevel + 2, dumpfunc, dumpdata);
for (it = n->values; it != NULL; it = it->next)
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_INLINED_STRING:
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_UINT:
case EET_T_ULONG_LONG:
eet_node_dump_simple_type(n, dumplevel, dumpfunc, dumpdata);
break;
eet_node_dump_simple_type(n, dumplevel, dumpfunc, dumpdata);
break;
}
}
void*
eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb, void *user_data)
void *
eet_node_walk(void *parent,
const char *name,
Eet_Node *root,
Eet_Node_Walk *cb,
void *user_data)
{
Eet_Node *it;
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 (parent) cb->struct_add(parent, name, NULL, user_data);
return NULL;
if (parent)
cb->struct_add(parent, name, NULL, user_data);
return NULL;
}
switch (root->type)
{
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)
eet_node_walk(me, it->name, it, cb, user_data);
for (it = root->values; it != NULL; it = it->next)
eet_node_walk(me, it->name, it, cb, user_data);
break;
break;
case EET_G_VAR_ARRAY:
case EET_G_ARRAY:
me = cb->array(root->type == EET_G_VAR_ARRAY ? EINA_TRUE : EINA_FALSE,
root->name, root->count, user_data);
me = cb->array(root->type == EET_G_VAR_ARRAY ? EINA_TRUE : EINA_FALSE,
root->name, root->count, user_data);
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);
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);
break;
break;
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)
cb->append(me, eet_node_walk(NULL, NULL, it, cb, user_data), user_data);
for (it = root->values; it != NULL; it = it->next)
cb->append(me, eet_node_walk(NULL,
NULL,
it,
cb,
user_data), user_data);
break;
break;
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_INLINED_STRING:
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_UINT:
case EET_T_ULONG_LONG:
me = cb->simple(root->type, &root->data, user_data);
break;
me = cb->simple(root->type, &root->data, user_data);
break;
}
if (parent) cb->struct_add(parent, name, me, user_data);
if (parent)
cb->struct_add(parent, name, me, user_data);
return me;
}
@ -632,9 +715,10 @@ eet_node_init(void)
choice = "chained_mempool";
tmp = getenv("EET_MEMPOOL");
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;
}

View File

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

View File

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

File diff suppressed because it is too large Load Diff