summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parser.c2
-rw-r--r--response.c2
-rw-r--r--string_utils.c149
-rw-r--r--string_utils.h1
4 files changed, 1 insertions, 153 deletions
diff --git a/parser.c b/parser.c
index a39fcce..5236250 100644
--- a/parser.c
+++ b/parser.c
@@ -686,8 +686,6 @@ void Parser_main (char *in, int interactive_terminal, void(*cbfunc)(gpointer, gc
if (parameter_found) {
units_found = Parser_get_unit(parameter,units);
- error_num=String_trim_excess_digits(parameter);
- error_num=String_trim_excess_digits(units);
}
if (!error_num) {
diff --git a/response.c b/response.c
index 52cf944..166cd6a 100644
--- a/response.c
+++ b/response.c
@@ -71,7 +71,7 @@ gboolean cbClientInput(gpointer data, gpointer additional)
}
if(size <= 0) {
- g_print_debug("Got: %d\n", size);
+ g_print_debug("Got: %d\n", (int) size);
return FALSE;
}
diff --git a/string_utils.c b/string_utils.c
index 3e3bcbb..a406663 100644
--- a/string_utils.c
+++ b/string_utils.c
@@ -33,155 +33,6 @@ void Float_To_Text(int decimal_digits,float number_in, gchar ** text_out)
}
-int String_trim_excess_digits(char *parameter)
-{
- /* this function takes a parameter like "1.2345678901234567890" and reduces it to "1.234567" */
- /* so that atof() will work properly */
-
- gchar* new_string = g_strdup(parameter);
- memset(new_string, 0, strlen(parameter));
-
- int i;
- int j;
- int sig_digits; /* number of significant digits so far */
- long exp_power; /* append an exponent of this power */
- int sign; /* is the exponent negative? */
- int start_of_exponent; /* location of exponent */
-
- i=0; /* location in input string */
- j=0; /* location in output string */
- sig_digits=0;
- exp_power=0;
- sign=NO;
-
-#define max_sig_dig 8
-
- if (!(isdigit(parameter[0]) || parameter[0]=='+' || parameter[0]=='-' || parameter[0]=='.')) {
- return OK;
- }
-
- /* take care of sign */
- if (parameter[0]=='+' || parameter[0]=='-') {
- new_string[j]=parameter[i];
- ++i;
- ++j;
- }
-
- /* leave in leading zeros */
- while (parameter[i]=='0') {
- new_string[j]=parameter[i];
- ++i;
- ++j;
- }
-
- /* leave in up to 8 pre-decimal significant digits */
- while (isdigit(parameter[i]) && sig_digits<max_sig_dig) {
- new_string[j]=parameter[i];
- ++i;
- ++j;
- ++sig_digits;
- }
-
- /* if there are remaining digits, truncate and add exponent, and then return immediately */
- while (isdigit(parameter[i]) && sig_digits==max_sig_dig) {
- ++i;
- ++exp_power;
- }
- if (exp_power>0) {
- strcat(new_string+j,"e");
-
- //replaced itoa (non standard) with sprintf
- char temp[64];
- memset(temp, 0, 64);
- sprintf(temp, "%ld", exp_power);
-
- strcat(new_string,temp);
-
- strcpy(parameter,new_string);
- if (exp_power<38) {
- return OK;
- } else {
- return OutOfRange;
- }
- }
-
- /* leave in decimal point */
- if (parameter[i]=='.') {
- new_string[j]=parameter[i];
- ++i;
- ++j;
- }
-
- /* leave in post-decimal zeros if no significant digits yet */
- while (parameter[i]=='0' && sig_digits==0) {
- new_string[j]=parameter[i];
- ++i;
- ++j;
- }
-
- /* leave in up to 8 post-decimal significant digits */
- while (isdigit(parameter[i]) && sig_digits<max_sig_dig) {
- new_string[j]=parameter[i];
- ++i;
- ++j;
- ++sig_digits;
- }
-
- /* skip extraneous post-decimal digits */
- while (isdigit(parameter[i]) && sig_digits==max_sig_dig) {
- ++i;
- }
-
- if (parameter[i]=='e') {
- new_string[j]=parameter[i];
- ++i;
- ++j;
-
- if (parameter[i]=='+') {
- sign=NO;
- new_string[j]=parameter[i];
- ++i;
- ++j;
- } else if (parameter[i]=='-') {
- sign=YES;
- new_string[j]=parameter[i];
- ++i;
- ++j;
- }
-
- if (i<strlen(parameter) && isdigit(parameter[i])) {
- start_of_exponent=j;
- new_string[j]=parameter[i];
- ++i;
- ++j;
- }
-
- while (i<strlen(parameter) && isdigit(parameter[i])) {
- new_string[j]=parameter[i];
- ++i;
- ++j;
- }
-
- new_string[j]=0;
- exp_power=atol(new_string+start_of_exponent);
-
- if (exp_power>37 && sign==NO) {
- g_free(new_string);
- return OutOfRange;
- }
- if (exp_power>37 && sign==YES) {
- strcpy(new_string,"0.0");
- }
- }
-
- new_string[j]=0;
-
- strcpy(parameter,new_string);
- g_free(new_string);
- return OK;
-}
-
-
/*----------------------------------------------------------------------------------------------------------*/
gboolean String_is_it_numeric(char *parameter) {
diff --git a/string_utils.h b/string_utils.h
index 33f9239..9cb8c4f 100644
--- a/string_utils.h
+++ b/string_utils.h
@@ -6,7 +6,6 @@
#define smallest_allowed_number 1.0e-18
void Float_To_Text(int decimal_digits,float number_in, gchar** text_out);
-int String_trim_excess_digits(char *parameter);
gboolean String_is_it_numeric(char *parameter);
#endif