From: Uwe Hermann Date: Sat, 24 Oct 2015 19:14:50 +0000 (+0200) Subject: Drop unneeded sr_analog_float_to_string(). X-Git-Tag: libsigrok-0.4.0~194 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=222fdfd526fde6d8450067675679eca6cc5d211b;p=libsigrok.git Drop unneeded sr_analog_float_to_string(). A simple g_strdup_printf() is sufficient, no need for an extra libsigrok API call here. --- diff --git a/include/libsigrok/proto.h b/include/libsigrok/proto.h index c0d40b94..069e7e84 100644 --- a/include/libsigrok/proto.h +++ b/include/libsigrok/proto.h @@ -30,8 +30,6 @@ SR_API int sr_analog_to_float(const struct sr_datafeed_analog *analog, float *buf); -SR_API int sr_analog_float_to_string(float value, unsigned int digits, - char **result); SR_API int sr_analog_unit_to_string(const struct sr_datafeed_analog *analog, char **result); SR_API void sr_rational_set(struct sr_rational *r, int64_t p, uint64_t q); diff --git a/src/analog.c b/src/analog.c index e4521689..8d87302a 100644 --- a/src/analog.c +++ b/src/analog.c @@ -220,44 +220,6 @@ SR_API int sr_analog_to_float(const struct sr_datafeed_analog *analog, return SR_OK; } -/** - * Convert a floating point value to a string, limited to the given - * number of decimal digits. - * - * @param[in] value The value to convert. - * @param[in] digits Number of digits after the decimal point to print. - * Must be >= 0. - * @param[out] result Pointer to store result. Must not be NULL. - * - * The string is allocated by the function and must be freed by the caller - * after use by calling g_free(). - * - * @retval SR_OK Success. - * @retval SR_ERR_ARG Invalid argument. - * - * @since 0.4.0 - */ -SR_API int sr_analog_float_to_string(float value, unsigned int digits, char **result) -{ - unsigned int cnt, i; - - if (!result) - return SR_ERR_ARG; - - /* This produces at least one too many digits. */ - *result = g_strdup_printf("%.*f", digits, value); - for (i = 0, cnt = 0; (*result)[i]; i++) { - if (isdigit((*result)[i++])) - cnt++; - if (cnt == digits) { - (*result)[i] = 0; - break; - } - } - - return SR_OK; -} - /** * Convert the unit/MQ/MQ flags in the analog struct to a string. * diff --git a/src/output/analog.c b/src/output/analog.c index 4535ed5c..88b85d18 100644 --- a/src/output/analog.c +++ b/src/output/analog.c @@ -336,8 +336,8 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p for (l = analog->meaning->channels, c = 0; l; l = l->next, c++) { ch = l->data; g_string_append_printf(*out, "%s: ", ch->name); - sr_analog_float_to_string(fdata[i * num_channels + c], - digits, &number); + number = g_strdup_printf("%.*f", digits, + fdata[i * num_channels + c]); g_string_append(*out, number); g_free(number); g_string_append(*out, " "); diff --git a/tests/analog.c b/tests/analog.c index c2c6555c..d193bcbe 100644 --- a/tests/analog.c +++ b/tests/analog.c @@ -124,25 +124,6 @@ START_TEST(test_analog_to_float_null) } END_TEST -#if 0 -START_TEST(test_analog_float_to_string) -{ - int ret; - unsigned int i; - char *result; - const char *r[] = {"3", "3.1", "3.14", "3.145", "3.1415", "3.15159"}; - - for (i = 0; i < ARRAY_SIZE(r); i++) { - ret = sr_analog_float_to_string(G_PI, i, &result); - fail_unless(ret == SR_OK); - fail_unless(result != NULL); - fail_unless(!strcmp(result, r[i]), "%s != %s", result, r[i]); - g_free(result); - } -} -END_TEST -#endif - START_TEST(test_analog_float_to_string_null) { int ret; @@ -234,9 +215,6 @@ Suite *suite_analog(void) tc = tcase_create("analog_to_float"); tcase_add_test(tc, test_analog_to_float); tcase_add_test(tc, test_analog_to_float_null); -#if 0 - tcase_add_test(tc, test_analog_float_to_string); -#endif tcase_add_test(tc, test_analog_float_to_string_null); tcase_add_test(tc, test_analog_unit_to_string); tcase_add_test(tc, test_analog_unit_to_string_null);