summaryrefslogtreecommitdiff
path: root/src/analysis/binary.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/analysis/binary.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/analysis/binary.c')
-rw-r--r--src/analysis/binary.c158
1 files changed, 58 insertions, 100 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index d7d050b..c528e96 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -39,6 +39,7 @@
#include "line_comment.h"
#include "line_prologue.h"
#include "prototype.h"
+#include "../common/extstr.h"
#include "../panel/log.h"
#include "../plugins/pglist.h"
@@ -160,7 +161,8 @@ openida_binary *load_binary_file(const char *filename)
/******************************************************************************
* *
-* Paramètres : xpathObj = point de lecture de tous les éléments. *
+* Paramètres : context = contexte pour les recherches XPath. *
+* path = chemin d'accès au noeud XML à lire. *
* *
* Description : Charge en mémoire le contenu d'un fichier à partir d'XML. *
* *
@@ -170,20 +172,69 @@ openida_binary *load_binary_file(const char *filename)
* *
******************************************************************************/
-openida_binary *load_binary_file_from_xml(xmlXPathObjectPtr xpathObj)
+openida_binary *g_binary_file_new_from_xml(xmlXPathContextPtr context, const char *path)
{
openida_binary *result; /* Adresse à retourner */
+ size_t access_len; /* Taille d'un chemin interne */
+ char *access; /* Chemin pour une sous-config.*/
+ char *filename; /* Chemin du binaire à charger */
- int i;
+ result = NULL;
- result = (openida_binary *)calloc(1, sizeof(openida_binary));
+ /* Chemin du fichier à retrouver */
+
+ access_len = strlen(path) + strlen("/Filename") + 1;
+
+ access = calloc(access_len, sizeof(char));
+ snprintf(access, access_len, "%s/Filename", path);
+
+ filename = get_node_text_value(context, access);
+
+ free(access);
+
+ /* Chargement */
+
+ if (filename != NULL)
+ {
+ result = load_binary_file(filename);
+ free(filename);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à traiter. *
+* xdoc = structure XML en cours d'édition. *
+* context = contexte à utiliser pour les recherches. *
+* path = chemin d'accès réservé au binaire. *
+* *
+* Description : Ecrit une sauvegarde du binaire dans un fichier XML. *
+* *
+* Retour : true si l'opération a bien tourné, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- for (i = 0; i < XPATH_OBJ_NODES_COUNT(xpathObj); i++)
- if (xmlStrEqual(NODE_FROM_PATH_OBJ(xpathObj, i)->name, BAD_CAST "Filename"))
- result->filename = qck_get_node_text_value(NODE_FROM_PATH_OBJ(xpathObj, i));
+bool g_openida_binary_save(const openida_binary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path)
+{
+ bool result; /* Bilan à faire remonter */
+ char *access; /* Chemin d'accès à un élément */
+
+ result = true;
+
+ /* Nom du fichier associé */
+ access = strdup(path);
+ access = stradd(access, "/Filename");
+ result &= add_content_to_node(xdoc, context, access, binary->filename);
+ free(access);
return result;
@@ -332,99 +383,6 @@ GRenderingLine *get_openida_binary_lines(const openida_binary *binary)
-/******************************************************************************
-* *
-* Paramètres : xpathCtx = contexte à utiliser pour mener les parcours. *
-* base = première partie de l'expression XPath d'accès. *
-* index = indice de la élément dans la liste des voisins. *
-* *
-* Description : Lit un élément binaire depuis un fichier XML. *
-* *
-* Retour : Représentation mise en place à libérer de la mémoire. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-openida_binary *read_openida_binary_from_xml(xmlXPathContextPtr xpathCtx, const char *base, unsigned int index)
-{
- openida_binary *result; /* Représentation à retourner */
- size_t expr_len; /* Taille d'une expression */
- char *expr; /* Chemin XPath reconstitué */
- xmlXPathObjectPtr xpathObj; /* Cible d'une recherche */
- char *value; /* Type d'élément rencontré */
- size_t sub_expr_len; /* Taille d'une expression #2 */
- char *sub_expr; /* Chemin XPath reconstitué #2 */
- int i; /* Boucle de parcours */
-
- result = NULL;
-
- /* S'occupe en premier lieu du niveau courant */
-
- expr_len = strlen(base) + strlen("/*[position()=") + strlen("4294967295") /* UINT_MAX */ + strlen("]") + 1;
-
- expr = (char *)calloc(expr_len, sizeof(char));
- snprintf(expr, expr_len, "%s/*[position()=%u]", base, index);
-
- xpathObj = get_node_xpath_object(xpathCtx, expr);
-
- value = qck_get_node_prop_value(NODE_FROM_PATH_OBJ(xpathObj, 0), "type");
-
- xmlXPathFreeObject(xpathObj);
-
- if (value == NULL) goto robfx_err1;
-
- /* Raffinement au second passage */
-
- sub_expr_len = expr_len + strlen("/*");
- sub_expr = (char *)calloc(sub_expr_len, sizeof(char));
- snprintf(sub_expr, sub_expr_len, "%s/*", expr);
-
- xpathObj = get_node_xpath_object(xpathCtx, sub_expr);
-
- if (strcmp(value, "file") == 0) result = load_binary_file_from_xml(xpathObj);
-
- xmlXPathFreeObject(xpathObj);
-
- free(sub_expr);
-
- robfx_err1:
-
- free(expr);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = élément binaire à traiter. *
-* writer = rédacteur dédié à l'écriture. *
-* *
-* Description : Ecrit une sauvegarde du binaire dans un fichier XML. *
-* *
-* Retour : true si l'opération a bien tourné, false sinon. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool write_openida_binary_to_xml(const openida_binary *binary, xmlTextWriterPtr writer)
-{
- bool result; /* Bilan à faire remonter */
-
- result = open_xml_element(writer, "Binary");
-
- result &= write_xml_attribute(writer, "type", "file");
-
- result &= write_xml_element_with_content(writer, "Filename", "%s", binary->filename);
-
- result &= close_xml_element(writer);
-
- return result;
-
-}