remove ultrix support
[oweals/cde.git] / cde / programs / dtcalc / calctool.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: calctool.h /main/7 1996/10/29 14:10:36 mustafa $ */
24 /*                                                                      *
25  *  calctool.h                                                          *
26  *   Contains the none user interface includes for the Desktop          *
27  *   Calculator.                                                        *
28  *                                                                      *
29  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
30  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
31  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
32  * (c) Copyright 1993, 1994 Novell, Inc.                                *
33  */
34
35 #include <float.h>
36
37 #include <locale.h>
38 #include <X11/Intrinsic.h>
39 #include <Dt/UserMsg.h>
40 #include <Dt/DtNlUtils.h>
41
42 #ifdef XGETTEXT
43 #define  MSGFILE_LABEL    "dtcalc.label"
44 #define  MSGFILE_MESSAGE  "dtcalc.message"
45 #else
46 extern char *MSGFILE_LABEL ;
47 extern char *MSGFILE_MESSAGE ;
48 #endif
49
50 #define  DGET(s)          (s)
51 #define  LGET(s)          (char *) dgettext(MSGFILE_LABEL,   s)
52 #define  MGET(s)          (char *) dgettext(MSGFILE_MESSAGE, s)
53
54 #define  dgettext(f, s)   (s)
55 #define  bindtextdomain(f, s)
56
57 #ifndef NO_MESSAGE_CATALOG
58 # define _CLIENT_CAT_NAME "dtcalc"
59 extern char *_DtGetMessage(char *filename, int set, int n, char *s);
60 # define GETMESSAGE(set, number, string)\
61     (_DtGetMessage(_CLIENT_CAT_NAME, set, number, string))
62 #else
63 # define GETMESSAGE(set, number, string)\
64     string
65 #endif
66
67 #if !(defined(sun) && (_XOPEN_VERSION==3))
68 #ifndef DOMAIN
69 #define DOMAIN     1
70 #endif
71 #ifndef SING
72 #define SING       2
73 #endif
74 #ifndef OVERFLOW
75 #define OVERFLOW   3
76 #endif
77 #ifndef UNDERFLOW
78 #define UNDERFLOW  4
79 #endif
80 #ifndef TLOSS
81 #define TLOSS      5
82 #endif
83 #ifndef PLOSS
84 #define PLOSS      6
85 #endif
86 #ifndef HUGE
87 #define HUGE       FLT_MAX
88 #endif
89 #endif  /* sun */
90
91 /* For all function declarations, if ANSI then use a prototype. */
92
93 #if  defined(__STDC__)
94 #define P(args)  args
95 #else  /* ! __STDC__ */
96 #define P(args)  ()
97 #endif  /* STDC */
98
99 #ifdef hpux
100 #define HIL_PC101_KBD           1
101 #define HIL_ITF_KBD             2
102 #define SERIAL_PC101_KBD        3
103 #define FIRST_HIL_KBD           0xC0
104 #define LAST_HIL_KBD            0xDF
105 #define LED_BITS                0x30
106 #define PS2_DIN_NAME            "PS2_DIN_KEYBOARD"
107 #endif
108
109 extern char *getenv   P((const char *)) ;
110 extern char *mktemp   P((char *)) ;
111
112 extern double drand48 P(()) ;
113
114 #define  MEM    1
115 #define  FIN    2
116
117 #define FIN_EPSILON 1.0e-10
118 #define MAX_FIN_ITER 1000
119
120 #define  MP_SIZE      150     /* Size of the multiple precision values. */
121
122 #define  FCLOSE       (void) fclose     /* To make lint happy. */
123 #define  FPRINTF      (void) fprintf
124 #define  FPUTS        (void) fputs
125 #define  FREE         (void) free
126 #define  MEMCPY       (void) memcpy
127 #define  MKTEMP       (void) mktemp
128 #define  REWIND       (void) rewind
129 #define  SPRINTF      (void) sprintf
130 #define  SSCANF       (void) sscanf
131 #define  STRCPY       (void) strcpy
132 #define  STRNCAT      (void) strncat
133 #define  UNLINK       (void) unlink
134
135 /* Various pseudo events used by the dtcalc program. */
136 #define  KEYBOARD_DOWN    100    /* Keyboard character was pressed. */
137 #define  KEYBOARD_UP      101    /* Keyboard character was released. */
138 #define  LASTEVENTPLUSONE 102    /* Not one of the above. */
139 #define  F4_PRESS         103    
140 #define  ARROW            104
141 #define  TAB              105
142 #define  CONTROL          106
143 #define  SHIFT            107
144 #define  SPACE            108
145 #define  ESCAPE           109
146 #define  META             110
147 #define  ALT              111
148 #define  NUM_LOCK         77
149
150 enum base_type { BIN, OCT, DEC, HEX } ;      /* Base definitions. */
151
152 /* Command line options (for saving). */
153 enum cmd_type { CMD_ACC,    CMD_MODE,  CMD_BASE,  CMD_DISP,  CMD_MENU_BAR,
154                 CMD_SESSION,  CMD_TRIG,  CMD_DUMMY } ;
155
156 /* Frame/Canvas/Pixwin types. */
157 enum fcp_type  { FCP_KEY, FCP_REG, FCP_MODE, FCP_FIN_REG } ;
158
159 /* Help string types. */
160 enum help_type { H_ACC,        H_BASE,    H_CON,     H_EXCH,
161                  H_FUN,        H_MODE,    H_NUM,
162                  H_RCL,        H_STO,     H_TRIG,
163                  H_ABUT,       H_AFRAME,  H_APANEL,
164                  H_APPEARANCE, H_APPLY,   H_ATEXT,   H_CFCBUT,
165                  H_CFDESC,     H_CFFRAME, H_CFNO,    H_CFPANEL,
166                  H_CFVAL,      H_DEF,     H_DISPLAY, H_PFRAME,
167                  H_PPANEL,     H_RESET,   H_STYLE,   H_DUMMY } ;
168
169 /* Pseudo panel items. */
170 enum item_type { BASEITEM, TTYPEITEM, NUMITEM,  HYPITEM,
171                  INVITEM,  OPITEM,    MODEITEM, DISPLAYITEM } ;
172
173 /* Motif labels for various items. */
174 enum label_type { L_LCALC,  L_UCALC,  L_CONNO,   L_NEWCON, L_FUNNO,
175                   L_NEWFUN, L_MEMT,   L_PROPT,   L_DESC,   L_VALUE,
176                   L_CONB,   L_FUNB,   L_FINMEMT, L_DUMMY } ;
177
178 /* Popup menu types. */
179 enum menu_type { M_ACC,  M_BASE, M_CON,  M_EXCH, M_FUN,  M_MODE,
180                  M_NUM,  M_RCL,  M_STO,  M_TRIG, M_NONE
181 } ;
182
183 /* Message string types. */
184 enum mess_type { MESS_PARAM, MESS_CON,  MESS_DUMMY } ;
185
186 /* Calculator modes. */
187 enum mode_type { FINANCIAL, LOGICAL, SCIENTIFIC } ;
188
189 enum mp_type { MP_ADD2A, MP_ADD2B, MP_PART1, MP_ASIN,   /* MP error types. */
190                MP_ATAN,  MP_CHKC,
191                MP_CHKD,  MP_CHKE,  MP_CHKF,  MP_CHKG,
192                MP_CHKH,  MP_CHKI,  MP_CHKJ,  MP_CHKL,
193                MP_CHKM,  MP_CHKN,  MP_CMD,   MP_CMR,
194                MP_CQM,   MP_DIVA,  MP_DIVB,  MP_DIVIA,
195                MP_DIVIB, MP_EXPA,  MP_EXPB,  MP_EXP1,
196                MP_LNA,   MP_LNB,   MP_LNSA,
197                MP_LNSB,  MP_LNSC,  MP_MULA,  MP_MULB,
198                MP_MULC,  MP_MUL2A, MP_MUL2B, MP_MULQ,
199                MP_NZRA,  MP_NZRB,  MP_NZRC,
200                MP_OVFL,  MP_PI,    MP_PWRA,
201                MP_PWRB,  MP_PWR2A, MP_PWR2B, MP_RECA,
202                MP_RECB,  MP_RECC,  MP_RECD,  MP_ROOTA,
203                MP_ROOTB, MP_ROOTC, MP_ROOTD,
204                MP_ROOTE, MP_ROOTF, MP_SETB,
205                MP_SETC,  MP_SETD,  MP_SETE,  MP_SIN,
206                MP_SIN1,  MP_SQRT,  MP_TAN,   MP_DUMMY } ;
207
208 enum num_type { ENG, FIX, SCI } ;            /* Number display mode. */
209
210 enum op_type { OP_SET, OP_CLEAR, OP_NOP } ;  /* Operation item settings. */
211
212 enum opt_type { O_ACCVAL, O_ACCRANGE, O_BASE,     O_DISPLAY,
213                 O_MODE,   O_TRIG,     O_SESSION,  O_DUMMY } ;
214
215 enum prop_type { P_CHAR, P_ASCIIT, P_DUMMY } ;
216
217 /* Resources. */
218 enum res_type { R_ACCURACY, R_BASE,    R_DISPLAY, R_MODE,  R_FREGS,
219                 R_REGS,     R_TRIG,    R_BEEP,    R_ICON,  R_WORKSPACE,
220                 R_HEIGHT,   R_WIDTH,   R_X,       R_Y,     R_DISPLAYED,    
221                 R_REG0,     R_REG1,    R_REG2,    R_REG3,  R_REG4,    
222                 R_REG5,     R_REG6,    R_REG7,    R_REG8,  R_REG9,    
223                 R_FREG0,    R_FREG1,   R_FREG2,   R_FREG3, R_FREG4,
224                 R_FREG5,    R_MENUBAR, R_KEYS,    R_DUMMY } ;
225
226 enum trig_type { DEG, GRAD, RAD } ;          /* Trigonometric types. */
227
228 /* Usage message types. */
229 enum usage_type { USAGE1, USAGE2, USAGE3, U_DUMMY } ;
230
231 enum var_type { V_CANCEL,
232                 V_CLR,      V_CONFIRM,  V_CONTINUE,
233                 V_CONWNAME, V_ERROR,
234                 V_FUNWNAME, V_HYP,      V_INV,
235                 V_INVCON,   V_LCON,     V_LFUN,
236                 V_NOCHANGE, V_NUMSTACK, V_OPSTACK,  V_OWRITE,
237                 V_RANGE,    V_TRUE,     V_UCON,     V_UFUN,
238                 V_NORSAVE,  V_DUMMY } ;
239
240 /* Abbreviations for the dtcalc keyboard and menu equivalents. */
241
242 #define  KEY_BLNKD buttons[0].value       /* q */
243 #define  KEY_FUN   buttons[1].value       /* F */
244 #define  KEY_CON   buttons[2].value       /* # */
245 #define  KEY_KEYS  buttons[3].value       /* k */
246
247 #define  KEY_INT   buttons[4].value       /* CTL('i') */
248 #define  KEY_FRAC  buttons[5].value       /* CTL('f') */
249 #define  KEY_ABS   buttons[6].value       /* CTL('u') */
250 #define  KEY_EXP   buttons[7].value       /* E */
251
252 #define  KEY_ACC   buttons[8].value       /* A */
253 #define  KEY_STO   buttons[9].value       /* S */
254 #define  KEY_RCL   buttons[10].value       /* R */
255 #define  KEY_EXCH  buttons[11].value       /* X */
256
257 #define  KEY_BLNK1 buttons[12].value       /* q */
258 #define  KEY_BLNK2 buttons[13].value       /* q */
259 #define  KEY_BLNK3 buttons[14].value       /* q */
260 #define  KEY_BLNK4 buttons[15].value       /* q */
261
262 #define  KEY_BLNK5 buttons[16].value       /* q */
263 #define  KEY_BLNK6 buttons[17].value       /* q */
264 #define  KEY_BLNK7 buttons[18].value       /* q */
265 #define  KEY_BLNK8 buttons[19].value       /* q */
266
267 #define  KEY_BLNK9 buttons[20].value       /* q */
268 #define  KEY_BLNKA buttons[21].value       /* q */
269 #define  KEY_BLNKB buttons[22].value       /* q */
270 #define  KEY_BLNKC buttons[23].value       /* q */
271
272 #define  KEY_REC   buttons[24].value       /* r */
273 #define  KEY_SQR   buttons[25].value       /* @ */
274 #define  KEY_SQRT  buttons[26].value       /* s */
275 #define  KEY_PER   buttons[27].value       /* % */
276
277 #define  KEY_LPAR  buttons[28].value       /* ( */
278 #define  KEY_RPAR  buttons[29].value       /* ) */
279 #define  KEY_BSP   buttons[30].value       /* CTL('h') */
280 #define  KEY_CLR   buttons[31].value       /* del */
281
282 #define  KEY_D     buttons[32].value       /* d */
283 #define  KEY_E     buttons[33].value       /* e */
284 #define  KEY_F     buttons[34].value       /* f */
285 #define  KEY_CHS   buttons[35].value       /* C */
286
287 #define  KEY_A     buttons[36].value       /* a */
288 #define  KEY_B     buttons[37].value       /* b */
289 #define  KEY_C     buttons[38].value       /* c */
290 #define  KEY_MUL   buttons[39].value       /* x */
291
292 #define  KEY_7     buttons[40].value       /* 7 */
293 #define  KEY_8     buttons[41].value       /* 8 */
294 #define  KEY_9     buttons[42].value       /* 9 */
295 #define  KEY_DIV   buttons[43].value       /* / */
296
297 #define  KEY_4     buttons[44].value       /* 4 */
298 #define  KEY_5     buttons[45].value       /* 5 */
299 #define  KEY_6     buttons[46].value       /* 6 */
300 #define  KEY_SUB   buttons[47].value       /* - */
301
302 #define  KEY_1     buttons[48].value       /* 1 */
303 #define  KEY_2     buttons[49].value       /* 2 */
304 #define  KEY_3     buttons[50].value       /* 3 */
305 #define  KEY_ADD   buttons[51].value       /* + */
306
307 #define  KEY_0     buttons[52].value       /* 0 */
308 #define  KEY_PNT   buttons[53].value       /* . */
309 #define  KEY_EQ    buttons[54].value       /* = */
310 #define  KEY_QUIT  buttons[55].value       /* q */
311
312 /* these are the extra definitions for MODE, BASE, and DISP */
313 #define  KEY_BASE  buttons[56].value       /* B */
314 #define  KEY_DISP  buttons[57].value       /* D */
315 #define  KEY_MODE  buttons[58].value       /* M */
316 #define  KEY_TRIG  buttons[59].value       /* T */
317
318 #define  ACC_START 0                             /* 0 */
319 #define  ACC_END   9                             /* 9 */
320
321 #define  MEM_START 10                            /* 0 */
322 #define  MEM_END   19                            /* 9 */
323
324 #define  BASE_BIN  menu_entries[20].val          /* b */
325 #define  BASE_OCT  menu_entries[21].val          /* o */
326 #define  BASE_DEC  menu_entries[22].val          /* d */
327 #define  BASE_HEX  menu_entries[23].val          /* h */
328
329 #define  DISP_ENG  menu_entries[24].val          /* e */
330 #define  DISP_FIX  menu_entries[25].val          /* f */
331 #define  DISP_SCI  menu_entries[26].val          /* s */
332
333 #define  TRIG_DEG  menu_entries[27].val          /* d */
334 #define  TRIG_GRA  menu_entries[28].val          /* g */
335 #define  TRIG_RAD  menu_entries[29].val          /* r */
336
337 #define  MODE_BAS  menu_entries[30].val          /* b */
338 #define  MODE_FIN  menu_entries[31].val          /* f */
339 #define  MODE_LOG  menu_entries[32].val          /* l */
340 #define  MODE_SCI  menu_entries[33].val          /* s */
341
342 #define  KEY_TERM  mode_buttons[0].value         /* T */
343 #define  KEY_RATE  mode_buttons[1].value         /* CTL('r') */
344 #define  KEY_PV    mode_buttons[2].value         /* p */
345 #define  KEY_PMT   mode_buttons[3].value         /* P */
346 #define  KEY_FV    mode_buttons[4].value         /* v */
347 #define  KEY_PYR   mode_buttons[5].value         /* y */
348 #define  KEY_FCLR  mode_buttons[6].value         /* L */
349 #define  KEY_CTRM  mode_buttons[7].value         /* CTL('t') */
350 #define  KEY_DDB   mode_buttons[8].value         /* CTL('d') */
351 #define  KEY_SLN   mode_buttons[9].value         /* CTL('s') */
352 #define  KEY_SYD   mode_buttons[10].value        /* CTL('y') */
353
354 #define  KEY_LSFT  mode_buttons[16].value        /* < */
355 #define  KEY_RSFT  mode_buttons[17].value        /* > */
356 #define  KEY_16    mode_buttons[18].value        /* [ */
357 #define  KEY_32    mode_buttons[19].value        /* ] */
358 #define  KEY_OR    mode_buttons[20].value        /* | */
359 #define  KEY_AND   mode_buttons[21].value        /* & */
360 #define  KEY_NOT   mode_buttons[22].value        /* ~ */
361 #define  KEY_XOR   mode_buttons[23].value        /* ^ */
362 #define  KEY_XNOR  mode_buttons[24].value        /* n */
363
364 #define  KEY_INV   mode_buttons[32].value        /* i */
365 #define  KEY_HYP   mode_buttons[33].value        /* h */
366 #define  KEY_ETOX  mode_buttons[34].value        /* { */
367 #define  KEY_TTOX  mode_buttons[35].value        /* } */
368 #define  KEY_YTOX  mode_buttons[36].value        /* y */
369 #define  KEY_FACT  mode_buttons[37].value        /* ! */
370 #define  KEY_COS   mode_buttons[38].value        /* CTL('c') */
371 #define  KEY_SIN   mode_buttons[39].value        /* CTL('s') */
372 #define  KEY_TAN   mode_buttons[40].value        /* CTL('t') */
373 #define  KEY_LN    mode_buttons[41].value        /* N */
374 #define  KEY_LOG   mode_buttons[42].value        /* G */
375 #define  KEY_RAND  mode_buttons[43].value        /* ? */
376
377 #define  BCOLS          4          /* No of columns of buttons. */
378 #define  BROWS          14          /* No of rows of buttons. */
379 #define  CALC_CANCEL    1          /* Cancel button pressed on notice. */
380 #define  CALC_CONFIRM   2          /* Confirm button pressed on notice. */
381 #define  CTL(n)         n - 96     /* Generate control character value. */
382 #define  EQUAL(a, b)    !strncmp(a, b, strlen(b))
383 #define  EXTRA          4          /* Extra useful character definitions. */
384
385 #define  INC            { argc-- ; argv++ ; }
386 #define  IS_KEY(v, n)   (v == n)
387
388 #ifndef  LINT_CAST
389 #ifdef   lint
390 #define  LINT_CAST(arg)  (arg ? 0 : 0)
391 #else
392 #define  LINT_CAST(arg)  (arg)
393 #endif /*lint*/
394 #endif /*LINT_CAST*/
395
396 #define  MAXCMDS        (int) CMD_DUMMY   /* Max. no. of command line opts. */
397 #define  MAX_DIGITS     41         /* Maximum displayable number of digits. */
398
399 /* Maximum number of various graphics pieces. */
400 #define  MAXFCP         3          /* Max no of frames/canvases/pixwins. */
401 #define  MAXHELP        (int) H_DUMMY     /* Max. no. help strings. */
402 #define  MAXIMAGES      3          /* Maximum number of button images. */
403 #define  MAXITEMS       8          /* Maximum number of panel items. */
404 #define  MAXLABELS      (int) L_DUMMY     /* Max no. Motif label strings. */
405 #define  MAXMENUS       13         /* Maximum number of popup menus. */
406 #define  MAXMESS        (int) MESS_DUMMY  /* Max. no. message strings. */
407 #define  MAXMPERRS      (int) MP_DUMMY    /* Max. no. MP error types. */
408
409 #ifndef  MAXLINE
410 #define  MAXLINE        256               /* Length of character strings. */
411 #endif /*MAXLINE*/
412
413 #define  MAXBASES       4                 /* Max. no. of numeric bases. */
414 #define  MAXDISPMODES   3                 /* Max. no. of display modes. */
415 #define  MAXENTRIES     55                /* Max. no. of menu entries. */
416 #define  MAXMODES       3                 /* Max. no. of calculator modes. */
417 #define  MAXOPTS        (int) O_DUMMY     /* Max. no. option types. */
418 #define  MAXPSTRS       (int) P_DUMMY     /* Max. no. property strings. */
419 #define  MAXREGS        10                /* Max. no. of memory registers. */
420 #define  FINREGS        6                 /* Max. no. of Fin. memory regs. */
421 #define  MAXRESOURCES   (int) R_DUMMY     /* Max. number. of X resources. */
422 #define  MAXSTACK       256               /* Parenthese stack size. */
423 #define  MAXTRIGMODES   3                 /* Max. no. of trig. modes. */
424 #define  MAXUSAGE       (int) U_DUMMY     /* Max. no. usage strings. */
425 #define  MAXVKEYS       6                 /* No. of valid keys after error. */
426 #define  MAXVMESS       (int) V_DUMMY     /* Max. no. various messages. */
427
428 #define  MCOLS          8              /* No. of columns of "special" keys. */
429 #define  MROWS          2              /* No. of rows of "special" keys. */
430 #define  MODEKEYS       MCOLS * MROWS
431
432 #define  MAXCOLS        BCOLS
433 #define  MAXROWS        BROWS
434
435 #ifndef  MIN
436 #define  MIN(x,y)       ((x) < (y) ? (x) : (y))
437 #endif /*MIN*/
438
439 #define  NOBUTTONS      BROWS * BCOLS
440
441 #ifndef  RCNAME
442 #define  RCNAME         ".dtcalcrc"
443 #endif /*RCNAME*/
444
445 #define  TITEMS         NOBUTTONS + EXTRA      /* Total definitions. */
446
447 #ifndef  TRUE                    /* Boolean definitions. */
448 #define  TRUE           1
449 #endif /*TRUE*/
450
451 #ifndef  FALSE
452 #define  FALSE          0
453 #endif /*FALSE*/
454
455 typedef  unsigned long  BOOLEAN ;
456
457 struct button {
458   char *str ;               /* Button display string. */
459   char *str2 ;              /* Button display string, with key. */
460   char value ;              /* Unique button keyboard equivalent. */
461   enum op_type opdisp ;     /* Is button selected during operation? */
462   enum menu_type mtype ;    /* Type of popup menu (if any). */
463   char *resname ;           /* Button resource name. */
464   void (*func)() ;          /* Function to obey on button press. */
465 } ;
466
467 struct menu_entry {
468   char *str ;               /* Menu entry string to be displayed. */
469   char val ;                /* Value when selected. */
470 } ;
471
472 struct menu {
473   char *title ;             /* Menu title. */
474   int  total ;              /* Number of menu entries. */
475   int  mindex ;             /* Index into menu string array. */
476   int  defval ;             /* Default menu item position (from 1). */
477 } ;
478
479 struct calcVars {                     /* Calctool variables and options. */
480   char *appname ;                     /* Application name for resources. */
481   char con_names[MAXREGS][MAXLINE] ;  /* Selectable constant names. */
482   char cur_op ;                       /* Current arithmetic operation. */
483   char current ;                      /* Current button/character pressed. */
484   char display[MAXLINE] ;             /* Current calculator display. */
485   char *exp_posn ;                    /* Position of the exponent sign. */
486   char fnum[MAX_DIGITS+1] ;           /* Scratchpad for fixed numbers. */
487   char fun_names[MAXREGS][MAXLINE] ;  /* Function names from .dtcalcrc. */
488   char fun_vals[MAXREGS][MAXLINE] ;   /* Function defs from .dtcalcrc. */
489   char *iconlabel ;                   /* The dtcalc icon label. */
490   char old_cal_value ;                /* Previous calculation operator. */
491   char *progname ;                    /* Name of this program. */
492   char pstr[5] ;                      /* Current button text string. */
493   char *selection ;                   /* Current [Get] selection. */
494   char *shelf ;                       /* PUT selection shelf contents. */
495   char snum[MAX_DIGITS+1] ;           /* Scratchpad for scientific numbers. */
496   char *titleline ;                   /* Value of titleline (if present). */
497   char *workspaces ;                  /* workspace names calc is in */
498
499   int x;
500   int y;
501   int width;
502   int height;
503
504   int MPcon_vals[MAXREGS][MP_SIZE] ;  /* Selectable constants. */
505   int MPdebug ;                       /* If set, debug info. to stderr. */
506   int MPerrors ;                      /* If set, output errors to stderr. */
507   int MPdisp_val[MP_SIZE] ;           /* Value of the current display. */
508   int MPlast_input[MP_SIZE] ;         /* Previous number input by user. */
509   int MPmvals[MAXREGS][MP_SIZE] ;     /* Memory register values. */
510   double MPfvals[FINREGS] ;           /* Financial Memory register values. */
511   int *MPnumstack[MAXSTACK] ;         /* Numeric stack for parens. */
512   int MPresult[MP_SIZE] ;             /* Current calculator total value. */
513   int MPtresults[3][MP_SIZE] ;        /* Current trigonometric results. */
514
515   enum base_type base ;            /* Current base: BIN, OCT, DEC or HEX. */
516   enum fcp_type curwin ;           /* Window current event occurred in. */
517   enum fcp_type pending_win ;      /* Window that pending op came from. */
518   enum mode_type modetype ;        /* Current calculator mode. */
519   enum mode_type pending_mode ;    /* Mode for pending op. */
520   enum num_type dtype ;            /* Number display mode. */
521   enum trig_type ttype ;           /* Trig. type (deg, grad or rad). */
522   BOOLEAN num_lock;    /* Indicator of the state of NUM_LOCK */
523   int accuracy ;      /* Number of digits precision (Max 9). */
524   int beep ;          /* Indicates whether there is a beep sound on error. */
525   int column ;        /* Column number of current key/mouse press. */
526   int cur_ch ;        /* Current character if keyboard event. */
527   int error ;         /* Indicates some kind of display error. */
528   int event_type ;    /* Type of event being currently processed. */
529   int hasicon ;       /* Set if user gave icon name on command line. */
530   int hyperbolic ;    /* If set, trig functions will be hyperbolic. */
531   int iconic ;        /* Set if window is currently iconic. */
532   int inverse ;       /* If set, trig and log functions will be inversed. */
533   int ismenu ;        /* Set when do_pending called via a popup menu. */
534   int key_exp ;       /* Set if entering exponent number. */
535   int new_input ;     /* New number input since last op. */
536   int noparens ;      /* Count of left brackets still to be matched. */
537   int numsptr ;       /* Pointer into the parenthese numeric stack. */
538   int opsptr ;        /* Pointer into the parentheses operand stack. */
539   int opstack[MAXSTACK] ;  /* Stack containing parentheses input. */
540   int pending ;            /* Set for command depending on multiple presses. */
541   int pending_n ;     /* Offset into function table for pending op. */
542   int pending_op ;    /* Arithmetic operation for pending command. */
543   int pointed ;       /* Whether a decimal point has been given. */
544   int row ;           /* Row number of current key/mouse press. */
545   int rstate ;        /* Indicates if memory register frame is displayed. */
546   int frstate ;       /* Indicates if financial memory register 
547                          frame is displayed. */
548   int show_paren ;    /* Set if we wish to show DISPLAYITEM during parens. */
549   int started ;       /* Set just before window is displayed. */
550   int toclear ;       /* Indicates if display should be cleared. */
551   int tstate ;        /* Indicates current button set being displayed. */
552   int funstate ;      /* whether the last key pressed was a fin. func. key*/
553   int defState ;      /* Set when calculator has just been cleared */
554
555 #ifdef hpux
556   int keybdID;
557 #endif
558 } CalcVars ;
559
560 typedef struct calcVars *Vars ;
561
562 /*  Structure, resource definitions, for View's optional parameters.  */
563 typedef struct
564 {
565    short menuBar;
566    int accuracy;
567    char *base;
568    char *display;
569    char *mode;
570    char *trigType;
571    char *session;
572 } ApplicationArgs, *ApplicationArgsPtr;
573
574 ApplicationArgs application_args;
575
576 /* MP definitions. */
577
578 #define  C_abs(x)    ((x) >= 0 ? (x) : -(x))
579 #define  dabs(x)     (double) C_abs(x)
580 #define  min(a, b)   ((a) <= (b) ? (a) : (b))
581 #define  max(a, b)   ((a) >= (b) ? (a) : (b))
582 #define  dmax(a, b)  (double) max(a, b)
583 #define  dmin(a, b)  (double) min(a, b)
584
585 BOOLEAN ibool                P((double)) ;
586 BOOLEAN ibool2                P((double)) ;
587
588 char *convert                P((char *)) ;
589 char *get_resource           P((enum res_type)) ;
590 char *make_eng_sci           P((int *)) ;
591 char *make_fixed             P((int *, int)) ;
592 char *make_number            P((int *, BOOLEAN)) ;
593
594 double mppow_di              P((double *, int *)) ;
595 double mppow_ri              P((float *, int *)) ;
596 double setbool               P((BOOLEAN)) ;
597
598 int char_val               P((char)) ;
599 int get_bool_resource      P((enum res_type, int *)) ;
600 int get_index              P((char)) ;
601 int get_int_resource       P((enum res_type, int *)) ;
602 int get_str_resource       P((enum res_type, char *)) ;
603 int main                   P((int, char **)) ;
604
605 void beep                  P(()) ;
606 void check_ow_beep         P(()) ;
607 void clear_display         P(()) ;
608 void doerr                 P((char *)) ;
609 void do_accuracy           P(()) ;
610 void do_ascii              P(()) ;
611 void do_base               P(()) ;
612 void set_base              P(()) ;
613 void do_business           P(()) ;
614 void do_calc               P(()) ;
615 void do_dtcalc             P((int, char **)) ;
616 void do_clear              P(()) ;
617 void do_constant           P(()) ;
618 void do_delete             P(()) ;
619 void do_exchange           P(()) ;
620 void do_expno              P(()) ;
621 void do_factorial          P((int *, int *)) ;
622 void do_frame              P(()) ;
623 void do_function           P(()) ;
624 void do_immed              P(()) ;
625 void do_keys               P(()) ;
626 void do_mode               P(()) ;
627 void do_none               P(()) ;
628 void do_number             P(()) ;
629 void do_numtype            P(()) ;
630 void do_paren              P(()) ;
631 void set_numtype           P((enum num_type dtype));
632 void do_nothing            P(()) ;
633 void do_pending            P(()) ;
634 void do_point              P(()) ;
635 void do_portion            P(()) ;
636 double do_round            P((double, int)) ;
637 void do_shift              P(()) ;
638 void do_sto_rcl            P(()) ;
639 void do_trig               P(()) ;
640 void do_trigtype           P(()) ;
641 void draw_button           P((int, enum fcp_type, int, int, int)) ;
642 void get_display           P(()) ;
643 void get_key_val           P((char *, char *)) ;
644 void get_label             P((int)) ;
645 void get_options           P((int, char **)) ;
646 void getparam              P((char *, char **, char *)) ;
647 void get_rcfile            P((char *)) ;
648 void grey_button           P((int, int, int)) ;
649 void grey_buttons          P((enum base_type)) ;
650 void handle_menu_selection P((int, int)) ;
651 void handle_selection      P(()) ;
652 void initialize            P(()) ;
653 void init_cmdline_opts     P(()) ;
654 void init_graphics         P(()) ;
655 void init_options          P(()) ;
656 void init_text             P(()) ;
657 void init_vars             P(()) ;
658 void key_init              P(()) ;
659 void load_resources        P(()) ;
660 void make_frames           P(()) ;
661 void make_items            P(()) ;
662 void make_modewin          P(()) ;
663 void make_fin_registers    P(()) ;
664 void make_registers        P((int)) ;
665 void MPstr_to_num          P((char *, enum base_type, int *)) ;
666 void paren_disp            P((char)) ;
667 void process_event         P((int)) ;
668 void process_item          P((int)) ;
669 void process_parens        P((char)) ;
670 void process_stack         P((int, int, int)) ;
671 void process_str           P((char *, enum menu_type)) ;
672 void push_num              P((int *)) ;
673 void push_op               P((int)) ;
674 void put_resource          P((enum res_type, char *)) ;
675 void read_rcfiles          P(()) ;
676 void read_resources        P(()) ;
677 void redraw_buttons        P(()) ;
678 void save_cmdline          P((int, char **)) ;
679 void save_pending_values   P((int)) ;
680 void save_resources        P((char *)) ;
681 void blank_display         P(()) ;
682 void ErrorDialog           P((char *string));
683 void set_item              P((enum item_type, char *)) ;
684 void set_title             P((enum fcp_type, char *)) ;
685 void show_ascii_frame      P(()) ;
686 void show_display          P((int *)) ;
687 void srand48               P(()) ;
688 void start_tool            P(()) ;
689 void switch_hands          P((int)) ;
690 void usage                 P((char *)) ;
691 void win_display           P((enum fcp_type, int)) ;
692 void write_cmdline         P(()) ;
693 void write_rcfile          P((enum menu_type, int, int, char *, char *)) ;
694 void write_resources       P((char *)) ;
695 void RestoreSession        P(()) ;
696 void TimerEvent            P(( XtPointer, XtIntervalId *)) ;
697 void ErrDialog             P(( char *, Widget ));
698
699 /* MP routines not found in the Brent FORTRAN package. */
700 void mpacos                P((int *, int *)) ;
701 void mpacosh               P((int *, int *)) ;
702 void mpasinh               P((int *, int *)) ;
703 void mpatanh               P((int *, int *)) ;
704 void mplog10               P((int *, int *)) ;
705
706 /* Brent MP routines in mp.c. */
707 int mpcmpi        P((int *, int *)) ;
708 int mpcmpr        P((int *, float *)) ;
709 int mpcomp        P((int *, int *)) ;
710 int pow_ii        P((int *, int *)) ;
711  
712 int mpeq          P((int *, int *)) ;
713 int mpge          P((int *, int *)) ;
714 int mpgt          P((int *, int *)) ;
715 int mple          P((int *, int *)) ;
716 int mplt          P((int *, int *)) ;
717
718 void mpabs        P((int *, int *)) ;
719 void mpadd        P((int *, int *, int *)) ;
720 void mpadd2       P((int *, int *, int *, int *, int *)) ;
721 void mpadd3       P((int *, int *, int *, int *, int *)) ;
722 void mpaddi       P((int *, int *, int *)) ;
723 void mpaddq       P((int *, int *, int *, int *)) ;
724 void mpart1       P((int *, int *)) ;
725 void mpasin       P((int *, int *)) ;
726 void mpatan       P((int *, int *)) ;
727 void mpcdm        P((double *, int *)) ;
728 void mpchk        P((int *, int *)) ;
729 void mpcim        P((int *, int *)) ;
730 void mpcmd        P((int *, double *)) ;
731 void mpcmf        P((int *, int *)) ;
732 void mpcmi        P((int *, int *)) ;
733 void mpcmim       P((int *, int *)) ;
734 void mpcmr        P((int *, float *)) ;
735 void mpcos        P((int *, int *)) ;
736 void mpcosh       P((int *, int *)) ;
737 void mpcqm        P((int *, int *, int *)) ;
738 void mpcrm        P((float *, int *)) ;
739 void mpdiv        P((int *, int *, int *)) ;
740 void mpdivi       P((int *, int *, int *)) ;
741 void mperr        P(()) ;
742 void mpexp        P((int *, int *)) ;
743 void mpexp1       P((int *, int *)) ;
744 void mpext        P((int *, int *, int *)) ;
745 void mpgcd        P((int *, int *)) ;
746 void mpln         P((int *, int *)) ;
747 void mplns        P((int *, int *)) ;
748 void mpmaxr       P((int *)) ;
749 void mpmlp        P((int *, int *, int *, int *)) ;
750 void mpmul        P((int *, int *, int *)) ;
751 void mpmul2       P((int *, int *, int *, int *)) ;
752 void mpmuli       P((int *, int *, int *)) ;
753 void mpmulq       P((int *, int *, int *, int *)) ;
754 void mpneg        P((int *, int *)) ;
755 void mpnzr        P((int *, int *, int *, int *)) ;
756 void mpovfl       P((int *)) ;
757 void mppi         P((int *)) ;
758 void mppwr        P((int *, int *, int *)) ;
759 void mppwr2       P((int *, int *, int *)) ;
760 void mprec        P((int *, int *)) ;
761 void mproot       P((int *, int *, int *)) ;
762 void mpset        P((int *, int *, int *)) ;
763 void mpsin        P((int *, int *)) ;
764 void mpsin1       P((int *, int *, int *)) ;
765 void mpsinh       P((int *, int *)) ;
766 void mpsqrt       P((int *, int *)) ;
767 void mpstr        P((int *, int *)) ;
768 void mpsub        P((int *, int *, int *)) ;
769 void mptanh       P((int *, int *)) ;
770 void mpunfl       P((int *)) ;
771
772 /* Help routines */
773 void Help                       P((char *, char *)) ;
774 void HelpRequestCB              P(()) ;
775 void HelpModeCB                 P(()) ;
776 void HelpCloseCB                P(()) ;
777 void HelpHyperlinkCB            P(()) ;
778 void DisplayHelp                P((char *, char *)) ;
779 void CenterMsgCB                P(()) ;
780 void HelpHelp                   P(()) ;
781 void SetWmHnts                  P(()) ;
782
783 void _DtmapCB                   P((Widget, XtPointer, XtPointer)) ;
784
785 void set_option_menu      P((int, int)) ;
786