summaryrefslogtreecommitdiffstats
path: root/generic/tkMain.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-05-25 12:19:47 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-05-25 12:19:47 (GMT)
commitd7e1d66497a877b980042968a57edd01d2840818 (patch)
treec70ccc1c14fdf986ba8530e11b5a1a69b08de298 /generic/tkMain.c
parentc6f6c74ebb2092a8b0b4b2e5c805d22253d19e33 (diff)
downloadtk-d7e1d66497a877b980042968a57edd01d2840818.zip
tk-d7e1d66497a877b980042968a57edd01d2840818.tar.gz
tk-d7e1d66497a877b980042968a57edd01d2840818.tar.bz2
Simpify determination whether we are running on cygwin.
Export Tk_GetHINSTANCE, TkSetPixmapColormap and TkpPrintWindowId on the Cygwin dll. Fix "make genstubs" when cross-compiling on UNIX
Diffstat (limited to 'generic/tkMain.c')
-rw-r--r--generic/tkMain.c105
1 files changed, 70 insertions, 35 deletions
diff --git a/generic/tkMain.c b/generic/tkMain.c
index 65a42a6..af2448e 100644
--- a/generic/tkMain.c
+++ b/generic/tkMain.c
@@ -28,6 +28,7 @@
#endif
#ifdef __WIN32__
#include "tkWinInt.h"
+#include "../win/tclWinPort.h"
#endif
#ifdef MAC_OSX_TK
#include "tkMacOSXInt.h"
@@ -55,7 +56,45 @@ static Tcl_ThreadDataKey dataKey;
* 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
#if !defined(MAC_TCL)
extern int isatty _ANSI_ARGS_((int fd));
#else
@@ -90,6 +129,8 @@ static void StdinProc _ANSI_ARGS_((ClientData clientData,
*
*----------------------------------------------------------------------
*/
+int LoadCygwinTk(Tcl_Interp *interp);
+
void
Tk_MainEx(argc, argv, appInitProc, interp)
int argc; /* Number of arguments. */
@@ -106,9 +147,6 @@ Tk_MainEx(argc, argv, appInitProc, interp)
Tcl_Channel inChannel, outChannel;
Tcl_DString appName;
ThreadSpecificData *tsdPtr;
-#ifdef __WIN32__
- HANDLE handle;
-#endif
/*
* Ensure that we are getting the matching version of Tcl. This is
@@ -119,6 +157,27 @@ Tk_MainEx(argc, argv, appInitProc, interp)
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));
@@ -126,7 +185,12 @@ Tk_MainEx(argc, argv, appInitProc, interp)
tsdPtr->interp = interp;
Tcl_Preserve((ClientData) interp);
-#if ((defined(__WIN32__) && !defined(__CYGWIN__)) || defined(MAC_TCL))
+#if defined(__WIN32__) && !defined(STATIC_BUILD)
+ if (!tclStubsPtr->reserved9) {
+ /* Only initialize console when not running under cygwin */
+ Tk_InitConsoleChannels(interp);
+ }
+#elif defined(__WIN32__) || defined(MAC_TCL)
Tk_InitConsoleChannels(interp);
#endif
@@ -194,37 +258,8 @@ Tk_MainEx(argc, argv, appInitProc, interp)
* 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