[gcalctool/gcalctool-newui2] ...



commit 33665ef59802883d6df9810920ad3665d3010c9e
Author: Robert Ancell <robert ancell gmail com>
Date:   Fri Sep 25 16:12:21 2009 +1000

    ...

 data/gcalctool.ui        |   16 +++++++++-------
 src/display.c            |   39 ++++++++++-----------------------------
 src/gtk.c                |   17 ++++++++++-------
 src/mp-binary.c          |   26 ++++++++++++++++++++++++++
 src/mp-equation-parser.y |   28 +++++-----------------------
 src/mp-equation.h        |    2 --
 src/mp-trigonometric.c   |    9 +++++++--
 src/mp.c                 |   10 ++++++++++
 8 files changed, 77 insertions(+), 70 deletions(-)
---
diff --git a/data/gcalctool.ui b/data/gcalctool.ui
index 56e831a..4ed75e7 100644
--- a/data/gcalctool.ui
+++ b/data/gcalctool.ui
@@ -215,6 +215,7 @@
                             <property name="pixels_above_lines">8</property>
                             <property name="pixels_below_lines">2</property>
                             <property name="editable">False</property>
+                            <property name="wrap_mode">word</property>
                             <property name="justification">right</property>
                             <property name="right_margin">6</property>
                             <property name="buffer">display_buffer</property>
@@ -243,6 +244,7 @@
                             <property name="buffer">info_buffer</property>
                           </object>
                           <packing>
+                            <property name="expand">False</property>
                             <property name="position">1</property>
                           </packing>
                         </child>
@@ -254,7 +256,6 @@
             </child>
           </object>
           <packing>
-            <property name="expand">False</property>
             <property name="position">1</property>
           </packing>
         </child>
@@ -2745,7 +2746,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
-                    <property name="tooltip_text" translatable="yes" comments="Tooltip for the natural logarithm button">Natural logarithm</property>		    
+                    <property name="tooltip_text" translatable="yes" comments="Tooltip for the natural logarithm button">Natural logarithm</property>
                     <property name="border_width">3</property>
                     <property name="use_underline">True</property>
                     <property name="focus_on_click">False</property>
@@ -2792,7 +2793,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
-                    <property name="tooltip_text" translatable="yes" comments="Tooltip for the absolute value button">Absolute value [|]</property>		    
+                    <property name="tooltip_text" translatable="yes" comments="Tooltip for the absolute value button">Absolute value [|]</property>
                     <property name="border_width">3</property>
                     <property name="use_underline">True</property>
                     <property name="focus_on_click">False</property>
@@ -2935,7 +2936,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
-                    <property name="tooltip_text" translatable="yes" comments="Tooltip for the subscript mode button">Subscipt number mode</property>
+                    <property name="tooltip_text" translatable="yes" comments="Tooltip for the subscript mode button">Subscipt number mode [Alt+number]</property>
                     <property name="border_width">3</property>
                     <property name="focus_on_click">False</property>
                     <signal name="clicked" handler="set_subscript_cb"/>
@@ -2962,7 +2963,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
-                    <property name="tooltip_text" translatable="yes" comments="Tooltip for the superscript mode button">Superscipt number mode</property>
+                    <property name="tooltip_text" translatable="yes" comments="Tooltip for the superscript mode button">Superscipt number mode [Ctrl+number]</property>
                     <property name="border_width">3</property>
                     <property name="focus_on_click">False</property>
                     <signal name="clicked" handler="set_superscript_cb"/>
@@ -3214,7 +3215,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
-                    <property name="tooltip_text" translatable="yes" comments="Tooltip for the ones&apos; complement button">Ones&apos; complement</property>
+                    <property name="tooltip_text" translatable="yes" comments="Tooltip for the ones' complement button">Ones' complement</property>
                     <property name="border_width">3</property>
                     <property name="use_underline">True</property>
                     <property name="focus_on_click">False</property>
@@ -3235,7 +3236,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
-                    <property name="tooltip_text" translatable="yes" comments="Tooltip for the two&apos;s complement button">Two&apos;s complement</property>
+                    <property name="tooltip_text" translatable="yes" comments="Tooltip for the two's complement button">Two's complement</property>
                     <property name="border_width">3</property>
                     <property name="use_underline">True</property>
                     <property name="focus_on_click">False</property>
@@ -3957,6 +3958,7 @@
             </child>
           </object>
           <packing>
+            <property name="expand">False</property>
             <property name="position">3</property>
           </packing>
         </child>
diff --git a/src/display.c b/src/display.c
index 0a66b1c..1b7c714 100644
--- a/src/display.c
+++ b/src/display.c
@@ -971,46 +971,27 @@ display_do_function(GCDisplay *display, int function, int arg, int cursor_start,
                         display_set_answer(display);
                         break;
 
-                    case -PARSER_ERR_BITWISEOP:
-                        /* Translators: Error displayed to user when they
-                         * perform an invalid bitwise operation, e.g.
-                         * 1 XOR -1 */
-                        message = _("Invalid bitwise operation");
-                        break;
-
-                    case -PARSER_ERR_MODULUSOP:
-                        /* Translators: Error displayed to user when they
-                         * perform an invalid modulus operation, e.g.
-                         * 6 MOD 1.2 */
-                        message = _("Invalid modulus operation");
-                        break;
-
                     case -PARSER_ERR_OVERFLOW:
-                        /* Translators; Error displayd to user when they
-                         * perform a bitwise operation on numbers greater
-                         * than the current word */
-                       message = _("Overflow. Try a bigger word size");
-                       break;
+                        /* Translators: Error displayed to user when they perform a bitwise operation on numbers greater than the current word */
+                        message = _("Overflow. Try a bigger word size");
+                        break;
 
                     case -PARSER_ERR_UNKNOWN_VARIABLE:
-                        /* Translators; Error displayd to user when they
-                         * an unknown variable is entered */
-                       message = _("Unknown variable");
-                       break;
+                        /* Translators: Error displayed to user when they an unknown variable is entered */
+                        message = _("Unknown variable");
+                        break;
 
                     case -PARSER_ERR_UNKNOWN_FUNCTION:
-                        /* Translators; Error displayd to user when they
-                         * an unknown function is entered */
-                       message = _("Unknown function");
-                       break;
+                        /* Translators: Error displayed to user when an unknown function is entered */
+                        message = _("Function '%s' is not defined");
+                        break;
 
                     case -PARSER_ERR_MP:
                         message = mp_get_error();
                         break;
 
                     default:
-                        /* Translators: Error displayed to user when they
-                         * enter an invalid calculation */
+                        /* Translators: Error displayed to user when they enter an invalid calculation */
                         message = _("Malformed expression");
                         break;
                 }
diff --git a/src/gtk.c b/src/gtk.c
index 0ccfb3e..7bfe074 100644
--- a/src/gtk.c
+++ b/src/gtk.c
@@ -544,8 +544,7 @@ about_cb(GtkWidget *widget)
     const gchar *translator_credits = _("translator-credits");
 
     /* Translators: The license this software is under (GPL2+) */
-    char *license =
-        _("Gcalctool is free software; you can redistribute it and/or modify\n"
+    char *license = _("Gcalctool is free software; you can redistribute it and/or modify\n"
           "it under the terms of the GNU General Public License as published by\n"
           "the Free Software Foundation; either version 2 of the License, or\n"
           "(at your option) any later version.\n"
@@ -620,10 +619,13 @@ help_display(void)
     if (error != NULL)
     {
         GtkWidget *d;
+        /* Translators: Error message displayed when unable to launch help browser */
+        const char *message = _("Unable to open help file");
+
         d = gtk_message_dialog_new (GTK_WINDOW (X.main_window),
                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                     GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
-                                    "%s", _("Unable to open help file"));
+                                    "%s", message);
         gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (d),
                                                   "%s", error->message);
         g_signal_connect (d, "response", G_CALLBACK (gtk_widget_destroy), NULL);
@@ -1188,12 +1190,13 @@ redo_cb(GtkWidget *widget)
 static void
 for_each_menu(GtkWidget *widget, gpointer data)
 {
-    /* Find the "Paste" entry and activate it (see bug #317786). */
-    if (strcmp(G_OBJECT_TYPE_NAME(widget), "GtkImageMenuItem") == 0) {  
+    /* Find the "Paste" entry and activate it (see bug #317786).
+     * It is disabled because the GtkEntry is not marked as editable.
+     */
+    if (strcmp(G_OBJECT_TYPE_NAME(widget), "GtkImageMenuItem") == 0) {
         GtkWidget *label = gtk_bin_get_child(GTK_BIN(widget));
 
-        // FIXME: WTF?
-        if (strcmp(gtk_label_get_text(GTK_LABEL(label)), _("Paste")) == 0) {
+         if (strcmp(gtk_label_get_text(GTK_LABEL(label)), _("Paste")) == 0) {
             if (gtk_clipboard_wait_is_text_available(
                         gtk_clipboard_get(X.clipboard_atom))) {
                 gtk_widget_set_sensitive(GTK_WIDGET(widget), TRUE);
diff --git a/src/mp-binary.c b/src/mp-binary.c
index 5992d38..3c382b3 100644
--- a/src/mp-binary.c
+++ b/src/mp-binary.c
@@ -78,6 +78,12 @@ mp_is_overflow (const MPNumber *x, int wordlen)
 void
 mp_and(const MPNumber *x, const MPNumber *y, MPNumber *z)
 {
+    if (!mp_is_natural(x) || !mp_is_natural(y))
+    {
+        /* Translators: Error displayed when boolean AND attempted on non-integer values */
+        mperr(_("Boolean AND only defined for natural numbers"));
+    }
+
     mp_bitwise(x, y, mp_bitwise_and, z, 0);
 }
 
@@ -85,6 +91,12 @@ mp_and(const MPNumber *x, const MPNumber *y, MPNumber *z)
 void
 mp_or(const MPNumber *x, const MPNumber *y, MPNumber *z)
 {
+    if (!mp_is_natural(x) || !mp_is_natural(y))
+    {
+        /* Translators: Error displayed when boolean OR attempted on non-integer values */        
+        mperr(_("Boolean OR only defined for natural numbers"));
+    }
+
     mp_bitwise(x, y, mp_bitwise_or, z, 0);
 }
 
@@ -92,6 +104,12 @@ mp_or(const MPNumber *x, const MPNumber *y, MPNumber *z)
 void
 mp_xor(const MPNumber *x, const MPNumber *y, MPNumber *z)
 {
+    if (!mp_is_natural(x) || !mp_is_natural(y))
+    {
+        /* Translators: Error displayed when boolean XOR attempted on non-integer values */
+        mperr(_("Boolean XOR only defined for natural numbers"));
+    }
+
     mp_bitwise(x, y, mp_bitwise_xor, z, 0);
 }
 
@@ -100,6 +118,13 @@ void
 mp_not(const MPNumber *x, int wordlen, MPNumber *z)
 {
     MPNumber temp;
+    
+    if (!mp_is_natural(x))
+    {
+        /* Translators: Error displayed when boolean XOR attempted on non-integer values */
+        mperr(_("Boolean NOT only defined for natural numbers"));
+    }
+
     mp_set_from_integer(0, &temp);
     mp_bitwise(x, &temp, mp_bitwise_not, z, wordlen);
 }
@@ -126,6 +151,7 @@ mp_shift(const MPNumber *x, int count, MPNumber *z)
     int i, multiplier = 1;
     
     if (!mp_is_integer(x)) {
+        /* Translators: Error displayed when bit shift attempted on non-integer values */
         mperr(_("Shift only possible on integer values"));
         return;
     }
diff --git a/src/mp-equation-parser.y b/src/mp-equation-parser.y
index 42429da..bcf2625 100644
--- a/src/mp-equation-parser.y
+++ b/src/mp-equation-parser.y
@@ -54,32 +54,14 @@ static void get_function(yyscan_t yyscanner, const char *name, const MPNumber *x
         set_error(yyscanner, -PARSER_ERR_UNKNOWN_FUNCTION);
 }
 
-static void do_bitwise(yyscan_t yyscanner, void (*mp_fn)(const MPNumber *x, const MPNumber *y, MPNumber *z), const MPNumber *x, const MPNumber *y, MPNumber *z)
-{
-    if (!mp_is_natural(x) || !mp_is_natural(y))
-	set_error(yyscanner, -PARSER_ERR_BITWISEOP);
-    else
-        mp_fn(x, y, z);
-}
-
 static void do_not(yyscan_t yyscanner, const MPNumber *x, MPNumber *z)
 {
-    if (!mp_is_natural(x)) {
-	set_error(yyscanner, -PARSER_ERR_BITWISEOP);
-    } else if (!mp_is_overflow(x, _mp_equation_get_extra(yyscanner)->options->wordlen)) {
+    if (!mp_is_overflow(x, _mp_equation_get_extra(yyscanner)->options->wordlen)) {
 	set_error(yyscanner, -PARSER_ERR_OVERFLOW);
     }
     mp_not(x, _mp_equation_get_extra(yyscanner)->options->wordlen, z);
 }
 
-static void do_mod(yyscan_t yyscanner, const MPNumber *x, const MPNumber *y, MPNumber *z)
-{
-    if (!mp_is_integer(x) || !mp_is_integer(y)) {
-	set_error(yyscanner, -PARSER_ERR_MODULUSOP);
-    } else {
-        mp_modulus_divide(x, y, z);
-    }
-}
 %}
 
 %pure-parser
@@ -133,7 +115,7 @@ exp:
 | tSUBTRACT exp %prec UNARY_MINUS {mp_invert_sign(&$2, &$$);}
 | tADD tNUMBER %prec UNARY_PLUS {mp_set_from_mp(&$2, &$$);}
 | exp tDIVIDE exp {mp_divide(&$1, &$3, &$$);}
-| exp tMOD exp {do_mod(yyscanner, &$1, &$3, &$$);}
+| exp tMOD exp {mp_modulus_divide(&$1, &$3, &$$);}
 | exp tMULTIPLY exp {mp_multiply(&$1, &$3, &$$);}
 | exp tADD exp '%' %prec PERCENTAGE {mp_add_integer(&$3, 100, &$3); mp_divide_integer(&$3, 100, &$3); mp_multiply(&$1, &$3, &$$);}
 | exp tSUBTRACT exp '%' %prec PERCENTAGE {mp_add_integer(&$3, -100, &$3); mp_divide_integer(&$3, -100, &$3); mp_multiply(&$1, &$3, &$$);}
@@ -141,9 +123,9 @@ exp:
 | exp tSUBTRACT exp {mp_subtract(&$1, &$3, &$$);}
 | exp '%' {mp_divide_integer(&$1, 100, &$$);}
 | tNOT exp {do_not(yyscanner, &$2, &$$);}
-| exp tAND exp %prec BOOLEAN_OPERATOR {do_bitwise(yyscanner, mp_and, &$1, &$3, &$$);}
-| exp tOR exp %prec BOOLEAN_OPERATOR {do_bitwise(yyscanner, mp_or, &$1, &$3, &$$);}
-| exp tXOR exp %prec BOOLEAN_OPERATOR {do_bitwise(yyscanner, mp_xor, &$1, &$3, &$$);}
+| exp tAND exp %prec BOOLEAN_OPERATOR {mp_and(&$1, &$3, &$$);}
+| exp tOR exp %prec BOOLEAN_OPERATOR {mp_or(&$1, &$3, &$$);}
+| exp tXOR exp %prec BOOLEAN_OPERATOR {mp_xor(&$1, &$3, &$$);}
 | tNUMBER {mp_set_from_mp(&$1, &$$);}
 ;
 
diff --git a/src/mp-equation.h b/src/mp-equation.h
index 1a6b585..3787e05 100644
--- a/src/mp-equation.h
+++ b/src/mp-equation.h
@@ -26,8 +26,6 @@
 #include "mp.h"
 
 #define PARSER_ERR_INVALID          1
-#define PARSER_ERR_BITWISEOP        3
-#define PARSER_ERR_MODULUSOP        4
 #define PARSER_ERR_OVERFLOW         5
 #define PARSER_ERR_UNKNOWN_VARIABLE 6
 #define PARSER_ERR_UNKNOWN_FUNCTION 7
diff --git a/src/mp-trigonometric.c b/src/mp-trigonometric.c
index 723ff57..f43a649 100644
--- a/src/mp-trigonometric.c
+++ b/src/mp-trigonometric.c
@@ -314,8 +314,10 @@ mp_asin(const MPNumber *x, MPAngleUnit unit, MPNumber *z)
 
     /* HERE ABS(X) >= 1.  SEE IF X == +-1 */
     mp_set_from_integer(x->sign, &t2);
-    if (!mp_is_equal(x, &t2))
+    if (!mp_is_equal(x, &t2)) {
+        /* Translators: Error displayed when inverse sine value is undefined */
         mperr(_("Inverse sine not defined for values outside [-1, 1]"));
+    }
 
     /* X == +-1 SO RETURN +-PI/2 */
     mp_get_pi(z);
@@ -336,6 +338,7 @@ mp_acos(const MPNumber *x, MPAngleUnit unit, MPNumber *z)
     mp_set_from_integer(-1, &MPn1);
 
     if (mp_is_greater_than(x, &t1) || mp_is_less_than(x, &MPn1)) {
+        /* Translators: Error displayed when inverse cosine value is undefined */
         mperr(_("Inverse cosine not defined for values outside [-1, 1]"));
         mp_set_from_integer(0, z);
     } else if (x->sign == 0) {
@@ -550,7 +553,8 @@ mp_acosh(const MPNumber *x, MPNumber *z)
     /* Check x >= 1 */
     mp_set_from_integer(1, &t);
     if (mp_is_less_than(x, &t)) {
-        mperr(_("Inverse cosine not defined for values less than or equal to one"));
+        /* Translators: Error displayed when inverse hyperbolic cosine value is undefined */
+        mperr(_("Inverse hyperbolic cosine not defined for values less than or equal to one"));
         mp_set_from_integer(0, z);
         return;
     }
@@ -573,6 +577,7 @@ mp_atanh(const MPNumber *x, MPNumber *z)
     mp_set_from_integer(1, &one);
     mp_set_from_integer(-1, &minus_one);
     if (mp_is_greater_equal(x, &one) || mp_is_less_equal(x, &minus_one)) {
+        /* Translators: Error displayed when inverse hyperbolic tangent value is undefined */
         mperr(_("Inverse hyperbolic tangent not defined for values outside [-1, 1]"));
         mp_set_from_integer(0, z);
         return;
diff --git a/src/mp.c b/src/mp.c
index f6370ac..cdc7d48 100644
--- a/src/mp.c
+++ b/src/mp.c
@@ -453,6 +453,7 @@ mp_divide(const MPNumber *x, const MPNumber *y, MPNumber *z)
 
     /* x/0 */
     if (y->sign == 0) {
+        /* Translators: Error displayed attempted to divide by zero */
         mperr(_("Division by zero is not defined"));
         mp_set_from_integer(0, z);
         return;
@@ -489,6 +490,7 @@ mp_divide_integer(const MPNumber *x, int y, MPNumber *z)
 
     /* x/0 */
     if (y == 0) {
+        /* Translators: Error displayed attempted to divide by zero */
         mperr(_("Division by zero is not defined"));
         mp_set_from_integer(0, z);
         return;
@@ -1018,6 +1020,7 @@ mp_ln(const MPNumber *x, MPNumber *z)
     
     /* ln(-x) invalid */
     if (x->sign <= 0) {
+        /* Translators: Error displayed attempted to take logarithm of negative value */
         mperr(_("Logarithm of negative values is undefined"));
         mp_set_from_integer(0, z);
         return;
@@ -1757,6 +1760,7 @@ mp_factorial(const MPNumber *x, MPNumber *z)
         return;
     }
     if (!mp_is_natural(x)) {
+        /* Translators: Error displayed when attempted take the factorial of a fractional number */
         mperr(_("Factorial only defined for natural numbers"));
         return;
     }
@@ -1774,6 +1778,11 @@ mp_modulus_divide(const MPNumber *x, const MPNumber *y, MPNumber *z)
 {
     MPNumber t1, t2;
 
+    if (!mp_is_integer(x) || !mp_is_integer(y)) {
+        /* Translators: Error displayed when attemping to do a modulus division on non-integer numbers */
+        mperr(_("Modulus division only defined for integers"));
+    }
+
     mp_divide(x, y, &t1);
     mp_integer_component(&t1, &t1);
     mp_multiply(&t1, y, &t2);
@@ -1809,6 +1818,7 @@ mp_xpowy_integer(const MPNumber *x, int n, MPNumber *z)
     
     /* 0^-n invalid */
     if (x->sign == 0 && n < 0) {
+        /* Translators: Error displayed when attempted to raise 0 to a negative exponent */
         mperr(_("The power of zero is not defined for a negative exponent"));
         return;
     }



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