GVariant: add support for single precision floats
[platform/upstream/glib.git] / gio / gdbus-tool.c
index 10b6a08..f24dd71 100644 (file)
@@ -13,9 +13,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  * Author: David Zeuthen <davidz@redhat.com>
  */
 
 #include <gi18n.h>
 
+#ifdef G_OS_WIN32
+#include "glib/glib-private.h"
+#endif
+
 /* ---------------------------------------------------------------------------------------------------- */
 
 G_GNUC_UNUSED static void completion_debug (const gchar *format, ...);
@@ -221,7 +223,7 @@ print_paths (GDBusConnection *c,
     }
   g_variant_get (result, "(&s)", &xml_data);
 
-  //g_printerr ("xml=`%s'", xml_data);
+  //g_printerr ("xml='%s'", xml_data);
 
   error = NULL;
   node = g_dbus_node_info_new_for_xml (xml_data, &error);
@@ -233,7 +235,7 @@ print_paths (GDBusConnection *c,
       goto out;
     }
 
-  //g_printerr ("bar `%s'\n", path);
+  //g_printerr ("bar '%s'\n", path);
 
   if (node->interfaces != NULL)
     g_print ("%s \n", path);
@@ -242,7 +244,7 @@ print_paths (GDBusConnection *c,
     {
       gchar *s;
 
-      //g_printerr ("foo `%s'\n", node->nodes[n].path);
+      //g_printerr ("foo '%s'\n", node->nodes[n].path);
 
       if (g_strcmp0 (path, "/") == 0)
         s = g_strdup_printf ("/%s", node->nodes[n]->path);
@@ -460,7 +462,7 @@ call_helper_get_method_in_signature (GDBusConnection  *c,
   if (interface_info == NULL)
     {
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                   _("Warning: According to introspection data, interface `%s' does not exist\n"),
+                   _("Warning: According to introspection data, interface '%s' does not exist\n"),
                    interface_name);
       goto out;
     }
@@ -469,7 +471,7 @@ call_helper_get_method_in_signature (GDBusConnection  *c,
   if (method_info == NULL)
     {
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                   _("Warning: According to introspection data, method `%s' does not exist on interface `%s'\n"),
+                   _("Warning: According to introspection data, method '%s' does not exist on interface '%s'\n"),
                    method_name,
                    interface_name);
       goto out;
@@ -625,7 +627,13 @@ handle_emit (gint        *argc,
       g_printerr (_("Error: signal not specified.\n"));
       goto out;
     }
+
   s = strrchr (opt_emit_signal, '.');
+  if (s == NULL)
+    {
+      g_printerr (_("Error: signal must be the fully-qualified name.\n"));
+      goto out;
+    }
   signal_name = g_strdup (s + 1);
   interface_name = g_strndup (opt_emit_signal, s - opt_emit_signal);
 
@@ -661,18 +669,24 @@ handle_emit (gint        *argc,
                                &error);
       if (value == NULL)
         {
+          gchar *context;
+
+          context = g_variant_parse_error_print_context (error, (*argv)[n]);
           g_error_free (error);
           error = NULL;
           value = _g_variant_parse_me_harder (NULL, (*argv)[n], &error);
           if (value == NULL)
             {
+              /* Use the original non-"parse-me-harder" error */
               g_printerr (_("Error parsing parameter %d: %s\n"),
                           n,
-                          error->message);
+                          context);
               g_error_free (error);
+              g_free (context);
               g_variant_builder_clear (&builder);
               goto out;
             }
+          g_free (context);
         }
       g_variant_builder_add_value (&builder, value);
     }
@@ -906,7 +920,7 @@ handle_call (gint        *argc,
   s = strrchr (opt_call_method, '.');
   if (!request_completion && s == NULL)
     {
-      g_printerr (_("Error: Method name `%s' is invalid\n"), opt_call_method);
+      g_printerr (_("Error: Method name '%s' is invalid\n"), opt_call_method);
       goto out;
     }
   method_name = g_strdup (s + 1);
@@ -963,6 +977,9 @@ handle_call (gint        *argc,
                                &error);
       if (value == NULL)
         {
+          gchar *context;
+
+          context = g_variant_parse_error_print_context (error, (*argv)[n]);
           g_error_free (error);
           error = NULL;
           value = _g_variant_parse_me_harder (type, (*argv)[n], &error);
@@ -971,22 +988,24 @@ handle_call (gint        *argc,
               if (type != NULL)
                 {
                   s = g_variant_type_dup_string (type);
-                  g_printerr (_("Error parsing parameter %d of type `%s': %s\n"),
+                  g_printerr (_("Error parsing parameter %d of type '%s': %s\n"),
                               n,
                               s,
-                              error->message);
+                              context);
                   g_free (s);
                 }
               else
                 {
                   g_printerr (_("Error parsing parameter %d: %s\n"),
                               n,
-                              error->message);
+                              context);
                 }
               g_error_free (error);
               g_variant_builder_clear (&builder);
+              g_free (context);
               goto out;
             }
+          g_free (context);
         }
       g_variant_builder_add_value (&builder, value);
     }
@@ -1007,8 +1026,11 @@ handle_call (gint        *argc,
                                         &error);
   if (result == NULL)
     {
-      g_printerr (_("Error: %s\n"), error->message);
-      g_error_free (error);
+      if (error)
+        {
+          g_printerr (_("Error: %s\n"), error->message);
+          g_error_free (error);
+        }
       if (in_signature_types != NULL)
         {
           GString *s;
@@ -1020,7 +1042,7 @@ handle_call (gint        *argc,
                                    g_variant_type_peek_string (type),
                                    g_variant_type_get_string_length (type));
             }
-          g_printerr ("(According to introspection data, you need to pass `%s')\n", s->str);
+          g_printerr ("(According to introspection data, you need to pass '%s')\n", s->str);
           g_string_free (s, TRUE);
         }
       goto out;
@@ -1713,16 +1735,12 @@ handle_monitor (gint        *argc,
   gchar *s;
   GError *error;
   GDBusConnection *c;
-  GVariant *result;
-  GDBusNodeInfo *node;
   gboolean complete_names;
   gboolean complete_paths;
   GMainLoop *loop;
 
   ret = FALSE;
   c = NULL;
-  node = NULL;
-  result = NULL;
 
   modify_argv0_for_command (argc, argv, "monitor");
 
@@ -1865,10 +1883,6 @@ handle_monitor (gint        *argc,
   ret = TRUE;
 
  out:
-  if (node != NULL)
-    g_dbus_node_info_unref (node);
-  if (result != NULL)
-    g_variant_unref (result);
   if (c != NULL)
     g_object_unref (c);
   g_option_context_free (o);
@@ -1921,13 +1935,15 @@ main (gint argc, gchar *argv[])
   gboolean request_completion;
   gchar *completion_cur;
   gchar *completion_prev;
+#ifdef G_OS_WIN32
+  gchar *tmp;
+#endif
 
   setlocale (LC_ALL, "");
   textdomain (GETTEXT_PACKAGE);
 
 #ifdef G_OS_WIN32
-  extern gchar *_glib_get_locale_dir (void);
-  gchar *tmp = _glib_get_locale_dir ();
+  tmp = _glib_get_locale_dir ();
   bindtextdomain (GETTEXT_PACKAGE, tmp);
   g_free (tmp);
 #else
@@ -1942,8 +1958,6 @@ main (gint argc, gchar *argv[])
   completion_cur = NULL;
   completion_prev = NULL;
 
-  g_type_init ();
-
   if (argc < 2)
     {
       usage (&argc, &argv, FALSE);
@@ -2029,7 +2043,7 @@ main (gint argc, gchar *argv[])
       completion_debug ("completion_point=%d", completion_point);
       completion_debug ("----");
       completion_debug (" 0123456789012345678901234567890123456789012345678901234567890123456789");
-      completion_debug ("`%s'", completion_line);
+      completion_debug ("'%s'", completion_line);
       completion_debug (" %*s^",
                          completion_point, "");
       completion_debug ("----");
@@ -2063,8 +2077,8 @@ main (gint argc, gchar *argv[])
             }
         }
 #if 0
-      completion_debug (" cur=`%s'", completion_cur);
-      completion_debug ("prev=`%s'", completion_prev);
+      completion_debug (" cur='%s'", completion_cur);
+      completion_debug ("prev='%s'", completion_prev);
 #endif
 
       argc = completion_argc;
@@ -2084,7 +2098,7 @@ main (gint argc, gchar *argv[])
         }
       else
         {
-          g_printerr ("Unknown command `%s'\n", command);
+          g_printerr ("Unknown command '%s'\n", command);
           usage (&argc, &argv, FALSE);
           goto out;
         }