summaryrefslogtreecommitdiff
path: root/legacy/eet
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2009-05-14 15:58:10 +0000
committerCedric BAIL <cedric.bail@free.fr>2009-05-14 15:58:10 +0000
commitb33629872701ff795df896d0608e66082bf8a550 (patch)
tree2ddd2c8033685950bf2ff2247ecec7b2daaffa27 /legacy/eet
parenta68c953591135ed430fb8017acdcd48e648bc71a (diff)
* Eet: Cleanup eet_data dump code.
SVN revision: 40643
Diffstat (limited to 'legacy/eet')
-rw-r--r--legacy/eet/src/lib/eet_data.c595
1 files changed, 254 insertions, 341 deletions
diff --git a/legacy/eet/src/lib/eet_data.c b/legacy/eet/src/lib/eet_data.c
index 8df4b750cc..7a0d943d26 100644
--- a/legacy/eet/src/lib/eet_data.c
+++ b/legacy/eet/src/lib/eet_data.c
@@ -219,6 +219,13 @@ static void *eet_data_put_null(Eet_Dictionary *ed, const void *src, int *size_re
219static int eet_data_get_type(const Eet_Dictionary *ed, int type, const void *src, const void *src_end, void *dest); 219static int eet_data_get_type(const Eet_Dictionary *ed, int type, const void *src, const void *src_end, void *dest);
220static void *eet_data_put_type(Eet_Dictionary *ed, int type, const void *src, int *size_ret); 220static void *eet_data_put_type(Eet_Dictionary *ed, int type, const void *src, int *size_ret);
221 221
222static void eet_data_dump_group_start(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, int group_type, const char *name);
223static void eet_data_dump_group_end(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
224static void eet_data_dump_level(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
225static void eet_data_dump_simple_type(int type, const char *name, void *dd,
226 int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata);
227
228
222static int eet_data_get_unknown(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk, int type, int group_type, void *data_in, int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, char **p, int *size); 229static int eet_data_get_unknown(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk, int type, int group_type, void *data_in, int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, char **p, int *size);
223static void eet_data_put_unknown(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in); 230static void eet_data_put_unknown(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
224static void eet_data_put_array(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in); 231static void eet_data_put_array(Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Stream *ds, void *data_in);
@@ -732,31 +739,17 @@ eet_data_chunk_get(const Eet_Dictionary *ed, Eet_Data_Chunk *chnk,
732 const char *s; 739 const char *s;
733 int ret1, ret2; 740 int ret1, ret2;
734 741
735 if (!src) 742 if (!src) return;
736 { 743 if (size <= 8) return;
737 fprintf(stderr, "stiouf -3\n");
738 return;
739 }
740 if (size <= 8)
741 {
742 fprintf(stderr, "stiouf -2 %i\n", size);
743 return;
744 }
745 744
746 if (!chnk) 745 if (!chnk) return;
747 {
748 fprintf(stderr, "stiouf -1\n");
749 return;
750 }
751 746
752 s = src; 747 s = src;
753 if (s[2] == 'K') 748 if (s[2] == 'K')
754 { 749 {
755 if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'K')) 750 if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'K'))
756 { 751 return;
757 fprintf(stderr, "stiouf 0\n"); 752
758 return;
759 }
760 chnk->type = (unsigned char)(s[3]); 753 chnk->type = (unsigned char)(s[3]);
761 if (chnk->type > EET_T_LAST) 754 if (chnk->type > EET_T_LAST)
762 { 755 {
@@ -775,28 +768,13 @@ eet_data_chunk_get(const Eet_Dictionary *ed, Eet_Data_Chunk *chnk,
775 else 768 else
776 { 769 {
777 if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'n') || (s[3] != 'K')) 770 if ((s[0] != 'C') || (s[1] != 'H') || (s[2] != 'n') || (s[3] != 'K'))
778 { 771 return;
779 fprintf(stderr, "stiouf 1\n");
780 return;
781 }
782 } 772 }
783 ret1 = eet_data_get_type(ed, EET_T_INT, (s + 4), (s + size), &(chnk->size)); 773 ret1 = eet_data_get_type(ed, EET_T_INT, (s + 4), (s + size), &(chnk->size));
784 if (ret1 <= 0) 774 if (ret1 <= 0) return;
785 { 775 if ((chnk->size < 0) || ((chnk->size + 8) > size)) return;
786 fprintf(stderr, "stiouf 2\n");
787 return;
788 }
789 if ((chnk->size < 0) || ((chnk->size + 8) > size))
790 {
791 fprintf(stderr, "stiouf 3\n");
792 return;
793 }
794 ret2 = eet_data_get_type(ed, EET_T_STRING, (s + 8), (s + size), &(chnk->name)); 776 ret2 = eet_data_get_type(ed, EET_T_STRING, (s + 8), (s + size), &(chnk->name));
795 if (ret2 <= 0) 777 if (ret2 <= 0) return;
796 {
797 fprintf(stderr, "stiouf 4\n");
798 return;
799 }
800 778
801 chnk->len = ret2; 779 chnk->len = ret2;
802 780
@@ -2199,7 +2177,7 @@ _eet_data_descriptor_decode(Eet_Free_Context *context,
2199 void *dumpdata) 2177 void *dumpdata)
2200{ 2178{
2201 void *data = NULL; 2179 void *data = NULL;
2202 char *p, tbuf[256]; 2180 char *p;
2203 int size, i, dump; 2181 int size, i, dump;
2204 int chnk_type; 2182 int chnk_type;
2205 Eet_Data_Chunk chnk; 2183 Eet_Data_Chunk chnk;
@@ -2247,23 +2225,15 @@ _eet_data_descriptor_decode(Eet_Free_Context *context,
2247 { 2225 {
2248 dump = 1; 2226 dump = 1;
2249 if (chnk.type == EET_T_UNKNOW) 2227 if (chnk.type == EET_T_UNKNOW)
2250 { 2228 eet_data_dump_group_start(level, dumpfunc, dumpdata, chnk.group_type, chnk.name);
2251 for (i = 0; i < level; i++) dumpfunc(dumpdata, " ");
2252 dumpfunc(dumpdata, "group \"");
2253 _eet_data_dump_string_escape(dumpdata, dumpfunc, chnk.name);
2254 dumpfunc(dumpdata, "\" ");
2255
2256 chnk_type = (chnk.group_type >= EET_G_UNKNOWN && chnk.group_type <= EET_G_HASH) ?
2257 chnk.group_type : EET_G_LAST;
2258
2259 dumpfunc(dumpdata, _dump_g_name[chnk_type - EET_G_UNKNOWN]);
2260 dumpfunc(dumpdata, " {\n");
2261 }
2262 } 2229 }
2263 while (size > 0) 2230 while (size > 0)
2264 { 2231 {
2265 Eet_Data_Chunk echnk; 2232 Eet_Data_Chunk echnk;
2266 Eet_Data_Element *ede; 2233 Eet_Data_Element *ede = NULL;
2234 unsigned char dd[128];
2235 int group_type = EET_G_UNKNOWN, type = EET_T_UNKNOW;
2236 int ret = 0;
2267 2237
2268 /* get next data chunk */ 2238 /* get next data chunk */
2269 memset(&echnk, 0, sizeof(Eet_Data_Chunk)); 2239 memset(&echnk, 0, sizeof(Eet_Data_Chunk));
@@ -2275,9 +2245,6 @@ _eet_data_descriptor_decode(Eet_Free_Context *context,
2275 ede = _eet_descriptor_hash_find(edd, echnk.name, echnk.hash); 2245 ede = _eet_descriptor_hash_find(edd, echnk.name, echnk.hash);
2276 if (ede) 2246 if (ede)
2277 { 2247 {
2278 int group_type = EET_G_UNKNOWN, type = EET_T_UNKNOW;
2279 int ret = 0;
2280
2281 group_type = ede->group_type; 2248 group_type = ede->group_type;
2282 type = ede->type; 2249 type = ede->type;
2283 if ((echnk.type == 0) && (echnk.group_type == 0)) 2250 if ((echnk.type == 0) && (echnk.group_type == 0))
@@ -2295,240 +2262,38 @@ _eet_data_descriptor_decode(Eet_Free_Context *context,
2295 (echnk.group_type == ede->group_type)) 2262 (echnk.group_type == ede->group_type))
2296 group_type = echnk.group_type; 2263 group_type = echnk.group_type;
2297 } 2264 }
2298 /* hashes doesnt fit well with the table */
2299 ret = eet_group_codec[group_type - 100].get(context, ed, edd, ede, &echnk, type, group_type, ((char *)data) + ede->offset, level, dumpfunc, dumpdata, &p, &size);
2300 if (ret <= 0) goto error;
2301 } 2265 }
2302 } 2266 }
2303 /*...... dump func */ 2267 /*...... dump func */
2304 else if (dumpfunc) 2268 else if (dumpfunc)
2305 { 2269 {
2306 unsigned char dd[128];
2307 int group_type = EET_G_UNKNOWN, type = EET_T_UNKNOW;
2308
2309 if ((echnk.type > EET_T_UNKNOW) && 2270 if ((echnk.type > EET_T_UNKNOW) &&
2310 (echnk.type < EET_T_LAST)) 2271 (echnk.type < EET_T_LAST))
2311 type = echnk.type; 2272 type = echnk.type;
2312 else if ((echnk.group_type > EET_G_UNKNOWN) && 2273 else if ((echnk.group_type > EET_G_UNKNOWN) &&
2313 (echnk.group_type < EET_G_LAST)) 2274 (echnk.group_type < EET_G_LAST))
2314 group_type = echnk.group_type; 2275 group_type = echnk.group_type;
2315 if (group_type == EET_G_UNKNOWN) 2276 }
2316 {
2317 int ret;
2318 void *data_ret;
2319
2320 if (IS_SIMPLE_TYPE(type))
2321 {
2322 const char *type_name = NULL;
2323
2324 ret = eet_data_get_type(ed,
2325 type,
2326 echnk.data,
2327 ((char *)echnk.data) + echnk.size,
2328 dd);
2329 if (ret <= 0) goto error;
2330
2331 for (i = 0; i < level; i++) dumpfunc(dumpdata, " ");
2332 dumpfunc(dumpdata, " value \"");
2333 _eet_data_dump_string_escape(dumpdata, dumpfunc, echnk.name);
2334 dumpfunc(dumpdata, "\" ");
2335
2336#define EET_T_TYPE(Eet_Type, Type) \
2337 case Eet_Type: \
2338 { \
2339 dumpfunc(dumpdata, _dump_t_name[Eet_Type][0]); \
2340 snprintf(tbuf, sizeof (tbuf), _dump_t_name[Eet_Type][1], *((Type *)dd)); \
2341 dumpfunc(dumpdata, tbuf); \
2342 break; \
2343 }
2344
2345 switch (type)
2346 {
2347 EET_T_TYPE(EET_T_CHAR, char);
2348 EET_T_TYPE(EET_T_SHORT, short);
2349 EET_T_TYPE(EET_T_INT, int);
2350 EET_T_TYPE(EET_T_LONG_LONG, long long);
2351 EET_T_TYPE(EET_T_FLOAT, float);
2352 EET_T_TYPE(EET_T_DOUBLE, double);
2353 EET_T_TYPE(EET_T_UCHAR, unsigned char);
2354 EET_T_TYPE(EET_T_USHORT, unsigned short);
2355 EET_T_TYPE(EET_T_UINT, unsigned int);
2356 EET_T_TYPE(EET_T_ULONG_LONG, unsigned long long);
2357 case EET_T_INLINED_STRING:
2358 type_name = "inlined: \"";
2359 case EET_T_STRING:
2360 if (!type_name) type_name = "string: \"";
2361
2362 {
2363 char *s;
2364
2365 s = *((char **)dd);
2366 if (s)
2367 {
2368 dumpfunc(dumpdata, type_name);
2369 _eet_data_dump_string_escape(dumpdata, dumpfunc, s);
2370 dumpfunc(dumpdata, "\"");
2371 }
2372 }
2373 break;
2374 case EET_T_NULL:
2375 dumpfunc(dumpdata, "null");
2376 break;
2377 default:
2378 dumpfunc(dumpdata, "???: ???"); break;
2379 break;
2380 }
2381 dumpfunc(dumpdata, ";\n");
2382 }
2383 else
2384 {
2385 data_ret = _eet_data_descriptor_decode(context,
2386 ed,
2387 NULL,
2388 echnk.data,
2389 echnk.size,
2390 level + 1,
2391 dumpfunc,
2392 dumpdata);
2393 if (!data_ret) goto error;
2394 }
2395 }
2396 else
2397 {
2398 for (i = 0; i < level; i++) dumpfunc(dumpdata, " ");
2399 dumpfunc(dumpdata, " group \"");
2400 _eet_data_dump_string_escape(dumpdata, dumpfunc, echnk.name);
2401 dumpfunc(dumpdata, "\" ");
2402
2403 chnk_type = (echnk.group_type >= EET_G_UNKNOWN && echnk.group_type <= EET_G_HASH) ?
2404 echnk.group_type : EET_G_LAST;
2405 2277
2406 dumpfunc(dumpdata, _dump_g_name[chnk_type - EET_G_UNKNOWN]); 2278 if (dumpfunc && group_type == EET_G_UNKNOWN && IS_SIMPLE_TYPE(type))
2407 dumpfunc(dumpdata, " {\n"); 2279 {
2408 switch (group_type) 2280 ret = eet_data_get_type(ed,
2409 { 2281 type,
2410 case EET_G_ARRAY: 2282 echnk.data,
2411 case EET_G_VAR_ARRAY: 2283 ((char *)echnk.data) + echnk.size,
2412 { 2284 dd);
2413 int count; 2285 if (ret <= 0) goto error;
2414 int ret; 2286
2415 int i; 2287 eet_data_dump_simple_type(type, echnk.name, dd, level, dumpfunc, dumpdata);
2416 2288 }
2417 EET_ASSERT(!IS_SIMPLE_TYPE(type), goto error); 2289 else
2418 2290 {
2419 ret = eet_data_get_type(ed, 2291 ret = eet_group_codec[group_type - 100].get(context,
2420 EET_T_INT, 2292 ed, edd, ede, &echnk,
2421 echnk.data, 2293 type, group_type, ede ? ((char *)data) + ede->offset : dd,
2422 ((char *)echnk.data) + echnk.size, 2294 level, dumpfunc, dumpdata,
2423 &count); 2295 &p, &size);
2424 if (ret <= 0) goto error; 2296 if (ret <= 0) goto error;
2425
2426 for (i = 0; i < level; i++) dumpfunc(dumpdata, " ");
2427 dumpfunc(dumpdata, " count ");
2428 snprintf(tbuf, sizeof(tbuf), "%i", count);
2429 dumpfunc(dumpdata, tbuf);
2430 dumpfunc(dumpdata, ";\n");
2431
2432 /* get all array elements */
2433 for (i = 0; i < count; i++)
2434 {
2435 void *data_ret = NULL;
2436
2437 /* Advance to next chunk */
2438 NEXT_CHUNK(p, size, echnk, ed);
2439 memset(&echnk, 0, sizeof(Eet_Data_Chunk));
2440
2441 eet_data_chunk_get(ed, &echnk, p, size);
2442 if (!echnk.name) goto error;
2443 /* get the data */
2444 data_ret = _eet_data_descriptor_decode(context,
2445 ed,
2446 NULL,
2447 echnk.data,
2448 echnk.size,
2449 level + 2,
2450 dumpfunc,
2451 dumpdata);
2452 if (!data_ret) goto error;
2453 }
2454 }
2455 break;
2456 case EET_G_LIST:
2457 {
2458 void *data_ret = NULL;
2459
2460 EET_ASSERT(!IS_SIMPLE_TYPE(type), goto error);
2461
2462 data_ret = _eet_data_descriptor_decode(context,
2463 ed,
2464 NULL,
2465 echnk.data,
2466 echnk.size,
2467 level + 2,
2468 dumpfunc,
2469 dumpdata);
2470 if (!data_ret) goto error;
2471 }
2472 break;
2473 case EET_G_HASH:
2474 {
2475 int ret;
2476 char *key = NULL;
2477 void *data_ret = NULL;
2478
2479 /* Read key */
2480 ret = eet_data_get_type(ed,
2481 EET_T_STRING,
2482 echnk.data,
2483 ((char *)echnk.data) + echnk.size,
2484 &key);
2485 if (ret <= 0) goto error;
2486
2487 /* Advance to next chunk */
2488 NEXT_CHUNK(p, size, echnk, ed);
2489 memset(&echnk, 0, sizeof(Eet_Data_Chunk));
2490
2491 /* Read value */
2492 eet_data_chunk_get(ed, &echnk, p, size);
2493 if (!echnk.name) goto error;
2494
2495 EET_ASSERT(!IS_SIMPLE_TYPE(type), goto error);
2496
2497 {
2498 char *s;
2499
2500 s = key;
2501 if (s)
2502 {
2503 for (i = 0; i < level; i++) dumpfunc(dumpdata, " ");
2504 dumpfunc(dumpdata, " key \"");
2505 _eet_data_dump_string_escape(dumpdata, dumpfunc, s);
2506 dumpfunc(dumpdata, "\";\n");
2507 }
2508 data_ret = _eet_data_descriptor_decode(context,
2509 ed,
2510 NULL,
2511 echnk.data,
2512 echnk.size,
2513 level + 2,
2514 dumpfunc,
2515 dumpdata);
2516 }
2517 if (!data_ret)
2518 {
2519 goto error;
2520 }
2521 }
2522 break;
2523 default:
2524 break;
2525 }
2526 if (dumpfunc)
2527 {
2528 for (i = 0; i < level; i++) dumpfunc(dumpdata, " ");
2529 dumpfunc(dumpdata, " }\n");
2530 }
2531 }
2532 } 2297 }
2533 /* advance to next chunk */ 2298 /* advance to next chunk */
2534 NEXT_CHUNK(p, size, echnk, ed); 2299 NEXT_CHUNK(p, size, echnk, ed);
@@ -2588,39 +2353,91 @@ error:
2588 return NULL; 2353 return NULL;
2589} 2354}
2590 2355
2356static void
2357eet_data_dump_level(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata)
2358{
2359 int i;
2360
2361 for (i = 0; i < level; i++) dumpfunc(dumpdata, " ");
2362}
2363
2364static void
2365eet_data_dump_group_start(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
2366 int group_type, const char *name)
2367{
2368 int chnk_type;
2369
2370 chnk_type = (group_type >= EET_G_UNKNOWN && group_type <= EET_G_HASH) ?
2371 group_type : EET_G_LAST;
2372
2373 eet_data_dump_level(level, dumpfunc, dumpdata);
2374 dumpfunc(dumpdata, "group \"");
2375 _eet_data_dump_string_escape(dumpdata, dumpfunc, name);
2376 dumpfunc(dumpdata, "\" ");
2377
2378 dumpfunc(dumpdata, _dump_g_name[chnk_type - EET_G_UNKNOWN]);
2379 dumpfunc(dumpdata, " {\n");
2380}
2381
2382static void
2383eet_data_dump_group_end(int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata)
2384{
2385 eet_data_dump_level(level, dumpfunc, dumpdata);
2386 dumpfunc(dumpdata, " }\n");
2387}
2388
2591static int 2389static int
2592eet_data_get_list(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk, 2390eet_data_get_list(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk,
2593 int type __UNUSED__, int group_type __UNUSED__, void *data, 2391 int type, int group_type __UNUSED__, void *data,
2594 int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata, 2392 int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata,
2595 char **p __UNUSED__, int *size __UNUSED__) 2393 char **p, int *size)
2596{ 2394{
2395 Eet_Data_Descriptor *subtype = NULL;
2597 void *list = NULL; 2396 void *list = NULL;
2598 void **ptr; 2397 void **ptr;
2599 void *data_ret; 2398 void *data_ret;
2399 int et = EET_T_UNKNOW;
2600 2400
2601 EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0); 2401 EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);
2602 2402
2403 if (edd)
2404 {
2405 subtype = ede->subtype;
2406 et = ede->type;
2407 }
2408 else if (dumpfunc)
2409 {
2410 eet_data_dump_group_start(level + 1, dumpfunc, dumpdata, echnk->group_type, echnk->name);
2411 }
2412
2603 ptr = (void **)data; 2413 ptr = (void **)data;
2604 list = *ptr; 2414 list = *ptr;
2605 data_ret = NULL; 2415 data_ret = NULL;
2606 2416
2607 if (ede->type >= EET_T_STRING) 2417 if (et >= EET_T_STRING)
2608 { 2418 {
2609 int ret; 2419 int ret;
2610 2420
2611 ret = eet_data_get_unknown(context, ed, edd, ede, echnk, ede->type, EET_G_UNKNOWN, 2421 ret = eet_data_get_unknown(context, ed, edd, ede, echnk, et, EET_G_UNKNOWN,
2612 &data_ret, level, dumpfunc, dumpdata, p, size); 2422 &data_ret, level, dumpfunc, dumpdata, p, size);
2613 if (!ret) return 0; 2423 if (!ret) return 0;
2614 } 2424 }
2615 else 2425 else
2616 { 2426 {
2617 data_ret = _eet_data_descriptor_decode(context, ed, ede->subtype, echnk->data, echnk->size, level + 2, dumpfunc, dumpdata); 2427 data_ret = _eet_data_descriptor_decode(context, ed, subtype,
2428 echnk->data, echnk->size,
2429 level + 2, dumpfunc, dumpdata);
2618 if (!data_ret) return 0; 2430 if (!data_ret) return 0;
2619 } 2431 }
2620 2432
2621 list = edd->func.list_append(list, data_ret); 2433 if (edd)
2622 *ptr = list; 2434 {
2623 _eet_freelist_list_add(context, ptr); 2435 list = edd->func.list_append(list, data_ret);
2436 *ptr = list;
2437 _eet_freelist_list_add(context, ptr);
2438 }
2439 else if (dumpfunc)
2440 eet_data_dump_group_end(level, dumpfunc, dumpdata);
2624 2441
2625 return 1; 2442 return 1;
2626} 2443}
@@ -2658,11 +2475,21 @@ eet_data_get_hash(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_
2658 eet_data_chunk_get(ed, echnk, *p, *size); 2475 eet_data_chunk_get(ed, echnk, *p, *size);
2659 if (!echnk->name) goto on_error; 2476 if (!echnk->name) goto on_error;
2660 2477
2478 if (dumpfunc && key)
2479 {
2480 eet_data_dump_group_start(level + 1, dumpfunc, dumpdata, echnk->group_type, echnk->name);
2481
2482 eet_data_dump_level(level, dumpfunc, dumpdata);
2483 dumpfunc(dumpdata, " key \"");
2484 _eet_data_dump_string_escape(dumpdata, dumpfunc, key);
2485 dumpfunc(dumpdata, "\";\n");
2486 }
2487
2661 if (type >= EET_T_STRING) 2488 if (type >= EET_T_STRING)
2662 { 2489 {
2663 int ret; 2490 int ret;
2664 2491
2665 ret = eet_data_get_unknown(context, ed, edd, ede, echnk, ede->type, EET_G_UNKNOWN, 2492 ret = eet_data_get_unknown(context, ed, edd, ede, echnk, ede ? ede->type : type, EET_G_UNKNOWN,
2666 &data_ret, level, dumpfunc, dumpdata, p, size); 2493 &data_ret, level, dumpfunc, dumpdata, p, size);
2667 if (!ret) return 0; 2494 if (!ret) return 0;
2668 } 2495 }
@@ -2670,7 +2497,7 @@ eet_data_get_hash(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_
2670 { 2497 {
2671 data_ret = _eet_data_descriptor_decode(context, 2498 data_ret = _eet_data_descriptor_decode(context,
2672 ed, 2499 ed,
2673 ede->subtype, 2500 ede ? ede->subtype : NULL,
2674 echnk->data, 2501 echnk->data,
2675 echnk->size, 2502 echnk->size,
2676 level + 2, 2503 level + 2,
@@ -2679,9 +2506,15 @@ eet_data_get_hash(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_
2679 if (!data_ret) goto on_error; 2506 if (!data_ret) goto on_error;
2680 } 2507 }
2681 2508
2682 hash = edd->func.hash_add(hash, key, data_ret); 2509 if (edd)
2683 *ptr = hash; 2510 {
2684 _eet_freelist_hash_add(context, ptr); 2511 hash = edd->func.hash_add(hash, key, data_ret);
2512 *ptr = hash;
2513 _eet_freelist_hash_add(context, ptr);
2514 }
2515 else if (dumpfunc)
2516 eet_data_dump_group_end(level, dumpfunc, dumpdata);
2517
2685 return 1; 2518 return 1;
2686 2519
2687 on_error: 2520 on_error:
@@ -2709,7 +2542,7 @@ eet_data_get_array(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data
2709 void *ptr; 2542 void *ptr;
2710 int count; 2543 int count;
2711 int ret; 2544 int ret;
2712 int subsize; 2545 int subsize = 0;
2713 int i; 2546 int i;
2714 2547
2715 EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0); 2548 EET_ASSERT(!((type > EET_T_UNKNOW) && (type < EET_T_STRING)), return 0);
@@ -2723,32 +2556,47 @@ eet_data_get_array(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data
2723 &count); 2556 &count);
2724 if (ret <= 0) return ret; 2557 if (ret <= 0) return ret;
2725 2558
2726 if (type >= EET_T_STRING)
2727 subsize = eet_basic_codec[ede->type].size;
2728 else
2729 subsize = ede->subtype->size;
2730
2731 name = echnk->name; 2559 name = echnk->name;
2732 2560
2733 if (group_type == EET_G_VAR_ARRAY) 2561 if (ede)
2734 { 2562 {
2735 /* store the number of elements 2563 if (type >= EET_T_STRING)
2736 * on the counter offset */ 2564 subsize = eet_basic_codec[ede->type].size;
2737 *(int *)(((char *)data) + ede->count - ede->offset) = count; 2565 else
2738 /* allocate space for the array of elements */ 2566 subsize = ede->subtype->size;
2739 *(void **)ptr = edd->func.mem_alloc(count * subsize); 2567
2568 if (group_type == EET_G_VAR_ARRAY)
2569 {
2570 /* store the number of elements
2571 * on the counter offset */
2572 *(int *)(((char *)data) + ede->count - ede->offset) = count;
2573 /* allocate space for the array of elements */
2574 *(void **)ptr = edd->func.mem_alloc(count * subsize);
2575
2576 if (!*(void **)ptr) return 0;
2577
2578 memset(*(void **)ptr, 0, count * subsize);
2740 2579
2741 if (!*(void **)ptr) return 0; 2580 _eet_freelist_add(context, *(void **)ptr);
2581 }
2582 }
2583 else
2584 {
2585 char tbuf[256];
2742 2586
2743 memset(*(void **)ptr, 0, count * subsize); 2587 eet_data_dump_group_start(level + 1, dumpfunc, dumpdata, echnk->group_type, echnk->name);
2744 2588
2745 _eet_freelist_add(context, *(void **)ptr); 2589 eet_data_dump_level(level, dumpfunc, dumpdata);
2590 dumpfunc(dumpdata, " count ");
2591 eina_convert_itoa(count, tbuf);
2592 dumpfunc(dumpdata, tbuf);
2593 dumpfunc(dumpdata, ";\n");
2746 } 2594 }
2747 2595
2748 /* get all array elements */ 2596 /* get all array elements */
2749 for (i = 0; i < count; i++) 2597 for (i = 0; i < count; i++)
2750 { 2598 {
2751 void *dst; 2599 void *dst = NULL;
2752 void *data_ret = NULL; 2600 void *data_ret = NULL;
2753 2601
2754 /* Advance to next chunk */ 2602 /* Advance to next chunk */
@@ -2760,49 +2608,103 @@ eet_data_get_array(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data
2760 /* get the data */ 2608 /* get the data */
2761 2609
2762 /* get the destination pointer */ 2610 /* get the destination pointer */
2763 if (group_type == EET_G_ARRAY) 2611 if (ede)
2764 dst = (char *)ptr + (subsize * i); 2612 {
2765 else 2613 if (group_type == EET_G_ARRAY)
2766 dst = *(char **)ptr + (subsize * i); 2614 dst = (char *)ptr + (subsize * i);
2615 else
2616 dst = *(char **)ptr + (subsize * i);
2617 }
2767 2618
2768 if (type >= EET_T_STRING) 2619 if (type >= EET_T_STRING)
2769 { 2620 {
2770 int ret; 2621 int ret;
2771 2622
2772 ret = eet_data_get_unknown(context, 2623 ret = eet_data_get_unknown(context, ed, edd, ede, echnk, ede ? ede->type : type, EET_G_UNKNOWN,
2773 ed, 2624 &data_ret, level, dumpfunc, dumpdata, p, size);
2774 edd,
2775 ede,
2776 echnk,
2777 ede->type,
2778 EET_G_UNKNOWN,
2779 &data_ret,
2780 level,
2781 dumpfunc,
2782 dumpdata,
2783 p,
2784 size);
2785 if (!ret) return 0; 2625 if (!ret) return 0;
2786 memcpy(dst, &data_ret, subsize); 2626 if (dst) memcpy(dst, &data_ret, subsize);
2787 } 2627 }
2788 else 2628 else
2789 { 2629 {
2790 data_ret = _eet_data_descriptor_decode(context, 2630 data_ret = _eet_data_descriptor_decode(context, ed, ede ? ede->subtype : NULL,
2791 ed, 2631 echnk->data, echnk->size,
2792 ede->subtype, 2632 level + 2, dumpfunc, dumpdata);
2793 echnk->data,
2794 echnk->size,
2795 level + 2,
2796 dumpfunc,
2797 dumpdata);
2798 if (!data_ret) return 0; 2633 if (!data_ret) return 0;
2799 memcpy(dst, data_ret, subsize); 2634 if (dst)
2800 _eet_freelist_add(context, data_ret); 2635 {
2636 memcpy(dst, data_ret, subsize);
2637 _eet_freelist_add(context, data_ret);
2638 }
2801 } 2639 }
2802 } 2640 }
2641
2642 if (dumpfunc)
2643 eet_data_dump_group_end(level, dumpfunc, dumpdata);
2644
2803 return 1; 2645 return 1;
2804} 2646}
2805 2647
2648static void
2649eet_data_dump_simple_type(int type, const char *name, void *dd,
2650 int level, void (*dumpfunc) (void *data, const char *str), void *dumpdata)
2651{
2652 const char *type_name = NULL;
2653 char tbuf[256];
2654
2655 eet_data_dump_level(level, dumpfunc, dumpdata);
2656 dumpfunc(dumpdata, " value \"");
2657 _eet_data_dump_string_escape(dumpdata, dumpfunc, name);
2658 dumpfunc(dumpdata, "\" ");
2659
2660#define EET_T_TYPE(Eet_Type, Type) \
2661 case Eet_Type: \
2662 { \
2663 dumpfunc(dumpdata, _dump_t_name[Eet_Type][0]); \
2664 snprintf(tbuf, sizeof (tbuf), _dump_t_name[Eet_Type][1], *((Type *)dd)); \
2665 dumpfunc(dumpdata, tbuf); \
2666 break; \
2667 }
2668
2669 switch (type)
2670 {
2671 EET_T_TYPE(EET_T_CHAR, char);
2672 EET_T_TYPE(EET_T_SHORT, short);
2673 EET_T_TYPE(EET_T_INT, int);
2674 EET_T_TYPE(EET_T_LONG_LONG, long long);
2675 EET_T_TYPE(EET_T_FLOAT, float);
2676 EET_T_TYPE(EET_T_DOUBLE, double);
2677 EET_T_TYPE(EET_T_UCHAR, unsigned char);
2678 EET_T_TYPE(EET_T_USHORT, unsigned short);
2679 EET_T_TYPE(EET_T_UINT, unsigned int);
2680 EET_T_TYPE(EET_T_ULONG_LONG, unsigned long long);
2681 case EET_T_INLINED_STRING:
2682 type_name = "inlined: \"";
2683 case EET_T_STRING:
2684 if (!type_name) type_name = "string: \"";
2685
2686 {
2687 char *s;
2688
2689 s = *((char **)dd);
2690 if (s)
2691 {
2692 dumpfunc(dumpdata, type_name);
2693 _eet_data_dump_string_escape(dumpdata, dumpfunc, s);
2694 dumpfunc(dumpdata, "\"");
2695 }
2696 }
2697 break;
2698 case EET_T_NULL:
2699 dumpfunc(dumpdata, "null");
2700 break;
2701 default:
2702 dumpfunc(dumpdata, "???: ???"); break;
2703 break;
2704 }
2705 dumpfunc(dumpdata, ";\n");
2706}
2707
2806static int 2708static int
2807eet_data_get_unknown(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk, 2709eet_data_get_unknown(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data_Descriptor *edd, Eet_Data_Element *ede, Eet_Data_Chunk *echnk,
2808 int type, int group_type __UNUSED__, void *data, 2710 int type, int group_type __UNUSED__, void *data,
@@ -2817,7 +2719,11 @@ eet_data_get_unknown(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Da
2817 ret = eet_data_get_type(ed, type, echnk->data, ((char *)echnk->data) + echnk->size, ((char *)data)); 2719 ret = eet_data_get_type(ed, type, echnk->data, ((char *)echnk->data) + echnk->size, ((char *)data));
2818 if (ret <= 0) return ret; 2720 if (ret <= 0) return ret;
2819 2721
2820 if (type == EET_T_STRING) 2722 if (!edd && dumpfunc)
2723 {
2724 eet_data_dump_simple_type(type, echnk->name, data, level, dumpfunc, dumpdata);
2725 }
2726 else if (type == EET_T_STRING)
2821 { 2727 {
2822 char **str; 2728 char **str;
2823 2729
@@ -2848,15 +2754,22 @@ eet_data_get_unknown(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Da
2848 } 2754 }
2849 } 2755 }
2850 } 2756 }
2851 else if (ede->subtype) 2757 else
2852 { 2758 {
2853 void **ptr; 2759 Eet_Data_Descriptor *subtype;
2854 2760
2855 data_ret = _eet_data_descriptor_decode(context, ed, ede->subtype, echnk->data, echnk->size, level + 1, dumpfunc, dumpdata); 2761 subtype = ede ? ede->subtype : NULL;
2856 if (!data_ret) return 0;
2857 2762
2858 ptr = (void **)(((char *)data)); 2763 if (subtype || dumpfunc)
2859 *ptr = (void *)data_ret; 2764 {
2765 void **ptr;
2766
2767 data_ret = _eet_data_descriptor_decode(context, ed, subtype, echnk->data, echnk->size, level + 1, dumpfunc, dumpdata);
2768 if (!data_ret) return 0;
2769
2770 ptr = (void **)(((char *)data));
2771 *ptr = (void *)data_ret;
2772 }
2860 } 2773 }
2861 2774
2862 return 1; 2775 return 1;