/* Main-Header File inserted by GenCodeC */
#ifdef __cplusplus
extern "C"
{
#endif

/* Libraries */
#include <libraries/mui.h>
#include <libraries/gadtools.h> /* for BARLABEL in MenuItem */

/* Prototypes */
#ifdef __GNUC__
#include <proto/muimaster.h>
#include <proto/exec.h>
#include <proto/alib.h>
#include <proto/dos.h>
#else
#include <clib/muimaster_protos.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>
#include <pragmas/muimaster_pragmas.h>
#endif /* __GNUC__ */

/*  Ansi  */
#include <stdlib.h>
#include <stdio.h>

#ifdef __cplusplus
}
#endif

/* Increase stack size */
LONG __stack = 8192;


/* GenCodeC header end */

/* Include generated by GenCodeC */
#include <SearchGUI.h>
#include <workbench/aDiskInfo.h>
#include <libraries/aArray.h>

/* Declarations for libraries (inserted by GenCodeC) */
struct Library * IntuitionBase;
struct Library * MUIMasterBase;
struct Library * LocaleBase;

#ifdef _DEBUG
FILE* con;
#endif

/* Init() function */
void init( void )
{
	if (!(IntuitionBase = OpenLibrary("intuition.library",37)))
	{
		printf("Can't Open Intuition Library\n");
		exit(20);
	}
	if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
	{
		printf("Can't Open MUIMaster Library\n");
		CloseLibrary(IntuitionBase);
		exit(20);
	}
	if (!(LocaleBase = OpenLibrary("locale.library",38)))
	{
		printf("Can't Open Locale Library\n");
		printf("Built-in Language will be used !!!\n");
	}
	OpenAppCatalog(NULL,NULL);
}
/* GenCodeC init() end */

/* End() function */
void end( void )
{
	CloseAppCatalog();
	if (LocaleBase)
		CloseLibrary(LocaleBase);
	CloseLibrary(MUIMasterBase);
	CloseLibrary(IntuitionBase);
	exit(20);
}
/* GenCodeC end() end */

/*

	Declare our mSQL Server outside of the main().
	If localy used, StormC doesn't call the destructor (???).
*/

void DoIt(char* host,char* database,char* table)
{
	/* Program initialisation : generated by GenCodeC */
	init();

	try
	{
		// Init our GUI object

		SearchGUI gui(host,database,table);

		// Get us running

		gui.Open();
		gui.DoEventLoop();
		gui.Close();
	}
	catch (char* c)
	{
		printf("SearchGUI failed: '%s'\n",c);
	}

	end();
}

/* Main Function inserted by GenCodeC */
int main(int argc,char **argv)
{
	DoIt("localhost",NULL,NULL);
}

void wbmain(struct WBStartup *argmsg)
{
	aDiskInfo di(argmsg);

	char* host = di.Get("HOST");
	char* db = di.Get("DATABASE");
	char* tbl = di.Get("TABLE");
	
	DoIt(host,db,tbl);
}
