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

           Branch data     Line data    Source code
       1                 :            : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
       2                 :            :  * GObject introspection: IDL generator
       3                 :            :  *
       4                 :            :  * Copyright (C) 2005 Matthias Clasen
       5                 :            :  * Copyright (C) 2008,2009 Red Hat, Inc.
       6                 :            :  *
       7                 :            :  * SPDX-License-Identifier: LGPL-2.1-or-later
       8                 :            :  *
       9                 :            :  * This library is free software; you can redistribute it and/or
      10                 :            :  * modify it under the terms of the GNU Lesser General Public
      11                 :            :  * License as published by the Free Software Foundation; either
      12                 :            :  * version 2 of the License, or (at your option) any later version.
      13                 :            :  *
      14                 :            :  * This library is distributed in the hope that it will be useful,
      15                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17                 :            :  * Lesser General Public License for more details.
      18                 :            :  *
      19                 :            :  * You should have received a copy of the GNU Lesser General Public
      20                 :            :  * License along with this library; if not, write to the
      21                 :            :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      22                 :            :  * Boston, MA 02111-1307, USA.
      23                 :            :  */
      24                 :            : 
      25                 :            : #include <locale.h>
      26                 :            : 
      27                 :            : #include <glib.h>
      28                 :            : #include <glib/gi18n.h>
      29                 :            : #include <glib/gstdio.h>
      30                 :            : #include <gmodule.h>
      31                 :            : #include <girepository.h>
      32                 :            : 
      33                 :            : #include "girwriter-private.h"
      34                 :            : #include "gitypelib-internal.h"
      35                 :            : 
      36                 :            : int
      37                 :          0 : main (int argc, char *argv[])
      38                 :            : {
      39                 :          0 :   GIRepository *repository = NULL;
      40                 :            :   gchar *param;
      41                 :          0 :   gchar *output = NULL;
      42                 :          0 :   gchar **includedirs = NULL;
      43                 :          0 :   gboolean show_all = FALSE;
      44                 :          0 :   gchar **input = NULL;
      45                 :            :   GOptionContext *context;
      46                 :          0 :   GError *error = NULL;
      47                 :            :   gboolean needs_prefix;
      48                 :          0 :   gboolean show_version = FALSE;
      49                 :            :   gint i;
      50                 :          0 :   GOptionEntry options[] =
      51                 :            :     {
      52                 :            :       { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, N_("Output file"), N_("FILE") },
      53                 :            :       { "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, N_("Include directories in GIR search path"), N_("DIRECTORY") },
      54                 :            :       { "all", 0, 0, G_OPTION_ARG_NONE, &show_all, N_("Show all available information"), NULL, },
      55                 :            :       { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program’s version number and exit"), NULL },
      56                 :            :       { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL },
      57                 :            :       G_OPTION_ENTRY_NULL
      58                 :            :     };
      59                 :            : 
      60                 :          0 :   g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
      61                 :            : 
      62                 :          0 :   setlocale (LC_ALL, "");
      63                 :            : 
      64                 :            :   /* Translators: commandline placeholder */
      65                 :          0 :   param = g_strdup_printf ("%s…", _("FILE"));
      66                 :          0 :   context = g_option_context_new (param);
      67                 :          0 :   g_free (param);
      68                 :          0 :   g_option_context_add_main_entries (context, options, NULL);
      69         [ #  # ]:          0 :   if (!g_option_context_parse (context, &argc, &argv, &error))
      70                 :            :     {
      71                 :          0 :       char *message = g_strdup_printf (_("Failed to parse: %s"), error->message);
      72                 :          0 :       g_fprintf (stderr, "%s\n", message);
      73                 :          0 :       g_free (message);
      74                 :          0 :       g_error_free (error);
      75                 :          0 :       return 1;
      76                 :            :     }
      77                 :            : 
      78         [ #  # ]:          0 :   if (show_version)
      79                 :            :     {
      80                 :          0 :       g_printf ("gi-decompile-typelib %u.%u.%u\n",
      81                 :            :                 GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
      82                 :          0 :       return 0;
      83                 :            :     }
      84                 :            : 
      85         [ #  # ]:          0 :   if (!input)
      86                 :            :     {
      87                 :          0 :       g_fprintf (stderr, "%s\n", _("No input files"));
      88                 :            : 
      89                 :          0 :       return 1;
      90                 :            :     }
      91                 :            : 
      92                 :          0 :   repository = gi_repository_new ();
      93                 :            : 
      94         [ #  # ]:          0 :   if (includedirs != NULL)
      95                 :            :     {
      96                 :          0 :       guint n = g_strv_length (includedirs);
      97                 :            :       guint j;
      98                 :            : 
      99         [ #  # ]:          0 :       for (j = 1; j <= n; j++)
     100                 :          0 :         gi_repository_prepend_search_path (repository, includedirs[n - j]);
     101                 :            :     }
     102                 :            : 
     103         [ #  # ]:          0 :   for (i = 0; input[i]; i++)
     104                 :            :     {
     105                 :            :       const char *namespace;
     106                 :          0 :       GMappedFile *mfile = NULL;
     107                 :          0 :       GBytes *bytes = NULL;
     108                 :            :       GITypelib *typelib;
     109                 :            : 
     110                 :          0 :       error = NULL;
     111                 :          0 :       mfile = g_mapped_file_new (input[i], FALSE, &error);
     112         [ #  # ]:          0 :       if (!mfile)
     113                 :          0 :         g_error (_("Failed to read ‘%s’: %s"), input[i], error->message);
     114                 :            : 
     115                 :          0 :       bytes = g_mapped_file_get_bytes (mfile);
     116                 :          0 :       g_clear_pointer (&mfile, g_mapped_file_unref);
     117                 :            : 
     118   [ #  #  #  # ]:          0 :       if (input[i + 1] && output)
     119                 :          0 :         needs_prefix = TRUE;
     120                 :            :       else
     121                 :          0 :         needs_prefix = FALSE;
     122                 :            : 
     123                 :          0 :       typelib = gi_typelib_new_from_bytes (bytes, &error);
     124         [ #  # ]:          0 :       if (!typelib)
     125                 :          0 :         g_error (_("Failed to create typelib ‘%s’: %s"), input[i], error->message);
     126                 :            : 
     127                 :          0 :       namespace = gi_repository_load_typelib (repository, typelib, 0, &error);
     128         [ #  # ]:          0 :       if (namespace == NULL)
     129                 :          0 :         g_error (_("Failed to load typelib: %s"), error->message);
     130                 :            : 
     131                 :          0 :       gi_ir_writer_write (repository, output, namespace, needs_prefix, show_all);
     132                 :            : 
     133                 :            :       /* when writing to stdout, stop after the first module */
     134   [ #  #  #  # ]:          0 :       if (input[i + 1] && !output)
     135                 :            :         {
     136                 :          0 :           char *message = g_strdup_printf (_("Warning: %u modules omitted"), g_strv_length (input) - 1);
     137                 :          0 :           g_fprintf (stderr, "%s\n", message);
     138                 :          0 :           g_free (message);
     139                 :            : 
     140                 :          0 :           break;
     141                 :            :         }
     142                 :            :     }
     143                 :            : 
     144                 :          0 :   g_clear_object (&repository);
     145                 :            : 
     146                 :          0 :   return 0;
     147                 :            : }

Generated by: LCOV version 1.14