summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--error_utils.c6
-rw-r--r--i2c.c2
-rw-r--r--parser.c14
-rw-r--r--string_utils.c67
4 files changed, 26 insertions, 63 deletions
diff --git a/error_utils.c b/error_utils.c
index 68c8b93..2c48aba 100644
--- a/error_utils.c
+++ b/error_utils.c
@@ -91,7 +91,8 @@ void queue_error(int error_num)
/*----------------------------------------------------------------------------------------------------------*/
void queue_error_and_get_text(gchar** response, int error_num)
{
- *response[0]=0;
+ g_assert (*response == NULL);
+
if (error_num == OK) {
return;
}
@@ -103,7 +104,8 @@ void queue_error_and_get_text(gchar** response, int error_num)
/*----------------------------------------------------------------------------------------------------------*/
void queue_error_from_parser(gchar** response, int error_num)
{
- *response[0]=0;
+ g_assert (*response == NULL);
+
if (error_num == OK) {
return;
}
diff --git a/i2c.c b/i2c.c
index 4c1499d..9dc4fe9 100644
--- a/i2c.c
+++ b/i2c.c
@@ -43,7 +43,7 @@ guchar I2C_Read(gulong address) {
int device = open(I2C_BUS, O_RDWR);
- if (device == -1) return device;
+ if (device == -1) return 0;
ioctl(device, I2C_SLAVE, address);
ioctl(device, I2C_SMBUS, &argsread);
diff --git a/parser.c b/parser.c
index eb97868..c425a98 100644
--- a/parser.c
+++ b/parser.c
@@ -743,15 +743,13 @@ void Parser_main (char *in, gchar** response, int allow_unrequested_responses, i
// int control_mode = 0; //CUSTOM
- if (response[0]) {
- // IO_output_to_comm_bus(response,control_mode);
-
-
- }
-
- if (*error_num) {
+// FIXME
+ if (*error_num) {
+ g_free (*response);
queue_error_from_parser(response, *error_num);
- }
+ } // else {
+// IO_output_to_comm_bus(response,control_mode);
+// }
if (!is_query) {
Main_update_shift_registers(); /* update values in pulse generator circuit */
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<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 is_number;
+ return *p == '\0';
}