Second work-in-progress MacTCP commit. We can now open a connection, but
[u/mdw/putty] / mac / mac.c
index 0abb337..8aac2ad 100644 (file)
--- a/mac/mac.c
+++ b/mac/mac.c
@@ -1,4 +1,4 @@
-/* $Id: mac.c,v 1.10 2002/12/30 18:21:17 ben Exp $ */
+/* $Id: mac.c,v 1.18 2003/01/05 10:52:56 ben Exp $ */
 /*
  * Copyright (c) 1999 Ben Harris
  * All rights reserved.
@@ -40,6 +40,7 @@
 #include <Devices.h>
 #include <DiskInit.h>
 #include <Gestalt.h>
+#include <LowMem.h>
 #include <Resources.h>
 #include <Script.h>
 #include <TextCommon.h>
@@ -117,14 +118,13 @@ static void mac_startup(void) {
     /* Init TextEdit */
     TEInit();
     /* Init Dialog Manager */
-    InitDialogs(nil);
+    InitDialogs(NULL);
     cold = 0;
     
     /* Get base system version (only used if there's no better selector) */
     if (Gestalt(gestaltSystemVersion, &mac_gestalts.sysvers) != noErr ||
-       (mac_gestalts.sysvers & 0xffff) < 0x700)
+       (mac_gestalts.sysvers &= 0xffff) < 0x700)
        fatalbox("PuTTY requires System 7 or newer");
-    mac_gestalts.sysvers &= 0xffff;
     /* Find out if we've got Color Quickdraw */
     if (Gestalt(gestaltQuickdrawVersion, &mac_gestalts.qdvers) != noErr)
        mac_gestalts.qdvers = gestaltOriginalQD;
@@ -139,12 +139,19 @@ static void mac_startup(void) {
     if (&RegisterAppearanceClient == kUnresolvedCFragSymbolAddress)
        mac_gestalts.apprvers = 0;
 #endif
+#if TARGET_CPU_68K
+    mac_gestalts.cntlattr = 0;
+    mac_gestalts.windattr = 0;
+#else
     /* Mac OS 8.5 Control Manager (proportional scrollbars)? */
-    if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr)
+    if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr ||
+       &SetControlViewSize == kUnresolvedCFragSymbolAddress)
        mac_gestalts.cntlattr = 0;
     /* Mac OS 8.5 Window Manager? */
-    if (Gestalt(gestaltWindowMgrAttr, &mac_gestalts.windattr) != noErr)
+    if (Gestalt(gestaltWindowMgrAttr, &mac_gestalts.windattr) != noErr ||
+       &SetWindowContentColor == kUnresolvedCFragSymbolAddress)
        mac_gestalts.windattr = 0;
+#endif
     /* Text Encoding Conversion Manager? */
     if (
 #if TARGET_RT_MAC_CFM
@@ -156,9 +163,12 @@ static void mac_startup(void) {
        mac_gestalts.encvvers = 0;
     else {
        mac_gestalts.encvvers = (*ti)->tecVersion;
+       mac_gestalts.uncvattr = (*ti)->tecUnicodeConverterFeatures;
        DisposeHandle((Handle)ti);
     }
 
+    mactcp_init();
+
     /* We've been tested with the Appearance Manager */
     if (mac_gestalts.apprvers != 0)
        RegisterAppearanceClient();
@@ -174,6 +184,20 @@ static void mac_startup(void) {
     windows.about = NULL;
     windows.licence = NULL;
 
+    default_protocol = DEFAULT_PROTOCOL;
+    default_port = DEFAULT_PORT;
+
+    {
+       short vol;
+       long dirid;
+
+       /* Set the default directory for loading and saving settings. */
+       /* XXX Should we create it? */
+       if (get_session_dir(FALSE, &vol, &dirid) == noErr) {
+           LMSetSFSaveDisk(-vol);
+           LMSetCurDirStore(dirid);
+       }
+    }
     init_ucs();
 }
 
@@ -261,13 +285,16 @@ static void mac_contentclick(WindowPtr window, EventRecord *event) {
        mac_clickterm(window, event);
        break;
       case wAbout:
-       if (DialogSelect(event, &(DialogPtr)window, &item))
+       if (DialogSelect(event, &window, &item))
            switch (item) {
              case wiAboutLicence:
                mac_openlicence();
                break;
            }
        break;
+      case wSettings:
+       mac_clickdlg(window, event);
+       break;
     }
 }
 
@@ -288,6 +315,9 @@ static void mac_activatewindow(WindowPtr window, EventRecord *event) {
       case wTerminal:
        mac_activateterm(window, active);
        break;
+      case wSettings:
+       mac_activatedlg(window, event);
+       break;
       case wAbout:
        mac_activateabout(window, event);
        break;
@@ -314,6 +344,7 @@ static void mac_updatewindow(WindowPtr window) {
        mac_updateterm(window);
        break;
       case wAbout:
+      case wSettings:
        BeginUpdate(window);
        UpdateDialog(window, window->visRgn);
        EndUpdate(window);
@@ -351,6 +382,7 @@ static void mac_updatelicence(WindowPtr window)
  */
 static int mac_windowtype(WindowPtr window) {
     int kind;
+    long refcon;
 
     if (window == NULL)
        return wNone;
@@ -359,7 +391,11 @@ static int mac_windowtype(WindowPtr window) {
        return wDA;
     if (GetWVariant(window) == zoomDocProc)
        return wTerminal;
-    return GetWRefCon(window);
+    refcon = GetWRefCon(window);
+    if (refcon < 1024)
+       return refcon;
+    else
+       return wSettings;
 }
 
 /*
@@ -566,6 +602,7 @@ static void mac_shutdown(void) {
     if (mac_gestalts.encvvers != 0)
        TerminateUnicodeConverter();
 #endif
+    mactcp_shutdown();
     exit(0);
 }
 
@@ -578,7 +615,7 @@ void fatalbox(char *fmt, ...) {
     stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap);
     va_end(ap);
     ParamText(stuff, NULL, NULL, NULL);
-    StopAlert(128, nil);
+    StopAlert(128, NULL);
     exit(1);
 }
 
@@ -591,7 +628,21 @@ void modalfatalbox(char *fmt, ...) {
     stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap);
     va_end(ap);
     ParamText(stuff, NULL, NULL, NULL);
-    StopAlert(128, nil);
+    StopAlert(128, NULL);
+    exit(1);
+}
+
+/* This should only kill the current session, not the whole application. */
+void connection_fatal(void *fontend, char *fmt, ...) {
+    va_list ap;
+    Str255 stuff;
+    
+    va_start(ap, fmt);
+    /* We'd like stuff to be a Pascal string */
+    stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap);
+    va_end(ap);
+    ParamText(stuff, NULL, NULL, NULL);
+    StopAlert(128, NULL);
     exit(1);
 }