]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - macosx/osxmain.m
Giant const-correctness patch of doom!
[PuTTY.git] / macosx / osxmain.m
index bd579852acf00e115f51ef13f5a81f45d10b6913..2ac772a835aa2883b984e1214fd1cfc9f9981604 100644 (file)
@@ -20,8 +20,6 @@ AppController *controller;
  * and Unix PuTTY code.
  */
 
-const char platform_x11_best_transport[] = "unix";
-
 char *platform_get_x_display(void) {
     return NULL;
 }
@@ -60,31 +58,68 @@ char *x_get_default(const char *key)
     return NULL;                      /* this is a stub */
 }
 
-void modalfatalbox(char *p, ...)
+static void commonfatalbox(const char *p, va_list ap)
+{
+    char errorbuf[2048];
+    NSAlert *alert;
+
+    /*
+     * We may have come here because we ran out of memory, in which
+     * case it's entirely likely that that further memory
+     * allocations will fail. So (a) we use vsnprintf to format the
+     * error message rather than the usual dupvprintf; and (b) we
+     * have a fallback way to get the message out via stderr if
+     * even creating an NSAlert fails.
+     */
+    vsnprintf(errorbuf, lenof(errorbuf), p, ap);
+
+    alert = [NSAlert alloc];
+    if (!alert) {
+       fprintf(stderr, "fatal error (and NSAlert failed): %s\n", errorbuf);
+    } else {
+       alert = [[alert init] autorelease];
+       [alert addButtonWithTitle:@"Terminate"];
+       [alert setInformativeText:[NSString stringWithCString:errorbuf]];
+       [alert runModal];
+    }
+    exit(1);
+}
+
+void nonfatal(void *frontend, const char *p, ...)
 {
-    /* FIXME: proper OS X GUI stuff */
+    char *errorbuf;
+    NSAlert *alert;
     va_list ap;
-    fprintf(stderr, "FATAL ERROR: ");
+
     va_start(ap, p);
-    vfprintf(stderr, p, ap);
+    errorbuf = dupvprintf(p, ap);
     va_end(ap);
-    fputc('\n', stderr);
-    exit(1);
+
+    alert = [[[NSAlert alloc] init] autorelease];
+    [alert addButtonWithTitle:@"Error"];
+    [alert setInformativeText:[NSString stringWithCString:errorbuf]];
+    [alert runModal];
+
+    sfree(errorbuf);
 }
 
-void fatalbox(char *p, ...)
+void fatalbox(const char *p, ...)
 {
-    /* FIXME: proper OS X GUI stuff */
     va_list ap;
-    fprintf(stderr, "FATAL ERROR: ");
     va_start(ap, p);
-    vfprintf(stderr, p, ap);
+    commonfatalbox(p, ap);
+    va_end(ap);
+}
+
+void modalfatalbox(const char *p, ...)
+{
+    va_list ap;
+    va_start(ap, p);
+    commonfatalbox(p, ap);
     va_end(ap);
-    fputc('\n', stderr);
-    exit(1);
 }
 
-void cmdline_error(char *p, ...)
+void cmdline_error(const char *p, ...)
 {
     va_list ap;
     fprintf(stderr, "%s: ", appname);