4 * Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
33 #include <glib/gi18n.h>
36 #define FCLOSE (void) fclose /* To make lint happy. */
37 #define FPRINTF (void) fprintf
38 #define FPUTS (void) fputs
39 #define GETHOSTNAME (void) gethostname
40 #define MEMCPY (void) memcpy
41 #define MEMSET (void) memset
42 #define MKSTEMP (void) mkstemp
43 #define REWIND (void) rewind
44 #define SNPRINTF (void) snprintf
45 #define SSCANF (void) sscanf
46 #define STRCAT (void) strcat
47 #define STRNCPY (void) strncpy
48 #define STRNCAT (void) strncat
49 #define UNLINK (void) unlink
51 /* Base definitions. */
52 enum base_type
{ BIN
, OCT
, DEC
, HEX
, MAXBASES
};
54 /* Calculator modes. */
55 enum mode_type
{ BASIC
, ADVANCED
, FINANCIAL
, SCIENTIFIC
, MAXMODES
};
57 /* Number display mode. */
58 enum num_type
{ ENG
, FIX
, SCI
, MAXDISPMODES
};
60 /* Trigonometric types. */
61 enum trig_type
{ DEG
, GRAD
, RAD
, MAXTRIGMODES
};
65 NPA
= 0, /* Non-precedence arithmetic */
66 EXPRS
, /* Expression with arithmetic precedence */
70 /* Abbreviations for the gcalctool keyboard */
73 KEY_0
, KEY_1
, KEY_2
, KEY_3
,
74 KEY_4
, KEY_5
, KEY_6
, KEY_7
,
75 KEY_8
, KEY_9
, KEY_A
, KEY_B
,
76 KEY_C
, KEY_D
, KEY_E
, KEY_F
,
79 KEY_CLEAR
, KEY_CLEAR_ENTRY
,
80 KEY_START_BLOCK
, KEY_END_BLOCK
,
81 KEY_ADD
, KEY_SUBTRACT
,
82 KEY_MULTIPLY
, KEY_DIVIDE
,
97 KEY_SIN
, KEY_SINH
, KEY_ASIN
, KEY_ASINH
,
98 KEY_COS
, KEY_COSH
, KEY_ACOS
, KEY_ACOSH
,
99 KEY_TAN
, KEY_TANH
, KEY_ATAN
, KEY_ATANH
,
100 KEY_NATURAL_LOGARITHM
,
108 KEY_NOT
, KEY_OR
, KEY_AND
, KEY_XOR
, KEY_XNOR
,
119 KEY_STORE
, KEY_RECALL
, KEY_EXCHANGE
,
128 #define LINT_CAST(arg) (arg ? 0 : 0)
130 #define LINT_CAST(arg) (arg)
134 #define MAX_DIGITS 200 /* Maximum displayable number of digits. */
135 #define MAX_LOCALIZED (MAX_DIGITS * (1 + MB_LEN_MAX) + MB_LEN_MAX)
137 #define DEFAULT_ACCURACY 9
140 #define MAXLINE 512 /* Length of character strings. */
143 #define MAXACC 99 /* Max. number of digits after numeric point. */
145 #define MAX_CONSTANTS 10
146 #define MAX_FUNCTIONS 10
147 #define MAX_REGISTERS 10 /* Maximum number of memory registers. */
148 #define MAXBITCALC 2 /* Choices for bitcalculating */
151 #define MIN(x,y) ((x) < (y) ? (x) : (y))
155 #define RCNAME ".gcalctoolrc"
158 #undef TRUE /* Boolean definitions. */
164 #define UNDO_HISTORY_LENGTH 16 /* Arithmetic mode undo history length */
166 #define MPMATH_ERR 20001
169 NUMBER
= (1 << 3), /* Number button */
170 FUNC
= (1 << 6), /* Function */
171 POSTFIXOP
= (1 << 14), /* Unary postfix operation */
172 PREFIXOP
= (1 << 15), /* Unary prefix operation */
177 char *symname
; /* Expression function name */
178 void (*func
)(); /* Function to obey on button press. */
179 enum button_flags flags
; /* Misc flags */
182 /* Expression mode state */
184 int ans
[MP_SIZE
]; /* Previously calculated answer */
185 char *expression
; /* Expression entered by user */
187 int clear
; /* Clear command issued */
190 /* Circular list of Arithmetic Precedence Mode states*/
191 struct exprm_state_history
{
194 unsigned int current
;
195 struct exprm_state e
[UNDO_HISTORY_LENGTH
]; /* Expression mode state */
198 struct calcVars
{ /* Calctool variables and options. */
199 struct exprm_state_history h
; /* History of expression mode states */
201 int current
; /* Current button/character pressed. */
203 char *appname
; /* Application name for resources. */
204 char *home
; /* Pathname for users home directory. */
205 char *progname
; /* Name of this program. */
207 char display
[MAXLINE
]; /* Current calculator display. */
208 char *exp_posn
; /* Position of the exponent sign. */
209 char fnum
[MAX_LOCALIZED
]; /* Scratchpad for fixed numbers. */
210 const char *radix
; /* Locale specific radix string. */
211 char *shelf
; /* PUT selection shelf contents. */
212 char snum
[MAX_LOCALIZED
]; /* Scratchpad for scientific numbers. */
213 const char *tsep
; /* Locale specific thousands separator. */
214 int tsep_count
; /* Number of digits between separator. */
216 char fun_names
[MAX_FUNCTIONS
][MAXLINE
]; /* Function names from .gcalctoolcf. */
217 char fun_vals
[MAX_FUNCTIONS
][MAXLINE
]; /* Function defs from .gcalctoolcf. */
218 char con_names
[MAX_CONSTANTS
][MAXLINE
]; /* Selectable constant names. */
219 int MPcon_vals
[MAX_CONSTANTS
][MP_SIZE
]; /* Selectable constants. */
221 int MPdebug
; /* If set, debug info. to stderr. */
222 int MPerrors
; /* If set, output errors to stderr. */
223 int MPdisp_val
[MP_SIZE
]; /* Value of the current display. */
224 int MPexpr_val
[MP_SIZE
]; /* Value of the current expression. */
225 int MPlast_input
[MP_SIZE
]; /* Previous number input by user. */
226 int MPmvals
[MAX_REGISTERS
][MP_SIZE
]; /* Memory register values. */
227 int MPresult
[MP_SIZE
]; /* Current calculator total value. */
228 int MPimresult
[MP_SIZE
]; /* Current intermediate result. */
229 int MPtresults
[3][MP_SIZE
]; /* Current trigonometric results. */
231 enum base_type base
; /* Current base: BIN, OCT, DEC or HEX. */
232 enum mode_type modetype
; /* Current calculator mode. */
233 enum num_type dtype
; /* Number display mode. */
234 enum trig_type ttype
; /* Trig. type (deg, grad or rad). */
236 enum syntax syntax
; /* Calculation syntax mode */
238 int accuracy
; /* Number of digits precision (Max 9). */
239 int cur_op
; /* Current arithmetic operation. */
240 int error
; /* Indicates some kind of display error. */
241 int math_error
; /* Math error (used in expression mode) */
242 int key_exp
; /* Set if entering exponent number. */
243 int new_input
; /* New number input since last op. */
244 int noparens
; /* Count of left brackets still to be matched. */
245 int numsptr
; /* Pointer into the parenthese numeric stack. */
246 int old_cal_value
; /* Previous calculation operator. */
247 int pointed
; /* Whether a decimal point has been given. */
248 int show_paren
; /* Set if we wish to show DISPLAYITEM during parens. */
249 int show_tsep
; /* Set if the thousands separator should be shown. */
250 int show_zeroes
; /* Set if trailing zeroes should be shown. */
251 int toclear
; /* Indicates if display should be cleared. */
254 typedef struct calcVars
*Vars
;
256 extern Vars v
; /* Calctool variables and options. */
257 extern int basevals
[]; /* Supported arithmetic bases. */
258 extern struct button buttons
[]; /* Calculator button values. */
262 #endif /*CALCTOOL_H*/