// If we have an option
if ( '-' == ctx.current )
{
- // And its a long one
- if( '-' == OPTS_NextCharacter( &ctx ) )
- {
- (void)OPTS_ParseLongOption( &ctx );
- }
- // or a short one
- else
- {
- (void)OPTS_ParseShortOption( &ctx );
- }
+ OPTS_ParseShortOption( &ctx );
+ //// And its a long one
+ //if( '-' == OPTS_NextCharacter( &ctx ) )
+ //{
+ // (void)OPTS_ParseLongOption( &ctx );
+ //}
+ //// or a short one
+ //else
+ //{
+ //}
}
// Or we have a floating argument
else
void OPTS_ParseShortOption( StreamContext_T* ctx )
{
+ // Get Config
+ // if( current != ' ' )
+ // {
+ // Get Config
+ // if( config != NULL )
+ // {
+ // Save option
+ // if( has arg )
+ // {
+ // Save arg
+ // }
+ // Add option to list
+ // }
+ // else
+ // {
+ // Exit: "Unknown option: %c\n"
+ // }
+ // }
}
void OPTS_ParseLongOption( StreamContext_T* ctx )
{
}
+OptionConfig_T* OPTS_GetOptConfig( OptionConfig_T* opts, OptionType_T typ, char* name )
+{
+ OptionConfig_T* cfg = NULL;
+ int i = 0;
+ while( opts[i].type != END )
+ {
+ if( (opts[i].type == typ) && (0 == strcmp(opts[i].name, name)) )
+ {
+ cfg = &(opts[i]);
+ break;
+ }
+ i++;
+ }
+ return cfg;
+}
+
char* OPTS_NextToken( StreamContext_T* ctx )
{
char* tok = NULL;
void OPTS_ParseArgument( StreamContext_T* ctx );
+OptionConfig_T* OPTS_GetOptConfig( OptionConfig_T* opts, OptionType_T typ, char* name );
+
char* OPTS_NextToken( StreamContext_T* ctx );
char OPTS_NextCharacter( StreamContext_T* ctx );
// free(results);
//}
+
+ //-------------------------------------------------------------------------
+ // Test GetOptConfig Function
+ //-------------------------------------------------------------------------
+ TEST(Verify_GetOptConfig_Can_Retrieve_A_Short_Config_By_Name_And_Type)
+ {
+ OptionConfig_T* result = NULL;
+ result = OPTS_GetOptConfig( Options_Config, SHORT, "a" );
+ CHECK( result == &(Options_Config[0]) );
+ }
+
+ TEST(Verify_GetOptConfig_Can_Retrieve_A_Long_Config_By_Name_And_Type)
+ {
+ OptionConfig_T* result = NULL;
+ result = OPTS_GetOptConfig( Options_Config, LONG, "foo" );
+ CHECK( result == &(Options_Config[2]) );
+ }
+
+ TEST(Verify_GetOptConfig_Returns_Null_If_No_Config_Found)
+ {
+ OptionConfig_T* result = NULL;
+ result = OPTS_GetOptConfig( Options_Config, LONG, "baz" );
+ CHECK( result == NULL );
+ }
+
+ TEST(Verify_GetOptConfig_Returns_Null_If_Config_List_Empty)
+ {
+ OptionConfig_T config[] = {
+ { END, NULL, NULL, 0, NULL }
+ };
+ OptionConfig_T* result = NULL;
+ result = OPTS_GetOptConfig( config, LONG, "foo" );
+ CHECK( result == NULL );
+ }
+
//-------------------------------------------------------------------------
// Test NextToken Function
//-------------------------------------------------------------------------