4 * Copyright (C) 2000-2010 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>
37 #define SOEXT ("." G_MODULE_SUFFIX)
40 #include "gtk/gtkrc.h"
41 #include "gtk/gtkimmodule.h"
42 #include "gtk/gtkversion.h"
45 escape_string (const char *str)
47 GString *result = g_string_new (NULL);
58 g_string_append (result, "\\n");
61 g_string_append (result, "\\\"");
64 /* Replace backslashes in path with forward slashes, so that
65 * it reads in without problems.
68 g_string_append (result, "/");
72 g_string_append_c (result, c);
77 return g_string_free (result, FALSE);
81 print_escaped (const char *str)
83 char *tmp = escape_string (str);
84 g_printf ("\"%s\" ", tmp);
89 query_module (const char *dir, const char *name)
91 void (*list) (const GtkIMContextInfo ***contexts,
93 void (*init) (GTypeModule *type_module);
95 GtkIMContext *(*create) (const gchar *context_id);
104 gboolean error = FALSE;
106 if (g_path_is_absolute (name))
107 path = g_strdup (name);
109 path = g_build_filename (dir, name, NULL);
111 module = g_module_open (path, 0);
115 g_fprintf (stderr, "Cannot load module %s: %s\n", path, g_module_error());
120 g_module_symbol (module, "im_module_list", &list_ptr) &&
121 g_module_symbol (module, "im_module_init", &init_ptr) &&
122 g_module_symbol (module, "im_module_exit", &exit_ptr) &&
123 g_module_symbol (module, "im_module_create", &create_ptr))
125 const GtkIMContextInfo **contexts;
134 print_escaped (path);
135 fputs ("\n", stdout);
137 (*list) (&contexts, &n_contexts);
139 for (i=0; i<n_contexts; i++)
141 print_escaped (contexts[i]->context_id);
142 print_escaped (contexts[i]->context_name);
143 print_escaped (contexts[i]->domain);
144 print_escaped (contexts[i]->domain_dirname);
145 print_escaped (contexts[i]->default_locales);
146 fputs ("\n", stdout);
148 fputs ("\n", stdout);
152 g_fprintf (stderr, "%s does not export GTK+ IM module API: %s\n", path,
159 g_module_close (module);
164 int main (int argc, char **argv)
169 gboolean error = FALSE;
171 g_printf ("# GTK+ Input Method Modules file\n"
172 "# Automatically generated file, do not edit\n"
173 "# Created by %s from gtk+-%d.%d.%d\n"
176 GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
179 if (argc == 1) /* No arguments given */
183 GHashTable *dirs_done;
185 path = gtk_rc_get_im_module_path ();
187 g_printf ("# ModulesPath = %s\n#\n", path);
189 dirs = pango_split_file_list (path);
190 dirs_done = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
192 for (i = 0; dirs[i]; i++)
193 if (!g_hash_table_lookup (dirs_done, dirs[i]))
195 GDir *dir = g_dir_open (dirs[i], 0, NULL);
200 while ((dent = g_dir_read_name (dir)))
202 if (g_str_has_suffix (dent, SOEXT))
203 error |= query_module (dirs[i], dent);
209 g_hash_table_insert (dirs_done, dirs[i], GUINT_TO_POINTER (TRUE));
212 g_hash_table_destroy (dirs_done);
216 cwd = g_get_current_dir ();
218 for (i = 1; i < argc; i++)
219 error |= query_module (cwd, argv[i]);
224 return error ? 1 : 0;