2015-04-19 01:03:52 +00:00
|
|
|
/* Copyright 2015 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* GTK+ 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.
|
|
|
|
*
|
|
|
|
* GLib 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 GTK+; see the file COPYING. If not,
|
|
|
|
* see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Matthias Clasen
|
|
|
|
*/
|
|
|
|
|
2022-04-17 04:26:25 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2015-04-19 01:03:52 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-11-13 03:29:02 +00:00
|
|
|
#include <errno.h>
|
2015-04-27 22:39:22 +00:00
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
2016-04-15 17:37:49 +00:00
|
|
|
#include <glib/gprintf.h>
|
2016-11-13 03:29:02 +00:00
|
|
|
#include <glib/gstdio.h>
|
2015-04-19 01:03:52 +00:00
|
|
|
#include <gtk/gtk.h>
|
2015-04-30 05:18:48 +00:00
|
|
|
#include "gtkbuilderprivate.h"
|
2020-05-18 10:04:15 +00:00
|
|
|
#include "gtk-builder-tool.h"
|
2015-04-19 01:03:52 +00:00
|
|
|
|
2020-05-18 10:04:15 +00:00
|
|
|
static void G_GNUC_NORETURN
|
2015-04-27 22:25:09 +00:00
|
|
|
usage (void)
|
|
|
|
{
|
2015-04-28 03:31:03 +00:00
|
|
|
g_print (_("Usage:\n"
|
2019-04-17 01:13:16 +00:00
|
|
|
" gtk-builder-tool [COMMAND] [OPTION…] FILE\n"
|
2015-04-28 03:31:03 +00:00
|
|
|
"\n"
|
2022-04-17 15:59:06 +00:00
|
|
|
"Perform various tasks on GtkBuilder .ui files.\n"
|
|
|
|
"\n"
|
2015-04-28 03:31:03 +00:00
|
|
|
"Commands:\n"
|
2019-04-17 01:13:16 +00:00
|
|
|
" validate Validate the file\n"
|
|
|
|
" simplify Simplify the file\n"
|
|
|
|
" enumerate List all named objects\n"
|
|
|
|
" preview Preview the file\n"
|
2022-04-17 04:26:25 +00:00
|
|
|
" screenshot Take a screenshot of the file\n"
|
2022-04-17 15:59:06 +00:00
|
|
|
"\n"));
|
2015-04-27 22:25:09 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2020-11-23 12:02:21 +00:00
|
|
|
/* A simplified version of g_log_writer_default_would_drop(), to avoid
|
|
|
|
* bumping up the required version of GLib to 2.68
|
|
|
|
*/
|
2020-11-01 20:48:37 +00:00
|
|
|
static gboolean
|
2020-11-23 12:02:21 +00:00
|
|
|
would_drop (GLogLevelFlags level,
|
|
|
|
const char *domain)
|
2020-11-01 20:48:37 +00:00
|
|
|
{
|
|
|
|
return (level & (G_LOG_LEVEL_ERROR |
|
|
|
|
G_LOG_LEVEL_CRITICAL |
|
|
|
|
G_LOG_LEVEL_WARNING)) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GLogWriterOutput
|
|
|
|
log_writer_func (GLogLevelFlags level,
|
|
|
|
const GLogField *fields,
|
|
|
|
gsize n_fields,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gsize i;
|
|
|
|
const char *domain = NULL;
|
|
|
|
const char *message = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < n_fields; i++)
|
|
|
|
{
|
|
|
|
if (g_strcmp0 (fields[i].key, "GLIB_DOMAIN") == 0)
|
|
|
|
domain = fields[i].value;
|
|
|
|
else if (g_strcmp0 (fields[i].key, "MESSAGE") == 0)
|
|
|
|
message = fields[i].value;
|
|
|
|
}
|
|
|
|
|
2020-11-23 12:02:21 +00:00
|
|
|
if (message != NULL && !would_drop (level, domain))
|
2020-11-01 20:48:37 +00:00
|
|
|
{
|
|
|
|
const char *prefix;
|
|
|
|
switch (level & G_LOG_LEVEL_MASK)
|
|
|
|
{
|
|
|
|
case G_LOG_LEVEL_ERROR:
|
|
|
|
prefix = "ERROR";
|
|
|
|
break;
|
|
|
|
case G_LOG_LEVEL_CRITICAL:
|
|
|
|
prefix = "CRITICAL";
|
|
|
|
break;
|
|
|
|
case G_LOG_LEVEL_WARNING:
|
|
|
|
prefix = "WARNING";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
prefix = "INFO";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_printerr ("%s-%s: %s\n", domain, prefix, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return G_LOG_WRITER_HANDLED;
|
|
|
|
}
|
|
|
|
|
2015-04-27 22:25:09 +00:00
|
|
|
int
|
2016-01-31 17:57:50 +00:00
|
|
|
main (int argc, const char *argv[])
|
2015-04-27 22:25:09 +00:00
|
|
|
{
|
2015-04-27 22:39:22 +00:00
|
|
|
g_set_prgname ("gtk-builder-tool");
|
|
|
|
|
2020-11-01 20:48:37 +00:00
|
|
|
g_log_set_writer_func (log_writer_func, NULL, NULL);
|
|
|
|
|
2022-04-17 15:19:07 +00:00
|
|
|
gtk_init_check ();
|
2015-04-27 22:25:09 +00:00
|
|
|
|
|
|
|
gtk_test_register_all_types ();
|
|
|
|
|
2022-04-17 15:59:06 +00:00
|
|
|
if (argc < 2)
|
2015-04-27 22:25:09 +00:00
|
|
|
usage ();
|
|
|
|
|
2022-04-17 15:59:06 +00:00
|
|
|
if (strcmp (argv[1], "--help") == 0)
|
2016-01-31 16:01:46 +00:00
|
|
|
usage ();
|
|
|
|
|
2016-01-31 17:57:50 +00:00
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
|
|
|
|
if (strcmp (argv[0], "validate") == 0)
|
2019-02-07 09:12:09 +00:00
|
|
|
do_validate (&argc, &argv);
|
2016-01-31 17:57:50 +00:00
|
|
|
else if (strcmp (argv[0], "simplify") == 0)
|
2016-11-13 03:29:02 +00:00
|
|
|
do_simplify (&argc, &argv);
|
2016-01-31 17:57:50 +00:00
|
|
|
else if (strcmp (argv[0], "enumerate") == 0)
|
2019-02-07 09:12:09 +00:00
|
|
|
do_enumerate (&argc, &argv);
|
2016-01-31 17:57:50 +00:00
|
|
|
else if (strcmp (argv[0], "preview") == 0)
|
2022-04-17 15:19:07 +00:00
|
|
|
do_preview (&argc, &argv);
|
2022-04-17 04:26:25 +00:00
|
|
|
else if (strcmp (argv[0], "screenshot") == 0)
|
|
|
|
do_screenshot (&argc, &argv);
|
2015-04-28 03:31:03 +00:00
|
|
|
else
|
|
|
|
usage ();
|
2015-04-27 22:25:09 +00:00
|
|
|
|
2015-04-19 01:03:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|