/*
Auto:		smake MCalc
*/


/* $Revision Header built automatically *************** (do not edit) ************
**
** © Copyright by GuntherSoft
**
** File             : SnakeSYS:CPrgs/MUICalc/MCalc.c
** Created on       : Saturday, 02.10.93 02:12:50
** Created by       : Kai Iske
** Current revision : V1.0
**
**
** Purpose
** -------
**   - This is a quite flexible, powerful Calculator made for all
**     those of you, who like to calc around ;) Even for
**     programmers...
**
** Revision V1.0
** --------------
** created on Saturday, 02.10.93 02:12:50  by  Kai Iske.   LogMessage :
**     --- Initial release ---
**
*********************************************************************************/



/**********************************************************************/
/*                    Externals to Scanner/Parser                     */
/**********************************************************************/
extern	UWORD		PCharRead;
extern	UWORD		PColumn;
extern	UWORD		PError;
extern	UWORD		NonDouble;
extern	int		yynerrs;
extern	int		yychar;
extern	int		yy_init;
extern	int		yy_start;
extern	FILE		*yyin, *yyout;
extern	void		*yy_current_buffer;


extern UWORD		RXIntType;
extern UWORD		RXIntBase;
extern UWORD		RXIntSign;
extern UWORD		RXIntAngle;


/**********************************************************************/
/*    Aehm, SAS 6.50 seams to open up a window just as it likes ;)    */
/**********************************************************************/
char __stdiowin[] = "NIL:";



/**********************************************************************/
/*                 External variables of ARexx module                 */
/**********************************************************************/
extern struct MUI_Command	RXCommands[];



/**********************************************************************/
/*                Special macro for setting up a list                 */
/**********************************************************************/
#define		NewList(x)	{\
x.lh_TailPred	= (struct Node *)&x;\
x.lh_Tail	= NULL;\
x.lh_Head	= (struct Node *)&x.lh_Tail;\
}


/**********************************************************************/
/*                      Routines for that module                      */
/**********************************************************************/
static BOOL OpenLibs(void);
static void CloseLibs(void);
static void SetMainWinCycle(void);
static BOOL OpenMainWin(void);
static void CloseMainWin(void);
static ULONG	__saveds __asm InsertFunc(register __a0 struct Hook *MyHook, register __a2 APTR Obj, register __a1 APTR *Data);
static ULONG	__saveds __asm DispConstructFunc(register __a0 struct Hook *MyHook, register __a2 APTR MemPool, register __a1 struct ListStruct *Data);
static ULONG	__saveds __asm StdDestructFunc(register __a0 struct Hook *MyHook, register __a2 APTR MemPool, register __a1 struct ListStruct *Data);
static ULONG	__saveds __asm DispViewFunc(register __a0 struct Hook *MyHook, register __a2 char **array, register __a1 struct ListStruct *Data);
static ULONG	__saveds __asm HistoryConstructFunc(register __a0 struct Hook *MyHook, register __a2 char **array, register __a1 struct DoubleNode *Data);
static ULONG	__saveds __asm DeviationDispFunc(register __a0 struct Hook *MyHook, register __a2 char **array, register __a1 struct DoubleNode *Data);
static ULONG	__saveds __asm RegressionDispFunc(register __a0 struct Hook *MyHook, register __a2 char **array, register __a1 struct DoubleNode *Data);
static ULONG	__saveds __asm ConstConstructFunc(register __a0 struct Hook *MyHook, register __a2 char **array, register __a1 struct ConstNode *Data);
static ULONG	__saveds __asm ConstDispFunc(register __a0 struct Hook *MyHook, register __a2 char **array, register __a1 struct ConstNode *Data);
static LONG	__saveds __asm ConstCompFunc(register __a1 struct ConstNode *Data1, register __a2 struct ConstNode *Data2);
static void InsertText(char *NewText);
static void WriteClip(char *Entry);
static void HandleInputs(void);




/**********************************************************************/
/*                           Library-Bases                            */
/**********************************************************************/
struct	ExecBase	*SysBase;

struct	IntuitionBase	*IntuitionBase		= NULL;
struct	GfxBase		*GfxBase		= NULL;
struct	Library		*UtilityBase		= NULL;
struct	Library		*IconBase		= NULL;
struct	Library		*MUIMasterBase		= NULL;
struct	Library		*MathIeeeDoubBasBase	= NULL;
struct	Library		*MathIeeeDoubTransBase	= NULL;
struct	Library		*IFFParseBase		= NULL;




/**********************************************************************/
/*                            The Objects                             */
/**********************************************************************/
static	struct	DiskObject	*DObject	= NULL;
APTR		AppObject			= NULL;		// Is referenced through ARexx module
static	APTR	MainWindow;
static	APTR	InOutGroup;
static	APTR	InputGroup;
APTR		InputString;					// Is referenced through ARexx module
static	APTR	OutputGroup;
APTR		OutputBox;					// Is referenced through ARexx module
static	APTR	RegObj;
static	APTR	InGads[116];
static	APTR	ExeObj;
static	APTR	ClrObj;
static	APTR	AllClrObj;

static	APTR	MainGroup;
static	APTR	FuncGroup;
static	APTR	InGroup;

static	APTR	PrefsWindow;
static	APTR	InOutObj;
static	APTR	DFuncObj;
static	APTR	DInObj;
static	APTR	TypeObj;
static	APTR	SizeObj;
static	APTR	SignObj;
static	APTR	AngleObj;
static	APTR	LinesObj;
static	APTR	LookObj;
static	APTR	ClearInObj;
static	APTR	FlushObj;
static	APTR	StdWinObj;
static	APTR	LinWinObj;
static	APTR	ConstWinObj;
static	APTR	ClipObj;
static	APTR	OkObj;
static	APTR	SaveObj;
static	APTR	CancelObj;

static	APTR	StdHistoryWindow;
static	APTR	StdHistoryObj;

static	APTR	LinHistoryWindow;
static	APTR	LinHistoryObj;

static	APTR	ConstantsWindow;
static	APTR	ConstantsObj;






/**********************************************************************/
/*                 Strings for Functions Cycle-Gadget                 */
/**********************************************************************/
static const char *FunctionEntries[] =
{
	"Math",
	"Programmer",
	"Memory",
	"Std. deviation",
	"Lin. regression",
	NULL
};






/**********************************************************************/
/*                      Strings for Prefs-Cycles                      */
/**********************************************************************/
static const char *InOutLookEntries[] =
{
	"Input then Output",
	"Output then Input",
	NULL
};

static const char *TypeEntries[] =
{
	"Decimal",
	"HexDecimal",
	"Octal",
	"Binary",
	NULL
};

static const char *SizeEntries[] =
{
	"8-Bit",
	"16-Bit",
	"32-Bit",
	NULL
};

static const char *SignEntries[] =
{
	"Signed",
	"Unsigned",
	NULL
};

static const char *AngleEntries[] =
{
	"Radians",
	"Degree",
	"Grads",
	NULL
};

static const char *LookEntries[] =
{
	"Input & Output",
	"Output & Input",
	"Input",
	"Output",
	NULL
};


static const char *LookTemplates[] =
{
	"COL=0 DELTA=12 P=\033r MAW=100 MIW=0, COL=1 DELTA=12 P=\033r MAW=-1 MIW=-1",
	"COL=1 DELTA=12 P=\033r MAW=-1 MIW=-1, COL=0 DELTA=12 P=\033r MAW=100 MIW=0",
	"COL=0 DELTA=12 P=\033r MIW=100",
	"COL=1 DELTA=12 P=\033r MIW=100"
};



/**********************************************************************/
/*                   Chars/String for window title                    */
/**********************************************************************/
static const char TypeChar[] =
{
	'D',
	'H',
	'O',
	'B'
};

static const char *BaseStr[] =
{
	"8",
	"16",
	"32"
};


static const char SignChar[] =
{
	'S',
	'U',
};


static const char *AngleStr[] =
{
	"RAD",
	"DEG",
	"GRA"
};




/**********************************************************************/
/*                          Menu-Definition                           */
/**********************************************************************/
static struct	NewMenu MainMenuDef[] =
{
	NM_TITLE, "Project", NULL, 0, NULL, NULL,
	NM_ITEM, "Preferences...", "P", 0, NULL, (APTR)ID_PREFS,
	NM_ITEM, NM_BARLABEL, NULL, 0, NULL, NULL,
	NM_ITEM, "About...", "?", 0, NULL, (APTR)ID_ABOUT,
	NM_ITEM, NM_BARLABEL, NULL, 0, NULL, NULL,
	NM_ITEM, "Quit", "Q", 0, NULL, (APTR)ID_QUIT,

	NM_TITLE, "Edit", NULL, 0, NULL, NULL,
	NM_ITEM, "Clear", "X", 0, NULL, (APTR)ID_CLEAR,
	NM_ITEM, "All Clear", "Y", 0, NULL, (APTR)ID_ALLCLEAR,

	NM_TITLE, "History", NULL, 0, NULL, NULL,
	NM_ITEM, "Pick left entry", "L", 0, NULL, (APTR)ID_PICKLEFT,
	NM_ITEM, "Pick right entry", "R", 0, NULL, (APTR)ID_PICKRIGHT,
	NM_ITEM, NM_BARLABEL, NULL, 0, NULL, NULL,
	NM_ITEM, "Copy left entry", "F", 0, NULL, (APTR)ID_CLIPCUTLEFT,
	NM_ITEM, "Copy right entry", "C", 0, NULL, (APTR)ID_CLIPCUTRIGHT,
	NM_ITEM, NM_BARLABEL, NULL, 0, NULL, NULL,
	NM_ITEM, "Delete entry", "K", 0, NULL, (APTR)ID_DELHISTORY,

	NM_TITLE, "Display Bases", NULL, 0, NULL, NULL,
	NM_ITEM, "Decimal", "D", CHECKIT|MENUTOGGLE, 14, (APTR)ID_DECIMAL,
	NM_ITEM, "Hexadecimal", "H", CHECKIT|MENUTOGGLE, 13, (APTR)ID_HEXDECIMAL,
	NM_ITEM, "Octal", "O", CHECKIT|MENUTOGGLE, 11, (APTR)ID_OCTAL,
	NM_ITEM, "Binary", "B", CHECKIT|MENUTOGGLE, 7, (APTR)ID_BINARY,

	NM_TITLE, "Size", NULL, 0, NULL, NULL,
	NM_ITEM, "8 Bit", "8", CHECKIT|MENUTOGGLE, 6, (APTR)ID_8BIT,
	NM_ITEM, "16 Bit", "16", CHECKIT|MENUTOGGLE, 5, (APTR)ID_16BIT,
	NM_ITEM, "32 Bit", "32", CHECKIT|MENUTOGGLE, 3, (APTR)ID_32BIT,

	NM_TITLE, "Sign", NULL, 0, NULL, NULL,
	NM_ITEM, "Signed", "S", CHECKIT|MENUTOGGLE, 2, (APTR)ID_SIGNED,
	NM_ITEM, "Unsigned", "U", CHECKIT|MENUTOGGLE, 1, (APTR)ID_UNSIGNED,

	NM_TITLE, "Angle", NULL, 0, NULL, NULL,
	NM_ITEM, "Radians", "A", CHECKIT|MENUTOGGLE, 6, (APTR)ID_RAD,
	NM_ITEM, "Degree", "E", CHECKIT|MENUTOGGLE, 5, (APTR)ID_DEG,
	NM_ITEM, "Grads", "G", CHECKIT|MENUTOGGLE, 3, (APTR)ID_GRAD,

	NM_TITLE, "Windows", NULL, 0, NULL, NULL,
	NM_ITEM, "Std.Deviation", "T", CHECKIT|MENUTOGGLE, 0, (APTR)ID_STDHISTORY,
	NM_ITEM, "Lin.Regression", "I", CHECKIT|MENUTOGGLE, 0, (APTR)ID_LINHISTORY,
	NM_ITEM, "Constants", "N", CHECKIT|MENUTOGGLE, 0, (APTR)ID_CONSTANTS,

	NM_END, NULL, NULL, 0, NULL, NULL
};





/**********************************************************************/
/*                       Some global Variables                        */
/**********************************************************************/
static struct	Hook	InsertHook = 			// This is our hook for the InputGadgets
{
	{NULL},
	(APTR)InsertFunc,
	NULL,
	NULL
};


static struct	Hook	DispConstructHook =		// Hooks for multi-column display
{
	{NULL},
	(APTR)DispConstructFunc,
	NULL,
	NULL
};

static struct Hook	StdDestructHook =
{
	{NULL},
	(APTR)StdDestructFunc,
	NULL,
	NULL
};

static struct Hook	DispViewHook =
{
	{NULL},
	(APTR)DispViewFunc,
	NULL,
	NULL
};

static struct	Hook	HistoryConstructHook =
{
	{NULL},
	(APTR)HistoryConstructFunc,
	NULL,
	NULL
};

static struct Hook	DeviationDispHook =
{
	{NULL},
	(APTR)DeviationDispFunc,
	NULL,
	NULL
};

static struct Hook	RegressionDispHook =
{
	{NULL},
	(APTR)RegressionDispFunc,
	NULL,
	NULL
};

static struct	Hook	ConstConstructHook =
{
	{NULL},
	(APTR)ConstConstructFunc,
	NULL,
	NULL
};

static struct Hook	ConstDispHook =
{
	{NULL},
	(APTR)ConstDispFunc,
	NULL,
	NULL
};

static struct Hook	ConstCompHook =
{
	{NULL},
	(APTR)ConstCompFunc,
	NULL,
	NULL
};




/**********************************************************************/
/*                        Constant definitions                        */
/**********************************************************************/
static	char	*ConstNames[] =
{
	"rest mass of proton",
	"Faraday constant",
	"Bohr radius",
	"speed of light",
	"Planck constant",
	"gravitational constant",
	"elementary charge",
	"rest mass of electron",
	"atomic mass unit",
	"Avogadro constant",
	"Boltzmann constant",
	"molar volume",
	"acceleration of free fall",
	"molar gas constant",
	"permittivity of vacuum",
	"permeability of vacuum",
	"m. moment of proton",
	"m. moment of electron",
	"nuclear magneton",
	"Bohr magneton",
	"h/2 pi",
	"fine-structure constant",
	"electron radius",
	"rest mass of neutron",
	"gyromagnetic coefficient p",
	"Compton wavelenght p",
	"Compton wavelength n",
	"Rydberg constant",
	"first radiation constant",
	"second radiation constant",
	"Stefan Boltzmann constant",
	"fluxoid quantum"
};

static	char	*ConstValues[] =
{
	"1.6726485e-27",
	"9.648456e4",
	"5.2917706e-11",
	"299792458",
	"6.626176e-34",
	"6.672e-11",
	"1.6021892e-19",
	"9.109534e-31",
	"1.6605655e-27",
	"6.022045e23",
	"1.380662e-23",
	"0.02241383",
	"9.80665",
	"8.31441",
	"8.854187818e-12",
	"1.256637061e-6",
	"1.41060761e-26",
	"9.2847701e-24",
	"5.050824e-27",
	"9.274078e-24",
	"1.0545887e-34",
	"7.2973506e-3",
	"2.817938e-15",
	"1.6749543e-27",
	"2.6751987e8",
	"1.3214099e-15",
	"1.3195909e-15",
	"1.097373177e7",
	"3.741832e-16",
	"1.438786e-2",
	"5.67032e-8",
	"2.0678506e-15"
};

static char	*ConstNotation[] =
{
	"kg",
	"C/mol",
	"m",
	"m/s",
	"J*s",
	"Nm²/kg²",
	"C",
	"kg",
	"kg",
	"1/mol",
	"J/K",
	"m³/mol",
	"m/s²",
	"J/(mol*K)",
	"F/m",
	"H/m",
	"A*m²",
	"A*m²",
	"A*m²",
	"A*m²",
	"J*s",
	"-",
	"m",
	"kg",
	"A*m²/(J*s)",
	"m",
	"m",
	"1/m",
	"W*m²",
	"m*K",
	"W*(K^4)/m²",
	"Wb",
};




/**********************************************************************/
/*                      Parser related variables                      */
/**********************************************************************/
char	*ParseInput;				// This has to be global, so that the scanner my find it ;)
APTR	ParsePool;				// Pointer to parser`s memory pool
char	Title[80];				// Title of main window


double	Value,					// Value being displayed and memories
	IMem,
	JMem,
	KMem,
	LMem,
	MMem,
	NMem,
	OMem,
	PMem,
	QMem,
	RMem,
	SMem,
	TMem,
	UMem,
	VMem,
	WMem,
	XMem,
	YMem,
	ZMem;

struct	List		StandardList;
struct	List		LinearList;

UWORD	InOutLook	= 0;				// How to order the String and ListView gadgets
UWORD	NoFuncs		= FALSE;			// Display function gadgets ???
UWORD	NoInput		= FALSE;			// Display input gadgets ???
UWORD	IntType		= ID_DECIMAL;			// Current output format
UWORD	IntBase		= ID_32BIT;			// Current conversion base
UWORD	IntSign		= ID_SIGNED;			// Current ouput sign-format
UWORD	IntAngle	= ID_RAD;			// Current angle format
UWORD	HistLines	= 32;				// Default number of history lines
UWORD	ListLook	= 0;				// Look of ListView
UWORD	FlushOnExit	= FALSE;			// Flush memory on exit ???
UWORD	ClearInput	= FALSE;			// Clear input string after RETURN/EXEC ???
UWORD	OpenStdWin	= FALSE;			// Open the standard deviation window?
UWORD	OpenLinWin	= FALSE;			// Open the linear regression window?
UWORD	OpenConstWin	= FALSE;			// Open the constants window?
UWORD	ClipUnit	= 0;				// Number of clipboard to use
UWORD	ContainsUnDec;					// This is to signal the main program,
							// that non-decimal digits have been used





/**********************************************************************/
/*                        Do the wild thing ;)                        */
/**********************************************************************/
ULONG __saveds main(void)
{
	struct	WBStartup	*WBMsg	= NULL;
	struct	Process		*MyProc;
	APTR			FlushPtr;
	int			i;

		// Get SysBase

	SysBase		= *((struct ExecBase **)0x4L);

	MyProc		= (struct Process *)SysBase->ThisTask;

		// Launched from WB

	if(!MyProc->pr_CLI)
	{
		WaitPort(&MyProc->pr_MsgPort);
		WBMsg	= (struct WBStartup *)GetMsg(&MyProc->pr_MsgPort);
	}


		// Try to open libs

	if(OpenLibs())
	{
			// Init lists for standard and linear regression

		NewList(StandardList);
		NewList(LinearList);

			// Try to open the main window

		if(OpenMainWin())
		{
				// Display "0" in desired format

			FormatOutput(FALSE);

				// Handle incoming inputs

			HandleInputs();
		}
		CloseMainWin();

			// Free lists

		FreeList(&StandardList);
		FreeList(&LinearList);
	}
	CloseLibs();


		// Should memory be flushed ???

	if(FlushOnExit)
	{
		for(i = 0; i < 10; i++)
		{
			if((FlushPtr = AllocMem(0x1DCD6500, MEMF_PUBLIC)))
				FreeMem(FlushPtr, 0x1DCD6500);
		}
	}

		// Cleanup

	if(WBMsg)
	{
		Forbid();
		ReplyMsg((struct Message *)WBMsg);
	}
	else
		return(0);
}




/**********************************************************************/
/*                      Open-Up needed libraries                      */
/**********************************************************************/
static BOOL OpenLibs(void)
{
	if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37)))
		return(FALSE);

	if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 37)))
		return(FALSE);

	if(!(UtilityBase = OpenLibrary("utility.library", 37)))
		return(FALSE);

	if(!(IconBase = OpenLibrary("icon.library", 37)))
		return(FALSE);

	if(!(MathIeeeDoubBasBase = OpenLibrary("mathieeedoubbas.library", 37)))
		return(FALSE);

	if(!(MathIeeeDoubTransBase = OpenLibrary("mathieeedoubtrans.library", 37)))
		return(FALSE);

	if(!(IFFParseBase = OpenLibrary("iffparse.library", 37)))
		return(FALSE);

	if(!(MUIMasterBase = OpenLibrary("muimaster.library", 7)))
		return(FALSE);

	return(TRUE);
}







/**********************************************************************/
/*                          Close used libs                           */
/**********************************************************************/
static void CloseLibs(void)
{
	if(MUIMasterBase)
		CloseLibrary(MUIMasterBase);

	if(IFFParseBase)
		CloseLibrary(IFFParseBase);

	if(MathIeeeDoubTransBase)
		CloseLibrary(MathIeeeDoubTransBase);

	if(MathIeeeDoubBasBase)
		CloseLibrary(MathIeeeDoubBasBase);

	if(IconBase)
		CloseLibrary(IconBase);

	if(UtilityBase)
		CloseLibrary(UtilityBase);

	if(GfxBase)
		CloseLibrary((struct Library *)GfxBase);

	if(IntuitionBase)
		CloseLibrary((struct Library *)IntuitionBase);
}






/**********************************************************************/
/*                  Set Cycle Chain for main window                   */
/**********************************************************************/
static void SetMainWinCycle(void)
{
	APTR	FirstCycle,
		LastCycle;
	int	GadNum;

	if(!InOutLook)
	{
		FirstCycle	= InputString;
		LastCycle	= OutputBox;
	}
	else
	{
		FirstCycle	= OutputBox;
		LastCycle	= InputString;
	}
		// Set Cycle chanin

	GadNum	= 0;
	DoMethod(MainWindow, MUIM_Window_SetCycleChain,
		FirstCycle,
		LastCycle,
		RegObj,
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		InGads[GadNum++],
		ClrObj,
		AllClrObj,
		ExeObj,
	NULL);
}




/**********************************************************************/
/*                    Open the Calculator`s Window                    */
/**********************************************************************/
static BOOL OpenMainWin(void)
{
	ULONG	Dummy, GadNum = 0;


		// The input String Requester

	InputGroup	= VGroup, Child,
		InputString	=	StringObject, StringFrame,
						MUIA_String_Contents,	"0",
						MUIA_String_MaxLen,	256,
						MUIA_String_Format,	MUIV_String_Format_Right,
						MUIA_String_BufferPos,	1,
					End,
	End;


		// The Output Box

	OutputGroup	= VGroup, Child,
		OutputBox	=	ListviewObject,
						MUIA_Listview_Input,		TRUE,
						MUIA_Listview_List,	ListObject, InputListFrame,
							MUIA_Background,		MUII_ListBack,
							MUIA_List_Format,		"COL=0 DELTA=8 P=\033r MAW=50 MIW=10, COL=1 DELTA=8 P=\033r MAW=50 MIW=10",
							MUIA_List_ConstructHook,	&DispConstructHook,
							MUIA_List_DestructHook,		&StdDestructHook,
							MUIA_List_DisplayHook,		&DispViewHook,
						End,
					End,
	End;


		// Create the Application window

	AppObject	= ApplicationObject,
				MUIA_Application_Title,		"MCalc",
				MUIA_Application_Version,	MUIVERS,
				MUIA_Application_Copyright,	"©1993/94 Kai Iske",
				MUIA_Application_Author,	"Kai Iske",
				MUIA_Application_Description,	"Quite powerful calculator, GiftWare",
				MUIA_Application_Base,		"MCalc",
				MUIA_Application_SingleTask,	TRUE,
				MUIA_Application_DiskObject,	DObject = GetDiskObjectNew("PROGDIR:MCalc"),
				MUIA_Application_Commands,	&RXCommands[0],
				MUIA_Application_HelpFile,	"MCalc.guide",

			// Now head for the main window

		SubWindow, MainWindow =	WindowObject,
						MUIA_Window_Title,	"MUIProCalc "REVISION" - "REVDATE,
						MUIA_Window_ID,		'MPCM',
						MUIA_Window_SizeGadget,	TRUE,
						MUIA_Window_Menu,	&MainMenuDef,
						MUIA_HelpNode,		NODE_MAIN,

				// Do the gadgets

			WindowContents,
			MainGroup = VGroup,

					// First of all the Input and Output Group

				Child,
				InOutGroup = VGroup, GroupFrame,
					MUIA_HelpNode,	NODE_INOUTPUT,
				End, // Input Area

					// Now check for the Function Gadgets

				Child,

				FuncGroup = VGroup, GroupFrame,
					MUIA_HelpNode, NODE_FUNCTIONS,


						// Function Buttons

					Child, RegObj = RegisterObject,
							MUIA_Register_Frame,	TRUE,
							MUIA_Register_Titles,	FunctionEntries,
							MUIA_Weight,		0,

						Child, ColGroup(8), MUIA_Group_SameWidth, TRUE,

								// First row of Functions

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Sin",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Cos",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Tan",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"ASin",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"ACos",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"ATan",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"SinH",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"CosH",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"TanH",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Log",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Log10",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Exp",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"^",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Pi",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Sqrt",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Abs",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Cot",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"e",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"%",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"%ch",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"%t",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"(n k)",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"YRoot",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Rez",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,
						End, // First Button Bank

							// Second Button-Bank

						Child, ColGroup(6), MUIA_Group_SameWidth, TRUE,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Mod",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"And",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Or",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"XOr",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Not",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Asl",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Asr",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Lsl",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Lsr",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Rol",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Ror",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,
							Child, HSpace(0),
						End, // Second Button Bank


							// Third Button-Bank

						Child, ColGroup(6), MUIA_Group_SameWidth, TRUE,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"I",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"J",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"K",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"L",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"M",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"N",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"O",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"P",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Q",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"R",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"S",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"T",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"U",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"V",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"W",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"X",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Y",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"Z",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,
						End, // Third Button Bank


							// Fourth Button-Bank

						Child, ColGroup(7), MUIA_Group_SameWidth, TRUE, MUIA_HelpNode, NODE_STDDEVIATION,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"SD",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"SD_AVE",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"SD_PDEV",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"SD_SDEV",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"SD_NUM",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"SD_QSUM",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"SD_SUM",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,
						End, // Fourth Button bank


							// Fith Button-Bank

						Child, ColGroup(7), MUIA_Group_SameWidth, TRUE, MUIA_HelpNode, NODE_LINREGRESSION,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_XAVE",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_YAVE",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_XPDEV",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_YPDEV",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_XSDEV",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_YSDEV",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_XNUM",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_YNUM",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_XQSUM",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_YQSUM",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_XSUM",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_YSUM",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_XYSUM",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_ALPHA",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_BETA",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_ASSX",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_ASSY",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_CORR",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_CCORR",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,

							Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
												MUIA_Text_Contents,	"LR_COVAR",
												MUIA_Text_PreParse,	"\33c",
												MUIA_Background,	MUII_ButtonBack,
												MUIA_InputMode,		MUIV_InputMode_RelVerify,
											End,
						End, // Fourth Button bank
					End, // Page-Group
				End, // Second Area

				Child,
				InGroup = VGroup, GroupFrame,
					MUIA_HelpNode,	NODE_INPUTS,

					Child, ColGroup(7), MUIA_Group_SameWidth, TRUE,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"A",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"B",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"C",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"D",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"E",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"$",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
											MUIA_Text_Contents,	"0x",
											MUIA_Text_PreParse,	"\33c",
											MUIA_Background,	MUII_ButtonBack,
											MUIA_InputMode,		MUIV_InputMode_RelVerify,
										End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"7",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"8",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"9",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"/",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"F",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"\\",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	=	TextObject, ButtonFrame,
											MUIA_Text_Contents,	"!",
											MUIA_Text_PreParse,	"\33c",
											MUIA_Background,	MUII_ButtonBack,
											MUIA_InputMode,		MUIV_InputMode_RelVerify,
										End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"4",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"5",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"6",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"*",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, HSpace(0),

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"&",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, ClrObj		=	TextObject, ButtonFrame,
											MUIA_Text_Contents,	"CLR",
											MUIA_Text_PreParse,	"\33c",
											MUIA_Background,	MUII_ButtonBack,
											MUIA_InputMode,		MUIV_InputMode_RelVerify,
										End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"1",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"2",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"3",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"-",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"EXG",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"(",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, AllClrObj	=	TextObject, ButtonFrame,
											MUIA_Text_Contents,	"ACLR",
											MUIA_Text_PreParse,	"\33c",
											MUIA_Background,	MUII_ButtonBack,
											MUIA_InputMode,		MUIV_InputMode_RelVerify,
										End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"0",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	".",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"=",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, InGads[GadNum++]	= TextObject, ButtonFrame,
										MUIA_Text_Contents,	"+",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, HSpace(0),

						Child, InGads[GadNum++]=	TextObject, ButtonFrame,
										MUIA_Text_Contents,	")",
										MUIA_Text_PreParse,	"\33c",
										MUIA_Background,	MUII_ButtonBack,
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

						Child, ExeObj		=	TextObject, ButtonFrame,
											MUIA_Text_Contents,	"Exec",
											MUIA_Text_PreParse,	"\33c",
											MUIA_Background,	MUII_ButtonBack,
											MUIA_InputMode,		MUIV_InputMode_RelVerify,
										End,
					End, // Input gadgets
				End, // Third input area
			End, // VGroup
		End, // Main window


			// Now generate the Prefs window

		SubWindow, PrefsWindow = WindowObject,
						MUIA_Window_Title,	"MUIProCalc Preferences",
						MUIA_Window_ID,		'MPCP',
						MUIA_Window_SizeGadget,	TRUE,
						MUIA_Window_NoMenus,	TRUE,
						MUIA_HelpNode,		NODE_PREFS,

			WindowContents, VGroup,

				Child, ColGroup(2),
					Child, VGroup, GroupFrameT("Window layout"),
						MUIA_HelpNode,	NODE_LAYOUT,

						Child, VSpace(0),
						Child, HGroup,

								// Display functions gadget

							Child, HGroup,
								Child, TextObject,
									MUIA_Text_PreParse,	"\033r",
									MUIA_Text_Contents,	"No Functions",
									MUIA_Text_HiChar,	'f',
								End,
								Child, HSpace(1),
								Child, DFuncObj	=	ImageObject, ImageButtonFrame,
												MUIA_InputMode,		MUIV_InputMode_Toggle,
												MUIA_Image_Spec,	MUII_CheckMark,
												MUIA_Image_FreeVert,	TRUE,
												MUIA_Selected,		NoFuncs,
												MUIA_Background,	MUII_ButtonBack,
												MUIA_ShowSelState,	FALSE,
												MUIA_ControlChar,	'f',
												MUIA_ExportID,		'FUNC',
											End,
							End,

								// Display Inputs gadget

							Child, HGroup,
								Child, TextObject,
									MUIA_Text_PreParse,	"\033r",
									MUIA_Text_Contents,	"No Input",
									MUIA_Text_HiChar,	'n',
								End,
								Child, HSpace(1),
								Child, DInObj	=	ImageObject, ImageButtonFrame,
												MUIA_InputMode,		MUIV_InputMode_Toggle,
												MUIA_Image_Spec,	MUII_CheckMark,
												MUIA_Image_FreeVert,	TRUE,
												MUIA_Selected,		NoInput,
												MUIA_Background,	MUII_ButtonBack,
												MUIA_ShowSelState,	FALSE,
												MUIA_ControlChar,	'n',
												MUIA_ExportID,		'INPU',
											End,
							End,
						End,

							// Cycle Gadget for default type

						Child, ColGroup(2),
							Child, KeyLabel1("In/Out Order", 'O'),
							Child, InOutObj	=	CycleObject, ButtonFrame,
											MUIA_Cycle_Active,	InOutLook,
											MUIA_Cycle_Entries,	InOutLookEntries,
											MUIA_ControlChar,	'o',
											MUIA_ExportID,		'ORDR',
										End,
						End,

						Child, VSpace(0),

					End, // Layout gadgets

					Child, VGroup, GroupFrameT("Output settings"),
						MUIA_HelpNode,	NODE_OUTPUT,

						Child, VSpace(0),

							// Cycle Gadget for default type

						Child, ColGroup(2),
							Child, KeyLabel1("Base:", 'B'),
							Child, TypeObj	=	CycleObject, ButtonFrame,
											MUIA_Cycle_Active,	IntType - ID_DECIMAL,
											MUIA_Cycle_Entries,	TypeEntries,
											MUIA_ControlChar,	'b',
											MUIA_ExportID,		'TYPE',
										End,

							Child, KeyLabel1("Size:", 'z'),
							Child, SizeObj	=	CycleObject, ButtonFrame,
											MUIA_Cycle_Active,	IntBase - ID_8BIT,
											MUIA_Cycle_Entries,	SizeEntries,
											MUIA_ControlChar,	'z',
											MUIA_ExportID,		'SIZE',
										End,

							Child, KeyLabel1("Sign:", 'i'),
							Child, SignObj	=	CycleObject, ButtonFrame,
											MUIA_Cycle_Active,	IntSign - ID_SIGNED,
											MUIA_Cycle_Entries,	SignEntries,
											MUIA_ControlChar,	'i',
											MUIA_ExportID,		'SIGN',
										End,

							Child, KeyLabel1("Angle:", 'a'),
							Child, AngleObj	=	CycleObject, ButtonFrame,
											MUIA_Cycle_Active,	IntAngle - ID_RAD,
											MUIA_Cycle_Entries,	AngleEntries,
											MUIA_ControlChar,	'a',
											MUIA_ExportID,		'ANGL',
										End,
						End, // Cycle gadgets

						Child, VSpace(0),

					End, // Output settings



					Child, VGroup, GroupFrameT("History settings"),
						MUIA_HelpNode,	NODE_HISTORY,

						Child, VSpace(0),

							// Number of lines to buffer

						Child, ColGroup(2),
							Child, KeyLabel1("Lines:", 'L'),
							Child, LinesObj	=	SliderObject,
											MUIA_Slider_Level,	HistLines,
											MUIA_Slider_Min,	1,
											MUIA_Slider_Max,	512,
											MUIA_ControlChar,	'l',
											MUIA_ExportID,		'LINE',
										End,


							Child, KeyLabel1("Entries:", 'E'),
							Child, LookObj	=	CycleObject, ButtonFrame,
											MUIA_Cycle_Active,	ListLook,
											MUIA_Cycle_Entries,	LookEntries,
											MUIA_ControlChar,	'e',
											MUIA_ExportID,		'LOOK',
										End,
						End, // History col group

							// Number of clipboard to use

						Child, ColGroup(2),
							Child, KeyLabel1("ClipUnit:", 'P'),
							Child, ClipObj	=	SliderObject,
											MUIA_Slider_Level,	ClipUnit,
											MUIA_Slider_Min,	0,
											MUIA_Slider_Max,	255,
											MUIA_ControlChar,	'p',
											MUIA_ExportID,		'CLIP',
										End,
						End, // Clipboard group

						Child, VSpace(0),

					End, // History settings


					Child, VGroup, GroupFrameT("Misc"),
						MUIA_HelpNode,	NODE_MISC,

						Child, VSpace(0),

							// Clear input checkbox

						Child, HGroup,
							Child, TextObject,
								MUIA_Text_PreParse,	"\033r",
								MUIA_Text_Contents,	"Clear input on exec",
								MUIA_Text_HiChar,	'r',
							End,
							Child, HSpace(1),
							Child, ClearInObj =	ImageObject, ImageButtonFrame,
											MUIA_InputMode,		MUIV_InputMode_Toggle,
											MUIA_Image_Spec,	MUII_CheckMark,
											MUIA_Image_FreeVert,	TRUE,
											MUIA_Selected,		ClearInput,
											MUIA_Background,	MUII_ButtonBack,
											MUIA_ShowSelState,	FALSE,
											MUIA_ControlChar,	'r',
											MUIA_ExportID,		'CLRI',
										End,
						End, // Clear checkbox

							// Flush memory gadget

						Child, HGroup,
							Child, TextObject,
								MUIA_Text_PreParse,	"\033r",
								MUIA_Text_Contents,	"Flush memory",
								MUIA_Text_HiChar,	'm',
							End,
							Child, HSpace(1),
							Child, FlushObj	=	ImageObject, ImageButtonFrame,
											MUIA_InputMode,		MUIV_InputMode_Toggle,
											MUIA_Image_Spec,	MUII_CheckMark,
											MUIA_Image_FreeVert,	TRUE,
											MUIA_Selected,		FlushOnExit,
											MUIA_Background,	MUII_ButtonBack,
											MUIA_ShowSelState,	FALSE,
											MUIA_ControlChar,	'm',
											MUIA_ExportID,		'FLUS',
										End,
						End, // Flush CheckBox

							// Open std. deviation window

						Child, HGroup,
							Child, TextObject,
								MUIA_Text_PreParse,	"\033r",
								MUIA_Text_Contents,	"Deviation window",
								MUIA_Text_HiChar,	'D',
							End,
							Child, HSpace(1),
							Child, StdWinObj =	ImageObject, ImageButtonFrame,
											MUIA_InputMode,		MUIV_InputMode_Toggle,
											MUIA_Image_Spec,	MUII_CheckMark,
											MUIA_Image_FreeVert,	TRUE,
											MUIA_Selected,		OpenStdWin,
											MUIA_Background,	MUII_ButtonBack,
											MUIA_ShowSelState,	FALSE,
											MUIA_ControlChar,	'd',
											MUIA_ExportID,		'DEVI',
										End,
						End, // Open std. deviation window

							// Open lin. regression window

						Child, HGroup,
							Child, TextObject,
								MUIA_Text_PreParse,	"\033r",
								MUIA_Text_Contents,	"Regression window",
								MUIA_Text_HiChar,	'g',
							End,
							Child, HSpace(1),
							Child, LinWinObj =	ImageObject, ImageButtonFrame,
											MUIA_InputMode,		MUIV_InputMode_Toggle,
											MUIA_Image_Spec,	MUII_CheckMark,
											MUIA_Image_FreeVert,	TRUE,
											MUIA_Selected,		OpenLinWin,
											MUIA_Background,	MUII_ButtonBack,
											MUIA_ShowSelState,	FALSE,
											MUIA_ControlChar,	'g',
											MUIA_ExportID,		'REGR',
										End,
						End, // Open lin. regression window

							// Open constants window

						Child, HGroup,
							Child, TextObject,
								MUIA_Text_PreParse,	"\033r",
								MUIA_Text_Contents,	"Constants window",
								MUIA_Text_HiChar,	't',
							End,
							Child, HSpace(1),
							Child, ConstWinObj =	ImageObject, ImageButtonFrame,
											MUIA_InputMode,		MUIV_InputMode_Toggle,
											MUIA_Image_Spec,	MUII_CheckMark,
											MUIA_Image_FreeVert,	TRUE,
											MUIA_Selected,		OpenConstWin,
											MUIA_Background,	MUII_ButtonBack,
											MUIA_ShowSelState,	FALSE,
											MUIA_ControlChar,	't',
											MUIA_ExportID,		'CONS',
										End,
						End, // Open constants window


						Child, VSpace(0),

					End, // Misc Group
				End, // Horizontal Groups

					// Ok, Cancel, Save gadgets

				Child, VGroup, GroupFrame,
					Child, ColGroup(3), MUIA_Group_SameWidth, TRUE,

							// Save Gadget

						Child, SaveObj	=	TextObject, ButtonFrame,
										MUIA_Background,	MUII_ButtonBack,
										MUIA_Text_PreParse,	"\33c",
										MUIA_Text_Contents,	"Save",
										MUIA_Text_HiChar,	'S',
										MUIA_ControlChar,	's',
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

							// Use Gadget

						Child, OkObj	=	TextObject, ButtonFrame,
										MUIA_Background,	MUII_ButtonBack,
										MUIA_Text_PreParse,	"\33c",
										MUIA_Text_Contents,	"Use",
										MUIA_Text_HiChar,	'U',
										MUIA_ControlChar,	'u',
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,

							// Cancel Gadget

						Child, CancelObj =	TextObject, ButtonFrame,
										MUIA_Background,	MUII_ButtonBack,
										MUIA_Text_PreParse,	"\33c",
										MUIA_Text_Contents,	"Cancel",
										MUIA_Text_HiChar,	'C',
										MUIA_ControlChar,	'c',
										MUIA_InputMode,		MUIV_InputMode_RelVerify,
									End,
					End, // ColGroup
				End, // Use - Cancel gadgets
			End, // Prefs window contents
		End, // Prefs window


			// Now generate the Standard deviation history window

		SubWindow, StdHistoryWindow = WindowObject,
						MUIA_Window_Title,	"MUIProCalc Std.Deviation",
						MUIA_Window_ID,		'MPCS',
						MUIA_Window_SizeGadget,	TRUE,
						MUIA_Window_Activate,	FALSE,
						MUIA_Window_NoMenus,	TRUE,
						MUIA_HelpNode,		NODE_WINDOWS,

			WindowContents, VGroup,

				Child,	StdHistoryObj	=	ListviewObject,
						MUIA_Listview_Input,		TRUE,
						MUIA_Listview_List,	ListObject, InputListFrame,
							MUIA_Background,		MUII_ListBack,
							MUIA_List_Title,		TRUE,
							MUIA_List_Format,		"COL=0 DELTA=12,COL=1 P=\033r",
							MUIA_List_ConstructHook,	&HistoryConstructHook,
							MUIA_List_DestructHook,		&StdDestructHook,
							MUIA_List_DisplayHook,		&DeviationDispHook,
						End,
					End,

			End, // Standard deviation window
		End, // Standard deviation window

			// Now generate the Linear Regression history window

		SubWindow, LinHistoryWindow = WindowObject,
						MUIA_Window_Title,	"MUIProCalc Lin.Regression",
						MUIA_Window_ID,		'MPCL',
						MUIA_Window_SizeGadget,	TRUE,
						MUIA_Window_Activate,	FALSE,
						MUIA_Window_NoMenus,	TRUE,
						MUIA_HelpNode,		NODE_WINDOWS,

			WindowContents, VGroup,

				Child,	LinHistoryObj	=	ListviewObject,
						MUIA_Listview_Input,		TRUE,
						MUIA_Listview_List,	ListObject, InputListFrame,
							MUIA_Background,		MUII_ListBack,
							MUIA_List_Title,		TRUE,
							MUIA_List_Format,		"COL=0 DELTA=12,COL=1 P=\033r DELTA=12,COL=2 P=\033r",
							MUIA_List_ConstructHook,	&HistoryConstructHook,
							MUIA_List_DestructHook,		&StdDestructHook,
							MUIA_List_DisplayHook,		&RegressionDispHook,
						End,
					End,

			End, // Linear Regression window
		End, // Linear Regression window


			// Now generate the Constants window

		SubWindow, ConstantsWindow = WindowObject,
						MUIA_Window_Title,	"MUIProCalc Constants",
						MUIA_Window_ID,		'MPCC',
						MUIA_Window_SizeGadget,	TRUE,
						MUIA_Window_Activate,	FALSE,
						MUIA_Window_NoMenus,	TRUE,
						MUIA_HelpNode,		NODE_WINDOWS,

			WindowContents, VGroup,

				Child,	ConstantsObj =	ListviewObject,
						MUIA_Listview_Input,		TRUE,
						MUIA_Listview_List,	ListObject, InputListFrame,
							MUIA_Background,		MUII_ListBack,
							MUIA_List_Title,		TRUE,
							MUIA_List_Format,		"COL=0,COL=1,COL=2",
							MUIA_List_ConstructHook,	&ConstConstructHook,
							MUIA_List_DestructHook,		&StdDestructHook,
							MUIA_List_DisplayHook,		&ConstDispHook,
							MUIA_List_CompareHook,		&ConstCompHook,
						End,
					End,

			End, // Constants group
		End, // Constants window
	End; // Application

	if(AppObject && InputGroup && OutputGroup)
	{
		int	i;


			// Set cycle chain for Prefs window

		DoMethod(PrefsWindow, MUIM_Window_SetCycleChain,
			DFuncObj,
			DInObj,
			InOutObj,
			TypeObj,
			SizeObj,
			SignObj,
			AngleObj,
			LinesObj,
			LookObj,
			ClipObj,
			ClearInObj,
			FlushObj,
			StdWinObj,
			LinWinObj,
			ConstWinObj,
			SaveObj,
			OkObj,
			CancelObj,
		NULL);

			// Set stuff for main window

		DoMethod(MainWindow, MUIM_Notify,
			MUIA_Window_CloseRequest,	TRUE,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_QUIT);

			// Set default object for window

		set(MainWindow, MUIA_Window_DefaultObject, InputString);

			//
			// Do the Gadgets
			//

			// Set ID for String-Input

		DoMethod(InputString, MUIM_Notify,
			MUIA_String_Acknowledge,	MUIV_EveryTime,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_INPUT);

			// Attach Output box to StringGadget

		set(InputString, MUIA_String_AttachedList, OutputBox);

			// Set up control gadgets to call Hook

		for(i = 0; i < GadNum; i++)
		{
				// First call the Hook when released

			DoMethod(InGads[i], MUIM_Notify,
				MUIA_Pressed,		FALSE,
				AppObject,		3,
				MUIM_CallHook,		&InsertHook, InGads[i]);

				// The reactivate the string gadget

			DoMethod(InGads[i], MUIM_Notify,
				MUIA_Pressed,		FALSE,
				MainWindow,		3,
				MUIM_Set,		MUIA_Window_ActiveObject, InputString);
		}


			// Return ID for Exe gadget

		DoMethod(ExeObj, MUIM_Notify,
			MUIA_Pressed,			FALSE,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_EXEC);

			// Return ID for CLR gadget

		DoMethod(ClrObj, MUIM_Notify,
			MUIA_Pressed,			FALSE,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_CLEAR);

			// Return ID for ACLR gadget

		DoMethod(AllClrObj, MUIM_Notify,
			MUIA_Pressed,			FALSE,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_ALLCLEAR);




			// Do the Prefs window

		DoMethod(PrefsWindow, MUIM_Notify,
			MUIA_Window_CloseRequest,	TRUE,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_PREFS_QUIT);


			// On OK, first save the prefs to env:

		DoMethod(OkObj, MUIM_Notify,
			MUIA_Pressed,			FALSE,
			AppObject,			2,
			MUIM_Application_Save,		MUIV_Application_Save_ENV);

			// Then signal the main program, that new prefs are available

		DoMethod(OkObj, MUIM_Notify,
			MUIA_Pressed,			FALSE,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_PREFS_NEW);




			// On SAVE, save both to env: and envarc:

		DoMethod(SaveObj, MUIM_Notify,
			MUIA_Pressed,			FALSE,
			AppObject,			2,
			MUIM_Application_Save, MUIV_Application_Save_ENV);

		DoMethod(SaveObj, MUIM_Notify,
			MUIA_Pressed,			FALSE,
			AppObject,			2,
			MUIM_Application_Save, MUIV_Application_Save_ENVARC);

			// New prefs available

		DoMethod(SaveObj, MUIM_Notify,
			MUIA_Pressed,			FALSE,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_PREFS_NEW);



			// On Cancel, simply close the window

		DoMethod(CancelObj, MUIM_Notify,
			MUIA_Pressed,			FALSE,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_PREFS_QUIT);


			// Do the Std.Deviation window

		DoMethod(StdHistoryWindow, MUIM_Window_SetCycleChain,
			StdHistoryObj,
		NULL);

		DoMethod(StdHistoryWindow, MUIM_Notify,
			MUIA_Window_CloseRequest,	TRUE,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_CLOSESTD);


			// Do the Lin.Regression window

		DoMethod(LinHistoryWindow, MUIM_Window_SetCycleChain,
			LinHistoryObj,
		NULL);

		DoMethod(LinHistoryWindow, MUIM_Notify,
			MUIA_Window_CloseRequest,	TRUE,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_CLOSELIN);


			// Do the Constants window

		DoMethod(ConstantsWindow, MUIM_Window_SetCycleChain,
			ConstantsObj,
		NULL);

		DoMethod(ConstantsWindow, MUIM_Notify,
			MUIA_Window_CloseRequest,	TRUE,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_CLOSECONST);

		DoMethod(ConstantsObj, MUIM_Notify,
			MUIA_Listview_DoubleClick,	TRUE,
			AppObject,			2,
			MUIM_Application_ReturnID,	ID_SELECTCONST);



			// Load the settings

		DoMethod(AppObject, MUIM_Application_Load, MUIV_Application_Load_ENV);


			// Load defaults into variables

		get(DFuncObj, MUIA_Selected, &Dummy);
		NoFuncs = Dummy;

		get(DInObj, MUIA_Selected, &Dummy);
		NoInput = Dummy;

		get(InOutObj, MUIA_Cycle_Active, &Dummy);
		InOutLook = Dummy;

		get(TypeObj, MUIA_Cycle_Active, &Dummy);
		IntType	= RXIntType 	= Dummy + ID_DECIMAL;

		get(SizeObj, MUIA_Cycle_Active, &Dummy);
		IntBase	= RXIntBase	= Dummy + ID_8BIT;

		get(SignObj, MUIA_Cycle_Active, &Dummy);
		IntSign	= RXIntSign	= Dummy + ID_SIGNED;

		get(AngleObj, MUIA_Cycle_Active, &Dummy);
		IntAngle = RXIntAngle	= Dummy + ID_RAD;

		get(LinesObj, MUIA_Slider_Level, &Dummy);
		HistLines = Dummy;

		get(ClipObj, MUIA_Slider_Level, &Dummy);
		ClipUnit = Dummy;

		get(LookObj, MUIA_Cycle_Active, &Dummy);
		ListLook = Dummy;

		get(ClearInObj, MUIA_Selected, &Dummy);
		ClearInput = Dummy;

		get(FlushObj, MUIA_Selected, &Dummy);
		FlushOnExit = Dummy;

		get(StdWinObj, MUIA_Selected, &Dummy);
		OpenStdWin = Dummy;

		get(LinWinObj, MUIA_Selected, &Dummy);
		OpenLinWin = Dummy;

		get(ConstWinObj, MUIA_Selected, &Dummy);
		OpenConstWin = Dummy;


			// Add in/out gadgets in correct order

		if(!InOutLook)
		{
			DoMethod(InOutGroup, OM_ADDMEMBER, InputGroup);
			DoMethod(InOutGroup, OM_ADDMEMBER, OutputGroup);
		}
		else
		{
			DoMethod(InOutGroup, OM_ADDMEMBER, OutputGroup);
			DoMethod(InOutGroup, OM_ADDMEMBER, InputGroup);
		}

			// Set cycle chain for main window _AFTER_ String and ListView have been added

		SetMainWinCycle();

			// Set listview look

		set(OutputBox, MUIA_List_Format, LookTemplates[ListLook]);


			// Add/Remove groups as requested

		if(NoFuncs)
			DoMethod(MainGroup, OM_REMMEMBER, FuncGroup, TAG_DONE);

		if(NoInput)
			DoMethod(MainGroup, OM_REMMEMBER, InGroup, TAG_DONE);


			// Add constants to constants window

		for(i = 0; i < sizeof(ConstNames) / sizeof(char *); i++)
		{
			struct	ConstNode	New;

			New.Constant	= ConstNames[i];
			New.Value	= ConstValues[i];
			New.Notation	= ConstNotation[i];

			DoMethod(ConstantsObj, MUIM_List_InsertSingle, (APTR)&New, MUIV_List_Insert_Sorted);
		}

			// Set InputString to default object

		set(MainWindow, MUIA_Window_DefaultObject, InputString);

			// Open the main window

		set(MainWindow, MUIA_Window_Open, TRUE);

			// Now set Checkmarks

		DoMethod(MainWindow, MUIM_Window_SetMenuCheck, (ULONG)IntType, TRUE);
		DoMethod(MainWindow, MUIM_Window_SetMenuCheck, (ULONG)IntBase, TRUE);
		DoMethod(MainWindow, MUIM_Window_SetMenuCheck, (ULONG)IntSign, TRUE);
		DoMethod(MainWindow, MUIM_Window_SetMenuCheck, (ULONG)IntAngle, TRUE);
		DoMethod(MainWindow, MUIM_Window_SetMenuCheck, ID_STDHISTORY, OpenStdWin);
		DoMethod(MainWindow, MUIM_Window_SetMenuCheck, ID_LINHISTORY, OpenLinWin);
		DoMethod(MainWindow, MUIM_Window_SetMenuCheck, ID_CONSTANTS, OpenConstWin);

			// Which support window to open?

		if(OpenStdWin)
			set(StdHistoryWindow, MUIA_Window_Open, TRUE);

		if(OpenLinWin)
			set(LinHistoryWindow, MUIA_Window_Open, TRUE);

		if(OpenConstWin)
			set(ConstantsWindow, MUIA_Window_Open, TRUE);
	}
	else
	{
		if(InputGroup)
			MUI_DisposeObject(InputGroup);

		if(OutputGroup)
			MUI_DisposeObject(OutputGroup);
	}

	return((BOOL)(AppObject && InputGroup && OutputGroup));
}






/**********************************************************************/
/*                    Close the main window again                     */
/**********************************************************************/
static void CloseMainWin(void)
{
		// Dispose all Objects

	if(AppObject)
	{
		set(MainWindow, MUIA_Window_Open, FALSE);
		MUI_DisposeObject(AppObject);
	}

		// Dispose DiskObject

	if(DObject)
		FreeDiskObject(DObject);
}







/**********************************************************************/
/*                      Format the output string                      */
/**********************************************************************/
BOOL FormatOutput(BOOL ReFormat)
{
	struct	ListStruct	NewEntry,
				*NewEntryPtr;
	ULONG	ULong;
	BOOL	RetVal		= FALSE;

		// Set title of window first

	sprintf(Title, "MUIProCalc "REVISION" - "REVDATE" - %c%s%c %s", TypeChar[IntType - ID_DECIMAL], BaseStr[IntBase - ID_8BIT], SignChar[IntSign - ID_SIGNED], AngleStr[IntAngle - ID_RAD]);
	set(MainWindow, MUIA_Window_Title, Title);

		// Reformat entry ???
	if(!ReFormat)
	{
			// Get the Gadgets buffer

		get(InputString, MUIA_String_Contents, &ParseInput);
		strcpy(NewEntry.Input, ParseInput);
	}
	else
	{
		ULONG	NumEntries;

			// Get input from bottom entry within History

		get(OutputBox, MUIA_List_Entries, &NumEntries);
		DoMethod(OutputBox, MUIM_List_GetEntry, NumEntries - 1, &NewEntryPtr);
		NewEntry	= *NewEntryPtr;
		ParseInput	= NewEntry.Input;
	}

	if(strlen(ParseInput))
	{
			// Allocate memory pool for parsing

		if((ParsePool = DoCreatePool(MEMF_CLEAR, 8192, 2048)))
		{
				// Reset scanner

			yychar			= -2;
			yynerrs			= 0;
			yy_init			= 1;
			yy_start		= 0;
			yyin = yyout		= NULL;
			yy_current_buffer	= NULL;
			ContainsUnDec		= FALSE;

				// Do the parse

			yyparse();

				// Delete pool again

			DoDeletePool(ParsePool);

			if(!yynerrs && !PError)
			{
				RetVal	= TRUE;

				switch(IntType)
				{
					case ID_DECIMAL :
					{
						if(!ContainsUnDec)
						{
							if((Value > 4294967295.0) || (Value < -4294967295.0) || ((Value < 1.0) && (Value > -1.0)))
								sprintf(NewEntry.Output, "%g ", Value);
							else
								sprintf(NewEntry.Output, "%f ", Value);
						}
						else
							sprintf(NewEntry.Output, "%f ", Value);
						break;
					}

					case ID_HEXDECIMAL :
					{
						if((Value > 4294967295.0) || (Value < -4294967295.0))
							strcpy(NewEntry.Output, "\0338Hex overflow");
						else
						{
							sprintf(NewEntry.Output, "%f ", Value);

								// Now convert that output to a Long

							stcd_l(NewEntry.Output, (LONG *)&ULong);

								// And reconvert it to hex output ;)

							sprintf(NewEntry.Output, "$%x ", ULong);
						}
						break;
					}
					case ID_OCTAL :
					{
						if((Value > 4294967295.0) || (Value < -4294967295.0))
							strcpy(NewEntry.Output, "\0338Octal overflow");
						else
						{
							sprintf(NewEntry.Output, "%f ", Value);

								// First convert to Long

							stcd_l(NewEntry.Output, (LONG *)&ULong);

								// Now conbert to octal

							sprintf(NewEntry.Output, "\\%o ", ULong);
						}
						break;
					}
					case ID_BINARY :
					{
						char	AddOn[2];
						int	i,
							NumBits;

						if((Value > 4294967295.0) || (Value < -4294967295.0))
							strcpy(NewEntry.Output, "\0338Binary overflow");
						else
						{
							sprintf(NewEntry.Output, "%f ", Value);

							switch(IntBase)
							{
								case ID_8BIT :
								{
									NumBits = 8;
									break;
								}
								case ID_16BIT :
								{
									NumBits = 16;
									break;
								}
								case ID_32BIT :
								{
									NumBits = 32;
									break;
								}
							}
								// First convert to Long

							stcd_l(NewEntry.Output, (LONG *)&ULong);

								// Set type identifier

							strcpy(NewEntry.Output, "&");

								// Now convert to binary output

							AddOn[1] = '\0';
							for(i = NumBits - 1; i >= 0; i--)
							{
								AddOn[0] = ((ULong & (1L << i)) ? (ULong & (1L << i)) - (1L << i) + '1' : '0');
								strcat(NewEntry.Output, AddOn);

									// 4 Bits done -> insert a space ;)

								if(!(i % 4))
									strcat(NewEntry.Output, " ");
							}
						}
						break;
					}
				}
			}
			else
			{
				if(PError == ERR_UNKNOWN_CHR)
					sprintf(NewEntry.Output, "\0338Unknown char in column %d", PColumn);
				else if(PError == ERR_DIVBY0)
					sprintf(NewEntry.Output, "\0338Division by Zero in column %d", PColumn);
				else if(PError == ERR_OVERFLOW)
					sprintf(NewEntry.Output, "\0338Overflow error in column %d", PColumn);
				else if(PError == ERR_UNDERFLOW)
					sprintf(NewEntry.Output, "\0338Underflow error in column %d", PColumn);
				else if(PError == ERR_NOMEM)
					strcpy(NewEntry.Output, "\0338Insufficient memory");
				else
					sprintf(NewEntry.Output, "\0338Syntax error in column %d", PColumn);
			}

				// On "History-Overflow" remove top entry

			get(OutputBox, MUIA_List_Entries, &ULong);
			if(ULong > HistLines)
				DoMethod(OutputBox, MUIM_List_Remove, MUIV_List_Remove_First);

			NewEntryPtr	= &NewEntry;
			DoMethod(OutputBox, MUIM_List_Insert, &NewEntryPtr, 1, MUIV_List_Insert_Bottom);
			set(OutputBox, MUIA_List_Active, MUIV_List_Active_Bottom);

			if(ClearInput)
				set(InputString, MUIA_String_Contents, "");
		}
		else
			MUI_Request(AppObject, MainWindow, NULL, NULL, "*Ok", "Sorry, no memory for parsing");
	}

	set(MainWindow, MUIA_Window_ActiveObject, InputString);

	return(RetVal);
}







/**********************************************************************/
/*                  Insert Hook for function gadgets                  */
/**********************************************************************/
static ULONG	__saveds __asm InsertFunc(register __a0 struct Hook *MyHook, register __a2 APTR Obj, register __a1 APTR *Data)
{
	char	*Text;

		// Get Text of selected gadget

	get(*Data, MUIA_Text_Contents, &Text);

		// Insert text at cursor position

	InsertText(Text);
	return(0);
}






/**********************************************************************/
/*        Hook-Function for generating a new entry for the LV         */
/**********************************************************************/
static ULONG	__saveds __asm DispConstructFunc(register __a0 struct Hook *MyHook, register __a2 APTR MemPool, register __a1 struct ListStruct *Data)
{
	struct	ListStruct	*New;

	if((New = AllocVec(sizeof(struct ListStruct), MEMF_CLEAR)))
	{
		*New	=	*Data;
		return((ULONG)New);
	}

	return(NULL);
}





/**********************************************************************/
/*         Hook-Function for removing a new entry from the LV         */
/**********************************************************************/
static ULONG	__saveds __asm StdDestructFunc(register __a0 struct Hook *MyHook, register __a2 APTR MemPool, register __a1 struct ListStruct *Data)
{
	FreeVec(Data);
	return(0);
}






/**********************************************************************/
/*                      Put pointers into array                       */
/**********************************************************************/
static ULONG	__saveds __asm DispViewFunc(register __a0 struct Hook *MyHook, register __a2 char **array, register __a1 struct ListStruct *Data)
{
	*array++	= Data->Input;
	*array		= Data->Output;

	return(NULL);
}




/**********************************************************************/
/*                Construct history entry for std/lin                 */
/**********************************************************************/
static ULONG	__saveds __asm HistoryConstructFunc(register __a0 struct Hook *MyHook, register __a2 APTR MemPool, register __a1 struct DoubleNode *Data)
{
	struct	DoubleNode	*New;

	if((New = AllocVec(sizeof(struct DoubleNode), MEMF_CLEAR)))
	{
		*New	=	*Data;
		return((ULONG)New);
	}

	return(NULL);
}




/**********************************************************************/
/*                       Display std deviation                        */
/**********************************************************************/
static ULONG	__saveds __asm DeviationDispFunc(register __a0 struct Hook *MyHook, register __a2 char **array, register __a1 struct DoubleNode *Data)
{
	static	char	Buffer1[32], Buffer2[64];

	if(Data)
	{
		sprintf(Buffer1, "Value %ld:", array[-1] + 1);
		sprintf(Buffer2, "%g", Data->ValueX);

		*array++	= Buffer1;
		*array		= Buffer2;
	}
	else
	{
		*array++	= "Element";
		*array		= "X-Value";
	};

	return(0);
}




/**********************************************************************/
/*                       Display lin regression                       */
/**********************************************************************/
static ULONG	__saveds __asm RegressionDispFunc(register __a0 struct Hook *MyHook, register __a2 char **array, register __a1 struct DoubleNode *Data)
{
	static	char	Buffer1[32], Buffer2[64], Buffer3[64];

	if(Data)
	{
		sprintf(Buffer1, "Pair %ld:", array[-1] + 1);
		sprintf(Buffer2, "%g", Data->ValueX);
		sprintf(Buffer3, "%g", Data->ValueY);

		*array++	= Buffer1;
		*array++	= Buffer2;
		*array		= Buffer3;
	}
	else
	{
		*array++	= "Element";
		*array++	= "X-Value";
		*array		= "Y-Value";
	}
	return(0);
}



/**********************************************************************/
/*                      Construct constant entry                      */
/**********************************************************************/
static ULONG	__saveds __asm ConstConstructFunc(register __a0 struct Hook *MyHook, register __a2 APTR MemPool, register __a1 struct ConstNode *Data)
{
	struct	ConstNode	*New;

	if((New = AllocVec(sizeof(struct ConstNode), MEMF_CLEAR)))
	{
		*New	=	*Data;
		return((ULONG)New);
	}

	return(NULL);
}


/**********************************************************************/
/*                       Display constant entry                       */
/**********************************************************************/
static ULONG	__saveds __asm ConstDispFunc(register __a0 struct Hook *MyHook, register __a2 char **array, register __a1 struct ConstNode *Data)
{
	if(Data)
	{
		*array++	= Data->Constant;
		*array++	= Data->Value;
		*array		= Data->Notation;
	}
	else
	{
		*array++	= "Name";
		*array++	= "Value";
		*array		= "Notation";
	}

	return(0);
}




/**********************************************************************/
/*            Compare two constants entries (for sorting)             */
/**********************************************************************/
static LONG	__saveds __asm ConstCompFunc(register __a1 struct ConstNode *Data1, register __a2 struct ConstNode *Data2)
{
	return(Stricmp(Data1->Constant, Data2->Constant));
}



/**********************************************************************/
/*        Insert a text-string at the current cursor-position         */
/**********************************************************************/
static void InsertText(char *NewText)
{
	char	NewBuff[258],
		*Text;
	ULONG	CursorPos;

		// No Error ?!?

	if(strncmp(NewText, "\0338", 2))
	{
			// Get current cursor Position within Input-String

		get(InputString, MUIA_String_BufferPos, &CursorPos);
		get(InputString, MUIA_String_Contents, &Text);

			// Copy to buffer, because the string`s contents may not be
			// directly altered

		strcpy(NewBuff, Text);

			// insert to cursor position

		if((strlen(NewBuff) + strlen(NewText)) < 256)
			strins(&NewBuff[CursorPos], NewText);
		else
			DisplayBeep(NULL);

			// Set new string for String-Gadget

		set(InputString, MUIA_String_Contents, NewBuff);
	}

	set(MainWindow, MUIA_Window_ActiveObject, InputString);
}





/**********************************************************************/
/*          Write the given entry to the specified clipboard          */
/**********************************************************************/
static void WriteClip(char *Entry)
{
	struct	IFFHandle	*Handle;
	BOOL	Ok = FALSE;

		// Length > 0 ???

	if(strlen(Entry) && strncmp(Entry, "\0338", 2))
	{
			// Try to obtain an IFF Handle

		if((Handle = AllocIFF()))
		{
				// Open needed clipboard unit

			if((Handle->iff_Stream = (ULONG)OpenClipboard(ClipUnit)))
			{
				InitIFFasClip(Handle);

					// Open Handle for write access

				if(!OpenIFF(Handle, IFFF_WRITE))
				{
						// Push first chunk (FORM)

					if(!PushChunk(Handle, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN))
					{
							// Push chars chunk

						if(!PushChunk(Handle, 0, ID_CHRS, IFFSIZE_UNKNOWN))
						{
								// Write data to clipboard

							if(WriteChunkBytes(Handle, Entry, strlen(Entry)) == strlen(Entry))
							{
									// Pop contents chunk

								if(!PopChunk(Handle))
									Ok = TRUE;
							}
						}

							// Pop FORM chunk

						if(Ok)
							PopChunk(Handle);
					}

						// Close IFF Handle

					CloseIFF(Handle);
				}

					// Close Clipboard again

				CloseClipboard((struct ClipboardHandle *)Handle->iff_Stream);
			}

				// Free IFF Handle

			FreeIFF(Handle);
		}
	}

	set(MainWindow, MUIA_Window_ActiveObject, InputString);
}






/**********************************************************************/
/*                    Delete an entry from history                    */
/**********************************************************************/
void DeleteHistory(LONG Entry)
{
		// No entry specified, delete active entry

	if(Entry == -1)
		DoMethod(OutputBox, MUIM_List_Remove, MUIV_List_Remove_Active);
	else if(Entry == -2)
		DoMethod(OutputBox, MUIM_List_Remove, MUIV_List_Remove_First);
	else if(Entry == -3)
		DoMethod(OutputBox, MUIM_List_Remove, MUIV_List_Remove_Last);
	else
		DoMethod(OutputBox, MUIM_List_Remove, Entry);
}




/**********************************************************************/
/*                This is the main controlling routine                */
/**********************************************************************/
static void HandleInputs(void)
{
	ULONG	MySig, ReturnID;
	BOOL	GoOn	= TRUE;

	while(GoOn)
	{
		switch(ReturnID = DoMethod(AppObject, MUIM_Application_Input, &MySig))
		{
				// Input done ;)

			case ID_INPUT :
			{
				FormatOutput(FALSE);
				break;
			}

				// Translate input

			case ID_EXEC :
			{
				FormatOutput(FALSE);
				break;
			}

				// Clear input

			case ID_CLEAR :
			{
				set(InputString, MUIA_String_Contents, "");
				FormatOutput(FALSE);
				break;
			}

				// Clear input AND Memory

			case ID_ALLCLEAR :
			{
				IMem = JMem = KMem = LMem = MMem = NMem = OMem = PMem = QMem = RMem = SMem = TMem = UMem = VMem = WMem = XMem = YMem = ZMem = 0.0;
				FreeList(&StandardList);
				FreeList(&LinearList);
				UpdateHistoryWindow(FALSE);
				UpdateHistoryWindow(TRUE);
				set(InputString, MUIA_String_Contents, "");
				FormatOutput(FALSE);
				break;
			}

				// Open Prefs window

			case ID_PREFS :
			{
				set(PrefsWindow, MUIA_Window_Open, TRUE);
				break;
			}

				// Display About

			case ID_ABOUT :
			{
				MUI_Request(AppObject, MainWindow, 0, NULL, "*Okay",
					"\033cMUIProCalc v%ld.%ld, written by Kai Iske, GiftWare\n\n"
					"\0338Powerful calculator, also suited for programmers\n\n"
					"\033l\0332To contact me, write to:\n\033c"
					"Kai Iske, Brucknerstrasse 18, 63452 Hanau, Germany\n"
					"Tel.: +49-(0)6181-850181\n\n"
					"\033lor use electronical mail\n\033c"
					"iske@informatik.uni-frankfurt.de\n"
					"Kai Iske, 100524,1201\n"
					"Kai Iske, 2:244/6302.11\n"
					"KAI@SWEET.RHEIN-MAIN.DE\n\n"
					"\033c\0332MUIProCalc is a MUI-Application\n"
					"MUI is © Stefan Stuntz",
					VERNUM, REVNUM, TAG_DONE);
				set(MainWindow, MUIA_Window_ActiveObject, InputString);
				break;
			}
				// Quit the program

			case ID_QUIT :
			case MUIV_Application_ReturnID_Quit :
			{
				set(PrefsWindow, MUIA_Window_Open, FALSE);
				GoOn = FALSE;
				break;
			}

				// Pick left entry from History ???

			case ID_PICKLEFT :
			{
				struct	ListStruct	*LSV;
				ULONG	ClickCol;

				DoMethod(OutputBox, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &LSV);

				if(LSV)
				{
					if(ListLook == 0 || ListLook == 2)
						ClickCol = 0;
					else if(ListLook == 1 || ListLook == 3)
						ClickCol = 1;

					if(!ClickCol)
						InsertText(LSV->Input);
					else
						InsertText(LSV->Output);
				}
				break;
			}

				// Pick right entry from History ???

			case ID_PICKRIGHT :
			{
				struct	ListStruct	*LSV;
				ULONG	ClickCol;

				DoMethod(OutputBox, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &LSV);

				if(LSV)
				{
					if(ListLook == 0 || ListLook == 3)
						ClickCol = 1;
					else if(ListLook == 1 || ListLook == 2)
						ClickCol = 0;

					if(!ClickCol)
						InsertText(LSV->Input);
					else
						InsertText(LSV->Output);
				}
				break;
			}

				// Copy left history entry to clipboard

			case ID_CLIPCUTLEFT :
			{
				struct	ListStruct	*LSV;
				ULONG	ClickCol;

				DoMethod(OutputBox, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &LSV);

				if(LSV)
				{
					if(ListLook == 0 || ListLook == 2)
						ClickCol = 0;
					else if(ListLook == 1 || ListLook == 3)
						ClickCol = 1;

					if(!ClickCol)
						WriteClip(LSV->Input);
					else
						WriteClip(LSV->Output);
				}

				break;
			}

				// Copy left history entry to clipboard

			case ID_CLIPCUTRIGHT :
			{
				struct	ListStruct	*LSV;
				ULONG	ClickCol;

				DoMethod(OutputBox, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &LSV);

				if(LSV)
				{
					if(ListLook == 0 || ListLook == 3)
						ClickCol = 1;
					else if(ListLook == 1 || ListLook == 2)
						ClickCol = 0;

					if(!ClickCol)
						WriteClip(LSV->Input);
					else
						WriteClip(LSV->Output);
				}

				break;
			}

				// Delete current entry from list

			case ID_DELHISTORY :
			{
				DeleteHistory(-1);
				break;
			}

				// Check Output Type

			case ID_DECIMAL :
			case ID_HEXDECIMAL :
			case ID_OCTAL :
			case ID_BINARY :
			{
				DoMethod(MainWindow, MUIM_Window_SetMenuCheck, (ULONG)IntType, FALSE);
				IntType	= ReturnID;
				DoMethod(MainWindow, MUIM_Window_SetMenuCheck, (ULONG)IntType, TRUE);
				FormatOutput(TRUE);
				break;
			}

				// Check for Bases

			case ID_8BIT :
			case ID_16BIT :
			case ID_32BIT :
			{
				DoMethod(MainWindow, MUIM_Window_SetMenuCheck, (ULONG)IntBase, FALSE);
				IntBase	= ReturnID;
				DoMethod(MainWindow, MUIM_Window_SetMenuCheck, (ULONG)IntBase, TRUE);
				FormatOutput(TRUE);
				break;
			}

				// Check for Signs

			case ID_SIGNED :
			case ID_UNSIGNED :
			{
				DoMethod(MainWindow, MUIM_Window_SetMenuCheck, (ULONG)IntSign, FALSE);
				IntSign	= ReturnID;
				DoMethod(MainWindow, MUIM_Window_SetMenuCheck, (ULONG)IntSign, TRUE);
				FormatOutput(TRUE);
				break;
			}

				// Check angle

			case ID_RAD :
			case ID_DEG :
			case ID_GRAD :
			{
				DoMethod(MainWindow, MUIM_Window_SetMenuCheck, (ULONG)IntAngle, FALSE);
				IntAngle	= ReturnID;
				DoMethod(MainWindow, MUIM_Window_SetMenuCheck, (ULONG)IntAngle, TRUE);
				FormatOutput(TRUE);
				break;
			}

				// Check for window open/close

			case ID_STDHISTORY :
			{
				OpenStdWin	= DoMethod(MainWindow, MUIM_Window_GetMenuCheck, ID_STDHISTORY);

				set(StdHistoryWindow, MUIA_Window_Open, OpenStdWin);
				break;
			}

			case ID_CLOSESTD :
			{
				OpenStdWin	= FALSE;
				DoMethod(MainWindow, MUIM_Window_SetMenuCheck, ID_STDHISTORY, OpenStdWin);

				set(StdHistoryWindow, MUIA_Window_Open, FALSE);
				break;
			}

			case ID_LINHISTORY :
			{
				OpenLinWin	= DoMethod(MainWindow, MUIM_Window_GetMenuCheck, ID_LINHISTORY);

				set(LinHistoryWindow, MUIA_Window_Open, OpenLinWin);
				break;
			}

			case ID_CLOSELIN :
			{
				OpenLinWin	= FALSE;
				DoMethod(MainWindow, MUIM_Window_SetMenuCheck, ID_LINHISTORY, OpenLinWin);

				set(LinHistoryWindow, MUIA_Window_Open, FALSE);
				break;
			}

			case ID_CONSTANTS :
			{
				OpenConstWin	= DoMethod(MainWindow, MUIM_Window_GetMenuCheck, ID_CONSTANTS);

				set(ConstantsWindow, MUIA_Window_Open, OpenConstWin);
				break;
			}

			case ID_CLOSECONST :
			{
				OpenConstWin	= FALSE;
				DoMethod(MainWindow, MUIM_Window_SetMenuCheck, ID_CONSTANTS, OpenConstWin);

				set(ConstantsWindow, MUIA_Window_Open, FALSE);
				break;
			}

			case ID_SELECTCONST :
			{
				struct	ConstNode	*Select;

				DoMethod(ConstantsObj, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &Select);

				if(Select)
					InsertText(Select->Value);
				break;
			}



				//
				// This is for the Prefs window
				//

				// Close prefs window

			case ID_PREFS_QUIT :
			{
				set(PrefsWindow, MUIA_Window_Open, FALSE);
				set(MainWindow, MUIA_Window_ActiveObject, InputString);

					// Reset preferences

				set(InOutObj, MUIA_Cycle_Active, InOutLook);
				set(DFuncObj, MUIA_Selected, NoFuncs);
				set(DInObj, MUIA_Selected, NoInput);
				set(TypeObj, MUIA_Cycle_Active, (ULONG)IntType);
				set(SizeObj, MUIA_Cycle_Active, (ULONG)IntBase);
				set(SignObj, MUIA_Cycle_Active, (ULONG)IntSign);
				set(AngleObj, MUIA_Cycle_Active, (ULONG)IntAngle);
				set(LinesObj, MUIA_Slider_Level, (ULONG)HistLines);
				set(ClipObj, MUIA_Slider_Level, (ULONG)ClipUnit);
				set(LookObj, MUIA_Cycle_Active, (ULONG)ListLook);
				set(ClearInObj, MUIA_Selected, (ULONG)ClearInput);
				set(FlushObj, MUIA_Selected, (ULONG)FlushOnExit);
				set(StdWinObj, MUIA_Selected, (ULONG)OpenStdWin);
				set(LinWinObj, MUIA_Selected, (ULONG)OpenLinWin);
				set(ConstWinObj, MUIA_Selected, (ULONG)OpenConstWin);
				break;
			}

			case ID_PREFS_NEW :
			{
				ULONG	NewInOut, NewFunc, NewInput, NewLook;

					// Get clear flag

				get(ClearInObj, MUIA_Selected, &NewFunc);
				ClearInput = NewFunc;

					// Get flush flag

				get(FlushObj, MUIA_Selected, &NewFunc);
				FlushOnExit = NewFunc;

					// Get window flags

				get(StdWinObj, MUIA_Selected, &NewFunc);
				OpenStdWin = NewFunc;

				get(LinWinObj, MUIA_Selected, &NewFunc);
				OpenLinWin = NewFunc;

				get(ConstWinObj, MUIA_Selected, &NewFunc);
				OpenConstWin = NewFunc;

					// Get ClipBoard unit

				get(ClipObj, MUIA_Slider_Level, &NewFunc);
				ClipUnit = NewFunc;

				set(PrefsWindow, MUIA_Window_Open, FALSE);
				get(LinesObj, MUIA_Slider_Level, &NewFunc);
				HistLines = NewFunc;

					// Rebuild History

				get(OutputBox, MUIA_List_Entries, &NewInput);
				while(NewInput > HistLines)
				{
					DoMethod(OutputBox, MUIM_List_Remove, MUIV_List_Remove_First);
					NewInput--;
				}

					// Check for changes on layout

				get(InOutObj, MUIA_Cycle_Active, &NewInOut);
				get(DFuncObj, MUIA_Selected, &NewFunc);
				get(DInObj, MUIA_Selected, &NewInput);
				get(LookObj, MUIA_Cycle_Active, &NewLook);

				if((NewInOut != InOutLook) || (NewFunc != NoFuncs) || (NewInput != NoInput))
				{
						// Close main window first

					set(MainWindow, MUIA_Window_Open, FALSE);

						// Rearrange input output order

					if(NewInOut != InOutLook)
					{
						InOutLook = NewInOut;

							// Remove groups first

						DoMethod(InOutGroup, OM_REMMEMBER, InputGroup);
						DoMethod(InOutGroup, OM_REMMEMBER, OutputGroup);

							// Readd groups

						if(!InOutLook)
						{
							DoMethod(InOutGroup, OM_ADDMEMBER, InputGroup);
							DoMethod(InOutGroup, OM_ADDMEMBER, OutputGroup);
						}
						else
						{
							DoMethod(InOutGroup, OM_ADDMEMBER, OutputGroup);
							DoMethod(InOutGroup, OM_ADDMEMBER, InputGroup);
						}

							// Reset cycle order

						SetMainWinCycle();
					}

						// First remove existent groups from main group

					if(!NoFuncs)
						DoMethod(MainGroup, OM_REMMEMBER, FuncGroup);

					if(!NoInput)
						DoMethod(MainGroup, OM_REMMEMBER, InGroup);

						// Add Function group when needed

					NoFuncs = NewFunc;
					if(!NoFuncs)
						DoMethod(MainGroup, OM_ADDMEMBER, FuncGroup);

						// Add Input group when needed

					NoInput = NewInput;
					if(!NoInput)
						DoMethod(MainGroup, OM_ADDMEMBER, InGroup);


						// Reopen window

					set(MainWindow, MUIA_Window_Open, TRUE);
				}

				if(NewLook != ListLook)
				{
							// Set listview look

					ListLook = NewLook;
					set(OutputBox, MUIA_List_Format, LookTemplates[ListLook]);
				}

				set(MainWindow, MUIA_Window_Activate, TRUE);
				set(MainWindow, MUIA_Window_ActiveObject, InputString);
				break;
			}
		}

		if(GoOn && MySig)
			Wait(MySig);
	}
}





/**********************************************************************/
/*                            Free a list                             */
/**********************************************************************/
void FreeList(struct List *Lst)
{
	struct	Node	*DelNode;

	while((DelNode = RemHead(Lst)))
		FreeVec(DelNode);
}







/**********************************************************************/
/*                 Update one of the history windows                  */
/**********************************************************************/
void UpdateHistoryWindow(BOOL LinearHistory)
{
	struct	List		*Lst		= (LinearHistory ? &LinearList : &StandardList);
	struct	DoubleNode	*Check		= (struct DoubleNode *)Lst->lh_Head;
	APTR			Obj		= (LinearHistory ? LinHistoryObj : StdHistoryObj);

		// Clear old list

	DoMethod(Obj, MUIM_List_Clear, NULL);

		// Add new entries

	while(Check->Link.ln_Succ)
	{
		DoMethod(Obj, MUIM_List_InsertSingle, (APTR)Check, MUIV_List_Insert_Bottom);

		Check	= (struct DoubleNode *)Check->Link.ln_Succ;
	}
}


/**********************************************************************/
/*               Dummy, to not to have to link with c.o               */
/**********************************************************************/
void __stdargs _XCEXIT(long num) {}
