Remove some goto statement
authorPeng Huang <shawn.p.huang@gmail.com>
Sat, 5 Dec 2009 10:30:44 +0000 (18:30 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Sat, 5 Dec 2009 10:30:44 +0000 (18:30 +0800)
src/ibusconnection.c
src/ibusengine.c
src/ibusinputcontext.c
src/ibusxml.c

index 0e5241a..f83f1e8 100644 (file)
@@ -248,23 +248,25 @@ ibus_connection_destroy (IBusConnection *connection)
                     connection);
     }
 
-    if (!priv->shared && priv->connection) {
-        dbus_connection_close (priv->connection);
-        dbus_connection_unref (priv->connection);
-        priv->connection = NULL;
-        goto _out;
-    }
+    do {
+        if (!priv->shared && priv->connection) {
+            dbus_connection_close (priv->connection);
+            dbus_connection_unref (priv->connection);
+            priv->connection = NULL;
+            break;
+        }
 
-    if (priv->shared && priv->connection) {
-        g_warn_if_fail (_connections != NULL);
-        if (_connections != NULL) {
-            g_hash_table_remove (_connections, priv->connection);
+        if (priv->shared && priv->connection) {
+            g_warn_if_fail (_connections != NULL);
+            if (_connections != NULL) {
+                g_hash_table_remove (_connections, priv->connection);
+            }
+            dbus_connection_unref (priv->connection);
+            priv->connection = NULL;
+            break;
         }
-        dbus_connection_unref (priv->connection);
-        priv->connection = NULL;
-        goto _out;
-    }
-_out:
+    } while (0);
+
     parent_class->destroy (IBUS_OBJECT (connection));
 }
 
index 9ef73bf..8ebfdaa 100644 (file)
@@ -649,6 +649,7 @@ ibus_engine_ibus_message (IBusEngine     *engine,
     g_assert (IBUS_IS_ENGINE (engine));
     g_assert (IBUS_IS_CONNECTION (connection));
     g_assert (message != NULL);
+    g_assert (ibus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_CALL);
 
     IBusEnginePrivate *priv;
     priv = IBUS_ENGINE_GET_PRIVATE (engine);
@@ -680,9 +681,6 @@ ibus_engine_ibus_message (IBusEngine     *engine,
     interface = ibus_message_get_interface (message);
     name = ibus_message_get_member (message);
 
-    if (ibus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
-        return parent_class->ibus_message ((IBusService *) engine, connection, message);
-
     if (interface != NULL && g_strcmp0 (interface, IBUS_INTERFACE_ENGINE) != 0)
         return parent_class->ibus_message ((IBusService *) engine, connection, message);
 
@@ -699,7 +697,7 @@ ibus_engine_ibus_message (IBusEngine     *engine,
                                         G_TYPE_INVALID);
 
         if (!retval)
-            goto _keypress2_fail;
+            goto _keypress_fail;
 
         retval = FALSE;
         g_signal_emit (engine,
@@ -718,11 +716,11 @@ ibus_engine_ibus_message (IBusEngine     *engine,
         ibus_message_unref (return_message);
         return TRUE;
 
-    _keypress2_fail:
+    _keypress_fail:
         error_message = ibus_message_new_error_printf (message,
                         DBUS_ERROR_INVALID_ARGS,
-                        "%s.%s: Can not match signature (ubu) of method",
-                        IBUS_INTERFACE_ENGINE, "ProcessKeyEvent2");
+                        "%s.%s: Can not match signature (uuu) of method",
+                        IBUS_INTERFACE_ENGINE, "ProcessKeyEvent");
         ibus_connection_send (connection, error_message);
         ibus_message_unref (error_message);
         return TRUE;
index 2e3acf7..1bcc4b6 100644 (file)
@@ -492,6 +492,7 @@ ibus_input_context_ibus_signal (IBusProxy           *proxy,
 {
     g_assert (IBUS_IS_INPUT_CONTEXT (proxy));
     g_assert (message != NULL);
+    g_assert (ibus_message_get_type (message) == DBUS_MESSAGE_TYPE_SIGNAL);
 
     IBusInputContext *context;
     IBusError *error = NULL;
@@ -519,192 +520,191 @@ ibus_input_context_ibus_signal (IBusProxy           *proxy,
         { "CursorDownLookupTable",  CURSOR_DOWN_LOOKUP_TABLE },
     };
 
-    interface = ibus_message_get_interface (message);
-    name = ibus_message_get_member (message);
+    do {
+        interface = ibus_message_get_interface (message);
+        name = ibus_message_get_member (message);
 
-    if (ibus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL)
-        goto failed;
-
-    if (interface != NULL && g_strcmp0 (interface, IBUS_INTERFACE_INPUT_CONTEXT) != 0)
-        goto failed;
-
-    if (g_strcmp0 (name, "CommitText") == 0) {
-        IBusText *text;
-        gboolean retval;
+        if (interface != NULL && g_strcmp0 (interface, IBUS_INTERFACE_INPUT_CONTEXT) != 0) {
+            error = ibus_error_new_from_printf (DBUS_ERROR_FAILED,
+                                                "%s.%s is not implemented", interface, name);
+            break;
+        }
 
-        retval = ibus_message_get_args (message,
-                                        &error,
-                                        IBUS_TYPE_TEXT, &text,
-                                        G_TYPE_INVALID);
-        if (!retval)
-            goto failed;
+        if (g_strcmp0 (name, "CommitText") == 0) {
+            IBusText *text;
+            gboolean retval;
+
+            retval = ibus_message_get_args (message,
+                                            &error,
+                                            IBUS_TYPE_TEXT, &text,
+                                            G_TYPE_INVALID);
+            if (retval) {
+                g_signal_emit (context, context_signals[COMMIT_TEXT], 0, text);
+                g_object_unref (text);
+            }
+            break;
+        }
+        if (g_strcmp0 (name, "UpdatePreeditText") == 0) {
+            IBusText *text;
+            gint32 cursor_pos;
+            gboolean visible;
+            gboolean retval;
+
+            retval = ibus_message_get_args (message,
+                                            &error,
+                                            IBUS_TYPE_TEXT, &text,
+                                            G_TYPE_UINT, &cursor_pos,
+                                            G_TYPE_BOOLEAN, &visible,
+                                            G_TYPE_INVALID);
+
+            if (retval) {
+                g_signal_emit (context,
+                               context_signals[UPDATE_PREEDIT_TEXT],
+                               0,
+                               text,
+                               cursor_pos,
+                               visible);
+                g_object_unref (text);
+            }
+            break;
+        }
 
-        g_signal_emit (context, context_signals[COMMIT_TEXT], 0, text);
-        g_object_unref (text);
-        goto handled;
-    }
-    else if (g_strcmp0 (name, "UpdatePreeditText") == 0) {
-        IBusText *text;
-        gint32 cursor_pos;
-        gboolean visible;
-        gboolean retval;
-
-        retval = ibus_message_get_args (message,
-                                        &error,
-                                        IBUS_TYPE_TEXT, &text,
-                                        G_TYPE_UINT, &cursor_pos,
-                                        G_TYPE_BOOLEAN, &visible,
-                                        G_TYPE_INVALID);
-
-        if (!retval)
-            goto failed;
-
-        g_signal_emit (context,
-                       context_signals[UPDATE_PREEDIT_TEXT],
-                       0,
-                       text,
-                       cursor_pos,
-                       visible);
-        g_object_unref (text);
-        goto handled;
-    }
+        for (i = 0; i < G_N_ELEMENTS (signals); i++) {
+            if (g_strcmp0 (name, signals[i].member) == 0) {
+                g_signal_emit (context, context_signals[signals[i].signal_id], 0);
+                break;
+            }
+        }
 
-    for (i = 0; i < G_N_ELEMENTS (signals); i++) {
-        if (g_strcmp0 (name, signals[i].member) == 0) {
-            g_signal_emit (context, context_signals[signals[i].signal_id], 0);
-            goto handled;
+        if (i >= G_N_ELEMENTS (signals))
+            break;
+        if (g_strcmp0 (name, "UpdateAuxiliaryText") == 0) {
+            IBusText *text;
+            gboolean visible;
+            gboolean retval;
+
+            retval = ibus_message_get_args (message,
+                                            &error,
+                                            IBUS_TYPE_TEXT, &text,
+                                            G_TYPE_BOOLEAN, &visible,
+                                            G_TYPE_INVALID);
+
+            if (retval) {
+                g_signal_emit (context,
+                               context_signals[UPDATE_AUXILIARY_TEXT],
+                               0,
+                               text,
+                               visible);
+                g_object_unref (text);
+            }
         }
-    }
+        else if (g_strcmp0 (name, "UpdateLookupTable") == 0) {
+            IBusLookupTable *table;
+            gboolean visible;
+            gboolean retval;
+
+            retval = ibus_message_get_args (message,
+                                            &error,
+                                            IBUS_TYPE_LOOKUP_TABLE, &table,
+                                            G_TYPE_BOOLEAN, &visible,
+                                            G_TYPE_INVALID);
+
+            if (retval) {
+                g_signal_emit (context,
+                               context_signals[UPDATE_LOOKUP_TABLE],
+                               0,
+                               table,
+                               visible);
+                g_object_unref (table);
+            }
+        }
+        else if (g_strcmp0 (name, "RegisterProperties") == 0) {
+            IBusPropList *prop_list;
+            gboolean retval;
+
+            retval = ibus_message_get_args (message,
+                                            &error,
+                                            IBUS_TYPE_PROP_LIST, &prop_list,
+                                            G_TYPE_INVALID);
+
+            if (retval) {
+                g_signal_emit (context,
+                               context_signals[REGISTER_PROPERTIES],
+                               0,
+                               prop_list);
+                g_object_unref (prop_list);
+            }
+        }
+        else if (g_strcmp0 (name, "UpdateProperty") == 0) {
+            IBusProperty *prop;
+            gboolean retval;
+
+            retval = ibus_message_get_args (message,
+                                            &error,
+                                            IBUS_TYPE_PROPERTY, &prop,
+                                            G_TYPE_INVALID);
+            if (retval) {
+                g_signal_emit (context, context_signals[UPDATE_PROPERTY], 0, prop);
+                g_object_unref (prop);
+            }
+        }
+        else if (g_strcmp0 (name, "ForwardKeyEvent") == 0) {
+            guint32 keyval;
+            guint32 keycode;
+            guint32 state;
+            gboolean retval;
+
+
+            retval = ibus_message_get_args (message,
+                                            &error,
+                                            G_TYPE_UINT, &keyval,
+                                            G_TYPE_UINT, &keycode,
+                                            G_TYPE_UINT, &state,
+                                            G_TYPE_INVALID);
+
+            if (retval) {
+                g_signal_emit (context,
+                               context_signals[FORWARD_KEY_EVENT],
+                               0,
+                               keyval,
+                               keycode,
+                               state | IBUS_FORWARD_MASK);
+            }
+        }
+        else if (g_strcmp0 (name, "DeleteSurroundingText") == 0) {
+            gint offset_from_cursor;
+            guint nchars;
+            gboolean retval;
+            retval = ibus_message_get_args (message,
+                                            &error,
+                                            G_TYPE_INT, &offset_from_cursor,
+                                            G_TYPE_UINT, &nchars,
+                                            G_TYPE_INVALID);
+
+
+            if (retval) {
+                g_signal_emit (context,
+                               context_signals[DELETE_SURROUNDING_TEXT],
+                               0,
+                               offset_from_cursor,
+                               nchars);
+            }
+        }
+        else {
+            error = ibus_error_new_from_printf (DBUS_ERROR_FAILED,
+                                                "%s.%s is not implemented", interface, name);
+            break;
+        }
+    } while (0);
 
-    if (g_strcmp0 (name, "UpdateAuxiliaryText") == 0) {
-        IBusText *text;
-        gboolean visible;
-        gboolean retval;
-
-        retval = ibus_message_get_args (message,
-                                        &error,
-                                        IBUS_TYPE_TEXT, &text,
-                                        G_TYPE_BOOLEAN, &visible,
-                                        G_TYPE_INVALID);
-
-        if (!retval)
-            goto failed;
-
-        g_signal_emit (context,
-                       context_signals[UPDATE_AUXILIARY_TEXT],
-                       0,
-                       text,
-                       visible);
-        g_object_unref (text);
-    }
-    else if (g_strcmp0 (name, "UpdateLookupTable") == 0) {
-        IBusLookupTable *table;
-        gboolean visible;
-        gboolean retval;
-
-        retval = ibus_message_get_args (message,
-                                        &error,
-                                        IBUS_TYPE_LOOKUP_TABLE, &table,
-                                        G_TYPE_BOOLEAN, &visible,
-                                        G_TYPE_INVALID);
-
-        if (!retval)
-            goto failed;
-
-        g_signal_emit (context,
-                       context_signals[UPDATE_LOOKUP_TABLE],
-                       0,
-                       table,
-                       visible);
-        g_object_unref (table);
-    }
-    else if (g_strcmp0 (name, "RegisterProperties") == 0) {
-        IBusPropList *prop_list;
-        gboolean retval;
-
-        retval = ibus_message_get_args (message,
-                                        &error,
-                                        IBUS_TYPE_PROP_LIST, &prop_list,
-                                        G_TYPE_INVALID);
-
-        if (!retval)
-            goto failed;
-
-        g_signal_emit (context,
-                       context_signals[REGISTER_PROPERTIES],
-                       0,
-                       prop_list);
-        g_object_unref (prop_list);
-    }
-    else if (g_strcmp0 (name, "UpdateProperty") == 0) {
-        IBusProperty *prop;
-        gboolean retval;
-
-        retval = ibus_message_get_args (message,
-                                        &error,
-                                        IBUS_TYPE_PROPERTY, &prop,
-                                        G_TYPE_INVALID);
-        if (!retval)
-            goto failed;
-
-        g_signal_emit (context, context_signals[UPDATE_PROPERTY], 0, prop);
-        g_object_unref (prop);
-    }
-    else if (g_strcmp0 (name, "ForwardKeyEvent") == 0) {
-        guint32 keyval;
-        guint32 keycode;
-        guint32 state;
-        gboolean retval;
-
-
-        retval = ibus_message_get_args (message,
-                                        &error,
-                                        G_TYPE_UINT, &keyval,
-                                        G_TYPE_UINT, &keycode,
-                                        G_TYPE_UINT, &state,
-                                        G_TYPE_INVALID);
-
-        if (!retval)
-            goto failed;
-        g_signal_emit (context,
-                       context_signals[FORWARD_KEY_EVENT],
-                       0,
-                       keyval,
-                       keycode,
-                       state | IBUS_FORWARD_MASK);
-    }
-    else if (g_strcmp0 (name, "DeleteSurroundingText") == 0) {
-        gint offset_from_cursor;
-        guint nchars;
-        gboolean retval;
-        retval = ibus_message_get_args (message,
-                                        &error,
-                                        G_TYPE_INT, &offset_from_cursor,
-                                        G_TYPE_UINT, &nchars,
-                                        G_TYPE_INVALID);
-
-
-        if (!retval)
-            goto failed;
-        g_signal_emit (context,
-                       context_signals[DELETE_SURROUNDING_TEXT],
-                       0,
-                       offset_from_cursor,
-                       nchars);
-    }
-    else {
-        return FALSE;
+    if (error == NULL) {
+        g_signal_stop_emission_by_name (context, "ibus-signal");
+        return TRUE;
     }
 
-handled:
-    g_signal_stop_emission_by_name (context, "ibus-signal");
-    return TRUE;
-
-failed:
-    if (error) {
-        g_warning ("%s: %s", error->name, error->message);
-        ibus_error_free (error);
-    }
+    /* some error happens */
+    g_warning ("%s: %s", error->name, error->message);
+    ibus_error_free (error);
     return FALSE;
 }
 
index 16bd83a..aefa8d4 100644 (file)
@@ -194,30 +194,33 @@ ibus_xml_parse_file (const gchar *filename)
         0,
     };
 
-    context = g_markup_parse_context_new (&root_parser, 0, &node, 0);
+    do {
+        context = g_markup_parse_context_new (&root_parser, 0, &node, 0);
 
-    while (!feof (pf)) {
-        gchar buf[1024];
-        gssize len = 0;
+        while (!feof (pf)) {
+            gchar buf[1024];
+            gssize len = 0;
 
-        len = fread (buf, 1, sizeof (buf), pf);
-        retval = g_markup_parse_context_parse (context, buf, len, &error);
+            len = fread (buf, 1, sizeof (buf), pf);
+            retval = g_markup_parse_context_parse (context, buf, len, &error);
 
-        if (!retval)
-            goto _failed_out;
-    }
+            if (!retval)
+                break;
+        }
+        fclose (pf);
 
-    fclose (pf);
+        if (!retval)
+            break;
 
-    retval = g_markup_parse_context_end_parse (context, &error);
-    if (!retval)
-        goto _failed_out;
+        retval = g_markup_parse_context_end_parse (context, &error);
+        if (!retval)
+            break;
 
-    g_markup_parse_context_free (context);
+        g_markup_parse_context_free (context);
 
-    return node;
+        return node;
+    } while (0);
 
-_failed_out:
     g_warning ("Parse %s failed: %s", filename, error->message);
     g_error_free (error);
     g_markup_parse_context_free (context);
@@ -243,25 +246,22 @@ ibus_xml_parse_buffer (const gchar *buffer)
 
     context = g_markup_parse_context_new (&root_parser, 0, &node, 0);
 
-    retval = g_markup_parse_context_parse (context, buffer, strlen (buffer), &error);
-
-    if (!retval)
-        goto _failed_out;
-
-    retval = g_markup_parse_context_end_parse (context, &error);
-    if (!retval)
-        goto _failed_out;
-
-    g_markup_parse_context_free (context);
+    do {
+        retval = g_markup_parse_context_parse (context, buffer, strlen (buffer), &error);
+        if (!retval)
+            break;
 
-    return node;
+        retval = g_markup_parse_context_end_parse (context, &error);
+        if (!retval)
+            break;
+        g_markup_parse_context_free (context);
+        return node;
+    } while (0);
 
-_failed_out:
     g_warning ("Parse buffer failed: %s", error->message);
     g_error_free (error);
     g_markup_parse_context_free (context);
     return NULL;
-
 }