--- Makefile
+++ Makefile	2004-04-26 15:50:34.000000000 +0200
@@ -28,7 +28,8 @@
 #  It can also be specified here by uncommenting the following
 #  macro definition and setting appropriately.
 #
-HELPNAME        = -DHELPNAME=\"$(LIBDIR)/calctool.help\"
+LIBDIR		= /usr/X11R6/lib
+HELPNAME	= -DHELPNAME=\"$(LIBDIR)/calctool.help\"
 #-----------------------------------------------------------------------
 #  An attempt is now made at using a portable math library. You should
 #  carefully setup the following three definitions.
@@ -37,7 +38,8 @@
 #  floating point format. If your machine does *not* use IEEE floating
 #  point format, then the following definition needs to be uncommented.
 #
-#NOIEEE             = -DIEEE
+#NOIEEE			= -DIEEE
+NOIEEE			=
 #-----------------------------------------------------------------------
 #  Some machines send a SIGFPE on math errors despite the presense
 #  of the handler routine in calctool.c. If calctool cores when you
@@ -72,7 +74,7 @@
 #  can also be specified here by uncommenting the following macro
 #  definition and setting appropriately.
 #
-#RCNAME          = -DRCNAME=\".calctoolrc\"
+RCNAME		= -DRCNAME=\".calctoolrc\"
 #-----------------------------------------------------------------------
 #  If you not running under a BSD4.3 derived system, the parameters
 #  to the select call are different, and this definition should be
@@ -105,7 +107,7 @@
 #  If you wish to use these function keys with a Sun4 keyboard, then you
 #  need to uncomment the following definition.
 #
-SUN4_KEYBOARD  = -DSUN4_KEYBOARD
+SUN4_KEYBOARD	= -DSUN4_KEYBOARD
 #-------------------------------------------------------------------------
 #  If you are running SunOS v3.x, then pr_ttext doesn't exist, and
 #  you must uncomment this definition.
@@ -116,38 +118,47 @@
 #  library files are not in a standard place, then the following
 #  two lines should be uncommented, and set appropriately.
 #
-#X11INCDIR         = -I$(OPENWINHOME)/include
-#X11LIBDIR         = -L$(OPENWINHOME)/lib
+#X11INCDIR	= -I$(OPENWINHOME)/include
+#X11LIBDIR	= -L$(OPENWINHOME)/lib
+X11INCDIR = -I/usr/X11R6/include
+X11LIBDIR = -L/usr/X11R6/lib
+#-------------------------------------------------------------------------
+#  For X11 interface a bit input menu popup exist. With
+#  this popup single bits of an unsigned integer can be changed.
+#  To activate/deactivate this the right mouse button have to
+#  clicked into the number display of calctool.
+#
+X11BITDEF = -DUSE_BITCALC
 #-------------------------------------------------------------------------
 #  If you are compiling the XView version, then the following two lines
 #  should be uncommented.
 #
-XVIEWINCDIR      = -I$(OPENWINHOME)/include
-XVIEWLIBDIR      = -L$(OPENWINHOME)/lib
+OPENWINHOME	= /usr/openwin
+XVIEWINCDIR	= -I$(OPENWINHOME)/include $(X11INCDIR)
+XVIEWLIBDIR	= -L$(OPENWINHOME)/lib $(X11LIBDIR)
 #
 #=========================================================================
 #
 #  Default locations where calctool files will be installed.
 #  You might wish to alter these values.
 #
-BINDIR          = /usr/local/bin
-LIBDIR          = /usr/local/lib
-MANDIR          = /usr/man/man$(MANSECT)
-MANSECT         = l
+BINDIR		= /usr/X11R6/bin
+MANSECT		= 1
+MANDIR		= /usr/X11R6/man/man$(MANSECT)
 #
 #  Compilation flags and standard macro definitions.
 #
 CFLAGS		= -g $(HELPNAME) $(NEWSFILE) $(STUPID_FPE) $(NOIEEE) \
 		     $(NOINDEX) $(RCNAME) $(SELTYPE) $(SHLIB) $(SIGRET) \
 		     $(SUN4_KEYBOARD) $(TTEXT) $(MGRPARAM) $(MGRINCDIR) \
-		     $(X11INCDIR) $(XVIEWINCDIR)
+		     $(X11INCDIR) $(XVIEWINCDIR) $(RPM_OPT_FLAGS) $(X11BITDEF)
 #
 #=========================================================================
 
 BINARIES        = mgr_calctool ps_calctool sv_calctool \
 		  tty_calctool xcalctool xv_calctool
 
-CC		= cc
+CC		= gcc
 
 LIBSRCS         = graphics.c display.c functions.c get.c
 LIBOBJS         = graphics.o display.o functions.o get.o
@@ -172,7 +183,7 @@
 NEWSLIBS        = $(CALCLIB) $$OPENWINHOME/lib/libcps.a -lm
 SVIEWLIBS       = $(CALCLIB) -lsuntool -lsunwindow -lpixrect -lm
 TTYLIBS	        = $(CALCLIB) -ltermcap -lm
-X11LIBS         = $(CALCLIB) -lX11 -lm
+X11LIBS         = $(CALCLIB) -lX11 -lXt -lXaw3d -lm
 XVIEWLIBS       = $(CALCLIB) -lxview -lolgx -lX11 -lm
 
 .PRECIOUS:      $(LIBNAME)
@@ -233,11 +244,13 @@
 			ld -o libcalctool.so.1.1 -assert pure-text $?
 
 install:
-		install -c -m 644 $(LIBNAME) $(LIBDIR)
-		install -s -m 751 calctool $(BINDIR)
-		install -c -m 644 calctool.help $(LIBDIR)
-		install -c -m 644 calctool.ps $(LIBDIR)
-		install -c -m 644 calctool.1 $(MANDIR)/calctool.$(MANSECT)
+		install -d -m 755 $(DESTDIR)$(BINDIR)
+		install -d -m 755 $(DESTDIR)$(LIBDIR)
+		install -d -m 755 $(DESTDIR)$(MANDIR)
+		install -s -m 755 calctool $(DESTDIR)$(BINDIR)
+		install -c -m 644 calctool.help $(DESTDIR)$(LIBDIR)
+		install -c -m 644 calctool.ps $(DESTDIR)$(LIBDIR)
+		install -c -m 644 calctool.1 $(DESTDIR)$(MANDIR)/calctool.$(MANSECT)
 
 clean:;         rm -f *.o archive.* *~ *.a $(BINARIES) core
 
--- calctool.1
+++ calctool.1	2004-04-26 15:50:34.000000000 +0200
@@ -1,5 +1,5 @@
 .\" @(#)calctool.1 1.9 90/02/02
-.TH CALCTOOL 1L "13 December 1989"
+.TH CALCTOOL 1x "13 December 1989"
 .SH NAME
 calctool \- a simple calculator
 .SH SYNOPSIS
@@ -74,10 +74,16 @@
 The calculator has arithmetical, logical and trigonometrical functions.
 These are grouped together and color coded on color workstations.
 .LP
-With the SunView and XView versions, there is support for popup menus with
+With the SunView, X11, and XView versions, there is support for popup menus with
 the right mouse button. Only certain buttons which have multiple options
 have this ability. These are the ACC, CON, EXCH, FUN, <, >, RCL and STO keys.
 .LP
+For X11 interface a bit input menu popup exist. With this popup single bits of
+an unsigned integer can be changed.  To activate/deactivate this the right mouse
+button have to be clicked into the number display of calctool.  If the left mouse
+button is used and no other cut buffer is active the current display value is stored
+in the cut buffer.
+.LP
 Online help is provided via a help button.  Select this button, and then
 the function you wish to be described. The calctool windows can be redrawn
 by typing ^L (control-l). This is very useful with the tty version after
@@ -347,9 +353,9 @@
 Change \fIcalctool\fP to an icon.
 .SH FILES
 .TP
-/usr/local/lib/calctool.help
-.TP
-/usr/local/lib/calctool.ps
+/usr/X11R6/lib/calctool.help
+.\" .TP
+.\" /usr/X11R6/lib/calctool.ps
 .TP
 ~/.calctoolrc
 .SH BUGS
--- calctool.c
+++ calctool.c	2004-04-26 17:00:09.000000000 +0200
@@ -1,4 +1,3 @@
-
 /*  @(#)calctool.c 1.14 90/08/14
  *
  *  A simple calculator program.
@@ -19,6 +18,8 @@
 
 #include <stdio.h>
 #include <strings.h>
+#include <string.h>
+#include <stdlib.h>
 #include <math.h>
 #include "patchlevel.h"
 #include "color.h"
@@ -72,16 +73,16 @@
 } ;
 
 char con_names[MAXREGS][MAXLINE] = {
-       "kilometres per hour <=> miles per hour.",
-       "square root of 2.",
-       "e.",
-       "pi.",
-       "centimetres <=> inch.",
-       "degrees in a radian.",
-       "2 ^ 20.",
-       "grams <=> ounce.",
-       "kilojoules <=> British thermal units.",
-       "cubic cms <=> cubic inches.",
+       "kilometres per hour <=> miles per hour",
+       "square root of 2",
+       "e",
+       "pi",
+       "centimetres <=> inch",
+       "degrees in a radian",
+       "2 ^ 20",
+       "grams <=> ounce",
+       "kilojoules <=> British thermal units",
+       "cubic cms <=> cubic inches",
 } ;
 
 char num_names[MAXREGS][2] = {    /* Used by the popup menus. */
@@ -161,11 +162,11 @@
 int y ;             /* Y offset for text for button. */
 
 /* Routines obeyed by mouse button or character presses. */
-int close_frame(),    destroy_frame(),  do_base() ;
-int do_calculation(), do_clear(),       do_constant(),  do_delete() ;
-int do_expno(),       do_immediate(),   do_keys(),      do_number() ;
-int do_pending(),     do_point(),       do_portion(),   do_repaint() ;
-int do_set_mode(),    do_trig(),        do_trigtype(),  toggle_reg_canvas() ;
+extern void close_frame(), destroy_frame(),  do_pending();
+extern void do_base(),     do_calculation(), do_clear(),     do_constant();
+extern void do_delete(),   do_expno(),       do_immediate(), do_keys();
+extern void do_number(),   do_point(),       do_portion(),   do_repaint();
+extern void do_set_mode(), do_trig(),        do_trigtype(),  toggle_reg_canvas();
 
 char cur_op ;                     /* Current arithmetic operation. */
 char current ;                    /* Current button or character pressed. */
@@ -193,7 +194,7 @@
 
 /* Calculator button values. */
 
-char sci_fix_button_str[5]; /* That button needs a writable string */
+static char sci_fix_button_str[5] = "SCI "; /* That button needs a writable string */
 
 struct button buttons[TITEMS] = {
   { "EXCH", CCTRL('e'), OP_SET,   MAUVE,    do_pending },       /* Row 1. */
@@ -326,6 +327,7 @@
 char helpname[MAXLINE] ;    /* Filename for help file. */
 char progname[MAXLINE] ;    /* Name of this program. */
 
+int
 main(argc,argv)
 int argc ;
 char *argv[] ;
@@ -356,7 +358,6 @@
   grey_buttons(base) ;
   ttype = DEG ;               /* Initial trigonometric type. */
   dtype = FIX ;               /* Initial number display mode. */
-  STRCPY(sci_fix_button_str,"SCI "); /* Initial setting for SCI/FIX button */
   down = 0 ;                  /* No mouse presses initially. */
 
 #ifdef STUPID_FPE
@@ -372,14 +373,14 @@
 
 
 /* Calctools' customised math library error-handling routine. */
-
+void
 doerr(funcname, etype, eval)
 char *funcname, *etype ;
 int eval ;
 {
   SPRINTF(display, "%s: %s error", funcname, etype) ;
-  set_item(DISPLAYITEM, display) ;
   error = eval ;
+  set_item(DISPLAYITEM, display) ;
   set_item(OPITEM, "CLR") ;
 }
 
@@ -387,11 +388,13 @@
 /* Default math library exception handling routine. */
 
 /*ARGSUSED*/
+int
 matherr(exc)
 struct exception *exc ;
 {
   STRCPY(display, "Error") ;
-  set_item(DISPLAYITEM, display) ;
   error = 1 ;
+  set_item(DISPLAYITEM, display) ;
   set_item(OPITEM, "CLR") ;
+  return 0;
 }
--- calctool.h
+++ calctool.h	2004-04-26 17:01:18.000000000 +0200
@@ -16,6 +16,11 @@
 
 char *getenv(), *getwd() /*, *sprintf()*/ ;
 
+#ifdef USE_BITCALC
+extern void toggle_bit_popup();
+extern void update_bit_popup(unsigned long val);
+#endif
+
 #define  CLOSE          (void) close      /* To make lint happy. */
 #define  FCLOSE         (void) fclose
 #define  FFLUSH         (void) fflush
@@ -176,5 +181,47 @@
          char value ;            /* Unique button keyboard equivalent. */
          enum op_type opdisp ;   /* Display operation code during operation. */
          char color ;            /* Color of button portion. */
-         int  (*func)() ;        /* Function to obey on button press. */
+         void (*func)() ;        /* Function to obey on button press. */
 } ;
+
+extern BOOLEAN ibool();
+extern void set_item();
+extern void make_registers();
+extern void get_options();
+extern void get_helpfile();
+extern void read_rcfiles();
+extern int  init_ws_type();
+extern void init_fonts();
+extern void make_icon();
+extern void make_frames();
+extern void make_subframes();
+extern void make_menus();
+extern void load_colors();
+extern void grey_buttons();
+extern void make_items();
+extern void set_cursor();
+extern void start_tool();
+extern void get_label();
+extern void drawtext();
+extern void drawline();
+extern void color_area();
+extern int  do_menu();
+extern void do_pending();
+extern void clear_canvas();
+extern void create_menu();
+extern void process_item();
+extern void handle_selection();
+extern void get_display();
+extern void grey_buttons();
+extern void show_display();
+extern void clear_display();
+extern void initialise();
+extern void process_item();
+extern void make_canvas();
+extern void set_cursor();
+extern void clear_canvas();
+extern void drawtext();
+extern void draw_button();
+extern void handle_menu_selection();
+extern void process_event();
+extern void show_display();
--- display.c
+++ display.c	2004-04-26 17:03:56.000000000 +0200
@@ -19,12 +19,13 @@
 
 #include <stdio.h>
 #include <strings.h>
+#include <string.h>
 #include <math.h>
 #include "calctool.h"
 #include "color.h"
 #include "extern.h"
 
-
+int
 char_val(chr)
 char chr ;
 {
@@ -33,7 +34,7 @@
   else return(-1) ;
 }
 
-
+void
 clear_display()
 {
   int i ;
@@ -53,7 +54,7 @@
 double
 convert_display()    /* Convert input string into a double. */
 {
-  int exp, exp_sign, i, inum ;
+  int exp, exp_sign = 1, i, inum ;
   double val ;
   char *optr ;
 
@@ -87,7 +88,7 @@
   return(val) ;
 }
  
- 
+void 
 get_label(n)
 int n ;
 {
@@ -113,7 +114,7 @@
   else STRCPY(pstr, buttons[n].str) ;
 }
 
-
+void
 initialise()
 {
   error = 0 ;              /* Currently no display error. */
@@ -190,8 +191,8 @@
 
   val = fabs(number) ;
   if (dtype == SCI ||
-      dtype == FIX && val != 0.0 && (val > max_fix[(int) base] ||
-                      val < exp_p1[accuracy][(int) base]))
+      (dtype == FIX && val != 0.0 && (val > max_fix[(int) base] ||
+                      val < exp_p1[accuracy][(int) base])))
     return(make_scientific(number)) ;
   else return(make_fixed(number, MAX_DIGITS)) ;
 }
@@ -268,7 +269,7 @@
   return(snum) ;
 }
 
-
+void
 process_item(n)
 int n ;
 {
@@ -303,11 +304,13 @@
                       break ;
       case OP_CLEAR : if (error) set_item(OPITEM, "CLR") ;
                             else set_item(OPITEM, "") ;
+      default       :
+		      break ;
     }
   (*buttons[n].func)() ;
 }
 
-
+void
 show_display(val)
 double val ;
 {
@@ -315,5 +318,8 @@
     {
       STRCPY(display, make_number(val)) ;
       set_item(DISPLAYITEM, display) ;
+#ifdef USE_BITCALC
+      update_bit_popup(ibool(val));
+#endif
     }
 }
--- extern.h
+++ extern.h	2004-04-26 15:50:34.000000000 +0200
@@ -88,6 +88,9 @@
 extern int posspec ;        /* Set if -Wp or -g option is present (for X11) */
 extern int row ;            /* Row number of current key/mouse press. */
 extern int rstate ;         /* Is memory register frame displayed? */
+#ifdef USE_BITCALC
+extern int bstate;	    /* Is bit input menu displayed? */
+#endif
 extern int signgam ;
 extern int spaces ;         /* Number of spaces in current button string. */
 extern int toclear ;        /* Indicates if display should be cleared. */
--- functions.c
+++ functions.c	2004-04-26 17:08:42.000000000 +0200
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <strings.h>
+#include <string.h>
 #include <math.h>
 #include "calctool.h"
 #include "color.h"
@@ -30,11 +31,12 @@
 extern double cos(), cosh(), exp(), fabs(), log(), log10(), pow() ;
 extern double sin(), sinh(), sqrt(), tan(), tanh() ;
 extern double addition(), subtraction(), multiply(), division() ;
+extern int char_val();
 
 BOOLEAN ibool() ;
 double setbool() ;
 
-
+void
 do_accuracy()     /* Set display accuracy. */
 {
   if (current >= '0' && current <= '9')
@@ -44,7 +46,7 @@
     }
 }
 
-
+void
 do_base()    /* Change the current base setting. */
 {
   switch (current)
@@ -63,12 +65,13 @@
   if (rstate) make_registers() ;
 }
 
-
+void
 do_calculation()      /* Perform arithmetic calculation and display result. */
 {
-  if (current == '=' && old_cal_value == '=')
+  if (current == '=' && old_cal_value == '=') {
     if (new_input) result = last_input ;
     else disp_val = last_input ;
+  }
 
   if (current != '=' && old_cal_value == '=') cur_op = '?' ;
   switch (cur_op)
@@ -117,7 +120,7 @@
   new_input = key_exp = 0 ;
 }
 
-
+void
 do_clear()       /* Clear the calculator display and re-initialise. */
 {
   clear_display() ;
@@ -125,7 +128,7 @@
   initialise() ;
 }
 
-
+void
 do_constant()
 {
   if (current >= '0' && current <= '9')
@@ -135,7 +138,7 @@
     }
 }
 
-
+void
 do_delete()     /* Remove the last numeric character typed. */
 {
   if (strlen(display)) display[strlen(display)-1] = '\0' ;
@@ -155,7 +158,7 @@
   disp_val = convert_display() ;    /* Convert input to a number. */
 }
 
-
+void
 do_exchange()         /* Exchange display with memory register. */
 {
   double temp ;
@@ -169,7 +172,7 @@
     }
 }
 
-
+void
 do_expno()           /* Get exponential number. */
 {
   if (!new_input)
@@ -213,7 +216,7 @@
   return (a) ;
 }
 
-
+void
 do_function()      /* Perform a user defined function. */
 {
   int fno, i, n ;
@@ -232,7 +235,7 @@
     }
 }
 
-
+void
 do_help()         /* Show online help facility. */
 {
   char help_str[MAXLINE], nextline[MAXLINE], *p ;
@@ -263,7 +266,7 @@
           p = fgets(nextline, BUFSIZ, hfd) ;
           if (EQUAL(p, "_calctool.help_\n"))
             {
-              while (p = fgets(nextline, BUFSIZ, hfd))
+              while ((p = fgets(nextline, BUFSIZ, hfd)))
                 if (*p == '_' && EQUAL(p, help_str)) break ;
               if (!p) drawtext(5, y, KEYCANVAS, NFONT, BLACK,
                                "No help for this item.") ;
@@ -286,7 +289,7 @@
     }
 }
 
-
+void
 do_immediate()
 {
   switch (current)
@@ -326,13 +329,13 @@
   show_display(disp_val) ;
 }
 
-
+void
 do_keys()      /* Display/undisplay the calctool key values. */
 {
   make_canvas(1) ;
 }
 
-
+void
 do_number()
 {
   int n ;
@@ -355,7 +358,7 @@
   new_input = 1 ;
 }
 
-
+void
 do_numtype()         /* Set number type (fixed or scientific). */
 {
   int n ;
@@ -370,7 +373,10 @@
   show_display(disp_val) ;
 }
 
+void do_shift();
+void do_sto_rcl();
 
+void
 do_pending()
 {
   if (base != DEC) grey_buttons(DEC) ;    /* Reshow all the keys. */
@@ -411,7 +417,7 @@
   grey_buttons(base) ;      /* Just show numeric keys for current base. */
 }
 
-
+void
 do_point()                  /* Handle numeric point. */
 {
   if (!pointed)
@@ -429,7 +435,7 @@
   disp_val = convert_display() ;    /* Convert input to a number. */
 }
 
-
+void
 do_portion()
 {
   switch (current)
@@ -443,7 +449,9 @@
   show_display(disp_val) ;
 }
 
+void do_trigtype();
 
+void
 do_set_mode()           /* Set or unset various calculator modes. */
 {
   switch (current)
@@ -463,7 +471,7 @@
   if (rstate) make_registers() ;
 }
 
-
+void
 do_shift()     /* Perform bitwise shift on display value. */
 {
   int n, shift ;
@@ -486,7 +494,7 @@
     }
 }
 
-
+void
 do_sto_rcl()     /* Save/restore value to/from memory register. */
 {
   if (current >= '0' && current <= '9')
@@ -513,7 +521,7 @@
            current == 'x' || current == '/') pending_op = current ;
 }
 
-
+void
 do_trig()         /* Perform all trigonometric functions. */
 {
   double temp ;
@@ -577,7 +585,7 @@
   disp_val = tresults[(int) ttype] ;
 }
 
-
+void
 do_trigtype()          /* Change the current trigonometric type. */
 {
   switch (current)
--- get.c
+++ get.c	2004-04-26 16:28:21.000000000 +0200
@@ -16,6 +16,9 @@
 
 #include <stdio.h>
 #include <strings.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
 #include <sys/param.h>
 #include <pwd.h>
 #include "patchlevel.h"
@@ -23,6 +26,9 @@
 #include "color.h"
 #include "extern.h"
 
+extern int char_val();
+void getparam();
+void usage();
 
 char *
 convert(line)              /* Convert .calctoolrc line to ascii values. */
@@ -48,7 +54,7 @@
   return(output) ;
 }
 
-
+void
 get_options(argc, argv)           /* Extract command line options. */
 int argc ;
 char *argv[] ;
@@ -58,7 +64,7 @@
   STRCPY(helpname, HELPNAME) ;    /* Default help filename. */
   STRCPY(x11_display, "") ;       /* Initially no X11 display value. */
   STRCPY(geometry, "") ;          /* Initialy no X11 geometry value. */
-  accuracy = 2 ;                  /* Initial accuracy. */
+  accuracy = 9 ;                  /* Initial accuracy. */
   inv_video = 0 ;                 /* Default is normal video. */
   INC ;
   while (argc > 0)
@@ -74,7 +80,7 @@
                            FPRINTF(stderr,
                                    "%s: accuracy should be in the range 0-9\n",
                                    progname) ;
-                           accuracy = 2 ;
+                           accuracy = 9 ;
                          }
                        break ;
             case 'd' : INC ;                 /* X11 display information. */
@@ -144,7 +150,7 @@
     }
 }
 
-
+void
 getparam(s, argv, errmes)
 char *s, *argv[], *errmes ;
 {
@@ -156,7 +162,7 @@
     }                                  
 }
 
-
+void
 get_helpfile(helpname)     /* Open helpfile if present. */
 char *helpname ;
 {
@@ -168,7 +174,7 @@
   if ((hfd = fopen(helpname,"r")) == NULL)
     {
       paths = getenv("PATH") ;
-      if ((ptr = paths) && helpname[0] != '/')
+      if ((ptr = paths) && helpname[0] != '/') {
         for (;;)
           if (*ptr == ':' || *ptr == '\0')
             {
@@ -182,12 +188,13 @@
               i = 0 ;
             }
           else name[i++] = *ptr++ ;
+      }
       FPRINTF(stderr, "%s: Help file: %s not found\r\n", progname, helpname) ;
       ishelp = 0 ;
     }
 }
 
-
+void
 get_rcfile(name)          /* Read .calctoolrc file. */
 char *name ;
 {
@@ -268,10 +275,10 @@
                   while (line[n] == ' ') n++ ;
                   line[strlen(line)-1] = '\0' ;
                   if (isval == 'c')
-                    SPRINTF(con_names[i], "%1d: %g [%s]",
+                    SPRINTF(con_names[i], "%1d   %g [%s]",
                             i, con_vals[i], &line[n]) ;
                   else
-                    SPRINTF(fun_names[i], "%1d: %s [%s]",
+                    SPRINTF(fun_names[i], "%1d   %s [%s]",
                             i, fun_vals[i], &line[n]) ;
                   break ;
                 }
@@ -280,7 +287,7 @@
   FCLOSE(rcfd) ;
 }
 
-
+void
 read_rcfiles()   /* Read .calctoolrc's from home and current directories. */
 {
   char *home ;            /* Pathname for users home directory. */
@@ -291,7 +298,7 @@
 
   for (n = 0; n < MAXREGS; n++)
     {
-      SPRINTF(name, "%1d: %g [%s]", n, con_vals[n], con_names[n]) ;
+      SPRINTF(name, "%1d   %g [%s]", n, con_vals[n], con_names[n]) ;
       STRCPY(con_names[n], name) ;
       STRCPY(fun_vals[n], "") ;       /* Initially empty function strings. */
     }
@@ -299,16 +306,16 @@
   if ((home = getenv("HOME")) == NULL)
     {
       if ((entry = getpwuid(getuid())) == NULL) return ;
-      home = entry->pw_dir ;
+      home = entry->pw_dir;
     }
   SPRINTF(name, "%s/%s", home, RCNAME) ;
   get_rcfile(name) ;      /* Read .calctoolrc from users home directory. */
 
-  SPRINTF(name, "%s/%s", getwd(pathname), RCNAME) ;
+  SPRINTF(name, "%s/%s", getcwd(pathname, MAXPATHLEN), RCNAME) ;
   get_rcfile(name) ;      /* Read .calctoolrc file from current directory. */
 }
 
-
+void
 usage()
 {
   FPRINTF(stderr, "Usage: %s: [-d display] [-g geometry] ", progname) ;
--- graphics.c
+++ graphics.c	2004-04-26 17:02:43.000000000 +0200
@@ -15,12 +15,14 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <strings.h>
+#include <string.h>
 #include "calctool.h"
 #include "color.h"
 #include "extern.h"
 
-
+void
 but_text(row, column, portion, state)
 int row, column, portion ;
 enum but_state state ;
@@ -45,13 +47,15 @@
        DISPLAY+row*(BHEIGHT+BGAP)+BBORDER+y, KEYCANVAS, butfont, color, pstr) ;
 }
 
+void make_canvas();
 
+void
 do_repaint()     /* Redraw the calctool canvas[es]. */
 {
   make_canvas(0) ;
 }
 
-
+void
 drawbox(x, y, width, height)
 int x, y, width, height ;
 {
@@ -61,7 +65,9 @@
   drawline(x+width, y, x+width, y+height) ;
 }
 
+void fillbox();
 
+void
 draw_button(row, column, portion, state)
 int row, column, portion ;
 enum but_state state ;
@@ -88,7 +94,7 @@
   but_text(row, column, portion, state) ;
 }
 
-
+void
 fillbox(x, y, width, height, boundry, color)
 int x, y, width, height, boundry, color ;
 {
@@ -100,7 +106,9 @@
   else color_area(x, y, width, height, color) ;
 }
 
+void handle_menu_selection();
 
+void
 get_menu_value()     /* Get menu value if valid right mouse press. */
 {
   int i, n, val ;
@@ -115,7 +123,7 @@
       }
 }
 
-
+void
 grey_buttons(base)     /* Grey out numeric buttons depending upon base. */
 enum base_type base ;
 {
@@ -141,7 +149,9 @@
     }                    
 }
 
+void inv_but();
 
+void
 handle_down_event(type)
 int type ;
 {
@@ -170,7 +180,7 @@
     } 
 }
 
-
+void
 handle_menu_selection(menu, item)   /* Process right button menu selection. */
 int menu, item ;
 {
@@ -181,7 +191,7 @@
   inv_but(row, column, portion, NORMAL) ;
 }
 
-
+void
 inv_but(row, column, portion, state)
 int row, column, portion ;
 enum but_state state ;
@@ -191,9 +201,10 @@
   n = row*BCOLS*2 + column*2 + portion ;
   if (pending_op != '?')
     {
-      if (state == NORMAL)
+      if (state == NORMAL) {
         if (iscolor) color = buttons[n].color ;
         else color = (portion) ? BLACK : WHITE ;
+      }
       if (state == INVERTED)
         color = (portion) ? WHITE : BLACK ;
       fillbox(column*(BWIDTH+BGAP)+BBORDER+6,
@@ -203,7 +214,10 @@
     }
 }
 
+void set_item();
+void make_menus();
 
+void
 make_canvas(toggle)
 int toggle ;
 {
@@ -227,7 +241,7 @@
   make_registers() ;
 }
 
-
+void
 make_menus()      /* Create the popup menus used by the graphics versions. */
 {
 
@@ -262,7 +276,7 @@
   create_menu(M_STO) ;     /* Register store. */
 }
 
-
+void
 make_registers()           /* Calculate memory register frame values. */
 {
   char line[MAXLINE] ;     /* Current memory register line. */
@@ -278,7 +292,7 @@
     }
 }
 
-
+void
 process_event(type)       /* Process this event. */
 int type ;
 {
@@ -347,7 +361,7 @@
     }                           
 }
 
-
+void
 set_item(itemno, str)
 enum item_type itemno ;
 char *str ;
@@ -369,4 +383,13 @@
 
   drawtext(x, y, KEYCANVAS, font, BLACK, str) ;
   STRCPY(items[(int) itemno].text, str) ;
+#ifdef USE_BITCALC
+  if (bstate)
+    {
+      if (error)
+	update_bit_popup(0UL);
+      else if (itemno == DISPLAYITEM)
+	update_bit_popup(ibool(convert_display()));
+    }
+#endif
 }
--- mathlib.c
+++ mathlib.c	2004-04-26 16:55:42.000000000 +0200
@@ -65,6 +65,7 @@
 double sinh(), sqrt() ;
 
 extern double frexp(), ldexp(), modf() ;
+extern void doerr();
 
 
 /*  FUNCTION
--- x11.c
+++ x11.c	2004-04-26 17:11:21.000000000 +0200
@@ -14,6 +14,8 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
 #include "calctool.h"
 #include "color.h"
 #include "extern.h"
@@ -22,10 +24,23 @@
 #include <X11/Xatom.h>
 #include <X11/cursorfont.h>
 #include <X11/keysym.h>
+#include <X11/Xmd.h>
+#include <X11/Intrinsic.h>
+#include <X11/Shell.h>
+#include <X11/StringDefs.h>
+#include <X11/Xaw3d/SmeBSB.h>
+#include <X11/Xaw3d/SimpleMenu.h>
+#include <X11/Xaw3d/SmeLine.h>
+#include <X11/Xaw3d/Form.h>
+#include <X11/Xaw3d/Label.h>
+#ifdef USE_BITCALC
+# include <X11/Xaw/Toggle.h>
+#endif
+#include <X11/Xmu/Atoms.h>
 
 #define  XGETSIZEHINTS  (void) XGetSizeHints
 
-#define  BIGFONT               "helvetica-bold-14"
+#define  BIGFONT               "*helvetica-bold-r-*-14-*-iso8859-1"
 #define  DEFFONT               "fixed"
 #define  NORMALFONT            "fixed"
 #define  SMALLFONT             "6x10"
@@ -34,6 +49,10 @@
 
 #define  FRAME_MASK  (ButtonPressMask | ButtonReleaseMask | KeyPressMask | \
                       EnterWindowMask | LeaveWindowMask | ExposureMask)
+#define  MENU_MASK   (ButtonPressMask | ButtonReleaseMask | KeyPressMask | \
+		      ButtonMotionMask | PointerMotionMask | ExposureMask)
+
+static int curmenu = -1;
 
 short help_cursor_array[16] = {
 #include "help.cursor"
@@ -47,6 +66,20 @@
 #include "calctool.color.icon"
 } ;
 
+static Widget menus[MAXMENUS];
+static Widget input;
+#ifdef USE_BITCALC
+static Widget bitcalc;
+int bstate;
+static void enable_bit_popup();
+typedef struct _bit_buttons_s {
+  unsigned int value:1;
+  Widget button;
+} bit_t;
+static bit_t bits[32];
+#endif
+static void menu_proc(Widget entry, XtPointer closure, XtPointer call);
+
 Atom protocol_atom, kill_atom ;
 Cursor help_cursor, main_cursor ;
 Display *dpy ;
@@ -54,6 +87,7 @@
 Pixmap calctool_icon, help_pixmap ;
 Pixmap load_icon() ;
 Window frame, rframe ;
+static Widget topw;
 XColor BGcolor, FGcolor, current_col ;
 XEvent event ;
 XFontStruct *bfont, *font, *nfont, *sfont ;
@@ -67,14 +101,14 @@
 unsigned long backgnd, foregnd ;
 unsigned long palette[CALC_COLORSIZE] ;
 
-
+void
 clear_canvas(ctype, color)
 enum can_type ctype ;
 int color ;
 {
   int x, y ;
   unsigned int width, height, bwidth, depth ;
-  Window root, window ;
+  Window root, window = frame;
 
        if (ctype == KEYCANVAS) window = frame ;
   else if (ctype == REGCANVAS) window = rframe ;
@@ -90,7 +124,7 @@
   XFillRectangle(dpy, window, gc, x, y, width, height) ;
 }
 
-
+void
 close_frame()
 {
   XEvent event ;
@@ -106,7 +140,7 @@
   XFlush(dpy) ;
 }
 
-
+void
 color_area(x, y, width, height, color)
 int x, y, width, height, color ;
 {
@@ -122,13 +156,80 @@
                  (unsigned int) width, (unsigned int) height) ;
 }
 
+void
+menu_set(Widget menu, char *name, int val)
+{
+  intptr_t tmp = (intptr_t)val;
+  XtCallbackRec cb[2] = {{(XtCallbackProc)menu_proc, (XtPointer)tmp}, {NULL, NULL}};
+  Arg av[3];
+  int ac = 0;
+
+  XtSetArg(av[ac], XtNcallback, (XtArgVal)cb); ac++;
+  XtSetArg(av[ac], XtNlabel, name); ac++;
+  XtSetArg(av[ac], XtNsensitive, True); ac++;
+
+  XtCreateManagedWidget (name, smeBSBObjectClass, menu, av, ac);
+
+  if (!XtIsRealized(menu))
+    {
+      unsigned long mask = (CWSaveUnder|CWEventMask);
+      XSetWindowAttributes attr;
+
+      attr.save_under        = True;
+      attr.event_mask        = MENU_MASK;
 
+      XtRealizeWidget(menu);
+      XChangeWindowAttributes(dpy, XtWindow(menu), mask, &attr);
+    }
+}
+
+static Widget
+menu_create(enum menu_type mtype)
+{
+  Widget menu;
+  char name[255];
+
+  sprintf(name, "menu%d", (int) mtype);
+  menu = XtCreatePopupShell (name, simpleMenuWidgetClass, topw, NULL, 0);
+
+  return menu;
+}
+
+void
 create_menu(mtype)    /* Create popup menu for right button press. */
 enum menu_type mtype ;
 {
-}
+  int i;
+
+  menus[(int) mtype] = menu_create(mtype);
 
+  for (i = 0; i < MAXREGS; i++)
+    {
+      switch (mtype)
+	{
+	  case M_ACC   :
+	  case M_EXCH  :
+	  case M_LSHIFT:
+	  case M_RCL   :
+	  case M_RSHIFT:
+	  case M_STO   :
+	    menu_set(menus[(int) mtype], num_names[i], i+1);
+	    break;
+	  case M_CON   :
+	    if (strlen(con_names[i]))
+	      menu_set(menus[(int) mtype], con_names[i], i+1);
+	    break;
+	  case M_FUN   :
+	    if (strlen(fun_names[i]))
+	      menu_set(menus[(int) mtype], fun_names[i], i+1);
+	    break;
+	  default:
+	    break;
+	}
+    }
+}
 
+void
 destroy_frame()
 {
   XDestroyWindow(dpy, frame) ;
@@ -136,13 +237,25 @@
   exit(0) ;
 }
 
-
+int
 do_menu(mtype)      /* Popup appropriate menu and get value. */
 enum menu_type mtype ;
 {
-}
+  if (XtIsRealized(menus[(int) mtype]))
+    {
+      Window r, c;
+      int rx, ry, cx, cy, m;
 
+      curmenu = (int)mtype;
+      XQueryPointer(dpy, RootWindow(dpy, screen),
+	&r, &c, &rx, &ry, &cx, &cy, &m);
+      XtMoveWidget (menus[(int) mtype], rx, ry);
+      XtPopup(menus[(int) mtype], XtGrabExclusive);
+    }
+  return 0;
+}
 
+void
 drawline(x1, y1, x2, y2)
 int x1, y1, x2, y2 ;
 {
@@ -153,20 +266,47 @@
   XDrawLine(dpy, frame, gc, x1, y1, x2, y2) ;
 }
 
+static int frame_pos(int *x, int *y)
+{
+  int w, h, b, d;
+  Window root, dummy;
+
+  if (!XGetGeometry(dpy, frame, &root, x, y, &w, &h, &b, &d))
+	return 0;
+  XTranslateCoordinates(dpy, frame, root, *x - b, *y - b, x, y, &dummy);
+  return 1;
+}
 
+void
 draw_regs()
 {
+  static int first;
+  if (!first)
+    {
+      int x = 0, y = 0;
+      if (frame_pos(&x, &y))
+	{
+	  if (x < 0) x = -x;
+	  if (y < 0) y = -y;
+	  if (x + 2*TWIDTH + 8>= DisplayWidth(dpy, screen))
+	    x -= TWIDTH + 24;
+	  else
+	    x += TWIDTH + 8;
+	  XMoveWindow(dpy, rframe, x, y - 30);
+	}
+      first++;
+    }
   XMapWindow(dpy, rframe) ;
 }
 
-
+void
 drawtext(x, y, ctype, fontno, color, str)
 enum font_type fontno ;
 enum can_type ctype ;
 int x, y, color ;
 char *str ;
 {
-  Window window ;
+  Window window = frame;
 
        if (fontno == SFONT) font = sfont ;
   else if (fontno == NFONT) font = nfont ;
@@ -187,17 +327,21 @@
   XDrawString(dpy, window, gc, x, y, str, strlen(str)) ;
 }
 
-
+void
 get_display()         /* GET function key was pressed. */
 {
 }
 
-
 XFontStruct *
 get_font(name)
 char *name ;
 {
-  XFontStruct *font ;
+  int found;
+  char **list = XListFonts(dpy, name, 1, &found);
+  XFontStruct *font;
+
+  if (list && list[0])
+    name = list[0];
 
   if (!(font = XLoadQueryFont(dpy, name)))
     if (!(font = XLoadQueryFont(dpy, DEFFONT)))
@@ -205,10 +349,52 @@
         perror("couldn't get the default font.") ;
         exit(1) ;
       }
+
+  if (list)
+    XFreeFontNames(list);
+
   return(font) ;
 }
 
 
+static Atom atoms[8];
+static String primary[XtNumber(atoms)] =
+{
+  "CUT_BUFFER0",
+  "CUT_BUFFER1",
+  "CUT_BUFFER2",
+  "CUT_BUFFER3",
+  "CUT_BUFFER4",
+  "CUT_BUFFER5",
+  "CUT_BUFFER6",
+  "CUT_BUFFER7",
+};
+static void cut_buffer()
+{
+  int c = 0;
+  size_t len = strlen(display);
+
+  if (len <= 0 || len > (4*XMaxRequestSize(dpy) - 32))
+    return;
+
+  XmuInternStrings(dpy, (String*)&primary, XtNumber(atoms), atoms);
+  switch (atoms[0])
+    {
+      case XA_CUT_BUFFER0: c = 0; break;
+      case XA_CUT_BUFFER1: c = 1; break;
+      case XA_CUT_BUFFER2: c = 2; break;
+      case XA_CUT_BUFFER3: c = 3; break;
+      case XA_CUT_BUFFER4: c = 4; break;
+      case XA_CUT_BUFFER5: c = 5; break;
+      case XA_CUT_BUFFER6: c = 6; break;
+      case XA_CUT_BUFFER7: c = 7; break;
+    }
+  XStoreBuffer(dpy, display, len, c);
+}
+
+int process_expose();
+
+int
 get_next_event()
 {
   XClientMessageEvent *ev ;
@@ -217,7 +403,18 @@
   char chs[2] ;
 
   if (!XCheckMaskEvent(dpy, ExposureMask, &event))
-    XNextEvent(dpy, &event) ;
+    XNextEvent(dpy, &event);
+
+  if ((event.xany.window != frame &&
+       event.xany.window != rframe
+#ifdef USE_BITCALC
+       && event.xany.window != XtWindow(bitcalc)
+#endif
+      ) /* || (curmenu >= 0) */)
+    {
+      XtDispatchEvent(&event);
+      return(LASTEVENTPLUSONE);
+    }
 
   switch (event.type)
     {
@@ -226,7 +423,22 @@
                               ev = (XClientMessageEvent *) &event ;
                               if (ev->message_type == protocol_atom &&
                                   ev->data.l[0] == kill_atom)
-                                exit(0) ;
+				{
+				  if (event.xany.window == frame)
+				    exit(0);
+				  else if (event.xany.window == rframe && rstate)
+				    {
+				      rstate = !rstate;
+				      XUnmapWindow(dpy, rframe);
+				    }
+#ifdef USE_BITCALC
+				  else if (event.xany.window == XtWindow(bitcalc) && bstate)
+				    {
+				      bstate = !bstate;
+				      XtPopdown(bitcalc);
+				    }
+#endif
+				}
                               return(LASTEVENTPLUSONE) ;
 
       case Expose           : return(process_expose(&event)) ;
@@ -248,6 +460,18 @@
 
       case ButtonPress      : curx = event.xbutton.x ;
                               cury = event.xbutton.y ;
+			      if (items[DISPLAYITEM].y > cury)
+				{
+#ifdef USE_BITCALC
+				  if (event.xbutton.button == Button3)
+				    {
+				      toggle_bit_popup();
+				      return(LASTEVENTPLUSONE);
+				    }
+#endif
+				  cut_buffer();
+				  return(LASTEVENTPLUSONE);
+				}
                               if (event.xbutton.button == Button1)
                                 return(LEFT_DOWN) ;
                               else if (event.xbutton.button == Button2)
@@ -266,34 +490,55 @@
 
       default               : return(LASTEVENTPLUSONE) ;
    }
-/*NOTREACHED*/
+   return 0; /*NOTREACHED*/
 }
 
-
+void
 handle_selection()
 {
 }
 
-
+void
 init_fonts()
 {
   bfont = get_font(BIGFONT) ;
   nfont = get_font(NORMALFONT) ;
-  nfont_width = 6 ;
+  nfont_width = nfont->max_bounds.rbearing - nfont->min_bounds.lbearing ;
   sfont = get_font(SMALLFONT) ;
 }
 
 
+static char *fallback_resources[] = {
+    "Calctool*SimpleMenu*menuLabel.vertSpace: 100",
+    "Calctool*SimpleMenu*HorizontalMargins: 4",
+    "Calctool*SimpleMenu*Sme.height: 4",
+    "Calctool*SimpleMenu*Cursor: top_left_arrow",
+    "Calctool*Foreground:  black",
+    "Calctool*Background:  grey",
+    NULL,
+};
+
+int
 init_ws_type()
 {
-  char * tmpGeometry;
-  
-  if ((dpy = XOpenDisplay(x11_display)) == NULL)
+  char * tmpGeometry = NULL;
+  XtAppContext Xtappcon;
+  int dummy = 0;
+
+  XtSetLanguageProc (NULL, NULL, NULL);
+
+  XtToolkitInitialize();
+  Xtappcon = XtCreateApplicationContext();
+  XtAppSetFallbackResources(Xtappcon, fallback_resources);
+
+  if ((dpy = XtOpenDisplay(Xtappcon, x11_display, "calctool", "Calctool", NULL, 0, &dummy, NULL)) == NULL)
     {
       FPRINTF(stderr,"%s: Couldn't open display %s\n", progname,
               (getenv ("DISPLAY") ? getenv("DISPLAY") : x11_display)) ;
       exit(1) ;
     }
+  topw = XtAppCreateShell("calctool", "Calctool", applicationShellWidgetClass, dpy, NULL, 0);
+  XtDisplayInitialize(Xtappcon, dpy, "calctool", "Calctool", NULL, 0, &dummy, NULL);
 
   screen = DefaultScreen(dpy) ;
 
@@ -310,7 +555,7 @@
   return 0 ;
 }
 
-
+void
 load_colors()      /* Create and load calctool color map. */
 {
   u_char red[CALC_COLORSIZE], green[CALC_COLORSIZE], blue[CALC_COLORSIZE] ;
@@ -366,7 +611,7 @@
   GC pix_gc ;
   Pixmap pixmap ;
   XImage *image ;
-  char cbuf[512*8] ;
+  CARD32 cbuf[512*8] ;
   int i ;
 
   if (iscolor)
@@ -378,7 +623,14 @@
         }
       pix_gc = DefaultGC(dpy, screen) ;
       image = XCreateImage(dpy, DefaultVisual(dpy, screen),
-                           scr_depth, ZPixmap, 0, cbuf, 64, 64, 8, 64) ;
+                           scr_depth, ZPixmap, 0, (void*)cbuf, ICONHEIGHT, ICONHEIGHT, 8, 0) ;
+#if __BYTE_ORDER == __BIG_ENDIAN
+      image->byte_order = MSBFirst;
+#else
+      image->byte_order = LSBFirst;
+#endif
+      image->bits_per_pixel = 32;
+      image->bytes_per_line = 4 * image->width;
       pixmap = XCreatePixmap(dpy, RootWindow(dpy, screen),
                              ICONWIDTH, (unsigned) image->height, scr_depth) ;
       XPutImage(dpy, pixmap, pix_gc, image, 0, 0, 0, 0,
@@ -391,13 +643,13 @@
           cbuf[i*2+0] = revtable[(sbuf[i] >> 8) & 0xFF] ;
           cbuf[i*2+1] = revtable[sbuf[i] & 0xFF] ;
         }
-      pixmap = XCreatePixmapFromBitmapData(dpy, RootWindow(dpy, screen), cbuf,
+      pixmap = XCreatePixmapFromBitmapData(dpy, RootWindow(dpy, screen), (void*)cbuf,
                                      64, 64, foregnd, backgnd, scr_depth) ;
     }
   return(pixmap) ;
 }
 
-
+void
 make_frames(argc, argv)
 int argc ;
 char *argv[] ;
@@ -405,7 +657,8 @@
   unsigned int h, w ;       /* Window dimensions. */
   int flags ;
   int x, y ;                /* Window position. */
-           
+  XClassHint class;
+
   load_colors() ;
   if (iscolor) calctool_icon = load_icon(cicon_image) ;
   else calctool_icon = load_icon(icon_image) ;
@@ -438,7 +691,6 @@
   frame = XCreateSimpleWindow(dpy, RootWindow(dpy, screen),
                               size.x, size.y, size.width, size.height,
                               CALCTOOL_BORDER_WIDTH, foregnd, backgnd) ;
-
   rframe = XCreateSimpleWindow(dpy, RootWindow(dpy, screen),
                                size.x + TWIDTH + 15, size.y,
                                size.width, 200,
@@ -447,7 +699,7 @@
   protocol_atom = XInternAtom(dpy, "WM_PROTOCOLS", False) ;
   kill_atom = XInternAtom(dpy, "WM_DELETE_WINDOW", False) ;
 
-  XSetStandardProperties(dpy, frame, "calctool", NULL, calctool_icon,
+  XSetStandardProperties(dpy, frame, "calctool", "calctool", calctool_icon,
                          argv, argc, &size) ;
 
   wm_hints.icon_x = ix ;
@@ -456,11 +708,29 @@
   wm_hints.icon_pixmap = calctool_icon ;
   wm_hints.flags = InputHint | IconPixmapHint ;
   if (iconic)
-    {
-      wm_hints.initial_state = IconicState ;
-      wm_hints.flags |= StateHint ;
-    }
+    wm_hints.initial_state = IconicState ;
+  else
+    wm_hints.initial_state = NormalState;
+  wm_hints.flags |= StateHint ;
+wm_hints.window_group = (XID)topw;
+wm_hints.flags |= WindowGroupHint;
   XSetWMHints(dpy, frame, &wm_hints) ;
+  class.res_name = "calctool";
+  class.res_class = "Calctool";
+  XSetClassHint(dpy, frame, &class);
+
+  wm_hints.input = False;
+  wm_hints.window_group = (XID)topw;
+  wm_hints.flags = InputHint | StateHint | WindowGroupHint;
+  XSetWMHints(dpy, rframe, &wm_hints) ;
+  class.res_name = "registers";
+  class.res_class = "Registers";
+  XSetClassHint(dpy, rframe, &class);
+  XSetTransientForHint(dpy, rframe, frame);
+
+  XFlush(dpy);
+  (void) XSetWMProtocols (dpy,  frame, &kill_atom, 1);
+  (void) XSetWMProtocols (dpy, rframe, &kill_atom, 1);
 
   gc_mask = GCFont | GCForeground | GCBackground | GCGraphicsExposures ;
   gc_val.font = nfont->fid ;
@@ -474,12 +744,15 @@
   FGcolor.red = FGcolor.green = FGcolor.blue = 0 ;
   BGcolor.red = BGcolor.green = BGcolor.blue = 0xffff ;
   help_cursor = load_cursor(help_cursor_array) ;
+#ifdef USE_BITCALC
+  enable_bit_popup();
+#endif
 }
 
-
+void
 make_icon() {}        /* Null routine - icon created in make_frame. */
 
-
+void
 make_items()
 {
   XSelectInput(dpy, frame, FRAME_MASK) ;
@@ -488,16 +761,31 @@
   XSelectInput(dpy, rframe, ExposureMask) ;
 }
 
-
+void
 make_subframes() {}          /* Null routine, see the make_frame routine. */
 
+static void menu_proc(Widget entry, XtPointer closure, XtPointer call)
+{
+  if (closure)
+    {
+      intptr_t tmp = (intptr_t)closure;
+      handle_menu_selection(curmenu, (int)tmp);
+    }
+  XtPopdown(XtParent(entry));
+  XFlush(dpy) ;
+  curmenu = -1;
+}
 
+int
 process_expose(event)
 /* XExposeEvent *event ; */
      XEvent *event ;
 {
   
   int doframe, dorframe ;
+#ifdef USE_BITCALC
+  int dobits = 0;
+#endif
 
   doframe = dorframe = 0 ;
   do
@@ -506,15 +794,23 @@
         {
                if (event->xexpose.window == frame) doframe++ ;
           else if (event->xexpose.window == rframe) dorframe++ ;
+#ifdef USE_BITCALC
+	  else if (event->xexpose.window == XtWindow(bitcalc)) dobits++;
+#endif
         }
     }
   while (XCheckMaskEvent(dpy, ExposureMask, event)) ;
  
   if (dorframe && rstate) make_registers() ;
   if (doframe) return(CFRAME_REPAINT) ;
+#ifdef USE_BITCALC
+  if (dobits && bstate)
+    update_bit_popup(ibool(disp_val));
+#endif
+  return(LASTEVENTPLUSONE);
 }
 
-
+void
 set_cursor(type)
 int type ;
 {
@@ -526,17 +822,146 @@
     }
 }
 
-
+void
 start_tool()
 {
   while (1)
     process_event(get_next_event()) ;
 }
 
-
+void
 toggle_reg_canvas()
 {
   rstate = !rstate ;
-  if (rstate) XMapWindow(dpy, rframe) ;
+  if (rstate) draw_regs();
   else XUnmapWindow(dpy, rframe) ;
 }
+
+#ifdef USE_BITCALC
+static void bit_cb(Widget entry, XtPointer closure, XtPointer call)
+{
+  if (closure)
+    {
+      intptr_t tmp = (intptr_t)closure;
+      unsigned long val = ibool(disp_val);
+      int slot = (int)(tmp - 1);
+
+      if (val & (1 << slot))
+	val &= ~(1 << slot);
+      else
+	val |=  (1 << slot);
+
+      disp_val = (double)val;	/* Do not use setbool() */
+      show_display(disp_val);
+      if (current == '=' && old_cal_value == '=')
+	last_input = disp_val;	/* No jumping values */
+      new_input = 1;
+    }
+}
+
+static
+void enable_bit_popup()
+{
+  int i;
+  Arg fav[1] = {{XtNdefaultDistance, 0}};
+  Widget form, beside = 0;
+  XSetWindowAttributes attr;
+  unsigned long mask = CWSaveUnder;
+
+  bitcalc = XtCreatePopupShell("bitcalc", transientShellWidgetClass, topw, NULL, 0);
+  form    = XtCreateManagedWidget("form", formWidgetClass, bitcalc,  fav, 1);
+
+  for (i = 31; i >= 0; i--)
+    {
+      char name[255];
+      intptr_t tmp = (intptr_t)(i+1);
+      XtCallbackRec cb[2] = {{(XtCallbackProc)bit_cb, (XtPointer)tmp}, {NULL, NULL}};
+      Arg av[5];
+      int ac = 0;
+
+      sprintf(name, "%d", i);
+      XtSetArg(av[ac], XtNcallback, (XtArgVal)cb); ac++;
+      XtSetArg(av[ac], XtNlabel, name); ac++;
+      XtSetArg(av[ac], XtNsensitive, True); ac++;
+      XtSetArg(av[ac], XtNhighlightThickness, 0); ac++;
+      if (beside) {
+	XtSetArg(av[ac], XtNfromHoriz, beside); ac++;
+      }
+      beside = XtCreateManagedWidget(name, toggleWidgetClass, form, av, ac);
+      bits[i].button = beside;
+    }
+  attr.save_under = True;
+  XtRealizeWidget(bitcalc);
+  XChangeWindowAttributes(dpy, XtWindow(bitcalc), mask, &attr);
+  XtMoveWidget (bitcalc, size.x + TWIDTH + 15, size.y);
+  wm_hints.input = False;
+  wm_hints.window_group = (XID)topw;
+  wm_hints.flags = InputHint | StateHint | WindowGroupHint;
+  XSetWMHints(dpy, XtWindow(bitcalc), &wm_hints) ;
+  XSetTransientForHint(dpy, XtWindow(bitcalc), frame);
+  (void) XSetWMProtocols (dpy, XtWindow(bitcalc), &kill_atom, 1);
+}
+
+static void draw_bit()
+{
+  static int first;
+  if (!first)
+    {
+      int x = 0, y = 0;
+      if (frame_pos(&x, &y))
+	{
+	  int bitx, bity;
+	  unsigned int width, height, bwidth, depth;
+	  Window root;
+
+	  XGetGeometry(dpy, XtWindow(bitcalc), &root, &bitx, &bity, &width, &height, &bwidth, &depth) ;
+	  if (x < 0) x = -x;
+	  if (y < 0) y = -y;
+	  y -= 30;
+
+	  if (x + width+TWIDTH + 8 >= DisplayWidth(dpy, screen))
+	    x -= width + 24;
+	  else
+	    x += TWIDTH + 8;
+
+	  if (x < 0)
+	    {
+	      x = 0;
+	      if (y > height + 30)
+		y -= 60; 
+	      else
+		y += THEIGHT + height + 30 + 16;
+	    }
+	  XMoveWindow(dpy, XtWindow(bitcalc), x, y);
+	}
+      first++;
+    }
+  XtPopup(bitcalc, XtGrabNonexclusive);
+}
+
+void toggle_bit_popup()
+{
+  bstate = !bstate;
+  if (bstate) draw_bit();
+  else XtPopdown(bitcalc);
+  if (bstate) update_bit_popup(ibool(disp_val));
+}
+
+void update_bit_popup(unsigned long val)
+{
+  if (bstate)
+    {
+      int i;
+      for (i = 31; i >= 0; i--)
+	{
+	  unsigned long pixel;
+	  Arg av[1];
+	  if (val & (1 << i))
+	    XtSetArg(av[0], XtNstate, True);
+	  else
+	    XtSetArg(av[0], XtNstate, False);
+	  XtSetValues(bits[i].button, av, 1);
+	}
+    }
+}
+#endif
