Correctly populate the constant and function menus (Bug #527545)
[gcalctool.git] / gcalctool / calctool.h
blobffeb60e6fe525d30db96e3c899ca91a461b67b32
2 /* $Header$
4 * Copyright (c) 1987-2008 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 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 };
63 /* Syntax mode. */
64 enum syntax {
65 NPA = 0, /* Non-precedence arithmetic */
66 EXPRS, /* Expression with arithmetic precedence */
67 MAXSYNTAX
70 /* Abbreviations for the gcalctool keyboard */
71 enum
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,
77 KEY_NUMERIC_POINT,
78 KEY_CALCULATE,
79 KEY_CLEAR, KEY_CLEAR_ENTRY,
80 KEY_START_BLOCK, KEY_END_BLOCK,
81 KEY_ADD, KEY_SUBTRACT,
82 KEY_MULTIPLY, KEY_DIVIDE,
83 KEY_BACKSPACE,
84 KEY_DELETE,
85 KEY_CHANGE_SIGN,
86 KEY_INTEGER,
87 KEY_FRACTION,
88 KEY_PERCENTAGE,
89 KEY_SQUARE,
90 KEY_SQUARE_ROOT,
91 KEY_RECIPROCAL,
92 KEY_E_POW_X,
93 KEY_10_POW_X,
94 KEY_X_POW_Y,
95 KEY_FACTORIAL,
96 KEY_RANDOM,
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,
101 KEY_LOGARITHM,
102 KEY_LOGARITHM2,
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 #define DEFAULT_ACCURACY 9
139 #ifndef MAXLINE
140 #define MAXLINE 512 /* Length of character strings. */
141 #endif /*MAXLINE*/
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 */
150 #ifndef MIN
151 #define MIN(x,y) ((x) < (y) ? (x) : (y))
152 #endif /*MIN*/
154 #ifndef RCNAME
155 #define RCNAME ".gcalctoolrc"
156 #endif /*RCNAME*/
158 #undef TRUE /* Boolean definitions. */
159 #define TRUE 1
161 #undef FALSE
162 #define FALSE 0
164 #define UNDO_HISTORY_LENGTH 16 /* Arithmetic mode undo history length */
166 #define MPMATH_ERR 20001
168 enum button_flags {
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 */
175 struct button {
176 int id;
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 */
183 struct exprm_state {
184 int ans[MP_SIZE]; /* Previously calculated answer */
185 char *expression; /* Expression entered by user */
186 int cursor;
187 int clear; /* Clear command issued */
190 /* Circular list of Arithmetic Precedence Mode states*/
191 struct exprm_state_history {
192 unsigned int begin;
193 unsigned int end;
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. */
260 void doerr(char *);
262 #endif /*CALCTOOL_H*/