summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conf.c46
-rw-r--r--conf.h6
-rw-r--r--main.c2
3 files changed, 53 insertions, 1 deletions
diff --git a/conf.c b/conf.c
index 70ceeae5..f45eabd5 100644
--- a/conf.c
+++ b/conf.c
@@ -22,6 +22,7 @@
#include "conf.h"
static DB_conf_item_t *conf_items;
+static int changed = 0;
int
conf_load (void) {
@@ -34,6 +35,7 @@ conf_load (void) {
return -1;
}
int line = 0;
+ DB_conf_item_t *tail = NULL;
while (fgets (str, 1024, fp) != NULL) {
line++;
if (str[0] == '#' || str[0] <= 0x20) {
@@ -63,19 +65,50 @@ conf_load (void) {
p++;
}
*p = 0;
- conf_set_str (str, value);
+ // new items are appended, to preserve order
+ DB_conf_item_t *it = malloc (sizeof (DB_conf_item_t));
+ memset (it, 0, sizeof (DB_conf_item_t));
+ it->key = strdup (str);
+ it->value = strdup (value);
+ if (!tail) {
+ conf_items = it;
+ }
+ else {
+ tail->next = it;
+ }
+ tail = it;
}
fclose (fp);
+ changed = 0;
return 0;
}
int
conf_save (void) {
+ extern char dbconfdir[1024]; // $HOME/.config/deadbeef
+ char str[1024];
+ snprintf (str, 1024, "%s/config", dbconfdir);
+ FILE *fp = fopen (str, "w+t");
+ if (!fp) {
+ fprintf (stderr, "failed to open config file for writing\n");
+ return -1;
+ }
+ for (DB_conf_item_t *it = conf_items; it; it = it->next) {
+ fprintf (fp, "%s %s\n", it->key, it->value);
+ }
+ fclose (fp);
return 0;
}
void
conf_free (void) {
+ DB_conf_item_t *next = NULL;
+ for (DB_conf_item_t *it = conf_items; it; it = next) {
+ next = it->next;
+ free (it->key);
+ free (it->value);
+ free (it);
+ }
}
const char *
@@ -113,6 +146,7 @@ conf_find (const char *group, DB_conf_item_t *prev) {
void
conf_set_str (const char *key, const char *val) {
+ changed = 1;
for (DB_conf_item_t *it = conf_items; it; it = it->next) {
if (!strcasecmp (key, it->key)) {
free (it->value);
@@ -141,3 +175,13 @@ conf_set_float (const char *key, float val) {
snprintf (s, sizeof (s), "%0.7f", val);
conf_set_str (key, s);
}
+
+int
+conf_ischanged (void) {
+ return changed;
+}
+
+void
+conf_setchanged (int c) {
+ changed = c;
+}
diff --git a/conf.h b/conf.h
index 4c090ab3..bce7572c 100644
--- a/conf.h
+++ b/conf.h
@@ -29,6 +29,12 @@ conf_save (void);
void
conf_free (void);
+int
+conf_ischanged (void);
+
+void
+conf_setchanged (int c);
+
const char *
conf_get_str (const char *key, const char *def);
diff --git a/main.c b/main.c
index 6029bb91..c383c48d 100644
--- a/main.c
+++ b/main.c
@@ -752,6 +752,8 @@ main (int argc, char *argv[]) {
session_save (sessfile);
pl_save (defpl);
pl_free ();
+ conf_save ();
+ conf_free ();
plug_unload_all ();
return 0;
}