summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2014-09-22 17:03:18 +0300
committerYakov Goldberg <yakov.g@samsung.com>2014-10-02 10:14:37 +0300
commit5a9f2848e3e7cd9297759918fb74002a3e816d9c (patch)
treee24cb8907a0ad277081d939bffde2a1cbb9b57eb
parent39f502168f3b0f9d74889a702e945c14af9e9643 (diff)
Generator: more code moving and context generation refactoring
-rw-r--r--src/lib/generator.c307
1 files changed, 152 insertions, 155 deletions
diff --git a/src/lib/generator.c b/src/lib/generator.c
index 3bfccf1..2d474ad 100644
--- a/src/lib/generator.c
+++ b/src/lib/generator.c
@@ -14,11 +14,13 @@
14typedef struct 14typedef struct
15{ 15{
16 const Gui_Context *ctx; /* Context with all data about widgets*/ 16 const Gui_Context *ctx; /* Context with all data about widgets*/
17 Eina_Strbuf *buf; /* buffer to print data into it */ 17 Eina_Strbuf *c_buf; /* buffer for source */
18 Eina_Strbuf *h_buf; /* buffer for headers */
18 Eina_List *global_entities; /* widgets ids which must be global */ 19 Eina_List *global_entities; /* widgets ids which must be global */
19 Eina_List *public_entities; /* widgets ids which must be public */ 20 Eina_List *public_entities; /* widgets ids which must be public */
20 Eina_List *public_main_wdgs; 21 Eina_List *public_main_wdgs;
21 char *formatted_project_name; 22 char *formatted_project_name;
23 Gui_Session *session;
22} Global_Gen_Context; 24} Global_Gen_Context;
23 25
24typedef struct 26typedef struct
@@ -39,8 +41,6 @@ typedef struct
39static Eina_Bool 41static Eina_Bool
40_c_generator_generator_interface_global_names_generate(const Eina_List *global_entities, Eina_Strbuf *buf); 42_c_generator_generator_interface_global_names_generate(const Eina_List *global_entities, Eina_Strbuf *buf);
41static Eina_Bool 43static Eina_Bool
42_c_generator_generator_interface_main_function_generate(const Gui_Context *ctx, Eina_Strbuf *buf);
43static Eina_Bool
44_c_generator_generator_interface_widget_create(const Gui_Widget *wdg, Eina_Strbuf *buf); 44_c_generator_generator_interface_widget_create(const Gui_Widget *wdg, Eina_Strbuf *buf);
45static Eina_Bool 45static Eina_Bool
46_c_generator_generator_interface_widget_property_add(const Gui_Widget *wdg, const Gui_Widget_Property *prop, Eina_Strbuf *buf); 46_c_generator_generator_interface_widget_property_add(const Gui_Widget *wdg, const Gui_Widget_Property *prop, Eina_Strbuf *buf);
@@ -63,7 +63,7 @@ _is_in_list(Eina_List *lst, Dep_Id *dep_id)
63/* Replaces spaces and dashes to underscore, 63/* Replaces spaces and dashes to underscore,
64 * and lowercase string*/ 64 * and lowercase string*/
65static char* 65static char*
66_project_name_format(char *in_str) 66_project_name_format(const char *in_str)
67{ 67{
68 Eina_Strbuf *buf = eina_strbuf_new(); 68 Eina_Strbuf *buf = eina_strbuf_new();
69 eina_strbuf_append_printf(buf, "%s", in_str); 69 eina_strbuf_append_printf(buf, "%s", in_str);
@@ -174,7 +174,7 @@ _format_string_add(const Gui_Context *ctx, Gui_Value *gui_value, Eina_Strbuf *p)
174 res = gui_context_resource_get(dep_id); 174 res = gui_context_resource_get(dep_id);
175 if (res) 175 if (res)
176 { 176 {
177 char *formatted = (char *) _project_name_format((char *) gui_context_project_name_get(ctx)); 177 char *formatted = (char *) _project_name_format(gui_context_project_name_get(ctx));
178 /* FIXME: remove this casting when item_append will support Eo_Callbacks. */ 178 /* FIXME: remove this casting when item_append will support Eo_Callbacks. */
179 eina_strbuf_append_printf(p, "(Evas_Smart_Cb) %s_%s", formatted, resource_name_get(res)); 179 eina_strbuf_append_printf(p, "(Evas_Smart_Cb) %s_%s", formatted, resource_name_get(res));
180 free(formatted); 180 free(formatted);
@@ -495,7 +495,7 @@ _wdg_cb_add_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, co
495 if (seq) 495 if (seq)
496 { 496 {
497 char _buf[1000] = {'\0'}; 497 char _buf[1000] = {'\0'};
498 char *formatted = (char *) _project_name_format((char *) gui_context_project_name_get(ctx)); 498 char *formatted = (char *) _project_name_format(gui_context_project_name_get(ctx));
499 sprintf(_buf, "%s_%s", formatted, sequence_name_get(seq)); 499 sprintf(_buf, "%s_%s", formatted, sequence_name_get(seq));
500 free(formatted); 500 free(formatted);
501 cb_name = _buf; 501 cb_name = _buf;
@@ -518,68 +518,22 @@ _wdg_cb_add_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, co
518 return ret; 518 return ret;
519} 519}
520 520
521/* Save context into "project" files. */
522static void 521static void
523_ctx_to_file_save(const Gui_Context *ctx) 522_ctx_generate(Global_Gen_Context *gl_ctx)
524{ 523{
525 char *filename_c = NULL; 524 const Gui_Context *ctx = gl_ctx->ctx;
526 char *filename_h = NULL;
527 FILE *fp_c = NULL, *fp_h = NULL;
528 const Eina_List *itr;
529
530 /* If code must be generated, create C and H files*/
531 const char *path = gui_context_export_path_get(ctx);
532 const char *filename = gui_context_export_filename_get(ctx); 525 const char *filename = gui_context_export_filename_get(ctx);
533 filename_c = (char *) calloc(strlen(path) + strlen(filename) + 4, 1); 526 const Eina_List *itr;
534 sprintf(filename_c, "%s/%s%s", path, filename, ".c");
535 fp_c = fopen(filename_c, "w+");
536 if (!fp_c)
537 {
538 ERR("Can't create file: %s", filename_c);
539 goto end;
540 }
541
542 filename_h = (char *) calloc(strlen(path) + strlen(filename) + 4, 1);
543 sprintf(filename_h, "%s/%s%s", path, filename, ".h");
544 fp_h = fopen(filename_h, "w+");
545 if (!fp_h)
546 {
547 ERR("Can't create file: %s", filename_h);
548 goto end;
549 }
550
551 /* Define global generator context */
552 Global_Gen_Context gl_gen_ctx;
553 gl_gen_ctx.ctx = ctx;
554 gl_gen_ctx.buf = eina_strbuf_new();
555 gl_gen_ctx.global_entities = NULL;
556 gl_gen_ctx.public_entities = NULL;
557 gl_gen_ctx.public_main_wdgs = NULL;
558 gl_gen_ctx.formatted_project_name = _project_name_format((char *) gui_context_project_name_get(ctx));
559 527
560 eina_strbuf_append_printf(gl_gen_ctx.buf, 528 Eina_Strbuf *resources_buf = eina_strbuf_new();
561 "#include <Elementary.h>\n"
562 "#include \"elm_widget_container.h\"\n"
563 "#include \"elm_interface_scrollable.h\"\n"
564 "#include \"%s.h\"\n\n", filename);
565 529
566 eina_strbuf_append_printf(gl_gen_ctx.buf, 530 Sequence_Context seq_ctx;
567 "static GUI %s;\n\n", PUB_WIDGETS); 531 seq_ctx.gl_ctx = gl_ctx;
568 eina_strbuf_append_printf(gl_gen_ctx.buf, "__GLOBAL_NAMES__"); 532 seq_ctx.buf = eina_strbuf_new();
569 533
570 /* Add declarations of resource callbacks. */ 534 Widget_Context wdg_ctx;
571 Dep_Id *res_id; 535 wdg_ctx.gl_ctx = gl_ctx;
572 const Eina_List *res_lst = gui_context_resource_list_get(ctx, RESOURCE_EO_CALLBACK); 536 wdg_ctx.buf = eina_strbuf_new();
573 EINA_LIST_FOREACH(res_lst, itr, res_id)
574 {
575 const Gui_Resource *res = gui_context_resource_get(res_id);
576 if (res && resource_type_get(res) == RESOURCE_EO_CALLBACK)
577 {
578 eina_strbuf_append_printf(gl_gen_ctx.buf,
579 "extern Eina_Bool\n%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n",
580 resource_value_get(res));
581 }
582 }
583 537
584 /* Add declaration of image paths. 538 /* Add declaration of image paths.
585 * Two cases are generated: 539 * Two cases are generated:
@@ -592,48 +546,53 @@ _ctx_to_file_save(const Gui_Context *ctx)
592 for (i = 1; i < RESOURCE_SENTINEL; i <<= 1) 546 for (i = 1; i < RESOURCE_SENTINEL; i <<= 1)
593 { 547 {
594 Gui_Resource_Type type = i; 548 Gui_Resource_Type type = i;
595 if (type != RESOURCE_IMAGE && type != RESOURCE_EDJE) continue; 549 Dep_Id *res_id;
596 res_lst = gui_context_resource_list_get(ctx, type); 550 const Eina_List *res_lst = gui_context_resource_list_get(ctx, type);
597 if (!res_lst) continue; 551 if (!res_lst) continue;
598 Eina_Strbuf *if_buf = eina_strbuf_new(); 552 if (type == RESOURCE_IMAGE || type == RESOURCE_EDJE)
599 EINA_LIST_FOREACH(res_lst, itr, res_id)
600 { 553 {
601 const Gui_Resource *res = gui_context_resource_get(res_id); 554 Eina_Strbuf *if_buf = eina_strbuf_new();
602 if (!res) continue; 555 EINA_LIST_FOREACH(res_lst, itr, res_id)
603 const char *_fn = ecore_file_file_get( 556 {
604 type == RESOURCE_EDJE?resource_edj_path_get(res):resource_value_get(res)); 557 const Gui_Resource *res = gui_context_resource_get(res_id);
605 if (first_res) eina_strbuf_append_printf(if_buf, "#ifdef %s\n", path_var); 558 if (!res) continue;
606 first_res = EINA_FALSE; 559 const char *_fn = ecore_file_file_get(
607 eina_strbuf_append_printf(if_buf, " const char *%s = %s\"/%s\";\n", resource_name_get(res), path_var, _fn); 560 type == RESOURCE_EDJE?resource_edj_path_get(res):resource_value_get(res));
561 if (first_res) eina_strbuf_append_printf(if_buf, "#ifdef %s\n", path_var);
562 first_res = EINA_FALSE;
563 eina_strbuf_append_printf(if_buf, " const char *%s = %s\"/%s\";\n", resource_name_get(res), path_var, _fn);
564 }
565 if (!first_res) eina_strbuf_append_printf(if_buf, "#endif\n");
566 if (!first_res)
567 {
568 if (path_var)
569 eina_strbuf_append_printf(resources_buf, "%s", eina_strbuf_string_get(if_buf));
570 else
571 eina_strbuf_append_printf(resources_buf,
572 "#error To generate resources paths, you have to define the prefix in project settings.\n");
573 }
574 eina_strbuf_free(if_buf);
608 } 575 }
609 if (!first_res) eina_strbuf_append_printf(if_buf, "#endif\n"); 576 if (type == RESOURCE_EO_CALLBACK)
610 if (!first_res)
611 { 577 {
612 if (path_var) 578 EINA_LIST_FOREACH(res_lst, itr, res_id)
613 eina_strbuf_append_printf(gl_gen_ctx.buf, "%s", eina_strbuf_string_get(if_buf)); 579 {
614 else 580 const Gui_Resource *res = gui_context_resource_get(res_id);
615 eina_strbuf_append_printf(gl_gen_ctx.buf, 581 if (res)
616 "#error To generate resources paths, you have to define the prefix in project settings.\n"); 582 eina_strbuf_append_printf(resources_buf,
583 "extern Eina_Bool\n%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n",
584 resource_value_get(res));
585 }
617 } 586 }
618 eina_strbuf_free(if_buf);
619 } 587 }
620 588
621 Gui_Session *session = session_new();
622 /* Generate sequences */ 589 /* Generate sequences */
623 Eina_List* seqs_list = gui_context_seq_list_get(ctx); 590 Eina_List* seqs_list = gui_context_seq_list_get(ctx);
624 Dep_Id *seq_id; 591 Dep_Id *seq_id;
625 EINA_LIST_FOREACH(seqs_list, itr, seq_id) 592 EINA_LIST_FOREACH(seqs_list, itr, seq_id)
626 { 593 {
627 Gui_Sequence *seq = sequence_get(seq_id); 594 Gui_Sequence *seq = sequence_get(seq_id);
628 if (seq) 595 if (seq) _sequence_generate(gl_ctx->session, seq, &seq_ctx);
629 {
630 Sequence_Context seq_ctx;
631 seq_ctx.gl_ctx = &gl_gen_ctx;
632 seq_ctx.buf = eina_strbuf_new();
633 _sequence_generate(session, seq, &seq_ctx);
634 eina_strbuf_append_printf(gl_gen_ctx.buf, "%s", eina_strbuf_string_get(seq_ctx.buf));
635 eina_strbuf_free(seq_ctx.buf);
636 }
637 } 596 }
638 597
639 Eina_List* wdgs_list = gui_context_wdg_list_get(ctx); 598 Eina_List* wdgs_list = gui_context_wdg_list_get(ctx);
@@ -643,89 +602,152 @@ _ctx_to_file_save(const Gui_Context *ctx)
643 Gui_Widget *wdg = wdg_get(wdg_id); 602 Gui_Widget *wdg = wdg_get(wdg_id);
644 if (wdg) 603 if (wdg)
645 { 604 {
646 if (!session_wdg_exists(session, wdg)) 605 if (!session_wdg_exists(gl_ctx->session, wdg))
647 { 606 {
648 Widget_Context wdg_ctx;
649 wdg_ctx.gl_ctx = &gl_gen_ctx;
650 wdg_ctx.buf = eina_strbuf_new();
651 wdg_ctx.declarations = NULL; 607 wdg_ctx.declarations = NULL;
652 printf("Generate %s\n", wdg_name_get(wdg)); 608 printf("Generate %s\n", wdg_name_get(wdg));
653 _wdg_creation_function_generate(session, wdg, &wdg_ctx); 609 _wdg_creation_function_generate(gl_ctx->session, wdg, &wdg_ctx);
654 eina_strbuf_append_printf(gl_gen_ctx.buf, "%s", eina_strbuf_string_get(wdg_ctx.buf));
655 eina_strbuf_free(wdg_ctx.buf);
656 } 610 }
657 } 611 }
658 } 612 }
659 613
660 Eina_Strbuf *global_entities_buf = eina_strbuf_new(); 614 eina_strbuf_append_printf(gl_ctx->c_buf,
661 _c_generator_generator_interface_global_names_generate(gl_gen_ctx.global_entities, global_entities_buf); 615 "#include <Elementary.h>\n"
662 eina_strbuf_replace_first(gl_gen_ctx.buf, "__GLOBAL_NAMES__", eina_strbuf_string_get(global_entities_buf)); 616 "#include \"elm_widget_container.h\"\n"
663 eina_strbuf_free(global_entities_buf); 617 "#include \"elm_interface_scrollable.h\"\n"
618 "#include \"%s.h\"\n\n", filename);
664 619
665 _c_generator_generator_interface_main_function_generate(ctx, gl_gen_ctx.buf); 620 eina_strbuf_append_printf(gl_ctx->c_buf,
621 "static GUI %s;\n\n", PUB_WIDGETS);
666 622
667 /* Print all data from buffer into the file. */ 623 _c_generator_generator_interface_global_names_generate(gl_ctx->global_entities, gl_ctx->c_buf);
668 fprintf(fp_c, "%s", eina_strbuf_string_get(gl_gen_ctx.buf)); 624
625 eina_strbuf_append_printf(gl_ctx->c_buf,"%s", eina_strbuf_string_get(resources_buf));
626 eina_strbuf_append_printf(gl_ctx->c_buf,"%s", eina_strbuf_string_get(seq_ctx.buf));
627 eina_strbuf_append_printf(gl_ctx->c_buf,"%s", eina_strbuf_string_get(wdg_ctx.buf));
628
629 seq_id = gui_context_dep_id_by_name_get(ctx, BIGBANG_STR);
630 const Gui_Resource *res = gui_context_resource_get(seq_id);
631 if (!res) return;
632 const char *func_name = resource_name_get(res);
633 eina_strbuf_append_printf(gl_ctx->c_buf,
634 "GUI *%s_gui_get()\n{\n"
635 " static Eina_Bool initialized = EINA_FALSE;\n"
636 " if (!initialized)\n"
637 " {\n"
638 " %s_%s(NULL, NULL, NULL, NULL);\n"
639 " initialized = EINA_TRUE;\n"
640 " }\n"
641 " return &%s;\n}",
642 gl_ctx->formatted_project_name,
643 gl_ctx->formatted_project_name, func_name,
644 PUB_WIDGETS);
669 645
670 /* Generate header file. */ 646 /* Generate header file. */
671 eina_strbuf_reset(gl_gen_ctx.buf); 647 eina_strbuf_append_printf(gl_ctx->h_buf,
672 eina_strbuf_append_printf(gl_gen_ctx.buf,
673 "#ifndef _%s_h\n" 648 "#ifndef _%s_h\n"
674 "#define _%s_h\n", filename, filename); 649 "#define _%s_h\n", filename, filename);
675 eina_strbuf_append_printf(gl_gen_ctx.buf, 650 eina_strbuf_append_printf(gl_ctx->h_buf,
676 "#include <Eo.h>\n" 651 "#include <Eo.h>\n"
677 "#include <Elementary.h>\n\n"); 652 "#include <Elementary.h>\n\n");
678 653
679 Dep_Id *dep_id; 654 Dep_Id *dep_id;
680 eina_strbuf_append_printf(gl_gen_ctx.buf, "typedef struct\n{\n"); 655 eina_strbuf_append_printf(gl_ctx->h_buf, "typedef struct\n{\n");
681 EINA_LIST_FOREACH(gl_gen_ctx.public_entities, itr, dep_id) 656 EINA_LIST_FOREACH(gl_ctx->public_entities, itr, dep_id)
682 { 657 {
683 switch (dep_type_get(dep_id)) 658 switch (dep_type_get(dep_id))
684 { 659 {
685 case DEP_TYPE_WIDGET: 660 case DEP_TYPE_WIDGET:
686 eina_strbuf_append_printf(gl_gen_ctx.buf, " Eo *%s;\n", dep_name_get(dep_id)); 661 eina_strbuf_append_printf(gl_ctx->h_buf, " Eo *%s;\n", dep_name_get(dep_id));
687 break; 662 break;
688 case DEP_TYPE_ITEM: 663 case DEP_TYPE_ITEM:
689 eina_strbuf_append_printf(gl_gen_ctx.buf, " Elm_Object_Item *%s;\n", dep_name_get(dep_id)); 664 eina_strbuf_append_printf(gl_ctx->h_buf, " Elm_Object_Item *%s;\n", dep_name_get(dep_id));
690 break; 665 break;
691 default: break; 666 default: break;
692 } 667 }
693 } 668 }
694 eina_strbuf_append_printf(gl_gen_ctx.buf, "} GUI;\n\n"); 669 eina_strbuf_append_printf(gl_ctx->h_buf, "} GUI;\n\n");
695 EINA_LIST_FOREACH(gl_gen_ctx.public_entities, itr, seq_id) 670 EINA_LIST_FOREACH(gl_ctx->public_entities, itr, seq_id)
696 { 671 {
697 if (dep_type_get(seq_id) == DEP_TYPE_RESOURCE) 672 if (dep_type_get(seq_id) == DEP_TYPE_RESOURCE)
698 { 673 {
699 const Gui_Sequence *seq = sequence_get(seq_id); 674 const Gui_Sequence *seq = sequence_get(seq_id);
700 if (seq) 675 if (seq)
701 eina_strbuf_append_printf(gl_gen_ctx.buf, 676 eina_strbuf_append_printf(gl_ctx->h_buf,
702 "Eina_Bool\n%s_%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n\n", 677 "Eina_Bool\n%s_%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n\n",
703 gl_gen_ctx.formatted_project_name, sequence_name_get(seq)); 678 gl_ctx->formatted_project_name, sequence_name_get(seq));
704 } 679 }
705 } 680 }
706 681
707 EINA_LIST_FREE(gl_gen_ctx.public_main_wdgs, wdg_id) 682 EINA_LIST_FREE(gl_ctx->public_main_wdgs, wdg_id)
708 { 683 {
709 eina_strbuf_append_printf(gl_gen_ctx.buf, "void\n%s_create();\n\n", dep_name_get(wdg_id)); 684 eina_strbuf_append_printf(gl_ctx->h_buf, "void\n%s_create();\n\n", dep_name_get(wdg_id));
710 } 685 }
711 686
712 eina_strbuf_append_printf(gl_gen_ctx.buf, "GUI *%s_gui_get();\n", gl_gen_ctx.formatted_project_name); 687 eina_strbuf_append_printf(gl_ctx->h_buf, "GUI *%s_gui_get();\n", gl_ctx->formatted_project_name);
688
689 eina_strbuf_append_printf(gl_ctx->h_buf, "#endif\n");
690
691 eina_strbuf_free(seq_ctx.buf);
692 eina_strbuf_free(wdg_ctx.buf);
693 eina_strbuf_free(resources_buf);
694}
695
696/* Save context into "project" files. */
697static void
698_ctx_to_file_save(const Gui_Context *ctx)
699{
700 Eina_Strbuf *filename = NULL;
701 FILE *fp = NULL;
702
703 /* Define global generator context */
704 Global_Gen_Context gl_gen_ctx;
705 gl_gen_ctx.ctx = ctx;
706 gl_gen_ctx.c_buf = eina_strbuf_new();
707 gl_gen_ctx.h_buf = eina_strbuf_new();
708 gl_gen_ctx.global_entities = NULL;
709 gl_gen_ctx.public_entities = NULL;
710 gl_gen_ctx.public_main_wdgs = NULL;
711 gl_gen_ctx.formatted_project_name = _project_name_format(gui_context_project_name_get(ctx));
712 gl_gen_ctx.session = session_new();
713 713
714 eina_strbuf_append_printf(gl_gen_ctx.buf, "#endif\n"); 714 _ctx_generate(&gl_gen_ctx);
715 fprintf(fp_h, "%s", eina_strbuf_string_get(gl_gen_ctx.buf));
716 715
717 eina_strbuf_free(gl_gen_ctx.buf); 716 filename = eina_strbuf_new();
718 eina_list_free(gl_gen_ctx.public_entities); 717 eina_strbuf_append_printf(filename, "%s/%s.c",
719 eina_list_free(gl_gen_ctx.global_entities); 718 gui_context_export_path_get(ctx),
720 free(gl_gen_ctx.formatted_project_name); 719 gui_context_export_filename_get(ctx));
720 fp = fopen(eina_strbuf_string_get(filename), "w+");
721 if (!fp)
722 {
723 ERR("Can't create file: %s", eina_strbuf_string_get(filename));
724 goto end;
725 }
726 fprintf(fp, "%s", eina_strbuf_string_get(gl_gen_ctx.c_buf));
727 fclose(fp);
721 728
722 session_del(session); 729 eina_strbuf_reset(filename);
730 eina_strbuf_append_printf(filename, "%s/%s.h",
731 gui_context_export_path_get(ctx),
732 gui_context_export_filename_get(ctx));
733 fp = fopen(eina_strbuf_string_get(filename), "w+");
734 if (!fp)
735 {
736 ERR("Can't create file: %s", eina_strbuf_string_get(filename));
737 goto end;
738 }
739 fprintf(fp, "%s", eina_strbuf_string_get(gl_gen_ctx.h_buf));
723 740
724end: 741end:
725 if (fp_c) fclose(fp_c); 742 eina_strbuf_free(gl_gen_ctx.c_buf);
726 if (fp_h) fclose(fp_h); 743 eina_strbuf_free(gl_gen_ctx.h_buf);
727 free(filename_c); 744 eina_list_free(gl_gen_ctx.public_entities);
728 free(filename_h); 745 eina_list_free(gl_gen_ctx.global_entities);
746 free(gl_gen_ctx.formatted_project_name);
747 session_del(gl_gen_ctx.session);
748
749 if (fp) fclose(fp);
750 eina_strbuf_free(filename);
729} 751}
730 752
731void 753void
@@ -778,31 +800,6 @@ _c_generator_generator_interface_global_names_generate(const Eina_List *global_e
778} 800}
779 801
780static Eina_Bool 802static Eina_Bool
781_c_generator_generator_interface_main_function_generate(const Gui_Context *ctx, Eina_Strbuf *buf)
782{
783 Dep_Id *dep_id = gui_context_dep_id_by_name_get(ctx, BIGBANG_STR);
784 const Gui_Resource *res = gui_context_resource_get(dep_id);
785 if (!res) return EINA_FALSE;
786 const char *func_name = resource_name_get(res);
787
788 char *project_name = (char *) gui_context_project_name_get(ctx);
789 char *formatted = _project_name_format(project_name);
790
791 /* Add get_gui function . */
792 eina_strbuf_append_printf(buf,
793 "GUI* %s_gui_get()\n{\n"
794 " static Eina_Bool initialized = EINA_FALSE;\n"
795 " if (!initialized)\n"
796 " {\n"
797 " %s_%s(NULL, NULL, NULL, NULL);\n"
798 " initialized = EINA_TRUE;\n"
799 " }\n"
800 " return &%s;\n}", formatted, formatted, func_name, PUB_WIDGETS);
801 free(formatted);
802 return EINA_TRUE;
803}
804
805static Eina_Bool
806_c_generator_generator_interface_widget_create(const Gui_Widget *wdg, Eina_Strbuf *buf) 803_c_generator_generator_interface_widget_create(const Gui_Widget *wdg, Eina_Strbuf *buf)
807{ 804{
808 const char *parent_id = wdg_parent_name_get(wdg); 805 const char *parent_id = wdg_parent_name_get(wdg);