From 033656896c39811033a3cd4f670346f71a2ea52c Mon Sep 17 00:00:00 2001 From: agibert Date: Mon, 26 Nov 2001 10:17:44 +0000 Subject: [PATCH] Merge win32 branche (1.1.2.19) with main trunc ! --- util/ndbench.c | 1694 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 1311 insertions(+), 383 deletions(-) diff --git a/util/ndbench.c b/util/ndbench.c index 70ae635..a0bb356 100644 --- a/util/ndbench.c +++ b/util/ndbench.c @@ -1,469 +1,1397 @@ +/*---------------------------------------------------------------------------------*/ +/* $RCSfile: ndbench.c,v $ */ +/*---------------------------------------------------------------------------------*/ +/* $Revision: 1.2 $ */ +/* $Name: $ */ +/* $Date: 2001/11/26 10:17:44 $ */ +/* $Author: agibert $ */ +/*---------------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------------*/ +/* Includes */ +/*---------------------------------------------------------------------------------*/ #include #include #include -#include #include +#include + + + +#ifdef _WIN32 + +# include + +#else + +# include + +#endif + +#ifdef _LIBVER_SUPPORT + +# include + +#endif + + + + + +/*---------------------------------------------------------------------------------*/ +/* Defines */ +/*---------------------------------------------------------------------------------*/ + +#ifdef _LIBVER +VER_INFO_EXPORT( ndbench, "$Revision: 1.2 $", "$Name: $", __FILE__, "$Author: agibert $") +#endif #define ND_MODE 1 #include -VER_INFO_EXPORT (ndbench, "$Revision: 1.1 $", "$Name: $", __FILE__, "$Author: smas $") -#define USAGE "Usage : %s [ --help | --version [-v] ]\n" -#define QUIT 0 -#define ADD_VALUE 1 -#define REMOVE_VALUE 2 -#define FIND_VALUE 3 -#define CHG_LIST_TYPE 4 -#define CONVERT_TO_TREE 5 -#define CONVERT_TO_LIST 6 -#define REORG 7 -#define INFO 8 -#define SHOW 9 -#define CHECK 10 +#define USAGE "Usage : %s [ --help | --version [-v] | --batch_run ]\n" + +#define QUIT 0 +#define DS_OPEN 1 +#define DS_CLOSE 2 +#define DS_FLUSH 3 +#define DS_CHECK 4 +#define DS_REORG 5 +#define DS_INFO_PRINT 6 +#define DS_VALUE_ADD 7 +#define DS_VALUE_REMOVE 8 +#define DS_VALUE_PRINT 9 +#define DS_VALUE_FIND 10 +#define INDEX_LIST_OPEN 11 +#define INDEX_TREE_OPEN 12 +#define INDEX_CLOSE 13 +#define INDEX_FLUSH 14 +#define INDEX_CHECK 15 +#define INDEX_LIST_SUBTYPE_SET 16 +#define INDEX_LIST_TO_TREE 17 +#define INDEX_TREE_SUBTYPE_SET 18 +#define INDEX_TREE_TO_LIST 19 +#define INDEX_REORG 20 +#define INDEX_INFO_PRINT 21 +#define INDEX_VALUE_PRINT 22 +#define BATCH_RUN 23 + +#define COMMAND_NB 24 + +#define INDEX_NB 32 + + + +#define DS_STATE_UNKNOWN 0 +#define DS_STATE_OPENED 1 +#define DS_STATE_CLOSED 2 + + + +#define ARG_SIZE ( 32 + 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]; + -char menu [1000]; -char buf [100]; -NDT_Root * Root; -long int random (void); -NDT_Status Module_Manager (va_list); -void init_menu (void); -int print_menu (void); -extern char * strdup (const char *); /* Mesure des temps d'exécution */ -typedef struct { - double sec; - struct timeval start; - struct timeval stop; -} cpt; +#ifdef _WIN32 + +typedef struct +{ + double sec; + struct _timeb start; + struct _timeb stop; +} cpt; + +# define t_start(x) { _ftime( &(x.start));} +# define t_stop(x) { _ftime( &(x.stop)); x.sec = (double)(x.stop.time) - (double)(x.start.time) + ((double)(x.stop.millitm) - (double)(x.start.millitm)) / 1000;} + +#else + +typedef struct +{ + 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;} + +#endif -#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;} cpt t_exec; + + /* Définition des valeurs attachées aux noeuds de la structure */ -typedef struct { - int Id; - char * Nom; +typedef struct +{ + int Id; + char *Nom; } T_Module; -int main (int argc, char ** argv) + + +NDT_Index_Type idx_type_tab[INDEX_NB]; + +NDT_Index_Type idx_type_fifo = NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO; + +NDT_Index_Type idx_type_sorted_list = NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_SORTED; + +NDT_Index_Type idx_type_balanced_tree = NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED; + + + + + +/*---------------------------------------------------------------------------------*/ +/* Prototype */ +/*---------------------------------------------------------------------------------*/ + +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 **, 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 *, FILE *, int, char *); +void Command_Exec( NDT_Root **, FILE *, int, char *, char *, FILE *); +void Batch_Run( NDT_Root **, FILE *, FILE *, short); + + + + + +/*---------------------------------------------------------------------------------*/ +/* Global Variable */ +/*---------------------------------------------------------------------------------*/ + +Command Command_Tab[] = { - char * tmp; - int n, m, i, j, choice, nb_removed, Nb_Detected, Nb_Corrected; - T_Module Ref_Module, * Module; - int Debug = TRUE; + { QUIT, "Quit", "Quit", ( 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)}, + { BATCH_RUN, "Batch_Run", "Run NDBench Bach", ( DS_STATE_OPENED | DS_STATE_CLOSED), ( NDD_INDEX_TYPE_LIST | NDD_INDEX_TYPE_TREE)} +}; - /* Lancement de commande en mode batch */ - if (argc >= 2) - { - if (!strcmp (argv[1], "--help")) + + + +/*---------------------------------------------------------------------------------*/ +/* */ +/*---------------------------------------------------------------------------------*/ + +NDT_Status Module_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Command, va_list Args) +{ + NDT_Command_Name Command_Name; + + + switch( Command) { - fprintf (stderr, USAGE, argv[0]); - return 1; + case NDD_CMD_MANAGER_VERSION: + { + NDT_Version_Name *Version_Name_Ptr = (NDT_Version_Name *)va_arg( Args, NDT_Version_Name *); + + Command_Name = "NDD_CMD_MANAGER_VERSION"; + + *Version_Name_Ptr = "$Revision: 1.2 $ $Name: $ $Date: 2001/11/26 10:17:44 $ $Author: agibert $"; + + return( NDS_OK); + } + + case NDD_CMD_INDEX_GET: + { + /* + NDT_Index_Id *Reply_Index_Id_Ptr = (NDT_Index_Id *)va_arg( Args, NDT_Index_Id *); + NDT_Command *Reply_Command_Ptr = (NDT_Command *)va_arg( Args, NDT_Command *); + NDT_Command Cmd = (NDT_Command)va_arg( Args, NDT_Command); + void *Value_ptr = (void *)va_arg( Args, void *); + */ + NDT_Index_Id *Reply_Index_Id_Ptr = (NDT_Index_Id *)va_arg( Args, NDT_Index_Id *); + NDT_Command *Reply_Command_Ptr = (NDT_Command *)va_arg( Args, NDT_Command *); + NDT_Command Cmd = (NDT_Command)va_arg( Args, NDT_Command); + T_Module **Module_Ptr_Ptr = (T_Module **)va_arg( Args, T_Module **); + + + Command_Name = "NDD_CMD_INDEX_GET"; + + 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: + { + /* + void **Value_Ptr_Ptr = (void **)va_arg( Args, void **); + va_list user_args = (va_list)va_arg( Args, va_list); + user_type user_data = (user_type)va_arg( user_args, user_type); + ... = (...)va_arg( user_args, ...); + */ + T_Module **Module_Ptr_Ptr = (T_Module **)va_arg( Args, T_Module **); + va_list user_args = (va_list)va_arg( Args, va_list); + char *Nom = (char *)va_arg( user_args, char *); + int Id = (int)va_arg( user_args, int); + + + Command_Name = "NDD_CMD_VALUE_ALLOC"; + + if( ( *Module_Ptr_Ptr = (T_Module *)malloc( sizeof(T_Module))) != NULL) + { + (*Module_Ptr_Ptr)->Nom = strdup(Nom); + (*Module_Ptr_Ptr)->Id = Id; + + return( NDS_OK); + } + else + { + return( NDS_KO); + } + + } + + case NDD_CMD_VALUE_FREE: + { + /* + void *Value_Ptr = (void *)va_arg( Args, void *); + va_list user_args = (va_list)va_arg( Args, va_list); + user_type user_data = (user_type)va_arg( user_args, user_type); + ... = (...)va_arg( user_args, ...); + */ + T_Module *Module_Ptr = (T_Module *)va_arg( Args, T_Module *); + + + Command_Name = "NDD_CMD_VALUE_FREE"; + + + free( Module_Ptr->Nom); + free( Module_Ptr); + + return( NDS_OK); + } + + case NDD_CMD_VALUE_COMP: + { + /* + void *Value1_Ptr = (void *)va_arg( Args, void *); + void *Value2_Ptr = (void *)va_arg( Args, void *); + va_list user_args = (va_list)va_arg( Args, va_list); + user_type user_data = (user_type)va_arg( user_args, user_type); + ... = (...)va_arg( user_args, ...); + */ + T_Module *Value1 = (T_Module *)va_arg( Args, T_Module *); + T_Module *Value2 = (T_Module *)va_arg( Args, T_Module *); + + + Command_Name = "NDD_CMD_VALUE_COMP"; + + if( ( Index_Id >= 0) && ( Index_Id < INDEX_NB)) + { + int rc; + + + rc = Value1->Id - Value2->Id; + + if( rc < 0) + { + return(NDS_LOWER); + } + else + { + if( rc > 0) + { + return(NDS_GREATER); + } + else + { + return(NDS_EQUAL); + } + } + } + else + { + printf( "Unknown COMP idx (%d) !\n", Index_Id); + return( NDS_KO); + } + + return( NDS_OK); + } + + case NDD_CMD_VALUE_ADD: + { + /* + void *Value_Ptr = (void *)va_arg( Args, void *); + va_list user_args = (va_list)va_arg( Args, va_list); + user_type user_data = (user_type)va_arg( user_args, user_type); + ... = (...)va_arg( user_args, ...); + */ + + + Command_Name = "NDD_CMD_VALUE_ADD"; + + return( NDS_OK); + } + + case NDD_CMD_VALUE_REMOVE: + { + /* + void *Value_Ptr = (void *)va_arg( Args, void *); + va_list user_args = (va_list)va_arg( Args, va_list); + user_type user_data = (user_type)va_arg( user_args, user_type); + ... = (...)va_arg( user_args, ...); + */ + + + Command_Name = "NDD_CMD_VALUE_REMOVE"; + return( NDS_OK); + } + + case NDD_CMD_VALUE_PRINT: + { + /* + NDT_Node *Next_Node_Ptr = (NDT_Node *)va_arg( Args, NDT_Node *); + va_list lib_args = (va_list)va_arg( Args, va_list); + FILE *Out = (FILE *)va_arg( lib_args, FILE *); + NDT_Recursive_Mode Recursive_Mode = (NDT_Recursive_Mode)va_arg( lib_args, NDT_Recursive_Mode); + NDT_Recursive_Depth Recursive_Depth = (NDT_Recursive_Depth)va_arg( lib_args, NDT_Recursive_Depth); + va_list user_args = (va_list)va_arg( lib_args, va_list); + user_type user_data = (user_type)va_arg( user_args, user_type); + ... = (...)va_arg( user_args, ...); + + void *Value_Ptr = Node_Ptr->Value; + */ + NDT_Node *Next_Node_Ptr = (NDT_Node *)va_arg( Args, NDT_Node *); + va_list lib_args = (va_list)va_arg( Args, va_list); + FILE *Out = (FILE *)va_arg( lib_args, FILE *); + NDT_Recursive_Mode Recursive_Mode = (NDT_Recursive_Mode)va_arg( lib_args, NDT_Recursive_Mode); + NDT_Recursive_Depth Recursive_Depth = (NDT_Recursive_Depth)va_arg( lib_args, NDT_Recursive_Depth); + + T_Module *Module_Ptr = Node_Ptr->Value; + + + Command_Name = "NDD_CMD_VALUE_PRINT"; + + fprintf( Out, "Id=%d\tNom=\"%s\"\n", Module_Ptr->Id, Module_Ptr->Nom); + + return( NDS_OK); + } + + case NDD_CMD_INFO_PRINT: + { + /* + NDT_Node *Next_Node_Ptr = (NDT_Node *)va_arg( Args, NDT_Node *); + va_list lib_args = (va_list)va_arg( Args, va_list); + FILE *Out = (FILE *)va_arg( lib_args, FILE *); + NDT_Recursive_Mode Recursive_Mode = (NDT_Recursive_Mode)va_arg( lib_args, NDT_Recursive_Mode); + NDT_Recursive_Depth Recursive_Depth = (NDT_Recursive_Depth)va_arg( lib_args, NDT_Recursive_Depth); + va_list user_args = (va_list)va_arg( lib_args, va_list); + user_type user_data = (user_type)va_arg( user_args, user_type); + ... = (...)va_arg( user_args, ...); + + void *Value_Ptr = Node_Ptr->Value; + */ + + + Command_Name = "NDD_CMD_INFO_PRINT"; + + return( NDS_OK); + + } + + default: + { + printf( "Module_Manager() called with an undefined command %d\n", Command); + return(NDS_ERRAPI); + + } } - else if (!strcmp (argv[1], "--version")) + + printf( "Module_Manager() called with command %d (%s)\n", Command, Command_Name); + return(NDS_OK); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* */ +/*---------------------------------------------------------------------------------*/ + +void Menu_Print( FILE *File_Output, NDT_Root *DS_Ptr) +{ + short i; + char headc; + + + fprintf( File_Output, "\n-----------------------------------------------------------------------\nMenu :\n"); + + for( i = 0; i < COMMAND_NB; i++) { - if (argc >= 3 && !strcmp (argv[2], "-v")) - return VER_Object_Print (stdout, VERD_VERBOSE); - else - return VER_Object_Print (stdout, VERD_MINIMAL); + 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))) + { + 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); + } +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* */ +/*---------------------------------------------------------------------------------*/ + +void Command_Get( int *choice, char **arg1, char **arg2, FILE *File_Output, FILE *File_Input, short Interactive_Flag) +{ + char buf[100]; + char *tmp_arg1, *tmp_arg2; + + + do + { + if( Interactive_Flag) + { + fprintf( File_Output, "\nChoice ? "); + } + + if( fgets( buf, 99, 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; + } + else + { + if( ( tmp_arg1 = strstr( buf, " ")) != NULL) + { + tmp_arg1++; + + if( ( tmp_arg2 = strstr( tmp_arg1, " ")) != NULL) + { + *tmp_arg2 = '\0'; + tmp_arg2++; + + *arg2 = malloc( ARG_SIZE); + if( *arg2 != NULL) strcpy( *arg2, tmp_arg2); + } + else + { + *arg2 = NULL; + } + + *arg1 = malloc( ARG_SIZE); + if( *arg1 != NULL) strcpy( *arg1, tmp_arg1); + } + else + { + *arg1 = NULL; + *arg2 = NULL; + } + } + } + else + { + *choice = 0; + *arg1 = NULL; + *arg2 = NULL; + } + } + while( *choice == -1); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* */ +/*---------------------------------------------------------------------------------*/ + +void Command_Exec_Begin_Print( FILE *File_Output, int Choice) +{ + fprintf( File_Output, "%s: %s...\n", Command_Tab[Choice].Name, Command_Tab[Choice].FullName); + fflush( File_Output); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* */ +/*---------------------------------------------------------------------------------*/ + +void Command_Exec_End_Print( FILE *File_Output, int Choice, cpt T_Exec, int nb) +{ + if( nb == 1) + { + fprintf( File_Output, "%s: Completed in (%.4f) second !\n", Command_Tab[Choice].Name, T_Exec.sec); + } + else + { + fprintf( File_Output, "%s: Completed in (%.4f) second, (%.2f) per second !\n", Command_Tab[Choice].Name, T_Exec.sec, nb / T_Exec.sec); + } +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* */ +/*---------------------------------------------------------------------------------*/ + +void Command_Index_Range_Get( FILE *File_Output, int *Low, int *High, char *Arg, FILE *File_Input, int Choice, char *Obj_Name) +{ + char buf[100]; + char *tmp; + + + if( Arg == NULL) + { + fprintf( File_Output, "%s: %s range (?-?) : ", Command_Tab[Choice].Name, Obj_Name); + fgets( buf, 99, File_Input); + + Arg = buf; + } + + tmp = strstr( Arg, "-"); + + if( tmp != NULL) + { + *tmp = '\0'; + *Low = atoi( Arg); + tmp++; + *High = atoi( tmp); + + 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; + } } else { - fprintf (stderr, USAGE, argv[0]); - return 0; + fprintf( File_Output, "%s: Invalit range !\n", Command_Tab[Choice].Name); + *Low = *High = -1; } - } +} - /* Lancement du menu intercatif */ - ND_Library_Open (Debug); - printf ("\nCréation d'une structure de type liste FIFO...\n"); - ND_DataStruct_Open (&Root, NDD_DS_LIST | NDD_MN_FIFO, NULL, NULL, NULL, TRUE); - strcpy (Root->Manager, "Module_Manager"); - choice = print_menu (); +/*---------------------------------------------------------------------------------*/ +/* */ +/*---------------------------------------------------------------------------------*/ - while (choice != QUIT) - { - switch (choice) +void Command_Exec( NDT_Root **DS_Ptr_Ptr, FILE *File_Output, int Choice, char *Arg1, char *Arg2, FILE *File_Input) +{ + int low, high, i, j, nb_removed, Nb_Detected, Nb_Corrected; + T_Module Ref_Module, *Module_Ptr; + char buf[100]; + NDT_Index_Type index_subtype; + + + fprintf( File_Output, "\n"); + + switch( Choice) { - case FIND_VALUE: - fprintf (stdout, "\nPlage de recherche (?->?) : "); - gets (buf); - tmp = strstr (buf, "->"); - if (tmp != NULL) + case QUIT: { - *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; } - i = n; - j = m + 1; - t_start (t_exec); - while (i < j) + case DS_OPEN: { - NDT_Node *Node; - Ref_Module.Id = n + (random () % m); - ND_Node_Find (Root, &Node, &Ref_Module, NULL); - i++; - } - t_stop (t_exec); + Command_Exec_Begin_Print( File_Output, Choice); - 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 (?->?) : "); - 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; - } - - fprintf (stdout, "\nOrdre d'ajout (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) - { - if (ND_Value_Alloc (Root, (void **)&Module, "x", i) == NDS_OK) - ND_Value_Add (Root, Module); - i++; - } - t_stop (t_exec); - } - else - { - i = m; - j = n - 1; - t_start (t_exec); - while (i > j) - { - if (ND_Value_Alloc (Root, (void **)&Module, "x", i) == NDS_OK) - ND_Value_Add (Root, Module); - i--; - } - t_stop (t_exec); - } - 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; - } - - 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 (ND_Value_Remove (Root, &Ref_Module, (void **)&Module) == NDS_OK) + for( i = 0; i < INDEX_NB; i++) { - nb_removed++; - ND_Value_Free (Root, Module); + idx_type_tab[i] = NDD_INDEX_STATUS_CLOSED; } - i++; - } - t_stop (t_exec); + + t_start( t_exec); + ND_DataStruct_Open( DS_Ptr_Ptr, INDEX_NB, idx_type_tab, "Module_Manager", Module_Manager, NULL, NULL, NULL, NULL, NDD_TRUE, NULL); + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, 1); + break; } - else + + case DS_CLOSE: { - i = m; - j = n - 1; - t_start (t_exec); - while (i > j) - { - Ref_Module.Id = i; - if (ND_Value_Remove (Root, &Ref_Module, (void **)&Module) == NDS_OK) + Command_Exec_Begin_Print( File_Output, Choice); + + t_start( t_exec); + ND_DataStruct_Close( *DS_Ptr_Ptr); + t_stop( t_exec); + + *DS_Ptr_Ptr = NULL; + + 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, stderr); + 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); + + ND_DataStruct_Info_Print( File_Output, *DS_Ptr_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 99, 0); + + 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, 99 ,stdin); + + Arg2 = buf; + } + + order = atoi( Arg2); + + fprintf( File_Output, "DS_Value_Add: from: (%d) to: (%d) order: (%d)...\n", low, high, order); + fflush( File_Output); + + t_start( t_exec); + + if( order == 0) + { + i = low; + j = high + 1; + + while( i < j) + { + if( ND_Value_Alloc( *DS_Ptr_Ptr, (void **)&Module_Ptr, "x", i) == NDS_OK) + { + ND_DataStruct_Value_Add( *DS_Ptr_Ptr, Module_Ptr); + } + else + { + fprintf( File_Output, "DS_Value_Add: Allocation Failled !\n"); + break; + } + + i++; + } + } + else + { + i = high; + j = low - 1; + + while( i > j) + { + if( ND_Value_Alloc( *DS_Ptr_Ptr, (void **)&Module_Ptr, "x", i) == NDS_OK) + { + ND_DataStruct_Value_Add( *DS_Ptr_Ptr, Module_Ptr); + } + else + { + fprintf( File_Output, "DS_Value_Add: Allocation Failled !\n"); + 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, 99, 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); + + i = low; + j = high + 1; + + t_start( t_exec); + + while( i < j) + { + Ref_Module.Id = low +( rand( ) % ( high - low)); + 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, File_Input, Choice, "Index"); + + if( low != -1) { - nb_removed++; - ND_Value_Free (Root, Module); - } - i--; - } - t_stop (t_exec); - } - fprintf (stdout, "\n%d valeur(s) supprimée(s) en %.4f sec (%.2f suppressions/sec)\n", \ - m - n + 1, t_exec.sec, (m - n + 1) / t_exec.sec ); - break; + fprintf( File_Output, "Index_List_Open: Open a FIFO List from: (%d) to: (%d)...\n", low, high); + fflush( File_Output); - case CHG_LIST_TYPE: - fprintf (stdout, "\nType de liste (FIFO=0 ; FILO=1 ; triée=2) ? "); - gets (buf); - choice = atoi (buf); - switch (choice) + t_start( t_exec); + + for( i = low; i <= high; i++) + { + ND_Index_Open( *DS_Ptr_Ptr, (NDT_Index_Id)i, idx_type_fifo); + } + + t_stop( t_exec); + + Command_Exec_End_Print( File_Output, Choice, t_exec, high - low); + } + + break; + } + + case INDEX_TREE_OPEN: { - case 0: - Root->Type = NDD_DS_LIST | NDD_MN_FIFO; - break; + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Index"); - case 1: - Root->Type = NDD_DS_LIST | NDD_MN_FILO; - break; + if( low != -1) + { - case 2: - Root->Type = NDD_DS_LIST | NDD_MN_ORDERED; - break; + fprintf( File_Output, "Index_Tree_Open: Open a balanced Tree from: (%d) to: (%d)...\n", low, high); + fflush( File_Output); + + 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); + } - default: - printf ("\nChoix non valide\n"); break; } - break; - case REORG: - t_start (t_exec); - ND_DataStruct_Reorg (Root); - t_stop (t_exec); - fprintf (stdout, "\nRéorganisation de la structure en %.4f sec\n", t_exec.sec); - break; + case INDEX_LIST_SUBTYPE_SET: + { + Command_Index_Range_Get( File_Output, &low, &high, Arg1, File_Input, Choice, "Index"); - case CONVERT_TO_LIST: - t_start (t_exec); - ND_DataStruct_Convert (Root, NDD_DS_LIST | NDD_MN_ORDERED); - t_stop (t_exec); - fprintf (stdout, "\nConversion arbre vers liste en %.4f sec\n", t_exec.sec); - break; + if( low != -1) + { + if( Arg2 == NULL) + { + fprintf( File_Output, "Index_List_SubType_Set: List SubType ( 0:FIFO | 1:LIFO | 2:Sorted) ? "); + fgets( buf, 99, File_Input); - case CONVERT_TO_TREE: - t_start (t_exec); - ND_DataStruct_Convert (Root, NDD_DS_TREE | NDD_MN_AUTO_EQU); - t_stop (t_exec); - fprintf (stdout, "\nConversion liste vers arbre en %.4f sec\n", t_exec.sec); - break; + Arg2 = buf; + } - case INFO: - ND_DataStruct_Info_Print (Root, stdout); - break; + Choice = atoi( Arg2); - case SHOW: - ND_DataStruct_Dump (Root, stdout); - break; + switch( Choice) + { + case 0: + { + index_subtype = NDD_INDEX_SUBTYPE_FIFO; + break; + } - case CHECK: - Nb_Corrected = Nb_Detected = 0; - ND_DataStruct_Check (Root, &Nb_Detected, &Nb_Corrected, stderr); - break; + case 1: + { + index_subtype = NDD_INDEX_SUBTYPE_FILO; + break; + } - default: - fprintf (stdout, "\nChoix %d non défini\n", choice); + 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", Choice); + 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)); + + 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: + { + 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, 99, stdin); + + Arg2 = buf; + } + + Choice = atoi( Arg2); + + switch( Choice) + { + 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", Choice); + 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); + + 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); + + 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); + + 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: + { + fprintf( File_Output, "DS_Info_Print:\n"); + fflush( File_Output); + + ND_DataStruct_Info_Print( File_Output, *DS_Ptr_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 99, 0); + + break; + } + + case INDEX_VALUE_PRINT: + { + fprintf( File_Output, "DS_Value_Print:\n"); + fflush( File_Output); + + ND_DataStruct_Value_Print( File_Output, *DS_Ptr_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 99, 0); + 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); + + Nb_Corrected = Nb_Detected = 0; + ND_Index_Check( *DS_Ptr_Ptr, (NDT_Index_Id)i, &Nb_Detected, &Nb_Corrected, stderr); + } + + 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, 99, 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); + } + else + { + fprintf( File_Output, "\n\n--------------------------------------------------------------------------------\n"); + fprintf( File_Output, "Batch_Run: Starting execution (%s)...\n", 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); + } + + break; + } + + default: + { + fprintf( File_Output, "\nUndefined command (%d) !\n", Choice); + } } - - choice = print_menu (); - } - - fprintf (stdout, "\nDestruction de la structure... "); - printf ("%s\n\n", (ND_DataStruct_Close (Root) == NDS_OK ? "OK" : "NOK")); - - ND_Library_Close (); - return 0; } -NDT_Status Module_Manager (va_list args_ptr) + + + + +/*---------------------------------------------------------------------------------*/ +/* */ +/*---------------------------------------------------------------------------------*/ + +void Batch_Run( NDT_Root **DS_Ptr_Ptr, FILE *File_Output, FILE *File_Input, short Interactive_Flag) { - NDT_Command Command = (NDT_Command)va_arg (args_ptr, NDT_Command); + int choice; + char *arg1, *arg2; - if (Command == NDD_CMD_MAKE_VALUE) - { - NDT_Root * Current_Root = va_arg (args_ptr, NDT_Root *); - T_Module ** Module = va_arg (args_ptr, T_Module **); - va_list Args = va_arg (args_ptr, va_list); - char * Nom = va_arg (Args, char *); - int Id = va_arg (Args, int); - *Module = (T_Module *)malloc (sizeof (T_Module)); - (*Module)->Nom = strdup (Nom); - (*Module)->Id = Id; - return NDS_OK; - } - - if (Command == NDD_CMD_PRINT_VALUE) - { - T_Module * Module = (T_Module *)va_arg (args_ptr, void *); - FILE * Out = va_arg (args_ptr, FILE *); - - fprintf (Out, "Id=%d\tNom=\"%s\"", Module->Id, Module->Nom); - - return NDS_OK; - } - - if (Command == NDD_CMD_DELETE_VALUE) - { - NDT_Root * Current_Root = va_arg (args_ptr, NDT_Root *); - T_Module * Module = (T_Module *)va_arg (args_ptr, void *); - - free (Module->Nom); - free (Module); - return NDS_OK; - } - - if (Command == NDD_CMD_PRINT_INFO) - { - NDT_Root * Current_Root = va_arg (args_ptr, NDT_Root *); - FILE * Out = va_arg (args_ptr, FILE *); - char Root_Type[100]; - - switch ((int) (Current_Root->Type & NDD_DS_MSK)) + do { - case NDD_DS_LIST : - - switch ((int) (Current_Root->Type & NDD_MN_MSK)) + if( Interactive_Flag) { - case NDD_MN_ORDERED : strcpy (Root_Type, "liste triée"); break; - case NDD_MN_FILO : strcpy (Root_Type, "liste FILO"); break; - case NDD_MN_FIFO : strcpy (Root_Type, "liste FIFO"); break; - default: strcpy (Root_Type, "inconnu"); break; + Menu_Print( File_Output, *DS_Ptr_Ptr); } - break; - case NDD_DS_TREE : + Command_Get( &choice, &arg1, &arg2, File_Output, File_Input, Interactive_Flag); - switch ((int) (Current_Root->Type & NDD_MN_MSK)) + if( ( choice != QUIT) && ( choice != -1)) { - case NDD_MN_AUTO_EQU : strcpy (Root_Type, "arbre auto-équilibré"); break; - default: strcpy (Root_Type, "arbre non auto-équilibré"); break; + Command_Exec( DS_Ptr_Ptr, File_Output, choice, arg1, arg2, File_Input); } - break; - default: strcpy (Root_Type, "inconnu"); break; + if( arg1 != NULL) free( arg1); + if( arg2 != NULL) free( arg2); + } + while( choice != QUIT); +} + + + + +/*---------------------------------------------------------------------------------*/ +/* */ +/*---------------------------------------------------------------------------------*/ + +int main( int argc, char ** argv) +{ + NDT_Root *ds_ptr = NULL; + int Debug = NDD_TRUE; + + + /* Lancement de commande en mode batch */ + + if( argc >= 2) + { + if( !strcmp( argv[1], "--help")) + { + fprintf( stderr, USAGE, argv[0]); + return( 1); + } + else if( !strcmp( argv[1], "--version")) + { + if( argc >= 3 && !strcmp( argv[2], "-v")) + { +#ifdef _LIBVER + return( VER_Object_Print( stdout, VERD_VERBOSE)); +#endif + } + else + { +#ifdef _LIBVER + return( VER_Object_Print( stdout, VERD_MINIMAL)); +#endif + } + } + else if( !strcmp( argv[1], "--batch_run")) + { + ND_Library_Open( Debug); + + Command_Exec( &ds_ptr, stdout, BATCH_RUN, argv[2], NULL, stdin); + + ND_Library_Close(); + + return(0); + } + else + { + fprintf( stderr, USAGE, argv[0]); + return(0); + } } - fprintf (Out, "\nStructure de type %s :\n\t- Nombre de noeuds = %ld\n", Root_Type, Current_Root->Node_Number); + /* Lancement du menu intercatif */ - if ((Current_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", \ - Current_Root->Max_Depth, Current_Root->Min_Depth, Current_Root->Max_Dif, Current_Root->Nb_Equ); + ND_Library_Open( Debug); - return (NDS_OK); - } + Batch_Run( &ds_ptr, stdout, stdin, 1); - if (Command == NDD_CMD_COMP_VALUE) - { - T_Module * Value1, * Value2; - long comp; + ND_Library_Close(); - Value1 = (T_Module *)va_arg (args_ptr, void *); - Value2 = (T_Module *)va_arg (args_ptr, void *); - va_end (args_ptr); - comp = Value1->Id - Value2->Id; - if (comp < 0) return NDS_LOWER; - if (comp > 0) return NDS_GREATER; - return NDS_EQUAL; - } - - va_end (args_ptr); - return (NDS_OK); -} - -void init_menu (void) -{ - sprintf (menu, "Menu :\n"); - sprintf (buf, "\t- %d) %-30s\n", QUIT, "Quitter"); strcat (menu, buf); - sprintf (buf, "\t- %d) %-30s", ADD_VALUE, "Ajout de valeurs"); strcat (menu, buf); - sprintf (buf, "\t- %d) %-30s\n", REMOVE_VALUE, "Suppression de valeurs"); strcat (menu, buf); - sprintf (buf, "\t- %d) %-30s\n", FIND_VALUE, "Recherche de valeurs aléatoires"); strcat (menu, buf); - if (ND_IS_LIST(Root)) - { - sprintf (buf, "\t- %d) %-30s", CHG_LIST_TYPE, "Changement de type de liste"); strcat (menu, buf); - sprintf (buf, "\t- %d) %-30s\n", CONVERT_TO_TREE, "Conversion en arbre"); strcat (menu, buf); - } - else - { - sprintf (buf, "\t- %d) %-30s\n", CONVERT_TO_LIST, "Conversion en liste triée"); strcat (menu, buf); - } - - sprintf (buf, "\t- %d) %-30s\n", REORG, "Réorganisation"); strcat (menu, buf); - sprintf (buf, "\t- %d) %-30s", INFO, "Informations sur la structure"); strcat (menu, buf); - sprintf (buf, "\t- %d) %-30s\n", SHOW, "Affichage de la structure"); strcat (menu, buf); - sprintf (buf, "\t- %d) %-30s\n", CHECK, "Vérification de la structure"); strcat (menu, buf); -} - -int print_menu (void) -{ - int choice; - - init_menu (); - fprintf (stdout, "\n-----------------------------------------------------------------------\n"); - fprintf (stdout, menu); - *buf = (char)0; - while (!*buf) - { - printf ("\nChoice ? "); - gets (buf); - } - choice = atoi (buf); - - return choice; + return( 0); }