summaryrefslogtreecommitdiff
path: root/legacy/eet/src/examples
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2010-07-28 01:45:57 +0000
committerCarsten Haitzler <raster@rasterman.com>2010-07-28 01:45:57 +0000
commit926db95c5476a7e58ae30873227140b627fc292d (patch)
tree921fa2fb03c97910853287c1a15379175e845994 /legacy/eet/src/examples
parentba10bce4342f61992ceaf06dc6299639cac83a81 (diff)
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
Diffstat (limited to 'legacy/eet/src/examples')
-rw-r--r--legacy/eet/src/examples/eet-data-file_descriptor.c371
-rw-r--r--legacy/eet/src/examples/eet-data-nested.c128
-rw-r--r--legacy/eet/src/examples/eet-data-simple.c93
3 files changed, 305 insertions, 287 deletions
diff --git a/legacy/eet/src/examples/eet-data-file_descriptor.c b/legacy/eet/src/examples/eet-data-file_descriptor.c
index c97b3984e5..a917e1d58b 100644
--- a/legacy/eet/src/examples/eet-data-file_descriptor.c
+++ b/legacy/eet/src/examples/eet-data-file_descriptor.c
@@ -7,7 +7,8 @@
7#include <unistd.h> 7#include <unistd.h>
8 8
9// complex real-world structures based on elmdentica database 9// complex real-world structures based on elmdentica database
10typedef struct { 10typedef struct
11{
11 const char *screen_name; 12 const char *screen_name;
12 const char *name; 13 const char *name;
13 const char *message; 14 const char *message;
@@ -17,19 +18,22 @@ typedef struct {
17 unsigned int timeline; 18 unsigned int timeline;
18} My_Message; 19} My_Message;
19 20
20typedef struct { 21typedef struct
22{
21 const char *dm_to; 23 const char *dm_to;
22 const char *message; 24 const char *message;
23} My_Post; 25} My_Post;
24 26
25typedef struct { 27typedef struct
28{
26 unsigned int id; 29 unsigned int id;
27 const char *name; 30 const char *name;
28 Eina_List *messages; 31 Eina_List *messages;
29 Eina_List *posts; 32 Eina_List *posts;
30} My_Account; 33} My_Account;
31 34
32typedef struct { 35typedef struct
36{
33 unsigned int version; // it is recommended to use versioned configuration! 37 unsigned int version; // it is recommended to use versioned configuration!
34 Eina_List *accounts; 38 Eina_List *accounts;
35} My_Cache; 39} My_Cache;
@@ -74,47 +78,47 @@ _my_cache_descriptor_init(void)
74 // Describe the members to be saved: 78 // Describe the members to be saved:
75 // Use a temporary macro so we don't type a lot, also avoid errors: 79 // Use a temporary macro so we don't type a lot, also avoid errors:
76 80
77#define ADD_BASIC(member, eet_type) \ 81#define ADD_BASIC(member, eet_type) \
78 EET_DATA_DESCRIPTOR_ADD_BASIC \ 82 EET_DATA_DESCRIPTOR_ADD_BASIC \
79 (_my_message_descriptor, My_Message, #member, member, eet_type) 83 (_my_message_descriptor, My_Message, # member, member, eet_type)
80 ADD_BASIC(screen_name, EET_T_STRING); 84 ADD_BASIC(screen_name, EET_T_STRING);
81 ADD_BASIC(name, EET_T_STRING); 85 ADD_BASIC(name, EET_T_STRING);
82 ADD_BASIC(message, EET_T_STRING); 86 ADD_BASIC(message, EET_T_STRING);
83 ADD_BASIC(id, EET_T_UINT); 87 ADD_BASIC(id, EET_T_UINT);
84 ADD_BASIC(status_id, EET_T_UINT); 88 ADD_BASIC(status_id, EET_T_UINT);
85 ADD_BASIC(date, EET_T_UINT); 89 ADD_BASIC(date, EET_T_UINT);
86 ADD_BASIC(timeline, EET_T_UINT); 90 ADD_BASIC(timeline, EET_T_UINT);
87#undef ADD_BASIC 91#undef ADD_BASIC
88 92
89#define ADD_BASIC(member, eet_type) \ 93#define ADD_BASIC(member, eet_type) \
90 EET_DATA_DESCRIPTOR_ADD_BASIC \ 94 EET_DATA_DESCRIPTOR_ADD_BASIC \
91 (_my_post_descriptor, My_Post, #member, member, eet_type) 95 (_my_post_descriptor, My_Post, # member, member, eet_type)
92 ADD_BASIC(dm_to, EET_T_STRING); 96 ADD_BASIC(dm_to, EET_T_STRING);
93 ADD_BASIC(message, EET_T_STRING); 97 ADD_BASIC(message, EET_T_STRING);
94#undef ADD_BASIC 98#undef ADD_BASIC
95 99
96#define ADD_BASIC(member, eet_type) \ 100#define ADD_BASIC(member, eet_type) \
97 EET_DATA_DESCRIPTOR_ADD_BASIC \ 101 EET_DATA_DESCRIPTOR_ADD_BASIC \
98 (_my_account_descriptor, My_Account, #member, member, eet_type) 102 (_my_account_descriptor, My_Account, # member, member, eet_type)
99 ADD_BASIC(name, EET_T_STRING); 103 ADD_BASIC(name, EET_T_STRING);
100 ADD_BASIC(id, EET_T_UINT); 104 ADD_BASIC(id, EET_T_UINT);
101#undef ADD_BASIC 105#undef ADD_BASIC
102 106
103 EET_DATA_DESCRIPTOR_ADD_LIST 107 EET_DATA_DESCRIPTOR_ADD_LIST
104 (_my_account_descriptor, My_Account, "messages", messages, 108 (_my_account_descriptor, My_Account, "messages", messages,
105 _my_message_descriptor); 109 _my_message_descriptor);
106 EET_DATA_DESCRIPTOR_ADD_LIST 110 EET_DATA_DESCRIPTOR_ADD_LIST
107 (_my_account_descriptor, My_Account, "posts", posts, 111 (_my_account_descriptor, My_Account, "posts", posts,
108 _my_post_descriptor); 112 _my_post_descriptor);
109 113
110#define ADD_BASIC(member, eet_type) \ 114#define ADD_BASIC(member, eet_type) \
111 EET_DATA_DESCRIPTOR_ADD_BASIC \ 115 EET_DATA_DESCRIPTOR_ADD_BASIC \
112 (_my_cache_descriptor, My_Cache, #member, member, eet_type) 116 (_my_cache_descriptor, My_Cache, # member, member, eet_type)
113 ADD_BASIC(version, EET_T_UINT); 117 ADD_BASIC(version, EET_T_UINT);
114#undef ADD_BASIC 118#undef ADD_BASIC
115 119
116 EET_DATA_DESCRIPTOR_ADD_LIST 120 EET_DATA_DESCRIPTOR_ADD_LIST
117 (_my_cache_descriptor, My_Cache, "accounts", accounts, 121 (_my_cache_descriptor, My_Cache, "accounts", accounts,
118 _my_account_descriptor); 122 _my_account_descriptor);
119} 123}
120 124
@@ -133,9 +137,11 @@ static void
133_eet_string_free(const char *str) 137_eet_string_free(const char *str)
134{ 138{
135 if (!str) 139 if (!str)
136 return; 140 return;
141
137 if ((_my_cache_dict) && (eet_dictionary_string_check(_my_cache_dict, str))) 142 if ((_my_cache_dict) && (eet_dictionary_string_check(_my_cache_dict, str)))
138 return; 143 return;
144
139 eina_stringshare_del(str); 145 eina_stringshare_del(str);
140} 146}
141 147
@@ -145,9 +151,10 @@ _my_message_new(const char *message)
145 My_Message *msg = calloc(1, sizeof(My_Message)); 151 My_Message *msg = calloc(1, sizeof(My_Message));
146 if (!msg) 152 if (!msg)
147 { 153 {
148 fprintf(stderr, "ERROR: could not calloc My_Message\n"); 154 fprintf(stderr, "ERROR: could not calloc My_Message\n");
149 return NULL; 155 return NULL;
150 } 156 }
157
151 msg->message = eina_stringshare_add(message); 158 msg->message = eina_stringshare_add(message);
152 return msg; 159 return msg;
153} 160}
@@ -167,9 +174,10 @@ _my_post_new(const char *message)
167 My_Post *post = calloc(1, sizeof(My_Post)); 174 My_Post *post = calloc(1, sizeof(My_Post));
168 if (!post) 175 if (!post)
169 { 176 {
170 fprintf(stderr, "ERROR: could not calloc My_Post\n"); 177 fprintf(stderr, "ERROR: could not calloc My_Post\n");
171 return NULL; 178 return NULL;
172 } 179 }
180
173 post->message = eina_stringshare_add(message); 181 post->message = eina_stringshare_add(message);
174 return post; 182 return post;
175} 183}
@@ -188,9 +196,10 @@ _my_account_new(const char *name)
188 My_Account *acc = calloc(1, sizeof(My_Account)); 196 My_Account *acc = calloc(1, sizeof(My_Account));
189 if (!acc) 197 if (!acc)
190 { 198 {
191 fprintf(stderr, "ERROR: could not calloc My_Account\n"); 199 fprintf(stderr, "ERROR: could not calloc My_Account\n");
192 return NULL; 200 return NULL;
193 } 201 }
202
194 acc->name = eina_stringshare_add(name); 203 acc->name = eina_stringshare_add(name);
195 return acc; 204 return acc;
196} 205}
@@ -204,10 +213,10 @@ _my_account_free(My_Account *acc)
204 _eet_string_free(acc->name); 213 _eet_string_free(acc->name);
205 214
206 EINA_LIST_FREE(acc->messages, m) 215 EINA_LIST_FREE(acc->messages, m)
207 _my_message_free(m); 216 _my_message_free(m);
208 217
209 EINA_LIST_FREE(acc->posts, p) 218 EINA_LIST_FREE(acc->posts, p)
210 _my_post_free(p); 219 _my_post_free(p);
211 220
212 free(acc); 221 free(acc);
213} 222}
@@ -218,8 +227,8 @@ _my_cache_new(void)
218 My_Cache *my_cache = calloc(1, sizeof(My_Cache)); 227 My_Cache *my_cache = calloc(1, sizeof(My_Cache));
219 if (!my_cache) 228 if (!my_cache)
220 { 229 {
221 fprintf(stderr, "ERROR: could not calloc My_Cache\n"); 230 fprintf(stderr, "ERROR: could not calloc My_Cache\n");
222 return NULL; 231 return NULL;
223 } 232 }
224 233
225 my_cache->version = 1; 234 my_cache->version = 1;
@@ -231,7 +240,7 @@ _my_cache_free(My_Cache *my_cache)
231{ 240{
232 My_Account *acc; 241 My_Account *acc;
233 EINA_LIST_FREE(my_cache->accounts, acc) 242 EINA_LIST_FREE(my_cache->accounts, acc)
234 _my_account_free(acc); 243 _my_account_free(acc);
235 free(my_cache); 244 free(my_cache);
236} 245}
237 246
@@ -241,8 +250,9 @@ _my_cache_account_find(My_Cache *my_cache, const char *name)
241 My_Account *acc; 250 My_Account *acc;
242 Eina_List *l; 251 Eina_List *l;
243 EINA_LIST_FOREACH(my_cache->accounts, l, acc) 252 EINA_LIST_FOREACH(my_cache->accounts, l, acc)
244 if (strcmp(acc->name, name) == 0) 253 if (strcmp(acc->name, name) == 0)
245 return acc; 254 return acc;
255
246 return NULL; 256 return NULL;
247} 257}
248 258
@@ -253,28 +263,29 @@ _my_cache_load(const char *filename)
253 Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); 263 Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
254 if (!ef) 264 if (!ef)
255 { 265 {
256 fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); 266 fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
257 return NULL; 267 return NULL;
258 } 268 }
259 269
260 my_cache = eet_data_read(ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY); 270 my_cache = eet_data_read(ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY);
261 if (!my_cache) 271 if (!my_cache)
262 { 272 {
263 eet_close(ef); 273 eet_close(ef);
264 return NULL; 274 return NULL;
265 } 275 }
266 276
267 if (my_cache->version < 1) 277 if (my_cache->version < 1)
268 { 278 {
269 fprintf(stderr, 279 fprintf(stderr,
270 "WARNING: version %#x was too old, upgrading it to %#x\n", 280 "WARNING: version %#x was too old, upgrading it to %#x\n",
271 my_cache->version, 1); 281 my_cache->version, 1);
272 282
273 my_cache->version = 1; 283 my_cache->version = 1;
274 } 284 }
275 285
276 if (_my_cache_file) 286 if (_my_cache_file)
277 eet_close(_my_cache_file); 287 eet_close(_my_cache_file);
288
278 _my_cache_file = ef; 289 _my_cache_file = ef;
279 _my_cache_dict = eet_dictionary_get(ef); 290 _my_cache_dict = eet_dictionary_get(ef);
280 291
@@ -293,27 +304,27 @@ _my_cache_save(const My_Cache *my_cache, const char *filename)
293 len = eina_strlcpy(tmp, filename, sizeof(tmp)); 304 len = eina_strlcpy(tmp, filename, sizeof(tmp));
294 if (len + 12 >= (int)sizeof(tmp)) 305 if (len + 12 >= (int)sizeof(tmp))
295 { 306 {
296 fprintf(stderr, "ERROR: file name is too big: %s\n", filename); 307 fprintf(stderr, "ERROR: file name is too big: %s\n", filename);
297 return EINA_FALSE; 308 return EINA_FALSE;
298 } 309 }
299 310
300 i = 0; 311 i = 0;
301 do 312 do
302 { 313 {
303 snprintf(tmp + len, 12, ".%u", i); 314 snprintf(tmp + len, 12, ".%u", i);
304 i++; 315 i++;
305 } 316 }
306 while (stat(tmp, &st) == 0); 317 while (stat(tmp, &st) == 0);
307 318
308 ef = eet_open(tmp, EET_FILE_MODE_WRITE); 319 ef = eet_open(tmp, EET_FILE_MODE_WRITE);
309 if (!ef) 320 if (!ef)
310 { 321 {
311 fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp); 322 fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp);
312 return EINA_FALSE; 323 return EINA_FALSE;
313 } 324 }
314 325
315 ret = eet_data_write 326 ret = eet_data_write
316 (ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY, my_cache, EINA_TRUE); 327 (ef, _my_cache_descriptor, MY_CACHE_FILE_ENTRY, my_cache, EINA_TRUE);
317 328
318 // VERY IMPORTANT NOTE: 329 // VERY IMPORTANT NOTE:
319 // after eet_close(), all strings mmaped from file will be GONE, invalid! 330 // 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)
327 338
328 if (ret) 339 if (ret)
329 { 340 {
330 unlink(filename); 341 unlink(filename);
331 rename(tmp, filename); 342 rename(tmp, filename);
332 } 343 }
333 344
334 return ret; 345 return ret;
@@ -343,15 +354,15 @@ int main(int argc, char *argv[])
343 354
344 if (argc < 3) 355 if (argc < 3)
345 { 356 {
346 fprintf(stderr, 357 fprintf(stderr,
347 "Usage:\n\t%s <input> <output> [action] [action-params]\n\n" 358 "Usage:\n\t%s <input> <output> [action] [action-params]\n\n"
348 "Where actions and their parameters:\n" 359 "Where actions and their parameters:\n"
349 "\tacc <name>\n" 360 "\tacc <name>\n"
350 "\tpost <account-name> <message>\n" 361 "\tpost <account-name> <message>\n"
351 "\tmessage <account-name> <message>\n" 362 "\tmessage <account-name> <message>\n"
352 "\n", 363 "\n",
353 argv[0]); 364 argv[0]);
354 return -1; 365 return -1;
355 } 366 }
356 367
357 eina_init(); 368 eina_init();
@@ -361,127 +372,131 @@ int main(int argc, char *argv[])
361 my_cache = _my_cache_load(argv[1]); 372 my_cache = _my_cache_load(argv[1]);
362 if (!my_cache) 373 if (!my_cache)
363 { 374 {
364 printf("creating new cache.\n"); 375 printf("creating new cache.\n");
365 my_cache = _my_cache_new(); 376 my_cache = _my_cache_new();
366 if (!my_cache) 377 if (!my_cache)
367 { 378 {
368 ret = -2; 379 ret = -2;
369 goto end; 380 goto end;
370 } 381 }
371 } 382 }
372 383
373 if (argc > 3) 384 if (argc > 3)
374 { 385 {
375 if (strcmp(argv[3], "acc") == 0) 386 if (strcmp(argv[3], "acc") == 0)
376 { 387 {
377 if (argc == 5) 388 if (argc == 5)
378 { 389 {
379 My_Account *acc = _my_cache_account_find(my_cache, argv[4]); 390 My_Account *acc = _my_cache_account_find(my_cache, argv[4]);
380 if (!acc) 391 if (!acc)
381 { 392 {
382 acc = _my_account_new(argv[4]); 393 acc = _my_account_new(argv[4]);
383 my_cache->accounts = eina_list_append 394 my_cache->accounts = eina_list_append
384 (my_cache->accounts, acc); 395 (my_cache->accounts, acc);
385 } 396 }
386 else 397 else
387 fprintf(stderr, "ERROR: account '%s' already exists.\n", 398 fprintf(stderr, "ERROR: account '%s' already exists.\n",
388 argv[4]); 399 argv[4]);
389 } 400 }
390 else 401 else
391 fprintf(stderr, "ERROR: wrong number of parameters (%d).\n", 402 fprintf(stderr,
392 argc); 403 "ERROR: wrong number of parameters (%d).\n",
393 } 404 argc);
394 else if (strcmp(argv[3], "post") == 0) 405 }
395 { 406 else if (strcmp(argv[3], "post") == 0)
396 if (argc == 6) 407 {
397 { 408 if (argc == 6)
398 My_Account *acc = _my_cache_account_find(my_cache, argv[4]); 409 {
399 if (acc) 410 My_Account *acc = _my_cache_account_find(my_cache, argv[4]);
400 { 411 if (acc)
401 My_Post *post = _my_post_new(argv[5]); 412 {
402 acc->posts = eina_list_append(acc->posts, post); 413 My_Post *post = _my_post_new(argv[5]);
403 } 414 acc->posts = eina_list_append(acc->posts, post);
404 else 415 }
405 fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); 416 else
406 } 417 fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
407 else 418 }
408 fprintf(stderr, "ERROR: wrong number of parameters (%d).\n", 419 else
409 argc); 420 fprintf(stderr,
410 } 421 "ERROR: wrong number of parameters (%d).\n",
411 else if (strcmp(argv[3], "message") == 0) 422 argc);
412 { 423 }
413 if (argc == 6) 424 else if (strcmp(argv[3], "message") == 0)
414 { 425 {
415 My_Account *acc = _my_cache_account_find(my_cache, argv[4]); 426 if (argc == 6)
416 if (acc) 427 {
417 { 428 My_Account *acc = _my_cache_account_find(my_cache, argv[4]);
418 My_Message *msg = _my_message_new(argv[5]); 429 if (acc)
419 acc->messages = eina_list_append(acc->messages, msg); 430 {
420 } 431 My_Message *msg = _my_message_new(argv[5]);
421 else 432 acc->messages = eina_list_append(acc->messages, msg);
422 fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]); 433 }
423 } 434 else
424 else 435 fprintf(stderr, "ERROR: unknown account: '%s'\n", argv[4]);
425 fprintf(stderr, "ERROR: wrong number of parameters (%d).\n", 436 }
426 argc); 437 else
427 } 438 fprintf(stderr,
428 else 439 "ERROR: wrong number of parameters (%d).\n",
429 fprintf(stderr, "ERROR: unknown action '%s'\n", argv[2]); 440 argc);
441 }
442 else
443 fprintf(stderr, "ERROR: unknown action '%s'\n", argv[2]);
430 } 444 }
431 445
432 printf("My_Cache:\n" 446 printf("My_Cache:\n"
433 "\tversion.: %#x\n" 447 "\tversion.: %#x\n"
434 "\taccounts: %u\n", 448 "\taccounts: %u\n",
435 my_cache->version, 449 my_cache->version,
436 eina_list_count(my_cache->accounts)); 450 eina_list_count(my_cache->accounts));
437 EINA_LIST_FOREACH(my_cache->accounts, l_acc, acc) 451 EINA_LIST_FOREACH(my_cache->accounts, l_acc, acc)
438 { 452 {
439 const My_Post *post; 453 const My_Post *post;
440 454
441 printf("\t > %-#8x '%.20s' stats: m=%u, p=%u\n", 455 printf("\t > %-#8x '%.20s' stats: m=%u, p=%u\n",
442 acc->id, acc->name ? acc->name : "", 456 acc->id, acc->name ? acc->name : "",
443 eina_list_count(acc->messages), 457 eina_list_count(acc->messages),
444 eina_list_count(acc->posts)); 458 eina_list_count(acc->posts));
445 459
446 if (eina_list_count(acc->messages)) 460 if (eina_list_count(acc->messages))
447 { 461 {
448 const Eina_List *l; 462 const Eina_List *l;
449 const My_Message *msg; 463 const My_Message *msg;
450 printf("\t |messages:\n"); 464 printf("\t |messages:\n");
451 465
452 EINA_LIST_FOREACH(acc->messages, l, msg) 466 EINA_LIST_FOREACH(acc->messages, l, msg)
453 { 467 {
454 printf("\t | %-8x '%s' [%s]: '%.20s'\n", 468 printf("\t | %-8x '%s' [%s]: '%.20s'\n",
455 msg->id, 469 msg->id,
456 msg->name ? msg->name : "", 470 msg->name ? msg->name : "",
457 msg->screen_name ? msg->screen_name : "", 471 msg->screen_name ? msg->screen_name : "",
458 msg->message ? msg->message : ""); 472 msg->message ? msg->message : "");
459 } 473 }
460 } 474 }
461 475
462 if (eina_list_count(acc->posts)) 476 if (eina_list_count(acc->posts))
463 { 477 {
464 const Eina_List *l; 478 const Eina_List *l;
465 const My_Post *post; 479 const My_Post *post;
466 printf("\t |posts:\n"); 480 printf("\t |posts:\n");
467 481
468 EINA_LIST_FOREACH(acc->posts, l, post) 482 EINA_LIST_FOREACH(acc->posts, l, post)
469 { 483 {
470 if (post->dm_to) 484 if (post->dm_to)
471 printf("\t | @%s: '%.20s'\n", post->dm_to, post->message); 485 printf("\t | @%s: '%.20s'\n", post->dm_to, post->message);
472 else 486 else
473 printf("\t | '%.20s'\n", post->message); 487 printf("\t | '%.20s'\n", post->message);
474 } 488 }
475 } 489 }
476 printf("\n"); 490
477 } 491 printf("\n");
492 }
478 493
479 if (!_my_cache_save(my_cache, argv[2])) 494 if (!_my_cache_save(my_cache, argv[2]))
480 ret = -3; 495 ret = -3;
481 496
482 _my_cache_free(my_cache); 497 _my_cache_free(my_cache);
483 498
484 end: 499end:
485 _my_cache_descriptor_shutdown(); 500 _my_cache_descriptor_shutdown();
486 eet_shutdown(); 501 eet_shutdown();
487 eina_shutdown(); 502 eina_shutdown();
diff --git a/legacy/eet/src/examples/eet-data-nested.c b/legacy/eet/src/examples/eet-data-nested.c
index 52a095d3c1..3675718a03 100644
--- a/legacy/eet/src/examples/eet-data-nested.c
+++ b/legacy/eet/src/examples/eet-data-nested.c
@@ -11,7 +11,8 @@
11// will be automatically handled. The other members will have their 11// will be automatically handled. The other members will have their
12// space reserved and zeroed (as it uses calloc()), but not 12// space reserved and zeroed (as it uses calloc()), but not
13// saved or loaded from eet files. 13// saved or loaded from eet files.
14typedef struct { 14typedef struct
15{
15 unsigned int version; // it is recommended to use versioned configuration! 16 unsigned int version; // it is recommended to use versioned configuration!
16 const char *name; 17 const char *name;
17 int id; 18 int id;
@@ -20,7 +21,8 @@ typedef struct {
20 Eina_List *subs; 21 Eina_List *subs;
21} My_Conf_Type; 22} My_Conf_Type;
22 23
23typedef struct { 24typedef struct
25{
24 const char *server; 26 const char *server;
25 int port; 27 int port;
26} My_Conf_Subtype; 28} My_Conf_Subtype;
@@ -62,24 +64,24 @@ _my_conf_descriptor_init(void)
62 64
63 // Describe the members to be saved: 65 // Describe the members to be saved:
64 // Use a temporary macro so we don't type a lot, also avoid errors: 66 // Use a temporary macro so we don't type a lot, also avoid errors:
65#define MY_CONF_ADD_BASIC(member, eet_type) \ 67#define MY_CONF_ADD_BASIC(member, eet_type) \
66 EET_DATA_DESCRIPTOR_ADD_BASIC \ 68 EET_DATA_DESCRIPTOR_ADD_BASIC \
67 (_my_conf_descriptor, My_Conf_Type, #member, member, eet_type) 69 (_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
68#define MY_CONF_SUB_ADD_BASIC(member, eet_type) \ 70#define MY_CONF_SUB_ADD_BASIC(member, eet_type) \
69 EET_DATA_DESCRIPTOR_ADD_BASIC \ 71 EET_DATA_DESCRIPTOR_ADD_BASIC \
70 (_my_conf_sub_descriptor, My_Conf_Subtype, #member, member, eet_type) 72 (_my_conf_sub_descriptor, My_Conf_Subtype, # member, member, eet_type)
71 73
72 MY_CONF_SUB_ADD_BASIC(server, EET_T_STRING); 74 MY_CONF_SUB_ADD_BASIC(server, EET_T_STRING);
73 MY_CONF_SUB_ADD_BASIC(port, EET_T_INT); 75 MY_CONF_SUB_ADD_BASIC(port, EET_T_INT);
74 76
75 MY_CONF_ADD_BASIC(version, EET_T_UINT); 77 MY_CONF_ADD_BASIC(version, EET_T_UINT);
76 MY_CONF_ADD_BASIC(name, EET_T_STRING); 78 MY_CONF_ADD_BASIC(name, EET_T_STRING);
77 MY_CONF_ADD_BASIC(id, EET_T_INT); 79 MY_CONF_ADD_BASIC(id, EET_T_INT);
78 MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR); 80 MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR);
79 81
80 // And add the sub descriptor as a linked list at 'subs' in the main struct 82 // And add the sub descriptor as a linked list at 'subs' in the main struct
81 EET_DATA_DESCRIPTOR_ADD_LIST 83 EET_DATA_DESCRIPTOR_ADD_LIST
82 (_my_conf_descriptor, My_Conf_Type, "subs", subs, _my_conf_sub_descriptor); 84 (_my_conf_descriptor, My_Conf_Type, "subs", subs, _my_conf_sub_descriptor);
83 85
84#undef MY_CONF_ADD_BASIC 86#undef MY_CONF_ADD_BASIC
85#undef MY_CONF_SUB_ADD_BASIC 87#undef MY_CONF_SUB_ADD_BASIC
@@ -99,8 +101,8 @@ _my_conf_new(void)
99 My_Conf_Subtype *sub; 101 My_Conf_Subtype *sub;
100 if (!my_conf) 102 if (!my_conf)
101 { 103 {
102 fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n"); 104 fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n");
103 return NULL; 105 return NULL;
104 } 106 }
105 107
106 my_conf->version = 0x112233; 108 my_conf->version = 0x112233;
@@ -109,9 +111,9 @@ _my_conf_new(void)
109 sub = calloc(1, sizeof(My_Conf_Subtype)); 111 sub = calloc(1, sizeof(My_Conf_Subtype));
110 if (sub) 112 if (sub)
111 { 113 {
112 sub->server = eina_stringshare_add("my-server.com"); 114 sub->server = eina_stringshare_add("my-server.com");
113 sub->port = 1234; 115 sub->port = 1234;
114 my_conf->subs = eina_list_append(my_conf->subs, sub); 116 my_conf->subs = eina_list_append(my_conf->subs, sub);
115 } 117 }
116 118
117 return my_conf; 119 return my_conf;
@@ -122,10 +124,10 @@ _my_conf_free(My_Conf_Type *my_conf)
122{ 124{
123 My_Conf_Subtype *sub; 125 My_Conf_Subtype *sub;
124 EINA_LIST_FREE(my_conf->subs, sub) 126 EINA_LIST_FREE(my_conf->subs, sub)
125 { 127 {
126 eina_stringshare_del(sub->server); 128 eina_stringshare_del(sub->server);
127 free(sub); 129 free(sub);
128 } 130 }
129 131
130 eina_stringshare_del(my_conf->name); 132 eina_stringshare_del(my_conf->name);
131 free(my_conf); 133 free(my_conf);
@@ -138,25 +140,25 @@ _my_conf_load(const char *filename)
138 Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); 140 Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
139 if (!ef) 141 if (!ef)
140 { 142 {
141 fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); 143 fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
142 return NULL; 144 return NULL;
143 } 145 }
144 146
145 my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY); 147 my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY);
146 if (!my_conf) 148 if (!my_conf)
147 goto end; 149 goto end;
148 150
149 if (my_conf->version < 0x112233) 151 if (my_conf->version < 0x112233)
150 { 152 {
151 fprintf(stderr, 153 fprintf(stderr,
152 "WARNING: version %#x was too old, upgrading it to %#x\n", 154 "WARNING: version %#x was too old, upgrading it to %#x\n",
153 my_conf->version, 0x112233); 155 my_conf->version, 0x112233);
154 156
155 my_conf->version = 0x112233; 157 my_conf->version = 0x112233;
156 my_conf->enabled = EINA_TRUE; 158 my_conf->enabled = EINA_TRUE;
157 } 159 }
158 160
159 end: 161end:
160 eet_close(ef); 162 eet_close(ef);
161 return my_conf; 163 return my_conf;
162} 164}
@@ -173,33 +175,33 @@ _my_conf_save(const My_Conf_Type *my_conf, const char *filename)
173 len = eina_strlcpy(tmp, filename, sizeof(tmp)); 175 len = eina_strlcpy(tmp, filename, sizeof(tmp));
174 if (len + 12 >= (int)sizeof(tmp)) 176 if (len + 12 >= (int)sizeof(tmp))
175 { 177 {
176 fprintf(stderr, "ERROR: file name is too big: %s\n", filename); 178 fprintf(stderr, "ERROR: file name is too big: %s\n", filename);
177 return EINA_FALSE; 179 return EINA_FALSE;
178 } 180 }
179 181
180 i = 0; 182 i = 0;
181 do 183 do
182 { 184 {
183 snprintf(tmp + len, 12, ".%u", i); 185 snprintf(tmp + len, 12, ".%u", i);
184 i++; 186 i++;
185 } 187 }
186 while (stat(tmp, &st) == 0); 188 while (stat(tmp, &st) == 0);
187 189
188 ef = eet_open(tmp, EET_FILE_MODE_WRITE); 190 ef = eet_open(tmp, EET_FILE_MODE_WRITE);
189 if (!ef) 191 if (!ef)
190 { 192 {
191 fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp); 193 fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp);
192 return EINA_FALSE; 194 return EINA_FALSE;
193 } 195 }
194 196
195 ret = eet_data_write 197 ret = eet_data_write
196 (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE); 198 (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE);
197 eet_close(ef); 199 eet_close(ef);
198 200
199 if (ret) 201 if (ret)
200 { 202 {
201 unlink(filename); 203 unlink(filename);
202 rename(tmp, filename); 204 rename(tmp, filename);
203 } 205 }
204 206
205 return ret; 207 return ret;
@@ -214,8 +216,8 @@ int main(int argc, char *argv[])
214 216
215 if (argc != 3) 217 if (argc != 3)
216 { 218 {
217 fprintf(stderr, "Usage:\n\t%s <input> <output>\n\n", argv[0]); 219 fprintf(stderr, "Usage:\n\t%s <input> <output>\n\n", argv[0]);
218 return -1; 220 return -1;
219 } 221 }
220 222
221 eina_init(); 223 eina_init();
@@ -225,37 +227,37 @@ int main(int argc, char *argv[])
225 my_conf = _my_conf_load(argv[1]); 227 my_conf = _my_conf_load(argv[1]);
226 if (!my_conf) 228 if (!my_conf)
227 { 229 {
228 printf("creating new configuration.\n"); 230 printf("creating new configuration.\n");
229 my_conf = _my_conf_new(); 231 my_conf = _my_conf_new();
230 if (!my_conf) 232 if (!my_conf)
231 { 233 {
232 ret = -2; 234 ret = -2;
233 goto end; 235 goto end;
234 } 236 }
235 } 237 }
236 238
237 printf("My_Conf_Type:\n" 239 printf("My_Conf_Type:\n"
238 "\tversion: %#x\n" 240 "\tversion: %#x\n"
239 "\tname...: '%s'\n" 241 "\tname...: '%s'\n"
240 "\tid.....: %d\n" 242 "\tid.....: %d\n"
241 "\tenabled: %hhu\n" 243 "\tenabled: %hhu\n"
242 "\tsubs...:\n", 244 "\tsubs...:\n",
243 my_conf->version, 245 my_conf->version,
244 my_conf->name ? my_conf->name : "", 246 my_conf->name ? my_conf->name : "",
245 my_conf->id, 247 my_conf->id,
246 my_conf->enabled); 248 my_conf->enabled);
247 249
248 EINA_LIST_FOREACH(my_conf->subs, l, sub) 250 EINA_LIST_FOREACH(my_conf->subs, l, sub)
249 printf("\t\tserver: '%s', port: %d\n", 251 printf("\t\tserver: '%s', port: %d\n",
250 sub->server ? sub->server : "", 252 sub->server ? sub->server : "",
251 sub->port); 253 sub->port);
252 254
253 if (!_my_conf_save(my_conf, argv[2])) 255 if (!_my_conf_save(my_conf, argv[2]))
254 ret = -3; 256 ret = -3;
255 257
256 _my_conf_free(my_conf); 258 _my_conf_free(my_conf);
257 259
258 end: 260end:
259 _my_conf_descriptor_shutdown(); 261 _my_conf_descriptor_shutdown();
260 eet_shutdown(); 262 eet_shutdown();
261 eina_shutdown(); 263 eina_shutdown();
diff --git a/legacy/eet/src/examples/eet-data-simple.c b/legacy/eet/src/examples/eet-data-simple.c
index 72d00c96d9..a4efd4ad7a 100644
--- a/legacy/eet/src/examples/eet-data-simple.c
+++ b/legacy/eet/src/examples/eet-data-simple.c
@@ -11,7 +11,8 @@
11// will be automatically handled. The other members will have their 11// will be automatically handled. The other members will have their
12// space reserved and zeroed (as it uses calloc()), but not 12// space reserved and zeroed (as it uses calloc()), but not
13// saved or loaded from eet files. 13// saved or loaded from eet files.
14typedef struct { 14typedef struct
15{
15 unsigned int version; // it is recommended to use versioned configuration! 16 unsigned int version; // it is recommended to use versioned configuration!
16 const char *name; 17 const char *name;
17 int id; 18 int id;
@@ -52,13 +53,13 @@ _my_conf_descriptor_init(void)
52 53
53 // Describe the members to be saved: 54 // Describe the members to be saved:
54 // Use a temporary macro so we don't type a lot, also avoid errors: 55 // Use a temporary macro so we don't type a lot, also avoid errors:
55#define MY_CONF_ADD_BASIC(member, eet_type) \ 56#define MY_CONF_ADD_BASIC(member, eet_type) \
56 EET_DATA_DESCRIPTOR_ADD_BASIC \ 57 EET_DATA_DESCRIPTOR_ADD_BASIC \
57 (_my_conf_descriptor, My_Conf_Type, #member, member, eet_type) 58 (_my_conf_descriptor, My_Conf_Type, # member, member, eet_type)
58 59
59 MY_CONF_ADD_BASIC(version, EET_T_UINT); 60 MY_CONF_ADD_BASIC(version, EET_T_UINT);
60 MY_CONF_ADD_BASIC(name, EET_T_STRING); 61 MY_CONF_ADD_BASIC(name, EET_T_STRING);
61 MY_CONF_ADD_BASIC(id, EET_T_INT); 62 MY_CONF_ADD_BASIC(id, EET_T_INT);
62 MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR); 63 MY_CONF_ADD_BASIC(enabled, EET_T_UCHAR);
63 64
64#undef MY_CONF_ADD_BASIC 65#undef MY_CONF_ADD_BASIC
@@ -76,8 +77,8 @@ _my_conf_new(void)
76 My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type)); 77 My_Conf_Type *my_conf = calloc(1, sizeof(My_Conf_Type));
77 if (!my_conf) 78 if (!my_conf)
78 { 79 {
79 fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n"); 80 fprintf(stderr, "ERROR: could not calloc My_Conf_Type\n");
80 return NULL; 81 return NULL;
81 } 82 }
82 83
83 my_conf->version = 0x112233; 84 my_conf->version = 0x112233;
@@ -99,25 +100,25 @@ _my_conf_load(const char *filename)
99 Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ); 100 Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
100 if (!ef) 101 if (!ef)
101 { 102 {
102 fprintf(stderr, "ERROR: could not open '%s' for read\n", filename); 103 fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
103 return NULL; 104 return NULL;
104 } 105 }
105 106
106 my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY); 107 my_conf = eet_data_read(ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY);
107 if (!my_conf) 108 if (!my_conf)
108 goto end; 109 goto end;
109 110
110 if (my_conf->version < 0x112233) 111 if (my_conf->version < 0x112233)
111 { 112 {
112 fprintf(stderr, 113 fprintf(stderr,
113 "WARNING: version %#x was too old, upgrading it to %#x\n", 114 "WARNING: version %#x was too old, upgrading it to %#x\n",
114 my_conf->version, 0x112233); 115 my_conf->version, 0x112233);
115 116
116 my_conf->version = 0x112233; 117 my_conf->version = 0x112233;
117 my_conf->enabled = EINA_TRUE; 118 my_conf->enabled = EINA_TRUE;
118 } 119 }
119 120
120 end: 121end:
121 eet_close(ef); 122 eet_close(ef);
122 return my_conf; 123 return my_conf;
123} 124}
@@ -134,33 +135,33 @@ _my_conf_save(const My_Conf_Type *my_conf, const char *filename)
134 len = eina_strlcpy(tmp, filename, sizeof(tmp)); 135 len = eina_strlcpy(tmp, filename, sizeof(tmp));
135 if (len + 12 >= (int)sizeof(tmp)) 136 if (len + 12 >= (int)sizeof(tmp))
136 { 137 {
137 fprintf(stderr, "ERROR: file name is too big: %s\n", filename); 138 fprintf(stderr, "ERROR: file name is too big: %s\n", filename);
138 return EINA_FALSE; 139 return EINA_FALSE;
139 } 140 }
140 141
141 i = 0; 142 i = 0;
142 do 143 do
143 { 144 {
144 snprintf(tmp + len, 12, ".%u", i); 145 snprintf(tmp + len, 12, ".%u", i);
145 i++; 146 i++;
146 } 147 }
147 while (stat(tmp, &st) == 0); 148 while (stat(tmp, &st) == 0);
148 149
149 ef = eet_open(tmp, EET_FILE_MODE_WRITE); 150 ef = eet_open(tmp, EET_FILE_MODE_WRITE);
150 if (!ef) 151 if (!ef)
151 { 152 {
152 fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp); 153 fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp);
153 return EINA_FALSE; 154 return EINA_FALSE;
154 } 155 }
155 156
156 ret = eet_data_write 157 ret = eet_data_write
157 (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE); 158 (ef, _my_conf_descriptor, MY_CONF_FILE_ENTRY, my_conf, EINA_TRUE);
158 eet_close(ef); 159 eet_close(ef);
159 160
160 if (ret) 161 if (ret)
161 { 162 {
162 unlink(filename); 163 unlink(filename);
163 rename(tmp, filename); 164 rename(tmp, filename);
164 } 165 }
165 166
166 return ret; 167 return ret;
@@ -173,8 +174,8 @@ int main(int argc, char *argv[])
173 174
174 if (argc != 3) 175 if (argc != 3)
175 { 176 {
176 fprintf(stderr, "Usage:\n\t%s <input> <output>\n\n", argv[0]); 177 fprintf(stderr, "Usage:\n\t%s <input> <output>\n\n", argv[0]);
177 return -1; 178 return -1;
178 } 179 }
179 180
180 eina_init(); 181 eina_init();
@@ -184,31 +185,31 @@ int main(int argc, char *argv[])
184 my_conf = _my_conf_load(argv[1]); 185 my_conf = _my_conf_load(argv[1]);
185 if (!my_conf) 186 if (!my_conf)
186 { 187 {
187 printf("creating new configuration.\n"); 188 printf("creating new configuration.\n");
188 my_conf = _my_conf_new(); 189 my_conf = _my_conf_new();
189 if (!my_conf) 190 if (!my_conf)
190 { 191 {
191 ret = -2; 192 ret = -2;
192 goto end; 193 goto end;
193 } 194 }
194 } 195 }
195 196
196 printf("My_Conf_Type:\n" 197 printf("My_Conf_Type:\n"
197 "\tversion: %#x\n" 198 "\tversion: %#x\n"
198 "\tname...: '%s'\n" 199 "\tname...: '%s'\n"
199 "\tid.....: %d\n" 200 "\tid.....: %d\n"
200 "\tenabled: %hhu\n", 201 "\tenabled: %hhu\n",
201 my_conf->version, 202 my_conf->version,
202 my_conf->name ? my_conf->name : "", 203 my_conf->name ? my_conf->name : "",
203 my_conf->id, 204 my_conf->id,
204 my_conf->enabled); 205 my_conf->enabled);
205 206
206 if (!_my_conf_save(my_conf, argv[2])) 207 if (!_my_conf_save(my_conf, argv[2]))
207 ret = -3; 208 ret = -3;
208 209
209 _my_conf_free(my_conf); 210 _my_conf_free(my_conf);
210 211
211 end: 212end:
212 _my_conf_descriptor_shutdown(); 213 _my_conf_descriptor_shutdown();
213 eet_shutdown(); 214 eet_shutdown();
214 eina_shutdown(); 215 eina_shutdown();