accel-parse: Clean up error handling

Now that we have the code in-tree, we can change the API to actually
report an error rather than checking afterwards.
This commit is contained in:
Jasper St. Pierre 2014-04-07 11:20:27 -04:00
parent e70f336a09
commit 545c3b6678

View File

@ -167,16 +167,16 @@ is_keycode (const gchar *string)
g_ascii_isxdigit (string[3])); g_ascii_isxdigit (string[3]));
} }
static void static gboolean
accelerator_parse (const gchar *accelerator, accelerator_parse (const gchar *accelerator,
guint *accelerator_key, guint *accelerator_key,
guint *accelerator_keycode, guint *accelerator_keycode,
MetaVirtualModifier *accelerator_mods) MetaVirtualModifier *accelerator_mods)
{ {
gboolean error = FALSE;
guint keyval, keycode; guint keyval, keycode;
MetaVirtualModifier mods; MetaVirtualModifier mods;
gint len; gint len;
gboolean error;
if (accelerator_key) if (accelerator_key)
*accelerator_key = 0; *accelerator_key = 0;
@ -184,9 +184,13 @@ accelerator_parse (const gchar *accelerator,
*accelerator_keycode = 0; *accelerator_keycode = 0;
if (accelerator_mods) if (accelerator_mods)
*accelerator_mods = 0; *accelerator_mods = 0;
g_return_if_fail (accelerator != NULL);
error = FALSE; if (accelerator == NULL)
{
error = TRUE;
goto out;
}
keyval = 0; keyval = 0;
mods = 0; mods = 0;
len = strlen (accelerator); len = strlen (accelerator);
@ -312,7 +316,7 @@ accelerator_parse (const gchar *accelerator,
out: out:
if (error) if (error)
keyval = keycode = mods = 0; return FALSE;
if (accelerator_key) if (accelerator_key)
*accelerator_key = keyval; *accelerator_key = keyval;
@ -320,6 +324,8 @@ out:
*accelerator_keycode = keycode; *accelerator_keycode = keycode;
if (accelerator_mods) if (accelerator_mods)
*accelerator_mods = mods; *accelerator_mods = mods;
return TRUE;
} }
gboolean gboolean
@ -328,52 +334,18 @@ meta_parse_accelerator (const char *accel,
unsigned int *keycode, unsigned int *keycode,
MetaVirtualModifier *mask) MetaVirtualModifier *mask)
{ {
MetaVirtualModifier gdk_mask = 0;
guint gdk_sym = 0;
guint gdk_code = 0;
*keysym = 0;
*keycode = 0;
*mask = 0;
if (!accel[0] || strcmp (accel, "disabled") == 0) if (!accel[0] || strcmp (accel, "disabled") == 0)
return TRUE; return TRUE;
accelerator_parse (accel, &gdk_sym, &gdk_code, &gdk_mask); return accelerator_parse (accel, keysym, keycode, mask);
if (gdk_mask == 0 && gdk_sym == 0 && gdk_code == 0)
return FALSE;
if (gdk_sym == None && gdk_code == 0)
return FALSE;
*keysym = gdk_sym;
*keycode = gdk_code;
*mask = gdk_mask;
return TRUE;
} }
gboolean gboolean
meta_parse_modifier (const char *accel, meta_parse_modifier (const char *accel,
MetaVirtualModifier *mask) MetaVirtualModifier *mask)
{ {
MetaVirtualModifier gdk_mask = 0;
guint gdk_sym = 0;
guint gdk_code = 0;
*mask = 0;
if (accel == NULL || !accel[0] || strcmp (accel, "disabled") == 0) if (accel == NULL || !accel[0] || strcmp (accel, "disabled") == 0)
return TRUE; return TRUE;
accelerator_parse (accel, &gdk_sym, &gdk_code, &gdk_mask); return accelerator_parse (accel, NULL, NULL, mask);
if (gdk_mask == 0 && gdk_sym == 0 && gdk_code == 0)
return FALSE;
if (gdk_sym != None || gdk_code != 0)
return FALSE;
*mask = gdk_mask;
return TRUE;
} }