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.
43 #include <pango/pango-utils.h>
44 #include "gtk/gtkrc.h"
45 #include "gtk/gtkimmodule.h"
48 print_escaped (const char *str)
50 char *tmp = g_strescape (str, NULL);
51 printf ("\"%s\" ", tmp);
56 query_module (const char *dir, const char *name)
58 void (*list) (const GtkIMContextInfo ***contexts,
60 void (*init) (GTypeModule *type_module);
62 GtkIMContext *(*create) (const gchar *context_id);
66 gboolean error = FALSE;
68 if (name[0] == G_DIR_SEPARATOR)
69 path = g_strdup (name);
71 path = g_strconcat (dir, G_DIR_SEPARATOR_S, name, NULL);
73 module = g_module_open (path, 0);
77 fprintf(stderr, "Cannot load module %s: %s\n", path, g_module_error());
82 g_module_symbol (module, "im_module_list", (gpointer)&list) &&
83 g_module_symbol (module, "im_module_init", (gpointer)&init) &&
84 g_module_symbol (module, "im_module_exit", (gpointer)&exit) &&
85 g_module_symbol (module, "im_module_create", (gpointer)&create))
87 const GtkIMContextInfo **contexts;
94 (*list) (&contexts, &n_contexts);
96 for (i=0; i<n_contexts; i++)
98 print_escaped (contexts[i]->context_id);
99 print_escaped (contexts[i]->context_name);
100 print_escaped (contexts[i]->domain);
101 print_escaped (contexts[i]->domain_dirname);
102 print_escaped (contexts[i]->default_locales);
103 fputs ("\n", stdout);
105 fputs ("\n", stdout);
109 fprintf (stderr, "%s does not export GTK+ IM module API: %s\n", path,
116 g_module_close (module);
121 int main (int argc, char **argv)
126 gboolean error = FALSE;
128 printf ("# GTK+ Input Method Modules file\n"
129 "# Automatically generated file, do not edit\n"
132 if (argc == 1) /* No arguments given */
137 path = gtk_rc_get_im_module_path ();
139 printf ("# ModulesPath = %s\n#\n", path);
141 dirs = pango_split_file_list (path);
143 for (i=0; dirs[i]; i++)
145 DIR *dir = opendir (dirs[i]);
150 while ((dent = readdir (dir)))
152 int len = strlen (dent->d_name);
153 if (len > 3 && strcmp (dent->d_name + len - strlen (SOEXT), SOEXT) == 0)
154 error |= query_module (dirs[i], dent->d_name);
163 getcwd (cwd, PATH_MAX);
165 for (i=1; i<argc; i++)
166 error |= query_module (cwd, argv[i]);
169 return error ? 1 : 0;