17 # define alloca __builtin_alloca
19 # define alloca __alloca
20 # elif defined _MSC_VER
22 # define alloca _alloca
23 # elif !defined HAVE_ALLOCA
27 void *alloca (size_t);
36 #include <Ecore_Evas.h>
39 #include "edje_convert.h"
40 #include "edje_multisense_convert.h"
45 typedef struct _External_Lookup External_Lookup;
46 typedef struct _Part_Lookup Part_Lookup;
47 typedef struct _Program_Lookup Program_Lookup;
48 typedef struct _Group_Lookup Group_Lookup;
49 typedef struct _Image_Lookup Image_Lookup;
50 typedef struct _Slave_Lookup Slave_Lookup;
51 typedef struct _Code_Lookup Code_Lookup;
54 struct _External_Lookup
61 Edje_Part_Collection *pc;
66 struct _Program_Lookup
68 Edje_Part_Collection *pc;
78 Eina_Bool anonymous : 1;
114 typedef struct _Script_Lua_Writer Script_Lua_Writer;
116 struct _Script_Lua_Writer
122 typedef struct _Script_Write Script_Write;;
123 typedef struct _Head_Write Head_Write;
124 typedef struct _Fonts_Write Fonts_Write;
125 typedef struct _Image_Write Image_Write;
126 typedef struct _Sound_Write Sound_Write;
127 typedef struct _Group_Write Group_Write;
135 int tmpn_fd, tmpo_fd;
157 Edje_Image_Directory_Entry *img;
169 Edje_Sound_Sample *sample;
176 Edje_Part_Collection *pc;
180 static int pending_threads = 0;
182 static void data_process_string(Edje_Part_Collection *pc, const char *prefix, char *s, void (*func)(Edje_Part_Collection *pc, char *name, char* ptr, int len));
184 Edje_File *edje_file = NULL;
185 Eina_List *edje_collections = NULL;
186 Eina_Hash *edje_collections_lookup = NULL;
187 Eina_List *externals = NULL;
188 Eina_List *fonts = NULL;
189 Eina_List *codes = NULL;
190 Eina_List *code_lookups = NULL;
191 Eina_List *aliases = NULL;
193 static Eet_Data_Descriptor *edd_edje_file = NULL;
194 static Eet_Data_Descriptor *edd_edje_part_collection = NULL;
196 static Eina_List *program_lookups = NULL;
197 static Eina_List *group_lookups = NULL;
198 static Eina_List *image_lookups = NULL;
199 static Eina_List *part_slave_lookups = NULL;
200 static Eina_List *image_slave_lookups= NULL;
202 static Eina_Hash *part_dest_lookup = NULL;
203 static Eina_Hash *part_pc_dest_lookup = NULL;
206 error_and_abort(Eet_File *ef __UNUSED__, const char *fmt, ...)
211 eina_log_vprint(_edje_cc_log_dom, EINA_LOG_LEVEL_CRITICAL,
212 "unknown", "unknown", 0, fmt, ap);
215 if (watchfile) unlink(watchfile);
220 _double_pointer_key_length(const void *key __UNUSED__)
222 return sizeof (void*) * 2;
226 _double_pointer_key_cmp(const void *key1, int key1_length,
227 const void *key2, int key2_length __UNUSED__)
229 return memcmp(key1, key2, key1_length);
233 _double_pointer_key_hash(const void *key, int key_length __UNUSED__)
236 return eina_hash_int64(key, sizeof (void*)) ^
237 eina_hash_int64((void*)(((unsigned char*) key) + sizeof (void*)), sizeof (void*));
239 /* double 32 bits pointer is ... 64bits awesome ! */
240 return eina_hash_int64(key, key_length);
245 data_part_lookup_free(Part_Lookup *pl)
254 edd_edje_file = _edje_edd_edje_file;
255 edd_edje_part_collection = _edje_edd_edje_part_collection;
257 part_dest_lookup = eina_hash_pointer_new(EINA_FREE_CB(eina_list_free));
258 part_pc_dest_lookup = eina_hash_new(EINA_KEY_LENGTH(_double_pointer_key_length),
259 EINA_KEY_CMP(_double_pointer_key_cmp),
260 EINA_KEY_HASH(_double_pointer_key_hash),
261 EINA_FREE_CB(data_part_lookup_free),
266 check_image_part_desc(Edje_Part_Collection *pc, Edje_Part *ep,
267 Edje_Part_Description_Image *epd, Eet_File *ef)
271 if (epd->image.id == -1 && epd->common.visible)
272 WRN("Collection %s(%i): image attributes missing for "
273 "part \"%s\", description \"%s\" %f",
274 pc->part, pc->id, ep->name, epd->common.state.name, epd->common.state.value);
276 for (i = 0; i < epd->image.tweens_count; ++i)
278 if (epd->image.tweens[i]->id == -1)
279 error_and_abort(ef, "Collection %i: tween image id missing for "
280 "part \"%s\", description \"%s\" %f",
281 pc->id, ep->name, epd->common.state.name, epd->common.state.value);
286 check_packed_items(Edje_Part_Collection *pc, Edje_Part *ep, Eet_File *ef)
290 for (i = 0; i < ep->items_count; ++i)
292 if (ep->items[i]->type == EDJE_PART_TYPE_GROUP && !ep->items[i]->source)
293 error_and_abort(ef, "Collection %i: missing source on packed item "
294 "of type GROUP in part \"%s\"",
296 if (ep->type == EDJE_PART_TYPE_TABLE && (ep->items[i]->col < 0 || ep->items[i]->row < 0))
297 error_and_abort(ef, "Collection %i: missing col/row on packed item "
298 "for part \"%s\" of type TABLE",
304 check_nameless_state(Edje_Part_Collection *pc, Edje_Part *ep, Edje_Part_Description_Common *ed, Eet_File *ef)
307 error_and_abort(ef, "Collection %i: description with state missing on part \"%s\"",
312 check_part(Edje_Part_Collection *pc, Edje_Part *ep, Eet_File *ef)
315 /* FIXME: check image set and sort them. */
316 if (!ep->default_desc)
317 error_and_abort(ef, "Collection %i: default description missing "
318 "for part \"%s\"", pc->id, ep->name);
320 for (i = 0; i < ep->other.desc_count; ++i)
321 check_nameless_state(pc, ep, ep->other.desc[i], ef);
323 if (ep->type == EDJE_PART_TYPE_IMAGE)
325 check_image_part_desc(pc, ep, (Edje_Part_Description_Image*) ep->default_desc, ef);
327 for (i = 0; i < ep->other.desc_count; ++i)
328 check_image_part_desc (pc, ep, (Edje_Part_Description_Image*) ep->other.desc[i], ef);
330 else if ((ep->type == EDJE_PART_TYPE_BOX) ||
331 (ep->type == EDJE_PART_TYPE_TABLE))
332 check_packed_items(pc, ep, ef);
334 /* FIXME: When mask are supported remove this check */
335 if (ep->clip_to_id != -1 &&
336 pc->parts[ep->clip_to_id]->type != EDJE_PART_TYPE_RECTANGLE)
337 error_and_abort(ef, "Collection %i: clip_to point to a non RECT part '%s' !",
338 pc->id, pc->parts[ep->clip_to_id]->name);
342 check_program(Edje_Part_Collection *pc, Edje_Program *ep, Eet_File *ef)
346 case EDJE_ACTION_TYPE_STATE_SET:
347 case EDJE_ACTION_TYPE_ACTION_STOP:
348 case EDJE_ACTION_TYPE_DRAG_VAL_SET:
349 case EDJE_ACTION_TYPE_DRAG_VAL_STEP:
350 case EDJE_ACTION_TYPE_DRAG_VAL_PAGE:
352 error_and_abort(ef, "Collection %i: target missing in program "
353 "\"%s\"", pc->id, ep->name);
361 data_thread_head(void *data, Ecore_Thread *thread __UNUSED__)
363 Head_Write *hw = data;
369 if (edje_file->collection)
371 Edje_Part_Collection_Directory_Entry *ce;
373 EINA_LIST_FREE(aliases, ce)
375 Edje_Part_Collection_Directory_Entry *sce;
379 snprintf(buf, sizeof(buf),
380 "Collection %i: name missing.", ce->id);
381 hw->errstr = strdup(buf);
385 sce = eina_hash_find(edje_collections_lookup, &ce->id);
388 memcpy(&ce->count, &sce->count, sizeof (ce->count));
392 snprintf(buf, sizeof(buf),
393 "Collection %s (%i) can't find an correct alias.",
395 hw->errstr = strdup(buf);
399 eina_hash_direct_add(edje_file->collection, ce->entry, ce);
402 bytes = eet_data_write(hw->ef, edd_edje_file, "edje/file", edje_file,
406 snprintf(buf, sizeof(buf),
407 "Unable to write \"edje_file\" entry to \"%s\"",
409 hw->errstr = strdup(buf);
414 INF("Wrote %9i bytes (%4iKb) for \"edje_file\" header",
415 bytes, (bytes + 512) / 1024);
419 data_thread_head_end(void *data, Ecore_Thread *thread __UNUSED__)
421 Head_Write *hw = data;
424 if (pending_threads <= 0) ecore_main_loop_quit();
427 error_and_abort(hw->ef, hw->errstr);
434 data_write_header(Eet_File *ef)
438 hw = calloc(1, sizeof(Head_Write));
442 ecore_thread_run(data_thread_head, data_thread_head_end, NULL, hw);
445 data_thread_head(hw, NULL);
446 data_thread_head_end(hw, NULL);
451 data_thread_fonts(void *data, Ecore_Thread *thread __UNUSED__)
453 Fonts_Write *fc = data;
461 f = eina_file_open(fc->fn->file, 0);
464 using_file(fc->fn->file, 'F');
465 m = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
471 EINA_LIST_FOREACH(fnt_dirs, ll, dat)
473 snprintf(buf, sizeof(buf), "%s/%s", dat, fc->fn->file);
474 f = eina_file_open(buf, 0);
477 using_file(buf, 'F');
478 m = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
487 if (f) eina_file_close(f);
488 snprintf(buf, sizeof(buf),
489 "Unable to load font part \"%s\" entry to %s",
490 fc->fn->file, file_out);
491 fc->errstr = strdup(buf);
495 snprintf(buf, sizeof(buf), "edje/fonts/%s", fc->fn->name);
496 bytes = eet_write(fc->ef, buf, m, eina_file_size_get(f), compress_mode);
498 if ((bytes <= 0) || eina_file_map_faulted(f, m))
500 eina_file_map_free(f, m);
502 snprintf(buf2, sizeof(buf2),
503 "Unable to write font part \"%s\" as \"%s\" "
504 "part entry to %s", fc->fn->file, buf, file_out);
505 fc->errstr = strdup(buf2);
509 INF("Wrote %9i bytes (%4iKb) for \"%s\" font entry \"%s\" compress: [real: %2.1f%%]",
510 bytes, (bytes + 512) / 1024, buf, fc->fn->file,
511 100 - (100 * (double)bytes) / ((double)(eina_file_size_get(f)))
513 eina_file_map_free(f, m);
518 data_thread_fonts_end(void *data, Ecore_Thread *thread __UNUSED__)
520 Fonts_Write *fc = data;
522 if (pending_threads <= 0) ecore_main_loop_quit();
525 error_and_abort(fc->ef, fc->errstr);
532 data_write_fonts(Eet_File *ef, int *font_num)
537 if (!edje_file->fonts) return;
539 it = eina_hash_iterator_data_new(edje_file->fonts);
540 EINA_ITERATOR_FOREACH(it, fn)
544 fc = calloc(1, sizeof(Fonts_Write));
550 ecore_thread_run(data_thread_fonts, data_thread_fonts_end, NULL, fc);
553 data_thread_fonts(fc, NULL);
554 data_thread_fonts_end(fc, NULL);
558 eina_iterator_free(it);
562 error_and_abort_image_load_error(Eet_File *ef, const char *file, int error)
564 const char *errmsg = evas_load_error_str(error);
565 char hint[1024] = "";
567 if (error == EVAS_LOAD_ERROR_DOES_NOT_EXIST)
571 " Check if path to file \"%s\" is correct "
572 "(both directory and file name).",
575 else if (error == EVAS_LOAD_ERROR_CORRUPT_FILE)
579 " Check if file \"%s\" is consistent.",
582 else if (error == EVAS_LOAD_ERROR_UNKNOWN_FORMAT)
584 const char *ext = strrchr(file, '.');
585 const char **itr, *known_loaders[] = {
586 /* list from evas_image_load.c */
615 " File \"%s\" does not have an extension, "
622 for (itr = known_loaders; *itr; itr++)
624 if (strcasecmp(ext, *itr) == 0)
628 " Check if Evas was compiled with %s module enabled and "
629 "all required dependencies exist.",
635 snprintf(hint, sizeof(hint),
636 " Check if Evas supports loading files of type \"%s\" (%s) "
637 "and this module was compiled and all its dependencies exist.",
642 (ef, "Unable to load image \"%s\" used by file \"%s\": %s.%s",
643 file, file_out, errmsg, hint);
647 data_thread_image(void *data, Ecore_Thread *thread __UNUSED__)
649 Image_Write *iw = data;
650 char buf[PATH_MAX], buf2[PATH_MAX];
651 unsigned int *start, *end;
652 Eina_Bool opaque = EINA_TRUE;
655 if ((iw->data) && (iw->w > 0) && (iw->h > 0))
659 snprintf(buf, sizeof(buf), "edje/images/%i", iw->img->id);
661 if ((iw->img->source_type == EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT) &&
662 (iw->img->source_param == 0))
664 else if ((iw->img->source_type == EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT) &&
665 (iw->img->source_param == 1))
666 mode = 1; /* COMPRESS */
668 mode = 2; /* LOSSY */
669 if ((mode == 0) && (no_raw))
671 mode = 1; /* promote compression */
672 iw->img->source_param = 95;
674 if ((mode == 2) && (no_lossy)) mode = 1; /* demote compression */
675 if ((mode == 1) && (no_comp))
677 if (no_lossy) mode = 0; /* demote compression */
680 iw->img->source_param = 90;
681 mode = 2; /* no choice. lossy */
686 qual = iw->img->source_param;
687 if (qual < min_quality) qual = min_quality;
688 if (qual > max_quality) qual = max_quality;
692 start = (unsigned int *) iw->data;
693 end = start + (iw->w * iw->h);
696 if ((*start & 0xff000000) != 0xff000000)
703 if (opaque) iw->alpha = 0;
706 bytes = eet_data_image_write(iw->ef, buf,
707 iw->data, iw->w, iw->h,
711 bytes = eet_data_image_write(iw->ef, buf,
712 iw->data, iw->w, iw->h,
717 bytes = eet_data_image_write(iw->ef, buf,
718 iw->data, iw->w, iw->h,
723 snprintf(buf2, sizeof(buf2),
724 "Unable to write image part "
725 "\"%s\" as \"%s\" part entry to "
726 "%s", iw->img->entry, buf, file_out);
727 iw->errstr = strdup(buf2);
733 snprintf(buf, sizeof(buf), "edje/images/%i", iw->img->id);
734 snprintf(buf2, sizeof(buf2),
735 "Unable to load image part "
736 "\"%s\" as \"%s\" part entry to "
737 "%s", iw->img->entry, buf, file_out);
738 iw->errstr = strdup(buf2);
742 if (eina_log_domain_level_check(_edje_cc_log_dom, EINA_LOG_LEVEL_INFO))
746 if (!iw->path || (stat(iw->path, &st))) st.st_size = 0;
747 INF("Wrote %9i bytes (%4iKb) for \"%s\" image entry \"%s\" compress: [raw: %2.1f%%] [real: %2.1f%%]",
748 bytes, (bytes + 512) / 1024, buf, iw->img->entry,
749 100 - (100 * (double)bytes) / ((double)(iw->w * iw->h * 4)),
750 100 - (100 * (double)bytes) / ((double)(st.st_size))
756 data_thread_image_end(void *data, Ecore_Thread *thread __UNUSED__)
758 Image_Write *iw = data;
761 if (pending_threads <= 0) ecore_main_loop_quit();
764 error_and_abort(iw->ef, iw->errstr);
767 if (iw->path) free(iw->path);
768 evas_object_del(iw->im);
773 data_image_preload_done(void *data, Evas *e __UNUSED__, Evas_Object *o, void *event_info __UNUSED__)
775 Image_Write *iw = data;
777 evas_object_image_size_get(o, &iw->w, &iw->h);
778 iw->alpha = evas_object_image_alpha_get(o);
779 iw->data = evas_object_image_data_get(o, 0);
781 ecore_thread_run(data_thread_image, data_thread_image_end, NULL, iw);
784 data_thread_image(iw, NULL);
785 data_thread_image_end(iw, NULL);
790 data_write_images(Eet_File *ef, int *image_num)
796 if (!((edje_file) && (edje_file->image_dir))) return;
799 ee = ecore_evas_buffer_new(1, 1);
801 error_and_abort(ef, "Cannot create buffer engine canvas for image load.");
802 evas = ecore_evas_get(ee);
804 for (i = 0; i < (int)edje_file->image_dir->entries_count; i++)
806 Edje_Image_Directory_Entry *img;
808 img = &edje_file->image_dir->entries[i];
809 if ((img->source_type == EDJE_IMAGE_SOURCE_TYPE_EXTERNAL) ||
810 (img->entry == NULL))
818 int load_err = EVAS_LOAD_ERROR_NONE;
821 iw = calloc(1, sizeof(Image_Write));
824 iw->im = im = evas_object_image_add(evas);
826 evas_object_event_callback_add(im,
827 EVAS_CALLBACK_IMAGE_PRELOADED,
828 data_image_preload_done,
830 EINA_LIST_FOREACH(img_dirs, ll, s)
834 snprintf(buf, sizeof(buf), "%s/%s", s, img->entry);
835 evas_object_image_file_set(im, buf, NULL);
836 load_err = evas_object_image_load_error_get(im);
837 if (load_err == EVAS_LOAD_ERROR_NONE)
840 iw->path = strdup(buf);
843 evas_object_image_preload(im, 0);
844 using_file(buf, 'I');
846 data_image_preload_done(iw, evas, im, NULL);
850 if (load_err != EVAS_LOAD_ERROR_NONE)
852 evas_object_image_file_set(im, img->entry, NULL);
853 load_err = evas_object_image_load_error_get(im);
854 if (load_err == EVAS_LOAD_ERROR_NONE)
857 iw->path = strdup(img->entry);
860 evas_object_image_preload(im, 0);
861 using_file(img->entry, 'I');
863 data_image_preload_done(iw, evas, im, NULL);
866 error_and_abort_image_load_error
867 (ef, img->entry, load_err);
874 data_thread_sounds(void *data, Ecore_Thread *thread __UNUSED__)
876 Sound_Write *sw = data;
878 #ifdef HAVE_LIBSNDFILE
879 Edje_Sound_Encode *enc_info;
881 char *dir_path = NULL;
882 char snd_path[PATH_MAX];
888 // Search the Sound file in all the -sd ( sound directory )
889 EINA_LIST_FOREACH(snd_dirs, ll, dir_path)
891 snprintf((char *)snd_path, sizeof(snd_path), "%s/%s", dir_path,
892 sw->sample->snd_src);
893 f = eina_file_open(snd_path, 0);
898 snprintf((char *)snd_path, sizeof(snd_path), "%s",
899 sw->sample->snd_src);
900 f = eina_file_open(snd_path, 0);
902 #ifdef HAVE_LIBSNDFILE
903 if (f) eina_file_close(f);
904 enc_info = _edje_multisense_encode(snd_path, sw->sample,
905 sw->sample->quality);
906 f = eina_file_open(enc_info->file, 0);
907 if (f) using_file(enc_info->file, 'S');
909 if (f) using_file(snd_path, 'S');
913 ERR("Unable to load sound data of: %s", sw->sample->name);
917 snprintf(sndid_str, sizeof(sndid_str), "edje/sounds/%i", sw->sample->id);
918 m = eina_file_map_all(f, EINA_FILE_WILLNEED);
921 bytes = eet_write(sw->ef, sndid_str, m, eina_file_size_get(f),
922 EET_COMPRESSION_NONE);
923 if (eina_file_map_faulted(f, m))
925 ERR("File access error when reading '%s'",
926 eina_file_filename_get(f));
929 eina_file_map_free(f, m);
933 #ifdef HAVE_LIBSNDFILE
934 //If encoded temporary file, delete it.
935 if (enc_info->encoded) unlink(enc_info->file);
937 #ifdef HAVE_LIBSNDFILE
938 INF("Wrote %9i bytes (%4iKb) for \"%s\" %s sound entry \"%s\"",
939 bytes, (bytes + 512) / 1024,
940 sndid_str, enc_info->comp_type, sw->sample->name);
942 INF("Wrote %9i bytes (%4iKb) for \"%s\" %s sound entry \"%s\"",
943 bytes, (bytes + 512) / 1024,
944 sndid_str, "RAW PCM", sw->sample->name);
947 #ifdef HAVE_LIBSNDFILE
948 if ((enc_info->file) && (!enc_info->encoded))
949 eina_stringshare_del(enc_info->file);
950 if (enc_info) free(enc_info);
956 data_thread_sounds_end(void *data, Ecore_Thread *thread __UNUSED__)
958 Sound_Write *sw = data;
960 if (pending_threads <= 0) ecore_main_loop_quit();
965 data_write_sounds(Eet_File *ef, int *sound_num)
967 if ((edje_file) && (edje_file->sound_dir))
971 for (i = 0; i < (int)edje_file->sound_dir->samples_count; i++)
975 sw = calloc(1, sizeof(Sound_Write));
978 sw->sample = &edje_file->sound_dir->samples[i];
983 ecore_thread_run(data_thread_sounds, data_thread_sounds_end, NULL, sw);
986 data_thread_sounds(sw, NULL);
987 data_thread_sounds_end(sw, NULL);
994 check_groups(Eet_File *ef)
996 Edje_Part_Collection *pc;
999 /* sanity checks for parts and programs */
1000 EINA_LIST_FOREACH(edje_collections, l, pc)
1004 for (i = 0; i < pc->parts_count; ++i)
1005 check_part(pc, pc->parts[i], ef);
1007 #define CHECK_PROGRAM(Type, Pc, It) \
1008 for (It = 0; It < Pc->programs.Type ## _count; ++It) \
1009 check_program(Pc, Pc->programs.Type[i], ef); \
1011 CHECK_PROGRAM(fnmatch, pc, i);
1012 CHECK_PROGRAM(strcmp, pc, i);
1013 CHECK_PROGRAM(strncmp, pc, i);
1014 CHECK_PROGRAM(strrncmp, pc, i);
1015 CHECK_PROGRAM(nocmp, pc, i);
1020 data_thread_group(void *data, Ecore_Thread *thread __UNUSED__)
1022 Group_Write *gw = data;
1025 char buf2[PATH_MAX];
1027 snprintf(buf, sizeof(buf), "edje/collections/%i", gw->pc->id);
1028 bytes = eet_data_write(gw->ef, edd_edje_part_collection, buf, gw->pc,
1033 snprintf(buf2, sizeof(buf2),
1034 "Unable to write \"%s\" part entry to %s",
1036 gw->errstr = strdup(buf2);
1040 INF("Wrote %9i bytes (%4iKb) for \"%s\" aka \"%s\" collection entry",
1041 bytes, (bytes + 512) / 1024, buf, gw->pc->part);
1045 data_thread_group_end(void *data, Ecore_Thread *thread __UNUSED__)
1047 Group_Write *gw = data;
1049 if (pending_threads <= 0) ecore_main_loop_quit();
1052 error_and_abort(gw->ef, gw->errstr);
1059 data_write_groups(Eet_File *ef, int *collection_num)
1062 Edje_Part_Collection *pc;
1064 EINA_LIST_FOREACH(edje_collections, l, pc)
1068 gw = calloc(1, sizeof(Group_Write));
1071 error_and_abort(ef, "Cannot allocate memory for group writer");
1078 ecore_thread_run(data_thread_group, data_thread_group_end, NULL, gw);
1081 data_thread_group(gw, NULL);
1082 data_thread_group_end(gw, NULL);
1084 *collection_num += 1;
1089 create_script_file(Eet_File *ef, const char *filename, const Code *cd, int fd)
1091 FILE *f = fdopen(fd, "wb");
1093 error_and_abort(ef, "Unable to open temp file \"%s\" for script "
1094 "compilation.", filename);
1099 fprintf(f, "#include <edje>\n");
1104 while (ln < (cd->l1 - 1))
1114 for (sp = cd->shared; *sp; sp++)
1116 if ((sp[0] == '#') && (newlined))
1121 if (sp[0] == '\n') newlined = 1;
1122 if (!hash) fputc(sp[0], f);
1123 else if (sp[0] == '\n') hash = 0;
1127 ln += cd->l2 - cd->l1 + 1;
1129 EINA_LIST_FOREACH(cd->programs, ll, cp)
1133 while (ln < (cp->l1 - 1))
1138 /* FIXME: this prototype needs to be */
1139 /* formalised and set in stone */
1140 fprintf(f, "public _p%i(sig[], src[]) {", cp->id);
1146 for (sp = cp->script; *sp; sp++)
1148 if ((sp[0] == '#') && (newlined))
1153 if (sp[0] == '\n') newlined = 1;
1154 if (!hash) fputc(sp[0], f);
1155 else if (sp[0] == '\n') hash = 0;
1159 ln += cp->l2 - cp->l1 + 1;
1167 data_thread_script(void *data, Ecore_Thread *thread __UNUSED__)
1169 Script_Write *sc = data;
1174 f = fdopen(sc->tmpo_fd, "rb");
1177 snprintf(buf, sizeof(buf),
1178 "Unable to open script object \"%s\" for reading.",
1180 sc->errstr = strdup(buf);
1184 fseek(f, 0, SEEK_END);
1190 void *dat = malloc(size);
1194 if (fread(dat, size, 1, f) != 1)
1196 snprintf(buf, sizeof(buf),
1197 "Unable to read all of script object \"%s\"",
1199 sc->errstr = strdup(buf);
1202 snprintf(buf, sizeof(buf), "edje/scripts/embryo/compiled/%i",
1204 eet_write(sc->ef, buf, dat, size, compress_mode);
1209 snprintf(buf, sizeof(buf),
1210 "Alloc failed for %lu bytes", (unsigned long)size);
1211 sc->errstr = strdup(buf);
1222 if (sc->cd->original)
1224 snprintf(buf, PATH_MAX, "edje/scripts/embryo/source/%i", sc->i);
1225 eet_write(sc->ef, buf, sc->cd->original,
1226 strlen(sc->cd->original) + 1, compress_mode);
1228 EINA_LIST_FOREACH(sc->cd->programs, ll, cp)
1230 if (!cp->original) continue;
1231 snprintf(buf, PATH_MAX, "edje/scripts/embryo/source/%i/%i",
1233 eet_write(sc->ef, buf, cp->original,
1234 strlen(cp->original) + 1, compress_mode);
1245 data_thread_script_end(void *data, Ecore_Thread *thread __UNUSED__)
1247 Script_Write *sc = data;
1249 if (pending_threads <= 0) ecore_main_loop_quit();
1252 error_and_abort(sc->ef, sc->errstr);
1259 data_scripts_exe_del_cb(void *data __UNUSED__, int evtype __UNUSED__, void *evinfo)
1261 Script_Write *sc = data;
1262 Ecore_Exe_Event_Del *ev = evinfo;
1264 if (!ev->exe) return ECORE_CALLBACK_RENEW;
1265 if (ecore_exe_data_get(ev->exe) != sc) return ECORE_CALLBACK_RENEW;
1266 if (ev->exit_code != 0)
1268 error_and_abort(sc->ef, "Compiling script code not clean.");
1269 return ECORE_CALLBACK_CANCEL;
1274 ecore_thread_run(data_thread_script, data_thread_script_end, NULL, sc);
1279 data_thread_script(sc, NULL);
1280 data_thread_script_end(sc, NULL);
1283 if (pending_threads <= 0) ecore_main_loop_quit();
1284 return ECORE_CALLBACK_CANCEL;
1288 data_write_scripts(Eet_File *ef)
1295 tmp_dir = (char *)evil_tmpdir_get();
1300 for (i = 0, l = codes; l; l = eina_list_next(l), i++)
1302 Code *cd = eina_list_data_get(l);
1308 if ((!cd->shared) && (!cd->programs))
1310 sc = calloc(1, sizeof(Script_Write));
1314 snprintf(sc->tmpn, PATH_MAX, "%s/edje_cc.sma-tmp-XXXXXX", tmp_dir);
1315 sc->tmpn_fd = mkstemp(sc->tmpn);
1316 if (sc->tmpn_fd < 0)
1317 error_and_abort(ef, "Unable to open temp file \"%s\" for script "
1318 "compilation.", sc->tmpn);
1319 snprintf(sc->tmpo, PATH_MAX, "%s/edje_cc.amx-tmp-XXXXXX", tmp_dir);
1320 sc->tmpo_fd = mkstemp(sc->tmpo);
1321 if (sc->tmpo_fd < 0)
1324 error_and_abort(ef, "Unable to open temp file \"%s\" for script "
1325 "compilation.", sc->tmpn);
1327 create_script_file(ef, sc->tmpn, cd, sc->tmpn_fd);
1328 snprintf(buf, sizeof(buf),
1329 "%s/embryo_cc -i %s/include -o %s %s",
1330 eina_prefix_bin_get(pfx),
1331 eina_prefix_data_get(pfx),
1332 sc->tmpo, sc->tmpn);
1334 sc->exe = ecore_exe_run(buf, sc);
1335 ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
1336 data_scripts_exe_del_cb, sc);
1342 _edje_lua_script_writer(lua_State *L __UNUSED__, const void *chunk_buf, size_t chunk_size, void *_data)
1344 Script_Lua_Writer *data;
1347 data = (Script_Lua_Writer *)_data;
1349 data->buf = malloc(data->size + chunk_size);
1350 memcpy(data->buf, old, data->size);
1351 memcpy(&((data->buf)[data->size]), chunk_buf, chunk_size);
1353 data->size += chunk_size;
1360 _edje_lua_error_and_abort(lua_State *L, int err_code, Script_Write *sc)
1368 err_type = "runtime";
1371 err_type = "syntax";
1374 err_type = "memory allocation";
1377 err_type = "error handler";
1380 err_type = "unknown";
1383 snprintf(buf, sizeof(buf),
1384 "Lua %s error: %s", err_type, lua_tostring(L, -1));
1385 sc->errstr = strdup(buf);
1389 data_thread_lua_script(void *data, Ecore_Thread *thread __UNUSED__)
1391 Script_Write *sc = data;
1396 Script_Lua_Writer dat;
1403 L = luaL_newstate();
1406 snprintf(buf, sizeof(buf),
1407 "Lua error: Lua state could not be initialized");
1408 sc->errstr = strdup(buf);
1412 luaL_buffinit(L, &b);
1418 while (ln < (sc->cd->l1 - 1))
1420 luaL_addchar(&b, '\n');
1423 luaL_addstring(&b, sc->cd->shared);
1424 ln += sc->cd->l2 - sc->cd->l1;
1427 EINA_LIST_FOREACH(sc->cd->programs, ll, cp)
1431 while (ln < (cp->l1 - 1))
1433 luaL_addchar(&b, '\n');
1436 luaL_addstring(&b, "_G[");
1437 lua_pushnumber(L, cp->id);
1439 luaL_addstring(&b, "] = function (ed, signal, source)");
1440 luaL_addstring(&b, cp->script);
1441 luaL_addstring(&b, "end\n");
1442 ln += cp->l2 - cp->l1 + 1;
1445 luaL_pushresult(&b);
1447 if (err_code = luaL_loadstring(L, lua_tostring (L, -1)))
1449 _edje_lua_error_and_abort(L, err_code, sc);
1452 lua_dump(L, _edje_lua_script_writer, &dat);
1453 #else // LUA_PLAIN_TEXT
1454 dat.buf = (char *)lua_tostring(L, -1);
1455 dat.size = strlen(dat.buf);
1457 //printf("lua chunk size: %d\n", dat.size);
1460 * TODO load and test Lua chunk
1464 if (luaL_loadbuffer(L, globbuf, globbufsize, "edje_lua_script"))
1465 printf("lua load error: %s\n", lua_tostring (L, -1));
1466 if (lua_pcall(L, 0, 0, 0))
1467 printf("lua call error: %s\n", lua_tostring (L, -1));
1470 snprintf(buf, sizeof(buf), "edje/scripts/lua/%i", sc->i);
1471 if (eet_write(sc->ef, buf, dat.buf, dat.size, compress_mode) <= 0)
1473 snprintf(buf, sizeof(buf),
1474 "Unable to write script %i", sc->i);
1475 sc->errstr = strdup(buf);
1485 data_thread_lua_script_end(void *data, Ecore_Thread *thread __UNUSED__)
1487 Script_Write *sc = data;
1489 if (pending_threads <= 0) ecore_main_loop_quit();
1492 error_and_abort(sc->ef, sc->errstr);
1499 data_write_lua_scripts(Eet_File *ef)
1504 for (i = 0, l = codes; l; l = eina_list_next(l), i++)
1509 cd = (Code *)eina_list_data_get(l);
1512 if ((!cd->shared) && (!cd->programs))
1515 sc = calloc(1, sizeof(Script_Write));
1521 ecore_thread_run(data_thread_lua_script, data_thread_lua_script_end, NULL, sc);
1524 data_thread_lua_script(sc, NULL);
1525 data_thread_lua_script_end(sc, NULL);
1531 data_thread_source(void *data, Ecore_Thread *thread __UNUSED__)
1533 Eet_File *ef = data;
1538 data_thread_source_end(void *data __UNUSED__, Ecore_Thread *thread __UNUSED__)
1541 if (pending_threads <= 0) ecore_main_loop_quit();
1545 data_thread_fontmap(void *data, Ecore_Thread *thread __UNUSED__)
1547 Eet_File *ef = data;
1548 source_fontmap_save(ef, fonts);
1552 data_thread_fontmap_end(void *data __UNUSED__, Ecore_Thread *thread __UNUSED__)
1555 if (pending_threads <= 0) ecore_main_loop_quit();
1565 int collection_num = 0;
1570 ERR("No data to put in \"%s\"", file_out);
1574 ef = eet_open(file_out, EET_FILE_MODE_WRITE);
1577 ERR("Unable to open \"%s\" for writing output", file_out);
1583 ecore_thread_max_set(ecore_thread_max_get() * 2);
1586 t = ecore_time_get();
1587 data_write_header(ef);
1589 INF("header: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1590 data_write_groups(ef, &collection_num);
1591 INF("groups: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1592 data_write_scripts(ef);
1593 INF("scripts: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1594 data_write_lua_scripts(ef);
1595 INF("lua scripts: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1599 ecore_thread_run(data_thread_source, data_thread_source_end, NULL, ef);
1602 data_thread_source(ef, NULL);
1603 data_thread_source_end(ef, NULL);
1605 INF("source: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1608 ecore_thread_run(data_thread_fontmap, data_thread_fontmap_end, NULL, ef);
1611 data_thread_fontmap(ef, NULL);
1612 data_thread_fontmap_end(ef, NULL);
1614 INF("fontmap: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1615 data_write_images(ef, &image_num);
1616 INF("images: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1617 data_write_fonts(ef, &font_num);
1618 INF("fonts: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1619 data_write_sounds(ef, &sound_num);
1620 INF("sounds: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1622 if (pending_threads > 0) ecore_main_loop_begin();
1623 INF("THREADS: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1627 if (eina_log_domain_level_check(_edje_cc_log_dom, EINA_LOG_LEVEL_INFO))
1630 " Wrote %i collections\n"
1631 " Wrote %i images\n"
1632 " Wrote %i sounds\n"
1645 Edje_Part_Collection *pc;
1647 Edje_Part_Parser *ep, *ep2;
1650 /* sanity checks for parts and programs */
1651 EINA_LIST_FOREACH(edje_collections, l, pc)
1653 unsigned int i, j, k;
1654 Eina_Bool found = EINA_FALSE;
1656 for (i = 0; i < pc->parts_count; i++)
1658 ep = (Edje_Part_Parser *)pc->parts[i];
1659 if (ep->reorder.insert_before && ep->reorder.insert_after)
1660 ERR("Unable to use together insert_before and insert_after in part \"%s\".", pc->parts[i]->name);
1662 if (ep->reorder.done)
1666 if (ep->reorder.insert_before || ep->reorder.insert_after)
1669 for (j = 0; j < pc->parts_count; j++)
1671 if (ep->reorder.insert_before &&
1672 !strcmp(ep->reorder.insert_before, pc->parts[j]->name))
1674 ep2 = (Edje_Part_Parser *)pc->parts[j];
1675 if (ep2->reorder.after)
1676 ERR("The part \"%s\" is ambiguous ordered part.",
1677 pc->parts[i]->name);
1678 if (ep2->reorder.linked_prev)
1679 ERR("Unable to insert two or more parts in same part \"%s\".",
1680 pc->parts[j]->name);
1683 ep2->reorder.linked_prev += ep->reorder.linked_prev + 1;
1684 ep->reorder.before = (Edje_Part_Parser *)pc->parts[j];
1685 while (ep2->reorder.before)
1687 ep2->reorder.before->reorder.linked_prev = ep2->reorder.linked_prev + 1;
1688 ep2 = ep2->reorder.before;
1692 else if (ep->reorder.insert_after &&
1693 !strcmp(ep->reorder.insert_after, pc->parts[j]->name))
1695 ep2 = (Edje_Part_Parser *)pc->parts[j];
1696 if (ep2->reorder.before)
1697 ERR("The part \"%s\" is ambiguous ordered part.", pc->parts[i]->name);
1698 if (ep2->reorder.linked_next)
1699 ERR("Unable to insert two or more parts in same part \"%s\".", pc->parts[j]->name);
1702 ep2->reorder.linked_next += ep->reorder.linked_next + 1;
1703 ep->reorder.after = (Edje_Part_Parser *)pc->parts[j];
1704 while (ep2->reorder.after)
1706 ep2->reorder.after->reorder.linked_next = ep2->reorder.linked_next + 1;
1707 ep2 = ep2->reorder.after;
1714 unsigned int amount, linked;
1716 if (((i > k) && ((i - ep->reorder.linked_prev) <= k))
1717 || ((i < k) && ((i + ep->reorder.linked_next) >= k)))
1718 ERR("The part order is wrong. It has circular dependency.");
1720 amount = ep->reorder.linked_prev + ep->reorder.linked_next + 1;
1721 linked = i - ep->reorder.linked_prev;
1722 parts = malloc(amount * sizeof(Edje_Part));
1723 for (j = 0 ; j < amount ; j++)
1725 parts[j] = pc->parts[linked];
1730 for (j = i - ep->reorder.linked_prev - 1 ; j >= k ; j--)
1732 pc->parts[j + amount] = pc->parts[j];
1733 pc->parts[j + amount]->id = j + amount;
1735 for (j = 0 ; j < amount ; j++)
1737 pc->parts[j + k] = parts[j];
1738 pc->parts[j + k]->id = j + k;
1743 for (j = i + ep->reorder.linked_next + 1 ; j <= k ; j++)
1745 pc->parts[j - amount] = pc->parts[j];
1746 pc->parts[j - amount]->id = j - amount;
1748 for (j = 0 ; j < amount ; j++)
1750 pc->parts[j + k - amount + 1] = parts[j];
1751 pc->parts[j + k - amount + 1]->id = j + k - amount + 1;
1755 ep->reorder.done = EINA_TRUE;
1764 data_queue_group_lookup(const char *name, Edje_Part *part)
1768 if (!name || !name[0]) return;
1770 gl = mem_alloc(SZ(Group_Lookup));
1771 group_lookups = eina_list_append(group_lookups, gl);
1772 gl->name = mem_strdup(name);
1777 data_queue_part_lookup(Edje_Part_Collection *pc, const char *name, int *dest)
1780 Part_Lookup *pl = NULL;
1786 pl = eina_hash_find(part_pc_dest_lookup, &key);
1792 pl->name = mem_strdup(name);
1796 list = eina_hash_find(part_dest_lookup, &pl->dest);
1797 list = eina_list_remove(list, pl);
1798 eina_hash_set(part_dest_lookup, &pl->dest, list);
1804 if (!name[0]) return;
1806 pl = mem_alloc(SZ(Part_Lookup));
1808 pl->name = mem_strdup(name);
1811 eina_hash_add(part_pc_dest_lookup, &key, pl);
1813 list = eina_hash_find(part_dest_lookup, &pl->dest);
1814 list = eina_list_prepend(list, pl);
1815 eina_hash_set(part_dest_lookup, &pl->dest, list);
1819 data_queue_copied_part_lookup(Edje_Part_Collection *pc, int *src, int *dest)
1825 list = eina_hash_find(part_dest_lookup, &src);
1826 EINA_LIST_FOREACH(list, l, pl)
1827 data_queue_part_lookup(pc, pl->name, dest);
1831 data_queue_anonymous_lookup(Edje_Part_Collection *pc, Edje_Program *ep, int *dest)
1836 if (!ep) return ; /* FIXME: should we stop compiling ? */
1838 EINA_LIST_FOREACH(program_lookups, l, pl)
1845 cd = eina_list_data_get(eina_list_last(codes));
1847 EINA_LIST_FOREACH(cd->programs, l2, cp)
1849 if (&(cp->id) == pl->dest)
1851 cd->programs = eina_list_remove(cd->programs, cp);
1856 program_lookups = eina_list_remove(program_lookups, pl);
1863 pl = mem_alloc(SZ(Program_Lookup));
1864 program_lookups = eina_list_append(program_lookups, pl);
1868 pl->anonymous = EINA_TRUE;
1873 data_queue_copied_anonymous_lookup(Edje_Part_Collection *pc, int *src, int *dest)
1879 EINA_LIST_FOREACH(program_lookups, l, pl)
1881 if (pl->dest == src && pl->u.ep->name)
1883 for (i = 0 ; i < pc->programs.fnmatch_count ; i++)
1885 if (pc->programs.fnmatch[i]->name &&
1886 !strcmp(pl->u.ep->name, pc->programs.fnmatch[i]->name))
1887 data_queue_anonymous_lookup(pc, pc->programs.fnmatch[i], dest);
1889 for (i = 0 ; i < pc->programs.strcmp_count ; i++)
1891 if (pc->programs.strcmp[i]->name &&
1892 !strcmp(pl->u.ep->name, pc->programs.strcmp[i]->name))
1893 data_queue_anonymous_lookup(pc, pc->programs.strcmp[i], dest);
1895 for (i = 0 ; i < pc->programs.strncmp_count ; i++)
1897 if (pc->programs.strncmp[i]->name &&
1898 !strcmp(pl->u.ep->name, pc->programs.strncmp[i]->name))
1899 data_queue_anonymous_lookup(pc, pc->programs.strncmp[i], dest);
1901 for (i = 0 ; i < pc->programs.strrncmp_count ; i++)
1903 if (pc->programs.strrncmp[i]->name &&
1904 !strcmp(pl->u.ep->name, pc->programs.strrncmp[i]->name))
1905 data_queue_anonymous_lookup(pc, pc->programs.strrncmp[i], dest);
1907 for (i = 0 ; i < pc->programs.nocmp_count ; i++)
1909 if (pc->programs.nocmp[i]->name &&
1910 !strcmp(pl->u.ep->name, pc->programs.nocmp[i]->name))
1911 data_queue_anonymous_lookup(pc, pc->programs.nocmp[i], dest);
1918 data_queue_program_lookup(Edje_Part_Collection *pc, const char *name, int *dest)
1922 if (!name) return ; /* FIXME: should we stop compiling ? */
1924 pl = mem_alloc(SZ(Program_Lookup));
1925 program_lookups = eina_list_append(program_lookups, pl);
1927 pl->u.name = mem_strdup(name);
1929 pl->anonymous = EINA_FALSE;
1933 data_queue_copied_program_lookup(Edje_Part_Collection *pc, int *src, int *dest)
1938 EINA_LIST_FOREACH(program_lookups, l, pl)
1940 if (pl->dest == src)
1941 data_queue_program_lookup(pc, pl->u.name, dest);
1946 data_queue_image_lookup(char *name, int *dest, Eina_Bool *set)
1950 il = mem_alloc(SZ(Image_Lookup));
1951 image_lookups = eina_list_append(image_lookups, il);
1952 il->name = mem_strdup(name);
1958 data_queue_image_remove(int *dest, Eina_Bool *set)
1963 EINA_LIST_FOREACH(image_lookups, l, il)
1965 if (il->dest == dest && il->set == set)
1967 image_lookups = eina_list_remove_list(image_lookups, l);
1976 data_queue_copied_image_lookup(int *src, int *dest, Eina_Bool *set)
1981 EINA_LIST_FOREACH(image_lookups, l, il)
1983 if (il->dest == src)
1984 data_queue_image_lookup(il->name, dest, set);
1988 data_queue_part_slave_lookup(int *master, int *slave)
1992 sl = mem_alloc(SZ(Slave_Lookup));
1993 part_slave_lookups = eina_list_append(part_slave_lookups, sl);
1994 sl->master = master;
1999 data_queue_image_slave_lookup(int *master, int *slave)
2003 sl = mem_alloc(SZ(Slave_Lookup));
2004 image_slave_lookups = eina_list_append(image_slave_lookups, sl);
2005 sl->master = master;
2010 handle_slave_lookup(Eina_List *list, int *master, int value)
2015 EINA_LIST_FOREACH(list, l, sl)
2016 if (sl->master == master)
2021 data_process_lookups(void)
2023 Edje_Part_Collection *pc;
2026 Program_Lookup *program;
2027 Group_Lookup *group;
2028 Image_Lookup *image;
2031 Eina_Hash *images_in_use;
2033 Eina_Bool is_lua = EINA_FALSE;
2035 /* remove all unreferenced Edje_Part_Collection */
2036 EINA_LIST_FOREACH_SAFE(edje_collections, l, l2, pc)
2038 Edje_Part_Collection_Directory_Entry *alias;
2039 Edje_Part_Collection_Directory_Entry *find;
2041 unsigned int id = 0;
2046 ERR("A collection without a name was detected, that's not allowed.");
2049 find = eina_hash_find(edje_file->collection, pc->part);
2050 if (find && find->id == pc->id)
2053 EINA_LIST_FOREACH(aliases, l3, alias)
2054 if (alias->id == pc->id)
2057 /* This Edje_Part_Collection is not used at all */
2058 edje_collections = eina_list_remove_list(edje_collections, l);
2059 l3 = eina_list_nth_list(codes, pc->id);
2060 codes = eina_list_remove_list(codes, l3);
2062 /* Unref all image used by that group */
2063 for (i = 0; i < pc->parts_count; ++i)
2064 part_description_image_cleanup(pc->parts[i]);
2066 /* Correct all id */
2067 EINA_LIST_FOREACH(edje_collections, l3, pc)
2071 /* Some group could be removed from the collection, but still be referenced by alias */
2072 find = eina_hash_find(edje_file->collection, pc->part);
2073 if (pc->id != find->id) find = NULL;
2075 /* Update all matching alias */
2076 EINA_LIST_FOREACH(aliases, l4, alias)
2077 if (pc->id == alias->id)
2081 if (find) find->id = pc->id;
2085 EINA_LIST_FOREACH(edje_collections, l, pc)
2087 unsigned int count = 0;
2090 if (pc->lua_script_only)
2092 #define PROGRAM_ID_SET(Type, Pc, It, Count) \
2093 for (It = 0; It < Pc->programs.Type ## _count; ++It) \
2095 Pc->programs.Type[It]->id = Count++; \
2098 PROGRAM_ID_SET(fnmatch, pc, i, count);
2099 PROGRAM_ID_SET(strcmp, pc, i, count);
2100 PROGRAM_ID_SET(strncmp, pc, i, count);
2101 PROGRAM_ID_SET(strrncmp, pc, i, count);
2102 PROGRAM_ID_SET(nocmp, pc, i, count);
2104 #undef PROGRAM_ID_SET
2107 it = eina_hash_iterator_data_new(part_pc_dest_lookup);
2108 EINA_ITERATOR_FOREACH(it, part)
2113 if (!strcmp(part->name, "-"))
2120 alias = eina_hash_find(part->pc->alias, part->name);
2123 for (i = 0; i < part->pc->parts_count; ++i)
2125 ep = part->pc->parts[i];
2127 if ((ep->name) && (!strcmp(ep->name, alias)))
2129 handle_slave_lookup(part_slave_lookups, part->dest, ep->id);
2130 *(part->dest) = ep->id;
2135 if (i == part->pc->parts_count)
2137 ERR("Unable to find part name \"%s\" needed in group '%s'.",
2138 alias, part->pc->part);
2143 eina_iterator_free(it);
2144 eina_hash_free(part_dest_lookup);
2145 eina_hash_free(part_pc_dest_lookup);
2147 EINA_LIST_FREE(program_lookups, program)
2150 Eina_Bool find = EINA_FALSE;
2152 #define PROGRAM_MATCH(Type, Pl, It) \
2153 for (It = 0; It < Pl->pc->programs.Type ## _count; ++It) \
2157 ep = Pl->pc->programs.Type[It]; \
2159 if ((Pl->anonymous && ep == Pl->u.ep) || \
2160 ((!Pl->anonymous) && (ep->name) && (!strcmp(ep->name, Pl->u.name)))) \
2162 *(Pl->dest) = ep->id; \
2168 PROGRAM_MATCH(fnmatch, program, i);
2169 PROGRAM_MATCH(strcmp, program, i);
2170 PROGRAM_MATCH(strncmp, program, i);
2171 PROGRAM_MATCH(strrncmp, program, i);
2172 PROGRAM_MATCH(nocmp, program, i);
2174 #undef PROGRAM_MATCH
2178 if (!program->anonymous)
2179 ERR("Unable to find program name \"%s\".",
2182 ERR("Unable to find anonymous program.");
2186 if (!program->anonymous)
2187 free(program->u.name);
2191 EINA_LIST_FREE(group_lookups, group)
2193 Edje_Part_Collection_Directory_Entry *de;
2197 if (group->part->type != EDJE_PART_TYPE_GROUP
2198 && group->part->type != EDJE_PART_TYPE_TEXTBLOCK
2199 && group->part->type != EDJE_PART_TYPE_BOX
2200 && group->part->type != EDJE_PART_TYPE_TABLE)
2204 de = eina_hash_find(edje_file->collection, group->name);
2208 Eina_Bool found = EINA_FALSE;
2210 EINA_LIST_FOREACH(aliases, l, de)
2211 if (strcmp(de->entry, group->name) == 0)
2216 if (!found) de = NULL;
2221 ERR("Unable to find group name \"%s\".", group->name);
2230 images_in_use = eina_hash_string_superfast_new(NULL);
2232 EINA_LIST_FREE(image_lookups, image)
2234 Eina_Bool find = EINA_FALSE;
2236 if (edje_file->image_dir)
2238 Edje_Image_Directory_Entry *de;
2241 for (i = 0; i < edje_file->image_dir->entries_count; ++i)
2243 de = edje_file->image_dir->entries + i;
2245 if ((de->entry) && (!strcmp(de->entry, image->name)))
2247 handle_slave_lookup(image_slave_lookups, image->dest, de->id);
2248 if (de->source_type == EDJE_IMAGE_SOURCE_TYPE_EXTERNAL)
2249 *(image->dest) = -de->id - 1;
2251 *(image->dest) = de->id;
2252 *(image->set) = EINA_FALSE;
2255 if (!eina_hash_find(images_in_use, image->name))
2256 eina_hash_direct_add(images_in_use, de->entry, de);
2263 Edje_Image_Directory_Set *set;
2265 for (i = 0; i < edje_file->image_dir->sets_count; ++i)
2267 set = edje_file->image_dir->sets + i;
2269 if ((set->name) && (!strcmp(set->name, image->name)))
2271 Edje_Image_Directory_Set_Entry *child;
2274 handle_slave_lookup(image_slave_lookups, image->dest, set->id);
2275 *(image->dest) = set->id;
2276 *(image->set) = EINA_TRUE;
2279 EINA_LIST_FOREACH(set->entries, lc, child)
2280 if (!eina_hash_find(images_in_use, child->name))
2281 eina_hash_direct_add(images_in_use, child->name, child);
2283 if (!eina_hash_find(images_in_use, image->name))
2284 eina_hash_direct_add(images_in_use, set->name, set);
2293 ERR("Unable to find image name \"%s\".", image->name);
2301 if (edje_file->image_dir && !is_lua)
2303 Edje_Image_Directory_Entry *de;
2304 Edje_Image_Directory_Set *set;
2307 for (i = 0; i < edje_file->image_dir->entries_count; ++i)
2309 de = edje_file->image_dir->entries + i;
2311 if (de->entry && eina_hash_find(images_in_use, de->entry))
2314 INF("Image '%s' in resource 'edje/image/%i' will not be included as it is unused.",
2320 for (i = 0; i < edje_file->image_dir->sets_count; ++i)
2322 set = edje_file->image_dir->sets + i;
2324 if (set->name && eina_hash_find(images_in_use, set->name))
2327 INF("Set '%s' will not be included as it is unused.", set->name);
2330 set->entries = NULL;
2334 eina_hash_free(images_in_use);
2336 EINA_LIST_FREE(part_slave_lookups, data)
2339 EINA_LIST_FREE(image_slave_lookups, data)
2344 data_process_string(Edje_Part_Collection *pc, const char *prefix, char *s, void (*func)(Edje_Part_Collection *pc, char *name, char* ptr, int len))
2351 key = alloca(strlen(prefix) + 2 + 1);
2353 strcpy(key, prefix);
2358 for (p = s; (p) && (*p); p++)
2370 if (!strncmp(p, key, keyl))
2383 if (*p == '\\') inesc = 1;
2384 else if (*p == '\"')
2386 /* string concatenation, see below */
2387 if (*(p + 1) != '\"')
2412 if (*pp == '\\') inesc = 1;
2413 else if (*pp == '\"')
2415 /* concat strings like "foo""bar" to "foobar" */
2416 if (*(pp + 1) == '\"')
2435 func(pc, name, ptr, len);
2443 if (*p == '\"') quote = 0;
2444 else if (*p == '\\') escape = 1;
2455 _data_queue_part_lookup(Edje_Part_Collection *pc, char *name, char *ptr, int len)
2459 cl = mem_alloc(SZ(Code_Lookup));
2463 data_queue_part_lookup(pc, name, &(cl->val));
2465 code_lookups = eina_list_append(code_lookups, cl);
2468 _data_queue_program_lookup(Edje_Part_Collection *pc, char *name, char *ptr, int len)
2472 cl = mem_alloc(SZ(Code_Lookup));
2476 data_queue_program_lookup(pc, name, &(cl->val));
2478 code_lookups = eina_list_append(code_lookups, cl);
2481 _data_queue_group_lookup(Edje_Part_Collection *pc __UNUSED__, char *name, char *ptr __UNUSED__, int len __UNUSED__)
2483 data_queue_group_lookup(name, NULL);
2486 _data_queue_image_pc_lookup(Edje_Part_Collection *pc __UNUSED__, char *name, char *ptr, int len)
2490 cl = mem_alloc(SZ(Code_Lookup));
2494 data_queue_image_lookup(name, &(cl->val), &(cl->set));
2496 code_lookups = eina_list_append(code_lookups, cl);
2500 data_process_scripts(void)
2504 for (l = codes, l2 = edje_collections; (l) && (l2); l = eina_list_next(l), l2 = eina_list_next(l2))
2506 Edje_Part_Collection *pc;
2509 cd = eina_list_data_get(l);
2510 pc = eina_list_data_get(l2);
2512 if ((cd->shared) && (!cd->is_lua))
2514 data_process_string(pc, "PART", cd->shared, _data_queue_part_lookup);
2515 data_process_string(pc, "PROGRAM", cd->shared, _data_queue_program_lookup);
2516 data_process_string(pc, "IMAGE", cd->shared, _data_queue_image_pc_lookup);
2517 data_process_string(pc, "GROUP", cd->shared, _data_queue_group_lookup);
2525 EINA_LIST_FOREACH(cd->programs, ll, cp)
2529 data_process_string(pc, "PART", cp->script, _data_queue_part_lookup);
2530 data_process_string(pc, "PROGRAM", cp->script, _data_queue_program_lookup);
2531 data_process_string(pc, "IMAGE", cp->script, _data_queue_image_pc_lookup);
2532 data_process_string(pc, "GROUP", cp->script, _data_queue_group_lookup);
2540 data_process_script_lookups(void)
2545 EINA_LIST_FOREACH(code_lookups, l, cl)
2550 /* FIXME !! Handle set in program */
2551 n = eina_convert_itoa(cl->val, buf);
2554 ERR("The unexpected happened. A numeric replacement string was larger than the original!");
2557 memset(cl->ptr, ' ', cl->len);
2558 strncpy(cl->ptr, buf, n);
2563 using_file(const char *filename, const char type)
2567 if (!watchfile) return;
2568 f = fopen(watchfile, "ab");
2572 fprintf(f, "%c: %s\n", type, filename);