home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-04-20 | 3.8 KB | 171 lines | [TEXT/PJMM] |
- program Main;
-
- { This program was written by Peter N Lewis, Mar 1992 in THINK Pascal 4.0.1 }
- { To compile it you will need the System 7 versions of the Interface files }
- { You may use this source in your own free/shareware projects as long as you acknowledge me }
- { in your About box and documentation files. You may include it in commercial products }
- { only if I explicitly allow it. }
-
- uses
- OOMainLoop, OOMenus, MyFMenus, OOStatus, MyAppleEvents, MySystem7, PrefsGlobals, Preferences, MyNotifier, {}
- TCPConnections, UDPStuff, Talks, TalkUtils, TalkInput, MyInternetMenu, MyHandleQuitBoth,{}
- MyUtils, BaseGlobals, MyFileSystem, MyUtilities, AppGlobals, TalkTos;
-
- 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);
- end;
-
- var
- fingerd_cp: connectionIndex;
-
- procedure SetTalkMenu (themenu, theitem: integer);
- var
- t, c: longInt;
- begin
- PurgeSpace(t, c);
- SetIDItemEnable(themenu, theitem, (t > 12000) and (c > 6000));
- end;
-
- function HandleMainEvents (var er: eventRecord): boolean;
- var
- b: boolean;
- fo: WObject;
- begin
- if SetOOMenuBar then
- DrawMenuBar;
- NotifyIdle(in_foreground);
- fo := FrontObject;
- b := fo.WaitForEvent(er, 10);
- b := fo.HandleEvents(er);
- HandleMainEvents := b;
- end;
-
- procedure MyDoFMenu (themenu, theitem: integer);
- var
- s: str255;
- begin
- case themenu of
- M_InternetTo: begin
- TalkTo(GetInternetCommand(themenu, theitem));
- HiliteMenu(0);
- end;
- M_RemoveTo: begin
- RemoveInternetCommand(themenu, theitem);
- HiliteMenu(0);
- end;
- otherwise
- DoFMenu(themenu, theitem);
- end;
- end;
-
- var
- er: eventRecord;
- s, s1, s2: str255;
- sh: stringHandle;
- paramCount, paramMessage, i: integer;
- af: appFile;
- doparams: boolean;
- oe: OSErr;
- dummyb: boolean;
- cer: connectionEventRecord;
- rfcn, size: longInt;
- cp: connectionIndex;
- dlg: dialogPtr;
- mainloop_dobj: DObject;
- begin
- 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);
- new(mainloop_dobj);
- InitMainLoop(mainloop_dobj, @MyDoFMenu);
- InitOOMenus(nil, GetGlobalString(help_menu_text));
- InitPreferences;
- InitQuitBoth('Tokd');
- SetFBoth(Ctalk, @Talk, @SetTalkMenu);
- InitCursor;
- oe := UDPInit;
- oe := InitConnections('');
- if oe = noErr then
- oe := TCPGetMyIPAddr(my_machine_addr);
- if oe <> noErr then begin
- FailAlert('TCP Initialize failed with ', oe);
- halt;
- end;
- InitOOStatus(@HandleStatusCommand);
- InitTalks;
- InitTalkInput;
- InitInternetMenu;
-
- if prefs.auto_talk then
- Talk;
-
- while not quitNow do begin
- UnloadAll;
- dummyb := HandleMainEvents(er);
- HandleEvents;
- if quitNow then
- quitNow := not FinishPreferences;
- end;
-
- FinishInternetMenu;
- FinishTalkInput;
- FinishTalks;
- FinishOOStatus;
- FinishQuitBoth;
- FinishEverything;
- UDPFinish;
- FinishOOmenus;
- FinishMainLoop;
- FinishNotify;
- end.