source: trunk/third/gtk2/gdk-pixbuf/queryloaders.c @ 18785

Revision 18785, 4.1 KB checked in by ghudson, 21 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18784, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- mode: C; c-file-style: "linux" -*- */
2/* GdkPixbuf library
3 * queryloaders.c:
4 *
5 * Copyright (C) 2002 The Free Software Foundation
6 *
7 * Author: Matthias Clasen <maclas@gmx.de>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
23 */
24
25#include <config.h>
26
27#include <glib.h>
28#include <glib/gprintf.h>
29#include <gmodule.h>
30
31#include <errno.h>
32#include <string.h>
33#ifdef HAVE_UNISTD_H
34#include <unistd.h>
35#endif
36
37#include "gdk-pixbuf/gdk-pixbuf.h"
38#include "gdk-pixbuf/gdk-pixbuf-private.h"
39#include "gdk-pixbuf/gdk-pixbuf-io.h"
40
41#if USE_LA_MODULES
42#define SOEXT ".la"
43#else
44#define SOEXT ("." G_MODULE_SUFFIX)
45#endif
46#define SOEXT_LEN (strlen (SOEXT))
47
48static void
49print_escaped (const char *str)
50{
51        gchar *tmp = g_strescape (str, "");
52        g_printf ("\"%s\" ", tmp);
53        g_free (tmp);
54}
55
56static void
57query_module (const char *dir, const char *file)
58{
59        char *path;
60        GModule *module;
61        void                    (*fill_info)     (GdkPixbufFormat *info);
62        void                    (*fill_vtable)   (GdkPixbufModule *module);
63        char **mime;
64        char **ext;
65        const GdkPixbufModulePattern *pattern;
66
67        if (g_path_is_absolute (dir))
68                path = g_build_filename (dir, file, NULL);
69        else {
70                char *cwd = g_get_current_dir ();
71                path = g_build_filename (cwd, dir, file, NULL);
72                g_free (cwd);
73        }             
74       
75
76        module = g_module_open (path, 0);
77        if (module &&
78            g_module_symbol (module, "fill_info", (gpointer *) &fill_info) &&
79            g_module_symbol (module, "fill_vtable", (gpointer *) &fill_vtable)) {
80                GdkPixbufFormat *info;
81#ifdef G_OS_WIN32
82                /* Replace backslashes in path with forward slashes, so that
83                 * it reads in without problems.
84                 */
85                {
86                        char *p = path;
87                        while (*p) {
88                                if (*p == '\\')
89                                        *p = '/';
90                                p++;
91                        }
92                }
93#endif 
94                g_printf("\"%s\"\n", path);
95                info = g_new0 (GdkPixbufFormat, 1);
96                (*fill_info) (info);
97                g_printf ("\"%s\" %d \"%s\" \"%s\"\n",
98                       info->name, info->flags,
99                       info->domain ? info->domain : GETTEXT_PACKAGE, info->description);
100                for (mime = info->mime_types; *mime; mime++) {
101                        g_printf ("\"%s\" ", *mime);
102                }
103                g_printf ("\"\"\n");
104                for (ext = info->extensions; *ext; ext++) {
105                        g_printf ("\"%s\" ", *ext);
106                }
107                g_printf ("\"\"\n");
108                for (pattern = info->signature; pattern->prefix; pattern++) {
109                        print_escaped (pattern->prefix);
110                        print_escaped (pattern->mask ? (const char *)pattern->mask : "");
111                        g_printf ("%d\n", pattern->relevance);
112                }
113                g_printf ("\n");
114                g_free (info);
115        }
116        else {
117                g_fprintf (stderr, "Cannot load loader %s\n", path);
118        }
119        if (module)
120                g_module_close (module);
121        g_free (path);
122}
123
124int main (int argc, char **argv)
125{
126        gint i;
127
128        g_printf ("# GdkPixbuf Image Loader Modules file\n"
129                "# Automatically generated file, do not edit\n"
130                "#\n");
131 
132        if (argc == 1) {
133#ifdef USE_GMODULE
134                const char *path;
135                GDir *dir;
136   
137                path = g_getenv ("GDK_PIXBUF_MODULEDIR");
138                if (path == NULL || *path == '\0')
139                        path = PIXBUF_LIBDIR;
140
141                g_printf ("# LoaderDir = %s\n#\n", path);
142
143                dir = g_dir_open (path, 0, NULL);
144                if (dir) {
145                        const char *dent;
146
147                        while ((dent = g_dir_read_name (dir))) {
148                                gint len = strlen (dent);
149                                if (len > SOEXT_LEN &&
150                                    strcmp (dent + len - SOEXT_LEN, SOEXT) == 0) {
151                                        query_module (path, dent);
152                                }
153                        }
154                        g_dir_close (dir);
155                }
156#else
157                g_printf ("# dynamic loading of modules not supported\n");
158#endif
159        }
160        else {
161                char *cwd = g_get_current_dir ();
162
163                for (i = 1; i < argc; i++)
164                        query_module (cwd, argv[i]);
165
166                g_free (cwd);
167        }
168
169        return 0;
170}
Note: See TracBrowser for help on using the repository browser.