]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/queryloaders.c
Use g_printf instead of system printf. (#99327)
[~andy/gtk] / gdk-pixbuf / queryloaders.c
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
48 static void
49 print_escaped (const char *str)
50 {
51         gchar *tmp = g_strescape (str, "");
52         g_printf ("\"%s\" ", tmp);
53         g_free (tmp);
54 }
55
56 static void
57 query_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                 g_printf("\"%s\"\n", path);
82                 info = g_new0 (GdkPixbufFormat, 1);
83                 (*fill_info) (info);
84                 g_printf ("\"%s\" %d \"%s\" \"%s\"\n", 
85                        info->name, info->flags, 
86                        info->domain ? info->domain : GETTEXT_PACKAGE, info->description);
87                 for (mime = info->mime_types; *mime; mime++) {
88                         g_printf ("\"%s\" ", *mime);
89                 }
90                 g_printf ("\"\"\n");
91                 for (ext = info->extensions; *ext; ext++) {
92                         g_printf ("\"%s\" ", *ext);
93                 }
94                 g_printf ("\"\"\n");
95                 for (pattern = info->signature; pattern->prefix; pattern++) {
96                         print_escaped (pattern->prefix);
97                         print_escaped (pattern->mask ? (const char *)pattern->mask : "");
98                         g_printf ("%d\n", pattern->relevance);
99                 }
100                 g_printf ("\n");
101                 g_free (info);
102         }
103         else {
104                 g_fprintf (stderr, "Cannot load loader %s\n", path);
105         }
106         if (module)
107                 g_module_close (module);
108         g_free (path);
109 }
110
111 int main (int argc, char **argv)
112 {
113         gint i;
114
115         g_printf ("# GdkPixbuf Image Loader Modules file\n"
116                 "# Automatically generated file, do not edit\n"
117                 "#\n");
118   
119         if (argc == 1) {
120 #ifdef USE_GMODULE
121                 const char *path;
122                 GDir *dir;
123     
124                 path = g_getenv ("GDK_PIXBUF_MODULEDIR");
125                 if (path == NULL || *path == '\0')
126                         path = PIXBUF_LIBDIR;
127
128                 g_printf ("# LoaderDir = %s\n#\n", path);
129
130                 dir = g_dir_open (path, 0, NULL);
131                 if (dir) {
132                         const char *dent;
133
134                         while ((dent = g_dir_read_name (dir))) {
135                                 gint len = strlen (dent);
136                                 if (len > SOEXT_LEN && 
137                                     strcmp (dent + len - SOEXT_LEN, SOEXT) == 0) {
138                                         query_module (path, dent);
139                                 }
140                         }
141                         g_dir_close (dir);
142                 }
143 #else
144                 g_printf ("# dynamic loading of modules not supported\n");
145 #endif
146         }
147         else {
148                 char *cwd = g_get_current_dir ();
149
150                 for (i = 1; i < argc; i++)
151                         query_module (cwd, argv[i]);
152
153                 g_free (cwd);
154         }
155
156         return 0;
157 }