Loading lib_util/cmdln_parser.c +15 −13 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> #include <stdint.h> #define MAX_SUPPORTED_OPTS ( 1024 ) #define MAX_OPTION_MATCH_LENGTH ( 30 ) Loading @@ -46,7 +48,7 @@ typedef CmdLnParser_Option OptionProps; typedef struct { OptionProps props; int8_t hasBeenParsed; bool hasBeenParsed; } Option; static int16_t validateNoDuplicateIds( Loading Loading @@ -114,7 +116,7 @@ static int16_t initOpts( } Option tmp = { .hasBeenParsed = 0 .hasBeenParsed = false }; tmp.props = options[i]; /* Cannot assign in aggregate initializer above - causes Visual Studio warning */ Loading @@ -130,30 +132,30 @@ static int16_t initOpts( return 0; } static int8_t stringLooksLikeOption( static bool stringLooksLikeOption( const char *str ) { if ( ( str[0] == '-' ) && !is_number( str ) ) { return 1; return true; } return 0; return false; } static int8_t optionMatchesString( static bool optionMatchesString( Option opt, const char *str ) { if ( !stringLooksLikeOption( str ) ) { return 0; return false; } if ( strnlen( str, MAX_OPTION_LENGTH + 1 ) > MAX_OPTION_LENGTH ) { /* String longer than longest possible option - not a match */ return 0; return false; } char str_to_upper[MAX_OPTION_LENGTH + 1]; Loading @@ -165,7 +167,7 @@ static int8_t optionMatchesString( to_upper( match_to_upper ); if ( strcmp( str_to_upper, match_to_upper ) == 0 ) { return 1; return true; } if ( opt.props.matchShort != NULL ) Loading @@ -175,11 +177,11 @@ static int8_t optionMatchesString( if ( strcmp( str_to_upper, match_to_upper ) == 0 ) { return 1; return true; } } return 0; return false; } static int16_t parseOpts( Loading Loading @@ -257,7 +259,7 @@ static int16_t parseOpts( { return -1; } currOpt->hasBeenParsed = 1; currOpt->hasBeenParsed = true; } currOpt = nextOpt; Loading @@ -275,7 +277,7 @@ static int16_t parseOpts( { return -1; } currOpt->hasBeenParsed = 1; currOpt->hasBeenParsed = true; } /* Check mandatory options */ Loading Loading
lib_util/cmdln_parser.c +15 −13 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> #include <stdint.h> #define MAX_SUPPORTED_OPTS ( 1024 ) #define MAX_OPTION_MATCH_LENGTH ( 30 ) Loading @@ -46,7 +48,7 @@ typedef CmdLnParser_Option OptionProps; typedef struct { OptionProps props; int8_t hasBeenParsed; bool hasBeenParsed; } Option; static int16_t validateNoDuplicateIds( Loading Loading @@ -114,7 +116,7 @@ static int16_t initOpts( } Option tmp = { .hasBeenParsed = 0 .hasBeenParsed = false }; tmp.props = options[i]; /* Cannot assign in aggregate initializer above - causes Visual Studio warning */ Loading @@ -130,30 +132,30 @@ static int16_t initOpts( return 0; } static int8_t stringLooksLikeOption( static bool stringLooksLikeOption( const char *str ) { if ( ( str[0] == '-' ) && !is_number( str ) ) { return 1; return true; } return 0; return false; } static int8_t optionMatchesString( static bool optionMatchesString( Option opt, const char *str ) { if ( !stringLooksLikeOption( str ) ) { return 0; return false; } if ( strnlen( str, MAX_OPTION_LENGTH + 1 ) > MAX_OPTION_LENGTH ) { /* String longer than longest possible option - not a match */ return 0; return false; } char str_to_upper[MAX_OPTION_LENGTH + 1]; Loading @@ -165,7 +167,7 @@ static int8_t optionMatchesString( to_upper( match_to_upper ); if ( strcmp( str_to_upper, match_to_upper ) == 0 ) { return 1; return true; } if ( opt.props.matchShort != NULL ) Loading @@ -175,11 +177,11 @@ static int8_t optionMatchesString( if ( strcmp( str_to_upper, match_to_upper ) == 0 ) { return 1; return true; } } return 0; return false; } static int16_t parseOpts( Loading Loading @@ -257,7 +259,7 @@ static int16_t parseOpts( { return -1; } currOpt->hasBeenParsed = 1; currOpt->hasBeenParsed = true; } currOpt = nextOpt; Loading @@ -275,7 +277,7 @@ static int16_t parseOpts( { return -1; } currOpt->hasBeenParsed = 1; currOpt->hasBeenParsed = true; } /* Check mandatory options */ Loading