summaryrefslogtreecommitdiff
path: root/pango/pango-utils.c
diff options
context:
space:
mode:
authorTor Lillqvist <tml@novell.com>2007-11-16 23:27:07 +0000
committerTor Lillqvist <tml@src.gnome.org>2007-11-16 23:27:07 +0000
commitfe95e6293d3923b33108198409e21c27a97ccb9d (patch)
treed6569184ff94f11113f1141b95131e4ad9233efc /pango/pango-utils.c
parent4313176f9884c37962327a5757546f9f258da423 (diff)
downloadpango-fe95e6293d3923b33108198409e21c27a97ccb9d.tar.gz
Factor out the common code from read_builtin_aliases() and
2007-11-16 Tor Lillqvist <tml@novell.com> * pango/pango-utils.c (handle_alias_line): Factor out the common code from read_builtin_aliases() and read_alias_file(). (#492517) svn path=/trunk/; revision=2498
Diffstat (limited to 'pango/pango-utils.c')
-rw-r--r--pango/pango-utils.c279
1 files changed, 111 insertions, 168 deletions
diff --git a/pango/pango-utils.c b/pango/pango-utils.c
index 2b6b1e06..51d8fd01 100644
--- a/pango/pango-utils.c
+++ b/pango/pango-utils.c
@@ -1239,117 +1239,148 @@ alias_free (struct PangoAlias *alias)
g_slice_free (struct PangoAlias, alias);
}
-#ifdef G_OS_WIN32
-
-static const char *builtin_aliases[] = {
- "courier = \"courier new\"",
- "\"segoe ui\" = \"segoe ui,arial unicode ms,browallia new,mingliu,simhei,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"",
- "tahoma = \"tahoma,arial unicode ms,browallia new,mingliu,simhei,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"",
- /* It sucks to use the same GulimChe, MS Gothic, Sylfaen, Kartika,
- * Latha, Mangal and Raavi fonts for all three of sans, serif and
- * mono, but it isn't like there would be much choice. For most
- * non-Latin scripts that Windows includes any font at all for, it
- * has ony one. One solution is to install the free DejaVu fonts
- * that are popular on Linux. They are listed here first.
- */
- "sans = \"dejavu sans,tahoma,arial unicode ms,browallia new,mingliu,simhei,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"",
- "sans-serif = \"dejavu sans,tahoma,arial unicode ms,browallia new,mingliu,simhei,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"",
- "serif = \"dejavu serif,georgia,angsana new,mingliu,simsun,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"",
- "mono = \"dejavu sans mono,courier new,courier monothai,mingliu,simsun,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"",
- "monospace = \"dejavu sans mono,courier new,courier monothai,mingliu,simsun,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\""
-};
-
static void
-read_builtin_aliases (void)
+handle_alias_line (GString *line_buffer,
+ char **errstring)
{
-
- GString *line_buffer;
GString *tmp_buffer1;
GString *tmp_buffer2;
const char *pos;
- int line;
struct PangoAlias alias_key;
struct PangoAlias *alias;
char **new_families;
int n_new;
int i;
- line_buffer = g_string_new (NULL);
tmp_buffer1 = g_string_new (NULL);
tmp_buffer2 = g_string_new (NULL);
-#define ASSERT(x) if (!(x)) g_error ("Assertion failed: " #x)
+ gboolean append = FALSE;
+
+ pos = line_buffer->str;
+ if (!pango_skip_space (&pos))
+ return;
- for (line = 0; line < G_N_ELEMENTS (builtin_aliases); line++)
+ if (!pango_scan_string (&pos, tmp_buffer1) ||
+ !pango_skip_space (&pos))
{
- gboolean append = FALSE;
+ *errstring = g_strdup ("Line is not of the form KEY=VALUE or KEY+=VALUE");
+ goto error;
+ }
- g_string_assign (line_buffer, builtin_aliases[line]);
+ if (*pos == '+')
+ {
+ append = TRUE;
+ pos++;
+ }
- pos = line_buffer->str;
+ if (*(pos++) != '=')
+ {
+ *errstring = g_strdup ("Line is not of the form KEY=VALUE or KEY+=VALUE");
+ goto error;
+ }
- ASSERT (pango_scan_string (&pos, tmp_buffer1) &&
- pango_skip_space (&pos));
+ if (!pango_scan_string (&pos, tmp_buffer2))
+ {
+ *errstring = g_strdup ("Error parsing value string");
+ goto error;
+ }
+ if (pango_skip_space (&pos))
+ {
+ *errstring = g_strdup ("Junk after value string");
+ goto error;
+ }
- if (*pos == '+')
- {
- append = TRUE;
- pos++;
- }
+ alias_key.alias = g_ascii_strdown (tmp_buffer1->str, -1);
- ASSERT (*(pos++) == '=');
+ /* Remove any existing values */
+ alias = g_hash_table_lookup (pango_aliases_ht, &alias_key);
- ASSERT (pango_scan_string (&pos, tmp_buffer2));
+ if (!alias)
+ {
+ alias = g_slice_new0 (struct PangoAlias);
+ alias->alias = alias_key.alias;
+
+ g_hash_table_insert (pango_aliases_ht,
+ alias, alias);
+ }
+ else
+ g_free (alias_key.alias);
- ASSERT (!pango_skip_space (&pos));
+ new_families = g_strsplit (tmp_buffer2->str, ",", -1);
- alias_key.alias = g_ascii_strdown (tmp_buffer1->str, -1);
+ n_new = 0;
+ while (new_families[n_new])
+ n_new++;
- /* Remove any existing values */
- alias = g_hash_table_lookup (pango_aliases_ht, &alias_key);
+ if (alias->families && append)
+ {
+ alias->families = g_realloc (alias->families,
+ sizeof (char *) *(n_new + alias->n_families));
+ for (i = 0; i < n_new; i++)
+ alias->families[alias->n_families + i] = new_families[i];
+ g_free (new_families);
+ alias->n_families += n_new;
+ }
+ else
+ {
+ for (i = 0; i < alias->n_families; i++)
+ g_free (alias->families[i]);
+ g_free (alias->families);
+
+ alias->families = new_families;
+ alias->n_families = n_new;
+ }
- if (!alias)
- {
- alias = g_slice_new0 (struct PangoAlias);
- alias->alias = alias_key.alias;
+ error:
+
+ g_string_free (tmp_buffer1, TRUE);
+ g_string_free (tmp_buffer2, TRUE);
+}
- g_hash_table_insert (pango_aliases_ht,
- alias, alias);
- }
- else
- g_free (alias_key.alias);
+#ifdef G_OS_WIN32
- new_families = g_strsplit (tmp_buffer2->str, ",", -1);
+static const char *builtin_aliases[] = {
+ "courier = \"courier new\"",
+ "\"segoe ui\" = \"segoe ui,arial unicode ms,browallia new,mingliu,simhei,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"",
+ "tahoma = \"tahoma,arial unicode ms,browallia new,mingliu,simhei,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"",
+ /* It sucks to use the same GulimChe, MS Gothic, Sylfaen, Kartika,
+ * Latha, Mangal and Raavi fonts for all three of sans, serif and
+ * mono, but it isn't like there would be much choice. For most
+ * non-Latin scripts that Windows includes any font at all for, it
+ * has ony one. One solution is to install the free DejaVu fonts
+ * that are popular on Linux. They are listed here first.
+ */
+ "sans = \"dejavu sans,tahoma,arial unicode ms,browallia new,mingliu,simhei,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"",
+ "sans-serif = \"dejavu sans,tahoma,arial unicode ms,browallia new,mingliu,simhei,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"",
+ "serif = \"dejavu serif,georgia,angsana new,mingliu,simsun,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"",
+ "mono = \"dejavu sans mono,courier new,courier monothai,mingliu,simsun,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\"",
+ "monospace = \"dejavu sans mono,courier new,courier monothai,mingliu,simsun,gulimche,ms gothic,sylfaen,kartika,latha,mangal,raavi\""
+};
- n_new = 0;
- while (new_families[n_new])
- n_new++;
+static void
+read_builtin_aliases (void)
+{
- if (alias->families && append)
- {
- alias->families = g_realloc (alias->families,
- sizeof (char *) *(n_new + alias->n_families));
- for (i = 0; i < n_new; i++)
- alias->families[alias->n_families + i] = new_families[i];
- g_free (new_families);
- alias->n_families += n_new;
- }
- else
- {
- for (i = 0; i < alias->n_families; i++)
- g_free (alias->families[i]);
- g_free (alias->families);
+ GString *line_buffer;
+ char *errstring = NULL;
+ int line;
- alias->families = new_families;
- alias->n_families = n_new;
- }
+ line_buffer = g_string_new (NULL);
+
+ for (line = 0; line < G_N_ELEMENTS (builtin_aliases) && errstring == NULL; line++)
+ {
+ g_string_assign (line_buffer, builtin_aliases[line]);
+ handle_alias_line (line_buffer, &errstring);
}
-#undef ASSERT
+ if (errstring)
+ {
+ g_error ("error in built-in aliases:%d: %s\n", line, errstring);
+ g_free (errstring);
+ }
g_string_free (line_buffer, TRUE);
- g_string_free (tmp_buffer1, TRUE);
- g_string_free (tmp_buffer2, TRUE);
}
#endif
@@ -1360,111 +1391,25 @@ read_alias_file (const char *filename)
FILE *file;
GString *line_buffer;
- GString *tmp_buffer1;
- GString *tmp_buffer2;
char *errstring = NULL;
- const char *pos;
int line = 0;
- struct PangoAlias alias_key;
- struct PangoAlias *alias;
- char **new_families;
- int n_new;
- int i;
file = g_fopen (filename, "r");
if (!file)
return;
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))
+ while (pango_read_line (file, line_buffer) &&
+ errstring == NULL)
{
- gboolean append = FALSE;
line++;
-
- pos = line_buffer->str;
- if (!pango_skip_space (&pos))
- continue;
-
- if (!pango_scan_string (&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_scan_string (&pos, tmp_buffer2))
- {
- errstring = g_strdup ("Error parsing value string");
- goto error;
- }
- if (pango_skip_space (&pos))
- {
- errstring = g_strdup ("Junk after value string");
- goto error;
- }
-
- alias_key.alias = g_ascii_strdown (tmp_buffer1->str, -1);
-
- /* Remove any existing values */
- alias = g_hash_table_lookup (pango_aliases_ht, &alias_key);
-
- if (!alias)
- {
- alias = g_slice_new0 (struct PangoAlias);
- alias->alias = alias_key.alias;
-
- g_hash_table_insert (pango_aliases_ht,
- alias, alias);
- }
- else
- g_free (alias_key.alias);
-
- new_families = g_strsplit (tmp_buffer2->str, ",", -1);
-
- n_new = 0;
- while (new_families[n_new])
- n_new++;
-
- if (alias->families && append)
- {
- alias->families = g_realloc (alias->families,
- sizeof (char *) *(n_new + alias->n_families));
- for (i = 0; i < n_new; i++)
- alias->families[alias->n_families + i] = new_families[i];
- g_free (new_families);
- alias->n_families += n_new;
- }
- else
- {
- for (i = 0; i < alias->n_families; i++)
- g_free (alias->families[i]);
- g_free (alias->families);
-
- alias->families = new_families;
- alias->n_families = n_new;
- }
+ handle_alias_line (line_buffer, &errstring);
}
- if (ferror (file))
+ if (errstring == NULL && ferror (file))
errstring = g_strdup (g_strerror(errno));
- error:
-
if (errstring)
{
g_warning ("error reading alias file: %s:%d: %s\n", filename, line, errstring);
@@ -1472,8 +1417,6 @@ read_alias_file (const char *filename)
}
g_string_free (line_buffer, TRUE);
- g_string_free (tmp_buffer1, TRUE);
- g_string_free (tmp_buffer2, TRUE);
fclose (file);
}