drummer/libnode.h
Arnaud G. GIBERT 785e178b87 - Import libnode-2.3.0 pre release,
- Fix args order in ND_Value_Alloc() calls.
2023-08-17 19:45:24 +02:00

348 lines
17 KiB
C
Raw Blame History

/*---------------------------------------------------------------------------------*/
/* $RCSfile: libnode.h,v $ */
/*---------------------------------------------------------------------------------*/
/* $Revision: 2.10 $ */
/* $Name: libnode-2_2_0-1 $ */
/* $Date: 2010/06/06 21:26:31 $ */
/* $Author: agibert $ */
/*---------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------*/
/* This file is part of LibNode */
/* */
/* LibNode is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU Lesser General Public Licence as published by */
/* the Free Software Foundation; either version 2.1 of the License, or */
/* (at your option) any later version. */
/* */
/* LibNode 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 Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with LibNode; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*---------------------------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <setjmp.h>
#include <dlfcn.h>
/* Utilisation des API de la LIBNODE sans v<>rification des arguments */
#define ND_MODE 1
#include <node.h>
#ifdef __linux
# define NDD_PRINTF_PTR_PREFIX ""
#else
# define NDD_PRINTF_PTR_PREFIX "0x"
#endif
#define NDD_HUGE_LONG ( long) 0xFFFFFFL
/* Table des symboles locale */
struct NDT_Symbol;
typedef struct NDT_Symbol
{
void *Ptr;
char *Name;
struct NDT_Symbol *Next;
} NDT_Symbol;
/* LibNode Global Base Structure */
typedef struct NDT_Base
{
int Open_Status;
int Debug_Mode;
char Err_String[512];
FILE *Err_Stream;
int Sig_Trapped;
#if !defined(_WIN32)
sigjmp_buf SigLongJmp_Env;
#else
jmp_buf SigLongJmp_Env;
#endif
NDT_Symbol *Symbol_First_Ptr;
void *DL_Ptr;
NDT_Index_Type OpenStruct_Index_Type[1];
NDT_Root *OpenStruct_Ptr;
} NDT_Base;
NDT_Base NDG_Base =
{
NDD_FALSE,
NDD_TRUE,
"",
(FILE *) -1,
0,
{0},
(NDT_Symbol *) NULL,
NULL,
{ NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO},
(NDT_Root *) NULL
};
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* Fonctions et proc<6F>dures priv<69>es de la librairie (moyen niveau) */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* Manager par d<>faut */
/*------------------------------------------------------------------------------*/
/* (I) va_list Arguments : Liste d'arguments contextuels */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Default_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
/*------------------------------------------------------------------------------*/
/* OpenStruct Manager */
/*------------------------------------------------------------------------------*/
/* (I) va_list Arguments : Liste d'arguments contextuels */
/*------------------------------------------------------------------------------*/
NDT_Status ND_OpenStruct_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
/*------------------------------------------------------------------------------*/
/* Red<65>finition de la fonction malloc() avec retour de type NDT_Status */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Default_Allocator( void **, size_t, void *);
/*------------------------------------------------------------------------------*/
/* Red<65>finition de la fonction free() avec retour de type NDT_Status */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Default_Deallocator( void *, void *);
/*------------------------------------------------------------------------------*/
/* Cr<43>ation d'un noeud */
/*------------------------------------------------------------------------------*/
/* (I) Root : adresse de la racine pour laquelle on cr<63>e un noeud */
/* (O) New_Node : adresse du pointeur sur le nouveau noeud */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Node_Alloc( NDT_Root * Root, NDT_Node ** New_Node);
/*------------------------------------------------------------------------------*/
/* Destruction d'un noeud */
/*------------------------------------------------------------------------------*/
/* (I) Root : adresse de la racine dans laquelle on d<>truit un noeud */
/* (I) Node : pointeur sur le noeud <20> d<>truire */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Node_Free( NDT_Root *, NDT_Node *);
/*------------------------------------------------------------------------------*/
/* Cr<43>ation d'une nouvelle structure de donn<6E>es */
/*------------------------------------------------------------------------------*/
/* (O) Root: adresse d'un pointeur sur la racine de la nouvelle structure */
/* (I) Type: type de la structure.de donn<6E>es (liste ou arbre binaire) */
/* (I) Allocator: pointeur vers la fonction d'allocation */
/* (I) Deallocator: pointeur vers la fonction de d<>sallocation */
/* (I) Data : pointeur de donn<6E>es utiles <20> l'allocateur */
/* (I) Own_Value : indique si la structure est propri<72>taire de ses valeurs */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Index_Clear( NDT_Root *, NDT_Index_Id);
/*------------------------------------------------------------------------------*/
/* Cr<43>ation de la racine d'une structure de donn<6E>es quelconque */
/*------------------------------------------------------------------------------*/
/* (O) New_Root : adresse du pointeur sur la nouvelle racine */
/* (I) Type : type de la structure de donn<6E>es */
/* (I) Allocater : pointeur vers la fonction d'allocation */
/* (I) Deallocater : pointeur vers la fonction de d<>sallocation */
/* (I) Data : pointeur de donn<6E>es utiles <20> l'allocateur */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Node_Root_Alloc( NDT_Root **, NDT_Index_Nb, NDT_Index_Type[], char *, NDT_Manager *, char *, NDT_Allocator *, char *, NDT_Deallocator *, short, void *);
/*------------------------------------------------------------------------------*/
/* Destruction d'une racine */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine <20> d<>truire */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Node_Root_Free( NDT_Root *);
/*------------------------------------------------------------------------------*/
/* Ajout d'un noeud <20> une liste cha<68>n<EFBFBD>e */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la liste */
/* (I) New_Node : pointeur sur le noeud <20> ajouter */
/*------------------------------------------------------------------------------*/
NDT_Status ND_List_Node_Add( NDT_Root *, NDT_Index_Id, NDT_Node *);
/*------------------------------------------------------------------------------*/
/* Ajout d'une nouvelle valeur <20> une liste */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la liste */
/* (I) Value : pointeur sur la valeur <20> ajouter */
/*------------------------------------------------------------------------------*/
NDT_Status ND_List_Value_Add( NDT_Root *, NDT_Index_Id, void *);
/*------------------------------------------------------------------------------*/
/* Ajout d'un noeud <20> un arbre binaire */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de l'arbre */
/* (I) Value : pointeur sur la valeur <20> ajouter */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Tree_Value_Add( NDT_Root *, NDT_Index_Id, void *);
/*------------------------------------------------------------------------------*/
/* Supprime le noeud d'une liste */
/*------------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud <20> supprimer */
/*------------------------------------------------------------------------------*/
NDT_Status ND_List_Node_Remove( NDT_Node *);
/*------------------------------------------------------------------------------*/
/* Conversion d'une structure en liste cha<68>n<EFBFBD>e */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine du la structure <20> convertir */
/*------------------------------------------------------------------------------*/
NDT_Status ND_List_Make( NDT_Root *, NDT_Index_Id);
/*------------------------------------------------------------------------------*/
/* Recherche une valeur dans une liste et retourne le noeud correspondant */
/*------------------------------------------------------------------------------*/
NDT_Node *ND_List_Node_Find( NDT_Root *, NDT_Index_Id, void *, va_list *);
/*------------------------------------------------------------------------------*/
/* Recherche un noeud dans un arbre et retourne le pointeur sur le noeud */
/*------------------------------------------------------------------------------*/
NDT_Node *ND_Tree_Node_Find( NDT_Root *, NDT_Index_Id, void *, va_list *);
/*------------------------------------------------------------------------------*/
/* Conversion d'une structure en arbre binaire */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine du la structure <20> convertir */
/* (I) Type : type du futur arbre */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Tree_Make( NDT_Root *, NDT_Index_Id);
/*------------------------------------------------------------------------------*/
/* Equilibrage d'un arbre */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de l'arbre */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Tree_Equalize( NDT_Root *, NDT_Index_Id);
/*------------------------------------------------------------------------------*/
/* Retourne la profondeur de la plus grande branche <20> partir d'un noeud */
/*------------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud */
/*------------------------------------------------------------------------------*/
long ND_Tree_MaxDepth_Get( NDT_Node *);
/*------------------------------------------------------------------------------*/
/* Retourne la profondeur de la plus petite branche <20> partir d'un noeud */
/*------------------------------------------------------------------------------*/
/* (I) Node : pointeur sur le noeud */
/*------------------------------------------------------------------------------*/
long ND_Tree_MinDepth_Get( NDT_Node *);
/*------------------------------------------------------------------------------*/
/* Ajout d'un noeud <20> un arbre binaire */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de l'arbre */
/* (I) Node : pointeur sur le noeud <20> ajouter */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Tree_Node_Add( NDT_Root *, NDT_Index_Id, NDT_Node *);
/*------------------------------------------------------------------------------*/
/* Ajoute tous les noeud d'une liste <20> un arbre */
/*------------------------------------------------------------------------------*/
/* (I) Tree_Root : pointeur sur la racine de l'arbre */
/* (I) List_Root : pointeur sur la racine de la liste */
/*------------------------------------------------------------------------------*/
NDT_Status ND_Tree_List_Add( NDT_Root *, NDT_Index_Id, NDT_Root *, NDT_Index_Id);
/*------------------------------------------------------------------------------*/
/* Fonction de comparaison de noeuds (pour le quick sort) */
/*------------------------------------------------------------------------------*/
int ND_Node_Compare( void **, void **);
/*------------------------------------------------------------------------------*/
/* Ordonne une liste cha<68>n<EFBFBD>e selon l'algorithme du tri <20> bulle */
/*------------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la liste <20> trier */
/*------------------------------------------------------------------------------*/
NDT_Status ND_List_Sort( NDT_Root *, NDT_Index_Id);
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
/* PRIVATE FUNCTIONS */
/*------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------*/
void ND_List_Check( NDT_Root *, NDT_Index_Id, int *, int *, FILE *);
void ND_List_Link_Check( NDT_Root *, NDT_Index_Id, int *, int *, FILE *);
void ND_Value_Check( NDT_Root *, NDT_Index_Id, int *, int *, FILE *);
void ND_Tree_Check( NDT_Root *, NDT_Index_Id, int *, int *, FILE *);
void ND_Tree_Link_Check( NDT_Root *, NDT_Index_Id, int *, int *, FILE *);
NDT_Status ND_List_Recursive_Make( NDT_Node *, NDT_Root *, NDT_Index_Id);
NDT_Node *ND_Tree_Recursive_Make( long, long, NDT_Node *);
void ND_Tree_Node_Recursive_Add( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Node **, long , NDT_Node *);
NDT_Node *ND_Tree_Node_First_Recursive_Get( NDT_Node *);
NDT_Node *ND_Tree_Node_Last_Recursive_Get( NDT_Node *);
NDT_Node *ND_Tree_Node_Recursive_Find( NDT_Node *, void *, va_list *);
NDT_Node *ND_Tree_Parent_Next_Recursive_Get( NDT_Node *);
NDT_Node *ND_Tree_Parent_Previous_Recursive_Get( NDT_Node *);
void ND_Tree_Recursive_Print( NDT_Node *, long, FILE *);
void ND_Tree_Link_Recursive_Check( NDT_Node *, int *, int *, FILE *);
NDT_Status ND_Symbol_Find( void **, const char *);
void ND_Error_Print( void);
void ND_Signal_Trap( int);
NDT_Status ND_Address_Check( void *);