From 35761ae1ef0d83189d2f3916620d59dee6648c7a Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Fri, 29 Apr 2016 12:25:31 +0200 Subject: fixup! g-ir-inspect: Inspect GI typelibs Signed-off-by: Igor Gnatenko --- tools/g-ir-inspect.c | 104 ++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 47 deletions(-) diff --git a/tools/g-ir-inspect.c b/tools/g-ir-inspect.c index b635ca43..8f6694ba 100644 --- a/tools/g-ir-inspect.c +++ b/tools/g-ir-inspect.c @@ -28,24 +28,26 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GITypelib, g_typelib_free) static void print_shlibs (const gchar *namespace) { - /* Finding the shared library we depend on (if any) */ - const gchar *shlibs = g_irepository_get_shared_library (NULL, namespace); - if (shlibs && shlibs[0] != '\0') { - /* shlibs is a comma-separated list of libraries */ - g_auto(GStrv) libs = g_strsplit (shlibs, ",", -1); - for (guint i = 0; libs[i]; i++) - g_print ("shlib: %s\n", libs[i]); + /* Finding the shared library we depend on (if any) */ + const gchar *shlibs = g_irepository_get_shared_library (NULL, namespace); + if (shlibs && shlibs[0] != '\0') + { + /* shlibs is a comma-separated list of libraries */ + g_auto(GStrv) libs = g_strsplit (shlibs, ",", -1); + for (guint i = 0; libs[i]; i++) + g_print ("shlib: %s\n", libs[i]); } } static void print_typelibs (const gchar *namespace) { - /* Finding all the typelib-based Requires */ - g_auto(GStrv) deps = g_irepository_get_dependencies (NULL, namespace); - if (deps) { - for (guint i = 0; deps[i]; i++) - g_print ("typelib: %s\n", deps[i]); + /* Finding all the typelib-based Requires */ + g_auto(GStrv) deps = g_irepository_get_dependencies (NULL, namespace); + if (deps) + { + for (guint i = 0; deps[i]; i++) + g_print ("typelib: %s\n", deps[i]); } } @@ -53,50 +55,58 @@ gint main (gint argc, gchar *argv[]) { - g_autoptr(GError) error = NULL; - g_autoptr(GITypelib) typelib = NULL; + g_autoptr(GError) error = NULL; + g_autoptr(GITypelib) typelib = NULL; - g_autofree gchar *version = NULL; - gboolean opt_shlibs = FALSE; - gboolean opt_typelibs = FALSE; - g_auto(GStrv) namespaces = NULL; - const GOptionEntry options[] = { - { "version", 0, 0, G_OPTION_ARG_STRING, &version, "Version", "VERSION" }, - { "print-shlibs", 0, 0, G_OPTION_ARG_NONE, &opt_shlibs, "List the shared libraries the typelib requires" }, - { "print-typelibs", 0, 0, G_OPTION_ARG_NONE, &opt_typelibs, "List other typelibs the inspected typelib requires" }, - { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &namespaces, "The typelib to inspect", "NAMESPACE" }, - { NULL }, - }; + g_autofree gchar *version = NULL; + gboolean opt_shlibs = FALSE; + gboolean opt_typelibs = FALSE; + g_auto(GStrv) namespaces = NULL; + const GOptionEntry options[] = { + { "version", 0, 0, G_OPTION_ARG_STRING, &version, "Version", "VERSION" }, + { "print-shlibs", 0, 0, G_OPTION_ARG_NONE, &opt_shlibs, "List the shared libraries the typelib requires" }, + { "print-typelibs", 0, 0, G_OPTION_ARG_NONE, &opt_typelibs, "List other typelibs the inspected typelib requires" }, + { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &namespaces, "The typelib to inspect", "NAMESPACE" }, + { NULL }, + }; - g_autoptr(GOptionContext) context = g_option_context_new ("- Inspect GI typelib"); - g_option_context_add_main_entries (context, options, NULL); - if (!g_option_context_parse (context, &argc, &argv, &error)) { - g_printerr ("Failed to parse command line options: %s\n", error->message); - return EXIT_FAILURE; + g_autoptr(GOptionContext) context = g_option_context_new ("- Inspect GI typelib"); + g_option_context_add_main_entries (context, options, NULL); + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + g_printerr ("Failed to parse command line options: %s\n", error->message); + return EXIT_FAILURE; } - if (!namespaces) { - g_printerr ("Please specify at least one namespace\n"); - return EXIT_FAILURE; - } else if (g_strv_length (namespaces) > 1) { - g_printerr ("Please specify only one namespace\n"); - return EXIT_FAILURE; + if (!namespaces) + { + g_printerr ("Please specify at least one namespace\n"); + return EXIT_FAILURE; } - const gchar *namespace = namespaces[0]; + else if (g_strv_length (namespaces) > 1) + { + g_printerr ("Please specify only one namespace\n"); + return EXIT_FAILURE; + } + const gchar *namespace = namespaces[0]; - if (!opt_shlibs && !opt_typelibs) { - g_printerr ("Please specify --print-shlibs, --print-typelibs or both.\n"); - return EXIT_FAILURE; + if (!opt_shlibs && !opt_typelibs) + { + g_printerr ("Please specify --print-shlibs, --print-typelibs or both.\n"); + return EXIT_FAILURE; } - typelib = g_irepository_require (NULL, namespace, version, 0, &error); - if (!typelib) { - g_printerr ("Failed to load typelib: %s\n", error->message); - return EXIT_FAILURE; + typelib = g_irepository_require (NULL, namespace, version, 0, &error); + if (!typelib) + { + g_printerr ("Failed to load typelib: %s\n", error->message); + return EXIT_FAILURE; } - if (opt_shlibs) print_shlibs (namespace); - if (opt_typelibs) print_typelibs (namespace); + if (opt_shlibs) + print_shlibs (namespace); + if (opt_typelibs) + print_typelibs (namespace); - return EXIT_SUCCESS; + return EXIT_SUCCESS; } -- cgit v1.2.1