summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornijtmans <nijtmans>2010-12-17 15:14:22 (GMT)
committernijtmans <nijtmans>2010-12-17 15:14:22 (GMT)
commit1ce54b013790bedd4d3c50f68c2e0542473a5508 (patch)
tree6709634c255afbf5eb36d05a4af81b5a53c1958c
parentbea0055b7eadfdb858b637f3407cf8b840b6b0a4 (diff)
downloadtk-1ce54b013790bedd4d3c50f68c2e0542473a5508.zip
tk-1ce54b013790bedd4d3c50f68c2e0542473a5508.tar.gz
tk-1ce54b013790bedd4d3c50f68c2e0542473a5508.tar.bz2
refactor isatty() function for Windows
Let TkpDisplayWarning() send the message directly to the debugger, if available, otherwise do as before
-rw-r--r--ChangeLog7
-rw-r--r--generic/tkMain.c56
-rw-r--r--win/tkWinImage.c5
-rw-r--r--win/tkWinInit.c31
4 files changed, 51 insertions, 48 deletions
diff --git a/ChangeLog b/ChangeLog
index 3b2c6db..2f5ec9b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-12-17 Jan Nijtmans <nijtmans@users.sf.net>
+
+ * generic/tkMain.c: refactor isatty() function for Windows.
+ * win/tkWinImage.c: better warning message.
+ * win/tkWinInit.c: Let TkpDisplayWarning() send the message
+ directly to the debugger, if available, otherwise do as before.
+
2010-12-16 Jan Nijtmans <nijtmans@users.sf.net>
* generic/tk.h: [Patch 3124554]: Move WishPanic from Tk to Tcl
diff --git a/generic/tkMain.c b/generic/tkMain.c
index 8a398f5..4a07154 100644
--- a/generic/tkMain.c
+++ b/generic/tkMain.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMain.c,v 1.40 2010/12/15 08:56:03 nijtmans Exp $
+ * RCS: @(#) $Id: tkMain.c,v 1.41 2010/12/17 15:14:22 nijtmans Exp $
*/
/**
@@ -94,7 +94,26 @@
* it will conflict with a declaration elsewhere on some systems.
*/
-#if !defined(__WIN32__) && !defined(_WIN32)
+#if 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.
+ */
+ handle = GetStdHandle(STD_INPUT_HANDLE + fd);
+ /*
+ * If it's a bad or closed handle, then it's been connected to a wish
+ * console window. A character file handle is a tty by definition.
+ */
+ return (handle == INVALID_HANDLE_VALUE) || (handle == 0)
+ || (GetFileType(handle) == FILE_TYPE_UNKNOWN)
+ || (GetFileType(handle) == FILE_TYPE_CHAR);
+}
+#else
extern int isatty(int fd);
#endif
@@ -154,9 +173,6 @@ Tk_MainEx(
int code, nullStdin = 0;
Tcl_Channel chan;
InteractiveState is;
-#ifdef __WIN32__
- HANDLE handle;
-#endif
/*
* Ensure that we are getting a compatible version of Tcl. This is really
@@ -243,37 +259,7 @@ 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.
- */
-
- is.tty = 1;
- } else if (GetFileType(handle) == FILE_TYPE_CHAR) {
- /*
- * A character file handle is a tty by definition.
- */
-
- is.tty = 1;
- } else {
- is.tty = 0;
- }
-
-#else
is.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
diff --git a/win/tkWinImage.c b/win/tkWinImage.c
index aa8e66f..97ce065 100644
--- a/win/tkWinImage.c
+++ b/win/tkWinImage.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkWinImage.c,v 1.13 2009/08/02 21:40:17 nijtmans Exp $
+ * RCS: @(#) $Id: tkWinImage.c,v 1.14 2010/12/17 15:14:22 nijtmans Exp $
*/
#include "tkWinInt.h"
@@ -303,8 +303,7 @@ XGetImageZPixmap(
BOOL ret;
if (format != ZPixmap) {
- TkpDisplayWarning(
- "XGetImageZPixmap: only ZPixmap types are implemented",
+ TkpDisplayWarning("Only ZPixmap types are implemented",
"XGetImageZPixmap Failure");
return NULL;
}
diff --git a/win/tkWinInit.c b/win/tkWinInit.c
index 8742e48..128cfa9 100644
--- a/win/tkWinInit.c
+++ b/win/tkWinInit.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkWinInit.c,v 1.17 2010/11/24 10:34:18 nijtmans Exp $
+ * RCS: @(#) $Id: tkWinInit.c,v 1.18 2010/12/17 15:14:22 nijtmans Exp $
*/
#include "tkWinInt.h"
@@ -119,20 +119,31 @@ TkpDisplayWarning(
const char *title) /* Title of warning. */
{
#define TK_MAX_WARN_LEN 1024
- WCHAR msgString[TK_MAX_WARN_LEN + 5];
- WCHAR titleString[TK_MAX_WARN_LEN + 1];
+ WCHAR titleString[TK_MAX_WARN_LEN];
+ WCHAR *msgString; /* points to titleString, just after title, leaving space for ": " */
+ int len; /* size of title, including terminating NULL */
- MultiByteToWideChar(CP_UTF8, 0, msg, -1, msgString, TK_MAX_WARN_LEN);
- MultiByteToWideChar(CP_UTF8, 0, title, -1, titleString, TK_MAX_WARN_LEN);
+ len = MultiByteToWideChar(CP_UTF8, 0, title, -1, titleString, TK_MAX_WARN_LEN);
+ msgString = &titleString[len + 1];
+ titleString[TK_MAX_WARN_LEN - 1] = L'\0';
+ MultiByteToWideChar(CP_UTF8, 0, msg, -1, msgString, (TK_MAX_WARN_LEN - 1) - len);
/*
* Truncate MessageBox string if it is too long to not overflow the screen
* and cause possible oversized window error.
*/
- memcpy(msgString + TK_MAX_WARN_LEN, L" ...", 5 * sizeof(WCHAR));
- titleString[TK_MAX_WARN_LEN] = L'\0';
- MessageBoxW(NULL, msgString, titleString,
- MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL
- | MB_SETFOREGROUND | MB_TOPMOST);
+ if (titleString[TK_MAX_WARN_LEN - 1] != L'\0') {
+ memcpy(titleString + (TK_MAX_WARN_LEN - 5), L" ...", 5 * sizeof(WCHAR));
+ }
+ if (IsDebuggerPresent()) {
+ titleString[len - 1] = L':';
+ titleString[len] = L' ';
+ OutputDebugStringW(titleString);
+ } else {
+ titleString[len - 1] = L'\0';
+ MessageBoxW(NULL, msgString, titleString,
+ MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL
+ | MB_SETFOREGROUND | MB_TOPMOST);
+ }
}
/*