Index: compat/strftime.c
===================================================================
RCS file: /cvsroot/tcl/tcl/compat/strftime.c,v
retrieving revision 1.10
diff -u -r1.10 strftime.c
--- compat/strftime.c	29 May 2002 00:19:39 -0000	1.10
+++ compat/strftime.c	24 May 2003 20:00:14 -0000
@@ -159,7 +159,7 @@
     const char *format;
     const struct tm *t;
 {
-#ifdef WIN32
+#if defined(WIN32) && !defined(UNDER_CE)
 #define BUF_SIZ 256
     TCHAR buf[BUF_SIZ];
     SYSTEMTIME syst = {
@@ -332,7 +332,7 @@
 		    if (!_conv(t->tm_wday, 1, '0'))
 			return(0);
 		    continue;
-#ifdef WIN32
+#if defined(WIN32) && !defined(UNDER_CE)
 		/*
 		 * To properly handle the localized time routines on Windows,
 		 * we must make use of the special localized calls.
Index: generic/tcl.h
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tcl.h,v
retrieving revision 1.153.2.3
diff -u -r1.153.2.3 tcl.h
--- generic/tcl.h	15 May 2003 18:59:37 -0000	1.153.2.3
+++ generic/tcl.h	24 May 2003 20:00:14 -0000
@@ -87,6 +87,12 @@
 #   endif
 #endif /* __WIN32__ */
 
+#ifdef UNDER_CE
+#   ifndef USE_TCLALLOC
+#	define USE_TCLALLOC 1
+#   endif
+#endif
+
 /*
  * The following definitions set up the proper options for Macintosh
  * compilers.  We use this method because there is no autoconf equivalent.
@@ -365,7 +371,26 @@
 #         define TCL_LL_MODIFIER	"L"
 #         define TCL_LL_MODIFIER_SIZE	1
 #      else /* __BORLANDC__ */
+#         ifdef UNDER_CE
+#      include <sys/types.h> // from CELIB
+struct _stat
+{
+    dev_t st_dev;
+    ino_t st_ino;
+    unsigned short st_mode;
+    short st_nlink;
+    short st_uid;
+    short st_gid;
+    dev_t st_rdev;
+    off_t st_size;
+    time_t st_atime;
+    time_t st_mtime;
+    time_t st_ctime;
+};
+typedef struct _stat	Tcl_StatBuf;
+#         else
 typedef struct _stati64	Tcl_StatBuf;
+#         endif
 #         define TCL_LL_MODIFIER	"I64"
 #         define TCL_LL_MODIFIER_SIZE	3
 #      endif /* __BORLANDC__ */
Index: generic/tclAlloc.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclAlloc.c,v
retrieving revision 1.16
diff -u -r1.16 tclAlloc.c
--- generic/tclAlloc.c	23 Apr 2002 17:03:34 -0000	1.16
+++ generic/tclAlloc.c	24 May 2003 20:00:14 -0000
@@ -41,7 +41,9 @@
  * here, but it can wait until Tcl uses config.h properly.
  */
 #if defined(MAC_TCL) || defined(_MSC_VER) || defined(__MINGW32__) || defined(__BORLANDC__)
+#ifndef UNDER_CE
 typedef unsigned long caddr_t;
+#endif
 #endif
 
 /*
Index: generic/tclIO.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclIO.c,v
retrieving revision 1.61.2.2
diff -u -r1.61.2.2 tclIO.c
--- generic/tclIO.c	11 Apr 2003 17:35:33 -0000	1.61.2.2
+++ generic/tclIO.c	24 May 2003 20:00:14 -0000
@@ -1102,8 +1102,9 @@
      * only if the user recompiles code with older channel drivers in
      * the new system as well.
      */
-
+#ifndef UNDER_CE
     assert(sizeof(Tcl_ChannelTypeVersion) == sizeof(Tcl_DriverBlockModeProc*));
+#endif
 
     /*
      * JH: We could subsequently memset these to 0 to avoid the
Index: generic/tclIOCmd.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclIOCmd.c,v
retrieving revision 1.15
diff -u -r1.15 tclIOCmd.c
--- generic/tclIOCmd.c	15 Feb 2002 14:28:49 -0000	1.15
+++ generic/tclIOCmd.c	24 May 2003 20:00:14 -0000
@@ -968,9 +968,9 @@
     if (!pipeline) {
         chan = Tcl_FSOpenFileChannel(interp, objv[1], modeString, prot);
     } else {
-#ifdef MAC_TCL
+#if defined(MAC_TCL) || defined(UNDER_CE)
 	Tcl_AppendResult(interp,
-		"command pipelines not supported on Macintosh OS",
+		"command pipelines not supported on this OS",
 		(char *)NULL);
 	return TCL_ERROR;
 #else
Index: generic/tclIOUtil.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclIOUtil.c,v
retrieving revision 1.77.2.4
diff -u -r1.77.2.4 tclIOUtil.c
--- generic/tclIOUtil.c	13 May 2003 22:55:50 -0000	1.77.2.4
+++ generic/tclIOUtil.c	24 May 2003 20:00:15 -0000
@@ -1777,7 +1777,11 @@
 	buf->st_nlink = oldStyleStatBuffer.st_nlink;
 	buf->st_uid = oldStyleStatBuffer.st_uid;
 	buf->st_gid = oldStyleStatBuffer.st_gid;
+#ifdef UNDER_CE
+	buf->st_size = oldStyleStatBuffer.st_size;
+#else
 	buf->st_size = Tcl_LongAsWide(oldStyleStatBuffer.st_size);
+#endif
 	buf->st_atime = oldStyleStatBuffer.st_atime;
 	buf->st_mtime = oldStyleStatBuffer.st_mtime;
 	buf->st_ctime = oldStyleStatBuffer.st_ctime;
Index: generic/tclMain.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclMain.c,v
retrieving revision 1.20
diff -u -r1.20 tclMain.c
--- generic/tclMain.c	29 May 2002 22:59:33 -0000	1.20
+++ generic/tclMain.c	24 May 2003 20:00:15 -0000
@@ -25,7 +25,9 @@
  * the Tcl source directory to make their own modified versions).
  */
 
-#if !defined(MAC_TCL)
+#if defined UNDER_CE
+#include <celib.h>
+#elif !defined(MAC_TCL)
 extern int		isatty _ANSI_ARGS_((int fd));
 #else
 #include <unistd.h>
Index: win/Makefile.in
===================================================================
RCS file: /cvsroot/tcl/tcl/win/Makefile.in,v
retrieving revision 1.68
diff -u -r1.68 Makefile.in
--- win/Makefile.in	28 Jan 2003 11:03:53 -0000	1.68
+++ win/Makefile.in	24 May 2003 20:00:15 -0000
@@ -110,6 +110,7 @@
 ROOT_DIR_NATIVE		= $(shell $(CYGPATH) '$(ROOT_DIR)')
 
 LIBRARY_DIR   = $(shell echo '$(ROOT_DIR_NATIVE)/library' | sed 's/\\/\//g' )
+CELIB_DIR		= @CELIB_DIR@
 
 DLLSUFFIX		= @DLLSUFFIX@
 LIBSUFFIX		= @LIBSUFFIX@
@@ -125,7 +126,7 @@
 PIPE_DLL_FILE		= tclpip$(VER)${DLLSUFFIX}
 
 SHARED_LIBRARIES 	= $(TCL_DLL_FILE) $(TCL_STUB_LIB_FILE) \
-			  $(DDE_DLL_FILE) $(REG_DLL_FILE) $(PIPE_DLL_FILE)
+			  $(DDE_DLL_FILE) $(REG_DLL_FILE)
 STATIC_LIBRARIES	= $(TCL_LIB_FILE) $(REG_LIB_FILE) $(DDE_LIB_FILE)
 
 # TCL_EXE is the name of a tclsh executable that is available *BEFORE*
@@ -299,6 +300,14 @@
 
 TCL_DOCS = "$(ROOT_DIR_NATIVE)"/doc/*.[13n]
 
+# Must do this check after AC_FLAGS is defined
+ifeq "$(findstring UNDER_CE,$(AC_FLAGS))" "UNDER_CE"
+WIN_OBJS		+= tclWinCE.$(OBJEXT)
+TCLSH_OBJS		+= tclWinCEmain.$(OBJEXT) tclWinCEconsole.$(OBJEXT)
+else
+SHARED_LIBRARIES 	+= $(PIPE_DLL_FILE)
+endif
+
 all: binaries libraries doc
 
 tcltest: $(TCLTEST)
@@ -411,7 +420,6 @@
 
 tclStubLib.${OBJEXT}: tclStubLib.c
 	$(CC) -c $(CC_SWITCHES) -DSTATIC_BUILD @DEPARG@ $(CC_OBJNAME)
-
 
 # Implicit rule for all object files that will end up in the Tcl library
 
Index: win/configure
===================================================================
RCS file: /cvsroot/tcl/tcl/win/configure,v
retrieving revision 1.56.2.2
diff -u -r1.56.2.2 configure
--- win/configure	15 May 2003 18:59:39 -0000	1.56.2.2
+++ win/configure	24 May 2003 20:00:15 -0000
@@ -18,6 +18,10 @@
 ac_help="$ac_help
   --enable-64bit          enable 64bit support (where applicable)"
 ac_help="$ac_help
+  --enable-wince          enable Win/CE support (where applicable)"
+ac_help="$ac_help
+  --with-celib=DIR        use Windows/CE support library from DIR"
+ac_help="$ac_help
   --enable-symbols        build with debugging symbols [--disable-symbols]"
 
 # Initialize some variables set by options.
@@ -575,7 +579,7 @@
 # Extract the first word of "gcc", so it can be a program name with args.
 set dummy gcc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:579: checking for $ac_word" >&5
+echo "configure:583: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -605,7 +609,7 @@
   # Extract the first word of "cc", so it can be a program name with args.
 set dummy cc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:609: checking for $ac_word" >&5
+echo "configure:613: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -656,7 +660,7 @@
       # Extract the first word of "cl", so it can be a program name with args.
 set dummy cl; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:660: checking for $ac_word" >&5
+echo "configure:664: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -688,7 +692,7 @@
 fi
 
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:692: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:696: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
 
 ac_ext=c
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
@@ -699,12 +703,12 @@
 
 cat > conftest.$ac_ext << EOF
 
-#line 703 "configure"
+#line 707 "configure"
 #include "confdefs.h"
 
 main(){return(0);}
 EOF
-if { (eval echo configure:708: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:712: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   ac_cv_prog_cc_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
@@ -730,12 +734,12 @@
   { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:734: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:738: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:739: checking whether we are using GNU C" >&5
+echo "configure:743: checking whether we are using GNU C" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -744,7 +748,7 @@
   yes;
 #endif
 EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:748: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:752: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gcc=yes
 else
   ac_cv_prog_gcc=no
@@ -763,7 +767,7 @@
 ac_save_CFLAGS="$CFLAGS"
 CFLAGS=
 echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:767: checking whether ${CC-cc} accepts -g" >&5
+echo "configure:771: checking whether ${CC-cc} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -806,7 +810,7 @@
     # Extract the first word of "ar", so it can be a program name with args.
 set dummy ar; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:810: checking for $ac_word" >&5
+echo "configure:814: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_AR'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -835,7 +839,7 @@
     # Extract the first word of "ranlib", so it can be a program name with args.
 set dummy ranlib; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:839: checking for $ac_word" >&5
+echo "configure:843: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -864,7 +868,7 @@
     # Extract the first word of "windres", so it can be a program name with args.
 set dummy windres; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:868: checking for $ac_word" >&5
+echo "configure:872: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_RC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -907,7 +911,7 @@
 #--------------------------------------------------------------------
 
 echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
-echo "configure:911: checking whether ${MAKE-make} sets \${MAKE}" >&5
+echo "configure:915: checking whether ${MAKE-make} sets \${MAKE}" >&5
 set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -939,12 +943,12 @@
 #--------------------------------------------------------------------
 
 echo $ac_n "checking for Cygwin environment""... $ac_c" 1>&6
-echo "configure:943: checking for Cygwin environment" >&5
+echo "configure:947: checking for Cygwin environment" >&5
 if eval "test \"`echo '$''{'ac_cv_cygwin'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 948 "configure"
+#line 952 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -955,7 +959,7 @@
 return __CYGWIN__;
 ; return 0; }
 EOF
-if { (eval echo configure:959: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:963: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_cygwin=yes
 else
@@ -980,7 +984,7 @@
 
 
 echo $ac_n "checking for SEH support in compiler""... $ac_c" 1>&6
-echo "configure:984: checking for SEH support in compiler" >&5
+echo "configure:988: checking for SEH support in compiler" >&5
 if eval "test \"`echo '$''{'tcl_cv_seh'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -988,7 +992,7 @@
   tcl_cv_seh=no
 else
   cat > conftest.$ac_ext <<EOF
-#line 992 "configure"
+#line 996 "configure"
 #include "confdefs.h"
 
 #define WIN32_LEAN_AND_MEAN
@@ -1007,7 +1011,7 @@
 }
 
 EOF
-if { (eval echo configure:1011: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1015: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   tcl_cv_seh=yes
 else
@@ -1037,12 +1041,12 @@
 # sufficient for getting the current code to work.
 #
 echo $ac_n "checking for EXCEPTION_DISPOSITION support in include files""... $ac_c" 1>&6
-echo "configure:1041: checking for EXCEPTION_DISPOSITION support in include files" >&5
+echo "configure:1045: checking for EXCEPTION_DISPOSITION support in include files" >&5
 if eval "test \"`echo '$''{'tcl_cv_eh_disposition'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1046 "configure"
+#line 1050 "configure"
 #include "confdefs.h"
 
 #define WIN32_LEAN_AND_MEAN
@@ -1055,7 +1059,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:1059: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1063: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   tcl_cv_eh_disposition=yes
 else
@@ -1081,12 +1085,12 @@
 # typedefs like LPFN_ACCEPT and friends.
 #
 echo $ac_n "checking for LPFN_ACCEPT support in winsock2.h""... $ac_c" 1>&6
-echo "configure:1085: checking for LPFN_ACCEPT support in winsock2.h" >&5
+echo "configure:1089: checking for LPFN_ACCEPT support in winsock2.h" >&5
 if eval "test \"`echo '$''{'tcl_cv_lpfn_decls'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1090 "configure"
+#line 1094 "configure"
 #include "confdefs.h"
 
 #define WIN32_LEAN_AND_MEAN
@@ -1100,7 +1104,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:1104: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1108: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   tcl_cv_lpfn_decls=yes
 else
@@ -1126,12 +1130,12 @@
 # used by mingw and cygwin is known to do this.
 
 echo $ac_n "checking for winnt.h that ignores VOID define""... $ac_c" 1>&6
-echo "configure:1130: checking for winnt.h that ignores VOID define" >&5
+echo "configure:1134: checking for winnt.h that ignores VOID define" >&5
 if eval "test \"`echo '$''{'tcl_cv_winnt_ignore_void'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1135 "configure"
+#line 1139 "configure"
 #include "confdefs.h"
 
 #define VOID void
@@ -1147,7 +1151,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:1151: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1155: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   tcl_cv_winnt_ignore_void=yes
 else
@@ -1179,12 +1183,12 @@
 # call it from inline asm code.
 
 echo $ac_n "checking for alloca declaration in malloc.h""... $ac_c" 1>&6
-echo "configure:1183: checking for alloca declaration in malloc.h" >&5
+echo "configure:1187: checking for alloca declaration in malloc.h" >&5
 if eval "test \"`echo '$''{'tcl_cv_malloc_decl_alloca'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1188 "configure"
+#line 1192 "configure"
 #include "confdefs.h"
 
 #include <malloc.h>
@@ -1198,7 +1202,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:1202: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1206: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   tcl_cv_malloc_decl_alloca=yes
 else
@@ -1225,12 +1229,12 @@
 # warning when initializing a union member.
 
 echo $ac_n "checking for cast to union support""... $ac_c" 1>&6
-echo "configure:1229: checking for cast to union support" >&5
+echo "configure:1233: checking for cast to union support" >&5
 if eval "test \"`echo '$''{'tcl_cv_cast_to_union'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1234 "configure"
+#line 1238 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -1240,7 +1244,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:1244: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1248: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   tcl_cv_cast_to_union=yes
 else
@@ -1267,13 +1271,13 @@
 #--------------------------------------------------------------------
 
 echo $ac_n "checking for object suffix""... $ac_c" 1>&6
-echo "configure:1271: checking for object suffix" >&5
+echo "configure:1275: checking for object suffix" >&5
 if eval "test \"`echo '$''{'ac_cv_objext'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   rm -f conftest*
 echo 'int i = 1;' > conftest.$ac_ext
-if { (eval echo configure:1277: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1281: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   for ac_file in conftest.*; do
     case $ac_file in
     *.c) ;;
@@ -1291,19 +1295,19 @@
 ac_objext=$ac_cv_objext
 
 echo $ac_n "checking for mingw32 environment""... $ac_c" 1>&6
-echo "configure:1295: checking for mingw32 environment" >&5
+echo "configure:1299: checking for mingw32 environment" >&5
 if eval "test \"`echo '$''{'ac_cv_mingw32'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1300 "configure"
+#line 1304 "configure"
 #include "confdefs.h"
 
 int main() {
 return __MINGW32__;
 ; return 0; }
 EOF
-if { (eval echo configure:1307: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1311: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_mingw32=yes
 else
@@ -1322,7 +1326,7 @@
 
 
 echo $ac_n "checking for executable suffix""... $ac_c" 1>&6
-echo "configure:1326: checking for executable suffix" >&5
+echo "configure:1330: checking for executable suffix" >&5
 if eval "test \"`echo '$''{'ac_cv_exeext'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1332,7 +1336,7 @@
   rm -f conftest*
   echo 'int main () { return 0; }' > conftest.$ac_ext
   ac_cv_exeext=
-  if { (eval echo configure:1336: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
+  if { (eval echo configure:1340: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
     for file in conftest.*; do
       case $file in
       *.c | *.o | *.obj) ;;
@@ -1359,7 +1363,7 @@
 
 
     echo $ac_n "checking for building with threads""... $ac_c" 1>&6
-echo "configure:1363: checking for building with threads" >&5
+echo "configure:1367: checking for building with threads" >&5
     # Check whether --enable-threads or --disable-threads was given.
 if test "${enable_threads+set}" = set; then
   enableval="$enable_threads"
@@ -1396,7 +1400,7 @@
 
 
     echo $ac_n "checking how to build libraries""... $ac_c" 1>&6
-echo "configure:1400: checking how to build libraries" >&5
+echo "configure:1404: checking how to build libraries" >&5
     # Check whether --enable-shared or --disable-shared was given.
 if test "${enable_shared+set}" = set; then
   enableval="$enable_shared"
@@ -1437,7 +1441,7 @@
     # Step 0: Enable 64 bit support?
 
     echo $ac_n "checking if 64bit support is requested""... $ac_c" 1>&6
-echo "configure:1441: checking if 64bit support is requested" >&5
+echo "configure:1445: checking if 64bit support is requested" >&5
     # Check whether --enable-64bit or --disable-64bit was given.
 if test "${enable_64bit+set}" = set; then
   enableval="$enable_64bit"
@@ -1448,13 +1452,39 @@
 
     echo "$ac_t""$do64bit" 1>&6
 
+    # Cross-compiling options for Windows/CE builds
+
+    echo $ac_n "checking if Windows/CE build is requested""... $ac_c" 1>&6
+echo "configure:1459: checking if Windows/CE build is requested" >&5
+    # Check whether --enable-wince or --disable-wince was given.
+if test "${enable_wince+set}" = set; then
+  enableval="$enable_wince"
+  doWince=$enableval
+else
+  doWince=no
+fi
+
+    echo "$ac_t""$doWince" 1>&6
+
+    echo $ac_n "checking for Windows/CE celib directory""... $ac_c" 1>&6
+echo "configure:1471: checking for Windows/CE celib directory" >&5
+    # Check whether --with-celib or --without-celib was given.
+if test "${with_celib+set}" = set; then
+  withval="$with_celib"
+  CELIB_DIR=$withval
+else
+  CELIB_DIR=NO_CELIB
+fi
+
+    echo "$ac_t""$CELIB_DIR" 1>&6
+
     # Set some defaults (may get changed below)
     EXTRA_CFLAGS=""
 
     # Extract the first word of "cygpath", so it can be a program name with args.
 set dummy cygpath; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1458: checking for $ac_word" >&5
+echo "configure:1488: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CYGPATH'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1498,9 +1528,9 @@
 	echo "END" >> $conftest
 
 	echo $ac_n "checking for Windows native path bug in windres""... $ac_c" 1>&6
-echo "configure:1502: checking for Windows native path bug in windres" >&5
+echo "configure:1532: checking for Windows native path bug in windres" >&5
 	cyg_conftest=`$CYGPATH $conftest`
-	if { ac_try='$RC -o conftest.res.o $cyg_conftest'; { (eval echo configure:1504: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } ; then
+	if { ac_try='$RC -o conftest.res.o $cyg_conftest'; { (eval echo configure:1534: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } ; then
 	    echo "$ac_t""no" 1>&6
 	else
 	    echo "$ac_t""yes" 1>&6
@@ -1519,7 +1549,7 @@
     # set various compiler flags depending on whether we are using gcc or cl
 
     echo $ac_n "checking compiler flags""... $ac_c" 1>&6
-echo "configure:1523: checking compiler flags" >&5
+echo "configure:1553: checking compiler flags" >&5
     if test "${GCC}" = "yes" ; then
 	if test "$do64bit" = "yes" ; then
 	    echo "configure: warning: "64bit mode not supported with GCC on Windows"" 1>&2
@@ -1667,7 +1697,7 @@
 	    fi
 	    # In order to work in the tortured autoconf environment,
 	    # we need to ensure that this path has no spaces
-	    MSSDK=$(cygpath -w -s "$MSSDK" | sed -e 's!\\!/!g')
+	    MSSDK=`cygpath -w -s "$MSSDK" | sed -e 's!\\\!/!g'`
 	    if test ! -d "${MSSDK}/bin/win64" ; then
 		echo "configure: warning: "could not find 64-bit SDK to enable 64bit mode"" 1>&2
 		do64bit="no"
@@ -1696,9 +1726,86 @@
 	    LINKBIN="link -link50compat"
 	fi
 
+	if test "$doWince" != "no" ; then
+	    # set defaults
+	    # Currently Tcl requires 300+
+	    CEVERSION=300;    # could be 211 300 301 ...
+	    TARGETCPU=ARM;    # could be ARM MIPS SH3 X86 ...
+	    PLATFORM="Pocket PC 2002"
+	    if test "$doWince" = "yes"; then
+		doWince="300,ARM,ARM,Pocket PC 2002"
+	    fi
+	    eval `echo $doWince | awk -F "," '{ \
+		if (length($1)) { printf "CEVERSION=%s\n", $1 }; \
+		if (length($2)) { printf "TARGETCPU=%s\n", toupper($2) }; \
+		if (length($3)) { printf "ARCH=%s\n", toupper($3) }; \
+		if (length($4)) { printf "PLATFORM=%s\n", $4 }; \
+		}'`
+	    OSVERSION=WCE$CEVERSION;
+	    if test "x${ARCH}" = "x" ; then
+	        ARCH=$TARGETCPU;  # could be ARM MIPS SH3 X86 X86EM ...
+	    fi
+	    if test "x${WCEROOT}" = "x" ; then
+		WCEROOT="C:/Program Files/Microsoft eMbedded Tools"
+	    fi
+	    if test "x${SDKROOT}" = "x" ; then
+		SDKROOT="C:/Windows CE Tools"
+	    fi
+	    # In order to work in the tortured autoconf environment,
+	    # we need to ensure that this path has no spaces
+	    WCEROOT=`cygpath -w -s "$WCEROOT" | sed -e 's!\\\!/!g'`
+	    SDKROOT=`cygpath -w -s "$SDKROOT" | sed -e 's!\\\!/!g'`
+	    CELIB_DIR=`cygpath -w -s "$CELIB_DIR" | sed -e 's!\\\!/!g'`
+	    if test ! -d "${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}"\
+		-o ! -d "${WCEROOT}/EVC/${OSVERSION}/bin"; then
+		{ echo "configure: error: could not find PocketPC SDK or target compiler to enable WinCE mode $CEVERSION,$TARGETCPU,$ARCH,$PLATFORM" 1>&2; exit 1; }
+		doWince="no"
+	    else
+		CEINCLUDE=`cygpath -w -s "${SDKROOT}/${OSVERSION}/${PLATFORM}/include" | sed -e 's!\\\!/!g'`
+		CELIBPATH=`cygpath -w -s "${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}" | sed -e 's!\\\!/!g'`
+	    fi
+	fi
+
+	if test "$doWince" != "no" ; then
+	    if test "${TARGETCPU}" = "X86"; then
+	        CC="${WCEROOT}/EVC/${OSVERSION}/bin/cl.exe -I\"\${CELIB_DIR}/inc\" -I\"${CEINCLUDE}\""
+	    else
+	        CC="${WCEROOT}/EVC/${OSVERSION}/bin/cl${TARGETCPU}.exe -I\"\${CELIB_DIR}/inc\" -I\"${CEINCLUDE}\""
+	    fi
+	    RC="${WCEROOT}/Common/EVC/bin/rc.exe"
+	    cpulower=`echo ${TARGETCPU} | awk '{print tolower($0)}'`
+	    defs="${TARGETCPU} _${TARGETCPU}_ ${cpulower} _${cpulower}_ POCKET_SIZE PALM_SIZE _MT _DLL _WINDOWS"
+	    for i in $defs ; do
+		cat >> confdefs.h <<EOF
+#define $i 1
+EOF
+
+	    done
+	    if test "${ARCH}" = "X86EM"; then
+		#AC_DEFINE_UNQUOTED(_WIN32_WCE_EMULATION)
+	    fi
+	    cat >> confdefs.h <<EOF
+#define _WIN32_WCE $CEVERSION
+EOF
+
+	    cat >> confdefs.h <<EOF
+#define UNDER_CE $CEVERSION
+EOF
+
+	    CFLAGS_DEBUG="-nologo -Zi -Od"
+	    CFLAGS_OPTIMIZE="-nologo -Ox"
+	    lflags="-nodefaultlib -MACHINE:${TARGETCPU} -LIBPATH:\"${CELIBPATH}\" -subsystem:windowsce,3.00"
+	    STLIB_LD="${WCEROOT}/EVC/${OSVERSION}/bin/lib.exe -nologo ${lflags}"
+	    LINKBIN="${WCEROOT}/EVC/${OSVERSION}/bin/link.exe ${lflags}"
+	    
+	    LIBS="\${CELIB_DIR}/wince-${ARCH}-pocket-${OSVERSION}-release/celib.lib coredll.lib corelibc.lib winsock.lib"
+	    LIBS_GUI="commctrl.lib"
+	else
+	    LIBS="user32.lib advapi32.lib"
+	    LIBS_GUI="gdi32.lib comdlg32.lib imm32.lib comctl32.lib shell32.lib"
+	fi
+
 	SHLIB_LD="${LINKBIN} -dll -nologo -incremental:no"
-	LIBS="user32.lib advapi32.lib"
-	LIBS_GUI="gdi32.lib comdlg32.lib imm32.lib comctl32.lib shell32.lib"
 	RC_OUT=-fo
 	RC_TYPE=-r
 	RC_INCLUDE=-i
@@ -1720,8 +1827,13 @@
 
 	# Specify linker flags depending on the type of app being 
 	# built -- Console vs. Window.
-	LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}"
-	LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}"
+	if test "$doWince" != "no" -a "${TARGETCPU}" != "X86"; then
+	    LDFLAGS_CONSOLE="-link ${lflags}"
+	    LDFLAGS_WINDOW=${LDFLAGS_CONSOLE}
+	else
+	    LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}"
+	    LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}"
+	fi
     fi
 
     # DL_LIBS is empty, but then we match the Unix version
@@ -1739,7 +1851,7 @@
 
 
     echo $ac_n "checking for build with symbols""... $ac_c" 1>&6
-echo "configure:1743: checking for build with symbols" >&5
+echo "configure:1855: checking for build with symbols" >&5
     # Check whether --enable-symbols or --disable-symbols was given.
 if test "${enable_symbols+set}" = set; then
   enableval="$enable_symbols"
@@ -1799,7 +1911,7 @@
 #--------------------------------------------------------------------
 
 echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:1803: checking how to run the C preprocessor" >&5
+echo "configure:1915: checking how to run the C preprocessor" >&5
 # On Suns, sometimes $CPP names a directory.
 if test -n "$CPP" && test -d "$CPP"; then
   CPP=
@@ -1814,13 +1926,13 @@
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp.
   cat > conftest.$ac_ext <<EOF
-#line 1818 "configure"
+#line 1930 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1824: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1936: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
@@ -1831,13 +1943,13 @@
   rm -rf conftest*
   CPP="${CC-cc} -E -traditional-cpp"
   cat > conftest.$ac_ext <<EOF
-#line 1835 "configure"
+#line 1947 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1841: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1953: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
@@ -1848,13 +1960,13 @@
   rm -rf conftest*
   CPP="${CC-cc} -nologo -E"
   cat > conftest.$ac_ext <<EOF
-#line 1852 "configure"
+#line 1964 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1858: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1970: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
@@ -1880,17 +1992,17 @@
 
 ac_safe=`echo "errno.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for errno.h""... $ac_c" 1>&6
-echo "configure:1884: checking for errno.h" >&5
+echo "configure:1996: checking for errno.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1889 "configure"
+#line 2001 "configure"
 #include "confdefs.h"
 #include <errno.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1894: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2006: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -2221,6 +2333,7 @@
 s%@EXEEXT@%$EXEEXT%g
 s%@TCL_THREADS@%$TCL_THREADS%g
 s%@CYGPATH@%$CYGPATH%g
+s%@CELIB_DIR@%$CELIB_DIR%g
 s%@DL_LIBS@%$DL_LIBS%g
 s%@CFLAGS_DEBUG@%$CFLAGS_DEBUG%g
 s%@CFLAGS_OPTIMIZE@%$CFLAGS_OPTIMIZE%g
Index: win/tcl.m4
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tcl.m4,v
retrieving revision 1.49.2.1
diff -u -r1.49.2.1 tcl.m4
--- win/tcl.m4	3 Apr 2003 10:03:27 -0000	1.49.2.1
+++ win/tcl.m4	24 May 2003 20:00:15 -0000
@@ -385,6 +385,17 @@
     AC_ARG_ENABLE(64bit,[  --enable-64bit          enable 64bit support (where applicable)], [do64bit=$enableval], [do64bit=no])
     AC_MSG_RESULT($do64bit)
 
+    # Cross-compiling options for Windows/CE builds
+
+    AC_MSG_CHECKING([if Windows/CE build is requested])
+    AC_ARG_ENABLE(wince,[  --enable-wince          enable Win/CE support (where applicable)], [doWince=$enableval], [doWince=no])
+    AC_MSG_RESULT($doWince)
+
+    AC_MSG_CHECKING([for Windows/CE celib directory])
+    AC_ARG_WITH(celib,[  --with-celib=DIR        use Windows/CE support library from DIR],
+	    CELIB_DIR=$withval, CELIB_DIR=NO_CELIB)
+    AC_MSG_RESULT([$CELIB_DIR])
+
     # Set some defaults (may get changed below)
     EXTRA_CFLAGS=""
 
@@ -573,7 +584,7 @@
 	    fi
 	    # In order to work in the tortured autoconf environment,
 	    # we need to ensure that this path has no spaces
-	    MSSDK=$(cygpath -w -s "$MSSDK" | sed -e 's!\\!/!g')
+	    MSSDK=`cygpath -w -s "$MSSDK" | sed -e 's!\\\!/!g'`
 	    if test ! -d "${MSSDK}/bin/win64" ; then
 		AC_MSG_WARN("could not find 64-bit SDK to enable 64bit mode")
 		do64bit="no"
@@ -602,9 +613,77 @@
 	    LINKBIN="link -link50compat"
 	fi
 
+	if test "$doWince" != "no" ; then
+	    # set defaults
+	    # Currently Tcl requires 300+
+	    CEVERSION=300;    # could be 211 300 301 ...
+	    TARGETCPU=ARM;    # could be ARM MIPS SH3 X86 ...
+	    PLATFORM="Pocket PC 2002"
+	    if test "$doWince" = "yes"; then
+		doWince="300,ARM,ARM,Pocket PC 2002"
+	    fi
+	    eval `echo $doWince | awk -F "," '{ \
+		if (length([$]1)) { printf "CEVERSION=%s\n", [$]1 }; \
+		if (length([$]2)) { printf "TARGETCPU=%s\n", toupper([$]2) }; \
+		if (length([$]3)) { printf "ARCH=%s\n", toupper([$]3) }; \
+		if (length([$]4)) { printf "PLATFORM=%s\n", [$]4 }; \
+		}'`
+	    OSVERSION=WCE$CEVERSION;
+	    if test "x${ARCH}" = "x" ; then
+	        ARCH=$TARGETCPU;  # could be ARM MIPS SH3 X86 X86EM ...
+	    fi
+	    if test "x${WCEROOT}" = "x" ; then
+		WCEROOT="C:/Program Files/Microsoft eMbedded Tools"
+	    fi
+	    if test "x${SDKROOT}" = "x" ; then
+		SDKROOT="C:/Windows CE Tools"
+	    fi
+	    # In order to work in the tortured autoconf environment,
+	    # we need to ensure that this path has no spaces
+	    WCEROOT=`cygpath -w -s "$WCEROOT" | sed -e 's!\\\!/!g'`
+	    SDKROOT=`cygpath -w -s "$SDKROOT" | sed -e 's!\\\!/!g'`
+	    CELIB_DIR=`cygpath -w -s "$CELIB_DIR" | sed -e 's!\\\!/!g'`
+	    if test ! -d "${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}"\
+		-o ! -d "${WCEROOT}/EVC/${OSVERSION}/bin"; then
+		AC_MSG_ERROR([could not find PocketPC SDK or target compiler to enable WinCE mode [$CEVERSION,$TARGETCPU,$ARCH,$PLATFORM]])
+		doWince="no"
+	    else
+		CEINCLUDE=`cygpath -w -s "${SDKROOT}/${OSVERSION}/${PLATFORM}/include" | sed -e 's!\\\!/!g'`
+		CELIBPATH=`cygpath -w -s "${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}" | sed -e 's!\\\!/!g'`
+	    fi
+	fi
+
+	if test "$doWince" != "no" ; then
+	    if test "${TARGETCPU}" = "X86"; then
+	        CC="${WCEROOT}/EVC/${OSVERSION}/bin/cl.exe -I\"\${CELIB_DIR}/inc\" -I\"${CEINCLUDE}\""
+	    else
+	        CC="${WCEROOT}/EVC/${OSVERSION}/bin/cl${TARGETCPU}.exe -I\"\${CELIB_DIR}/inc\" -I\"${CEINCLUDE}\""
+	    fi
+	    RC="${WCEROOT}/Common/EVC/bin/rc.exe"
+	    cpulower=`echo ${TARGETCPU} | awk '{print tolower([$]0)}'`
+	    defs="${TARGETCPU} _${TARGETCPU}_ ${cpulower} _${cpulower}_ POCKET_SIZE PALM_SIZE _MT _DLL _WINDOWS"
+	    for i in $defs ; do
+		AC_DEFINE_UNQUOTED($i)
+	    done
+	    if test "${ARCH}" = "X86EM"; then
+		#AC_DEFINE_UNQUOTED(_WIN32_WCE_EMULATION)
+	    fi
+	    AC_DEFINE_UNQUOTED(_WIN32_WCE, $CEVERSION)
+	    AC_DEFINE_UNQUOTED(UNDER_CE, $CEVERSION)
+	    CFLAGS_DEBUG="-nologo -Zi -Od"
+	    CFLAGS_OPTIMIZE="-nologo -Ox"
+	    lflags="-nodefaultlib -MACHINE:${TARGETCPU} -LIBPATH:\"${CELIBPATH}\" -subsystem:windowsce,3.00"
+	    STLIB_LD="${WCEROOT}/EVC/${OSVERSION}/bin/lib.exe -nologo ${lflags}"
+	    LINKBIN="${WCEROOT}/EVC/${OSVERSION}/bin/link.exe ${lflags}"
+	    AC_SUBST(CELIB_DIR)
+	    LIBS="\${CELIB_DIR}/wince-${ARCH}-pocket-${OSVERSION}-release/celib.lib coredll.lib corelibc.lib winsock.lib"
+	    LIBS_GUI="commctrl.lib"
+	else
+	    LIBS="user32.lib advapi32.lib"
+	    LIBS_GUI="gdi32.lib comdlg32.lib imm32.lib comctl32.lib shell32.lib"
+	fi
+
 	SHLIB_LD="${LINKBIN} -dll -nologo -incremental:no"
-	LIBS="user32.lib advapi32.lib"
-	LIBS_GUI="gdi32.lib comdlg32.lib imm32.lib comctl32.lib shell32.lib"
 	RC_OUT=-fo
 	RC_TYPE=-r
 	RC_INCLUDE=-i
@@ -626,8 +705,13 @@
 
 	# Specify linker flags depending on the type of app being 
 	# built -- Console vs. Window.
-	LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}"
-	LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}"
+	if test "$doWince" != "no" -a "${TARGETCPU}" != "X86"; then
+	    LDFLAGS_CONSOLE="-link ${lflags}"
+	    LDFLAGS_WINDOW=${LDFLAGS_CONSOLE}
+	else
+	    LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}"
+	    LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}"
+	fi
     fi
 
     # DL_LIBS is empty, but then we match the Unix version
Index: win/tclAppInit.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclAppInit.c,v
retrieving revision 1.11.2.1
diff -u -r1.11.2.1 tclAppInit.c
--- win/tclAppInit.c	10 May 2003 05:00:11 -0000	1.11.2.1
+++ win/tclAppInit.c	24 May 2003 20:00:15 -0000
@@ -16,7 +16,11 @@
 
 #include "tcl.h"
 #include <windows.h>
+#ifdef UNDER_CE
+#include <io.h>
+#else
 #include <locale.h>
+#endif
 
 #ifdef TCL_TEST
 extern int		Procbodytest_Init _ANSI_ARGS_((Tcl_Interp *interp));
@@ -82,6 +86,7 @@
     extern int TCL_LOCAL_MAIN_HOOK _ANSI_ARGS_((int *argc, char ***argv));
 #endif
 
+#ifndef UNDER_CE
     char buffer[MAX_PATH +1];
     char *p;
     /*
@@ -109,6 +114,7 @@
 	    *p = '/';
 	}
     }
+#endif
 
 #ifdef TCL_LOCAL_MAIN_HOOK
     TCL_LOCAL_MAIN_HOOK(&argc, &argv);
@@ -150,7 +156,9 @@
     /*
      * Install a signal handler to the win32 console tclsh is running in.
      */
+#ifndef UNDER_CE
     SetConsoleCtrlHandler(sigHandler, TRUE);
+#endif
     exitToken = Tcl_AsyncCreate(asyncExit, NULL);
 
     /*
@@ -402,6 +410,7 @@
     return code;
 }
 
+#ifndef UNDER_CE
 /*
  *----------------------------------------------------------------------
  *
@@ -444,6 +453,37 @@
 	CloseHandle(hStdIn);
     }
 
-    /* indicate to the OS not to call the default terminator */
-    return TRUE;
+    /* indicate to the OS not to call the default terminator */ 
+    return TRUE; 
+} 
+#endif // UNDER_CE
+
+#ifdef UNDER_CEX
+#include "celib.h"
+
+LRESULT WINAPI
+wWinMain(HINSTANCE hInstance,
+         HINSTANCE hPrevInstance, 
+         LPWSTR    lpszCmdLine, 
+         int       nCmdShow)
+{
+    char **argv;
+    int argc;
+
+    nCmdShow = SW_SHOWNORMAL;
+
+    XCEShowWaitCursor();
+
+    xceinit(lpszCmdLine);
+    argc = __xceargc;
+    argv = __xceargv;
+
+#ifdef TCL_LOCAL_MAIN_HOOK
+    TCL_LOCAL_MAIN_HOOK(&argc, &argv);
+#endif
+
+    Tcl_Main(argc, argv, TCL_LOCAL_APPINIT);
+
+    return 0;
 }
+#endif // UNDER_CE
Index: win/tclWin32Dll.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWin32Dll.c,v
retrieving revision 1.24.2.1
diff -u -r1.24.2.1 tclWin32Dll.c
--- win/tclWin32Dll.c	14 Apr 2003 15:45:59 -0000	1.24.2.1
+++ win/tclWin32Dll.c	24 May 2003 20:00:15 -0000
@@ -51,7 +51,7 @@
  * wide-character or multi-byte versions of the operating system calls,
  * depending on whether the Unicode calls are available.
  */
-
+#ifndef UNDER_CE
 static TclWinProcs asciiProcs = {
     0,
 
@@ -88,7 +88,7 @@
     (BOOL (WINAPI *)(CONST TCHAR *)) SetCurrentDirectoryA,
     (BOOL (WINAPI *)(CONST TCHAR *, DWORD)) SetFileAttributesA,
     /* 
-     * The three NULL function pointers will only be set when
+     * The NULL function pointers will only be set when
      * Tcl_FindExecutable is called.  If you don't ever call that
      * function, the application will crash whenever WinTcl tries to call
      * functions through these null pointers.  That is not a bug in Tcl
@@ -137,7 +137,7 @@
     (BOOL (WINAPI *)(CONST TCHAR *)) SetCurrentDirectoryW,
     (BOOL (WINAPI *)(CONST TCHAR *, DWORD)) SetFileAttributesW,
     /* 
-     * The three NULL function pointers will only be set when
+     * The NULL function pointers will only be set when
      * Tcl_FindExecutable is called.  If you don't ever call that
      * function, the application will crash whenever WinTcl tries to call
      * functions through these null pointers.  That is not a bug in Tcl
@@ -149,6 +149,102 @@
     NULL,
     NULL,
 };
+#else
+
+/*
+ * Definitions used under Windows CE.
+ */
+
+static TclWinProcs asciiProcs = {
+    0,
+    (BOOL (WINAPI *)(CONST TCHAR *, LPDCB)) XCEBuildCommDCBA,
+    (TCHAR *(WINAPI *)(TCHAR *)) XCECharLowerA,
+    (BOOL (WINAPI *)(CONST TCHAR *, CONST TCHAR *, BOOL)) XCECopyFileA,
+    (BOOL (WINAPI *)(CONST TCHAR *, LPSECURITY_ATTRIBUTES)) XCECreateDirectoryA,
+    (HANDLE (WINAPI *)(CONST TCHAR *, DWORD, DWORD, SECURITY_ATTRIBUTES *, 
+	    DWORD, DWORD, HANDLE)) XCECreateFileA,
+    (BOOL (WINAPI *)(CONST TCHAR *, TCHAR *, LPSECURITY_ATTRIBUTES, 
+	    LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, CONST TCHAR *, 
+	    LPSTARTUPINFOA, LPPROCESS_INFORMATION)) XCECreateProcessA,
+    (BOOL (WINAPI *)(CONST TCHAR *)) XCEDeleteFileA,
+    (HANDLE (WINAPI *)(CONST TCHAR *, WIN32_FIND_DATAT *)) XCEFindFirstFileA,
+    (BOOL (WINAPI *)(HANDLE, WIN32_FIND_DATAT *)) XCEFindNextFileA,
+    (BOOL (WINAPI *)(WCHAR *, LPDWORD)) XCEGetComputerNameA,
+    (DWORD (WINAPI *)(DWORD, WCHAR *)) XCEGetCurrentDirectoryA,
+    (DWORD (WINAPI *)(CONST TCHAR *)) XCEGetFileAttributesA,
+    (DWORD (WINAPI *)(CONST TCHAR *, DWORD nBufferLength, WCHAR *, 
+	    TCHAR **)) XCEGetFullPathNameA,
+    (DWORD (WINAPI *)(HMODULE, WCHAR *, int)) XCEGetModuleFileNameA,
+    (DWORD (WINAPI *)(CONST TCHAR *, WCHAR *, DWORD)) XCEGetShortPathNameA,
+    (UINT (WINAPI *)(CONST TCHAR *, CONST TCHAR *, UINT uUnique, 
+	    WCHAR *)) XCEGetTempFileNameA,
+    (DWORD (WINAPI *)(DWORD, WCHAR *)) XCEGetTempPathA,
+    (BOOL (WINAPI *)(CONST TCHAR *, WCHAR *, DWORD, LPDWORD, LPDWORD, LPDWORD,
+	    WCHAR *, DWORD)) XCEGetVolumeInformationA,
+    (HINSTANCE (WINAPI *)(CONST TCHAR *)) XCELoadLibraryA,
+    (TCHAR (WINAPI *)(WCHAR *, CONST TCHAR *)) XCElstrcpyA,
+    (BOOL (WINAPI *)(CONST TCHAR *, CONST TCHAR *)) XCEMoveFileA,
+    (BOOL (WINAPI *)(CONST TCHAR *)) XCERemoveDirectoryA,
+    (DWORD (WINAPI *)(CONST TCHAR *, CONST TCHAR *, CONST TCHAR *, DWORD, 
+	    WCHAR *, TCHAR **)) NULL,
+    (BOOL (WINAPI *)(CONST TCHAR *)) XCESetCurrentDirectoryA,
+    (BOOL (WINAPI *)(CONST TCHAR *, DWORD)) XCESetFileAttributesA,
+    (BOOL (WINAPI *)(CONST TCHAR *, GET_FILEEX_INFO_LEVELS, 
+	    LPVOID)) XXCEGetFileAttributesExA,
+    (BOOL (WINAPI *)(CONST TCHAR *, CONST TCHAR*, 
+	    LPSECURITY_ATTRIBUTES)) NULL, //CreateHardLinkA,
+    (int (__cdecl*)(CONST TCHAR *, struct _utimbuf *)) xceutime,
+    (HANDLE (WINAPI *)(CONST TCHAR*, UINT, LPVOID, UINT, LPVOID,
+	    DWORD)) NULL, // FindFirstFileExA,
+    (BOOL (WINAPI *)(CONST TCHAR*, TCHAR*,
+	    DWORD)) NULL, // GetVolumeNameForVolumeMountPointA,
+};
+
+static TclWinProcs unicodeProcs = {
+    1,
+    (BOOL (WINAPI *)(CONST TCHAR *, LPDCB)) NULL, //BuildCommDCBW,
+    (TCHAR *(WINAPI *)(TCHAR *)) CharLowerW,
+    (BOOL (WINAPI *)(CONST TCHAR *, CONST TCHAR *, BOOL)) CopyFileW,
+    (BOOL (WINAPI *)(CONST TCHAR *, LPSECURITY_ATTRIBUTES)) CreateDirectoryW,
+    (HANDLE (WINAPI *)(CONST TCHAR *, DWORD, DWORD, SECURITY_ATTRIBUTES *, 
+	    DWORD, DWORD, HANDLE)) CreateFileW,
+    (BOOL (WINAPI *)(CONST TCHAR *, TCHAR *, LPSECURITY_ATTRIBUTES, 
+	    LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, CONST TCHAR *, 
+	    LPSTARTUPINFOA, LPPROCESS_INFORMATION)) CreateProcessW,
+    (BOOL (WINAPI *)(CONST TCHAR *)) DeleteFileW,
+    (HANDLE (WINAPI *)(CONST TCHAR *, WIN32_FIND_DATAT *)) FindFirstFileW,
+    (BOOL (WINAPI *)(HANDLE, WIN32_FIND_DATAT *)) FindNextFileW,
+    (BOOL (WINAPI *)(WCHAR *, LPDWORD)) XXCEGetComputerNameW, //GetComputerNameW,
+    (DWORD (WINAPI *)(DWORD, WCHAR *)) XCEGetCurrentDirectoryW, //GetCurrentDirectoryW,
+    (DWORD (WINAPI *)(CONST TCHAR *)) GetFileAttributesW,
+    (DWORD (WINAPI *)(CONST TCHAR *, DWORD nBufferLength, WCHAR *, 
+	    TCHAR **)) XXCEGetFullPathNameW, //GetFullPathNameW,
+    (DWORD (WINAPI *)(HMODULE, WCHAR *, int)) GetModuleFileNameW,
+    (DWORD (WINAPI *)(CONST TCHAR *, WCHAR *, DWORD)) XXCEGetShortPathNameW,//GetShortPathNameW,
+    (UINT (WINAPI *)(CONST TCHAR *, CONST TCHAR *, UINT uUnique, 
+	    WCHAR *)) GetTempFileNameW,
+    (DWORD (WINAPI *)(DWORD, WCHAR *)) GetTempPathW,
+    (BOOL (WINAPI *)(CONST TCHAR *, WCHAR *, DWORD, LPDWORD, LPDWORD, LPDWORD, 
+	    WCHAR *, DWORD)) XXCEGetVolumeInformationW, //GetVolumeInformationW,
+    (HINSTANCE (WINAPI *)(CONST TCHAR *)) LoadLibraryW,
+    (TCHAR (WINAPI *)(WCHAR *, CONST TCHAR *)) lstrcpyW,
+    (BOOL (WINAPI *)(CONST TCHAR *, CONST TCHAR *)) MoveFileW,
+    (BOOL (WINAPI *)(CONST TCHAR *)) RemoveDirectoryW,
+    (DWORD (WINAPI *)(CONST TCHAR *, CONST TCHAR *, CONST TCHAR *, DWORD, 
+	    WCHAR *, TCHAR **)) NULL, //SearchPathW,
+    (BOOL (WINAPI *)(CONST TCHAR *)) XCESetCurrentDirectoryW, //SetCurrentDirectoryW,
+    (BOOL (WINAPI *)(CONST TCHAR *, DWORD)) SetFileAttributesW,
+    (BOOL (WINAPI *)(CONST TCHAR *, GET_FILEEX_INFO_LEVELS, 
+	    LPVOID)) GetFileAttributesExW,
+    (BOOL (WINAPI *)(CONST TCHAR *, CONST TCHAR*, 
+	    LPSECURITY_ATTRIBUTES)) NULL, //CreateHardLinkW,
+    (int (__cdecl*)(CONST TCHAR *, struct _utimbuf *)) NULL,
+    (HANDLE (WINAPI *)(CONST TCHAR*, UINT, LPVOID, UINT, LPVOID,
+	    DWORD)) FindFirstFileExW,
+    (BOOL (WINAPI *)(CONST TCHAR*, TCHAR*,
+	    DWORD)) NULL, // GetVolumeNameForVolumeMountPointW,
+};
+#endif
 
 TclWinProcs *tclWinProcs;
 static Tcl_Encoding tclWinTCharEncoding;
@@ -157,7 +253,7 @@
  * The following declaration is for the VC++ DLL entry point.
  */
 
-BOOL APIENTRY		DllMain(HINSTANCE hInst, DWORD reason, 
+BOOL APIENTRY		DllMain(HANDLE hInst, DWORD reason, 
 				LPVOID reserved);
 
 /*
@@ -207,7 +303,7 @@
 
 BOOL APIENTRY
 DllEntryPoint(hInst, reason, reserved)
-    HINSTANCE hInst;		/* Library instance handle. */
+    HANDLE hInst;		/* Library instance handle. */
     DWORD reason;		/* Reason this function is being called. */
     LPVOID reserved;		/* Not used. */
 {
@@ -233,7 +329,7 @@
  */
 BOOL APIENTRY
 DllMain(hInst, reason, reserved)
-    HINSTANCE hInst;		/* Library instance handle. */
+    HANDLE hInst;		/* Library instance handle. */
     DWORD reason;		/* Reason this function is being called. */
     LPVOID reserved;		/* Not used. */
 {
@@ -329,6 +425,7 @@
  *	    VER_PLATFORM_WIN32s		Win32s on Windows 3.1. (not supported)
  *	    VER_PLATFORM_WIN32_WINDOWS	Win32 on Windows 95.
  *	    VER_PLATFORM_WIN32_NT	Win32 on Windows NT
+ *	    VER_PLATFORM_WIN32_CE	Win32 on Windows CE
  *
  * Side effects:
  *	None.
Index: win/tclWinCE.c
===================================================================
RCS file: win/tclWinCE.c
diff -N win/tclWinCE.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ win/tclWinCE.c	24 May 2003 20:00:15 -0000
@@ -0,0 +1,360 @@
+/*
+ * tclWinCE.c --
+ *
+ *	This file contains emulation code for Tcl on Windows CE.
+ *	It is adapted from Rainer Keuchel's celib-based port.
+ *	Original celib Time-stamp: <23/12/01 16:44:22 keuchel@netwave.de>
+ *
+ * Copyright (c) 2003 ActiveState Corporation
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
+ * RCS: @(#) $Id: Exp $
+ */
+
+#include "tclWinInt.h"
+#include <winsock.h>
+
+void	async_remove(int s);
+void	async_reset(int s, UINT flag);
+DWORD	async_func(LPDWORD param);
+
+// This should yield to other threads until a message arrives.
+// This is only used in tclWinSock and is ignored for now...
+
+int
+WaitMessage()
+{
+    Sleep(100);
+    return 0;
+}
+
+#undef isatty
+
+int
+isatty(int fd)
+{
+    return xceisatty(fd);
+}
+
+BOOL
+XXCEGetFileAttributesExA(LPCTSTR lpFileName, 
+	GET_FILEEX_INFO_LEVELS fInfoLevelId, 
+	LPVOID lpFileInformation)
+{
+    wchar_t wfname[MAX_PATH];
+
+    MultiByteToWideChar(CP_ACP, 0, lpFileName, -1, wfname, COUNTOF(wfname));
+
+    return GetFileAttributesExW(wfname, fInfoLevelId, lpFileInformation);
+}
+
+BOOL
+XXCEGetComputerNameW(WCHAR *wbuf, LPDWORD lpdwSize)
+{
+    char buf[MAX_PATH];
+
+    if (XCEGetEnvironmentVariableFromRegA("COMPUTERNAME", buf, sizeof(buf))
+	    == 0) {
+	return FALSE;
+    }
+
+    if (wbuf != NULL) {
+	MultiByteToWideChar(CP_ACP, 0, buf, -1, wbuf, *lpdwSize);
+    }
+
+    *lpdwSize = wcslen(wbuf);
+
+    return TRUE;
+}
+
+DWORD
+XXCEGetFullPathNameW(LPCTSTR lpFileName,
+	DWORD nBufferLength, WCHAR *lpBuffer, LPTSTR *lpFilePart)
+{
+    char tmp[MAX_PATH];
+    char tmp2[MAX_PATH];
+    int len;
+
+    WideCharToMultiByte(CP_ACP, 0, lpFileName, -1, tmp, sizeof(tmp),
+	    NULL, NULL);
+    len = XCEGetFullPathNameA(tmp, sizeof(tmp2), tmp2, NULL);
+    if (len) {
+	MultiByteToWideChar(CP_ACP, 0, tmp2, -1, lpBuffer, nBufferLength);
+    }
+    return len;
+}
+
+DWORD
+XXCEGetShortPathNameW(LPCTSTR lpszLongPath, WCHAR *lpszShortPath,
+	DWORD cchBuffer)
+{
+    char tmp[MAX_PATH];
+    char tmp2[MAX_PATH];
+    int len;
+
+    WideCharToMultiByte(CP_ACP, 0, lpszLongPath, -1, tmp, sizeof(tmp),
+	    NULL, NULL);
+    len = XCEGetShortPathNameA(tmp, tmp2, sizeof(tmp2));
+    if (len) {
+	MultiByteToWideChar(CP_ACP, 0, tmp2, -1, lpszShortPath, cchBuffer);
+    }
+    return len;
+}
+
+BOOL
+XXCEGetVolumeInformationW(
+    LPCTSTR  lpRootPathName,	
+    WCHAR *lpVolumeNameBuffer,
+    DWORD  nVolumeNameSize,	
+    LPDWORD  lpVolumeSerialNumber,
+    LPDWORD  lpMaximumComponentLength,
+    LPDWORD  lpFileSystemFlags,	
+    WCHAR *lpFileSystemNameBuffer,
+    DWORD  nFileSystemNameSize)
+{
+    /*
+     * FIX: HACK!  This assumes we are passed a local path.
+     */
+    if (lpMaximumComponentLength) {
+	*lpMaximumComponentLength = MAX_PATH;
+    }
+    if (lpFileSystemNameBuffer) {
+	memset(lpFileSystemNameBuffer, 0, nFileSystemNameSize);
+	xcesnprintf(lpFileSystemNameBuffer, nFileSystemNameSize, L"MEM");
+    }
+    return TRUE;
+}
+
+//////////////////////////////////////////////////////////////////////
+// WSAASyncSelect emulation - needed for xmaxima...
+
+HANDLE hAsyncThread;
+
+#define MAXASYNCSOCKS 10
+
+typedef struct async_entry
+{
+    SOCKET s;
+    HWND hwnd;
+    UINT msg;
+    LONG events;
+    UINT posted;
+} ASYNC_DATA;
+
+ASYNC_DATA asynctab[MAXASYNCSOCKS];
+
+int
+StartAsyncThread()
+{
+    DWORD dwThreadId;
+
+    hAsyncThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) async_func,
+	    NULL, 0, &dwThreadId);
+
+    return 0;
+}
+
+int
+WSAAsyncSelect (SOCKET skt, HWND hwnd, unsigned int msg, long events)
+{
+    int i;
+    int one = 1;
+    int zero = 0;
+
+    XCETrace("WSAAsyncSelect(%d, %x, %x, %x)",
+	    skt, hwnd, msg, events);
+
+    // seems to have problems...
+    if(hAsyncThread == NULL)
+	StartAsyncThread();
+
+    // update old
+    for (i = 0; i < MAXASYNCSOCKS; i++) {
+	ASYNC_DATA *a = &asynctab[i];
+
+	if(a->s == skt) {
+	    a->s = skt; a->hwnd = hwnd; a->msg = msg; a->events = events;
+
+	    if(events == 0) {
+		// Seems to be wrong!?!!!!
+		// ioctlsocket(a->s, FIONBIO, &zero);
+	    } else {
+		ioctlsocket(a->s, FIONBIO, &one);
+	    }
+
+	    return 0;
+	}
+    }
+
+    // new
+    for (i = 0; i < MAXASYNCSOCKS; i++) {
+	ASYNC_DATA *a = &asynctab[i];
+
+	if (a->hwnd == 0) {
+	    a->s = skt; a->hwnd = hwnd; a->msg = msg; a->events = events;
+
+	    ioctlsocket(a->s, FIONBIO, &one);
+
+	    return 0;
+	}
+    }
+
+    return SOCKET_ERROR;
+}
+
+// called from closesocket...
+
+void
+async_remove(int s)
+{
+    int i;
+
+    for (i = 0; i < MAXASYNCSOCKS; i++) {
+	ASYNC_DATA *a = &asynctab[i];
+
+	if (a->s == s) {
+	    a->s = 0;
+	    a->hwnd = 0;
+	    a->msg = 0;
+	    a->events = 0;
+	    a->posted = 0;
+	}
+    }
+}
+
+// called from recv/send
+
+void
+async_reset(int s, UINT flag)
+{
+    int i;
+
+    for (i = 0; i < MAXASYNCSOCKS; i++) {
+	ASYNC_DATA *a = &asynctab[i];
+
+	if (a->s == s) {
+	    a->posted &= ~flag;
+	}
+    }
+}
+
+// thread func
+
+DWORD
+async_func(LPDWORD param)
+{
+    struct timeval tv;
+    fd_set r, w, e;
+    int n;
+    int i;
+
+    while(1) {
+	FD_ZERO(&r);
+	FD_ZERO(&w);
+	FD_ZERO(&e);
+
+	tv.tv_sec = 1;
+	tv.tv_usec = 0;
+
+	for (i = 0; i < MAXASYNCSOCKS; i++) {
+	    int one = 1;
+	    ASYNC_DATA *a = &asynctab[i];
+
+	    if(a->hwnd == 0)
+		continue;
+
+	    if((a->events & FD_ACCEPT) && !(a->posted & FD_ACCEPT))
+		FD_SET(a->s, &r);
+	    if((a->events & FD_READ) && !(a->posted & FD_READ))
+		FD_SET(a->s, &r);
+	    if((a->events & FD_WRITE) && !(a->posted & FD_WRITE))
+		FD_SET(a->s, &w);
+	}
+
+	if ((n = select(0, &r, &w, &e, &tv)) == SOCKET_ERROR) {
+	    DWORD dwError = WSAGetLastError();
+
+	    XCETrace("select: %d", dwError);
+
+	    if (dwError == WSAENOTSOCK) {
+		// could be a socket that has been closed, probably a
+		// listensock that has accepted something...
+	    } else {
+		XCEShowMessageA("tcl: select: %d", WSAGetLastError());
+		exit(1);
+	    }
+	    continue;
+	}
+
+	if (n == 0) {
+	    Sleep(100);
+	    continue;
+	}
+
+	for (i = 0; i < MAXASYNCSOCKS; i++) {
+	    ASYNC_DATA *a = &asynctab[i];
+
+	    if (a->hwnd == 0)
+		continue;
+
+	    if ((a->events & FD_ACCEPT) && FD_ISSET(a->s, &r)) {
+		if(!(a->posted & FD_ACCEPT)) {
+		    XCETrace("Sending FD_ACCEPT to %x, sock %d",
+			    a->hwnd, a->s);
+
+		    PostMessage(a->hwnd, a->msg, a->s, FD_ACCEPT);
+		    a->posted |= FD_ACCEPT;
+		}
+	    }
+	    if ((a->events & FD_READ) && FD_ISSET(a->s, &r)) {
+		if (!(a->posted & FD_READ)) {
+		    XCETrace("Sending FD_READ to %x, sock %d",
+			    a->hwnd, a->s);
+
+		    PostMessage(a->hwnd, a->msg, a->s, FD_READ);
+		    a->posted |= FD_READ;
+		}
+	    }
+	    if ((a->events & FD_WRITE) && FD_ISSET(a->s, &w)) {
+		if (!(a->posted & FD_WRITE)) {
+		    XCETrace("Sending FD_WRITE to %x, sock %d",
+			    a->hwnd, a->s);
+
+		    PostMessage(a->hwnd, a->msg, a->s, FD_WRITE);
+		    a->posted |= FD_WRITE;
+		}
+	    }
+	}
+	Sleep(0);
+    }
+}
+
+//////////////////////////////////////////////////////////////////////
+
+int
+wce_killpid(unsigned long pid)
+{
+    HANDLE hProc;
+    int res;
+
+    XCETrace("Killing %u", pid);
+
+    if ((hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid)) == NULL) {
+	XCETrace("OpenProcess: %d", GetLastError());
+	return -1;
+    }
+
+    if ((res = TerminateProcess(hProc, -1)) != TRUE) {
+	XCETrace("TerminateProcess: %d", GetLastError());
+	return -1;
+    }
+
+    CloseHandle(hProc);
+
+    if (res == FALSE) {
+	return -1;
+    }
+    return 0;
+}
Index: win/tclWinCEconsole.c
===================================================================
RCS file: win/tclWinCEconsole.c
diff -N win/tclWinCEconsole.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ win/tclWinCEconsole.c	24 May 2003 20:00:15 -0000
@@ -0,0 +1,1403 @@
+/* 
+ * tclWinCEconsole.c --
+ *
+ *	This file contains the main entry point for tclsh on Windows CE.
+ *	It is adapted with minor modifications from Rainer Keuchel's
+ *	celib-based w32console package, w32cosole.c file, originally
+ *	written for tvision by (rk).
+ *	celib Time-stamp: <12/02/02 06:41:40 keuchel@netwave.de>
+ *
+ * Copyright (c) 2003 ActiveState Corporation
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
+ * RCS: @(#) $Id: Exp $
+ */
+
+// The buffer is stupid! Too much memcpy()! Should use lines array.
+
+#include <windows.h>
+#include <stdio.h>
+#include <signal.h>
+#include <termios.h>
+#include "tclWinCEconsole.h"
+
+//////////////////////////////////////////////////////////////////////
+
+extern HWND hMainWnd;
+extern char *szTitle;
+extern char *szClassName;
+
+Window *pCurrentWnd;
+
+//////////////////////////////////////////////////////////////////////
+
+int console_read(int fd, unsigned char *buf, int size);
+int console_write(int fd, unsigned char *buf, int size);
+int console_ioctl(int fd, int flags, void *arg);
+
+//////////////////////////////////////////////////////////////////////
+
+int w32console_usefunctionkeys = 1;
+// set to 0 by telnet
+int w32console_handle_signal_chars = 1;
+// set to 0 by telnet
+int w32console_icrlf = 1;
+// unused
+int w32console_optimize_cursor = 0;
+
+// used for terminfo csr
+int scrollstart, scrollend;
+
+int g_nCharWidth[256];
+
+//////////////////////////////////////////////////////////////////////
+
+// Automagically generated by FontTool
+LOGFONT lf = {
+    -10, // lfHeight
+    0,  // lfWidth
+    0, // lfEscapement
+    0, // lfOrientation
+    400, // lfWeight
+    0, // lfItalic
+    0, // lfUnderline
+    0, // lfStrikeOut
+    0, // lfCharSet
+    3, // lfOutPrecision
+    2, // lfClipPrecision
+    1, // lfQuality
+    49, // lfPitchAndFamily
+    "Courier New" // lfFaceName
+};
+
+int wincolors[] = {
+    RGB(0x00, 0x00, 0x00), // BLACK
+    RGB(0xFF, 0xFF, 0xFF), // WHITE
+    RGB(0x00, 0x00, 0xFF), // BLUE
+    RGB(204, 0x00, 0x00), // RED
+    RGB(0x00, 0xFF, 0x00), // GREEN
+    RGB(204, 204, 204), // LIGHTGRAY
+    RGB(153, 153, 153), // DARKGRAY
+    RGB(0x00, 0xFF, 0xFF), // CYAN
+    RGB(0xFF, 0x00, 0x00), // BLACK + BLINK (red)
+    RGB(0xFF, 0x00, 0x00), // WHITE + BLINK (red)
+    RGB(0xFF, 0x00, 0x00), // BLUE + BLINK (red)
+    RGB(0xFF, 0x00, 0x00), // RED + BLINK (red)
+    RGB(0xFF, 0x00, 0x00), // GREEN + BLINK (red)
+    RGB(0xFF, 0x00, 0x00), // LIGHT + BLINK (red)
+    RGB(0xFF, 0x00, 0x00), // DARK + BLINK (red)
+    RGB(0xFF, 0x00, 0x00) // CYAN + BLINK (red)
+};
+
+int
+console_start()
+{
+    int rows = 0;
+    int cols = 0;
+    TEXTMETRIC tm;
+    HDC hdc;
+    HFONT hFont, hOldFont;
+    UINT cx, cy;
+    char buf[126];
+
+    Window *pNew = malloc(sizeof(Window));
+
+    if (XCEGetEnvironmentVariableFromRegA("COLS", buf, sizeof(buf)) > 0) {
+	cols = atoi(buf);
+    }
+    if (XCEGetEnvironmentVariableFromRegA("ROWS", buf, sizeof(buf)) > 0) {
+	rows = atoi(buf);
+    }
+
+    if (rows == 0 || cols == 0) {
+	if ((hdc = GetDC(NULL)) == NULL)
+	    XCEShowMessageA("Cannot get screen DC");
+
+	if ((hFont = console_create_font()) == NULL)
+	    XCEShowMessageA("Cannot create font");
+
+	hOldFont = SelectObject(hdc, hFont);
+	GetTextMetrics(hdc, &tm);
+	SelectObject(hdc, hOldFont);
+	DeleteObject(hFont);
+	ReleaseDC(NULL, hdc);
+
+	cx = GetSystemMetrics(SM_CXSCREEN);
+	cy = GetSystemMetrics(SM_CYSCREEN);
+	cy -= GetSystemMetrics(SM_CYCAPTION);
+
+	cols = cx / tm.tmAveCharWidth;
+	rows = (cy / tm.tmHeight) - 2;
+    }
+
+    pCurrentWnd = window_create(pNew, NULL, 0, 0, cols, rows);
+
+    scrollstart = 0;
+    scrollend = rows - 1;
+
+    // old
+    //xceinitconsole(console_write, console_read);
+    xceinitconsole2(hMainWnd, console_write, console_read, console_ioctl);
+
+    return 0;
+}
+
+HFONT 
+console_create_font()
+{
+    char *p;
+
+    if ((p = getenv("CONSOLEFONTSIZE")) != NULL) {
+	lf.lfHeight = -(atoi(p) + 3);
+    }
+
+    return CreateFontIndirect(&lf);
+}
+
+Window *
+window_create(Window *this, Window *parent, int _x, int _y, int _r, int _b)
+{
+    DWORD dwStyle;
+    int x, y, width, height;
+    HDC hdc;
+    HWND hwndParent = NULL;
+    int i;
+    int color;
+    int size;
+    RECT r;
+
+    this->cx = _x;
+    this->cy = _y;
+    this->cwidth = _r - _x;
+    this->cheight = _b - _y - 2; // magic -2 hack JH
+    this->ctype = _NOCURSOR;
+    this->curcx = 0;
+    this->curcy = 0;
+    //this->bg = DARKGRAY;
+    this->bg = WHITE;
+    this->fg = BLACK;
+
+    this->linemode = 1;
+    this->echo = 1;
+
+    this->inbuf = malloc(sizeof(PFILE));
+    this->inbuf->_base = malloc(512);
+    this->inbuf->_cnt = 0;
+
+    x = 0; 
+    y = 0;
+    width = 0; 
+    height = 0;
+
+    size = this->cwidth * (this->cheight + 1) * sizeof(short);
+    this->buf = (unsigned short *) malloc(size);
+
+    color = (this->fg << 4) | this->bg;
+
+    for (i = 0; i < (this->cheight + 1) * this->cwidth; i++)
+	this->buf[i] = (color << 8) | ' ';
+
+    this->parent = parent;
+
+    if (parent) {
+	hwndParent = parent->hwnd;
+	dwStyle = WS_VISIBLE;
+
+	if ((this->hwnd = CreateWindow(szClassName, szTitle, dwStyle,
+		x, y, width, height, hwndParent, 
+		NULL, NULL, NULL)) == NULL) {
+	    MessageBox(NULL, "Cannot create window", szTitle, MB_OK);
+	    exit(1);
+        }
+    } else {
+	this->hwnd = hMainWnd;
+    }
+
+    SetWindowLongW(this->hwnd, GWL_USERDATA, (long) this);
+
+    hdc = GetDC(this->hwnd);
+    this->hFont = console_create_font();
+    SelectObject(hdc, this->hFont);
+    GetTextMetrics(hdc, &this->tm);
+    XCEGetCharWidthA(hdc, 0, 255, g_nCharWidth);
+    ReleaseDC(this->hwnd, hdc);
+
+  //this->nCharWidth = this->tm.tmMaxCharWidth;
+    this->nCharWidth = this->tm.tmAveCharWidth;
+
+    // When we set CONSOLEFONTSIZE to 9, tmAveCharWidth is 8 and
+    // all in g_nCharWidth are 7...
+    if (this->tm.tmAveCharWidth != g_nCharWidth[0]) {
+	this->nCharWidth = g_nCharWidth[0];
+    }
+
+    this->nCharHeight = this->tm.tmHeight;
+
+    x = _x * this->nCharWidth;
+    y = _y * this->nCharHeight;
+    width = (this->cwidth + 1) * (this->nCharWidth);
+    height = (this->cheight + 1) * (this->nCharHeight);
+
+    if (this->hwnd == hMainWnd) {
+	r.left = x;
+	r.top = y;
+	r.right = x + width;
+	r.bottom = y + height;
+
+#ifdef UNDER_CE
+	AdjustWindowRect(&r, WS_OVERLAPPED, FALSE);
+#else
+	AdjustWindowRect(&r, WS_OVERLAPPED, TRUE);
+#endif
+
+	width = r.right - r.left;
+	height = r.bottom - r.top;
+    } else {
+	r.left = x;
+	r.top = y;
+	r.right = x + width;
+	r.bottom = y + height;
+
+	AdjustWindowRect(&r, WS_OVERLAPPED, FALSE);
+
+	width = r.right - r.left;
+	height = r.bottom - r.top;
+    }
+
+    GetWindowRect(this->hwnd, &r);
+    // on pocket emulator, the top menubar hides the caption
+    XCEMoveWindow(this->hwnd, r.left, r.top, width, height, TRUE);
+
+    return this;
+}
+
+void
+window_delete(Window *this)
+{
+    free(this->buf);
+}
+
+int
+window_gotoxy(Window *this, int x, int y)
+{
+    window_update_cursor(this, 0);
+
+    this->curcx = x - 1; 
+    this->curcy = y - 1;
+
+    if (this->curcx > this->cwidth)
+	this->curcx = this->cwidth;
+    if (this->curcy > this->cheight)
+	this->curcy = this->cheight;
+
+    window_update_cursor(this, 1);
+
+    return 0;
+}
+
+int
+window_getxy(Window *this, int *x, int *y)
+{
+    *x = this->curcx + 1; 
+    *y = this->curcy + 1;
+
+    return 0;
+}
+
+void
+window_setcursortype(Window *this, int type)
+{
+    this->ctype = type;
+}
+
+// This is usually only called with one char...
+
+int
+window_output(Window *this, const char *s)
+{
+    const unsigned char *p;
+    HDC hdc;
+    int x, y;
+    unsigned short color;
+
+    window_update_cursor(this, 0);
+
+    hdc = GetDC(this->hwnd);
+    SelectObject(hdc, this->hFont);
+
+    x = this->curcx * this->nCharWidth;
+    y = this->curcy * this->nCharHeight;
+
+    for (p = (unsigned char *) s; *p; p++) {
+	if (p[0] == '\r') {
+	    x = 0;
+	    this->curcx = 0; 
+	    continue;
+	} else if (p[0] == '\n') {
+	    x = 0;
+	    this->curcx = 0; 
+
+	    if (this->curcy + 1 >= this->cheight) {
+		window_scroll(this, 1);
+            } else {
+		y += this->nCharHeight;
+		this->curcy++;
+            }
+
+	    continue;
+        }
+
+	if (this->curcx < this->cwidth) {
+	    wchar_t wc;
+
+	    SetTextColor(hdc, wincolors[this->fg]);
+	    SetBkColor(hdc, wincolors[this->bg]);
+
+#if 1	  
+	    wc = *p;
+
+	    ExtTextOutW(hdc, x, y, 0, NULL, &wc, 1, NULL);
+#else
+	    ExtTextOut(hdc, x, y, 0, NULL, (char *) p, 1, NULL);
+#endif
+	    color = (this->fg << 4) | (this->bg);
+
+	    this->buf[this->curcy * this->cwidth + this->curcx] 
+		= (color << 8) | *p;
+	}
+
+	this->curcx++;
+
+	x += this->nCharWidth;
+    }
+
+    ReleaseDC(this->hwnd, hdc);
+
+    window_update_cursor(this, 1);
+
+    return 0;
+}
+
+void
+window_handle_timer(Window *this, HWND hwnd)
+{
+    static int flag = 0;
+
+    if (this)
+	window_update_cursor(this, flag);
+
+    flag = !flag;
+}
+
+void
+window_handle_paint(Window *this, HWND hwnd)
+{
+    PAINTSTRUCT ps;
+    HDC hdc;
+    int row;
+    Window *pWnd = this;
+    RECT r;
+
+    BeginPaint(hwnd, &ps);
+    hdc = ps.hdc;
+
+    SelectObject(hdc, this->hFont);
+
+    // fill right/bottom margins 
+    GetClientRect(this->hwnd, &r);
+    r.top = r.bottom - this->nCharHeight;
+    FillRect(hdc, &r, (HBRUSH) (COLOR_WINDOW+1));
+
+    GetClientRect(this->hwnd, &r);
+    r.left = r.right - this->nCharWidth;
+    FillRect(hdc, &r, (HBRUSH) (COLOR_WINDOW+1));
+
+    for (row = 0; row <= pWnd->cheight; row++) {
+	window_update_row(pWnd, row);
+    }
+
+    EndPaint(hwnd, &ps);
+
+    window_update_cursor(this, 1);
+}
+
+void
+window_clearscreen(Window *this)
+{
+    int i;
+    int color = (this->fg << 4) | this->bg;
+  
+    for (i = 0; i < this->cheight * this->cwidth; i++)
+	this->buf[i] = (color << 8) | ' ';
+
+    InvalidateRect(this->hwnd, NULL, TRUE);
+}
+
+void
+window_clear_to_end_of_screen(Window *this)
+{
+    int i;
+    int color = (this->fg << 4) | this->bg;
+    int row;
+
+    for (i = this->curcy * this->cwidth; i < this->cheight * this->cwidth; i++)
+	this->buf[i] = (color << 8) | ' ';
+
+    for (row = this->curcy; row < this->cheight; row++)
+	window_update_row(this, row);
+}
+
+void
+window_cleartoeol(Window *this)
+{
+    int i;
+    int color = (this->fg << 4) | this->bg;
+
+    for (i = this->curcx; i < this->cwidth; i++)
+	this->buf[this->curcy * this->cwidth + i] = (color << 8) | ' ';
+
+    window_update_row(this, this->curcy);
+}
+
+void
+window_insertline(Window *this)
+{
+    int i;
+    int color = (this->fg << 4) | this->bg;
+    int row;
+
+    for (row = scrollend - 1; row >= this->curcy; row--) {
+	memmove(&this->buf[(row+1) * this->cwidth],
+		&this->buf[(row+0) * this->cwidth],
+		this->cwidth * sizeof(short));
+    }
+
+    for (i = this->curcx; i < this->cwidth; i++)
+	this->buf[this->curcy * this->cwidth + i] = (color << 8) | ' ';
+
+    for (row = this->curcy; row <= scrollend; row++)
+	window_update_row(this, row);
+}
+
+void
+window_deleteline(Window *this)
+{
+    int i;
+    int color = (this->fg << 4) | this->bg;
+    int row;
+
+    for (row = this->curcy; row < scrollend; row++) {
+	memmove(&this->buf[(row+0) * this->cwidth],
+		&this->buf[(row+1) * this->cwidth],
+		this->cwidth * sizeof(short));
+    }
+
+    for (i = 0; i < this->cwidth; i++)
+	this->buf[scrollend * this->cwidth + i] = (color << 8) | ' ';
+
+    for (row = this->curcy; row <= scrollend; row++)
+	window_update_row(this, row);
+}
+
+void
+window_scroll(Window *w, int n)
+{
+    int i, j;
+    int color = (w->fg << 4) | w->bg;
+    HDC hdc;
+    RECT r;
+    unsigned short *ps;
+
+    int linesize = w->cwidth * sizeof(w->buf[0]);
+    int l1 = 0;
+    int l2 = w->cwidth;
+
+    // only for n = 1 now...
+    n = 1;
+
+    // move lines up, not very fast...
+    for (i = 0; i < w->cheight-1; i++) {
+	memcpy(&w->buf[l1], &w->buf[l2], linesize);
+	l1 += w->cwidth;
+	l2 += w->cwidth;
+    }
+
+    // clear last line
+    ps = &w->buf[(w->cheight - 1) * w->cwidth];
+    for (j = 0; j < w->cwidth; j++)
+	*ps++ = (color << 8) | ' ';
+
+    ScrollWindowEx(w->hwnd, 0, -(w->nCharHeight), 
+	    NULL, NULL, NULL, NULL, 0);
+
+    // fill new area
+    GetClientRect(w->hwnd, &r);
+    r.top = (w->cheight - 1) * w->nCharHeight;
+
+    hdc = GetDC(w->hwnd);
+    FillRect(hdc, &r, (HBRUSH) (COLOR_WINDOW+1));
+    ReleaseDC(w->hwnd, hdc);
+
+    window_update_row(w, w->cheight-1);
+}
+
+void
+window_update_row(Window *this, int row)
+{
+    char *p;
+    HDC hdc;
+    int x, y;
+    int col;
+    Window *pWnd = this;
+    unsigned short *pb;
+    int oldcolor;
+    int colorchange = 0;
+    char buf[100];
+
+    hdc = GetDC(this->hwnd);
+    SelectObject(hdc, this->hFont);
+
+    x = 0;
+    y = row * this->nCharHeight;
+
+    pb = &pWnd->buf[row * pWnd->cwidth];
+
+    // simple optimization when whole row has same color...
+    // we should output chunks with same color...
+    oldcolor = (*pb) >> 8;
+    for (col = 0, p = buf; col < pWnd->cwidth; col++, pb++) {
+	int color = (*pb) >> 8;
+
+	if (color != oldcolor) {
+	    colorchange = 1;
+	    break;
+	}
+
+	*p++ = (*pb) & 0xFF;
+    }
+
+    pb = &pWnd->buf[row * pWnd->cwidth];
+
+    if (!colorchange) {
+	int color = oldcolor;
+
+	SetTextColor(hdc, wincolors[color >> 4]);
+	SetBkColor(hdc, wincolors[color & 0x0F]);
+
+	ExtTextOut(hdc, x, y, 0, NULL, (char *) buf, pWnd->cwidth, NULL);
+    } else {
+	for (col = 0; col < pWnd->cwidth; col++, pb++) {
+	    unsigned char c = (*pb) & 0xFF;
+	    int color = (*pb) >> 8;
+      
+	    SetTextColor(hdc, wincolors[color >> 4]);
+	    SetBkColor(hdc, wincolors[color & 0x0F]);
+
+	    ExtTextOut(hdc, x, y, 0, NULL, (char *) &c, 1, NULL);
+
+	    x += this->nCharWidth;
+	}
+    }
+
+    ReleaseDC(this->hwnd, hdc);
+
+    window_update_cursor(this, 1);
+}
+
+void
+window_update_cursor(Window *this, int flag)
+{
+    int x, y;
+    HDC hdc;
+    BYTE ch;
+    unsigned short s;
+    int color;
+    int fg, bg;
+
+    x = this->curcx * this->nCharWidth;
+    y = this->curcy * this->nCharHeight;
+
+    hdc = GetDC(this->hwnd);
+    SelectObject(hdc, this->hFont);
+
+    s = this->buf[this->curcy * this->cwidth + this->curcx];
+
+    ch = s & 0xFF;
+    color = s >> 8;
+
+    if (flag) {
+	bg = color >> 4;
+	fg = color & 0xF;
+    } else {
+	fg = color >> 4;
+	bg = color & 0xF;
+    }
+
+    SetTextColor(hdc, wincolors[fg]);
+    SetBkColor(hdc, wincolors[bg]);
+
+    //XCETrace("UpdateCursor(%d, %d, %d, '%c')", flag, x, y, ch);
+
+    ExtTextOut(hdc, x, y, ETO_OPAQUE, NULL, &ch, 1, NULL);
+
+    ReleaseDC(this->hwnd, hdc);
+}
+
+int
+gotoxy(int x, int y)
+{
+    window_gotoxy(pCurrentWnd, x, y);
+
+    return 0;
+}
+
+int
+getxy(int *x, int *y)
+{
+    window_getxy(pCurrentWnd, x, y);
+
+    return 0;
+}
+
+int
+clrscr()
+{
+    window_clearscreen(pCurrentWnd);
+
+    return 0;
+}
+
+int
+clrtoeos()
+{
+    window_clear_to_end_of_screen(pCurrentWnd);
+
+    return 0;
+}
+
+int
+clreol()
+{
+    window_cleartoeol(pCurrentWnd);
+    
+    return 0;
+}
+
+int
+insertline()
+{
+    window_insertline(pCurrentWnd);
+    
+    return 0;
+}
+
+int
+deleteline()
+{
+    window_deleteline(pCurrentWnd);
+    
+    return 0;
+}
+
+int
+textbackground(int color)
+{
+    pCurrentWnd->bg = color;
+    return 0;
+}
+
+int
+textcolor(int color)
+{
+    pCurrentWnd->fg = color;
+    return 0;
+}
+
+int
+setcursortype(int type)
+{
+    window_setcursortype(pCurrentWnd, type);
+
+    return 0;
+}
+
+int
+window_create_new(int x, int y, int w, int h)
+{
+    if (x == 1 && y == 1 && w == 80 && h == 25) {
+	if (pCurrentWnd->parent) {
+	    DestroyWindow(pCurrentWnd->hwnd);
+	    pCurrentWnd = pCurrentWnd->parent;
+	    /* TODO: delete called from WM_DESTROY */
+        }
+    } else {
+	Window *pNew = malloc(sizeof(Window));
+
+	pCurrentWnd = window_create(pNew, pCurrentWnd, x, y, w, h);
+    }
+    return 0;
+}
+
+/* these are not really needed as window() is implemented
+   using real windows */
+
+int
+gettext(int x, int y, int r, int b, void *buf)
+{
+    int row, col;
+    unsigned short *p = (unsigned short *) buf;
+
+    for (row = y - 1; row < b; row++) {
+	for (col = x - 1; col < r; col++)
+	    *p++ = pCurrentWnd->buf[pCurrentWnd->cwidth * row + col];
+    }
+
+    return 0;
+}
+
+int
+puttext(int x, int y, int r, int b, void *buf)
+{
+    int row, col;
+    unsigned short *p = (unsigned short *) buf;
+
+    for (row = y - 1; row < b; row++) {
+	for (col = x - 1; col < r; col++)
+	    pCurrentWnd->buf[pCurrentWnd->cwidth * row + col] = *p++;
+    }
+
+    InvalidateRect(pCurrentWnd->hwnd, NULL, FALSE);
+
+    return 0;
+}
+
+int 
+gettextinfo(struct text_info *ti)
+{
+    ti->winleft = pCurrentWnd->cx;
+    ti->wintop = pCurrentWnd->cy;
+    ti->winright = pCurrentWnd->cx + pCurrentWnd->cwidth;
+    ti->winbottom = pCurrentWnd->cy + pCurrentWnd->cheight;
+    ti->attribute = (pCurrentWnd->fg << 4) | pCurrentWnd->bg;
+    ti->screenheight = 25;
+    ti->screenwidth = 80;
+    ti->curx = pCurrentWnd->curcx;
+    ti->cury = pCurrentWnd->curcy;
+
+    return 0;
+}
+
+int 
+textattr(int attr)
+{
+    pCurrentWnd->fg = (attr >> 4);
+    pCurrentWnd->bg = (attr & 0x0F);
+
+    return 0;
+}
+
+static char console_inputbuf[100];
+static char *console_inputbufp = console_inputbuf;
+
+int
+cgetch()
+{
+    MSG msg;
+
+    window_update_cursor(pCurrentWnd, 1);
+
+    if (*console_inputbufp) {
+	return *console_inputbufp++;
+    } else {
+	console_inputbuf[0] = 0;
+	console_inputbufp = console_inputbuf;
+    }
+
+    while (1) {
+	// This gets messages only for the calling thread and
+	// does not seem to work when called from another thread
+	// than the window thread...
+
+	GetMessage(&msg, NULL, 0, 0);
+
+	if (msg.message == WM_KEYDOWN && w32console_usefunctionkeys) {
+	    char *buf = console_inputbuf;
+
+	    switch(msg.wParam) {
+		case VK_SPACE:
+		    if (GetKeyState(VK_CONTROL)) // Emacs: C-Space
+			return 0;
+		    break;
+		case VK_BACK:
+		    strcpy(buf, "\177");
+		    break;
+		case VK_RIGHT:
+		    strcpy(buf, "\033[C");
+		    break;
+		case VK_LEFT:
+		    strcpy(buf, "\033[D");
+		    break;
+		case VK_UP:
+		    strcpy(buf, "\033[A");
+		    break;
+		case VK_DOWN:
+		    strcpy(buf, "\033[B");
+		    break;
+		default:
+		    buf[0] = 0;
+		    break;
+            }
+
+	    if (buf[0] != 0) {
+		console_inputbufp = buf;
+		return *console_inputbufp++;
+	    }
+        }
+
+	TranslateMessage(&msg);
+	DispatchMessage(&msg);
+
+	if (msg.message == WM_CHAR) {
+	    if (msg.wParam == '\r' && w32console_icrlf)
+		msg.wParam = '\n';
+
+	    // some devices have strange mapping to non-ascii!
+	    if (msg.wParam == 0x2019)
+		msg.wParam = '\'';
+
+	    // telnet escape
+	    if (msg.wParam == ']' && GetKeyState(VK_CONTROL))
+		msg.wParam &= 0x1F;
+
+	    if (msg.wParam == '\003' && w32console_handle_signal_chars)
+		xceraise(SIGINT);
+	    else
+		return msg.wParam;
+        }
+    }
+
+    return 0; // never reached
+}
+
+// get char with echo
+
+int
+cgetche()
+{
+    int c;
+    char buf[2];
+
+    while (1) {
+	c = cgetch();
+
+	if (c == 0x08 && pCurrentWnd->linemode == 1) {
+	    int x, y;
+
+	    getxy(&x, &y);
+
+	    if (x > 1) {
+		gotoxy(x - 1, y);
+		cputch(' ');
+		gotoxy(x - 1, y);
+
+		return c;
+	    }
+	} else {
+	    break;
+	}
+    }
+    
+    if (c != 27 && c != 0) {
+	buf[0] = c;
+	buf[1] = 0;
+
+	cputs(buf);
+    }
+    return c;
+}
+
+int
+cputs(const char *s)
+{
+    const char *p;
+
+    for (p = s; *p; p++)
+	cputch(*p);
+
+    return 0;
+}
+
+int
+cprintf(const char *fmt, ...)
+{
+    va_list ap;
+    char buf[1024];
+    int len;
+
+    va_start(ap, fmt);
+    len = vsprintf(buf, fmt, ap);
+
+    cputs(buf);
+
+    return len;
+}
+
+int
+cputch(int c)
+{
+    static char seq[10];
+    static char *pseq;
+    static int escape = 0;
+
+    unsigned char buf[2];
+
+    // This seems to be DM=242, DATAMARK. Probably OOB...
+    // It is sent when hitting ^G in Emacs under Telnet.
+    // we just ignore it... It's an accent character...
+    if (c == 0xF2) {
+	return c;
+    }
+
+    if (c == '\033') {
+	pseq = seq;
+	*pseq++ = c;
+	escape++;
+	return c;
+    } else if (c == '\t') {
+	int x = pCurrentWnd->curcx; 
+	int y = pCurrentWnd->curcy; 
+
+	x = x / 8;
+	x = x + 1;
+	x = x * 8;
+
+	gotoxy(x+1, y+1);
+
+	return c;
+    } else if (c == '\b') {
+	int x, y;
+	    
+	getxy(&x, &y);
+
+	gotoxy(x - 1, y);
+
+#if 0
+	// readline uses backspace for moving left...
+	cputch(' ');
+	gotoxy(x - 1, y);
+#endif
+
+	return c;
+    } else if (c == '\a') {
+	MessageBeep(0xFFFFFFFF);
+	return c;
+    }
+
+    if (escape == 1 && c != '[')
+	escape = 0;
+
+    if (escape) {
+	*pseq++ = c;
+	escape++;
+
+	switch(c) {
+	    case 'P': // delete char
+	    {
+		Window *w = pCurrentWnd;
+		int i;
+		int start, end;
+		int color = (pCurrentWnd->fg << 4) | pCurrentWnd->bg;
+
+		start = w->curcy * w->cwidth + w->curcx;
+		end = start + w->cwidth - w->curcx;
+
+		for (i = start; i < end; i++) {
+		    w->buf[i] = w->buf[i+1];
+		}
+
+		w->buf[end] = (color << 8) | ' ';
+	    
+		window_update_row(w, w->curcy);
+
+		*pseq++ = 0;
+	    }
+	    escape = 0;
+	    break;
+	    case 'A': // move up
+	    {
+		int x, y;
+	    
+		*pseq++ = 0;
+	    
+		getxy(&x, &y);
+		gotoxy(x, y - 1);
+	    }
+	    escape = 0;
+	    break;
+	    case 'B': // move down
+	    {
+		int x, y;
+	    
+		*pseq++ = 0;
+	    
+		getxy(&x, &y);
+		gotoxy(x, y + 1);
+	    }
+	    escape = 0;
+	    break;
+	    case 'C': // move right
+	    {
+		int x, y;
+	    
+		*pseq++ = 0;
+	    
+		getxy(&x, &y);
+		gotoxy(x + 1, y);
+	    }
+	    escape = 0;
+	    break;
+	    case 'D': // move left
+	    {
+		int x, y;
+	    
+		*pseq++ = 0;
+	    
+		getxy(&x, &y);
+		gotoxy(x - 1, y);
+	    }
+	    escape = 0;
+	    break;
+	    case 'K': 
+	    {
+		*pseq++ = 0;
+		clreol();
+	    }
+	    escape = 0;
+	    break;
+	    case 'L': 
+	    {
+		*pseq++ = 0;
+		insertline();
+	    }	    
+	    escape = 0;
+	    break;
+	    case 'M': 
+	    {
+		*pseq++ = 0;
+		deleteline();
+	    }	    
+	    escape = 0;
+	    break;
+	    case 'm':
+	    {
+		int code;
+
+		*pseq++ = 0;
+
+		if (strcmp(seq, "\033[m") == 0) {
+		    strcpy(seq, "\033[0m");
+		}
+
+		if (sscanf(seq, "\033[%dm", &code) == 1) {
+		    switch(code) {
+			case 0:
+			    textbackground(WHITE);
+			    textcolor(BLACK);
+			    break;
+			case 7:
+			    textbackground(BLACK);
+			    textcolor(WHITE);
+			    break;
+			default:
+			    break;
+		    }
+		}
+	    }
+	    escape = 0;
+	    break;
+	    case 'J':
+	    {
+		*pseq++ = 0;
+
+		if (strcmp(seq, "\033[J") == 0) { // cd
+		    clrtoeos();
+		} else if (strcmp(seq, "\033[2J") == 0) { // cl
+		    clrscr();
+		    gotoxy(1, 1);
+		}
+	    }
+	    escape = 0;
+	    break;
+	    case 'H':
+		// cursor move
+	    {
+		int x, y;
+
+		*pseq++ = 0;
+
+		if (strcmp(seq, "\033[H") == 0) { // home
+		    gotoxy(1, 1);
+		} else if (sscanf(seq, "\033[%d;%dH", &y, &x) == 2) { // cm
+		    if (x <= 0)
+			x = 1;
+		    if (y <= 0)
+			y = 1;
+
+		    gotoxy(x, y);
+		}
+	    }
+	    escape = 0;
+	    break;
+	    case 'r':
+	    {
+		int i1, i2;
+
+		*pseq++ = 0;
+
+		if (sscanf(seq, "\033[%d;%dH", &i1, &i2) == 2) {
+		    // terminfo: csr
+		    scrollstart = i1-1;
+		    scrollend = i2-1;
+		}
+	    }
+	    escape = 0;
+	    break;
+	    default:
+		break;
+	}
+	return c;
+    }
+
+    buf[0] = c;
+    buf[1] = 0;
+
+    window_output(pCurrentWnd, (char *) buf);
+
+    return c;
+}
+
+char *
+cgets(char *buf)
+{
+    char *p;
+    Window *w = pCurrentWnd;
+
+    if ((p = buf) == NULL)
+	return NULL;
+
+    while (1) {
+	if (w->echo)
+	    *p = cgetche();
+	else
+	    *p = cgetch();
+
+	if (*p == 0x08 && p > buf) // backspace
+	    --p;
+	else if (*p == '\n')
+	    break;
+	else
+	    p++;
+    }
+
+    *++p = 0;
+
+    return buf;
+}
+
+//////////////////////////////////////////////////////////////////////
+// external functions
+
+int 
+console_read(int fd, unsigned char *buf, int size)
+{
+    Window *w = pCurrentWnd;
+    int cc = 0;
+
+    if (w->linemode == 0) {
+	if (w->echo)
+	    buf[cc] = cgetche();
+	else
+	    buf[cc] = cgetch();
+
+	size--;
+	cc++;
+
+	while (size && *console_inputbufp) {
+	    buf[cc++] = *console_inputbufp++;
+	}
+
+	return cc;
+    } else if (w->linemode == 1) {
+	for (cc = 0; cc < size;) {
+	    if (w->inbuf->_cnt == 0) {
+		cgets(w->inbuf->_base);
+		w->inbuf->_cnt = strlen(w->inbuf->_base);
+		w->inbuf->_ptr = w->inbuf->_base;
+	    }
+
+	    *buf = *w->inbuf->_ptr++;
+	    cc++; w->inbuf->_cnt--;
+
+	    if (*buf == '\n')
+		break;
+
+	    buf++; 
+	}
+	return cc;
+    }
+    return 0;
+}
+
+int 
+console_write(int fd, unsigned char *buf, int size)
+{
+    int i;
+
+    for (i = 0; i < size; i++)
+	cputch(buf[i]);
+
+    return size;
+}
+
+// 0,0 based
+int
+console_getcursorpos(int *px, int *py)
+{
+    // 1,1 based
+    getxy(px, py);
+    *px -= 1;
+    *py -= 1;
+
+    return 0;
+}
+
+// 0,0 based
+int
+console_gotoxy(int x, int y)
+{
+    // 1,1 based
+    return gotoxy(x+1, y+1);
+}
+
+int
+console_clearscreen()
+{
+    clrscr();
+    gotoxy(1, 1);
+
+    return 0;
+}
+
+int
+console_setlinemode(int linemode)
+{
+    pCurrentWnd->linemode = linemode;
+
+    if (linemode)
+	w32console_icrlf = 1;
+    else
+	w32console_icrlf = 0;
+
+    return 0;
+}
+
+int
+console_setecho(int echo)
+{
+    pCurrentWnd->echo = echo;
+    return 0;
+}
+
+int
+console_readchar(int echo)
+{
+    if (echo)
+	return cgetche();
+
+    return cgetch();
+}
+
+int
+console_getcolsrows(int *pcols, int *prows)
+{
+    *pcols = pCurrentWnd->cwidth;
+    *prows = pCurrentWnd->cheight;
+  
+    return 0;
+}
+
+int
+console_cleartoeol()
+{
+    return clreol();
+}
+
+int
+console_settitle(const char *title)
+{
+    SetWindowText(hMainWnd, title);
+    return 0;
+}
+
+//////////////////////////////////////////////////////////////////////
+static struct termios cur_termios;
+
+int
+console_setattr(int fd, int flags, struct termios *tio)
+{
+    memcpy(&cur_termios, tio, sizeof(struct termios));
+
+    if (tio->c_lflag & ICANON) {
+	console_setlinemode(1);
+    } else {
+	console_setlinemode(0);
+    }
+
+    if (tio->c_lflag & ECHO) {
+	console_setecho(1);
+    } else {
+	console_setecho(0);
+    }
+
+    return 0;
+}
+
+int
+console_getattr(int fd, int flags, struct termios *tio)
+{
+    memcpy(tio, &cur_termios, sizeof(struct termios));
+    return 0;
+}
+
+int
+console_ioctl(int fd, int flags, void *arg)
+{
+    if (flags == TCSETA) {
+	return console_setattr(fd, flags, arg);
+    }
+    else if (flags == TCGETA) {
+	return console_getattr(fd, flags, arg);
+    }
+    else if (flags == TIOCGWINSZ) {
+	struct winsize *ws = (struct winsize *) arg;
+	char *p;
+	int rows = 25;
+	int cols = 80;
+
+	if ((p = getenv("ROWS")) != NULL)
+	    rows = atoi(p);
+
+	if ((p = getenv("COLS")) != NULL)
+	    cols = atoi(p);
+
+	ws->ws_row = rows;
+	ws->ws_col = cols;
+
+	return 0;
+    }
+
+    errno = EINVAL;
+    return -1;
+}
Index: win/tclWinCEconsole.h
===================================================================
RCS file: win/tclWinCEconsole.h
diff -N win/tclWinCEconsole.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ win/tclWinCEconsole.h	24 May 2003 20:00:15 -0000
@@ -0,0 +1,104 @@
+/* 
+ * tclWinCEmain.c --
+ *
+ *	This file contains the main entry point for tclsh on Windows CE.
+ *	It is adapted with minor modifications from Rainer Keuchel's
+ *	celib-based w32console package, w32console.h file.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
+ * RCS: @(#) $Id: Exp $
+ */
+
+#ifndef W32CONSOLE_H
+#define W32CONSOLE_H 1
+
+#include <windows.h>
+#include <celib.h>
+#include <stdio-palmsize.h>
+
+#define BLACK     0
+#define WHITE     1
+#define BLUE      2 
+#define RED       3
+#define GREEN     4
+#define LIGHTGRAY 5
+#define DARKGRAY  6
+#define CYAN      7
+#define BLINK     8
+
+#define _NOCURSOR     0
+#define _NORMALCURSOR 1
+#define _SOLIDCURSOR  2
+
+#define MAXPATH 255
+
+struct _Window {
+    unsigned short *buf;
+    int cx, cy, cwidth, cheight;
+    int curcx, curcy;
+    int ctype;
+    int fg, bg;
+    HANDLE hwnd;
+    HFONT hFont;
+    TEXTMETRIC tm;
+    int nCharWidth;
+    int nCharHeight;
+    int linemode;
+    int echo;
+    PFILE *inbuf;
+    struct _Window *parent;
+};
+
+typedef struct _Window Window;
+
+struct text_info {
+    unsigned char winleft;
+    unsigned char wintop;
+    unsigned char winright;
+    unsigned char winbottom;
+    unsigned char attribute;
+    unsigned char normattr;
+    unsigned char currmode;
+    unsigned char screenheight;
+    unsigned char screenwidth;
+    unsigned char curx;
+    unsigned char cury;
+};
+
+int setcursortype(int type);
+int gettextinfo(struct text_info *ti);
+int textcolor(int c);
+int textbackground(int c);
+int gotoxy(int x, int y);
+int textattr(int attr);
+int clrscr();
+int gettext(int x, int y, int width, int height, void *buf);
+int puttext(int x, int y, int width, int height, void *buf);
+int window(int x, int y, int width, int height);
+
+int cgetch();
+int cgetche();
+int cputs(const char *s);
+int cprintf(const char *fmt, ...);
+int cputch(int c);
+char *cgets(char *s);
+
+int console_start();
+HFONT console_create_font();
+
+Window *window_create(Window *this, Window *parent, int, int, int, int);
+void window_delete(Window *this);
+int window_gotoxy(Window *this, int x, int y);
+void window_setcursortype(Window *this, int type);
+int window_output(Window *this, const char *s);
+void window_handle_timer(Window *this, HWND hwnd);
+void window_handle_paint(Window *this, HWND hwnd);
+void window_clearscreen(Window *this);
+void window_scroll(Window *w, int n);
+
+void window_update_cursor(Window *this, int flag);
+void window_update_row(Window *this, int row);
+
+#endif
Index: win/tclWinCEmain.c
===================================================================
RCS file: win/tclWinCEmain.c
diff -N win/tclWinCEmain.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ win/tclWinCEmain.c	24 May 2003 20:00:15 -0000
@@ -0,0 +1,326 @@
+/* 
+ * tclWinCEmain.c --
+ *
+ *	This file contains the main entry point for tclsh on Windows CE.
+ *	It is adapted with minor modifications from Rainer Keuchel's
+ *	celib-based w32console package, wmain.c file.
+ *	celib Time-stamp: <09/02/02 07:27:49 keuchel@netwave.de>
+ *
+ * Copyright (c) 2003 ActiveState Corporation
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
+ * RCS: @(#) $Id: Exp $
+ */
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <windowsx.h>
+#include <shellapi.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include "tclWinCEconsole.h"
+
+#define CLASSNAME   "ConsoleClass"
+#define CLASSNAMEW  L"ConsoleClass"
+
+#ifdef UNDER_CE
+#include "celib.h"
+#include "ceshared.h"
+#endif
+
+HINSTANCE hInst;
+HWND hMainWnd;
+char     szTitle[126];
+char    *szClassName  = CLASSNAME;
+wchar_t *szClassNameW = CLASSNAMEW;
+
+#define IDM_EXIT 0x100
+
+#define WM_START (WM_USER+100)
+
+BOOL InitApplication(HINSTANCE);
+HWND InitInstance(HINSTANCE, INT);
+void Message(HWND hwnd, const char *fmt, ...);
+
+void DoExit();
+
+int APIENTRY
+wWinMain(HINSTANCE hInstance,
+	HINSTANCE hPrevInstance, 
+#ifdef UNDER_CE
+	LPWSTR    lpCmdLine, 
+#else
+	LPSTR     lpCmdLine, 
+#endif
+	int       nCmdShow)
+{
+    MSG msg;
+    HWND hwnd;
+    char *p;
+    BOOL bNoConsole = FALSE;
+    LPWSTR pw;
+
+    if ((pw = wcsstr(lpCmdLine, L"--noconsole")) != NULL) {
+	bNoConsole = TRUE;
+
+	while (*pw && *pw != ' ')
+	    *pw++ = ' ';
+    }
+
+    // must be called before init!
+    if (xceshared_getshowwindow() == 0) {
+	bNoConsole = TRUE;
+    }
+
+    //XCEShowMessageW(L"%s", lpCmdLine);
+
+    xceinit(lpCmdLine);
+
+    if (bNoConsole) {
+	DoExit(main(__xceargc, __xceargv, environ));
+	// NOT REACHED
+	return 0;
+    }
+
+    if ((p = strrchr(__xceargv[0], '/')) == NULL)
+	p = __xceargv[0];
+    else
+	p++;
+
+    strcpy(szTitle, p);
+
+    if ((p = strrchr(szTitle, '.')) != NULL)
+	*p = 0;
+
+#if 0
+    // When two programms use console, and one starts the other,
+    // FindWindow hangs until the first has exited! Why is this???
+    // Might be possible that this happens only in CE300!
+    if ((hwnd = FindWindow(szClassName, szTitle)) != NULL) {
+	SetForegroundWindow(hwnd);
+	SetActiveWindow(hwnd);
+	return 0;
+    }
+#endif
+
+    if (!hPrevInstance) {
+	if (!InitApplication(hInstance)) {
+	    return FALSE;  
+	}
+    }
+
+    if ((hMainWnd = hwnd = InitInstance(hInstance, nCmdShow)) == NULL) {
+	return FALSE;
+    }
+
+#if 0
+    // Cursor Blink Timer
+    SetTimer(hMainWnd, 23, 1000, NULL);
+#endif
+
+#if 0
+    // handle WM_PAINTS...
+    // infinite loop in emulator, not needed...
+    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+	TranslateMessage(&msg);
+	DispatchMessage(&msg); 
+    }
+#endif
+
+    SendMessage(hwnd, WM_START, 0, 0L);
+
+    while (GetMessage(&msg, NULL, 0, 0)) {
+	TranslateMessage(&msg);
+	DispatchMessage(&msg); 
+    }
+    return TRUE;
+}
+
+int APIENTRY
+WinMain(HINSTANCE hInstance,
+	HINSTANCE hPrevInstance, 
+#ifdef UNDER_CE
+	LPWSTR    lpCmdLine, 
+#else
+	LPSTR     lpCmdLine, 
+#endif
+	int       nCmdShow)
+{
+    return wWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
+}
+
+int
+HandleWMPaint(HWND hwnd)
+{
+    Window *pWnd;
+
+    pWnd = (Window *) GetWindowLongW(hwnd, GWL_USERDATA);
+
+    if (pWnd) {
+	window_handle_paint(pWnd, hwnd);
+	return 0;
+    }
+    return 1;
+}
+
+int
+HandleWMTimer(HWND hwnd)
+{
+    Window *pWnd;
+
+    pWnd = (Window *) GetWindowLongW(hwnd, GWL_USERDATA);
+
+    if (pWnd) {
+	window_handle_timer(pWnd, hwnd);
+	return 0;
+    }
+    return 1;
+}
+
+LRESULT CALLBACK 
+WndProc(HWND hwnd,
+	UINT uMessage,
+	WPARAM wparam,
+	LPARAM lparam)
+{
+    switch(uMessage) {
+	case WM_DESTROY:
+	    KillTimer(hMainWnd, 23);
+	    if (hwnd == hMainWnd)
+		DoExit(0);
+	    break;
+	case WM_COMMAND:
+	    switch(GET_WM_COMMAND_ID(wparam,lparam)) {
+		case IDM_EXIT:
+		    DestroyWindow(hwnd);
+		    DoExit(0);
+		    break;
+	    }
+	    break;
+	case WM_PAINT:
+	    return HandleWMPaint(hwnd);
+	    break;
+	case WM_TIMER:
+	    return HandleWMTimer(hwnd);
+	    break;
+	case WM_START:
+	    console_start();
+#ifdef HANDLE_EXCEPTIONS
+	    __try {
+		//DebugBreak(); // MIPS does not get DebugExceptions!
+#endif
+		DoExit(main(__xceargc, __xceargv, environ));
+#ifdef HANDLE_EXCEPTIONS
+	    }
+	    __except(EXCEPTION_EXECUTE_HANDLER) {
+		XCEShowMessageA("Exception in main()");
+	    }
+#endif
+	    break;
+	default:
+	    return DefWindowProcW(hwnd, uMessage, wparam, lparam);
+    }
+    return 0;
+}
+
+BOOL 
+InitApplication(HINSTANCE hInstance)
+{
+    WNDCLASSW wc;
+
+    wc.style         = CS_HREDRAW | CS_VREDRAW;
+    wc.lpfnWndProc   = (WNDPROC)WndProc;       
+    wc.cbClsExtra    = 0;                      
+    wc.cbWndExtra    = 0;                      
+    wc.hInstance     = hInstance;              
+    wc.hIcon         = NULL;
+    wc.hCursor       = NULL;
+    wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
+    wc.lpszMenuName  = NULL;
+    wc.lpszClassName = szClassNameW;
+
+    if (!RegisterClassW((LPWNDCLASSW)&wc.style))
+	return FALSE;
+
+    return TRUE;
+}
+
+HWND
+InitInstance(HINSTANCE hInstance, int nCmdShow)
+{
+    HWND hwnd;
+#ifndef UNDER_CE
+    HMENU hMenuFile;
+    HMENU hMenuFileDrop;
+#endif
+    DWORD dwStyle;
+    DWORD dwExStyle;
+
+    hInst = hInstance; 
+
+    dwExStyle = 0;
+
+    dwStyle = 0;
+    dwStyle |= WS_CAPTION;
+    dwStyle |= WS_OVERLAPPED;
+    dwStyle |= WS_CAPTION;
+    dwStyle |= WS_SYSMENU;
+    dwStyle |= WS_MINIMIZEBOX|WS_MAXIMIZEBOX;
+
+    hwnd = CreateWindowEx(
+	dwExStyle,
+	szClassName, 
+	szTitle,        
+	dwStyle,
+	CW_USEDEFAULT, 0,   
+	CW_USEDEFAULT, 0,   
+	NULL,               
+	NULL,               
+	hInstance,           
+	NULL);               
+    
+    if (!hwnd)
+	return NULL;
+
+#ifndef UNDER_CE
+    // init menu
+    hMenuFile = CreateMenu();
+    hMenuFileDrop = CreateMenu();
+    AppendMenu(hMenuFile, MF_POPUP, (UINT) hMenuFileDrop, "&File");
+    AppendMenu(hMenuFileDrop, MF_STRING, IDM_EXIT, "E&xit");
+    SetMenu(hwnd, hMenuFile);
+#endif
+
+    nCmdShow = SW_SHOWNORMAL;
+    ShowWindow(hwnd, nCmdShow);
+    UpdateWindow(hwnd);
+
+    return hwnd;
+}
+
+void
+Message(HWND hwnd, const char *fmt, ...)
+{
+    va_list ap;
+    char buf[1024];
+
+    va_start(ap, fmt);
+    vsprintf(buf, fmt, ap);
+    MessageBox(hwnd, buf, "Info", MB_OK);
+}
+
+void
+DoExit(int code)
+{
+    XCETrace("Exitcode %d", code);
+
+#ifdef _WIN32_WCE_EMULATION
+    // NOTE: does not flush file buffers!!!!
+    TerminateProcess(GetCurrentProcess(), code);
+#else
+    exit(code);
+#endif
+}
Index: win/tclWinChan.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinChan.c,v
retrieving revision 1.30
diff -u -r1.30 tclWinChan.c
--- win/tclWinChan.c	26 Jan 2003 05:59:38 -0000	1.30
+++ win/tclWinChan.c	24 May 2003 20:00:15 -0000
@@ -405,9 +405,12 @@
      */
 
     if (!TclInThreadExit() 
+#ifndef UNDER_CE
 	    || ((GetStdHandle(STD_INPUT_HANDLE) != fileInfoPtr->handle)
 		&& (GetStdHandle(STD_OUTPUT_HANDLE) != fileInfoPtr->handle)
-		&& (GetStdHandle(STD_ERROR_HANDLE) != fileInfoPtr->handle))) {
+		&& (GetStdHandle(STD_ERROR_HANDLE) != fileInfoPtr->handle))
+#endif
+	) {
 	if (CloseHandle(fileInfoPtr->handle) == FALSE) {
 	    TclWinConvertError(GetLastError());
 	    errorCode = errno;
@@ -752,7 +755,11 @@
 {
     Tcl_Channel channel = 0;
     int channelPermissions;
+#ifdef UNDER_CE
+    DWORD accessMode, createMode, shareMode, flags, type;
+#else
     DWORD accessMode, createMode, shareMode, flags, consoleParams, type;
+#endif
     CONST TCHAR *nativeName;
     DCB dcb;
     HANDLE handle;
@@ -861,15 +868,26 @@
      * test for the console case first because this is more common.
      */
 
+#ifdef UNDER_CE
+    if (_strnicmp(nativeName, "com", 3) == 0 && 
+	    isdigit(nativeName[3]) &&
+	    nativeName[4] == ':') {
+	type = FILE_TYPE_SERIAL;
+    }
+#endif
+
     if (type == FILE_TYPE_CHAR) {
+#ifdef UNDER_CE
+        if (((DWORD) handle & 0xFFFF000) == 0xBBCD0000) {
+#else
 	if (GetConsoleMode(handle, &consoleParams)) {
+#endif
 	    type = FILE_TYPE_CONSOLE;
 	} else {
 	    dcb.DCBlength = sizeof( DCB ) ;
 	    if (GetCommState(handle, &dcb)) {
 		type = FILE_TYPE_SERIAL;
 	    }
-		    
 	}
     }
 
@@ -914,7 +932,6 @@
 					channelPermissions,
 					(mode & O_APPEND) ? FILE_APPEND : 0);
 	break;
-
     default:
 	/*
 	 * The handle is of an unknown type, probably /dev/nul equivalent
@@ -957,22 +974,29 @@
     char channelName[16 + TCL_INTEGER_SPACE];
     Tcl_Channel channel = NULL;
     HANDLE handle = (HANDLE) rawHandle;
+#ifndef UNDER_CE
     HANDLE dupedHandle;
+    BOOL result;
+    DWORD consoleParams;
+#endif
+    DWORD type;
     DCB dcb;
-    DWORD consoleParams, type;
     TclFile readFile = NULL;
     TclFile writeFile = NULL;
-    BOOL result;
 
     if (mode == 0) {
 	return NULL;
     }
 
+#ifdef UNDER_CEX
+    type = 0;
+#else
     /*
      * GetFileType() returns FILE_TYPE_UNKNOWN for invalid handles.
      */
 
     type = GetFileType(handle);
+#endif
 
     /*
      * If the file is a character device, we need to try to figure out
@@ -981,7 +1005,11 @@
      */
 
     if (type == FILE_TYPE_CHAR) {
+#ifdef UNDER_CE
+        if (((DWORD) handle & 0xFFFF000) == 0xBBCD0000) {
+#else
 	if (GetConsoleMode(handle, &consoleParams)) {
+#endif
 	    type = FILE_TYPE_CONSOLE;
 	} else {
 	    dcb.DCBlength = sizeof( DCB ) ;
@@ -991,8 +1019,7 @@
 	}
     }
 
-    switch (type)
-    {
+    switch (type) {
     case FILE_TYPE_SERIAL:
 	channel = TclWinOpenSerialChannel(handle, channelName, mode);
 	break;
@@ -1000,12 +1027,10 @@
 	channel = TclWinOpenConsoleChannel(handle, channelName, mode);
 	break;
     case FILE_TYPE_PIPE:
-	if (mode & TCL_READABLE)
-	{
+	if (mode & TCL_READABLE) {
 	    readFile = TclWinMakeFile(handle);
 	}
-	if (mode & TCL_WRITABLE)
-	{
+	if (mode & TCL_WRITABLE) {
 	    writeFile = TclWinMakeFile(handle);
 	}
 	channel = TclpCreateCommandChannel(readFile, writeFile, NULL, 0, NULL);
@@ -1027,6 +1052,9 @@
 	 * function in this way.
 	 */
 
+#ifdef UNDER_CE
+	return NULL;
+#else
 	result = DuplicateHandle(GetCurrentProcess(), handle,
 		GetCurrentProcess(), &dupedHandle, 0, FALSE,
 		DUPLICATE_SAME_ACCESS);
@@ -1122,10 +1150,12 @@
 	 */
 
 	channel = TclWinOpenFileChannel(handle, channelName, mode, 0);
+#endif // UNDER_CE
     }
 
     return channel;
 }
+#ifndef UNDER_CE
 #ifdef HAVE_NO_SEH
 static
 __attribute__ ((cdecl))
@@ -1142,7 +1172,8 @@
     _except_makefilechannel_handler(NULL, NULL, NULL, NULL);
     return 0; /* Function does not return */
 }
-#endif
+#endif // HAVE_NO_SEH
+#endif // UNDER_CE
 
 /*
  *----------------------------------------------------------------------
@@ -1170,7 +1201,6 @@
     int mode;
     char *bufMode;
     DWORD handleId;		/* Standard handle to retrieve. */
-
 
     switch (type) {
 	case TCL_STDIN:
Index: win/tclWinConsole.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinConsole.c,v
retrieving revision 1.11
diff -u -r1.11 tclWinConsole.c
--- win/tclWinConsole.c	26 Nov 2002 22:41:58 -0000	1.11
+++ win/tclWinConsole.c	24 May 2003 20:00:15 -0000
@@ -18,6 +18,12 @@
 #include <io.h>
 #include <sys/stat.h>
 
+#ifdef UNDER_CE
+#define ReadConsole ReadFile
+#define ReadConsoleA ReadFile
+#define WriteConsoleA WriteFile
+#endif
+
 /*
  * The following variable is used to tell whether this module has been
  * initialized.
@@ -1012,10 +1018,13 @@
     int blocking)		/* Indicates whether call should be
 				 * blocking or not. */
 {
-    DWORD timeout, count;
     HANDLE *handle = infoPtr->handle;
+    DWORD timeout;
+#ifndef UNDER_CE
+    DWORD count;
     INPUT_RECORD input;
-    
+#endif
+
     while (1) {
 	/*
 	 * Synchronize with the reader thread.
@@ -1043,7 +1052,8 @@
 	if (infoPtr->readFlags & CONSOLE_EOF) {
 	    return 1;
 	}
-	
+
+#ifndef UNDER_CE
 	if (PeekConsoleInput(handle, &input, 1, &count) == FALSE) {
             /*
 	     * Check to see if the peek failed because of EOF.
@@ -1066,6 +1076,7 @@
 		return -1;
 	    }
 	}
+#endif
 
 	/*
 	 * If there is data in the buffer, the console must be
@@ -1289,10 +1300,13 @@
     char *channelName;
     int permissions;
 {
+#ifndef UNDER_CE
     char encoding[4 + TCL_INTEGER_SPACE];
+    DWORD modes;
+#endif
+    DWORD id;
     ConsoleInfo *infoPtr;
     ThreadSpecificData *tsdPtr;
-    DWORD id, modes;
 
     tsdPtr = ConsoleInit();
 
@@ -1306,7 +1320,9 @@
     infoPtr->validMask = permissions;
     infoPtr->handle = handle;
 
+#ifndef UNDER_CE
     wsprintfA(encoding, "cp%d", GetConsoleCP());
+#endif
 
     /*
      * Use the pointer for the name of the result channel.
@@ -1322,6 +1338,7 @@
     infoPtr->threadId = Tcl_GetCurrentThread();
 
     if (permissions & TCL_READABLE) {
+#ifndef UNDER_CE
 	/*
 	 * Make sure the console input buffer is ready for only character
 	 * input notifications and the buffer is set for line buffering.
@@ -1332,6 +1349,7 @@
 	modes &= ~(ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT);
 	modes |= ENABLE_LINE_INPUT;
 	SetConsoleMode(infoPtr->handle, modes);
+#endif
 
 	infoPtr->readable = CreateEvent(NULL, TRUE, TRUE, NULL);
 	infoPtr->startReader = CreateEvent(NULL, FALSE, FALSE, NULL);
@@ -1357,7 +1375,9 @@
     
     Tcl_SetChannelOption(NULL, infoPtr->channel, "-translation", "auto");
     Tcl_SetChannelOption(NULL, infoPtr->channel, "-eofchar", "\032 {}");
+#ifndef UNDER_CE
     Tcl_SetChannelOption(NULL, infoPtr->channel, "-encoding", encoding);
+#endif
 
     return infoPtr->channel;
 }
Index: win/tclWinDde.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinDde.c,v
retrieving revision 1.13
diff -u -r1.13 tclWinDde.c
--- win/tclWinDde.c	3 Mar 2003 17:12:48 -0000	1.13
+++ win/tclWinDde.c	24 May 2003 20:00:15 -0000
@@ -14,6 +14,7 @@
  */
 
 #include "tclPort.h"
+#ifndef UNDER_CE
 #include <ddeml.h>
 
 /*
@@ -1384,3 +1385,28 @@
     }
     return TCL_ERROR;
 }
+
+#else // UNDER_CE
+EXTERN int Dde_Init(Tcl_Interp *interp);
+/*
+ *----------------------------------------------------------------------
+ *
+ * Dde_Init --
+ *
+ *	This procedure initializes the dde command.
+ *
+ * Results:
+ *	A standard Tcl result.
+ *
+ * Side effects:
+ *	None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+Dde_Init(Tcl_Interp *interp)
+{
+    return TCL_OK;
+}
+#endif // UNDER_CE
Index: win/tclWinFCmd.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinFCmd.c,v
retrieving revision 1.35
diff -u -r1.35 tclWinFCmd.c
--- win/tclWinFCmd.c	7 Feb 2003 15:29:33 -0000	1.35
+++ win/tclWinFCmd.c	24 May 2003 20:00:15 -0000
@@ -160,6 +160,10 @@
     Tcl_Obj *srcPathPtr;
     Tcl_Obj *destPathPtr;
 {
+#ifdef UNDER_CE // CE lacks a true notion of "current directory"
+    srcPathPtr  = Tcl_FSGetNormalizedPath(NULL, srcPathPtr);
+    destPathPtr = Tcl_FSGetNormalizedPath(NULL, destPathPtr);
+#endif
     return DoRenameFile(Tcl_FSGetNativePath(srcPathPtr), 
 			Tcl_FSGetNativePath(destPathPtr));
 }
@@ -517,6 +521,10 @@
     Tcl_Obj *srcPathPtr;
     Tcl_Obj *destPathPtr;
 {
+#ifdef UNDER_CE // CE lacks a true notion of "current directory"
+    srcPathPtr  = Tcl_FSGetNormalizedPath(NULL, srcPathPtr);
+    destPathPtr = Tcl_FSGetNormalizedPath(NULL, destPathPtr);
+#endif
     return DoCopyFile(Tcl_FSGetNativePath(srcPathPtr),
 		      Tcl_FSGetNativePath(destPathPtr));
 }
@@ -695,6 +703,9 @@
 TclpObjDeleteFile(pathPtr)
     Tcl_Obj *pathPtr;
 {
+#ifdef UNDER_CE // CE lacks a true notion of "current directory"
+    pathPtr = Tcl_FSGetNormalizedPath(NULL, pathPtr);
+#endif
     return TclpDeleteFile(Tcl_FSGetNativePath(pathPtr));
 }
 
@@ -804,6 +815,9 @@
 TclpObjCreateDirectory(pathPtr)
     Tcl_Obj *pathPtr;
 {
+#ifdef UNDER_CE // CE lacks a true notion of "current directory"
+    pathPtr = Tcl_FSGetNormalizedPath(NULL, pathPtr);
+#endif
     return DoCreateDirectory(Tcl_FSGetNativePath(pathPtr));
 }
 
@@ -856,6 +870,10 @@
     Tcl_DString srcString, dstString;
     int ret;
 
+#ifdef UNDER_CE // CE lacks a true notion of "current directory"
+    srcPathPtr  = Tcl_FSGetNormalizedPath(NULL, srcPathPtr);
+    destPathPtr = Tcl_FSGetNormalizedPath(NULL, destPathPtr);
+#endif
     Tcl_WinUtfToTChar(Tcl_FSGetTranslatedStringPath(NULL,srcPathPtr), 
 		      -1, &srcString);
     Tcl_WinUtfToTChar(Tcl_FSGetTranslatedStringPath(NULL,destPathPtr), 
@@ -911,6 +929,10 @@
 {
     Tcl_DString ds;
     int ret;
+
+#ifdef UNDER_CE // CE lacks a true notion of "current directory"
+    pathPtr = Tcl_FSGetNormalizedPath(NULL, pathPtr);
+#endif
     if (recursive) {
 	/* 
 	 * In the recursive case, the string rep is used to construct a
@@ -999,10 +1021,11 @@
 	    /* 
 	     * Windows 95 and Win32s report removing a non-empty directory 
 	     * as EACCES, not EEXIST.  If the directory is not empty,
-	     * change errno so caller knows what's going on.
+	     * change errno so caller knows what's going on.  Only check
+	     * WIN32_WINDOWS as Win32s is no longer supported.
 	     */
 
-	    if (TclWinGetPlatformId() != VER_PLATFORM_WIN32_NT) {
+	    if (TclWinGetPlatformId() == VER_PLATFORM_WIN32_WINDOWS) {
 		CONST char *path, *find;
 		HANDLE handle;
 		WIN32_FIND_DATAA data;
@@ -1077,8 +1100,8 @@
 				 * causing error. */
 {
     int res = DoRemoveJustDirectory(Tcl_DStringValue(pathPtr), recursive, 
-				    errorPtr);
-    
+	    errorPtr);
+
     if ((res == TCL_ERROR) && (recursive != 0) && (Tcl_GetErrno() == EEXIST)) {
 	/*
 	 * The directory is nonempty, but the recursive flag has been
@@ -1537,6 +1560,9 @@
     Tcl_Obj *splitPath;
     int result = TCL_OK;
 
+#ifdef UNDER_CE // CE lacks a true notion of "current directory"
+    fileName  = Tcl_FSGetNormalizedPath(NULL, fileName);
+#endif
     splitPath = Tcl_FSSplitPath(fileName, &pathc);
 
     if (splitPath == NULL || pathc == 0) {
@@ -1617,6 +1643,9 @@
 		result = TCL_ERROR;
 		goto cleanup;
 	    }
+#ifdef UNDER_CE
+	    nativeName = (TCHAR *) data.w.cFileName;
+#else
 	    if (tclWinProcs->useWide) {
 		nativeName = (TCHAR *) data.w.cAlternateFileName;
 		if (longShort) {
@@ -1640,6 +1669,7 @@
 		    }
 		}
 	    }
+#endif
 
 	    /*
 	     * Purify reports a extraneous UMR in Tcl_WinTCharToUtf() trying 
@@ -1847,6 +1877,11 @@
 Tcl_Obj*
 TclpObjListVolumes(void)
 {
+#ifdef UNDER_CE
+    Tcl_Obj *resultPtr = Tcl_NewObj();
+    Tcl_IncrRefCount(resultPtr);
+    return resultPtr;
+#else
     Tcl_Obj *resultPtr, *elemPtr;
     char buf[40 * 4];		/* There couldn't be more than 30 drives??? */
     int i;
@@ -1892,4 +1927,5 @@
     
     Tcl_IncrRefCount(resultPtr);
     return resultPtr;
+#endif
 }
Index: win/tclWinFile.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinFile.c,v
retrieving revision 1.44.2.4
diff -u -r1.44.2.4 tclWinFile.c
--- win/tclWinFile.c	16 May 2003 01:43:01 -0000	1.44.2.4
+++ win/tclWinFile.c	24 May 2003 20:00:15 -0000
@@ -20,7 +20,12 @@
 #include <winioctl.h>
 #include <sys/stat.h>
 #include <shlobj.h>
+#ifdef UNDER_CE
+#include "dirent.h"
+#include "pwd.h"
+#else
 #include <lmaccess.h>		/* For TclpGetUserHome(). */
+#endif
 
 /*
  * Declarations for 'link' related information.  This information
@@ -128,11 +133,13 @@
     WCHAR  dummyBuf[MAX_PATH*3];
 } DUMMY_REPARSE_BUFFER;
 
+#ifndef UNDER_CE
 #if defined(_MSC_VER) && ( _MSC_VER <= 1100 )
 #define HAVE_NO_FINDEX_ENUMS
 #elif !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0400)
 #define HAVE_NO_FINDEX_ENUMS
 #endif
+#endif
 
 #ifdef HAVE_NO_FINDEX_ENUMS
 /* These two aren't in VC++ 5.2 headers */
@@ -152,6 +159,7 @@
 
 static time_t		ToCTime(FILETIME fileTime);
 
+#ifndef UNDER_CE
 typedef NET_API_STATUS NET_API_FUNCTION NETUSERGETINFOPROC
 	(LPWSTR servername, LPWSTR username, DWORD level, LPBYTE *bufptr);
 
@@ -160,6 +168,7 @@
 
 typedef NET_API_STATUS NET_API_FUNCTION NETGETDCNAMEPROC
 	(LPWSTR servername, LPWSTR domainname, LPBYTE *bufptr);
+#endif
 
 extern Tcl_FSDupInternalRepProc NativeDupInternalRep;
 
@@ -1147,6 +1156,12 @@
     Tcl_DString *bufferPtr;	/* Uninitialized or free DString filled
 				 * with name of user's home directory. */
 {
+#ifdef UNDER_CE
+    Tcl_DStringInit(bufferPtr);
+
+    Tcl_DStringAppend(bufferPtr, "/", 1);
+    return Tcl_DStringValue(bufferPtr);
+#else // UNDER_CE
     char *result;
     HINSTANCE netapiInst;
 
@@ -1243,6 +1258,7 @@
     }
 
     return result;
+#endif // UNDER_CE
 }
 
 /*
@@ -1396,6 +1412,9 @@
     int result;
     CONST TCHAR *nativePath;
 
+#ifdef UNDER_CE // CE lacks a true notion of "current directory"
+    pathPtr  = Tcl_FSGetNormalizedPath(NULL, pathPtr);
+#endif
     nativePath = (CONST TCHAR *) Tcl_FSGetNativePath(pathPtr);
     result = (*tclWinProcs->setCurrentDirectoryProc)(nativePath);
 
@@ -1546,6 +1565,10 @@
     }
 #endif
     
+#ifdef UNDER_CE // CE lacks a true notion of "current directory"
+    pathPtr  = Tcl_FSGetNormalizedPath(NULL, pathPtr);
+#endif
+
     /*
      * Ensure correct file sizes by forcing the OS to write any
      * pending data to disk. This is done only for channels which are
@@ -1595,6 +1618,7 @@
     unsigned short mode;
     
     if (tclWinProcs->getFileAttributesExProc == NULL) {
+#ifndef UNDER_CE
         /* 
          * We don't have the faster attributes proc, so we're
          * probably running on Win95
@@ -1678,6 +1702,7 @@
 	statPtr->st_atime = ToCTime(data.a.ftLastAccessTime);
 	statPtr->st_mtime = ToCTime(data.a.ftLastWriteTime);
 	statPtr->st_ctime = ToCTime(data.a.ftCreationTime);
+#endif // UNDER_CE
     } else {
 	WIN32_FILE_ATTRIBUTE_DATA data;
 	if((*tclWinProcs->getFileAttributesExProc)(nativePath,
@@ -1937,6 +1962,9 @@
     Tcl_Obj *pathPtr;
     int mode;
 {
+#ifdef UNDER_CE // CE lacks a true notion of "current directory"
+    pathPtr  = Tcl_FSGetNormalizedPath(NULL, pathPtr);
+#endif
     return NativeAccess((CONST TCHAR*) Tcl_FSGetNativePath(pathPtr), mode);
 }
 
@@ -1945,6 +1973,10 @@
     Tcl_Obj *pathPtr;
     Tcl_StatBuf *statPtr; 
 {
+#ifdef UNDER_CE // CE lacks a true notion of "current directory"
+    pathPtr  = Tcl_FSGetNormalizedPath(NULL, pathPtr);
+#endif
+
     /*
      * Ensure correct file sizes by forcing the OS to write any
      * pending data to disk. This is done only for channels which are
@@ -1964,6 +1996,10 @@
     Tcl_Obj *toPtr;
     int linkAction;
 {
+#ifdef UNDER_CE // CE lacks a true notion of "current directory"
+    pathPtr = Tcl_FSGetNormalizedPath(NULL, pathPtr);
+    toPtr   = Tcl_FSGetNormalizedPath(NULL, toPtr);
+#endif
     if (toPtr != NULL) {
 	int res;
 	TCHAR* LinkTarget = (TCHAR*)Tcl_FSGetNativePath(toPtr);
@@ -2087,6 +2123,7 @@
     path = Tcl_GetString(pathPtr);
 
     if (TclWinGetPlatformId() == VER_PLATFORM_WIN32_WINDOWS) {
+#ifndef UNDER_CE
 	/* 
 	 * We're on Win95, 98 or ME.  There are two assumptions
 	 * in this block of code.  First that the native (NULL)
@@ -2163,8 +2200,9 @@
 	    }
 	    currentPathEndPosition++;
 	}
+#endif // UNDER_CE
     } else {
-	/* We're on WinNT or 2000 or XP */
+	/* We're on WinNT/2000/XP/CE */
 	Tcl_Obj *temp = NULL;
 	int isDrive = 1;
 	Tcl_DString ds;
@@ -2250,11 +2288,15 @@
 					  sizeof(WCHAR));
 		    } else {
 			WCHAR *nativeName;
+#ifdef UNDER_CE
+			nativeName = fData.cFileName;
+#else
 			if (fData.cFileName[0] != '\0') {
 			    nativeName = fData.cFileName;
 			} else {
 			    nativeName = fData.cAlternateFileName;
 			}
+#endif // UNDER_CE
 			FindClose(handle);
 			Tcl_DStringAppend(&dsNorm,(CONST char*)L"/", 
 					  sizeof(WCHAR));
@@ -2331,6 +2373,10 @@
     Tcl_Obj *pathPtr;      /* File to modify */
     struct utimbuf *tval;  /* New modification date structure */
 {
+#ifdef UNDER_CE
+    Tcl_SetErrno(EACCES);
+    return 0;
+#else
     int res;
     /* 
      * Windows uses a slightly different structure name and, possibly,
@@ -2343,4 +2389,5 @@
     
     res = (*tclWinProcs->utimeProc)(Tcl_FSGetNativePath(pathPtr),&buf);
     return res;
+#endif
 }
Index: win/tclWinInit.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinInit.c,v
retrieving revision 1.40
diff -u -r1.40 tclWinInit.c
--- win/tclWinInit.c	27 Feb 2003 03:47:09 -0000	1.40
+++ win/tclWinInit.c	24 May 2003 20:00:15 -0000
@@ -15,6 +15,10 @@
 #include <winbase.h>
 #include <lmcons.h>
 
+#ifdef UNDER_CE
+char _environ[2048];
+#endif
+
 /*
  * The following declaration is a workaround for some Microsoft brain damage.
  * The SYSTEM_INFO structure is different in various releases, even though the
@@ -68,9 +72,9 @@
  */
 
 
-#define NUMPLATFORMS 3
+#define NUMPLATFORMS 4
 static char* platforms[NUMPLATFORMS] = {
-    "Win32s", "Windows 95", "Windows NT"
+    "Win32s", "Windows 95", "Windows NT", "Windows CE"
 };
 
 #define NUMPROCESSORS 9
@@ -331,7 +335,9 @@
     CONST char *lib)
 {
     int pathc;
+#ifndef UNDER_CE
     WCHAR wBuf[MAX_PATH];
+#endif
     char buf[MAX_PATH * TCL_UTF_MAX];
     Tcl_Obj *objPtr;
     Tcl_DString ds;
@@ -342,12 +348,16 @@
      * that this is a unicode string.
      */
     
+#ifdef UNDER_CE
+    GetEnvironmentVariableA("TCL_LIBRARY", buf, MAX_PATH);
+#else
     if (GetEnvironmentVariableW(L"TCL_LIBRARY", wBuf, MAX_PATH) == 0) {
         buf[0] = '\0';
 	GetEnvironmentVariableA("TCL_LIBRARY", buf, MAX_PATH);
     } else {
 	ToUtf(wBuf, buf);
     }
+#endif
 
     if (buf[0] != '\0') {
 	objPtr = Tcl_NewStringObj(buf, -1);
@@ -524,19 +534,22 @@
     char buf[4 + TCL_INTEGER_SPACE];
 
     if (libraryPathEncodingFixed == 0) {
-	int platformId;
+	int platformId, useWide;
+
 	platformId = TclWinGetPlatformId();
-	TclWinSetInterfaces(platformId == VER_PLATFORM_WIN32_NT);
-	
+	useWide = ((platformId == VER_PLATFORM_WIN32_NT)
+		|| (platformId == VER_PLATFORM_WIN32_CE));
+	TclWinSetInterfaces(useWide);
+
 	wsprintfA(buf, "cp%d", GetACP());
 	Tcl_SetSystemEncoding(NULL, buf);
 
-	if (platformId != VER_PLATFORM_WIN32_NT) {
+	if (!useWide) {
 	    Tcl_Obj *pathPtr = TclGetLibraryPath();
 	    if (pathPtr != NULL) {
 		int i, objc;
 		Tcl_Obj **objv;
-		
+
 		objc = 0;
 		Tcl_ListObjGetElements(NULL, pathPtr, &objc, &objv);
 		for (i = 0; i < objc; i++) {
Index: win/tclWinInt.h
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinInt.h,v
retrieving revision 1.20.2.1
diff -u -r1.20.2.1 tclWinInt.h
--- win/tclWinInt.h	14 Apr 2003 15:46:01 -0000	1.20.2.1
+++ win/tclWinInt.h	24 May 2003 20:00:15 -0000
@@ -37,10 +37,14 @@
 /*
  * Some versions of Borland C have a define for the OSVERSIONINFO for
  * Win32s and for NT, but not for Windows 95.
+ * Define VER_PLATFORM_WIN32_CE for those without newer headers.
  */
 
 #ifndef VER_PLATFORM_WIN32_WINDOWS
 #define VER_PLATFORM_WIN32_WINDOWS 1
+#endif
+#ifndef VER_PLATFORM_WIN32_CE
+#define VER_PLATFORM_WIN32_CE 3
 #endif
 
 /*
Index: win/tclWinMtherr.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinMtherr.c,v
retrieving revision 1.5
diff -u -r1.5 tclWinMtherr.c
--- win/tclWinMtherr.c	31 May 2002 22:20:22 -0000	1.5
+++ win/tclWinMtherr.c	24 May 2003 20:00:15 -0000
@@ -40,6 +40,9 @@
 _matherr(xPtr)
     struct exception *xPtr;	/* Describes error that occurred. */
 {
+#ifdef UNDER_CE
+    return 0;
+#else
     if ((xPtr->type == DOMAIN)
 #ifdef __BORLANDC__
 	    || (xPtr->type == TLOSS)
@@ -50,4 +53,5 @@
 	errno = ERANGE;
     }
     return 1;
+#endif
 }
Index: win/tclWinPipe.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinPipe.c,v
retrieving revision 1.33.2.1
diff -u -r1.33.2.1 tclWinPipe.c
--- win/tclWinPipe.c	12 Mar 2003 19:19:32 -0000	1.33.2.1
+++ win/tclWinPipe.c	24 May 2003 20:00:15 -0000
@@ -982,7 +982,10 @@
     STARTUPINFOA startInfo;
     PROCESS_INFORMATION procInfo;
     SECURITY_ATTRIBUTES secAtts;
-    HANDLE hProcess, h, inputHandle, outputHandle, errorHandle;
+    HANDLE hProcess, inputHandle, outputHandle, errorHandle;
+#ifndef UNDER_CE
+    HANDLE h;
+#endif
     char execPath[MAX_PATH * TCL_UTF_MAX];
     WinFile *filePtr;
 
@@ -1041,6 +1044,12 @@
 	}
     }
 
+#ifdef UNDER_CE
+    if (inputHandle == NULL) {
+	inputHandle = INVALID_HANDLE_VALUE;
+    }
+#endif
+
     /*
      * Duplicate all the handles which will be passed off as stdin, stdout
      * and stderr of the child process. The duplicate handles are set to
@@ -1060,20 +1069,24 @@
 	 * as an immediate EOF and can pass that information to the 
 	 * child process.
 	 */
-
+#ifndef UNDER_CE
 	if (CreatePipe(&startInfo.hStdInput, &h, &secAtts, 0) != FALSE) {
 	    CloseHandle(h);
 	}
+#endif
     } else {
 	DuplicateHandle(hProcess, inputHandle, hProcess, &startInfo.hStdInput,
 		0, TRUE, DUPLICATE_SAME_ACCESS);
     }
+
+#ifndef UNDER_CE
     if (startInfo.hStdInput == INVALID_HANDLE_VALUE) {
 	TclWinConvertError(GetLastError());
 	Tcl_AppendResult(interp, "couldn't duplicate input handle: ",
 		Tcl_PosixError(interp), (char *) NULL);
 	goto end;
     }
+#endif
 
     if (outputHandle == INVALID_HANDLE_VALUE) {
 	/*
@@ -1091,6 +1104,10 @@
 	 * as a sink.
 	 */
 
+#ifdef UNDER_CE
+	// we simply use the invalid handle value...
+	startInfo.hStdOutput = INVALID_HANDLE_VALUE;
+#else
 	if ((TclWinGetPlatformId() == VER_PLATFORM_WIN32_WINDOWS) 
 		&& (applType == APPL_DOS)) {
 	    if (CreatePipe(&h, &startInfo.hStdOutput, &secAtts, 0) != FALSE) {
@@ -1100,16 +1117,20 @@
 	    startInfo.hStdOutput = CreateFileA("NUL:", GENERIC_WRITE, 0,
 		    &secAtts, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 	}
+#endif
     } else {
 	DuplicateHandle(hProcess, outputHandle, hProcess, &startInfo.hStdOutput, 
 		0, TRUE, DUPLICATE_SAME_ACCESS);
     }
+
+#ifndef UNDER_CE
     if (startInfo.hStdOutput == INVALID_HANDLE_VALUE) {
 	TclWinConvertError(GetLastError());
 	Tcl_AppendResult(interp, "couldn't duplicate output handle: ",
 		Tcl_PosixError(interp), (char *) NULL);
 	goto end;
     }
+#endif
 
     if (errorHandle == INVALID_HANDLE_VALUE) {
 	/*
@@ -1117,18 +1138,26 @@
 	 * deep sink.
 	 */
 
+#ifdef UNDER_CE
+	// we simply use the invalid handle value...
+	startInfo.hStdError = INVALID_HANDLE_VALUE;
+#else
 	startInfo.hStdError = CreateFileA("NUL:", GENERIC_WRITE, 0,
 		&secAtts, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+#endif
     } else {
 	DuplicateHandle(hProcess, errorHandle, hProcess, &startInfo.hStdError, 
 		0, TRUE, DUPLICATE_SAME_ACCESS);
     } 
+
+#ifndef UNDER_CE
     if (startInfo.hStdError == INVALID_HANDLE_VALUE) {
 	TclWinConvertError(GetLastError());
 	Tcl_AppendResult(interp, "couldn't duplicate error handle: ",
 		Tcl_PosixError(interp), (char *) NULL);
 	goto end;
     }
+#endif
     /* 
      * If we do not have a console window, then we must run DOS and
      * WIN32 console mode applications as detached processes. This tells
@@ -1143,6 +1172,10 @@
      * detached processes.  The GUI window will still pop up to the
      * foreground.
      */
+#ifdef UNDER_CE
+//#define CREATE_NEW_CONSOLE 0
+#define DETACHED_PROCESS 0
+#endif
 
     if (TclWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
 	if (HasConsole()) {
@@ -1262,9 +1295,16 @@
 
     BuildCommandLine(execPath, argc, argv, &cmdLine);
 
+#ifdef UNDER_CE
+    createFlags = 0;
+    SetLastError(0);
+
+    startInfo.wShowWindow = SW_HIDE;
+    startInfo.dwFlags |= STARTF_USESHOWWINDOW;
+#endif
     if ((*tclWinProcs->createProcessProc)(NULL, 
 	    (TCHAR *) Tcl_DStringValue(&cmdLine), NULL, NULL, TRUE, 
-	    (DWORD) createFlags, NULL, NULL, &startInfo, &procInfo) == 0) {
+	    (DWORD) 0, NULL, NULL, &startInfo, &procInfo) == 0) {
 	TclWinConvertError(GetLastError());
 	Tcl_AppendResult(interp, "couldn't execute \"", argv[0],
 		"\": ", Tcl_PosixError(interp), (char *) NULL);
@@ -1289,7 +1329,9 @@
      * CloseHandle(), the problem does not occur." PSS ID Number: Q124121
      */
 
+#ifndef UNDER_CE
     WaitForInputIdle(procInfo.hProcess, 5000);
+#endif
     CloseHandle(procInfo.hThread);
 
     *pidPtr = (Tcl_Pid) procInfo.hProcess;
@@ -1401,6 +1443,12 @@
     WCHAR nativeFullPath[MAX_PATH];
     static char extensions[][5] = {"", ".com", ".exe", ".bat"};
 
+#if UNDER_CE // NOT IMPLEMENTED
+    Tcl_AppendResult(interp, "couldn't execute \"", originalName,
+	    "\": ", "not supported on Windows CE", (char *) NULL);
+    return APPL_NONE;
+#endif
+
     /* Look for the program as an external program.  First try the name
      * as it is, then try adding .com, .exe, and .bat, in that order, to
      * the name, looking for an executable.
@@ -2576,11 +2624,11 @@
 		case EXCEPTION_INVALID_HANDLE:
 		    *statPtr = SIGSEGV;
 		    break;
-
+#ifndef UNDER_CE
 		case CONTROL_C_EXIT:
 		    *statPtr = SIGINT;
 		    break;
-
+#endif
 		default:
 		    *statPtr = SIGABRT;
 		    break;
Index: win/tclWinPort.h
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinPort.h,v
retrieving revision 1.36
diff -u -r1.36 tclWinPort.h
--- win/tclWinPort.h	27 Nov 2002 18:13:38 -0000	1.36
+++ win/tclWinPort.h	24 May 2003 20:00:15 -0000
@@ -44,7 +44,11 @@
 #include <float.h>
 #include <io.h>
 #include <malloc.h>
+#ifdef UNDER_CE
+#include <winnls.h>
+#else
 #include <process.h>
+#endif
 #include <signal.h>
 #include <string.h>
 
@@ -73,13 +77,44 @@
  * Ask for the winsock function typedefs, also.
  */
 #define INCL_WINSOCK_API_TYPEDEFS   1
-#include <winsock2.h>
+#ifdef UNDER_CE
+#    include <winsock.h>
+#else
+#    include <winsock2.h>
+#endif
 
 #ifdef BUILD_tcl
 #   undef TCL_STORAGE_CLASS
 #   define TCL_STORAGE_CLASS DLLEXPORT
 #endif /* BUILD_tcl */
 
+#ifdef UNDER_CE
+#   include "celib.h"
+
+EXTERN BOOL
+XXCEGetFileAttributesExA(LPCTSTR lpFileName, 
+	GET_FILEEX_INFO_LEVELS fInfoLevelId, 
+	LPVOID lpFileInformation);
+EXTERN BOOL
+XXCEGetComputerNameW(WCHAR *wbuf, LPDWORD lpdwSize);
+EXTERN DWORD
+XXCEGetFullPathNameW(LPCTSTR lpFileName,
+	DWORD nBufferLength, WCHAR *lpBuffer, LPTSTR *lpFilePart);
+EXTERN DWORD
+XXCEGetShortPathNameW(LPCTSTR lpszLongPath, WCHAR *lpszShortPath,
+	DWORD cchBuffer);
+EXTERN BOOL
+XXCEGetVolumeInformationW(
+    LPCTSTR  lpRootPathName,	
+    WCHAR *lpVolumeNameBuffer,
+    DWORD  nVolumeNameSize,	
+    LPDWORD  lpVolumeSerialNumber,
+    LPDWORD  lpMaximumComponentLength,
+    LPDWORD  lpFileSystemFlags,	
+    WCHAR *lpFileSystemNameBuffer,
+    DWORD  nFileSystemNameSize);
+#endif
+
 /*
  * Define EINPROGRESS in terms of WSAEINPROGRESS.
  */
@@ -204,6 +239,10 @@
 #   define EREMOTE	66	/* The object is remote */
 #endif
 
+#ifndef ENAMETOOLONG
+#define ENAMETOOLONG	36	/* file name is too long */
+#endif
+
 /*
  * It is very hard to determine how Windows reacts to attempting to
  * set a file pointer outside the input datatype's representable
@@ -365,7 +404,9 @@
  */
 
 #if defined(_MSC_VER) || defined(__MINGW32__)
+#ifndef UNDER_CE
 #    define environ _environ
+#endif
 #    define hypot _hypot
 #    define exception _exception
 #    undef EDEADLOCK
@@ -456,6 +497,10 @@
  * wrappers that redirect through the winSock function table (see the
  * file tclWinSock.c).
  */
+
+#ifdef UNDER_CE
+#undef getservbyname
+#endif
 
 #define getservbyname	TclWinGetServByName
 #define getsockopt	TclWinGetSockOpt
Index: win/tclWinReg.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinReg.c,v
retrieving revision 1.21
diff -u -r1.21 tclWinReg.c
--- win/tclWinReg.c	3 Mar 2003 17:12:49 -0000	1.21
+++ win/tclWinReg.c	24 May 2003 20:00:15 -0000
@@ -45,6 +45,17 @@
  * to the system predefined keys.
  */
 
+#ifdef UNDER_CE
+static char *rootKeyNames[] = {
+    "HKEY_LOCAL_MACHINE", "HKEY_USERS", "HKEY_CLASSES_ROOT",
+    "HKEY_CURRENT_USER", NULL
+};
+
+static HKEY rootKeys[] = {
+    HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT, 
+    HKEY_CURRENT_USER
+};
+#else
 static CONST char *rootKeyNames[] = {
     "HKEY_LOCAL_MACHINE", "HKEY_USERS", "HKEY_CLASSES_ROOT",
     "HKEY_CURRENT_USER", "HKEY_CURRENT_CONFIG",
@@ -55,6 +66,7 @@
     HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT, HKEY_CURRENT_USER,
     HKEY_CURRENT_CONFIG, HKEY_PERFORMANCE_DATA, HKEY_DYN_DATA
 };
+#endif
 
 /*
  * The following table maps from registry types to strings.  Note that
@@ -77,6 +89,61 @@
  * of the current code page.
  */
 
+#ifdef UNDER_CE
+LONG WINAPI
+WinCERegEnumKeyW(
+    HKEY  hKey,	
+    DWORD  iSubKey,
+    LPWSTR lpszName,
+    DWORD  cchName
+    );
+
+LONG WINAPI
+WinCERegConnectRegistryW(
+    LPWSTR  lpszComputerName,
+    HKEY  hKey,	
+    PHKEY  phkResult
+    );
+
+LONG WINAPI
+WinCERegConnectRegistryA(
+    LPSTR  lpszComputerName,
+    HKEY  hKey,	
+    PHKEY  phkResult
+    );
+
+LONG WINAPI 
+WinCERegQueryInfoKeyA (
+    HKEY  hKey,	
+    LPSTR    lpszClass,	
+    LPDWORD  lpcchClass,	
+    LPDWORD  lpdwReserved,	
+    LPDWORD  lpcSubKeys,	
+    LPDWORD  lpcchMaxSubkey,	
+    LPDWORD  lpcchMaxClass,	
+    LPDWORD  lpcValues,	
+    LPDWORD  lpcchMaxValueName,	
+    LPDWORD  lpcbMaxValueData,	
+    LPDWORD  lpcbSecurityDescriptor,	
+    PFILETIME  lpftLastWriteTime 	
+    );
+
+LONG WINAPI
+WinCERegDeleteValueA(
+    HKEY  hKey,	
+    LPTSTR  lpszValue 	
+    );
+
+LONG WINAPI
+WinCERegEnumKeyA(
+    HKEY  hKey,	
+    DWORD  iSubKey,
+    LPSTR  lpszName,
+    DWORD  cchName
+    );
+
+#endif
+
 typedef struct RegWinProcs {
     int useWide;
 
@@ -105,7 +172,28 @@
 
 static RegWinProcs asciiProcs = {
     0,
-
+#ifdef UNDER_CE
+    (LONG (WINAPI *)(TCHAR *, HKEY, PHKEY)) WinCERegConnectRegistryA,
+    (LONG (WINAPI *)(HKEY, CONST TCHAR *, DWORD, TCHAR *,
+	    DWORD, REGSAM, SECURITY_ATTRIBUTES *, HKEY *,
+	    DWORD *)) XCERegCreateKeyExA, 
+    (LONG (WINAPI *)(HKEY, CONST TCHAR *)) XCERegDeleteKeyA,
+    (LONG (WINAPI *)(HKEY, CONST TCHAR *)) WinCERegDeleteValueA,
+    (LONG (WINAPI *)(HKEY, DWORD, TCHAR *, DWORD)) WinCERegEnumKeyA,
+    (LONG (WINAPI *)(HKEY, DWORD, TCHAR *, DWORD *, DWORD *,
+	    TCHAR *, DWORD *, FILETIME *)) XCERegEnumKeyExA,
+    (LONG (WINAPI *)(HKEY, DWORD, TCHAR *, DWORD *, DWORD *,
+	    DWORD *, BYTE *, DWORD *)) XCERegEnumValueA,
+    (LONG (WINAPI *)(HKEY, CONST TCHAR *, DWORD, REGSAM,
+	    HKEY *)) XCERegOpenKeyExA,
+    (LONG (WINAPI *)(HKEY, TCHAR *, DWORD *, DWORD *,
+	    DWORD *, DWORD *, DWORD *, DWORD *, DWORD *, DWORD *, DWORD *,
+	    FILETIME *)) WinCERegQueryInfoKeyA,
+    (LONG (WINAPI *)(HKEY, CONST TCHAR *, DWORD *, DWORD *,
+	    BYTE *, DWORD *)) XCERegQueryValueExA,
+    (LONG (WINAPI *)(HKEY, CONST TCHAR *, DWORD, DWORD,
+	    CONST BYTE*, DWORD)) XCERegSetValueExA,
+#else
     (LONG (WINAPI *)(CONST TCHAR *, HKEY, PHKEY)) RegConnectRegistryA,
     (LONG (WINAPI *)(HKEY, CONST TCHAR *, DWORD, TCHAR *,
 	    DWORD, REGSAM, SECURITY_ATTRIBUTES *, HKEY *,
@@ -126,18 +214,26 @@
 	    BYTE *, DWORD *)) RegQueryValueExA,
     (LONG (WINAPI *)(HKEY, CONST TCHAR *, DWORD, DWORD,
 	    CONST BYTE*, DWORD)) RegSetValueExA,
+#endif
 };
 
 static RegWinProcs unicodeProcs = {
     1,
-
-    (LONG (WINAPI *)(CONST TCHAR *, HKEY, PHKEY)) RegConnectRegistryW,
+#ifdef UNDER_CE
+    (LONG (WINAPI *)(TCHAR *, HKEY, PHKEY)) WinCERegConnectRegistryW,
+#else
+    (LONG (WINAPI *)(TCHAR *, HKEY, PHKEY)) RegConnectRegistryW,
+#endif
     (LONG (WINAPI *)(HKEY, CONST TCHAR *, DWORD, TCHAR *,
 	    DWORD, REGSAM, SECURITY_ATTRIBUTES *, HKEY *,
 	    DWORD *)) RegCreateKeyExW, 
     (LONG (WINAPI *)(HKEY, CONST TCHAR *)) RegDeleteKeyW,
     (LONG (WINAPI *)(HKEY, CONST TCHAR *)) RegDeleteValueW,
+#ifdef UNDER_CE
+    (LONG (WINAPI *)(HKEY, DWORD, TCHAR *, DWORD)) WinCERegEnumKeyW,
+#else
     (LONG (WINAPI *)(HKEY, DWORD, TCHAR *, DWORD)) RegEnumKeyW,
+#endif
     (LONG (WINAPI *)(HKEY, DWORD, TCHAR *, DWORD *, DWORD *,
 	    TCHAR *, DWORD *, FILETIME *)) RegEnumKeyExW,
     (LONG (WINAPI *)(HKEY, DWORD, TCHAR *, DWORD *, DWORD *,
@@ -220,12 +316,15 @@
      * Determine if the unicode interfaces are available and select the
      * appropriate registry function table.
      */
-
+#ifdef UNDER_CE
+    regWinProcs = &unicodeProcs;
+#else
     if (TclWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
 	regWinProcs = &unicodeProcs;
     } else {
 	regWinProcs = &asciiProcs;
     }
+#endif
 
     Tcl_CreateObjCommand(interp, "registry", RegistryObjCmd, NULL, NULL);
     return Tcl_PkgProvide(interp, "registry", "1.1.1");
@@ -909,6 +1008,10 @@
     HKEY rootKey;
     DWORD result;
 
+#ifdef UNDER_CE
+    mode = 0;
+#endif
+
     keyName = Tcl_GetStringFromObj(keyNameObj, &length);
     buffer = ckalloc((unsigned int) length + 1);
     strcpy(buffer, keyName);
@@ -960,6 +1063,10 @@
     DWORD result;
     Tcl_DString buf;
 
+#ifdef UNDER_CE
+    mode = 0;
+#endif
+
     /*
      * Attempt to open the root key on a remote host if necessary.
      */
@@ -985,6 +1092,7 @@
 	result = (*regWinProcs->regCreateKeyExProc)(rootKey, keyName, 0, "",
 		REG_OPTION_NON_VOLATILE, mode, NULL, keyPtr, &create);
     } else {
+#ifndef UNDER_CE
 	if (rootKey == HKEY_PERFORMANCE_DATA) {
 	    /*
 	     * Here we fudge it for this special root key.
@@ -993,7 +1101,9 @@
 	     */
 	    *keyPtr = HKEY_PERFORMANCE_DATA;
 	    result = ERROR_SUCCESS;
-	} else {
+	} else
+#endif
+	    {
 	    result = (*regWinProcs->regOpenKeyExProc)(rootKey, keyName, 0,
 		    mode, keyPtr);
 	}
@@ -1358,8 +1468,10 @@
     /*
      * Use the ignore the result.
      */
+#ifndef UNDER_CE // wait until CE.NET
     result = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE,
 	    (WPARAM) 0, (LPARAM) str, SMTO_ABORTIFHUNG, timeout, &sendResult);
+#endif
 
     objPtr = Tcl_NewObj();
     Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewIntObj((int) result));
@@ -1486,3 +1598,123 @@
     localType = (*((char*)(&order)) == 1) ? REG_DWORD : REG_DWORD_BIG_ENDIAN;
     return (type != localType) ? SWAPLONG(value) : value;
 }
+
+//////////////////////////////////////////////////////////////////////
+
+#ifdef UNDER_CE
+LONG WINAPI
+WinCERegEnumKeyW(
+    HKEY  hKey,	
+    DWORD  iSubKey,
+    LPWSTR lpszName,
+    DWORD  cchName
+   )
+{
+  int res;
+  WCHAR lpszClass[126];
+  DWORD cchClass = 126;
+  FILETIME ft;
+
+  res = RegEnumKeyExW(hKey, iSubKey, lpszName, &cchName, NULL, lpszClass,
+		      &cchClass, &ft);
+
+  return res;
+}
+
+LONG WINAPI
+WinCERegConnectRegistryW(
+    LPWSTR  lpszComputerName,
+    HKEY  hKey,	
+    PHKEY  phkResult
+   )
+{
+  return ERROR_INVALID_FUNCTION;
+}
+
+LONG WINAPI
+WinCERegConnectRegistryA(
+    LPSTR  lpszComputerName,
+    HKEY  hKey,	
+    PHKEY  phkResult
+   )
+{
+  return ERROR_INVALID_FUNCTION;
+}
+
+LONG WINAPI 
+WinCERegQueryInfoKeyA (
+    HKEY  hKey,	
+    LPSTR    lpszClass,	
+    LPDWORD  lpcchClass,	
+    LPDWORD  lpdwReserved,	
+    LPDWORD  lpcSubKeys,	
+    LPDWORD  lpcchMaxSubkey,	
+    LPDWORD  lpcchMaxClass,	
+    LPDWORD  lpcValues,	
+    LPDWORD  lpcchMaxValueName,	
+    LPDWORD  lpcbMaxValueData,	
+    LPDWORD  lpcbSecurityDescriptor,	
+    PFILETIME  lpftLastWriteTime 	
+   )
+{
+  LONG res;
+  WCHAR *lpszClassW = NULL;
+
+  if(lpszClass != NULL)
+    DebugBreak();
+
+  res = RegQueryInfoKeyW (hKey,	
+			  lpszClassW,	
+			  lpcchClass,	
+			  lpdwReserved,	
+			  lpcSubKeys,	
+			  lpcchMaxSubkey,	
+			  lpcchMaxClass,	
+			  lpcValues,	
+			  lpcchMaxValueName,	
+			  lpcbMaxValueData,	
+			  lpcbSecurityDescriptor,	
+			  lpftLastWriteTime 	
+			  );
+
+  return res;
+}
+
+LONG WINAPI
+WinCERegDeleteValueA(
+    HKEY hKey,	
+    LPSTR lpszValue 	
+   )
+{
+  LONG res;
+  int len;
+  WCHAR *lpszValueW;
+
+  len = strlen(lpszValue);
+  lpszValueW = _alloca((len+1) * 2);
+  MultiByteToWideChar(CP_ACP, 0, lpszValue, -1, lpszValueW, len+1);
+  res = RegDeleteValueW(hKey, lpszValueW);
+
+  return res;
+}
+
+LONG WINAPI
+WinCERegEnumKeyA(
+    HKEY  hKey,	
+    DWORD  iSubKey,
+    LPSTR  lpszName,
+    DWORD  cchName
+   )
+{
+  int res;
+  char lpszClass[126];
+  DWORD cchClass = 126;
+  FILETIME ft;
+
+  res = XCERegEnumKeyExA(hKey, iSubKey, lpszName, &cchName, NULL, lpszClass,
+			 &cchClass, &ft);
+
+  return res;
+}
+
+#endif
Index: win/tclWinSerial.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinSerial.c,v
retrieving revision 1.25.2.1
diff -u -r1.25.2.1 tclWinSerial.c
--- win/tclWinSerial.c	11 May 2003 00:31:41 -0000	1.25.2.1
+++ win/tclWinSerial.c	24 May 2003 20:00:15 -0000
@@ -747,10 +747,12 @@
             /* ReadFile failed, but it isn't delayed. Report error. */
             return FALSE;
         } else {   
+#ifndef UNDER_CE
             /* Read is pending, wait for completion, timeout ? */
             if (! GetOverlappedResult(infoPtr->handle, osPtr, lpRead, TRUE) ) {
                 return FALSE;
             }
+#endif
         }
     } else {
         /* ReadFile completed immediately. */
@@ -808,10 +810,12 @@
         int err = GetLastError();
         switch (err) {
         case ERROR_IO_PENDING:
+#ifndef UNDER_CE
             /* Write is pending, wait for completion */
-            if (! GetOverlappedResult(infoPtr->handle, osPtr, lpWritten, TRUE) ) {
+            if (!GetOverlappedResult(infoPtr->handle, osPtr, lpWritten, TRUE)) {
                 return FALSE;
             }
+#endif
             break;
         case ERROR_COUNTER_TIMEOUT:
             /* Write timeout handled in SerialOutputProc */
@@ -918,9 +922,9 @@
     }
 
     /*
-    *  Perform blocking read. Doesn't block in non-blocking mode, 
-    *  because we checked the number of available bytes.
-    */
+     *  Perform blocking read. Doesn't block in non-blocking mode, 
+     *  because we checked the number of available bytes.
+     */
     if (blockingRead(infoPtr, (LPVOID) buf, (DWORD) bufSize, &bytesRead,
             &infoPtr->osRead) == FALSE) {
         goto error;
@@ -1605,7 +1609,11 @@
             return TCL_ERROR;
         }
         native = Tcl_WinUtfToTChar(value, -1, &ds);
+#ifdef UNDER_CE
+	result = FALSE; // NOT IMPLEMENTED
+#else
         result = (*tclWinProcs->buildCommDCBProc)(native, &dcb);
+#endif
         Tcl_DStringFree(&ds);
         
         if (result == FALSE) {
Index: win/tclWinSock.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinSock.c,v
retrieving revision 1.36
diff -u -r1.36 tclWinSock.c
--- win/tclWinSock.c	16 Jan 2003 19:02:00 -0000	1.36
+++ win/tclWinSock.c	24 May 2003 20:00:15 -0000
@@ -35,6 +35,10 @@
 
 TCL_DECLARE_MUTEX(socketMutex)
 
+#ifdef UNDER_CE
+#undef WSAGetLastError
+extern int WSAAsyncSelect(SOCKET s, HWND hwnd, unsigned int msg, long events);
+#endif
 
 /*
  * Mingw and Cygwin may not have LPFN_* typedefs.
@@ -323,7 +327,11 @@
 	initialized = 1;
 	Tcl_CreateExitHandler(SocketExitHandler, (ClientData) NULL);
 
+#ifdef UNDER_CE
+	winSock.hModule = LoadLibraryA("winsock.dll");
+#else
 	winSock.hModule = LoadLibraryA("wsock32.dll");
+#endif
 
 	if (winSock.hModule == NULL) {
 	    return;
@@ -349,8 +357,18 @@
 		GetProcAddress(winSock.hModule, "gethostname");
 	winSock.getpeername = (LPFN_GETPEERNAME)
 		GetProcAddress(winSock.hModule, "getpeername");
+#ifdef UNDER_CE
+	{
+	    HMODULE hCelib = LoadLibrary("celib.dll");
+
+	    winSock.getservbyname = (struct servent* (*)
+		    (const char* name, const char* proto))
+		GetProcAddress(hCelib, "xcegetservbyname");
+	}
+#else
 	winSock.getservbyname = (LPFN_GETSERVBYNAME)
 		GetProcAddress(winSock.hModule, "getservbyname");
+#endif
 	winSock.getsockname = (LPFN_GETSOCKNAME)
 		GetProcAddress(winSock.hModule, "getsockname");
 	winSock.getsockopt = (LPFN_GETSOCKOPT)
@@ -377,6 +395,12 @@
 		GetProcAddress(winSock.hModule, "setsockopt");
 	winSock.socket = (LPFN_SOCKET)
 		GetProcAddress(winSock.hModule, "socket");
+#ifdef UNDER_CE
+	winSock.WSAAsyncSelect  = WSAAsyncSelect;
+	winSock.WSACleanup      = WSACleanup;
+	winSock.WSAGetLastError = GetLastError;
+	winSock.WSAStartup      = WSAStartup;
+#else
 	winSock.WSAAsyncSelect = (LPFN_WSAASYNCSELECT)
 		GetProcAddress(winSock.hModule, "WSAAsyncSelect");
 	winSock.WSACleanup = (LPFN_WSACLEANUP)
@@ -385,13 +409,14 @@
 		GetProcAddress(winSock.hModule, "WSAGetLastError");
 	winSock.WSAStartup = (LPFN_WSASTARTUP)
 		GetProcAddress(winSock.hModule, "WSAStartup");
-    
+#endif
+
 	/*
 	 * Now check that all fields are properly initialized. If not,
 	 * return zero to indicate that we failed to initialize
 	 * properly.
 	 */
-    
+
 	if ((winSock.accept == NULL) ||
 		(winSock.bind == NULL) ||
 		(winSock.closesocket == NULL) ||
@@ -493,7 +518,11 @@
 	tsdPtr->socketListLock = CreateEvent(NULL, FALSE, TRUE, NULL);
 	tsdPtr->socketThread = CreateThread(NULL, 256, SocketThread,
 		tsdPtr, 0, &id);
+#ifdef UNDER_CE
+	SetThreadPriority(tsdPtr->socketThread, THREAD_PRIORITY_ABOVE_NORMAL);
+#else
 	SetThreadPriority(tsdPtr->socketThread, THREAD_PRIORITY_HIGHEST);
+#endif
 
 	if (tsdPtr->socketThread == NULL) {
 	    goto unloadLibrary;
@@ -1117,8 +1146,9 @@
      * Win-NT has a misfeature that sockets are inherited in child
      * processes by default.  Turn off the inherit bit.
      */
-
+#ifndef UNDER_CE
     SetHandleInformation( (HANDLE) sock, HANDLE_FLAG_INHERIT, 0 );
+#endif
 	
     /*
      * Set kernel space buffering
@@ -1630,7 +1660,9 @@
      * processes by default.  Turn off the inherit bit.
      */
 
+#ifndef UNDER_CE
     SetHandleInformation( (HANDLE) newSocket, HANDLE_FLAG_INHERIT, 0 );
+#endif
 
     /*
      * Add this socket to the global list of sockets.
Index: win/tclWinThrd.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinThrd.c,v
retrieving revision 1.24.2.2
diff -u -r1.24.2.2 tclWinThrd.c
--- win/tclWinThrd.c	13 May 2003 09:57:40 -0000	1.24.2.2
+++ win/tclWinThrd.c	24 May 2003 20:00:15 -0000
@@ -141,7 +141,7 @@
 
     EnterCriticalSection(&joinLock);
 
-#if defined(_MSC_VER) || defined(__MSVCRT__) || defined(__BORLANDC__)
+#if (defined(_MSC_VER) || defined(__MSVCRT__) || defined(__BORLANDC__)) && !defined(UNDER_CE)
     tHandle = (HANDLE) _beginthreadex(NULL, (unsigned) stackSize, proc,
 	clientData, 0, (unsigned *)idPtr);
 #else
@@ -220,7 +220,7 @@
     TclSignalExitThread (Tcl_GetCurrentThread (), status);
     LeaveCriticalSection(&joinLock);
 
-#if defined(_MSC_VER) || defined(__MSVCRT__) || defined(__BORLANDC__)
+#if (defined(_MSC_VER) || defined(__MSVCRT__) || defined(__BORLANDC__)) && !defined(UNDER_CE)
     _endthreadex((unsigned) status);
 #else
     ExitThread((DWORD) status);
Index: win/tclWinTime.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinTime.c,v
retrieving revision 1.14.2.2
diff -u -r1.14.2.2 tclWinTime.c
--- win/tclWinTime.c	15 Apr 2003 21:06:36 -0000	1.14.2.2
+++ win/tclWinTime.c	24 May 2003 20:00:15 -0000
@@ -14,6 +14,10 @@
 
 #include "tclWinInt.h"
 
+#ifdef UNDER_CE
+#define GetSystemTimeAsFileTime XCEGetSystemTimeAsFileTime
+#endif
+
 #define SECSPERDAY (60L * 60L * 24L)
 #define SECSPERYEAR (SECSPERDAY * 365L)
 #define SECSPER4YEAR (SECSPERYEAR * 4L + SECSPERDAY)
@@ -788,7 +792,7 @@
 
 	/* If the exitEvent is set, break out of the loop. */
 
-	waitResult = WaitForSingleObjectEx(timeInfo.exitEvent, 1000, FALSE);
+	waitResult = WaitForSingleObject(timeInfo.exitEvent, 1000);
 	if ( waitResult == WAIT_OBJECT_0 ) {
 	    break;
 	}
