}
}  if (regNameAllocd) free(regName);
void main(void){    OSErr retCode;    long gestResponse;    FSSpec aliasToSelf;    EventRecord mainEventRec;    Boolean eventFlag, bDone = false;;        HREG reg;    int rv = DONE;    // initialize QuickDraw globals    InitGraf(&qd.thePort);    // initialize application globals    gQuitFlag = false;    gSleepVal = kSleepMax;    // is the Apple Event Manager available?    retCode = Gestalt(gestaltAppleEventsAttr, &gestResponse);    if (retCode == noErr &&        (gestResponse & (1 << gestaltAppleEventsPresent)) != 0)        gAppleEventsFlag = true;    else gAppleEventsFlag = false;    // install Apple event handlers    InitAppleEventsStuff();    // put an alias to ourselves in the Startup Items folder    // so that if we are shutdown before finishing we do our     // tasks at startup    FSMakeFSSpec(0, 0, "\p", &aliasToSelf);  // initialize    PutAliasInStartupItems(&aliasToSelf);        if ( REGERR_OK == NR_StartupRegistry())    {        if ( REGERR_OK == NR_RegOpen("", &reg) )        {            // main event loop            while (!gQuitFlag)            {                eventFlag = WaitNextEvent(everyEvent, &mainEventRec, gSleepVal, nil);                if (mainEventRec.what == kHighLevelEvent)                    DoHighLevelEvent(&mainEventRec);                rv = PerformScheduledTasks(reg);                if (rv == DONE)                {                    bDone = true;                    gQuitFlag = true;                }            }                        NR_ShutdownRegistry();        }          }        // clean up the alias to ouselves since we have     // completed our tasks successfully    if (bDone)        RemoveAliasFromStartupItems(&aliasToSelf);}