summaryrefslogtreecommitdiff
path: root/tk/macosx/tkMacOSXAppInit.c
diff options
context:
space:
mode:
Diffstat (limited to 'tk/macosx/tkMacOSXAppInit.c')
-rw-r--r--tk/macosx/tkMacOSXAppInit.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/tk/macosx/tkMacOSXAppInit.c b/tk/macosx/tkMacOSXAppInit.c
index b088faace24..f9551b576ab 100644
--- a/tk/macosx/tkMacOSXAppInit.c
+++ b/tk/macosx/tkMacOSXAppInit.c
@@ -14,18 +14,16 @@
* 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");
+ }
+ }
}
/*