[gcalctool] General tidyups



commit 9912ce6d0c4ef742f0d0527868b0cc74cb55a5c4
Author: Robert Ancell <robert ancell gmail com>
Date:   Tue May 19 12:33:15 2009 +0200

    General tidyups
---
 src/calctool.c   |    2 +-
 src/display.c    |    4 ++--
 src/gtk.c        |    2 ++
 src/mp-binary.c  |    6 +++---
 src/mp-convert.c |    9 +++------
 src/mp.h         |    3 ++-
 src/register.c   |    2 +-
 src/unittest.c   |    2 +-
 8 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/calctool.c b/src/calctool.c
index f940777..1516758 100644
--- a/src/calctool.c
+++ b/src/calctool.c
@@ -95,7 +95,7 @@ solve(const char *equation)
         exit(1);
     }
     else {
-        mp_cast_to_string(&result, basevals[v->base], 9, result_str, MAXLINE);
+        mp_cast_to_string(&result, basevals[v->base], 9, 1, result_str, MAXLINE);
         printf("%s\n", result_str);
         exit(0);
     }
diff --git a/src/display.c b/src/display.c
index 8d029ff..1dbbc1d 100644
--- a/src/display.c
+++ b/src/display.c
@@ -695,7 +695,7 @@ make_eng_sci(GCDisplay *display, char *target, int target_len, const MPNumber *M
         }
     }
  
-    mp_cast_to_string(&MPmant, basevals[base], v->accuracy, fixed, MAX_DIGITS);
+    mp_cast_to_string(&MPmant, basevals[base], v->accuracy, !v->display.show_zeroes, fixed, MAX_DIGITS);
     len = strlen(fixed);
     for (i = 0; i < len; i++) {
         *optr++ = fixed[i];
@@ -766,6 +766,6 @@ display_make_number(GCDisplay *display, char *target, int target_len, const MPNu
         (display->format == FIX && val != 0.0 && (val > max_fix[base]))) {
         make_eng_sci(display, target, target_len, MPnumber, base);
     } else {
-        mp_cast_to_string(MPnumber, basevals[base], v->accuracy, target, target_len);
+        mp_cast_to_string(MPnumber, basevals[base], v->accuracy, !v->display.show_zeroes, target, target_len);
     }
 }
diff --git a/src/gtk.c b/src/gtk.c
index 6ce6b00..698ce5d 100644
--- a/src/gtk.c
+++ b/src/gtk.c
@@ -1621,6 +1621,7 @@ finc_response_cb(GtkWidget *widget, gint response_id)
             continue;
         }
         entry = GET_FINC_WIDGET(finc_dialog_fields[dialog][i]);
+        // FIXME: Have to delocalize the input
         mp_set_from_string(gtk_entry_get_text(GTK_ENTRY(entry)), 10, &arg[i]);
         gtk_entry_set_text(GTK_ENTRY(entry), "0");
     }
@@ -1743,6 +1744,7 @@ edit_constants_response_cb(GtkDialog *dialog, gint id)
                                    COLUMN_NUMBER, &number,
                                    COLUMN_VALUE, &value,
                                    COLUMN_DESCRIPTION, &description, -1);
+                // FIXME: Have to delocalize
                 mp_set_from_string(value, 10, &temp);
                 constant_set(number, description, &temp);
             } while (gtk_tree_model_iter_next(X.constants_model, &iter));
diff --git a/src/mp-binary.c b/src/mp-binary.c
index 8bbf3c7..e9b10b7 100644
--- a/src/mp-binary.c
+++ b/src/mp-binary.c
@@ -22,8 +22,8 @@ mp_bitwise(const MPNumber *x, const MPNumber *y, int (*bitwise_operator)(int, in
     char text1[MAX_DIGITS], text2[MAX_DIGITS], text_out[MAX_DIGITS];
     int offset1, offset2, offset_out;
    
-    mp_cast_to_string(x, 16, 0, text1, MAX_DIGITS);
-    mp_cast_to_string(y, 16, 0, text2, MAX_DIGITS);
+    mp_cast_to_string(x, 16, 0, 0, text1, MAX_DIGITS);
+    mp_cast_to_string(y, 16, 0, 0, text2, MAX_DIGITS);
     offset1 = strlen(text1) - 1;
     offset2 = strlen(text2) - 1;
     offset_out = wordlen / 4 - 1;
@@ -115,7 +115,7 @@ mp_mask(const MPNumber *x, int wordlen, MPNumber *z)
     size_t len, offset;
     
     /* Convert to a hexadecimal string and use last characters */
-    mp_cast_to_string(x, 16, 0, text, MAX_DIGITS);
+    mp_cast_to_string(x, 16, 0, 0, text, MAX_DIGITS);
     len = strlen(text);
     offset = wordlen / 4;
     offset = len > offset ? len - offset: 0;
diff --git a/src/mp-convert.c b/src/mp-convert.c
index c54e1ca..d0e9cf4 100644
--- a/src/mp-convert.c
+++ b/src/mp-convert.c
@@ -27,9 +27,6 @@
 #include "mp.h"
 #include "mp-internal.h"
 
-// FIXME: Needed for v->radix
-#include "calctool.h"
-
 /*  SETS Y = X FOR MP X AND Y.
  *  SEE IF X AND Y HAVE THE SAME ADDRESS (THEY OFTEN DO)
  */
@@ -482,7 +479,7 @@ mp_cast_to_double(const MPNumber *x)
  * maximum number of digits specified.
  */
 void
-mp_cast_to_string(const MPNumber *MPnumber, int base, int accuracy, char *buffer, int buffer_length)
+mp_cast_to_string(const MPNumber *MPnumber, int base, int accuracy, int trim_zeroes, char *buffer, int buffer_length)
 {
     static char digits[] = "0123456789ABCDEF";
     char *optr, *start, *end, *stopper, *last_non_zero;
@@ -571,7 +568,7 @@ mp_cast_to_string(const MPNumber *MPnumber, int base, int accuracy, char *buffer
     }
 
     /* Strip trailing zeroes */
-    if (!v->display.show_zeroes || accuracy == 0)
+    if (trim_zeroes || accuracy == 0)
        optr = last_non_zero;
 
     *optr = '\0';
@@ -634,7 +631,7 @@ mp_set_from_string(const char *str, int base, MPNumber *MPval)
     }
    
     /* Convert fractional part */
-    if (*optr == '.' || *optr == *v->radix) {
+    if (*optr == '.') {
         MPNumber numerator, denominator;
        
         optr++;
diff --git a/src/mp.h b/src/mp.h
index afb1f86..36a14c4 100644
--- a/src/mp.h
+++ b/src/mp.h
@@ -206,9 +206,10 @@ int    mp_cast_to_int(const MPNumber *x);
  * The string is written into 'buffer' which is guaranteed to be at least 'buffer_length' octets in size.
  * If not enough space is available the string is truncated.
  * The numbers are written in 'base' (e.g. 10).
+ * If 'trim_zeroes' is non-zero then strip off trailing zeroes.
  * Fractional components are truncated at 'max_digits' digits.
  */
-void   mp_cast_to_string(const MPNumber *x, int base, int max_digits, char *buffer, int buffer_length);
+void   mp_cast_to_string(const MPNumber *x, int base, int max_digits, int trim_zeroes, char *buffer, int buffer_length);
 
 /* Sets z = sin(x) */
 void   mp_sin(const MPNumber *x, MPAngleUnit unit, MPNumber *z);
diff --git a/src/register.c b/src/register.c
index f117821..8a8ff8c 100644
--- a/src/register.c
+++ b/src/register.c
@@ -153,7 +153,7 @@ void constant_set(int index, const char *name, MPNumber *value)
 
     /* NOTE: Constants are written out with no thousands separator and with a
        radix character of ".". */
-    mp_cast_to_string(value, 10, MAX_DIGITS, text, MAX_LOCALIZED);
+    mp_cast_to_string(value, 10, MAX_DIGITS, 1, text, MAX_LOCALIZED);
     SNPRINTF(key, MAXLINE, "constant%1dvalue", index);
     set_resource(key, text);
 }
diff --git a/src/unittest.c b/src/unittest.c
index 28d6907..8052a0f 100644
--- a/src/unittest.c
+++ b/src/unittest.c
@@ -73,7 +73,7 @@ test(char *expression, char *expected, int expected_error)
     error = mp_equation_parse(expression, &result);
 
     if(error == 0) {
-        mp_cast_to_string(&result, basevals[v->base], 9, result_str, MAXLINE);
+        mp_cast_to_string(&result, basevals[v->base], 9, 1, result_str, MAXLINE);
         if(expected_error != 0)
             fail("'%s' -> %s, expected error %d", expression, result_str, expected_error);
         else if(strcmp(result_str, expected) != 0)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]