summaryrefslogtreecommitdiff
path: root/legacy/eet/src/examples/eet-data-file_descriptor_02.c
diff options
context:
space:
mode:
authorGustavo Lima Chaves <glima@profusion.mobi>2011-08-09 20:33:50 +0000
committerGustavo Lima Chaves <glima@profusion.mobi>2011-08-09 20:33:50 +0000
commitfc80ec34c2268f42f0405fb5b38e7a5b0cfceba1 (patch)
treeb1e89f079c74b178935aca1977bf3bf9e37a85cb /legacy/eet/src/examples/eet-data-file_descriptor_02.c
parent2fa1f8c3d58fad9c57539dc321c126c61337b99d (diff)
[eet] New examples.
SVN revision: 62264
Diffstat (limited to '')
-rw-r--r--legacy/eet/src/examples/eet-data-file_descriptor_02.c941
1 files changed, 941 insertions, 0 deletions
diff --git a/legacy/eet/src/examples/eet-data-file_descriptor_02.c b/legacy/eet/src/examples/eet-data-file_descriptor_02.c
new file mode 100644
index 0000000000..9690d6b19b
--- /dev/null
+++ b/legacy/eet/src/examples/eet-data-file_descriptor_02.c
@@ -0,0 +1,941 @@
1/*
2 * build: gcc -o eet_data_file_descriptor_02 eet-data-file_descriptor_02.c `pkg-config --cflags --libs eet eina`
3 */
4
5#include <Eina.h>
6#include <Eet.h>
7#include <stdio.h>
8#include <limits.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <unistd.h>
12
13typedef enum _Example_Data_Type Example_Data_Type;
14typedef struct _Example_Variant_Type Example_Variant_Type;
15typedef struct _Example_Variant Example_Variant;
16typedef struct _Example_Union Example_Union;
17typedef struct _Example_Struct1 Example_Struct1;
18typedef struct _Example_Struct2 Example_Struct2;
19typedef struct _Example_Struct3 Example_Struct3;
20typedef struct _Example_Lists Example_Lists;
21
22enum _Example_Data_Type
23{
24 EET_UNKNOWN = 0,
25 EET_STRUCT1,
26 EET_STRUCT2,
27 EET_STRUCT3
28};
29
30struct
31{
32 Example_Data_Type u;
33 const char *name;
34} eet_mapping[] = {
35 { EET_STRUCT1, "ST1" },
36 { EET_STRUCT2, "ST2" },
37 { EET_STRUCT3, "ST3" },
38 { EET_UNKNOWN, NULL }
39};
40
41struct _Example_Struct1
42{
43 double val1;
44 int stuff;
45 const char *s1;
46};
47
48struct _Example_Struct2
49{
50 Eina_Bool b1;
51 unsigned long long v1;
52};
53
54struct _Example_Struct3
55{
56 int body;
57};
58
59struct _Example_Union
60{
61 Example_Data_Type type;
62
63 union {
64 Example_Struct1 st1;
65 Example_Struct2 st2;
66 Example_Struct3 st3;
67 } u;
68};
69
70struct _Example_Variant_Type
71{
72 const char *type;
73 Eina_Bool unknow : 1;
74};
75
76struct _Example_Variant
77{
78 Example_Variant_Type t;
79
80 void *data; /* differently than the union type, we
81 * don't need to pre-allocate the memory
82 * for the field*/
83};
84
85struct _Example_Lists
86{
87 Eina_List *union_list;
88 Eina_List *variant_list;
89};
90
91static void
92_st1_set(Example_Struct1 *st1,
93 double v1,
94 int v2,
95 const char *v3)
96{
97 st1->val1 = v1;
98 st1->stuff = v2;
99 st1->s1 = v3;
100} /* _st1_set */
101
102static void
103_st2_set(Example_Struct2 *st2,
104 Eina_Bool v1,
105 unsigned long long v2)
106{
107 st2->b1 = v1;
108 st2->v1 = v2;
109} /* _st2_set */
110
111static void
112_st3_set(Example_Struct3 *st3,
113 int v1)
114{
115 st3->body = v1;
116} /* _st3_set */
117
118static const char * /* union type_get() */
119_union_type_get(const void *data,
120 Eina_Bool *unknow)
121{
122 const Example_Data_Type *u = data;
123 int i;
124
125 if (unknow)
126 *unknow = EINA_FALSE;
127
128 for (i = 0; eet_mapping[i].name != NULL; ++i)
129 if (*u == eet_mapping[i].u)
130 return eet_mapping[i].name;
131
132 if (unknow)
133 *unknow = EINA_TRUE;
134
135 return NULL;
136} /* _union_type_get */
137
138static Eina_Bool
139_union_type_set(const char *type,
140 void *data,
141 Eina_Bool unknow)
142{
143 Example_Data_Type *u = data;
144 int i;
145
146 if (unknow)
147 return EINA_FALSE;
148
149 for (i = 0; eet_mapping[i].name != NULL; ++i)
150 if (strcmp(eet_mapping[i].name, type) == 0)
151 {
152 *u = eet_mapping[i].u;
153 return EINA_TRUE;
154 }
155
156 return EINA_FALSE;
157} /* _union_type_set */
158
159static const char *
160_variant_type_get(const void *data,
161 Eina_Bool *unknow)
162{
163 const Example_Variant_Type *type = data;
164 int i;
165
166 if (unknow)
167 *unknow = type->unknow;
168
169 for (i = 0; eet_mapping[i].name != NULL; ++i)
170 if (strcmp(type->type, eet_mapping[i].name) == 0)
171 return eet_mapping[i].name;
172
173 if (unknow)
174 *unknow = EINA_FALSE;
175
176 return type->type;
177} /* _variant_type_get */
178
179static Eina_Bool
180_variant_type_set(const char *type,
181 void *data,
182 Eina_Bool unknow)
183{
184 Example_Variant_Type *vt = data;
185
186 vt->type = type;
187 vt->unknow = unknow;
188 return EINA_TRUE;
189} /* _variant_type_set */
190
191static Eet_Data_Descriptor *
192_st1_dd(void)
193{
194 Eet_Data_Descriptor_Class eddc;
195 Eet_Data_Descriptor *res;
196
197 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Example_Struct1);
198 res = eet_data_descriptor_file_new(&eddc);
199 EET_DATA_DESCRIPTOR_ADD_BASIC(
200 res, Example_Struct1, "val1", val1, EET_T_DOUBLE);
201 EET_DATA_DESCRIPTOR_ADD_BASIC(
202 res, Example_Struct1, "stuff", stuff, EET_T_INT);
203 EET_DATA_DESCRIPTOR_ADD_BASIC(
204 res, Example_Struct1, "s1", s1, EET_T_STRING);
205
206 return res;
207} /* _st1_dd */
208
209static Eet_Data_Descriptor *
210_st2_dd(void)
211{
212 Eet_Data_Descriptor_Class eddc;
213 Eet_Data_Descriptor *res;
214
215 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Example_Struct2);
216 res = eet_data_descriptor_file_new(&eddc);
217 EET_DATA_DESCRIPTOR_ADD_BASIC(
218 res, Example_Struct2, "b1", b1, EET_T_UCHAR);
219 EET_DATA_DESCRIPTOR_ADD_BASIC(
220 res, Example_Struct2, "v1", v1, EET_T_ULONG_LONG);
221
222 return res;
223} /* _st2_dd */
224
225static Eet_Data_Descriptor *
226_st3_dd(void)
227{
228 Eet_Data_Descriptor_Class eddc;
229 Eet_Data_Descriptor *res;
230
231 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Example_Struct3);
232 res = eet_data_descriptor_file_new(&eddc);
233 EET_DATA_DESCRIPTOR_ADD_BASIC(
234 res, Example_Struct3, "body", body, EET_T_INT);
235
236 return res;
237} /* _st3_dd */
238
239/* string that represents the entry in the eet file. you might like to
240 * have different profiles or so in the same file, this is possible
241 * with different strings
242 */
243static const char CACHE_FILE_ENTRY[] = "cache";
244
245/* keep the descriptor static global, so it can be shared by different
246 * functions (load/save) of this and only this file.
247 */
248static Eet_Data_Descriptor *_lists_descriptor;
249static Eet_Data_Descriptor *_struct_1_descriptor;
250static Eet_Data_Descriptor *_struct_2_descriptor;
251static Eet_Data_Descriptor *_struct_3_descriptor;
252static Eet_Data_Descriptor *_union_descriptor;
253static Eet_Data_Descriptor *_variant_descriptor;
254static Eet_Data_Descriptor *_union_unified_descriptor;
255static Eet_Data_Descriptor *_variant_unified_descriptor;
256
257/* keep file handle alive, so mmap()ed strings are all alive as
258 * well */
259static Eet_File *_cache_file = NULL;
260static Eet_Dictionary *_cache_dict = NULL;
261
262static void /* declaring types */
263_data_descriptors_init(void)
264{
265 Eet_Data_Descriptor_Class eddc;
266
267 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Example_Lists);
268 _lists_descriptor = eet_data_descriptor_file_new(&eddc);
269
270 _struct_1_descriptor = _st1_dd();
271 _struct_2_descriptor = _st2_dd();
272 _struct_3_descriptor = _st3_dd();
273
274 /* for union */
275 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Example_Union);
276 _union_descriptor = eet_data_descriptor_file_new(&eddc);
277
278 eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
279 eddc.func.type_get = _union_type_get;
280 eddc.func.type_set = _union_type_set;
281 _union_unified_descriptor = eet_data_descriptor_file_new(&eddc);
282
283 EET_DATA_DESCRIPTOR_ADD_MAPPING(
284 _union_unified_descriptor, "ST1", _struct_1_descriptor);
285 EET_DATA_DESCRIPTOR_ADD_MAPPING(
286 _union_unified_descriptor, "ST2", _struct_2_descriptor);
287 EET_DATA_DESCRIPTOR_ADD_MAPPING(
288 _union_unified_descriptor, "ST3", _struct_3_descriptor);
289
290 EET_DATA_DESCRIPTOR_ADD_UNION(
291 _union_descriptor, Example_Union, "u", u, type,
292 _union_unified_descriptor);
293
294 EET_DATA_DESCRIPTOR_ADD_LIST(
295 _lists_descriptor, Example_Lists, "union_list", union_list,
296 _union_descriptor);
297
298 /* for variant */
299 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Example_Variant);
300 _variant_descriptor = eet_data_descriptor_file_new(&eddc);
301
302 eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
303 eddc.func.type_get = _variant_type_get;
304 eddc.func.type_set = _variant_type_set;
305 _variant_unified_descriptor = eet_data_descriptor_stream_new(&eddc);
306
307 EET_DATA_DESCRIPTOR_ADD_MAPPING(
308 _variant_unified_descriptor, "ST1", _struct_1_descriptor);
309 EET_DATA_DESCRIPTOR_ADD_MAPPING(
310 _variant_unified_descriptor, "ST2", _struct_2_descriptor);
311 EET_DATA_DESCRIPTOR_ADD_MAPPING(
312 _variant_unified_descriptor, "ST3", _struct_3_descriptor);
313
314 EET_DATA_DESCRIPTOR_ADD_VARIANT(
315 _variant_descriptor, Example_Variant, "data", data, t,
316 _variant_unified_descriptor);
317
318 EET_DATA_DESCRIPTOR_ADD_LIST(
319 _lists_descriptor, Example_Lists, "variant_list", variant_list,
320 _variant_descriptor);
321} /* _data_descriptors_init */
322
323static void
324_data_descriptors_shutdown(void)
325{
326 eet_data_descriptor_free(_lists_descriptor);
327 eet_data_descriptor_free(_struct_1_descriptor);
328 eet_data_descriptor_free(_struct_2_descriptor);
329 eet_data_descriptor_free(_struct_3_descriptor);
330 eet_data_descriptor_free(_union_descriptor);
331 eet_data_descriptor_free(_variant_descriptor);
332 eet_data_descriptor_free(_union_unified_descriptor);
333 eet_data_descriptor_free(_variant_unified_descriptor);
334} /* _data_descriptors_shutdown */
335
336/* need to check if the pointer came from mmap()ed area in
337 * eet_dictionary or it was allocated with eina_stringshare_add()
338 */
339static void
340_string_free(const char *str)
341{
342 if (!str)
343 return;
344
345 if ((_cache_dict) && (eet_dictionary_string_check(_cache_dict, str)))
346 return;
347
348 eina_stringshare_del(str);
349} /* _string_free */
350
351static Example_Union *
352_union_1_new(const char *v1,
353 const char *v2,
354 const char *v3)
355{
356 Example_Union *un = calloc(1, sizeof(Example_Union));
357 if (!un)
358 {
359 fprintf(
360 stderr, "ERROR: could not allocate an Example_Union struct.\n");
361 return NULL;
362 }
363
364 un->type = EET_STRUCT1;
365 _st1_set(&(un->u.st1), atof(v1), atoi(v2), eina_stringshare_add(v3));
366
367 return un;
368}
369
370static Example_Union *
371_union_2_new(const char *v1,
372 const char *v2)
373{
374 Example_Union *un = calloc(1, sizeof(Example_Union));
375 if (!un)
376 {
377 fprintf(
378 stderr, "ERROR: could not allocate an Example_Union struct.\n");
379 return NULL;
380 }
381
382 un->type = EET_STRUCT2;
383 _st2_set(&(un->u.st2), atoi(v1), atoi(v2));
384
385 return un;
386}
387
388static Example_Union *
389_union_3_new(const char *v1)
390{
391 Example_Union *un = calloc(1, sizeof(Example_Union));
392 if (!un)
393 {
394 fprintf(
395 stderr, "ERROR: could not allocate an Example_Union struct.\n");
396 return NULL;
397 }
398
399 un->type = EET_STRUCT3;
400 _st3_set(&(un->u.st3), atoi(v1));
401
402 return un;
403}
404
405static Example_Variant *
406_variant_1_new(const char *v1,
407 const char *v2,
408 const char *v3)
409{
410 Example_Struct1 *st1;
411 Example_Variant *va = calloc(1, sizeof(Example_Variant));
412 if (!va)
413 {
414 fprintf(
415 stderr, "ERROR: could not allocate an Example_Variant struct.\n");
416 return NULL;
417 }
418
419 va = calloc(1, sizeof (Example_Variant));
420 va->t.type = eet_mapping[0].name;
421 st1 = calloc(1, sizeof (Example_Struct1));
422 _st1_set(st1, atof(v1), atoi(v2), eina_stringshare_add(v3));
423 va->data = st1;
424
425 return va;
426}
427
428static Example_Variant *
429_variant_2_new(const char *v1,
430 const char *v2)
431{
432 printf("varinant 2 new\n");
433
434 Example_Struct2 *st2;
435 Example_Variant *va = calloc(1, sizeof(Example_Variant));
436 if (!va)
437 {
438 fprintf(
439 stderr, "ERROR: could not allocate an Example_Variant struct.\n");
440 return NULL;
441 }
442
443 va = calloc(1, sizeof (Example_Variant));
444
445 va->t.type = eet_mapping[1].name;
446
447 printf("type gets %s\n", va->t.type);
448
449 st2 = calloc(1, sizeof (Example_Struct2));
450 _st2_set(st2, atoi(v1), atoi(v2));
451 va->data = st2;
452
453 return va;
454}
455
456static Example_Variant *
457_variant_3_new(const char *v1)
458{
459 Example_Struct3 *st3;
460 Example_Variant *va = calloc(1, sizeof(Example_Variant));
461 if (!va)
462 {
463 fprintf(
464 stderr, "ERROR: could not allocate an Example_Variant struct.\n");
465 return NULL;
466 }
467
468 va = calloc(1, sizeof (Example_Variant));
469 va->t.type = eet_mapping[2].name;
470 st3 = calloc(1, sizeof (Example_Struct3));
471 _st3_set(st3, atoi(v1));
472 va->data = st3;
473
474 return va;
475}
476
477static Example_Lists *
478_data_new(void)
479{
480 Example_Lists *example_lists = calloc(1, sizeof(Example_Lists));
481 if (!example_lists)
482 {
483 fprintf(stderr, "ERROR: could not allocate a Example_Lists struct.\n");
484 return NULL;
485 }
486
487 return example_lists;
488} /* _data_new */
489
490static void
491_union_free(Example_Union *un)
492{
493 if (un->type == EET_STRUCT1)
494 {
495 Example_Struct1 *st1 = &(un->u.st1);
496 _string_free(st1->s1);
497 }
498
499 free(un);
500}
501
502static void
503_variant_free(Example_Variant *va)
504{
505 if (!strcmp(va->t.type, eet_mapping[0].name))
506 {
507 Example_Struct1 *st1 = va->data;
508 _string_free(st1->s1);
509 }
510
511 free(va->data);
512 free(va);
513}
514
515static void
516_data_free(Example_Lists *cache)
517{
518 Example_Union *un;
519 Example_Variant *va;
520
521 EINA_LIST_FREE(cache->union_list, un)
522 _union_free(un);
523
524 EINA_LIST_FREE(cache->variant_list, va)
525 _variant_free(va);
526
527 free(cache);
528} /* _data_free */
529
530static Example_Lists *
531_data_load(const char *filename)
532{
533 Example_Lists *data;
534 Eet_File *ef = eet_open(filename, EET_FILE_MODE_READ);
535 if (!ef)
536 {
537 fprintf(stderr, "ERROR: could not open '%s' for read\n", filename);
538 return NULL;
539 }
540
541 data = eet_data_read(ef, _lists_descriptor, CACHE_FILE_ENTRY);
542 if (!data)
543 {
544 eet_close(ef);
545 return NULL;
546 }
547
548 if (_cache_file)
549 eet_close(_cache_file);
550
551 _cache_file = ef;
552 _cache_dict = eet_dictionary_get(ef);
553
554 return data;
555} /* _data_load */
556
557static Eina_Bool
558_data_save(const Example_Lists *cache,
559 const char *filename)
560{
561 char tmp[PATH_MAX];
562 Eet_File *ef;
563 Eina_Bool ret;
564 unsigned int i, len;
565 struct stat st;
566
567 len = eina_strlcpy(tmp, filename, sizeof(tmp));
568 if (len + 12 >= (int)sizeof(tmp))
569 {
570 fprintf(stderr, "ERROR: file name is too big: %s\n", filename);
571 return EINA_FALSE;
572 }
573
574 i = 0;
575 do
576 {
577 snprintf(tmp + len, 12, ".%u", i);
578 i++;
579 }
580 while (stat(tmp, &st) == 0);
581
582 ef = eet_open(tmp, EET_FILE_MODE_WRITE);
583 if (!ef)
584 {
585 fprintf(stderr, "ERROR: could not open '%s' for write\n", tmp);
586 return EINA_FALSE;
587 }
588
589 ret = eet_data_write
590 (ef, _lists_descriptor, CACHE_FILE_ENTRY, cache, EINA_TRUE);
591
592 eet_close(ef);
593
594 if (ret)
595 {
596 unlink(filename);
597 rename(tmp, filename);
598 }
599
600 return ret;
601} /* _data_save */
602
603static void
604_print_union(const Example_Union *un)
605{
606 printf("\t | type: %s'\n", eet_mapping[un->type - 1].name);
607
608 switch (un->type)
609 {
610 case EET_STRUCT1:
611 printf("\t\t val1: %f\n", un->u.st1.val1);
612 printf("\t\t stuff: %d\n", un->u.st1.stuff);
613 printf("\t\t s1: %s\n", un->u.st1.s1);
614 break;
615
616 case EET_STRUCT2:
617 printf("\t\t val1: %i\n", un->u.st2.b1);
618 printf("\t\t stuff: %lli\n", un->u.st2.v1);
619 break;
620
621 case EET_STRUCT3:
622 printf("\t\t val1: %i\n", un->u.st3.body);
623 break;
624
625 default:
626 return;
627 }
628}
629
630static void
631_print_variant(const Example_Variant *va)
632{
633 printf("\t | type: %s'\n", va->t.type);
634
635 switch (va->t.type[2])
636 {
637 case '1':
638 {
639 Example_Struct1 *st1 = va->data;
640
641 printf("\t\t val1: %f\n", st1->val1);
642 printf("\t\t stuff: %d\n", st1->stuff);
643 printf("\t\t s1: %s\n", st1->s1);
644 }
645 break;
646
647 case '2':
648 {
649 Example_Struct2 *st2 = va->data;
650
651 printf("\t\t val1: %i\n", st2->b1);
652 printf("\t\t stuff: %lli\n", st2->v1);
653 }
654 break;
655
656 case '3':
657 {
658 Example_Struct3 *st3 = va->data;
659
660 printf("\t\t val1: %i\n", st3->body);
661 }
662 break;
663
664 default:
665 return;
666 }
667}
668
669int
670main(int argc,
671 char *argv[])
672{
673 Example_Lists *data_lists;
674 int ret = 0;
675
676 if (argc < 3)
677 {
678 fprintf(stderr,
679 "Usage:\n\t%s <input> <output> [action action-params]\n\n"
680 "where actions and their parameters are:\n"
681 "\tunion <type> [fields]\n"
682 "\tvariant <type> [fields]\n"
683 "\n",
684 argv[0]);
685 return -1;
686 }
687
688 eina_init();
689 eet_init();
690 _data_descriptors_init();
691
692 data_lists = _data_load(argv[1]);
693 if (!data_lists)
694 {
695 printf("Creating new data lists.\n");
696 data_lists = _data_new();
697 if (!data_lists)
698 {
699 ret = -2;
700 goto end;
701 }
702 }
703
704 if (argc > 3)
705 {
706 if (strcmp(argv[3], "union") == 0)
707 {
708 if (argc > 4)
709 {
710 int type = atoi(argv[4]);
711 Example_Union *un;
712
713 if (type < EET_STRUCT1 || type > EET_STRUCT3)
714 {
715 fprintf(stderr,
716 "ERROR: invalid type parameter (%s).\n",
717 argv[4]);
718 goto cont;
719 }
720
721 switch (type)
722 {
723 case 1:
724 if (argc != 8)
725 {
726 fprintf(
727 stderr, "ERROR: wrong number of parameters"
728 " (%d).\n", argc);
729 goto cont;
730 }
731
732 un = _union_1_new(
733 argv[5], argv[6], argv[7]);
734 if (!un)
735 {
736 fprintf(
737 stderr, "ERROR: could not create the "
738 "requested union.\n");
739 goto cont;
740 }
741 data_lists->union_list =
742 eina_list_append(data_lists->union_list, un);
743 break;
744
745 case 2:
746 if (argc != 7)
747 {
748 fprintf(
749 stderr, "ERROR: wrong number of parameters"
750 " (%d).\n", argc);
751 goto cont;
752 }
753
754 un = _union_2_new(argv[5], argv[6]);
755 if (!un)
756 {
757 fprintf(
758 stderr, "ERROR: could not create the "
759 "requested union.\n");
760 goto cont;
761 }
762 data_lists->union_list =
763 eina_list_append(data_lists->union_list, un);
764 break;
765
766 case 3:
767 if (argc != 6)
768 {
769 fprintf(
770 stderr, "ERROR: wrong number of parameters"
771 " (%d).\n", argc);
772 goto cont;
773 }
774
775 un = _union_3_new(argv[5]);
776 if (!un)
777 {
778 fprintf(
779 stderr, "ERROR: could not create the "
780 "requested union.\n");
781 goto cont;
782 }
783 data_lists->union_list =
784 eina_list_append(data_lists->union_list, un);
785 break;
786
787 default:
788 fprintf(
789 stderr, "ERROR: bad type of of struct passed\n");
790 goto cont;
791 }
792 }
793 else
794 fprintf(stderr,
795 "ERROR: wrong number of parameters (%d).\n",
796 argc);
797 }
798 else if (strcmp(argv[3], "variant") == 0)
799 {
800 if (argc > 4)
801 {
802 int type = atoi(argv[4]);
803 Example_Variant *va;
804
805 if (type < EET_STRUCT1 || type > EET_STRUCT3)
806 {
807 fprintf(stderr,
808 "ERROR: invalid type parameter (%s).\n",
809 argv[4]);
810 goto cont;
811 }
812
813 switch (type)
814 {
815 case 1:
816 if (argc != 8)
817 {
818 fprintf(
819 stderr, "ERROR: wrong number of parameters"
820 " (%d).\n", argc);
821 goto cont;
822 }
823
824 va = _variant_1_new(
825 argv[5], argv[6], argv[7]);
826 if (!va)
827 {
828 fprintf(
829 stderr, "ERROR: could not create the "
830 "requested variant.\n");
831 goto cont;
832 }
833 data_lists->variant_list =
834 eina_list_append(data_lists->variant_list, va);
835 break;
836
837 case 2:
838 if (argc != 7)
839 {
840 fprintf(
841 stderr, "ERROR: wrong number of parameters"
842 " (%d).\n", argc);
843 goto cont;
844 }
845
846 va = _variant_2_new(argv[5], argv[6]);
847 if (!va)
848 {
849 fprintf(
850 stderr, "ERROR: could not create the "
851 "requested variant.\n");
852 goto cont;
853 }
854 data_lists->variant_list =
855 eina_list_append(data_lists->variant_list, va);
856 break;
857
858 case 3:
859 if (argc != 6)
860 {
861 fprintf(
862 stderr, "ERROR: wrong number of parameters"
863 " (%d).\n", argc);
864 goto cont;
865 }
866
867 va = _variant_3_new(argv[5]);
868 if (!va)
869 {
870 fprintf(
871 stderr, "ERROR: could not create the "
872 "requested variant.\n");
873 goto cont;
874 }
875 data_lists->variant_list =
876 eina_list_append(data_lists->variant_list, va);
877 break;
878
879 default:
880 fprintf(
881 stderr, "ERROR: bad type of of struct passed\n");
882 goto cont;
883 }
884 }
885 else
886 fprintf(stderr,
887 "ERROR: wrong number of parameters (%d).\n",
888 argc);
889 }
890 else
891 fprintf(stderr, "ERROR: unknown action '%s'\n", argv[3]);
892 }
893
894cont:
895 printf("Cached data:\n");
896
897 printf("\tstats: unions=%u, variants=%u\n",
898 eina_list_count(data_lists->union_list),
899 eina_list_count(data_lists->variant_list));
900
901 if (eina_list_count(data_lists->union_list))
902 {
903 const Eina_List *l;
904 const Example_Union *un;
905 printf("\t * union list:\n");
906
907 EINA_LIST_FOREACH(data_lists->union_list, l, un)
908 {
909 _print_union(un);
910 }
911 }
912
913 if (eina_list_count(data_lists->variant_list))
914 {
915 const Eina_List *l;
916 const Example_Variant *un;
917 printf("\t * variant list:\n");
918
919 EINA_LIST_FOREACH(data_lists->variant_list, l, un)
920 {
921 _print_variant(un);
922 }
923 }
924
925 printf("\n");
926
927 if (!_data_save(data_lists, argv[2]))
928 ret = -3;
929
930 _data_free(data_lists);
931
932end:
933 if (_cache_file)
934 eet_close(_cache_file);
935 _data_descriptors_shutdown();
936 eet_shutdown();
937 eina_shutdown();
938
939 return ret;
940} /* main */
941