diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2009-12-13 11:54:32 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2009-12-13 11:54:32 (GMT) | 
| commit | 7468875c1022337efbff78069d715672ae083150 (patch) | |
| tree | 0a8e5ce9cce113506a601539c9aa0a1b4ae48680 /src/common | |
| parent | c6409e2c6a390a7cca40da8572c93a5268e90a27 (diff) | |
Loaded and saved binary parts.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@140 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/dllist.c | 24 | ||||
| -rw-r--r-- | src/common/dllist.h | 29 | ||||
| -rw-r--r-- | src/common/xml.c | 107 | ||||
| -rw-r--r-- | src/common/xml.h | 12 | 
4 files changed, 129 insertions, 43 deletions
diff --git a/src/common/dllist.c b/src/common/dllist.c index 5de3cd9..2a75768 100644 --- a/src/common/dllist.c +++ b/src/common/dllist.c @@ -79,27 +79,3 @@ void __dl_list_del(dl_list_item *item, dl_list_head *head)      }  } - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : item = point d'insertion.                                    * -*                head = seconde liste à intégrer.                             * -*                                                                             * -*  Description : Insère une liste au sein d'une autre.                        * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void __dl_list_splice(dl_list_item *pos, dl_list_head head) -{ -    pos->next->prev = head; -    head->prev->next = pos->next; - -    pos->next = head; -    head->prev = pos; - -} diff --git a/src/common/dllist.h b/src/common/dllist.h index 3feef5c..499151e 100644 --- a/src/common/dllist.h +++ b/src/common/dllist.h @@ -58,9 +58,6 @@ void __dl_list_add(dl_list_item *, dl_list_head *, dl_list_item *, dl_list_item  /* Supprime un élément d'une liste doublement chaînée. */  void __dl_list_del(dl_list_item *, dl_list_head *); -/* Insère une liste au sein d'une autre. */ -void __dl_list_splice(dl_list_item *, dl_list_head); -  #define dl_list_empty(head)                                                         \      ((head) == NULL) @@ -79,6 +76,17 @@ void __dl_list_splice(dl_list_item *, dl_list_head);      }                                                                               \      while (0) +#define dl_list_add_before(new, head, pos, member)                                  \ +    do                                                                              \ +    {                                                                               \ +        pos->member.prev->next = &new->member;                                      \ +        new->member.prev = pos->member.prev;                                        \ +        pos->member.prev = &new->member;                                            \ +        new->member.next = &pos->member;                                            \ +        if (pos == *head) *head = new;                                              \ +    }                                                                               \ +    while (0) +  #define dl_list_add_tail(new, head, type, member)                                   \      do                                                                              \      {                                                                               \ @@ -109,21 +117,6 @@ void __dl_list_splice(dl_list_item *, dl_list_head);          _result;                                                                    \      }) -#define dl_list_splice_before(pos, head1, head2, type, member)                      \ -    do                                                                              \ -    {                                                                               \ -        if (pos == *head1)                                                          \ -        {                                                                           \ -            __dl_list_splice(head2->member.prev, &(*head1)->member);                \ -            *head1 = head2;                                                         \ -        }                                                                           \ -        else __dl_list_splice(pos->member.prev, &head2->member);                    \ -    }                                                                               \ -    while(0) - -#define dl_list_splice_after(pos, head2, type, member)                              \ -        __dl_list_splice(&pos->member, &head2->member); -  #define dl_list_next_iter(iter, head, type, member)                                 \      (iter->member.next == &head->member ?                                           \       NULL : container_of(iter->member.next, type, member)) diff --git a/src/common/xml.c b/src/common/xml.c index b89b4f9..eb450e0 100644 --- a/src/common/xml.c +++ b/src/common/xml.c @@ -26,6 +26,7 @@  #include <stdarg.h> +#include <stdio.h>  #include <string.h> @@ -694,6 +695,60 @@ xmlNodePtr get_node_from_xpath(xmlXPathContextPtr context, const char *path)  *  Paramètres  : xdoc    = structure XML chargée.                             *  *                context = contexte à utiliser pour les recherches.           *  *                path    = chemin d'accès au noeud visé.                      * +*                name    = nom du nouveau noeud à créer.                      * +*                                                                             * +*  Description : Ajoute un noeud à un autre noeud.                            * +*                                                                             * +*  Retour      : Adresse du noeud mis en place ou NULL en cas d'échec.        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +xmlNodePtr add_node_to_xpath(xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path, const char *name) +{ +    xmlNodePtr result;                      /* Noeud créé à retourner      */ +    xmlNodePtr parent;                      /* Support du nouveau noeud    */ + +    parent = get_node_from_xpath(context, path); +    if (parent == NULL) return NULL; + +    return add_node_to_node(xdoc, parent, name); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : xdoc   = structure XML chargée.                              * +*                parent = noeud parent de rattachement.                       * +*                name   = nom du nouveau noeud à créer.                       * +*                                                                             * +*  Description : Ajoute un noeud à un autre noeud.                            * +*                                                                             * +*  Retour      : Adresse du noeud mis en place ou NULL en cas d'échec.        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +xmlNodePtr add_node_to_node(xmlDocPtr xdoc, xmlNodePtr parent, const char *name) +{ +    xmlNodePtr result;                      /* Noeud créé à retourner      */ + +    result = xmlNewDocNode(xdoc, NULL, BAD_CAST name, NULL); +    result = xmlAddChild(parent, result); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : xdoc    = structure XML chargée.                             * +*                context = contexte à utiliser pour les recherches.           * +*                path    = chemin d'accès au noeud visé.                      *  *                                                                             *  *  Description : S'assure qu'un noeud donné est bien présent dans le document.*  *                                                                             * @@ -802,8 +857,58 @@ bool add_content_to_node(xmlDocPtr xdoc, xmlXPathContextPtr context, const char      node = ensure_node_exist(xdoc, context, path);      if (node == NULL) return false; -    xmlNodeSetContent(node, content); +    xmlNodeSetContent(node, BAD_CAST content);      return true;  } + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : node  = noeud dont le contenu est à mettre à jour.           * +*                name  = nom de la propriété à créer.                         * +*                value = chaîne de caractère à placer.                        * +*                                                                             * +*  Description : Ajoute une propriété à un noeud existant donné.              * +*                                                                             * +*  Retour      : true en cas de succès, false sinon.                          * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool add_string_attribute_to_node(xmlNodePtr node, const char *name, const char *value) +{ +    xmlAttrPtr attrib;                      /* Attribut créé et en place   */ + +    attrib = xmlSetProp(node, BAD_CAST name, BAD_CAST value); + +    return (attrib != NULL); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : node  = noeud dont le contenu est à mettre à jour.           * +*                name  = nom de la propriété à créer.                         * +*                value = valeur numérique à placer.                           * +*                                                                             * +*  Description : Ajoute une propriété à un noeud existant donné.              * +*                                                                             * +*  Retour      : true en cas de succès, false sinon.                          * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool add_long_attribute_to_node(xmlNodePtr node, const char *name, long value) +{ +    char tmp[11/*strlen("2147483647")*/];   /* Stockage temporaire         */ + +    snprintf(tmp, 11, "%ld", value); + +    return add_string_attribute_to_node(node, name, tmp); + +} diff --git a/src/common/xml.h b/src/common/xml.h index 82e2578..a555f56 100644 --- a/src/common/xml.h +++ b/src/common/xml.h @@ -111,12 +111,24 @@ bool write_xml_content(xmlTextWriterPtr, const char *, ...);  /* Fournit le premier noeud correspondant à un chemin XPath. */  xmlNodePtr get_node_from_xpath(xmlXPathContextPtr, const char *); +/* Ajoute un noeud à un autre noeud. */ +xmlNodePtr add_node_to_path(xmlDocPtr, xmlXPathContextPtr, const char *, const char *); + +/* Ajoute un noeud à un autre noeud. */ +xmlNodePtr add_node_to_node(xmlDocPtr, xmlNodePtr, const char *); +  /* S'assure qu'un noeud donné est bien présent dans le document. */  xmlNodePtr ensure_node_exist(xmlDocPtr, xmlXPathContextPtr, const char *);  /* S'assure qu'un noeud donné est bien présent dans le document. */  bool add_content_to_node(xmlDocPtr, xmlXPathContextPtr, const char *, const char *); +/* Ajoute une propriété à un noeud existant donné. */ +bool add_string_attribute_to_node(xmlNodePtr, const char *, const char *); + +/* Ajoute une propriété à un noeud existant donné. */ +bool add_long_attribute_to_node(xmlNodePtr, const char *, long); +  #endif  /* _XML_H */  | 
