Fixed indentation, added removal

This commit is contained in:
Jesse van den Kieboom 2006-01-02 17:54:19 +00:00
parent 5fe84415e1
commit 906856cab0
1 changed files with 34 additions and 21 deletions

View File

@ -10,7 +10,8 @@
extern int errno;
#define GM_OPTIONS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GM_TYPE_OPTIONS, GmOptionsPrivate))
#define GM_OPTIONS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), \
GM_TYPE_OPTIONS, GmOptionsPrivate))
struct _GmOptionsPrivate {
GHashTable *options;
@ -90,7 +91,7 @@ gm_options_dup(GmOptions *source) {
// Adds an option to opt, even if key already exists
void
gm_options_set(GmOptions * options, const gchar *key, const gchar *value) {
gm_options_set(GmOptions * options, gchar const *key, gchar const *value) {
gchar *trimmed = gm_string_trim(key);
gchar *lookup = g_hash_table_lookup(options->priv->options, trimmed);
gboolean changed = lookup != NULL && lookup != value;
@ -107,22 +108,22 @@ gm_options_set(GmOptions * options, const gchar *key, const gchar *value) {
g_free(trimmed);
}
const gchar *
gm_options_get(GmOptions *options, const gchar *key) {
gchar const *
gm_options_get(GmOptions *options, gchar const *key) {
return g_hash_table_lookup(options->priv->options, key);
}
void
gm_options_set_int(GmOptions *options, const gchar *key, int value) {
gm_options_set_int(GmOptions *options, gchar const *key, int value) {
gchar val[15];
g_snprintf((gchar *) &val, 15, "%d", value);
gm_options_set(options, key, (const gchar *)val);
gm_options_set(options, key, (gchar const *)val);
}
int
gm_options_get_int(GmOptions *options, const gchar *key) {
const gchar *val = gm_options_get(options, key);
gm_options_get_int(GmOptions *options, gchar const *key) {
gchar const *val = gm_options_get(options, key);
int ret;
if (val && gm_string_to_int(val, &ret)) {
@ -132,9 +133,15 @@ gm_options_get_int(GmOptions *options, const gchar *key) {
}
}
void
gm_options_remove(GmOptions *options, gchar const *key) {
g_hash_table_remove(options->priv->options, key);
}
void
gm_options_save_value(gchar *key, gchar *value, FILE *f) {
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.SaveValue: saving %s, %s", key, value);
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.SaveValue: saving %s, %s", key,
value);
fprintf(f, "%s=%s\n", key, value);
}
@ -148,7 +155,8 @@ gm_options_save(GmOptions *options) {
f = fopen(options->priv->filepath, "w");
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.save: saving options (%s)!", options->priv->filepath);
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.save: saving options (%s)!",
options->priv->filepath);
if (f) {
g_hash_table_foreach(options->priv->options,
@ -157,13 +165,13 @@ gm_options_save(GmOptions *options) {
fclose(f);
chmod(options->priv->filepath, 0660);
} else {
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.save: couldn't open option file for saving: %s",
strerror(errno));
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.save: couldn't open option "
"file for saving: %s", strerror(errno));
}
}
void
gm_options_save_as(GmOptions *options, const gchar *filename) {
gm_options_save_as(GmOptions *options, gchar const *filename) {
g_free(options->priv->filepath);
options->priv->filepath = g_strdup(filename);
@ -176,7 +184,8 @@ gm_options_load(GmOptions *options, const char *filename) {
gchar **keyvalue, line[1024];
int i;
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.load: loading options (%s)!", filename);
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.load: loading options (%s)!",
filename);
if ((f = fopen(filename, "r")) != NULL) {
i = 0;
@ -184,16 +193,20 @@ gm_options_load(GmOptions *options, const char *filename) {
line[strlen((char *) &line) - 1] = '\0';
i++;
if (strlen(line) != 0) { // Empty lines, we don't need to process those
if (strlen(line) != 0) {
// Empty lines, we don't need to process those
keyvalue = g_strsplit(line, "=", 2);
// This will return at least 1 element, at most 2, we need 2
if (strncmp(keyvalue[0], "#", 1) != 0) { // Commented lines, well ignore them too
if (strncmp(keyvalue[0], "#", 1) != 0) {
// Commented lines, well ignore them too
if (keyvalue[1] != NULL) {
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.load: adding %s, %s", keyvalue[0], keyvalue[1]);
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.load: "
"adding %s, %s", keyvalue[0], keyvalue[1]);
gm_options_set(options, keyvalue[0], keyvalue[1]);
} else {
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.load: wrong syntax of options "
"line in %s line %d", filename, i);
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.load: wrong "
"syntax of options line in %s line %d",
filename, i);
}
}
@ -203,8 +216,8 @@ gm_options_load(GmOptions *options, const char *filename) {
fclose(f);
} else {
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.load: could not retrieve contents of file "
"%s (%s)", filename, strerror(errno));
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.load: could not retrieve "
"contents of file %s (%s)", filename, strerror(errno));
}
g_free(options->priv->filepath);