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_List *externals = NULL;
187 Eina_List *fonts = NULL;
188 Eina_List *codes = NULL;
189 Eina_List *code_lookups = NULL;
190 Eina_List *aliases = NULL;
192 static Eet_Data_Descriptor *edd_edje_file = NULL;
193 static Eet_Data_Descriptor *edd_edje_part_collection = NULL;
195 static Eina_List *part_lookups = 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;
203 error_and_abort(Eet_File *ef __UNUSED__, const char *fmt, ...)
208 eina_log_vprint(_edje_cc_log_dom, EINA_LOG_LEVEL_CRITICAL,
209 "unknown", "unknown", 0, fmt, ap);
218 edd_edje_file = _edje_edd_edje_file;
219 edd_edje_part_collection = _edje_edd_edje_part_collection;
223 check_image_part_desc(Edje_Part_Collection *pc, Edje_Part *ep,
224 Edje_Part_Description_Image *epd, Eet_File *ef)
228 /* FIXME: This check sounds like not a useful one */
229 if (epd->image.id == -1 && epd->common.visible)
230 WRN("Collection %s(%i): image attributes missing for "
231 "part \"%s\", description \"%s\" %f",
232 pc->part, pc->id, ep->name, epd->common.state.name, epd->common.state.value);
234 for (i = 0; i < epd->image.tweens_count; ++i)
236 if (epd->image.tweens[i]->id == -1)
237 error_and_abort(ef, "Collection %i: tween image id missing for "
238 "part \"%s\", description \"%s\" %f",
239 pc->id, ep->name, epd->common.state.name, epd->common.state.value);
244 check_packed_items(Edje_Part_Collection *pc, Edje_Part *ep, Eet_File *ef)
248 for (i = 0; i < ep->items_count; ++i)
250 if (ep->items[i]->type == EDJE_PART_TYPE_GROUP && !ep->items[i]->source)
251 error_and_abort(ef, "Collection %i: missing source on packed item "
252 "of type GROUP in part \"%s\"",
254 if (ep->type == EDJE_PART_TYPE_TABLE && (ep->items[i]->col < 0 || ep->items[i]->row < 0))
255 error_and_abort(ef, "Collection %i: missing col/row on packed item "
256 "for part \"%s\" of type TABLE",
262 check_nameless_state(Edje_Part_Collection *pc, Edje_Part *ep, Edje_Part_Description_Common *ed, Eet_File *ef)
265 error_and_abort(ef, "Collection %i: description with state missing on part \"%s\"",
270 check_part(Edje_Part_Collection *pc, Edje_Part *ep, Eet_File *ef)
273 /* FIXME: check image set and sort them. */
274 if (!ep->default_desc)
275 error_and_abort(ef, "Collection %i: default description missing "
276 "for part \"%s\"", pc->id, ep->name);
278 for (i = 0; i < ep->other.desc_count; ++i)
279 check_nameless_state(pc, ep, ep->other.desc[i], ef);
281 if (ep->type == EDJE_PART_TYPE_IMAGE)
283 check_image_part_desc(pc, ep, (Edje_Part_Description_Image*) ep->default_desc, ef);
285 for (i = 0; i < ep->other.desc_count; ++i)
286 check_image_part_desc (pc, ep, (Edje_Part_Description_Image*) ep->other.desc[i], ef);
288 else if ((ep->type == EDJE_PART_TYPE_BOX) ||
289 (ep->type == EDJE_PART_TYPE_TABLE))
290 check_packed_items(pc, ep, ef);
292 /* FIXME: When mask are supported remove this check */
293 if (ep->clip_to_id != -1 &&
294 pc->parts[ep->clip_to_id]->type != EDJE_PART_TYPE_RECTANGLE)
295 error_and_abort(ef, "Collection %i: clip_to point to a non RECT part '%s' !",
296 pc->id, pc->parts[ep->clip_to_id]->name);
300 check_program(Edje_Part_Collection *pc, Edje_Program *ep, Eet_File *ef)
304 case EDJE_ACTION_TYPE_STATE_SET:
305 case EDJE_ACTION_TYPE_ACTION_STOP:
306 case EDJE_ACTION_TYPE_DRAG_VAL_SET:
307 case EDJE_ACTION_TYPE_DRAG_VAL_STEP:
308 case EDJE_ACTION_TYPE_DRAG_VAL_PAGE:
310 error_and_abort(ef, "Collection %i: target missing in program "
311 "\"%s\"", pc->id, ep->name);
319 data_thread_head(void *data, Ecore_Thread *thread __UNUSED__)
321 Head_Write *hw = data;
327 if (edje_file->collection)
329 Edje_Part_Collection_Directory_Entry *ce;
331 EINA_LIST_FREE(aliases, ce)
333 Edje_Part_Collection_Directory_Entry *sce;
338 snprintf(buf, sizeof(buf),
339 "Collection %i: name missing.", ce->id);
340 hw->errstr = strdup(buf);
344 it = eina_hash_iterator_data_new(edje_file->collection);
346 EINA_ITERATOR_FOREACH(it, sce)
348 if (ce->id == sce->id)
350 memcpy(&ce->count, &sce->count, sizeof (ce->count));
357 snprintf(buf, sizeof(buf),
358 "Collection %s (%i) can't find an correct alias.",
360 hw->errstr = strdup(buf);
363 eina_iterator_free(it);
364 eina_hash_direct_add(edje_file->collection, ce->entry, ce);
367 bytes = eet_data_write(hw->ef, edd_edje_file, "edje/file", edje_file,
371 snprintf(buf, sizeof(buf),
372 "Unable to write \"edje_file\" entry to \"%s\"",
374 hw->errstr = strdup(buf);
379 INF("Wrote %9i bytes (%4iKb) for \"edje_file\" header",
380 bytes, (bytes + 512) / 1024);
384 data_thread_head_end(void *data, Ecore_Thread *thread __UNUSED__)
386 Head_Write *hw = data;
389 if (pending_threads <= 0) ecore_main_loop_quit();
392 error_and_abort(hw->ef, hw->errstr);
399 data_write_header(Eet_File *ef)
403 hw = calloc(1, sizeof(Head_Write));
407 ecore_thread_run(data_thread_head, data_thread_head_end, NULL, hw);
410 data_thread_head(hw, NULL);
411 data_thread_head_end(hw, NULL);
416 data_thread_fonts(void *data, Ecore_Thread *thread __UNUSED__)
418 Fonts_Write *fc = data;
426 f = eina_file_open(fc->fn->file, 0);
429 using_file(fc->fn->file);
430 m = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
436 EINA_LIST_FOREACH(fnt_dirs, ll, dat)
438 snprintf(buf, sizeof(buf), "%s/%s", dat, fc->fn->file);
439 f = eina_file_open(buf, 0);
443 m = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
452 if (f) eina_file_close(f);
453 snprintf(buf, sizeof(buf),
454 "Unable to load font part \"%s\" entry to %s",
455 fc->fn->file, file_out);
456 fc->errstr = strdup(buf);
460 snprintf(buf, sizeof(buf), "edje/fonts/%s", fc->fn->name);
461 bytes = eet_write(fc->ef, buf, m, eina_file_size_get(f), compress_mode);
463 if ((bytes <= 0) || eina_file_map_faulted(f, m))
465 eina_file_map_free(f, m);
467 snprintf(buf2, sizeof(buf2),
468 "Unable to write font part \"%s\" as \"%s\" "
469 "part entry to %s", fc->fn->file, buf, file_out);
470 fc->errstr = strdup(buf2);
474 INF("Wrote %9i bytes (%4iKb) for \"%s\" font entry \"%s\" compress: [real: %2.1f%%]",
475 bytes, (bytes + 512) / 1024, buf, fc->fn->file,
476 100 - (100 * (double)bytes) / ((double)(eina_file_size_get(f)))
478 eina_file_map_free(f, m);
483 data_thread_fonts_end(void *data, Ecore_Thread *thread __UNUSED__)
485 Fonts_Write *fc = data;
487 if (pending_threads <= 0) ecore_main_loop_quit();
490 error_and_abort(fc->ef, fc->errstr);
497 data_write_fonts(Eet_File *ef, int *font_num)
502 if (!edje_file->fonts) return;
504 it = eina_hash_iterator_data_new(edje_file->fonts);
505 EINA_ITERATOR_FOREACH(it, fn)
509 fc = calloc(1, sizeof(Fonts_Write));
515 ecore_thread_run(data_thread_fonts, data_thread_fonts_end, NULL, fc);
518 data_thread_fonts(fc, NULL);
519 data_thread_fonts_end(fc, NULL);
523 eina_iterator_free(it);
527 error_and_abort_image_load_error(Eet_File *ef, const char *file, int error)
529 const char *errmsg = evas_load_error_str(error);
530 char hint[1024] = "";
532 if (error == EVAS_LOAD_ERROR_DOES_NOT_EXIST)
536 " Check if path to file \"%s\" is correct "
537 "(both directory and file name).",
540 else if (error == EVAS_LOAD_ERROR_CORRUPT_FILE)
544 " Check if file \"%s\" is consistent.",
547 else if (error == EVAS_LOAD_ERROR_UNKNOWN_FORMAT)
549 const char *ext = strrchr(file, '.');
550 const char **itr, *known_loaders[] = {
551 /* list from evas_image_load.c */
580 " File \"%s\" does not have an extension, "
587 for (itr = known_loaders; *itr; itr++)
589 if (strcasecmp(ext, *itr) == 0)
593 " Check if Evas was compiled with %s module enabled and "
594 "all required dependencies exist.",
600 snprintf(hint, sizeof(hint),
601 " Check if Evas supports loading files of type \"%s\" (%s) "
602 "and this module was compiled and all its dependencies exist.",
607 (ef, "Unable to load image \"%s\" used by file \"%s\": %s.%s",
608 file, file_out, errmsg, hint);
612 data_thread_image(void *data, Ecore_Thread *thread __UNUSED__)
614 Image_Write *iw = data;
615 char buf[PATH_MAX], buf2[PATH_MAX];
616 unsigned int *start, *end;
617 Eina_Bool opaque = EINA_TRUE;
620 if ((iw->data) && (iw->w > 0) && (iw->h > 0))
624 snprintf(buf, sizeof(buf), "edje/images/%i", iw->img->id);
626 if ((iw->img->source_type == EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT) &&
627 (iw->img->source_param == 0))
629 else if ((iw->img->source_type == EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT) &&
630 (iw->img->source_param == 1))
631 mode = 1; /* COMPRESS */
633 mode = 2; /* LOSSY */
634 if ((mode == 0) && (no_raw))
636 mode = 1; /* promote compression */
637 iw->img->source_param = 95;
639 if ((mode == 2) && (no_lossy)) mode = 1; /* demote compression */
640 if ((mode == 1) && (no_comp))
642 if (no_lossy) mode = 0; /* demote compression */
645 iw->img->source_param = 90;
646 mode = 2; /* no choice. lossy */
651 qual = iw->img->source_param;
652 if (qual < min_quality) qual = min_quality;
653 if (qual > max_quality) qual = max_quality;
657 start = (unsigned int *) iw->data;
658 end = start + (iw->w * iw->h);
661 if ((*start & 0xff000000) != 0xff000000)
668 if (opaque) iw->alpha = 0;
671 bytes = eet_data_image_write(iw->ef, buf,
672 iw->data, iw->w, iw->h,
676 bytes = eet_data_image_write(iw->ef, buf,
677 iw->data, iw->w, iw->h,
682 bytes = eet_data_image_write(iw->ef, buf,
683 iw->data, iw->w, iw->h,
688 snprintf(buf2, sizeof(buf2),
689 "Unable to write image part "
690 "\"%s\" as \"%s\" part entry to "
691 "%s", iw->img->entry, buf, file_out);
692 iw->errstr = strdup(buf2);
698 snprintf(buf, sizeof(buf), "edje/images/%i", iw->img->id);
699 snprintf(buf2, sizeof(buf2),
700 "Unable to load image part "
701 "\"%s\" as \"%s\" part entry to "
702 "%s", iw->img->entry, buf, file_out);
703 iw->errstr = strdup(buf2);
707 if (eina_log_domain_level_check(_edje_cc_log_dom, EINA_LOG_LEVEL_INFO))
711 if (!iw->path || (stat(iw->path, &st))) st.st_size = 0;
712 INF("Wrote %9i bytes (%4iKb) for \"%s\" image entry \"%s\" compress: [raw: %2.1f%%] [real: %2.1f%%]",
713 bytes, (bytes + 512) / 1024, buf, iw->img->entry,
714 100 - (100 * (double)bytes) / ((double)(iw->w * iw->h * 4)),
715 100 - (100 * (double)bytes) / ((double)(st.st_size))
721 data_thread_image_end(void *data, Ecore_Thread *thread __UNUSED__)
723 Image_Write *iw = data;
726 if (pending_threads <= 0) ecore_main_loop_quit();
729 error_and_abort(iw->ef, iw->errstr);
732 if (iw->path) free(iw->path);
733 evas_object_del(iw->im);
738 data_image_preload_done(void *data, Evas *e __UNUSED__, Evas_Object *o, void *event_info __UNUSED__)
740 Image_Write *iw = data;
742 evas_object_image_size_get(o, &iw->w, &iw->h);
743 iw->alpha = evas_object_image_alpha_get(o);
744 iw->data = evas_object_image_data_get(o, 0);
746 ecore_thread_run(data_thread_image, data_thread_image_end, NULL, iw);
749 data_thread_image(iw, NULL);
750 data_thread_image_end(iw, NULL);
755 data_write_images(Eet_File *ef, int *image_num)
761 if (!((edje_file) && (edje_file->image_dir))) return;
764 ee = ecore_evas_buffer_new(1, 1);
766 error_and_abort(ef, "Cannot create buffer engine canvas for image load.");
767 evas = ecore_evas_get(ee);
769 for (i = 0; i < (int)edje_file->image_dir->entries_count; i++)
771 Edje_Image_Directory_Entry *img;
773 img = &edje_file->image_dir->entries[i];
774 if ((img->source_type == EDJE_IMAGE_SOURCE_TYPE_EXTERNAL) ||
775 (img->entry == NULL))
783 int load_err = EVAS_LOAD_ERROR_NONE;
786 iw = calloc(1, sizeof(Image_Write));
789 iw->im = im = evas_object_image_add(evas);
791 evas_object_event_callback_add(im,
792 EVAS_CALLBACK_IMAGE_PRELOADED,
793 data_image_preload_done,
795 EINA_LIST_FOREACH(img_dirs, ll, s)
799 snprintf(buf, sizeof(buf), "%s/%s", s, img->entry);
800 evas_object_image_file_set(im, buf, NULL);
801 load_err = evas_object_image_load_error_get(im);
802 if (load_err == EVAS_LOAD_ERROR_NONE)
805 iw->path = strdup(buf);
808 evas_object_image_preload(im, 0);
811 data_image_preload_done(iw, evas, im, NULL);
815 if (load_err != EVAS_LOAD_ERROR_NONE)
817 evas_object_image_file_set(im, img->entry, NULL);
818 load_err = evas_object_image_load_error_get(im);
819 if (load_err == EVAS_LOAD_ERROR_NONE)
822 iw->path = strdup(img->entry);
825 evas_object_image_preload(im, 0);
826 using_file(img->entry);
828 data_image_preload_done(iw, evas, im, NULL);
831 error_and_abort_image_load_error
832 (ef, img->entry, load_err);
839 data_thread_sounds(void *data, Ecore_Thread *thread __UNUSED__)
841 Sound_Write *sw = data;
843 #ifdef HAVE_LIBSNDFILE
844 Edje_Sound_Encode *enc_info;
846 char *dir_path = NULL;
847 char snd_path[PATH_MAX];
853 // Search the Sound file in all the -sd ( sound directory )
854 EINA_LIST_FOREACH(snd_dirs, ll, dir_path)
856 snprintf((char *)snd_path, sizeof(snd_path), "%s/%s", dir_path,
857 sw->sample->snd_src);
858 f = eina_file_open(snd_path, 0);
863 snprintf((char *)snd_path, sizeof(snd_path), "%s",
864 sw->sample->snd_src);
865 f = eina_file_open(snd_path, 0);
867 #ifdef HAVE_LIBSNDFILE
868 if (f) eina_file_close(f);
869 enc_info = _edje_multisense_encode(snd_path, sw->sample,
870 sw->sample->quality);
871 f = eina_file_open(enc_info->file, 0);
872 if (f) using_file(enc_info->file);
874 if (f) using_file(snd_path);
878 ERR("Unable to load sound data of: %s", sw->sample->name);
882 snprintf(sndid_str, sizeof(sndid_str), "edje/sounds/%i", sw->sample->id);
883 m = eina_file_map_all(f, EINA_FILE_WILLNEED);
886 bytes = eet_write(sw->ef, sndid_str, m, eina_file_size_get(f),
887 EET_COMPRESSION_NONE);
888 if (eina_file_map_faulted(f, m))
890 ERR("File access error when reading '%s'",
891 eina_file_filename_get(f));
894 eina_file_map_free(f, m);
898 #ifdef HAVE_LIBSNDFILE
899 //If encoded temporary file, delete it.
900 if (enc_info->encoded) unlink(enc_info->file);
902 #ifdef HAVE_LIBSNDFILE
903 INF("Wrote %9i bytes (%4iKb) for \"%s\" %s sound entry \"%s\"",
904 bytes, (bytes + 512) / 1024,
905 sndid_str, enc_info->comp_type, sw->sample->name);
907 INF("Wrote %9i bytes (%4iKb) for \"%s\" %s sound entry \"%s\"",
908 bytes, (bytes + 512) / 1024,
909 sndid_str, "RAW PCM", sw->sample->name);
912 #ifdef HAVE_LIBSNDFILE
913 if ((enc_info->file) && (!enc_info->encoded))
914 eina_stringshare_del(enc_info->file);
915 if (enc_info) free(enc_info);
921 data_thread_sounds_end(void *data, Ecore_Thread *thread __UNUSED__)
923 Sound_Write *sw = data;
925 if (pending_threads <= 0) ecore_main_loop_quit();
930 data_write_sounds(Eet_File *ef, int *sound_num)
932 if ((edje_file) && (edje_file->sound_dir))
936 for (i = 0; i < (int)edje_file->sound_dir->samples_count; i++)
940 sw = calloc(1, sizeof(Sound_Write));
943 sw->sample = &edje_file->sound_dir->samples[i];
948 ecore_thread_run(data_thread_sounds, data_thread_sounds_end, NULL, sw);
951 data_thread_sounds(sw, NULL);
952 data_thread_sounds_end(sw, NULL);
959 check_groups(Eet_File *ef)
961 Edje_Part_Collection *pc;
964 /* sanity checks for parts and programs */
965 EINA_LIST_FOREACH(edje_collections, l, pc)
969 for (i = 0; i < pc->parts_count; ++i)
970 check_part(pc, pc->parts[i], ef);
972 #define CHECK_PROGRAM(Type, Pc, It) \
973 for (It = 0; It < Pc->programs.Type ## _count; ++It) \
974 check_program(Pc, Pc->programs.Type[i], ef); \
976 CHECK_PROGRAM(fnmatch, pc, i);
977 CHECK_PROGRAM(strcmp, pc, i);
978 CHECK_PROGRAM(strncmp, pc, i);
979 CHECK_PROGRAM(strrncmp, pc, i);
980 CHECK_PROGRAM(nocmp, pc, i);
985 data_thread_group(void *data, Ecore_Thread *thread __UNUSED__)
987 Group_Write *gw = data;
992 snprintf(buf, sizeof(buf), "edje/collections/%i", gw->pc->id);
993 bytes = eet_data_write(gw->ef, edd_edje_part_collection, buf, gw->pc,
998 snprintf(buf2, sizeof(buf2),
999 "Unable to write \"%s\" part entry to %s",
1001 gw->errstr = strdup(buf2);
1005 INF("Wrote %9i bytes (%4iKb) for \"%s\" aka \"%s\" collection entry",
1006 bytes, (bytes + 512) / 1024, buf, gw->pc->part);
1010 data_thread_group_end(void *data, Ecore_Thread *thread __UNUSED__)
1012 Group_Write *gw = data;
1014 if (pending_threads <= 0) ecore_main_loop_quit();
1017 error_and_abort(gw->ef, gw->errstr);
1024 data_write_groups(Eet_File *ef, int *collection_num)
1027 Edje_Part_Collection *pc;
1029 EINA_LIST_FOREACH(edje_collections, l, pc)
1033 gw = calloc(1, sizeof(Group_Write));
1036 error_and_abort(ef, "Cannot allocate memory for group writer");
1043 ecore_thread_run(data_thread_group, data_thread_group_end, NULL, gw);
1046 data_thread_group(gw, NULL);
1047 data_thread_group_end(gw, NULL);
1049 *collection_num += 1;
1054 create_script_file(Eet_File *ef, const char *filename, const Code *cd, int fd)
1056 FILE *f = fdopen(fd, "wb");
1058 error_and_abort(ef, "Unable to open temp file \"%s\" for script "
1059 "compilation.", filename);
1064 fprintf(f, "#include <edje>\n");
1069 while (ln < (cd->l1 - 1))
1079 for (sp = cd->shared; *sp; sp++)
1081 if ((sp[0] == '#') && (newlined))
1086 if (sp[0] == '\n') newlined = 1;
1087 if (!hash) fputc(sp[0], f);
1088 else if (sp[0] == '\n') hash = 0;
1092 ln += cd->l2 - cd->l1 + 1;
1094 EINA_LIST_FOREACH(cd->programs, ll, cp)
1098 while (ln < (cp->l1 - 1))
1103 /* FIXME: this prototype needs to be */
1104 /* formalised and set in stone */
1105 fprintf(f, "public _p%i(sig[], src[]) {", cp->id);
1111 for (sp = cp->script; *sp; sp++)
1113 if ((sp[0] == '#') && (newlined))
1118 if (sp[0] == '\n') newlined = 1;
1119 if (!hash) fputc(sp[0], f);
1120 else if (sp[0] == '\n') hash = 0;
1124 ln += cp->l2 - cp->l1 + 1;
1132 data_thread_script(void *data, Ecore_Thread *thread __UNUSED__)
1134 Script_Write *sc = data;
1139 f = fdopen(sc->tmpo_fd, "rb");
1142 snprintf(buf, sizeof(buf),
1143 "Unable to open script object \"%s\" for reading.",
1145 sc->errstr = strdup(buf);
1149 fseek(f, 0, SEEK_END);
1155 void *dat = malloc(size);
1159 if (fread(dat, size, 1, f) != 1)
1161 snprintf(buf, sizeof(buf),
1162 "Unable to read all of script object \"%s\"",
1164 sc->errstr = strdup(buf);
1167 snprintf(buf, sizeof(buf), "edje/scripts/embryo/compiled/%i",
1169 eet_write(sc->ef, buf, dat, size, compress_mode);
1174 snprintf(buf, sizeof(buf),
1175 "Alloc failed for %lu bytes", (unsigned long)size);
1176 sc->errstr = strdup(buf);
1187 if (sc->cd->original)
1189 snprintf(buf, PATH_MAX, "edje/scripts/embryo/source/%i", sc->i);
1190 eet_write(sc->ef, buf, sc->cd->original,
1191 strlen(sc->cd->original) + 1, compress_mode);
1193 EINA_LIST_FOREACH(sc->cd->programs, ll, cp)
1195 if (!cp->original) continue;
1196 snprintf(buf, PATH_MAX, "edje/scripts/embryo/source/%i/%i",
1198 eet_write(sc->ef, buf, cp->original,
1199 strlen(cp->original) + 1, compress_mode);
1210 data_thread_script_end(void *data, Ecore_Thread *thread __UNUSED__)
1212 Script_Write *sc = data;
1214 if (pending_threads <= 0) ecore_main_loop_quit();
1217 error_and_abort(sc->ef, sc->errstr);
1224 data_scripts_exe_del_cb(void *data __UNUSED__, int evtype __UNUSED__, void *evinfo)
1226 Script_Write *sc = data;
1227 Ecore_Exe_Event_Del *ev = evinfo;
1229 if (!ev->exe) return ECORE_CALLBACK_RENEW;
1230 if (ecore_exe_data_get(ev->exe) != sc) return ECORE_CALLBACK_RENEW;
1231 if (ev->exit_code != 0)
1233 error_and_abort(sc->ef, "Compiling script code not clean.");
1234 return ECORE_CALLBACK_CANCEL;
1239 ecore_thread_run(data_thread_script, data_thread_script_end, NULL, sc);
1244 data_thread_script(sc, NULL);
1245 data_thread_script_end(sc, NULL);
1248 if (pending_threads <= 0) ecore_main_loop_quit();
1249 return ECORE_CALLBACK_CANCEL;
1253 data_write_scripts(Eet_File *ef)
1260 tmp_dir = (char *)evil_tmpdir_get();
1265 for (i = 0, l = codes; l; l = eina_list_next(l), i++)
1267 Code *cd = eina_list_data_get(l);
1273 if ((!cd->shared) && (!cd->programs))
1275 sc = calloc(1, sizeof(Script_Write));
1279 snprintf(sc->tmpn, PATH_MAX, "%s/edje_cc.sma-tmp-XXXXXX", tmp_dir);
1280 sc->tmpn_fd = mkstemp(sc->tmpn);
1281 if (sc->tmpn_fd < 0)
1282 error_and_abort(ef, "Unable to open temp file \"%s\" for script "
1283 "compilation.", sc->tmpn);
1284 snprintf(sc->tmpo, PATH_MAX, "%s/edje_cc.amx-tmp-XXXXXX", tmp_dir);
1285 sc->tmpo_fd = mkstemp(sc->tmpo);
1286 if (sc->tmpo_fd < 0)
1289 error_and_abort(ef, "Unable to open temp file \"%s\" for script "
1290 "compilation.", sc->tmpn);
1292 create_script_file(ef, sc->tmpn, cd, sc->tmpn_fd);
1293 snprintf(buf, sizeof(buf),
1294 "%s/embryo_cc -i %s/include -o %s %s",
1295 eina_prefix_bin_get(pfx),
1296 eina_prefix_data_get(pfx),
1297 sc->tmpo, sc->tmpn);
1299 sc->exe = ecore_exe_run(buf, sc);
1300 ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
1301 data_scripts_exe_del_cb, sc);
1307 _edje_lua_script_writer(lua_State *L __UNUSED__, const void *chunk_buf, size_t chunk_size, void *_data)
1309 Script_Lua_Writer *data;
1312 data = (Script_Lua_Writer *)_data;
1314 data->buf = malloc(data->size + chunk_size);
1315 memcpy(data->buf, old, data->size);
1316 memcpy(&((data->buf)[data->size]), chunk_buf, chunk_size);
1318 data->size += chunk_size;
1325 _edje_lua_error_and_abort(lua_State *L, int err_code, Script_Write *sc)
1333 err_type = "runtime";
1336 err_type = "syntax";
1339 err_type = "memory allocation";
1342 err_type = "error handler";
1345 err_type = "unknown";
1348 snprintf(buf, sizeof(buf),
1349 "Lua %s error: %s", err_type, lua_tostring(L, -1));
1350 sc->errstr = strdup(buf);
1354 data_thread_lua_script(void *data, Ecore_Thread *thread __UNUSED__)
1356 Script_Write *sc = data;
1361 Script_Lua_Writer dat;
1368 L = luaL_newstate();
1371 snprintf(buf, sizeof(buf),
1372 "Lua error: Lua state could not be initialized");
1373 sc->errstr = strdup(buf);
1377 luaL_buffinit(L, &b);
1383 while (ln < (sc->cd->l1 - 1))
1385 luaL_addchar(&b, '\n');
1388 luaL_addstring(&b, sc->cd->shared);
1389 ln += sc->cd->l2 - sc->cd->l1;
1392 EINA_LIST_FOREACH(sc->cd->programs, ll, cp)
1396 while (ln < (cp->l1 - 1))
1398 luaL_addchar(&b, '\n');
1401 luaL_addstring(&b, "_G[");
1402 lua_pushnumber(L, cp->id);
1404 luaL_addstring(&b, "] = function (ed, signal, source)");
1405 luaL_addstring(&b, cp->script);
1406 luaL_addstring(&b, "end\n");
1407 ln += cp->l2 - cp->l1 + 1;
1410 luaL_pushresult(&b);
1412 if (err_code = luaL_loadstring(L, lua_tostring (L, -1)))
1414 _edje_lua_error_and_abort(L, err_code, sc);
1417 lua_dump(L, _edje_lua_script_writer, &dat);
1418 #else // LUA_PLAIN_TEXT
1419 dat.buf = (char *)lua_tostring(L, -1);
1420 dat.size = strlen(dat.buf);
1422 //printf("lua chunk size: %d\n", dat.size);
1425 * TODO load and test Lua chunk
1429 if (luaL_loadbuffer(L, globbuf, globbufsize, "edje_lua_script"))
1430 printf("lua load error: %s\n", lua_tostring (L, -1));
1431 if (lua_pcall(L, 0, 0, 0))
1432 printf("lua call error: %s\n", lua_tostring (L, -1));
1435 snprintf(buf, sizeof(buf), "edje/scripts/lua/%i", sc->i);
1436 if (eet_write(sc->ef, buf, dat.buf, dat.size, compress_mode) <= 0)
1438 snprintf(buf, sizeof(buf),
1439 "Unable to write script %i", sc->i);
1440 sc->errstr = strdup(buf);
1450 data_thread_lua_script_end(void *data, Ecore_Thread *thread __UNUSED__)
1452 Script_Write *sc = data;
1454 if (pending_threads <= 0) ecore_main_loop_quit();
1457 error_and_abort(sc->ef, sc->errstr);
1464 data_write_lua_scripts(Eet_File *ef)
1469 for (i = 0, l = codes; l; l = eina_list_next(l), i++)
1474 cd = (Code *)eina_list_data_get(l);
1477 if ((!cd->shared) && (!cd->programs))
1480 sc = calloc(1, sizeof(Script_Write));
1486 ecore_thread_run(data_thread_lua_script, data_thread_lua_script_end, NULL, sc);
1489 data_thread_lua_script(sc, NULL);
1490 data_thread_lua_script_end(sc, NULL);
1496 data_thread_source(void *data, Ecore_Thread *thread __UNUSED__)
1498 Eet_File *ef = data;
1503 data_thread_source_end(void *data __UNUSED__, Ecore_Thread *thread __UNUSED__)
1506 if (pending_threads <= 0) ecore_main_loop_quit();
1510 data_thread_fontmap(void *data, Ecore_Thread *thread __UNUSED__)
1512 Eet_File *ef = data;
1513 source_fontmap_save(ef, fonts);
1517 data_thread_fontmap_end(void *data __UNUSED__, Ecore_Thread *thread __UNUSED__)
1520 if (pending_threads <= 0) ecore_main_loop_quit();
1530 int collection_num = 0;
1535 ERR("No data to put in \"%s\"", file_out);
1539 ef = eet_open(file_out, EET_FILE_MODE_WRITE);
1542 ERR("Unable to open \"%s\" for writing output", file_out);
1548 ecore_thread_max_set(ecore_thread_max_get() * 2);
1551 t = ecore_time_get();
1552 data_write_header(ef);
1554 INF("header: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1555 data_write_groups(ef, &collection_num);
1556 INF("groups: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1557 data_write_scripts(ef);
1558 INF("scripts: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1559 data_write_lua_scripts(ef);
1560 INF("lua scripts: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1564 ecore_thread_run(data_thread_source, data_thread_source_end, NULL, ef);
1567 data_thread_source(ef, NULL);
1568 data_thread_source_end(ef, NULL);
1570 INF("source: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1573 ecore_thread_run(data_thread_fontmap, data_thread_fontmap_end, NULL, ef);
1576 data_thread_fontmap(ef, NULL);
1577 data_thread_fontmap_end(ef, NULL);
1579 INF("fontmap: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1580 data_write_images(ef, &image_num);
1581 INF("images: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1582 data_write_fonts(ef, &font_num);
1583 INF("fonts: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1584 data_write_sounds(ef, &sound_num);
1585 INF("sounds: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1587 if (pending_threads > 0) ecore_main_loop_begin();
1588 INF("THREADS: %3.5f", ecore_time_get() - t); t = ecore_time_get();
1592 if (eina_log_domain_level_check(_edje_cc_log_dom, EINA_LOG_LEVEL_INFO))
1595 " Wrote %i collections\n"
1596 " Wrote %i images\n"
1597 " Wrote %i sounds\n"
1610 Edje_Part_Collection *pc;
1612 Edje_Part_Parser *ep, *ep2;
1615 /* sanity checks for parts and programs */
1616 EINA_LIST_FOREACH(edje_collections, l, pc)
1618 unsigned int i, j, k;
1619 Eina_Bool found = EINA_FALSE;
1621 for (i = 0; i < pc->parts_count; i++)
1623 ep = (Edje_Part_Parser *)pc->parts[i];
1624 if (ep->reorder.insert_before && ep->reorder.insert_after)
1625 ERR("Unable to use together insert_before and insert_after in part \"%s\".", pc->parts[i]->name);
1627 if (ep->reorder.done)
1631 if (ep->reorder.insert_before || ep->reorder.insert_after)
1634 for (j = 0; j < pc->parts_count; j++)
1636 if (ep->reorder.insert_before &&
1637 !strcmp(ep->reorder.insert_before, pc->parts[j]->name))
1639 ep2 = (Edje_Part_Parser *)pc->parts[j];
1640 if (ep2->reorder.after)
1641 ERR("The part \"%s\" is ambiguous ordered part.",
1642 pc->parts[i]->name);
1643 if (ep2->reorder.linked_prev)
1644 ERR("Unable to insert two or more parts in same part \"%s\".",
1645 pc->parts[j]->name);
1648 ep2->reorder.linked_prev += ep->reorder.linked_prev + 1;
1649 ep->reorder.before = (Edje_Part_Parser *)pc->parts[j];
1650 while (ep2->reorder.before)
1652 ep2->reorder.before->reorder.linked_prev = ep2->reorder.linked_prev + 1;
1653 ep2 = ep2->reorder.before;
1657 else if (ep->reorder.insert_after &&
1658 !strcmp(ep->reorder.insert_after, pc->parts[j]->name))
1660 ep2 = (Edje_Part_Parser *)pc->parts[j];
1661 if (ep2->reorder.before)
1662 ERR("The part \"%s\" is ambiguous ordered part.", pc->parts[i]->name);
1663 if (ep2->reorder.linked_next)
1664 ERR("Unable to insert two or more parts in same part \"%s\".", pc->parts[j]->name);
1667 ep2->reorder.linked_next += ep->reorder.linked_next + 1;
1668 ep->reorder.after = (Edje_Part_Parser *)pc->parts[j];
1669 while (ep2->reorder.after)
1671 ep2->reorder.after->reorder.linked_next = ep2->reorder.linked_next + 1;
1672 ep2 = ep2->reorder.after;
1679 unsigned int amount, linked;
1681 if (((i > k) && ((i - ep->reorder.linked_prev) <= k))
1682 || ((i < k) && ((i + ep->reorder.linked_next) >= k)))
1683 ERR("The part order is wrong. It has circular dependency.");
1685 amount = ep->reorder.linked_prev + ep->reorder.linked_next + 1;
1686 linked = i - ep->reorder.linked_prev;
1687 parts = malloc(amount * sizeof(Edje_Part));
1688 for (j = 0 ; j < amount ; j++)
1690 parts[j] = pc->parts[linked];
1695 for (j = i - ep->reorder.linked_prev - 1 ; j >= k ; j--)
1697 pc->parts[j + amount] = pc->parts[j];
1698 pc->parts[j + amount]->id = j + amount;
1700 for (j = 0 ; j < amount ; j++)
1702 pc->parts[j + k] = parts[j];
1703 pc->parts[j + k]->id = j + k;
1708 for (j = i + ep->reorder.linked_next + 1 ; j <= k ; j++)
1710 pc->parts[j - amount] = pc->parts[j];
1711 pc->parts[j - amount]->id = j - amount;
1713 for (j = 0 ; j < amount ; j++)
1715 pc->parts[j + k - amount + 1] = parts[j];
1716 pc->parts[j + k - amount + 1]->id = j + k - amount + 1;
1720 ep->reorder.done = EINA_TRUE;
1729 data_queue_group_lookup(const char *name, Edje_Part *part)
1733 if (!name || !name[0]) return;
1735 gl = mem_alloc(SZ(Group_Lookup));
1736 group_lookups = eina_list_append(group_lookups, gl);
1737 gl->name = mem_strdup(name);
1741 //#define NEWPARTLOOKUP 1
1742 #ifdef NEWPARTLOOKUP
1743 static Eina_Hash *_part_lookups_hash = NULL;
1744 static Eina_Hash *_part_lookups_dest_hash = NULL;
1748 data_queue_part_lookup(Edje_Part_Collection *pc, const char *name, int *dest)
1750 Part_Lookup *pl = NULL;
1752 #ifdef NEWPARTLOOKUP
1756 #ifdef NEWPARTLOOKUP
1757 snprintf(buf, sizeof(buf), "%lu-%lu",
1758 (unsigned long)name, (unsigned long)dest);
1759 if (_part_lookups_hash) pl = eina_hash_find(_part_lookups_hash, buf);
1764 pl->name = mem_strdup(name);
1767 eina_hash_del(_part_lookups_hash, buf, pl);
1768 snprintf(buf, sizeof(buf), "%lu", (unsigned long)dest);
1769 eina_hash_del(_part_lookups_dest_hash, buf, pl);
1770 part_lookups = eina_list_remove(part_lookups, pl);
1776 EINA_LIST_FOREACH(part_lookups, l, pl)
1778 if ((pl->pc == pc) && (pl->dest == dest))
1782 pl->name = mem_strdup(name);
1785 part_lookups = eina_list_remove(part_lookups, pl);
1792 if (!name[0]) return;
1794 pl = mem_alloc(SZ(Part_Lookup));
1795 part_lookups = eina_list_prepend(part_lookups, pl);
1797 pl->name = mem_strdup(name);
1799 #ifdef NEWPARTLOOKUP
1800 if (!_part_lookups_hash)
1801 _part_lookups_hash = eina_hash_string_superfast_new(NULL);
1802 eina_hash_add(_part_lookups_hash, buf, pl);
1804 snprintf(buf, sizeof(buf), "%lu", (unsigned long)dest);
1805 if (!_part_lookups_dest_hash)
1806 _part_lookups_dest_hash = eina_hash_string_superfast_new(NULL);
1807 l = eina_hash_find(_part_lookups_dest_hash, buf);
1810 l = eina_list_append(l, pl);
1811 eina_hash_modify(_part_lookups_dest_hash, buf, l);
1815 l = eina_list_append(l, pl);
1816 eina_hash_add(_part_lookups_dest_hash, buf, l);
1822 data_queue_copied_part_lookup(Edje_Part_Collection *pc, int *src, int *dest)
1826 #ifdef NEWPARTLOOKUP
1831 #ifdef NEWPARTLOOKUP
1832 if (!_part_lookups_dest_hash) return;
1833 snprintf(buf, sizeof(buf), "%lu", (unsigned long)src);
1834 list = eina_hash_find(_part_lookups_dest_hash, buf);
1835 EINA_LIST_FOREACH(list, l, pl)
1837 data_queue_part_lookup(pc, pl->name, dest);
1840 EINA_LIST_FOREACH(part_lookups, l, pl)
1842 if (pl->dest == src)
1843 data_queue_part_lookup(pc, pl->name, dest);
1849 data_queue_anonymous_lookup(Edje_Part_Collection *pc, Edje_Program *ep, int *dest)
1854 if (!ep) return ; /* FIXME: should we stop compiling ? */
1856 EINA_LIST_FOREACH(program_lookups, l, pl)
1863 cd = eina_list_data_get(eina_list_last(codes));
1865 EINA_LIST_FOREACH(cd->programs, l2, cp)
1867 if (&(cp->id) == pl->dest)
1869 cd->programs = eina_list_remove(cd->programs, cp);
1874 program_lookups = eina_list_remove(program_lookups, pl);
1881 pl = mem_alloc(SZ(Program_Lookup));
1882 program_lookups = eina_list_append(program_lookups, pl);
1886 pl->anonymous = EINA_TRUE;
1891 data_queue_copied_anonymous_lookup(Edje_Part_Collection *pc, int *src, int *dest)
1897 EINA_LIST_FOREACH(program_lookups, l, pl)
1899 if (pl->dest == src)
1901 for (i = 0 ; i < pc->programs.fnmatch_count ; i++)
1903 if (pl->u.ep->name && pc->programs.fnmatch[i]->name &&
1904 !strcmp(pl->u.ep->name, pc->programs.fnmatch[i]->name))
1905 data_queue_anonymous_lookup(pc, pc->programs.fnmatch[i], dest);
1907 for (i = 0 ; i < pc->programs.strcmp_count ; i++)
1909 if (pl->u.ep->name && pc->programs.strcmp[i]->name &&
1910 !strcmp(pl->u.ep->name, pc->programs.strcmp[i]->name))
1911 data_queue_anonymous_lookup(pc, pc->programs.strcmp[i], dest);
1913 for (i = 0 ; i < pc->programs.strncmp_count ; i++)
1915 if (pl->u.ep->name && pc->programs.strncmp[i]->name &&
1916 !strcmp(pl->u.ep->name, pc->programs.strncmp[i]->name))
1917 data_queue_anonymous_lookup(pc, pc->programs.strncmp[i], dest);
1919 for (i = 0 ; i < pc->programs.strrncmp_count ; i++)
1921 if (pl->u.ep->name && pc->programs.strrncmp[i]->name &&
1922 !strcmp(pl->u.ep->name, pc->programs.strrncmp[i]->name))
1923 data_queue_anonymous_lookup(pc, pc->programs.strrncmp[i], dest);
1925 for (i = 0 ; i < pc->programs.nocmp_count ; i++)
1927 if (pl->u.ep->name && pc->programs.nocmp[i]->name &&
1928 !strcmp(pl->u.ep->name, pc->programs.nocmp[i]->name))
1929 data_queue_anonymous_lookup(pc, pc->programs.nocmp[i], dest);
1936 data_queue_program_lookup(Edje_Part_Collection *pc, const char *name, int *dest)
1940 if (!name) return ; /* FIXME: should we stop compiling ? */
1942 pl = mem_alloc(SZ(Program_Lookup));
1943 program_lookups = eina_list_append(program_lookups, pl);
1945 pl->u.name = mem_strdup(name);
1947 pl->anonymous = EINA_FALSE;
1951 data_queue_copied_program_lookup(Edje_Part_Collection *pc, int *src, int *dest)
1956 EINA_LIST_FOREACH(program_lookups, l, pl)
1958 if (pl->dest == src)
1959 data_queue_program_lookup(pc, pl->u.name, dest);
1964 data_queue_image_lookup(char *name, int *dest, Eina_Bool *set)
1968 il = mem_alloc(SZ(Image_Lookup));
1969 image_lookups = eina_list_append(image_lookups, il);
1970 il->name = mem_strdup(name);
1976 data_queue_image_remove(int *dest, Eina_Bool *set)
1981 EINA_LIST_FOREACH(image_lookups, l, il)
1983 if (il->dest == dest && il->set == set)
1985 image_lookups = eina_list_remove_list(image_lookups, l);
1994 data_queue_copied_image_lookup(int *src, int *dest, Eina_Bool *set)
1999 EINA_LIST_FOREACH(image_lookups, l, il)
2001 if (il->dest == src)
2002 data_queue_image_lookup(il->name, dest, set);
2006 data_queue_part_slave_lookup(int *master, int *slave)
2010 sl = mem_alloc(SZ(Slave_Lookup));
2011 part_slave_lookups = eina_list_append(part_slave_lookups, sl);
2012 sl->master = master;
2017 data_queue_image_slave_lookup(int *master, int *slave)
2021 sl = mem_alloc(SZ(Slave_Lookup));
2022 image_slave_lookups = eina_list_append(image_slave_lookups, sl);
2023 sl->master = master;
2028 handle_slave_lookup(Eina_List *list, int *master, int value)
2033 EINA_LIST_FOREACH(list, l, sl)
2034 if (sl->master == master)
2039 data_process_lookups(void)
2041 Edje_Part_Collection *pc;
2043 Program_Lookup *program;
2044 Group_Lookup *group;
2045 Image_Lookup *image;
2048 Eina_Hash *images_in_use;
2050 Eina_Bool is_lua = EINA_FALSE;
2052 /* remove all unreferenced Edje_Part_Collection */
2053 EINA_LIST_FOREACH_SAFE(edje_collections, l, l2, pc)
2055 Edje_Part_Collection_Directory_Entry *alias;
2056 Edje_Part_Collection_Directory_Entry *find;
2058 unsigned int id = 0;
2063 ERR("A collection without a name was detected, that's not allowed.");
2066 find = eina_hash_find(edje_file->collection, pc->part);
2067 if (find && find->id == pc->id)
2070 EINA_LIST_FOREACH(aliases, l3, alias)
2071 if (alias->id == pc->id)
2074 /* This Edje_Part_Collection is not used at all */
2075 edje_collections = eina_list_remove_list(edje_collections, l);
2076 l3 = eina_list_nth_list(codes, pc->id);
2077 codes = eina_list_remove_list(codes, l3);
2079 /* Unref all image used by that group */
2080 for (i = 0; i < pc->parts_count; ++i)
2081 part_description_image_cleanup(pc->parts[i]);
2083 /* Correct all id */
2084 EINA_LIST_FOREACH(edje_collections, l3, pc)
2088 /* Some group could be removed from the collection, but still be referenced by alias */
2089 find = eina_hash_find(edje_file->collection, pc->part);
2090 if (pc->id != find->id) find = NULL;
2092 /* Update all matching alias */
2093 EINA_LIST_FOREACH(aliases, l4, alias)
2094 if (pc->id == alias->id)
2098 if (find) find->id = pc->id;
2102 EINA_LIST_FOREACH(edje_collections, l, pc)
2104 unsigned int count = 0;
2107 if (pc->lua_script_only)
2109 #define PROGRAM_ID_SET(Type, Pc, It, Count) \
2110 for (It = 0; It < Pc->programs.Type ## _count; ++It) \
2112 Pc->programs.Type[It]->id = Count++; \
2115 PROGRAM_ID_SET(fnmatch, pc, i, count);
2116 PROGRAM_ID_SET(strcmp, pc, i, count);
2117 PROGRAM_ID_SET(strncmp, pc, i, count);
2118 PROGRAM_ID_SET(strrncmp, pc, i, count);
2119 PROGRAM_ID_SET(nocmp, pc, i, count);
2121 #undef PROGRAM_ID_SET
2124 EINA_LIST_FREE(part_lookups, part)
2129 if (!strcmp(part->name, "-"))
2136 alias = eina_hash_find(part->pc->alias, part->name);
2139 for (i = 0; i < part->pc->parts_count; ++i)
2141 ep = part->pc->parts[i];
2143 if ((ep->name) && (!strcmp(ep->name, alias)))
2145 handle_slave_lookup(part_slave_lookups, part->dest, ep->id);
2146 *(part->dest) = ep->id;
2151 if (i == part->pc->parts_count)
2153 ERR("Unable to find part name \"%s\" needed in group '%s'.",
2154 alias, part->pc->part);
2163 EINA_LIST_FREE(program_lookups, program)
2166 Eina_Bool find = EINA_FALSE;
2168 #define PROGRAM_MATCH(Type, Pl, It) \
2169 for (It = 0; It < Pl->pc->programs.Type ## _count; ++It) \
2173 ep = Pl->pc->programs.Type[It]; \
2175 if ((Pl->anonymous && ep == Pl->u.ep) || \
2176 ((!Pl->anonymous) && (ep->name) && (!strcmp(ep->name, Pl->u.name)))) \
2178 *(Pl->dest) = ep->id; \
2184 PROGRAM_MATCH(fnmatch, program, i);
2185 PROGRAM_MATCH(strcmp, program, i);
2186 PROGRAM_MATCH(strncmp, program, i);
2187 PROGRAM_MATCH(strrncmp, program, i);
2188 PROGRAM_MATCH(nocmp, program, i);
2190 #undef PROGRAM_MATCH
2194 if (!program->anonymous)
2195 ERR("Unable to find program name \"%s\".",
2198 ERR("Unable to find anonymous program.");
2202 if (!program->anonymous)
2203 free(program->u.name);
2207 EINA_LIST_FREE(group_lookups, group)
2209 Edje_Part_Collection_Directory_Entry *de;
2213 if (group->part->type != EDJE_PART_TYPE_GROUP
2214 && group->part->type != EDJE_PART_TYPE_TEXTBLOCK
2215 && group->part->type != EDJE_PART_TYPE_BOX
2216 && group->part->type != EDJE_PART_TYPE_TABLE)
2220 de = eina_hash_find(edje_file->collection, group->name);
2224 Eina_Bool found = EINA_FALSE;
2226 EINA_LIST_FOREACH(aliases, l, de)
2227 if (strcmp(de->entry, group->name) == 0)
2232 if (!found) de = NULL;
2237 ERR("Unable to find group name \"%s\".", group->name);
2246 images_in_use = eina_hash_string_superfast_new(NULL);
2248 EINA_LIST_FREE(image_lookups, image)
2250 Eina_Bool find = EINA_FALSE;
2252 if (edje_file->image_dir)
2254 Edje_Image_Directory_Entry *de;
2257 for (i = 0; i < edje_file->image_dir->entries_count; ++i)
2259 de = edje_file->image_dir->entries + i;
2261 if ((de->entry) && (!strcmp(de->entry, image->name)))
2263 handle_slave_lookup(image_slave_lookups, image->dest, de->id);
2264 if (de->source_type == EDJE_IMAGE_SOURCE_TYPE_EXTERNAL)
2265 *(image->dest) = -de->id - 1;
2267 *(image->dest) = de->id;
2268 *(image->set) = EINA_FALSE;
2271 if (!eina_hash_find(images_in_use, image->name))
2272 eina_hash_direct_add(images_in_use, de->entry, de);
2279 Edje_Image_Directory_Set *set;
2281 for (i = 0; i < edje_file->image_dir->sets_count; ++i)
2283 set = edje_file->image_dir->sets + i;
2285 if ((set->name) && (!strcmp(set->name, image->name)))
2287 Edje_Image_Directory_Set_Entry *child;
2290 handle_slave_lookup(image_slave_lookups, image->dest, set->id);
2291 *(image->dest) = set->id;
2292 *(image->set) = EINA_TRUE;
2295 EINA_LIST_FOREACH(set->entries, lc, child)
2296 if (!eina_hash_find(images_in_use, child->name))
2297 eina_hash_direct_add(images_in_use, child->name, child);
2299 if (!eina_hash_find(images_in_use, image->name))
2300 eina_hash_direct_add(images_in_use, set->name, set);
2309 ERR("Unable to find image name \"%s\".", image->name);
2317 if (edje_file->image_dir && !is_lua)
2319 Edje_Image_Directory_Entry *de;
2320 Edje_Image_Directory_Set *set;
2323 for (i = 0; i < edje_file->image_dir->entries_count; ++i)
2325 de = edje_file->image_dir->entries + i;
2327 if (de->entry && eina_hash_find(images_in_use, de->entry))
2330 INF("Image '%s' in resource 'edje/image/%i' will not be included as it is unused.",
2336 for (i = 0; i < edje_file->image_dir->sets_count; ++i)
2338 set = edje_file->image_dir->sets + i;
2340 if (set->name && eina_hash_find(images_in_use, set->name))
2343 INF("Set '%s' will not be included as it is unused.", set->name);
2346 set->entries = NULL;
2350 eina_hash_free(images_in_use);
2352 EINA_LIST_FREE(part_slave_lookups, data)
2355 EINA_LIST_FREE(image_slave_lookups, data)
2360 data_process_string(Edje_Part_Collection *pc, const char *prefix, char *s, void (*func)(Edje_Part_Collection *pc, char *name, char* ptr, int len))
2367 key = alloca(strlen(prefix) + 2 + 1);
2369 strcpy(key, prefix);
2374 for (p = s; (p) && (*p); p++)
2386 if (!strncmp(p, key, keyl))
2399 if (*p == '\\') inesc = 1;
2400 else if (*p == '\"')
2402 /* string concatenation, see below */
2403 if (*(p + 1) != '\"')
2428 if (*pp == '\\') inesc = 1;
2429 else if (*pp == '\"')
2431 /* concat strings like "foo""bar" to "foobar" */
2432 if (*(pp + 1) == '\"')
2451 func(pc, name, ptr, len);
2459 if (*p == '\"') quote = 0;
2460 else if (*p == '\\') escape = 1;
2471 _data_queue_part_lookup(Edje_Part_Collection *pc, char *name, char *ptr, int len)
2475 cl = mem_alloc(SZ(Code_Lookup));
2479 data_queue_part_lookup(pc, name, &(cl->val));
2481 code_lookups = eina_list_append(code_lookups, cl);
2484 _data_queue_program_lookup(Edje_Part_Collection *pc, char *name, char *ptr, int len)
2488 cl = mem_alloc(SZ(Code_Lookup));
2492 data_queue_program_lookup(pc, name, &(cl->val));
2494 code_lookups = eina_list_append(code_lookups, cl);
2497 _data_queue_group_lookup(Edje_Part_Collection *pc __UNUSED__, char *name, char *ptr __UNUSED__, int len __UNUSED__)
2499 data_queue_group_lookup(name, NULL);
2502 _data_queue_image_pc_lookup(Edje_Part_Collection *pc __UNUSED__, char *name, char *ptr, int len)
2506 cl = mem_alloc(SZ(Code_Lookup));
2510 data_queue_image_lookup(name, &(cl->val), &(cl->set));
2512 code_lookups = eina_list_append(code_lookups, cl);
2516 data_process_scripts(void)
2520 for (l = codes, l2 = edje_collections; (l) && (l2); l = eina_list_next(l), l2 = eina_list_next(l2))
2522 Edje_Part_Collection *pc;
2525 cd = eina_list_data_get(l);
2526 pc = eina_list_data_get(l2);
2528 if ((cd->shared) && (!cd->is_lua))
2530 data_process_string(pc, "PART", cd->shared, _data_queue_part_lookup);
2531 data_process_string(pc, "PROGRAM", cd->shared, _data_queue_program_lookup);
2532 data_process_string(pc, "IMAGE", cd->shared, _data_queue_image_pc_lookup);
2533 data_process_string(pc, "GROUP", cd->shared, _data_queue_group_lookup);
2541 EINA_LIST_FOREACH(cd->programs, ll, cp)
2545 data_process_string(pc, "PART", cp->script, _data_queue_part_lookup);
2546 data_process_string(pc, "PROGRAM", cp->script, _data_queue_program_lookup);
2547 data_process_string(pc, "IMAGE", cp->script, _data_queue_image_pc_lookup);
2548 data_process_string(pc, "GROUP", cp->script, _data_queue_group_lookup);
2556 data_process_script_lookups(void)
2561 EINA_LIST_FOREACH(code_lookups, l, cl)
2566 /* FIXME !! Handle set in program */
2567 n = eina_convert_itoa(cl->val, buf);
2570 ERR("The unexpected happened. A numeric replacement string was larger than the original!");
2573 memset(cl->ptr, ' ', cl->len);
2574 strncpy(cl->ptr, buf, n);
2579 using_file(const char *filename)
2583 if (!watchfile) return;
2584 f = fopen(watchfile, "ab");