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.
25 #include <glib/gprintf.h>
40 #include <pango/pango-utils.h>
41 #include "gtk/gtkrc.h"
42 #include "gtk/gtkimmodule.h"
45 escape_string (const char *str)
47 GString *result = g_string_new ("");
58 g_string_append (result, "\\n");
61 g_string_append (result, "\\\"");
64 g_string_append_c (result, c);
69 return g_string_free (result, FALSE);
73 print_escaped (const char *str)
75 char *tmp = escape_string (str);
76 g_printf ("\"%s\" ", tmp);
81 query_module (const char *dir, const char *name)
83 void (*list) (const GtkIMContextInfo ***contexts,
85 void (*init) (GTypeModule *type_module);
87 GtkIMContext *(*create) (const gchar *context_id);
91 gboolean error = FALSE;
93 if (g_path_is_absolute (name))
94 path = g_strdup (name);
96 path = g_build_filename (dir, name, NULL);
98 module = g_module_open (path, 0);
102 g_fprintf (stderr, "Cannot load module %s: %s\n", path, g_module_error());
107 g_module_symbol (module, "im_module_list", (gpointer *) &list) &&
108 g_module_symbol (module, "im_module_init", (gpointer *) &init) &&
109 g_module_symbol (module, "im_module_exit", (gpointer *) &exit) &&
110 g_module_symbol (module, "im_module_create", (gpointer *) &create))
112 const GtkIMContextInfo **contexts;
116 print_escaped (path);
117 fputs ("\n", stdout);
119 (*list) (&contexts, &n_contexts);
121 for (i=0; i<n_contexts; i++)
123 print_escaped (contexts[i]->context_id);
124 print_escaped (contexts[i]->context_name);
125 print_escaped (contexts[i]->domain);
126 print_escaped (contexts[i]->domain_dirname);
127 print_escaped (contexts[i]->default_locales);
128 fputs ("\n", stdout);
130 fputs ("\n", stdout);
134 g_fprintf (stderr, "%s does not export GTK+ IM module API: %s\n", path,
141 g_module_close (module);
146 int main (int argc, char **argv)
151 gboolean error = FALSE;
153 g_printf ("# GTK+ Input Method Modules file\n"
154 "# Automatically generated file, do not edit\n"
157 if (argc == 1) /* No arguments given */
162 path = gtk_rc_get_im_module_path ();
164 g_printf ("# ModulesPath = %s\n#\n", path);
166 dirs = pango_split_file_list (path);
168 for (i=0; dirs[i]; i++)
170 GDir *dir = g_dir_open (dirs[i], 0, NULL);
175 while ((dent = g_dir_read_name (dir)))
177 int len = strlen (dent);
178 if (len > 3 && strcmp (dent + len - strlen (SOEXT), SOEXT) == 0)
179 error |= query_module (dirs[i], dent);
188 cwd = g_get_current_dir ();
190 for (i=1; i<argc; i++)
191 error |= query_module (cwd, argv[i]);
196 return error ? 1 : 0;