home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-02-24 | 4.6 KB | 219 lines | [TEXT/PJMM] |
- program Main;
-
- { This code is part of the Finger/Fingerd source code, written in THINK Pascal 4 }
- { Copyright 1991-1992 Peter N Lewis }
- { If you use this code, you must give me credit in your about box and documentation }
-
- uses
- OOMainLoop, OOMenus, MyNotifier, MyAppleEvents, TCPConnections, MyHandleQuitBoth,{}
- FingerDaemon, MyInternetMenu, Fingers, MyGrowZones, Preferences, MyPrinting, MyTEPrinting;
-
- var
- launched_with_option: boolean;
-
- function DoOApp: OSErr;
- begin
- DoOApp := noErr;
- end;
-
- function DoODoc (fs: FSSpec): OSErr;
- var
- pb: CInfoPBRec;
- oe: OSErr;
- begin
- GetPreferences(fs.vRefNum, fs.parID, fs.name);
- DoODoc := noErr;
- end;
-
- function DoQuit: OSErr;
- begin
- DoCommand(0, 0, Cquit);
- DoQuit := noErr;
- end;
-
- procedure UnloadAll;
- begin
- UnloadSeg(@SegmentInit);
- UnloadSeg(@SegmentUtil);
- UnloadSeg(@SegmentUtil2);
- UnloadSeg(@SegmentSystem7);
- UnloadSeg(@SegmentTerm);
- UnloadSeg(@SegmentMFS);
- UnloadSeg(@SegmentMFSByte);
- UnloadSeg(@SegmentPrefs);
- UnloadSeg(@SegmentPrinting);
- end;
-
- procedure SetFingerMenu (themenu, theitem: integer);
- var
- t, c: longInt;
- begin
- PurgeSpace(t, c);
- SetIDItemEnable(themenu, theitem, (t > 12000) and (c > 6000));
- end;
-
- procedure SetPrintMenu (themenu, theitem: integer);
- begin
- SetIDItemEnable(themenu, theitem, IsFingerWindow(FrontWindow));
- end;
-
- procedure SetGoodPort;
- var
- wmgrportP: ^grafptr;
- begin
- if FrontWindow <> nil then
- SetPort(FrontWindow)
- else begin
- wmgrportP := POINTER($9DE);
- Setport(wmgrportP^);
- end;
- end;
-
- function HandleMainEvents (var er: eventRecord): boolean;
- var
- b: boolean;
- fw: windowPtr;
- begin
- SetGoodPort;
- if SetOOMenuBar then
- DrawMenuBar;
- if in_foreground then
- NotifyCompletion;
- fw := FrontWindow;
- b := GetWObject(fw).WaitForEvent(er, 10);
- b := GetWObject(fw).HandleEvents(er);
- SetGoodPort;
- HandleMainEvents := b;
- end;
-
- procedure MyDoFMenu (themenu, theitem: integer);
- var
- s: str255;
- begin
- giveOoMerror := true;
- case themenu of
- M_InternetTo: begin
- DoFingerCommand(GetInternetCommand(themenu, theitem));
- HiliteMenu(0);
- end;
- M_RemoveTo: begin
- RemoveInternetCommand(themenu, theitem);
- HiliteMenu(0);
- end;
- otherwise
- DoFMenu(themenu, theitem);
- end;
- end;
-
- var
- pob: TEPObject;
-
- procedure MyPrint;
- begin
- UnloadAll;
- pob.te := GetFingerTE(FrontWindow);
- PrintStuff(pob, thePrintingRecordHandle);
- end;
-
- procedure MyPageSetup;
- begin
- DoPageSetup(pob, thePrintingRecordHandle);
- end;
-
- function StackPtr: longInt;
- inline
- $2E8F;
-
- const
- gestaltMacTCPAttr = 'mtcp';
-
- var
- er: eventRecord;
- paramCount, paramMessage: integer;
- af: appFile;
- oe: OSErr;
- dummyb: boolean;
- mainloop_dobj: DefObject;
- a, i: integer;
- appllimitP: ^longInt;
- gv: longInt;
- begin
- applLimitP := POINTER($130);
- applLimitP^ := StackPtr - 12000;
- { SetApplLimit(ptr(StackPtr - 5000));}
- MaxApplZone;
- InitGrowZone(outofmem_alert_id);
- if MemoryCritical then begin
- a := Alert(outofmem_alert_id, nil);
- halt;
- end;
- giveOoMerror := true;
- dummyb := GetOSEvent(0, er);
- launched_with_option := BAND(er.modifiers, optionKey) <> 0;
- InitNotify;
- InitUtilities;
- if not has_AppleEvents then begin
- CountAppFiles(paramMessage, paramCount);
- if paramMessage <> appOpen then { Must be Open, not Print! }
- begin
- FailAlert('Sorry, I can''t print ', 0);
- halt;
- end;
- for i := 1 to paramCount do begin
- GetAppFiles(i, af);
- with af do
- if fType = myAppType then begin
- GetPreferences(vRefNum, 0, fName);
- ClrAppFiles(i);
- end;
- end;
- end
- else
- oe := InitAppleEvents(@DoOApp, @DoODoc, nil, @DoQuit);
- oe := InitConnections('Hosts');
- if oe <> noErr then begin
- FailAlert('TCP Initialize failed with ', oe);
- halt;
- end;
- new(mainloop_dobj);
- InitMainLoop(DObject(mainloop_dobj), @MyDoFMenu);
- InitOOMenus(nil, GetGlobalString(help_menu_text));
- InitPrinting;
- new(pob);
- pob.Create;
- InitPreferences;
- InitQuitBoth('PLFD');
- SetFBoth(Cfinger, @Finger, @SetFingerMenu);
- SetFSetMenu(CXInternet, @SetXMenu);
- SetFSetMenu(CXRemove, @SetXMenu);
- SetFCommand(CPageSetup, @MyPageSetup);
- SetFBoth(Cprint, @MyPrint, @SetPrintMenu);
- InitCursor;
- oe := Gestalt(gestaltMacTCPAttr, gv);
- has_MacTCP11 := (oe = noErr) and (gv >= 1);
- InitInternetMenu;
- InitFingers;
-
- if prefs.autoopen then
- Finger;
- while not quitNow do begin
- UnloadAll;
- GrowZoneIdle;
- IdleFingers;
- dummyb := HandleMainEvents(er);
- HandleFingerTCPEvents;
- if quitNow then
- quitNow := not FinishPreferences;
- end;
-
- pob.Destroy;
- FinishPrinting;
- FinishFingers;
- FinishInternetMenu;
- FinishQuitBoth;
- FinishOOmenus;
- FinishMainLoop;
- FinishEverything; { buggers up the resources for some god forsaken reason }
- FinishNotify;
- FinishGrowZone;
- end.