glib/girepository/tools/generate.c

111 lines
3.3 KiB
C
Raw Normal View History

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
* Copyright (C) 2008,2009 Red Hat, Inc.
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.
*/
#include <glib.h>
#include <glib/gstdio.h>
#include <gmodule.h>
2005-05-09 16:24:46 +02:00
#include "girwriter.h"
2005-05-09 16:24:46 +02:00
#include "girepository.h"
#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
{
gboolean shlib = FALSE;
gchar *output = NULL;
gchar **includedirs = NULL;
gboolean show_all = FALSE;
gchar **input = NULL;
2005-05-09 16:24:46 +02:00
GOptionContext *context;
GError *error = NULL;
gboolean needs_prefix;
gint i;
2010-03-25 13:17:03 +01:00
GOptionEntry options[] =
{
{ "shlib", 0, 0, G_OPTION_ARG_NONE, &shlib, "handle typelib embedded in shlib", NULL },
2010-03-25 13:17:03 +01:00
{ "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" },
{ "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, "include directories in GIR search path", NULL },
{ "all", 0, 0, G_OPTION_ARG_NONE, &show_all, "show all available information", NULL, },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL },
{ NULL, }
};
2005-05-09 16:24:46 +02:00
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
g_typelib_check_sanity ();
Revert revisions 157,149-148,136-129 and 120. Move back to using 2008-04-22 Johan Dahlin <johan@gnome.org> * girepository/ginfo.c (g_info_from_entry), (g_type_info_new), (g_type_info_is_pointer), (g_type_info_get_tag), (g_type_info_get_param_type), (g_type_info_get_interface), (g_type_info_get_array_length), (g_type_info_is_zero_terminated), (g_type_info_get_n_error_domains), (g_type_info_get_error_domain), (g_error_domain_info_get_codes), (g_enum_info_get_value), (g_object_info_get_interface), (g_object_info_get_field), (g_interface_info_get_prerequisite), (g_signal_info_get_class_closure), (g_constant_info_get_value): * girepository/ginvoke.c (get_ffi_type): * girepository/girepository.h: * girepository/gmetadata.c (g_metadata_get_dir_entry), (g_metadata_check_sanity), (validate_header), (validate_array_type_blob), (validate_iface_type_blob), (validate_param_type_blob), (validate_error_type_blob), (validate_type_blob), (validate_constant_blob), (validate_struct_blob), (validate_enum_blob): * girepository/gmetadata.h: * tests/Makefile.am: * tests/invoke/Makefile.am: * tests/invoke/invoke.c (main): * tests/roundtrips.sh: * tools/Makefile.am: * tools/compiler.c (format_output), (write_out_metadata), (main): * tools/generate.c (write_type_name), (write_type_info), (write_constant_value), (write_enum_info), (load_metadata), (main): * tools/gidlcompilercontext.c: * tools/gidlcompilercontext.h: * tools/gidlcompilerentrynode.c: * tools/gidlcompilerentrynode.h: * tools/gidlcompilertypenode.c: * tools/gidlcompilertypenode.h: * tools/gidlmodule.c (g_idl_module_build_metadata): * tools/gidlmodule.h: * tools/gidlnode.c (init_stats), (dump_stats), (g_idl_node_get_size), (g_idl_node_get_full_size), (g_idl_node_cmp), (g_idl_node_can_have_member), (g_idl_node_add_member), (g_idl_node_param_direction_string), (parse_int_value), (parse_uint_value), (parse_float_value), (parse_boolean_value), (find_entry_node), (find_entry), (serialize_type), (g_idl_node_build_metadata), (write_string): * tools/gidlnode.h: * tools/gidlparser.c (parse_type_internal): * tools/quote-file.sh: Revert revisions 157,149-148,136-129 and 120. Move back to using g-idl-generate to generate the metadata and avoids dependency on a c compiler. svn path=/trunk/; revision=214
2008-04-23 00:48:16 +02:00
2005-05-09 16:24:46 +02:00
context = g_option_context_new ("");
g_option_context_add_main_entries (context, options, NULL);
g_option_context_parse (context, &argc, &argv, &error);
2010-03-25 13:17:03 +01:00
if (!input)
{
g_fprintf (stderr, "no input files\n");
2005-05-09 16:24:46 +02:00
return 1;
}
if (includedirs != NULL)
for (i = 0; includedirs[i]; i++)
g_irepository_prepend_search_path (includedirs[i]);
2005-05-09 16:24:46 +02:00
for (i = 0; input[i]; i++)
{
GError *error = NULL;
const char *namespace;
GMappedFile *mfile;
GITypelib *typelib;
2005-05-09 16:24:46 +02:00
mfile = g_mapped_file_new (input[i], FALSE, &error);
if (!mfile)
g_error ("failed to read '%s': %s", input[i], error->message);
2005-05-09 16:24:46 +02:00
if (input[i + 1] && output)
needs_prefix = TRUE;
else
needs_prefix = FALSE;
typelib = g_typelib_new_from_mapped_file (mfile, &error);
if (!typelib)
g_error ("failed to create typelib '%s': %s", input[i], error->message);
namespace = g_irepository_load_typelib (g_irepository_get_default (), typelib, 0,
&error);
if (namespace == NULL)
g_error ("failed to load typelib: %s", error->message);
gir_writer_write (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)
{
g_fprintf (stderr, "warning, %d modules omitted\n",
g_strv_length (input) - 1);
break;
}
}
2010-03-25 13:17:03 +01:00
2005-05-09 16:24:46 +02:00
return 0;
}