Official patch #2 for calctool v2.1 - please apply it.

Rich Burridge richb at sunaus.oz
Sun Mar 13 12:28:13 AEST 1988


This is the second official patch to Calctool v2.1. Please apply it.

It fixes the following problems.

  * the Makefile will now install the manual page in the appropriate
    place. Thanks to Kjell Eriksson. (erix!erialfa!kjelle at munnari.oz).
  * hopefully the trigonometrical routines are now fully working.
    Thanks to Vaughan Roberts (mvr at mimir.dmt.oz).
  * Incorrect parameters to a window_set routine. Recompiling calctool
    on a Sun2 and combining it with another program discovered this one.
    Thanks to John P. Nelson. (jpn at genrad.com@munnari.oz) and
    Randy Ballew. (sun!violet.Berkeley.EDU!randy).
  * after an error condition, checks are made against a list of valid
    keys, such as help, mem, off, quit etc.. This allows the novice
    user to try to find out what to do. The message CLR is also
    displayed in the op feed, and will not be removed until the clr
    key is pressed. Thanks to John Gilmore. (hoptoad!gnu at munnari.oz).
  * the [Get] key was not working correctly over the canvas area.
    Thanks to John Gilmore. (hoptoad!gnu at munnari.oz).

I've also received the following suggestions, which will be included
in a future release.

  * modulo key.
  * brackets for arithmetic operator precedence.

Thanks everybody for the feedback on bugs and suggestions, particularily
when they include code fixes. It's really appreciated. I'm into the NeWS
version at the moment, so no new enhancements for a while, just bug fixes.

    Rich.

PS. To Rick Rodgers; yes I've received both of your mail messages. Thankyou.
    I seem unable to find a return path to you. Could you try mailing via
    Sun.COM please.

Rich Burridge,           JANET richb%sunaus.oz at uk.ac.ucl.cs
ACSnet  richb at sunaus.oz  UUCP {uunet,hplabs,mcvax,ukc}!munnari!sunaus.oz!richb
PHONE: +61 2 436 4699    ARPAnet rburridge at Sun.COM
Sun Microsystems, Unit 2, 49-53 Hotham Pde, Artarmon, N.S.W. 2164, AUSTRALIA.

------CUT HERE------CUT HERE------CUT HERE------
*** original/Makefile	Thu Mar 10 18:45:49 1988
--- Makefile	Fri Mar 11 10:43:35 1988
***************
*** 15,22 ****
  #
  
  BINARIES        = calctool
! BINDIR          = .
! LIBDIR          = .
  CFLAGS          = -g -DHELPGIVEN -DHELPNAME=\"$(LIBDIR)/calctool.help\"
  HEADERS         = calctool.h color.h
  OBJS            = calctool.o functions.o sunview.o
--- 15,24 ----
  #
  
  BINARIES        = calctool
! BINDIR          = /usr/local/bin
! LIBDIR          = /usr/local/lib
! MANDIR          = /usr/man/man$(MANSECT)
! MANSECT         = l
  CFLAGS          = -g -DHELPGIVEN -DHELPNAME=\"$(LIBDIR)/calctool.help\"
  HEADERS         = calctool.h color.h
  OBJS            = calctool.o functions.o sunview.o
***************
*** 30,35 ****
--- 32,38 ----
  install:        $(BINARIES)
  		install -s -m 751 calctool $(BINDIR)
  		install -c -m 644 calctool.help $(LIBDIR)
+ 		install -c -m 644 calctool.1 $(MANDIR)/calctool.$(MANSECT)
  
  clean:
  		rm -f *.o core
*** original/calctool.c	Sun Feb 28 11:53:04 1988
--- calctool.c	Sat Mar 12 23:04:26 1988
***************
*** 48,53 ****
--- 48,57 ----
  /* X offset in pixels for various length button strings. */
  int chxoff[4] = { 5, 9, 14, 16 } ;
  
+ /* Valid keys when an error condition has occured. */
+ /*                            MEM  KEYS HELP   clr   QUIT OFF  */
+ char validkeys[MAXVALID]  = { 'M', 'K', '?', '\177', 'q', 'o' } ;
+ 
  double disp_val ;             /* Value of the current display. */
  double last_input ;           /* Previous number input by user. */
  double mem_vals[MAXREGS] ;    /* Memory register values. */
***************
*** 64,69 ****
--- 68,74 ----
  int error ;         /* Indicates some kind of display error. */
  int iscolor ;       /* Set if this is a color screen. */
  int ishelp ;        /* Set if there is a help file. */
+ int issel ;         /* Set if valid [Get] selection. */
  int new_input ;     /* New number input since last op. */
  int pending ;       /* Indicates command depending on multiple presses. */
  int pending_op ;    /* Arithmetic operation for pending command. */
***************
*** 89,94 ****
--- 94,100 ----
  char current ;          /* Current button or character pressed. */
  char old_cal_value ;    /* Previous calculation operator. */
  char pstr[5] ;          /* Current button text string. */
+ char *selection ;       /* Current [Get] selection. */
  
  struct button buttons[TITEMS] = {              /* Calculator button values. */
    { ">   ", '>',    OP_SET,   LGREY,    do_pending },       /* Row 1. */
***************
*** 365,370 ****
--- 371,377 ----
      {
        STRCPY(display,"Error") ;
        error = 1 ;
+       display_op_item("CLR") ;
        return(display) ;
      }
  
***************
*** 392,397 ****
--- 399,405 ----
          {
            STRCPY(display,"Overflow") ;
            error = 1 ;
+           display_op_item("CLR") ;
            return(display) ;
          }
        else
***************
*** 427,432 ****
--- 435,441 ----
    SPRINTF(display,"Error in %s",x->name) ;
    display_result(display) ;
    error = 1 ;
+   display_op_item("CLR") ;
    return(1) ;
  }
  
***************
*** 464,469 ****
--- 473,480 ----
  process_item(n)
  int n ;
  {
+   int i,isvalid ;
+ 
    if (n > TITEMS) return ;
  
    current = buttons[n].value ;
***************
*** 472,478 ****
    if (current == '\015') current = '=' ;
    if (current == 'Q') current = 'q' ;
  
!   if (error && current != '\177') return ;    /* If error, must clear first. */
  
    if (pending)
      {
--- 483,496 ----
    if (current == '\015') current = '=' ;
    if (current == 'Q') current = 'q' ;
  
!   if (error)
!     {
!       isvalid = 0 ;                    /* Must press a valid key first. */
!       for (i = 0; i < MAXVALID; i++)
!         if (current == validkeys[i]) isvalid = 1 ;
!       if (pending == '?') isvalid = 1 ;
!       if (!isvalid) return ;
!     }
  
    if (pending)
      {
***************
*** 483,489 ****
      {
        case OP_SET   : display_op_item(buttons[n].str) ;
                        break ;
!       case OP_CLEAR : display_op_item("") ;
      }
    (*buttons[n].func)() ;
  }
--- 501,508 ----
      {
        case OP_SET   : display_op_item(buttons[n].str) ;
                        break ;
!       case OP_CLEAR : if (error) display_op_item("CLR") ;
!                       else display_op_item("") ;
      }
    (*buttons[n].func)() ;
  }
*** original/calctool.h	Thu Mar 10 18:45:52 1988
--- calctool.h	Thu Mar 10 15:57:57 1988
***************
*** 80,85 ****
--- 80,86 ----
  #define  MAX_DIGITS     32               /* Maximum displayable number of digits. */
  #define  MAXLINE        80               /* Length of character strings. */
  #define  MAXREGS        10               /* Maximum number of memory registers. */
+ #define  MAXVALID       6                /* Number of valid keys after an error. */
  #define  MIN(x,y)       ((x) < (y) ? (x) : (y))
  #define  NOBUTTONS      BROWS * BCOLS
  #define  THEIGHT        (BROWS*BHEIGHT) + ((BROWS-1) * BGAP) + (2*BBORDER)
*** original/functions.c	Thu Mar 10 18:45:53 1988
--- functions.c	Sat Mar 12 10:51:23 1988
***************
*** 44,49 ****
--- 44,50 ----
  extern int accuracy ;             /* Number of digits precision (Max 9). */
  extern int base ;                 /* Current base: BIN, OCT, DEC or HEX. */
  extern int color ;                /* Color of current raster operation. */
+ extern int error ;                /* Indicates some kind of display error. */
  extern int iscolor ;              /* Set if this is a color screen. */
  extern int ishelp ;               /* Set if there is a help file. */
  extern int new_input ;            /* New number input since last op. */
***************
*** 63,77 ****
  {
    switch (current)
      {
!       case ')' : disp_val = acos(disp_val) ;         /* cos-1. */
                   break ;
!       case '}' : disp_val = asin(disp_val) ;         /* sin-1. */
                   break ;
!       case 'T' : disp_val = atan(disp_val) ;         /* tan-1. */
      }
  
!   tresults[DEG]  = disp_val *= 180.0 / M_PI ;
!   tresults[GRAD] = disp_val *= 200.0 / M_PI ;
    tresults[RAD]  = disp_val ;
    cur_op = current ;
    show_display(tresults[ttype]) ;
--- 64,78 ----
  {
    switch (current)
      {
!       case ')' : disp_val = acos(disp_val) ;     /* cos-1. */
                   break ;
!       case '}' : disp_val = asin(disp_val) ;     /* sin-1. */
                   break ;
!       case 'T' : disp_val = atan(disp_val) ;     /* tan-1. */
      }
  
!   tresults[DEG]  = disp_val * 180.0 / M_PI ;
!   tresults[GRAD] = disp_val * 200.0 / M_PI ;
    tresults[RAD]  = disp_val ;
    cur_op = current ;
    show_display(tresults[ttype]) ;
***************
*** 150,155 ****
--- 151,157 ----
  do_clear()       /* Clear the calculator display and re-initialise. */
  {
    clear_display() ;
+   if (error) display_op_item("") ;
    initialise() ;
  }
  
***************
*** 375,381 ****
                     }
      }    
    show_display(disp_val) ;
!   display_op_item("") ;
    pending = 0 ;
  }
  
--- 377,384 ----
                     }
      }    
    show_display(disp_val) ;
!   if (error) display_op_item("CLR") ;
!   else display_op_item("") ;
    pending = 0 ;
  }
  
***************
*** 414,438 ****
  
  do_trig()
  {
-   int i ;
    double temp ;
  
!   tresults[DEG]  = disp_val *= M_PI / 180.0 ;
!   tresults[GRAD] = disp_val *= M_PI / 200.0 ;
!   tresults[RAD]  = disp_val ;
  
-   for (i = 0; i < 3; i++)
-     switch (current)
-       {
-         case '(' : tresults[i] = cos(tresults[i]) ;   /* cos. */
-                    break ;
-         case '{' : tresults[i] = sin(tresults[i]) ;   /* sin. */
-                    break ;
- /*        case 't' : temp = cos(tresults[i]) ;   */       /* tan. */
- /*                   tresults[i] = sin(tresults[i]) / temp ; */
- 
-         case 't' : tresults[i] = tan(tresults[i]) ;          /* tan. */
-       }
    cur_op = current ;
    show_display(tresults[ttype]) ;
    disp_val = tresults[ttype] ;
--- 417,439 ----
  
  do_trig()
  {
    double temp ;
+  
+        if (ttype == DEG)  temp = disp_val * M_PI / 180.0 ;
+   else if (ttype == GRAD) temp = disp_val * M_PI / 200.0 ;
+   else                    temp = disp_val ;
  
!   switch (current)
!     {
!       case '(' : tresults[RAD] = cos(temp) ;   /* cos. */
!                  break ;
!       case '{' : tresults[RAD] = sin(temp) ;   /* sin. */
!                  break ;
!       case 't' : tresults[RAD] = tan(temp) ;   /* tan. */
!     } 
!   tresults[DEG]  = disp_val * 180.0 / M_PI ;
!   tresults[GRAD] = disp_val * 200.0 / M_PI ;
  
    cur_op = current ;
    show_display(tresults[ttype]) ;
    disp_val = tresults[ttype] ;
***************
*** 450,456 ****
        case CTRL('r') : ttype = RAD ;
      }
    if (cur_op == ')' || cur_op == '}' || cur_op == 'T' ||
!       cur_op == '(' || cur_op == '{' || cur_op == 't') show_display(tresults[ttype]) ;
    display_ttype(ttype) ;
  }
  
--- 451,461 ----
        case CTRL('r') : ttype = RAD ;
      }
    if (cur_op == ')' || cur_op == '}' || cur_op == 'T' ||
!       cur_op == '(' || cur_op == '{' || cur_op == 't')
!     {
!       disp_val = tresults[ttype] ;
!       show_display(tresults[ttype]) ;
!     }
    display_ttype(ttype) ;
  }
  
*** original/patchlevel.h	Thu Mar 10 18:45:54 1988
--- patchlevel.h	Sun Mar 13 12:49:02 1988
***************
*** 18,21 ****
   *  reported to me then an attempt will be made to fix them.
   */
  
! #define  PATCHLEVEL  1
--- 18,21 ----
   *  reported to me then an attempt will be made to fix them.
   */
  
! #define  PATCHLEVEL  2
*** original/sunview.c	Thu Mar 10 18:45:55 1988
--- sunview.c	Sun Mar 13 12:43:30 1988
***************
*** 24,34 ****
--- 24,37 ----
  #include <suntool/sunview.h>
  #include <suntool/canvas.h>
  #include <suntool/panel.h>
+ #include <suntool/selection_svc.h>
+ #include <suntool/selection_attributes.h>
  
  #define  ICON_SET           (void) icon_set
  #define  PANEL_SET          (void) panel_set
  #define  PW_SETCMSNAME      (void) pw_setcmsname
  #define  PW_PUTCOLORMAP     (void) pw_putcolormap
+ #define  SELN_QUERY         (void) seln_query
  #define  WINDOW_DESTROY     (void) window_destroy
  #define  WINDOW_DONE        (void) window_done
  #define  WINDOW_READ_EVENT  (void) window_read_event
***************
*** 37,42 ****
--- 40,46 ----
  void canvas_proc() ;
  int draw_background() ;
  Panel_setting panel_proc() ;
+ Seln_result get_proc() ;
  
  Canvas canvas, rcanvas ;
  Cursor main_cursor ;
***************
*** 46,51 ****
--- 50,58 ----
  Panel_item base_item, display_item, op_item, ttype_item ;
  Pixfont *sfont, *nfont, *bfont, *font ;
  Pixwin *cpw, *rcpw ;
+ Seln_client client ;
+ Seln_holder holder ;
+ Seln_rank rank = SELN_PRIMARY ;
  
  short help_cursor_array[16] = {
  #include "help.cursor"
***************
*** 66,71 ****
--- 73,79 ----
  
  extern char *make_number() ;
  extern char pstr[] ;              /* Current button text string. */
+ extern char *selection ;          /* Current [Get] selection. */
  extern double mem_vals[] ;        /* Memory register values. */
  extern int chxoff[] ;             /* X offset for various length button strings. */
  extern int color ;                /* Color being used for current raster operation. */
***************
*** 72,77 ****
--- 80,86 ----
  extern int column ;               /* Column number of current key/mouse press. */
  extern int down ;                 /* Indicates if mouse button is down. */
  extern int iscolor ;              /* Set if this is a color screen. */
+ extern int issel ;                /* Set if valid [Get] selection. */
  extern int pending ;              /* Set for command with on multiple presses. */
  extern int pending_op ;           /* Arithmetic operation for pending command. */
  extern int portion ;              /* Portion of button on current key/mouse press. */
***************
*** 92,97 ****
--- 101,107 ----
  caddr_t arg ;
   
  {
+   char context = 0 ;
    int i,n ;
   
    x = event_x(event) ;
***************
*** 155,160 ****
--- 165,185 ----
        down = 0 ;
        return ;
      }
+   else if ((event_id(event) == KEY_LEFT(8)) && event_is_up(event))
+     {
+       holder = seln_inquire(rank) ;
+       if (holder.state == SELN_NONE) return ;
+       SELN_QUERY(&holder,get_proc,&context,SELN_REQ_CONTENTS_ASCII,0,0) ;
+       if (issel)
+         for (i = 0 ; i < strlen(selection); i++)
+           for (n = 0; n < TITEMS; n++)
+             if (selection[i] == buttons[n].value)
+               {
+                 process_item(n) ;
+                 break ;
+               }
+       return ;
+     }
    else window_default_event_proc(win,event,arg) ;
   
    process_item(n) ;
***************
*** 273,278 ****
--- 298,321 ----
  }
  
  
+ Seln_result
+ get_proc(buffer)
+ Seln_request *buffer ;
+ {
+   issel = 0 ;
+   if (*buffer->requester.context == 0)
+     {
+       if (buffer == (Seln_request *) NULL ||
+           *((Seln_attribute *) buffer->data) != SELN_REQ_CONTENTS_ASCII)
+         return ;
+       selection = buffer->data + sizeof(Seln_attribute) ;
+       *buffer->requester.context = 1 ;
+     }
+   else selection = buffer->data ;
+   issel = 1 ;
+ }
+ 
+ 
  init_fonts()
  {
    sfont = pf_open(SMALLFONT) ;
***************
*** 426,432 ****
                           WIN_EVENT_PROC,canvas_proc,
                           0) ;
    WINDOW_SET(canvas,WIN_CONSUME_KBD_EVENT,WIN_ASCII_EVENTS,0) ;
!   WINDOW_SET(canvas,WIN_CONSUME_KBD_EVENTS,WIN_LEFT_KEYS,WIN_TOP_KEYS,WIN_RIGHT_KEYS,0) ;
    WINDOW_SET(canvas,WIN_IGNORE_PICK_EVENT,LOC_MOVE,0) ;
  }
  
--- 469,476 ----
                           WIN_EVENT_PROC,canvas_proc,
                           0) ;
    WINDOW_SET(canvas,WIN_CONSUME_KBD_EVENT,WIN_ASCII_EVENTS,0) ;
!   WINDOW_SET(canvas,WIN_CONSUME_KBD_EVENTS,WIN_LEFT_KEYS,WIN_TOP_KEYS,WIN_RIGHT_KEYS,0,0) ;
!   WINDOW_SET(canvas,WIN_CONSUME_KBD_EVENT,WIN_UP_EVENTS,0) ;
    WINDOW_SET(canvas,WIN_IGNORE_PICK_EVENT,LOC_MOVE,0) ;
  }
  



More information about the Comp.sources.bugs mailing list