scp_result resolve_numbers_1_2(const sc_char *operator_name, scp_operand *param1, scp_operand *param2, double *num1, double *num2)
{
    sc_stream *stream;
    sc_uint32 length = 0, read_length = 0;
    sc_char *data1, *data2;
    if (SCP_ASSIGN == param1->param_type || SCP_ASSIGN == param2->param_type)
    {
        return print_error(operator_name, "Both parameters must have FIXED modifier");
    }
    if (SC_FALSE == sc_memory_is_element(param1->addr))
    {
        return print_error(operator_name, "Parameter 1 has not value");
    }
    if (SC_FALSE == sc_memory_is_element(param2->addr))
    {
        return print_error(operator_name, "Parameter 2 has not value");
    }
    if (check_type(param1->addr, scp_type_link) == SCP_RESULT_FALSE || check_type(param2->addr, scp_type_link) == SCP_RESULT_FALSE)
    {
        return print_error(operator_name, "Both parameters must have link type");
    }
    if (SCP_RESULT_FALSE == check_numeric_type(param1->addr) || SCP_RESULT_FALSE == check_numeric_type(param2->addr))
    {
        return print_error(operator_name, "Both parameters must have numeric format");
    }

    if (sc_memory_get_link_content(param1->addr, &stream) != SC_RESULT_OK)
    {
        return print_error(operator_name, "Parameter 1 content reading error");
    }
    sc_stream_get_length(stream, &length);
    data1 = calloc(length, sizeof(sc_char));
    sc_stream_read_data(stream, data1, length, &read_length);
    sc_stream_free(stream);
    if (sc_memory_get_link_content(param2->addr, &stream) != SC_RESULT_OK)
    {
        return print_error(operator_name, "Parameter 2 content reading error");
    }
    sc_stream_get_length(stream, &length);
    data2 = calloc(length, sizeof(sc_char));
    sc_stream_read_data(stream, data2, length, &read_length);
    sc_stream_free(stream);

    (*num1) = atof(data1);
    (*num2) = atof(data2);
    free(data1);
    free(data2);
    return SCP_RESULT_TRUE;
}
Example #2
0
scp_result resolve_number(sc_memory_context *context, const sc_char *operator_name, const sc_char *parameter_name, scp_operand *param, double *num)
{
    sc_stream *stream;
    sc_uint32 length = 0, read_length = 0;
    sc_char *data1;

    if (SCP_ASSIGN == param->param_type)
    {
        return print_parameter_error(operator_name, parameter_name, "must have FIXED modifier");
    }

    if (SC_FALSE == sc_memory_is_element(context, param->addr))
    {
        return print_parameter_error(operator_name, parameter_name, "has not value");
    }

    if (SCP_RESULT_FALSE == check_type(context, param->addr, scp_type_link))
    {
        return print_parameter_error(operator_name, parameter_name, "must have link type");
    }

    if (SCP_RESULT_FALSE == check_numeric_type(context, param->addr))
    {
        return print_parameter_error(operator_name, parameter_name, "must have numeric format");
    }

    if (SC_RESULT_OK != sc_memory_get_link_content(context, param->addr, &stream))
    {
        return print_parameter_error(operator_name, parameter_name, "content reading error");
    }

    sc_stream_get_length(stream, &length);
    data1 = calloc(length, sizeof(sc_char));
    sc_stream_read_data(stream, data1, length, &read_length);
    sc_stream_free(stream);

    *num = atof(data1);
    free(data1);

    return SCP_RESULT_TRUE;
}