From 886d0a169c21734e775e8d85abd92a744157c368 Mon Sep 17 00:00:00 2001 From: Kevin Walzer Date: Sat, 19 Sep 2020 17:31:00 +0000 Subject: Restore console --- macosx/tkMacOSXInit.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 2601d6b..2fbfd4d 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -381,8 +381,9 @@ TkpInit( * clicking Wish) then use the Tk based console interpreter. */ - if (!isatty(0) && (fstat(0, &st) || (S_ISCHR(st.st_mode) && st.st_blocks == 0))) { - if (getenv("TK_CONSOLE")) { + if (getenv("TK_CONSOLE") || + (!isatty(0) && (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)); @@ -400,11 +401,11 @@ TkpInit( if (intvar == NULL) { Tcl_SetVar2(interp, "tcl_interactive", NULL, "1", TCL_GLOBAL_ONLY); + NSLog(@"tcl_interactive"); } } if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) { return TCL_ERROR; - } } else { /* -- cgit v0.12 From b2860267059c788e0ee6018d84f65dd406d5335b Mon Sep 17 00:00:00 2001 From: Kevin Walzer Date: Sat, 19 Sep 2020 18:14:34 +0000 Subject: Remove debugging statement --- macosx/tkMacOSXInit.c | 1 - 1 file changed, 1 deletion(-) diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 2fbfd4d..7f3f241 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -401,7 +401,6 @@ TkpInit( if (intvar == NULL) { Tcl_SetVar2(interp, "tcl_interactive", NULL, "1", TCL_GLOBAL_ONLY); - NSLog(@"tcl_interactive"); } } if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) { -- cgit v0.12 From d0d64252096e9dd308d7460e9dc384b440dd8f43 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Sat, 19 Sep 2020 22:10:01 +0000 Subject: Fix the regression with ScidvsMac; reorganize the code in the rest of TkpInit and edit misleading comments. --- macosx/tkMacOSXInit.c | 113 +++++++++++++++++++++++++++----------------------- 1 file changed, 62 insertions(+), 51 deletions(-) diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 7f3f241..5bd1e57 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -284,17 +284,29 @@ TkpInit( if (!initialized) { struct stat st; + Bool isBeingLaunched; + Bool shouldOpenConsole = NO; /* * Initialize/check OS version variable for runtime checks. */ - initialized = 1; - #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 # error Mac OS X 10.6 required #endif + initialized = 1; + fstat(0, &st); + + /* + * If we don't have a TTY or stdin is a special character file of + * length 0, (e.g. /dev/null, which is what Finder sets when double + * clicking Wish) then we are being launched as a macOS app. + */ + + isBeingLaunched = (!isatty(0) || + (S_ISCHR(st.st_mode) && st.st_blocks == 0)); + #ifdef TK_FRAMEWORK /* * When Tk is in a framework, force tcl_findLibrary to look in the @@ -312,16 +324,6 @@ TkpInit( #endif /* - * FIXME: Close stdin & stdout for remote debugging otherwise we will - * fight with gdb for stdin & stdout - */ - - if (getenv("XCNOSTDIN") != NULL) { - close(0); - close(1); - } - - /* * Instantiate our NSApplication object. This needs to be done before * we check whether to open a console window. */ @@ -376,49 +378,54 @@ TkpInit( Tcl_DoOneEvent(TCL_WINDOW_EVENTS | TCL_DONT_WAIT); /* - * If we don't have a TTY or 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. + * Decide whether to open a console window. If the TK_CONSOLE + * environment variable is not defined we only show the console if + * there is no startup script. */ - if (getenv("TK_CONSOLE") || - (!isatty(0) && (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)); - - /* - * Only show the console if we don't have a startup script and - * tcl_interactive hasn't been set already. - */ - - if (Tcl_GetStartupScript(NULL) == NULL) { - const char *intvar = Tcl_GetVar2(interp, - "tcl_interactive", NULL, TCL_GLOBAL_ONLY); - - if (intvar == NULL) { - Tcl_SetVar2(interp, "tcl_interactive", NULL, "1", - TCL_GLOBAL_ONLY); - } - } - if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) { - return TCL_ERROR; - } else { - - /* - * When launched as a macOS application with no console, - * redirect stderr and stdout to /dev/null. This avoids waiting - * forever for those files to become writable if the underlying - * Tcl program tries to write to them with a puts command. - */ - - FILE *null = fopen("/dev/null", "w"); - dup2(fileno(null), STDOUT_FILENO); - dup2(fileno(null), STDERR_FILENO); + if (getenv("TK_CONSOLE")) { + shouldOpenConsole = YES; + } else if (Tcl_GetStartupScript(NULL) == NULL) { + const char *intvar = Tcl_GetVar2(interp, "tcl_interactive", + NULL, TCL_GLOBAL_ONLY); + if (intvar == NULL) { + Tcl_SetVar2(interp, "tcl_interactive", NULL, "1", + TCL_GLOBAL_ONLY); + } + shouldOpenConsole = YES; + } + if (shouldOpenConsole) { + 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) { + return TCL_ERROR; } } + if (isBeingLaunched && !shouldOpenConsole) { + + /* + * When launched as a macOS application with no console, + * redirect stderr and stdout to /dev/null. This avoids waiting + * forever for those files to become writable if the underlying + * Tcl program tries to write to them with a puts command. + */ + + FILE *null = fopen("/dev/null", "w"); + dup2(fileno(null), STDOUT_FILENO); + dup2(fileno(null), STDERR_FILENO); + } + + /* + * FIXME: Close stdin & stdout for remote debugging if XCNOSTDIN is + * set. Otherwise we will fight with gdb for stdin & stdout + */ + + if (getenv("XCNOSTDIN") != NULL) { + close(0); + close(1); + } /* * Initialize the NSServices object here. Apple's docs say to do this @@ -445,6 +452,10 @@ TkpInit( } } + /* + * Initialization steps that are needed for all interpreters. + */ + if (tkLibPath[0] != '\0') { Tcl_SetVar2(interp, "tk_library", NULL, tkLibPath, TCL_GLOBAL_ONLY); } -- cgit v0.12 From 3d4ce1dd066a78e295cf5ddc7ae6e30ed057d3f6 Mon Sep 17 00:00:00 2001 From: marc_culler Date: Sat, 19 Sep 2020 22:32:17 +0000 Subject: Tiny code improvement --- macosx/tkMacOSXInit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 5bd1e57..c4ae077 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -402,8 +402,7 @@ TkpInit( if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) { return TCL_ERROR; } - } - if (isBeingLaunched && !shouldOpenConsole) { + } else if (isBeingLaunched) { /* * When launched as a macOS application with no console, -- cgit v0.12 From e1716fd8b1debf155c619ae32316de18418dc25b Mon Sep 17 00:00:00 2001 From: marc_culler Date: Sun, 20 Sep 2020 04:30:26 +0000 Subject: Don't open a console when running Wish from the command line; further simplification. --- macosx/tkMacOSXInit.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index c4ae077..d77da23 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -284,7 +284,6 @@ TkpInit( if (!initialized) { struct stat st; - Bool isBeingLaunched; Bool shouldOpenConsole = NO; /* @@ -296,16 +295,6 @@ TkpInit( #endif initialized = 1; - fstat(0, &st); - - /* - * If we don't have a TTY or stdin is a special character file of - * length 0, (e.g. /dev/null, which is what Finder sets when double - * clicking Wish) then we are being launched as a macOS app. - */ - - isBeingLaunched = (!isatty(0) || - (S_ISCHR(st.st_mode) && st.st_blocks == 0)); #ifdef TK_FRAMEWORK /* @@ -380,12 +369,12 @@ TkpInit( /* * Decide whether to open a console window. If the TK_CONSOLE * environment variable is not defined we only show the console if - * there is no startup script. + * stdin is not a tty and there is no startup script. */ if (getenv("TK_CONSOLE")) { shouldOpenConsole = YES; - } else if (Tcl_GetStartupScript(NULL) == NULL) { + } else if (!isatty(0) && Tcl_GetStartupScript(NULL) == NULL) { const char *intvar = Tcl_GetVar2(interp, "tcl_interactive", NULL, TCL_GLOBAL_ONLY); if (intvar == NULL) { @@ -402,7 +391,7 @@ TkpInit( if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) { return TCL_ERROR; } - } else if (isBeingLaunched) { + } else if (!isatty(0)) { /* * When launched as a macOS application with no console, -- cgit v0.12