Import of DJ Dalories hcalc window calculator
authorSteven Edwards <winehacker@gmail.com>
Mon, 15 Jul 2002 04:55:44 +0000 (04:55 +0000)
committerSteven Edwards <winehacker@gmail.com>
Mon, 15 Jul 2002 04:55:44 +0000 (04:55 +0000)
svn path=/trunk/; revision=3225

rosapps/hcalc/bitmap1.bmp [new file with mode: 0644]
rosapps/hcalc/chars.bmp [new file with mode: 0644]
rosapps/hcalc/face.bmp [new file with mode: 0644]
rosapps/hcalc/hcalc.aps [new file with mode: 0644]
rosapps/hcalc/hcalc.c [new file with mode: 0644]
rosapps/hcalc/hcalc.h [new file with mode: 0644]
rosapps/hcalc/hcalc.mak [new file with mode: 0644]
rosapps/hcalc/hcalc.rc [new file with mode: 0644]
rosapps/hcalc/hcalc.vcp [new file with mode: 0644]
rosapps/hcalc/input.c [new file with mode: 0644]
rosapps/hcalc/resource.h [new file with mode: 0644]

diff --git a/rosapps/hcalc/bitmap1.bmp b/rosapps/hcalc/bitmap1.bmp
new file mode 100644 (file)
index 0000000..ac8f47a
Binary files /dev/null and b/rosapps/hcalc/bitmap1.bmp differ
diff --git a/rosapps/hcalc/chars.bmp b/rosapps/hcalc/chars.bmp
new file mode 100644 (file)
index 0000000..f296e59
Binary files /dev/null and b/rosapps/hcalc/chars.bmp differ
diff --git a/rosapps/hcalc/face.bmp b/rosapps/hcalc/face.bmp
new file mode 100644 (file)
index 0000000..1e81d74
Binary files /dev/null and b/rosapps/hcalc/face.bmp differ
diff --git a/rosapps/hcalc/hcalc.aps b/rosapps/hcalc/hcalc.aps
new file mode 100644 (file)
index 0000000..c07a907
Binary files /dev/null and b/rosapps/hcalc/hcalc.aps differ
diff --git a/rosapps/hcalc/hcalc.c b/rosapps/hcalc/hcalc.c
new file mode 100644 (file)
index 0000000..1186057
--- /dev/null
@@ -0,0 +1,282 @@
+/* Copyright 1998 DJ Delorie <dj@delorie.com>
+   Distributed under the terms of the GNU GPL
+   http://www.delorie.com/store/hcalc/
+*/
+#include <stdio.h>
+#include <stdarg.h>
+
+#define  STRICT
+#define  WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#include "hcalc.h"
+
+#define WIDTH 125
+#define HEIGHT 147
+
+/*
+** local vars
+*/
+static char            szAppName[16];
+static char            szTitle[80];
+static HINSTANCE       hInst;
+static HBITMAP         face, chars, bits;
+
+static int r=0, g=0, b=0;
+static HWND window;
+
+static char shown_offsets[15];
+static int shown_bitmask;
+static int show_bits;
+
+#define CHARS_LEFT     6
+#define CHARS_TOP      6
+
+#define BITS_RIGHT     92
+#define BITS_TOP       6
+
+char charmap[] = " 0123456789ABCDEF-x,.ro+";
+int char_to_x[256];
+
+void
+paint_bits(HDC dc, HDC bdc)
+{
+  int i;
+  SelectObject(bdc, bits);
+  for (i=0; i<32; i++)
+  {
+    int b = (shown_bitmask >> i) & 1;
+    BitBlt(dc, BITS_RIGHT-2*i-3*(i/4), BITS_TOP, 1, 7,
+          bdc, b, 0, SRCCOPY);
+  }
+  
+}
+
+void
+paint_chars(HDC dc, HDC bdc)
+{
+  int i;
+  SelectObject(bdc, chars);
+  for (i=0; i<15; i++)
+  {
+    BitBlt(dc, CHARS_LEFT+6*i, CHARS_TOP, 5, 7,
+          bdc, shown_offsets[i], 0, SRCCOPY);
+  }
+}
+
+int
+paint()
+{
+  PAINTSTRUCT paintstruct;
+  HDC dc = BeginPaint(window, &paintstruct);
+  HDC bdc = CreateCompatibleDC(dc);
+  SelectObject(bdc, face);
+  BitBlt(dc, 0, 0, WIDTH, HEIGHT, bdc, 0, 0, SRCCOPY);
+
+  if (show_bits)
+    paint_bits(dc, bdc);
+  else
+    paint_chars(dc, bdc);
+
+  DeleteDC(bdc);
+  EndPaint(window, &paintstruct);
+  return 0;
+}
+
+void
+redraw()
+{
+  RECT r;
+  r.left = 0;
+  r.right = WIDTH-1;
+  r.top = 0;
+  r.bottom = HEIGHT-1;
+  InvalidateRect(window, &r, FALSE);
+}
+
+void
+set_bits(int b)
+{
+  shown_bitmask = b;
+  show_bits = 1;
+  redraw();
+}
+
+void
+set_string(char *s)
+{
+  char tmp[16];
+  int i;
+  sprintf(tmp, "%15.15s", s);
+  for (i=0; i<15; i++)
+    shown_offsets[i] = char_to_x[tmp[i]];
+  show_bits = 0;
+  redraw();
+}
+
+static int count=0;
+static char tmp[100];
+static char ctmp[20] = "                ";
+
+void
+do_exit(int ec)
+{
+  PostQuitMessage(ec);
+}
+
+/*
+** Main Windows Proc
+*/
+LRESULT CALLBACK
+WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+  int i;
+  int lw = LOWORD(wParam);
+  int hw = HIWORD(wParam);
+  HWND w = (HWND)lParam;
+
+  window = hWnd;
+
+  switch (message)
+  {
+  case WM_DESTROY:
+    PostQuitMessage(0);
+    break;
+
+  case WM_PAINT:
+    return paint();
+
+  case WM_LBUTTONDOWN:
+#if 0
+    count++;
+    wsprintf(tmp, "%3d %3d", LOWORD(lParam), HIWORD(lParam));
+    set_string(tmp);
+#else
+    button(1, LOWORD(lParam), HIWORD(lParam));
+#endif
+    break;
+
+  case WM_RBUTTONDOWN:
+#if 0
+    count++;
+    set_bits(count);
+#else
+    button(2, LOWORD(lParam), HIWORD(lParam));
+#endif
+    break;
+
+  case WM_CHAR:
+#if 0
+    for (i=0; i<20; i++)
+      ctmp[i] = ctmp[i+1];
+    ctmp[14] = wParam;
+    ctmp[15] = 0;
+    set_string(ctmp);
+#else
+    key(wParam);
+#endif
+    break;
+
+  default:
+    break;
+
+  } /* switch message */
+
+  return DefWindowProc (hWnd, message, wParam, lParam);
+}
+
+/*
+** register class
+*/
+static BOOL
+InitApplication(HINSTANCE hInstance, int nCmdShow)
+{
+  int i, style;
+  WNDCLASS wc;
+  HWND hWnd;
+  RECT size;
+
+  LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
+  LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
+
+  hInst = hInstance;
+
+  wc.style          = CS_HREDRAW | CS_VREDRAW;
+  wc.lpfnWndProc   = (WNDPROC)WndProc;
+  wc.cbClsExtra    = 0;
+  wc.cbWndExtra    = 0;
+  wc.hInstance     = hInstance;
+  wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
+  wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
+  wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
+  wc.lpszMenuName  = NULL;
+  wc.lpszClassName = szAppName;
+
+  if (RegisterClass(&wc) == 0)
+    return FALSE;
+
+  style = WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX;
+
+  size.left = 0;
+  size.top = 0;
+  size.right = WIDTH-3;
+  size.bottom = HEIGHT-3;
+  AdjustWindowRect(&size, style, 0);
+
+  hWnd = CreateWindowEx(WS_EX_TOPMOST,
+                     szAppName,
+                     szTitle,
+                     style,
+                     CW_USEDEFAULT, 0,
+                     size.right-size.left, size.bottom-size.top,
+                     NULL,
+                     NULL,
+                     hInstance,
+                     NULL
+                     );
+
+  if (hWnd == NULL)
+    return FALSE;
+
+  face  = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_FACE));
+  chars = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_CHARS));
+  bits  = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITS));
+
+  for (i=0; i<256; i++)
+    char_to_x[i] = 0;
+  for (i=0; charmap[i]; i++)
+    char_to_x[charmap[i]] = i*6;
+
+  window = hWnd;
+
+  ShowWindow(hWnd, nCmdShow);
+  UpdateWindow(hWnd);
+
+  return TRUE;
+}
+
+/*
+** Main entry
+*/
+int WINAPI
+WinMain(HINSTANCE hInstance,
+       HINSTANCE hPrevInstance,
+       LPSTR lpszCmdLine,
+       int nCmdShow)
+{
+    MSG msg;
+    HANDLE hAccelTable;
+
+    if (!InitApplication(hInstance, nCmdShow))
+       return FALSE;
+
+    hAccelTable = LoadAccelerators(hInstance, szAppName);
+
+    while( GetMessage(&msg, NULL, 0, 0))
+       if (!TranslateAccelerator (msg.hwnd, hAccelTable, &msg))
+       {
+           TranslateMessage(&msg);
+           DispatchMessage(&msg);
+       }
+    return msg.wParam;
+}
diff --git a/rosapps/hcalc/hcalc.h b/rosapps/hcalc/hcalc.h
new file mode 100644 (file)
index 0000000..b7aaf4c
--- /dev/null
@@ -0,0 +1,5 @@
+/* Copyright 1998 DJ Delorie <dj@delorie.com>
+   Distributed under the terms of the GNU GPL
+   http://www.delorie.com/store/hcalc/
+*/
+#include "resource.h"
diff --git a/rosapps/hcalc/hcalc.mak b/rosapps/hcalc/hcalc.mak
new file mode 100644 (file)
index 0000000..1c344ad
--- /dev/null
@@ -0,0 +1,135 @@
+# Microsoft Visual C++ Generated NMAKE File, Format Version 2.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+!IF "$(CFG)" == ""
+CFG=Win32 Release
+!MESSAGE No configuration specified.  Defaulting to Win32 Release.
+!ENDIF 
+
+!IF "$(CFG)" != "Win32 Release"
+!MESSAGE Invalid configuration "$(CFG)" specified.
+!MESSAGE You can specify a configuration when running NMAKE on this makefile
+!MESSAGE by defining the macro CFG on the command line.  For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "hcalc.mak" CFG="Win32 Release"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE 
+!ERROR An invalid configuration is specified.
+!ENDIF 
+
+################################################################################
+# Begin Project
+# PROP Target_Last_Scanned "Win32 Debug"
+OUTDIR=.\WinRel
+INTDIR=.\WinRel
+
+ALL : $(OUTDIR)/hcalc.exe $(OUTDIR)/hcalc.bsc
+
+$(OUTDIR) : 
+    if not exist $(OUTDIR)/nul mkdir $(OUTDIR)
+
+MTL=MkTypLib.exe
+CPP=cl.exe
+RSC=rc.exe
+BSC32=bscmake.exe
+BSC32_SBRS= \
+       $(INTDIR)/hcalc.sbr \
+       $(INTDIR)/input.sbr
+LINK32=link.exe
+DEF_FILE=
+LINK32_OBJS= \
+       $(INTDIR)/hcalc.obj \
+       $(INTDIR)/hcalc.res \
+       $(INTDIR)/input.obj
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "WinRel"
+# PROP BASE Intermediate_Dir "WinRel"
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "WinRel"
+# PROP Intermediate_Dir "WinRel"
+# ADD BASE MTL /nologo /D "NDEBUG" /win32
+# ADD MTL /nologo /D "NDEBUG" /win32
+# ADD BASE CPP /nologo /W3 /GX /YX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FR /c
+# ADD CPP /nologo /W3 /GX /YX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FR /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+BSC32_FLAGS=/nologo /o$(OUTDIR)/"hcalc.bsc" 
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /NOLOGO /SUBSYSTEM:windows /MACHINE:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /NOLOGO /SUBSYSTEM:windows /MACHINE:I386
+LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
+ advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib\
+ odbccp32.lib /NOLOGO /SUBSYSTEM:windows /INCREMENTAL:no\
+ /PDB:$(OUTDIR)/"hcalc.pdb" /MACHINE:I386 /OUT:$(OUTDIR)/"hcalc.exe" 
+MTL_PROJ=/nologo /D "NDEBUG" /win32 
+CPP_PROJ=/nologo /W3 /GX /YX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS"\
+ /FR$(INTDIR)/ /Fp$(OUTDIR)/"hcalc.pch" /Fo$(INTDIR)/ /c 
+CPP_OBJS=.\WinRel/
+
+.c{$(CPP_OBJS)}.obj:
+   $(CPP) $(CPP_PROJ) $<  
+
+.cpp{$(CPP_OBJS)}.obj:
+   $(CPP) $(CPP_PROJ) $<  
+
+.cxx{$(CPP_OBJS)}.obj:
+   $(CPP) $(CPP_PROJ) $<  
+
+RSC_PROJ=/l 0x409 /fo$(INTDIR)/"hcalc.res" /d "NDEBUG" 
+
+$(OUTDIR)/hcalc.bsc : $(OUTDIR)  $(BSC32_SBRS)
+    $(BSC32) @<<
+  $(BSC32_FLAGS) $(BSC32_SBRS)
+<<
+
+$(OUTDIR)/hcalc.exe : $(OUTDIR)  $(DEF_FILE) $(LINK32_OBJS)
+    $(LINK32) @<<
+  $(LINK32_FLAGS) $(LINK32_OBJS)
+<<
+
+################################################################################
+# Begin Group "Source Files"
+
+################################################################################
+# Begin Source File
+
+SOURCE=.\hcalc.c
+DEP_HCALC=\
+       .\HCALC.H
+
+$(INTDIR)/hcalc.obj :  $(SOURCE)  $(DEP_HCALC) $(INTDIR)
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE=.\hcalc.rc
+DEP_HCALC_=\
+       .\chars.bmp\
+       .\face.bmp
+
+$(INTDIR)/hcalc.res :  $(SOURCE)  $(DEP_HCALC_) $(INTDIR)
+   $(RSC) $(RSC_PROJ)  $(SOURCE) 
+
+# End Source File
+################################################################################
+# Begin Source File
+
+SOURCE=.\input.c
+DEP_INPUT=\
+       .\HCALC.H
+
+$(INTDIR)/input.obj :  $(SOURCE)  $(DEP_INPUT) $(INTDIR)
+
+# End Source File
+# End Group
+# End Project
+################################################################################
diff --git a/rosapps/hcalc/hcalc.rc b/rosapps/hcalc/hcalc.rc
new file mode 100644 (file)
index 0000000..e0c11c6
--- /dev/null
@@ -0,0 +1,73 @@
+//Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE DISCARDABLE 
+BEGIN
+    "resource.h\0"
+END
+
+2 TEXTINCLUDE DISCARDABLE 
+BEGIN
+    "#include ""afxres.h""\r\n"
+    "\0"
+END
+
+3 TEXTINCLUDE DISCARDABLE 
+BEGIN
+    "\r\n"
+    "\0"
+END
+
+/////////////////////////////////////////////////////////////////////////////
+#endif    // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Bitmap
+//
+
+IDB_CHARS               BITMAP  DISCARDABLE     "chars.bmp"
+IDB_FACE                BITMAP  DISCARDABLE     "face.bmp"
+IDB_BITS                BITMAP  DISCARDABLE     "bitmap1.bmp"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// String Table
+//
+
+STRINGTABLE DISCARDABLE 
+BEGIN
+    IDS_APPNAME             "hcalc"
+    IDS_DESCRIPTION         "hcalc"
+END
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif    // not APSTUDIO_INVOKED
+
diff --git a/rosapps/hcalc/hcalc.vcp b/rosapps/hcalc/hcalc.vcp
new file mode 100644 (file)
index 0000000..75c2a4c
Binary files /dev/null and b/rosapps/hcalc/hcalc.vcp differ
diff --git a/rosapps/hcalc/input.c b/rosapps/hcalc/input.c
new file mode 100644 (file)
index 0000000..4d3f53d
--- /dev/null
@@ -0,0 +1,452 @@
+/* Copyright 1998 DJ Delorie <dj@delorie.com>
+   Distributed under the terms of the GNU GPL
+   http://www.delorie.com/store/hcalc/
+*/
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+
+extern void set_bits(int);
+extern void set_string(char *);
+extern void do_exit(int);
+
+#ifdef GNUC
+#define longlong long long
+#else
+#define longlong __int64
+#define XBell(d,v) 1
+#endif
+
+char pending_op = 0;
+int making_number = 0;
+int base = 10;
+
+#define MAXIN 40
+
+char input_buf[MAXIN];
+int iptr;
+double value, saved, stored=0;
+
+void
+convert_number()
+{
+  char *ip = input_buf;
+  double scale = 1;
+  int sign = +1;
+
+  if (*ip == '-')
+    sign = -1;
+  value = 0;
+  while (*++ip)
+  {
+    if (*ip == '.')
+      break;
+    if (*ip >= '0' && *ip <= '9')
+    {
+      value *= base;
+      value += *ip-'0';
+    }
+    if (*ip >= 'a' && *ip <= 'f')
+    {
+      value *= base;
+      value += *ip-'a'+10;
+    }
+  }
+  if (*ip)
+    while (*++ip)
+    {
+      if (*ip >= '0' && *ip <= '9')
+      {
+       scale *= base;
+       value += (*ip-'0')/scale;
+      }
+      if (*ip >= 'a' && *ip <= 'f')
+      {
+       scale *= base;
+       value += (*ip-'a'+10)/scale;
+      }
+    }
+  value *= sign;
+}
+
+void
+show_value()
+{
+  char tmp[20], *tp;
+  char commas[40], *cp, *dp;
+  double v = value;
+
+  if (base == 2)
+  {
+    int q = (unsigned int)((longlong)v & 0xffffffffL);
+    set_bits(q);
+    return;
+  }
+
+  tmp[0] = ' ';
+  if (v < 0)
+  {
+    tmp[0] = '-';
+    v = -v;
+  }
+
+  if (base == 10)
+  {
+    sprintf(tmp+1, "%.14G", v);
+    if (strchr(tmp+1, 'E'))
+      sprintf(tmp+1, "%.9G", v);
+    if (tmp[14] == '.')
+      tmp[14] = 0;
+  }
+  else
+  {
+    static char tohex[] = "0123456789ABCDEF";
+    longlong ll = (longlong)v;
+    char *revptr;
+    tp = tmp+1;
+    if (base == 16)
+    {
+      *tp++ = '0';
+      *tp++ = 'x';
+    }
+    else if (base == 8)
+      *tp++ = '0';
+
+    revptr = tp;
+    do {
+      *tp++ = tohex[ll%base];
+      ll /= base;
+    } while (ll);
+    *tp-- = 0;
+    while (revptr < tp) {
+      char t = *revptr;
+      *revptr = *tp;
+      *tp = t;
+      tp--;
+      revptr++;
+    }
+  }
+
+  cp = commas+40;
+  tp = tmp+strlen(tmp);
+  dp = strchr(tmp, '.');
+  if (dp == 0)
+    dp = tp;
+
+  *--cp = 0;
+  while (tp>=tmp)
+  {
+    *--cp = *tp--;
+    switch (base)
+    {
+    case 10:
+      if (isdigit(cp[0]) && isdigit(cp[1]) && isdigit(cp[2]) && tp<dp
+         && tp>=tmp && isdigit(*tp))
+       *--cp = ',';
+      break;
+    case 16:
+      if (isxdigit(cp[0]) && isxdigit(cp[1])
+         && isxdigit(cp[2]) && isxdigit(cp[3])
+         && tp>=tmp && isxdigit(*tp))
+       *--cp = ',';
+      break;
+    }
+  }
+
+  if (strlen(cp) > 15)
+    set_string(tmp);
+  else
+    set_string(cp);
+}
+
+void
+end_number()
+{
+  if (!making_number)
+    return;
+  making_number = 0;
+  iptr = 0;
+
+  switch (pending_op)
+  {
+  case '+':
+    value = saved + value;
+    break;
+  case '-':
+    value = saved - value;
+    break;
+  case '*':
+    value = saved * value;
+    break;
+  case '/':
+    value = saved / value;
+    break;
+  case '&':
+    value = (double)((longlong)saved & (longlong)value);
+    break;
+  case '|':
+    value = (double)((longlong)saved | (longlong)value);
+    break;
+  case '^':
+    value = (double)((longlong)saved ^ (longlong)value);
+    break;
+  case 'S':
+    if (value < 0)
+      value = (double)((longlong)saved >> (longlong)(-value));
+    else
+      value = (double)((longlong)saved << (longlong)value);
+    break;
+  }
+  saved = value;
+  pending_op = 0;
+  show_value();
+}
+
+void
+start_number()
+{
+  if (making_number)
+    return;
+
+  iptr = 1;
+  input_buf[0] = ' ';
+  input_buf[1] = 0;
+  making_number = 1;
+}
+
+void
+key(char c)
+{
+  int v = c;
+  /* printf("key %c\n", c); */
+
+  switch (c)
+  {
+  case 27:
+    making_number = 0;
+    iptr = 0;
+    pending_op = 0;
+    value = saved = 0;
+    set_string("");
+    break;
+  case 'u':
+    if (making_number)
+    {
+      making_number = 0;
+      set_string("");
+    }
+    break;
+
+  case 'a':
+  case 'b':
+  case 'c':
+  case 'd':
+  case 'e':
+  case 'f':
+    v = c - 'a' - '9' - 1;
+  case '0':
+  case '1':
+  case '2':
+  case '3':
+  case '4':
+  case '5':
+  case '6':
+  case '7':
+  case '8':
+  case '9':
+    v -= '0';
+    if (v >= base || iptr == MAXIN-1)
+      XBell(display, 0);
+    else
+    {
+      start_number();
+      input_buf[iptr++] = c;
+      input_buf[iptr] = 0;
+      convert_number();
+      show_value();
+    }
+    break;
+  case '.':
+    if (strchr(input_buf, '.'))
+    {
+      XBell(display, 0);
+      break;
+    }
+  case ',':
+    if (iptr == 1 || iptr == MAXIN-1)
+      XBell(display, 0);
+    else
+    {
+      start_number();
+      input_buf[iptr++] = c;
+      input_buf[iptr] = 0;
+      convert_number();
+      show_value();
+    }
+    break;
+
+  case 8:
+    if (iptr == 1)
+      XBell(display, 0);
+    else
+    {
+      input_buf[--iptr] = 0;
+      convert_number();
+      show_value();
+    }
+    break;
+
+  case '_': /* +/- */
+    if (making_number)
+    {
+      if (input_buf[0] == '-')
+       input_buf[0] = ' ';
+      else
+       input_buf[0] = '-';
+      convert_number();
+      show_value();
+    }
+    else
+    {
+      value *= -1.0;
+      saved *= -1.0;
+      show_value();
+    }
+    break;
+
+  case 'D':
+    end_number();
+    base = 10;
+    show_value();
+    break;
+  case 'H':
+    end_number();
+    base = 16;
+    show_value();
+    break;
+  case 'O':
+    end_number();
+    base = 8;
+    show_value();
+    break;
+  case 'B':
+    end_number();
+    base = 2;
+    show_value();
+    break;
+
+  case 'x':
+    c = '*';
+  case '+':
+  case '-':
+  case '*':
+  case '/':
+  case '^':
+  case '&':
+  case '|':
+  case 'S':
+  case '=':
+    end_number();
+    pending_op = c;
+    break;
+
+  case 13:
+  case 10:
+    end_number();
+    break;
+
+  case '~':
+    end_number();
+    value = (double)(~(longlong)value);
+    show_value();
+    break;
+
+  case '<':
+    end_number();
+    value = (double)((longlong)value << 1);
+    show_value();
+    break;
+
+  case '>':
+    end_number();
+    value = (double)((longlong)value >> 1);
+    show_value();
+    break;
+
+  case '[': /* STO */
+    stored = value;
+    break;
+  case ']': /* RCL */
+    value = stored;
+    show_value();
+    making_number = 1;
+    iptr = 1;
+    input_buf[0] = ' ';
+    break;
+  case '}': /* SUM */
+    stored += value;
+    break;
+
+  case 'P': /* click on the display itself */
+    break;
+  }
+}
+
+static char *bmap[] = {
+  "PPPP\033",
+  "DHOB\010",
+  "[]}<>",
+  "Sdef/",
+  "~abc*",
+  "|789-",
+  "&456+",
+  "^123=",
+  "u0._="
+};
+
+#if 0
+void
+copy()
+{
+  XSetSelectionOwner(display, XA_PRIMARY, window, event.xbutton.time);
+}
+
+void
+paste()
+{
+  XConvertSelection(display, XA_PRIMARY, XA_STRING, paste_atom, window,
+                   event.xbutton.time);
+}
+
+void
+complete_paste(char *s, int n)
+{
+  int i;
+  for (i=0; i<n; i++)
+    key(s[i]);
+  
+}
+#endif
+
+void
+button(int b, int x, int y)
+{
+  x = (x-2)/24;
+  if (x < 0) x = 0;
+  if (x > 4) x = 4;
+  y = (y-1)/16;
+  if (y < 0) y = 0;
+  if (y > 8) y = 8;
+
+  if (bmap[y][x] == 27 && b == 3)
+    do_exit(0);
+
+#if 0
+  if (bmap[y][x] == 'P' && b == 1)
+    copy();
+  if (bmap[y][x] == 'P' && b != 1)
+    paste();
+#endif
+
+  key(bmap[y][x]);
+}
diff --git a/rosapps/hcalc/resource.h b/rosapps/hcalc/resource.h
new file mode 100644 (file)
index 0000000..c91643b
--- /dev/null
@@ -0,0 +1,20 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by hcalc.rc
+//
+#define IDS_APPNAME                     1
+#define IDS_DESCRIPTION                 2
+#define IDB_CHARS                       102
+#define IDB_FACE                        103
+#define IDB_BITS                        105
+
+// Next default values for new objects
+// 
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE        106
+#define _APS_NEXT_COMMAND_VALUE         40001
+#define _APS_NEXT_CONTROL_VALUE         1000
+#define _APS_NEXT_SYMED_VALUE           101
+#endif
+#endif