free(da);
}
-static Eina_Bool
-_delayed_action_cb_timer(void *data)
-{
- Delayed_Action *da;
- E_Action *act;
-
- da = data;
- da->timer = NULL;
- act = e_action_find(da->delayed.action);
- if (act)
- {
- if (act->func.go) act->func.go(da->obj, da->delayed.params);
- }
- _delayed_actions = eina_list_remove(_delayed_actions, da);
- _delayed_action_free(da);
- return ECORE_CALLBACK_CANCEL;
-}
-
static void
_delayed_action_do(Delayed_Action *da)
{
}
static void
-_delayed_action_list_parse_action(const char *str, double *delay, const char **action, const char **params)
-{
- char fbuf[16];
- char buf[1024];
- const char *p;
-
- buf[0] = 0;
- sscanf(str, "%10s %1000s", fbuf, buf);
- *action = eina_stringshare_add(buf);
- *delay = atof(fbuf);
- p = strchr(str, ' ');
- if (p)
- {
- p++;
- p = strchr(p, ' ');
- if (p)
- {
- p++;
- *params = eina_stringshare_add(p);
- }
- }
-}
-
-static void
-_delayed_action_list_parse(Delayed_Action *da, const char *params)
-{
- double delay = 2.0;
- const char *p, *a1start = NULL, *a1stop = NULL;
- const char *a2start = NULL, *a2stop = NULL;
-
- // FORMAT: "[0.0 default_action param1 param2] [x.x action2 param1 param2]"
- p = params;
- while (*p)
- {
- if ((*p == '[') && ((p == params) || ((p > params) && (p[-1] != '\\')))) {a1start = p + 1; break; }
- p++;
- }
- while (*p)
- {
- if ((*p == ']') && ((p == params) || ((p > params) && (p[-1] != '\\')))) {a1stop = p; break; }
- p++;
- }
- while (*p)
- {
- if ((*p == '[') && ((p == params) || ((p > params) && (p[-1] != '\\')))) {a2start = p + 1; break; }
- p++;
- }
- while (*p)
- {
- if ((*p == ']') && ((p == params) || ((p > params) && (p[-1] != '\\')))) {a2stop = p; break; }
- p++;
- }
- if ((a1start) && (a2start) && (a1stop) && (a2stop))
- {
- char *a1, *a2;
-
- a1 = alloca(a1stop - a1start + 1);
- eina_strlcpy(a1, a1start, a1stop - a1start + 1);
- _delayed_action_list_parse_action(a1, &delay, &da->def.action, &da->def.params);
-
- a2 = alloca(a1stop - a1start + 1);
- eina_strlcpy(a2, a2start, a2stop - a2start + 1);
- _delayed_action_list_parse_action(a2, &delay, &da->delayed.action, &da->delayed.params);
- }
- da->timer = ecore_timer_add(delay, _delayed_action_cb_timer, da);
-}
-
-static void
-_delayed_action_key_add(E_Object *obj, const char *params, Ecore_Event_Key *ev)
+_delayed_action_key_add(E_Object *obj, const char *params EINA_UNUSED, Ecore_Event_Key *ev)
{
Delayed_Action *da;
}
da->mouse = 0;
da->key = eina_stringshare_add(ev->key);
- if (params) _delayed_action_list_parse(da, params);
_delayed_actions = eina_list_append(_delayed_actions, da);
}
}
static void
-_delayed_action_mouse_add(E_Object *obj, const char *params, E_Binding_Event_Mouse_Button *ev)
+_delayed_action_mouse_add(E_Object *obj, const char *params EINA_UNUSED, E_Binding_Event_Mouse_Button *ev)
{
Delayed_Action *da;
}
da->mouse = 1;
da->button = ev->button;
- if (params) _delayed_action_list_parse(da, params);
_delayed_actions = eina_list_append(_delayed_actions, da);
}
static Eina_Bool _e_info_client_eldbus_message_with_args(const char *method, E_Info_Message_Cb cb, const char *signature, ...);
static void _e_info_client_eldbus_message_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending *p);
+static Eina_Bool
+_util_string_to_int(const char *str, int *num, int base)
+{
+ char *end;
+ int errsv;
+
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(str, EINA_FALSE);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(num, EINA_FALSE);
+
+ const long sl = strtol(str, &end, base);
+ errsv = errno;
+
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((end == str), EINA_FALSE); /* given string is not a decimal number */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(('\0' != *end), EINA_FALSE); /* given string has extra characters */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errsv)), EINA_FALSE); /* out of range of type long */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((sl > INT_MAX), EINA_FALSE); /* greater than INT_MAX */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((sl < INT_MIN), EINA_FALSE); /* less than INT_MIN */
+
+ *num = (int)sl;
+
+ return EINA_TRUE;
+}
+
+/* buff: string to be parsed
+ * next: return values it contains the address of the first invalid character
+ * num: return value it contains integer value according to the given base
+ */
+static Eina_Bool
+_util_string_to_int_token(const char *str, char **next, int *num, int base)
+{
+ int errsv;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(str, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(next, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(num, EINA_FALSE);
+
+ const long sl = strtol(str, next, base);
+ errsv = errno;
+
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((*next == str), EINA_FALSE); /* given string is not a decimal number */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errsv)), EINA_FALSE); /* out of range of type long */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((sl > INT_MAX), EINA_FALSE); /* greater than INT_MAX */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((sl < INT_MIN), EINA_FALSE); /* less than INT_MIN */
+
+ *num = (int)sl;
+
+ return EINA_TRUE;
+}
+
+static Eina_Bool
+_util_string_to_double(const char *str, double *num)
+{
+ char *end;
+ int errsv;
+
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(str, EINA_FALSE);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(num, EINA_FALSE);
+
+ const double sd = strtod(str, &end);
+ errsv = errno;
+
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((end == str), EINA_FALSE); /* given string is not a floating point number */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(('\0' != *end), EINA_FALSE); /* given string has extra characters */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(((DBL_MIN == sd || DBL_MAX == sd) && (ERANGE == errsv)), EINA_FALSE); /* out of range of type double */
+
+ *num = sd;
+
+ return EINA_TRUE;
+}
+
static E_Win_Info *
_e_win_info_new(Ecore_Window id, uint32_t res_id, int pid, Eina_Bool alpha, int opaque, const char *name, int x, int y, int w, int h, int layer, int visible, int visibility, int iconic, int frame_visible, int focused, int hwc, int pl_zpos, Ecore_Window parent_id, const char *layer_name)
{
while (keepRunning);
}
+static Eina_Bool
+_opt_parse(char *opt, char *delims, int *vals, int n_vals)
+{
+ Eina_Bool res;
+ int n, i;
+
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(n_vals > 0, EINA_FALSE);
+
+ for (i = 0; i < n_vals; i++)
+ {
+ res = _util_string_to_int_token(opt, &opt, &n, 10);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EINA_FALSE);
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(
+ (!((strlen(opt) == 0) && (i == (n_vals - 1))) &&
+ (strlen(opt) < 2)),
+ EINA_FALSE);
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((*opt != delims[i]), EINA_FALSE);
+
+ opt = opt + 1;
+ vals[i] = n;
+ }
+
+ return EINA_TRUE;
+}
+
static void
_e_info_client_proc_punch(int argc, char **argv)
{
int onoff = 0, x = 0, y = 0, w = 0, h = 0;
int a = 0, r = 0, g = 0, b = 0;
- char *arg;
+ char delims_geom[] = { 'x', '+', '+', '\0' };
+ int vals_geom[] = { 0, 0, 0, 0 };
+ char delims_col[] = { ',', ',', ',', '\0' };
+ int vals_col[] = { 0, 0, 0, 0 };
+ Eina_Bool res;
- EINA_SAFETY_ON_FALSE_RETURN(argc >= 3);
- EINA_SAFETY_ON_NULL_RETURN(argv[2]);
+ EINA_SAFETY_ON_FALSE_GOTO(argc >= 3, wrong_args);
+ EINA_SAFETY_ON_NULL_GOTO(argv[2], wrong_args);
+ EINA_SAFETY_ON_NULL_GOTO(argv[3], wrong_args);
- arg = argv[2];
- if (!strncmp(arg, "on", 2))
- onoff = 1;
+ if (!strncmp(argv[2], "on", 2)) onoff = 1;
- arg = argv[3];
- if (arg && sscanf(arg, "%dx%d+%d+%d", &w, &h, &x, &y) < 0)
- {
- printf("wrong geometry arguments(<w>x<h>+<x>+<y>\n");
- return;
- }
+ res = _opt_parse(argv[3], delims_geom, vals_geom, (sizeof(vals_geom) / sizeof(int)));
+ EINA_SAFETY_ON_FALSE_GOTO(res, wrong_args);
- if (argc == 5 && argv[4])
+ w = vals_geom[0]; h = vals_geom[1];
+ x = vals_geom[2]; y = vals_geom[3];
+
+ if (argc == 5)
{
- arg = argv[4];
- if (sscanf(arg, "%d,%d,%d,%d", &a, &r, &g, &b) < 0)
- {
- printf("wrong color arguments(<a>,<r>,<g>,<b>)\n");
- return;
- }
+ EINA_SAFETY_ON_NULL_GOTO(argv[4], wrong_args);
+
+ res = _opt_parse(argv[4], delims_col, vals_col, (sizeof(vals_col) / sizeof(int)));
+ EINA_SAFETY_ON_FALSE_GOTO(res, wrong_args);
+
+ a = vals_col[0]; r = vals_col[1]; g = vals_col[2]; b = vals_col[3];
}
_e_info_client_eldbus_message_with_args("punch", NULL, "iiiiiiiii", onoff, x, y, w, h, a, r, g, b);
+ return;
+
+wrong_args:
+ printf("wrong geometry arguments(<w>x<h>+<x>+<y>\n");
+ printf("wrong color arguments(<a>,<r>,<g>,<b>)\n");
}
static void
int i;
int mode = 0;
const char *value = NULL;
+ Eina_Bool res = EINA_FALSE;
if (argc < 3)
{
value = argv[4];
int32_t value_number;
if (strlen(value) >= 2 && value[0] == '0' && value[1] == 'x')
- sscanf(value, "%x", &value_number);
+ res = _util_string_to_int(value, &value_number, 16);
else
- sscanf(value, "%d", &value_number);
+ res = _util_string_to_int(value, &value_number, 10);
+
+ EINA_SAFETY_ON_FALSE_RETURN(res);
param[1] = value_number;
}
else if (eina_streq(argv[2], "timeout"))
{
if (argc != 4) goto arg_err;
- sscanf(argv[3], "%lf", &sec);
- cmd = E_INFO_CMD_SCRSAVER_TIMEOUT;
+ res = _util_string_to_double(argv[3], &sec);
+ EINA_SAFETY_ON_FALSE_GOTO(res, arg_err);
+
+ cmd = E_INFO_CMD_SCRSAVER_TIMEOUT;
printf("sec: %lf\n", sec);
}
else
E_Client *ec;
Evas_Object *o;
int32_t value_number = 0;
+ Eina_Bool res = EINA_FALSE;
eldbus_message_iter_arguments_append(iter, "a(ss)", &array_of_ec);
else
{
if (strlen(value) >= 2 && value[0] == '0' && value[1] == 'x')
- sscanf(value, "%x", &value_number);
+ res = e_util_string_to_int(value, &value_number, 16);
else
- sscanf(value, "%d", &value_number);
+ res = e_util_string_to_int(value, &value_number, 10);
+
+ EINA_SAFETY_ON_FALSE_RETURN(res);
}
}
int32_t value_number;
Evas_Object *o;
E_Client *ec;
+ Eina_Bool res = EINA_FALSE;
if (!eldbus_message_arguments_get(msg, "siiiiiiii", &value, &transform_id, &enable, &x, &y, &sx, &sy, °ree, &background))
{
}
if (strlen(value) >= 2 && value[0] == '0' && value[1] == 'x')
- sscanf(value, "%x", &value_number);
+ res = e_util_string_to_int(value, &value_number, 16);
else
- sscanf(value, "%d", &value_number);
+ res = e_util_string_to_int(value, &value_number, 10);
+
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(res, reply);
for (o = evas_object_top_get(e_comp->evas); o; o = evas_object_below_get(o))
{
int32_t win_id = 0;
E_Client *ec;
Evas_Object *o;
+ Eina_Bool res = EINA_FALSE;
if (!e_policy)
{
options = eina_list_append(options, str);
}
- sscanf(win_str, "%x", &win_id);
+ res = e_util_string_to_int(win_str, &win_id, 16);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(res, reply);
+
for (o = evas_object_top_get(e_comp->evas); o; o = evas_object_below_get(o))
{
ec = evas_object_data_get(o, "E_Client");
static void
_e_main_desk_restore(void)
{
- const Eina_List *l;
- E_Zone *zone;
E_Client *ec;
- char *env;
- char name[1024];
-
- EINA_LIST_FOREACH(e_comp->zones, l, zone)
- {
- E_Desk *desk;
- int desk_x, desk_y;
- char buf_e[64];
-
- snprintf(name, sizeof(name), "DESK_%d_%d", 0, zone->num);
- env = getenv(name);
- if (!env) continue;
- snprintf(buf_e, sizeof(buf_e), "%s", env);
- if (!sscanf(buf_e, "%d,%d", &desk_x, &desk_y)) continue;
- desk = e_desk_at_xy_get(zone, desk_x, desk_y);
- if (!desk) continue;
- e_desk_show(desk);
- }
E_CLIENT_REVERSE_FOREACH(ec)
if ((!e_client_util_ignored_get(ec)) && e_client_util_desk_visible(ec, e_desk_current_get(ec->zone)))
return str;
}
+E_API Eina_Bool
+e_util_string_to_int(const char *str, int *num, int base)
+{
+ char *end;
+ int errsv;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(str, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(num, EINA_FALSE);
+
+ const long sl = strtol(str, &end, base);
+ errsv = errno;
+
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((end == str), EINA_FALSE); /* given string is not a decimal number */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(('\0' != *end), EINA_FALSE); /* given string has extra characters */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errsv)), EINA_FALSE); /* out of range of type long */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((sl > INT_MAX), EINA_FALSE); /* greater than INT_MAX */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((sl < INT_MIN), EINA_FALSE); /* less than INT_MIN */
+
+ *num = (int)sl;
+
+ return EINA_TRUE;
+}
+
+/* str : string to be parsed
+ * next: return values it contains the address of the first invalid character
+ * num : return value it contains integer value according to the given base
+ */
+E_API Eina_Bool
+e_util_string_to_int_token(const char *str, char **next, int *num, int base)
+{
+ int errsv;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(str, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(next, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(num, EINA_FALSE);
+
+ const long sl = strtol(str, next, base);
+ errsv = errno;
+
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((*next == str), EINA_FALSE); /* given string is not a decimal number */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errsv)), EINA_FALSE); /* out of range of type long */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((sl > INT_MAX), EINA_FALSE); /* greater than INT_MAX */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((sl < INT_MIN), EINA_FALSE); /* less than INT_MIN */
+
+ *num = (int)sl;
+
+ return EINA_TRUE;
+}
+
+E_API Eina_Bool
+e_util_string_to_double(const char *str, double *num)
+{
+ char *end;
+ int errsv;
+
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(str, EINA_FALSE);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(num, EINA_FALSE);
+
+ const double sd = strtod(str, &end);
+ errsv = errno;
+
+ EINA_SAFETY_ON_TRUE_RETURN_VAL((end == str), EINA_FALSE); /* given string is not a floating point number */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(('\0' != *end), EINA_FALSE); /* given string has extra characters */
+ EINA_SAFETY_ON_TRUE_RETURN_VAL(((DBL_MIN == sd || DBL_MAX == sd) && (ERANGE == errsv)), EINA_FALSE); /* out of range of type double */
+
+ *num = sd;
+
+ return EINA_TRUE;
+}
+
E_API void
e_util_evas_objects_above_print(Evas_Object *o)
{
E_API char *e_util_string_append_char(char *str, size_t *size, size_t *len, char c);
E_API char *e_util_string_append_quoted(char *str, size_t *size, size_t *len, const char *src);
+E_API Eina_Bool e_util_string_to_int(const char *str, int *num, int base);
+E_API Eina_Bool e_util_string_to_int_token(const char *str, char **next, int *num, int base);
+E_API Eina_Bool e_util_string_to_double(const char *str, double *num);
E_API void e_util_evas_objects_above_print(Evas_Object *o);
E_API void e_util_evas_objects_above_print_smart(Evas_Object *o);