OSDN Git Service

Updated to tk 8.4.1
[pf3gnuchains/sourceware.git] / tk / macosx / tkMacOSXAppInit.c
index b088faa..f9551b5 100644 (file)
  * RCS: @(#) $Id$
  */
 #include <pthread.h>
+#include <sys/stat.h>
 #include "tk.h"
 #include "tclInt.h"
 #include "locale.h"
 
 #include <Carbon/Carbon.h>
+#include "tkPort.h"
 #include "tkMacOSX.h"
 #include "tkMacOSXEvent.h"
 
-#ifndef MAX_PATH_LEN
-    #define MAX_PATH_LEN 1024
-#endif
-
 /*
  * If the App is in an App package, then we want to add the Scripts
  * directory to the auto_path.  But we have to wait till after the
@@ -33,7 +31,7 @@
  * figured out in main.
  */
  
-char scriptPath[MAX_PATH_LEN + 1];
+char scriptPath[PATH_MAX + 1];
 
 extern Tcl_Interp *gStdoutInterp;
 
@@ -115,17 +113,17 @@ main(argc, argv)
 
         if (appMainURL != NULL) {
             CFURLRef scriptFldrURL;
-            char *startupScript = malloc(MAX_PATH_LEN + 1);
+            char *startupScript = malloc(PATH_MAX + 1);
                             
             if (CFURLGetFileSystemRepresentation (appMainURL, true,
-                    startupScript, MAX_PATH_LEN)) {
+                    startupScript, PATH_MAX)) {
                 TclSetStartupScriptFileName(startupScript);
                 scriptFldrURL = CFBundleCopyResourceURL(bundleRef,
                         CFSTR("Scripts"),
                         NULL,
                         NULL);
                 CFURLGetFileSystemRepresentation(scriptFldrURL, 
-                        true, scriptPath, MAX_PATH_LEN);
+                        true, scriptPath, PATH_MAX);
                 CFRelease(scriptFldrURL);
             } else {
                 free(startupScript);
@@ -190,22 +188,26 @@ Tcl_AppInit(interp)
 #endif /* TK_TEST */
 
     /*
-     * If we don't have a TTY, then use the Tk based console
-     * interpreter instead.
+     * If we don't have a TTY and stdin is a special character file of length 0,
+     * (e.g. /dev/null, which is what Finder sets when double clicking Wish)
+     * then use the Tk based console interpreter.
      */
 
-    if (ttyname(0) == NULL) {
-        Tk_InitConsoleChannels(interp);
-        Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDIN));
-        Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDOUT));
-        Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDERR));
-        if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
-            goto error;
-        }
-       /* Only show the console if we don't have a startup script */
-        if (TclGetStartupScriptPath() == NULL) {
-            Tcl_Eval(interp, "console show");
-        }
+    if (!isatty(0)) {
+       struct stat st;
+       if (fstat(0, &st) || (S_ISCHR(st.st_mode) && st.st_blocks == 0)) {
+            Tk_InitConsoleChannels(interp);
+            Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDIN));
+            Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDOUT));
+            Tcl_RegisterChannel(interp, Tcl_GetStdChannel(TCL_STDERR));
+           if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
+               goto error;
+           }
+           /* Only show the console if we don't have a startup script */
+           if (TclGetStartupScriptPath() == NULL) {
+               Tcl_Eval(interp, "console show");
+           }
+       }
     }
     
     /*