Commit 8e4664ea authored by sagnowski's avatar sagnowski
Browse files

CmdLnParser: Use bool where appropriate

parent 003cbb53
Loading
Loading
Loading
Loading
+15 −13
Original line number Diff line number Diff line
@@ -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 )
@@ -46,7 +48,7 @@ typedef CmdLnParser_Option OptionProps;
typedef struct
{
    OptionProps props;
    int8_t hasBeenParsed;
    bool hasBeenParsed;
} Option;

static int16_t validateNoDuplicateIds(
@@ -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 */

@@ -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];
@@ -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 )
@@ -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(
@@ -257,7 +259,7 @@ static int16_t parseOpts(
                {
                    return -1;
                }
                currOpt->hasBeenParsed = 1;
                currOpt->hasBeenParsed = true;
            }

            currOpt = nextOpt;
@@ -275,7 +277,7 @@ static int16_t parseOpts(
        {
            return -1;
        }
        currOpt->hasBeenParsed = 1;
        currOpt->hasBeenParsed = true;
    }

    /* Check mandatory options */