summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2006-01-31 22:56:14 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2006-01-31 22:56:14 +0000
commitce4f52f71600a4480c17d51e43c889eba17cf70c (patch)
tree8ae8fe1598eb6c7ffb1d3b16930436a1948bbf68
parenta4d93baaf30e7e5befa210594fed884fe7bbab31 (diff)
downloadpango-ce4f52f71600a4480c17d51e43c889eba17cf70c.tar.gz
Bug 328313 – Use GKeyFile for parsing pangorc Patch from Antoine
2006-01-31 Behdad Esfahbod <behdad@gnome.org> Bug 328313 – Use GKeyFile for parsing pangorc Patch from Antoine Dopffer. * pango/pango-utils.c (read_config_file): Use GKeyFile to parse config file.
-rw-r--r--ChangeLog8
-rw-r--r--pango/pango-utils.c178
2 files changed, 64 insertions, 122 deletions
diff --git a/ChangeLog b/ChangeLog
index 712ce948..0b90616f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2006-01-31 Behdad Esfahbod <behdad@gnome.org>
+ Bug 328313 – Use GKeyFile for parsing pangorc
+ Patch from Antoine Dopffer.
+
+ * pango/pango-utils.c (read_config_file): Use GKeyFile to parse
+ config file.
+
+2006-01-31 Behdad Esfahbod <behdad@gnome.org>
+
* pango/fonts.c, pango/glyphstring.c pango/pango-attributes.c
pango/pango-color.c, pango/pango-context.c
pango/pango-coverage.c, pango/pango-fontset.c
diff --git a/pango/pango-utils.c b/pango/pango-utils.c
index eae158f9..a654dd0d 100644
--- a/pango/pango-utils.c
+++ b/pango/pango-utils.c
@@ -456,137 +456,71 @@ static GHashTable *config_hash = NULL;
static void
read_config_file (const char *filename, gboolean enoent_error)
{
- FILE *file;
-
- GString *line_buffer;
- GString *tmp_buffer1;
- GString *tmp_buffer2;
- char *errstring = NULL;
- const char *pos;
- char *section = NULL;
- int line = 0;
-
- file = g_fopen (filename, "r");
- if (!file)
- {
- if (errno != ENOENT || enoent_error)
- g_printerr ("Pango:%s: Error opening config file: %s\n",
- filename, g_strerror (errno));
- return;
- }
+ GKeyFile *key_file = g_key_file_new();
+ GError *key_file_error = NULL;
+ gchar **groups;
+ gsize groups_length = 0;
+ gsize i = 0;
- line_buffer = g_string_new (NULL);
- tmp_buffer1 = g_string_new (NULL);
- tmp_buffer2 = g_string_new (NULL);
-
- while (pango_read_line (file, line_buffer))
+ if (!g_key_file_load_from_file(key_file,filename, 0, &key_file_error))
{
- line++;
-
- pos = line_buffer->str;
- if (!pango_skip_space (&pos))
- continue;
-
- if (*pos == '[') /* Section */
+ if (key_file_error)
{
- pos++;
- if (!pango_skip_space (&pos) ||
- !pango_scan_word (&pos, tmp_buffer1) ||
- !pango_skip_space (&pos) ||
- *(pos++) != ']' ||
- pango_skip_space (&pos))
+ if (key_file_error->domain != G_FILE_ERROR || key_file_error->code != G_FILE_ERROR_NOENT || enoent_error)
{
- errstring = g_strdup ("Error parsing [SECTION] declaration");
- goto error;
+ g_warning ("error opening config file '%s': %s\n",
+ filename, key_file_error->message);
}
-
- section = g_strdup (tmp_buffer1->str);
+ g_error_free(key_file_error);
}
- else /* Key */
+ g_key_file_free(key_file);
+ return;
+ }
+
+ groups = g_key_file_get_groups (key_file, &groups_length);
+ while (i < groups_length)
+ {
+ gsize keys_length = 0;
+ gchar *current_group = groups[i];
+ GError *keys_error = NULL;
+ gsize j = 0;
+ gchar **keys = g_key_file_get_keys(key_file,current_group, &keys_length,&keys_error);
+
+ if (keys)
{
- gboolean empty = FALSE;
- gboolean append = FALSE;
- char *v;
-
- if (!section)
+ while ( j < keys_length)
{
- errstring = g_strdup ("A [SECTION] declaration must occur first");
- goto error;
- }
-
- if (!pango_scan_word (&pos, tmp_buffer1) ||
- !pango_skip_space (&pos))
- {
- errstring = g_strdup ("Line is not of the form KEY=VALUE or KEY+=VALUE");
- goto error;
- }
- if (*pos == '+')
- {
- append = TRUE;
- pos++;
- }
-
- if (*(pos++) != '=')
- {
- errstring = g_strdup ("Line is not of the form KEY=VALUE or KEY+=VALUE");
- goto error;
- }
-
- if (!pango_skip_space (&pos))
- {
- empty = TRUE;
- }
- else
- {
- if (!pango_scan_string (&pos, tmp_buffer2))
+ gchar *key = keys[j];
+ GError *key_error = NULL;
+ gchar *value = g_key_file_get_value(key_file,current_group,key, &key_error);
+ if (value != NULL)
{
- errstring = g_strdup ("Error parsing value string");
- goto error;
+ g_hash_table_insert (config_hash,
+ g_strdup (key),
+ g_strdup (value));
+ free(value);
}
- if (pango_skip_space (&pos))
+ if (key_error)
{
- errstring = g_strdup ("Junk after value string");
- goto error;
+ g_warning ("error getting key '%s' in config file '%s'\n",
+ key, filename);
+ g_error_free(key_error);
}
+ j++;
}
-
- g_string_prepend_c (tmp_buffer1, '/');
- g_string_prepend (tmp_buffer1, section);
-
- if (append)
- {
- /* Get any existing value */
- v = g_hash_table_lookup (config_hash, tmp_buffer1->str);
- if (v)
- g_string_prepend (tmp_buffer2, v);
- }
-
- if (!empty)
- {
- g_hash_table_insert (config_hash,
- g_strdup (tmp_buffer1->str),
- g_strdup (tmp_buffer2->str));
- }
+ g_strfreev(keys);
+
}
+ if (keys_error)
+ {
+ g_warning ("error getting keys in group '%s' of config file '%s'\n",
+ filename, current_group);
+ g_error_free(keys_error);
+ }
+ i++;
}
-
- if (ferror (file))
- errstring = g_strdup (g_strerror(errno));
-
- error:
-
- if (errstring)
- {
- g_printerr ("Pango:%s:%d: %s\n", filename, line, errstring);
- g_free (errstring);
- }
-
- g_free (section);
- g_string_free (line_buffer, TRUE);
- g_string_free (tmp_buffer1, TRUE);
- g_string_free (tmp_buffer2, TRUE);
-
- fclose (file);
+ g_strfreev(groups);
+ g_key_file_free(key_file);
}
static void
@@ -752,7 +686,7 @@ pango_parse_style (const char *str,
break;
}
if (warn)
- g_warning ("Style must be normal, italic, or oblique");
+ g_warning ("style must be normal, italic, or oblique");
return FALSE;
}
@@ -799,7 +733,7 @@ pango_parse_variant (const char *str,
}
if (warn)
- g_warning ("Variant must be normal or small_caps");
+ g_warning ("variant must be normal or small_caps");
return FALSE;
}
@@ -887,7 +821,7 @@ pango_parse_weight (const char *str,
if (*end != '\0')
{
if (warn)
- g_warning ("Cannot parse numerical weight '%s'", str);
+ g_warning ("failed parsing numerical weight '%s'", str);
return FALSE;
}
return TRUE;
@@ -895,7 +829,7 @@ pango_parse_weight (const char *str,
}
if (warn)
- g_warning ("Weight must be ultralight, light, normal, bold, ultrabold, heavy, or an integer");
+ g_warning ("weight must be ultralight, light, normal, bold, ultrabold, heavy, or an integer");
return FALSE;
}
@@ -992,7 +926,7 @@ pango_parse_stretch (const char *str,
}
if (warn)
- g_warning ("Stretch must be ultra_condensed, extra_condensed, condensed, semi_condensed, normal, semi_expanded, expanded, extra_expanded, or ultra_expanded");
+ g_warning ("stretch must be ultra_condensed, extra_condensed, condensed, semi_condensed, normal, semi_expanded, expanded, extra_expanded, or ultra_expanded");
return FALSE;
}
@@ -1709,7 +1643,7 @@ read_alias_file (const char *filename)
if (errstring)
{
- g_printerr ("Pango:%s:%d: %s\n", filename, line, errstring);
+ g_warning ("error reading alias file: %s:%d: %s\n", filename, line, errstring);
g_free (errstring);
}