summaryrefslogtreecommitdiffhomepage
path: root/mixlib/mix_config.c
diff options
context:
space:
mode:
Diffstat (limited to 'mixlib/mix_config.c')
-rw-r--r--mixlib/mix_config.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/mixlib/mix_config.c b/mixlib/mix_config.c
index d13feab..9d1c04b 100644
--- a/mixlib/mix_config.c
+++ b/mixlib/mix_config.c
@@ -1,24 +1,24 @@
/* -*-c-*- -------------- mix_config.c :
* Implementation of the functions declared in mix_config.h
* ------------------------------------------------------------------
- * $Id: mix_config.c,v 1.8 2002/04/10 23:39:40 jao Exp $
+ * $Id: mix_config.c,v 1.9 2004/06/07 05:29:01 jao Exp $
* ------------------------------------------------------------------
- * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
- *
+ * Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
+ *
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
+ *
*/
@@ -40,7 +40,7 @@ static const gchar *HISTORY_KEY_ = "History.file";
static const gchar *HISTORY_SIZE_KEY_ = "History.size";
/* the config type */
-struct mix_config_t
+struct mix_config_t
{
gchar *filename; /* full path to configuration file */
gboolean autosave; /* whether save on destroy */
@@ -61,13 +61,13 @@ mix_config_new (const gchar *dirname, const gchar *filename)
if (DEF_DIRNAME_ == NULL)
DEF_DIRNAME_ = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S,
MIX_CONFIG_DIR, NULL);
-
+
if (dirname == NULL) dirname = DEF_DIRNAME_;
if (filename == NULL) filename = DEF_FILENAME_;
-
+
if (!mix_stat_dir (dirname, "configuration")) return NULL;
- result = g_new (mix_config_t, 1);
+ result = g_new (mix_config_t, 1);
result->filename = g_strdup_printf ("%s/%s", dirname, filename);
result->items = g_hash_table_new (g_str_hash, g_str_equal);
@@ -84,22 +84,26 @@ mix_config_new (const gchar *dirname, const gchar *filename)
if (line && line[0] != COMMENT_PREFIX_)
{
gchar **vals = g_strsplit (line, "=", 2);
+ gchar *key = g_strdup (g_strstrip (vals[0]));
+ gchar *value =
+ (vals[1][0] == '"')
+ ? g_strndup (vals[1] + 1, strlen (vals[1]) - 2)
+ : g_strdup (g_strstrip (vals[1]));
g_hash_table_insert (result->items,
- (gpointer)g_strdup (g_strstrip (vals[0])),
- (gpointer)g_strdup (g_strstrip (vals[1])));
+ (gpointer)key,
+ (gpointer)value);
g_strfreev (vals);
}
}
fclose (f);
}
-
+
autosave = mix_config_get (result, AUTOSAVE_KEY_);
result->autosave = autosave && !g_strcasecmp (autosave, AUTOSAVE_YES_);
return result;
}
-
/* delete a config handler, saving the configuration if needed */
void
mix_config_delete (mix_config_t *config)
@@ -125,10 +129,9 @@ mix_config_get (const mix_config_t *config, const gchar *key)
{
g_return_val_if_fail (config != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
-
+
return (const gchar*)g_hash_table_lookup (config->items, key);
}
-
gint
mix_config_get_integer (const mix_config_t *config, const gchar *key)
@@ -147,11 +150,11 @@ mix_config_update (mix_config_t *config, const gchar *key, const gchar *value)
{
gpointer okey = NULL;
gpointer oval = NULL;
-
+
g_return_if_fail (config != NULL);
g_return_if_fail (key != NULL);
g_return_if_fail (value != NULL);
-
+
if (g_hash_table_lookup_extended (config->items, key, &okey, &oval))
{
if (oval != value)
@@ -165,7 +168,7 @@ mix_config_update (mix_config_t *config, const gchar *key, const gchar *value)
okey = (gpointer)g_strdup (key);
oval = (gpointer)g_strdup (value);
}
-
+
g_hash_table_insert (config->items, okey, oval);
}
@@ -173,10 +176,10 @@ void
mix_config_update_integer (mix_config_t *config, const gchar *key, gint value)
{
gchar *val;
-
+
g_return_if_fail (config != NULL);
g_return_if_fail (key != NULL);
-
+
val = g_strdup_printf ("%d", value);
mix_config_update (config, key, val);
g_free (val);
@@ -186,7 +189,7 @@ void
mix_config_remove (mix_config_t *config, const gchar *key)
{
gchar *val;
-
+
g_return_if_fail (config != NULL);
g_return_if_fail (key != NULL);
@@ -209,7 +212,7 @@ void
mix_config_save (const mix_config_t *config)
{
FILE *f;
-
+
g_return_if_fail (config != NULL);
f = fopen (config->filename, "w");