]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - mac/mac.c
Minimal shell of PuTTYgen for Mac. No actual PuTTYgen-specific code there
[PuTTY.git] / mac / mac.c
1 /* $Id: mac.c,v 1.48 2003/02/12 23:53:15 ben Exp $ */
2 /*
3  * Copyright (c) 1999 Ben Harris
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or
11  * sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following
13  * conditions:
14  * 
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  * 
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  */
27 /*
28  * mac.c -- miscellaneous Mac-specific routines
29  */
30
31 #include <MacTypes.h>
32 #include <AEDataModel.h>
33 #include <AppleEvents.h>
34 #include <Quickdraw.h>
35 #include <Fonts.h>
36 #include <MacWindows.h>
37 #include <Menus.h>
38 #include <TextEdit.h>
39 #include <Appearance.h>
40 #include <CodeFragments.h>
41 #include <Dialogs.h>
42 #include <Devices.h>
43 #include <DiskInit.h>
44 #include <Gestalt.h>
45 #include <LowMem.h>
46 #include <Navigation.h>
47 #include <Resources.h>
48 #include <Script.h>
49 #include <TextCommon.h>
50 #include <ToolUtils.h>
51 #include <UnicodeConverter.h>
52
53 #include <assert.h>
54 #include <limits.h>
55 #include <stdarg.h>
56 #include <stdlib.h>             /* putty.h needs size_t */
57 #include <stdio.h>              /* for vsprintf */
58
59 #define PUTTY_DO_GLOBALS
60
61 #include "macresid.h"
62 #include "putty.h"
63 #include "ssh.h"
64 #include "mac.h"
65
66 Session *sesslist;
67
68 static int cold = 1;
69 static int borednow = FALSE;
70 struct mac_gestalts mac_gestalts;
71
72 static void mac_startup(void);
73 static void mac_eventloop(void);
74 #pragma noreturn (mac_eventloop)
75 static void mac_event(EventRecord *);
76 static void mac_contentclick(WindowPtr, EventRecord *);
77 static void mac_growwindow(WindowPtr, EventRecord *);
78 static void mac_activatewindow(WindowPtr, EventRecord *);
79 static void mac_activateabout(WindowPtr, EventRecord *);
80 static void mac_updatewindow(WindowPtr);
81 static void mac_updatelicence(WindowPtr);
82 static void mac_keypress(EventRecord *);
83 static int mac_windowtype(WindowPtr);
84 static void mac_menucommand(long);
85 static void mac_openabout(void);
86 static void mac_openlicence(void);
87 static void mac_adjustcursor(RgnHandle);
88 static void mac_adjustmenus(void);
89 static void mac_closewindow(WindowPtr);
90 static void mac_zoomwindow(WindowPtr, short);
91 #pragma noreturn (cleanup_exit)
92
93 struct mac_windows {
94     WindowPtr about;
95     WindowPtr licence;
96 };
97
98 struct mac_windows windows;
99
100 int main (int argc, char **argv) {
101
102     mac_startup();
103     mac_eventloop();
104 }
105
106 #pragma noreturn (main)
107
108 static void mac_startup(void) {
109     Handle menuBar;
110     TECInfoHandle ti;
111
112 #if !TARGET_API_MAC_CARBON
113     /* Init Memory Manager */
114     MaxApplZone();
115     /* Init QuickDraw */
116     InitGraf(&qd.thePort);
117     /* Init Font Manager */
118     InitFonts();
119     /* Init Window Manager */
120     InitWindows();
121     /* Init Menu Manager */
122     InitMenus();
123     /* Init TextEdit */
124     TEInit();
125     /* Init Dialog Manager */
126     InitDialogs(NULL);
127 #endif
128     cold = 0;
129     
130     /* Get base system version (only used if there's no better selector) */
131     if (Gestalt(gestaltSystemVersion, &mac_gestalts.sysvers) != noErr ||
132         (mac_gestalts.sysvers &= 0xffff) < 0x700)
133         fatalbox("PuTTY requires System 7 or newer");
134     /* Find out if we've got Color Quickdraw */
135     if (Gestalt(gestaltQuickdrawVersion, &mac_gestalts.qdvers) != noErr)
136         mac_gestalts.qdvers = gestaltOriginalQD;
137     /* ... and the Appearance Manager? */
138     if (Gestalt(gestaltAppearanceVersion, &mac_gestalts.apprvers) != noErr)
139         if (Gestalt(gestaltAppearanceAttr, NULL) == noErr)
140             mac_gestalts.apprvers = 0x0100;
141         else
142             mac_gestalts.apprvers = 0;
143 #if TARGET_RT_MAC_CFM
144     /* Paranoia: Did we manage to pull in AppearanceLib? */
145     if (&RegisterAppearanceClient == kUnresolvedCFragSymbolAddress)
146         mac_gestalts.apprvers = 0;
147 #endif
148 #if TARGET_CPU_68K
149     mac_gestalts.cntlattr = 0;
150     mac_gestalts.windattr = 0;
151 #else
152     /* Mac OS 8.5 Control Manager (proportional scrollbars)? */
153     if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr ||
154         &SetControlViewSize == kUnresolvedCFragSymbolAddress)
155         mac_gestalts.cntlattr = 0;
156     /* Mac OS 8.5 Window Manager? */
157     if (Gestalt(gestaltWindowMgrAttr, &mac_gestalts.windattr) != noErr ||
158         &SetWindowContentColor == kUnresolvedCFragSymbolAddress)
159         mac_gestalts.windattr = 0;
160 #endif
161     /* Text Encoding Conversion Manager? */
162     if (
163 #if TARGET_RT_MAC_CFM
164         &TECGetInfo == kUnresolvedCFragSymbolAddress ||
165 #else
166         InitializeUnicodeConverter(NULL) != noErr ||
167 #endif
168         TECGetInfo(&ti) != noErr)
169         mac_gestalts.encvvers = 0;
170     else {
171         mac_gestalts.encvvers = (*ti)->tecVersion;
172         mac_gestalts.uncvattr = (*ti)->tecUnicodeConverterFeatures;
173         DisposeHandle((Handle)ti);
174     }
175     /* Navigation Services? */
176     if (NavServicesAvailable())
177         mac_gestalts.navsvers = NavLibraryVersion();
178     else
179         mac_gestalts.navsvers = 0;
180
181     sk_init();
182
183     /* We've been tested with the Appearance Manager */
184     if (mac_gestalts.apprvers != 0)
185         RegisterAppearanceClient();
186
187     menuBar = GetNewMBar(128);
188     if (menuBar == NULL)
189         fatalbox("Unable to create menu bar.");
190     SetMenuBar(menuBar);
191     AppendResMenu(GetMenuHandle(mApple), 'DRVR');
192     mac_adjustmenus();
193     DrawMenuBar();
194     InitCursor();
195     windows.about = NULL;
196     windows.licence = NULL;
197
198     default_protocol = be_default_protocol;
199     /* Find the appropriate default port. */
200     {
201         int i;
202         default_port = 0; /* illegal */
203         for (i = 0; backends[i].backend != NULL; i++)
204             if (backends[i].protocol == default_protocol) {
205                 default_port = backends[i].backend->default_port;
206                 break;
207             }
208     }
209     flags = FLAG_INTERACTIVE;
210
211 #if !TARGET_API_MAC_CARBON
212     {
213         short vol;
214         long dirid;
215
216         /* Set the default directory for loading and saving settings. */
217         /* XXX Should we create it? */
218         if (get_session_dir(FALSE, &vol, &dirid) == noErr) {
219             LMSetSFSaveDisk(-vol);
220             LMSetCurDirStore(dirid);
221         }
222     }
223 #endif
224
225     /* Install Apple Event handlers. */
226     AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
227                           NewAEEventHandlerUPP(&mac_aevt_oapp), 0, FALSE);
228     AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
229                           NewAEEventHandlerUPP(&mac_aevt_odoc), 0, FALSE);
230     AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
231                           NewAEEventHandlerUPP(&mac_aevt_pdoc), 0, FALSE);
232     AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
233                           NewAEEventHandlerUPP(&mac_aevt_quit), 0, FALSE);
234 }
235
236 static void mac_eventloop(void) {
237     Boolean gotevent;
238     EventRecord event;
239     RgnHandle cursrgn;
240
241     cursrgn = NewRgn();
242     for (;;) {
243         mac_adjustcursor(cursrgn);
244         gotevent = WaitNextEvent(everyEvent, &event, LONG_MAX, cursrgn);
245         mac_adjustcursor(cursrgn);
246         if (gotevent)
247             mac_event(&event);
248         if (borednow)
249             cleanup_exit(0);
250         sk_poll();
251         mac_pollterm();
252     }
253     DisposeRgn(cursrgn);
254 }
255
256 static void mac_event(EventRecord *event) {
257     short part;
258     WindowPtr window;
259
260     switch (event->what) {
261       case mouseDown:
262         part = FindWindow(event->where, &window);
263         switch (part) {
264           case inMenuBar:
265             mac_adjustmenus();
266             mac_menucommand(MenuSelect(event->where));
267             break;
268 #if !TARGET_API_MAC_CARBON
269           case inSysWindow:
270             SystemClick(event, window);
271             break;
272 #endif
273           case inContent:
274             if (window != FrontWindow())
275                 /* XXX: check for movable modal dboxes? */
276                 SelectWindow(window);
277             else
278                 mac_contentclick(window, event);
279             break;
280           case inGoAway:
281             if (TrackGoAway(window, event->where))
282                 mac_closewindow(window);
283             break;
284           case inDrag:
285             /* XXX: moveable modal check? */
286 #if TARGET_API_MAC_CARBON
287             {
288                 BitMap screenBits;
289
290                 GetQDGlobalsScreenBits(&screenBits);
291                 DragWindow(window, event->where, &screenBits.bounds);
292             }
293 #else
294             DragWindow(window, event->where, &qd.screenBits.bounds);
295 #endif
296             break;
297           case inGrow:
298             mac_growwindow(window, event);
299             break;
300           case inZoomIn:
301           case inZoomOut:
302             if (TrackBox(window, event->where, part))
303                 mac_zoomwindow(window, part);
304             break;
305         }
306         break;
307       case keyDown:
308       case autoKey:
309         mac_keypress(event);
310         break;
311       case activateEvt:
312         mac_activatewindow((WindowPtr)event->message, event);
313         break;
314       case updateEvt:
315         mac_updatewindow((WindowPtr)event->message);
316         break;
317 #if !TARGET_API_MAC_CARBON
318       case diskEvt:
319         if (HiWord(event->message) != noErr) {
320             Point pt;
321
322             SetPt(&pt, 120, 120);
323             DIBadMount(pt, event->message);
324         }
325         break;
326 #endif
327       case kHighLevelEvent:
328         AEProcessAppleEvent(event); /* errors? */
329         break;
330     }
331 }
332
333 static void mac_contentclick(WindowPtr window, EventRecord *event) {
334     short item;
335     DialogRef dialog;
336
337     switch (mac_windowtype(window)) {
338       case wTerminal:
339         mac_clickterm(window, event);
340         break;
341       case wAbout:
342         dialog = GetDialogFromWindow(window);
343         if (DialogSelect(event, &dialog, &item))
344             switch (item) {
345               case wiAboutLicence:
346                 mac_openlicence();
347                 break;
348             }
349         break;
350       case wSettings:
351         mac_clickdlg(window, event);
352         break;
353       case wEventLog:
354         mac_clickeventlog(window, event);
355         break;
356     }
357 }
358
359 static void mac_growwindow(WindowPtr window, EventRecord *event) {
360
361     switch (mac_windowtype(window)) {
362       case wTerminal:
363         mac_growterm(window, event);
364         break;
365       case wEventLog:
366         mac_groweventlog(window, event);
367         break;
368     }
369 }
370
371 static void mac_activatewindow(WindowPtr window, EventRecord *event) {
372     int active;
373
374     active = (event->modifiers & activeFlag) != 0;
375     mac_adjustmenus();
376     switch (mac_windowtype(window)) {
377       case wTerminal:
378         mac_activateterm(window, active);
379         break;
380       case wSettings:
381         mac_activatedlg(window, event);
382         break;
383       case wAbout:
384         mac_activateabout(window, event);
385         break;
386       case wEventLog:
387         mac_activateeventlog(window, event);
388         break;
389     }
390 }
391
392 static void mac_activateabout(WindowPtr window, EventRecord *event) {
393     DialogRef dialog;
394     DialogItemType itemtype;
395     Handle itemhandle;
396     short item;
397     Rect itemrect;
398     int active;
399
400     dialog = GetDialogFromWindow(window);
401     active = (event->modifiers & activeFlag) != 0;
402     GetDialogItem(dialog, wiAboutLicence, &itemtype, &itemhandle, &itemrect);
403     HiliteControl((ControlHandle)itemhandle, active ? 0 : 255);
404     DialogSelect(event, &dialog, &item);
405 }
406
407 static void mac_updatewindow(WindowPtr window)
408 {
409 #if TARGET_API_MAC_CARBON
410     RgnHandle rgn;
411 #endif
412
413     switch (mac_windowtype(window)) {
414       case wTerminal:
415         mac_updateterm(window);
416         break;
417       case wAbout:
418       case wSettings:
419         BeginUpdate(window);
420 #if TARGET_API_MAC_CARBON
421         rgn = NewRgn();
422         GetPortVisibleRegion(GetWindowPort(window), rgn);
423         UpdateDialog(GetDialogFromWindow(window), rgn);
424         DisposeRgn(rgn);
425 #else
426         UpdateDialog(window, window->visRgn);
427 #endif
428         EndUpdate(window);
429         break;
430       case wLicence:
431         mac_updatelicence(window);
432         break;
433       case wEventLog:
434         mac_updateeventlog(window);
435         break;
436     }
437 }
438
439 static void mac_updatelicence(WindowPtr window)
440 {
441     Handle h;
442     int len;
443     long fondsize;
444     Rect textrect;
445
446     SetPort((GrafPtr)GetWindowPort(window));
447     BeginUpdate(window);
448     fondsize = GetScriptVariable(smRoman, smScriptSmallFondSize);
449     TextFont(HiWord(fondsize));
450     TextSize(LoWord(fondsize));
451     h = Get1Resource('TEXT', wLicence);
452     len = GetResourceSizeOnDisk(h);
453 #if TARGET_API_MAC_CARBON
454     GetPortBounds(GetWindowPort(window), &textrect);
455 #else
456     textrect = window->portRect;
457 #endif
458     if (h != NULL) {
459         HLock(h);
460         TETextBox(*h, len, &textrect, teFlushDefault);
461         HUnlock(h);
462     }
463     EndUpdate(window);
464 }
465
466 /*
467  * Work out what kind of window we're dealing with.
468  */
469 static int mac_windowtype(WindowPtr window)
470 {
471
472 #if !TARGET_API_MAC_CARBON
473     if (GetWindowKind(window) < 0)
474         return wDA;
475 #endif
476     return ((WinInfo *)GetWRefCon(window))->wtype;
477 }
478
479 /*
480  * Handle a key press
481  */
482 static void mac_keypress(EventRecord *event) {
483     WindowPtr window;
484
485     window = FrontWindow();
486     /*
487      * Check for a command-key combination, but ignore it if it counts
488      * as a meta-key combination and we're in a terminal window.
489      */
490     if (event->what == keyDown && (event->modifiers & cmdKey) /*&&
491         !((event->modifiers & cfg.meta_modifiers) == cfg.meta_modifiers &&
492             mac_windowtype(window) == wTerminal)*/) {
493         mac_adjustmenus();
494         mac_menucommand(MenuKey(event->message & charCodeMask));
495     } else {
496         switch (mac_windowtype(window)) {
497           case wTerminal:
498             mac_keyterm(window, event);
499             break;
500         }
501     }       
502 }
503
504 static void mac_menucommand(long result) {
505     short menu, item;
506     WindowPtr window;
507 #if !TARGET_API_MAC_CARBON
508     Str255 da;
509 #endif
510
511     menu = HiWord(result);
512     item = LoWord(result);
513     window = FrontWindow();
514     /* Things which do the same whatever window we're in. */
515     switch (menu) {
516       case mApple:
517         switch (item) {
518           case iAbout:
519             mac_openabout();
520             goto done;
521 #if !TARGET_API_MAC_CARBON
522           default:
523             GetMenuItemText(GetMenuHandle(mApple), item, da);
524             OpenDeskAcc(da);
525             goto done;
526 #endif
527         }
528         break;
529       case mFile:
530         switch (item) {
531           case iNew:
532             mac_newsession();
533             goto done;
534           case iOpen:
535             mac_opensession();
536             goto done;
537           case iClose:
538             mac_closewindow(window);
539             goto done;
540           case iSave:
541             mac_savesession();
542             goto done;
543           case iSaveAs:
544             mac_savesessionas();
545             goto done;
546           case iDuplicate:
547             mac_dupsession();
548             goto done;
549           case iQuit:
550             cleanup_exit(0);
551             goto done;
552         }
553         break;
554     }
555     /* If we get here, handling is up to window-specific code. */
556     switch (mac_windowtype(window)) {
557       case wTerminal:
558         mac_menuterm(window, menu, item);
559         break;
560     }
561   done:
562     HiliteMenu(0);
563 }
564
565 static void mac_openabout(void) {
566     DialogItemType itemtype;
567     Handle item;
568     VersRecHndl vers;
569     Rect box;
570     StringPtr longvers;
571     WinInfo *wi;
572
573     if (windows.about)
574         SelectWindow(windows.about);
575     else {
576         windows.about =
577             GetDialogWindow(GetNewDialog(wAbout, NULL, (WindowPtr)-1));
578         wi = smalloc(sizeof(*wi));
579         wi->s = NULL;
580         wi->wtype = wAbout;
581         SetWRefCon(windows.about, (long)wi);
582         vers = (VersRecHndl)Get1Resource('vers', 1);
583         if (vers != NULL && *vers != NULL) {
584             longvers = (*vers)->shortVersion + (*vers)->shortVersion[0] + 1;
585             GetDialogItem(GetDialogFromWindow(windows.about), wiAboutVersion,
586                           &itemtype, &item, &box);
587             assert(itemtype & kStaticTextDialogItem);
588             SetDialogItemText(item, longvers);
589         }
590         ShowWindow(windows.about);
591     }
592 }
593
594 static void mac_openlicence(void) {
595     WinInfo *wi;
596
597     if (windows.licence)
598         SelectWindow(windows.licence);
599     else {
600         windows.licence = GetNewWindow(wLicence, NULL, (WindowPtr)-1);
601         wi = smalloc(sizeof(*wi));
602         wi->s = NULL;
603         wi->wtype = wLicence;
604         SetWRefCon(windows.licence, (long)wi);
605         ShowWindow(windows.licence);
606     }
607 }
608
609 static void mac_closewindow(WindowPtr window) {
610
611     switch (mac_windowtype(window)) {
612 #if !TARGET_API_MAC_CARBON
613       case wDA:
614         CloseDeskAcc(GetWindowKind(window));
615         break;
616 #endif
617       case wTerminal:
618         mac_closeterm(window);
619         break;
620       case wAbout:
621         windows.about = NULL;
622         DisposeDialog(GetDialogFromWindow(window));
623         break;
624       case wLicence:
625         windows.licence = NULL;
626         DisposeWindow(window);
627         break;
628     }
629 }
630
631 static void mac_zoomwindow(WindowPtr window, short part) {
632
633     /* FIXME: do something */
634 }
635
636 /*
637  * Make the menus look right before the user gets to see them.
638  */
639 #if TARGET_API_MAC_CARBON
640 #define EnableItem EnableMenuItem
641 #define DisableItem DisableMenuItem
642 #endif
643 static void mac_adjustmenus(void) {
644     WindowPtr window;
645     MenuHandle menu;
646
647     window = FrontWindow();
648     menu = GetMenuHandle(mApple);
649     EnableItem(menu, 0);
650     EnableItem(menu, iAbout);
651
652     menu = GetMenuHandle(mFile);
653     EnableItem(menu, 0);
654     EnableItem(menu, iNew);
655     if (window != NULL)
656         EnableItem(menu, iClose);
657     else
658         DisableItem(menu, iClose);
659     EnableItem(menu, iQuit);
660
661     switch (mac_windowtype(window)) {
662       case wSettings:
663         DisableItem(menu, iSave); /* XXX enable if modified */
664         EnableItem(menu, iSaveAs);
665         EnableItem(menu, iDuplicate);
666         menu = GetMenuHandle(mEdit);
667         DisableItem(menu, 0);
668         break;
669       case wTerminal:
670         mac_adjusttermmenus(window);
671         break;
672       default:
673         DisableItem(menu, iSave);
674         DisableItem(menu, iSaveAs);
675         DisableItem(menu, iDuplicate);
676         menu = GetMenuHandle(mEdit);
677         DisableItem(menu, 0);
678         menu = GetMenuHandle(mWindow);
679         DisableItem(menu, 0); /* Until we get more than 1 item on it. */
680         break;
681     }
682     DrawMenuBar();
683 }
684
685 /*
686  * Make sure the right cursor's being displayed.
687  */
688 static void mac_adjustcursor(RgnHandle cursrgn) {
689     Point mouse;
690     WindowPtr window, front;
691     short part;
692 #if TARGET_API_MAC_CARBON
693     Cursor arrow;
694     RgnHandle visrgn;
695 #endif
696
697     GetMouse(&mouse);
698     LocalToGlobal(&mouse);
699     part = FindWindow(mouse, &window);
700     front = FrontWindow();
701     if (part != inContent || window == NULL || window != front) {
702         /* Cursor isn't in the front window, so switch to arrow */
703 #if TARGET_API_MAC_CARBON
704         GetQDGlobalsArrow(&arrow);
705         SetCursor(&arrow);
706 #else
707         SetCursor(&qd.arrow);
708 #endif
709         SetRectRgn(cursrgn, SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX);
710         if (front != NULL) {
711 #if TARGET_API_MAC_CARBON
712             visrgn = NewRgn();
713             GetPortVisibleRegion(GetWindowPort(front), visrgn);
714             DiffRgn(cursrgn, visrgn, cursrgn);
715             DisposeRgn(visrgn);
716 #else
717             DiffRgn(cursrgn, front->visRgn, cursrgn);
718 #endif
719         }
720     } else {
721         switch (mac_windowtype(window)) {
722           case wTerminal:
723             mac_adjusttermcursor(window, mouse, cursrgn);
724             break;
725           default:
726 #if TARGET_API_MAC_CARBON
727             GetQDGlobalsArrow(&arrow);
728             SetCursor(&arrow);
729             GetPortVisibleRegion(GetWindowPort(window), cursrgn);
730 #else
731             SetCursor(&qd.arrow);
732             CopyRgn(window->visRgn, cursrgn);
733 #endif
734             break;
735         }
736     }
737 }
738
739 pascal OSErr mac_aevt_quit(const AppleEvent *req, AppleEvent *reply,
740                                   long refcon)
741 {
742     DescType type;
743     Size size;
744
745     if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard,
746                           &type, NULL, 0, &size) == noErr)
747         return errAEParamMissed;
748
749     borednow = 1;
750     return noErr;
751 }
752
753 void cleanup_exit(int status)
754 {
755
756 #if !TARGET_RT_MAC_CFM
757     if (mac_gestalts.encvvers != 0)
758         TerminateUnicodeConverter();
759 #endif
760     sk_cleanup();
761     exit(status);
762 }
763
764 /* This should only kill the current session, not the whole application. */
765 void connection_fatal(void *fontend, char *fmt, ...) {
766     va_list ap;
767     Str255 stuff;
768     
769     va_start(ap, fmt);
770     /* We'd like stuff to be a Pascal string */
771     stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap);
772     va_end(ap);
773     ParamText(stuff, NULL, NULL, NULL);
774     StopAlert(128, NULL);
775     cleanup_exit(1);
776 }
777
778 /* Null SSH agent client -- never finds an agent. */
779
780 int agent_exists(void)
781 {
782
783     return FALSE;
784 }
785
786 void agent_query(void *in, int inlen, void **out, int *outlen)
787 {
788
789     *out = NULL;
790     *outlen = 0;
791 }
792
793 /* Temporary null routines for testing. */
794
795 void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
796                          char *keystr, char *fingerprint)
797 {
798
799 }
800
801 void askcipher(void *frontend, char *ciphername, int cs)
802 {
803
804 }
805
806 void old_keyfile_warning(void)
807 {
808
809 }
810
811 FontSpec platform_default_fontspec(char const *name)
812 {
813     FontSpec ret;
814     long smfs;
815
816     if (!strcmp(name, "Font")) {
817         smfs = GetScriptVariable(smSystemScript, smScriptMonoFondSize);
818         if (smfs == 0)
819             smfs = GetScriptVariable(smRoman, smScriptMonoFondSize);
820         if (smfs != 0) {
821             GetFontName(HiWord(smfs), ret.name);
822             if (ret.name[0] == 0)
823                 memcpy(ret.name, "\pMonaco", 7);
824             ret.size = LoWord(smfs);
825         } else {
826             memcpy(ret.name, "\pMonaco", 7);
827             ret.size = 9;
828         }
829         ret.face = 0;
830     } else {
831         ret.name[0] = 0;
832     }
833
834     return ret;
835 }
836
837 Filename platform_default_filename(const char *name)
838 {
839     Filename ret;
840     if (!strcmp(name, "LogFileName"))
841         FSMakeFSSpec(0, 0, "\pputty.log", &ret.fss);
842     else
843         memset(&ret, 0, sizeof(ret));
844     return ret;
845 }
846
847 char *platform_default_s(char const *name)
848 {
849     return NULL;
850 }
851
852 int platform_default_i(char const *name, int def)
853 {
854
855     /* Non-raw cut and paste of line-drawing chars works badly on the
856      * current Unix stub implementation of the Unicode functions.
857      * So I'm going to temporarily set the default to raw mode so
858      * that the failure mode isn't quite so drastically horrid.
859      * When Unicode comes in, this can all be put right. */
860     if (!strcmp(name, "RawCNP"))
861         return 1;
862     return def;
863 }
864
865 void platform_get_x11_auth(char *display, int *proto,
866                            unsigned char *data, int *datalen)
867 {
868     /* SGT: I have no idea whether Mac X servers need anything here. */
869 }
870
871 /*
872  * Local Variables:
873  * c-file-style: "simon"
874  * End:
875  */