use strbuf instead of strcat in edgebinding string synthesis

CID 1039800
This commit is contained in:
Mike Blumenkrantz 2016-02-29 09:52:54 -05:00
parent 02c0612faf
commit 55fc7f4961
1 changed files with 29 additions and 30 deletions

View File

@ -1361,65 +1361,64 @@ _find_edge_binding_action(const char *action, const char *params, int *g, int *a
static char *
_edge_binding_text_get(E_Zone_Edge edge, float delay, int mod, int drag_only)
{
char b[256] = "";
if (mod & E_BINDING_MODIFIER_CTRL)
strcat(b, _("CTRL"));
Eina_Strbuf *b;
char *ret;
b = eina_strbuf_new();
if (mod & E_BINDING_MODIFIER_ALT)
{
if (b[0]) strcat(b, " + ");
strcat(b, _("ALT"));
if (eina_strbuf_length_get(b)) eina_strbuf_append(b, " + ");
eina_strbuf_append(b, _("ALT"));
}
if (mod & E_BINDING_MODIFIER_SHIFT)
{
if (b[0]) strcat(b, " + ");
strcat(b, _("SHIFT"));
if (eina_strbuf_length_get(b)) eina_strbuf_append(b, " + ");
eina_strbuf_append(b, _("SHIFT"));
}
if (mod & E_BINDING_MODIFIER_WIN)
{
if (b[0]) strcat(b, " + ");
strcat(b, _("WIN"));
if (eina_strbuf_length_get(b)) eina_strbuf_append(b, " + ");
eina_strbuf_append(b, _("WIN"));
}
if (edge)
{
if (b[0]) strcat(b, " + ");
if (eina_strbuf_length_get(b)) eina_strbuf_append(b, " + ");
switch (edge)
{
case E_ZONE_EDGE_LEFT:
strcat(b, _("Left Edge"));
eina_strbuf_append(b, _("Left Edge"));
break;
case E_ZONE_EDGE_TOP:
strcat(b, _("Top Edge"));
eina_strbuf_append(b, _("Top Edge"));
break;
case E_ZONE_EDGE_RIGHT:
strcat(b, _("Right Edge"));
eina_strbuf_append(b, _("Right Edge"));
break;
case E_ZONE_EDGE_BOTTOM:
strcat(b, _("Bottom Edge"));
eina_strbuf_append(b, _("Bottom Edge"));
break;
case E_ZONE_EDGE_TOP_LEFT:
strcat(b, _("Top Left Edge"));
eina_strbuf_append(b, _("Top Left Edge"));
break;
case E_ZONE_EDGE_TOP_RIGHT:
strcat(b, _("Top Right Edge"));
eina_strbuf_append(b, _("Top Right Edge"));
break;
case E_ZONE_EDGE_BOTTOM_RIGHT:
strcat(b, _("Bottom Right Edge"));
eina_strbuf_append(b, _("Bottom Right Edge"));
break;
case E_ZONE_EDGE_BOTTOM_LEFT:
strcat(b, _("Bottom Left Edge"));
eina_strbuf_append(b, _("Bottom Left Edge"));
break;
default:
@ -1429,25 +1428,25 @@ _edge_binding_text_get(E_Zone_Edge edge, float delay, int mod, int drag_only)
if (delay)
{
char buf[20];
if (b[0]) strcat(b, " ");
if (eina_strbuf_length_get(b)) eina_strbuf_append(b, " ");
if (delay == -1.0)
snprintf(buf, 20, _("(left clickable)"));
eina_strbuf_append(b, _("(left clickable)"));
else if (delay < -1.0)
snprintf(buf, 20, _("(clickable)"));
eina_strbuf_append(b, _("(clickable)"));
else
snprintf(buf, 20, "%.2fs", delay);
strcat(b, buf);
eina_strbuf_append_printf(b, "%.2fs", delay);
}
if (drag_only)
{
if (b[0]) strcat(b, " ");
strcat(b, _("(drag only)"));
if (eina_strbuf_length_get(b)) eina_strbuf_append(b, " ");
eina_strbuf_append(b, _("(drag only)"));
}
if (!b[0]) return strdup(TEXT_NONE_ACTION_EDGE);
return strdup(b);
ret = eina_strbuf_string_steal(b);
eina_strbuf_free(b);
if (ret[0]) return ret;
free(ret);
return strdup(TEXT_NONE_ACTION_EDGE);
}