14
#include <Ecore_Getopt.h>
15
#include <Ecore_Evas.h>
16
#include <Ecore_File.h>
19
#define EDJE_EDIT_IS_UNSTABLE_AND_I_KNOW_ABOUT_IT 1
23
#define DBG(...) EINA_LOG_DOM_DBG(_log_dom, __VA_ARGS__)
24
#define ERR(...) EINA_LOG_DOM_ERR(_log_dom, __VA_ARGS__)
26
static Ecore_Evas *ee = NULL;
27
static char *file = NULL;
28
static char *group = NULL;
29
static char *prefix = NULL;
30
static FILE *source_fd = NULL;
31
static FILE *header_fd = NULL;
32
static Eina_List *externals = NULL;
37
"#include <Edje.h>\n" \
38
"#include <Evas.h>\n\n" \
39
"#include <stdlib.h>\n\n"
42
"\n#endif /* _%s */\n"
47
#define C_CODEGEN_OBJECT_ADD \
49
"%s_object_add(Evas *e, const char *file)\n" \
51
" Evas_Object *o;\n\n" \
52
" o = edje_object_add(e);\n" \
53
" if (!o) return NULL;\n\n" \
55
" edje_object_file_set(o, file, \"%s\");\n" \
57
" edje_object_file_set(o, \"%s\", \"%s\");\n\n" \
61
#define H_CODEGEN_OBJECT_ADD \
62
"/**\n * @brief Creates the Edje object and set the edj file\n" \
63
" * @param e The surface\n" \
64
" * @param file The path to edj, if NULL it's used the path given\n" \
65
" * to edje_codegen\n */\n" \
66
"Evas_Object *%s_object_add(Evas *e, const char *file);\n\n"
68
#define C_CODEGEN_DRAG_SET(option) \
70
"%s_%s_drag_" #option "_set(Evas_Object *o, double dx, double dy)\n" \
72
" return edje_object_part_drag_" #option "_set(o, \"%s\", dx, dy);\n" \
75
#define H_CODEGEN_DRAG_SET(option) \
76
"Eina_Bool %s_%s_drag_" #option "_set(Evas_Object *o, double dx, double dy);\n"
78
#define C_CODEGEN_DRAG_GET(option) \
80
"%s_%s_drag_" #option "_get(Evas_Object *o, double *dx, double *dy)\n" \
82
" return edje_object_part_drag_" #option "_get(o, \"%s\", dx, dy);\n" \
85
#define H_CODEGEN_DRAG_GET(option) \
86
"Eina_Bool %s_%s_drag_" #option "_get(Evas_Object *o, double *dx" \
89
#define C_CODEGEN_DRAG_ACTION(option) \
91
"%s_%s_drag_" #option "(Evas_Object *o, double dx, double dy)\n" \
93
" return edje_object_part_drag_" #option "(o, \"%s\", dx, dy);\n" \
96
#define H_CODEGEN_DRAG_ACTION(option) \
97
"Eina_Bool %s_%s_drag_" #option "(Evas_Object *o, double dx, double dy);\n"
99
#define C_CODEGEN_DRAG_DIR_GET \
101
"%s_%s_drag_dir_get(Evas_Object *o)\n" \
103
" return edje_object_part_drag_dir_get(o, \"%s\");\n" \
106
#define H_CODEGEN_DRAG_DIR_GET \
107
"Edje_Drag_Dir %s_%s_drag_dir_get(Evas_Object *o);\n"
109
#define C_CODEGEN_PART_TEXT_SET \
111
"%s_%s_set(Evas_Object *o, const char *value)\n" \
113
" edje_object_part_text_set(o, \"%s\", value);\n" \
116
#define H_CODEGEN_PART_TEXT_SET \
117
"void %s_%s_set(Evas_Object *o, const char *value);\n"
119
#define C_CODEGEN_PART_SWALLOW_SET \
121
"%s_%s_set(Evas_Object *o, Evas_Object *value)\n" \
123
" edje_object_part_swallow(o, \"%s\", value);\n" \
126
#define H_CODEGEN_PART_SWALLOW_SET \
127
"void %s_%s_set(Evas_Object *o, Evas_Object *value);\n"
129
#define C_CODEGEN_PART_TEXT_GET \
131
"%s_%s_get(const Evas_Object *o)\n" \
133
" return edje_object_part_text_get(o, \"%s\");\n" \
136
#define H_CODEGEN_PART_TEXT_GET \
137
"const char *%s_%s_get(const Evas_Object *o);\n"
139
#define C_CODEGEN_PART_SWALLOW_GET \
141
"%s_%s_get(const Evas_Object *o)\n" \
143
" return edje_object_part_swallow_get(o, \"%s\");\n" \
146
#define H_CODEGEN_PART_SWALLOW_GET \
147
"Evas_Object *%s_%s_get(const Evas_Object *o);\n"
149
#define C_CODEGEN_PART_BOX_APPEND \
151
"%s_%s_append(Evas_Object *o, Evas_Object *child)\n" \
153
" return edje_object_part_box_append(o, \"%s\", child);\n" \
156
#define H_CODEGEN_PART_BOX_APPEND \
157
"Eina_Bool %s_%s_append(Evas_Object *o, Evas_Object *child);\n"
159
#define C_CODEGEN_PART_BOX_PREPEND \
161
"%s_%s_prepend(Evas_Object *o, Evas_Object *child)\n" \
163
" return edje_object_part_box_prepend(o, \"%s\", child);\n" \
166
#define H_CODEGEN_PART_BOX_PREPEND \
167
"Eina_Bool %s_%s_prepend(Evas_Object *o, Evas_Object *child);\n"
169
#define C_CODEGEN_PART_BOX_INSERT_BEFORE \
171
"%s_%s_insert_before(Evas_Object *o, Evas_Object *child, " \
172
"const Evas_Object *reference)\n" \
174
" return edje_object_part_box_insert_before(o, \"%s\", " \
175
"child, reference);\n" \
178
#define H_CODEGEN_PART_BOX_INSERT_BEFORE \
179
"Eina_Bool %s_%s_insert_before(Evas_Object *o, Evas_Object *child, " \
180
"const Evas_Object *reference);\n"
182
#define C_CODEGEN_PART_BOX_INSERT_AT \
184
"%s_%s_insert_at(Evas_Object *o, Evas_Object *child, unsigned int pos)\n" \
186
" return edje_object_part_box_insert_at(o, \"%s\", child, pos);\n" \
189
#define H_CODEGEN_PART_BOX_INSERT_AT \
190
"Eina_Bool %s_%s_insert_at(Evas_Object *o, Evas_Object *child, " \
191
"unsigned int pos);\n"
193
#define C_CODEGEN_PART_BOX_REMOVE \
195
"%s_%s_remove(Evas_Object *o, Evas_Object *child)\n" \
197
" return edje_object_part_box_remove(o, \"%s\", child);\n" \
200
#define H_CODEGEN_PART_BOX_REMOVE \
201
"Evas_Object *%s_%s_remove(Evas_Object *o, Evas_Object *child);\n"
203
#define C_CODEGEN_PART_BOX_REMOVE_AT \
205
"%s_%s_remove_at(Evas_Object *o, unsigned int pos)\n" \
207
" return edje_object_part_box_remove_at(o, \"%s\", pos);\n" \
210
#define H_CODEGEN_PART_BOX_REMOVE_AT \
211
"Evas_Object *%s_%s_remove_at(Evas_Object *o, unsigned int pos);\n"
213
#define C_CODEGEN_PART_BOX_REMOVE_ALL \
215
"%s_%s_remove_all(Evas_Object *o, Eina_Bool clear)\n" \
217
" return edje_object_part_box_remove_all(o, \"%s\", clear);\n" \
220
#define H_CODEGEN_PART_BOX_REMOVE_ALL \
221
"Eina_Bool %s_%s_remove_all(Evas_Object *o, Eina_Bool clear);\n"
223
#define C_CODEGEN_PART_TABLE_CHILD_GET \
225
"%s_%s_child_get(Evas_Object *o, unsigned int col, unsigned int row)\n" \
227
" return edje_object_part_table_child_get(o, \"%s\", col, row);\n" \
230
#define H_CODEGEN_PART_TABLE_CHILD_GET \
231
"Evas_Object * %s_%s_child_get(Evas_Object *o, unsigned int col, " \
232
"unsigned int row);\n"
234
#define C_CODEGEN_PART_TABLE_PACK \
236
"%s_%s_pack(Evas_Object *o, Evas_Object *child, unsigned short col, " \
237
"unsigned short row, unsigned short colspan, unsigned short rowspan)\n" \
239
" return edje_object_part_table_pack(o, \"%s\", child, col, row, " \
240
"colspan, rowspan);\n" \
243
#define H_CODEGEN_PART_TABLE_PACK \
244
"Eina_Bool %s_%s_pack(Evas_Object *o, Evas_Object *child, " \
245
"unsigned short col, unsigned short row, unsigned short " \
246
"colspan, unsigned short rowspan);\n"
248
#define C_CODEGEN_PART_TABLE_UNPACK \
250
"%s_%s_unpack(Evas_Object *o, Evas_Object *child)\n" \
252
" return edje_object_part_table_unpack(o, \"%s\", child);\n" \
255
#define H_CODEGEN_PART_TABLE_UNPACK \
256
"Eina_Bool %s_%s_unpack(Evas_Object *o, Evas_Object *child);\n"
258
#define C_CODEGEN_PART_TABLE_CLEAR \
260
"%s_%s_clear(Evas_Object *o, Eina_Bool clear)\n" \
262
" return edje_object_part_table_clear(o, \"%s\", clear);\n" \
265
#define H_CODEGEN_PART_TABLE_CLEAR \
266
"Eina_Bool %s_%s_clear(Evas_Object *o, Eina_Bool clear);\n"
268
#define C_CODEGEN_PART_TABLE_COL_ROW_SIZE_GET \
270
"%s_%s_col_row_size_get(Evas_Object *o, int *cols, int *rows)\n" \
272
" return edje_object_part_table_col_row_size_get(o, \"%s\", " \
276
#define H_CODEGEN_PART_TABLE_COL_ROW_SIZE_GET \
277
"Eina_Bool %s_%s_col_row_size_get(Evas_Object *o, int *cols, int *rows);\n"
279
#define C_CODEGEN_PART_EXTERNAL_PARAM_SET(type, param_type, field) \
281
"%s_%s_%s_set(Evas_Object *o, "type "value)\n" \
283
" Edje_External_Param param;\n\n" \
284
" param.name = \"%s\";\n" \
285
" param.type = "param_type ";\n" \
286
" param."field " = value;\n" \
287
" return edje_object_part_external_param_set(o, \"%s\", ¶m);\n" \
290
#define H_CODEGEN_PART_EXTERNAL_PARAM_SET(type) \
291
"Eina_Bool %s_%s_%s_set(Evas_Object *o, "type "value);\n"
293
#define C_CODEGEN_PART_EXTERNAL_PARAM_GET(type, param_type, field) \
295
"%s_%s_%s_get(Evas_Object *o, "type "*value)\n" \
297
" if (!value) return EINA_FALSE;\n\n" \
298
" Edje_External_Param param;\n\n" \
299
" param.name = \"%s\";\n" \
300
" param.type = "param_type ";\n" \
301
" if (!edje_object_part_external_param_get(o, \"%s\", ¶m))\n" \
302
" return EINA_FALSE;\n\n" \
303
" *value = param."field ";\n" \
304
" return EINA_TRUE;\n" \
307
#define H_CODEGEN_PART_EXTERNAL_PARAM_GET(type) \
308
"Eina_Bool %s_%s_%s_get(Evas_Object *o, "type "*value);\n"
310
#define C_CODEGEN_PROGRAM_EMIT \
312
"%s_%s_emit(Evas_Object *o)\n" \
314
" edje_object_signal_emit(o, \"%s\", \"%s\");\n" \
317
#define H_CODEGEN_PROGRAM_EMIT \
318
"void %s_%s_emit(Evas_Object *o);\n"
320
#define C_CODEGEN_PROGRAM_CALLBACK_ADD \
322
"%s_%s_callback_add(Evas_Object *o, Edje_Signal_Cb func, void *data)\n" \
324
" edje_object_signal_callback_add(o, \"%s\", \"%s\", func, data);\n" \
327
#define H_CODEGEN_PROGRAM_CALLBACK_ADD \
328
"void %s_%s_callback_add(Evas_Object *o, Edje_Signal_Cb func, " \
331
#define C_CODEGEN_PROGRAM_CALLBACK_DEL \
333
"%s_%s_callback_del_full(Evas_Object *o, Edje_Signal_Cb func, void *data)\n" \
335
" edje_object_signal_callback_del_full(o, \"%s\", \"%s\", func, data);\n" \
338
#define H_CODEGEN_PROGRAM_CALLBACK_DEL \
339
"void %s_%s_callback_del_full(Evas_Object *o, Edje_Signal_Cb func, " \
342
typedef struct _Part_External_Info Part_External_Info;
343
struct _Part_External_Info
345
const char *description, *name, *source;
350
const Ecore_Getopt optdesc = {
352
"%prog [options] <file.edj> <group> <source_file_name> <header_file_name>",
354
"(C) 2012 - The Enlightenment Project",
356
"Edje generates the boilerplate code to get and set the "
357
"parts of a group from a compiled (binary) edje "
358
"file avoiding common errors with typos.\n",
361
ECORE_GETOPT_STORE_STR('p', "prefix", "The prefix for the " \
363
ECORE_GETOPT_LICENSE('L', "license"),
364
ECORE_GETOPT_COPYRIGHT('C', "copyright"),
365
ECORE_GETOPT_VERSION('V', "version"),
366
ECORE_GETOPT_HELP('h', "help"),
367
ECORE_GETOPT_SENTINEL
372
_standardizes_header(const char *filename)
374
char *str, *itr, *aux;
376
aux = strrchr(filename, '/');
377
str = itr = strdup(aux ? aux + 1 : filename);
383
*itr = toupper(*itr);
389
_open_file_descriptors(const char *source, const char *header)
391
header_fd = fopen(header, "wb");
395
source_fd = fopen(source, "wb");
407
_close_file_descriptors(void)
409
Eina_Bool ret = EINA_FALSE;
411
if (!fclose(header_fd))
414
if (!fclose(source_fd))
421
_write_headers(const char *filename)
426
str = _standardizes_header(filename);
427
snprintf(buf, sizeof(buf), H_HEADER, str, str);
428
if (fwrite(buf, strlen(buf), 1, header_fd) != 1)
436
snprintf(buf, sizeof(buf), C_HEADER, ecore_file_file_get(filename));
437
if (fwrite(buf, strlen(buf), 1, source_fd) != 1)
444
_write_footer(const char *filename)
449
str = _standardizes_header(filename);
450
snprintf(buf, sizeof(buf), H_FOOTER, str);
451
if (fwrite(buf, strlen(buf), 1, header_fd) != 1)
463
_write_object_get(void)
467
snprintf(buf, sizeof(buf), H_CODEGEN_OBJECT_ADD, prefix);
468
if (fwrite(buf, strlen(buf), 1, header_fd) != 1)
471
snprintf(buf, sizeof(buf), C_CODEGEN_OBJECT_ADD, prefix, group, file, group);
472
if (fwrite(buf, strlen(buf), 1, source_fd) != 1)
479
_write_part_draggable(const char *apiname, const char *partname)
483
#define TEMPLATE_DRAGGABLE(sufix, option) \
485
const char *template; \
486
template = C_CODEGEN_DRAG_##sufix(option); \
487
snprintf(buf, sizeof(buf), template, prefix, apiname, \
489
if (fwrite(buf, strlen(buf), 1, source_fd) != 1) \
491
template = H_CODEGEN_DRAG_##sufix(option); \
492
snprintf(buf, sizeof(buf), template, prefix, \
494
if (fwrite(buf, strlen(buf), 1, header_fd) != 1) \
498
TEMPLATE_DRAGGABLE(SET, value);
499
TEMPLATE_DRAGGABLE(GET, value);
500
TEMPLATE_DRAGGABLE(SET, size);
501
TEMPLATE_DRAGGABLE(GET, size);
502
TEMPLATE_DRAGGABLE(SET, page);
503
TEMPLATE_DRAGGABLE(GET, page);
504
TEMPLATE_DRAGGABLE(SET, step);
505
TEMPLATE_DRAGGABLE(GET, step);
506
TEMPLATE_DRAGGABLE(ACTION, page);
507
TEMPLATE_DRAGGABLE(ACTION, step);
509
#undef TEMPLATE_DRAGGABLE
511
snprintf(buf, sizeof(buf), C_CODEGEN_DRAG_DIR_GET, prefix,
513
if (fwrite(buf, strlen(buf), 1, source_fd) != 1)
515
snprintf(buf, sizeof(buf), H_CODEGEN_DRAG_DIR_GET, prefix, apiname);
516
if (fwrite(buf, strlen(buf), 1, header_fd) != 1)
523
_write_part_external_param(const Part_External_Info *info,
524
const Edje_External_Param_Info *param)
526
const char *template;
529
#define WRITE_TEMPLATE(type, param_type, field) \
531
template = C_CODEGEN_PART_EXTERNAL_PARAM_SET(type, param_type, field); \
532
snprintf(buf, sizeof(buf), template, info->apiname, info->name, \
533
param->name, param->name, info->name); \
534
if (fwrite(buf, strlen(buf), 1, source_fd) != 1) \
536
template = H_CODEGEN_PART_EXTERNAL_PARAM_SET(type); \
537
snprintf(buf, sizeof(buf), template, info->apiname, info->name, \
539
if (fwrite(buf, strlen(buf), 1, header_fd) != 1) \
542
C_CODEGEN_PART_EXTERNAL_PARAM_GET(type, param_type, field); \
543
snprintf(buf, sizeof(buf), template, info->apiname, info->name, \
544
param->name, param->name, info->name); \
545
if (fwrite(buf, strlen(buf), 1, source_fd) != 1) \
547
template = H_CODEGEN_PART_EXTERNAL_PARAM_GET(type); \
548
snprintf(buf, sizeof(buf), template, info->apiname, info->name, \
550
if (fwrite(buf, strlen(buf), 1, header_fd) != 1) \
556
case EDJE_EXTERNAL_PARAM_TYPE_INT:
557
WRITE_TEMPLATE("int ", "EDJE_EXTERNAL_PARAM_TYPE_INT", "i");
560
case EDJE_EXTERNAL_PARAM_TYPE_DOUBLE:
561
WRITE_TEMPLATE("double ", "EDJE_EXTERNAL_PARAM_TYPE_DOUBLE", "d");
564
case EDJE_EXTERNAL_PARAM_TYPE_STRING:
565
WRITE_TEMPLATE("const char *", "EDJE_EXTERNAL_PARAM_TYPE_STRING", "s");
568
case EDJE_EXTERNAL_PARAM_TYPE_BOOL:
569
WRITE_TEMPLATE("Eina_Bool ", "EDJE_EXTERNAL_PARAM_TYPE_BOOL", "i");
572
case EDJE_EXTERNAL_PARAM_TYPE_CHOICE:
573
WRITE_TEMPLATE("const char *", "EDJE_EXTERNAL_PARAM_TYPE_CHOICE", "s");
586
_write_part_external(Eina_List **parts)
590
Part_External_Info *ei;
591
const Eina_Hash_Tuple *tuple;
592
Eina_List *l, *l_next;
594
Eina_Bool ret = EINA_TRUE;
596
itr = edje_external_iterator_get();
597
EINA_ITERATOR_FOREACH(itr, tuple)
599
const Edje_External_Type *type = tuple->data;
600
const Edje_External_Param_Info *param;
605
ERR("no type value for '%s'", name);
608
else if (type->abi_version != edje_external_type_abi_version_get())
610
ERR("type '%s' with incorrect abi_version %u (expected %u)",
611
name, type->abi_version, edje_external_type_abi_version_get());
615
EINA_LIST_FOREACH_SAFE(*parts, l, l_next, ei)
617
if (!strcmp(ei->source, name))
621
snprintf(buf, sizeof(buf), "\n/**\n * @brief %s\n */\n",
623
if (fwrite(buf, strlen(buf), 1, header_fd) != 1)
632
if (!_write_part_draggable(ei->apiname, ei->name))
639
for (param = type->parameters_info; param->name != NULL;
641
if (!_write_part_external_param(ei, param))
647
edje_edit_string_free(ei->description);
651
*parts = eina_list_remove_list(*parts, l);
657
if (eina_list_count(*parts) == 0) *parts = NULL;
658
eina_iterator_free(itr);
664
_write_part(const char *apiname, const char *partname, Edje_Part_Type parttype,
665
const char *description, Eina_Bool draggable)
669
#define TEMPLATE_NAME(sufix) \
671
snprintf(buf, sizeof(buf), C_CODEGEN_##sufix, prefix, \
672
apiname, partname); \
673
if (fwrite(buf, strlen(buf), 1, source_fd) != 1) \
675
snprintf(buf, sizeof(buf), H_CODEGEN_##sufix, prefix, \
677
if (fwrite(buf, strlen(buf), 1, header_fd) != 1) \
683
snprintf(buf, sizeof(buf), "\n/**\n * @brief %s\n */\n", description);
684
if (fwrite(buf, strlen(buf), 1, header_fd) != 1)
690
case EDJE_PART_TYPE_BOX:
691
TEMPLATE_NAME(PART_BOX_APPEND);
692
TEMPLATE_NAME(PART_BOX_PREPEND);
693
TEMPLATE_NAME(PART_BOX_INSERT_BEFORE);
694
TEMPLATE_NAME(PART_BOX_INSERT_AT);
695
TEMPLATE_NAME(PART_BOX_REMOVE);
696
TEMPLATE_NAME(PART_BOX_REMOVE_AT);
697
TEMPLATE_NAME(PART_BOX_REMOVE_ALL);
700
case EDJE_PART_TYPE_TABLE:
701
TEMPLATE_NAME(PART_TABLE_PACK);
702
TEMPLATE_NAME(PART_TABLE_UNPACK);
703
TEMPLATE_NAME(PART_TABLE_CHILD_GET);
704
TEMPLATE_NAME(PART_TABLE_CLEAR);
705
TEMPLATE_NAME(PART_TABLE_COL_ROW_SIZE_GET);
708
case EDJE_PART_TYPE_TEXT:
709
TEMPLATE_NAME(PART_TEXT_SET);
710
TEMPLATE_NAME(PART_TEXT_GET);
713
case EDJE_PART_TYPE_SWALLOW:
714
TEMPLATE_NAME(PART_SWALLOW_SET);
715
TEMPLATE_NAME(PART_SWALLOW_GET);
723
if (!_write_part_draggable(apiname, partname))
731
ERR("Could not write the part: %s", partname);
735
static inline Eina_Bool
738
if ((c >= '0') && (c <= '9')) return EINA_TRUE;
739
if ((c >= 'a') && (c <= 'z')) return EINA_TRUE;
740
if ((c >= 'A') && (c <= 'Z')) return EINA_TRUE;
746
_api_name_fix(const char *orig)
748
char *d, *d_end, buf[256];
751
if (!orig) return NULL;
755
d_end = d + sizeof(buf) - 1;
757
for (; (*s != '\0') && (d < d_end); s++, d++)
758
if (_c_id_allowed(*s)) *d = *s;
766
_part_api_name_get(Evas_Object *ed, const char *program)
771
orig = edje_edit_part_api_name_get(ed, program);
772
fix = _api_name_fix(orig);
773
edje_edit_string_free(orig);
779
_parse_parts(Evas_Object *ed)
781
Eina_List *parts, *l, *parts_external = NULL;
782
const char *name, *description;
785
Eina_Bool draggable, ret = EINA_TRUE;
786
Part_External_Info *ei;
788
parts = edje_edit_parts_list_get(ed);
789
EINA_LIST_FOREACH(parts, l, name)
791
if (!(apiname = _part_api_name_get(ed, name)))
793
DBG("filter out part '%s': not API.", name);
797
type = edje_edit_part_type_get(ed, name);
798
if (!((type == EDJE_PART_TYPE_TEXT) ||
799
(type == EDJE_PART_TYPE_SWALLOW) ||
800
(type == EDJE_PART_TYPE_BOX) ||
801
(type == EDJE_PART_TYPE_EXTERNAL) ||
802
(type == EDJE_PART_TYPE_IMAGE) ||
803
(type == EDJE_PART_TYPE_TABLE)))
805
ERR("Invalid part type %d", type);
809
if (edje_edit_part_drag_x_get(ed, name) ||
810
edje_edit_part_drag_y_get(ed, name))
811
draggable = EINA_TRUE;
813
draggable = EINA_FALSE;
815
description = edje_edit_part_api_description_get(ed, name);
816
if (type == EDJE_PART_TYPE_EXTERNAL)
818
ei = calloc(1, sizeof(Part_External_Info));
824
ei->description = description;
825
ei->source = edje_edit_part_source_get(ed, name);
826
ei->apiname = apiname;
828
ei->draggable = draggable;
830
parts_external = eina_list_append(parts_external, ei);
834
if (!_write_part(apiname, name, type, description, draggable))
837
edje_edit_string_free(description);
842
edje_edit_string_free(description);
847
ret = _write_part_external(&parts_external);
850
edje_edit_string_list_free(parts);
851
EINA_LIST_FREE(parts_external, ei)
853
edje_edit_string_free(ei->description);
862
_write_program_emit(const char *apiname, const char *source, const char *sig,
863
const char *description)
867
snprintf(buf, sizeof(buf), C_CODEGEN_PROGRAM_EMIT, prefix,
868
apiname, sig, source);
869
if (fwrite(buf, strlen(buf), 1, source_fd) != 1)
874
snprintf(buf, sizeof(buf), "\n/**\n * @brief %s\n */\n", description);
875
if (fwrite(buf, strlen(buf), 1, header_fd) != 1)
879
snprintf(buf, sizeof(buf), H_CODEGEN_PROGRAM_EMIT, prefix,
881
if (fwrite(buf, strlen(buf), 1, header_fd) != 1)
887
ERR("Could not write the program: %s", apiname);
892
_write_program_add(const char *apiname, const char *source, const char *sig,
893
const char *description)
897
snprintf(buf, sizeof(buf), C_CODEGEN_PROGRAM_CALLBACK_ADD, prefix,
898
apiname, sig, source);
899
if (fwrite(buf, strlen(buf), 1, source_fd) != 1)
902
snprintf(buf, sizeof(buf), C_CODEGEN_PROGRAM_CALLBACK_DEL, prefix,
903
apiname, sig, source);
904
if (fwrite(buf, strlen(buf), 1, source_fd) != 1)
909
snprintf(buf, sizeof(buf), "\n/**\n * @brief %s\n */\n", description);
910
if (fwrite(buf, strlen(buf), 1, header_fd) != 1)
914
snprintf(buf, sizeof(buf), H_CODEGEN_PROGRAM_CALLBACK_ADD, prefix,
916
if (fwrite(buf, strlen(buf), 1, header_fd) != 1)
919
snprintf(buf, sizeof(buf), H_CODEGEN_PROGRAM_CALLBACK_DEL, prefix,
921
if (fwrite(buf, strlen(buf), 1, header_fd) != 1)
927
ERR("Could not write the program [action]: %s", apiname);
932
_program_api_name_get(Evas_Object *ed, const char *program)
937
orig = edje_edit_program_api_name_get(ed, program);
938
fix = _api_name_fix(orig);
939
edje_edit_string_free(orig);
945
_parse_programs(Evas_Object *ed)
947
Eina_Bool ret = EINA_TRUE;
948
Eina_List *programs, *l;
949
const char *name, *source = NULL, *sig = NULL, *description;
951
Edje_Action_Type type;
953
programs = edje_edit_programs_list_get(ed);
954
EINA_LIST_FOREACH(programs, l, name)
956
if (!(apiname = _program_api_name_get(ed, name)))
958
DBG("filter out program '%s': not API.", name);
962
description = edje_edit_program_api_description_get(ed, name);
963
type = edje_edit_program_action_get(ed, name);
964
if (type == EDJE_ACTION_TYPE_SIGNAL_EMIT)
966
const char *str, *str2;
967
str = edje_edit_program_state_get(ed, name);
968
str2 = edje_edit_program_state2_get(ed, name);
970
if (!_write_program_add(apiname, str2, str, description))
973
edje_edit_string_free(str);
974
edje_edit_string_free(str2);
978
edje_edit_string_free(str);
979
edje_edit_string_free(str2);
982
sig = edje_edit_program_signal_get(ed, name);
986
edje_edit_string_free(description);
990
source = edje_edit_program_source_get(ed, name);
994
edje_edit_string_free(sig);
995
edje_edit_string_free(description);
999
if (!_write_program_emit(apiname, source, sig, description))
1005
edje_edit_string_free(description);
1006
edje_edit_string_free(sig);
1007
edje_edit_string_free(source);
1011
edje_edit_string_list_free(programs);
1014
edje_edit_string_free(description);
1015
edje_edit_string_free(sig);
1016
edje_edit_string_free(source);
1024
_module_matches(const char *module)
1029
EINA_LIST_FOREACH(externals, l, name)
1031
if (!strcmp(module, name))
1043
const char *module_name;
1044
const Eina_List *modules_available, *l;
1045
unsigned short modules_loaded = 0;
1047
modules_available = edje_available_modules_get();
1048
ed = edje_edit_object_add(ecore_evas_get(ee));
1049
if (!edje_object_file_set(ed, file, group))
1051
Edje_Load_Error err = edje_object_load_error_get(ed);
1052
const char *errmsg = edje_load_error_str(err);
1053
ERR("could not load group '%s' from file '%s': %s",
1054
group, file, errmsg);
1055
evas_object_del(ed);
1059
externals = edje_edit_externals_list_get(ed);
1062
EINA_LIST_FOREACH(modules_available, l, module_name)
1064
if (_module_matches(module_name))
1066
if (!edje_module_load(module_name))
1068
ERR("error loading external '%s'", module_name);
1076
if (eina_list_count(externals) != modules_loaded)
1078
edje_edit_string_list_free(externals);
1079
evas_object_del(ed);
1083
ret = _parse_parts(ed) && _parse_programs(ed);
1085
evas_object_del(ed);
1090
main(int argc, char *argv[])
1092
Eina_Bool quit_option = EINA_FALSE;
1093
char *source, *header;
1094
int arg_index, ret = 0;
1095
Ecore_Getopt_Value values[] = {
1096
ECORE_GETOPT_VALUE_STR(prefix),
1097
ECORE_GETOPT_VALUE_BOOL(quit_option),
1098
ECORE_GETOPT_VALUE_BOOL(quit_option),
1099
ECORE_GETOPT_VALUE_BOOL(quit_option),
1100
ECORE_GETOPT_VALUE_BOOL(quit_option),
1101
ECORE_GETOPT_VALUE_NONE
1104
setlocale(LC_NUMERIC, "C");
1106
ecore_app_no_system_modules();
1115
fprintf(stderr, "Missing action. See '--help or -h'.\n");
1120
_log_dom = eina_log_domain_register("edje_codegen", EINA_COLOR_YELLOW);
1123
EINA_LOG_CRIT("could not register log domain 'edje_codegen'");
1128
arg_index = ecore_getopt_parse(&optdesc, values, argc, argv);
1131
ERR("could not parse arguments.");
1135
else if (quit_option)
1137
else if (arg_index != argc - 4)
1139
fprintf(stderr, "Incorrect number of parameters. Requires " \
1140
"fours arguments, an edje, the group, " \
1141
"the source output (foo.c) and the header(foo.h).\n" \
1142
"See %s --help\n", argv[0]);
1147
file = argv[arg_index++];
1150
if (access(file, R_OK) == -1)
1152
ERR("File '%s' not accessible, error %d (%s).\n",
1153
file, errno, strerror(errno));
1158
group = argv[arg_index++];
1159
source = argv[arg_index++];
1160
header = argv[arg_index++];
1162
if (!edje_file_group_exists(file, group))
1164
ERR("The group %s not exists", group);
1169
ee = ecore_evas_buffer_new(1, 1);
1172
ERR("could not create ecore_evas_buffer");
1177
if (!_open_file_descriptors(source, header))
1179
ERR("Could not create the source files, error %d (%s)",
1180
errno, strerror(errno));
1185
if (!_write_headers(header))
1187
ERR("Could not write the header, error %d (%s)",
1188
errno, strerror(errno));
1193
if (!_write_object_get())
1195
ERR("Could not write the object get, error %d (%s)",
1196
errno, strerror(errno));
1203
ERR("Could not parsing the EDJE");
1208
if (!_write_footer(header))
1210
ERR("Could not write the footer, error %d (%s)",
1211
errno, strerror(errno));
1216
if (!_close_file_descriptors())
1218
ERR("Could not close the source files, error %d (%s)",
1219
errno, strerror(errno));
1225
ecore_evas_free(ee);
1229
ecore_evas_shutdown();
1231
eina_log_domain_unregister(_log_dom);