From ed071953b2d01d9235df542acd7099926d2aedbb Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 21 Feb 2000 17:15:30 +0000 Subject: [PATCH] fixed a gtk-doc comment. 2000-02-21 Michael Natterer * libgimp/gimppixmap.c: fixed a gtk-doc comment. * libgimp/gimpenv.[ch]: new functions: - gimp_path_parse(): Creates a GList of strings from a searchpath string and performs sanity checks. - gimp_path_to_str(): Creates a searchpath string from the list returned by gimp_path_parse(). - gimp_path_free(): Frees the list returned by gimp_path_parse(). - gimp_path_get_user_writable_dir(): Returns the first dir in a path where the user has write access. With this function the "Save" dialogs of some plugins always show the plugin's subdirectory of the user's gimp_dir instead of the read-only global one. * app/datafiles.[ch] * app/gimpbrushlist.c: use the new functions and s/datafile_loader_t/GimpDataFileLoaderFunc/. * plug-ins/FractalExplorer/Dialogs.c * plug-ins/FractalExplorer/FractalExplorer.c * plug-ins/gfig/gfig.c * plug-ins/gflare/gflare.c * plug-ins/gimpressionist/gimpressionist.c: use the new functions. --- ChangeLog | 27 +++ app/core/gimpdatafiles.c | 136 ++++++-------- app/core/gimpdatafiles.h | 19 +- app/datafiles.c | 136 ++++++-------- app/datafiles.h | 19 +- app/gimpbrushlist.c | 14 +- libgimp/gimpenv.c | 196 +++++++++++++++++++++ libgimp/gimpenv.h | 17 +- libgimp/gimppixmap.c | 2 +- libgimpbase/gimpdatafiles.c | 136 ++++++-------- libgimpbase/gimpdatafiles.h | 19 +- libgimpbase/gimpenv.c | 196 +++++++++++++++++++++ libgimpbase/gimpenv.h | 17 +- libgimpwidgets/gimppixmap.c | 2 +- plug-ins/FractalExplorer/Dialogs.c | 20 ++- plug-ins/FractalExplorer/FractalExplorer.c | 111 +++--------- plug-ins/gfig/gfig.c | 142 ++++----------- plug-ins/gflare/gflare.c | 85 +++------ plug-ins/gimpressionist/gimpressionist.c | 92 +++++----- 19 files changed, 790 insertions(+), 596 deletions(-) diff --git a/ChangeLog b/ChangeLog index b7a7735eda..f126ab034b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2000-02-21 Michael Natterer + + * libgimp/gimppixmap.c: fixed a gtk-doc comment. + + * libgimp/gimpenv.[ch]: new functions: + + - gimp_path_parse(): Creates a GList of strings from a searchpath + string and performs sanity checks. + - gimp_path_to_str(): Creates a searchpath string from the list + returned by gimp_path_parse(). + - gimp_path_free(): Frees the list returned by gimp_path_parse(). + - gimp_path_get_user_writable_dir(): Returns the first dir in a + path where the user has write access. With this function the + "Save" dialogs of some plugins always show the plugin's + subdirectory of the user's gimp_dir instead of the read-only + global one. + + * app/datafiles.[ch] + * app/gimpbrushlist.c: use the new functions and + s/datafile_loader_t/GimpDataFileLoaderFunc/. + + * plug-ins/FractalExplorer/Dialogs.c + * plug-ins/FractalExplorer/FractalExplorer.c + * plug-ins/gfig/gfig.c + * plug-ins/gflare/gflare.c + * plug-ins/gimpressionist/gimpressionist.c: use the new functions. + Mon Feb 21 14:05:56 CET 2000 Sven Neumann * app/gimpbrushlist.c diff --git a/app/core/gimpdatafiles.c b/app/core/gimpdatafiles.c index 71410b3213..86e8580c23 100644 --- a/app/core/gimpdatafiles.c +++ b/app/core/gimpdatafiles.c @@ -45,16 +45,13 @@ #endif /* G_OS_WIN32 */ #include "datafiles.h" -#include "errors.h" -#include "general.h" #include "gimprc.h" +#include "libgimp/gimpenv.h" /***** Functions *****/ -/*****/ - -static int filestat_valid = 0; +static gint filestat_valid = 0; static struct stat filestat; #ifdef G_OS_WIN32 @@ -66,7 +63,7 @@ static struct stat filestat; * variable, which is also used by cmd.exe. */ gboolean -is_script (const gchar* filename) +is_script (const gchar *filename) { const gchar *ext = strrchr (filename, '.'); gchar *pathext; @@ -103,105 +100,78 @@ is_script (const gchar* filename) #endif void -datafiles_read_directories (char *path_str, - datafile_loader_t loader_func, - int flags) +datafiles_read_directories (gchar *path_str, + GimpDataFileLoaderFunc loader_func, + gint flags) { - char *home; - char *local_path; - char *path; - char *filename; - char *token; - char *next_token; - int err; - DIR *dir; + gchar *local_path; + GList *path; + GList *list; + gchar *filename; + gint err; + DIR *dir; struct dirent *dir_ent; 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); + #ifdef __EMX__ /* * Change drive so opendir works. */ if (local_path[1] == ':') - { - _chdrive(local_path[0]); - } -#endif - /* Search through all directories in the local path */ - - next_token = local_path; - - token = xstrsep(&next_token, G_SEARCHPATH_SEPARATOR_S); - - while (token) { - if (*token == '~') + _chdrive (local_path[0]); + } +#endif + + path = gimp_path_parse (local_path, 16, TRUE, NULL); + + for (list = path; list; list = g_list_next (list)) + { + /* Open directory */ + dir = opendir ((gchar *) list->data); + + if (!dir) { - path = g_malloc(strlen(home) + strlen(token) + 1); - sprintf(path, "%s%s", home, token + 1); + g_message ("error reading datafiles directory \"%s\"", + (gchar *) list->data); } else { - path = g_malloc(strlen(token) + 2); - strcpy(path, token); - } /* else */ - - /* Check if directory exists and if it has any items in it */ - err = stat(path, &filestat); - - if (!err && S_ISDIR(filestat.st_mode)) - { - if (path[strlen(path) - 1] != G_DIR_SEPARATOR) - strcat(path, G_DIR_SEPARATOR_S); - - /* Open directory */ - dir = opendir(path); - - if (!dir) - g_message ("error reading datafiles directory \"%s\"", path); - else + while ((dir_ent = readdir(dir))) { - while ((dir_ent = readdir(dir))) + filename = g_strdup_printf ("%s%s", + (gchar *) list->data, + dir_ent->d_name); + + /* Check the file and see that it is not a sub-directory */ + err = stat (filename, &filestat); + + if (!err && S_ISREG (filestat.st_mode) && + (!(flags & MODE_EXECUTABLE) || + (filestat.st_mode & S_IXUSR) || + is_script (filename))) { - filename = g_strdup_printf("%s%s", path, dir_ent->d_name); + filestat_valid = 1; + (*loader_func) (filename); + filestat_valid = 0; + } - /* Check the file and see that it is not a sub-directory */ - err = stat(filename, &filestat); + g_free (filename); + } - if (!err && S_ISREG(filestat.st_mode) && - (!(flags & MODE_EXECUTABLE) || - (filestat.st_mode & S_IXUSR) || - is_script (filename))) - { - filestat_valid = 1; - (*loader_func) (filename); - filestat_valid = 0; - } + closedir (dir); + } + } - g_free(filename); - } /* while */ - - closedir(dir); - } /* else */ - } /* if */ - - g_free(path); - - token = xstrsep(&next_token, G_SEARCHPATH_SEPARATOR_S); - } /* while */ - - g_free(local_path); -} /* datafiles_read_directories */ + gimp_path_free (path); +} time_t -datafile_atime () +datafile_atime (void) { if (filestat_valid) return filestat.st_atime; @@ -209,7 +179,7 @@ datafile_atime () } time_t -datafile_mtime () +datafile_mtime (void) { if (filestat_valid) return filestat.st_mtime; @@ -217,7 +187,7 @@ datafile_mtime () } time_t -datafile_ctime () +datafile_ctime (void) { if (filestat_valid) return filestat.st_ctime; diff --git a/app/core/gimpdatafiles.h b/app/core/gimpdatafiles.h index 0e297aa375..a48e93eb58 100644 --- a/app/core/gimpdatafiles.h +++ b/app/core/gimpdatafiles.h @@ -19,11 +19,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#ifndef _DATAFILES_H_ -#define _DATAFILES_H_ +#ifndef __DATAFILES_H__ +#define __DATAFILES_H__ #include +#include #define INCLUDE_TEMP_DIR 0x1 #define MODE_EXECUTABLE 0x2 @@ -31,23 +31,22 @@ /***** Types *****/ -typedef void (*datafile_loader_t) (char *filename); +typedef void (* GimpDataFileLoaderFunc) (gchar *filename); /***** Functions *****/ -void datafiles_read_directories(char *path_str, - datafile_loader_t loader_func, - int flags); +void datafiles_read_directories (gchar *path_str, + GimpDataFileLoaderFunc loader_func, + gint flags); /* Return the current datafiles access, modification * or change time. The current datafile is the one for - * which the "datafile_loader_t" function has been called + * which the "DataFileLoaderFunc" function has been called * on. */ time_t datafile_atime (void); time_t datafile_mtime (void); time_t datafile_ctime (void); - -#endif +#endif /* __DATAFILES_H__ */ diff --git a/app/datafiles.c b/app/datafiles.c index 71410b3213..86e8580c23 100644 --- a/app/datafiles.c +++ b/app/datafiles.c @@ -45,16 +45,13 @@ #endif /* G_OS_WIN32 */ #include "datafiles.h" -#include "errors.h" -#include "general.h" #include "gimprc.h" +#include "libgimp/gimpenv.h" /***** Functions *****/ -/*****/ - -static int filestat_valid = 0; +static gint filestat_valid = 0; static struct stat filestat; #ifdef G_OS_WIN32 @@ -66,7 +63,7 @@ static struct stat filestat; * variable, which is also used by cmd.exe. */ gboolean -is_script (const gchar* filename) +is_script (const gchar *filename) { const gchar *ext = strrchr (filename, '.'); gchar *pathext; @@ -103,105 +100,78 @@ is_script (const gchar* filename) #endif void -datafiles_read_directories (char *path_str, - datafile_loader_t loader_func, - int flags) +datafiles_read_directories (gchar *path_str, + GimpDataFileLoaderFunc loader_func, + gint flags) { - char *home; - char *local_path; - char *path; - char *filename; - char *token; - char *next_token; - int err; - DIR *dir; + gchar *local_path; + GList *path; + GList *list; + gchar *filename; + gint err; + DIR *dir; struct dirent *dir_ent; 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); + #ifdef __EMX__ /* * Change drive so opendir works. */ if (local_path[1] == ':') - { - _chdrive(local_path[0]); - } -#endif - /* Search through all directories in the local path */ - - next_token = local_path; - - token = xstrsep(&next_token, G_SEARCHPATH_SEPARATOR_S); - - while (token) { - if (*token == '~') + _chdrive (local_path[0]); + } +#endif + + path = gimp_path_parse (local_path, 16, TRUE, NULL); + + for (list = path; list; list = g_list_next (list)) + { + /* Open directory */ + dir = opendir ((gchar *) list->data); + + if (!dir) { - path = g_malloc(strlen(home) + strlen(token) + 1); - sprintf(path, "%s%s", home, token + 1); + g_message ("error reading datafiles directory \"%s\"", + (gchar *) list->data); } else { - path = g_malloc(strlen(token) + 2); - strcpy(path, token); - } /* else */ - - /* Check if directory exists and if it has any items in it */ - err = stat(path, &filestat); - - if (!err && S_ISDIR(filestat.st_mode)) - { - if (path[strlen(path) - 1] != G_DIR_SEPARATOR) - strcat(path, G_DIR_SEPARATOR_S); - - /* Open directory */ - dir = opendir(path); - - if (!dir) - g_message ("error reading datafiles directory \"%s\"", path); - else + while ((dir_ent = readdir(dir))) { - while ((dir_ent = readdir(dir))) + filename = g_strdup_printf ("%s%s", + (gchar *) list->data, + dir_ent->d_name); + + /* Check the file and see that it is not a sub-directory */ + err = stat (filename, &filestat); + + if (!err && S_ISREG (filestat.st_mode) && + (!(flags & MODE_EXECUTABLE) || + (filestat.st_mode & S_IXUSR) || + is_script (filename))) { - filename = g_strdup_printf("%s%s", path, dir_ent->d_name); + filestat_valid = 1; + (*loader_func) (filename); + filestat_valid = 0; + } - /* Check the file and see that it is not a sub-directory */ - err = stat(filename, &filestat); + g_free (filename); + } - if (!err && S_ISREG(filestat.st_mode) && - (!(flags & MODE_EXECUTABLE) || - (filestat.st_mode & S_IXUSR) || - is_script (filename))) - { - filestat_valid = 1; - (*loader_func) (filename); - filestat_valid = 0; - } + closedir (dir); + } + } - g_free(filename); - } /* while */ - - closedir(dir); - } /* else */ - } /* if */ - - g_free(path); - - token = xstrsep(&next_token, G_SEARCHPATH_SEPARATOR_S); - } /* while */ - - g_free(local_path); -} /* datafiles_read_directories */ + gimp_path_free (path); +} time_t -datafile_atime () +datafile_atime (void) { if (filestat_valid) return filestat.st_atime; @@ -209,7 +179,7 @@ datafile_atime () } time_t -datafile_mtime () +datafile_mtime (void) { if (filestat_valid) return filestat.st_mtime; @@ -217,7 +187,7 @@ datafile_mtime () } time_t -datafile_ctime () +datafile_ctime (void) { if (filestat_valid) return filestat.st_ctime; diff --git a/app/datafiles.h b/app/datafiles.h index 0e297aa375..a48e93eb58 100644 --- a/app/datafiles.h +++ b/app/datafiles.h @@ -19,11 +19,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#ifndef _DATAFILES_H_ -#define _DATAFILES_H_ +#ifndef __DATAFILES_H__ +#define __DATAFILES_H__ #include +#include #define INCLUDE_TEMP_DIR 0x1 #define MODE_EXECUTABLE 0x2 @@ -31,23 +31,22 @@ /***** Types *****/ -typedef void (*datafile_loader_t) (char *filename); +typedef void (* GimpDataFileLoaderFunc) (gchar *filename); /***** Functions *****/ -void datafiles_read_directories(char *path_str, - datafile_loader_t loader_func, - int flags); +void datafiles_read_directories (gchar *path_str, + GimpDataFileLoaderFunc loader_func, + gint flags); /* Return the current datafiles access, modification * or change time. The current datafile is the one for - * which the "datafile_loader_t" function has been called + * which the "DataFileLoaderFunc" function has been called * on. */ time_t datafile_atime (void); time_t datafile_mtime (void); time_t datafile_ctime (void); - -#endif +#endif /* __DATAFILES_H__ */ diff --git a/app/gimpbrushlist.c b/app/gimpbrushlist.c index 4f97dd4e73..7ce1b3b874 100644 --- a/app/gimpbrushlist.c +++ b/app/gimpbrushlist.c @@ -53,10 +53,10 @@ GimpBrushList *brush_list = NULL; static GimpBrush *standard_brush = NULL; /* local function prototypes */ -static void brushes_brush_load (gchar *filename); +static void brushes_brush_load (gchar *filename); -static gint brush_compare_func (gconstpointer first, - gconstpointer second); +static gint brush_compare_func (gconstpointer first, + gconstpointer second); /* class functions */ static GimpObjectClass* parent_class; @@ -134,7 +134,7 @@ gimp_brush_list_new (void) /* function declarations */ void -brushes_init (int no_data) +brushes_init (gint no_data) { if (brush_list) brushes_free (); @@ -146,9 +146,11 @@ brushes_init (int no_data) brush_select_freeze_all (); datafiles_read_directories (brush_path, - (datafile_loader_t) brushes_brush_load, 0); + (GimpDataFileLoaderFunc) brushes_brush_load, + 0); datafiles_read_directories (brush_vbr_path, - (datafile_loader_t) brushes_brush_load, 0); + (GimpDataFileLoaderFunc) brushes_brush_load, + 0); brush_select_thaw_all (); } diff --git a/libgimp/gimpenv.c b/libgimp/gimpenv.c index 3d8f05e40f..805b811283 100644 --- a/libgimp/gimpenv.c +++ b/libgimp/gimpenv.c @@ -22,6 +22,12 @@ #include #include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif + #include "gimpenv.h" #ifdef G_OS_WIN32 @@ -240,6 +246,196 @@ gimp_gtkrc (void) return gimp_gtkrc_filename; } +/** + * gimp_path_parse: + * @path: A list of directories separated by #G_SEARCHPATH_SEPARATOR. + * @max_path: The maximum number of directories to return. + * @check: #TRUE if you want the directories to be checked. + * @not_found: # + * + * Return: A list of all directories in @path. + * + */ +GList * +gimp_path_parse (gchar *path, + gint max_paths, + gboolean check, + GList **check_failed) +{ + gchar *home; + gchar **patharray; + GList *list = NULL; + GList *fail_list = NULL; + gint i; + struct stat filestat; + gint err = FALSE; + if (!path || !*path || max_paths < 1 || max_paths > 256) + return NULL; + home = g_get_home_dir (); + + patharray = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, max_paths); + + for (i = 0; i < max_paths; i++) + { + GString *dir; + + if (!patharray[i]) + break; + + if (*patharray[i] == '~') + { + dir = g_string_new (home); + g_string_append (dir, patharray[i] + 1); + } + else + { + dir = g_string_new (patharray[i]); + } + +#ifdef __EMX__ + _fnslashify (dir); +#endif + + if (check) + { + /* check if directory exists */ + err = stat (dir->str, &filestat); + + if (!err && S_ISDIR (filestat.st_mode)) + { + if (dir->str[dir->len - 1] != G_DIR_SEPARATOR) + g_string_append_c (dir, G_DIR_SEPARATOR); + } + } + + if (!err) + list = g_list_prepend (list, dir->str); + else if (check_failed) + fail_list = g_list_prepend (fail_list, dir->str); + + g_string_free (dir, FALSE); + } + + g_strfreev (patharray); + + list = g_list_reverse (list); + + if (check && check_failed) + { + fail_list = g_list_reverse (fail_list); + *check_failed = fail_list; + } + + return list; +} + +/** + * gimp_path_to_str: + * @path: A list of directories as returned by gimp_path_parse(). + * + * Returns: A searchpath string separated by #G_SEARCHPATH_SEPARATOR. + * + */ +gchar * +gimp_path_to_str (GList *path) +{ + GString *str = NULL; + GList *list; + gchar *retval = NULL; + + for (list = path; list; list = g_list_next (list)) + { + if (str) + { + g_string_append_c (str, G_SEARCHPATH_SEPARATOR); + g_string_append (str, (gchar *) list->data); + } + else + { + str = g_string_new ((gchar *) list->data); + } + } + + if (str) + { + retval = str->str; + g_string_free (str, FALSE); + } + + return retval; +} + +/** + * gimp_path_free: + * @path: A list of directories as returned by gimp_path_parse(). + * + * This function frees the memory allocated for the list and it's strings. + * + */ +void +gimp_path_free (GList *path) +{ + GList *list; + + if (path) + { + for (list = path; list; list = g_list_next (list)) + { + g_free (list->data); + } + + g_list_free (path); + } +} + +/** + * gimp_path_get_user_writable_dir: + * @path: A list of directories as returned by gimp_path_parse(). + * + * Returns: The first directory in @path where the user has write permission. + * + */ +gchar * +gimp_path_get_user_writable_dir (GList *path) +{ + GList *list; + + uid_t euid; + gid_t egid; + + struct stat filestat; + gint err; + + euid = geteuid (); + egid = getegid (); + + for (list = path; list; list = g_list_next (list)) + { + /* check if directory exists */ + err = stat ((gchar *) list->data, &filestat); + + /* this is tricky: + * if a file is e.g. owned by the current user but not user-writable, + * the user has no permission to write to the file regardless + * of his group's or other's write permissions + */ + if (!err && S_ISDIR (filestat.st_mode) && + + ((filestat.st_mode & S_IWUSR) || + + ((filestat.st_mode & S_IWGRP) && + (euid != filestat.st_uid)) || + + ((filestat.st_mode & S_IWOTH) && + (euid != filestat.st_uid) && + (egid != filestat.st_gid)))) + { + return (gchar *) list->data; + } + } + + return NULL; +} diff --git a/libgimp/gimpenv.h b/libgimp/gimpenv.h index 3fe88e83b4..a59cee74e3 100644 --- a/libgimp/gimpenv.h +++ b/libgimp/gimpenv.h @@ -27,10 +27,19 @@ extern "C" { /* For information look into the C source or the html documentation */ -gchar* gimp_directory (void); -gchar* gimp_personal_rc_file (gchar *basename); -gchar* gimp_data_directory (void); -gchar* gimp_gtkrc (void); +gchar * gimp_directory (void); +gchar * gimp_personal_rc_file (gchar *basename); +gchar * gimp_data_directory (void); +gchar * gimp_gtkrc (void); + +GList * gimp_path_parse (gchar *path, + gint max_paths, + gboolean check, + GList **check_failed); +gchar * gimp_path_to_str (GList *path); +void gimp_path_free (GList *path); + +gchar * gimp_path_get_user_writable_dir (GList *path); #ifdef __cplusplus } diff --git a/libgimp/gimppixmap.c b/libgimp/gimppixmap.c index 1709313ec7..aaf9c52687 100644 --- a/libgimp/gimppixmap.c +++ b/libgimp/gimppixmap.c @@ -118,7 +118,7 @@ gimp_pixmap_new (gchar **xpm_data) } /** - * gimp_pixmap_new: + * gimp_pixmap_set: * @pixmap: The pixmap widget you want to set the new xpm_data for. * @xpm_data: A pointer to a XPM data structure as found in XPM files. * diff --git a/libgimpbase/gimpdatafiles.c b/libgimpbase/gimpdatafiles.c index 71410b3213..86e8580c23 100644 --- a/libgimpbase/gimpdatafiles.c +++ b/libgimpbase/gimpdatafiles.c @@ -45,16 +45,13 @@ #endif /* G_OS_WIN32 */ #include "datafiles.h" -#include "errors.h" -#include "general.h" #include "gimprc.h" +#include "libgimp/gimpenv.h" /***** Functions *****/ -/*****/ - -static int filestat_valid = 0; +static gint filestat_valid = 0; static struct stat filestat; #ifdef G_OS_WIN32 @@ -66,7 +63,7 @@ static struct stat filestat; * variable, which is also used by cmd.exe. */ gboolean -is_script (const gchar* filename) +is_script (const gchar *filename) { const gchar *ext = strrchr (filename, '.'); gchar *pathext; @@ -103,105 +100,78 @@ is_script (const gchar* filename) #endif void -datafiles_read_directories (char *path_str, - datafile_loader_t loader_func, - int flags) +datafiles_read_directories (gchar *path_str, + GimpDataFileLoaderFunc loader_func, + gint flags) { - char *home; - char *local_path; - char *path; - char *filename; - char *token; - char *next_token; - int err; - DIR *dir; + gchar *local_path; + GList *path; + GList *list; + gchar *filename; + gint err; + DIR *dir; struct dirent *dir_ent; 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); + #ifdef __EMX__ /* * Change drive so opendir works. */ if (local_path[1] == ':') - { - _chdrive(local_path[0]); - } -#endif - /* Search through all directories in the local path */ - - next_token = local_path; - - token = xstrsep(&next_token, G_SEARCHPATH_SEPARATOR_S); - - while (token) { - if (*token == '~') + _chdrive (local_path[0]); + } +#endif + + path = gimp_path_parse (local_path, 16, TRUE, NULL); + + for (list = path; list; list = g_list_next (list)) + { + /* Open directory */ + dir = opendir ((gchar *) list->data); + + if (!dir) { - path = g_malloc(strlen(home) + strlen(token) + 1); - sprintf(path, "%s%s", home, token + 1); + g_message ("error reading datafiles directory \"%s\"", + (gchar *) list->data); } else { - path = g_malloc(strlen(token) + 2); - strcpy(path, token); - } /* else */ - - /* Check if directory exists and if it has any items in it */ - err = stat(path, &filestat); - - if (!err && S_ISDIR(filestat.st_mode)) - { - if (path[strlen(path) - 1] != G_DIR_SEPARATOR) - strcat(path, G_DIR_SEPARATOR_S); - - /* Open directory */ - dir = opendir(path); - - if (!dir) - g_message ("error reading datafiles directory \"%s\"", path); - else + while ((dir_ent = readdir(dir))) { - while ((dir_ent = readdir(dir))) + filename = g_strdup_printf ("%s%s", + (gchar *) list->data, + dir_ent->d_name); + + /* Check the file and see that it is not a sub-directory */ + err = stat (filename, &filestat); + + if (!err && S_ISREG (filestat.st_mode) && + (!(flags & MODE_EXECUTABLE) || + (filestat.st_mode & S_IXUSR) || + is_script (filename))) { - filename = g_strdup_printf("%s%s", path, dir_ent->d_name); + filestat_valid = 1; + (*loader_func) (filename); + filestat_valid = 0; + } - /* Check the file and see that it is not a sub-directory */ - err = stat(filename, &filestat); + g_free (filename); + } - if (!err && S_ISREG(filestat.st_mode) && - (!(flags & MODE_EXECUTABLE) || - (filestat.st_mode & S_IXUSR) || - is_script (filename))) - { - filestat_valid = 1; - (*loader_func) (filename); - filestat_valid = 0; - } + closedir (dir); + } + } - g_free(filename); - } /* while */ - - closedir(dir); - } /* else */ - } /* if */ - - g_free(path); - - token = xstrsep(&next_token, G_SEARCHPATH_SEPARATOR_S); - } /* while */ - - g_free(local_path); -} /* datafiles_read_directories */ + gimp_path_free (path); +} time_t -datafile_atime () +datafile_atime (void) { if (filestat_valid) return filestat.st_atime; @@ -209,7 +179,7 @@ datafile_atime () } time_t -datafile_mtime () +datafile_mtime (void) { if (filestat_valid) return filestat.st_mtime; @@ -217,7 +187,7 @@ datafile_mtime () } time_t -datafile_ctime () +datafile_ctime (void) { if (filestat_valid) return filestat.st_ctime; diff --git a/libgimpbase/gimpdatafiles.h b/libgimpbase/gimpdatafiles.h index 0e297aa375..a48e93eb58 100644 --- a/libgimpbase/gimpdatafiles.h +++ b/libgimpbase/gimpdatafiles.h @@ -19,11 +19,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#ifndef _DATAFILES_H_ -#define _DATAFILES_H_ +#ifndef __DATAFILES_H__ +#define __DATAFILES_H__ #include +#include #define INCLUDE_TEMP_DIR 0x1 #define MODE_EXECUTABLE 0x2 @@ -31,23 +31,22 @@ /***** Types *****/ -typedef void (*datafile_loader_t) (char *filename); +typedef void (* GimpDataFileLoaderFunc) (gchar *filename); /***** Functions *****/ -void datafiles_read_directories(char *path_str, - datafile_loader_t loader_func, - int flags); +void datafiles_read_directories (gchar *path_str, + GimpDataFileLoaderFunc loader_func, + gint flags); /* Return the current datafiles access, modification * or change time. The current datafile is the one for - * which the "datafile_loader_t" function has been called + * which the "DataFileLoaderFunc" function has been called * on. */ time_t datafile_atime (void); time_t datafile_mtime (void); time_t datafile_ctime (void); - -#endif +#endif /* __DATAFILES_H__ */ diff --git a/libgimpbase/gimpenv.c b/libgimpbase/gimpenv.c index 3d8f05e40f..805b811283 100644 --- a/libgimpbase/gimpenv.c +++ b/libgimpbase/gimpenv.c @@ -22,6 +22,12 @@ #include #include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif + #include "gimpenv.h" #ifdef G_OS_WIN32 @@ -240,6 +246,196 @@ gimp_gtkrc (void) return gimp_gtkrc_filename; } +/** + * gimp_path_parse: + * @path: A list of directories separated by #G_SEARCHPATH_SEPARATOR. + * @max_path: The maximum number of directories to return. + * @check: #TRUE if you want the directories to be checked. + * @not_found: # + * + * Return: A list of all directories in @path. + * + */ +GList * +gimp_path_parse (gchar *path, + gint max_paths, + gboolean check, + GList **check_failed) +{ + gchar *home; + gchar **patharray; + GList *list = NULL; + GList *fail_list = NULL; + gint i; + struct stat filestat; + gint err = FALSE; + if (!path || !*path || max_paths < 1 || max_paths > 256) + return NULL; + home = g_get_home_dir (); + + patharray = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, max_paths); + + for (i = 0; i < max_paths; i++) + { + GString *dir; + + if (!patharray[i]) + break; + + if (*patharray[i] == '~') + { + dir = g_string_new (home); + g_string_append (dir, patharray[i] + 1); + } + else + { + dir = g_string_new (patharray[i]); + } + +#ifdef __EMX__ + _fnslashify (dir); +#endif + + if (check) + { + /* check if directory exists */ + err = stat (dir->str, &filestat); + + if (!err && S_ISDIR (filestat.st_mode)) + { + if (dir->str[dir->len - 1] != G_DIR_SEPARATOR) + g_string_append_c (dir, G_DIR_SEPARATOR); + } + } + + if (!err) + list = g_list_prepend (list, dir->str); + else if (check_failed) + fail_list = g_list_prepend (fail_list, dir->str); + + g_string_free (dir, FALSE); + } + + g_strfreev (patharray); + + list = g_list_reverse (list); + + if (check && check_failed) + { + fail_list = g_list_reverse (fail_list); + *check_failed = fail_list; + } + + return list; +} + +/** + * gimp_path_to_str: + * @path: A list of directories as returned by gimp_path_parse(). + * + * Returns: A searchpath string separated by #G_SEARCHPATH_SEPARATOR. + * + */ +gchar * +gimp_path_to_str (GList *path) +{ + GString *str = NULL; + GList *list; + gchar *retval = NULL; + + for (list = path; list; list = g_list_next (list)) + { + if (str) + { + g_string_append_c (str, G_SEARCHPATH_SEPARATOR); + g_string_append (str, (gchar *) list->data); + } + else + { + str = g_string_new ((gchar *) list->data); + } + } + + if (str) + { + retval = str->str; + g_string_free (str, FALSE); + } + + return retval; +} + +/** + * gimp_path_free: + * @path: A list of directories as returned by gimp_path_parse(). + * + * This function frees the memory allocated for the list and it's strings. + * + */ +void +gimp_path_free (GList *path) +{ + GList *list; + + if (path) + { + for (list = path; list; list = g_list_next (list)) + { + g_free (list->data); + } + + g_list_free (path); + } +} + +/** + * gimp_path_get_user_writable_dir: + * @path: A list of directories as returned by gimp_path_parse(). + * + * Returns: The first directory in @path where the user has write permission. + * + */ +gchar * +gimp_path_get_user_writable_dir (GList *path) +{ + GList *list; + + uid_t euid; + gid_t egid; + + struct stat filestat; + gint err; + + euid = geteuid (); + egid = getegid (); + + for (list = path; list; list = g_list_next (list)) + { + /* check if directory exists */ + err = stat ((gchar *) list->data, &filestat); + + /* this is tricky: + * if a file is e.g. owned by the current user but not user-writable, + * the user has no permission to write to the file regardless + * of his group's or other's write permissions + */ + if (!err && S_ISDIR (filestat.st_mode) && + + ((filestat.st_mode & S_IWUSR) || + + ((filestat.st_mode & S_IWGRP) && + (euid != filestat.st_uid)) || + + ((filestat.st_mode & S_IWOTH) && + (euid != filestat.st_uid) && + (egid != filestat.st_gid)))) + { + return (gchar *) list->data; + } + } + + return NULL; +} diff --git a/libgimpbase/gimpenv.h b/libgimpbase/gimpenv.h index 3fe88e83b4..a59cee74e3 100644 --- a/libgimpbase/gimpenv.h +++ b/libgimpbase/gimpenv.h @@ -27,10 +27,19 @@ extern "C" { /* For information look into the C source or the html documentation */ -gchar* gimp_directory (void); -gchar* gimp_personal_rc_file (gchar *basename); -gchar* gimp_data_directory (void); -gchar* gimp_gtkrc (void); +gchar * gimp_directory (void); +gchar * gimp_personal_rc_file (gchar *basename); +gchar * gimp_data_directory (void); +gchar * gimp_gtkrc (void); + +GList * gimp_path_parse (gchar *path, + gint max_paths, + gboolean check, + GList **check_failed); +gchar * gimp_path_to_str (GList *path); +void gimp_path_free (GList *path); + +gchar * gimp_path_get_user_writable_dir (GList *path); #ifdef __cplusplus } diff --git a/libgimpwidgets/gimppixmap.c b/libgimpwidgets/gimppixmap.c index 1709313ec7..aaf9c52687 100644 --- a/libgimpwidgets/gimppixmap.c +++ b/libgimpwidgets/gimppixmap.c @@ -118,7 +118,7 @@ gimp_pixmap_new (gchar **xpm_data) } /** - * gimp_pixmap_new: + * gimp_pixmap_set: * @pixmap: The pixmap widget you want to set the new xpm_data for. * @xpm_data: A pointer to a XPM data structure as found in XPM files. * diff --git a/plug-ins/FractalExplorer/Dialogs.c b/plug-ins/FractalExplorer/Dialogs.c index bf759ae58b..2523cd8b2e 100644 --- a/plug-ins/FractalExplorer/Dialogs.c +++ b/plug-ins/FractalExplorer/Dialogs.c @@ -1718,24 +1718,30 @@ create_file_selection (void) "clicked", GTK_SIGNAL_FUNC (file_selection_ok), (gpointer) window); - gimp_help_set_help_data (GTK_FILE_SELECTION(window)->ok_button, _("Click here to save your file"), NULL); + gimp_help_set_help_data (GTK_FILE_SELECTION(window)->ok_button, + _("Click here to save your file"), NULL); gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(window)->cancel_button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (window)); - gimp_help_set_help_data (GTK_FILE_SELECTION(window)->cancel_button, _("Click here to cancel save procedure"), NULL); + gimp_help_set_help_data (GTK_FILE_SELECTION (window)->cancel_button, + _("Click here to cancel save procedure"), NULL); } if (tpath) { gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), tpath); } - else if(fractalexplorer_path_list) + else if (fractalexplorer_path_list) { - /* Last path is where usually saved to */ - gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), - g_list_nth (fractalexplorer_path_list, - g_list_length (fractalexplorer_path_list)-1)->data); + gchar *dir; + + dir = gimp_path_get_user_writable_dir (fractalexplorer_path_list); + + if (!dir) + dir = gimp_directory (); + + gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), dir); } else gtk_file_selection_set_filename (GTK_FILE_SELECTION (window),"/tmp"); diff --git a/plug-ins/FractalExplorer/FractalExplorer.c b/plug-ins/FractalExplorer/FractalExplorer.c index 7bc4961e61..695da3c60d 100644 --- a/plug-ins/FractalExplorer/FractalExplorer.c +++ b/plug-ins/FractalExplorer/FractalExplorer.c @@ -1135,17 +1135,11 @@ plug_in_parse_fractalexplorer_path (void) { GParam *return_vals; gint nreturn_vals; - gchar *path_string; - gchar *home; - gchar *path; - gchar *token; - gchar *next_token; - struct stat filestat; - gint err; - - if(fractalexplorer_path_list) - g_list_free(fractalexplorer_path_list); - + + GList *fail_list = NULL; + GList *list; + + gimp_path_free (fractalexplorer_path_list); fractalexplorer_path_list = NULL; return_vals = gimp_run_procedure ("gimp_gimprc_query", @@ -1164,52 +1158,28 @@ plug_in_parse_fractalexplorer_path (void) return; } - path_string = g_strdup (return_vals[1].data.d_string); + fractalexplorer_path_list = gimp_path_parse (return_vals[1].data.d_string, + 16, TRUE, &fail_list); + gimp_destroy_params (return_vals, nreturn_vals); - /* Set local path to contain temp_path, where (supposedly) - * there may be working files. - */ - home = g_get_home_dir (); - - /* Search through all directories in the path */ - - next_token = path_string; - token = strtok (next_token, G_SEARCHPATH_SEPARATOR_S); - - while (token) + if (fail_list) { - if (*token == '\0') - { - token = strtok (NULL, G_SEARCHPATH_SEPARATOR_S); - continue; - } + GString *err = + g_string_new (_("fractalexplorer-path misconfigured - " + "the following directories were not found")); - if (*token == '~') - { - path = g_strdup_printf ("%s%s", home, token + 1); - } - else - { - path = g_strdup (token); - } /* else */ + for (list = fail_list; list; list = g_list_next (list)) + { + g_string_append_c (err, '\n'); + g_string_append (err, (gchar *) list->data); + } - /* Check if directory exists */ - err = stat (path, &filestat); + g_message (err->str); - if (!err && S_ISDIR (filestat.st_mode)) - { - fractalexplorer_path_list = g_list_append (fractalexplorer_path_list, path); - } - else - { - g_message (_("fractalexplorer-path misconfigured\nPath " - "\"%s\" not found."), path); - g_free (path); - } - token = strtok (NULL, G_SEARCHPATH_SEPARATOR_S); + g_string_free (err, TRUE); + gimp_path_free (fail_list); } - g_free (path_string); } static void @@ -1448,17 +1418,11 @@ fractalexplorer_rescan_ok_callback (GtkWidget *widget, gpointer data) { GtkWidget *patheditor; - GList *list; gchar *raw_path; - gchar **path; - gint i; gtk_widget_set_sensitive (GTK_WIDGET (data), FALSE); - for (list = fractalexplorer_path_list; list; list = g_list_next (list)) - g_free (list->data); - - g_list_free (fractalexplorer_path_list); + gimp_path_free (fractalexplorer_path_list); fractalexplorer_path_list = NULL; patheditor = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (data), @@ -1466,18 +1430,9 @@ fractalexplorer_rescan_ok_callback (GtkWidget *widget, raw_path = gimp_path_editor_get_path (GIMP_PATH_EDITOR (patheditor)); - path = g_strsplit (raw_path, ":", 16); + fractalexplorer_path_list = gimp_path_parse (raw_path, 16, FALSE, NULL); - for (i = 0; i < 16; i++) - { - if (!path[i]) - break; - - fractalexplorer_path_list = g_list_append (fractalexplorer_path_list, - g_strdup (path[i])); - } - - g_strfreev (path); + g_free (raw_path); if (fractalexplorer_path_list) { @@ -1496,8 +1451,7 @@ fractalexplorer_rescan_list (void) static GtkWidget *dlg = NULL; GtkWidget *patheditor; - GString *path = NULL; - GList *list; + gchar *path; if (dlg) { @@ -1522,26 +1476,15 @@ fractalexplorer_rescan_list (void) GTK_SIGNAL_FUNC (gtk_widget_destroyed), &dlg); - for (list = fractalexplorer_path_list; list; list = g_list_next (list)) - { - if (path == NULL) - { - path = g_string_new (list->data); - } - else - { - g_string_append_c (path, G_SEARCHPATH_SEPARATOR); - g_string_append (path, list->data); - } - } + path = gimp_path_to_str (fractalexplorer_path_list); - patheditor = gimp_path_editor_new (_("Add FractalExplorer Path"), path->str); + patheditor = gimp_path_editor_new (_("Add FractalExplorer Path"), path); gtk_container_set_border_width (GTK_CONTAINER (patheditor), 6); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), patheditor, TRUE, TRUE, 0); gtk_widget_show (patheditor); - g_string_free (path, TRUE); + g_free (path); gtk_object_set_data (GTK_OBJECT (dlg), "patheditor", patheditor); diff --git a/plug-ins/gfig/gfig.c b/plug-ins/gfig/gfig.c index 0ed43c12d8..e8dfc3784e 100644 --- a/plug-ins/gfig/gfig.c +++ b/plug-ins/gfig/gfig.c @@ -134,7 +134,6 @@ static GtkWidget *gfig_preview; static GtkWidget *pic_preview; static GtkWidget *gfig_gtk_list; static gint gfig_preview_exp_id; -static GdkPixmap *gfig_pixmap; static gint32 gfig_image; static gint32 gfig_drawable; static GtkWidget *brush_page_pw; @@ -818,9 +817,7 @@ gfig_clear_selection (gint32 image_ID) } /* - * Query gimprc for gfig-path, and parse it. - * This code is based on script_fu_find_scripts () - * and the Gflare plugin. + * Query gimprc for gfig-path, and parse it. */ static void @@ -828,16 +825,12 @@ plug_in_parse_gfig_path (void) { GParam *return_vals; gint nreturn_vals; - gchar *path_string; - gchar *home; - gchar *path; - gchar *token; - gchar *next_token; - struct stat filestat; - gint err; + + GList *fail_list = NULL; + GList *list; if (gfig_path_list) - g_list_free (gfig_path_list); + gimp_path_free (gfig_path_list); gfig_path_list = NULL; @@ -849,7 +842,7 @@ plug_in_parse_gfig_path (void) if (return_vals[0].data.d_status != STATUS_SUCCESS || return_vals[1].data.d_string == NULL) { - g_message ("No gfig-path in gimprc: gfig_path_list is NULL\n\n" + g_message ("No gfig-path in gimprc:\n\n" "You need to add an entry like\n" "(gfig-path \"${gimp_dir}/gfig:${gimp_data_dir}/gfig\n" "to your ~/.gimp/gimprc file\n"); @@ -857,63 +850,28 @@ plug_in_parse_gfig_path (void) return; } - path_string = g_strdup (return_vals[1].data.d_string); + gfig_path_list = gimp_path_parse (return_vals[1].data.d_string, + 16, TRUE, &fail_list); + gimp_destroy_params (return_vals, nreturn_vals); - - /* Set local path to contain temp_path, where (supposedly) - * there may be working files. - */ - home = g_get_home_dir (); - /* Search through all directories in the path */ - - next_token = path_string; - token = strtok (next_token, G_SEARCHPATH_SEPARATOR_S); - - while (token) + if (fail_list) { - if (*token == '\0') + GString *err = + g_string_new (_("gfig-path misconfigured - " + "the following directories were not found")); + + for (list = fail_list; list; list = g_list_next (list)) { - token = strtok (NULL, G_SEARCHPATH_SEPARATOR_S); - continue; + g_string_append_c (err, '\n'); + g_string_append (err, (gchar *) list->data); } - 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); - } /* else */ -#ifdef __EMX__ - _fnslashify (path); -#endif + g_message (err->str); - /* Check if directory exists */ - err = stat (path, &filestat); - - if (!err && S_ISDIR (filestat.st_mode)) - { - if (path[strlen (path) - 1] != G_DIR_SEPARATOR) - strcat (path, G_DIR_SEPARATOR_S); - -#ifdef DEBUG - printf ("Added `%s' to gfig_path_list\n", path); -#endif /* DEBUG */ - gfig_path_list = g_list_append (gfig_path_list, path); - } - else - { - g_message ("gfig-path misconfigured - \nPath `%.100s' not found\n", - path); - } - token = strtok (NULL, G_SEARCHPATH_SEPARATOR_S); + g_string_free (err, TRUE); + gimp_path_free (fail_list); } - - g_free (path_string); } @@ -1640,15 +1598,17 @@ create_file_selection (GFigObj *obj, { gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), tpath); } - else - /* Last path is where usually saved to */ - if (gfig_path_list) - { - gtk_file_selection_set_filename - (GTK_FILE_SELECTION (window), - g_list_nth (gfig_path_list, - g_list_length (gfig_path_list) - 1)->data); - } + else if (gfig_path_list) + { + gchar *dir; + + dir = gimp_path_get_user_writable_dir (gfig_path_list); + + if (!dir) + dir = gimp_directory (); + + gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), dir); + } else gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), "/tmp"); @@ -4523,17 +4483,11 @@ gfig_rescan_ok_callback (GtkWidget *widget, gpointer data) { GtkWidget *patheditor; - GList *list; gchar *raw_path; - gchar **path; - gint i; gtk_widget_set_sensitive (GTK_WIDGET (data), FALSE); - for (list = gfig_path_list; list; list = g_list_next (list)) - g_free (list->data); - - g_list_free (gfig_path_list); + gimp_path_free (gfig_path_list); gfig_path_list = NULL; patheditor = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (data), @@ -4541,17 +4495,9 @@ gfig_rescan_ok_callback (GtkWidget *widget, raw_path = gimp_path_editor_get_path (GIMP_PATH_EDITOR (patheditor)); - path = g_strsplit (raw_path, ":", 16); + gfig_path_list = gimp_path_parse (raw_path, 16, FALSE, NULL); - for (i = 0; i < 16; i++) - { - if (!path[i]) - break; - - gfig_path_list = g_list_append (gfig_path_list, g_strdup (path[i])); - } - - g_strfreev (path); + g_free (raw_path); if (gfig_path_list) { @@ -4570,8 +4516,7 @@ gfig_rescan_list (void) static GtkWidget *dlg = NULL; GtkWidget *patheditor; - GString *path = NULL; - GList *list; + gchar *path; if (dlg) { @@ -4596,26 +4541,15 @@ gfig_rescan_list (void) GTK_SIGNAL_FUNC (gtk_widget_destroyed), &dlg); - for (list = gfig_path_list; list; list = g_list_next (list)) - { - if (path == NULL) - { - path = g_string_new (list->data); - } - else - { - g_string_append_c (path, G_SEARCHPATH_SEPARATOR); - g_string_append (path, list->data); - } - } + path = gimp_path_to_str (gfig_path_list); - patheditor = gimp_path_editor_new (_("Add Gfig Path"), path->str); + patheditor = gimp_path_editor_new (_("Add Gfig Path"), path); gtk_container_set_border_width (GTK_CONTAINER (patheditor), 6); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), patheditor, TRUE, TRUE, 0); gtk_widget_show (patheditor); - g_string_free (path, TRUE); + g_free (path); gtk_object_set_data (GTK_OBJECT (dlg), "patheditor", patheditor); diff --git a/plug-ins/gflare/gflare.c b/plug-ins/gflare/gflare.c index 242d4c9eae..df7be17fa3 100644 --- a/plug-ins/gflare/gflare.c +++ b/plug-ins/gflare/gflare.c @@ -599,7 +599,7 @@ static GFlareDialog *dlg = NULL; static GFlareEditor *ed = NULL; static GList *gflares_list = NULL; static gint num_gflares = 0; -GList *gflare_path_list; +static GList *gflare_path_list = NULL; static CalcParams calc; static GList *gradient_menus; static gchar **gradient_names = NULL; @@ -967,14 +967,11 @@ plug_in_parse_gflare_path (void) { GParam *return_vals; gint nreturn_vals; - gchar *path_string; - gchar *home; - gchar *path; - gchar *token; - gchar *next_token; - struct stat filestat; - gint err; + GList *fail_list = NULL; + GList *list; + + gimp_path_free (gflare_path_list); gflare_path_list = NULL; return_vals = gimp_run_procedure ("gimp_gimprc_query", @@ -982,62 +979,40 @@ plug_in_parse_gflare_path (void) PARAM_STRING, "gflare-path", PARAM_END); - if (return_vals[0].data.d_status != STATUS_SUCCESS || return_vals[1].data.d_string == NULL) + if (return_vals[0].data.d_status != STATUS_SUCCESS || + return_vals[1].data.d_string == NULL) { - DEBUG_PRINT ("No gflare-path in gimprc: gflare_path_list is NULL\n"); + g_message ("No gflare-path in gimprc:\n\n" + "You need to add an entry like\n" + "(gfig-path \"${gimp_dir}/gfig:${gimp_data_dir}/gfig\n" + "to your ~/.gimp/gimprc file\n"); gimp_destroy_params (return_vals, nreturn_vals); return; } - path_string = g_strdup (return_vals[1].data.d_string); + + gflare_path_list = gimp_path_parse (return_vals[1].data.d_string, + 16, TRUE, &fail_list); + gimp_destroy_params (return_vals, nreturn_vals); - home = g_get_home_dir (); - - /* Search through all directories in the path */ - - next_token = path_string; - token = strtok (next_token, G_SEARCHPATH_SEPARATOR_S); - - while (token) + if (fail_list) { - if (*token == '\0') - { - token = strtok (NULL, G_SEARCHPATH_SEPARATOR_S); - continue; - } + GString *err = + g_string_new (_("gflare-path misconfigured - " + "the following directories were not found")); - 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); - } /* else */ + for (list = fail_list; list; list = g_list_next (list)) + { + g_string_append_c (err, '\n'); + g_string_append (err, (gchar *) list->data); + } - /* Check if directory exists */ - err = stat (path, &filestat); + g_message (err->str); - if (!err && S_ISDIR (filestat.st_mode)) - { - if (path[strlen (path) - 1] != G_DIR_SEPARATOR) - strcat (path, G_DIR_SEPARATOR_S); - - DEBUG_PRINT(("Added `%s' to gflare_path_list\n", path)); - gflare_path_list = g_list_append (gflare_path_list, path); - } - else - { - DEBUG_PRINT(("Not found `%s'\n", path)); - g_free (path); - } - token = strtok (NULL, G_SEARCHPATH_SEPARATOR_S); + g_string_free (err, TRUE); + gimp_path_free (fail_list); } - g_free (path_string); - } @@ -1548,14 +1523,12 @@ gflare_save (GFlare *gflare) if (gflare_path_list == NULL) { if (!message_ok) - g_message (message, - gflare->name); + g_message (message, gflare->name); message_ok = TRUE; return; } - /* get first entry of path */ - path = gflare_path_list->data; + path = gimp_path_get_user_writable_dir (gflare_path_list); gflare->filename = g_strdup_printf ("%s%s", path, gflare->name); } diff --git a/plug-ins/gimpressionist/gimpressionist.c b/plug-ins/gimpressionist/gimpressionist.c index 3e8fe628d7..b1f06b6d40 100644 --- a/plug-ins/gimpressionist/gimpressionist.c +++ b/plug-ins/gimpressionist/gimpressionist.c @@ -21,7 +21,6 @@ #include "ppmtool.h" #include #include -/* #include */ #ifndef GIMP_CHECK_VERSION #define GIMP_CHECK_VERSION(a,b,c) 0 @@ -40,15 +39,16 @@ GtkTooltips *tooltips = NULL; struct ppm infile = {0,0,NULL}; struct ppm inalpha = {0,0,NULL}; -GList *parsepath(void) +GList * parsepath (void) { GParam *return_vals; gint nreturn_vals; static GList *lastpath = NULL; - char *gimpdatasubdir, *defaultpath, *tmps, *lastchr; + gchar *gimpdatasubdir, *defaultpath, *tmps; struct stat st; - if(lastpath) return lastpath; + if (lastpath) + return lastpath; #if GIMP_CHECK_VERSION(1, 1, 0) gimpdatasubdir = g_strconcat (gimp_data_directory (), @@ -68,54 +68,46 @@ GList *parsepath(void) gimpdatasubdir = strchr (defaultpath, ':') + 1; #endif - if(standalone) - tmps = g_strdup(defaultpath); - else { - return_vals = gimp_run_procedure ("gimp_gimprc_query", &nreturn_vals, - PARAM_STRING, "gimpressionist-path", - PARAM_END); - if(return_vals[0].data.d_status != STATUS_SUCCESS || - return_vals[1].data.d_string == NULL) { - if (stat (gimpdatasubdir, &st) != 0 - || !S_ISDIR(st.st_mode)) { - /* No gimpressionist-path parameter, and the default doesn't exist */ -#if GIMP_CHECK_VERSION(1, 1, 0) - g_message( "*** Warning ***\n" - "It is highly recommended to add\n" - " (gimpressionist-path \"${gimp_dir}" G_DIR_SEPARATOR_S "gimpressionist" - G_SEARCHPATH_SEPARATOR_S - "${gimp_data_dir}" G_DIR_SEPARATOR_S "gimpressionist\")\n" - "(or similar) to your gimprc file.\n"); -#else - g_message( _("*** Warning ***\nIt is highly recommended to add\n (gimpressionist-path \"%s\")\n(or similar) to your gimprc file.\n"), defaultpath); -#endif - } - tmps = g_strdup(defaultpath); - } else { - tmps = g_strdup(return_vals[1].data.d_string); - } - gimp_destroy_params (return_vals, nreturn_vals); - } + if (standalone) + tmps = g_strdup (defaultpath); + else + { + return_vals = gimp_run_procedure ("gimp_gimprc_query", &nreturn_vals, + PARAM_STRING, "gimpressionist-path", + PARAM_END); - for(;;) { - lastchr = strchr(tmps, G_SEARCHPATH_SEPARATOR); - if(lastchr) *lastchr = '\0'; - if(*tmps == '~') { - char *tmps2, *home; - home = g_get_home_dir (); - if(!home) { - g_message( _("*** Warning ***\nNo home directory!\n")); - home = ""; - } - tmps2 = g_strconcat(home, tmps + 1, NULL); - tmps = tmps2; + if (return_vals[0].data.d_status != STATUS_SUCCESS || + return_vals[1].data.d_string == NULL) + { + if (stat (gimpdatasubdir, &st) != 0 + || !S_ISDIR(st.st_mode)) + { + /* No gimpressionist-path parameter, + * and the default doesn't exist */ +#if GIMP_CHECK_VERSION(1, 1, 0) + g_message( "*** Warning ***\n" + "It is highly recommended to add\n" + " (gimpressionist-path \"${gimp_dir}" G_DIR_SEPARATOR_S "gimpressionist" + G_SEARCHPATH_SEPARATOR_S + "${gimp_data_dir}" G_DIR_SEPARATOR_S "gimpressionist\")\n" + "(or similar) to your gimprc file.\n"); +#else + g_message( _("*** Warning ***\nIt is highly recommended to add\n (gimpressionist-path \"%s\")\n(or similar) to your gimprc file.\n"), defaultpath); +#endif + } + tmps = g_strdup (defaultpath); + } + else + { + tmps = g_strdup (return_vals[1].data.d_string); + } + gimp_destroy_params (return_vals, nreturn_vals); } - lastpath = g_list_append(lastpath, tmps); - if(lastchr) - tmps = lastchr + 1; - else - break; - } + + lastpath = gimp_path_parse (tmps, 16, FALSE, NULL); + + g_free (tmps); + return lastpath; }