2002-10-03 22:39:51 +00:00
|
|
|
/* -*- mode: C; c-file-style: "linux" -*- */
|
|
|
|
/* GdkPixbuf library
|
|
|
|
* queryloaders.c:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 The Free Software Foundation
|
|
|
|
*
|
|
|
|
* Author: Matthias Clasen <maclas@gmx.de>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library 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.
|
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2002-10-03 22:39:51 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
2002-12-15 01:49:01 +00:00
|
|
|
#include <glib/gprintf.h>
|
2002-10-03 22:39:51 +00:00
|
|
|
#include <gmodule.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gdk-pixbuf/gdk-pixbuf.h"
|
|
|
|
#include "gdk-pixbuf/gdk-pixbuf-private.h"
|
|
|
|
#include "gdk-pixbuf/gdk-pixbuf-io.h"
|
|
|
|
|
2006-10-08 05:32:07 +00:00
|
|
|
#ifdef USE_LA_MODULES
|
2002-10-03 22:39:51 +00:00
|
|
|
#define SOEXT ".la"
|
|
|
|
#else
|
|
|
|
#define SOEXT ("." G_MODULE_SUFFIX)
|
|
|
|
#endif
|
|
|
|
#define SOEXT_LEN (strlen (SOEXT))
|
|
|
|
|
2004-03-15 14:10:08 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
static void
|
|
|
|
print_escaped (const char *str)
|
|
|
|
{
|
|
|
|
gchar *tmp = g_strescape (str, "");
|
2002-12-15 01:49:01 +00:00
|
|
|
g_printf ("\"%s\" ", tmp);
|
2002-10-03 22:39:51 +00:00
|
|
|
g_free (tmp);
|
|
|
|
}
|
|
|
|
|
2003-11-09 21:07:31 +00:00
|
|
|
static int
|
|
|
|
loader_sanity_check (const char *path, GdkPixbufFormat *info, GdkPixbufModule *vtable)
|
|
|
|
{
|
|
|
|
const GdkPixbufModulePattern *pattern;
|
|
|
|
const char *error = "";
|
|
|
|
|
2003-11-14 23:28:01 +00:00
|
|
|
for (pattern = info->signature; pattern->prefix; pattern++)
|
|
|
|
{
|
|
|
|
int prefix_len = strlen (pattern->prefix);
|
|
|
|
if (prefix_len == 0)
|
2003-11-09 21:07:31 +00:00
|
|
|
{
|
|
|
|
error = "empty pattern";
|
|
|
|
|
|
|
|
goto error;
|
|
|
|
}
|
2003-11-14 23:28:01 +00:00
|
|
|
if (pattern->mask)
|
|
|
|
{
|
|
|
|
int mask_len = strlen (pattern->mask);
|
|
|
|
if (mask_len != prefix_len)
|
|
|
|
{
|
|
|
|
error = "mask length mismatch";
|
|
|
|
|
|
|
|
goto error;
|
|
|
|
}
|
2005-07-22 20:28:31 +00:00
|
|
|
if (strspn (pattern->mask, " !xzn*") < mask_len)
|
2003-11-14 23:28:01 +00:00
|
|
|
{
|
|
|
|
error = "bad char in mask";
|
|
|
|
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-11-09 21:07:31 +00:00
|
|
|
|
|
|
|
if (!vtable->load && !vtable->begin_load && !vtable->load_animation)
|
|
|
|
{
|
|
|
|
error = "no load method implemented";
|
|
|
|
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vtable->begin_load && (!vtable->stop_load || !vtable->load_increment))
|
|
|
|
{
|
|
|
|
error = "incremental loading support incomplete";
|
|
|
|
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2008-02-22 15:26:48 +00:00
|
|
|
if ((info->flags & GDK_PIXBUF_FORMAT_WRITABLE) && !(vtable->save || vtable->save_to_callback))
|
2003-11-09 21:07:31 +00:00
|
|
|
{
|
|
|
|
error = "loader claims to support saving but doesn't implement save";
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
error:
|
|
|
|
g_fprintf (stderr, "Loader sanity check failed for %s: %s\n",
|
|
|
|
path, error);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-04 22:22:30 +00:00
|
|
|
static void
|
2003-11-09 21:07:31 +00:00
|
|
|
write_loader_info (const char *path, GdkPixbufFormat *info)
|
|
|
|
{
|
|
|
|
const GdkPixbufModulePattern *pattern;
|
2009-09-04 22:22:30 +00:00
|
|
|
char **mime;
|
|
|
|
char **ext;
|
2003-11-09 21:07:31 +00:00
|
|
|
|
|
|
|
g_printf("\"%s\"\n", path);
|
2009-09-04 22:22:30 +00:00
|
|
|
g_printf ("\"%s\" %u \"%s\" \"%s\" \"%s\"\n",
|
|
|
|
info->name,
|
|
|
|
info->flags,
|
|
|
|
info->domain ? info->domain : GETTEXT_PACKAGE,
|
|
|
|
info->description,
|
|
|
|
info->license ? info->license : "");
|
2003-11-09 21:07:31 +00:00
|
|
|
for (mime = info->mime_types; *mime; mime++) {
|
|
|
|
g_printf ("\"%s\" ", *mime);
|
|
|
|
}
|
|
|
|
g_printf ("\"\"\n");
|
|
|
|
for (ext = info->extensions; *ext; ext++) {
|
|
|
|
g_printf ("\"%s\" ", *ext);
|
|
|
|
}
|
|
|
|
g_printf ("\"\"\n");
|
|
|
|
for (pattern = info->signature; pattern->prefix; pattern++) {
|
|
|
|
print_escaped (pattern->prefix);
|
|
|
|
print_escaped (pattern->mask ? (const char *)pattern->mask : "");
|
|
|
|
g_printf ("%d\n", pattern->relevance);
|
|
|
|
}
|
|
|
|
g_printf ("\n");
|
|
|
|
}
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
static void
|
|
|
|
query_module (const char *dir, const char *file)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
GModule *module;
|
|
|
|
void (*fill_info) (GdkPixbufFormat *info);
|
|
|
|
void (*fill_vtable) (GdkPixbufModule *module);
|
2008-07-18 18:27:30 +00:00
|
|
|
gpointer fill_info_ptr;
|
|
|
|
gpointer fill_vtable_ptr;
|
2002-10-03 22:39:51 +00:00
|
|
|
|
2003-07-11 20:36:25 +00:00
|
|
|
if (g_path_is_absolute (file))
|
|
|
|
path = g_strdup (file);
|
|
|
|
else
|
2002-10-03 22:39:51 +00:00
|
|
|
path = g_build_filename (dir, file, NULL);
|
|
|
|
|
|
|
|
module = g_module_open (path, 0);
|
|
|
|
if (module &&
|
2008-07-18 18:27:30 +00:00
|
|
|
g_module_symbol (module, "fill_info", &fill_info_ptr) &&
|
|
|
|
g_module_symbol (module, "fill_vtable", &fill_vtable_ptr)) {
|
2002-10-04 05:23:13 +00:00
|
|
|
GdkPixbufFormat *info;
|
2003-11-09 21:07:31 +00:00
|
|
|
GdkPixbufModule *vtable;
|
|
|
|
|
2004-03-15 13:07:04 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
/* Replace backslashes in path with forward slashes, so that
|
|
|
|
* it reads in without problems.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
char *p = path;
|
|
|
|
while (*p) {
|
|
|
|
if (*p == '\\')
|
|
|
|
*p = '/';
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2002-10-04 05:23:13 +00:00
|
|
|
info = g_new0 (GdkPixbufFormat, 1);
|
2003-11-09 21:07:31 +00:00
|
|
|
vtable = g_new0 (GdkPixbufModule, 1);
|
2004-11-15 16:22:49 +00:00
|
|
|
|
|
|
|
vtable->module = module;
|
|
|
|
|
2008-07-18 18:27:30 +00:00
|
|
|
fill_info = fill_info_ptr;
|
|
|
|
fill_vtable = fill_vtable_ptr;
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
(*fill_info) (info);
|
2003-11-09 21:07:31 +00:00
|
|
|
(*fill_vtable) (vtable);
|
|
|
|
|
|
|
|
if (loader_sanity_check (path, info, vtable))
|
|
|
|
write_loader_info (path, info);
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
g_free (info);
|
2003-11-09 21:07:31 +00:00
|
|
|
g_free (vtable);
|
2002-10-03 22:39:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-02-06 19:31:46 +00:00
|
|
|
if (module == NULL)
|
|
|
|
g_fprintf (stderr, "g_module_open() failed for %s: %s\n", path,
|
|
|
|
g_module_error());
|
|
|
|
else
|
|
|
|
g_fprintf (stderr, "Cannot load loader %s\n", path);
|
2002-10-03 22:39:51 +00:00
|
|
|
}
|
|
|
|
if (module)
|
|
|
|
g_module_close (module);
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
gint i;
|
2004-12-22 06:20:26 +00:00
|
|
|
gchar *prgname;
|
2002-10-03 22:39:51 +00:00
|
|
|
|
2004-03-15 14:10:08 +00:00
|
|
|
#ifdef G_OS_WIN32
|
2004-12-05 12:43:47 +00:00
|
|
|
gchar *libdir;
|
|
|
|
gchar *runtime_prefix;
|
2004-03-15 14:10:08 +00:00
|
|
|
gchar *slash;
|
|
|
|
|
|
|
|
if (g_ascii_strncasecmp (PIXBUF_LIBDIR, GTK_PREFIX, strlen (GTK_PREFIX)) == 0 &&
|
2004-12-05 12:43:47 +00:00
|
|
|
G_IS_DIR_SEPARATOR (PIXBUF_LIBDIR[strlen (GTK_PREFIX)])) {
|
2004-03-15 14:10:08 +00:00
|
|
|
/* GTK_PREFIX is a prefix of PIXBUF_LIBDIR, as it
|
|
|
|
* normally is. Replace that prefix in PIXBUF_LIBDIR
|
|
|
|
* with the installation directory on this machine.
|
|
|
|
* We assume this invokation of
|
|
|
|
* gdk-pixbuf-query-loaders is run from either a "bin"
|
|
|
|
* subdirectory of the installation directory, or in
|
2004-12-05 12:43:47 +00:00
|
|
|
* the installation directory itself.
|
2004-03-15 14:10:08 +00:00
|
|
|
*/
|
2009-01-13 11:17:25 +00:00
|
|
|
wchar_t fn[1000];
|
|
|
|
GetModuleFileNameW (NULL, fn, G_N_ELEMENTS (fn));
|
|
|
|
runtime_prefix = g_utf16_to_utf8 (fn, -1, NULL, NULL, NULL);
|
2004-03-15 14:10:08 +00:00
|
|
|
slash = strrchr (runtime_prefix, '\\');
|
|
|
|
*slash = '\0';
|
|
|
|
slash = strrchr (runtime_prefix, '\\');
|
2009-01-13 11:17:25 +00:00
|
|
|
/* If running from some weird location, or from the
|
|
|
|
* build directory (either in the .libs folder where
|
|
|
|
* libtool places the real executable when using a
|
|
|
|
* wrapper, or directly from the gdk-pixbuf folder),
|
|
|
|
* use the compile-time libdir.
|
|
|
|
*/
|
|
|
|
if (slash == NULL ||
|
|
|
|
g_ascii_strcasecmp (slash + 1, ".libs") == 0 ||
|
|
|
|
g_ascii_strcasecmp (slash + 1, "gdk-pixbuf") == 0) {
|
|
|
|
libdir = PIXBUF_LIBDIR;
|
2004-03-15 14:10:08 +00:00
|
|
|
}
|
2009-01-13 11:17:25 +00:00
|
|
|
else {
|
|
|
|
if (slash != NULL && g_ascii_strcasecmp (slash + 1, "bin") == 0) {
|
|
|
|
*slash = '\0';
|
|
|
|
}
|
2004-03-15 14:10:08 +00:00
|
|
|
|
2009-01-13 11:17:25 +00:00
|
|
|
libdir = g_strconcat (runtime_prefix,
|
|
|
|
"/",
|
|
|
|
PIXBUF_LIBDIR + strlen (GTK_PREFIX) + 1,
|
|
|
|
NULL);
|
|
|
|
}
|
2004-12-05 12:43:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
libdir = PIXBUF_LIBDIR;
|
2004-03-15 14:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef PIXBUF_LIBDIR
|
|
|
|
#define PIXBUF_LIBDIR libdir
|
|
|
|
|
|
|
|
#endif
|
2004-12-22 06:20:26 +00:00
|
|
|
prgname = g_get_prgname ();
|
2002-12-15 01:49:01 +00:00
|
|
|
g_printf ("# GdkPixbuf Image Loader Modules file\n"
|
2004-12-22 06:20:26 +00:00
|
|
|
"# Automatically generated file, do not edit\n"
|
|
|
|
"# Created by %s from gtk+-%s\n"
|
|
|
|
"#\n",
|
2010-05-08 05:18:53 +00:00
|
|
|
(prgname ? prgname : "gdk-pixbuf-query-loaders-3.0"),
|
2004-12-22 06:20:26 +00:00
|
|
|
GDK_PIXBUF_VERSION);
|
2002-10-03 22:39:51 +00:00
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
#ifdef USE_GMODULE
|
|
|
|
const char *path;
|
2002-10-04 05:46:51 +00:00
|
|
|
GDir *dir;
|
2002-10-03 22:39:51 +00:00
|
|
|
|
|
|
|
path = g_getenv ("GDK_PIXBUF_MODULEDIR");
|
2004-12-05 12:43:47 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
if (path != NULL && *path != '\0')
|
|
|
|
path = g_locale_to_utf8 (path, -1, NULL, NULL, NULL);
|
|
|
|
#endif
|
2002-10-03 22:39:51 +00:00
|
|
|
if (path == NULL || *path == '\0')
|
|
|
|
path = PIXBUF_LIBDIR;
|
|
|
|
|
2002-12-15 01:49:01 +00:00
|
|
|
g_printf ("# LoaderDir = %s\n#\n", path);
|
2002-10-03 22:39:51 +00:00
|
|
|
|
2002-10-04 05:46:51 +00:00
|
|
|
dir = g_dir_open (path, 0, NULL);
|
2002-10-03 22:39:51 +00:00
|
|
|
if (dir) {
|
|
|
|
const char *dent;
|
|
|
|
|
|
|
|
while ((dent = g_dir_read_name (dir))) {
|
|
|
|
gint len = strlen (dent);
|
|
|
|
if (len > SOEXT_LEN &&
|
|
|
|
strcmp (dent + len - SOEXT_LEN, SOEXT) == 0) {
|
|
|
|
query_module (path, dent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_dir_close (dir);
|
|
|
|
}
|
|
|
|
#else
|
2002-12-15 01:49:01 +00:00
|
|
|
g_printf ("# dynamic loading of modules not supported\n");
|
2002-10-03 22:39:51 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char *cwd = g_get_current_dir ();
|
|
|
|
|
2004-12-05 12:43:47 +00:00
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
char *infilename = argv[i];
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
infilename = g_locale_to_utf8 (infilename,
|
|
|
|
-1, NULL, NULL, NULL);
|
|
|
|
#endif
|
|
|
|
query_module (cwd, infilename);
|
|
|
|
}
|
2002-10-03 22:39:51 +00:00
|
|
|
g_free (cwd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|