BAXTER_A@wehi.dn.mu.oz (02/23/90)
/* EXAMPLE STARTUP CODE: This code will start a program from cli or wb with arguments, send error messages as allerts, open the largest screen possible, default to PAL in Australia or NTSC in US if workbench is closed, find the location in the filing system of itself and the project filename it was started with, and make the coffee. */ #include <exec/exec.h> #include <exec/types.h> #include <intuition/intuitionbase.h> #include <stdio.h> #include <workbench/startup.h> #include <workbench/workbench.h> #include <workbench/icon.h> #include <math.h> struct IntuitionBase *IntuitionBase; /* Pointer aus exec */ struct GfxBase *GfxBase; struct DiskfontBase *DiskfontBase; long IconBase; int MAXVERT=512; /* Globally declared int replaces #define to allow */ /* switches in screen size for Australia Vs USA */ int MAXHORIZ=640; extern struct Screen *screen; extern struct NewScreen newscreen; extern struct NewWindow newwindow; #define QUIT 0 #define GO 1 #define OFF 0 #define ON 1 int Overscan=ON; /* Overscan flag can be turned off at start */ /* closes the screen when "New" is selected. */ char filename[150]; char progname[150]; struct RastPort *p; char StartDir[150]; main(argc,argv) int argc; union { char **args; struct WBStartup *msg; } argv; { struct WBArg *arg; int x=0,y=0; int terse=TRUE, fpal=1; FILE *fp; char **ToolArray; char *Value; struct IntuiMessage *p_message; /* pointer to message */ struct DiskObject *diskobj; void ProcMes(); filename[0] = 0; /*** OPEN LIBRARIES ***/ if (!(IconBase = OpenLibrary("icon.library", ErrorAlert(1); sexit(FALSE); } FFPLARGE = 1.0e10; FFPSMALL = 1.0e-10; DiskfontBase = (struct DiskfontBase *) OpenLibrary("diskfont.library",0); if( DiskfontBase == NULL ) { ErrorAlert(2); sexit(FALSE); } GfxBase=NULL; GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",33); if(GfxBe == NULL) { ErrorAlert(3); sexit (FALSE); } /*** PARSE ARGS ***/ if (argc != 0) { /* called from CLI */ stcgfp(StartDir,argv.args[0]); if (argc>1) { if (argv.args[argc-1][0] == '?') { printf("usage: Programname [f if (argv.args[argc-1][0] != '-') { strcpy(filename,argv.args[argc-1]); strcpy(Gadget4SIBuff,filename); } if (argv.args[1][0] == '-') { if ((agv.args[1][1] == 'O')||(argv.args[1][1]=='o')) { Overscan=OFF; } } } } else { /* called from workbench */ arg = argv.msg->sm_Argves */ if (arg->wa_Lock != NULL) { getpath(arg->wa_Lock,StartDir); if (isdev(StartDir)) strcat(StartDir,":"); } else stcgfp(StartDir,arg->wa_Name); arg++; if (argv.msg->sm_NumArgs > 1) { /* find where data es */ getpath(arg->wa_Lock,Gadget4SIBuff); if (isdev(Gadget4SIBuff)) strcat(Gadget4SIBuff,":"); strmfp(Gadget4SIBuff,Gadget4SIBuff,agramname"); /* CHECK IF OVERSCAN IS NOT WANTED */ if (diskobj=GetDiskObject(progname)) { ToolArray=diskobj->do_ToolTypes; Value=FindToolType(ToolArray,"OVERSCAN"); if (MatchToolValue(Value,"OFF")) {Overscan=OFFeeDiskObject(diskobj); } } /* SORT OUT DEFAULT SCREEN SIZING */ IntuitionBase=NULL; IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",33); /* PAL Revision */ if (IntuitionBase == NULL) { fpal=0ionBase = (sttionBase *)OpenLibrary("intuition.library",0); if(IntuitionBase == NULL) { ErrorAlert(4); sexit(FALSE); if ((Overscan==ON)&&(ScreenSize(&x,&y))) /* Will try to get maximum screen size from WorkBench */ { MAXVERT = y; MAXHORIZ = x; newscreen.Height=y; newscreen.Width=x; newwindow.Height=y; newwindow.Width=x; } else FROM SETPAL_NTSC *******/ if (fpal > 0) { if (! ( (GfxBase->DisplayFlags) & PAL ) ) fpal=0; } if (fpal == 0) { MAXVERT=400; newscreen.Heightight=400; } } if (!(screen = (struct Screen *)OpenScreen(&newscreen))) { ErrorAlert(0); sexit(FLSE); (IconBase) CloseLibrnBase); if (IntuitionBase) CloseLibrary(IntuitionBase); if (GfxBase) CloseLibrary(GfxBase); if (DiskfontBase) CloseLibrary(DiskfontBase); exit(Err); } ScreenSize(x,y) int *x; int *y; { struct Screen *WBScreen; int result; WBScreen = (struct Screen *)AllocMem(sizeof(struct Screen),MEMF_CLEAR); result = GetScreenData(WBScreen,sizeof(struct Screen),WBENCHSCREEN,NULL); *x=WBScreen->Width; if (WBScreen->Height > 300) *y=WBScreen->Height; /* if wb is interlace */ else *y=2*(WBScreen->Height); /* RETURNS SIZE FOR INTERLACE SCREEN */ FreeMem(WBScreen,sizeof(struct Screen)); e MESSAGE_HEIGHT 63 UBYTE ErrorMessage[][100] = { "\x00\xCC\x14Hot Damn! You need more ram!\x00\xFF\x00\xAC\x22Please Click Left Mouse Button to Quit\x "\x00\xCC\x14I can't open the Icon Library\x00\xFF\x00\xAC\x22Please Click Left Mouse Button to Quit\x00", "\x00\xCC\x14I can't open Diskfont Library\x00\xFF\x00\xAC\x22Please Click Left Mouse Button to Quit\x00", "\x00\xCC\x14I can't open Graphics Library\x00\xFF\x00\xAC\x22Please Click Left Mouse Button to Quit\x00", "\x00\xCC\x14I can't open Intuition Library\x00\xFF\x00\xAC\x22Please Click Left Mouse Button to Quit\x00", "\x00\xCC\x14 Can't open the Message Window\x00\xFF\x00\xAC\x22 Click Left Mouse Button to Continue\x00" }; VOID ErrorAlert(error_number) int error_number; { (VOID )DisplayAlert(RECOVERY_ALERT,ErrorMessage[error_number],MESSAGE_HEIGHT); }