summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJee-Yong Um <jc9.um@samsung.com>2016-05-19 01:42:14 -0700
committerCedric Bail <cedric@osg.samsung.com>2016-05-19 02:23:56 -0700
commit9bf261fa2410739b1b76baf2febfd21789c5ca2a (patch)
tree71630f5f21b869dd7aee0d220895289818704044
parenta3cdafe9a25b2f12a1ba3dc7d99df1fda23c5fd1 (diff)
LazEDC: introduce simple external param syntax
Summary: EXTERNAL parts can have parameters, and its form is like the next. params.string: "param_name" "param_value"; This patch will shorten above line by the next syntax. params.param_name: "param_value"; The type of param will be determined by the type of inserted value. Reviewers: cedric, raster, Hermet Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D3958 Signed-off-by: Cedric Bail <cedric@osg.samsung.com>
-rw-r--r--src/bin/edje/edje_cc.h1
-rw-r--r--src/bin/edje/edje_cc_handlers.c165
-rw-r--r--src/bin/edje/edje_cc_parse.c53
3 files changed, 211 insertions, 8 deletions
diff --git a/src/bin/edje/edje_cc.h b/src/bin/edje/edje_cc.h
index 1ee0362ba2..a097d8eb1e 100644
--- a/src/bin/edje/edje_cc.h
+++ b/src/bin/edje/edje_cc.h
@@ -220,6 +220,7 @@ int get_arg_count(void);
220void check_arg_count(int n); 220void check_arg_count(int n);
221void check_min_arg_count(int n); 221void check_min_arg_count(int n);
222int check_range_arg_count(int n, int m); 222int check_range_arg_count(int n, int m);
223int param_had_quote(int n);
223 224
224int object_handler_num(void); 225int object_handler_num(void);
225int object_handler_short_num(void); 226int object_handler_short_num(void);
diff --git a/src/bin/edje/edje_cc_handlers.c b/src/bin/edje/edje_cc_handlers.c
index a4b85cd81c..00eb2365de 100644
--- a/src/bin/edje/edje_cc_handlers.c
+++ b/src/bin/edje/edje_cc_handlers.c
@@ -478,13 +478,14 @@ static void st_collections_group_parts_part_api(void);
478 478
479/* external part parameters */ 479/* external part parameters */
480static void st_collections_group_parts_part_description_params_int(void); 480static void st_collections_group_parts_part_description_params_int(void);
481static void ob_collections_group_programs_program(void);
482static void st_collections_group_parts_part_description_params_double(void); 481static void st_collections_group_parts_part_description_params_double(void);
483
484static void st_collections_group_programs_program_name(void);
485static void st_collections_group_parts_part_description_params_string(void); 482static void st_collections_group_parts_part_description_params_string(void);
486static void st_collections_group_parts_part_description_params_bool(void); 483static void st_collections_group_parts_part_description_params_bool(void);
487static void st_collections_group_parts_part_description_params_choice(void); 484static void st_collections_group_parts_part_description_params_choice(void);
485static void st_collections_group_parts_part_description_params_smart(void);
486
487static void ob_collections_group_programs_program(void);
488static void st_collections_group_programs_program_name(void);
488static void st_collections_group_programs_program_signal(void); 489static void st_collections_group_programs_program_signal(void);
489static void st_collections_group_programs_program_source(void); 490static void st_collections_group_programs_program_source(void);
490static void st_collections_group_programs_program_filter(void); 491static void st_collections_group_programs_program_filter(void);
@@ -963,6 +964,7 @@ New_Statement_Handler statement_handlers[] =
963 {"collections.group.parts.part.description.params.string", st_collections_group_parts_part_description_params_string}, 964 {"collections.group.parts.part.description.params.string", st_collections_group_parts_part_description_params_string},
964 {"collections.group.parts.part.description.params.bool", st_collections_group_parts_part_description_params_bool}, 965 {"collections.group.parts.part.description.params.bool", st_collections_group_parts_part_description_params_bool},
965 {"collections.group.parts.part.description.params.choice", st_collections_group_parts_part_description_params_choice}, 966 {"collections.group.parts.part.description.params.choice", st_collections_group_parts_part_description_params_choice},
967 {"collections.group.parts.part.description.params.*", st_collections_group_parts_part_description_params_smart},
966 IMAGE_STATEMENTS("collections.group.parts.part.description.") 968 IMAGE_STATEMENTS("collections.group.parts.part.description.")
967 {"collections.group.parts.part.description.font", st_fonts_font}, /* dup */ 969 {"collections.group.parts.part.description.font", st_fonts_font}, /* dup */
968 FONT_STYLE_CC_STATEMENTS("collections.group.parts.part.description.") 970 FONT_STYLE_CC_STATEMENTS("collections.group.parts.part.description.")
@@ -1149,6 +1151,163 @@ New_Statement_Handler statement_handlers_short_single[] =
1149 {"collections.group.parts.part.description.inherit", st_collections_group_parts_part_description_inherit}, 1151 {"collections.group.parts.part.description.inherit", st_collections_group_parts_part_description_inherit},
1150}; 1152};
1151 1153
1154/** @edcsubsection{lazedc_external_params,
1155 * LazEDC Group.Parts.External.Desc.Params} */
1156
1157/**
1158 @page edcref
1159 @block
1160 params
1161 @context
1162 ...
1163 external {
1164 desc { "default";
1165 params {
1166 number: 10; -> int: "number" 10;
1167 number2: 1.1; -> double: "number2" 1.1;
1168 label: "OK"; -> string: "label" "OK";
1169 check: true; -> bool: "check" 1;
1170 check2: false; -> bool: "check2" 0;
1171 text_wrap: mixed; -> choice: "text_wrap" "mixed";
1172 }
1173 }
1174 }
1175 ...
1176 @description
1177 The name of parameter can be used as a statement keyword in params block.
1178 The type of parameter is determined automatically by the value,
1179 so it should follow the next rules.
1180 Number without decimal point is considered as an integer.
1181 Number with decimal point is considered as a double.
1182 Double-quoted string is considered as a string.
1183 'true' or 'false' without quotes is considred as a boolean.
1184 String without quotes except for 'true' or 'false' is considered as a choice.
1185 @since 1.18
1186 @endblock
1187*/
1188static Edje_External_Param_Type
1189_parse_external_param_type(char *token)
1190{
1191 Eina_Bool num, point;
1192 char *begin;
1193
1194 if (param_had_quote(0))
1195 return EDJE_EXTERNAL_PARAM_TYPE_STRING;
1196
1197 num = EINA_TRUE;
1198 point = EINA_FALSE;
1199 begin = token;
1200
1201 while (*token)
1202 {
1203 if ((*token < '0') || (*token > '9'))
1204 {
1205 if ((!point) && (*token == '.'))
1206 {
1207 point = EINA_TRUE;
1208 }
1209 else
1210 {
1211 num = EINA_FALSE;
1212 break;
1213 }
1214 }
1215 token++;
1216 }
1217
1218 if (num)
1219 {
1220 if (!point)
1221 return EDJE_EXTERNAL_PARAM_TYPE_INT;
1222 else
1223 return EDJE_EXTERNAL_PARAM_TYPE_DOUBLE;
1224 }
1225 else
1226 {
1227 if (!strcmp(begin, "true") || !strcmp(begin, "false"))
1228 return EDJE_EXTERNAL_PARAM_TYPE_BOOL;
1229 else
1230 return EDJE_EXTERNAL_PARAM_TYPE_CHOICE;
1231 }
1232}
1233
1234static void
1235st_collections_group_parts_part_description_params_smart(void)
1236{
1237 Edje_Part_Description_External *ed;
1238 Edje_External_Param *param;
1239 Eina_List *l;
1240 char *last, *name, *token;
1241 int found = 0;
1242
1243 check_arg_count(1);
1244
1245 if (current_part->type != EDJE_PART_TYPE_EXTERNAL)
1246 {
1247 ERR("parse error %s:%i. params in non-EXTERNAL part.",
1248 file_in, line - 1);
1249 exit(-1);
1250 }
1251
1252 ed = (Edje_Part_Description_External*) current_desc;
1253
1254 last = eina_list_last_data_get(stack);
1255 if (!strncmp(last, "params.", strlen("params.")))
1256 name = strdup(last + strlen("params."));
1257 else
1258 name = strdup(last);
1259
1260 /* if a param with this name already exists, overwrite it */
1261 EINA_LIST_FOREACH(ed->external_params, l, param)
1262 {
1263 if (!strcmp(param->name, name))
1264 {
1265 found = 1;
1266 break;
1267 }
1268 }
1269
1270 if (!found)
1271 {
1272 param = mem_alloc(SZ(Edje_External_Param));
1273 param->name = name;
1274 }
1275
1276 token = parse_str(0);
1277
1278 param->type = _parse_external_param_type(token);
1279 param->i = 0;
1280 param->d = 0;
1281 param->s = NULL;
1282
1283 switch (param->type)
1284 {
1285 case EDJE_EXTERNAL_PARAM_TYPE_BOOL:
1286 if (!strcmp(token, "true"))
1287 param->i = 1;
1288 else if (!strcmp(token, "false"))
1289 param->i = 0;
1290 break;
1291 case EDJE_EXTERNAL_PARAM_TYPE_INT:
1292 param->i = parse_int(0);
1293 break;
1294 case EDJE_EXTERNAL_PARAM_TYPE_DOUBLE:
1295 param->d = parse_float(0);
1296 break;
1297 case EDJE_EXTERNAL_PARAM_TYPE_CHOICE:
1298 case EDJE_EXTERNAL_PARAM_TYPE_STRING:
1299 param->s = parse_str(0);
1300 break;
1301 default:
1302 ERR("parse error %s:%i. Invalid param type.",
1303 file_in, line - 1);
1304 break;
1305 }
1306
1307 if (!found)
1308 ed->external_params = eina_list_append(ed->external_params, param);
1309}
1310
1152#define PROGRAM_OBJECTS(PREFIX) \ 1311#define PROGRAM_OBJECTS(PREFIX) \
1153 {PREFIX".program", ob_collections_group_programs_program}, /* dup */ \ 1312 {PREFIX".program", ob_collections_group_programs_program}, /* dup */ \
1154 {PREFIX".program.script", ob_collections_group_programs_program_script}, /* dup */ \ 1313 {PREFIX".program.script", ob_collections_group_programs_program_script}, /* dup */ \
diff --git a/src/bin/edje/edje_cc_parse.c b/src/bin/edje/edje_cc_parse.c
index 542079a689..4c860b5dba 100644
--- a/src/bin/edje/edje_cc_parse.c
+++ b/src/bin/edje/edje_cc_parse.c
@@ -65,6 +65,7 @@ int line = 0;
65Eina_List *stack = NULL; 65Eina_List *stack = NULL;
66Eina_Array params; 66Eina_Array params;
67int had_quote = 0; 67int had_quote = 0;
68int params_quote = 0;
68 69
69static char file_buf[4096]; 70static char file_buf[4096];
70static int did_wildcard = 0; 71static int did_wildcard = 0;
@@ -210,6 +211,19 @@ new_object(void)
210 sh = eina_hash_find(_new_statement_short_hash, id); 211 sh = eina_hash_find(_new_statement_short_hash, id);
211 if (!sh) 212 if (!sh)
212 sh = eina_hash_find(_new_statement_short_single_hash, id); 213 sh = eina_hash_find(_new_statement_short_single_hash, id);
214 if (!sh)
215 {
216 char buf[512] = { 0, };
217 char *end;
218
219 strcpy(buf, id);
220 end = strrchr(buf, '.');
221 if (end) end++;
222 else end = buf;
223
224 strcpy(end, "*");
225 sh = eina_hash_find(_new_statement_hash, buf);
226 }
213 if ((!sh) && (!did_wildcard) && (!had_quote)) 227 if ((!sh) && (!did_wildcard) && (!had_quote))
214 { 228 {
215 ERR("%s:%i unhandled keyword %s", 229 ERR("%s:%i unhandled keyword %s",
@@ -239,11 +253,29 @@ new_statement(void)
239 } 253 }
240 else 254 else
241 { 255 {
242 ERR("%s:%i unhandled keyword %s", 256 char buf[512] = { 0, };
243 file_in, line - 1, 257 char *end;
244 (char *)eina_list_data_get(eina_list_last(stack))); 258
245 err_show(); 259 strcpy(buf, id);
246 exit(-1); 260 end = strrchr(buf, '.');
261 if (end) end++;
262 else end = buf;
263
264 strcpy(end, "*");
265 sh = eina_hash_find(_new_statement_hash, buf);
266
267 if (sh)
268 {
269 if (sh->func) sh->func();
270 }
271 else
272 {
273 ERR("%s:%i unhandled keyword %s",
274 file_in, line - 1,
275 (char *)eina_list_data_get(eina_list_last(stack)));
276 err_show();
277 exit(-1);
278 }
247 } 279 }
248} 280}
249 281
@@ -729,6 +761,7 @@ parse(char *data, off_t size)
729 /* clear out params */ 761 /* clear out params */
730 while ((param = eina_array_pop(&params))) 762 while ((param = eina_array_pop(&params)))
731 free(param); 763 free(param);
764 params_quote = 0;
732 /* remove top from stack */ 765 /* remove top from stack */
733 stack_pop(); 766 stack_pop();
734 } 767 }
@@ -775,10 +808,14 @@ parse(char *data, off_t size)
775 { 808 {
776 if (do_params) 809 if (do_params)
777 { 810 {
811 if (had_quote)
812 params_quote |= (1 << eina_array_count(&params));
778 eina_array_push(&params, token); 813 eina_array_push(&params, token);
779 } 814 }
780 else if (do_indexes) 815 else if (do_indexes)
781 { 816 {
817 if (had_quote)
818 params_quote |= (1 << eina_array_count(&params));
782 do_indexes++; 819 do_indexes++;
783 eina_array_push(&params, token); 820 eina_array_push(&params, token);
784 } 821 }
@@ -1868,3 +1905,9 @@ get_param_index(char *str)
1868 1905
1869 return -1; 1906 return -1;
1870} 1907}
1908
1909int
1910param_had_quote(int n)
1911{
1912 return (params_quote & (1 << n));
1913}