Tcl Source Code

Artifact [8017429a85]
Login

Artifact 8017429a857f3a29a3d61a6a01db1bf9da212fd8:

Attachment "491789.patch" to ticket [491789ffff] added by nijtmans 2010-09-16 21:46:09.
Index: generic/tkDecls.h
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkDecls.h,v
retrieving revision 1.50
diff -u -r1.50 tkDecls.h
--- generic/tkDecls.h	21 Aug 2010 16:35:34 -0000	1.50
+++ generic/tkDecls.h	16 Sep 2010 14:33:24 -0000
@@ -1729,14 +1729,18 @@
 
 /* !END!: Do not edit above this line. */
 
-#undef TCL_STORAGE_CLASS
-#define TCL_STORAGE_CLASS DLLIMPORT
-
 /* Functions that don't belong in the stub table */
 #undef Tk_MainEx
 #undef Tk_Init
 #undef Tk_SafeInit
 #undef Tk_CreateConsoleWindow
 
-#endif /* _TKDECLS */
+#if defined(_WIN32) && defined(UNICODE)
+EXTERN void Tk_MainExW(int, TCHAR **, Tcl_AppInitProc *, Tcl_Interp *);
+#   define Tk_MainEx Tk_MainExW
+#endif
 
+#undef TCL_STORAGE_CLASS
+#define TCL_STORAGE_CLASS DLLIMPORT
+
+#endif /* _TKDECLS */
Index: generic/tkMain.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkMain.c,v
retrieving revision 1.33
diff -u -r1.33 tkMain.c
--- generic/tkMain.c	16 Jul 2010 22:06:05 -0000	1.33
+++ generic/tkMain.c	16 Sep 2010 14:33:24 -0000
@@ -16,6 +16,16 @@
  * RCS: @(#) $Id: tkMain.c,v 1.33 2010/07/16 22:06:05 nijtmans Exp $
  */
 
+/**
+ * On Windows, this file needs to be compiled twice, once with
+ * TK_ASCII_MAIN defined. This way both Tk_MainEx and Tk_MainExW
+ * can be implemented, sharing the same source code.
+ */
+#ifndef TK_ASCII_MAIN
+#   undef UNICODE
+#   undef _UNICODE
+#endif
+
 #include <ctype.h>
 #include <stdio.h>
 #include <string.h>
@@ -25,9 +35,39 @@
 #else
 #   include <stdlib.h>
 #endif
+
+/*
+ * This file can be compiled on Windows in UNICODE mode, as well as
+ * on all other platforms using the native encoding. This is done
+ * by using the normal Windows functions like _tcscmp, but on
+ * platforms which don't have <tchar.h> we have to translate that
+ * to strcmp here.
+ */
 #ifdef __WIN32__
-#include "tkWinInt.h"
+#   include "tkWinInt.h"
+#else
+#   define TCHAR char
+#   define TEXT(arg) arg
+#   define _tcscmp strcmp
+#   define _tcslen strlen
+#   define _tcsncmp strncmp
 #endif
+
+/*
+ * Further on, in UNICODE mode, we need to use functions like
+ * Tcl_GetUnicodeFromObj, while otherwise Tcl_GetStringFromObj
+ * is needed. Those macro's assure that the right functions
+ * are used depending on the mode.
+ */
+#ifndef UNICODE
+#   undef Tcl_GetUnicodeFromObj
+#   define Tcl_GetUnicodeFromObj Tcl_GetStringFromObj
+#   undef Tcl_NewUnicodeObj
+#   define Tcl_NewUnicodeObj Tcl_NewStringObj
+#   undef Tcl_WinTCharToUtf
+#   define Tcl_WinTCharToUtf(a,b,c) Tcl_ExternalToUtfDString(NULL,a,b,c)
+#endif /* !UNICODE */
+
 #ifdef MAC_OSX_TK
 #include "tkMacOSXInt.h"
 #endif
@@ -87,7 +127,7 @@
 void
 Tk_MainEx(
     int argc,			/* Number of arguments. */
-    char **argv,		/* Array of argument strings. */
+    TCHAR **argv,		/* Array of argument strings. */
     Tcl_AppInitProc *appInitProc,
 				/* Application-specific initialization
 				 * function to call after most initialization
@@ -150,32 +190,34 @@
 	 *	-file FILENAME		(ancient history support only)
 	 */
 
-	if ((argc > 3) && (0 == strcmp("-encoding", argv[1]))
-		&& ('-' != argv[3][0])) {
-	    Tcl_SetStartupScript(Tcl_NewStringObj(argv[3], -1), argv[2]);
+	if ((argc > 3) && (0 == _tcscmp(TEXT("-encoding"), argv[1]))
+		&& (TEXT('-') != argv[3][0])) {
+		Tcl_Obj *value = Tcl_NewUnicodeObj(argv[2], -1);
+	    Tcl_SetStartupScript(Tcl_NewUnicodeObj(argv[3], -1), Tcl_GetString(value));
+	    Tcl_DecrRefCount(value);
 	    argc -= 3;
 	    argv += 3;
-	} else if ((argc > 1) && ('-' != argv[1][0])) {
-	    Tcl_SetStartupScript(Tcl_NewStringObj(argv[1], -1), NULL);
+	} else if ((argc > 1) && (TEXT('-') != argv[1][0])) {
+	    Tcl_SetStartupScript(Tcl_NewUnicodeObj(argv[1], -1), NULL);
 	    argc--;
 	    argv++;
-	} else if ((argc > 2) && (length = strlen(argv[1]))
-		&& (length > 1) && (0 == strncmp("-file", argv[1], length))
-		&& ('-' != argv[2][0])) {
-	    Tcl_SetStartupScript(Tcl_NewStringObj(argv[2], -1), NULL);
+	} else if ((argc > 2) && (length = _tcslen(argv[1]))
+		&& (length > 1) && (0 == _tcsncmp(TEXT("-file"), argv[1], length))
+		&& (TEXT('-') != argv[2][0])) {
+	    Tcl_SetStartupScript(Tcl_NewUnicodeObj(argv[2], -1), NULL);
 	    argc -= 2;
 	    argv += 2;
 	}
     }
 
     path = Tcl_GetStartupScript(&encodingName);
-    if (NULL == path) {
-	Tcl_ExternalToUtfDString(NULL, argv[0], -1, &appName);
+    if (path == NULL) {
+	Tcl_WinTCharToUtf(argv[0], -1, &appName);
     } else {
 	int numBytes;
-	const char *pathName = Tcl_GetStringFromObj(path, &numBytes);
+	const TCHAR *pathName = Tcl_GetUnicodeFromObj(path, &numBytes);
 
-	Tcl_ExternalToUtfDString(NULL, pathName, numBytes, &appName);
+	Tcl_WinTCharToUtf(pathName, numBytes * sizeof(TCHAR), &appName);
 	path = Tcl_NewStringObj(Tcl_DStringValue(&appName), -1);
 	Tcl_SetStartupScript(path, encodingName);
     }
@@ -190,7 +232,7 @@
     while (argc--) {
 	Tcl_DString ds;
 
-	Tcl_ExternalToUtfDString(NULL, *argv++, -1, &ds);
+	Tcl_WinTCharToUtf(*argv++, -1, &ds);
 	Tcl_ListObjAppendElement(NULL, argvPtr, Tcl_NewStringObj(
 		Tcl_DStringValue(&ds), Tcl_DStringLength(&ds)));
 	Tcl_DStringFree(&ds);
Index: generic/tkStubInit.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkStubInit.c,v
retrieving revision 1.76
diff -u -r1.76 tkStubInit.c
--- generic/tkStubInit.c	21 Aug 2010 16:35:34 -0000	1.76
+++ generic/tkStubInit.c	16 Sep 2010 14:33:25 -0000
@@ -40,6 +40,12 @@
 
 MODULE_SCOPE const TkStubs tkStubs;
 
+/*
+ * Remove macros that will interfere with the definitions below.
+ */
+
+#undef Tk_MainEx
+
 /* !BEGIN!: Do not edit below this line. */
 
 static const TkIntStubs tkIntStubs = {
Index: win/Makefile.in
===================================================================
RCS file: /cvsroot/tktoolkit/tk/win/Makefile.in,v
retrieving revision 1.93
diff -u -r1.93 Makefile.in
--- win/Makefile.in	14 Sep 2010 08:50:20 -0000	1.93
+++ win/Makefile.in	16 Sep 2010 14:33:26 -0000
@@ -315,6 +315,7 @@
 	tkListbox.$(OBJEXT) \
 	tkMacWinMenu.$(OBJEXT) \
 	tkMain.$(OBJEXT) \
+	tkMain2.$(OBJEXT) \
 	tkMenu.$(OBJEXT) \
 	tkMenubutton.$(OBJEXT) \
 	tkMenuDraw.$(OBJEXT) \
@@ -655,6 +656,9 @@
 tkSquare.$(OBJEXT): tkSquare.c
 	$(CC) -c $(CC_SWITCHES) @DEPARG@ $(CC_OBJNAME)
 
+tkMain2.$(OBJEXT): tkMain.c
+	$(CC) -c $(CC_SWITCHES) -DBUILD_tk -DTK_ASCII_MAIN @DEPARG@ $(CC_OBJNAME)
+
 # Extra dependency info
 tkConsole.$(OBJEXT): configure Makefile
 tkMain.$(OBJEXT): configure Makefile
@@ -703,10 +707,12 @@
 	@echo "This warning can be safely ignored, do not report as a bug!"
 
 genstubs:
-	$(TCL_EXE) "$(TCL_TOOL_DIR}\genStubs.tcl" \
+	$(TCL_EXE) "$(TCL_TOOL_DIR)\genStubs.tcl" \
 	    "$(GENERIC_DIR_NATIVE)" \
 	    "$(GENERIC_DIR_NATIVE)\tk.decls" \
-            "$(GENERIC_DIR_NATIVE)\tkInt.decls"
+	    "$(GENERIC_DIR_NATIVE)\tkInt.decls"
+	$(TCL_EXE) "$(TTK_DIR)/ttkGenStubs.tcl" \
+		"$(TTK_DIR)" "$(TTK_DIR)/ttk.decls"
 
 #
 # The list of all the targets that do not correspond to real files. This stops
Index: win/makefile.vc
===================================================================
RCS file: /cvsroot/tktoolkit/tk/win/makefile.vc,v
retrieving revision 1.131
diff -u -r1.131 makefile.vc
--- win/makefile.vc	9 Sep 2010 14:59:24 -0000	1.131
+++ win/makefile.vc	16 Sep 2010 14:33:26 -0000
@@ -331,6 +331,7 @@
 	$(TMP_DIR)\tkListbox.obj \
 	$(TMP_DIR)\tkMacWinMenu.obj \
 	$(TMP_DIR)\tkMain.obj \
+	$(TMP_DIR)\tkMain2.obj \
 	$(TMP_DIR)\tkMenu.obj \
 	$(TMP_DIR)\tkMenubutton.obj \
 	$(TMP_DIR)\tkMenuDraw.obj \
@@ -798,6 +799,9 @@
 	    -DTCL_USE_STATIC_PACKAGES=$(TCL_USE_STATIC_PACKAGES) \
 	    -Fo$@ $?
 
+$(TMP_DIR)\tkMain2.obj: $(GENERICDIR)\tkMain.c
+	$(cc32) -DBUILD_tk $(TK_CFLAGS) -DTK_ASCII_MAIN -Fo$@ $?
+
 # The following objects are part of the stub library and should not
 # be built as DLL objects but none of the symbols should be exported
 # and no reference made to a C runtime.