OSErr err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(handleQuitApplication), 0, false);
int main(int argc, char **argv){#if !TARGET_CARBON    // Set up the toolbox and (if DEBUG) the console    InitializeMacToolbox();#endif    // Install an a Quit AppleEvent handler.    OSErr err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,                                      NewAEEventHandlerUPP(handleQuitApplication),                                      0, false);    NS_ASSERTION((err==noErr), "AEInstallEventHandler failed");#ifdef XP_MACOSX    // use the location of the executable to learn where everything is, this    // is because the current working directory is ill-defined when the    // application is double-clicked from the Finder.    {        char* path = strdup(argv[0]);        char* lastSlash = strrchr(path, '/');        if (lastSlash) {            *lastSlash = '\0';            setenv("MOZILLA_FIVE_HOME", path, 1);        }        free(path);    }#endif    // Start up XPCOM?    nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);    NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed");    gTheApp = new nsNativeViewerApp();    if (gTheApp != nsnull) {        NS_ADDREF(gTheApp);        if (gTheApp->Initialize(argc, argv) == NS_OK)            gTheApp->Run();        NS_RELEASE(gTheApp);    }    // Shutdown XPCOM?    rv = NS_ShutdownXPCOM(nsnull);    NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");    return 0;}