1998-10-02 06:02:32 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Objective Caml */
|
|
|
|
/* */
|
|
|
|
/* Damien Doligez, projet Para, INRIA Rocquencourt */
|
|
|
|
/* */
|
|
|
|
/* Copyright 1997 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
|
|
|
/* under the terms of the GNU Library General Public License. */
|
1998-10-02 06:02:32 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
QDGlobals qd;
|
|
|
|
int gHasDragAndDrop = 0;
|
|
|
|
int gHasPowerManager = 0;
|
|
|
|
int launch_toplevel_requested = 0;
|
|
|
|
|
|
|
|
static OSErr Initialise (void)
|
|
|
|
{
|
|
|
|
long gestval;
|
|
|
|
int i;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
SetApplLimit (GetApplLimit () - kExtraStackSpace);
|
|
|
|
MaxApplZone ();
|
|
|
|
for (i = 0; i < kMoreMasters; i++) MoreMasters ();
|
|
|
|
InitGraf (&qd.thePort);
|
|
|
|
InitFonts ();
|
|
|
|
InitWindows ();
|
|
|
|
InitMenus ();
|
|
|
|
TEInit ();
|
|
|
|
InitDialogs (nil);
|
|
|
|
InitCursor ();
|
|
|
|
FlushEvents (everyEvent, 0);
|
|
|
|
|
|
|
|
/* Unload the clipboard to disk if it's too big. */
|
|
|
|
if (InfoScrap ()->scrapSize > kScrapThreshold) UnloadScrap ();
|
|
|
|
|
|
|
|
/* Check for system 7. */
|
|
|
|
if (Gestalt (gestaltSystemVersion, &gestval) != noErr
|
|
|
|
|| gestval < kMinSystemVersion){
|
|
|
|
InitCursor ();
|
|
|
|
StopAlert (kAlertNeedSys7, NULL);
|
|
|
|
ExitToShell ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for 32-bit color QuickDraw. */
|
|
|
|
if (Gestalt (gestaltQuickdrawVersion, &gestval) != noErr
|
|
|
|
|| gestval < gestalt32BitQD){
|
|
|
|
InitCursor ();
|
|
|
|
StopAlert (kAlertNeed32BitQD, NULL);
|
|
|
|
ExitToShell ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for Drag Manager. */
|
|
|
|
if (Gestalt (gestaltDragMgrAttr, &gestval) == noErr
|
|
|
|
&& (gestval & (1 << gestaltDragMgrPresent))
|
|
|
|
&& (&NewDrag != NULL)){
|
|
|
|
gHasDragAndDrop = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for Power Manager. */
|
|
|
|
if (Gestalt (gestaltPowerMgrAttr, &gestval) == noErr
|
|
|
|
&& (gestval & (1 << gestaltPMgrExists))){
|
|
|
|
gHasPowerManager = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = InitialiseErrors ();
|
|
|
|
if (err != noErr) goto problem;
|
|
|
|
|
|
|
|
if (gHasDragAndDrop){
|
|
|
|
err = InstallDragHandlers ();
|
|
|
|
if (err != noErr) goto problem;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = InitialiseEvents ();
|
|
|
|
if (err != noErr) goto problem;
|
|
|
|
|
|
|
|
err = InitialiseMenus ();
|
|
|
|
if (err != noErr) goto problem;
|
|
|
|
|
|
|
|
err = InitialiseScroll ();
|
|
|
|
if (err != noErr) goto problem;
|
|
|
|
|
|
|
|
err = InitialiseWindows ();
|
|
|
|
if (err != noErr) goto problem;
|
|
|
|
|
|
|
|
err = InitialiseModalFilter ();
|
|
|
|
if (err != noErr) goto problem;
|
|
|
|
|
|
|
|
ReadPrefs ();
|
|
|
|
|
|
|
|
return noErr;
|
|
|
|
|
|
|
|
problem: return err;
|
|
|
|
}
|
|
|
|
|
2001-03-13 08:37:33 -08:00
|
|
|
void FinaliseAndQuit (void)
|
1998-10-02 06:02:32 -07:00
|
|
|
{
|
|
|
|
if (gHasDragAndDrop) RemoveDragHandlers ();
|
|
|
|
WritePrefs ();
|
2001-03-13 08:37:33 -08:00
|
|
|
ExitToShell ();
|
1998-10-02 06:02:32 -07:00
|
|
|
}
|
|
|
|
|
2000-04-05 11:30:22 -07:00
|
|
|
int main (void)
|
1998-10-02 06:02:32 -07:00
|
|
|
{
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
err = Initialise ();
|
2000-04-05 11:30:22 -07:00
|
|
|
if (err != noErr){
|
2001-03-13 08:37:33 -08:00
|
|
|
FinaliseAndQuit ();
|
1998-10-02 06:02:32 -07:00
|
|
|
}
|
2000-04-07 09:15:34 -07:00
|
|
|
while (!launch_toplevel_requested){
|
|
|
|
GetAndProcessEvents (waitEvent, 0, 0);
|
|
|
|
}
|
2000-04-17 13:01:40 -07:00
|
|
|
err = launch_caml_main (); /* launch bytecode interp and event loop */
|
2000-04-05 11:30:22 -07:00
|
|
|
if (err != noErr) ErrorAlertGeneric (err);
|
2001-03-13 08:37:33 -08:00
|
|
|
FinaliseAndQuit ();
|
2000-04-17 13:01:40 -07:00
|
|
|
return 0; /* not reached */
|
1998-10-02 06:02:32 -07:00
|
|
|
}
|