/* SCOptsPlus
   Copyright (©) 1997, Infinity Labs Development Organization
   All Rights Reserved
   Author: Manolis S. Pappas
   	   Thermopilon 24
	   14231 Nea Ionia
	   Athens, GREECE
*/

/* Main program code */

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

/* Prototypes */
#include <clib/muimaster_protos.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>
#include <clib/icon_protos.h>

/*  Pragmas  */
#ifdef __MAXON__
#include <proto/muimaster_lib.h>
#include <proto/exec_lib.h>
#else
#include <pragmas/muimaster_pragmas.h>
#include <pragmas/exec_pragmas.h>
#endif

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

/* System */
#ifdef __SASC__
#include <dos.h>
#endif

/* Include generated by GenCodeC */
#include "SASCOptionsGUI.h"

/* Safe memory allocations (only for DEBUG) */
#ifdef DEBUG
#include "mem.h"
#endif

/* Definition of the EasyRequest structure */
struct EasyStruct miniErrorreq={
	sizeof(struct EasyStruct),
	0,
	"SCOpts+ Error Message",
	"%s",
	"Ok",
};

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

/* Program Functions (called by hooks) */
APTR h_ABOUT( struct Hook *a0, APTR a2, APTR a1 );		/* About Program */
APTR h_ABOUT_MUI( struct Hook *a0, APTR a2, APTR a1 );		/* About MUI */
APTR h_RESTORE_SCOPTS( struct Hook *a0, APTR a2, APTR a1 );	/* Restore from */
APTR h_RESTORE_ENV( struct Hook *a0, APTR a2, APTR a1 );	/* Restore from */
APTR h_RESTORE( struct Hook *a0, APTR a2, APTR a1 );		/* Restore from... */
APTR h_RESTORE_DEF( struct Hook *a0, APTR a2, APTR a1 );	/* Restore from SAS/C */
APTR h_SAVE_SCOPTS( struct Hook *a0, APTR a2, APTR a1 );	/* Save to SCOPTIONS */
APTR h_SAVE_ENV( struct Hook *a0, APTR a2, APTR a1 );		/* Save to ENV: */
APTR h_SAVE( struct Hook *a0, APTR a2, APTR a1 );		/* Save as... */

/* Program functions (called by reference) */
void default_opts(void);


/* Compiler Options Parameters (default values by SAS/C, 0=NO) */

/*
/* Compiler */
int comp_debug=0; /* nodebug */
int comp_shortint=0; /* noshortintegers */
int comp_stringmerge=0; /* nostringmerge */
int comp_uchar=0; /* nounsignedchar */
int comp_cnest=0; /* nocommentnest */
int comp_mincludes=0; /*multipleincludes */
int comp_gstimm=0; /* nogstimmediate */
int comp_icons=1; /* icons */
int comp_modified=0; /* nomodified */
int comp_pponly=0; /* nopponly */
int comp_cxxonly=0; /* nocxxonly */
int comp_memsize=3; /* memsize=large */
int comp_strconst=0; /* nostringconst */
int comp_wvoidreturn=1; /* nowarnvoidreturn */
int comp_mccconstants=0; /* nomccconstants */

/* Message */
int msg_ansi=0; /* noansi */
int msg_strict=0; /* nostrict */
int msg_erexx=0; /* noerrorrexx */
int msg_econsole=1; /* errorconsole */
int msg_elist=1; /* errorlisting */
int msg_esource=1; /* errorsource */
int msg_ehighlt=1; /* errorhighlight */
int msg_structequiv=0; /* nostructureequivallence */
int msg_onerror=0; /* onerror=stop */

/* Code */
int code_data=0; /* data=near */
int code_code=0; /* code=near */
int code_strsect=0; /* strsect=default */
int code_math=0; /* nomath */
int code_precision=0; /* precision=mixed */
int code_cpu=0; /* cpu=68000 */
int code_parms=0; /* parms=stack */
int code_stkext=0; /* nostackextend */
int code_stkchk=1; /* stackcheck */
int code_saveds=0; /* nosaveds */
int code_datamem=0; /* datamem=any */
int code_areg=1; /* autoregister */
int code_utillib=0; /* noutillib */
int code_clibbase=1; /* constlibbase */
int code_libcode=0; /* nolibcode */
int code_absfuncpointer=0; /* noabsfuncpointer */
int code_common=0; /* nocommon */
int code_coverage=0; /* nocoverage */
int code_profile=0; /* noprofile */

/* List */
int list_macros=0; /* nolistmacros */
int list_includes=0; /* nolistincludes */
int list_headers=1; /* listheaders */
int list_system=0; /* nolistsystem */
int list_narrow=1; /* listnarrow */
int list_errorlisting=1; /* errorlisting */
int list_xrefsystem=0; /* noxrefsystem */
int list_xrefheaders=0; /* noxrefheaders */

/* Optimizer */
int opt_global=1; /* optimizeglobal */
int opt_peep=1; /* optimizepeep */
int opt_schedule=0; /* nooptimizeschedule */
int opt_inline=1; /* optimizeinline */
int opt_inlocal=0; /* nooptinlocal */
int opt_loop=1; /* optloop */
int opt_size=0; /* nooptsize */
int opt_time=0; /* noopttime */
int opt_alias=0; /* nooptalias */
int opt_comp=0; /* optcomp=0 */
int opt_depth=0; /* optdepth=0 */
int opt_rdepth=0; /* optrdepth=0 */

/* Prototype */
int proto_extern=1; /* genprotoextern */
int proto_static=0; /* nogenprotostatic */
int proto_parm=0; /* nogenprotoparm */
int proto_typedef=1; /* genprototypedef */
int proto_dataitem=1; /* genprotodataitem */

/* Linker */
int lnk_smallcode=0; /* nosmallcode */
int lnk_smalldata=0; /* nosmalldata */
int lnk_addsym=0; /* noaddsym */
int lnk_stripdebug=0; /* nostripdebug */
int lnk_chkabort=1; /* chkabort */
int lnk_batch=0; /* nobatch */

/* map */
int map_hunk=0; /* nomaphunk */
int map_symbols=0; /* nomapsymbols */
int map_libraries=0; /* nomaplibraries */
int map_xref=0; /* nomapxref */
int map_overlay=0; /* nomapoverlay */
*/

/* Init() function */
void init( void )
{
	if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
	{
		EasyRequest(NULL,&miniErrorreq,0,"Can't open muimaster.library\nCheck if MUI is correctly installed\nand try again");
		exit(20);
	}
	if (!(IconBase = OpenLibrary("icon.library",37)))
	{
		EasyRequest(NULL,&miniErrorreq,0,"Can't open icon.library\n");
		exit(20);
	}
}

/* End() function */
void end( void )
{
	CloseLibrary(MUIMasterBase);
	CloseLibrary(IconBase);
#ifdef DEBUG
	ShowMemList();
	ClearMemList();
#endif
	exit(20);
}
/* GenCodeC end() end */

/* Main Function inserted by GenCodeC */
int main(int argc,char **argv)
{
	struct ObjApp * App = NULL;		/* Object */
	struct DiskObject * SCOptsPlusIcon;	/* Disk (Icon) Object */
		
	BOOL	running = TRUE;
	ULONG	signal;

	/* Program initialisation : opening libraries */
	init();

	/* Create Object : generated by GenCodeC */
	if (!(App = CreateApp()))
	{
		EasyRequest(NULL,&miniErrorreq,0,"Can't create MUI Application\n(Internal Error)");
		end();
	}

	/* open program's .icon file (if available) and use it when iconified */
	SCOptsPlusIcon = GetDiskObject(_WBArgv[0]);
	set(App->App, MUIA_Application_DiskObject,SCOptsPlusIcon);
	
	while (running)
	{
		switch (DoMethod(App->App,MUIM_Application_Input,&signal))
		{
			case MUIV_Application_ReturnID_Quit:
				running = FALSE;
				break;

			/* Insert your code between the "case" statement and comment "end of case ..." */
			/* End computing of IDCMP */
		}
		if (running && signal) Wait(signal);
	}
	DisposeApp(App);
	FreeDiskObject(SCOptsPlusIcon);
	end();
}

/* All MUI code is done! Proceed to the main program now */

/* Functions called by hooks */

/* About/MUI */
APTR __saveds h_ABOUT_MUI(struct Hook *a0, APTR MNlabel1MUI, struct ObjApp *MyApp)
{
	static APTR aboutwin;

	if(!aboutwin)
	{
		aboutwin = AboutmuiObject,
			MUIA_Window_RefWindow, MyApp->SCOPTS_MainWin,
			MUIA_Aboutmui_Application, MNlabel1MUI,
			End;
	}
	if(aboutwin)
		set(aboutwin, MUIA_Window_Open, TRUE);
	else
		DisplayBeep(0);
}

/* About/SCOptions */
APTR __saveds h_ABOUT(struct Hook *a0, APTR MNlabel1SASCOptions, struct ObjApp *MyApp)
{
	MUI_Request(MyApp->App,MyApp->SCOPTS_MainWin,0,NULL,"OK","SAS/C SCOpts+ for SAS/C v6.59+\nCopyright © 1998, Infinity Labs\nVersion 0.5\n\nProgram author: Manolis S. Pappas");
}


/* Functions called by references */
