diff options
author | Carsten Haitzler <raster@rasterman.com> | 2011-10-21 05:40:01 +0000 |
---|---|---|
committer | Carsten Haitzler <raster@rasterman.com> | 2011-10-21 05:40:01 +0000 |
commit | a9fc805e92cdec45e7e3322f4562cf8a2ed32502 (patch) | |
tree | 62e6dd4b7dbeed83c1db00c594ac3aa4949f57c6 /src/examples | |
parent | d32e3400a0bd6f5b4e8490b0c8fcd5ffe6ce5607 (diff) | |
download | eet-a9fc805e92cdec45e7e3322f4562cf8a2ed32502.tar.gz |
ran ecrustify on eet. this seems to do a good job of eet. comments?
SVN revision: 64237
Diffstat (limited to 'src/examples')
-rw-r--r-- | src/examples/eet-basic.c | 53 | ||||
-rw-r--r-- | src/examples/eet-data-cipher_decipher.c | 36 | ||||
-rw-r--r-- | src/examples/eet-data-file_descriptor_01.c | 242 | ||||
-rw-r--r-- | src/examples/eet-data-file_descriptor_02.c | 7 | ||||
-rw-r--r-- | src/examples/eet-data-nested.c | 81 | ||||
-rw-r--r-- | src/examples/eet-data-simple.c | 41 | ||||
-rw-r--r-- | src/examples/eet-file.c | 121 |
7 files changed, 300 insertions, 281 deletions
diff --git a/src/examples/eet-basic.c b/src/examples/eet-basic.c index 390cd71..05ff397 100644 --- a/src/examples/eet-basic.c +++ b/src/examples/eet-basic.c @@ -3,37 +3,38 @@ int main(void) { - Eet_File *ef; - char *ret; - int size; - char *entries[] = - { + Eet_File *ef; + char *ret; + int size; + char *entries[] = + { "Entry 1", "Big text string here compared to others", "Eet is cool" - }; + }; - eet_init(); + eet_init(); - // blindly open an file for output and write strings with their NUL char - ef = eet_open("test.eet", EET_FILE_MODE_WRITE); - eet_write(ef, "Entry 1", entries[0], strlen(entries[0]) + 1, 0); - eet_write(ef, "Entry 2", entries[1], strlen(entries[1]) + 1, 1); - eet_write(ef, "Entry 3", entries[2], strlen(entries[2]) + 1, 0); - eet_close(ef); + // blindly open an file for output and write strings with their NUL char + ef = eet_open("test.eet", EET_FILE_MODE_WRITE); + eet_write(ef, "Entry 1", entries[0], strlen(entries[0]) + 1, 0); + eet_write(ef, "Entry 2", entries[1], strlen(entries[1]) + 1, 1); + eet_write(ef, "Entry 3", entries[2], strlen(entries[2]) + 1, 0); + eet_close(ef); - // open the file again and blindly get the entries we wrote - ef = eet_open("test.eet", EET_FILE_MODE_READ); - ret = eet_read(ef, "Entry 1", &size); - printf("%s\n", ret); - free(ret); - ret = eet_read(ef, "Entry 2", &size); - printf("%s\n", ret); - free(ret); - ret = eet_read(ef, "Entry 3", &size); - printf("%s\n", ret); - free(ret); - eet_close(ef); + // open the file again and blindly get the entries we wrote + ef = eet_open("test.eet", EET_FILE_MODE_READ); + ret = eet_read(ef, "Entry 1", &size); + printf("%s\n", ret); + free(ret); + ret = eet_read(ef, "Entry 2", &size); + printf("%s\n", ret); + free(ret); + ret = eet_read(ef, "Entry 3", &size); + printf("%s\n", ret); + free(ret); + eet_close(ef); - eet_shutdown(); + eet_shutdown(); } + diff --git a/src/examples/eet-data-cipher_decipher.c b/src/examples/eet-data-cipher_decipher.c index 1688e02..2ef965c 100644 --- a/src/examples/eet-data-cipher_decipher.c +++ b/src/examples/eet-data-cipher_decipher.c @@ -27,7 +27,7 @@ main(void) if (!(file = tmpnam(file))) { fprintf( - stderr, "ERROR: could not create temporary file (%s).\n", file); + stderr, "ERROR: could not create temporary file (%s).\n", file); goto panic; } @@ -36,14 +36,14 @@ main(void) if (!ef) { fprintf( - stderr, "ERROR: could not access file (%s).\n", file); + stderr, "ERROR: could not access file (%s).\n", file); goto error; } if (!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0, key)) { fprintf( - stderr, "ERROR: could not access file (%s).\n", file); + stderr, "ERROR: could not access file (%s).\n", file); goto error; } @@ -54,7 +54,7 @@ main(void) if (!ef) { fprintf( - stderr, "ERROR: could not access file (%s).\n", file); + stderr, "ERROR: could not access file (%s).\n", file); goto error; } @@ -62,22 +62,22 @@ main(void) if (!test) { fprintf( - stderr, "ERROR: could decript contents on file %s, with key %s.\n", - file, key); + stderr, "ERROR: could decript contents on file %s, with key %s.\n", + file, key); goto error; } if (size != (int)strlen(buffer) + 1) { fprintf( - stderr, "ERROR: something is wrong with the decripted data\n"); + stderr, "ERROR: something is wrong with the decripted data\n"); goto error; } if (memcmp(test, buffer, strlen(buffer) + 1) != 0) { fprintf( - stderr, "ERROR: something is wrong with the decripted data\n"); + stderr, "ERROR: something is wrong with the decripted data\n"); goto error; } @@ -88,7 +88,7 @@ main(void) if (!ef) { fprintf( - stderr, "ERROR: could not access file (%s).\n", file); + stderr, "ERROR: could not access file (%s).\n", file); goto error; } @@ -96,24 +96,24 @@ main(void) if (size == (int)strlen(buffer) + 1) if (memcmp(test, buffer, strlen(buffer) + 1) == 0) - { - fprintf( + { + fprintf( stderr, "ERROR: something is wrong with the contents of %s, as" - " we accessed it with a different key and it decripted our" - " information right.\n", file); - goto error; - } + " we accessed it with a different key and it decripted our" + " information right.\n", file); + goto error; + } eet_close(ef); - error: +error: if (unlink(file) != 0) { fprintf( - stderr, "ERROR: could not unlink file (%s).\n", file); + stderr, "ERROR: could not unlink file (%s).\n", file); } - panic: +panic: eet_shutdown(); } diff --git a/src/examples/eet-data-file_descriptor_01.c b/src/examples/eet-data-file_descriptor_01.c index ed0f724..4b5b75f 100644 --- a/src/examples/eet-data-file_descriptor_01.c +++ b/src/examples/eet-data-file_descriptor_01.c @@ -82,48 +82,48 @@ _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_message_descriptor); + (_my_account_descriptor, My_Account, "messages", messages, + _my_message_descriptor); EET_DATA_DESCRIPTOR_ADD_VAR_ARRAY - (_my_account_descriptor, My_Account, "posts", posts, - _my_post_descriptor); + (_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_HASH - (_my_cache_descriptor, My_Cache, "accounts", accounts, - _my_account_descriptor); + (_my_cache_descriptor, My_Cache, "accounts", accounts, + _my_account_descriptor); } /* _my_cache_descriptor_init */ static void @@ -138,21 +138,21 @@ _my_cache_descriptor_shutdown(void) // need to check if the pointer came from mmaped area in eet_dictionary // or it was allocated with eina_stringshare_add() static void -_eet_string_free(const char * str) +_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); } /* _eet_string_free */ static My_Message * -_my_message_new(const char * message) +_my_message_new(const char *message) { - My_Message * msg = calloc(1, sizeof(My_Message)); + My_Message *msg = calloc(1, sizeof(My_Message)); if (!msg) { fprintf(stderr, "ERROR: could not calloc My_Message\n"); @@ -164,7 +164,7 @@ _my_message_new(const char * message) } /* _my_message_new */ static void -_my_message_free(My_Message * msg) +_my_message_free(My_Message *msg) { _eet_string_free(msg->screen_name); _eet_string_free(msg->name); @@ -173,7 +173,8 @@ _my_message_free(My_Message * msg) } /* _my_message_free */ static Eina_Bool -_my_post_add(My_Account *acc, const char * message) +_my_post_add(My_Account *acc, + const char *message) { int new_count = acc->posts_count + 1; My_Post *post = realloc(acc->posts, new_count * sizeof(My_Post)); @@ -187,20 +188,20 @@ _my_post_add(My_Account *acc, const char * message) post[acc->posts_count].dm_to = NULL; acc->posts_count = new_count; acc->posts = post; - return EINA_TRUE;; + return EINA_TRUE; } /* _my_post_new */ static void -_my_post_free(My_Post * post) +_my_post_free(My_Post *post) { _eet_string_free(post->dm_to); _eet_string_free(post->message); } /* _my_post_free */ static My_Account * -_my_account_new(const char * name) +_my_account_new(const char *name) { - My_Account * acc = calloc(1, sizeof(My_Account)); + My_Account *acc = calloc(1, sizeof(My_Account)); if (!acc) { fprintf(stderr, "ERROR: could not calloc My_Account\n"); @@ -212,15 +213,15 @@ _my_account_new(const char * name) } /* _my_account_new */ static void -_my_account_free(My_Account * acc) +_my_account_free(My_Account *acc) { - My_Message * m; + My_Message *m; int i; _eet_string_free(acc->name); EINA_LIST_FREE(acc->messages, m) - _my_message_free(m); + _my_message_free(m); for (i = 0; i < acc->posts_count; i++) _my_post_free(&acc->posts[i]); @@ -232,7 +233,7 @@ _my_account_free(My_Account * acc) static My_Cache * _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) { fprintf(stderr, "ERROR: could not calloc My_Cache\n"); @@ -246,32 +247,36 @@ _my_cache_new(void) } /* _my_cache_new */ static Eina_Bool -_my_cache_account_free_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata) +_my_cache_account_free_cb(const Eina_Hash *hash, + const void *key, + void *data, + void *fdata) { _my_account_free(data); return EINA_TRUE; } static void -_my_cache_free(My_Cache * my_cache) +_my_cache_free(My_Cache *my_cache) { - My_Account * acc; + My_Account *acc; eina_hash_foreach(my_cache->accounts, _my_cache_account_free_cb, NULL); eina_hash_free(my_cache->accounts); free(my_cache); } /* _my_cache_free */ static My_Account * -_my_cache_account_find(My_Cache * my_cache, const char * name) +_my_cache_account_find(My_Cache *my_cache, + const char *name) { return eina_hash_find(my_cache->accounts, name); } /* _my_cache_account_find */ static My_Cache * -_my_cache_load(const char * filename) +_my_cache_load(const char *filename) { - My_Cache * my_cache; - Eet_File * ef = eet_open(filename, EET_FILE_MODE_READ); + My_Cache *my_cache; + Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); if (!ef) { fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); @@ -295,7 +300,7 @@ _my_cache_load(const char * filename) } 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); @@ -304,10 +309,11 @@ _my_cache_load(const char * filename) } /* _my_cache_load */ static Eina_Bool -_my_cache_save(const My_Cache * my_cache, const char * filename) +_my_cache_save(const My_Cache *my_cache, + const char *filename) { char tmp[PATH_MAX]; - Eet_File * ef; + Eet_File *ef; Eina_Bool ret; unsigned int i, len; struct stat st; @@ -335,7 +341,7 @@ _my_cache_save(const My_Cache * my_cache, const char * filename) } 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! @@ -356,12 +362,14 @@ _my_cache_save(const My_Cache * my_cache, const char * filename) return ret; } /* _my_cache_save */ -int main(int argc, char * argv[]) +int +main(int argc, + char *argv[]) { - My_Cache * my_cache; - const Eina_List * l_acc; + My_Cache *my_cache; + const Eina_List *l_acc; Eina_Iterator *it; - My_Account * acc; + My_Account *acc; int ret = 0; if (argc < 3) @@ -399,58 +407,58 @@ int main(int argc, char * argv[]) { 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) { acc = _my_account_new(argv[4]); eina_hash_direct_add(my_cache->accounts, acc->name, acc); } else - fprintf(stderr, "ERROR: account '%s' already exists.\n", - argv[4]); + fprintf(stderr, "ERROR: account '%s' already exists.\n", + argv[4]); } else - fprintf(stderr, - "ERROR: wrong number of parameters (%d).\n", - argc); + 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]); + My_Account *acc = _my_cache_account_find(my_cache, argv[4]); if (acc) { _my_post_add(acc, argv[5]); } else - fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); + fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); } else - fprintf(stderr, - "ERROR: wrong number of parameters (%d).\n", - argc); + 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]); + My_Account *acc = _my_cache_account_find(my_cache, argv[4]); if (acc) { - My_Message * msg = _my_message_new(argv[5]); + 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]); + fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); } else - fprintf(stderr, - "ERROR: wrong number of parameters (%d).\n", - argc); + fprintf(stderr, + "ERROR: wrong number of parameters (%d).\n", + argc); } else - fprintf(stderr, "ERROR: unknown action '%s'\n", argv[2]); + fprintf(stderr, "ERROR: unknown action '%s'\n", argv[2]); } printf("My_Cache:\n" @@ -460,52 +468,52 @@ int main(int argc, char * argv[]) eina_hash_population(my_cache->accounts)); it = eina_hash_iterator_data_new(my_cache->accounts); EINA_ITERATOR_FOREACH(it, acc) - { - 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), - acc->posts_count); - - 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 : ""); - } - } - - if (acc->posts_count) - { - const My_Post * post; - int i; - printf("\t |posts:\n"); - - for (i = 0; i < acc->posts_count; i++) - { - post = &acc->posts[i]; - if (post->dm_to) - printf("\t | @%s: '%.20s'\n", post->dm_to, post->message); - else - printf("\t | '%.20s'\n", post->message); - } - } - - printf("\n"); - } + { + 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), + acc->posts_count); + + 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 : ""); + } + } + + if (acc->posts_count) + { + const My_Post *post; + int i; + printf("\t |posts:\n"); + + for (i = 0; i < acc->posts_count; i++) + { + post = &acc->posts[i]; + if (post->dm_to) + printf("\t | @%s: '%.20s'\n", post->dm_to, post->message); + else + printf("\t | '%.20s'\n", post->message); + } + } + + printf("\n"); + } eina_iterator_free(it); if (!_my_cache_save(my_cache, argv[2])) - ret = -3; + ret = -3; _my_cache_free(my_cache); diff --git a/src/examples/eet-data-file_descriptor_02.c b/src/examples/eet-data-file_descriptor_02.c index 9690d6b..65ba79e 100644 --- a/src/examples/eet-data-file_descriptor_02.c +++ b/src/examples/eet-data-file_descriptor_02.c @@ -115,7 +115,9 @@ _st3_set(Example_Struct3 *st3, st3->body = v1; } /* _st3_set */ -static const char * /* union type_get() */ +static const char * +/* union + type_get() */ _union_type_get(const void *data, Eina_Bool *unknow) { @@ -259,7 +261,8 @@ static Eet_Data_Descriptor *_variant_unified_descriptor; static Eet_File *_cache_file = NULL; static Eet_Dictionary *_cache_dict = NULL; -static void /* declaring types */ +static void +/* declaring types */ _data_descriptors_init(void) { Eet_Data_Descriptor_Class eddc; diff --git a/src/examples/eet-data-nested.c b/src/examples/eet-data-nested.c index 882fc24..a6b0e12 100644 --- a/src/examples/eet-data-nested.c +++ b/src/examples/eet-data-nested.c @@ -17,17 +17,17 @@ typedef struct { unsigned int version; // it is recommended to use versioned configuration! - const char * name; + const char *name; int id; int not_saved_value; // example of not saved data inside! Eina_Bool enabled; - Eina_List * subs; + Eina_List *subs; } My_Conf_Type; typedef struct { - const char * server; - int port; + const char *server; + int port; } My_Conf_Subtype; // string that represents the entry in eet file, you might like to have @@ -38,8 +38,8 @@ static const char MY_CONF_FILE_ENTRY[] = "config"; // keep the descriptor static global, so it can be // shared by different functions (load/save) of this and only this // file. -static Eet_Data_Descriptor * _my_conf_descriptor; -static Eet_Data_Descriptor * _my_conf_sub_descriptor; +static Eet_Data_Descriptor *_my_conf_descriptor; +static Eet_Data_Descriptor *_my_conf_sub_descriptor; static void _my_conf_descriptor_init(void) @@ -66,24 +66,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 +99,8 @@ _my_conf_descriptor_shutdown(void) static My_Conf_Type * _my_conf_new(void) { - My_Conf_Type * my_conf = calloc(1, sizeof(My_Conf_Type)); - My_Conf_Subtype * sub; + My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type)); + My_Conf_Subtype *sub; if (!my_conf) { fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n"); @@ -122,24 +122,24 @@ _my_conf_new(void) } /* _my_conf_new */ static void -_my_conf_free(My_Conf_Type * my_conf) +_my_conf_free(My_Conf_Type *my_conf) { - My_Conf_Subtype * sub; + 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); } /* _my_conf_free */ static My_Conf_Type * -_my_conf_load(const char * filename) +_my_conf_load(const char *filename) { - My_Conf_Type * my_conf; - Eet_File * ef = eet_open(filename, EET_FILE_MODE_READ); + My_Conf_Type *my_conf; + Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); if (!ef) { fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); @@ -148,7 +148,7 @@ _my_conf_load(const char * filename) 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) { @@ -166,10 +166,11 @@ end: } /* _my_conf_load */ static Eina_Bool -_my_conf_save(const My_Conf_Type * my_conf, const char * filename) +_my_conf_save(const My_Conf_Type *my_conf, + const char *filename) { char tmp[PATH_MAX]; - Eet_File * ef; + Eet_File *ef; Eina_Bool ret; unsigned int i, len; struct stat st; @@ -197,7 +198,7 @@ _my_conf_save(const My_Conf_Type * my_conf, const char * filename) } 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) @@ -209,11 +210,13 @@ _my_conf_save(const My_Conf_Type * my_conf, const char * filename) return ret; } /* _my_conf_save */ -int main(int argc, char * argv[]) +int +main(int argc, + char *argv[]) { - My_Conf_Type * my_conf; - const My_Conf_Subtype * sub; - const Eina_List * l; + My_Conf_Type *my_conf; + const My_Conf_Subtype *sub; + const Eina_List *l; int ret = 0; if (argc != 3) @@ -250,12 +253,12 @@ int main(int argc, char * argv[]) 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); diff --git a/src/examples/eet-data-simple.c b/src/examples/eet-data-simple.c index 395a8d6..1951fc0 100644 --- a/src/examples/eet-data-simple.c +++ b/src/examples/eet-data-simple.c @@ -17,7 +17,7 @@ typedef struct { unsigned int version; // it is recommended to use versioned configuration! - const char * name; + const char *name; int id; int not_saved_value; // example of not saved data inside! Eina_Bool enabled; @@ -31,7 +31,7 @@ static const char MY_CONF_FILE_ENTRY[] = "config"; // keep the descriptor static global, so it can be // shared by different functions (load/save) of this and only this // file. -static Eet_Data_Descriptor * _my_conf_descriptor; +static Eet_Data_Descriptor *_my_conf_descriptor; static void _my_conf_descriptor_init(void) @@ -55,13 +55,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,7 +76,7 @@ _my_conf_descriptor_shutdown(void) static My_Conf_Type * _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) { fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n"); @@ -89,17 +89,17 @@ _my_conf_new(void) } /* _my_conf_new */ static void -_my_conf_free(My_Conf_Type * my_conf) +_my_conf_free(My_Conf_Type *my_conf) { eina_stringshare_del(my_conf->name); free(my_conf); } /* _my_conf_free */ static My_Conf_Type * -_my_conf_load(const char * filename) +_my_conf_load(const char *filename) { - My_Conf_Type * my_conf; - Eet_File * ef = eet_open(filename, EET_FILE_MODE_READ); + My_Conf_Type *my_conf; + Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); if (!ef) { fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); @@ -108,7 +108,7 @@ _my_conf_load(const char * filename) 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) { @@ -126,10 +126,11 @@ end: } /* _my_conf_load */ static Eina_Bool -_my_conf_save(const My_Conf_Type * my_conf, const char * filename) +_my_conf_save(const My_Conf_Type *my_conf, + const char *filename) { char tmp[PATH_MAX]; - Eet_File * ef; + Eet_File *ef; Eina_Bool ret; unsigned int i, len; struct stat st; @@ -157,7 +158,7 @@ _my_conf_save(const My_Conf_Type * my_conf, const char * filename) } 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) @@ -169,9 +170,11 @@ _my_conf_save(const My_Conf_Type * my_conf, const char * filename) return ret; } /* _my_conf_save */ -int main(int argc, char * argv[]) +int +main(int argc, + char *argv[]) { - My_Conf_Type * my_conf; + My_Conf_Type *my_conf; int ret = 0; if (argc != 3) @@ -207,7 +210,7 @@ int main(int argc, char * argv[]) my_conf->enabled); if (!_my_conf_save(my_conf, argv[2])) - ret = -3; + ret = -3; _my_conf_free(my_conf); diff --git a/src/examples/eet-file.c b/src/examples/eet-file.c index 017a6cd..740c179 100644 --- a/src/examples/eet-file.c +++ b/src/examples/eet-file.c @@ -12,25 +12,25 @@ create_eet_file(void) char buf[1024], *ptr; int size, len, i; const char *some_strings[] = { - "And some more strings", - "spread across several", - "elements of an array!" + "And some more strings", + "spread across several", + "elements of an array!" }; const char some_data[] = - "\x1e\xe7\x0f\x42\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x35" - "\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x00\x00\x24\x00\x00\x00\x11" - "\x00\x00\x00\x00\x2f\x6d\x69\x73\x74\x65\x72\x69\x6f\x75\x73\x2f" - "\x64\x61\x74\x61\x00\x41\x6e\x20\x45\x45\x54\x20\x69\x6e\x73\x69" - "\x64\x65\x20\x6f\x66\x20\x61\x6e\x20\x45\x45\x54\x21\x0a\x54\x68" - "\x69\x73\x20\x77\x61\x73\x6e\x27\x74\x20\x72\x65\x61\x6c\x6c\x79" - "\x20\x75\x73\x65\x66\x75\x6c\x20\x62\x75\x74\x20\x69\x74\x20\x68" - "\x65\x6c\x70\x65\x64\x20\x74\x6f\x20\x73\x68\x6f\x77\x20\x68\x6f" - "\x77\x0a\x74\x6f\x20\x75\x73\x65\x20\x65\x65\x74\x5f\x6d\x65\x6d" - "\x6f\x70\x65\x6e\x5f\x72\x65\x61\x64\x28\x29\x20\x74\x6f\x20\x6f" - "\x70\x65\x6e\x20\x61\x6e\x20\x65\x65\x74\x20\x66\x69\x6c\x65\x20" - "\x66\x72\x6f\x6d\x0a\x64\x61\x74\x61\x20\x61\x6c\x72\x65\x61\x64" - "\x79\x20\x6c\x6f\x61\x64\x65\x64\x20\x69\x6e\x20\x6d\x65\x6d\x6f" - "\x72\x79\x2e\x0a\x00"; + "\x1e\xe7\x0f\x42\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x35" + "\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x00\x00\x24\x00\x00\x00\x11" + "\x00\x00\x00\x00\x2f\x6d\x69\x73\x74\x65\x72\x69\x6f\x75\x73\x2f" + "\x64\x61\x74\x61\x00\x41\x6e\x20\x45\x45\x54\x20\x69\x6e\x73\x69" + "\x64\x65\x20\x6f\x66\x20\x61\x6e\x20\x45\x45\x54\x21\x0a\x54\x68" + "\x69\x73\x20\x77\x61\x73\x6e\x27\x74\x20\x72\x65\x61\x6c\x6c\x79" + "\x20\x75\x73\x65\x66\x75\x6c\x20\x62\x75\x74\x20\x69\x74\x20\x68" + "\x65\x6c\x70\x65\x64\x20\x74\x6f\x20\x73\x68\x6f\x77\x20\x68\x6f" + "\x77\x0a\x74\x6f\x20\x75\x73\x65\x20\x65\x65\x74\x5f\x6d\x65\x6d" + "\x6f\x70\x65\x6e\x5f\x72\x65\x61\x64\x28\x29\x20\x74\x6f\x20\x6f" + "\x70\x65\x6e\x20\x61\x6e\x20\x65\x65\x74\x20\x66\x69\x6c\x65\x20" + "\x66\x72\x6f\x6d\x0a\x64\x61\x74\x61\x20\x61\x6c\x72\x65\x61\x64" + "\x79\x20\x6c\x6f\x61\x64\x65\x64\x20\x69\x6e\x20\x6d\x65\x6d\x6f" + "\x72\x79\x2e\x0a\x00"; ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_WRITE); if (!ef) return 0; @@ -60,67 +60,68 @@ create_eet_file(void) eet_delete(ef, "/several/strings"); - return (eet_close(ef) == EET_ERROR_NONE); + return eet_close(ef) == EET_ERROR_NONE; } int main(void) { - Eet_File *ef; - char *ret, **list; - int size, num, i; + Eet_File *ef; + char *ret, **list; + int size, num, i; - eet_init(); + eet_init(); - if (!create_eet_file()) - return -1; + if (!create_eet_file()) + return -1; - ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_READ); - if (!ef) return -1; + ef = eet_open("/tmp/my_file.eet", EET_FILE_MODE_READ); + if (!ef) return -1; - list = eet_list(ef, "*", &num); - if (list) - { - for (i = 0; i < num; i++) - printf("Key stored: %s\n", list[i]); - free(list); - } + list = eet_list(ef, "*", &num); + if (list) + { + for (i = 0; i < num; i++) + printf("Key stored: %s\n", list[i]); + free(list); + } - ret = eet_read(ef, "/key/to_store/at", &size); - if (ret) - { - printf("Data read (%i bytes):\n%s\n", size, ret); - free(ret); - } + ret = eet_read(ef, "/key/to_store/at", &size); + if (ret) + { + printf("Data read (%i bytes):\n%s\n", size, ret); + free(ret); + } - ret = eet_read(ef, "/several/strings", &size); - if (ret) - { - printf("More data read (%i bytes):\n%s\n", size, ret); - free(ret); - } + ret = eet_read(ef, "/several/strings", &size); + if (ret) + { + printf("More data read (%i bytes):\n%s\n", size, ret); + free(ret); + } - ret = eet_read(ef, "/some/mysterious/data", &size); - if (ret) - { - Eet_File *ef2; + ret = eet_read(ef, "/some/mysterious/data", &size); + if (ret) + { + Eet_File *ef2; - ef2 = eet_memopen_read(ret, size); + ef2 = eet_memopen_read(ret, size); - num = eet_num_entries(ef2); - printf("Mysterious data has %d entries\n", num); + num = eet_num_entries(ef2); + printf("Mysterious data has %d entries\n", num); - printf("Mysterious data:\n%s\n", - (char *)eet_read_direct(ef2, "/mysterious/data", NULL)); + printf("Mysterious data:\n%s\n", + (char *)eet_read_direct(ef2, "/mysterious/data", NULL)); - eet_close(ef2); + eet_close(ef2); - free(ret); - } + free(ret); + } - eet_close(ef); + eet_close(ef); - eet_shutdown(); + eet_shutdown(); - return 0; + return 0; } + |