* Boston, MA 02111-1307, USA.
*/
-#include "config.h"
+#include <config.h>
#include <glib.h>
+#include <glib/gprintf.h>
#include <gmodule.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#include <stdio.h>
-#ifdef G_OS_WIN32
-#define SOEXT ".dll"
+#ifdef USE_LA_MODULES
+#define SOEXT ".la"
#else
-#define SOEXT ".so"
+#define SOEXT ("." G_MODULE_SUFFIX)
#endif
#include <pango/pango-utils.h>
#include "gtk/gtkrc.h"
#include "gtk/gtkimmodule.h"
+#include "gtk/gtkversion.h"
+
+static char *
+escape_string (const char *str)
+{
+ GString *result = g_string_new (NULL);
-void
+ while (TRUE)
+ {
+ char c = *str++;
+
+ switch (c)
+ {
+ case '\0':
+ goto done;
+ case '\n':
+ g_string_append (result, "\\n");
+ break;
+ case '\"':
+ g_string_append (result, "\\\"");
+ break;
+#ifdef G_OS_WIN32
+ /* Replace backslashes in path with forward slashes, so that
+ * it reads in without problems.
+ */
+ case '\\':
+ g_string_append (result, "/");
+ break;
+#endif
+ default:
+ g_string_append_c (result, c);
+ }
+ }
+
+ done:
+ return g_string_free (result, FALSE);
+}
+
+static void
print_escaped (const char *str)
{
- char *tmp = g_strescape (str, NULL);
- printf ("\"%s\" ", tmp);
+ char *tmp = escape_string (str);
+ g_printf ("\"%s\" ", tmp);
g_free (tmp);
}
-gboolean
+static gboolean
query_module (const char *dir, const char *name)
{
void (*list) (const GtkIMContextInfo ***contexts,
if (!module)
{
- fprintf(stderr, "Cannot load module %s: %s\n", path, g_module_error());
+ g_fprintf (stderr, "Cannot load module %s: %s\n", path, g_module_error());
error = TRUE;
}
if (module &&
- g_module_symbol (module, "im_module_list", (gpointer)&list) &&
- g_module_symbol (module, "im_module_init", (gpointer)&init) &&
- g_module_symbol (module, "im_module_exit", (gpointer)&exit) &&
- g_module_symbol (module, "im_module_create", (gpointer)&create))
+ g_module_symbol (module, "im_module_list", (gpointer *) &list) &&
+ g_module_symbol (module, "im_module_init", (gpointer *) &init) &&
+ g_module_symbol (module, "im_module_exit", (gpointer *) &exit) &&
+ g_module_symbol (module, "im_module_create", (gpointer *) &create))
{
const GtkIMContextInfo **contexts;
guint n_contexts;
}
else
{
- fprintf (stderr, "%s does not export GTK+ IM module API: %s\n", path,
- g_module_error());
+ g_fprintf (stderr, "%s does not export GTK+ IM module API: %s\n", path,
+ g_module_error ());
error = TRUE;
}
char *path;
gboolean error = FALSE;
- printf ("# GTK+ Input Method Modules file\n"
- "# Automatically generated file, do not edit\n"
- "#\n");
+ g_printf ("# GTK+ Input Method Modules file\n"
+ "# Automatically generated file, do not edit\n"
+ "# Created by %s from gtk+-%d.%d.%d\n"
+ "#\n",
+ argv[0],
+ GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
+
if (argc == 1) /* No arguments given */
{
char **dirs;
int i;
+ GHashTable *dirs_done;
path = gtk_rc_get_im_module_path ();
- printf ("# ModulesPath = %s\n#\n", path);
+ g_printf ("# ModulesPath = %s\n#\n", path);
dirs = pango_split_file_list (path);
+ dirs_done = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
for (i=0; dirs[i]; i++)
- {
- GDir *dir = g_dir_open (dirs[i], 0, NULL);
- if (dir)
- {
- char *dent;
-
- while ((dent = g_dir_read_name (dir)))
- {
- int len = strlen (dent);
- if (len > 3 && strcmp (dent + len - strlen (SOEXT), SOEXT) == 0)
- error |= query_module (dirs[i], dent);
- }
-
- g_dir_close (dir);
- }
- }
+ if (!g_hash_table_lookup (dirs_done, dirs[i]))
+ {
+ GDir *dir = g_dir_open (dirs[i], 0, NULL);
+ if (dir)
+ {
+ const char *dent;
+
+ while ((dent = g_dir_read_name (dir)))
+ {
+ if (g_str_has_suffix (dent, SOEXT))
+ error |= query_module (dirs[i], dent);
+ }
+
+ g_dir_close (dir);
+ }
+
+ g_hash_table_insert (dirs_done, dirs[i], GUINT_TO_POINTER (TRUE));
+ }
+
+ g_hash_table_destroy (dirs_done);
}
else
{