2012-02-03 19:42:56 +01:00
|
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
|
|
* GObject introspection: IDL generator
|
2005-05-09 16:24:46 +02:00
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2005 Matthias Clasen
|
2009-02-20 03:48:51 +01:00
|
|
|
|
* Copyright (C) 2008,2009 Red Hat, Inc.
|
2005-05-09 16:24:46 +02:00
|
|
|
|
*
|
2024-02-08 15:01:57 +01:00
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
*
|
2005-05-09 16:24:46 +02:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-01-11 06:35:34 +01:00
|
|
|
|
#include <locale.h>
|
|
|
|
|
|
2005-05-09 16:24:46 +02:00
|
|
|
|
#include <glib.h>
|
2024-02-26 13:43:30 +01:00
|
|
|
|
#include <glib/gi18n.h>
|
2005-05-09 16:24:46 +02:00
|
|
|
|
#include <glib/gstdio.h>
|
2010-06-07 15:52:43 +02:00
|
|
|
|
#include <gmodule.h>
|
2024-02-08 15:35:36 +01:00
|
|
|
|
#include <girepository.h>
|
2005-05-09 16:24:46 +02:00
|
|
|
|
|
2024-02-08 15:35:36 +01:00
|
|
|
|
#include "girwriter-private.h"
|
2010-05-31 22:44:46 +02:00
|
|
|
|
#include "gitypelib-internal.h"
|
2005-05-09 16:24:46 +02:00
|
|
|
|
|
2010-03-25 13:17:03 +01:00
|
|
|
|
int
|
2005-05-09 16:24:46 +02:00
|
|
|
|
main (int argc, char *argv[])
|
2010-03-25 13:17:03 +01:00
|
|
|
|
{
|
2024-02-08 15:35:36 +01:00
|
|
|
|
GIRepository *repository = NULL;
|
2024-02-28 12:25:07 +01:00
|
|
|
|
gchar *param;
|
2010-06-07 15:41:00 +02:00
|
|
|
|
gchar *output = NULL;
|
|
|
|
|
gchar **includedirs = NULL;
|
|
|
|
|
gboolean show_all = FALSE;
|
2008-03-11 15:25:08 +01:00
|
|
|
|
gchar **input = NULL;
|
2005-05-09 16:24:46 +02:00
|
|
|
|
GOptionContext *context;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
gboolean needs_prefix;
|
2018-12-16 13:42:27 +01:00
|
|
|
|
gboolean show_version = FALSE;
|
2005-05-09 16:24:46 +02:00
|
|
|
|
gint i;
|
2010-03-25 13:17:03 +01:00
|
|
|
|
GOptionEntry options[] =
|
2008-03-11 15:25:08 +01:00
|
|
|
|
{
|
2024-02-26 13:43:30 +01:00
|
|
|
|
{ "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, N_("Output file"), N_("FILE") },
|
2024-02-28 12:23:54 +01:00
|
|
|
|
{ "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, N_("Include directories in GIR search path"), N_("DIRECTORY") },
|
2024-02-26 13:43:30 +01:00
|
|
|
|
{ "all", 0, 0, G_OPTION_ARG_NONE, &show_all, N_("Show all available information"), NULL, },
|
|
|
|
|
{ "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program’s version number and exit"), NULL },
|
2008-03-11 15:25:08 +01:00
|
|
|
|
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL },
|
2024-02-08 15:35:36 +01:00
|
|
|
|
G_OPTION_ENTRY_NULL
|
2008-03-11 15:25:08 +01:00
|
|
|
|
};
|
2005-05-09 16:24:46 +02:00
|
|
|
|
|
2008-08-30 22:31:07 +02:00
|
|
|
|
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
|
|
|
|
|
|
2016-01-11 06:35:34 +01:00
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
|
2024-02-28 12:25:07 +01:00
|
|
|
|
/* Translators: commandline placeholder */
|
|
|
|
|
param = g_strdup_printf ("%s…", _("FILE"));
|
|
|
|
|
context = g_option_context_new (param);
|
|
|
|
|
g_free (param);
|
2005-05-09 16:24:46 +02:00
|
|
|
|
g_option_context_add_main_entries (context, options, NULL);
|
2018-07-29 15:40:31 +02:00
|
|
|
|
if (!g_option_context_parse (context, &argc, &argv, &error))
|
|
|
|
|
{
|
2024-02-26 13:43:30 +01:00
|
|
|
|
char *message = g_strdup_printf (_("Failed to parse: %s"), error->message);
|
|
|
|
|
g_fprintf (stderr, "%s\n", message);
|
|
|
|
|
g_free (message);
|
2018-07-29 15:40:31 +02:00
|
|
|
|
g_error_free (error);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2005-05-09 16:24:46 +02:00
|
|
|
|
|
2018-12-16 13:42:27 +01:00
|
|
|
|
if (show_version)
|
|
|
|
|
{
|
2024-02-08 15:35:36 +01:00
|
|
|
|
g_printf ("gi-decompile-typelib %u.%u.%u\n",
|
|
|
|
|
GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
|
2018-12-16 13:42:27 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-25 13:17:03 +01:00
|
|
|
|
if (!input)
|
|
|
|
|
{
|
2024-02-26 13:43:30 +01:00
|
|
|
|
g_fprintf (stderr, "%s\n", _("No input files"));
|
2010-03-25 13:17:03 +01:00
|
|
|
|
|
2005-05-09 16:24:46 +02:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-08 15:35:36 +01:00
|
|
|
|
repository = gi_repository_new ();
|
|
|
|
|
|
2008-08-30 22:31:07 +02:00
|
|
|
|
if (includedirs != NULL)
|
2024-02-14 12:25:46 +01:00
|
|
|
|
{
|
|
|
|
|
guint n = g_strv_length (includedirs);
|
|
|
|
|
guint j;
|
|
|
|
|
|
|
|
|
|
for (j = 1; j <= n; j++)
|
|
|
|
|
gi_repository_prepend_search_path (repository, includedirs[n - j]);
|
|
|
|
|
}
|
2008-08-30 22:31:07 +02:00
|
|
|
|
|
2005-05-09 16:24:46 +02:00
|
|
|
|
for (i = 0; input[i]; i++)
|
|
|
|
|
{
|
2008-08-30 22:31:07 +02:00
|
|
|
|
const char *namespace;
|
2024-02-08 15:35:36 +01:00
|
|
|
|
GMappedFile *mfile = NULL;
|
|
|
|
|
GBytes *bytes = NULL;
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *typelib;
|
2005-05-09 16:24:46 +02:00
|
|
|
|
|
2018-07-29 15:56:35 +02:00
|
|
|
|
error = NULL;
|
2010-07-14 17:59:11 +02:00
|
|
|
|
mfile = g_mapped_file_new (input[i], FALSE, &error);
|
|
|
|
|
if (!mfile)
|
2024-02-26 13:43:30 +01:00
|
|
|
|
g_error (_("Failed to read ‘%s’: %s"), input[i], error->message);
|
2005-05-09 16:24:46 +02:00
|
|
|
|
|
2024-02-08 15:35:36 +01:00
|
|
|
|
bytes = g_mapped_file_get_bytes (mfile);
|
|
|
|
|
g_clear_pointer (&mfile, g_mapped_file_unref);
|
|
|
|
|
|
2005-05-09 16:24:46 +02:00
|
|
|
|
if (input[i + 1] && output)
|
|
|
|
|
needs_prefix = TRUE;
|
|
|
|
|
else
|
|
|
|
|
needs_prefix = FALSE;
|
|
|
|
|
|
2024-02-08 15:35:36 +01:00
|
|
|
|
typelib = gi_typelib_new_from_bytes (bytes, &error);
|
2010-07-14 17:59:11 +02:00
|
|
|
|
if (!typelib)
|
2024-02-26 13:43:30 +01:00
|
|
|
|
g_error (_("Failed to create typelib ‘%s’: %s"), input[i], error->message);
|
2010-07-14 17:59:11 +02:00
|
|
|
|
|
2024-02-08 15:35:36 +01:00
|
|
|
|
namespace = gi_repository_load_typelib (repository, typelib, 0, &error);
|
2008-08-30 22:31:07 +02:00
|
|
|
|
if (namespace == NULL)
|
2024-02-26 13:43:30 +01:00
|
|
|
|
g_error (_("Failed to load typelib: %s"), error->message);
|
2024-02-08 15:35:36 +01:00
|
|
|
|
|
2024-02-13 17:58:25 +01:00
|
|
|
|
gi_ir_writer_write (repository, output, namespace, needs_prefix, show_all);
|
2005-05-09 16:24:46 +02:00
|
|
|
|
|
|
|
|
|
/* when writing to stdout, stop after the first module */
|
|
|
|
|
if (input[i + 1] && !output)
|
|
|
|
|
{
|
2024-02-26 13:43:30 +01:00
|
|
|
|
char *message = g_strdup_printf (_("Warning: %u modules omitted"), g_strv_length (input) - 1);
|
|
|
|
|
g_fprintf (stderr, "%s\n", message);
|
|
|
|
|
g_free (message);
|
2005-05-09 16:24:46 +02:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-25 13:17:03 +01:00
|
|
|
|
|
2024-02-08 15:35:36 +01:00
|
|
|
|
g_clear_object (&repository);
|
|
|
|
|
|
2005-05-09 16:24:46 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|