diff options
-rw-r--r-- | parser.c | 1 | ||||
-rw-r--r-- | string_utils.c | 53 |
2 files changed, 45 insertions, 9 deletions
@@ -744,6 +744,7 @@ void Parser_main (char *in, gchar** response, int allow_unrequested_responses) // FIXME
if (error_num) {
g_free (*response);
+ *response = NULL;
queue_error_from_parser(response, error_num);
if (allow_unrequested_responses) {
; // SEND ERROR RESPONSE TO CLIENT NOW!
diff --git a/string_utils.c b/string_utils.c index 1ee96db..cbe310f 100644 --- a/string_utils.c +++ b/string_utils.c @@ -181,23 +181,58 @@ int String_trim_excess_digits(char *parameter) return OK;
}
+
/*----------------------------------------------------------------------------------------------------------*/
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 */
- // FIXME - replace in calling code with strtof
+ int i;
+ int j;
+ int is_number;
+
+ is_number=0;
+ i=0;
+
+
+ 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) {}
- gchar *testme = g_strdup (parameter);
- g_strstrip (parameter);
-
- char * p;
- strtof (testme, &p);
-
- g_free (testme);
+ /* suck out spaces */
+ while ( (i<strlen(parameter)) && (isspace(parameter[i])) ) {
+ for(j=i; j<strlen(parameter); ++j) {
+ parameter[j]=parameter[j+1];
+ }
+ parameter[j]=0;
+ }
+
+ if (i < strlen(parameter))
+ if ( (parameter[i]=='e' && parameter[i+1]=='-')
+ || (parameter[i]=='e' && parameter[i+1]=='+') )
+ for (i+=2; (i < strlen(parameter)) && isdigit(parameter[i]); ++i) {}
+ else if (parameter[i]=='e' && isdigit(parameter[i+1]) )
+ for (i+=2; (i < strlen(parameter)) && isdigit(parameter[i]); ++i) {}
+
+ /* suck out spaces */
+ while ( (i<strlen(parameter)) && (isspace(parameter[i])) ) {
+ for(j=i; j<strlen(parameter); ++j) {
+ parameter[j]=parameter[j+1];
+ }
+ parameter[j]=0;
+ }
+
+ if (i = strlen(parameter)) {
+ is_number=1;
+ parameter[i]=0;
+ }
+ }
- return *p == '\0';
+ return is_number;
}
|