LCOV - code coverage report
Current view: top level - glib/girepository/inspector - inspector.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 63 0.0 %
Date: 2024-05-07 05:15:23 Functions: 0 3 0.0 %
Branches: 0 26 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* GObject introspection: typelib inspector
       2                 :            :  *
       3                 :            :  * Copyright (C) 2011-2016 Dominique Leuenberger <dimstar@opensuse.org>
       4                 :            :  * Copyright © 2016 Igor Gnatenko <ignatenko@redhat.com>
       5                 :            :  *
       6                 :            :  * SPDX-License-Identifier: LGPL-2.1-or-later
       7                 :            :  *
       8                 :            :  * This library is free software; you can redistribute it and/or
       9                 :            :  * modify it under the terms of the GNU Lesser General Public
      10                 :            :  * License as published by the Free Software Foundation; either
      11                 :            :  * version 2 of the License, or (at your option) any later version.
      12                 :            :  *
      13                 :            :  * This library is distributed in the hope that it will be useful,
      14                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16                 :            :  * Lesser General Public License for more details.
      17                 :            :  *
      18                 :            :  * You should have received a copy of the GNU Lesser General Public
      19                 :            :  * License along with this library; if not, write to the
      20                 :            :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      21                 :            :  * Boston, MA 02111-1307, USA.
      22                 :            :  */
      23                 :            : 
      24                 :            : #include <glib.h>
      25                 :            : #include <glib/gi18n.h>
      26                 :            : #include <girepository.h>
      27                 :            : #include <stdlib.h>
      28                 :            : #include <locale.h>
      29                 :            : 
      30                 :            : static void
      31                 :          0 : print_shlibs (GIRepository *repository,
      32                 :            :               const gchar  *namespace)
      33                 :            : {
      34                 :            :   /* Finding the shared library we depend on (if any) */
      35                 :          0 :   const char * const *shlibs = gi_repository_get_shared_libraries (repository, namespace, NULL);
      36   [ #  #  #  # ]:          0 :   for (size_t i = 0; shlibs != NULL && shlibs[i] != NULL; i++)
      37                 :          0 :     g_print ("shlib: %s\n", shlibs[i]);
      38                 :          0 : }
      39                 :            : 
      40                 :            : static void
      41                 :          0 : print_typelibs (GIRepository *repository,
      42                 :            :                 const gchar  *namespace)
      43                 :            : {
      44                 :          0 :   guint i = 0;
      45                 :            : 
      46                 :            :   /* Finding all the typelib-based Requires */
      47                 :          0 :   GStrv deps = gi_repository_get_dependencies (repository, namespace, NULL);
      48         [ #  # ]:          0 :   if (deps)
      49                 :            :     {
      50         [ #  # ]:          0 :       for (i = 0; deps[i]; i++)
      51                 :          0 :         g_print ("typelib: %s\n", deps[i]);
      52                 :          0 :       g_strfreev (deps);
      53                 :            :     }
      54                 :          0 : }
      55                 :            : 
      56                 :            : gint
      57                 :          0 : main (gint   argc,
      58                 :            :       gchar *argv[])
      59                 :            : {
      60                 :          0 :   gint status = EXIT_SUCCESS;
      61                 :            : 
      62                 :          0 :   GError *error = NULL;
      63                 :          0 :   GIRepository *repository = NULL;
      64                 :          0 :   GITypelib *typelib = NULL;
      65                 :            : 
      66                 :          0 :   gchar *version = NULL;
      67                 :          0 :   gboolean opt_shlibs = FALSE;
      68                 :          0 :   gboolean opt_typelibs = FALSE;
      69                 :          0 :   GStrv namespaces = NULL;
      70                 :          0 :   const gchar *namespace = NULL;
      71                 :          0 :   const GOptionEntry options[] = {
      72                 :            :     { "typelib-version", 0, 0, G_OPTION_ARG_STRING, &version, N_("Typelib version to inspect"), N_("VERSION") },
      73                 :            :     { "print-shlibs", 0, 0, G_OPTION_ARG_NONE, &opt_shlibs, N_("List the shared libraries the typelib requires"), NULL },
      74                 :            :     { "print-typelibs", 0, 0, G_OPTION_ARG_NONE, &opt_typelibs, N_("List other typelibs the inspected typelib requires"), NULL },
      75                 :            :     { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &namespaces, N_("The typelib to inspect"), N_("NAMESPACE") },
      76                 :            :     G_OPTION_ENTRY_NULL
      77                 :            :   };
      78                 :          0 :   GOptionContext *context = NULL;
      79                 :            : 
      80                 :          0 :   setlocale (LC_ALL, "");
      81                 :            : 
      82                 :          0 :   context = g_option_context_new (_("- Inspect GI typelib"));
      83                 :          0 :   g_option_context_add_main_entries (context, options, NULL);
      84         [ #  # ]:          0 :   if (!g_option_context_parse (context, &argc, &argv, &error))
      85                 :            :     {
      86                 :          0 :       char *message = g_strdup_printf (_("Failed to parse command line options: %s"), error->message);
      87                 :          0 :       status = EXIT_FAILURE;
      88                 :          0 :       g_printerr ("%s\n", message);
      89                 :          0 :       g_free (message);
      90                 :          0 :       goto out;
      91                 :            :     }
      92                 :            : 
      93   [ #  #  #  # ]:          0 :   if (!namespaces || g_strv_length (namespaces) > 1)
      94                 :            :     {
      95                 :          0 :       status = EXIT_FAILURE;
      96                 :          0 :       g_printerr ("%s\n", _("Please specify exactly one namespace"));
      97                 :          0 :       goto out;
      98                 :            :     }
      99                 :            : 
     100                 :          0 :   namespace = namespaces[0];
     101                 :            : 
     102   [ #  #  #  # ]:          0 :   if (!opt_shlibs && !opt_typelibs)
     103                 :            :     {
     104                 :          0 :       status = EXIT_FAILURE;
     105                 :          0 :       g_printerr ("%s\n", _("Please specify --print-shlibs, --print-typelibs or both"));
     106                 :          0 :       goto out;
     107                 :            :     }
     108                 :            : 
     109                 :          0 :   repository = gi_repository_new ();
     110                 :          0 :   typelib = gi_repository_require (repository, namespace, version, 0, &error);
     111         [ #  # ]:          0 :   if (!typelib)
     112                 :            :     {
     113                 :          0 :       char *message = g_strdup_printf (_("Failed to load typelib: %s"), error->message);
     114                 :          0 :       status = EXIT_FAILURE;
     115                 :          0 :       g_printerr ("%s\n", message);
     116                 :          0 :       g_free (message);
     117                 :          0 :       goto out;
     118                 :            :     }
     119                 :            : 
     120         [ #  # ]:          0 :   if (opt_shlibs)
     121                 :          0 :     print_shlibs (repository, namespace);
     122         [ #  # ]:          0 :   if (opt_typelibs)
     123                 :          0 :     print_typelibs (repository, namespace);
     124                 :            : 
     125                 :          0 : out:
     126                 :          0 :   g_option_context_free (context);
     127         [ #  # ]:          0 :   if (error)
     128                 :          0 :     g_error_free (error);
     129                 :          0 :   g_clear_object (&repository);
     130                 :          0 :   g_strfreev (namespaces);
     131                 :          0 :   g_free (version);
     132                 :            : 
     133                 :          0 :   return status;
     134                 :            : }

Generated by: LCOV version 1.14