4 * Copyright (c) 1987-2007 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 SPRINTF (void) sprintf
46 #define SSCANF (void) sscanf
47 #define STRCAT (void) strcat
48 #define STRCPY (void) strcpy
49 #define STRNCPY (void) strncpy
50 #define STRNCAT (void) strncat
51 #define UNLINK (void) unlink
53 /* Base definitions. */
54 enum base_type
{ BIN
, OCT
, DEC
, HEX
, MAXBASES
};
56 /* Calculator modes. */
57 enum mode_type
{ BASIC
, ADVANCED
, FINANCIAL
, SCIENTIFIC
, MAXMODES
};
59 /* Number display mode. */
60 enum num_type
{ ENG
, FIX
, SCI
, MAXDISPMODES
};
62 /* Trigonometric types. */
63 enum trig_type
{ DEG
, GRAD
, RAD
, MAXTRIGMODES
};
67 NPA
= 0, /* Non-precedence arithmetic */
68 EXPRS
, /* Expression with arithmetic precedence */
72 /* Abbreviations for the gcalctool keyboard */
75 KEY_0
, KEY_1
, KEY_2
, KEY_3
,
76 KEY_4
, KEY_5
, KEY_6
, KEY_7
,
77 KEY_8
, KEY_9
, KEY_A
, KEY_B
,
78 KEY_C
, KEY_D
, KEY_E
, KEY_F
,
81 KEY_CLEAR
, KEY_CLEAR_ENTRY
,
82 KEY_START_BLOCK
, KEY_END_BLOCK
,
83 KEY_ADD
, KEY_SUBTRACT
,
84 KEY_MULTIPLY
, KEY_DIVIDE
,
98 KEY_SIN
, KEY_SINH
, KEY_ASIN
, KEY_ASINH
,
99 KEY_COS
, KEY_COSH
, KEY_ACOS
, KEY_ACOSH
,
100 KEY_TAN
, KEY_TANH
, KEY_ATAN
, KEY_ATANH
,
101 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)
138 #define MAXLINE 512 /* Length of character strings. */
141 #define MAXACC 99 /* Max. number of digits after numeric point. */
143 #define MAX_CONSTANTS 10
144 #define MAX_FUNCTIONS 10
145 #define MAX_REGISTERS 10 /* Maximum number of memory registers. */
146 #define MAXBITCALC 2 /* Choices for bitcalculating */
149 #define MIN(x,y) ((x) < (y) ? (x) : (y))
153 #define RCNAME ".gcalctoolrc"
156 #undef TRUE /* Boolean definitions. */
162 #define UNDO_HISTORY_LENGTH 16 /* Arithmetic mode undo history length */
164 #define MPMATH_ERR 20001
167 NUMBER
= (1 << 3), /* Number button */
168 FUNC
= (1 << 6), /* Function */
169 POSTFIXOP
= (1 << 14), /* Unary postfix operation */
170 PREFIXOP
= (1 << 15), /* Unary prefix operation */
175 char *symname
; /* Expression function name */
176 void (*func
)(); /* Function to obey on button press. */
177 enum button_flags flags
; /* Misc flags */
180 struct exprm_state
{ /* Expression mode state */
181 struct button button
; /* Current button/character pressed. */
183 int ans
[MP_SIZE
]; /* Previously calculated answer */
184 char *expression
; /* Expression entered by user */
187 /* Circular list of Arithmetic Precedence Mode states*/
188 struct exprm_state_history
{
191 unsigned int current
;
192 struct exprm_state e
[UNDO_HISTORY_LENGTH
]; /* Expression mode state */
195 struct calcVars
{ /* Calctool variables and options. */
196 struct exprm_state_history h
; /* History of expression mode states */
198 int current
; /* Current button/character pressed. */
200 char *appname
; /* Application name for resources. */
201 char *home
; /* Pathname for users home directory. */
202 char *progname
; /* Name of this program. */
204 char display
[MAXLINE
]; /* Current calculator display. */
205 char *exp_posn
; /* Position of the exponent sign. */
206 char fnum
[MAX_DIGITS
]; /* Scratchpad for fixed numbers. */
207 const char *radix
; /* Locale specific radix string. */
208 char *shelf
; /* PUT selection shelf contents. */
209 char snum
[MAX_DIGITS
]; /* Scratchpad for scientific numbers. */
210 const char *tsep
; /* Locale specific thousands seperator. */
212 char fun_names
[MAX_FUNCTIONS
][MAXLINE
]; /* Function names from .gcalctoolcf. */
213 char fun_vals
[MAX_FUNCTIONS
][MAXLINE
]; /* Function defs from .gcalctoolcf. */
214 char con_names
[MAX_CONSTANTS
][MAXLINE
]; /* Selectable constant names. */
215 int MPcon_vals
[MAX_CONSTANTS
][MP_SIZE
]; /* Selectable constants. */
217 int MPdebug
; /* If set, debug info. to stderr. */
218 int MPerrors
; /* If set, output errors to stderr. */
219 int MPdisp_val
[MP_SIZE
]; /* Value of the current display. */
220 int MPexpr_val
[MP_SIZE
]; /* Value of the current expression. */
221 int MPlast_input
[MP_SIZE
]; /* Previous number input by user. */
222 int MPmvals
[MAX_REGISTERS
][MP_SIZE
]; /* Memory register values. */
223 int MPresult
[MP_SIZE
]; /* Current calculator total value. */
224 int MPimresult
[MP_SIZE
]; /* Current intermediate result. */
225 int MPtresults
[3][MP_SIZE
]; /* Current trigonometric results. */
227 enum base_type base
; /* Current base: BIN, OCT, DEC or HEX. */
228 enum mode_type modetype
; /* Current calculator mode. */
229 enum num_type dtype
; /* Number display mode. */
230 enum trig_type ttype
; /* Trig. type (deg, grad or rad). */
232 enum syntax syntax
; /* Calculation syntax mode */
234 int accuracy
; /* Number of digits precision (Max 9). */
235 int cur_op
; /* Current arithmetic operation. */
236 int error
; /* Indicates some kind of display error. */
237 int ghost_zero
; /* Flag to indicate display with "0", actually
238 having empty content. */
239 int math_error
; /* Math error (used in expression mode) */
240 int key_exp
; /* Set if entering exponent number. */
241 int new_input
; /* New number input since last op. */
242 int noparens
; /* Count of left brackets still to be matched. */
243 int numsptr
; /* Pointer into the parenthese numeric stack. */
244 int old_cal_value
; /* Previous calculation operator. */
245 int pointed
; /* Whether a decimal point has been given. */
246 int show_paren
; /* Set if we wish to show DISPLAYITEM during parens. */
247 int show_tsep
; /* Set if the thousands seperator should be shown. */
248 int show_zeroes
; /* Set if trailing zeroes should be shown. */
249 int toclear
; /* Indicates if display should be cleared. */
250 int warn_change_mode
; /* Should we warn user when changing modes? */
251 int bitcalculating_mode
; /* 0 = no, else yes */
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*/