gcalctool r2318 - trunk/gcalctool
- From: rancell svn gnome org
- To: svn-commits-list gnome org
- Subject: gcalctool r2318 - trunk/gcalctool
- Date: Sat, 29 Nov 2008 08:43:32 +0000 (UTC)
Author: rancell
Date: Sat Nov 29 08:43:32 2008
New Revision: 2318
URL: http://svn.gnome.org/viewvc/gcalctool?rev=2318&view=rev
Log:
tidy up
Modified:
trunk/gcalctool/calctool.c
trunk/gcalctool/calctool.h
trunk/gcalctool/functions.c
trunk/gcalctool/gtk.c
trunk/gcalctool/mp.c
trunk/gcalctool/mpmath.c
trunk/gcalctool/register.c
Modified: trunk/gcalctool/calctool.c
==============================================================================
--- trunk/gcalctool/calctool.c (original)
+++ trunk/gcalctool/calctool.c Sat Nov 29 08:43:32 2008
@@ -32,107 +32,14 @@
#include "functions.h"
#include "ui.h"
#include "mpmath.h"
+#include "register.h"
time_t time();
int basevals[4] = { 2, 8, 10, 16 };
/* Calctool variables and options. */
-Vars v;
-
-// FIXME: Sort this list
-/* Note that none of these strings can be translated as the parser expects them to be correct */
-/* id, symname flags */
-struct button buttons[NKEYS] = {
-{ KEY_0, "0", NUMBER },
-{ KEY_1, "1", NUMBER },
-{ KEY_2, "2", NUMBER },
-{ KEY_3, "3", NUMBER },
-{ KEY_4, "4", NUMBER },
-{ KEY_5, "5", NUMBER },
-{ KEY_6, "6", NUMBER },
-{ KEY_7, "7", NUMBER },
-{ KEY_8, "8", NUMBER },
-{ KEY_9, "9", NUMBER },
-{ KEY_A, "A", NUMBER },
-{ KEY_B, "B", NUMBER },
-{ KEY_C, "C", NUMBER },
-{ KEY_D, "D", NUMBER },
-{ KEY_E, "E", NUMBER },
-{ KEY_F, "F", NUMBER },
-{ KEY_NUMERIC_POINT, ".", NUMBER },
-{ KEY_CALCULATE, NULL, 0 },
-{ KEY_CLEAR, NULL, 0 },
-{ KEY_CLEAR_ENTRY, NULL, 0 },
-{ KEY_START_BLOCK, "(", 0 },
-{ KEY_END_BLOCK, ")", 0 },
-{ KEY_ADD, "+", 0 },
-{ KEY_SUBTRACT, "-", 0 },
-{ KEY_MULTIPLY, "*", 0 },
-{ KEY_DIVIDE, "/", 0 },
-{ KEY_BACKSPACE, NULL, 0 },
-{ KEY_DELETE, NULL, 0 },
-{ KEY_CHANGE_SIGN, NULL, 0 },
-{ KEY_INTEGER, "Int", FUNC },
-{ KEY_FRACTION, "Frac", FUNC },
-{ KEY_PERCENTAGE, "%", 0 },
-{ KEY_SQUARE, "^2", 0 },
-{ KEY_SQUARE_ROOT, "Sqrt", FUNC },
-{ KEY_RECIPROCAL, NULL, 0 },
-{ KEY_E_POW_X, "e^", PREFIXOP },
-{ KEY_10_POW_X, "10^", PREFIXOP },
-{ KEY_2_POW_X, "2^", PREFIXOP },
-{ KEY_X_POW_Y, "^", 0 },
-{ KEY_X_POW_Y_INV, "^(1/(", 0 },
-{ KEY_FACTORIAL, "!", 0 },
-{ KEY_RANDOM, "Rand", 0 },
-{ KEY_SIN, "Sin", FUNC },
-{ KEY_SINH, "Sinh", FUNC },
-{ KEY_ASIN, "Asin", FUNC },
-{ KEY_ASINH, "Asinh", FUNC },
-{ KEY_COS, "Cos", FUNC },
-{ KEY_COSH, "Cosh", FUNC },
-{ KEY_ACOS, "Acos", FUNC },
-{ KEY_ACOSH, "Acosh", FUNC },
-{ KEY_TAN, "Tan", FUNC },
-{ KEY_TANH, "Tanh", FUNC },
-{ KEY_ATAN, "Atan", FUNC },
-{ KEY_TAN, "Atanh", FUNC },
-{ KEY_NATURAL_LOGARITHM, "Ln", FUNC },
-{ KEY_LOGARITHM, "Log", FUNC },
-{ KEY_LOGARITHM2, "Log2", FUNC },
-{ KEY_ABSOLUTE_VALUE, "Abs", FUNC },
-{ KEY_MASK_16, "u16", FUNC },
-{ KEY_MASK_32, "u32", FUNC },
-{ KEY_MODULUS_DIVIDE, " Mod ", 0 },
-{ KEY_EXPONENTIAL, "e", 0 },
-{ KEY_NOT, "~", 0 },
-{ KEY_OR, " OR ", 0 },
-{ KEY_AND, " AND ", 0 },
-{ KEY_XOR, " XOR ", 0 },
-{ KEY_XNOR, " XNOR ", 0 },
-{ KEY_FINC_CTRM, "Ctrm", 0 },
-{ KEY_FINC_DDB, "Ddb", 0 },
-{ KEY_FINC_FV, "Fv", 0 },
-{ KEY_FINC_GPM, "Gpm", 0 },
-{ KEY_FINC_PMT, "Pmt", 0 },
-{ KEY_FINC_PV, "Pv", 0 },
-{ KEY_FINC_RATE, "Rate", 0 },
-{ KEY_FINC_SLN, "Sln", 0 },
-{ KEY_FINC_SYD , "Syd", 0 },
-{ KEY_FINC_TERM, "Term", 0 },
-{ KEY_SHIFT, NULL, 0 },
-{ KEY_STORE, NULL, 0 },
-{ KEY_RECALL, NULL, 0 },
-{ KEY_EXCHANGE, NULL, 0 },
-{ KEY_SET_ACCURACY, NULL, 0 },
-{ KEY_SET_BASE, NULL, 0 },
-{ KEY_SET_NUMBERTYPE, NULL, 0 },
-{ KEY_UNDO, NULL, 0 },
-{ KEY_REDO, NULL, 0 },
-{ KEY_CONSTANT, NULL, 0 },
-{ KEY_FUNCTION, NULL, 0 }
-};
+CalculatorVariables *v;
/* Calctools' customised math library error-handling routine. */
@@ -238,7 +145,7 @@
static void
init_state(void)
{
- int acc, i, size;
+ int acc, size;
v->accuracy = DEFAULT_ACCURACY;
v->show_zeroes = FALSE; /* Don't show trailing zeroes. */
@@ -249,7 +156,6 @@
acc = MAX_DIGITS + 12; /* MP internal accuracy. */
size = MP_SIZE;
mpset(acc, size, size);
-
v->error = 0; /* No calculator error initially. */
}
@@ -257,9 +163,7 @@
int
main(int argc, char **argv)
{
- char *ptr;
-
- v = (Vars) LINT_CAST(calloc(1, sizeof(struct calcVars)));
+ v = (CalculatorVariables *)LINT_CAST(calloc(1, sizeof(CalculatorVariables)));
bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
Modified: trunk/gcalctool/calctool.h
==============================================================================
--- trunk/gcalctool/calctool.h (original)
+++ trunk/gcalctool/calctool.h Sat Nov 29 08:43:32 2008
@@ -23,12 +23,8 @@
#define CALCTOOL_H
#include <string.h>
-#include <unistd.h>
#include <stdlib.h>
-#include <locale.h>
-#include <math.h>
#include <glib/gi18n.h>
-#include <gtk/gtk.h>
#include "config.h"
#include "mp.h"
@@ -152,35 +148,20 @@
#define MAX_FUNCTIONS 10
#define MAX_REGISTERS 10 /* Maximum number of memory registers. */
-#ifndef MIN
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
-#endif /*MIN*/
-
#ifndef RCNAME
#define RCNAME ".gcalctoolrc"
#endif /*RCNAME*/
-#undef TRUE /* Boolean definitions. */
+/* Boolean definitions. */
+#undef TRUE
#define TRUE 1
-
#undef FALSE
#define FALSE 0
#define MPMATH_ERR 20001
-enum button_flags {
- NUMBER = (1 << 3), /* Number button */
- FUNC = (1 << 6), /* Function */
- PREFIXOP = (1 << 15), /* Unary prefix operation */
-};
-
-struct button {
- int id;
- char *symname; /* Expression function name */
- enum button_flags flags; /* Misc flags */
-};
-
-struct calcVars { /* Calctool variables and options. */
+/* Calctool variables and options. */
+typedef struct {
char *progname; /* Name of this program. */
GCDisplay display;
@@ -202,13 +183,10 @@
int math_error; /* Math error (used in expression mode) */
int show_tsep; /* Set if the thousands separator should be shown. */
int show_zeroes; /* Set if trailing zeroes should be shown. */
-};
-
-typedef struct calcVars *Vars;
+} CalculatorVariables;
-extern Vars v; /* Calctool variables and options. */
+extern CalculatorVariables *v; /* Calctool variables and options. */
extern int basevals[]; /* Supported arithmetic bases. */
-extern struct button buttons[]; /* Calculator button values. */
void doerr(char *);
Modified: trunk/gcalctool/functions.c
==============================================================================
--- trunk/gcalctool/functions.c (original)
+++ trunk/gcalctool/functions.c Sat Nov 29 08:43:32 2008
@@ -37,6 +37,111 @@
#include "ce_parser.h"
#include "ui.h"
+enum button_flags {
+ NUMBER = (1 << 3), /* Number button */
+ FUNC = (1 << 6), /* Function */
+ PREFIXOP = (1 << 15), /* Unary prefix operation */
+};
+
+typedef struct {
+ int id;
+ char *symname; /* Expression function name */
+ enum button_flags flags; /* Misc flags */
+} Button;
+
+// FIXME: Sort this list
+/* Note that none of these strings can be translated as the parser expects them to be correct */
+/* id, symname flags */
+static Button buttons[NKEYS] = {
+{ KEY_0, "0", NUMBER },
+{ KEY_1, "1", NUMBER },
+{ KEY_2, "2", NUMBER },
+{ KEY_3, "3", NUMBER },
+{ KEY_4, "4", NUMBER },
+{ KEY_5, "5", NUMBER },
+{ KEY_6, "6", NUMBER },
+{ KEY_7, "7", NUMBER },
+{ KEY_8, "8", NUMBER },
+{ KEY_9, "9", NUMBER },
+{ KEY_A, "A", NUMBER },
+{ KEY_B, "B", NUMBER },
+{ KEY_C, "C", NUMBER },
+{ KEY_D, "D", NUMBER },
+{ KEY_E, "E", NUMBER },
+{ KEY_F, "F", NUMBER },
+{ KEY_NUMERIC_POINT, ".", NUMBER },
+{ KEY_CALCULATE, NULL, 0 },
+{ KEY_CLEAR, NULL, 0 },
+{ KEY_CLEAR_ENTRY, NULL, 0 },
+{ KEY_START_BLOCK, "(", 0 },
+{ KEY_END_BLOCK, ")", 0 },
+{ KEY_ADD, "+", 0 },
+{ KEY_SUBTRACT, "-", 0 },
+{ KEY_MULTIPLY, "*", 0 },
+{ KEY_DIVIDE, "/", 0 },
+{ KEY_BACKSPACE, NULL, 0 },
+{ KEY_DELETE, NULL, 0 },
+{ KEY_CHANGE_SIGN, NULL, 0 },
+{ KEY_INTEGER, "Int", FUNC },
+{ KEY_FRACTION, "Frac", FUNC },
+{ KEY_PERCENTAGE, "%", 0 },
+{ KEY_SQUARE, "^2", 0 },
+{ KEY_SQUARE_ROOT, "Sqrt", FUNC },
+{ KEY_RECIPROCAL, NULL, 0 },
+{ KEY_E_POW_X, "e^", PREFIXOP },
+{ KEY_10_POW_X, "10^", PREFIXOP },
+{ KEY_2_POW_X, "2^", PREFIXOP },
+{ KEY_X_POW_Y, "^", 0 },
+{ KEY_X_POW_Y_INV, "^(1/(", 0 },
+{ KEY_FACTORIAL, "!", 0 },
+{ KEY_RANDOM, "Rand", 0 },
+{ KEY_SIN, "Sin", FUNC },
+{ KEY_SINH, "Sinh", FUNC },
+{ KEY_ASIN, "Asin", FUNC },
+{ KEY_ASINH, "Asinh", FUNC },
+{ KEY_COS, "Cos", FUNC },
+{ KEY_COSH, "Cosh", FUNC },
+{ KEY_ACOS, "Acos", FUNC },
+{ KEY_ACOSH, "Acosh", FUNC },
+{ KEY_TAN, "Tan", FUNC },
+{ KEY_TANH, "Tanh", FUNC },
+{ KEY_ATAN, "Atan", FUNC },
+{ KEY_TAN, "Atanh", FUNC },
+{ KEY_NATURAL_LOGARITHM, "Ln", FUNC },
+{ KEY_LOGARITHM, "Log", FUNC },
+{ KEY_LOGARITHM2, "Log2", FUNC },
+{ KEY_ABSOLUTE_VALUE, "Abs", FUNC },
+{ KEY_MASK_16, "u16", FUNC },
+{ KEY_MASK_32, "u32", FUNC },
+{ KEY_MODULUS_DIVIDE, " Mod ", 0 },
+{ KEY_EXPONENTIAL, "e", 0 },
+{ KEY_NOT, "~", 0 },
+{ KEY_OR, " OR ", 0 },
+{ KEY_AND, " AND ", 0 },
+{ KEY_XOR, " XOR ", 0 },
+{ KEY_XNOR, " XNOR ", 0 },
+{ KEY_FINC_CTRM, "Ctrm", 0 },
+{ KEY_FINC_DDB, "Ddb", 0 },
+{ KEY_FINC_FV, "Fv", 0 },
+{ KEY_FINC_GPM, "Gpm", 0 },
+{ KEY_FINC_PMT, "Pmt", 0 },
+{ KEY_FINC_PV, "Pv", 0 },
+{ KEY_FINC_RATE, "Rate", 0 },
+{ KEY_FINC_SLN, "Sln", 0 },
+{ KEY_FINC_SYD , "Syd", 0 },
+{ KEY_FINC_TERM, "Term", 0 },
+{ KEY_SHIFT, NULL, 0 },
+{ KEY_STORE, NULL, 0 },
+{ KEY_RECALL, NULL, 0 },
+{ KEY_EXCHANGE, NULL, 0 },
+{ KEY_SET_ACCURACY, NULL, 0 },
+{ KEY_SET_BASE, NULL, 0 },
+{ KEY_SET_NUMBERTYPE, NULL, 0 },
+{ KEY_UNDO, NULL, 0 },
+{ KEY_REDO, NULL, 0 },
+{ KEY_CONSTANT, NULL, 0 },
+{ KEY_FUNCTION, NULL, 0 }
+};
static void
clear_undo_history(void)
Modified: trunk/gcalctool/gtk.c
==============================================================================
--- trunk/gcalctool/gtk.c (original)
+++ trunk/gcalctool/gtk.c Sat Nov 29 08:43:32 2008
@@ -23,15 +23,16 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
-#include <limits.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <netdb.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
#include <glade/glade.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <unistd.h>
+#include <netdb.h>
+
#include "ui.h"
#include "config.h"
Modified: trunk/gcalctool/mp.c
==============================================================================
--- trunk/gcalctool/mp.c (original)
+++ trunk/gcalctool/mp.c Sat Nov 29 08:43:32 2008
@@ -20,6 +20,7 @@
*/
#include <stdio.h>
+#include <math.h>
#include "mp.h"
#include "mp-internal.h"
Modified: trunk/gcalctool/mpmath.c
==============================================================================
--- trunk/gcalctool/mpmath.c (original)
+++ trunk/gcalctool/mpmath.c Sat Nov 29 08:43:32 2008
@@ -19,8 +19,9 @@
#include <assert.h>
#include <errno.h>
+#include <stdio.h>
+#include <math.h>
-#include "mp.h"
#include "mpmath.h"
static char digits[] = "0123456789ABCDEF";
@@ -431,7 +432,7 @@
void
make_fixed(char *target, int target_len, const int *MPnumber, int base, int cmax)
{
- char half[MAXLINE], *optr;
+ char *optr;
int MP1base[MP_SIZE], MP1[MP_SIZE], MP2[MP_SIZE], MPval[MP_SIZE];
int ndig; /* Total number of digits to generate. */
int ddig; /* Number of digits to left of decimal sep. */
@@ -447,9 +448,7 @@
mp_set_from_integer(basevals[base], MP1base);
mppwr(MP1base, v->accuracy, MP1);
- /* FIXME: string const. if MPstr_to_num can get it */
- SNPRINTF(half, MAXLINE, "0.5");
- MPstr_to_num(half, 10, MP2);
+ MPstr_to_num("0.5", 10, MP2);
mpdiv(MP2, MP1, MP1);
mp_add(MPval, MP1, MPval);
@@ -464,7 +463,7 @@
}
}
- ndig = MIN(ddig + v->accuracy, --cmax);
+ ndig = (ddig + v->accuracy) < (--cmax) ? (ddig + v->accuracy) : (--cmax);
while (ndig-- > 0) {
if (ddig-- == 0) {
@@ -503,7 +502,7 @@
void
make_eng_sci(char *target, int target_len, const int *MPnumber, int base)
{
- char half[MAXLINE], fixed[MAX_DIGITS], *optr;
+ char fixed[MAX_DIGITS], *optr;
int MP1[MP_SIZE], MPatmp[MP_SIZE], MPval[MP_SIZE];
int MP1base[MP_SIZE], MP3base[MP_SIZE], MP10base[MP_SIZE];
int i, dval, len;
@@ -571,8 +570,7 @@
*optr++ = '+';
}
- SNPRINTF(half, MAXLINE, "0.5");
- MPstr_to_num(half, 10, MP1);
+ MPstr_to_num("0.5", 10, MP1);
mp_add_integer(MP1, exp, MPval);
mp_set_from_integer(1, MP1);
for (ddig = 0; mp_is_greater_equal(MPval, MP1); ddig++) {
Modified: trunk/gcalctool/register.c
==============================================================================
--- trunk/gcalctool/register.c (original)
+++ trunk/gcalctool/register.c Sat Nov 29 08:43:32 2008
@@ -19,7 +19,10 @@
* 02111-1307, USA.
*/
+#include <stdio.h>
+
#include "register.h"
+#include "calctool.h"
#include "get.h"
#include "mpmath.h"
@@ -131,7 +134,7 @@
void constant_set(int index, const char *name, int value[MP_SIZE])
{
- char key[MAXLINE], temp[MAXLINE];
+ char key[MAXLINE], temp[MAX_LOCALIZED];
STRNCPY(constant_names[index], name, MAXLINE - 1);
mp_set_from_mp(value, constant_values[index]);
@@ -141,7 +144,7 @@
/* NOTE: Constants are written out with no thousands separator and with a
radix character of ".". */
- make_number(temp, MAXLINE, value, 10, TRUE);
+ make_number(temp, MAX_LOCALIZED, value, DEC, TRUE);
SNPRINTF(key, MAXLINE, "constant%1dvalue", index);
set_resource(key, temp);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]