From 52b66ee4a84620966636a8fb87c45437a4a04b04 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 31 Dec 1999 20:12:42 -0500 Subject: many small fixes --- string_utils.c | 67 +++++++++++++--------------------------------------------- 1 file changed, 15 insertions(+), 52 deletions(-) (limited to 'string_utils.c') diff --git a/string_utils.c b/string_utils.c index 31ef0ff..1ee96db 100644 --- a/string_utils.c +++ b/string_utils.c @@ -18,18 +18,18 @@ END DESCRIPTION **********************************************************/ void Float_To_Text(int decimal_digits,float number_in, gchar ** text_out) { + g_assert (*text_out == NULL); + if (fabs(number_in)<1.1*smallest_allowed_number) { if (number_in<0.0) { - *text_out = g_strdup("-0.000000000"); - *text_out[decimal_digits+3]=0; + *text_out = g_strdup_printf("-0.%0*d",decimal_digits,0); } else { - *text_out = g_strdup("0.000000000"); - *text_out[decimal_digits+2]=0; + *text_out = g_strdup_printf("0.%0*d",decimal_digits,0); } + return; } - if(*text_out == NULL) *text_out = g_strdup_printf("%.*e", decimal_digits, number_in); - else g_sprintf (*text_out, "%.*e", decimal_digits, number_in); + *text_out = g_strdup_printf("%.*e", decimal_digits, number_in); } @@ -187,54 +187,17 @@ int String_is_it_numeric(char *parameter) /* this function takes a parameter like "1e+6" or "on" and determines if it is numeric or not */ /* it is similar to the Parser_get_unit function */ - int i; - int j; - int is_number; - - is_number=0; - i=0; + // FIXME - replace in calling code with strtof + gchar *testme = g_strdup (parameter); + g_strstrip (parameter); + + char * p; + strtof (testme, &p); + + g_free (testme); - if (isdigit(parameter[0]) || parameter[0]=='+' || parameter[0] == '-' || parameter[0] == '.') { - for (i=1; (i < strlen(parameter)) && isdigit(parameter[i]); ++i) {} - - if (i < strlen(parameter)) - if ( parameter[i]=='.' ) - for (++i; (i < strlen(parameter)) && isdigit(parameter[i]); ++i) {} - - /* suck out spaces */ - while ( (i