libdatastr/util/dsbench.c
Arnaud G. GIBERT 618e86de1b - Add DS_DataStruct_Value_Find(), DS_Index_Reorg(),
- DSBech: Implement DS_Value_Remove, DS_Value_Find, Index_Close, Index_Reorg, Index_List_To_Tree & Index_Tree_To_List commands.
2024-05-04 18:43:08 +02:00

1859 lines
59 KiB
C

/*----------------------------------------------------------------------------*/
/* dsbench.c */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* This file is part of LibDataStr. */
/* */
/* LibDataStr is free software: you can redistribute it and/or modify it */
/* under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* LibDataStr is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with LibDataStr. If not, see <https://www.gnu.org/licenses/>. */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* Includes */
/*----------------------------------------------------------------------------*/
#define DS_MODE 2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <sys/time.h>
#include <log.h>
#include <node.h>
#include <datastr.h>
/*----------------------------------------------------------------------------*/
/* Defines */
/*----------------------------------------------------------------------------*/
#define LGD_MODULE_NAME "dsb"
#define USAGE "Usage : %s [ --help | --batch_run <batch_file_name>]\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
#define CLOSE_STRUCT 3
#define DELETE_STRUCT 4
#define ADD_VALUE 5
#define REMOVE_VALUE 6
#define FIND_VALUE 7
#define CHG_LIST_TYPE 8
#define CONVERT_TO_TREE 9
#define CONVERT_TO_LIST 10
#define REORG 11
#define INFO 12
#define SHOW 13
#define CHECK 14
#define BATCH_RUN 27
*/
/*
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)
/*----------------------------------------------------------------------------*/
/* Types */
/*----------------------------------------------------------------------------*/
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];
/* Mesure des temps d'exécution */
typedef struct cpt
{
double sec;
struct timeval start;
struct timeval stop;
} cpt;
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 T_Module
{
int Id;
char Nom[ DSD_NAME_SIZE];
} 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 *, DST_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( DST_Root **, FILE *, int, char *, char *, char *, FILE *);
void Batch_Run( DST_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)}
};
/*---------------------------------------------------------------------------------*/
/* Module_Manager */
/*---------------------------------------------------------------------------------*/
NDT_Status Module_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Command, va_list *Args_Ptr)
{
NDT_Command_Name Command_Name;
// LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Manager command: (%d) called", Command);
switch( Command)
{
case NDD_CMD_MANAGER_VERSION:
{
ND_VA_ARG_GET( Version_Name_Ptr, *Args_Ptr, NDT_Version_Name *);
Command_Name = "NDD_CMD_MANAGER_VERSION";
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name);
*Version_Name_Ptr = "Module Manager - DSBench";
return( NDS_OK);
}
case NDD_CMD_INDEX_GET:
{
/*
ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *);
ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *);
ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command);
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
*/
ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *);
ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *);
ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command);
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
Command_Name = "NDD_CMD_INDEX_GET";
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name);
switch(Cmd)
{
/*
case NDT_CMD_SOME_USER_CMD:
{
*Reply_Index_Id_Ptr = 0;
*Reply_Command_Ptr = NDD_CMD_SOME_OTHER_CMD;
break;
}
...
*/
default:
{
*Reply_Index_Id_Ptr = Index_Id;
*Reply_Command_Ptr = Cmd;
break;
}
}
return( NDS_OK);
}
case NDD_CMD_VALUE_ALLOC:
{
/*
ND_VA_ARG_GET( Value_Ptr_Ptr, *Args_Ptr, void **);
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
ND_VA_ARG_GET( user_data, user_args, user_type);
ND_VA_ARG_GET( ..., user_args, ...);
ND_VA_LIST_CLOSE( user_args);
*/
ND_VA_ARG_GET( Module_Ptr_Ptr, *Args_Ptr, T_Module **);
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
ND_VA_ARG_GET( Id, user_args, int);
ND_VA_ARG_GET( Nom, user_args, char *);
ND_VA_LIST_CLOSE( user_args);
Command_Name = "NDD_CMD_VALUE_ALLOC";
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name);
if( DS_Alloc( (void **)Module_Ptr_Ptr, Root_Ptr, sizeof( T_Module)) != DSS_OK)
{
LG_LOG_ERROR_0( "Allocation error");
return( DSS_KO);
}
else
{
( *Module_Ptr_Ptr)->Id = Id;
strncpy( ( *Module_Ptr_Ptr)->Nom, Nom, DSD_NAME_LEN);
( *Module_Ptr_Ptr)->Nom[ DSD_NAME_LEN] = '\0';
return( DSS_OK);
}
}
case NDD_CMD_VALUE_FREE:
{
/*
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
ND_VA_ARG_GET( user_data, user_args, user_type);
ND_VA_ARG_GET( ..., user_args, ...);
ND_VA_LIST_CLOSE( user_args);
*/
ND_VA_ARG_GET( Module_Ptr_Ptr, *Args_Ptr, T_Module **);
Command_Name = "NDD_CMD_VALUE_FREE";
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name);
return( DS_Free( Root_Ptr, Module_Ptr_Ptr));
}
case NDD_CMD_VALUE_COMP:
{
/*
ND_VA_ARG_GET( Value1_Ptr, *Args_Ptr, void *);
ND_VA_ARG_GET( Value2_Ptr, *Args_Ptr, void *);
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
ND_VA_ARG_GET( user_data, user_args, user_type);
ND_VA_ARG_GET( ..., user_args, ...);
ND_VA_LIST_CLOSE( user_args);
*/
ND_VA_ARG_GET( Value1_Ptr, *Args_Ptr, T_Module *);
ND_VA_ARG_GET( Value2_Ptr, *Args_Ptr, T_Module *);
Command_Name = "NDD_CMD_VALUE_COMP";
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name);
switch( Index_Id)
{
case 0:
{
if( Value1_Ptr->Id < Value2_Ptr->Id)
{
return( NDS_LOWER);
}
else
{
if( Value1_Ptr->Id > Value2_Ptr->Id)
{
return( NDS_GREATER);
}
else
{
return( NDS_EQUAL);
}
}
}
default:
{
LG_LOG_ERROR_1( "Unknown comp index: (%d)", Index_Id);
return( NDS_KO);
}
}
return( NDS_OK);
}
case NDD_CMD_VALUE_ADD:
{
/*
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
ND_VA_ARG_GET( user_data, user_args, user_type);
ND_VA_ARG_GET( ..., user_args, ...);
ND_VA_LIST_CLOSE( user_args);
*/
Command_Name = "NDD_CMD_VALUE_ADD";
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name);
/*
return( NDS_OK);
*/
}
case NDD_CMD_VALUE_REMOVE:
{
/*
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
ND_VA_ARG_GET( user_data, user_args, user_type);
ND_VA_ARG_GET( ..., user_args, ...);
ND_VA_LIST_CLOSE( user_args);
*/
Command_Name = "NDD_CMD_VALUE_REMOVE";
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name);
return( NDS_OK);
}
case NDD_CMD_VALUE_PRINT:
{
/*
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
ND_VA_LIST_OPEN( lib_args, *Args_Ptr);
ND_VA_ARG_GET( Out, lib_args, FILE *);
ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode);
ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth);
ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset);
ND_VA_LIST_OPEN( user_args, lib_args);
ND_VA_ARG_GET( user_data, user_args, user_type);
ND_VA_ARG_GET( ..., user_args, ...);
ND_VA_LIST_CLOSE( user_args);
ND_VA_LIST_CLOSE( lib_args);
void *Value_Ptr = Node_Ptr->Value;
*/
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
ND_VA_LIST_OPEN( lib_args, *Args_Ptr);
ND_VA_ARG_GET( Out, lib_args, FILE *);
ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode);
ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth);
ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset);
ND_VA_LIST_CLOSE( lib_args);
T_Module *Module_Ptr = (T_Module *)Node_Ptr->Value;
Command_Name = "NDD_CMD_VALUE_PRINT";
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name);
LG_LOG_INFO_2( "Id Module: (%d) Nom Module: [%s]", Module_Ptr->Id, Module_Ptr->Nom);
return( NDS_OK);
}
case NDD_CMD_INFO_PRINT:
{
/*
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
ND_VA_LIST_OPEN( lib_args, *Args_Ptr);
ND_VA_ARG_GET( Out, lib_args, FILE *);
ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode);
ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth);
ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset);
ND_VA_LIST_OPEN( user_args, lib_args);
ND_VA_ARG_GET( user_data, user_args, user_type);
ND_VA_ARG_GET( ..., user_args, ...);
ND_VA_LIST_CLOSE( user_args);
ND_VA_LIST_CLOSE( lib_args);
*/
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
ND_VA_LIST_OPEN( lib_args, *Args_Ptr);
ND_VA_ARG_GET( Out, lib_args, FILE *);
ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode);
ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth);
ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset);
ND_VA_LIST_CLOSE( lib_args);
char *Root_Type;
// DST_RootDesc *RootDesc;
Command_Name = "NDD_CMD_INFO_PRINT";
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name);
/*
switch( (int)(Root_Ptr->Type & NDD_DS_MSK))
{
case NDD_DS_LIST:
{
switch ((int)(Root_Ptr->Type & NDD_MN_MSK))
{
case NDD_MN_ORDERED: Root_Type = strdup ("liste triée"); break;
case NDD_MN_FILO: Root_Type = strdup ("liste FILO"); break;
case NDD_MN_FIFO: Root_Type = strdup ("liste FIFO"); break;
default: Root_Type = strdup ("inconnu"); break;
}
break;
}
case NDD_DS_TREE :
{
switch( (int)(Root_Ptr->Type & NDD_MN_MSK))
{
case NDD_MN_AUTO_EQU: Root_Type = strdup ("arbre auto-équilibré"); break;
default: Root_Type = strdup ("arbre non auto-équilibré"); break;
}
break;
}
default: Root_Type = strdup ("inconnu"); break;
}
RootDesc = (DST_RootDesc *)(Root->User);
fprintf( Out, \
"\nStructure de type %s :\n\t- Nom = %s\n\t- Manager = %s\n\t- Nombre de modules = %ld\n", \
Root_Type, RootDesc->Heap_Name, RootDesc->Manager_FileName, Root_Ptr->Node_Number);
if( ( Root->Type & NDD_DS_MSK) == NDD_DS_TREE)
fprintf( Out, "\t- Profondeur maxi = %ld\n\t- Profondeur mini = %ld\n\t- Différence maximale autorisée = %ld\n\t- Nombre d'équilibrages = %ld\n", \
Root_Ptr->Max_Depth, Root_Ptr->Min_Depth, Root_Ptr->Max_Dif, Root_Ptr->Nb_Equ);
if( Root_Type) free( Root_Type);
*/
return( NDS_OK);
}
case NDD_CMD_USER_TRAVERSE:
{
/*
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
ND_VA_ARG_GET( user_data, user_args, user_type);
ND_VA_ARG_GET( ..., user_args, ...);
ND_VA_LIST_CLOSE( user_args);
void *Value_Ptr = Node_Ptr->Value;
*/
Command_Name = "NDD_CMD_USER_TRAVERSE";
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name);
/*
return( NDS_OK);
*/
}
default:
{
LG_LOG_ERROR_1( "Manager called with an undefined command: (%d)", Command);
return( NDS_ERRAPI);
}
}
LG_LOG_ERROR_2( "Manager internal error with command: (%d) name: [%s]", Command, Command_Name);
return( NDS_OK);
}
/*----------------------------------------------------------------------------*/
/* Menu_Print */
/*----------------------------------------------------------------------------*/
void Menu_Print( FILE *File_Output, DST_Root *DS_Ptr)
{
short i;
char headc;
fprintf( File_Output, "\n-----------------------------------------------------------------------\nMenu :\n");
for( i = 0; i < COMMAND_NB; i++)
{
if( ( DS_Ptr && ( Command_Tab[i].DS_State & DS_STATE_OPENED) && ( DS_Ptr->ND_Root.Index_Tab[0].Type & Command_Tab[i].Index_Type))
|| ( !DS_Ptr && ( Command_Tab[i].DS_State & DS_STATE_CLOSED)))
{
headc = '-';
}
else
{
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);
}
}
/*----------------------------------------------------------------------------*/
/* Command_Get */
/*----------------------------------------------------------------------------*/
void Command_Get( int *choice, char **Arg1, char **Arg2, char **Arg3, FILE *File_Output, FILE *File_Input, short Interactive_Flag)
{
char buf[100];
char *tmp_arg1, *tmp_arg2, *tmp_arg3;
do
{
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);
}
*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( DST_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, inc, 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] opened", 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, status: (%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);
if( ( status = DS_DataStruct_Flush( *DS_Ptr_Ptr)) != DSS_OK)
{
LG_LOG_ERROR_1( "Can't flush data structure, status: (%d)", status);
}
else
{
LG_LOG_INFO_0( "Data structure flushed");
}
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);
DS_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);
DS_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, Arg2, File_Input, Choice, "Value");
if( low != -1)
{
if( Arg3 == NULL)
{
DBD_ARG_READ( Arg3, local_arg3, "DS_Value_Add: Add order ( 0:croissant | 1:decroissant): ");
}
order = atoi( Arg3);
LG_LOG_INFO_3( "DS_Value_Add: Adding from: (%d) to: (%d) order: (%d)...", low, high, order);
if( order == 0)
{
i = low;
j = high + 1;
inc = 1;
}
else
{
i = high;
j = low - 1;
inc = -1;
}
t_start( t_exec);
while( i != j)
{
char tmp_name[ DSD_NAME_SIZE];
snprintf( tmp_name, DSD_NAME_LEN, "Element #: (%ld)", i);
tmp_name[ DSD_NAME_LEN] = '\0';
if( DS_Value_Alloc( (void **)&module_ptr, *DS_Ptr_Ptr, i, tmp_name) != DSS_OK)
{
LG_LOG_ERROR_0( "DS_Value_Add: Allocation Failled !");
break;
}
else
{
DS_DataStruct_Value_Add( *DS_Ptr_Ptr, module_ptr);
}
i += inc;
}
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, Arg2, File_Input, Choice, "Value");
if( low != -1)
{
if( Arg3 == NULL)
{
DBD_ARG_READ( Arg3, local_arg3, "Remove ( 0:croissant | 1:decroissant): ");
}
order = atoi( Arg3);
if( order == 0)
{
i = low;
j = high + 1;
inc = 1;
}
else
{
i = high;
j = low - 1;
inc = -1;
}
t_start( t_exec);
while( i != j)
{
ref_module.Id = i;
if( ( DS_DataStruct_Value_Find( (void **)&module_ptr, *DS_Ptr_Ptr, &ref_module) == DSS_OK) && ( module_ptr != NULL))
{
if( DS_DataStruct_Value_Remove( *DS_Ptr_Ptr, (void *)module_ptr) == NDS_OK)
{
nb_removed++;
if( DS_Value_Free( *DS_Ptr_Ptr, module_ptr) != DSS_OK)
{
LG_LOG_ERROR_0( "DS_Value_Remove: Deallocation Failled !");
break;
}
}
}
i += inc;
}
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);
if( ( status = DS_DataStruct_Value_Print( File_Output, *DS_Ptr_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 99, 0)) != DSS_OK)
{
LG_LOG_ERROR_1( "Unable to print data structure values, status: (%d)", status);
}
break;
}
case DS_VALUE_FIND:
{
Command_Index_Range_Get( File_Output, &low, &high, Arg1, Arg2, File_Input, Choice, "Search");
if( low != -1)
{
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));
if( DS_DataStruct_Value_Find( (void *)&module_ptr, *DS_Ptr_Ptr, &ref_module) != DSS_OK)
{
LG_LOG_ERROR_0( "DS_Value_Find: Search Failled !");
break;
}
else
{
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++)
{
if( ( status = DS_Index_Open( *DS_Ptr_Ptr, (NDT_Index_Id)i, DBD_IDX_TYPE_FIFO)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable to open index: (%d), status: (%d)", i, status);
break;
}
}
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, Arg2, File_Input, Choice, "Index");
if( low != -1)
{
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++)
{
if( ( status = DS_Index_Open( *DS_Ptr_Ptr, (NDT_Index_Id)i, DBD_IDX_TYPE_BALANCED_TREE)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable to open index: (%d), status: (%d)", i, status);
break;
}
}
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, Arg2, File_Input, Choice, "Index");
if( low != -1)
{
LG_LOG_INFO_2( "Index_Close: Closing index from: (%d) to: (%d)...", low, high);
t_start( t_exec);
for( i = high; i >= low; i--)
{
if( ( status = DS_Index_Close( *DS_Ptr_Ptr, (NDT_Index_Id)i)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable to close index: (%d), status: (%d)", i, status);
break;
}
}
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, Arg2, File_Input, Choice, "Index");
if( low != -1)
{
t_start( t_exec);
for( i = low; i <= high; i++)
{
LG_LOG_INFO_1( "Index_Reorg: Reorganizing index (%d)...", i);
if( ( status = DS_Index_Reorg( *DS_Ptr_Ptr, (NDT_Index_Id)i)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable to reorganise index: (%d), status: (%d)", i, status);
break;
}
}
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, Arg2, File_Input, Choice, "Index");
if( low != -1)
{
t_start( t_exec);
for( i = low; i <= high; i++)
{
LG_LOG_INFO_1( "Index_List_To_Tree: Converting Index (%d)...", i);
if( ( status = DS_Index_Convert( *DS_Ptr_Ptr, (NDT_Index_Id)i, DBD_IDX_TYPE_BALANCED_TREE)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable to convert index: (%d), status: (%d)", i, status);
break;
}
}
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, Arg2, File_Input, Choice, "Index");
if( low != -1)
{
t_start( t_exec);
for( i = low; i <= high; i++)
{
LG_LOG_INFO_1( "Index_Tree_To_List: Converting Index (%d)...", i);
if( ( status = DS_Index_Convert( *DS_Ptr_Ptr, (NDT_Index_Id)i, DBD_IDX_TYPE_SORTED_LIST)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable to convert index: (%d), status: (%d)", i, status);
break;
}
}
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( DST_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);
}
/*---------------------------------------------------------------------------------*/
/* main */
/*---------------------------------------------------------------------------------*/
int main( int argc, char **argv)
{
int rc = 0;
LGT_Status lg_status;
DST_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);
return( -1);
}
LG_LOG_INFO_0( "Start DSBench");
/* Init Random numbers... */
t_start( t_exec);
t_stop( t_exec);
srand( seed_get( t_exec));
/* Args Parsing */
if( argc >= 2)
{
if( !strcmp( argv[1], "--help"))
{
fprintf( stderr, USAGE, argv[0]);
rc = 1;
}
else
{
if( !strcmp( argv[1], "--batch_run"))
{
/* Batch Mode */
Command_Exec( &ds_ptr, stdout, BATCH_RUN, argv[2], NULL, NULL, stdin);
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 NDBench");
if( ( lg_status = LG_Library_Close( true)) != LGS_OK)
{
fprintf( stderr, "Can't close LibLog library: (%d)\n", lg_status);
rc = -1;
}
return( rc);
}