mirror of https://github.com/GNOME/gimp.git
app: port GimpInterpreterDB and GimpEnvironTable loading to GFileEnumerator
This commit is contained in:
parent
e820f26eec
commit
3ab1084df7
|
@ -47,8 +47,8 @@ struct _GimpEnvironValue
|
|||
|
||||
static void gimp_environ_table_finalize (GObject *object);
|
||||
|
||||
static void gimp_environ_table_load_env_file (const GimpDatafileData *file_data,
|
||||
gpointer user_data);
|
||||
static void gimp_environ_table_load_env_file (GimpEnvironTable *environ_table,
|
||||
GFile *file);
|
||||
static gboolean gimp_environ_table_legal_name (gchar *name);
|
||||
|
||||
static void gimp_environ_table_populate (GimpEnvironTable *environ_table);
|
||||
|
@ -138,8 +138,10 @@ gimp_environ_table_str_equal (gconstpointer v1,
|
|||
|
||||
void
|
||||
gimp_environ_table_load (GimpEnvironTable *environ_table,
|
||||
const gchar *env_path)
|
||||
GList *path)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
g_return_if_fail (GIMP_IS_ENVIRON_TABLE (environ_table));
|
||||
|
||||
gimp_environ_table_clear (environ_table);
|
||||
|
@ -150,10 +152,41 @@ gimp_environ_table_load (GimpEnvironTable *environ_table,
|
|||
g_free,
|
||||
(GDestroyNotify) gimp_environ_table_free_value);
|
||||
|
||||
gimp_datafiles_read_directories (env_path,
|
||||
G_FILE_TEST_EXISTS,
|
||||
gimp_environ_table_load_env_file,
|
||||
environ_table);
|
||||
for (list = path; list; list = g_list_next (list))
|
||||
{
|
||||
GFile *dir = list->data;
|
||||
GFileEnumerator *enumerator;
|
||||
|
||||
enumerator =
|
||||
g_file_enumerate_children (dir,
|
||||
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
|
||||
G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
NULL, NULL);
|
||||
|
||||
if (enumerator)
|
||||
{
|
||||
GFileInfo *info;
|
||||
|
||||
while ((info = g_file_enumerator_next_file (enumerator,
|
||||
NULL, NULL)))
|
||||
{
|
||||
if (! g_file_info_get_is_hidden (info) &&
|
||||
g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR)
|
||||
{
|
||||
GFile *file = g_file_enumerator_get_child (enumerator, info);
|
||||
|
||||
gimp_environ_table_load_env_file (environ_table, file);
|
||||
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
g_object_unref (enumerator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -239,20 +272,23 @@ gimp_environ_table_get_envp (GimpEnvironTable *environ_table)
|
|||
/* private */
|
||||
|
||||
static void
|
||||
gimp_environ_table_load_env_file (const GimpDatafileData *file_data,
|
||||
gpointer user_data)
|
||||
gimp_environ_table_load_env_file (GimpEnvironTable *environ_table,
|
||||
GFile *file)
|
||||
{
|
||||
GimpEnvironTable *environ_table = GIMP_ENVIRON_TABLE (user_data);
|
||||
FILE *env;
|
||||
gchar *path;
|
||||
gchar buffer[4096];
|
||||
gsize len;
|
||||
gchar *name, *value, *separator, *p, *q;
|
||||
GimpEnvironValue *val;
|
||||
|
||||
if (environ_table->verbose)
|
||||
g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (file_data->filename));
|
||||
g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
|
||||
|
||||
path = g_file_get_path (file);
|
||||
env = g_fopen (path, "r");
|
||||
g_free (path);
|
||||
|
||||
env = g_fopen (file_data->filename, "r");
|
||||
if (! env)
|
||||
return;
|
||||
|
||||
|
@ -282,7 +318,7 @@ gimp_environ_table_load_env_file (const GimpDatafileData *file_data,
|
|||
if (name[0] == '\0')
|
||||
{
|
||||
g_message (_("Empty variable name in environment file %s"),
|
||||
gimp_filename_to_utf8 (file_data->filename));
|
||||
gimp_file_get_utf8_name (file));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -300,7 +336,7 @@ gimp_environ_table_load_env_file (const GimpDatafileData *file_data,
|
|||
if (! gimp_environ_table_legal_name (name))
|
||||
{
|
||||
g_message (_("Illegal variable name in environment file %s: %s"),
|
||||
gimp_filename_to_utf8 (file_data->filename), name);
|
||||
gimp_file_get_utf8_name (file), name);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ GType gimp_environ_table_get_type (void) G_GNUC_CONST;
|
|||
GimpEnvironTable * gimp_environ_table_new (gboolean verbose);
|
||||
|
||||
void gimp_environ_table_load (GimpEnvironTable *environ_table,
|
||||
const gchar *env_path);
|
||||
GList *path);
|
||||
|
||||
void gimp_environ_table_add (GimpEnvironTable *environ_table,
|
||||
const gchar *name,
|
||||
|
|
|
@ -79,26 +79,26 @@ struct _GimpInterpreterMagic
|
|||
};
|
||||
|
||||
|
||||
static void gimp_interpreter_db_finalize (GObject *object);
|
||||
static void gimp_interpreter_db_finalize (GObject *object);
|
||||
|
||||
static void gimp_interpreter_db_load_interp_file (const GimpDatafileData *file_data,
|
||||
gpointer user_data);
|
||||
static void gimp_interpreter_db_load_interp_file (GimpInterpreterDB *db,
|
||||
GFile *file);
|
||||
|
||||
static void gimp_interpreter_db_add_program (GimpInterpreterDB *db,
|
||||
const GimpDatafileData *file_data,
|
||||
gchar *buffer);
|
||||
static void gimp_interpreter_db_add_binfmt_misc (GimpInterpreterDB *db,
|
||||
const GimpDatafileData *file_data,
|
||||
gchar *buffer);
|
||||
static void gimp_interpreter_db_add_program (GimpInterpreterDB *db,
|
||||
GFile *file,
|
||||
gchar *buffer);
|
||||
static void gimp_interpreter_db_add_binfmt_misc (GimpInterpreterDB *db,
|
||||
GFile *file,
|
||||
gchar *buffer);
|
||||
|
||||
static gboolean gimp_interpreter_db_add_extension (GimpInterpreterDB *db,
|
||||
gchar **tokens);
|
||||
static gboolean gimp_interpreter_db_add_magic (GimpInterpreterDB *db,
|
||||
gchar **tokens);
|
||||
static gboolean gimp_interpreter_db_add_extension (GimpInterpreterDB *db,
|
||||
gchar **tokens);
|
||||
static gboolean gimp_interpreter_db_add_magic (GimpInterpreterDB *db,
|
||||
gchar **tokens);
|
||||
|
||||
static void gimp_interpreter_db_clear_magics (GimpInterpreterDB *db);
|
||||
static void gimp_interpreter_db_clear_magics (GimpInterpreterDB *db);
|
||||
|
||||
static void gimp_interpreter_db_resolve_programs (GimpInterpreterDB *db);
|
||||
static void gimp_interpreter_db_resolve_programs (GimpInterpreterDB *db);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpInterpreterDB, gimp_interpreter_db, G_TYPE_OBJECT)
|
||||
|
@ -141,8 +141,10 @@ gimp_interpreter_db_new (gboolean verbose)
|
|||
|
||||
void
|
||||
gimp_interpreter_db_load (GimpInterpreterDB *db,
|
||||
const gchar *interp_path)
|
||||
GList *path)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
g_return_if_fail (GIMP_IS_INTERPRETER_DB (db));
|
||||
|
||||
gimp_interpreter_db_clear (db);
|
||||
|
@ -159,10 +161,41 @@ gimp_interpreter_db_load (GimpInterpreterDB *db,
|
|||
db->extension_names = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, NULL);
|
||||
|
||||
gimp_datafiles_read_directories (interp_path,
|
||||
G_FILE_TEST_EXISTS,
|
||||
gimp_interpreter_db_load_interp_file,
|
||||
db);
|
||||
for (list = path; list; list = g_list_next (list))
|
||||
{
|
||||
GFile *dir = list->data;
|
||||
GFileEnumerator *enumerator;
|
||||
|
||||
enumerator =
|
||||
g_file_enumerate_children (dir,
|
||||
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
|
||||
G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
NULL, NULL);
|
||||
|
||||
if (enumerator)
|
||||
{
|
||||
GFileInfo *info;
|
||||
|
||||
while ((info = g_file_enumerator_next_file (enumerator,
|
||||
NULL, NULL)))
|
||||
{
|
||||
if (! g_file_info_get_is_hidden (info) &&
|
||||
g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR)
|
||||
{
|
||||
GFile *file = g_file_enumerator_get_child (enumerator, info);
|
||||
|
||||
gimp_interpreter_db_load_interp_file (db, file);
|
||||
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
g_object_unref (enumerator);
|
||||
}
|
||||
}
|
||||
|
||||
gimp_interpreter_db_resolve_programs (db);
|
||||
}
|
||||
|
@ -200,20 +233,21 @@ gimp_interpreter_db_clear (GimpInterpreterDB *db)
|
|||
}
|
||||
|
||||
static void
|
||||
gimp_interpreter_db_load_interp_file (const GimpDatafileData *file_data,
|
||||
gpointer user_data)
|
||||
gimp_interpreter_db_load_interp_file (GimpInterpreterDB *db,
|
||||
GFile *file)
|
||||
{
|
||||
GimpInterpreterDB *db;
|
||||
FILE *interp_file;
|
||||
gchar buffer[4096];
|
||||
gsize len;
|
||||
|
||||
db = GIMP_INTERPRETER_DB (user_data);
|
||||
FILE *interp_file;
|
||||
gchar *path;
|
||||
gchar buffer[4096];
|
||||
gsize len;
|
||||
|
||||
if (db->verbose)
|
||||
g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (file_data->filename));
|
||||
g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
|
||||
|
||||
path = g_file_get_path (file);
|
||||
interp_file = g_fopen (path, "r");
|
||||
g_free (path);
|
||||
|
||||
interp_file = g_fopen (file_data->filename, "r");
|
||||
if (! interp_file)
|
||||
return;
|
||||
|
||||
|
@ -232,18 +266,22 @@ gimp_interpreter_db_load_interp_file (const GimpDatafileData *file_data,
|
|||
buffer[len] = '\0';
|
||||
|
||||
if (g_ascii_isalnum (buffer[0]) || (buffer[0] == '/'))
|
||||
gimp_interpreter_db_add_program (db, file_data, buffer);
|
||||
{
|
||||
gimp_interpreter_db_add_program (db, file, buffer);
|
||||
}
|
||||
else if (! g_ascii_isspace (buffer[0]) && (buffer[0] != '\0'))
|
||||
gimp_interpreter_db_add_binfmt_misc (db, file_data, buffer);
|
||||
{
|
||||
gimp_interpreter_db_add_binfmt_misc (db, file, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
fclose (interp_file);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_interpreter_db_add_program (GimpInterpreterDB *db,
|
||||
const GimpDatafileData *file_data,
|
||||
gchar *buffer)
|
||||
gimp_interpreter_db_add_program (GimpInterpreterDB *db,
|
||||
GFile *file,
|
||||
gchar *buffer)
|
||||
{
|
||||
gchar *name;
|
||||
gchar *program;
|
||||
|
@ -261,7 +299,7 @@ gimp_interpreter_db_add_program (GimpInterpreterDB *db,
|
|||
if (! g_file_test (program, G_FILE_TEST_IS_EXECUTABLE))
|
||||
{
|
||||
g_message (_("Bad interpreter referenced in interpreter file %s: %s"),
|
||||
gimp_filename_to_utf8 (file_data->filename),
|
||||
gimp_file_get_utf8_name (file),
|
||||
gimp_filename_to_utf8 (program));
|
||||
return;
|
||||
}
|
||||
|
@ -271,9 +309,9 @@ gimp_interpreter_db_add_program (GimpInterpreterDB *db,
|
|||
}
|
||||
|
||||
static void
|
||||
gimp_interpreter_db_add_binfmt_misc (GimpInterpreterDB *db,
|
||||
const GimpDatafileData *file_data,
|
||||
gchar *buffer)
|
||||
gimp_interpreter_db_add_binfmt_misc (GimpInterpreterDB *db,
|
||||
GFile *file,
|
||||
gchar *buffer)
|
||||
{
|
||||
gchar **tokens = NULL;
|
||||
gchar *name, *type, *program;
|
||||
|
@ -320,7 +358,7 @@ gimp_interpreter_db_add_binfmt_misc (GimpInterpreterDB *db,
|
|||
|
||||
bail:
|
||||
g_message (_("Bad binary format string in interpreter file %s"),
|
||||
gimp_filename_to_utf8 (file_data->filename));
|
||||
gimp_file_get_utf8_name (file));
|
||||
|
||||
out:
|
||||
g_strfreev (tokens);
|
||||
|
|
|
@ -57,7 +57,7 @@ GType gimp_interpreter_db_get_type (void) G_GNUC_CONST;
|
|||
GimpInterpreterDB * gimp_interpreter_db_new (gboolean verbose);
|
||||
|
||||
void gimp_interpreter_db_load (GimpInterpreterDB *db,
|
||||
const gchar *interp_path);
|
||||
GList *path);
|
||||
|
||||
void gimp_interpreter_db_clear (GimpInterpreterDB *db);
|
||||
|
||||
|
|
|
@ -271,24 +271,25 @@ void
|
|||
gimp_plug_in_manager_initialize (GimpPlugInManager *manager,
|
||||
GimpInitStatusFunc status_callback)
|
||||
{
|
||||
gchar *path;
|
||||
GimpCoreConfig *config;
|
||||
GList *path;
|
||||
|
||||
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
|
||||
g_return_if_fail (status_callback != NULL);
|
||||
|
||||
config = manager->gimp->config;
|
||||
|
||||
status_callback (NULL, _("Plug-In Interpreters"), 0.8);
|
||||
|
||||
path = gimp_config_path_expand (manager->gimp->config->interpreter_path,
|
||||
TRUE, NULL);
|
||||
path = gimp_config_path_expand_to_files (config->interpreter_path, NULL);
|
||||
gimp_interpreter_db_load (manager->interpreter_db, path);
|
||||
g_free (path);
|
||||
g_list_free_full (path, (GDestroyNotify) g_object_unref);
|
||||
|
||||
status_callback (NULL, _("Plug-In Environment"), 0.9);
|
||||
|
||||
path = gimp_config_path_expand (manager->gimp->config->environ_path,
|
||||
TRUE, NULL);
|
||||
path = gimp_config_path_expand_to_files (config->environ_path, NULL);
|
||||
gimp_environ_table_load (manager->environ_table, path);
|
||||
g_free (path);
|
||||
g_list_free_full (path, (GDestroyNotify) g_object_unref);
|
||||
|
||||
/* allocate a piece of shared memory for use in transporting tiles
|
||||
* to plug-ins. if we can't allocate a piece of shared memory then
|
||||
|
|
Loading…
Reference in New Issue