summaryrefslogtreecommitdiff
path: root/src/configuration.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2009-07-12 15:26:23 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2009-07-12 15:26:23 (GMT)
commitc9465acd65e197e48da8648eb8d1ef602d6772ed (patch)
treefbb5ceaaa683bd1beb0b66d5e5d212b927a9f6b0 /src/configuration.c
parent5f2cd35c377989e07b241870f89fdf87d851465d (diff)
Read and saved projects from and into XML files.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@91 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/configuration.c')
-rw-r--r--src/configuration.c125
1 files changed, 125 insertions, 0 deletions
diff --git a/src/configuration.c b/src/configuration.c
new file mode 100644
index 0000000..f7cdfbe
--- /dev/null
+++ b/src/configuration.c
@@ -0,0 +1,125 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * configuration.c - éléments de configuration du programme
+ *
+ * Copyright (C) 2009 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "configuration.h"
+
+
+#include <malloc.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+#include "xml.h"
+#include "common/extstr.h"
+
+
+
+
+/* Paramètres de configuration */
+struct _configuration
+{
+ config_param *params; /* Paramètres à consulter */
+ unsigned int count; /* Quantité de ces paramètres */
+
+ char *filename; /* Fichier externe */
+
+ xmlDocPtr xdoc; /* Document XML de configurat° */
+ xmlXPathContextPtr context; /* Contexte de recherche XPath */
+
+};
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : name = désignation de la configuration. *
+* params = tableau de paramètres à consulter / mettre à jour. *
+* count = taille du tableau en question. *
+* *
+* Description : Charge la configuration principale. *
+* *
+* Retour : Configuration prête à emploi. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+configuration *load_configuration(const char *name, config_param *params, unsigned int count)
+{
+ configuration *result; /* Structure à retourner */
+ char *home; /* Répertoire de l'utilisateur */
+
+ result = (configuration *)calloc(1, sizeof(configuration));
+
+ result->params = params;
+ result->count = count;
+
+ /* FIXME : créer le répertoire, et en XDG */
+ home = strdup(getenv("HOME") != NULL ? getenv("HOME") : "");
+ result->filename = stradd(home, "/.openida/");
+ result->filename = stradd(result->filename, name);
+ result->filename = stradd(result->filename, ".xml");
+
+ if (!open_xml_file(result->filename, &result->xdoc, &result->context))
+ create_new_xml_file(&result->xdoc, &result->context);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : config = configuration à libérer de la mémoire. *
+* *
+* Description : Décharge la configuration principale. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void unload_configuration(configuration *config)
+{
+ unsigned int i; /* Boucle de parcours */
+
+ printf("Writing '%s'\n", config->filename);
+
+ for (i = 0; i < config->count; i++)
+ switch (1)
+ {
+ case 1:
+ add_content_to_node(config->xdoc, config->context,
+ config->params[i].path, config->params[i].cur.string);
+ break;
+
+ }
+
+ save_xml_file(config->xdoc, config->filename);
+
+ free(config);
+
+}