WinMain
By SalimMeghani
- 309 reads
Complete C++ Listing for EZSPREAD.
//**************************************************************************
//* *
//* A Genetic Spreadsheet For MS Visual C++2013 (Express Edition) *
//**************************************************************************/
// By Salim Shahbudeen Meghani, BSc(hons).
// User documentation: Use = for formulas, $ for text
// Cursor keys or scroll bars to move to cells.
// Enter numbers (accuracy to 2 dp only).
// Cell references are entered using lowercase column
// and a numeric row value.
// Scientific notation is supported. Use a capital E and exponent.
/*
Attention : This version is on test with a Reverse Polish Parser & Replicate function.
By Salim Meghani.
*/
// All debug assertion failures have been disabled.
// A note about calculations.
// The way I carry out formulae calculations are as follows:
// 1. First I breakdown a formula to its equivalent numeric formula (string).
// 2. Then, I pass the numeric formula to the reverse polish parser to
// evaluate it.
// An example.
// 1. Suppose a1=1, a2,=2, b1=a1+a2, c1=b1*2.
// Then when evaluating cells, the formula : b1=1+2
// c1=(1+2)*2
// is the breakdown in numerical form of the expression in c1.
// NB: How when I evaluate a formula within a formula, I insert brackets for solving dependency.
//
//
// A note about the Reverse Polish Parser.
//
// It is on test and may not function properly.
// The evaluation of a formula is dependant on size of certain arrays:
// These are:
/*
char texas[65536]; This is the texas line stack.
char calif[65536]; This is the California string
char* newyk=NULL; This is the New York line.
char stak[65536];
char star[65536];
char previous;
char number[50];
char bop;
double num[10000];
Reference : Structured Computer Organization (3rd ed). AS Tanenbaum.
*/
//
#define _CRT_SECURE_NO_DEPRECATE 1
#include "stdafx.h"
#include "resource.h"
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <crtdbg.h>
//
#define MAX_LOADSTRING 100
#define ID_EDIT 1
#define DELIMETER 1
#define VARIABLE 2
#define NUMBER 3
// Declare Global Variables:
WNDPROC wpOrigEditProc;
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
static char szInputStr[2048];
static char szOutputStr[2048];
static char szBuffer[2048];
static char szName[256];
int input=0,
fcol=0,
frow=0,
scol=0,
srow=0,
ecol=0,
erow=0,
dcol=0,
drow=0,
pvalue=0,
column=1,
row=1,
fitem=0,
cval=0,
rval=0,
hredraw=1,
vredraw=1,
credraw=1,
dscroll=0,
scroll=0,
stxpos=1,
endxpos=8,
stypos=1,
endypos=24,
ctxpos=1,
ctypos=1,
curxpos=1,
curypos=1,
olrxpos=1,
olrypos=1,
cvalx=0,
cvaly=0,
c_input=0,
istat=0,
istat2=0,
dorepl=0,
fcat=1,left=0,right=0,up=0,down=0,
setcursor=0,
scrolled=0,
newscroll=0,
preced=1,
repstrx=0,
repstry=0,
rependx=0,
rependy=0,
repfrmx=0,
repfrmy=0,
errflag=0;
char switc; // This is the switch
char texas[65536]; // This is the texas line's stack.
char calif[65536]; // This is the California string
char* newyk=NULL; // This is the New York line.
char star[65536]; // Used to hold a number.
char previous; // The previous operator
char bop;
char dell[65536];
char nwdll[65536];
double num[10000];
char frop;
double answer=0;
double ans=0;
double right1=0;
double left1=0;
double no=0;
char rgt;
char lft;
char blop;
char check;
char op;
char rop;
char lop;
int x=0; int y=0;
int s=0;
int c=0;
int n=0;
int gene = 0;
int g=0;
int notrue=0;
int str=0;
int start=0;
int end=0;
int bracket=0;
int length=0;
double sol=0;
char* form3=NULL;
char* form2=NULL;
int error=0;
char* genetic=NULL;
//
static short cxChar,cyChar,cxClient,cyClient, NUMLINES,NUMCHARS,NUMD,NUMCOLS,MAXROW;
// Define array pointers for numbers and strings and formulae.
// For example a cell is a pointer of type pointer of char.
// If you have an address for cell, and it belongs to an address of type char,
// then it is a two dimensional structure and can be traversed by setting the
// cells address in scell, the same goes for type and stype, numeric and stype .
char* *cell;
char* *scell;
char *type;
char *stype;
char *rtype;
char *srtype;
double* *numeric;
double* *snumeric;
GLOBALHANDLE hGlobalMemory, hGlobalMemory2, hGlobalMemory3, hGlobalMemory4;
double value;
char fch=0;
char sch=0;
static short
nVscrollPos=1,
nHscrollPos=1;
HWND hwndEdit;
// Foward declarations of functions included in this code module:
//int find_optr(int start, char *form);
void clr_str(char *source);
void current_column(char *fch, char *sch, int column);
//void find_brkt(int *error, char *form, int *start, int *end, int *brcket, int *length);
void cleanup(char *output, char *input);
//void eval_brkt(int *error, char *form, int start, int end, int bracket, int length);
//double eval_form(int *error, char *form);
double expr_p(int *error,char *form, int qol, int rw);
int isbracket(char c);
int isstop(char c);
int isoperator(char c);
int moreops(char *c);
void parser(int *error, char *source, char *dest,int qol, int rw, int uniq);
void evaluate_cell(int column, int row, char type, char *szBuffer, char top, char *genetic);
void pushtexas(char switcd); // Pushes a character onto the stack.
void poptexas(int st1); // Pops a character off the stack.
void fpdel(void); // Deletes both a char from the stack and switch.
void putcalif(char switcd); // Puts a character on the California line.
void fperror(int *error); // If there is an unbalanced expression,
void pushstk(double num);
double popstk(void);
void find_brkt(int *error, char *form, int *start, int *end, int *bracket, int *length);
void eval_brkt(int *error, char *form, int *start, int *end, int *bracket, int *length);
void clr_str(char *source);
double eval_form(int *error, char *form);
double eval_parser(char* newyk, int *error);
void clear_vars(void);
void columnwiserepl(HWND hWnd, int repstrx, int repstry, int rependx, int rependy, int repfrmx, int repfrmy, int y, char *nwdll, char *dell);
void rowwiserepl(HWND hwnd, int repstrx, int repstry, int rependx, int rependy, int repfrmx, int repfrmy, int reps, char *nwdll, char *dcell);
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK EditSubclassProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Input(HWND, UINT, WPARAM, LPARAM);
//
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
_CrtSetReportMode(_CRT_ASSERT,0);
//
form2=(char *) calloc((unsigned long) 65535, sizeof(char));
genetic=(char *) calloc((unsigned long) 32767, sizeof(char));
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_SALIMHELLO, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SALIMHELLO);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
//
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SALIMHELLO);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wcex.lpszMenuName = (LPCSTR)IDC_SALIMHELLO;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW | WM_VSCROLL| WM_HSCROLL,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
- Log in to post comments