4 * Copyright (C) 2000 Red Hat Software
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
40 #include <pango/pango-utils.h>
41 #include "gtk/gtkrc.h"
42 #include "gtk/gtkimmodule.h"
45 print_escaped (const char *str)
47 char *tmp = g_strescape (str, NULL);
48 printf ("\"%s\" ", tmp);
53 query_module (const char *dir, const char *name)
55 void (*list) (const GtkIMContextInfo ***contexts,
57 void (*init) (GTypeModule *type_module);
59 GtkIMContext *(*create) (const gchar *context_id);
63 gboolean error = FALSE;
65 if (g_path_is_absolute (name))
66 path = g_strdup (name);
68 path = g_build_filename (dir, name, NULL);
70 module = g_module_open (path, 0);
74 fprintf(stderr, "Cannot load module %s: %s\n", path, g_module_error());
79 g_module_symbol (module, "im_module_list", (gpointer *) &list) &&
80 g_module_symbol (module, "im_module_init", (gpointer *) &init) &&
81 g_module_symbol (module, "im_module_exit", (gpointer *) &exit) &&
82 g_module_symbol (module, "im_module_create", (gpointer *) &create))
84 const GtkIMContextInfo **contexts;
91 (*list) (&contexts, &n_contexts);
93 for (i=0; i<n_contexts; i++)
95 print_escaped (contexts[i]->context_id);
96 print_escaped (contexts[i]->context_name);
97 print_escaped (contexts[i]->domain);
98 print_escaped (contexts[i]->domain_dirname);
99 print_escaped (contexts[i]->default_locales);
100 fputs ("\n", stdout);
102 fputs ("\n", stdout);
106 fprintf (stderr, "%s does not export GTK+ IM module API: %s\n", path,
113 g_module_close (module);
118 int main (int argc, char **argv)
123 gboolean error = FALSE;
125 printf ("# GTK+ Input Method Modules file\n"
126 "# Automatically generated file, do not edit\n"
129 if (argc == 1) /* No arguments given */
134 path = gtk_rc_get_im_module_path ();
136 printf ("# ModulesPath = %s\n#\n", path);
138 dirs = pango_split_file_list (path);
140 for (i=0; dirs[i]; i++)
142 GDir *dir = g_dir_open (dirs[i], 0, NULL);
147 while ((dent = g_dir_read_name (dir)))
149 int len = strlen (dent);
150 if (len > 3 && strcmp (dent + len - strlen (SOEXT), SOEXT) == 0)
151 error |= query_module (dirs[i], dent);
160 cwd = g_get_current_dir ();
162 for (i=1; i<argc; i++)
163 error |= query_module (cwd, argv[i]);
168 return error ? 1 : 0;