gimp/libgimpbase/gimpenv.c

566 lines
13 KiB
C
Raw Normal View History

1999-03-07 20:56:03 +08:00
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimpenv.c
1999-03-07 20:56:03 +08:00
*
* Copyright (C) 1999 Tor Lillqvist
*
* This program is free software; you can redistribute it and/or modify
Regarding the GPL => LGPL change: ----------------------------------------------------------------------------- Hi. The following files in libgimp/ state that they are GPL'ed, rather than LGPL'ed: gimpenv.c color_selector.h color_display.h I looked through the cvs logs of these files and found these "authors" (the files may be older, but it's all I got): * Manish Singh <yosh@gimp.org> * ape@spacetec.no (Asbjorn Pettersen) * Tor Lillqvist <tml@iki.fi> * Austin Donnelly <austin@gimp.org> * Michael Natterer <mitch@gimp.org> petm@xcf.berkeley.edu spencer@xcf.berkeley.edu I'd like to change the notice to LGPL again. If all of you agree with this (just reply with a "yes") then I will just do this and paste your replies into the log file. ----------------------------------------------------------------------------- Date: Wed, 17 Nov 1999 23:30:27 +0200 (EET) From: Tor Lillqvist <tml@sgic.fi> Message-Id: <199911172130.XAA18357@platon.sgic.fi> > I'd like to change the notice to LGPL again. If all of you agree with this > (just reply with a "yes") then I will just do this and paste your replies > into the log file. YES! --tml ----------------------------------------------------------------------------- Date: Wed, 17 Nov 1999 13:31:45 -0800 From: Manish Singh <yosh@gimp.org> Message-ID: <19991117133145.A7895@wilber.gimp.org> On Wed, Nov 17, 1999 at 10:26:25PM +0100, Marc Lehmann wrote: > Hi. The following files in libgimp/ state that they are GPL'ed, rather than > LGPL'ed: > > gimpenv.c Needs S&P approval too. (yes for me) ----------------------------------------------------------------------------- Message-ID: <3833B9B6.6AD4B80A@cs.tu-berlin.de> Date: Thu, 18 Nov 1999 09:32:54 +0100 From: Michael Natterer <mitschel@cs.tu-berlin.de> > I'd like to change the notice to LGPL again. If all of you agree with this > (just reply with a "yes") then I will just do this and paste your replies > into the log file. Yes ;-) (go for it please...) --Mitch ----------------------------------------------------------------------------- Message-Id: <199911180815.JAA17782@spacetec.no> From: "Asbjoern Pettersen" <ape@spacetec.no> Date: Thu, 18 Nov 99 09:15:14 OK for me. (asbjorn) >> Tor Lillqvist <tml@iki.fi> >> Austin Donnelly <austin@gimp.org> >> Michael Natterer <mitch@gimp.org> >> >> I'd like to change the notice to LGPL again. If all of you agree with this >> (just reply with a "yes") then I will just do this and paste your replies >> into the log file. ----------------------------------------------------------------------------- Message-ID: <14387.56381.340662.797845@bailey.cl.cam.ac.uk> From: Austin Donnelly <Austin.Donnelly@cl.cam.ac.uk> Date: Thu, 18 Nov 1999 11:00:13 +0000 (GMT) [...] Yes, I don't mind them going under LGPL. Austin
2000-01-16 05:30:17 +08:00
* it under the terms of the GNU Lesser General Public License as published by
1999-03-07 20:56:03 +08:00
* 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.
*
Regarding the GPL => LGPL change: ----------------------------------------------------------------------------- Hi. The following files in libgimp/ state that they are GPL'ed, rather than LGPL'ed: gimpenv.c color_selector.h color_display.h I looked through the cvs logs of these files and found these "authors" (the files may be older, but it's all I got): * Manish Singh <yosh@gimp.org> * ape@spacetec.no (Asbjorn Pettersen) * Tor Lillqvist <tml@iki.fi> * Austin Donnelly <austin@gimp.org> * Michael Natterer <mitch@gimp.org> petm@xcf.berkeley.edu spencer@xcf.berkeley.edu I'd like to change the notice to LGPL again. If all of you agree with this (just reply with a "yes") then I will just do this and paste your replies into the log file. ----------------------------------------------------------------------------- Date: Wed, 17 Nov 1999 23:30:27 +0200 (EET) From: Tor Lillqvist <tml@sgic.fi> Message-Id: <199911172130.XAA18357@platon.sgic.fi> > I'd like to change the notice to LGPL again. If all of you agree with this > (just reply with a "yes") then I will just do this and paste your replies > into the log file. YES! --tml ----------------------------------------------------------------------------- Date: Wed, 17 Nov 1999 13:31:45 -0800 From: Manish Singh <yosh@gimp.org> Message-ID: <19991117133145.A7895@wilber.gimp.org> On Wed, Nov 17, 1999 at 10:26:25PM +0100, Marc Lehmann wrote: > Hi. The following files in libgimp/ state that they are GPL'ed, rather than > LGPL'ed: > > gimpenv.c Needs S&P approval too. (yes for me) ----------------------------------------------------------------------------- Message-ID: <3833B9B6.6AD4B80A@cs.tu-berlin.de> Date: Thu, 18 Nov 1999 09:32:54 +0100 From: Michael Natterer <mitschel@cs.tu-berlin.de> > I'd like to change the notice to LGPL again. If all of you agree with this > (just reply with a "yes") then I will just do this and paste your replies > into the log file. Yes ;-) (go for it please...) --Mitch ----------------------------------------------------------------------------- Message-Id: <199911180815.JAA17782@spacetec.no> From: "Asbjoern Pettersen" <ape@spacetec.no> Date: Thu, 18 Nov 99 09:15:14 OK for me. (asbjorn) >> Tor Lillqvist <tml@iki.fi> >> Austin Donnelly <austin@gimp.org> >> Michael Natterer <mitch@gimp.org> >> >> I'd like to change the notice to LGPL again. If all of you agree with this >> (just reply with a "yes") then I will just do this and paste your replies >> into the log file. ----------------------------------------------------------------------------- Message-ID: <14387.56381.340662.797845@bailey.cl.cam.ac.uk> From: Austin Donnelly <Austin.Donnelly@cl.cam.ac.uk> Date: Thu, 18 Nov 1999 11:00:13 +0000 (GMT) [...] Yes, I don't mind them going under LGPL. Austin
2000-01-16 05:30:17 +08:00
* You should have received a copy of the GNU Lesser General Public License
1999-03-07 20:56:03 +08:00
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib.h>
#include <string.h>
#include <sys/types.h>
2000-02-26 05:06:52 +08:00
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
1999-03-07 20:56:03 +08:00
#include "gimpenv.h"
#ifdef G_OS_WIN32
1999-03-07 20:56:03 +08:00
#define STRICT
#include <windows.h> /* For GetModuleFileName */
#include <io.h>
#ifndef S_IWUSR
# define S_IWUSR _S_IWRITE
#endif
#ifndef S_IWGRP
#define S_IWGRP (_S_IWRITE>>3)
#define S_IWOTH (_S_IWRITE>>6)
#endif
#ifndef S_ISDIR
# define __S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask))
# define S_ISDIR(mode) __S_ISTYPE((mode), _S_IFDIR)
#endif
#define uid_t gint
#define gid_t gint
#define geteuid() 0
#define getegid() 0
1999-03-07 20:56:03 +08:00
#endif
1999-04-24 22:54:47 +08:00
#ifdef __EMX__
extern const char *__XOS2RedirRoot(const char *);
#endif
2000-02-07 07:16:24 +08:00
/**
* gimp_directory:
*
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
* Returns the user-specific GIMP settings directory. If the
* environment variable GIMP_DIRECTORY exists, it is used. If it is an
* absolute path, it is used as is. If it is a relative path, it is
* taken to be a subdirectory of the home directory. If it is a
* relative path, and no home directory can be determined, it is taken
* to be a subdirectory of gimp_data_directory().
2000-02-07 07:16:24 +08:00
*
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
* The usual case is that no GIMP_DIRECTORY environment variable
* exists, and then we use the GIMPDIR subdirectory of the home
* directory. If no home directory exists, we use a per-user
* subdirectory of gimp_data_directory(). In any case, we always
* return some non-empty string, whether it corresponds to an existing
* directory or not.
2000-02-07 07:16:24 +08:00
*
* The returned string is allocated just once, and should *NOT* be
* freed with g_free().
*
* Returns: The user-specific GIMP settings directory.
**/
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
const gchar *
2000-02-07 07:16:24 +08:00
gimp_directory (void)
1999-03-07 20:56:03 +08:00
{
2000-02-07 07:16:24 +08:00
static gchar *gimp_dir = NULL;
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
const gchar *env_gimp_dir;
const gchar *home_dir;
gchar *home_dir_sep;
1999-03-07 20:56:03 +08:00
if (gimp_dir != NULL)
return gimp_dir;
env_gimp_dir = g_getenv ("GIMP_DIRECTORY");
home_dir = g_get_home_dir ();
if (home_dir != NULL && home_dir[strlen (home_dir)-1] != G_DIR_SEPARATOR)
home_dir_sep = G_DIR_SEPARATOR_S;
else
home_dir_sep = "";
1999-03-07 20:56:03 +08:00
if (NULL != env_gimp_dir)
{
if (g_path_is_absolute (env_gimp_dir))
gimp_dir = g_strdup (env_gimp_dir);
1999-03-07 20:56:03 +08:00
else
{
if (NULL != home_dir)
{
gimp_dir = g_strconcat (home_dir,
home_dir_sep,
1999-03-07 20:56:03 +08:00
env_gimp_dir,
NULL);
}
else
{
gimp_dir = g_strconcat (gimp_data_directory (),
G_DIR_SEPARATOR_S,
env_gimp_dir,
NULL);
}
}
}
else
{
1999-08-06 19:14:01 +08:00
#ifdef __EMX__
gimp_dir = g_strdup(__XOS2RedirRoot(GIMPDIR));
return gimp_dir;
#endif
if (NULL != home_dir)
1999-03-07 20:56:03 +08:00
{
gimp_dir = g_strconcat (home_dir,
home_dir_sep,
GIMPDIR,
NULL);
1999-03-07 20:56:03 +08:00
}
else
{
#ifndef G_OS_WIN32
1999-11-23 06:38:02 +08:00
g_message ("warning: no home directory.");
app/makefile.cygwin app/makefile.msc plug-ins/makefile.cygwin * app/makefile.cygwin * app/makefile.msc * plug-ins/makefile.cygwin * plug-ins/makefile.msc * modules/makefile.cygwin * modules/makefile.msc * tools/gcg/makefile.cygwin: Various updates. GCC-compiled DLL name change. * app/context_manager.c: Include paint_options.h for prototype. * app/gimpimage.c (gimp_image_initialize_projection): Break out of loop as soon as possible. * app/menus.c (menus_last_opened_cmd_callback): Check if referring to entry not in list. * app/module_db.c (valid_module_name): (Win32) Require module DLL names to include name of compiler built with. * app/paths_dialog.c (paths_draw_segment_points): No use to draw lines if we have less that two points. * app/qmask.c: Include stdio.h and floating_sel.h. * libgimp/makefile.cygwin: New file. * libgimp/Makefile.am: Distribute above file. * libgimp/gimp.def: Update. * libgimp/gimpenv.c (gimp_directory): Don't warn about missing home directory on Win32, it is perfectly natural. * plug-ins/sel2path/global.h: Bypass unused declarations, some of which clash with functions in MSVCRT. * plug-ins/sel2path/math.c * modules/colorsel_water.c: Define M_PI if necessary. * plug-ins/sel2path/sel2path.c: Include config.h and glib.h. Define rint() if needed. * plug-ins/sel2path/vector.c: Include glib.h (for hypot() renaming on Win32; In the MS C runtime, as hypot() is non-ANSI, it's called _hypot(), sigh). * plug-ins/sinus/sinus_logo.h: Use indexed format, it is easier on some compilers than the huge string.
1999-07-15 00:02:32 +08:00
#endif
1999-03-07 20:56:03 +08:00
gimp_dir = g_strconcat (gimp_data_directory (),
G_DIR_SEPARATOR_S,
GIMPDIR,
".",
g_get_user_name (),
NULL);
}
}
return gimp_dir;
}
2000-02-07 07:16:24 +08:00
/**
* gimp_personal_rc_file:
* @basename: The basename of a rc_file.
*
* Returns the name of a file in the user-specific GIMP settings directory.
*
* The returned string is allocated dynamically and *SHOULD* be freed
* with g_free() after use.
*
* Returns: The name of a file in the user-specific GIMP settings directory.
**/
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
gchar *
gimp_personal_rc_file (const gchar *basename)
1999-03-07 20:56:03 +08:00
{
return g_strconcat (gimp_directory (),
G_DIR_SEPARATOR_S,
basename,
NULL);
}
2000-02-07 07:16:24 +08:00
/**
* gimp_data_directory:
*
* Returns the top directory for GIMP data. If the environment variable
* GIMP_DATADIR exists, that is used. It should be an absolute pathname.
* Otherwise, on Unix the compile-time defined directory is used. On
* Win32, the installation directory as deduced from the executable's
* name is used.
*
* The returned string is allocated just once, and should *NOT* be
* freed with g_free().
*
* Returns: The top directory for GIMP data.
**/
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
const gchar *
2000-02-07 07:16:24 +08:00
gimp_data_directory (void)
1999-03-07 20:56:03 +08:00
{
2000-02-07 07:16:24 +08:00
static gchar *gimp_data_dir = NULL;
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
const gchar *env_gimp_data_dir;
1999-03-07 20:56:03 +08:00
if (gimp_data_dir != NULL)
return gimp_data_dir;
env_gimp_data_dir = g_getenv ("GIMP_DATADIR");
if (NULL != env_gimp_data_dir)
{
if (!g_path_is_absolute (env_gimp_data_dir))
g_error ("GIMP_DATADIR environment variable should be an absolute path.");
1999-07-29 03:36:04 +08:00
#ifndef __EMX__
1999-03-07 20:56:03 +08:00
gimp_data_dir = g_strdup (env_gimp_data_dir);
1999-07-29 03:36:04 +08:00
#else
gimp_data_dir = g_strdup (__XOS2RedirRoot(env_gimp_data_dir));
#endif
1999-03-07 20:56:03 +08:00
}
else
{
#ifndef G_OS_WIN32
1999-04-24 22:54:47 +08:00
#ifndef __EMX__
1999-03-07 20:56:03 +08:00
gimp_data_dir = DATADIR;
1999-04-24 22:54:47 +08:00
#else
gimp_data_dir = g_strdup(__XOS2RedirRoot(DATADIR));
#endif
1999-03-07 20:56:03 +08:00
#else
/* Figure it out from the executable name */
2000-02-07 07:16:24 +08:00
gchar filename[MAX_PATH];
gchar *sep1, *sep2;
1999-03-07 20:56:03 +08:00
if (GetModuleFileName (NULL, filename, sizeof (filename)) == 0)
g_error ("GetModuleFilename failed\n");
/* If the executable file name is of the format
* <foobar>\bin\gimp.exe of <foobar>\plug-ins\filter.exe, * use
* <foobar>. Otherwise, use the directory where the executable
1999-03-07 20:56:03 +08:00
* is.
*/
sep1 = strrchr (filename, G_DIR_SEPARATOR);
*sep1 = '\0';
sep2 = strrchr (filename, G_DIR_SEPARATOR);
if (sep2 != NULL)
{
if (g_strcasecmp (sep2 + 1, "bin") == 0
|| g_strcasecmp (sep2 + 1, "plug-ins") == 0)
1999-03-07 20:56:03 +08:00
*sep2 = '\0';
}
gimp_data_dir = g_strdup (filename);
#endif
}
return gimp_data_dir;
}
/**
* gimp_sysconf_directory:
*
* Returns the top directory for GIMP config files. If the environment
* variable GIMP_SYSCONFDIR exists, that is used. It should be an
* absolute pathname. Otherwise, on Unix the compile-time defined
* directory is used. On Win32, the installation directory as deduced
* from the executable's name is used.
*
* The returned string is allocated just once, and should *NOT* be
* freed with g_free().
*
* Returns: The top directory for GIMP config files.
**/
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
const gchar *
gimp_sysconf_directory (void)
{
static gchar *gimp_sysconf_dir = NULL;
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
const gchar *env_gimp_sysconf_dir;
if (gimp_sysconf_dir != NULL)
return gimp_sysconf_dir;
env_gimp_sysconf_dir = g_getenv ("GIMP_SYSCONFDIR");
if (NULL != env_gimp_sysconf_dir)
{
if (!g_path_is_absolute (env_gimp_sysconf_dir))
g_error ("GIMP_SYSCONFDIR environment variable should be an absolute path.");
#ifndef __EMX__
gimp_sysconf_dir = g_strdup (env_gimp_sysconf_dir);
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
#else
gimp_sysconf_dir = g_strdup (__XOS2RedirRoot(env_gimp_sysconf_dir));
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
#endif
}
else
{
#ifndef G_OS_WIN32
#ifndef __EMX__
gimp_sysconf_dir = SYSCONFDIR;
#else
gimp_sysconf_dir = g_strdup(__XOS2RedirRoot(SYSCONFDIR));
#endif
#else
/* Figure it out from the executable name */
gchar filename[MAX_PATH];
gchar *sep1, *sep2;
if (GetModuleFileName (NULL, filename, sizeof (filename)) == 0)
g_error ("GetModuleFilename failed\n");
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
/* If the executable file name is of the format
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
* <foobar>\bin\gimp.exe or <foobar>\plug-ins\filter.exe, use
* <foobar>. Otherwise, use the directory where the executable
* is.
*/
sep1 = strrchr (filename, G_DIR_SEPARATOR);
*sep1 = '\0';
sep2 = strrchr (filename, G_DIR_SEPARATOR);
if (sep2 != NULL)
{
if (g_strcasecmp (sep2 + 1, "bin") == 0
|| g_strcasecmp (sep2 + 1, "plug-ins") == 0)
*sep2 = '\0';
}
gimp_sysconf_dir = g_strdup (filename);
#endif
}
return gimp_sysconf_dir;
}
2000-02-07 07:16:24 +08:00
/**
* gimp_gtkrc:
*
* Returns the name of the GIMP's application-specific gtkrc file.
1999-03-07 20:56:03 +08:00
*
* The returned string is allocated just once, and should *NOT* be
* freed with g_free().
2000-02-07 07:16:24 +08:00
*
* Returns: The name of the GIMP's application-specific gtkrc file.
**/
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
const gchar *
2000-02-07 07:16:24 +08:00
gimp_gtkrc (void)
1999-03-07 20:56:03 +08:00
{
2000-02-07 07:16:24 +08:00
static gchar *gimp_gtkrc_filename = NULL;
1999-03-07 20:56:03 +08:00
if (gimp_gtkrc_filename != NULL)
return gimp_gtkrc_filename;
gimp_gtkrc_filename = g_strconcat (gimp_sysconf_directory (),
1999-03-07 20:56:03 +08:00
G_DIR_SEPARATOR_S,
"gtkrc",
NULL);
return gimp_gtkrc_filename;
}
2000-02-07 07:16:24 +08:00
/**
* gimp_path_parse:
* @path: A list of directories separated by #G_SEARCHPATH_SEPARATOR.
* @max_paths: The maximum number of directories to return.
* @check: #TRUE if you want the directories to be checked.
* @check_failed: Returns a #GList of path elements for which the
* check failed. Each list element is guaranteed
* to end with a #G_PATH_SEPARATOR.
*
* Returns: A #GList of all directories in @path. Each list element
* is guaranteed to end with a #G_PATH_SEPARATOR.
**/
GList *
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
gimp_path_parse (const gchar *path,
gint max_paths,
gboolean check,
GList **check_failed)
{
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
const 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;
2000-02-07 07:16:24 +08:00
home = g_get_home_dir ();
patharray = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, max_paths);
for (i = 0; i < max_paths; i++)
{
GString *dir;
2000-02-07 07:16:24 +08:00
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
if (! patharray[i])
break;
#ifndef G_OS_WIN32
if (*patharray[i] == '~')
{
dir = g_string_new (home);
g_string_append (dir, patharray[i] + 1);
}
else
#endif
{
dir = g_string_new (patharray[i]);
}
#ifdef __EMX__
_fnslashify (dir);
#endif
if (check)
{
/* check if directory exists */
err = stat (dir->str, &filestat);
2000-02-07 07:16:24 +08:00
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, g_strdup (dir->str));
else if (check_failed)
fail_list = g_list_prepend (fail_list, g_strdup (dir->str));
g_string_free (dir, TRUE);
}
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().
*
* Note that you have to g_free() the returned string.
*
* 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 */
/* ugly hack to handle paths with an extra G_DIR_SEPARATOR
* attached. The stat() in MSVCRT doesn't like that.
*/
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
gchar *dir;
gchar *p;
gint pl;
p = dir = g_strdup ((gchar *) list->data);
if (g_path_is_absolute (dir))
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
p = (gchar *) g_path_skip_root (dir);
pl = strlen (p);
if (pl > 0 && p[pl-1] == G_DIR_SEPARATOR)
p[pl-1] = '\0';
err = stat (dir, &filestat);
g_free (dir);
/* 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 g_strdup ((gchar *) list->data);
}
}
return NULL;
}