home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / calctool / part01 / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-29  |  18.6 KB  |  608 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:        display.c                    */
  20. /*                                    */
  21. /*    Function:    Manage calculator display            */
  22. /*                                    */
  23. /*    Public Names:    update_display    resolve stack top and display    */
  24. /*            convert_display    convert user entry to stack top    */
  25. /*            convert_value    convert value to string        */
  26. /*            fix_proc    handle display widths        */
  27. /*            do_digit    handle digit input        */
  28. /*            clear_entry    clear any typed digits        */
  29. /*            keyboard    handle keyboard entries        */
  30. /*                                    */
  31. /*    Change History:    17 Nov 86    Creation            */
  32. /*                                    */
  33. /************************************************************************/
  34.  
  35. #include    <stdio.h>
  36.  
  37. #include    <suntool/sunview.h>
  38. #include    <suntool/panel.h>
  39. #include    <suntool/canvas.h>
  40.  
  41. #include    "manifest.h"
  42. #include    "globals.h"
  43. #include    "keys.h"
  44.  
  45. #define        DIGIT_FONT        "/usr/lib/fonts/fixedwidthfonts/gallant.r.19"
  46.  
  47. #define        margin(x)        (((curr_mode == SCIENTIFIC? 15 : 16) - strlen(x)) * DIGIT_WIDTH)
  48.  
  49. #define        MAX_DIGITS        ((curr_mode == SCIENTIFIC)? 14 : 16)
  50. #define        DIGIT_WIDTH        d_font->pf_defaultsize.x
  51. #define        DIGIT_HEIGHT        d_font->pf_defaultsize.y
  52. #define        STATUS_WIDTH        s_font->pf_defaultsize.x
  53. #define        STATUS_HEIGHT        s_font->pf_defaultsize.y
  54.  
  55. PUBLIC    double    atof();
  56. PUBLIC    char    *index();
  57.  
  58. PUBLIC    Canvas    display;
  59. PUBLIC    Panel    keys;
  60. PUBLIC    struct    pixfont    *key_font;
  61.  
  62. PRIVATE    Pixwin    *pw = NULL;
  63. PRIVATE    struct    pixfont    *d_font = NULL;
  64. PRIVATE    struct    pixfont    *s_font = NULL;
  65. PRIVATE    char    e_str[5], d_str[18];
  66. PRIVATE    int    e_len = 0;
  67. PRIVATE    int    d_len = 0;
  68. PRIVATE    int    pw_width;
  69. PRIVATE    int    pw_height;
  70. PRIVATE    char    *digit = "0123456789ABCDEF.E-";
  71.  
  72. PRIVATE    verify(source, valid)
  73.  
  74. char    *source;
  75. char    *valid;
  76.  
  77. {    register    char    *s;
  78.  
  79.     for ( ; *source; source++) {
  80.        for (s = valid; *s && *s != *source; s++)
  81.           ;
  82.        if (*s == '\0')
  83.           return(FALSE);
  84.        }
  85.     return(TRUE);
  86. }
  87.  
  88. PRIVATE    convert_stacktop()
  89.  
  90. {    char    buf[60], *p;
  91.  
  92.     convert_value(v_stack[v_top], buf);
  93.     if (curr_mode == SCIENTIFIC && (p = index(buf, 'E')) != NULL) {
  94.        strcpy(e_str, p + 1);
  95.        if (*e_str == '+')
  96.           strcpy(e_str, e_str + 1);
  97.        e_len = strlen(e_str);
  98.        if (e_len == 2) {
  99.           e_str[3] = '\0';
  100.           e_str[2] = e_str[1];
  101.           e_str[1] = e_str[0];
  102.           e_str[0] = '0';
  103.           e_len = 3;
  104.           }
  105.        else if (e_len == 3 && *e_str == '-') {
  106.           e_str[4] = '\0';
  107.           e_str[3] = e_str[2];
  108.           e_str[2] = e_str[1];
  109.           e_str[1] = '0';
  110.           e_len = 4;
  111.           }
  112.        *p = '\0';
  113.        }
  114.     else {
  115.        *e_str = '\0';
  116.        e_len = 0;
  117.        }
  118.     strcpy(d_str, buf);
  119.     d_len = strlen(d_str);
  120. }
  121.  
  122. PUBLIC    update_display()
  123.  
  124. {    char    buf[60], *p, *op_str();
  125.     int    i, w;
  126.     static    char    *tm[] = {"Deg ", "Rad ", "Grad"};
  127.  
  128.     if (d_font == NULL)
  129.        if ((d_font = pf_open(DIGIT_FONT)) == NULL) {
  130.           fprintf(stderr, "calctool: could not open font %s\n", DIGIT_FONT);
  131.           exit(1);
  132.           }
  133.     if (s_font == NULL)
  134.        if ((s_font = pf_open(STATUS_FONT)) == NULL) {
  135.           fprintf(stderr, "calctool: could not open font %s\n", DIGIT_FONT);
  136.           exit(1);
  137.           }
  138.     if (pw == NULL) {
  139.        pw = canvas_pixwin(display);
  140.        pw_width = (int) window_get(display, WIN_WIDTH);
  141.        pw_height = (int) window_get(display, WIN_HEIGHT);
  142.        }
  143.     for (i = w = 0; i < o_top && w < 23; w += strlen(op_str(o_stack[i++])))
  144.        pw_text(pw, w * STATUS_WIDTH + 1, 7, PIX_SRC, s_font, op_str(o_stack[i]));
  145.     for ( ; w < 23; w++)
  146.        pw_text(pw, w * STATUS_WIDTH + 1, 7, PIX_SRC, s_font, " ");
  147.     pw_text(pw, 23 * STATUS_WIDTH, 7, PIX_SRC, s_font, (curr_mode == SCIENTIFIC)? tm[trig_mode] : "    ");
  148.     if (curr_mode == SCIENTIFIC && ee_mode)
  149.        pw_text(pw, 28 * STATUS_WIDTH, 7, PIX_SRC, s_font, eng_mode? "Eng " : "EE  ");
  150.     else
  151.        pw_text(pw, 28 * STATUS_WIDTH, 7, PIX_SRC, s_font, "    ");
  152.     if (curr_mode == SCIENTIFIC)
  153.        if (curr_width[0] == -1)
  154.           strcpy(buf, "    Float");
  155.        else
  156.           sprintf(buf, "%2d Digits", curr_width[0]);
  157.     else
  158.        sprintf(buf, "  %2d Bits", curr_width[index_of(curr_base)]);
  159.     pw_text(pw, 32 * STATUS_WIDTH, 7, PIX_SRC, s_font, buf);
  160.     if (d_len > 0) {
  161.        if (e_len > 0) {
  162.           pw_text(pw, pw_width - 6 * DIGIT_WIDTH, 26, PIX_SRC, d_font, " e");
  163.           pw_text(pw, pw_width - 4 * DIGIT_WIDTH, 26, PIX_SRC, d_font, e_str);
  164.           if (e_len == 3)
  165.              pw_text(pw, pw_width - DIGIT_WIDTH, 26, PIX_SRC, d_font, " ");
  166.           }
  167.        else
  168.           pw_text(pw, pw_width - 6 * DIGIT_WIDTH, 26, PIX_SRC, d_font, "      ");
  169.        pw_rop(pw, 0, pw_height - DIGIT_HEIGHT + 1, margin(d_str), DIGIT_HEIGHT, PIX_SRC | PIX_COLOR(0), NULL, 0, 0);
  170.        pw_text(pw, margin(d_str), 26, PIX_SRC, d_font, d_str);
  171.        }
  172.     else {
  173.        convert_value(v_stack[v_top], buf);
  174.        if (strcmp(buf, "NaN") == 0) {
  175.           strcpy(buf, "       Error!   ");
  176.           pw_text(pw, pw_width - 6 * DIGIT_WIDTH, 26, PIX_SRC, d_font, "      ");
  177.           }
  178.        else if (curr_mode == SCIENTIFIC && (p = index(buf, 'E')) != NULL) {
  179.           pw_text(pw, pw_width - 6 * DIGIT_WIDTH, 26, PIX_SRC, d_font, " e");
  180.           *p++ = '\0';
  181.           i = 4;
  182.           if (*p == '+')
  183.              p++;
  184.           if (*p == '-') {
  185.              pw_text(pw, pw_width - i-- * DIGIT_WIDTH, 26, PIX_SRC, d_font, "-");
  186.              p++;
  187.              }
  188.           if (strlen(p) == 2)
  189.              pw_text(pw, pw_width - i-- * DIGIT_WIDTH, 26, PIX_SRC, d_font, "0");
  190.           pw_text(pw, pw_width - i * DIGIT_WIDTH, 26, PIX_SRC, d_font, p);
  191.           if (i - strlen(p) == 1)
  192.             pw_text(pw, pw_width - DIGIT_WIDTH, 26, PIX_SRC, d_font, " ");
  193.           }
  194.        else
  195.           pw_text(pw, pw_width - 6 * DIGIT_WIDTH, 26, PIX_SRC, d_font, "      ");
  196.        pw_rop(pw, 0, pw_height - DIGIT_HEIGHT + 1, margin(buf), DIGIT_HEIGHT, PIX_SRC|PIX_COLOR(0), NULL, 0, 0);
  197.        pw_text(pw, margin(buf), 26, PIX_SRC, d_font, buf);
  198.        }
  199. }
  200.  
  201. PUBLIC    convert_display()
  202.  
  203. {    char    buf[60], *p;
  204.     int    i;
  205.  
  206.     if (d_len > 0 || e_len > 0)
  207.        if (curr_mode == SCIENTIFIC) {
  208.           strcpy(buf, d_str);
  209.           strcat(buf, "E");
  210.           strcat(buf, e_str);
  211.           v_stack[v_top] = atof(buf);
  212.           }
  213.        else {
  214.           for (i = 0, p = d_str; *p; p++)
  215.              i = i * curr_base + (index(digit, *p) - digit);
  216.           v_stack[v_top] = (double) i;
  217.           }
  218.     edit_ee = FALSE;
  219.     clear_entry();
  220. }
  221.  
  222. PUBLIC    convert_value(val, s)
  223.  
  224. double    val;
  225. char    *s;
  226.  
  227. {    unsigned    int    i;
  228.     int    start, exp, dp, sign = 1, j, sp;
  229.     char    *p, *q, buf[60];
  230.  
  231.     if (curr_mode == SCIENTIFIC) {
  232.        sprintf(s, "                              %-20.15E", val);
  233.        if (!verify(s, " 0123456789eE+-.")) {
  234.           strcpy(s, "NaN");
  235.           return;
  236.           }
  237.        if (s[30] == '-') {
  238.           sign = -1;
  239.           strcpy(&(s[30]), &(s[31]));
  240.           }
  241.        start = 30;
  242.        sscanf(&(s[start + 18]), "%d", &exp);
  243.        s[start + 17] = '\0';
  244.        strcpy(&(s[start + 1]), &(s[start + 2])); /* lose the decimal point */
  245.        exp++; /* and remember it */
  246.        if (s[start + 13] >= '5') /* round up */
  247.           for (i = start + 12; ; i--) {
  248.              s[i]++;
  249.              if (s[i] == ':') {
  250.                 s[i] = '0';
  251.                 if (i == start) {
  252.                    s[--start] = '1';
  253.                    exp++;
  254.                    break;
  255.                    }
  256.                 }
  257.              else
  258.                 break;
  259.              }
  260.        s[start + 13] = '\0'; /* retain 13 digits */
  261.        s[start - 1] = s[start];
  262.        s[start--] = '.';
  263.        exp--;
  264.        dp = start + 1;
  265.        if (ee_mode || exp > 12 || exp < ((curr_width[0] == -1)? -12 : -curr_width[0])) {
  266.           if (eng_mode)
  267.              for ( ; exp % 3; dp++, exp--) {
  268.                 s[dp] = s[dp + 1];
  269.                 s[dp + 1] = '.';
  270.                 }
  271.           if (curr_width[0] != -1) {
  272.              i = strlen(s + dp + 1);
  273.              if (i > curr_width[0])
  274.                 s[dp + curr_width[0] + 1] = '\0';
  275.              }
  276.           else
  277.              for (i = strlen(s) - 1; s[i] == '0'; s[i--] = '\0')
  278.                 ;
  279.           if (s[i = strlen(s) - 1] == '.')
  280.              s[i] = '\0';
  281.           sprintf(s + strlen(s), "E%03d", exp);
  282.           }
  283.        else {
  284.           for ( ; exp > 0; dp++, exp--) {
  285.              s[dp] = s[dp + 1];
  286.              s[dp + 1] = '.';
  287.              }
  288.           for ( ; exp < 0; dp--, exp++) {
  289.              s[dp] = s[dp - 1];
  290.              s[dp - 1] = '.';
  291.              s[dp - 2] = '0';
  292.              start = dp - 2;
  293.              }
  294.           if (curr_width[0] != -1) {
  295.              i = strlen(s + dp + 1);
  296.              if (i > curr_width[0])
  297.                 s[dp + curr_width[0] + 1] = '\0';
  298.              else
  299.                 for ( ; i < curr_width[0]; i++)
  300.                    strcat(s, "0");
  301.              if (strlen(s + start) > 14)
  302.                 s[start + 14] = '\0';
  303.              }
  304.           else {
  305.              for (i = strlen(s) - 1; s[i] == '0'; s[i--] = '\0');
  306.              if (strlen(s + dp + 1) > 12)
  307.                 s[dp + 13] = '\0';
  308.              if (s[i = strlen(s) - 1] == '.')
  309.                 s[i] = '\0';
  310.              }
  311.           }
  312.        if (sign == -1)
  313.           s[--start] = '-';
  314.        strcpy(s, s + start);
  315.        }
  316.     else {
  317.        i = (unsigned int) val;
  318.        i &= ((unsigned) 0xffffffff) >> (32 - curr_width[index_of(curr_base)]);
  319.        for (p = buf; i; i = i >> index_of(curr_base))
  320.           *p++ = digit[i & (curr_base - 1)];
  321.        *p = '\0';
  322.        if (*buf == '\0')
  323.           strcpy(buf, "0");
  324.        for (j = strlen(buf) - 1, p = s; j >= 0; j--, p++)
  325.           *p = buf[j];
  326.        *p = '\0';
  327.        }
  328. }
  329.  
  330.  
  331. PUBLIC    fix_proc(item, event)
  332.  
  333. Panel_item    item;
  334. Event        *event;
  335.  
  336. {    static    Menu    s_menu = NULL;
  337.     static    Menu    b_menu = NULL;
  338.     static    Menu    h_menu = NULL;
  339.     static    Menu    t_menu = NULL;
  340.     int    i;
  341.  
  342.     if (event_id(event) >= ASCII_FIRST && event_id(event) <= ASCII_LAST) {
  343.        keyboard(event_id(event));
  344.        return;
  345.        }
  346.     if ((event_id(event) == MS_LEFT && !inverted) || (event_id(event) == MS_MIDDLE && inverted))
  347.        if (curr_mode == SCIENTIFIC)
  348.           if (curr_width[0] == 12)
  349.              curr_width[0] = -1;
  350.           else
  351.              curr_width[0]++;
  352.        else
  353.           switch (curr_base) {
  354.              case BINARY      : if (curr_width[1] == 16)
  355.                             curr_width[1] = 4;
  356.                              else
  357.                                 curr_width[1] *= 2;
  358.                              break;
  359.              case OCTAL       : 
  360.              case HEXADECIMAL : if (curr_width[index_of(curr_base)] == 32)
  361.                             curr_width[index_of(curr_base)] = 8;
  362.                              else
  363.                                 curr_width[index_of(curr_base)] *= 2;
  364.                              break;
  365.              }
  366.     else if (curr_mode == SCIENTIFIC && ((event_id(event) == MS_LEFT && inverted) || (event_id(event) == MS_MIDDLE && !inverted)))
  367.        if (trig_mode == GRAD)
  368.           trig_mode = DEG;
  369.        else
  370.           trig_mode++;
  371.     else if (event_id(event) == MS_RIGHT) {
  372.        if (inverted) {
  373.           if (t_menu == NULL)
  374.              t_menu = menu_create(MENU_INITIAL_SELECTION, MENU_DEFAULT,
  375.                            MENU_ITEM, MENU_STRING, "Degrees", MENU_VALUE, 1, MENU_FONT, key_font, 0,
  376.                            MENU_ITEM, MENU_STRING, "Radians", MENU_VALUE, 2, MENU_FONT, key_font, 0,
  377.                            MENU_ITEM, MENU_STRING, "Grads",   MENU_VALUE, 3, MENU_FONT, key_font, 0,
  378.                            0);
  379.           menu_set(t_menu, MENU_DEFAULT, trig_mode + 1, 0);
  380.           if ((i = (int) menu_show(t_menu, keys, event, 0)) != 0)
  381.              trig_mode = i - 1;
  382.           }
  383.        else if (curr_mode == SCIENTIFIC) {
  384.           if (s_menu == NULL)
  385.              s_menu = menu_create(MENU_INITIAL_SELECTION, MENU_DEFAULT,
  386.                            MENU_ITEM, MENU_STRING, "   Float",  MENU_VALUE,  1, MENU_FONT, key_font, 0,
  387.                            MENU_ITEM, MENU_STRING, " 0 Digits", MENU_VALUE,  2, MENU_FONT, key_font, 0,
  388.                            MENU_ITEM, MENU_STRING, " 1 Digit",  MENU_VALUE,  3, MENU_FONT, key_font, 0,
  389.                            MENU_ITEM, MENU_STRING, " 2 Digits", MENU_VALUE,  4, MENU_FONT, key_font, 0,
  390.                            MENU_ITEM, MENU_STRING, " 3 Digits", MENU_VALUE,  5, MENU_FONT, key_font, 0,
  391.                            MENU_ITEM, MENU_STRING, " 4 Digits", MENU_VALUE,  6, MENU_FONT, key_font, 0,
  392.                            MENU_ITEM, MENU_STRING, " 5 Digits", MENU_VALUE,  7, MENU_FONT, key_font, 0,
  393.                            MENU_ITEM, MENU_STRING, " 6 Digits", MENU_VALUE,  8, MENU_FONT, key_font, 0,
  394.                            MENU_ITEM, MENU_STRING, " 7 Digits", MENU_VALUE,  9, MENU_FONT, key_font, 0,
  395.                            MENU_ITEM, MENU_STRING, " 8 Digits", MENU_VALUE, 10, MENU_FONT, key_font, 0,
  396.                            MENU_ITEM, MENU_STRING, " 9 Digits", MENU_VALUE, 11, MENU_FONT, key_font, 0,
  397.                            MENU_ITEM, MENU_STRING, "10 Digits", MENU_VALUE, 12, MENU_FONT, key_font, 0,
  398.                            MENU_ITEM, MENU_STRING, "11 Digits", MENU_VALUE, 13, MENU_FONT, key_font, 0,
  399.                            MENU_ITEM, MENU_STRING, "12 Digits", MENU_VALUE, 14, MENU_FONT, key_font, 0,
  400.                            0);
  401.           menu_set(s_menu, MENU_DEFAULT, curr_width[0] + 2, 0);
  402.           if ((i = (int) menu_show(s_menu, keys, event, 0)) != 0)
  403.              curr_width[0] = i - 2;
  404.           }
  405.        else if (curr_base == BINARY) {
  406.           if (b_menu == NULL)
  407.              b_menu = menu_create(MENU_INITIAL_SELECTION, MENU_DEFAULT,
  408.                            MENU_ITEM, MENU_STRING, " 4 Bits", MENU_VALUE,  4, MENU_FONT, key_font, 0,
  409.                            MENU_ITEM, MENU_STRING, " 8 Bits", MENU_VALUE,  8, MENU_FONT, key_font, 0,
  410.                            MENU_ITEM, MENU_STRING, "16 Bits", MENU_VALUE, 16, MENU_FONT, key_font, 0,
  411.                            0);
  412.           menu_set(b_menu, MENU_DEFAULT_ITEM, menu_find(b_menu, MENU_VALUE, curr_width[1], 0), 0);
  413.           if ((i = (int) menu_show(b_menu, keys, event, 0)) != 0)
  414.              curr_width[1] = i;
  415.           }
  416.        else {
  417.           if (h_menu == NULL)
  418.              h_menu = menu_create(MENU_INITIAL_SELECTION, MENU_DEFAULT,
  419.                            MENU_ITEM, MENU_STRING, " 8 Bits", MENU_VALUE,  8, MENU_FONT, key_font, 0,
  420.                            MENU_ITEM, MENU_STRING, "16 Bits", MENU_VALUE, 16, MENU_FONT, key_font, 0,
  421.                            MENU_ITEM, MENU_STRING, "32 Bits", MENU_VALUE, 32, MENU_FONT, key_font, 0,
  422.                            0);
  423.           menu_set(h_menu, MENU_DEFAULT_ITEM, menu_find(h_menu, MENU_VALUE, curr_width[index_of(curr_base)], 0), 0);
  424.           if ((i = (int) menu_show(h_menu, keys, event, 0)) != 0)
  425.              curr_width[index_of(curr_base)] = i;
  426.           }
  427.        }
  428.     convert_display();
  429.     update_display();
  430.     if (inverted)
  431.        invert_proc();
  432. }
  433.  
  434. do_digit(op)
  435.  
  436. int    op;
  437.  
  438. {    char    temp[60];
  439.  
  440.     if (op <= DIGIT_F) {
  441.        if (edit_ee && e_len > 0) {
  442.           e_str[e_len - 3] = e_str[e_len - 2];
  443.           e_str[e_len - 2] = e_str[e_len - 1];
  444.           e_str[e_len - 1] = digit[op];
  445.           }
  446.        else if (d_len == 1 && d_str[0] == '0')
  447.           d_str[0] = digit[op];
  448.        else if (d_len < MAX_DIGITS) {
  449.           d_str[d_len] = digit[op];
  450.           d_str[++d_len] = '\0';
  451.           }
  452.        }
  453.     else if (op == DIGIT_DOT) {
  454.        if (e_len == 0 && index(d_str, '.') == 0) {
  455.           if (d_len == 0) {
  456.              strcpy(d_str, "0.");
  457.              d_len = 2;
  458.              }
  459.           else {
  460.              d_str[d_len] = '.';
  461.              d_str[++d_len] = '\0';
  462.              }
  463.           }
  464.        }
  465.     else if (op == DIGIT_CHS) {
  466.        if (edit_ee && e_len > 0)
  467.           if (e_len == 4) {
  468.              strcpy(e_str, e_str + 1);
  469.              e_len = 3;
  470.              }
  471.           else {
  472.              e_str[3] = e_str[2];
  473.              e_str[2] = e_str[1];
  474.              e_str[1] = e_str[0];
  475.              e_str[0] = '-';
  476.              e_len = 4;
  477.              }
  478.        else {
  479.           if (d_len == 0)
  480.              convert_stacktop();
  481.           if (curr_mode == SCIENTIFIC) {
  482.              if (d_len > 0 && strcmp(d_str, "0") != 0)
  483.                 if (d_str[0] == '-') {
  484.                    strcpy(d_str, d_str + 1);
  485.                    d_len -= 1;
  486.                    }
  487.                 else {
  488.                    strcpy(temp, d_str);
  489.                    d_str[0] = '-';
  490.                    strcpy(d_str + 1, temp);
  491.                    d_len += 1;
  492.                    }
  493.              }
  494.           else {
  495.              convert_display();
  496.              v_stack[v_top] = -v_stack[v_top];
  497.              convert_stacktop();
  498.              }
  499.           }
  500.        }
  501.     else if (op == DIGIT_EE) {
  502.        ee_mode = TRUE;
  503.        edit_ee = !edit_ee;
  504.        if (d_len == 0)
  505.           convert_stacktop();
  506.        if (e_len == 0) {
  507.           e_len = 3;
  508.           strcpy(e_str, "000");
  509.           }
  510.        }
  511.     update_display();
  512. }
  513.  
  514. PUBLIC    clear_entry()
  515.  
  516. {
  517.     e_str[e_len = 0] = d_str[d_len = 0] = '\0';
  518.     edit_ee = FALSE;
  519. }
  520.  
  521. PUBLIC    keyboard(key)
  522.  
  523. char    key;
  524.  
  525. {    double    temp;
  526.  
  527.     switch (key) {
  528.        case '0' : 
  529.        case '1' : 
  530.        case '2' : 
  531.        case '3' : 
  532.        case '4' : 
  533.        case '5' : 
  534.        case '6' : 
  535.        case '7' : 
  536.        case '8' : 
  537.        case '9' : if (curr_mode == SCIENTIFIC || (key - '0' + DIGIT_0 < curr_base))
  538.                 do_digit(blink(key - '0' + DIGIT_0));
  539.                  break;
  540.        case 'A' : 
  541.        case 'B' : 
  542.        case 'C' : 
  543.        case 'D' : 
  544.        case 'F' : if (curr_mode == PROGRAMMER && curr_base == HEXADECIMAL)
  545.                do_digit(blink(key - 'A' + DIGIT_A));
  546.                  break;
  547.        case 'a' : 
  548.        case 'b' : 
  549.        case 'c' : 
  550.        case 'd' : 
  551.        case 'f' : if (curr_mode == PROGRAMMER && curr_base == HEXADECIMAL)
  552.                 do_digit(blink(key - 'a' + DIGIT_A));
  553.                  break;
  554.        case 'e' :
  555.        case 'E' : if (curr_mode == PROGRAMMER && curr_base == HEXADECIMAL)
  556.                 do_digit(blink(DIGIT_E));
  557.                  else if (curr_mode == SCIENTIFIC)
  558.                     do_digit(blink(DIGIT_EE));
  559.                  break;
  560.        case 'g' :
  561.        case 'G' : blink(EXC_OP);
  562.                  convert_display();
  563.                  do_exchange(0);
  564.                  break;
  565.        case 'r' :
  566.        case 'R' : blink(RCL_OP);
  567.                  clear_entry();
  568.                  do_recall(0);
  569.                  break;
  570.        case 's' :
  571.        case 'S' : blink(STO_OP);
  572.                  convert_display();
  573.                  do_store(0);
  574.                  break;
  575.        case '.' : if (curr_mode == SCIENTIFIC)
  576.                 do_digit(blink(DIGIT_DOT));
  577.                  break;
  578.        case '+' : do_binary(blink(ADD_OP));
  579.                  break;
  580.        case '-' : do_binary(blink(SUB_OP));
  581.                  break;
  582.        case 'x' :
  583.        case 'X' :
  584.        case '*' : do_binary(blink(MUL_OP));
  585.                  break;
  586.        case '/' : do_binary(blink(DIV_OP));
  587.                  break;
  588.        case '&' : if (curr_mode == PROGRAMMER)
  589.                 do_binary(blink(AND_OP));
  590.                  break;
  591.        case '|' : if (curr_mode == PROGRAMMER)
  592.                 do_binary(blink(OR_OP));
  593.                  break;
  594.        case '^' : if (curr_mode == PROGRAMMER)
  595.                 do_binary(blink(XOR_OP));
  596.                  break;
  597.        case '\n':
  598.        case '\r':
  599.        case '=' : do_unary(blink(EQUAL_OP));
  600.                  break;
  601.        case '(' : do_unary(blink(LPAREN_OP));
  602.                  break;
  603.        case ')' : do_unary(blink(RPAREN_OP));
  604.                  break;
  605.        }
  606. }
  607.  
  608.