gcalctool r2158 - trunk/gcalctool



Author: rancell
Date: Sat Aug  9 06:35:17 2008
New Revision: 2158
URL: http://svn.gnome.org/viewvc/gcalctool?rev=2158&view=rev

Log:
Streamline display code

Modified:
   trunk/gcalctool/ce_tokeniser.l
   trunk/gcalctool/display.c
   trunk/gcalctool/display.h
   trunk/gcalctool/functions.c
   trunk/gcalctool/functions.h
   trunk/gcalctool/gtk.c
   trunk/gcalctool/mpmath.c
   trunk/gcalctool/mpmath.h
   trunk/gcalctool/ui.h

Modified: trunk/gcalctool/ce_tokeniser.l
==============================================================================
--- trunk/gcalctool/ce_tokeniser.l	(original)
+++ trunk/gcalctool/ce_tokeniser.l	Sat Aug  9 06:35:17 2008
@@ -105,7 +105,7 @@
 {DEC_NUM}{EXP}{DEC_NUM} {
 if (v->base == HEX) REJECT;
 if (strlen(yytext) > MAX_DIGITS) parser_state.error = -PARSER_ERR_TOO_LONG_NUMBER;
-make_exp(yytext, celval.int_t);
+mp_set_from_string(yytext, celval.int_t);
 return tNUMBER;
 }
 

Modified: trunk/gcalctool/display.c
==============================================================================
--- trunk/gcalctool/display.c	(original)
+++ trunk/gcalctool/display.c	Sat Aug  9 06:35:17 2008
@@ -1,6 +1,7 @@
 /*  $Header$
  *
  *  Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
+ *  Copyright (c) 2008 Robert Ancell
  *           
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by

Modified: trunk/gcalctool/display.h
==============================================================================
--- trunk/gcalctool/display.h	(original)
+++ trunk/gcalctool/display.h	Sat Aug  9 06:35:17 2008
@@ -1,6 +1,7 @@
 /*  $Header$
  *
  *  Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
+ *  Copyright (c) 2008 Robert Ancell
  *           
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by

Modified: trunk/gcalctool/functions.c
==============================================================================
--- trunk/gcalctool/functions.c	(original)
+++ trunk/gcalctool/functions.c	Sat Aug  9 06:35:17 2008
@@ -2,6 +2,7 @@
 /*  $Header$
  *
  *  Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
+ *  Copyright (c) 2008 Robert Ancell
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -35,40 +36,6 @@
 #include "ce_parser.h"
 #include "ui.h"
 
-void
-make_exp(char *number, int t[MP_SIZE])
-{
-    int i;
-    char *a = NULL;
-    char *b = NULL;
-
-    int MP_a[MP_SIZE];
-    int MP_b[MP_SIZE];
-
-    assert(number);
-    a = strdup(number);
-    assert(a);
-
-    for (i = 0; !((a[i] == 'e') || (a[i] == 'E')); i++) {
-        assert(a[i]);
-    }
-
-    a[i] = 0;
-    b = &a[i+2];
-
-    MPstr_to_num(a, v->base, MP_a);
-    MPstr_to_num(b, v->base, MP_b);
-    if (a[i+1] == '-') {
-        int MP_c[MP_SIZE];
-        mp_invert_sign(MP_b, MP_c);
-        calc_xtimestenpowx(MP_a, MP_c, t);
-    } else {
-        calc_xtimestenpowx(MP_a, MP_b, t);
-    }
-
-    free(a);
-}
-
 
 static void
 clear_undo_history(void)

Modified: trunk/gcalctool/functions.h
==============================================================================
--- trunk/gcalctool/functions.h	(original)
+++ trunk/gcalctool/functions.h	Sat Aug  9 06:35:17 2008
@@ -1,7 +1,8 @@
 
 /*  $Header$
  *
- *  Copyright (C) 2004-2008 Sami Pietila
+ *  Copyright (c) 2004-2008 Sami Pietila
+ *  Copyright (c) 2008 Robert Ancell
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -27,7 +28,6 @@
 void do_expression(int function, int arg, int cursor);
 
 // FIXME: Not functions
-void make_exp(char *number, int t[MP_SIZE]);
 void do_rcl_reg(int reg, int value[MP_SIZE]);
 void do_sto_reg(int reg, int value[MP_SIZE]);
 

Modified: trunk/gcalctool/gtk.c
==============================================================================
--- trunk/gcalctool/gtk.c	(original)
+++ trunk/gcalctool/gtk.c	Sat Aug  9 06:35:17 2008
@@ -2,6 +2,7 @@
 /*  $Header$
  *
  *  Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
+ *  Copyright (c) 2008 Robert Ancell
  *           
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by

Modified: trunk/gcalctool/mpmath.c
==============================================================================
--- trunk/gcalctool/mpmath.c	(original)
+++ trunk/gcalctool/mpmath.c	Sat Aug  9 06:35:17 2008
@@ -1090,6 +1090,41 @@
 }
 
 
+void
+mp_set_from_string(char *number, int t[MP_SIZE])
+{
+    int i;
+    char *a = NULL;
+    char *b = NULL;
+
+    int MP_a[MP_SIZE];
+    int MP_b[MP_SIZE];
+
+    assert(number);
+    a = strdup(number);
+    assert(a);
+
+    for (i = 0; !((a[i] == 'e') || (a[i] == 'E')); i++) {
+        assert(a[i]);
+    }
+
+    a[i] = 0;
+    b = &a[i+2];
+
+    MPstr_to_num(a, v->base, MP_a);
+    MPstr_to_num(b, v->base, MP_b);
+    if (a[i+1] == '-') {
+        int MP_c[MP_SIZE];
+        mp_invert_sign(MP_b, MP_c);
+        calc_xtimestenpowx(MP_a, MP_c, t);
+    } else {
+        calc_xtimestenpowx(MP_a, MP_b, t);
+    }
+
+    free(a);
+}
+
+
 /* Calculate the factorial of MPval. */
 void
 calc_factorial(int *MPval, int *MPres)

Modified: trunk/gcalctool/mpmath.h
==============================================================================
--- trunk/gcalctool/mpmath.h	(original)
+++ trunk/gcalctool/mpmath.h	Sat Aug  9 06:35:17 2008
@@ -78,7 +78,9 @@
 int
 is_natural(int MPnum[MP_SIZE]);
 
+// FIXME: These should be merged together
 void MPstr_to_num(const char *, enum base_type, int *);
+void mp_set_from_string(char *number, int t[MP_SIZE]);
 void make_fixed(char *, int, int *, int, int, int);
 void make_number(char *, int, int *, int, int);
 

Modified: trunk/gcalctool/ui.h
==============================================================================
--- trunk/gcalctool/ui.h	(original)
+++ trunk/gcalctool/ui.h	Sat Aug  9 06:35:17 2008
@@ -2,6 +2,7 @@
 /*  $Header$
  *
  *  Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
+ *  Copyright (c) 2008 Robert Ancell
  *           
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by



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