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 /* Menu bar menu types. */
55 enum mb_type
{ M_ABOUT
, M_ASCII
, M_BASIC
, M_ADV
, M_CONTENTS
, M_COPY
, M_FIN
,
56 M_PASTE
, M_QUIT
, M_REGS
, M_SCI
, M_EXP
, M_TSEP
, M_ZEROES
,
57 M_LR_ARITH
, M_OP_ARITH
};
59 enum base_type
{ BIN
, OCT
, DEC
, HEX
}; /* Base definitions. */
61 enum item_type
{ BASEITEM
, TTYPEITEM
, NUMITEM
,
62 HYPITEM
, INVITEM
, OPITEM
, MODEITEM
};
64 /* Calculator modes. */
65 enum mode_type
{ BASIC
, ADVANCED
, FINANCIAL
, SCIENTIFIC
};
67 enum num_type
{ ENG
, FIX
, SCI
}; /* Number display mode. */
69 enum trig_type
{ DEG
, GRAD
, RAD
}; /* Trigonometric types. */
71 enum trig_func
{SIN
=0, COS
=1, TAN
=2};
73 /* Abbreviations for the gcalctool keyboard */
119 KEY_NATURAL_LOGARITHM
,
151 #define EQUAL(a, b) (strlen(a)==strlen(b)) & !strcmp(a, b)
155 #define LINT_CAST(arg) (arg ? 0 : 0)
157 #define LINT_CAST(arg) (arg)
161 #define MAX_DIGITS 200 /* Maximum displayable number of digits. */
162 #define MAX_LOCALIZED (MAX_DIGITS * (1 + MB_LEN_MAX) + MB_LEN_MAX)
165 #define MAXLINE 512 /* Length of character strings. */
168 #define MAXACC 99 /* Max. number of digits after numeric point. */
169 #define MAXBASES 4 /* Maximum number of numeric bases. */
170 #define MAXCONFUN 10 /* Maximum number of constants/functions. */
171 #define MAXDISPMODES 3 /* Maximum number of display modes. */
172 #define MAXMODES 4 /* Maximum number of calculator modes. */
173 #define MAXREGS 10 /* Maximum number of memory registers. */
174 #define MAXSTACK 256 /* Parenthese stack size. */
175 #define MAXTRIGMODES 3 /* Maximum number of trig. modes. */
176 #define MAXSYNTAX 2 /* Number of syntaxes in calculator */
177 #define MAXBITCALC 2 /* Choices for bitcalculating */
180 #define MIN(x,y) ((x) < (y) ? (x) : (y))
184 #define CFNAME ".gcalctoolcf"
188 #define RCNAME ".gcalctoolrc"
191 #undef TRUE /* Boolean definitions. */
197 #define UNDO_HISTORY_LENGTH 16 /* Arithmetic mode undo history length */
199 #define MPMATH_ERR 20001
202 none
= 0, /* No flags */
203 enter
= (1 << 2), /* Expression is entered */
204 number
= (1 << 3), /* Number button */
205 func
= (1 << 6), /* Function */
206 bsp
= (1 << 7), /* Backspace */
207 clear
= (1 << 8), /* Clear display */
208 neg
= (1 << 9), /* Negate display */
209 inv
= (1 << 10), /* Reciprocial */
210 con
= (1 << 11), /* Constant */
211 regrcl
= (1 << 12), /* Recall register */
212 expnum
= (1 << 13), /* Exponential number */
213 postfixop
= (1 << 14), /* Unary postfix operation */
214 prefixop
= (1 << 15), /* Unary prefix operation */
215 dpoint
= (1 << 16) /* Decimal point */
224 npa
= 0, /* Non-precedence arithmetic */
225 exprs
, /* Expression with arithmetic precedence */
230 char *symname
; /* Expression function name */
231 void (*func
)(); /* Function to obey on button press. */
232 enum button_flags flags
; /* Misc flags */
235 struct exprm_state
{ /* Expression mode state */
236 struct button button
; /* Current button/character pressed. */
238 int ans
[MP_SIZE
]; /* Previously calculated answer */
239 char *expression
; /* Expression entered by user */
242 /* Circular list of Arithmetic Precedence Mode states*/
243 struct exprm_state_history
{
246 unsigned int current
;
247 struct exprm_state e
[UNDO_HISTORY_LENGTH
]; /* Expression mode state */
251 char *title
; /* Menu title. */
252 int total
; /* Number of menu entries. */
253 int index
; /* Index into menu string array. */
254 int defval
; /* Default menu item position (from 1). */
257 struct calcVars
{ /* Calctool variables and options. */
258 struct exprm_state_history h
; /* History of expression mode states */
260 int current
; /* Current button/character pressed. */
262 char *appname
; /* Application name for resources. */
263 char con_names
[MAXREGS
][MAXLINE
]; /* Selectable constant names. */
264 char display
[MAXLINE
]; /* Current calculator display. */
265 char *exp_posn
; /* Position of the exponent sign. */
266 char fnum
[MAX_DIGITS
]; /* Scratchpad for fixed numbers. */
267 char fun_names
[MAXREGS
][MAXLINE
]; /* Function names from .gcalctoolcf. */
268 char fun_vals
[MAXREGS
][MAXLINE
]; /* Function defs from .gcalctoolcf. */
269 char *home
; /* Pathname for users home directory. */
270 char *iconlabel
; /* The calctool icon label. */
271 char op_item_text
[5]; /* Operand item panel string. */
272 char opstr
[5]; /* Operand string during pending op. */
273 char *progname
; /* Name of this program. */
274 char pstr
[5]; /* Current button text string. */
275 const char *radix
; /* Locale specific radix string. */
276 char *shelf
; /* PUT selection shelf contents. */
277 char snum
[MAX_DIGITS
]; /* Scratchpad for scientific numbers. */
278 const char *tsep
; /* Locale specific thousands seperator. */
280 int MPcon_vals
[MAXREGS
][MP_SIZE
]; /* Selectable constants. */
281 int MPdebug
; /* If set, debug info. to stderr. */
282 int MPerrors
; /* If set, output errors to stderr. */
283 int MPdisp_val
[MP_SIZE
]; /* Value of the current display. */
284 int MPexpr_val
[MP_SIZE
]; /* Value of the current expression. */
285 int MPlast_input
[MP_SIZE
]; /* Previous number input by user. */
286 int MPmvals
[MAXREGS
][MP_SIZE
]; /* Memory register values. */
287 int *MPnumstack
[MAXSTACK
]; /* Numeric stack for parens. */
288 int MPresult
[MP_SIZE
]; /* Current calculator total value. */
289 int MPimresult
[MP_SIZE
]; /* Current intermediate result. */
290 int MPtresults
[3][MP_SIZE
]; /* Current trigonometric results. */
292 enum base_type base
; /* Current base: BIN, OCT, DEC or HEX. */
293 enum mode_type modetype
; /* Current calculator mode. */
294 enum num_type dtype
; /* Number display mode. */
295 enum trig_type ttype
; /* Trig. type (deg, grad or rad). */
297 enum syntax syntax
; /* Calculation syntax mode */
299 int accuracy
; /* Number of digits precision (Max 9). */
300 int cur_op
; /* Current arithmetic operation. */
301 int doing_mi
; /* Set if adjusting the "show zeroes" menu item. */
302 int error
; /* Indicates some kind of display error. */
303 int ghost_zero
; /* Flag to indicate display with "0", actually
304 having empty content. */
305 int math_error
; /* Math error (used in expression mode) */
306 int hyperbolic
; /* If set, trig functions will be hyperbolic. */
307 int iconic
; /* Set if window is currently iconic. */
308 int inverse
; /* If set, trig and log functions will be inversed. */
309 int key_exp
; /* Set if entering exponent number. */
310 int ndisplay
; /* Height of the numerical display. */
311 int new_input
; /* New number input since last op. */
312 int noparens
; /* Count of left brackets still to be matched. */
313 int numsptr
; /* Pointer into the parenthese numeric stack. */
314 int old_cal_value
; /* Previous calculation operator. */
315 int opsptr
; /* Pointer into the parentheses operand stack. */
316 int opstack
[MAXSTACK
]; /* Stack containing parentheses input. */
317 int pointed
; /* Whether a decimal point has been given. */
318 int rstate
; /* Indicates if memory register frame is displayed. */
319 int show_paren
; /* Set if we wish to show DISPLAYITEM during parens. */
320 int show_tsep
; /* Set if the thousands seperator should be shown. */
321 int show_zeroes
; /* Set if trailing zeroes should be shown. */
322 int started
; /* Set just before window is displayed. */
323 int toclear
; /* Indicates if display should be cleared. */
324 int warn_change_mode
; /* Should we warn user when changing modes? */
325 int bitcalculating_mode
; /* 0 = no, else yes */
328 typedef struct calcVars
*Vars
;
330 extern Vars v
; /* Calctool variables and options. */
331 extern int basevals
[]; /* Supported arithmetic bases. */
332 extern struct button buttons
[]; /* Calculator button values. */
336 #endif /*CALCTOOL_H*/