diff options
author | root <root@fedora-arm.domain.avtechpulse.com> | 1999-12-31 20:12:42 -0500 |
---|---|---|
committer | root <root@fedora-arm.domain.avtechpulse.com> | 1999-12-31 20:12:42 -0500 |
commit | 52b66ee4a84620966636a8fb87c45437a4a04b04 (patch) | |
tree | b618739c95459df0eaf05f092039b2f15af1743a | |
parent | 08819acf094883c069e7c3088d5da6a9c24c45b8 (diff) |
many small fixes
-rw-r--r-- | error_utils.c | 6 | ||||
-rw-r--r-- | i2c.c | 2 | ||||
-rw-r--r-- | parser.c | 14 | ||||
-rw-r--r-- | string_utils.c | 67 |
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;
}
@@ -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); @@ -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';
}
|