mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 22:46:15 +01:00
girepository: Cleanup compiler.c formatting
This commit is contained in:
parent
5d997cad03
commit
3bd7635516
@ -1,7 +1,7 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
|
||||
/* GObject introspection: Typelib compiler
|
||||
*
|
||||
*
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
#include <locale.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <gio/gio.h>
|
||||
#include <girepository.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#include "girmodule-private.h"
|
||||
@ -51,8 +51,8 @@ gboolean verbose = FALSE;
|
||||
gboolean show_version = FALSE;
|
||||
|
||||
static gboolean
|
||||
write_out_typelib (gchar *prefix,
|
||||
GITypelib *typelib)
|
||||
write_out_typelib (gchar *prefix,
|
||||
GITypelib *typelib)
|
||||
{
|
||||
FILE *file;
|
||||
gsize written;
|
||||
@ -77,28 +77,33 @@ write_out_typelib (gchar *prefix,
|
||||
else
|
||||
{
|
||||
if (prefix)
|
||||
filename = g_strdup_printf ("%s-%s", prefix, output);
|
||||
{
|
||||
filename = g_strdup_printf ("%s-%s", prefix, output);
|
||||
}
|
||||
else
|
||||
filename = g_strdup (output);
|
||||
{
|
||||
filename = g_strdup (output);
|
||||
}
|
||||
file_obj = g_file_new_for_path (filename);
|
||||
tmp_filename = g_strdup_printf ("%s.tmp", filename);
|
||||
tmp_file_obj = g_file_new_for_path (tmp_filename);
|
||||
file = g_fopen (tmp_filename, "wb");
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
{
|
||||
g_fprintf (stderr, "failed to open '%s': %s\n",
|
||||
tmp_filename, g_strerror (errno));
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
written = fwrite (typelib->data, 1, typelib->len, file);
|
||||
if (written < typelib->len) {
|
||||
g_fprintf (stderr, "ERROR: Could not write the whole output: %s",
|
||||
strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
if (written < typelib->len)
|
||||
{
|
||||
g_fprintf (stderr, "ERROR: Could not write the whole output: %s",
|
||||
strerror (errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (output != NULL)
|
||||
fclose (file);
|
||||
@ -106,9 +111,9 @@ write_out_typelib (gchar *prefix,
|
||||
{
|
||||
if (!g_file_move (tmp_file_obj, file_obj, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error))
|
||||
{
|
||||
g_fprintf (stderr, "ERROR: failed to rename %s to %s: %s", tmp_filename, filename, error->message);
|
||||
g_fprintf (stderr, "ERROR: failed to rename %s to %s: %s", tmp_filename, filename, error->message);
|
||||
g_clear_error (&error);
|
||||
goto out;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
success = TRUE;
|
||||
@ -123,31 +128,30 @@ out:
|
||||
|
||||
GLogLevelFlags logged_levels;
|
||||
|
||||
static void log_handler (const gchar *log_domain,
|
||||
GLogLevelFlags log_level,
|
||||
const gchar *message,
|
||||
gpointer user_data)
|
||||
static void
|
||||
log_handler (const gchar *log_domain,
|
||||
GLogLevelFlags log_level,
|
||||
const gchar *message,
|
||||
gpointer user_data)
|
||||
{
|
||||
|
||||
if (log_level & logged_levels)
|
||||
g_log_default_handler (log_domain, log_level, message, user_data);
|
||||
}
|
||||
|
||||
static GOptionEntry options[] =
|
||||
{
|
||||
{ "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, "include directories in GIR search path", NULL },
|
||||
{ "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" },
|
||||
{ "module", 'm', 0, G_OPTION_ARG_STRING, &mname, "module to compile", "NAME" },
|
||||
{ "shared-library", 'l', 0, G_OPTION_ARG_FILENAME_ARRAY, &shlibs, "shared library", "FILE" },
|
||||
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "show debug messages", NULL },
|
||||
{ "verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, "show verbose messages", NULL },
|
||||
static GOptionEntry options[] = {
|
||||
{ "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, "include directories in GIR search path", NULL },
|
||||
{ "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" },
|
||||
{ "module", 'm', 0, G_OPTION_ARG_STRING, &mname, "module to compile", "NAME" },
|
||||
{ "shared-library", 'l', 0, G_OPTION_ARG_FILENAME_ARRAY, &shlibs, "shared library", "FILE" },
|
||||
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "show debug messages", NULL },
|
||||
{ "verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, "show verbose messages", NULL },
|
||||
{ "version", 0, 0, G_OPTION_ARG_NONE, &show_version, "show program's version number and exit", NULL },
|
||||
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL },
|
||||
G_OPTION_ENTRY_NULL
|
||||
};
|
||||
|
||||
int
|
||||
main (int argc, char ** argv)
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
GOptionContext *context;
|
||||
GError *error = NULL;
|
||||
@ -170,7 +174,7 @@ main (int argc, char ** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
logged_levels = G_LOG_LEVEL_MASK & ~(G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_DEBUG);
|
||||
logged_levels = G_LOG_LEVEL_MASK & ~(G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_DEBUG);
|
||||
if (debug)
|
||||
logged_levels = logged_levels | G_LOG_LEVEL_DEBUG;
|
||||
if (verbose)
|
||||
@ -186,26 +190,26 @@ main (int argc, char ** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!input)
|
||||
{
|
||||
g_fprintf (stderr, "no input files\n");
|
||||
if (!input)
|
||||
{
|
||||
g_fprintf (stderr, "no input files\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_debug ("[parsing] start, %d includes",
|
||||
includedirs ? g_strv_length (includedirs) : 0);
|
||||
g_debug ("[parsing] start, %d includes",
|
||||
includedirs ? g_strv_length (includedirs) : 0);
|
||||
|
||||
parser = gi_ir_parser_new ();
|
||||
|
||||
gi_ir_parser_set_includes (parser, (const char*const*) includedirs);
|
||||
gi_ir_parser_set_includes (parser, (const char *const *) includedirs);
|
||||
|
||||
module = gi_ir_parser_parse_file (parser, input[0], &error);
|
||||
if (module == NULL)
|
||||
if (module == NULL)
|
||||
{
|
||||
g_fprintf (stderr, "error parsing file %s: %s\n",
|
||||
input[0], error->message);
|
||||
|
||||
g_fprintf (stderr, "error parsing file %s: %s\n",
|
||||
input[0], error->message);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -214,36 +218,36 @@ main (int argc, char ** argv)
|
||||
g_debug ("[building] start");
|
||||
|
||||
{
|
||||
GITypelib *typelib;
|
||||
GITypelib *typelib;
|
||||
|
||||
if (shlibs)
|
||||
{
|
||||
if (module->shared_library)
|
||||
g_free (module->shared_library);
|
||||
module->shared_library = g_strjoinv (",", shlibs);
|
||||
}
|
||||
if (shlibs)
|
||||
{
|
||||
if (module->shared_library)
|
||||
g_free (module->shared_library);
|
||||
module->shared_library = g_strjoinv (",", shlibs);
|
||||
}
|
||||
|
||||
g_debug ("[building] module %s", module->name);
|
||||
g_debug ("[building] module %s", module->name);
|
||||
|
||||
typelib = gi_ir_module_build_typelib (module);
|
||||
if (typelib == NULL)
|
||||
g_error ("Failed to build typelib for module '%s'\n", module->name);
|
||||
if (!gi_typelib_validate (typelib, &error))
|
||||
g_error ("Invalid typelib for module '%s': %s",
|
||||
module->name, error->message);
|
||||
typelib = gi_ir_module_build_typelib (module);
|
||||
if (typelib == NULL)
|
||||
g_error ("Failed to build typelib for module '%s'\n", module->name);
|
||||
if (!gi_typelib_validate (typelib, &error))
|
||||
g_error ("Invalid typelib for module '%s': %s",
|
||||
module->name, error->message);
|
||||
|
||||
if (!write_out_typelib (NULL, typelib))
|
||||
return 1;
|
||||
gi_typelib_free (typelib);
|
||||
typelib = NULL;
|
||||
}
|
||||
if (!write_out_typelib (NULL, typelib))
|
||||
return 1;
|
||||
gi_typelib_free (typelib);
|
||||
typelib = NULL;
|
||||
}
|
||||
|
||||
g_debug ("[building] done");
|
||||
|
||||
#if 0
|
||||
/* No point */
|
||||
gi_ir_parser_free (parser);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user