From 6de5b803e2beeec8ced3f2ceed3bdd27bd099bbd Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 16 Jun 2003 11:31:10 +0000 Subject: [PATCH] use gimp_datafiles_read_directories() instead of doing the same manually. 2003-06-16 Michael Natterer * plug-ins/script-fu/script-fu-scripts.c (script_fu_find_scripts): use gimp_datafiles_read_directories() instead of doing the same manually. * plug-ins/script-fu/siod-wrapper.c (siod_init): s/gint/gboolean/. --- ChangeLog | 8 ++ plug-ins/script-fu/scheme-wrapper.c | 2 +- plug-ins/script-fu/script-fu-interface.c | 128 +++++++---------------- plug-ins/script-fu/script-fu-scripts.c | 128 +++++++---------------- plug-ins/script-fu/siod-wrapper.c | 2 +- 5 files changed, 86 insertions(+), 182 deletions(-) diff --git a/ChangeLog b/ChangeLog index 91b3a2f3f4..18fed68ba8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-06-16 Michael Natterer + + * plug-ins/script-fu/script-fu-scripts.c (script_fu_find_scripts): + use gimp_datafiles_read_directories() instead of doing the same + manually. + + * plug-ins/script-fu/siod-wrapper.c (siod_init): s/gint/gboolean/. + 2003-06-16 Sven Neumann * plug-ins/script-fu/script-fu-console.c diff --git a/plug-ins/script-fu/scheme-wrapper.c b/plug-ins/script-fu/scheme-wrapper.c index 74a37ec2a0..26e367680c 100644 --- a/plug-ins/script-fu/scheme-wrapper.c +++ b/plug-ins/script-fu/scheme-wrapper.c @@ -93,7 +93,7 @@ static void init_procedures (void); static gboolean register_scripts = FALSE; void -siod_init (gint local_register_scripts) +siod_init (gboolean local_register_scripts) { char *siod_argv[] = { diff --git a/plug-ins/script-fu/script-fu-interface.c b/plug-ins/script-fu/script-fu-interface.c index a6f364fa13..f6cb41bc22 100644 --- a/plug-ins/script-fu/script-fu-interface.c +++ b/plug-ins/script-fu/script-fu-interface.c @@ -32,6 +32,8 @@ #include #endif +#include + #include #include @@ -139,6 +141,7 @@ extern long nlength (LISP obj); * Local Functions */ +static void script_fu_load_script (GimpDatafileData *file_data); static gboolean script_fu_install_script (gpointer foo, SFScript *script, gpointer bar); @@ -212,16 +215,7 @@ extern gchar siod_err_msg[]; void script_fu_find_scripts (void) { - const gchar *home; - const gchar *entry; - gchar *path_str; - gchar *local_path; - gchar *path; - gchar *filename; - gchar *token; - gchar *next_token; - gchar *command; - GDir *dir; + gchar *path_str; /* Make sure to clear any existing scripts */ if (script_list != NULL) @@ -239,87 +233,10 @@ script_fu_find_scripts (void) if (path_str == NULL) return; - /* Set local path to contain temp_path, where (supposedly) - * there may be working files. - */ - home = g_get_home_dir (); - local_path = g_strdup (path_str); - - /* Search through all directories in the local path */ - - next_token = local_path; - - token = strtok (next_token, G_SEARCHPATH_SEPARATOR_S); + gimp_datafiles_read_directories (path_str, G_FILE_TEST_IS_REGULAR, + script_fu_load_script, + NULL); - while (token) - { - if (*token == '~') - { - path = g_malloc (strlen (home) + strlen (token) + 2); - sprintf (path, "%s%s", home, token + 1); - } - else - { - path = g_malloc (strlen (token) + 2); - strcpy (path, token); - } - - /* Check if directory exists and if it has any items in it */ - if (g_file_test (path, G_FILE_TEST_IS_DIR)) - { - GError *error; - - dir = g_dir_open (path, 0, &error); - - if (!dir) - { - g_message ("Error reading script folder '%s'\n%s", - path, error->message); - g_clear_error (&error); - } - else - { - while ((entry = g_dir_read_name (dir))) - { - filename = g_build_filename (path, entry, NULL); - - if (g_ascii_strcasecmp (filename + strlen (filename) - 4, ".scm") == 0) - { - /* Check the file and see that it is not a sub-directory */ - if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) - { - gchar *qf = g_strescape (filename, NULL); -#ifdef __EMX__ - _fnslashify(qf); -#endif - command = g_strdup_printf ("(load \"%s\")", qf); - g_free (qf); - - if (repl_c_string (command, 0, 0, 1) != 0) - script_fu_error_msg (command); -#ifdef G_OS_WIN32 - /* No, I don't know why, but this is - * necessary on NT 4.0. - */ - Sleep(0); -#endif - g_free (command); - } - } - - g_free (filename); - } /* while */ - - g_dir_close (dir); - } /* else */ - } /* if */ - - g_free (path); - - token = strtok (NULL, G_SEARCHPATH_SEPARATOR_S); - } /* while */ - - g_free (local_path); g_free (path_str); /* now that all scripts are read in and sorted, tell gimp about them */ @@ -740,6 +657,37 @@ script_fu_report_cc (gchar *command) } +/* private functions */ + +static void +script_fu_load_script (GimpDatafileData *file_data) +{ + if (gimp_datafiles_check_extension (file_data->filename, ".scm")) + { + gchar *command; + gchar *qf = g_strescape (file_data->filename, NULL); + +#ifdef __EMX__ + _fnslashify (qf); +#endif + + command = g_strdup_printf ("(load \"%s\")", qf); + g_free (qf); + + if (repl_c_string (command, 0, 0, 1) != 0) + script_fu_error_msg (command); + +#ifdef G_OS_WIN32 + /* No, I don't know why, but this is + * necessary on NT 4.0. + */ + Sleep(0); +#endif + + g_free (command); + } +} + /* * The following function is a GTraverseFunction. Please * note that it frees the script->args structure. --Sven diff --git a/plug-ins/script-fu/script-fu-scripts.c b/plug-ins/script-fu/script-fu-scripts.c index a6f364fa13..f6cb41bc22 100644 --- a/plug-ins/script-fu/script-fu-scripts.c +++ b/plug-ins/script-fu/script-fu-scripts.c @@ -32,6 +32,8 @@ #include #endif +#include + #include #include @@ -139,6 +141,7 @@ extern long nlength (LISP obj); * Local Functions */ +static void script_fu_load_script (GimpDatafileData *file_data); static gboolean script_fu_install_script (gpointer foo, SFScript *script, gpointer bar); @@ -212,16 +215,7 @@ extern gchar siod_err_msg[]; void script_fu_find_scripts (void) { - const gchar *home; - const gchar *entry; - gchar *path_str; - gchar *local_path; - gchar *path; - gchar *filename; - gchar *token; - gchar *next_token; - gchar *command; - GDir *dir; + gchar *path_str; /* Make sure to clear any existing scripts */ if (script_list != NULL) @@ -239,87 +233,10 @@ script_fu_find_scripts (void) if (path_str == NULL) return; - /* Set local path to contain temp_path, where (supposedly) - * there may be working files. - */ - home = g_get_home_dir (); - local_path = g_strdup (path_str); - - /* Search through all directories in the local path */ - - next_token = local_path; - - token = strtok (next_token, G_SEARCHPATH_SEPARATOR_S); + gimp_datafiles_read_directories (path_str, G_FILE_TEST_IS_REGULAR, + script_fu_load_script, + NULL); - while (token) - { - if (*token == '~') - { - path = g_malloc (strlen (home) + strlen (token) + 2); - sprintf (path, "%s%s", home, token + 1); - } - else - { - path = g_malloc (strlen (token) + 2); - strcpy (path, token); - } - - /* Check if directory exists and if it has any items in it */ - if (g_file_test (path, G_FILE_TEST_IS_DIR)) - { - GError *error; - - dir = g_dir_open (path, 0, &error); - - if (!dir) - { - g_message ("Error reading script folder '%s'\n%s", - path, error->message); - g_clear_error (&error); - } - else - { - while ((entry = g_dir_read_name (dir))) - { - filename = g_build_filename (path, entry, NULL); - - if (g_ascii_strcasecmp (filename + strlen (filename) - 4, ".scm") == 0) - { - /* Check the file and see that it is not a sub-directory */ - if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) - { - gchar *qf = g_strescape (filename, NULL); -#ifdef __EMX__ - _fnslashify(qf); -#endif - command = g_strdup_printf ("(load \"%s\")", qf); - g_free (qf); - - if (repl_c_string (command, 0, 0, 1) != 0) - script_fu_error_msg (command); -#ifdef G_OS_WIN32 - /* No, I don't know why, but this is - * necessary on NT 4.0. - */ - Sleep(0); -#endif - g_free (command); - } - } - - g_free (filename); - } /* while */ - - g_dir_close (dir); - } /* else */ - } /* if */ - - g_free (path); - - token = strtok (NULL, G_SEARCHPATH_SEPARATOR_S); - } /* while */ - - g_free (local_path); g_free (path_str); /* now that all scripts are read in and sorted, tell gimp about them */ @@ -740,6 +657,37 @@ script_fu_report_cc (gchar *command) } +/* private functions */ + +static void +script_fu_load_script (GimpDatafileData *file_data) +{ + if (gimp_datafiles_check_extension (file_data->filename, ".scm")) + { + gchar *command; + gchar *qf = g_strescape (file_data->filename, NULL); + +#ifdef __EMX__ + _fnslashify (qf); +#endif + + command = g_strdup_printf ("(load \"%s\")", qf); + g_free (qf); + + if (repl_c_string (command, 0, 0, 1) != 0) + script_fu_error_msg (command); + +#ifdef G_OS_WIN32 + /* No, I don't know why, but this is + * necessary on NT 4.0. + */ + Sleep(0); +#endif + + g_free (command); + } +} + /* * The following function is a GTraverseFunction. Please * note that it frees the script->args structure. --Sven diff --git a/plug-ins/script-fu/siod-wrapper.c b/plug-ins/script-fu/siod-wrapper.c index 74a37ec2a0..26e367680c 100644 --- a/plug-ins/script-fu/siod-wrapper.c +++ b/plug-ins/script-fu/siod-wrapper.c @@ -93,7 +93,7 @@ static void init_procedures (void); static gboolean register_scripts = FALSE; void -siod_init (gint local_register_scripts) +siod_init (gboolean local_register_scripts) { char *siod_argv[] = {