home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / calctool / part02 / memory.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-29  |  4.2 KB  |  177 lines

  1. /************************************************************************/
  2. /*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  3. /*                                    */
  4. /*    Permission to use, copy, modify, and distribute this software    */
  5. /*    and its documentation for any purpose and without fee is    */
  6. /*    hereby granted, provided that the above copyright notice    */
  7. /*    appear in all copies and that both that copyright notice and    */
  8. /*    this permission notice appear in supporting documentation, and    */
  9. /*    that the name of Chuck Musciano and Harris Corporation not be    */
  10. /*    used in advertising or publicity pertaining to distribution    */
  11. /*    of the software without specific, written prior permission.    */
  12. /*    Chuck Musciano and Harris Corporation make no representations    */
  13. /*    about the suitability of this software for any purpose.  It is    */
  14. /*    provided "as is" without express or implied warranty.        */
  15. /************************************************************************/
  16.  
  17. /************************************************************************/
  18. /*                                    */
  19. /*    Module:        memory.c                    */
  20. /*                                    */
  21. /*    Function:    Manage calculator memories            */
  22. /*                                    */
  23. /*    Public Names:    store_proc    store a value            */
  24. /*            recall_proc    recall a value            */
  25. /*            exchange_proc    exchange a value and a memory    */
  26. /*            do_store    store in memory            */
  27. /*            do_recall    recall from memory        */
  28. /*            do_exchange    exchange with memory        */
  29. /*                                    */
  30. /*    Change History:    17 Nov 86    Creation            */
  31. /*            22 May 87    Added do_* procs        */
  32. /*                                    */
  33. /************************************************************************/
  34.  
  35. #include    <suntool/sunview.h>
  36. #include    <suntool/panel.h>
  37.  
  38. #include    "manifest.h"
  39. #include    "globals.h"
  40.  
  41. #define        HAS_STORE        0
  42. #define        NO_STORE        1
  43.  
  44. PUBLIC    Panel    keys;
  45. PUBLIC    struct    pixfont    *key_font;
  46.  
  47. PRIVATE    double    memory[MAX_MEMORY] = {0.0};
  48. PRIVATE    char    mem_image[MAX_MEMORY][60];
  49. PRIVATE    int    mem_count = 1;
  50. PRIVATE    Menu    menu = NULL;
  51.  
  52. PRIVATE    update_menu(store)
  53.  
  54. int    store;
  55.  
  56. {    int    i;
  57.  
  58.     if (menu)
  59.        menu_destroy(menu);
  60.     menu = menu_create(MENU_INITIAL_SELECTION, MENU_DEFAULT, 0);
  61.     for (i = 0; i < mem_count; i++) {
  62.        sprintf(mem_image[i], "%2d: ", i);
  63.        convert_value(memory[i], &(mem_image[i][4]));
  64.        menu_set(menu, 
  65.                   MENU_ITEM, 
  66.                      MENU_STRING, mem_image[i], 
  67.                      MENU_FONT, key_font, 
  68.                      MENU_VALUE, i + 1, 
  69.                      0, 
  70.                   0);
  71.        }
  72.     if (store && mem_count < MAX_MEMORY)
  73.        menu_set(menu, 
  74.                   MENU_ITEM, 
  75.                      MENU_STRING, "New Memory", 
  76.                      MENU_FONT, key_font, 
  77.                      MENU_VALUE, i + 1, 
  78.                      0, 
  79.                   0);
  80.     menu_set(menu, MENU_DEFAULT, 1, 0);
  81. }
  82.  
  83. PUBLIC    do_store(slot)
  84.  
  85. int    slot;
  86.  
  87. {
  88.     memory[slot] = v_stack[v_top];
  89. }
  90.  
  91. PUBLIC    store_proc(item, event)
  92.  
  93. Panel_item    item;
  94. Event        *event;
  95.  
  96. {    int    slot;
  97.  
  98.     if (event_id(event) >= ASCII_FIRST && event_id(event) <= ASCII_LAST)
  99.        keyboard(event_id(event));
  100.     else {
  101.        convert_display();
  102.        if (event_id(event) == MS_RIGHT) {
  103.           update_menu(TRUE);
  104.           if (slot = (int) menu_show(menu, keys, event, 0)) {
  105.              do_store(--slot);
  106.              if (slot == mem_count)
  107.                 mem_count++;
  108.              }
  109.           }
  110.        else
  111.           do_store(0);
  112.        }
  113. }
  114.  
  115. PUBLIC    do_recall(slot)
  116.  
  117. int    slot;
  118.  
  119. {
  120.     v_stack[v_top] = memory[slot];
  121.     update_display();
  122. }
  123.  
  124. PUBLIC    recall_proc(item, event)
  125.  
  126. Panel_item    item;
  127. Event        *event;
  128.  
  129. {    int    slot;
  130.  
  131.     if (event_id(event) >= ASCII_FIRST && event_id(event) <= ASCII_LAST)
  132.        keyboard(event_id(event));
  133.     else {
  134.        clear_entry();
  135.        if (event_id(event) == MS_RIGHT) {
  136.           update_menu(FALSE);
  137.           if (slot = (int) menu_show(menu, keys, event, 0))
  138.              do_recall(--slot);
  139.           }
  140.        else
  141.           do_recall(0);
  142.        }
  143. }
  144.  
  145. PUBLIC    do_exchange(slot)
  146.  
  147. int    slot;
  148.  
  149. {    double    temp;
  150.  
  151.     temp = v_stack[v_top];
  152.     v_stack[v_top] = memory[slot];
  153.     memory[slot] = temp;
  154.     update_display();
  155. }
  156.  
  157. PUBLIC    exchange_proc(item, event)
  158.  
  159. Panel_item    item;
  160. Event        *event;
  161.  
  162. {    int    slot;
  163.  
  164.     if (event_id(event) >= ASCII_FIRST && event_id(event) <= ASCII_LAST)
  165.        keyboard(event_id(event));
  166.     else {
  167.        convert_display();
  168.        if (event_id(event) == MS_RIGHT) {
  169.           update_menu(FALSE);
  170.           if (slot = (int) menu_show(menu, keys, event, 0))
  171.              do_exchange(--slot);
  172.           }
  173.        else
  174.           do_exchange(0);
  175.        }
  176. }
  177.