diff options
Diffstat (limited to 'generic/tkMain.c')
-rw-r--r-- | generic/tkMain.c | 104 |
1 files changed, 68 insertions, 36 deletions
diff --git a/generic/tkMain.c b/generic/tkMain.c index 69c7d25..c6d5238 100644 --- a/generic/tkMain.c +++ b/generic/tkMain.c @@ -18,6 +18,7 @@ #include "tkInt.h" #ifdef __WIN32__ #include "tkWinInt.h" +#include "../win/tclWinPort.h" #endif #ifdef MAC_OSX_TK #include "tkMacOSXInt.h" @@ -44,7 +45,45 @@ static Tcl_ThreadDataKey dataKey; * it will conflict with a declaration elsewhere on some systems. */ -#if !defined(__WIN32__) && !defined(_WIN32) +#if defined(__WIN32__) || defined(_WIN32) +#define isatty WinIsTty +static int WinIsTty(int fd) { + HANDLE handle; + + /* + * For now, under Windows, we assume we are not running as a console mode + * app, so we need to use the GUI console. In order to enable this, we + * always claim to be running on a tty. This probably isn't the right + * way to do it. + */ + +#if !defined(STATIC_BUILD) + if (tclStubsPtr->reserved9 && TclpIsAtty) { + /* We are running on Cygwin */ + return TclpIsAtty(fd); + } +#endif + handle = GetStdHandle(STD_INPUT_HANDLE + fd); + + if ((handle == INVALID_HANDLE_VALUE) || (handle == 0) + || (GetFileType(handle) == FILE_TYPE_UNKNOWN)) { + /* + * If it's a bad or closed handle, then it's been connected + * to a wish console window. + */ + + return 1; + } else if (GetFileType(handle) == FILE_TYPE_CHAR) { + /* + * A character file handle is a tty by definition. + */ + + return 1; + } else { + return 0; + } +} +#else extern int isatty(int fd); extern char * strrchr(CONST char *string, int c); #endif @@ -74,7 +113,6 @@ static void StdinProc(ClientData clientData, int mask); * *---------------------------------------------------------------------- */ - void Tk_MainEx( int argc, /* Number of arguments. */ @@ -90,9 +128,6 @@ Tk_MainEx( int code, nullStdin = 0; Tcl_Channel inChannel, outChannel; ThreadSpecificData *tsdPtr; -#ifdef __WIN32__ - HANDLE handle; -#endif Tcl_DString appName; /* @@ -104,6 +139,27 @@ Tk_MainEx( abort(); } +#if defined(__WIN32__) && !defined(STATIC_BUILD) + if (tclStubsPtr->reserved9) { + /* We are running win32 Tk under Cygwin, so let's check + * whether the env("DISPLAY") variable or the -display + * argument is set. If so, we really want to run the + * Tk_MainEx function of libtk.dll, not this one. */ + if (Tcl_GetVar2(interp, "env", "DISPLAY", TCL_GLOBAL_ONLY)) { + loadCygwinTk: + Tcl_Panic("Should load libtk.dll now, not yet implemented"); + } else { + int i; + + for (i = 1; i < argc; ++i) { + if (!strcmp(argv[i], "-display")) { + goto loadCygwinTk; + } + } + } + } +#endif + tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); @@ -111,7 +167,12 @@ Tk_MainEx( tsdPtr->interp = interp; Tcl_Preserve((ClientData) interp); -#if defined(__WIN32__) && !defined(__CYGWIN__) +#if defined(__WIN32__) && !defined(STATIC_BUILD) + if (!tclStubsPtr->reserved9) { + /* Only initialize console when not running under cygwin */ + Tk_InitConsoleChannels(interp); + } +#elif defined(__WIN32__) Tk_InitConsoleChannels(interp); #endif @@ -194,37 +255,8 @@ Tk_MainEx( * Set the "tcl_interactive" variable. */ -#ifdef __WIN32__ - /* - * For now, under Windows, we assume we are not running as a console mode - * app, so we need to use the GUI console. In order to enable this, we - * always claim to be running on a tty. This probably isn't the right way - * to do it. - */ - - handle = GetStdHandle(STD_INPUT_HANDLE); - - if ((handle == INVALID_HANDLE_VALUE) || (handle == 0) - || (GetFileType(handle) == FILE_TYPE_UNKNOWN)) { - /* - * If it's a bad or closed handle, then it's been connected to a wish - * console window. - */ - - tsdPtr->tty = 1; - } else if (GetFileType(handle) == FILE_TYPE_CHAR) { - /* - * A character file handle is a tty by definition. - */ - - tsdPtr->tty = 1; - } else { - tsdPtr->tty = 0; - } - -#else tsdPtr->tty = isatty(0); -#endif + #if defined(MAC_OSX_TK) /* * On TkAqua, if we don't have a TTY and stdin is a special character file |