home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************/
- /* Copyright 1988 by Chuck Musciano and Harris Corporation */
- /* */
- /* Permission to use, copy, modify, and distribute this software */
- /* and its documentation for any purpose and without fee is */
- /* hereby granted, provided that the above copyright notice */
- /* appear in all copies and that both that copyright notice and */
- /* this permission notice appear in supporting documentation, and */
- /* that the name of Chuck Musciano and Harris Corporation not be */
- /* used in advertising or publicity pertaining to distribution */
- /* of the software without specific, written prior permission. */
- /* Chuck Musciano and Harris Corporation make no representations */
- /* about the suitability of this software for any purpose. It is */
- /* provided "as is" without express or implied warranty. */
- /************************************************************************/
-
- /************************************************************************/
- /* */
- /* Module: memory.c */
- /* */
- /* Function: Manage calculator memories */
- /* */
- /* Public Names: store_proc store a value */
- /* recall_proc recall a value */
- /* exchange_proc exchange a value and a memory */
- /* do_store store in memory */
- /* do_recall recall from memory */
- /* do_exchange exchange with memory */
- /* */
- /* Change History: 17 Nov 86 Creation */
- /* 22 May 87 Added do_* procs */
- /* */
- /************************************************************************/
-
- #include <suntool/sunview.h>
- #include <suntool/panel.h>
-
- #include "manifest.h"
- #include "globals.h"
-
- #define HAS_STORE 0
- #define NO_STORE 1
-
- PUBLIC Panel keys;
- PUBLIC struct pixfont *key_font;
-
- PRIVATE double memory[MAX_MEMORY] = {0.0};
- PRIVATE char mem_image[MAX_MEMORY][60];
- PRIVATE int mem_count = 1;
- PRIVATE Menu menu = NULL;
-
- PRIVATE update_menu(store)
-
- int store;
-
- { int i;
-
- if (menu)
- menu_destroy(menu);
- menu = menu_create(MENU_INITIAL_SELECTION, MENU_DEFAULT, 0);
- for (i = 0; i < mem_count; i++) {
- sprintf(mem_image[i], "%2d: ", i);
- convert_value(memory[i], &(mem_image[i][4]));
- menu_set(menu,
- MENU_ITEM,
- MENU_STRING, mem_image[i],
- MENU_FONT, key_font,
- MENU_VALUE, i + 1,
- 0,
- 0);
- }
- if (store && mem_count < MAX_MEMORY)
- menu_set(menu,
- MENU_ITEM,
- MENU_STRING, "New Memory",
- MENU_FONT, key_font,
- MENU_VALUE, i + 1,
- 0,
- 0);
- menu_set(menu, MENU_DEFAULT, 1, 0);
- }
-
- PUBLIC do_store(slot)
-
- int slot;
-
- {
- memory[slot] = v_stack[v_top];
- }
-
- PUBLIC store_proc(item, event)
-
- Panel_item item;
- Event *event;
-
- { int slot;
-
- if (event_id(event) >= ASCII_FIRST && event_id(event) <= ASCII_LAST)
- keyboard(event_id(event));
- else {
- convert_display();
- if (event_id(event) == MS_RIGHT) {
- update_menu(TRUE);
- if (slot = (int) menu_show(menu, keys, event, 0)) {
- do_store(--slot);
- if (slot == mem_count)
- mem_count++;
- }
- }
- else
- do_store(0);
- }
- }
-
- PUBLIC do_recall(slot)
-
- int slot;
-
- {
- v_stack[v_top] = memory[slot];
- update_display();
- }
-
- PUBLIC recall_proc(item, event)
-
- Panel_item item;
- Event *event;
-
- { int slot;
-
- if (event_id(event) >= ASCII_FIRST && event_id(event) <= ASCII_LAST)
- keyboard(event_id(event));
- else {
- clear_entry();
- if (event_id(event) == MS_RIGHT) {
- update_menu(FALSE);
- if (slot = (int) menu_show(menu, keys, event, 0))
- do_recall(--slot);
- }
- else
- do_recall(0);
- }
- }
-
- PUBLIC do_exchange(slot)
-
- int slot;
-
- { double temp;
-
- temp = v_stack[v_top];
- v_stack[v_top] = memory[slot];
- memory[slot] = temp;
- update_display();
- }
-
- PUBLIC exchange_proc(item, event)
-
- Panel_item item;
- Event *event;
-
- { int slot;
-
- if (event_id(event) >= ASCII_FIRST && event_id(event) <= ASCII_LAST)
- keyboard(event_id(event));
- else {
- convert_display();
- if (event_id(event) == MS_RIGHT) {
- update_menu(FALSE);
- if (slot = (int) menu_show(menu, keys, event, 0))
- do_exchange(--slot);
- }
- else
- do_exchange(0);
- }
- }
-