more simplification, got gtk.c under 3k lines
[gcalctool.git] / gcalctool / calctool.h
blob74aa52a634d01ddf2ca37b0615b564d1c1ae10ab
2 /* $Header$
4 * Copyright (c) 1987-2007 Sun Microsystems, Inc. All Rights Reserved.
5 *
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)
9 * any later version.
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
19 * 02111-1307, USA.
22 #ifndef CALCTOOL_H
23 #define CALCTOOL_H
25 #include "config.h"
26 #include "mp.h"
28 #include <string.h>
29 #include <unistd.h>
30 #include <stdlib.h>
31 #include <locale.h>
32 #include <math.h>
33 #include <glib/gi18n.h>
34 #include <gtk/gtk.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 };
65 /* Syntax mode. */
66 enum syntax {
67 NPA = 0, /* Non-precedence arithmetic */
68 EXPRS, /* Expression with arithmetic precedence */
69 MAXSYNTAX
72 /* Abbreviations for the gcalctool keyboard */
73 enum
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,
79 KEY_NUMERIC_POINT,
80 KEY_CALCULATE,
81 KEY_CLEAR, KEY_CLEAR_ENTRY,
82 KEY_START_BLOCK, KEY_END_BLOCK,
83 KEY_ADD, KEY_SUBTRACT,
84 KEY_MULTIPLY, KEY_DIVIDE,
85 KEY_BACKSPACE,
86 KEY_CHANGE_SIGN,
87 KEY_INTEGER,
88 KEY_FRACTION,
89 KEY_PERCENTAGE,
90 KEY_SQUARE,
91 KEY_SQUARE_ROOT,
92 KEY_RECIPROCAL,
93 KEY_E_POW_X,
94 KEY_10_POW_X,
95 KEY_X_POW_Y,
96 KEY_FACTORIAL,
97 KEY_RANDOM,
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,
102 KEY_LOGARITHM,
103 KEY_ABSOLUTE_VALUE,
104 KEY_MASK_16,
105 KEY_MASK_32,
106 KEY_MODULUS_DIVIDE,
107 KEY_EXPONENTIAL,
108 KEY_NOT, KEY_OR, KEY_AND, KEY_XOR, KEY_XNOR,
109 KEY_FINC_CTRM,
110 KEY_FINC_DDB,
111 KEY_FINC_FV,
112 KEY_FINC_PMT,
113 KEY_FINC_PV,
114 KEY_FINC_RATE,
115 KEY_FINC_SLN,
116 KEY_FINC_SYD,
117 KEY_FINC_TERM,
118 KEY_SHIFT,
119 KEY_STORE, KEY_RECALL, KEY_EXCHANGE,
120 KEY_SET_ACCURACY,
121 KEY_CONSTANT,
122 KEY_FUNCTION,
123 NKEYS
126 #ifndef LINT_CAST
127 #ifdef lint
128 #define LINT_CAST(arg) (arg ? 0 : 0)
129 #else
130 #define LINT_CAST(arg) (arg)
131 #endif /*lint*/
132 #endif /*LINT_CAST*/
134 #define MAX_DIGITS 200 /* Maximum displayable number of digits. */
135 #define MAX_LOCALIZED (MAX_DIGITS * (1 + MB_LEN_MAX) + MB_LEN_MAX)
137 #ifndef MAXLINE
138 #define MAXLINE 512 /* Length of character strings. */
139 #endif /*MAXLINE*/
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 */
148 #ifndef MIN
149 #define MIN(x,y) ((x) < (y) ? (x) : (y))
150 #endif /*MIN*/
152 #ifndef RCNAME
153 #define RCNAME ".gcalctoolrc"
154 #endif /*RCNAME*/
156 #undef TRUE /* Boolean definitions. */
157 #define TRUE 1
159 #undef FALSE
160 #define FALSE 0
162 #define UNDO_HISTORY_LENGTH 16 /* Arithmetic mode undo history length */
164 #define MPMATH_ERR 20001
166 enum button_flags {
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 */
173 struct button {
174 int id;
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. */
182 int value;
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 {
189 unsigned int begin;
190 unsigned int end;
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. */
260 void doerr(char *);
262 #endif /*CALCTOOL_H*/