Commit 023c7697 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

configure.in etc/Makefile.am etc/gimprc.in removed templates for gimprc

2002-12-29  Sven Neumann  <sven@gimp.org>

	* configure.in
	* etc/Makefile.am
	* etc/gimprc.in
	* etc/gimprc_user.in: removed templates for gimprc files.

	* etc/gimprc: added this file as generated by gimp-config-dump.

	* app/gui/user-install-dialog.c
	* data/misc/user_install: don't install an empty user gimprc.

	* app/config/Makefile.am
	* app/config/gimpconfig-substitute.[ch]: removed these files.
	* app/config/gimpconfig-path.[ch]: and added them again with
	reduced functionality. Paths found in config files are now
	basically handled like standard strings by the config system.
	Users of the GimpConfig path variables need to expand the path
	themselves.

	* app/config/gimpbaseconfig.c
	* app/config/gimpconfig-deserialize.c
	* app/config/gimpconfig-dump.c
	* app/config/gimpconfig-utils.c
	* app/config/gimpconfig.c
	* app/config/gimpcoreconfig.c
	* app/config/gimprc.c:
	* app/base/base.c
	* app/base/temp-buf.c
	* app/core/gimp.c
	* app/core/gimpdatafactory.c
	* app/core/gimpmodules.c
	* app/gui/user-install-dialog.c
	* app/plug-in/plug-in.c
	* app/tools/tools.c
	* app/widgets/gimppropwidgets.c: changed accordingly.
parent d3e9fc64
2002-12-29 Sven Neumann <sven@gimp.org>
* configure.in
* etc/Makefile.am
* etc/gimprc.in
* etc/gimprc_user.in: removed templates for gimprc files.
* etc/gimprc: added this file as generated by gimp-config-dump.
* app/gui/user-install-dialog.c
* data/misc/user_install: don't install an empty user gimprc.
* app/config/Makefile.am
* app/config/gimpconfig-substitute.[ch]: removed these files.
* app/config/gimpconfig-path.[ch]: and added them again with
reduced functionality. Paths found in config files are now
basically handled like standard strings by the config system.
Users of the GimpConfig path variables need to expand the path
themselves.
* app/config/gimpbaseconfig.c
* app/config/gimpconfig-deserialize.c
* app/config/gimpconfig-dump.c
* app/config/gimpconfig-utils.c
* app/config/gimpconfig.c
* app/config/gimpcoreconfig.c
* app/config/gimprc.c:
* app/base/base.c
* app/base/temp-buf.c
* app/core/gimp.c
* app/core/gimpdatafactory.c
* app/core/gimpmodules.c
* app/gui/user-install-dialog.c
* app/plug-in/plug-in.c
* app/tools/tools.c
* app/widgets/gimppropwidgets.c: changed accordingly.
2002-12-29 Simon Budig <simon@gimp.org>
* app/core/gimpimage-mask-select.c
......
......@@ -36,6 +36,7 @@
#include "base-types.h"
#include "config/gimpbaseconfig.h"
#include "config/gimpconfig-path.h"
#include "paint-funcs/paint-funcs.h"
......@@ -62,6 +63,7 @@ base_init (GimpBaseConfig *config,
gboolean use_mmx)
{
gchar *swapfile;
gchar *swapdir;
gchar *path;
g_return_if_fail (GIMP_IS_BASE_CONFIG (config));
......@@ -86,13 +88,15 @@ base_init (GimpBaseConfig *config,
/* Add the swap file */
if (! config->swap_path)
g_object_set (G_OBJECT (config), "swap_path", g_get_tmp_dir ());
g_object_set (G_OBJECT (config), "swap_path", "${gimp_dir}");
swapdir = gimp_config_path_expand (config->swap_path, TRUE, NULL);
swapfile = g_strdup_printf ("gimpswap.%lu", (unsigned long) getpid ());
path = g_build_filename (config->swap_path, swapfile, NULL);
path = g_build_filename (swapdir, swapfile, NULL);
g_free (swapfile);
g_free (swapdir);
tile_swap_add (path, NULL, NULL);
......@@ -122,15 +126,25 @@ base_exit (void)
static void
base_toast_old_temp_files (GimpBaseConfig *config)
{
GDir *dir = NULL;
GDir *dir = NULL;
gchar *dirname;
const char *entry;
if (config->swap_path)
dir = g_dir_open (config->swap_path, 0, NULL);
if (!config->swap_path)
return;
if (!dir)
dirname = gimp_config_path_expand (config->swap_path, TRUE, NULL);
if (!dirname)
return;
dir = g_dir_open (dirname, 0, NULL);
if (!dir)
{
g_free (dirname);
return;
}
while ((entry = g_dir_read_name (dir)) != NULL)
if (! strncmp (entry, "gimpswap.", 9))
{
......@@ -153,13 +167,15 @@ base_toast_old_temp_files (GimpBaseConfig *config)
{
gchar *filename;
filename = g_build_filename (config->swap_path, entry, NULL);
filename = g_build_filename (dirname, entry, NULL);
unlink (filename);
g_free (filename);
}
}
g_dir_close (dir);
g_free (dirname);
}
static void
......
......@@ -37,6 +37,7 @@
#include "base-types.h"
#include "config/gimpbaseconfig.h"
#include "config/gimpconfig-path.h"
#include "pixel-region.h"
#include "temp-buf.h"
......@@ -620,7 +621,7 @@ mask_buf_data_clear (MaskBuf *mask_buf)
/* a static counter for generating unique filenames
*/
static gint swap_index = 0;
static gint tmp_file_index = 0;
/* a static pointer which keeps track of the last request for
......@@ -630,21 +631,25 @@ static TempBuf *cached_in_memory = NULL;
static gchar *
generate_unique_filename (const gchar *temp_path)
generate_unique_tmp_filename (GimpBaseConfig *config)
{
pid_t pid;
gchar *swapfile;
gchar *tmpdir;
gchar *tmpfile;
gchar *path;
tmpdir = gimp_config_path_expand (config->temp_path, TRUE, NULL);
pid = getpid ();
swapfile = g_strdup_printf ("gimp%d.%d",
(gint) pid,
swap_index++);
tmpfile = g_strdup_printf ("gimp%d.%d",
(gint) pid,
tmp_file_index++);
path = g_build_filename (temp_path, swapfile, NULL);
path = g_build_filename (tmpdir, tmpfile, NULL);
g_free (swapfile);
g_free (tmpfile);
g_free (tmpdir);
return path;
}
......@@ -679,7 +684,7 @@ temp_buf_swap (TempBuf *buf)
return;
/* Get a unique filename for caching the data to a UNIX file */
filename = generate_unique_filename (base_config->temp_path);
filename = generate_unique_tmp_filename (base_config);
/* Check if generated filename is valid */
if (g_file_test (filename, G_FILE_TEST_IS_DIR))
......
......@@ -10,10 +10,10 @@ libappconfig_a_SOURCES = \
gimpconfig-deserialize.h \
gimpconfig-params.c \
gimpconfig-params.h \
gimpconfig-path.c \
gimpconfig-path.h \
gimpconfig-serialize.c \
gimpconfig-serialize.h \
gimpconfig-substitute.c \
gimpconfig-substitute.h \
gimpconfig-serialize.h \
gimpconfig-types.c \
gimpconfig-types.h \
......
......@@ -102,12 +102,11 @@ gimp_base_config_class_init (GimpBaseConfigClass *klass)
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_TEMP_PATH,
"temp-path", TEMP_PATH_BLURB,
g_build_filename (gimp_directory (),
"tmp", NULL),
"${gimp_dir}" G_DIR_SEPARATOR_S "tmp",
GIMP_PARAM_RESTART);
GIMP_CONFIG_INSTALL_PROP_PATH (object_class, PROP_SWAP_PATH,
"swap-path", SWAP_PATH_BLURB,
g_strdup (gimp_directory ()),
"${gimp_dir}",
GIMP_PARAM_RESTART);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_STINGY_MEMORY_USE,
"stingy-memory-use", STINGY_MEMORY_USE_BLURB,
......
......@@ -37,7 +37,7 @@
#include "gimpconfig.h"
#include "gimpconfig-deserialize.h"
#include "gimpconfig-params.h"
#include "gimpconfig-substitute.h"
#include "gimpconfig-path.h"
#include "gimpconfig-types.h"
#include "gimpscanner.h"
......@@ -69,7 +69,6 @@ static GTokenType gimp_config_deserialize_memsize (GValue *value,
GParamSpec *prop_spec,
GScanner *scanner);
static GTokenType gimp_config_deserialize_path (GValue *value,
GObject *object,
GParamSpec *prop_spec,
GScanner *scanner);
static GTokenType gimp_config_deserialize_color (GValue *value,
......@@ -319,8 +318,7 @@ gimp_config_deserialize_value (GValue *value,
}
else if (prop_spec->value_type == GIMP_TYPE_PATH)
{
return gimp_config_deserialize_path (value,
object, prop_spec, scanner);
return gimp_config_deserialize_path (value, prop_spec, scanner);
}
else if (prop_spec->value_type == GIMP_TYPE_COLOR)
{
......@@ -512,11 +510,10 @@ gimp_config_deserialize_memsize (GValue *value,
static GTokenType
gimp_config_deserialize_path (GValue *value,
GObject *object,
GParamSpec *prop_spec,
GScanner *scanner)
{
gchar *path;
GError *error = NULL;
if (g_scanner_peek_next_token (scanner) != G_TOKEN_STRING)
return G_TOKEN_STRING;
......@@ -526,12 +523,28 @@ gimp_config_deserialize_path (GValue *value,
if (!scanner_string_utf8_valid (scanner, prop_spec->name))
return G_TOKEN_NONE;
path = gimp_config_substitute_path (object, scanner->value.v_string, TRUE);
if (scanner->value.v_string)
{
/* Check if the string can be expanded
* and converted to thde filesystem encoding.
*/
gchar *expand = gimp_config_path_expand (scanner->value.v_string,
TRUE, &error);
if (!path)
return G_TOKEN_NONE;
if (!expand)
{
g_scanner_error (scanner,
_("while parsing token %s: %s"),
prop_spec->name, error->message);
g_error_free (error);
return G_TOKEN_NONE;
}
g_free (expand);
g_value_set_string_take_ownership (value, path);
g_value_set_static_string (value, scanner->value.v_string);
}
return G_TOKEN_RIGHT_PAREN;
}
......
......@@ -125,19 +125,14 @@ dump_system_gimprc (void)
"# Lines that start with a '#' are comments. Blank lines are ignored.\n"
"#\n"
"# By default everything in this file is commented out. The file then\n"
"# documents the default values and shows what changes are possible\n."
"# documents the default values and shows what changes are possible.\n"
"\n"
"# The variable gimp_dir is set to either the internal value\n"
"# @gimpdir@ or the environment variable GIMP_DIRECTORY. If\n"
"# the path in GIMP_DIRECTORY is relative, it is considered\n"
"# relative to your home directory.\n"
"\n"
"(prefix \"@prefix@\"\n"
"(exec_prefix \"@exec_prefix@\")\n"
"(gimp_data_dir \"@gimpdatadir@\")\n"
"(gimp_plugin_dir \"@gimpplugindir@\")\n"
"\n");
write (1, str->str, str->len);
rc = g_object_new (GIMP_TYPE_RC, NULL);
......
......@@ -28,8 +28,9 @@
#include "libgimpbase/gimpenv.h"
#include "gimpconfig.h"
#include "gimpconfig-substitute.h"
#include "gimpconfig-path.h"
#include "libgimp/gimpintl.h"
#define SUBSTS_ALLOC 4
......@@ -38,27 +39,37 @@ static inline gchar * extract_token (const gchar **str);
gchar *
gimp_config_substitute_path (GObject *object,
const gchar *path,
gboolean use_env)
gimp_config_path_expand (const gchar *path,
gboolean recode,
GError **error)
{
const gchar *p;
const gchar *s;
gchar *n;
gchar *token;
gchar *new_path = NULL;
gchar *filename;
gchar *expanded = NULL;
gchar **substs = NULL;
guint n_substs = 0;
gint length = 0;
gint i;
g_return_val_if_fail (G_IS_OBJECT (object), NULL);
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
p = path;
if (recode)
{
if (!(filename = g_filename_from_utf8 (path, -1, NULL, NULL, error)))
return NULL;
}
else
{
filename = (gchar *) path;
}
while (*p)
for (p = filename; *p; )
{
#ifndef G_OS_WIN32
if (*p == '~')
{
......@@ -66,7 +77,8 @@ gimp_config_substitute_path (GObject *object,
p += 1;
}
else
#endif
#endif /* G_OS_WIN32 */
if ((token = extract_token (&p)) != NULL)
{
for (i = 0; i < n_substs; i++)
......@@ -79,54 +91,50 @@ gimp_config_substitute_path (GObject *object,
}
else
{
s = gimp_config_lookup_unknown_token (object, token);
s = NULL;
if (!s && use_env)
{
if (!s && strcmp (token, "gimp_dir") == 0)
s = gimp_directory ();
if (!s && strcmp (token, "gimp_datadir") == 0)
s = gimp_data_directory ();
if (!s && strcmp (token, "gimp_dir") == 0)
s = gimp_directory ();
if (!s &&
((strcmp (token, "gimp_plug_in_dir")) == 0 ||
(strcmp (token, "gimp_plugin_dir")) == 0))
s = gimp_plug_in_directory ();
if (!s && strcmp (token, "gimp_data_dir") == 0)
s = gimp_data_directory ();
if (!s && strcmp (token, "gimp_sysconfdir") == 0)
s = gimp_sysconf_directory ();
if (!s &&
((strcmp (token, "gimp_plug_in_dir")) == 0 ||
(strcmp (token, "gimp_plugin_dir")) == 0))
s = gimp_plug_in_directory ();
if (!s)
s = g_getenv (token);
if (!s && strcmp (token, "gimp_sysconf_dir") == 0)
s = gimp_sysconf_directory ();
if (!s)
s = g_getenv (token);
#ifdef G_OS_WIN32
/* The default user gimprc on Windows references
* ${TEMP}, but not all Windows installations have that
* environment variable, even if it should be kinda
* standard. So special-case it.
*/
if (!s && strcmp (token, "TEMP") == 0)
s = g_get_tmp_dir ();
#endif
}
/* The default user gimprc on Windows references
* ${TEMP}, but not all Windows installations have that
* environment variable, even if it should be kinda
* standard. So special-case it.
*/
if (!s && strcmp (token, "TEMP") == 0)
s = g_get_tmp_dir ();
#endif /* G_OS_WIN32 */
}
if (!s)
{
g_message ("token referenced but not defined: ${%s}", token);
g_free (token);
goto cleanup;
}
if (n_substs % SUBSTS_ALLOC == 0)
substs = g_renew (gchar *, substs, 2*(n_substs+SUBSTS_ALLOC));
substs[2*n_substs] = token;
substs[2*n_substs + 1] = (gchar *) s;
n_substs++;
if (!s)
{
g_set_error (error, 0, 0, _("can not expand ${%s}"), token);
g_free (token);
goto cleanup;
}
if (n_substs % SUBSTS_ALLOC == 0)
substs = g_renew (gchar *, substs, 2 * (n_substs + SUBSTS_ALLOC));
substs[2*n_substs] = token;
substs[2*n_substs + 1] = (gchar *) s;
n_substs++;
length += strlen (s);
}
else
......@@ -136,16 +144,17 @@ gimp_config_substitute_path (GObject *object,
}
}
if (!n_substs)
return g_strdup (path);
if (n_substs == 0)
return recode ? filename : g_strdup (filename);
new_path = g_new (gchar, length + 1);
expanded = g_new (gchar, length + 1);
p = path;
n = new_path;
p = filename;
n = expanded;
while (*p)
{
#ifndef G_OS_WIN32
if (*p == '~')
{
......@@ -155,7 +164,8 @@ gimp_config_substitute_path (GObject *object,
p += 1;
}
else
#endif
#endif /* G_OS_WIN32 */
if ((token = extract_token (&p)) != NULL)
{
for (i = 0; i < n_substs; i++)
......@@ -188,7 +198,10 @@ gimp_config_substitute_path (GObject *object,
g_free (substs);
return new_path;
if (recode)
g_free (filename);
return expanded;
}
static inline gchar *
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* String substitution utilities for config files
* Copyright (C) 2001 Sven Neumann <sven@gimp.org>
* gimpconfig-path.h
* Copyright (C) 2001-2002 Sven Neumann <sven@gimp.org>
*
* 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
......@@ -19,13 +19,13 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_CONFIG_SUBSTITUTE_H__
#define __GIMP_CONFIG_SUBSTITUTE_H__
#ifndef __GIMP_CONFIG_PATH_H__
#define __GIMP_CONFIG_PATH_H__
gchar * gimp_config_substitute_path (GObject *object,
const gchar *string,
gboolean use_env);
gchar * gimp_config_path_expand (const gchar *path,
gboolean recode,
GError **error);
#endif /* __GIMP_CONFIG_SUBSTITUTE_H__ */
#endif /* __GIMP_CONFIG_PATH_H__ */
......@@ -118,17 +118,17 @@ gimp_config_copy_properties (GObject *src,
gchar *
gimp_config_build_data_path (const gchar *name)
{
return g_strconcat (gimp_directory (), G_DIR_SEPARATOR_S, name,
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name,
G_SEARCHPATH_SEPARATOR_S,
gimp_data_directory (), G_DIR_SEPARATOR_S, name,
"${gimp_data_dir}", G_DIR_SEPARATOR_S, name,
NULL);
}
gchar *
gimp_config_build_plug_in_path (const gchar *name)
{
return g_strconcat (gimp_directory (), G_DIR_SEPARATOR_S, name,
return g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, name,
G_SEARCHPATH_SEPARATOR_S,
gimp_plug_in_directory (), G_DIR_SEPARATOR_S, name,
"${gimp_plug_in_dir}", G_DIR_SEPARATOR_S, name,
NULL);
}
......@@ -42,7 +42,6 @@
#include "gimpconfig.h"
#include "gimpconfig-serialize.h"
#include "gimpconfig-deserialize.h"
#include "gimpconfig-substitute.h"
#include "gimpconfig-utils.h"
#include "gimpscanner.h"
......@@ -87,8 +86,7 @@ gimp_config_interface_get_type (void)
&config_iface_info,
0);
g_type_interface_add_prerequisite (config_iface_type,
G_TYPE_OBJECT);
g_type_interface_add_prerequisite (config_iface_type, G_TYPE_OBJECT);
}
return config_iface_type;
......@@ -120,7 +118,8 @@ gimp_config_iface_deserialize (GObject *object,
gint nest_level,
gpointer data)
{
return gimp_config_deserialize_properties (object, scanner, nest_level, FALSE);
return gimp_config_deserialize_properties (object,
scanner, nest_level, FALSE);
}
static GObject *
......@@ -488,13 +487,10 @@ gimp_config_add_unknown_token (GObject *object,
GSList *unknown_tokens;
GSList *last;
GSList *list;
gchar *dup_value;
g_return_if_fail (G_IS_OBJECT (object));
g_return_if_fail (key != NULL);
dup_value = value ? gimp_config_substitute_path (object, value, TRUE) : NULL;
unknown_tokens = (GSList *) g_object_get_data (object,
GIMP_CONFIG_UNKNOWN_TOKENS);
......@@ -510,7 +506,7 @@ gimp_config_add_unknown_token (GObject *object,
if (value)
{
token->value = dup_value;
token->value = g_strdup (value);
}
else
{
......@@ -531,7 +527,7 @@ gimp_config_add_unknown_token (GObject *object,
token = g_new (GimpConfigToken, 1);
token->key = g_strdup (key);
token->value = dup_value;
token->value = g_strdup (value);
if (last)
{
......
......@@ -225,8 +225,7 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
GIMP_CONFIG_INSTALL_PROP_PATH (object_class,
PROP_PLUGINRC_PATH,
"pluginrc-path", PLUGINRC_PATH_BLURB,
g_build_filename (gimp_directory (),
"pluginrc", NULL),
"${gimp_dir}" G_DIR_SEPARATOR_S "pluginrc",
GIMP_PARAM_RESTART);
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_MODULE_LOAD_INHIBIT,
"module-load-inhibit",
......
......@@ -286,17 +286,22 @@ gimp_rc_serialize (GObject *object,
gint indent_level,
gpointer data)
{
if (!gimp_config_serialize_unknown_tokens (object, fd, indent_level))
return FALSE;
if (data && GIMP_IS_RC (data))
{
if (!gimp_config_serialize_changed_properties (object, G_OBJECT (data),
fd, indent_level))
return FALSE;
}
else
{
if (!gimp_config_serialize_properties (object, fd, indent_level))
return FALSE;
}
if (write (fd, "\n", 1) < 0)
return FALSE;
if (data && GIMP_IS_RC (data))
return gimp_config_serialize_changed_properties (object, G_OBJECT (data),
fd, indent_level);
else
return gimp_config_serialize_properties (object, fd, indent_level);
return gimp_config_serialize_unknown_tokens (object, fd, indent_level);
}
static gboolean
......
......@@ -37,6 +37,7 @@
#include "core-types.h"
#include "config/gimpcoreconfig.h"
#include "config/gimpconfig-path.h"
#include "gimp.h"
#include "gimplist.h"
......@@ -77,11 +78,7 @@ gimp_modules_load (Gimp *gimp)
g_free (filename);
#endif
gimp_module_db_set_load_inhibit (gimp->module_db,
gimp->config->module_load_inhibit);
gimp_module_db_load (gimp->module_db,
gimp->config->module_path);
gimp_modules_refresh (gimp);
}
static void
......@@ -136,11 +133,14 @@ gimp_modules_unload (Gimp *gimp)
void
gimp_modules_refresh (Gimp *gimp)
{
gchar *path;
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp_module_db_set_load_inhibit (gimp->module_db,
gimp->config->module_load_inhibit);
gimp_module_db_refresh (gimp->module_db,
gimp->config->module_path);
path = gimp_config_path_expand (gimp->config->module_path, TRUE, NULL);
gimp_module_db_refresh (gimp->module_db, path);
g_free (path);
}
......@@ -28,6 +28,7 @@
#include "config/gimpconfig.h"
#include "config/gimpconfig-params.h"
#include "config/gimpconfig-path.h"
#include "config/gimprc.h"
#include "pdb/procedural_db.h"
......@@ -606,6 +607,7 @@ gimp_initialize (Gimp *gimp,
GimpInitStatusFunc status_callback)
{
GimpContext *context;
gchar *path;
static const GimpDataFactoryLoaderEntry brush_loader_entries[] =
{
......@@ -715,7 +717,10 @@ gimp_initialize (Gimp *gimp,
internal_procs_init (gimp, status_callback);
(* status_callback) (_("Plug-In Environment"), "", -1);
gimp_environ_table_load (gimp->environ_table, gimp->config->environ_path);
path = gimp_config_path_expand (gimp->config->environ_path, TRUE, NULL);
gimp_environ_table_load (gimp->environ_table, path);
g_free (path);
}
void
......
......@@ -31,6 +31,7 @@
#include "core-types.h"
#include "config/gimpbaseconfig.h"
#include "config/gimpconfig-path.h"
#include "gimp.h"
#include "gimpcontext.h"
......@@ -196,6 +197,12 @@ gimp_data_factory_data_init (GimpDataFactory *factory,
if (path && strlen (path))
{
gchar *tmp;
tmp = gimp_config_path_expand (path, TRUE, NULL);
g_free (path);