summaryrefslogtreecommitdiff
path: root/gtk/gtkimmodule.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2015-05-16 18:54:35 -0400
committerMatthias Clasen <mclasen@redhat.com>2015-12-29 08:09:23 -0500
commit9950764f1224c61ad482c9ccfb1bf7e7667b10f7 (patch)
tree36fc735aebcdebe3cf214d9a61f74cdc662d7ccb /gtk/gtkimmodule.c
parent1e1af62beed4f89722a6c88a23a344a6e0828244 (diff)
downloadgtk+-9950764f1224c61ad482c9ccfb1bf7e7667b10f7.tar.gz
Drop deprecated pango-utils api
Copy the few parsing functions we need.
Diffstat (limited to 'gtk/gtkimmodule.c')
-rw-r--r--gtk/gtkimmodule.c179
1 files changed, 158 insertions, 21 deletions
diff --git a/gtk/gtkimmodule.c b/gtk/gtkimmodule.c
index a7f7b979d0..405d87626f 100644
--- a/gtk/gtkimmodule.c
+++ b/gtk/gtkimmodule.c
@@ -314,6 +314,147 @@ add_builtin_module (const gchar *module_name,
return module;
}
+static gboolean
+scan_string (const char **pos, GString *out)
+{
+ const char *p = *pos, *q = *pos;
+ char *tmp, *tmp2;
+ gboolean quoted;
+
+ while (g_ascii_isspace (*p))
+ p++;
+
+ if (!*p)
+ return FALSE;
+ else if (*p == '"')
+ {
+ p++;
+ quoted = FALSE;
+ for (q = p; (*q != '"') || quoted; q++)
+ {
+ if (!*q)
+ return FALSE;
+ quoted = (*q == '\\') && !quoted;
+ }
+
+ tmp = g_strndup (p, q - p);
+ tmp2 = g_strcompress (tmp);
+ g_string_truncate (out, 0);
+ g_string_append (out, tmp2);
+ g_free (tmp);
+ g_free (tmp2);
+ }
+
+ q++;
+ *pos = q;
+
+ return TRUE;
+}
+
+static gboolean
+skip_space (const char **pos)
+{
+ const char *p = *pos;
+
+ while (g_ascii_isspace (*p))
+ p++;
+
+ *pos = p;
+
+ return !(*p == '\0');
+}
+
+static gint
+read_line (FILE *stream, GString *str)
+{
+ gboolean quoted = FALSE;
+ gboolean comment = FALSE;
+ int n_read = 0;
+ int lines = 1;
+
+ flockfile (stream);
+
+ g_string_truncate (str, 0);
+
+ while (1)
+ {
+ int c;
+
+ c = getc_unlocked (stream);
+
+ if (c == EOF)
+ {
+ if (quoted)
+ g_string_append_c (str, '\\');
+
+ goto done;
+ }
+ else
+ n_read++;
+
+ if (quoted)
+ {
+ quoted = FALSE;
+
+ switch (c)
+ {
+ case '#':
+ g_string_append_c (str, '#');
+ break;
+ case '\r':
+ case '\n':
+ {
+ int next_c = getc_unlocked (stream);
+
+ if (!(next_c == EOF ||
+ (c == '\r' && next_c == '\n') ||
+ (c == '\n' && next_c == '\r')))
+ ungetc (next_c, stream);
+
+ lines++;
+
+ break;
+ }
+ default:
+ g_string_append_c (str, '\\');
+ g_string_append_c (str, c);
+ }
+ }
+ else
+ {
+ switch (c)
+ {
+ case '#':
+ comment = TRUE;
+ break;
+ case '\\':
+ if (!comment)
+ quoted = TRUE;
+ break;
+ case '\n':
+ {
+ int next_c = getc_unlocked (stream);
+
+ if (!(c == EOF ||
+ (c == '\r' && next_c == '\n') ||
+ (c == '\n' && next_c == '\r')))
+ ungetc (next_c, stream);
+
+ goto done;
+ }
+ default:
+ if (!comment)
+ g_string_append_c (str, c);
+ }
+ }
+ }
+
+ done:
+ funlockfile (stream);
+
+ return (n_read > 0) ? lines : 0;
+}
+
static void
gtk_im_module_initialize (void)
{
@@ -400,14 +541,13 @@ gtk_im_module_initialize (void)
return;
}
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- while (!have_error && pango_read_line (file, line_buf))
+ while (!have_error && read_line (file, line_buf))
{
const char *p;
-
+
p = line_buf->str;
- if (!pango_skip_space (&p))
+ if (!skip_space (&p))
{
/* Blank line marking the end of a module
*/
@@ -417,7 +557,7 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
module = NULL;
infos = NULL;
}
-
+
continue;
}
@@ -427,11 +567,9 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
*/
module = g_object_new (GTK_TYPE_IM_MODULE, NULL);
- if (!pango_scan_string (&p, tmp_buf) ||
- pango_skip_space (&p))
+ if (!scan_string (&p, tmp_buf) || skip_space (&p))
{
- g_warning ("Error parsing context info in '%s'\n %s",
- filename, line_buf->str);
+ g_warning ("Error parsing context info in '%s'\n %s", filename, line_buf->str);
have_error = TRUE;
}
@@ -444,45 +582,44 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
else
{
GtkIMContextInfo *info = g_new0 (GtkIMContextInfo, 1);
-
+
/* Read information about a context type
*/
- if (!pango_scan_string (&p, tmp_buf))
+ if (!scan_string (&p, tmp_buf))
goto context_error;
info->context_id = g_strdup (tmp_buf->str);
- if (!pango_scan_string (&p, tmp_buf))
+ if (!scan_string (&p, tmp_buf))
goto context_error;
info->context_name = g_strdup (tmp_buf->str);
- if (!pango_scan_string (&p, tmp_buf))
+ if (!scan_string (&p, tmp_buf))
goto context_error;
info->domain = g_strdup (tmp_buf->str);
- if (!pango_scan_string (&p, tmp_buf))
+ if (!scan_string (&p, tmp_buf))
goto context_error;
+
info->domain_dirname = g_strdup (tmp_buf->str);
#ifdef G_OS_WIN32
correct_localedir_prefix ((char **) &info->domain_dirname);
#endif
- if (!pango_scan_string (&p, tmp_buf))
+ if (!scan_string (&p, tmp_buf))
goto context_error;
info->default_locales = g_strdup (tmp_buf->str);
- if (pango_skip_space (&p))
+ if (skip_space (&p))
goto context_error;
infos = g_slist_prepend (infos, info);
continue;
context_error:
- g_warning ("Error parsing context info in '%s'\n %s",
- filename, line_buf->str);
+ g_warning ("Error parsing context info in '%s'\n %s", filename, line_buf->str);
have_error = TRUE;
}
}
-G_GNUC_END_IGNORE_DEPRECATIONS
if (have_error)
{
@@ -499,8 +636,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS
}
static gint
-compare_gtkimcontextinfo_name(const GtkIMContextInfo **a,
- const GtkIMContextInfo **b)
+compare_gtkimcontextinfo_name (const GtkIMContextInfo **a,
+ const GtkIMContextInfo **b)
{
return g_utf8_collate ((*a)->context_name, (*b)->context_name);
}