📄 calc.c
字号:
/**************************************************************************\
*** SCICALC Scientific Calculator for Windows 3.00.12
*** By Kraig Brockschmidt, Microsoft Co-op, Contractor, 1988-1989
*** (c)1989 Microsoft Corporation. All Rights Reserved.
***
*** scimain.c
***
*** Definitions of all globals, WinMain procedure
***
*** Last modification
*** Fri 22-Nov-1996
***
*** -by- Jonathan Parati. [jonpa] 22-Nov-1996
*** Converted Calc from floating point to infinite precision.
*** The new math engine is in ..\ratpak
***
***
*** -by- Amit Chatterjee. [amitc] 05-Jan-1990.
*** Calc did not have a floating point exception signal handler. This
*** would cause CALC to be forced to exit on a FP exception as that's
*** the default.
*** The signal handler is defined in SCIFUNC.C, in WinMain we hook the
*** the signal.
\**************************************************************************/
#include "scicalc.h"
#include "calchelp.h"
#include "signal.h"
#include "unifunc.h"
#include "input.h"
/**************************************************************************/
/*** Global variable declarations and initializations ***/
/**************************************************************************/
int nCalc=0; /* 0=Scientific, 1=Simple. */
BOOL gbUseSep=FALSE; /* display the number with a separator */
ANGLE_TYPE nDecMode=ANGLE_DEG; /* Holder for last used Deg/Rad/Grad mode. */
int nHexMode=0; /* Holder for last used Dword/Word/Byte mode. */
int nTempCom=0, /* Holding place for the last command. */
nParNum=0, /* Number of parenthases. */
nOpCode=0, /* ID value of operation. */
nOp[25], /* Holding array for parenthasis operations. */
nPrecOp[25], /* Holding array for precedence operations. */
nPrecNum=0, /* Current number of precedence ops in holding. */
gcIntDigits; /* Number of digits allowed in the current base */
eNUMOBJ_FMT nFE = FMT_FLOAT; /* Scientific notation conversion flag. */
HWND g_hwndDlg=0, /* Global handle to main window. */
hEdit=0, /* Handle to Clibboard I/O edit control */
hStatBox=0, /* Global handle to statistics box. */
hListBox=0; /* Global handle for statistics list box. */
HMENU g_hHexMenu=NULL; // Global handle for hex menu
HMENU g_hDecMenu=NULL; // Global handle for dec menu
HANDLE hAccel; // Accelerator handle.
HINSTANCE hInst; // Global instance.
BOOL bHyp=FALSE, // Hyperbolic on/off flag.
bInv=FALSE, // Inverse on/off flag.
bError=FALSE, // Error flag.
bColor=TRUE; // Flag indicating if color is available.
HNUMOBJ ghnoNum=NULL, // Currently displayed number used everywhere.
ghnoParNum[25], // Holding array for parenthasis values.
ghnoPrecNum[25], // Holding array for precedence values.
ghnoMem=NULL, // Current memory value.
ghnoLastNum = NULL; // Number before operation (left operand).
LONG nPrecision = 32, // number of digits to use in decimal mode
nDecimalPlaces = 10, // number of decimal places to show
nRadix=10, // the current base (2, 8, 10, or 16)
dwWordBitWidth = 64; // # of bits in currently selected word size
HNUMOBJ g_ahnoChopNumbers[4]; // word size inforcement
BOOL bFarEast; // true if we need to use Far East localization
#ifdef USE_MIRRORING
BOOL g_fLayoutRTL = FALSE;
#endif
extern CALCINPUTOBJ gcio;
extern BOOL gbRecord;
/* DO NOT LOCALIZE THESE STRINGS. */
TCHAR szAppName[10]=TEXT("SciCalc"), /* Application name. */
szDec[5]=TEXT("."), /* Default decimal character */
gszSep[5]=TEXT(","), /* Default thousand seperator */
szBlank[6]=TEXT(""); /* Blank space. */
LPTSTR gpszNum = NULL;
static TCHAR szInitNum[] = TEXT("0"); // text to init gpszNum with
/* END WARNING */
/* rgpsz[] is an array of pointers to strings in a locally allocated */
/* memory block. This block is fixed such that LocalLock does not need */
/* to be called to use a string. */
TCHAR *rgpsz[CSTRINGS];
RECT rcDeg[6];
void ParseCmdLine( LPSTR pszCmdA );
BOOL InitializeWindowClass( HINSTANCE hPrevInstance );
void InitialOneTimeOnlySetup();
void EverythingResettingNumberSetup();
/**************************************************************************/
/*** Main Window Procedure. ***/
/*** ***/
/*** Important functions: ***/
/*** 1) Gets text dimensions and sets conversion units correctly. ***/
/*** ***/
/*** 2) Checks the display device driver for color capability. ***/
/*** If only 2 colors are available (mono, cga), bColor is ***/
/*** set to FALSE, and the background brush is gray. If ***/
/*** color is available, the background brush colors are read ***/
/*** from WIN.INI and the brush is created. ***/
/*** ***/
/*** 3) Window and hidden edit control are created. ***/
/*** ***/
/*** 4) Contains message loop and deletes the brushes used. ***/
/*** ***/
/**************************************************************************/
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
INT nx;
TCHAR *psz;
WORD cch = 0, cchTotal = 0;
HANDLE hMem;
TCHAR szTempString[100];
#ifdef USE_MIRRORING
DWORD dwLayout;
#endif
// A bunch of sanity checks to ensure nobody is violating any of the
// bazillion
// assumptions calc makes about the order of controls. Of course these
// asserts
// wouldn't prevent a really dedicated idiot from messing things up but they
// should help guide a rational person who might not be aware of calc's
// idiosyncrasies.
// Anyone who modifies the resource file should hit these asserts which
// will then
// alert them to the consequences of their actions.
// IDC_0 to IDC_F must be in sequential increasing order
ASSERT( 15 == (IDC_F - IDC_0) );
// Binary operators IDC_AND through IDC_PWR must be in order
ASSERT( (95-86) == (IDC_PWR - IDC_AND) );
// Unary operators IDC_CHOP through IDC_EQU must be in order
ASSERT( (112-96) == (IDC_EQU - IDC_CHOP) );
// menu item id's must be in order
ASSERT( 5 == (IDM_LASTMENU - IDM_FIRSTMENU) );
#ifdef USE_MIRRORING
GetProcessDefaultLayout(&dwLayout);
if (dwLayout & LAYOUT_RTL)
{
SetProcessDefaultLayout(dwLayout & ~LAYOUT_RTL);
g_fLayoutRTL = TRUE;
}
#endif
ParseCmdLine( lpCmdLine );
hInst = hInstance;
if ( !InitializeWindowClass( hPrevInstance ) )
return FALSE;
// Read strings for keys, errors, trig types, etc.
// These will be copied from the resources to local memory. A larger
// than needed block is allocated first and then reallocated once we
// know how much is actually used.
try
{
hMem = LocalAlloc(LPTR, ByteCountOf(CCHSTRINGSMAX));
if (!hMem)
throw;
psz = (TCHAR *)hMem;
for (nx = 0; nx <= CSTRINGS; nx++)
{
ASSERT( (CCHSTRINGSMAX-cchTotal) > LoadString(hInstance, (WORD) IDS_FIRSTKEY + nx, NULL, 0) );
cch = (WORD)(1 + LoadString(hInstance, (WORD) IDS_FIRSTKEY + nx, psz, (int) (CCHSTRINGSMAX-cchTotal)));
cchTotal += cch;
rgpsz[nx] = psz;
psz += cch;
}
if (!LocalReAlloc(hMem, ByteCountOf(cchTotal), LMEM_FIXED))
throw;
}
catch ( ... )
{
if (!LoadString(hInst, IDS_NOMEM, szTempString, CharSizeOf(szTempString)))
{
// only do this if LoadString Fails, means system is really hosed!
lstrcpy(szTempString, TEXT("<Main> Not enough memory."));
}
MessageBox((HWND) NULL, szTempString, NULL, MB_OK | MB_ICONHAND);
return FALSE;
}
// The display in calc isn't really an edit control so we use this edit
// control to simplify cutting to the clipboard
hEdit = CreateWindow( TEXT("EDIT"), TEXT("CalcMsgPumpWnd"),
WS_OVERLAPPED | WS_VISIBLE,
CW_USEDEFAULT,0,CW_USEDEFAULT,0,
NULL, NULL, hInst, NULL );
// This initializes things that only need to be set up once, including a
// call to ratpak so that ratpak can create any constants it needs
InitialOneTimeOnlySetup();
// we store in the win.ini file our desired display mode, Scientific
// or Standard
nCalc = (INT)GetProfileInt(szAppName, TEXT("layout"), 1);
gbUseSep = (INT)GetProfileInt(szAppName, TEXT("UseSep"), 0);
// InitSciCalc creates a dialog based on what the value of nCalc is.
// A handle to the window that is created is stored in g_hwndDlg
InitSciCalc(TRUE);
hAccel = LoadAccelerators(hInst, MAKEINTRESOURCE(IDA_ACCELTABLE));
while (GetMessage(&msg, NULL, 0, 0))
{
if (!hStatBox || !IsDialogMessage(hStatBox, &msg))
{
if ( ((msg.hwnd == g_hwndDlg)||IsChild(g_hwndDlg, msg.hwnd)) && TranslateAccelerator (g_hwndDlg, (HACCEL)hAccel, &msg))
continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
LocalFree(hMem);
return (DWORD)msg.wParam;
}
/**************************************************************************\
*
* Command Line processing routines
*
* History
* 22-Nov-1996 JonPa Wrote it
*
\**************************************************************************/
#define IsWhiteSpace( ch ) ((ch) == TEXT(' ') || (ch) == TEXT('\t'))
#define IsDigit( ch ) ((ch) >= TEXT('0') && (ch) <= TEXT('9'))
LPTSTR TtoL( LPTSTR psz, LONG *pl ) {
LONG l = 0;
while( IsDigit( *psz ) ) {
l = l * 10 + (*psz - TEXT('0'));
psz = CharNext( psz );
}
*pl = l;
return psz;
}
void ParseCmdLine( LPSTR pszCmdA ) {
BOOL fInQuote;
LPTSTR pszCmdT = GetCommandLine();
// parse cmd line
// usage: -p:## -r:## -w:## -e -x -i
// -e, -x, and -i currently do nothing.
// Skip app name
while( *pszCmdT && IsWhiteSpace( *pszCmdT )) {
pszCmdT = CharNext( pszCmdT );
}
fInQuote = FALSE;
while( *pszCmdT && (fInQuote || !IsWhiteSpace(*pszCmdT)) ) {
if (*pszCmdT == TEXT('\"'))
fInQuote = !fInQuote;
pszCmdT = CharNext( pszCmdT );
}
while( *pszCmdT )
{
switch( *pszCmdT )
{
case TEXT('p'):
case TEXT('P'):
// -p:## precision
pszCmdT = CharNext(pszCmdT);
// Skip ':' and white space
while( *pszCmdT && (*pszCmdT == TEXT(':') || IsWhiteSpace(*pszCmdT)) ) {
pszCmdT = CharNext(pszCmdT);
}
pszCmdT = TtoL( pszCmdT, &nPrecision );
// a percision > C_NUM_MAX_DIGITS will allow a string too long for it's buffer
if ( nPrecision > C_NUM_MAX_DIGITS)
{
ASSERT( nPrecision <= C_NUM_MAX_DIGITS );
nPrecision = C_NUM_MAX_DIGITS;
}
// NOTE: this code assumes there MUST be a space after the number
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -