summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaehwan Kim <jae.hwan.kim@samsung.com>2015-12-31 11:59:48 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-12-31 11:59:48 +0900
commit26d0c5823f3ff514e82184505043dc1b795ddc8a (patch)
tree70171e6bff071ea3537edff15258e1693ff40ea1
parenta96bf53c21395edb28610b5d8d44c49da8fae959 (diff)
edje_embryo: add printf feature.
Summary: The edc debugging is difficult because users can not check whether or not any program is executed or the state of part. If users can print that property, they can do debugging more easily. This "printf" feature is for debugging edc. @feature Test Plan: add printf("test : %s %d %f", "text", 1, 0.5); in the script in the edc build it by edje_cc excute it and see the log Reviewers: cedric, raster, jpeg Reviewed By: jpeg Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D3499
-rw-r--r--data/embryo/default.inc2
-rw-r--r--src/lib/embryo/embryo_str.c301
2 files changed, 172 insertions, 131 deletions
diff --git a/data/embryo/default.inc b/data/embryo/default.inc
index b82ff14b0a..632b30b892 100644
--- a/data/embryo/default.inc
+++ b/data/embryo/default.inc
@@ -95,6 +95,8 @@ native strstr(str[], ndl[]);
95native strchr(str[], ch[]); 95native strchr(str[], ch[]);
96/* same as strrchr, except ch must be a 1 charater long string and returns string index */ 96/* same as strrchr, except ch must be a 1 charater long string and returns string index */
97native strrchr(str[], ch[]); 97native strrchr(str[], ch[]);
98/* same as printf, except only supports %%, %c, %i, %d, %f, %x, %X, %s, \n and \t */
99native printf(fmt[], ...);
98/* return random number 0 - 65535 */ 100/* return random number 0 - 65535 */
99native rand(); 101native rand();
100/* return random number 0.0 - 1.0 */ 102/* return random number 0.0 - 1.0 */
diff --git a/src/lib/embryo/embryo_str.c b/src/lib/embryo/embryo_str.c
index d213f61f01..e428179074 100644
--- a/src/lib/embryo/embryo_str.c
+++ b/src/lib/embryo/embryo_str.c
@@ -260,13 +260,149 @@ _embryo_str_strcut(Embryo_Program *ep, Embryo_Cell *params)
260} 260}
261 261
262static Embryo_Cell 262static Embryo_Cell
263_embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params) 263_str_snprintf(Embryo_Program *ep, char *s1, char *s2, int max_len, int pnum, Embryo_Cell *params)
264{ 264{
265 char *s1, *s2; 265 int i, o, p;
266 int i, o;
267 int inesc = 0; 266 int inesc = 0;
268 int insub = 0; 267 int insub = 0;
269 int p, pnum; 268
269 for (p = 0, o = 0, i = 0; (s1[i]) && (o < max_len) && (p < (pnum + 1)); i++)
270 {
271 if ((!inesc) && (!insub))
272 {
273 if (s1[i] == '\\') inesc = 1;
274 else if (s1[i] == '%') insub = 1;
275 if ((!inesc) && (!insub))
276 {
277 s2[o] = s1[i];
278 o++;
279 }
280 }
281 else
282 {
283 Embryo_Cell *cptr;
284
285 if (inesc)
286 {
287 switch (s1[i])
288 {
289 case 't':
290 s2[o] = '\t';
291 o++;
292 break;
293 case 'n':
294 s2[o] = '\n';
295 o++;
296 break;
297 default:
298 s2[o] = s1[i];
299 o++;
300 break;
301 }
302 inesc = 0;
303 }
304 if ((insub) && (s1[i] == '%')) pnum++;
305 if ((insub) && (p < pnum))
306 {
307 switch (s1[i])
308 {
309 case '%':
310 s2[o] = '%';
311 o++;
312 break;
313 case 'c':
314 cptr = embryo_data_address_get(ep, params[p]);
315 if (cptr) s2[o] = (char)(*cptr);
316 p++;
317 o++;
318 break;
319 case 'i':
320 case 'd':
321 case 'x':
322 case 'X':
323 {
324 char fmt[10] = "";
325 char tmp[256] = "";
326 int l;
327
328 if (s1[i] == 'i') strcpy(fmt, "%i");
329 else if (s1[i] == 'd') strcpy(fmt, "%d");
330 else if (s1[i] == 'x') strcpy(fmt, "%x");
331 else if (s1[i] == 'X') strcpy(fmt, "%08x");
332 cptr = embryo_data_address_get(ep, params[p]);
333 if (cptr) snprintf(tmp, sizeof(tmp), fmt, (int)(*cptr));
334 l = strlen(tmp);
335 if ((o + l) > max_len)
336 {
337 l = max_len - o;
338 if (l < 0) l = 0;
339 tmp[l] = 0;
340 }
341 strcpy(s2 + o, tmp);
342 o += l;
343 p++;
344 }
345 break;
346 case 'f':
347 {
348 char tmp[256] = "";
349 int l;
350
351 cptr = embryo_data_address_get(ep, params[p]);
352 if (cptr) snprintf(tmp, sizeof(tmp), "%f", (double)EMBRYO_CELL_TO_FLOAT(*cptr));
353 l = strlen(tmp);
354 if ((o + l) > max_len)
355 {
356 l = max_len - o;
357 if (l < 0) l = 0;
358 tmp[l] = 0;
359 }
360 strcpy(s2 + o, tmp);
361 o += l;
362 p++;
363 }
364 break;
365 case 's':
366 {
367 char *tmp;
368 int l;
369
370 STRGET(ep, tmp, params[p]);
371 if (tmp)
372 {
373 l = strlen(tmp);
374 if ((o + l) > max_len)
375 {
376 l = max_len - o;
377 if (l < 0) l = 0;
378 tmp[l] = 0;
379 }
380 strcpy(s2 + o, tmp);
381 o += l;
382 }
383 p++;
384 }
385 break;
386 default:
387 break;
388 }
389 insub = 0;
390 }
391 else if (insub)
392 insub = 0;
393 }
394 }
395 s2[o] = 0;
396
397 return o;
398}
399
400static Embryo_Cell
401_embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params)
402{
403 char *s1, *s2;
404 int o = 0;
405 int pnum;
270 406
271 /* params[1] = buf */ 407 /* params[1] = buf */
272 /* params[2] = bufsize */ 408 /* params[2] = bufsize */
@@ -280,135 +416,37 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params)
280 if (!s2) return -1; 416 if (!s2) return -1;
281 s2[0] = 0; 417 s2[0] = 0;
282 pnum = (params[0] / sizeof(Embryo_Cell)) - 3; 418 pnum = (params[0] / sizeof(Embryo_Cell)) - 3;
283 for (p = 0, o = 0, i = 0; (s1[i]) && (o < (params[2] - 1)) && (p < (pnum + 1)); i++) 419
284 { 420 _str_snprintf(ep, s1, s2, params[2], pnum, &params[4]);
285 if ((!inesc) && (!insub))
286 {
287 if (s1[i] == '\\') inesc = 1;
288 else if (s1[i] == '%') insub = 1;
289 if ((!inesc) && (!insub))
290 {
291 s2[o] = s1[i];
292 o++;
293 }
294 }
295 else
296 {
297 Embryo_Cell *cptr;
298
299 if (inesc)
300 {
301 switch (s1[i])
302 {
303 case 't':
304 s2[o] = '\t';
305 o++;
306 break;
307 case 'n':
308 s2[o] = '\n';
309 o++;
310 break;
311 default:
312 s2[o] = s1[i];
313 o++;
314 break;
315 }
316 inesc = 0;
317 }
318 if ((insub) && (s1[i] == '%')) pnum++;
319 if ((insub) && (p < pnum))
320 {
321 switch (s1[i])
322 {
323 case '%':
324 s2[o] = '%';
325 o++;
326 break;
327 case 'c':
328 cptr = embryo_data_address_get(ep, params[4 + p]);
329 if (cptr) s2[o] = (char)(*cptr);
330 p++;
331 o++;
332 break;
333 case 'i':
334 case 'd':
335 case 'x':
336 case 'X':
337 {
338 char fmt[10] = "";
339 char tmp[256] = "";
340 int l;
341
342 if (s1[i] == 'i') strcpy(fmt, "%i");
343 else if (s1[i] == 'd') strcpy(fmt, "%d");
344 else if (s1[i] == 'x') strcpy(fmt, "%x");
345 else if (s1[i] == 'X') strcpy(fmt, "%08x");
346 cptr = embryo_data_address_get(ep, params[4 + p]);
347 if (cptr) snprintf(tmp, sizeof(tmp), fmt, (int)(*cptr));
348 l = strlen(tmp);
349 if ((o + l) > (params[2] - 1))
350 {
351 l = params[2] - 1 - o;
352 if (l < 0) l = 0;
353 tmp[l] = 0;
354 }
355 strcpy(s2 + o, tmp);
356 o += l;
357 p++;
358 }
359 break;
360 case 'f':
361 {
362 char tmp[256] = "";
363 int l;
364
365 cptr = embryo_data_address_get(ep, params[4 + p]);
366 if (cptr) snprintf(tmp, sizeof(tmp), "%f", (double)EMBRYO_CELL_TO_FLOAT(*cptr));
367 l = strlen(tmp);
368 if ((o + l) > (params[2] - 1))
369 {
370 l = params[2] - 1 - o;
371 if (l < 0) l = 0;
372 tmp[l] = 0;
373 }
374 strcpy(s2 + o, tmp);
375 o += l;
376 p++;
377 }
378 break;
379 case 's':
380 {
381 char *tmp;
382 int l;
383
384 STRGET(ep, tmp, params[4 + p]);
385 if (tmp)
386 {
387 l = strlen(tmp);
388 if ((o + l) > (params[2] - 1))
389 {
390 l = params[2] - 1 - o;
391 if (l < 0) l = 0;
392 tmp[l] = 0;
393 }
394 strcpy(s2 + o, tmp);
395 o += l;
396 }
397 p++;
398 }
399 break;
400 default:
401 break;
402 }
403 insub = 0;
404 }
405 else if (insub)
406 insub = 0;
407 }
408 }
409 s2[o] = 0;
410 421
411 STRSET(ep, params[1], s2); 422 STRSET(ep, params[1], s2);
423
424 return o;
425}
426
427static Embryo_Cell
428_embryo_str_printf(Embryo_Program *ep, Embryo_Cell *params)
429{
430 char *s1, *s2;
431 int o = 0;
432 int pnum;
433 int max_len = 0;
434
435 /* params[1] = format_string */
436 /* params[2] = first arg ... */
437 if (params[0] < (Embryo_Cell)(1 * sizeof(Embryo_Cell))) return 0;
438 STRGET(ep, s1, params[1]);
439 if (!s1) return -1;
440 max_len = strlen(s1) + (params[0] - 1) * 256;
441 s2 = alloca(max_len + 1);
442 if (!s2) return -1;
443 s2[0] = 0;
444 pnum = (params[0] / sizeof(Embryo_Cell)) - 1;
445
446 _str_snprintf(ep, s1, s2, max_len, pnum, &params[2]);
447
448 DBG("%s", s2);
449
412 return o; 450 return o;
413} 451}
414 452
@@ -481,4 +519,5 @@ _embryo_str_init(Embryo_Program *ep)
481 embryo_program_native_call_add(ep, "strstr", _embryo_str_strstr); 519 embryo_program_native_call_add(ep, "strstr", _embryo_str_strstr);
482 embryo_program_native_call_add(ep, "strchr", _embryo_str_strchr); 520 embryo_program_native_call_add(ep, "strchr", _embryo_str_strchr);
483 embryo_program_native_call_add(ep, "strrchr", _embryo_str_strrchr); 521 embryo_program_native_call_add(ep, "strrchr", _embryo_str_strrchr);
522 embryo_program_native_call_add(ep, "printf", _embryo_str_printf);
484} 523}