1445 lines
38 KiB
C
1445 lines
38 KiB
C
/*---------------------------------------------------------------------------------*/
|
|
/* $RCSfile: libopt.c,v $ */
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* $Revision: 1.1 $ */
|
|
/* $Name: $ */
|
|
/* $Date: 2001/12/17 01:12:41 $ */
|
|
/* $Author: agibert $ */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#define _OPTION_C_
|
|
|
|
#include "tima.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
NDT_Status Manager_OptionValueStruct( 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)
|
|
{
|
|
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.1 $ $Name: $ $Date: 2001/12/17 01:12:41 $ $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);
|
|
*/
|
|
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);
|
|
|
|
|
|
Command_Name = "NDD_CMD_IDX_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, ...);
|
|
*/
|
|
TIMAT_OptionValue **OptionValue_Ptr_Ptr = (TIMAT_OptionValue **)va_arg( Args, TIMAT_OptionValue **);
|
|
|
|
|
|
Command_Name = "NDD_CMD_VALUE_ALLOC";
|
|
|
|
if( ( *OptionValue_Ptr_Ptr = (void *)malloc( sizeof(TIMAT_OptionValue))) == NULL)
|
|
{
|
|
return(NDS_ERRMEM);
|
|
}
|
|
else
|
|
{
|
|
(*OptionValue_Ptr_Ptr)->Node = NULL;
|
|
(*OptionValue_Ptr_Ptr)->Data[0] = '\0';
|
|
return( NDS_OK);
|
|
}
|
|
|
|
}
|
|
|
|
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, ...);
|
|
*/
|
|
TIMAT_OptionValue *OptionValue_Ptr = (TIMAT_OptionValue *)va_arg( Args, TIMAT_OptionValue *);
|
|
|
|
|
|
Command_Name = "NDD_CMD_VALUE_FREE";
|
|
|
|
free( OptionValue_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, ...);
|
|
*/
|
|
|
|
|
|
Command_Name = "NDD_CMD_VALUE_COMP";
|
|
|
|
/*
|
|
switch( Index_Id)
|
|
{
|
|
case 0:
|
|
{
|
|
int rc;
|
|
|
|
|
|
rc = strcmp( Value1_Ptr->..., Value2_Ptr->...);
|
|
|
|
if( rc < 0)
|
|
{
|
|
return(NDS_LOWER);
|
|
}
|
|
else
|
|
{
|
|
if( rc > 0)
|
|
{
|
|
return(NDS_GREATER);
|
|
}
|
|
else
|
|
{
|
|
return(NDS_EQUAL);
|
|
}
|
|
}
|
|
}
|
|
|
|
case 1:
|
|
{
|
|
int val1 = atoi(Value1_Ptr->...);
|
|
int val2 = atoi(Value2_Ptr->...);
|
|
|
|
|
|
if( val1 < val2)
|
|
{
|
|
return(NDS_LOWER);
|
|
}
|
|
else
|
|
{
|
|
if( val1 > val2)
|
|
{
|
|
return(NDS_GREATER);
|
|
}
|
|
else
|
|
{
|
|
return(NDS_EQUAL);
|
|
}
|
|
}
|
|
}
|
|
|
|
case 2:
|
|
{
|
|
...
|
|
}
|
|
|
|
default:
|
|
{
|
|
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, ...);
|
|
*/
|
|
TIMAT_OptionValue *OptionValue_Ptr = (TIMAT_OptionValue *)va_arg( Args, TIMAT_OptionValue *);
|
|
|
|
|
|
Command_Name = "NDD_CMD_VALUE_ADD";
|
|
|
|
OptionValue_Ptr->Node = Node_Ptr;
|
|
|
|
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);
|
|
|
|
TIMAT_OptionValue *OptionValue_Ptr = Node_Ptr->Value;
|
|
|
|
|
|
Command_Name = "NDD_CMD_VALUE_PRINT";
|
|
|
|
fprintf( Out, "[");
|
|
TIMA_Opt_OptionValue_Print( Out, OptionValue_Ptr);
|
|
fprintf( Out, "] ");
|
|
|
|
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);
|
|
}
|
|
|
|
case NDD_CMD_USER_TRAVERSE:
|
|
{
|
|
/*
|
|
NDT_Node *Next_Node_Ptr = (NDT_Node *)va_arg( Args, NDT_Node *);
|
|
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, ...);
|
|
|
|
void *Value_Ptr = Node_Ptr->Value;
|
|
*/
|
|
|
|
|
|
Command_Name = "NDD_CMD_USER_TRAVERSE";
|
|
|
|
/*
|
|
return( NDS_OK);
|
|
*/
|
|
}
|
|
|
|
default:
|
|
{
|
|
printf( "Default_Manager() called with an undefined command %d\n", Command);
|
|
return(NDS_ERRAPI);
|
|
}
|
|
}
|
|
|
|
printf( "Default_Manager() called with command %d (%s)\n", Command, Command_Name);
|
|
return(NDS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status TIMA_Opt_Eval( char *Output_Str, int Output_Size, char *Input_Str)
|
|
{
|
|
char *cmd_prefix = "echo ";
|
|
char *command_ptr;
|
|
int old_stdout, pipe[2];
|
|
|
|
|
|
if( ( command_ptr = malloc( strlen( cmd_prefix) + strlen( Input_Str) + 1)) == NULL)
|
|
{
|
|
printf( "TIMA_Opt_Eval: malloc() failed !\n");
|
|
return(TIMAS_OK);
|
|
}
|
|
|
|
sprintf( command_ptr, "%s%s", cmd_prefix, Input_Str);
|
|
|
|
|
|
|
|
if( ( old_stdout = _dup( _fileno( stdout))) == -1)
|
|
{
|
|
printf( "TIMA_Opt_Eval: _dup2() failed !\n");
|
|
return(TIMAS_OK);
|
|
}
|
|
|
|
if( _pipe( pipe, 1024, _O_BINARY) == -1)
|
|
{
|
|
printf( "TIMA_Opt_Eval: _pipe() failed !\n");
|
|
return(TIMAS_OK);
|
|
}
|
|
|
|
if( _dup2( pipe[1], _fileno( stdout)) == -1)
|
|
{
|
|
printf( "TIMA_Opt_Eval: _dup2() failed !\n");
|
|
return(TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
if( system( command_ptr) == -1)
|
|
{
|
|
printf( "TIMA_Opt_Eval: system() failed !\n");
|
|
return(TIMAS_OK);
|
|
}
|
|
|
|
if( fflush( stdout) != 0)
|
|
{
|
|
printf( "TIMA_Opt_Eval: fflush() failed !\n");
|
|
return(TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
Output_Str[ _read( pipe[0], Output_Str, Output_Size) - 2] = '\0';
|
|
|
|
if( _dup2( old_stdout, _fileno( stdout)) == -1)
|
|
{
|
|
printf( "TIMA_Opt_Eval: _dup2() failed !\n");
|
|
return(TIMAS_OK);
|
|
}
|
|
|
|
if( _close( pipe[0]) == -1)
|
|
{
|
|
printf( "TIMA_Opt_Eval: _close() failed !\n");
|
|
return(TIMAS_OK);
|
|
}
|
|
|
|
if( _close( pipe[1]) == -1)
|
|
{
|
|
printf( "TIMA_Opt_Eval: _close() failed !\n");
|
|
return(TIMAS_OK);
|
|
}
|
|
|
|
free( command_ptr);
|
|
|
|
return( TIMAS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status Opt_Option_String_Parse( int *argc, char **argv, char *Input_String)
|
|
{
|
|
short i, j;
|
|
short new_arg;
|
|
|
|
|
|
for( i = 0, j = 0, new_arg = 1; ( i < 1024) && ( Input_String[i] != '\0'); i++)
|
|
{
|
|
if( ( Input_String[i] == ' ') || ( Input_String[i] == '\t') || ( Input_String[i] == '\r') || ( Input_String[i] == '\n'))
|
|
{
|
|
Input_String[i] = '\0';
|
|
new_arg = 1;
|
|
}
|
|
else
|
|
{
|
|
if( Input_String[i] == '#')
|
|
{
|
|
Input_String[i--] = '\0';
|
|
}
|
|
else
|
|
{
|
|
if( new_arg)
|
|
{
|
|
new_arg = 0;
|
|
argv[j++] = &Input_String[i];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
*argc = j;
|
|
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status Opt_Option_Value_Copy( TIMAT_Option *Option_Tab, short Opt, short Env, int *ArgNb_Ptr, int ArgC, char **ArgV, short Switch)
|
|
{
|
|
NDT_Status nd_status;
|
|
short arg;
|
|
TIMAT_OptionValue *optionvalue_ptr;
|
|
TIMAT_OptionValue value;
|
|
|
|
|
|
if( Option_Tab[Opt].Arg_Type == TIMAD_OPTION_ARG_TYPE_MONO)
|
|
{
|
|
if( Option_Tab[Opt].Arg_Number > 2)
|
|
{
|
|
if( Option_Tab[Opt].OptionValueStruct_Tab[Env] != NULL)
|
|
{
|
|
if( ( nd_status = ND_DataStruct_Flush( Option_Tab[Opt].OptionValueStruct_Tab[Env])) != NDS_OK)
|
|
{
|
|
printf( "Opt_Option_Value_Copy: ND_DataStructure_Flush() failed (%d) !\n", nd_status);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if( ( Option_Tab[Opt].Arg_Number - 1) > ArgC)
|
|
{
|
|
printf( "Opt_Option_Value_Copy: Missing option value for [%s] !\n", Option_Tab[Opt].Switch_Long);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
arg = 0;
|
|
|
|
do
|
|
{
|
|
if( Option_Tab[Opt].Arg_Number == 1)
|
|
{
|
|
value.Type = Option_Tab[Opt].Value_Type_Tab[0];
|
|
value.Data[0] = (char)Switch;
|
|
value.Node = NULL;
|
|
}
|
|
else
|
|
{
|
|
value.Type = Option_Tab[Opt].Value_Type_Tab[ arg % ( Option_Tab[Opt].Arg_Number - 1)];
|
|
value.Node = NULL;
|
|
|
|
if( *(char *)( ArgV[arg]) == TIMAD_UNKNOWN)
|
|
{
|
|
*((char *)value.Data) = TIMAD_UNKNOWN;
|
|
}
|
|
else
|
|
{
|
|
switch( value.Type)
|
|
{
|
|
case TIMAD_OPTION_VALUE_TYPE_UNKNOWN:
|
|
{
|
|
*((char *)value.Data) = TIMAD_UNKNOWN;
|
|
break;
|
|
}
|
|
|
|
case TIMAD_OPTION_VALUE_TYPE_FLAG:
|
|
{
|
|
*((char *)value.Data) = ArgV[arg][0];
|
|
break;
|
|
}
|
|
|
|
case TIMAD_OPTION_VALUE_TYPE_LONG:
|
|
{
|
|
*((long *)value.Data) = atoi( ArgV[arg]);
|
|
break;
|
|
}
|
|
|
|
case TIMAD_OPTION_VALUE_TYPE_STRING:
|
|
{
|
|
strcpy( value.Data, ArgV[arg]);
|
|
break;
|
|
}
|
|
|
|
default:
|
|
{
|
|
printf( "Opt_Option_Value_Copy: Unknown option value type (%d) !\n", value.Type);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if( Option_Tab[Opt].Arg_Type == TIMAD_OPTION_ARG_TYPE_MONO)
|
|
{
|
|
Option_Tab[Opt].OptionValueData_Tab[Env].Type = value.Type;
|
|
strncpy( Option_Tab[Opt].OptionValueData_Tab[Env].Data, value.Data, TIMAD_OPTION_VALUE_LEN);
|
|
Option_Tab[Opt].OptionValueData_Tab[Env].Node = NULL;
|
|
}
|
|
else
|
|
{
|
|
if( ( nd_status = ND_Value_Alloc( Option_Tab[Opt].OptionValueStruct_Tab[Env], (void **)&optionvalue_ptr)) != NDS_OK)
|
|
{
|
|
printf( "Opt_Option_Value_Copy: ND_Value_Alloc() failed (%d) !\n", nd_status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
optionvalue_ptr->Type = value.Type;
|
|
strncpy( optionvalue_ptr->Data, value.Data, TIMAD_OPTION_VALUE_LEN);
|
|
|
|
if( ( nd_status = ND_DataStruct_Value_Add( Option_Tab[Opt].OptionValueStruct_Tab[Env], optionvalue_ptr)) != NDS_OK)
|
|
{
|
|
printf( "Opt_Option_Value_Copy: ND_DataStruct_Value_Add() failed (%d) !\n", nd_status);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
|
|
arg++;
|
|
}
|
|
while( arg < ArgC);
|
|
|
|
if( Option_Tab[Opt].Arg_Number == 1)
|
|
{
|
|
*ArgNb_Ptr = 0;
|
|
}
|
|
else
|
|
{
|
|
*ArgNb_Ptr = arg;
|
|
}
|
|
|
|
return(TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status Opt_Option_Init( TIMAT_Option *Option_Tab)
|
|
{
|
|
NDT_Status nd_status;
|
|
TIMAT_Status status;
|
|
short opt,env;
|
|
char val_def[TIMAD_OPTION_ARG_NUMBER_MAX * ( TIMAD_OPTION_VALUE_SIZE + 1)];
|
|
TIMAT_OptionValueData val_tmp;
|
|
int argc, argnb;
|
|
char *argv[255];
|
|
|
|
|
|
for( opt = 1; Option_Tab[opt].Arg_Number != 0; opt++)
|
|
{
|
|
for( env = 0; env < TIMAD_OPTION_ENV_NUMBER; env++)
|
|
{
|
|
if( Option_Tab[opt].Arg_Type == TIMAD_OPTION_ARG_TYPE_MULTI)
|
|
{
|
|
if( ( nd_status = ND_DataStruct_Open( &( Option_Tab[opt].OptionValueStruct_Tab[env]), 1, TIMAG_OptionValue_Type_Initial_Tab, \
|
|
"Manager_OptionValueStruct", Manager_OptionValueStruct, NULL, NULL, NULL, NULL, \
|
|
0, NULL)) != NDS_OK)
|
|
{
|
|
printf( "Opt_Option_Init: ND_DataStruct_Open() OptionStruct failed: (%d)...\n", nd_status);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
|
|
if( env == TIMAD_OPTION_ENV_DEFAULT)
|
|
{
|
|
if( *((char *)Option_Tab[opt].OptionValueData_Flat_Default) != TIMAD_UNKNOWN)
|
|
{
|
|
strcpy( val_def, Option_Tab[opt].OptionValueData_Flat_Default);
|
|
|
|
if( ( status = Opt_Option_String_Parse( &argc, argv, val_def)) != TIMAS_OK)
|
|
{
|
|
printf( "Opt_Option_Init: Opt_Option_String_Parse() failed: (%d)...\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
argc = 1;
|
|
val_tmp[0] = (char)TIMAD_UNKNOWN;
|
|
argv[0] = val_tmp;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
argc = 1;
|
|
val_tmp[0] = (char)TIMAD_UNKNOWN;
|
|
argv[0] = val_tmp;
|
|
}
|
|
|
|
if( ( *((char *)argv[0]) != TIMAD_UNKNOWN) || ( Option_Tab[opt].Arg_Type == TIMAD_OPTION_ARG_TYPE_MONO))
|
|
{
|
|
if( ( status = Opt_Option_Value_Copy( Option_Tab, opt, env, &argnb, argc, argv, Option_Tab[opt].OptionValueData_Flat_Default[0])) != TIMAS_OK)
|
|
{
|
|
printf( "Opt_Option_Init: Opt_Option_Value_Copy() failed: (%d)...\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status Opt_Option_DeInit( TIMAT_Option *Option_Tab)
|
|
{
|
|
NDT_Status nd_status;
|
|
short i, j;
|
|
|
|
|
|
for( i = 1; Option_Tab[i].Arg_Number != 0; i++)
|
|
{
|
|
if( Option_Tab[i].Arg_Type == TIMAD_OPTION_ARG_TYPE_MULTI)
|
|
{
|
|
for( j = 1; j < TIMAD_OPTION_ENV_NUMBER; j++)
|
|
{
|
|
if( Option_Tab[i].OptionValueStruct_Tab[j] != NULL)
|
|
{
|
|
if( ( nd_status = ND_DataStruct_Close( Option_Tab[i].OptionValueStruct_Tab[j])) != NDS_OK)
|
|
{
|
|
printf( "Opt_Option_DeInit: ND_DataStruct_Close OptionStruct failled: (%d)...\n", nd_status);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status TIMA_Opt_Init( void)
|
|
{
|
|
TIMAT_Status status;
|
|
|
|
|
|
if( ( status = Opt_Option_Init( TIMAG_Option_Tab)) != TIMAS_OK)
|
|
{
|
|
printf( "TIMA_Opt_Init: Opt_Option_Init() failed: (%d)...\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
printf( "TIMA_Opt_Init Ok !\n");
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status TIMA_Opt_DeInit( void)
|
|
{
|
|
TIMAT_Status status;
|
|
|
|
|
|
if( ( status = Opt_Option_DeInit( TIMAG_Option_Tab)) != TIMAS_OK)
|
|
{
|
|
printf( "TIMA_Opt_DeInit: Opt_Option_Init() failed: (%d)...\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
printf( "TIMA_Opt_DeInit Ok !\n");
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status Opt_Option_Value_Load( TIMAT_Option *Option_Tab, short Env, int *ArgNb_Ptr, int ArgC, char **ArgV)
|
|
{
|
|
NDT_Status nd_status;
|
|
TIMAT_Status status;
|
|
char *option_name;
|
|
short name_type;
|
|
short swtch;
|
|
short i;
|
|
|
|
|
|
if( *(ArgV[0]) == '-')
|
|
{
|
|
if( *(ArgV[0] + 1) == '-')
|
|
{
|
|
option_name = ArgV[0] + 2;
|
|
name_type = TIMAD_OPTION_NAME_TYPE_LONG;
|
|
}
|
|
else
|
|
{
|
|
option_name = ArgV[0] + 1;
|
|
name_type = TIMAD_OPTION_NAME_TYPE_SHORT;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
printf( "TIMA_Opt_Option_Value_Load: Invalid command line string [%s]...\n", ArgV[0]);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
for( i = 1; Option_Tab[i].Arg_Number != 0; i++)
|
|
{
|
|
if( Option_Tab[i].Arg_Number == 1)
|
|
{
|
|
if( name_type == TIMAD_OPTION_NAME_TYPE_LONG)
|
|
{
|
|
if( !strcmp( Option_Tab[i].Switch_On_Long, option_name))
|
|
{
|
|
swtch = TIMAD_TRUE;
|
|
break;
|
|
}
|
|
|
|
if( !strcmp( Option_Tab[i].Switch_Off_Long, option_name))
|
|
{
|
|
swtch = TIMAD_FALSE;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if( !strcmp( Option_Tab[i].Switch_On_Short, option_name))
|
|
{
|
|
swtch = TIMAD_TRUE;
|
|
break;
|
|
}
|
|
|
|
if( !strcmp( Option_Tab[i].Switch_Off_Short, option_name))
|
|
{
|
|
swtch = TIMAD_FALSE;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if( name_type == TIMAD_OPTION_NAME_TYPE_LONG)
|
|
{
|
|
if( !strcmp( Option_Tab[i].Switch_Long, option_name)) break;
|
|
}
|
|
else
|
|
{
|
|
if( !strcmp( Option_Tab[i].Switch_Short, option_name)) break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if( Option_Tab[i].Arg_Number == 0)
|
|
{
|
|
printf( "TIMA_Opt_Option_Value_Load: Unknown option [%s]...\n", ArgV[0]);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
if( Option_Tab[i].Arg_Type == TIMAD_OPTION_ARG_TYPE_MONO)
|
|
{
|
|
if( Option_Tab[i].Arg_Number > 2)
|
|
{
|
|
if( Option_Tab[i].OptionValueStruct_Tab[Env] != NULL)
|
|
{
|
|
if( ( nd_status = ND_DataStruct_Flush( Option_Tab[i].OptionValueStruct_Tab[Env])) != NDS_OK)
|
|
{
|
|
printf( "Opt_Option_Value_Load: ND_DataStructure_Flush() failed (%d) !\n", nd_status);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if( Option_Tab[i].Arg_Number > ArgC)
|
|
{
|
|
printf( "TIMA_Opt_Option_Value_Load: Missing option value for [%s] !\n", ArgV[0]);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
if( ( status = Opt_Option_Value_Copy( Option_Tab, i, Env, ArgNb_Ptr, (Option_Tab[i].Arg_Number - 1), (ArgV + 1), swtch)) != TIMAS_OK)
|
|
{
|
|
printf( "Opt_Option_Init: Opt_Option_Value_Copy() failed: (%d)...\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
(*ArgNb_Ptr)++;
|
|
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status Opt_Option_Arg_Parse( TIMAT_Option *Option_Tab, short Env, int ArgC, char **ArgV)
|
|
{
|
|
TIMAT_Status status;
|
|
int argnb;
|
|
short i;
|
|
|
|
|
|
for( i = 1; i < ArgC; i += argnb)
|
|
{
|
|
if( ( status = Opt_Option_Value_Load( Option_Tab, Env, &argnb, ( ArgC - i), &(ArgV[i]))) != TIMAS_OK)
|
|
{
|
|
printf( "TIMA_Opt_Option_Arg_Parse: Can't load value (%d)...\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status Opt_Option_File_Parse( TIMAT_Option *Option_Tab, short Env, char *Config_File_Name)
|
|
{
|
|
TIMAT_Status status;
|
|
FILE *config_file;
|
|
char buf[1025] = "--";
|
|
int argc;
|
|
char *argv[255];
|
|
int argnb;
|
|
|
|
|
|
if( ( config_file = fopen( Config_File_Name, "r")) == NULL)
|
|
{
|
|
fprintf( stderr, "Opt_Option_File_Parse: can't open config file [%s] !\n", Config_File_Name);
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
while( ( !feof( config_file)) && ( fgets( (buf + 2), 1022, config_file) != NULL))
|
|
{
|
|
if( ( status = Opt_Option_String_Parse( &argc, argv, buf)) != TIMAS_OK)
|
|
{
|
|
printf( "Opt_Option_File_Parse: Opt_Option_String_Parse() failed (%d)...\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
if( argc > 0)
|
|
{
|
|
if( ( status = Opt_Option_Value_Load( Option_Tab, Env, &argnb, argc, argv)) != TIMAS_OK)
|
|
{
|
|
printf( "Opt_Option_File_Parse: Can't load value (%d)...\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
}
|
|
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status Opt_Option_Env_Copy( TIMAT_Option *Option_Tab, short Dst_Env, short Src_Env)
|
|
{
|
|
|
|
TIMAT_Status status;
|
|
NDT_Status nd_status;
|
|
short opt;
|
|
TIMAT_OptionValue *value_next_ptr, *value_new_ptr;
|
|
|
|
|
|
for( opt = 1; Option_Tab[opt].Arg_Number != 0 ; opt++)
|
|
{
|
|
if( ( Option_Tab[opt].Arg_Type == TIMAD_OPTION_ARG_TYPE_MONO) && ( Option_Tab[opt].Arg_Number <= 2))
|
|
{
|
|
if( Option_Tab[opt].OptionValueData_Tab[Src_Env].Data[0] != TIMAD_UNKNOWN)
|
|
{
|
|
Option_Tab[opt].OptionValueData_Tab[Dst_Env].Type = Option_Tab[opt].OptionValueData_Tab[Src_Env].Type;
|
|
strncpy( Option_Tab[opt].OptionValueData_Tab[Dst_Env].Data, Option_Tab[opt].OptionValueData_Tab[Src_Env].Data, TIMAD_OPTION_VALUE_SIZE);
|
|
Option_Tab[opt].OptionValueData_Tab[Dst_Env].Node = Option_Tab[opt].OptionValueData_Tab[Src_Env].Node;
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if( Option_Tab[opt].OptionValueStruct_Tab[Src_Env]->Index_Tab[NDD_INDEX_PRIMARY].Node_Number > 0)
|
|
{
|
|
if( Option_Tab[opt].Arg_Type == TIMAD_OPTION_ARG_TYPE_MONO)
|
|
{
|
|
if( Option_Tab[opt].OptionValueStruct_Tab[Dst_Env] != NULL)
|
|
{
|
|
if( ( nd_status = ND_DataStruct_Flush( Option_Tab[opt].OptionValueStruct_Tab[Dst_Env])) != NDS_OK)
|
|
{
|
|
printf( "Opt_Option_Env_Copy: ND_DataStructure_Flush() failed (%d) !\n", nd_status);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
}
|
|
|
|
value_next_ptr = NULL;
|
|
|
|
do
|
|
{
|
|
if( ( status = TIMA_Opt_OptionValue_Next( &value_next_ptr, value_next_ptr, &Option_Tab[opt], Src_Env)) != TIMAS_OK)
|
|
{
|
|
printf( "Opt_Option_Value_Load: TIMA_OptionValue_Next() failed (%d) !\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
if( value_next_ptr != NULL)
|
|
{
|
|
if( ( nd_status = ND_Value_Alloc( Option_Tab[opt].OptionValueStruct_Tab[Dst_Env], (void **)&value_new_ptr)) != NDS_OK)
|
|
{
|
|
printf( "Opt_Option_Value_Load: ND_Value_Alloc() failed (%d) !\n", nd_status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
value_new_ptr->Type = value_next_ptr->Type;
|
|
strncpy( value_new_ptr->Data, value_next_ptr->Data, TIMAD_OPTION_VALUE_LEN);
|
|
|
|
if( ( nd_status = ND_DataStruct_Value_Add( Option_Tab[opt].OptionValueStruct_Tab[Dst_Env], value_new_ptr)) != NDS_OK)
|
|
{
|
|
printf( "Opt_Option_Value_Load: ND_DataStruct_Value_Add() failed (%d) !\n", nd_status);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
}
|
|
while( value_next_ptr != NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status TIMA_Opt_Option_Load( int ArgC, char **ArgV)
|
|
{
|
|
TIMAT_Status status;
|
|
char cscs_path[TIMAD_OPTION_VALUE_SIZE];
|
|
char *config_file_name;
|
|
char config_file_path[TIMAD_OPTION_VALUE_SIZE];
|
|
|
|
|
|
/* Initial command line loading */
|
|
|
|
if( ( status = Opt_Option_Arg_Parse( TIMAG_Option_Tab, TIMAD_OPTION_ENV_COMMAND, ArgC, ArgV)) != TIMAS_OK)
|
|
{
|
|
printf( "TIMA_Opt_Option_Load: Opt_Option_Arg_Parse() Command Env failed (%d) !\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
|
|
|
|
/* CSCS dir handling */
|
|
|
|
if( TIMAG_Option_Tab[TIMAD_OPTION_ID_CSCS_DIR].OptionValueData_Tab[TIMAD_OPTION_ENV_COMMAND].Data[0] != TIMAD_UNKNOWN)
|
|
{
|
|
strcpy( cscs_path, TIMAG_Option_Tab[TIMAD_OPTION_ID_CSCS_DIR].OptionValueData_Tab[TIMAD_OPTION_ENV_COMMAND].Data);
|
|
}
|
|
else
|
|
{
|
|
if( TIMAG_Option_Tab[TIMAD_OPTION_ID_CSCS_DIR].OptionValueData_Tab[TIMAD_OPTION_ENV_DEFAULT].Data[0] != TIMAD_UNKNOWN)
|
|
{
|
|
strcpy( cscs_path, TIMAG_Option_Tab[TIMAD_OPTION_ID_CSCS_DIR].OptionValueData_Tab[TIMAD_OPTION_ENV_DEFAULT].Data);
|
|
}
|
|
else
|
|
{
|
|
printf( "CSCSPATH not found !\n");
|
|
exit( -1);
|
|
}
|
|
}
|
|
|
|
if( ( status = TIMA_Opt_Eval( cscs_path, TIMAD_OPTION_VALUE_SIZE, cscs_path)) != TIMAS_OK)
|
|
{
|
|
printf( "TIMA_Opt_Option_Load: TIMA_Opt_Eval() failed (%d) !\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
|
|
|
|
/* Config file handling */
|
|
|
|
if( TIMAG_Option_Tab[TIMAD_OPTION_ID_CONFIG_FILE].OptionValueData_Tab[TIMAD_OPTION_ENV_COMMAND].Data[0] != TIMAD_UNKNOWN)
|
|
{
|
|
config_file_name = TIMAG_Option_Tab[TIMAD_OPTION_ID_CONFIG_FILE].OptionValueData_Tab[TIMAD_OPTION_ENV_COMMAND].Data;
|
|
}
|
|
else
|
|
{
|
|
if( TIMAG_Option_Tab[TIMAD_OPTION_ID_CONFIG_FILE].OptionValueData_Tab[TIMAD_OPTION_ENV_DEFAULT].Data[0] != TIMAD_UNKNOWN)
|
|
{
|
|
config_file_name = TIMAG_Option_Tab[TIMAD_OPTION_ID_CONFIG_FILE].OptionValueData_Tab[TIMAD_OPTION_ENV_DEFAULT].Data;
|
|
}
|
|
else
|
|
{
|
|
config_file_name = NULL;
|
|
}
|
|
}
|
|
|
|
if( config_file_name != NULL)
|
|
{
|
|
sprintf( config_file_path, "%s\\%s", cscs_path, config_file_name);
|
|
|
|
if( ( status = Opt_Option_File_Parse( TIMAG_Option_Tab, TIMAD_OPTION_ENV_CONFIG, config_file_path)) != TIMAS_OK)
|
|
{
|
|
printf( "TIMA_Opt_Option_Load: Opt_Option_File_Load() failed (%d) !\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Final command line loading */
|
|
|
|
if( ( status = Opt_Option_Env_Copy( TIMAG_Option_Tab, TIMAD_OPTION_ENV_CURRENT, TIMAD_OPTION_ENV_DEFAULT)) != TIMAS_OK)
|
|
{
|
|
printf( "TIMA_Opt_Option_Load: Opt_Option_Env_Copy() DEFAULT to CURRENT failed (%d) !\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
if( ( status = Opt_Option_Env_Copy( TIMAG_Option_Tab, TIMAD_OPTION_ENV_CURRENT, TIMAD_OPTION_ENV_CONFIG)) != TIMAS_OK)
|
|
{
|
|
printf( "TIMA_Opt_Option_Load: Opt_Option_Env_Copy() CONFIG to CURRENT failed (%d) !\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
if( ( status = Opt_Option_Env_Copy( TIMAG_Option_Tab, TIMAD_OPTION_ENV_CURRENT, TIMAD_OPTION_ENV_COMMAND)) != TIMAS_OK)
|
|
{
|
|
printf( "TIMA_Opt_Option_Load: Opt_Option_Env_Copy() COMMAND to CURRENT failed (%d) !\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status TIMA_Opt_OptionValue_Print( FILE *Out, TIMAT_OptionValue *OptionValue_Ptr)
|
|
{
|
|
switch( OptionValue_Ptr->Type)
|
|
{
|
|
case TIMAD_OPTION_VALUE_TYPE_UNKNOWN:
|
|
{
|
|
fprintf( Out, "Unknown Type");
|
|
break;
|
|
}
|
|
|
|
case TIMAD_OPTION_VALUE_TYPE_FLAG:
|
|
{
|
|
fprintf( Out, "%s", ( *OptionValue_Ptr->Data == TIMAD_UNKNOWN) ? "Unknown" : ( ( *OptionValue_Ptr->Data == TIMAD_TRUE) ? "ON" : ( ( *OptionValue_Ptr->Data == TIMAD_FALSE) ? "OFF" : "???")));
|
|
break;
|
|
}
|
|
|
|
case TIMAD_OPTION_VALUE_TYPE_LONG:
|
|
{
|
|
if( *(char *)OptionValue_Ptr->Data == TIMAD_UNKNOWN)
|
|
{
|
|
fprintf( Out, "%s", "Unknown");
|
|
}
|
|
else
|
|
{
|
|
fprintf( Out, "%d", *(long *)OptionValue_Ptr->Data);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case TIMAD_OPTION_VALUE_TYPE_STRING:
|
|
{
|
|
fprintf( Out, "%s", ( *OptionValue_Ptr->Data == TIMAD_UNKNOWN) ? "Unknown" : OptionValue_Ptr->Data);
|
|
break;
|
|
}
|
|
|
|
default:
|
|
{
|
|
fprintf( Out, "???");
|
|
break;
|
|
}
|
|
}
|
|
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status TIMA_Opt_Option_Print( FILE *Out, TIMAT_Option *OptionStruct_Ptr)
|
|
{
|
|
NDT_Status nd_status;
|
|
short i;
|
|
|
|
|
|
for( i = 1; TIMAG_Option_Tab[i].Arg_Number != 0; i++)
|
|
{
|
|
|
|
if( TIMAG_Option_Tab[i].Switch_Off_Long[0] != '\0')
|
|
{
|
|
fprintf( Out, "-%s%*s--%s%*sSwitch On %s\n",
|
|
TIMAG_Option_Tab[i].Switch_On_Short, ( 3 + TIMAD_OPTION_SWITCH_SHORT_SIZE - strlen( TIMAG_Option_Tab[i].Switch_On_Short)), " ",
|
|
TIMAG_Option_Tab[i].Switch_On_Long, ( 3 + TIMAD_OPTION_SWITCH_LONG_SIZE - strlen( TIMAG_Option_Tab[i].Switch_On_Long) + 3 + TIMAD_OPTION_ARG_LABEL_SIZE), " ",
|
|
TIMAG_Option_Tab[i].Label);
|
|
|
|
fprintf( Out, "-%s%*s--%s%*sSwitch Off %s%*s",
|
|
TIMAG_Option_Tab[i].Switch_Off_Short, ( 3 + TIMAD_OPTION_SWITCH_SHORT_SIZE - strlen( TIMAG_Option_Tab[i].Switch_Off_Short)), " ",
|
|
TIMAG_Option_Tab[i].Switch_Off_Long, ( 3 + TIMAD_OPTION_SWITCH_LONG_SIZE - strlen( TIMAG_Option_Tab[i].Switch_Off_Long) + 3 + TIMAD_OPTION_ARG_LABEL_SIZE), " ",
|
|
TIMAG_Option_Tab[i].Label, ( 3 + TIMAD_OPTION_LABEL_SIZE - strlen( TIMAG_Option_Tab[i].Label) - 11), " ");
|
|
}
|
|
else
|
|
{
|
|
fprintf( Out, "-%s%*s--%s%*s%s%*s%s%*s",
|
|
TIMAG_Option_Tab[i].Switch_Short, ( 3 + TIMAD_OPTION_SWITCH_SHORT_SIZE - strlen( TIMAG_Option_Tab[i].Switch_Short)), " ",
|
|
TIMAG_Option_Tab[i].Switch_Long, ( 3 + TIMAD_OPTION_SWITCH_LONG_SIZE - strlen( TIMAG_Option_Tab[i].Switch_Long)), " ",
|
|
TIMAG_Option_Tab[i].Arg_Label, ( 3 + TIMAD_OPTION_ARG_LABEL_SIZE - strlen( TIMAG_Option_Tab[i].Arg_Label)), " ",
|
|
TIMAG_Option_Tab[i].Label, ( 3 + TIMAD_OPTION_LABEL_SIZE - strlen( TIMAG_Option_Tab[i].Label)), " ");
|
|
}
|
|
|
|
fprintf( Out, "Default: ");
|
|
|
|
if( ( TIMAG_Option_Tab[i].Arg_Number <= 2) && ( TIMAG_Option_Tab[i].Arg_Type == TIMAD_OPTION_ARG_TYPE_MONO))
|
|
{
|
|
fprintf( Out, "[");
|
|
TIMA_Opt_OptionValue_Print( Out, &TIMAG_Option_Tab[i].OptionValueData_Tab[TIMAD_OPTION_ENV_DEFAULT]);
|
|
fprintf( Out, "]\n");
|
|
}
|
|
else
|
|
{
|
|
if( TIMAG_Option_Tab[i].OptionValueStruct_Tab[TIMAD_OPTION_ENV_DEFAULT]->Index_Tab[NDD_INDEX_PRIMARY].Node_Number >0)
|
|
{
|
|
if( ( nd_status = ND_DataStruct_Value_Print( Out, TIMAG_Option_Tab[i].OptionValueStruct_Tab[TIMAD_OPTION_ENV_DEFAULT], NDD_RECURSIVE_MODE_PARENT_CHILD, 2, 0)) != NDS_OK)
|
|
{
|
|
printf( "TIMA_Opt_Option_Print: ND_DataStruct_Value_Print() failed: (%d)...\n", nd_status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
fprintf( Out, "\n");
|
|
}
|
|
else
|
|
{
|
|
fprintf( Out, "[]\n");
|
|
}
|
|
}
|
|
}
|
|
fprintf( Out, "\n");
|
|
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status TIMA_Opt_Option_Dump( FILE *Out, TIMAT_Option *OptionStruct_Ptr)
|
|
{
|
|
NDT_Status nd_status;
|
|
short i, j;
|
|
|
|
|
|
for( i = 1; TIMAG_Option_Tab[i].Arg_Number != 0; i++)
|
|
{
|
|
|
|
if( TIMAG_Option_Tab[i].Switch_Off_Long[0] != '\0')
|
|
{
|
|
fprintf( Out, "Long On Switch: [--%s] Short On Switch: [-%s] Long Off Switch: [--%s] Short Off Switch: [-%s] ",
|
|
TIMAG_Option_Tab[i].Switch_On_Long, TIMAG_Option_Tab[i].Switch_On_Short,
|
|
TIMAG_Option_Tab[i].Switch_Off_Long, TIMAG_Option_Tab[i].Switch_Off_Short);
|
|
}
|
|
else
|
|
{
|
|
fprintf( Out, "Long Switch: [--%s] Short Switch: [-%s] ",
|
|
TIMAG_Option_Tab[i].Switch_Long, TIMAG_Option_Tab[i].Switch_Short);
|
|
}
|
|
|
|
fprintf( Out, "Label: [%s] Arg Number: (%d) Arg Type: (%d) [%s]\nValue Type: ",
|
|
TIMAG_Option_Tab[i].Label, TIMAG_Option_Tab[i].Arg_Number, TIMAG_Option_Tab[i].Arg_Type, TIMA_OPTION_ARG_TYPE_ASCII_GET( TIMAG_Option_Tab[i].Arg_Type));
|
|
|
|
for( j = 0; j < TIMAG_Option_Tab[i].Arg_Number; j++)
|
|
{
|
|
fprintf( Out, "(%d) [%s] ", TIMAG_Option_Tab[i].Value_Type_Tab[j], TIMA_OPTION_VALUE_TYPE_ASCII_GET(TIMAG_Option_Tab[i].Value_Type_Tab[j]));
|
|
}
|
|
|
|
fprintf( Out, "OptionValueData Flat Default: [%s]\n", ( TIMAG_Option_Tab[i].OptionValueData_Flat_Default[0] == (char)TIMAD_UNKNOWN) ? "Unknown" : TIMAG_Option_Tab[i].OptionValueData_Flat_Default);
|
|
fprintf( Out, "Value:");
|
|
|
|
if( TIMAG_Option_Tab[i].Arg_Type == TIMAD_OPTION_ARG_TYPE_MONO)
|
|
{
|
|
for( j = 0; j < TIMAD_OPTION_ENV_NUMBER; j++)
|
|
{
|
|
if( j != TIMAD_OPTION_ENV_UNKNOWN)
|
|
{
|
|
fprintf( Out, " %s: [", TIMA_OPTION_ENV_ASCII_GET( j));
|
|
TIMA_Opt_OptionValue_Print( Out, &TIMAG_Option_Tab[i].OptionValueData_Tab[j]);
|
|
fprintf( Out, "]");
|
|
}
|
|
}
|
|
|
|
fprintf( Out, "\n");
|
|
}
|
|
else
|
|
{
|
|
if( TIMAG_Option_Tab[i].Arg_Type == TIMAD_OPTION_ARG_TYPE_MULTI)
|
|
{
|
|
for( j = 0; j < TIMAD_OPTION_ENV_NUMBER; j++)
|
|
{
|
|
if( j != TIMAD_OPTION_ENV_UNKNOWN)
|
|
{
|
|
fprintf( Out, "\n %s:%*s", TIMA_OPTION_ENV_ASCII_GET( j), ( 10 - strlen(TIMA_OPTION_ENV_ASCII_GET( j))), " ");
|
|
|
|
if( ( nd_status = ND_DataStruct_Value_Print( Out, TIMAG_Option_Tab[i].OptionValueStruct_Tab[j], NDD_RECURSIVE_MODE_PARENT_CHILD, 2, 0)) != NDS_OK)
|
|
{
|
|
printf( "TIMA_Opt_Option_Dump: ND_DataStruct_Value_Print() failed: (%d)...\n", nd_status);
|
|
return( TIMAS_KO);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fprintf( Out, "\n");
|
|
}
|
|
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status TIMA_Opt_OptionValue_Next( TIMAT_OptionValue **OptionValue_Next_Ptr_Ptr, TIMAT_OptionValue *OptionValue_Cur_Ptr, TIMAT_Option *Option_Ptr, short Env)
|
|
{
|
|
NDT_Status nd_status;
|
|
NDT_Node *node_ptr;
|
|
|
|
|
|
if( OptionValue_Cur_Ptr == NULL)
|
|
{
|
|
if( ( nd_status = ND_Index_Node_First_Get( &node_ptr, Option_Ptr->OptionValueStruct_Tab[Env], NDD_INDEX_PRIMARY)) != NDS_OK)
|
|
{
|
|
node_ptr = NULL;
|
|
// return( TIMAS_KO);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if( ( nd_status = ND_Index_Node_Next_Get( &node_ptr, OptionValue_Cur_Ptr->Node)) != NDS_OK)
|
|
{
|
|
node_ptr = NULL;
|
|
// return( TIMAS_KO);
|
|
}
|
|
}
|
|
|
|
if( node_ptr != NULL)
|
|
{
|
|
*OptionValue_Next_Ptr_Ptr = node_ptr->Value;
|
|
}
|
|
else
|
|
{
|
|
*OptionValue_Next_Ptr_Ptr = NULL;
|
|
}
|
|
|
|
return( TIMAS_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------------*/
|
|
/* */
|
|
/*---------------------------------------------------------------------------------*/
|
|
|
|
TIMAT_Status TIMA_Opt_Obj_Status_Get( short *Status, short Option_Id_Enabled, short Option_Id_Disabled, short Env, short OptionValueData_Nb, TIMAT_OptionValueData *Data_Tab)
|
|
{
|
|
TIMAT_Status status;
|
|
TIMAT_OptionValue *optionvalue_ptr = NULL;
|
|
short match, i;
|
|
|
|
|
|
do
|
|
{
|
|
for( i = 0, match = TIMAD_TRUE; i < OptionValueData_Nb; i++)
|
|
{
|
|
if( ( status = TIMA_Opt_OptionValue_Next( &optionvalue_ptr, optionvalue_ptr, &TIMAG_Option_Tab[Option_Id_Enabled], Env)) != TIMAS_OK)
|
|
{
|
|
printf( "TIMA_Opt_Obj_Status_Get: TIMA_Opt_OptionValue_Next() failed (%d)...\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
if( optionvalue_ptr == NULL)
|
|
{
|
|
i = OptionValueData_Nb;
|
|
}
|
|
else
|
|
{
|
|
if( ( match == TIMAD_TRUE) && ( strcmp( optionvalue_ptr->Data, Data_Tab[i])))
|
|
{
|
|
match = TIMAD_FALSE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
while( ( optionvalue_ptr != NULL) && ( match != TIMAD_TRUE));
|
|
|
|
if( optionvalue_ptr == NULL)
|
|
{
|
|
do
|
|
{
|
|
for( i = 0, match = TIMAD_TRUE; i < OptionValueData_Nb; i++)
|
|
{
|
|
if( ( status = TIMA_Opt_OptionValue_Next( &optionvalue_ptr, optionvalue_ptr, &TIMAG_Option_Tab[Option_Id_Disabled], Env)) != TIMAS_OK)
|
|
{
|
|
printf( "TIMA_Opt_Obj_Status_Get: TIMA_Opt_OptionValue_Next() failed (%d)...\n", status);
|
|
return( TIMAS_KO);
|
|
}
|
|
|
|
if( optionvalue_ptr == NULL)
|
|
{
|
|
i = OptionValueData_Nb;
|
|
}
|
|
else
|
|
{
|
|
if( ( match == TIMAD_TRUE) && ( strcmp( optionvalue_ptr->Data, Data_Tab[i])))
|
|
{
|
|
match = TIMAD_FALSE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
while( ( optionvalue_ptr != NULL) && ( match != TIMAD_TRUE));
|
|
|
|
if( optionvalue_ptr == NULL)
|
|
{
|
|
*Status = TIMAD_TRUE;
|
|
}
|
|
else
|
|
{
|
|
*Status = TIMAD_FALSE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
*Status = TIMAD_TRUE;
|
|
}
|
|
|
|
return(TIMAS_OK);
|
|
}
|