Commit ed071953 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

fixed a gtk-doc comment.

2000-02-21  Michael Natterer  <mitch@gimp.org>

	* 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.
parent d4b05436
2000-02-21 Michael Natterer <mitch@gimp.org>
* 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 <sven@gimp.org>
* app/gimpbrushlist.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]);
}
{
_chdrive (local_path[0]);
}
#endif
/* Search through all directories in the local path */
next_token = local_path;
path = gimp_path_parse (local_path, 16, TRUE, NULL);
token = xstrsep(&next_token, G_SEARCHPATH_SEPARATOR_S);
while (token)
for (list = path; list; list = g_list_next (list))
{
if (*token == '~')
/* 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", path, 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)))
{
filestat_valid = 1;
(*loader_func) (filename);
filestat_valid = 0;
}
filename = g_strdup_printf ("%s%s",
(gchar *) list->data,
dir_ent->d_name);
g_free(filename);
} /* while */
/* Check the file and see that it is not a sub-directory */
err = stat (filename, &filestat);
closedir(dir);
} /* else */
} /* if */
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;
}
g_free(path);
g_free (filename);
}
token = xstrsep(&next_token, G_SEARCHPATH_SEPARATOR_S);
} /* while */
closedir (dir);
}
}
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;
......
......@@ -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 <time.h>
#include <glib.h>
#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__ */
......@@ -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]);
}
{
_chdrive (local_path[0]);
}
#endif
/* Search through all directories in the local path */
next_token = local_path;
path = gimp_path_parse (local_path, 16, TRUE, NULL);
token = xstrsep(&next_token, G_SEARCHPATH_SEPARATOR_S);
while (token)
for (list = path; list; list = g_list_next (list))
{
if (*token == '~')
/* 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", path, 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)))
{
filestat_valid = 1;
(*loader_func) (filename);
filestat_valid = 0;
}
filename = g_strdup_printf ("%s%s",
(gchar *) list->data,
dir_ent->d_name);
g_free(filename);
} /* while */
/* Check the file and see that it is not a sub-directory */
err = stat (filename, &filestat);
closedir(dir);
} /* else */
} /* if */
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;
}
g_free(path);
g_free (filename);
}
token = xstrsep(&next_token, G_SEARCHPATH_SEPARATOR_S);
} /* while */
closedir (dir);
}
}
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;
......
......@@ -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 <time.h>
#include <glib.h>
#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__ */
......@@ -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 ();
}
......
......@@ -22,6 +22,12 @@
#include <glib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#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);