Source/main.c

/*************************************************************************************
#
#       main.c
#
#       This is the main entry point.
#
#       Author(s):  Michael Marinkovich & Guillermo Ortiz
#                   marink@apple.com
#
#       Modification History: 
#
#           4/3/96      MWM     Initial coding                   
#
#       Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
#
#
#       You may incorporate this sample code into your applications without
#       restriction, though the sample code has been provided "AS IS" and the
#       responsibility for its operation is 100% yours.  However, what you are
#       not permitted to do is to redistribute the source as "DSC Sample Code"
#       after having made changes. If you're going to re-distribute the source,
#       we require that you make it clear in the source that the code was
#       descended from Apple Sample Code, but that you've made changes.
#
*************************************************************************************/
 
#include <ConditionalMacros.h>
#if OLDROUTINELOCATIONS
    #include <SegLoad.h>
#else
    #include <Processes.h>
#endif
#include <Resources.h>
#include <ToolUtils.h>
 
#include "App.h"
#include "Global.h"
#include "Proto.h"
 
 
 
//----------------------------------------------------------------------
//
//  main - main entry point of our program
//
//
//----------------------------------------------------------------------
 
void main(void)
{
    OSErr           err;
    short           m = 5;
        
    MaxApplZone();
    
    for (;m == 0;m--)               // alloc the master pointers
    {
        MoreMasters();
    }
    
    err = Initialize();
    
    EventLoop();
        
    ExitToShell();
 
}
 
 
//----------------------------------------------------------------------
//
//  HandleError - basic error notification procedure
//
//
//----------------------------------------------------------------------
 
void HandleError(short errNo,Boolean fatal)
{
    DialogPtr           errDialog;
    short               itemHit;
    short               c;
    Handle              button;
    short               itemType;
    Rect                itemRect;
    StringHandle        errString;
    Str255              numString;
    GrafPtr             oldPort;
    
    GetPort(&oldPort);
    SysBeep(30);
    SetCursor(&qd.arrow);
    
    errDialog = GetNewDialog(rErrorDlg, nil, (WindowPtr) -1);
    if (errDialog != nil) 
    {
        ShowWindow(errDialog);
        SetPort(errDialog);
        SetGWorld((CGrafPtr)errDialog, nil);
        PenPat(&qd.gray);                               // frame user areas
        
        for (c = 7;c < 9;c++) 
        {
            GetDItem(errDialog,c,&itemType,&button,&itemRect);
            FrameRect(&itemRect);
        }
        PenPat(normal);
 
        GetDItem( errDialog, fatal ? 2 : 1, &itemType, &button, &itemRect );
        HiliteControl( (ControlHandle)button, 255);      // unhilite appropriate button
        
        SetDialogDefaultItem(errDialog,fatal  ? 1 : 2);
        
        NumToString( errNo, numString );
        if ( errNo < 0 )
            errNo = -errNo + 200;
            
        errString = GetString( 128 + errNo );
        
        if ( errString == nil )
                errString = GetString( 128 );
        
        DetachResource((Handle)errString);
        HLock((Handle)errString);
        ParamText( numString, *errString, nil, nil );
        HUnlock((Handle)errString);
        DisposeHandle((Handle)errString);
        
        ModalDialog( nil, &itemHit );
        
        SetPort( oldPort );
 
        DisposeDialog( errDialog );
    }
    else
        ExitToShell();      // since didn't have mem to open dialog assume the worst
            
    if (fatal) 
        ExitToShell();      //  it's a bad one, get out of here
    
}
 
 
//----------------------------------------------------------------------
//
//  HandleAlert - display alert and then exit to shell
//
//
//----------------------------------------------------------------------
 
void HandleAlert(short alertID)
{
    short           item;
    
    
    item = Alert(alertID, nil);
    ExitToShell();
 
}