FERSAT-ZAD7-PID_Refactoring/Code/main/parser.cpp
PSR_Status_t PSR_Argument_to_int(int *retval, const PSR_Command_t *command) {
    int i;
    int sign;

    /* If there are no arguments */
    if (command->argument_length == 0) {
        return PSR_ERROR;
    }

    i = 0;

    /* Check for sign */
    if (command->argument[i] == '-') {
        sign = -1;
        i++;
    } else {
        sign =  1;
    }

    *retval   = 0;

    /* For every digit */
    for ( ; i<command->argument_length; i++) {
        /* If there is some non-digit char */
        if (!isdigit(command->argument[i] )) {
            return PSR_ERROR;   /* Return Failure */
        }

        *retval = *retval * 10 + (command->argument[i] - '0');
    }

    *retval = *retval * sign;

    return PSR_OK;   /* Return Success */
}
/**
 * @brief               Converts the string type Command argument to integer.
 * 
 * @param retval        Integer type of the argument string
 * @param command       Parser Command with function name and argument.
 * @return PSR_Status_t PSR_OK
 *                      PSR_ERROR
 */
@brief               Converts the string type Command argument to integer.

@param retval        Integer type of the argument string
@param command       Parser Command with function name and argument.
@brief Converts the string type Command argument to integer . @param retval Integer type of the argument string @param command Parser Command with function name and argument .
PSR_Status_t PSR_Argument_to_int(int *retval, const PSR_Command_t *command) {
    int i;
    int sign;
    if (command->argument_length == 0) {
        return PSR_ERROR;
    }
    i = 0;
    if (command->argument[i] == '-') {
        sign = -1;
        i++;
    } else {
        sign =  1;
    }
    *retval   = 0;
    for ( ; i<command->argument_length; i++) {
        if (!isdigit(command->argument[i] )) {
            return PSR_ERROR;   
        }
        *retval = *retval * 10 + (command->argument[i] - '0');
    }
    *retval = *retval * sign;
    return PSR_OK;   
}
PSR_Status_t PSR_Argument_to_int ( int * retval , const PSR_Command_t * command ) { int i ; int sign ; if ( command -> argument_length == 0 ) { return PSR_ERROR ; } i = 0 ; if ( command -> argument [ i ] == ' ' ) { sign = -1 ; i ++ ; } else { sign = 1 ; } * retval = 0 ; for ( ; i < command -> argument_length ; i ++ ) { if ( ! isdigit ( command -> argument [ i ] ) ) { return PSR_ERROR ; } * retval = * retval * 10 + ( command -> argument [ i ] - ' ' ) ; } * retval = * retval * sign ; return PSR_OK ; }
@brief               Converts the string type Command argument to integer.
@brief Converts the string type Command argument to integer .
/* If there are no arguments */ /* Check for sign */ /* For every digit */ /* If there is some non-digit char */ /* Return Failure */ /* Return Success */