From 42ab4c90299c06f31ff699749f5b727e694c81e7 Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Tue, 30 Apr 2024 19:03:08 +0200 Subject: [PATCH] - Start a new ndbench implementation, based on ndbench, - Implement DS_Index_Open_I(), DS_Index_Close_I(), DS_Index_Convert_I(), - Convert DST_DataStruct.Name from pointer to array. --- include/datastr.h | 74 +- lib/libdatastr.c | 127 +++- lib/libdatastr.h | 2 +- util/dsbench.c | 1745 +++++++++++++++++++++++++++++++++------------ 4 files changed, 1481 insertions(+), 467 deletions(-) diff --git a/include/datastr.h b/include/datastr.h index 7aaad63..af59780 100644 --- a/include/datastr.h +++ b/include/datastr.h @@ -177,6 +177,7 @@ typedef struct DST_RootDesc # define DS_Library_Open DS_Library_Open_I # define DS_Library_Close DS_Library_Close_I # define DS_Library_Stderr_Set DS_Library_Stderr_Set_I + # define DS_DataStruct_Open DS_DataStruct_Open_I # define DS_DataStruct_Close DS_DataStruct_Close_I # define DS_DataStruct_Reorg DS_DataStruct_Reorg_I @@ -188,6 +189,11 @@ typedef struct DST_RootDesc # define DS_DataStruct_Check DS_DataStruct_Check_I # define DS_DataStruct_Lock DS_DataStruct_Lock_I # define DS_DataStruct_Unlock DS_DataStruct_Unlock_I + +# define DS_Index_Open DS_Index_Open_I +# define DS_Index_Close DS_Index_Close_I +# define DS_Index_Convert DS_Index_Convert_I + # define DS_Node_Root_Get DS_Node_Root_Get_I # define DS_Node_First_Get DS_Node_First_Get_I # define DS_Node_Last_Get DS_Node_Last_Get_I @@ -196,10 +202,12 @@ typedef struct DST_RootDesc # define DS_Node_Add DS_Node_Add_I # define DS_Node_Remove DS_Node_Remove_I # define DS_Node_Find DS_Node_Find_I + # define DS_Value_Alloc DS_Value_Alloc_I # define DS_Value_Add DS_Value_Add_I # define DS_Value_Remove DS_Value_Remove_I # define DS_Value_Free DS_Value_Free_I + # define DS_Alloc DS_Alloc_I # define DS_Free DS_Free_I @@ -213,6 +221,7 @@ typedef struct DST_RootDesc # define DS_Library_Open DS_Library_Open_L # define DS_Library_Close DS_Library_Close_L # define DS_Library_Stderr_Set DS_Library_Stderr_Set_L + # define DS_DataStruct_Open DS_DataStruct_Open_L # define DS_DataStruct_Close DS_DataStruct_Close_L # define DS_DataStruct_Reorg DS_DataStruct_Reorg_L @@ -224,6 +233,11 @@ typedef struct DST_RootDesc # define DS_DataStruct_Check DS_DataStruct_Check_L # define DS_DataStruct_Lock DS_DataStruct_Lock_L # define DS_DataStruct_Unlock DS_DataStruct_Unlock_L + +# define DS_Index_Open DS_Index_Open_L +# define DS_Index_Close DS_Index_Close_L +# define DS_Index_Convert DS_Index_Convert_L + # define DS_Node_Root_Get DS_Node_Root_Get_L # define DS_Node_First_Get DS_Node_First_Get_L # define DS_Node_Last_Get DS_Node_Last_Get_L @@ -232,10 +246,12 @@ typedef struct DST_RootDesc # define DS_Node_Add DS_Node_Add_L # define DS_Node_Remove DS_Node_Remove_L # define DS_Node_Find DS_Node_Find_L + # define DS_Value_Alloc DS_Value_Alloc_L # define DS_Value_Add DS_Value_Add_L # define DS_Value_Remove DS_Value_Remove_L # define DS_Value_Free DS_Value_Free_L + # define DS_Alloc DS_Alloc_L # define DS_Free DS_Free_L @@ -249,6 +265,7 @@ typedef struct DST_RootDesc # define DS_Library_Open DS_Library_Open_CL # define DS_Library_Close DS_Library_Close_CL # define DS_Library_Stderr_Set DS_Library_Stderr_Set_CL + # define DS_DataStruct_Open DS_DataStruct_Open_CL # define DS_DataStruct_Close DS_DataStruct_Close_CL # define DS_DataStruct_Reorg DS_DataStruct_Reorg_CL @@ -260,6 +277,11 @@ typedef struct DST_RootDesc # define DS_DataStruct_Check DS_DataStruct_Check_CL # define DS_DataStruct_Lock DS_DataStruct_Lock_CL # define DS_DataStruct_Unlock DS_DataStruct_Unlock_CL + +# define DS_Index_Open DS_Index_Open_CL +# define DS_Index_Close DS_Index_Close_CL +# define DS_Index_Convert DS_Index_Convert_CL + # define DS_Node_Root_Get DS_Node_Root_Get_CL # define DS_Node_First_Get DS_Node_First_Get_CL # define DS_Node_Last_Get DS_Node_Last_Get_CL @@ -268,10 +290,12 @@ typedef struct DST_RootDesc # define DS_Node_Add DS_Node_Add_CL # define DS_Node_Remove DS_Node_Remove_CL # define DS_Node_Find DS_Node_Find_CL + # define DS_Value_Alloc DS_Value_Alloc_CL # define DS_Value_Add DS_Value_Add_CL # define DS_Value_Remove DS_Value_Remove_CL # define DS_Value_Free DS_Value_Free_CL + # define DS_Alloc DS_Alloc_CL # define DS_Free DS_Free_CL @@ -396,11 +420,14 @@ DSD_API DST_Status DS_DataStruct_Close_CL( NDT_Root *Root_Ptr, DST_Flags Clo /*----------------------------------------------------------------------------*/ /* (I) Stream: Output stream */ /* (I) Root_Ptr: Data structure pointer */ +/* (I) Recursive_Mode: Child or Parent */ +/* (I) Recursive_Depth: Curent recursion depth */ +/* (I) Recursive_Offset: Curent print out offset */ /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_DataStruct_Info_Print_I( FILE *Out, NDT_Root *Root_Ptr); -DSD_API DST_Status DS_DataStruct_Info_Print_L( FILE *Out, NDT_Root *Root_Ptr); -DSD_API DST_Status DS_DataStruct_Info_Print_CL( FILE *Out, NDT_Root *Root_Ptr); +DSD_API DST_Status DS_DataStruct_Info_Print_I( FILE *Out, NDT_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset); +DSD_API DST_Status DS_DataStruct_Info_Print_L( FILE *Out, NDT_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset); +DSD_API DST_Status DS_DataStruct_Info_Print_CL( FILE *Out, NDT_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset); @@ -491,6 +518,47 @@ DSD_API DST_Status DS_DataStruct_Value_Print_CL( FILE *Out_Ptr, NDT_Root *Roo +/*----------------------------------------------------------------------------*/ +/* Create a new index */ +/*----------------------------------------------------------------------------*/ +/* (I) Root_Ptr: Data structure pointer */ +/* (I) Index_Id: Id of the index */ +/* (I) Index_Type: Index type (List, tree, ...) */ +/*----------------------------------------------------------------------------*/ + +DSD_API NDT_Status DS_Index_Open_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); +DSD_API NDT_Status DS_Index_Open_L( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); +DSD_API NDT_Status DS_Index_Open_CL( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); + + + +/*----------------------------------------------------------------------------*/ +/* Remove an Index */ +/*----------------------------------------------------------------------------*/ +/* (I) Root_Ptr: Data structure pointer */ +/* (I) Index_Id: Id of the index */ +/*----------------------------------------------------------------------------*/ + +DSD_API NDT_Status DS_Index_Close_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id); +DSD_API NDT_Status DS_Index_Close_L( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id); +DSD_API NDT_Status DS_Index_Close_CL( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id); + + + +/*----------------------------------------------------------------------------*/ +/* Convert a data structure index to another type */ +/*----------------------------------------------------------------------------*/ +/* (I) Root_Ptr: Data structure pointer */ +/* (I) Index_Id: Id of the index */ +/* (I) Index_Type: Index type (List, tree, ...) */ +/*----------------------------------------------------------------------------*/ + +DSD_API NDT_Status DS_Index_Convert_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); +DSD_API NDT_Status DS_Index_Convert_L( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); +DSD_API NDT_Status DS_Index_Convert_CL( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); + + + /*----------------------------------------------------------------------------*/ /* Récupération du premier noeud d'une structure */ /*----------------------------------------------------------------------------*/ diff --git a/lib/libdatastr.c b/lib/libdatastr.c index 49b7151..6a4e4a6 100644 --- a/lib/libdatastr.c +++ b/lib/libdatastr.c @@ -563,7 +563,7 @@ Strange: why end the heap here ? /* On ajoute la data structure à la liste des structures ouvertes par le processus courant */ - if( ( nd_status = ND_Value_Alloc( (void **)&opened_datastruct_ptr, OpenedDS_List, DS_Name, Root_Ptr_Ptr)) != NDS_OK) + if( ( nd_status = ND_Value_Alloc( (void **)&opened_datastruct_ptr, OpenedDS_List, DS_Name, *Root_Ptr_Ptr)) != NDS_OK) { LG_LOG_ERROR_2( "Unable to alloc a new opened data structure element: [%s], status: (%d)", DS_Name, nd_status); @@ -882,16 +882,16 @@ DST_Status DS_DataStruct_Close_I( NDT_Root *Root_Ptr, DST_Flags Close_Mode) /* Suppression de la data structure de la liste des structures ouvertes */ - to_remove.Name = ds_name; + strncpy( to_remove.Name, ds_name, DSD_NAME_LEN); - if( ( nd_status = ND_DataStruct_Value_Find( ( void **)&opened_datastruct_ptr, OpenedDS_List, &to_remove)) != NDS_OK) + if( ( ( nd_status = ND_DataStruct_Value_Find( ( void **)&opened_datastruct_ptr, OpenedDS_List, &to_remove)) != NDS_OK) || ( opened_datastruct_ptr == NULL)) { LG_LOG_ERROR_2( "Unable to find data struct element: [%s] from opened structure list, status: (%d)", ds_name, nd_status); return( DSS_KO); } else - { + { if( ( nd_status = ND_DataStruct_Value_Remove( OpenedDS_List, opened_datastruct_ptr)) != NDS_OK) { LG_LOG_ERROR_2( "Unable to remove data struct element: [%s] from opened structure list, status: (%d)", ds_name, nd_status); @@ -919,9 +919,12 @@ DST_Status DS_DataStruct_Close_I( NDT_Root *Root_Ptr, DST_Flags Close_Mode) /*----------------------------------------------------------------------------*/ /* (I) Stream: Output stream */ /* (I) Root_Ptr: Data structure pointer */ +/* (I) Recursive_Mode: Child or Parent */ +/* (I) Recursive_Depth: Curent recursion depth */ +/* (I) Recursive_Offset: Curent print out offset */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Info_Print_I( FILE *Out, NDT_Root *Root_Ptr) +DST_Status DS_DataStruct_Info_Print_I( FILE *Out, NDT_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset) { DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); @@ -957,7 +960,7 @@ DST_Status DS_DataStruct_Info_Print_I( FILE *Out, NDT_Root *Root_Ptr) /* Affichage des informations sur la structure */ - if( ( nd_status = ND_DataStruct_Info_Print( Out, Root_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 99, 0)) != NDS_OK) + if( ( nd_status = ND_DataStruct_Info_Print( Out, Root_Ptr, Recursive_Mode, Recursive_Depth, Recursive_Offset)) != NDS_OK) { LG_LOG_ERROR_1( "Unable to print info about the data structure: (%d)", nd_status); @@ -965,6 +968,24 @@ DST_Status DS_DataStruct_Info_Print_I( FILE *Out, NDT_Root *Root_Ptr) } + /* Opened DS Print */ + + if( ( nd_status = ND_DataStruct_Info_Print( Out, OpenedDS_List, Recursive_Mode, Recursive_Depth, Recursive_Offset)) != NDS_OK) + { + LG_LOG_ERROR_1( "Unable to print info about the data structure: (%d)", nd_status); + + return( DSS_KO); + } + + + if( ( nd_status = ND_DataStruct_Value_Print( Out, OpenedDS_List, Recursive_Mode, Recursive_Depth, Recursive_Offset)) != NDS_OK) + { + LG_LOG_ERROR_1( "Unable to print values about the data structure: (%d)", nd_status); + + return( DSS_KO); + } + + /* Dump SM */ SM_Library_Dump( stderr); @@ -1319,6 +1340,92 @@ DST_Status DS_DataStruct_Value_Print_I( FILE *Out_Ptr, NDT_Root *Root_Ptr, ND +/*----------------------------------------------------------------------------*/ +/* Create a new index */ +/*----------------------------------------------------------------------------*/ +/* (I) Root_Ptr: Data structure pointer */ +/* (I) Index_Id: Id of the index */ +/* (I) Index_Type: Index type (List, tree, ...) */ +/*----------------------------------------------------------------------------*/ + +NDT_Status DS_Index_Open_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type) +{ + NDT_Status nd_status; + + + if( ( nd_status = ND_Index_Open_I( Root_Ptr, Index_Id, Index_Type)) != NDS_OK) + { + LG_LOG_ERROR_2( "Unable to open index: (%d), status: (%d)", Index_Id, nd_status); + + return( DSS_KO); + } + else + { + return( DSS_OK); + } +} + + + + + +/*----------------------------------------------------------------------------*/ +/* Remove an Index */ +/*----------------------------------------------------------------------------*/ +/* (I) Root_Ptr: Data structure pointer */ +/* (I) Index_Id: Id of the index */ +/*----------------------------------------------------------------------------*/ + +NDT_Status DS_Index_Close_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id) +{ + NDT_Status nd_status; + + + if( ( nd_status = ND_Index_Close_I( Root_Ptr, Index_Id)) != NDS_OK) + { + LG_LOG_ERROR_2( "Unable to close index: (%d), status: (%d)", Index_Id, nd_status); + + return( DSS_KO); + } + else + { + return( DSS_OK); + } +} + + + + + +/*----------------------------------------------------------------------------*/ +/* Convert a data structure index to another type */ +/*----------------------------------------------------------------------------*/ +/* (I) Root_Ptr: Data structure pointer */ +/* (I) Index_Id: Id of the index */ +/* (I) Index_Type: Index type (List, tree, ...) */ +/*----------------------------------------------------------------------------*/ + +NDT_Status DS_Index_Convert_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type) +{ + NDT_Status nd_status; + + + if( ( nd_status = ND_Index_Convert_I( Root_Ptr, Index_Id, Index_Type)) != NDS_OK) + { + LG_LOG_ERROR_2( "Unable to convert index: (%d), status: (%d)", Index_Id, nd_status); + + return( DSS_KO); + } + else + { + return( DSS_OK); + } +} + + + + + /*----------------------------------------------------------------------------*/ /* Récupération du premier noeud d'une structure */ /*----------------------------------------------------------------------------*/ @@ -3207,7 +3314,7 @@ DST_Status DS_DataStruct_IsOpen( NDT_Root **Root_Ptr_Ptr, char *DS_Name) DST_DataStruct to_find, *found_ptr; - to_find.Name = DS_Name; + strncpy( to_find.Name, DS_Name, DSD_NAME_LEN); if( ( nd_status = ND_DataStruct_Value_Find( (void **)&found_ptr, OpenedDS_List, &to_find)) != NDS_OK) { @@ -3629,7 +3736,7 @@ NDT_Status DS_OpenedDS_List_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name); - if( ( *Opened_DataStruct_Ptr_Ptr = (DST_DataStruct *)malloc( sizeof( DST_DataStruct))) == NULL) + if( ( *Opened_DataStruct_Ptr_Ptr = ( DST_DataStruct *)malloc( sizeof( DST_DataStruct))) == NULL) { LG_LOG_ERROR_1( "Can't allocate value zise: (%d)", sizeof( DST_DataStruct)); @@ -3637,8 +3744,10 @@ NDT_Status DS_OpenedDS_List_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id } else { - ( *Opened_DataStruct_Ptr_Ptr)->Name = DS_Name; + strncpy( ( *Opened_DataStruct_Ptr_Ptr)->Name, DS_Name, DSD_NAME_LEN); ( *Opened_DataStruct_Ptr_Ptr)->Root_Ptr = Root_Ptr; + + LG_LOG_TRACE_2( LGD_LOG_LEVEL_DEFAULT, "Allocate new DS: Name: [%s] Root_Ptr: (%p)", DS_Name, Root_Ptr); return( DSS_OK); } diff --git a/lib/libdatastr.h b/lib/libdatastr.h index 873cf44..4c84d97 100644 --- a/lib/libdatastr.h +++ b/lib/libdatastr.h @@ -94,7 +94,7 @@ NDT_Root *OpenedDS_List; typedef struct DST_DataStruct { - char *Name; + char Name[ DSD_NAME_SIZE]; NDT_Root *Root_Ptr; } DST_DataStruct; diff --git a/util/dsbench.c b/util/dsbench.c index d57a7b1..f9c7804 100644 --- a/util/dsbench.c +++ b/util/dsbench.c @@ -30,8 +30,9 @@ #include #include #include -#include #include +#include +#include #include #include @@ -39,14 +40,52 @@ + + /*----------------------------------------------------------------------------*/ /* Defines */ /*----------------------------------------------------------------------------*/ #define LGD_MODULE_NAME "dsb" -extern char * strdup ( const char *); +#define USAGE "Usage : %s [ --help | --batch_run ]\n" +//extern char * strdup ( const char *); + +#define QUIT 0 +#define LIB_OPEN 1 +#define LIB_CLOSE 2 +#define DS_OPEN 3 +#define DS_CLOSE 4 +#define DS_FLUSH 5 +#define DS_CHECK 6 +#define DS_REORG 7 +#define DS_INFO_PRINT 8 +#define DS_VALUE_ADD 9 +#define DS_VALUE_REMOVE 10 +#define DS_VALUE_PRINT 11 +#define DS_VALUE_FIND 12 +#define INDEX_LIST_OPEN 13 +#define INDEX_TREE_OPEN 14 +#define INDEX_CLOSE 15 +#define INDEX_FLUSH 16 +#define INDEX_CHECK 17 +#define INDEX_LIST_SUBTYPE_SET 18 +#define INDEX_LIST_TO_TREE 19 +#define INDEX_TREE_SUBTYPE_SET 20 +#define INDEX_TREE_TO_LIST 21 +#define INDEX_REORG 22 +#define INDEX_INFO_PRINT 23 +#define INDEX_VALUE_PRINT 24 +#define INDEX_VALUE_BREAK 25 +#define INDEX_NODE_BREAK 26 +#define BATCH_RUN 27 + +#define COMMAND_NB 28 + +#define INDEX_NB 32 + +/* #define QUIT 0 #define CREATE_STRUCT 1 #define OPEN_STRUCT 2 @@ -63,48 +102,174 @@ extern char * strdup ( const char *); #define SHOW 13 #define CHECK 14 +#define BATCH_RUN 27 +*/ - -char DataStruct_Name [100]; +/* +char DataStruct_Name[ 100]; char menu [1000]; char buf [100]; long int random ( void ); +*/ + +#define DS_STATE_UNKNOWN 0 +#define DS_STATE_OPENED 1 +#define DS_STATE_CLOSED 2 + + + +#define ARG_SIZE ( 32 + 1) + + + +#define BUF_LEN 99 +#define BUF_SIZE (BUF_LEN + 1) /*----------------------------------------------------------------------------*/ -/* Prototype */ +/* Types */ /*----------------------------------------------------------------------------*/ -NDT_Status Module_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); +typedef struct Command +{ + + short id; + char Name[25]; + char FullName[64]; + short DS_State; + NDT_Index_Type Index_Type; + +} Command; + +typedef char Arg[32 + 1]; + -void Menu_Init ( NDT_Root *); -int Menu_Print ( NDT_Root *); /* Mesure des temps d'exécution */ -typedef struct { - double sec; - struct timeval start; - struct timeval stop; -} T_Cpt; +typedef struct cpt +{ + double sec; + struct timeval start; + struct timeval stop; +} cpt; -#define t_start(x) { gettimeofday (&(x.start), NULL);} -#define t_stop( x) { gettimeofday (&(x.stop), NULL); x.sec = (double)(x.stop.tv_sec) - (double)(x.start.tv_sec) + ((double)(x.stop.tv_usec) - (double)(x.start.tv_usec)) / 1000000;} -T_Cpt t_exec; + +cpt t_exec; + + +#define t_start(x) { gettimeofday( &((x).start), NULL);} +#define t_stop(x) { gettimeofday( &((x).stop), NULL); (x).sec = (double)((x).stop.tv_sec) - (double)((x).start.tv_sec) + ((double)((x).stop.tv_usec) - (double)((x).start.tv_usec)) / 1000000;} +#define seed_get(x) (int)( (x).start.tv_sec) /* Définition des valeurs attachées aux noeuds de la structure */ -typedef struct +typedef struct T_Module { int Id; char Nom[ DSD_NAME_SIZE]; -} T_Module; +} T_Module; + + + +NDT_Index_Type idx_type_tab[ INDEX_NB]; + +NDT_Index_Type DBD_IDX_TYPE_FIFO = NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO; + +NDT_Index_Type DBD_IDX_TYPE_SORTED_LIST = NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_SORTED; + +NDT_Index_Type DBD_IDX_TYPE_BALANCED_TREE = NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED; + + + + +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ + +#define DBD_ARG_READ( target_arg, local_arg, prompt_ptr) fprintf( File_Output, (prompt_ptr)); \ + fgets( buf, BUF_LEN, File_Input); \ + buf[ ( strlen( buf) - 1)] = '\0'; \ + strcpy( (local_arg), buf); \ + (target_arg) = (local_arg); + + +#define DBD_ARG_COPY( target_arg, local_arg) if( ( target_arg = malloc( ARG_SIZE)) != NULL) \ + { \ + if( !strcmp( local_arg, "\"\"")) \ + { \ + target_arg[0] = '\0'; \ + } \ + else \ + { \ + strcpy( target_arg, local_arg); \ + } \ + } + + + + + + +/*----------------------------------------------------------------------------*/ +/* Prototypes */ +/*----------------------------------------------------------------------------*/ + +NDT_Status Module_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); + +void Menu_Print( FILE *, NDT_Root *); +void Command_Get( int *, char **, char **, char **, FILE *, FILE *, short); +void Command_Exec_Begin_Print( FILE *, int); +void Command_Exec_End_Print( FILE *, int, cpt, int); +void Command_Index_Range_Get( FILE *, int *, int *, char *, char *, FILE *, int, char *); +void Command_Exec( NDT_Root **, FILE *, int, char *, char *, char *, FILE *); +void Batch_Run( NDT_Root **, FILE *, FILE *, short); + + + + + +/*----------------------------------------------------------------------------*/ +/* Global Variable */ +/*----------------------------------------------------------------------------*/ + +Command Command_Tab[] = +{ + { QUIT, "Quit", "Quit", ( DS_STATE_OPENED | DS_STATE_CLOSED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { LIB_OPEN, "Lib_Open", "Open Library", ( DS_STATE_OPENED | DS_STATE_CLOSED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { LIB_CLOSE, "Lib_Close", "Close Library", ( DS_STATE_OPENED | DS_STATE_CLOSED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { DS_OPEN, "DS_Open", "Open DataStructure", ( DS_STATE_CLOSED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { DS_CLOSE, "DS_Close", "Close DataStructure", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { DS_FLUSH, "DS_Flush", "Flush DataStructure", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { DS_CHECK, "DS_Check", "Check DataStructure", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { DS_REORG, "DS_Reorg", "Reorg DataStructure", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { DS_INFO_PRINT, "DS_Info_Print", "Print DataStructure Informations", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { DS_VALUE_ADD, "DS_Value_Add", "Add Values to DataStructure", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { DS_VALUE_REMOVE, "DS_Value_Remove", "Remove Values from DataStructure", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { DS_VALUE_PRINT, "DS_Value_Print", "Print DataStructure Values", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { DS_VALUE_FIND, "DS_Value_Find", "Find Values in DataStructure", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { INDEX_LIST_OPEN, "Index_List_Open", "Open List Index", ( DS_STATE_CLOSED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { INDEX_TREE_OPEN, "Index_Tree_Open", "Open Tree Index", ( DS_STATE_CLOSED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { INDEX_CLOSE, "Index_Close", "Close Index", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { INDEX_FLUSH, "Index_Flush", "Flush Index", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { INDEX_CHECK, "Index_Check", "Check Index", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { INDEX_LIST_SUBTYPE_SET, "Index_List_SubType_Set", "Set List SubType", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST)}, + { INDEX_LIST_TO_TREE, "Index_List_To_Tree", "Convert List to Tree", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST)}, + { INDEX_TREE_SUBTYPE_SET, "Index_Tree_SubType_Set", "Set Tree SubType", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_TREE)}, + { INDEX_TREE_TO_LIST, "Index_Tree_To_List", "Convert Tree to List", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_TREE)}, + { INDEX_REORG, "Index_Reorg", "Reorg Index", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { INDEX_INFO_PRINT, "Index_Info_Print", "Print Index Informations", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { INDEX_VALUE_PRINT, "Index_Value_Print", "Print Index Values", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { INDEX_VALUE_BREAK, "Index_Value_Break", "Break Index Value", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { INDEX_NODE_BREAK, "Index_Node_Break", "Break Index Node", ( DS_STATE_OPENED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)}, + { BATCH_RUN, "Batch_Run", "Run NDBench Bach", ( DS_STATE_OPENED | DS_STATE_CLOSED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)} +}; @@ -498,53 +663,31 @@ NDT_Status Module_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod -/*---------------------------------------------------------------------------------*/ -/* Menu_Init */ -/*---------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/* Menu_Print */ +/*----------------------------------------------------------------------------*/ -void Menu_Init( NDT_Root *Root ) +void Menu_Print( FILE *File_Output, NDT_Root *DS_Ptr) { - sprintf (menu, "Menu :\n"); - sprintf (buf, " - %d) %-30s\n", QUIT, "Quitter"); - strcat (menu, buf); - sprintf (buf, " - %d) %-30s", CREATE_STRUCT, "Création de structure"); - strcat (menu, buf); - sprintf (buf, " - %d) %-30s\n", OPEN_STRUCT, "Ouverture de structure"); - strcat (menu, buf); - if (Root != NULL) + short i; + char headc; + + + fprintf( File_Output, "\n-----------------------------------------------------------------------\nMenu :\n"); + + for( i = 0; i < COMMAND_NB; i++) { - sprintf (buf, " - %d) %-30s", CLOSE_STRUCT, "Fermer la structure"); - strcat (menu, buf); - sprintf (buf, " - %d) %-30s\n", DELETE_STRUCT, "Détruire la structure"); - strcat (menu, buf); - sprintf (buf, " - %d) %-30s", ADD_VALUE, "Ajout de valeurs"); - strcat (menu, buf); - sprintf (buf, " - %d) %-30s\n", REMOVE_VALUE, "Suppression de valeurs"); - strcat (menu, buf); - sprintf (buf, " - %d) %-30s\n", FIND_VALUE, "Recherche de valeurs aléatoires"); - strcat (menu, buf); - - if( ND_INDEX_TYPE_LIST_IS( Root, NDD_INDEX_PRIMARY)) + if( ( DS_Ptr && ( Command_Tab[i].DS_State & DS_STATE_OPENED) && ( DS_Ptr->Index_Tab[0].Type & Command_Tab[i].Index_Type)) + || ( !DS_Ptr && ( Command_Tab[i].DS_State & DS_STATE_CLOSED))) { - sprintf (buf, " - %d) %-30s", CHG_LIST_TYPE, "Changement de type de liste"); - strcat (menu, buf); - sprintf (buf, " - %d) %-30s\n", CONVERT_TO_TREE, "Conversion en arbre"); - strcat (menu, buf); + headc = '-'; } else { - sprintf (buf, " - %d) %-30s", CONVERT_TO_LIST, "Conversion en liste triée"); - strcat (menu, buf); - } - - sprintf (buf, " - %d) %-30s\n", REORG, "Réorganisation"); - strcat (menu, buf); - sprintf (buf, " - %d) %-30s", INFO, "Informations sur la structure"); - strcat (menu, buf); - sprintf (buf, " - %d) %-30s\n", SHOW, "Affichage de la structure"); - strcat (menu, buf); - sprintf (buf, " - %d) %-30s\n", CHECK, "Vérification de la structure"); - strcat (menu, buf); + headc = '*'; + } + + fprintf( File_Output, "\t%c (%2d) [%s]%*s%s\n", headc, i, Command_Tab[i].Name, ( 25 - strlen(Command_Tab[i].Name)), " ", Command_Tab[i].FullName); } } @@ -552,23 +695,1066 @@ void Menu_Init( NDT_Root *Root ) -/*---------------------------------------------------------------------------------*/ -/* Menu_Print */ -/*---------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/* Command_Get */ +/*----------------------------------------------------------------------------*/ -int Menu_Print( NDT_Root *Root ) +void Command_Get( int *choice, char **Arg1, char **Arg2, char **Arg3, FILE *File_Output, FILE *File_Input, short Interactive_Flag) { - Menu_Init (Root); - fprintf (stdout, "\n---------------------------------------------------------\n"); - fprintf (stdout, menu); - buf [0] = '\0'; - while (buf [0] == '\0') + char buf[100]; + char *tmp_arg1, *tmp_arg2, *tmp_arg3; + + + do { - printf ("\nChoice ? "); - fgets( buf, 100, stdin); + if( Interactive_Flag) + { + fprintf( File_Output, "\nChoice ? "); + } + + if( fgets( buf, BUF_LEN, File_Input) != NULL) + { + while( ( buf[ strlen( buf) - 1] == '\r') || ( buf[ strlen( buf) - 1] == '\n') || ( buf[ strlen( buf) - 1] == '\t') || ( buf[ strlen( buf) - 1] == ' ')) + { + buf[ strlen( buf) - 1] = '\0'; + } + + if( isdigit( *buf)) + { + *choice = atoi( buf); + } + else + { + for( *choice = 0; ( *choice < COMMAND_NB) && ( strncmp( buf, Command_Tab[*choice].Name, strlen(Command_Tab[*choice].Name))) ; (*choice)++); + } + + if( ( *choice < 0) || ( *choice >= COMMAND_NB)) + { + if( strlen( buf) != 0) fprintf( File_Output, "\nUndefined choice (%s) !\n",buf); + + *choice = -1; + *Arg1 = NULL; + *Arg2 = NULL; + *Arg3 = NULL; + } + else + { + if( ( tmp_arg1 = strstr( buf, " ")) != NULL) + { + tmp_arg1++; + + if( ( tmp_arg2 = strstr( tmp_arg1, " ")) != NULL) + { + *tmp_arg2 = '\0'; + tmp_arg2++; + + if( ( tmp_arg3 = strstr( tmp_arg2, " ")) != NULL) + { + *tmp_arg3 = '\0'; + tmp_arg3++; +/* + *Arg3 = malloc( ARG_SIZE); + if( *Arg3 != NULL) strcpy( *Arg3, tmp_arg3); +*/ + DBD_ARG_COPY( *Arg3, tmp_arg3); + } + else + { + *Arg3 = NULL; + } +/* + *Arg2 = malloc( ARG_SIZE); + if( *Arg2 != NULL) strcpy( *Arg2, tmp_arg2); +*/ + DBD_ARG_COPY( *Arg2, tmp_arg2); + + } + else + { + *Arg2 = NULL; + *Arg3 = NULL; + } +/* + *Arg1 = malloc( ARG_SIZE); + if( *Arg1 != NULL) strcpy( *Arg1, tmp_arg1); +*/ + DBD_ARG_COPY( *Arg1, tmp_arg1); + } + else + { + *Arg1 = NULL; + *Arg2 = NULL; + *Arg3 = NULL; + } + } + } + else + { + *choice = 0; + *Arg1 = NULL; + *Arg2 = NULL; + *Arg3 = NULL; + } + } + while( *choice == -1); + + LG_LOG_INFO_3( "Arg1: [%s] Arg2: [%s] Arg3: [%s]", *Arg1, *Arg2, *Arg3); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* Command_Exec_Begin_Print */ +/*----------------------------------------------------------------------------*/ + +void Command_Exec_Begin_Print( FILE *File_Output, int Choice) +{ + LG_LOG_INFO_2( "%s: %s...", Command_Tab[Choice].Name, Command_Tab[Choice].FullName); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* Command_Exec_End_Print */ +/*----------------------------------------------------------------------------*/ + +void Command_Exec_End_Print( FILE *File_Output, int Choice, cpt T_Exec, int nb) +{ + if( nb == 1) + { + LG_LOG_INFO_2( "%s: Completed in (%.4f) second !", Command_Tab[Choice].Name, T_Exec.sec); + } + else + { + LG_LOG_INFO_3( "%s: Completed in (%.4f) second, (%.2f) per second !", Command_Tab[Choice].Name, T_Exec.sec, nb / T_Exec.sec); + } +} + + + + + +/*----------------------------------------------------------------------------*/ +/* Command_Index_Range_Get */ +/*----------------------------------------------------------------------------*/ + +void Command_Index_Range_Get( FILE *File_Output, int *Low, int *High, char *Arg1, char *Arg2, FILE *File_Input, int Choice, char *Obj_Name) +{ + char prompt[ 100], buf[ 100], local_arg1[ 100], local_arg2[ 100]; + char *tmp; + + + if( Arg1 == NULL) + { + snprintf( prompt, 100, "%s: %s range from: ", Command_Tab[Choice].Name, Obj_Name); + DBD_ARG_READ( Arg1, local_arg1, prompt); + + snprintf( prompt, 100, "%s: %s range to: ", Command_Tab[Choice].Name, Obj_Name); + DBD_ARG_READ( Arg2, local_arg2, prompt); } - return atoi (buf); + *Low = atoi( Arg1); + *High = atoi( Arg2); + + if( ( *High < *Low) || ( !strcmp( Obj_Name, "Index") && ( *High >= INDEX_NB))) + { + fprintf( File_Output, "%s: Invalit range (%d-%d) !\n", Command_Tab[Choice].Name, *Low, *High); + *Low = *High = -1; + } +} + + + + + +/*----------------------------------------------------------------------------*/ +/* Command_Exec */ +/*----------------------------------------------------------------------------*/ + +void Command_Exec( NDT_Root **DS_Ptr_Ptr, FILE *File_Output, int Choice, char *Arg1, char *Arg2, char *Arg3, FILE *File_Input) +{ + DST_Status status; + int sub_choice_int1, sub_choice_int2, low, high, i, j, nb_removed, Nb_Detected, Nb_Corrected; + char *sub_choice_str; + T_Module Ref_Module, *Module_Ptr; + char buf[ BUF_SIZE], local_arg1[ BUF_SIZE], local_arg2[ BUF_SIZE], local_arg3[ BUF_SIZE]; + NDT_Index_Type index_subtype; + + +// fprintf( File_Output, "\n"); + + switch( Choice) + { + case QUIT: + { + break; + } + + case LIB_OPEN: + { + Command_Exec_Begin_Print( File_Output, Choice); + + if( Arg1 == NULL) + { + DBD_ARG_READ( Arg1, local_arg1, "Library_Open: Instance # (Default: 0): "); + DBD_ARG_READ( Arg2, local_arg2, "Library_Open: Context (Default: ""): "); + DBD_ARG_READ( Arg3, local_arg3, "Library_Open: Debug Mode (0:OFF | 1:ON): "); + } + sub_choice_int1 = atoi( Arg1); + sub_choice_str = strlen( Arg2) ? Arg2 : NULL; + sub_choice_int2 = atoi( Arg3); + + LG_LOG_TRACE_3( LGD_LOG_LEVEL_DEFAULT, "DS_Library_Open: Instance: (%d) Contect: [%s] Debug Mode: (%d)", sub_choice_int1, sub_choice_str, sub_choice_int2); + + t_start( t_exec); + DS_Library_Open( sub_choice_int1, sub_choice_str, sub_choice_int2); + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, 1); + break; + } + + case LIB_CLOSE: + { + Command_Exec_Begin_Print( File_Output, Choice); + + t_start( t_exec); + DS_Library_Close(); + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, 1); + break; + } + + case DS_OPEN: + { + Command_Exec_Begin_Print( File_Output, Choice); + + if( Arg1 == NULL) + { + DBD_ARG_READ( Arg1, local_arg1, "DataStruct_Open: Name: "); + DBD_ARG_READ( Arg2, local_arg2, "DataStruct_Open: Mode (0:Open | 1:Create): "); + } + + sub_choice_str = Arg1; + sub_choice_int1 = atoi( Arg2); + + for( i = 0; i < INDEX_NB; i++) + { + idx_type_tab[i] = NDD_INDEX_STATUS_CLOSED; + } + + LG_LOG_TRACE_2( LGD_LOG_LEVEL_DEFAULT, "DS_DataStruct_Open: Name: [%s] Open Mode: (%d)", sub_choice_str, sub_choice_int1); + + t_start( t_exec); + + if( ( status = DS_DataStruct_Open( DS_Ptr_Ptr, sub_choice_str, INDEX_NB, idx_type_tab, "Module_Manager", 0, ( sub_choice_int1 ? DSD_CREATE : DSD_OPEN), TRUE)) != DSS_OK) + { + LG_LOG_ERROR_2( "Can't open data structure: [%s], status: (%d)", sub_choice_str, status); + } + else + { + LG_LOG_INFO_1( "Data structure: [%s] created", sub_choice_str); + } + + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, 1); + break; + } + + case DS_CLOSE: + { + Command_Exec_Begin_Print( File_Output, Choice); + + t_start( t_exec); + if( ( status = DS_DataStruct_Close( *DS_Ptr_Ptr, DSD_CLOSE) != DSS_OK)) + { + LG_LOG_ERROR_1( "Can't close data structure: (%d)", status); + } + else + { + LG_LOG_INFO_0( "Data structure closed"); + *DS_Ptr_Ptr = NULL; + } + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, 1); + break; + } +/* + case DS_FLUSH: + { + Command_Exec_Begin_Print( File_Output, Choice); + + t_start( t_exec); + ND_DataStruct_Flush( *DS_Ptr_Ptr); + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, 1); + break; + } + + case DS_CHECK: + { + Command_Exec_Begin_Print( File_Output, Choice); + + Nb_Corrected = Nb_Detected = 0; + + t_start( t_exec); + ND_DataStruct_Check( *DS_Ptr_Ptr, &Nb_Detected, &Nb_Corrected, File_Output); + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, 1); + break; + } + + case DS_REORG: + { + Command_Exec_Begin_Print( File_Output, Choice); + + t_start( t_exec); + ND_DataStruct_Reorg( *DS_Ptr_Ptr); + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, 1); + break; + } +*/ + case DS_INFO_PRINT: + { + Command_Exec_Begin_Print( File_Output, Choice); + + t_start( t_exec); + + DS_DataStruct_Info_Print( File_Output, *DS_Ptr_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 99, 0); + + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, 1); + break; + } +/* + case DS_VALUE_ADD: + { + int order; + + + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Value"); + + if( low != -1) + { + if( Arg2 == NULL) + { + fprintf( File_Output, "DS_Value_Add: Add order ( 0:croissant | 1:decroissant) ? "); + fgets( buf, BUF_LEN ,stdin); + + Arg2 = buf; + } + + order = atoi( Arg2); + +// fprintf( File_Output, "DS_Value_Add: Adding from: (%d) to: (%d) order: (%d)...\n", low, high, order); +// fflush( File_Output); + + LG_LOG_INFO_3( "DS_Value_Add: Adding from: (%d) to: (%d) order: (%d)...", low, high, order); + + + t_start( t_exec); + + if( order == 0) + { + i = low; + j = high + 1; + + while( i < j) + { + if( ND_Value_Alloc( (void **)&Module_Ptr, *DS_Ptr_Ptr, "x", i) == NDS_OK) + { + ND_DataStruct_Value_Add( *DS_Ptr_Ptr, Module_Ptr); + } + else + { +// fprintf( File_Output, "DS_Value_Add: Allocation Failled !\n"); + + LG_LOG_ERROR_0( "DS_Value_Add: Allocation Failled !"); + break; + } + + i++; + } + } + else + { + i = high; + j = low - 1; + + while( i > j) + { + if( ND_Value_Alloc( (void **)&Module_Ptr, *DS_Ptr_Ptr, "x", i) == NDS_OK) + { + ND_DataStruct_Value_Add( *DS_Ptr_Ptr, Module_Ptr); + } + else + { +// fprintf( File_Output, "DS_Value_Add: Allocation Failled !\n"); + LG_LOG_ERROR_0( "DS_Value_Add: Allocation Failled !"); + break; + } + + i--; + } + } + + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + + break; + } + + case DS_VALUE_REMOVE: + { + int order; + nb_removed = 0; + + + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Value"); + + if( low != -1) + { + if( Arg2 == NULL) + { + fprintf( File_Output, "\nDS_Value_Remove: Remove order (croissant=0 | decroissant=1) ? "); + fgets( buf, BUF_LEN, File_Input); + + Arg2 = buf; + } + + order = atoi( Arg2); + + t_start( t_exec); + + if( order == 0) + { + i = low; + j = high + 1; + + while( i < j) + { + Ref_Module.Id = i; + + if( ( ND_DataStruct_Value_Find( (void **)&Module_Ptr, *DS_Ptr_Ptr, &Ref_Module) == NDS_OK) && ( Module_Ptr != NULL)) + { + if( ND_DataStruct_Value_Remove( *DS_Ptr_Ptr, (void *)Module_Ptr) == NDS_OK) + { + nb_removed++; + ND_Value_Free( *DS_Ptr_Ptr, Module_Ptr); + } + } + + i++; + } + } + else + { + i = high; + j = low - 1; + t_start( t_exec); + + while( i > j) + { + Ref_Module.Id = i; + + if( ( ND_DataStruct_Value_Find( (void **)&Module_Ptr, *DS_Ptr_Ptr, &Ref_Module) == NDS_OK) && ( Module_Ptr != NULL)) + { + if( ND_DataStruct_Value_Remove( *DS_Ptr_Ptr, (void *)Module_Ptr) == NDS_OK) + { + nb_removed++; + ND_Value_Free( *DS_Ptr_Ptr, Module_Ptr); + } + } + + i--; + } + } + + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + + break; + } + + case DS_VALUE_PRINT: + { + Command_Exec_Begin_Print( File_Output, Choice); + + ND_DataStruct_Value_Print( File_Output, *DS_Ptr_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 99, 0); + break; + } + + case DS_VALUE_FIND: + { + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Search"); + + if( low != -1) + { +// fprintf( File_Output, "DS_Value_Find: from: (%d) to: (%d)...\n", low, high); +// fflush( File_Output); + + LG_LOG_INFO_2( "DS_Value_Find: from: (%d) to: (%d)...", low, high); + + + i = low; + j = high + 1; + + t_start( t_exec); + + while( i < j) + { + Ref_Module.Id = low + (int)( (double)( high - low) * rand() / ( RAND_MAX + 1.0)); + ND_DataStruct_Value_Find( (void *)&Module_Ptr, *DS_Ptr_Ptr, &Ref_Module); + i++; + } + + t_stop (t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + + break; + } +*/ + case INDEX_LIST_OPEN: + { + Command_Index_Range_Get( File_Output, &low, &high, Arg1, Arg2, File_Input, Choice, "Index"); + + if( low != -1) + { + LG_LOG_INFO_2( "Index_List_Open: Opening a FIFO List from: (%d) to: (%d)...", low, high); + + t_start( t_exec); + + for( i = low; i <= high; i++) + { + DS_Index_Open( *DS_Ptr_Ptr, (NDT_Index_Id)i, DBD_IDX_TYPE_FIFO); + } + + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + + break; + } +/* + case INDEX_TREE_OPEN: + { + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Index"); + + if( low != -1) + { +// fprintf( File_Output, "Index_Tree_Open: Opening a balanced Tree from: (%d) to: (%d)...\n", low, high); +// fflush( File_Output); + + LG_LOG_INFO_2( "Index_Tree_Open: Opening a balanced Tree from: (%d) to: (%d)...", low, high); + + t_start( t_exec); + + for( i = low; i <= high; i++) + { + ND_Index_Open( *DS_Ptr_Ptr, (NDT_Index_Id)i, idx_type_balanced_tree); + } + + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + + break; + } + + case INDEX_CLOSE: + { + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Index"); + + if( low != -1) + { +// fprintf( File_Output, "Index_Close: Closing index from: (%d) to: (%d)...\n", low, high); +// fflush( File_Output); + + LG_LOG_INFO_2( "Index_Close: Closing index from: (%d) to: (%d)...", low, high); + + t_start( t_exec); + + for( i = high; i >= low; i--) + { + ND_Index_Close( *DS_Ptr_Ptr, (NDT_Index_Id)i); + } + + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + + break; + } + + case INDEX_LIST_SUBTYPE_SET: + { + int subtype; + + + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Index"); + + if( low != -1) + { + if( Arg2 == NULL) + { + fprintf( File_Output, "Index_List_SubType_Set: List SubType ( 0:FIFO | 1:LIFO | 2:Sorted) ? "); + fgets( buf, BUF_LEN, File_Input); + + Arg2 = buf; + } + + subtype = atoi( Arg2); + + switch( subtype) + { + case 0: + { + index_subtype = NDD_INDEX_SUBTYPE_FIFO; + break; + } + + case 1: + { + index_subtype = NDD_INDEX_SUBTYPE_FILO; + break; + } + + case 2: + { + index_subtype = NDD_INDEX_SUBTYPE_SORTED; + break; + } + + default: + { + index_subtype = NDD_INDEX_SUBTYPE_UNKNOWN; + printf ("Index_List_SubType_Set: Invalid selection (%d) !\n", subtype); + break; + } + } + + if( index_subtype != NDD_INDEX_SUBTYPE_UNKNOWN) + { +// fprintf( File_Output, "Index_List_SubType_Set: Setting List SubType to: (%d) (%s) !\n", index_subtype, ND_INDEX_SUBTYPE_VALUE_ASCII_GET( index_subtype)); + LG_LOG_INFO_2( "Index_List_SubType_Set: Setting List SubType to: (%d) (%s) !", index_subtype, ND_INDEX_SUBTYPE_VALUE_ASCII_GET( index_subtype)); + + t_start( t_exec); + + for( i = low; i <= high; i++) + { + if( ND_INDEX_TYPE_LIST_IS( *DS_Ptr_Ptr, i)) + { + (*DS_Ptr_Ptr)->Index_Tab[i].Type = ( (*DS_Ptr_Ptr)->Index_Tab[i].Type & NDD_INDEX_SUBTYPE_RMSK) | index_subtype; + } + else + { + fprintf( File_Output, "Index_List_SubType_Set: Error: index (%d) is not a List !\n", i); + } + } + + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + } + + break; + } + + case INDEX_TREE_SUBTYPE_SET: + { + int subtype; + + + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Index"); + + if( low != -1) + { + if( Arg2 == NULL) + { + fprintf( File_Output, "Index_Tree_SubType_Set: Tree SubType (0:UnBalanced | 1:Balanced) ? "); + fgets( buf, BUF_LEN, stdin); + + Arg2 = buf; + } + + subtype = atoi( Arg2); + + switch( subtype) + { + case 0: + { + index_subtype = NDD_INDEX_SUBTYPE_UNBALANCED; + break; + } + + case 1: + { + index_subtype = NDD_INDEX_SUBTYPE_BALANCED; + break; + } + + default: + { + index_subtype = NDD_INDEX_SUBTYPE_UNKNOWN; + printf ("Index_Tree_SubType_Set: Invalid selection (%d)!\n", subtype); + break; + } + } + + if( index_subtype != NDD_INDEX_SUBTYPE_UNKNOWN) + { + + t_start( t_exec); + + for( i = low; i <= high; i++) + { + if( ND_INDEX_TYPE_TREE_IS( *DS_Ptr_Ptr, i)) + { + (*DS_Ptr_Ptr)->Index_Tab[i].Type = ( (*DS_Ptr_Ptr)->Index_Tab[i].Type & NDD_INDEX_SUBTYPE_RMSK) | index_subtype; + } + else + { + fprintf( File_Output, "Index_Tree_SubType_Set: Error: index (%d) is not a Tree !\n", i); + } + } + + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + } + + break; + } + + case INDEX_REORG: + { + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Index"); + + if( low != -1) + { + t_start( t_exec); + + for( i = low; i <= high; i++) + { +// fprintf( File_Output, "Index_Reorg: Reorganizing index (%d)...\n", i); +// fflush( File_Output); + + LG_LOG_INFO_1( "Index_Reorg: Reorganizing index (%d)...", i); + + ND_Index_Reorg( *DS_Ptr_Ptr, (NDT_Index_Id)i); + } + + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + + break; + } + + case INDEX_TREE_TO_LIST: + { + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Index"); + + if( low != -1) + { + t_start( t_exec); + + for( i = low; i <= high; i++) + { +// fprintf( File_Output, "Index_Tree_To_List: Converting Index (%d)...\n", i); +// fflush( File_Output); + + LG_LOG_INFO_1( "Index_Tree_To_List: Converting Index (%d)...", i); + + ND_Index_Convert( *DS_Ptr_Ptr, (NDT_Index_Id)i, idx_type_sorted_list); + } + + t_stop (t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + + break; + } + + case INDEX_LIST_TO_TREE: + { + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Index"); + + if( low != -1) + { + t_start( t_exec); + + for( i = low; i <= high; i++) + { +// fprintf( File_Output, "Index_List_To_Tree: Converting Index (%d)...\n", i); +// fflush( File_Output); + + LG_LOG_INFO_1( "Index_List_To_Tree: Converting Index (%d)...", i); + + ND_Index_Convert( *DS_Ptr_Ptr, (NDT_Index_Id)i, idx_type_balanced_tree); + } + + t_stop (t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + + break; + } + + case INDEX_INFO_PRINT: + { + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Index"); + + if( low != -1) + { +// fprintf( File_Output, "Index_Info_Print: Printing index from: (%d) to: (%d)...\n", low, high); +// fflush( File_Output); + + LG_LOG_INFO_2( "Index_Info_Print: Printing index from: (%d) to: (%d)...", low, high); + + for( i = low; i <= high; i++) + { + ND_Index_Info_Print( File_Output, *DS_Ptr_Ptr, (NDT_Index_Id)i, NDD_RECURSIVE_MODE_PARENT_CHILD, 99, 0); + } + } + + break; + } + + case INDEX_VALUE_PRINT: + { +// fprintf( File_Output, "DS_Value_Print:\n"); +// fflush( File_Output); + + LG_LOG_INFO_0( "DS_Value_Print:"); + + ND_DataStruct_Value_Print( File_Output, *DS_Ptr_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 99, 0); + break; + } + + case INDEX_VALUE_BREAK: + { + int position; + NDT_Node *node_ptr; + + + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Index"); + + if( low != -1) + { + if( Arg2 == NULL) + { + fprintf( File_Output, "Index_Value_Break: Value position (0:Head | 1:Tail | 2:Random) ? "); + fgets( buf, BUF_LEN, stdin); + + Arg2 = buf; + } + + position = atoi( Arg2); + +// fprintf( File_Output, "Index_Value_Break: Breaking %s values from index : (%d) to: (%d)...\n", +// ( position == 0 ) ? "Head" : ( ( position == 1) ? "Tail" : "Random"), +// low, high); +// fflush( File_Output); + + LG_LOG_INFO_3( "Index_Value_Break: Breaking: (%s) values from index: (%d) to: (%d)...", + ( position == 0 ) ? "Head" : ( ( position == 1) ? "Tail" : "Random"), + low, high); + + t_start( t_exec); + +// fprintf( File_Output, "Index_Value_Break: Breaking value of nodes: "); +// fflush( File_Output); + + for( i = low; i <= high; i++) + { + switch( position) + { + case 0: + { + node_ptr =(*DS_Ptr_Ptr)->Index_Tab[i].Head; + break; + } + + case 1: + { + node_ptr=(*DS_Ptr_Ptr)->Index_Tab[i].Tail; + break; + } + + case 2: + { + j = (int)( (double)( (*DS_Ptr_Ptr)->Index_Tab[i].Node_Number) * rand() / ( RAND_MAX + 1.0)); + + for( node_ptr = (*DS_Ptr_Ptr)->Index_Tab[i].Head; j > 0; j--) + { + node_ptr = node_ptr->Right; + } + + break; + } + } + +// fprintf( File_Output, "0x(%x)", node_ptr); +// fflush( File_Output); + + LG_LOG_INFO_1( "Index_Value_Break: Breaking value of node: 0x(%x)", node_ptr); + + node_ptr->Value = (void *)-1; + } + + t_stop (t_exec); + + fprintf( File_Output, "\n"); + fflush( File_Output); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + + break; + } + + case INDEX_NODE_BREAK: + { + + break; + } + + case INDEX_CHECK: + { + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Index"); + + if( low != -1) + { + t_start( t_exec); + + for( i = low; i <= high; i++) + { +// fprintf( File_Output, "Index_Check: Checking Index (%d)...\n", i); +// fprintf( File_Output, "Index_Check: "); +// fflush( File_Output); + + LG_LOG_INFO_1( "Index_Check: Checking Index (%d)...", i); + LG_LOG_INFO_0( "Index_Check: "); + + Nb_Corrected = Nb_Detected = 0; + ND_Index_Check( *DS_Ptr_Ptr, (NDT_Index_Id)i, &Nb_Detected, &Nb_Corrected, File_Output); + } + + t_stop (t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + + break; + } +*/ + case BATCH_RUN: + { + FILE *file_input; + + + if( Arg1 == NULL) + { + fprintf( File_Output, "Batch_Run: Batch file name ? "); + + fgets( buf, BUF_LEN, stdin); + buf[ strlen( buf) - 1] = '\0'; + Arg1 = buf; + } + + file_input = fopen( Arg1, "r"); + + if( file_input == NULL) + { +// fprintf( File_Output, "Batch_Run: Can't open file (%s)!\n", Arg1); + LG_LOG_ERROR_1( "Batch_Run: Can't open file (%s)!", Arg1); + } + else + { +// fprintf( File_Output, "\n\n--------------------------------------------------------------------------------\n"); +// fprintf( File_Output, "Batch_Run: Starting execution (%s)...\n", Arg1); + LG_LOG_INFO_0( "--------------------------------------------------------------------------------"); + LG_LOG_INFO_1( "Batch_Run: Starting execution (%s)...", Arg1); + + Batch_Run( DS_Ptr_Ptr, File_Output, file_input, 0); + +// fprintf( File_Output, "\n"); +// fprintf( File_Output, "Batch_Run: Ending execution (%s)...\n", Arg1); + LG_LOG_INFO_1( "Batch_Run: Ending execution (%s)...", Arg1); + + fclose( file_input); + } + + break; + } + + default: + { + fprintf( File_Output, "\nUndefined command (%d) !\n", Choice); + } + } +} + + + + + +/*----------------------------------------------------------------------------*/ +/* Batch_Run */ +/*----------------------------------------------------------------------------*/ + +void Batch_Run( NDT_Root **DS_Ptr_Ptr, FILE *File_Output, FILE *File_Input, short Interactive_Flag) +{ + int choice; + char *arg1, *arg2, *arg3; + + + do + { + if( Interactive_Flag) + { + Menu_Print( File_Output, *DS_Ptr_Ptr); + } + + Command_Get( &choice, &arg1, &arg2, &arg3, File_Output, File_Input, Interactive_Flag); + + if( ( choice != QUIT) && ( choice != -1)) + { + Command_Exec( DS_Ptr_Ptr, File_Output, choice, arg1, arg2, arg3, File_Input); + } + + if( arg1 != NULL) free( arg1); + if( arg2 != NULL) free( arg2); + if( arg3 != NULL) free( arg3); + } + while( choice != QUIT); } @@ -581,19 +1767,11 @@ int Menu_Print( NDT_Root *Root ) int main( int argc, char **argv) { - DST_Status status; - LGT_Status lg_status; - int rc; - NDT_Root *Root_Ptr = NULL; - NDT_Index_Type index_type = ( NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO); - char *tmp; - int n, m, i, j; - int choice, nb_removed, locked; - int Nb_Detected, Nb_Corrected; - T_Module *Module, Ref_Module; - NDT_Node *Node; + int rc = 0; + LGT_Status lg_status; + NDT_Root *ds_ptr = NULL; + - if( ( lg_status = LG_Library_Open( LGD_LOG_WRITER_DEFAULT, true)) != LGS_OK) { fprintf( stderr, "Can't open LibLog library: (%d)\n", lg_status); @@ -603,387 +1781,48 @@ int main( int argc, char **argv) LG_LOG_INFO_0( "Start DSBench"); - if( argc > 1 && !strcmp (argv[1], "-h")) + /* Init Random numbers... */ + t_start( t_exec); + t_stop( t_exec); + srand( seed_get( t_exec)); + + + /* Args Parsing */ + + if( argc >= 2) { - fprintf( stdout, "Usage : %s [-h] [instance [context]]\n", argv[0]); - rc = 0; - } - else - { - if( DS_Library_Open( 0, NULL, DSD_DEBUG_ALL) != DSS_OK) + if( !strcmp( argv[1], "--help")) { - LG_LOG_ERROR_0( "Can't open DataStr library"); - rc = -1; + fprintf( stderr, USAGE, argv[0]); + rc = 1; } else { - choice = Menu_Print( Root_Ptr); - - while (choice != QUIT) + if( !strcmp( argv[1], "--batch_run")) { - switch (choice) - { - case CREATE_STRUCT: - { - fprintf( stdout, "\nNom de la structure à créer ? "); - fgets( DataStruct_Name, 100, stdin); - - if( strlen( DataStruct_Name) < 2) - { - fprintf( stdout, "Bad name!\n"); - } - else - { - DataStruct_Name[ strlen( DataStruct_Name) - 1] = 0; - if( ( status = DS_DataStruct_Open( &Root_Ptr, DataStruct_Name, 1, &index_type, "Module_Manager", 0, DSD_CREATE, TRUE)) != DSS_OK) - { - LG_LOG_ERROR_1( "Can't create data structure: (%d)", status); - } - else - { - LG_LOG_INFO_1( "Data structure: [%s] created", DataStruct_Name); - } - } + /* Batch Mode */ - break; - } - - case DELETE_STRUCT: - { - if( ( status = DS_DataStruct_Close( Root_Ptr, DSD_DESTROY)) != DSS_OK) - { - LG_LOG_ERROR_2( "Can't delete data structure: [%s], status: (%d)", DataStruct_Name, status); - } - else - { - LG_LOG_INFO_1( "Data structure: [%s] deleted", DataStruct_Name); - - Root_Ptr = NULL; - } - - break; - } - - case OPEN_STRUCT: - { - fprintf (stdout, "\nNom de la structure à ouvrir ? "); - fgets( DataStruct_Name, 100, stdin); - - if( strlen( DataStruct_Name) < 2) - { - fprintf( stdout, "Bad name!\n"); - } - else - { - DataStruct_Name[ strlen( DataStruct_Name) - 1] = 0; - if( ( status = DS_DataStruct_Open( &Root_Ptr, DataStruct_Name, 1, &index_type, "Module_Manager", 0, DSD_OPEN, TRUE)) != DSS_OK) - { - LG_LOG_ERROR_1( "Can't open data structure: (%d)", status); - } - else - { - LG_LOG_INFO_1( "Data structure: [%s] opened", DataStruct_Name); - } - } - - break; - } - - case CLOSE_STRUCT: - { - if( ( status = DS_DataStruct_Close( Root_Ptr, DSD_CLOSE) != DSS_OK)) - { - LG_LOG_ERROR_1( "Can't close data structure: (%d)", status); - } - else - { - LG_LOG_INFO_1( "Data structure: [%s] Closed", DataStruct_Name); - Root_Ptr = NULL; - } - - break; - } -/* - case FIND_VALUE: - { - fprintf (stdout, "\nPlage de recherche (?->?) : "); - gets (buf); - tmp = strstr (buf, "->"); - if (tmp != NULL) - { - * tmp = '\0'; - n = atoi (buf); - tmp++; - tmp++; - m = atoi (tmp); - if (m < n) - { - printf ("\nEntrées non valides\n"); - break; - } - } - else - { - printf ("\nEntrées non valides\n"); - break; - } - - DS_DataStruct_Lock (Root, DSD_READ, &Locked); - - i = n; - j = m + 1; - t_start (t_exec); - while (i < j) - { - Module->Id = n + (random () % m); - DS_Node_Find (Root, &Node, Module, NULL); - i++; - } - t_stop (t_exec); - - DS_DataStruct_Unlock (Root); - - fprintf (stdout, "\n%d valeur(s) recherchée(s) en %.4f sec (%.2f select/sec)\n", \ - m - n + 1, t_exec.sec, (m - n + 1) / t_exec.sec); - break; - } -*/ - case ADD_VALUE: - { - fprintf (stdout, "\nPlage des valeurs à ajouter (?-?) : "); - fgets( buf, 100, stdin); - tmp = strstr( buf, "-"); - - if( tmp != NULL) - { - *tmp = '\0'; - n = atoi( buf); - tmp++; - m = atoi( tmp); - - if( m < n) - { - printf ("\nEntrées non valides\n"); - break; - } - } - else - { - printf( "\nEntrées non valides\n"); - break; - } - - DS_DataStruct_Lock( Root_Ptr, DSD_WRITE, &locked); - - fprintf (stdout, "\nOrdre d'ajout (croissant=0 décroissant=1) ? "); - fgets( buf, 100, stdin); - choice = atoi (buf); - - if( choice == 0) - { - i = n; - j = m + 1; - t_start (t_exec); - - while( i < j) - { - if( DS_Value_Alloc( (void **)&Module, Root_Ptr, i, "x") == NDS_OK) DS_Value_Add( Root_Ptr, Module); - i++; - } - - t_stop( t_exec); - } - else - { - i = m; - j = n - 1; - t_start( t_exec); - - while( i > j) - { - if( DS_Value_Alloc( (void **)&Module, Root_Ptr, i, "x") == NDS_OK) DS_Value_Add( Root_Ptr, Module); - i--; - } - - t_stop (t_exec); - } - - DS_DataStruct_Unlock( Root_Ptr); - - fprintf( stdout, "\n%d valeur(s) ajoutée(s) en %.4f sec (%.2f ajouts/sec)\n", m - n + 1, \ - t_exec.sec, (m - n + 1) / t_exec.sec); - break; - } -/* - case REMOVE_VALUE: - { - Nb_Removed = 0; - fprintf (stdout, "\nPlage des valeurs à supprimer (?->?) : "); - gets (buf); - tmp = strstr (buf, "->"); - if (tmp != NULL) - { - * tmp = '\0'; - n = atoi (buf); - tmp++; - tmp++; - m = atoi (tmp); - if (m < n) - { - printf ("\nEntrées non valides\n"); - break; - } - } - else - { - printf ("\nEntrées non valides\n"); - break; - } - - DS_DataStruct_Lock (Root, DSD_WRITE, &Locked); - - fprintf (stdout, "\nOrdre de suppression (croissant=0 décroissant=1) ? "); - gets (buf); - choice = atoi (buf); - if (choice == 0) - { - i = n; - j = m + 1; - t_start (t_exec); - while (i < j) - { - Ref_Module.Id = i; - if (DS_Value_Remove (Root, &Ref_Module, (void **)&Module) == NDS_OK) - { - DS_Value_Free (Root, Module); - Nb_Removed++; - } - i++; - } - t_stop (t_exec); - } - else - { - i = m; - j = n - 1; - t_start (t_exec); - while (i > j) - { - Ref_Module.Id = i; - if (DS_Value_Remove (Root, &Ref_Module, (void **)&Module) == NDS_OK) - { - DS_Value_Free (Root, Module); - Nb_Removed++; - } - i--; - } - t_stop (t_exec); - } - - DS_DataStruct_Unlock (Root); - - fprintf (stdout, "\n%d valeur(s) supprimée(s) en %.4f sec (%.2f suppressions/sec)\n",\ - Nb_Removed, t_exec.sec, (m - n + 1) / t_exec.sec); - break; - } - - case CHG_LIST_TYPE: - { - fprintf (stdout, "\nType de liste (FIFO=0 ; FILO=1 ; triée=2) ? "); - gets (buf); - choice = atoi (buf); - DS_DataStruct_Lock (Root, DSD_WRITE, &Locked); - switch (choice) - { - case 0: - Root->Type = NDD_DS_LIST | NDD_MN_FIFO; - break; - case 1: - Root->Type = NDD_DS_LIST | NDD_MN_FILO; - break; - case 2: - Root->Type = NDD_DS_LIST | NDD_MN_ORDERED; - break; - default: - printf ("\nChoix non valide\n"); - break; - } - DS_DataStruct_Unlock (Root); - break; - } - - case REORG: - { - t_start (t_exec); - DS_DataStruct_Lock (Root, DSD_WRITE, &Locked); - DS_DataStruct_Reorg (Root); - DS_DataStruct_Unlock (Root); - t_stop (t_exec); - fprintf (stdout, "\nRéorganisation de la structure en %.4f sec\n", t_exec.sec); - break; - } - - case CONVERT_TO_LIST: - { - t_start (t_exec); - DS_DataStruct_Lock (Root, DSD_WRITE, &Locked); - DS_DataStruct_Convert (Root, NDD_DS_LIST | NDD_MN_ORDERED); - DS_DataStruct_Unlock (Root); - t_stop (t_exec); - fprintf (stdout, "\nConversion arbre vers liste en %.4f sec\n", t_exec.sec); - break; - } - - case CONVERT_TO_TREE: - { - t_start (t_exec); - DS_DataStruct_Lock (Root, DSD_WRITE, &Locked); - DS_DataStruct_Convert (Root, NDD_DS_TREE | NDD_MN_AUTO_EQU); - DS_DataStruct_Unlock (Root); - t_stop (t_exec); - fprintf (stdout, "\nConversion liste vers arbre en %.4f sec\n", t_exec.sec); - break; - } - -*/ - case INFO: - { -// DS_DataStruct_Lock (Root, DSD_READ, &Locked); - DS_DataStruct_Info_Print( stdout, Root_Ptr); -// DS_DataStruct_Unlock (Root); - break; - } - - case SHOW: - { - DS_DataStruct_Lock( Root_Ptr, DSD_READ, &locked); - DS_DataStruct_Value_Print( stdout, Root_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0); - DS_DataStruct_Unlock( Root_Ptr); - break; - } -/* - case CHECK: - { - Nb_Corrected = Nb_Detected = 0; - ND_DataStruct_Check (Root, &Nb_Detected, &Nb_Corrected, stderr); - break; - } -*/ - default: - { - fprintf (stdout, "\nChoix %d non défini\n", choice); - } - } - choice = Menu_Print( Root_Ptr); - } - - DS_Library_Close(); + Command_Exec( &ds_ptr, stdout, BATCH_RUN, argv[2], NULL, NULL, stdin); + rc = 0; - rc = 0; + } + else + { + fprintf( stderr, USAGE, argv[0]); + rc = -1; + } } } + else + { + /* Interactive Mode */ + + Batch_Run( &ds_ptr, stdout, stdin, 1); + rc = 0; + } - LG_LOG_INFO_0( "End DSBench"); + + LG_LOG_INFO_0( "End NDBench"); if( ( lg_status = LG_Library_Close( true)) != LGS_OK) { @@ -993,5 +1832,3 @@ int main( int argc, char **argv) return( rc); } - -