2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-02-11 09:21:21 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2006-04-29 06:26:51 +08:00
|
|
|
* gimpplugindebug.c
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-02-11 09:21:21 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-02-11 09:21:21 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-02-11 09:21:21 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
#include "plug-in-types.h"
|
2003-02-11 09:21:21 +08:00
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
#include "gimpplugindebug.h"
|
2003-02-11 09:21:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
struct _GimpPlugInDebug
|
|
|
|
{
|
|
|
|
gchar *name;
|
|
|
|
guint flags;
|
|
|
|
gchar **args;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
static const GDebugKey gimp_debug_wrap_keys[] =
|
|
|
|
{
|
|
|
|
{ "query", GIMP_DEBUG_WRAP_QUERY },
|
|
|
|
{ "init", GIMP_DEBUG_WRAP_INIT },
|
|
|
|
{ "run", GIMP_DEBUG_WRAP_RUN },
|
|
|
|
{ "on", GIMP_DEBUG_WRAP_DEFAULT }
|
2003-02-11 09:21:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
GimpPlugInDebug *
|
|
|
|
gimp_plug_in_debug_new (void)
|
2003-02-11 09:21:21 +08:00
|
|
|
{
|
2006-04-29 06:26:51 +08:00
|
|
|
GimpPlugInDebug *debug;
|
2003-02-11 09:21:21 +08:00
|
|
|
const gchar *wrap, *wrapper;
|
|
|
|
gchar *debug_string;
|
|
|
|
gchar **args;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
wrap = g_getenv ("GIMP_PLUGIN_DEBUG_WRAP");
|
|
|
|
wrapper = g_getenv ("GIMP_PLUGIN_DEBUG_WRAPPER");
|
|
|
|
|
|
|
|
if (!(wrap && wrapper))
|
2006-04-29 06:26:51 +08:00
|
|
|
return NULL;
|
2003-02-11 09:21:21 +08:00
|
|
|
|
|
|
|
if (!g_shell_parse_argv (wrapper, NULL, &args, &error))
|
|
|
|
{
|
|
|
|
g_warning ("Unable to parse debug wrapper: \"%s\"\n%s",
|
|
|
|
wrapper, error->message);
|
|
|
|
g_error_free (error);
|
2006-04-29 06:26:51 +08:00
|
|
|
return NULL;
|
2003-02-11 09:21:21 +08:00
|
|
|
}
|
|
|
|
|
2007-05-23 16:57:53 +08:00
|
|
|
debug = g_slice_new (GimpPlugInDebug);
|
2003-02-11 09:21:21 +08:00
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
debug->args = args;
|
2003-02-11 09:21:21 +08:00
|
|
|
|
|
|
|
debug_string = strchr (wrap, ',');
|
|
|
|
|
|
|
|
if (debug_string)
|
|
|
|
{
|
2006-04-29 06:26:51 +08:00
|
|
|
debug->name = g_strndup (wrap, debug_string - wrap);
|
|
|
|
debug->flags = g_parse_debug_string (debug_string + 1,
|
|
|
|
gimp_debug_wrap_keys,
|
|
|
|
G_N_ELEMENTS (gimp_debug_wrap_keys));
|
2003-02-11 09:21:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-29 06:26:51 +08:00
|
|
|
debug->name = g_strdup (wrap);
|
|
|
|
debug->flags = GIMP_DEBUG_WRAP_DEFAULT;
|
2003-02-11 09:21:21 +08:00
|
|
|
}
|
2006-01-17 20:43:50 +08:00
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
return debug;
|
2003-02-11 09:21:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-04-29 06:26:51 +08:00
|
|
|
gimp_plug_in_debug_free (GimpPlugInDebug *debug)
|
2003-02-11 09:21:21 +08:00
|
|
|
{
|
2006-04-29 06:26:51 +08:00
|
|
|
g_return_if_fail (debug != NULL);
|
2003-02-11 09:21:21 +08:00
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
if (debug->name)
|
|
|
|
g_free (debug->name);
|
2003-02-11 09:21:21 +08:00
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
if (debug->args)
|
|
|
|
g_strfreev (debug->args);
|
2003-02-11 09:21:21 +08:00
|
|
|
|
2007-05-23 16:57:53 +08:00
|
|
|
g_slice_free (GimpPlugInDebug, debug);
|
2003-02-11 09:21:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar **
|
2006-04-29 06:26:51 +08:00
|
|
|
gimp_plug_in_debug_argv (GimpPlugInDebug *debug,
|
|
|
|
const gchar *name,
|
|
|
|
GimpDebugWrapFlag flag,
|
2008-09-05 23:46:00 +08:00
|
|
|
const gchar **args)
|
2003-02-11 09:21:21 +08:00
|
|
|
{
|
2006-04-29 06:26:51 +08:00
|
|
|
GPtrArray *argv;
|
|
|
|
gchar **arg;
|
2006-05-04 19:58:10 +08:00
|
|
|
gchar *basename;
|
2003-02-11 09:21:21 +08:00
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
g_return_val_if_fail (debug != NULL, NULL);
|
2006-05-04 19:58:10 +08:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
2003-02-11 09:21:21 +08:00
|
|
|
g_return_val_if_fail (args != NULL, NULL);
|
|
|
|
|
2006-05-04 19:58:10 +08:00
|
|
|
basename = g_path_get_basename (name);
|
|
|
|
|
|
|
|
if (!(debug->flags & flag) || (strcmp (debug->name, basename) != 0))
|
|
|
|
{
|
|
|
|
g_free (basename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (basename);
|
2003-02-11 09:21:21 +08:00
|
|
|
|
|
|
|
argv = g_ptr_array_sized_new (8);
|
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
for (arg = debug->args; *arg != NULL; arg++)
|
2003-02-11 09:21:21 +08:00
|
|
|
g_ptr_array_add (argv, *arg);
|
|
|
|
|
2008-09-05 23:46:00 +08:00
|
|
|
for (arg = (gchar **) args; *arg != NULL; arg++)
|
2003-02-11 09:21:21 +08:00
|
|
|
g_ptr_array_add (argv, *arg);
|
|
|
|
|
|
|
|
g_ptr_array_add (argv, NULL);
|
|
|
|
|
|
|
|
return (gchar **) g_ptr_array_free (argv, FALSE);
|
|
|
|
}
|