X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fqueryimmodules.c;h=f4e561de449d94e7dec7153d3aae49662a0960e5;hb=d97861bd8b338c3d25d7ffb5496edee9eee9bfbb;hp=4c46a8842d9f03777fb0368c3d07f9fbb81ebcf6;hpb=53dd05475bea9a6c0152e1d5a88410721c1bd06f;p=~andy%2Fgtk
diff --git a/gtk/queryimmodules.c b/gtk/queryimmodules.c
index 4c46a8842..f4e561de4 100644
--- a/gtk/queryimmodules.c
+++ b/gtk/queryimmodules.c
@@ -1,7 +1,7 @@
/* GTK+
* querymodules.c:
*
- * Copyright (C) 2000 Red Hat Software
+ * Copyright (C) 2000-2010 Red Hat Software
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -10,20 +10,17 @@
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see .
*/
-#include
+#include "config.h"
#include
#include
-#include
#include
#include
@@ -37,62 +34,65 @@
#define SOEXT ("." G_MODULE_SUFFIX)
#endif
-#include "gtk/gtkrc.h"
-#include "gtk/gtkimmodule.h"
+#include "gtk/gtkimcontextinfo.h"
#include "gtk/gtkversion.h"
-static char *
-escape_string (const char *str)
-{
- GString *result = g_string_new (NULL);
+#define GDK_DISABLE_DEPRECATION_WARNINGS
+
+#include "gtk/deprecated/gtkrc.h"
+static void
+escape_string (GString *contents, const char *str)
+{
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;
+ {
+ case '\0':
+ goto done;
+ case '\n':
+ g_string_append (contents, "\\n");
+ break;
+ case '\"':
+ g_string_append (contents, "\\\"");
+ 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);
- }
+ /* Replace backslashes in path with forward slashes, so that
+ * it reads in without problems.
+ */
+ case '\\':
+ g_string_append (contents, "/");
+ break;
+#endif
+ default:
+ g_string_append_c (contents, c);
+ }
}
- done:
- return g_string_free (result, FALSE);
+ done:;
}
static void
-print_escaped (const char *str)
+print_escaped (GString *contents, const char *str)
{
- char *tmp = escape_string (str);
- g_printf ("\"%s\" ", tmp);
- g_free (tmp);
+ g_string_append_c (contents, '"');
+ escape_string (contents, str);
+ g_string_append_c (contents, '"');
+ g_string_append_c (contents, ' ');
}
static gboolean
-query_module (const char *dir, const char *name)
+query_module (const char *dir, const char *name, GString *contents)
{
void (*list) (const GtkIMContextInfo ***contexts,
- guint *n_contexts);
- void (*init) (GTypeModule *type_module);
- void (*exit) (void);
- GtkIMContext *(*create) (const gchar *context_id);
+ guint *n_contexts);
+
+ gpointer list_ptr;
+ gpointer init_ptr;
+ gpointer exit_ptr;
+ gpointer create_ptr;
GModule *module;
gchar *path;
@@ -102,7 +102,7 @@ query_module (const char *dir, const char *name)
path = g_strdup (name);
else
path = g_build_filename (dir, name, NULL);
-
+
module = g_module_open (path, 0);
if (!module)
@@ -110,37 +110,39 @@ query_module (const char *dir, const char *name)
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", &list_ptr) &&
+ g_module_symbol (module, "im_module_init", &init_ptr) &&
+ g_module_symbol (module, "im_module_exit", &exit_ptr) &&
+ g_module_symbol (module, "im_module_create", &create_ptr))
{
const GtkIMContextInfo **contexts;
guint n_contexts;
int i;
- print_escaped (path);
- fputs ("\n", stdout);
+ list = list_ptr;
+
+ print_escaped (contents, path);
+ g_string_append_c (contents, '\n');
(*list) (&contexts, &n_contexts);
- for (i=0; icontext_id);
- print_escaped (contexts[i]->context_name);
- print_escaped (contexts[i]->domain);
- print_escaped (contexts[i]->domain_dirname);
- print_escaped (contexts[i]->default_locales);
- fputs ("\n", stdout);
- }
- fputs ("\n", stdout);
+ for (i = 0; i < n_contexts; i++)
+ {
+ print_escaped (contents, contexts[i]->context_id);
+ print_escaped (contents, contexts[i]->context_name);
+ print_escaped (contents, contexts[i]->domain);
+ print_escaped (contents, contexts[i]->domain_dirname);
+ print_escaped (contents, contexts[i]->default_locales);
+ g_string_append_c (contents, '\n');
+ }
+ g_string_append_c (contents, '\n');
}
else
{
g_fprintf (stderr, "%s does not export GTK+ IM module API: %s\n", path,
- g_module_error ());
+ g_module_error ());
error = TRUE;
}
@@ -149,7 +151,7 @@ query_module (const char *dir, const char *name)
g_module_close (module);
return error;
-}
+}
int main (int argc, char **argv)
{
@@ -157,16 +159,26 @@ int main (int argc, char **argv)
int i;
char *path;
gboolean error = FALSE;
+ gchar *cache_file = NULL;
+ gint first_file = 1;
+ GString *contents;
- 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 && strcmp (argv[1], "--update-cache") == 0)
+ {
+ cache_file = gtk_rc_get_im_module_file ();
+ first_file = 2;
+ }
+ contents = g_string_new ("");
+ g_string_append_printf (contents,
+ "# 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 */
+ if (argc == first_file) /* No file arguments given */
{
char **dirs;
int i;
@@ -174,27 +186,27 @@ int main (int argc, char **argv)
path = gtk_rc_get_im_module_path ();
- g_printf ("# ModulesPath = %s\n#\n", path);
+ g_string_append_printf (contents, "# 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++)
+ for (i = 0; dirs[i]; i++)
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);
- }
+ 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, contents);
+ }
+
+ g_dir_close (dir);
+ }
g_hash_table_insert (dirs_done, dirs[i], GUINT_TO_POINTER (TRUE));
}
@@ -204,12 +216,29 @@ int main (int argc, char **argv)
else
{
cwd = g_get_current_dir ();
-
- for (i=1; istr, -1, &err))
+ {
+ g_fprintf (stderr, "%s\n", err->message);
+ error = 1;
+ }
+ }
+ else
+ g_print ("%s\n", contents->str);
+ }
+
return error ? 1 : 0;
}