Consequences of Simon's recent deglobalisation changes.
[u/mdw/putty] / mac / mac.c
index fe46f3f..0e55933 100644 (file)
--- a/mac/mac.c
+++ b/mac/mac.c
@@ -1,4 +1,4 @@
-/* $Id: mac.c,v 1.23 2003/01/10 18:33:35 simon Exp $ */
+/* $Id: mac.c,v 1.27 2003/01/12 16:11:27 ben Exp $ */
 /*
  * Copyright (c) 1999 Ben Harris
  * All rights reserved.
@@ -169,8 +169,21 @@ static void mac_startup(void) {
        mac_gestalts.uncvattr = (*ti)->tecUnicodeConverterFeatures;
        DisposeHandle((Handle)ti);
     }
-
-    mactcp_init();
+    /* OpenTransport? */
+    if (Gestalt(gestaltOpenTpt, &mac_gestalts.otptattr) != noErr ||
+       (mac_gestalts.otptattr & gestaltOpenTptTCPPresentMask) == 0 ||
+       ot_init() != noErr)
+       mac_gestalts.otptattr = 0;
+    if (mac_gestalts.otptattr == 0) {
+       /* MacTCP? */
+       if (Gestalt(FOUR_CHAR_CODE('mtcp'), &mac_gestalts.mtcpvers) != noErr)
+           mac_gestalts.mtcpvers = 0;
+       if (mac_gestalts.mtcpvers > 0) {
+           if (mactcp_init() != noErr)
+               mac_gestalts.mtcpvers = 0;
+       }
+    } else
+       mac_gestalts.mtcpvers = 0;
 
     /* We've been tested with the Appearance Manager */
     if (mac_gestalts.apprvers != 0)
@@ -191,14 +204,6 @@ static void mac_startup(void) {
     default_port = DEFAULT_PORT;
     flags = FLAG_INTERACTIVE;
 
-    /*
-     * Really grotty hack to ensure that anything that looks at the
-     * global "cfg" variable gets something vaguely sensible.
-     * Obviously, nothing should actually be using it, but that will
-     * take a while to arrange.
-     */
-    do_defaults(NULL, &cfg);
-
     {
        short vol;
        long dirid;
@@ -225,7 +230,10 @@ static void mac_eventloop(void) {
        mac_adjustcursor(cursrgn);
        if (gotevent)
            mac_event(&event);
-       mactcp_poll();
+       if (mac_gestalts.mtcpvers != 0)
+           mactcp_poll();
+       if (mac_gestalts.otptattr != 0)
+           ot_poll();
        mac_pollterm();
     }
     DisposeRgn(cursrgn);
@@ -617,7 +625,7 @@ void cleanup_exit(int status)
     if (mac_gestalts.encvvers != 0)
        TerminateUnicodeConverter();
 #endif
-    mactcp_shutdown();
+    sk_cleanup();
     exit(status);
 }
 
@@ -631,7 +639,7 @@ void fatalbox(char *fmt, ...) {
     va_end(ap);
     ParamText(stuff, NULL, NULL, NULL);
     StopAlert(128, NULL);
-    exit(1);
+    cleanup_exit(1);
 }
 
 void modalfatalbox(char *fmt, ...) {
@@ -644,7 +652,7 @@ void modalfatalbox(char *fmt, ...) {
     va_end(ap);
     ParamText(stuff, NULL, NULL, NULL);
     StopAlert(128, NULL);
-    exit(1);
+    cleanup_exit(1);
 }
 
 /* This should only kill the current session, not the whole application. */
@@ -658,7 +666,7 @@ void connection_fatal(void *fontend, char *fmt, ...) {
     va_end(ap);
     ParamText(stuff, NULL, NULL, NULL);
     StopAlert(128, NULL);
-    exit(1);
+    cleanup_exit(1);
 }
 
 /* Null SSH agent client -- never finds an agent. */