diff options
author | Owen Taylor <otaylor@redhat.com> | 2000-06-30 22:08:26 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2000-06-30 22:08:26 +0000 |
commit | b49e8181c16e91afc0b2e771243f9adab9bc8b5d (patch) | |
tree | f3b463eec927649a43bd0b22464a5118f0b0d4a7 /pango/modules.c | |
parent | 036da71c38c9d81a087f20079cc7b96154fc5a3c (diff) | |
download | pango-b49e8181c16e91afc0b2e771243f9adab9bc8b5d.tar.gz |
A bunch of simple functions for reading from files, manipulating strings
Fri Jun 30 16:46:31 2000 Owen Taylor <otaylor@redhat.com>
* pango/pango-utils.[ch] Makefile.am: A bunch of simple functions
for reading from files, manipulating strings as necessary for
config files. Also, a simple gnome-config/win.ini style
config file reader.
* pango/modules.c: Remove DOTFILES stuff. Instead, read names
of modules file from pangorc. (Which can be set from PANGO_RC_FILE).
Rewrite parsing code using pango-utils.c.
* pango/pangox-fontmap.c: Read list of files from
PangoX/AliasFiles key. Rewrite parsing code for alias files using
pango-utils.c.
* examples/pangox.aliases: Move to new name from pangox_aliases,
reformat using new parsing code.
* examples/pangorc (AliasFiles) examples/pango-viewer: Add a
pangorc file for in-place testing.
* pango/querymodules.c (main): Add comment to the top of
the output indicating that the file should not be hand-edited.
Diffstat (limited to 'pango/modules.c')
-rw-r--r-- | pango/modules.c | 220 |
1 files changed, 89 insertions, 131 deletions
diff --git a/pango/modules.c b/pango/modules.c index fcd42813..b7572aac 100644 --- a/pango/modules.c +++ b/pango/modules.c @@ -22,12 +22,13 @@ #include <ctype.h> #include <stdio.h> #include <string.h> -#include <dirent.h> #include <limits.h> +#include <errno.h> #include <gmodule.h> #include "pango-modules.h" +#include "pango-utils.h" #include "modules.h" typedef struct _PangoMapInfo PangoMapInfo; @@ -165,31 +166,6 @@ pango_engine_pair_get_engine (PangoEnginePair *pair) return pair->engine; } - -static char * -readline(FILE *file) -{ - static GString *bufstring = NULL; - int c; - - if (!bufstring) - bufstring = g_string_new (NULL); - else - g_string_truncate (bufstring, 0); - - while ((c = getc(file)) != EOF) - { - g_string_append_c (bufstring, c); - if (c == '\n') - break; - } - - if (bufstring->len == 0) - return NULL; - else - return g_strdup (bufstring->str); -} - static void add_included_modules (void) { @@ -217,87 +193,88 @@ add_included_modules (void) } static gboolean /* Returns true if succeeded, false if failed */ -process_module_file(FILE *module_file) +process_module_file (FILE *module_file) { - char *line; + GString *line_buf = g_string_new (NULL); + GString *tmp_buf = g_string_new (NULL); + gboolean have_error = FALSE; - while ((line = readline (module_file))) + while (pango_read_line (module_file, line_buf)) { PangoEnginePair *pair = g_new (PangoEnginePair, 1); PangoEngineRange *range; - GList *ranges; + GList *ranges = NULL; GList *tmp_list; - char *p, *q; + + const char *p, *q; int i; - int start; - int end; + int start, end; pair->included = FALSE; - p = line; - q = line; - ranges = NULL; + p = line_buf->str; + + if (!pango_skip_space (&p)) + continue; /* Break line into words on whitespace */ i = 0; while (1) { - if (!*p || isspace(*p)) + if (!pango_scan_string (&p, tmp_buf)) { - switch (i) - { - case 0: - pair->load_info = g_strndup (q, p-q); - break; - case 1: - pair->info.id = g_strndup (q, p-q); - break; - case 2: - pair->info.engine_type = g_strndup (q, p-q); - break; - case 3: - pair->info.render_type = g_strndup (q, p-q); - break; - default: - range = g_new (PangoEngineRange, 1); - if (sscanf(q, "%d-%d:", &start, &end) != 2) - { - fprintf(stderr, "Error reading pango.modules"); - return FALSE; - } - q = strchr (q, ':'); - if (!q) - { - fprintf(stderr, "Error reading pango.modules"); - return FALSE; - } - q++; - range->start = start; - range->end = end; - range->langs = g_strndup (q, p-q); + have_error = TRUE; + goto error; + } - ranges = g_list_prepend (ranges, range); + switch (i) + { + case 0: + pair->load_info = g_strdup (tmp_buf->str); + break; + case 1: + pair->info.id = g_strdup (tmp_buf->str); + break; + case 2: + pair->info.engine_type = g_strdup (tmp_buf->str); + break; + case 3: + pair->info.render_type = g_strdup (tmp_buf->str); + break; + default: + range = g_new (PangoEngineRange, 1); + if (sscanf(tmp_buf->str, "%d-%d:", &start, &end) != 2) + { + fprintf(stderr, "Error reading modules file"); + have_error = TRUE; + goto error; + } + q = strchr (tmp_buf->str, ':'); + if (!q) + { + fprintf(stderr, "Error reading modules file"); + have_error = TRUE; + goto error; } + q++; + range->start = start; + range->end = end; + range->langs = g_strdup (tmp_buf->str); - i++; - - do - p++; - while (*p && isspace(*p)); - - if (!*p) - break; - - q = p; + ranges = g_list_prepend (ranges, range); } - else - p++; - } + if (!pango_skip_space (&p)) + break; + + i++; + } + if (i<3) { - fprintf(stderr, "Error reading pango.modules"); - return FALSE; + fprintf(stderr, "Error reading modules file"); + have_error = TRUE; + goto error; } ranges = g_list_reverse (ranges); @@ -311,13 +288,19 @@ process_module_file(FILE *module_file) tmp_list = tmp_list->next; } + pair->engine = NULL; + + engines = g_list_prepend (engines, pair); + + error: g_list_foreach (ranges, (GFunc)g_free, NULL); g_list_free (ranges); - g_free (line); - - pair->engine = NULL; - engines = g_list_prepend (engines, pair); + if (have_error) + { + g_free(pair); + return FALSE; + } } return TRUE; @@ -327,57 +310,32 @@ static void read_modules (void) { FILE *module_file; - gboolean read_module_file = FALSE; - /* FIXME FIXME FIXME - this is a potential security problem from leaving - * pango.modules files scattered around to trojan modules. - */ - module_file = fopen ("pango.modules", "r"); - if(module_file) - { - read_module_file = read_module_file || process_module_file(module_file); - process_module_file(module_file); - fclose(module_file); - } - else - { - DIR *dirh; - - dirh = opendir(DOTMODULEDIR); - if(dirh) - { - struct dirent *dent; + char *file_str = pango_config_key_get ("Pango/ModuleFiles"); + char **files; + int n; - while((dent = readdir(dirh))) - { - char fullfn[PATH_MAX]; - char *ctmp; + if (!file_str) + file_str = g_strdup (SYSCONFDIR "/pango/pango.modules"); - if(dent->d_name[0] == '.') - continue; + files = pango_split_file_list (file_str); - ctmp = strrchr(dent->d_name, '.'); - if(!ctmp || strcmp(ctmp, ".modules") != 0) - continue; + n = 0; + while (files[n]) + n++; - g_snprintf(fullfn, sizeof(fullfn), DOTMODULEDIR "/%s", dent->d_name); - module_file = fopen(fullfn, "r"); - if(module_file) - { - read_module_file = read_module_file || process_module_file(module_file); - fclose(module_file); - } - } - } + while (n-- > 0) + { + module_file = fopen (files[n], "r"); + if (!module_file) + g_warning ("Error opening module file '%s': %s\n", files[n], g_strerror (errno)); - closedir(dirh); + process_module_file(module_file); + fclose(module_file); } - if (!read_module_file) - { - fprintf(stderr, "Could not load any module files!\n"); - /* FIXME: Error */ - } + g_strfreev (files); + g_free (file_str); } static void |