1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* Datafiles module copyight (C) 1996 Federico Mena Quintero
|
|
|
|
* federico@nuclecu.unam.mx
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-29 23:22:01 +08:00
|
|
|
|
1999-02-21 07:20:54 +08:00
|
|
|
#include "config.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
Check for mmap.
* configure.in: Check for mmap.
* app/makefile.msc: Depend on gimpi.lib.
* app/app_procs.c (app_init): Fix gccism: Allocate filenames (an
array with non-constant size) dynamically.
* app/{datafiles,fileops,general,install,module_db,temp_buf}.c:
Include glib.h before standard headers, because of certain obscure
details related to compiling with gcc on Win32.
(If you really want to know: glib.h defines he names of POSIXish
(but non-ANSI) functions as prefixed with underscore, because
that's how they are named in the msvcrt runtime C library we want
to use. However, defining stat as _stat causes some problems if
done after including the mingw32 <sys/stat.h>. So, it's easiest to
include <glib.h> early.)
* app/main.c: Use _stdcall and __argc, __argv with MSC, but
__attribute__((stdcall)) and _argc, _argv with gcc. Don't print
the "Passed serialization test" message on Win32. (It would open
up an otherwise unnecessary console window.)
* app/paint_funcs.c (gaussian_blur_region): Don't use variable sum
until initialized.
* app/{bezier_select,paths_dialog}.c: Include config.h and define
rint() if necessary.
* app/plug_in.c: Use _spawnv, not spawnv, on Win32 and OS/2.
1999-05-29 01:47:17 +08:00
|
|
|
#include <glib.h>
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1999-05-05 20:32:24 +08:00
|
|
|
#include <sys/types.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <sys/stat.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <unistd.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_DIRENT_H
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <dirent.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#endif
|
|
|
|
|
1999-10-05 03:26:07 +08:00
|
|
|
#ifdef G_OS_WIN32
|
1999-02-21 07:20:54 +08:00
|
|
|
#ifndef S_ISDIR
|
|
|
|
#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
|
|
|
|
#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
|
|
|
|
#endif
|
libgimp/gimp.def libgimp/gimpui.def libgimp/makefile.{cygwin,msc}
2000-02-15 Tor Lillqvist <tml@iki.fi>
* libgimp/gimp.def
* libgimp/gimpui.def
* libgimp/makefile.{cygwin,msc}
* app/makefile.{cygwin,msc}
* plug-ins/makefile.{cygwin,msc}: Updates.
* app/datafiles.c (is_script): New Win32-only function, which
tests if a file's extension matches one of the extensions in the
PATHEXT environment variable (which the cmd.exe command
interpreter also uses). This is to avoid starting applications
associated with any random data file the user might have dropped
in the plug-ins folder, while still supporting plug-ins written in
scripting languages.
* app/gimpparasite.c (gimp_parasiterc_save): (Win32:) Cannot
rename to an existing file.
* plug-ins/Lighting/lighting_image.c
* plug-ins/Lighting/lighting_share.c
* plug-ins/MapObject/mapobject_preview.c
* plug-ins/MapObject/mapobject_shade.c: Use G_PI.
* plug-ins/common/gz.c: #ifdef G_OS_WIN32 was used before its
potential definition via glib.h.
* plug-ins/common/jpeg.c: Also recognize Exif files, which are
typically produced by digital cameras. The usually have a .jpg
file name extension, and would thus already match this plug-in,
but add the magic string just in case. They are loaded just fine
by libjpeg even if they don't have the JFIF signature.
* plug-ins/common/tiff.c: Set TIFF warning and error handler, so
we get to pass libtiff's messages through the normal channels.
2000-02-15 06:44:06 +08:00
|
|
|
#ifndef S_IXUSR
|
|
|
|
#define S_IXUSR _S_IEXEC
|
|
|
|
#endif
|
Add gimpcolorspace object.
2000-01-04 Tor Lillqvist <tml@iki.fi>
* libgimp/makefile.{cygwin.msc}: Add gimpcolorspace object.
* libgimp/gimp.def: Add functions from it.
Fixes from Hans Breuer:
* app/datafiles.c: redefine the executable flag for Win32
to _S_IREAD, to get _all_ files from the plug-in dirs as
executables (including scripts)
* app/main.c: Win32-specific changes to allow building Gimp as a
console application, with all its benefits (like inheriting the
console), but hide it if the user doesn't want it. Also, if stdout
goes to a console, give the user a chance to read the help or
version messages. (tml: I am not convinced that it is better to
build gimp as a console application, but let's try it this way for
a while.)
* app/makefile.{cygwin,msc}: Build as console application, and
link with shell32 library.
* app/paint_core.c (paint_core_motion): Pass the value of a call
to the function gimage_active_drawable() to the paint_func,
instead of just passing the address of gimage_active_drawable...
(tml: This code is only called when the TOOL_TRACES_ON_WINDOW flag
is on, and only the clone tool sets that, and the clone tool's
paint_func doesn't use the drawable argument, so this hasn't
caused any trouble.)
* app/plug_in.c: On Win32, to support scripts, use new function
xspawn() instead of _spawnv. Add some more code to properly kill
plug-ins.
* libgimp/color_display.h: Add G_MODULE_EXPORT declarations.
2000-01-05 01:46:41 +08:00
|
|
|
#endif /* G_OS_WIN32 */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-22 04:30:16 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core/core-types.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "datafiles.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2000-02-22 23:14:54 +08:00
|
|
|
static gboolean filestat_valid = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
static struct stat filestat;
|
|
|
|
|
2001-01-14 11:55:56 +08:00
|
|
|
|
libgimp/gimp.def libgimp/gimpui.def libgimp/makefile.{cygwin,msc}
2000-02-15 Tor Lillqvist <tml@iki.fi>
* libgimp/gimp.def
* libgimp/gimpui.def
* libgimp/makefile.{cygwin,msc}
* app/makefile.{cygwin,msc}
* plug-ins/makefile.{cygwin,msc}: Updates.
* app/datafiles.c (is_script): New Win32-only function, which
tests if a file's extension matches one of the extensions in the
PATHEXT environment variable (which the cmd.exe command
interpreter also uses). This is to avoid starting applications
associated with any random data file the user might have dropped
in the plug-ins folder, while still supporting plug-ins written in
scripting languages.
* app/gimpparasite.c (gimp_parasiterc_save): (Win32:) Cannot
rename to an existing file.
* plug-ins/Lighting/lighting_image.c
* plug-ins/Lighting/lighting_share.c
* plug-ins/MapObject/mapobject_preview.c
* plug-ins/MapObject/mapobject_shade.c: Use G_PI.
* plug-ins/common/gz.c: #ifdef G_OS_WIN32 was used before its
potential definition via glib.h.
* plug-ins/common/jpeg.c: Also recognize Exif files, which are
typically produced by digital cameras. The usually have a .jpg
file name extension, and would thus already match this plug-in,
but add the magic string just in case. They are loaded just fine
by libjpeg even if they don't have the JFIF signature.
* plug-ins/common/tiff.c: Set TIFF warning and error handler, so
we get to pass libtiff's messages through the normal channels.
2000-02-15 06:44:06 +08:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
/*
|
2000-02-22 23:14:54 +08:00
|
|
|
* On Windows there is no concept like the Unix executable flag.
|
libgimp/gimp.def libgimp/gimpui.def libgimp/makefile.{cygwin,msc}
2000-02-15 Tor Lillqvist <tml@iki.fi>
* libgimp/gimp.def
* libgimp/gimpui.def
* libgimp/makefile.{cygwin,msc}
* app/makefile.{cygwin,msc}
* plug-ins/makefile.{cygwin,msc}: Updates.
* app/datafiles.c (is_script): New Win32-only function, which
tests if a file's extension matches one of the extensions in the
PATHEXT environment variable (which the cmd.exe command
interpreter also uses). This is to avoid starting applications
associated with any random data file the user might have dropped
in the plug-ins folder, while still supporting plug-ins written in
scripting languages.
* app/gimpparasite.c (gimp_parasiterc_save): (Win32:) Cannot
rename to an existing file.
* plug-ins/Lighting/lighting_image.c
* plug-ins/Lighting/lighting_share.c
* plug-ins/MapObject/mapobject_preview.c
* plug-ins/MapObject/mapobject_shade.c: Use G_PI.
* plug-ins/common/gz.c: #ifdef G_OS_WIN32 was used before its
potential definition via glib.h.
* plug-ins/common/jpeg.c: Also recognize Exif files, which are
typically produced by digital cameras. The usually have a .jpg
file name extension, and would thus already match this plug-in,
but add the magic string just in case. They are loaded just fine
by libjpeg even if they don't have the JFIF signature.
* plug-ins/common/tiff.c: Set TIFF warning and error handler, so
we get to pass libtiff's messages through the normal channels.
2000-02-15 06:44:06 +08:00
|
|
|
* There is a weak emulation provided by the MS C Runtime using file
|
|
|
|
* extensions (com, exe, cmd, bat). This needs to be extended to treat
|
|
|
|
* scripts (Python, Perl, ...) as executables, too. We use the PATHEXT
|
|
|
|
* variable, which is also used by cmd.exe.
|
|
|
|
*/
|
2000-02-22 23:14:54 +08:00
|
|
|
static gboolean
|
2000-02-22 01:15:30 +08:00
|
|
|
is_script (const gchar *filename)
|
libgimp/gimp.def libgimp/gimpui.def libgimp/makefile.{cygwin,msc}
2000-02-15 Tor Lillqvist <tml@iki.fi>
* libgimp/gimp.def
* libgimp/gimpui.def
* libgimp/makefile.{cygwin,msc}
* app/makefile.{cygwin,msc}
* plug-ins/makefile.{cygwin,msc}: Updates.
* app/datafiles.c (is_script): New Win32-only function, which
tests if a file's extension matches one of the extensions in the
PATHEXT environment variable (which the cmd.exe command
interpreter also uses). This is to avoid starting applications
associated with any random data file the user might have dropped
in the plug-ins folder, while still supporting plug-ins written in
scripting languages.
* app/gimpparasite.c (gimp_parasiterc_save): (Win32:) Cannot
rename to an existing file.
* plug-ins/Lighting/lighting_image.c
* plug-ins/Lighting/lighting_share.c
* plug-ins/MapObject/mapobject_preview.c
* plug-ins/MapObject/mapobject_shade.c: Use G_PI.
* plug-ins/common/gz.c: #ifdef G_OS_WIN32 was used before its
potential definition via glib.h.
* plug-ins/common/jpeg.c: Also recognize Exif files, which are
typically produced by digital cameras. The usually have a .jpg
file name extension, and would thus already match this plug-in,
but add the magic string just in case. They are loaded just fine
by libjpeg even if they don't have the JFIF signature.
* plug-ins/common/tiff.c: Set TIFF warning and error handler, so
we get to pass libtiff's messages through the normal channels.
2000-02-15 06:44:06 +08:00
|
|
|
{
|
|
|
|
const gchar *ext = strrchr (filename, '.');
|
|
|
|
gchar *pathext;
|
|
|
|
static gchar **exts = NULL;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (exts == NULL)
|
|
|
|
{
|
|
|
|
pathext = g_getenv ("PATHEXT");
|
|
|
|
if (pathext != NULL)
|
|
|
|
{
|
|
|
|
exts = g_strsplit (pathext, G_SEARCHPATH_SEPARATOR_S, 100);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
exts = g_new (gchar *, 1);
|
|
|
|
exts[0] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (exts[i] != NULL)
|
|
|
|
{
|
|
|
|
if (g_strcasecmp (ext, exts[i]) == 0)
|
|
|
|
return TRUE;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#else /* !G_OS_WIN32 */
|
|
|
|
#define is_script(filename) FALSE
|
|
|
|
#endif
|
|
|
|
|
2001-02-12 00:14:25 +08:00
|
|
|
gboolean
|
2001-05-10 06:34:59 +08:00
|
|
|
gimp_datafiles_check_extension (const gchar *filename,
|
|
|
|
const gchar *extension)
|
2001-02-12 00:14:25 +08:00
|
|
|
{
|
|
|
|
gint name_len;
|
|
|
|
gint ext_len;
|
|
|
|
|
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (extension != NULL, FALSE);
|
|
|
|
|
|
|
|
name_len = strlen (filename);
|
|
|
|
ext_len = strlen (extension);
|
|
|
|
|
|
|
|
if (! (name_len && ext_len && (name_len > ext_len)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return (strcmp (&filename[name_len - ext_len], extension) == 0);
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
2001-05-10 06:34:59 +08:00
|
|
|
gimp_datafiles_read_directories (const gchar *path_str,
|
|
|
|
GimpDataFileFlags flags,
|
|
|
|
GimpDataFileLoaderFunc loader_func,
|
|
|
|
gpointer loader_data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-02-22 01:15:30 +08:00
|
|
|
gchar *local_path;
|
|
|
|
GList *path;
|
|
|
|
GList *list;
|
|
|
|
gchar *filename;
|
|
|
|
gint err;
|
|
|
|
DIR *dir;
|
1997-11-25 06:05:25 +08:00
|
|
|
struct dirent *dir_ent;
|
|
|
|
|
2001-02-12 00:14:25 +08:00
|
|
|
g_return_if_fail (path_str != NULL);
|
|
|
|
g_return_if_fail (loader_func != NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
local_path = g_strdup (path_str);
|
2000-02-22 01:15:30 +08:00
|
|
|
|
1999-08-06 19:14:01 +08:00
|
|
|
#ifdef __EMX__
|
|
|
|
/*
|
|
|
|
* Change drive so opendir works.
|
|
|
|
*/
|
|
|
|
if (local_path[1] == ':')
|
2000-02-22 01:15:30 +08:00
|
|
|
{
|
|
|
|
_chdrive (local_path[0]);
|
|
|
|
}
|
2001-05-21 21:58:46 +08:00
|
|
|
#endif
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
path = gimp_path_parse (local_path, 16, TRUE, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
for (list = path; list; list = g_list_next (list))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-02-22 01:15:30 +08:00
|
|
|
/* Open directory */
|
|
|
|
dir = opendir ((gchar *) list->data);
|
|
|
|
|
|
|
|
if (!dir)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-02-22 01:15:30 +08:00
|
|
|
g_message ("error reading datafiles directory \"%s\"",
|
|
|
|
(gchar *) list->data);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-02-22 23:14:54 +08:00
|
|
|
while ((dir_ent = readdir (dir)))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-02-22 01:15:30 +08:00
|
|
|
filename = g_strdup_printf ("%s%s",
|
|
|
|
(gchar *) list->data,
|
|
|
|
dir_ent->d_name);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
/* Check the file and see that it is not a sub-directory */
|
|
|
|
err = stat (filename, &filestat);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
if (!err && S_ISREG (filestat.st_mode) &&
|
|
|
|
(!(flags & MODE_EXECUTABLE) ||
|
|
|
|
(filestat.st_mode & S_IXUSR) ||
|
|
|
|
is_script (filename)))
|
|
|
|
{
|
2000-02-22 23:14:54 +08:00
|
|
|
filestat_valid = TRUE;
|
2001-02-12 00:14:25 +08:00
|
|
|
|
|
|
|
(* loader_func) (filename, loader_data);
|
|
|
|
|
2000-02-22 23:14:54 +08:00
|
|
|
filestat_valid = FALSE;
|
2000-02-22 01:15:30 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
g_free (filename);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
closedir (dir);
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-22 01:15:30 +08:00
|
|
|
gimp_path_free (path);
|
2000-02-24 09:52:31 +08:00
|
|
|
g_free (local_path);
|
2000-02-22 01:15:30 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
time_t
|
2001-05-10 06:34:59 +08:00
|
|
|
gimp_datafile_atime (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (filestat_valid)
|
|
|
|
return filestat.st_atime;
|
2001-01-14 11:55:56 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t
|
2001-05-10 06:34:59 +08:00
|
|
|
gimp_datafile_mtime (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (filestat_valid)
|
|
|
|
return filestat.st_mtime;
|
2001-01-14 11:55:56 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t
|
2001-05-10 06:34:59 +08:00
|
|
|
gimp_datafile_ctime (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (filestat_valid)
|
|
|
|
return filestat.st_ctime;
|
2001-01-14 11:55:56 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|