changeset 4834:b3ea9c582280

Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
author Ben Wing <ben@xemacs.org>
date Tue, 12 Jan 2010 01:38:04 -0600
parents 4dd2389173fc
children 1e90dc478938
files configure configure.ac lisp/ChangeLog lisp/mule/mule-cmds.el lisp/unicode.el src/ChangeLog src/config.h.in src/device-x.c src/dialog-msw.c src/editfns.c src/emacs.c src/event-gtk.c src/fileio.c src/font-mgr.c src/glyphs-eimage.c src/glyphs-msw.c src/glyphs-shared.c src/glyphs-x.c src/hpplay.c src/intl-win32.c src/process-unix.c src/process.c src/realpath.c src/sound.h src/symsinit.h src/sysdep.c src/sysdll.c src/sysfile.h src/syswindows.h src/text.h src/tooltalk.c src/unicode.c src/win32.c tests/ChangeLog tests/automated/mule-tests.el
diffstat 35 files changed, 781 insertions(+), 359 deletions(-) [+]
line wrap: on
line diff
--- a/configure	Sun Jan 10 01:06:15 2010 -0600
+++ b/configure	Tue Jan 12 01:38:04 2010 -0600
@@ -1,12 +1,14 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.64 for XEmacs 21.5.
+# Generated by GNU Autoconf 2.65 for XEmacs 21.5.
 #
 # Report bugs to <xemacs-beta@xemacs.org>.
 #
+#
 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
-# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software
-# Foundation, Inc.
+# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
+# Inc.
+#
 #
 # This configure script is free software; the Free Software Foundation
 # gives unlimited permission to copy, distribute and modify it.
@@ -573,7 +575,8 @@
 as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
 
 
-exec 7<&0 </dev/null 6>&1
+test -n "$DJDIR" || exec 7<&0 </dev/null
+exec 6>&1
 
 # Name of the host.
 # hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
@@ -1989,7 +1992,7 @@
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
               nonstandard directory <lib dir>
   LIBS        libraries to pass to the linker, e.g. -l<library>
-  CPPFLAGS    C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
+  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
               you have headers in a nonstandard directory <include dir>
   CPP         C preprocessor
   YACC        The `Yet Another C Compiler' implementation to use. Defaults to
@@ -2066,7 +2069,7 @@
 if $ac_init_version; then
   cat <<\_ACEOF
 XEmacs configure 21.5
-generated by GNU Autoconf 2.64
+generated by GNU Autoconf 2.65
 
 Copyright (C) 2009 Free Software Foundation, Inc.
 This configure script is free software; the Free Software Foundation
@@ -2159,7 +2162,7 @@
 	ac_retval=1
 fi
   eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
-  return $ac_retval
+  as_fn_set_status $ac_retval
 
 } # ac_fn_c_try_compile
 
@@ -2196,7 +2199,7 @@
     ac_retval=1
 fi
   eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
-  return $ac_retval
+  as_fn_set_status $ac_retval
 
 } # ac_fn_c_try_cpp
 
@@ -2331,7 +2334,7 @@
 fi
   rm -rf conftest.dSYM conftest_ipa8_conftest.oo
   eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
-  return $ac_retval
+  as_fn_set_status $ac_retval
 
 } # ac_fn_c_try_run
 
@@ -2408,7 +2411,7 @@
   # left behind by Apple's compiler.  We do this before executing the actions.
   rm -rf conftest.dSYM conftest_ipa8_conftest.oo
   eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
-  return $ac_retval
+  as_fn_set_status $ac_retval
 
 } # ac_fn_c_try_link
 
@@ -2803,7 +2806,7 @@
 
   fi
   eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
-  return $ac_retval
+  as_fn_set_status $ac_retval
 
 } # ac_fn_c_compute_int
 cat >config.log <<_ACEOF
@@ -2811,7 +2814,7 @@
 running configure, to aid debugging if configure makes a mistake.
 
 It was created by XEmacs $as_me 21.5, which was
-generated by GNU Autoconf 2.64.  Invocation command line was
+generated by GNU Autoconf 2.65.  Invocation command line was
 
   $ $0 $@
 
@@ -3064,7 +3067,7 @@
 for ac_site_file in "$ac_site_file1" "$ac_site_file2"
 do
   test "x$ac_site_file" = xNONE && continue
-  if test -r "$ac_site_file"; then
+  if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
 $as_echo "$as_me: loading site script $ac_site_file" >&6;}
     sed 's/^/| /' "$ac_site_file" >&5
@@ -3073,9 +3076,9 @@
 done
 
 if test -r "$cache_file"; then
-  # Some versions of bash will fail to source /dev/null (special
-  # files actually), so we avoid doing that.
-  if test -f "$cache_file"; then
+  # Some versions of bash will fail to source /dev/null (special files
+  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
+  if test /dev/null != "$cache_file" && test -f "$cache_file"; then
     { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
 $as_echo "$as_me: loading cache $cache_file" >&6;}
     case $cache_file in
@@ -6298,32 +6301,30 @@
 ... rest of stderr output deleted ...
          10q' conftest.err >conftest.er1
     cat conftest.er1 >&5
-    rm -f conftest.er1 conftest.err
-  fi
+  fi
+  rm -f conftest.er1 conftest.err
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }
 done
 
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#include <stdio.h>
-int
-main ()
-{
-FILE *f = fopen ("conftest.out", "w");
- return ferror (f) || fclose (f) != 0;
+
+int
+main ()
+{
 
   ;
   return 0;
 }
 _ACEOF
 ac_clean_files_save=$ac_clean_files
-ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out conftest.out"
+ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
 # Try to create an executable without -o first, disregard a.out.
 # It will help us diagnose broken compilers, and finding out an intuition
 # of exeext.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
-$as_echo_n "checking for C compiler default output file name... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
+$as_echo_n "checking whether the C compiler works... " >&6; }
 ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
 
 # The possible output files:
@@ -6385,10 +6386,10 @@
 else
   ac_file=''
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
-$as_echo "$ac_file" >&6; }
 if test -z "$ac_file"; then :
-  $as_echo "$as_me: failed program was:" >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+$as_echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
@@ -6396,51 +6397,18 @@
 { as_fn_set_status 77
 as_fn_error "C compiler cannot create executables
 See \`config.log' for more details." "$LINENO" 5; }; }
-fi
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
+$as_echo_n "checking for C compiler default output file name... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
+$as_echo "$ac_file" >&6; }
 ac_exeext=$ac_cv_exeext
 
-# Check that the compiler produces executables we can run.  If not, either
-# the compiler is broken, or we cross compile.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
-$as_echo_n "checking whether the C compiler works... " >&6; }
-# If not cross compiling, check that we can run a simple program.
-if test "$cross_compiling" != yes; then
-  if { ac_try='./$ac_file'
-  { { case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_try") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }; then
-    cross_compiling=no
-  else
-    if test "$cross_compiling" = maybe; then
-	cross_compiling=yes
-    else
-	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error "cannot run C compiled programs.
-If you meant to cross compile, use \`--host'.
-See \`config.log' for more details." "$LINENO" 5; }
-    fi
-  fi
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out conftest.out
+rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
 ac_clean_files=$ac_clean_files_save
-# Check that the compiler produces executables we can run.  If not, either
-# the compiler is broken, or we cross compile.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
-$as_echo_n "checking whether we are cross compiling... " >&6; }
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
-$as_echo "$cross_compiling" >&6; }
-
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
 $as_echo_n "checking for suffix of executables... " >&6; }
 if { { ac_try="$ac_link"
@@ -6473,13 +6441,72 @@
 as_fn_error "cannot compute suffix of executables: cannot compile and link
 See \`config.log' for more details." "$LINENO" 5; }
 fi
-rm -f conftest$ac_cv_exeext
+rm -f conftest conftest$ac_cv_exeext
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
 $as_echo "$ac_cv_exeext" >&6; }
 
 rm -f conftest.$ac_ext
 EXEEXT=$ac_cv_exeext
 ac_exeext=$EXEEXT
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdio.h>
+int
+main ()
+{
+FILE *f = fopen ("conftest.out", "w");
+ return ferror (f) || fclose (f) != 0;
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files="$ac_clean_files conftest.out"
+# Check that the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
+$as_echo_n "checking whether we are cross compiling... " >&6; }
+if test "$cross_compiling" != yes; then
+  { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+  if { ac_try='./conftest$ac_cv_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+	cross_compiling=yes
+    else
+	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." "$LINENO" 5; }
+    fi
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
+$as_echo "$cross_compiling" >&6; }
+
+rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
+ac_clean_files=$ac_clean_files_save
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
 $as_echo_n "checking for suffix of object files... " >&6; }
 if test "${ac_cv_objext+set}" = set; then :
@@ -7538,8 +7565,8 @@
 ... rest of stderr output deleted ...
          10q' conftest.err >conftest.er1
     cat conftest.er1 >&5
-    rm -f conftest.er1 conftest.err
-  fi
+  fi
+  rm -f conftest.er1 conftest.err
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }
 done
@@ -8086,8 +8113,8 @@
 ... rest of stderr output deleted ...
          10q' conftest.err >conftest.er1
     cat conftest.er1 >&5
-    rm -f conftest.er1 conftest.err
-  fi
+  fi
+  rm -f conftest.er1 conftest.err
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }
 done
@@ -8634,8 +8661,8 @@
 ... rest of stderr output deleted ...
          10q' conftest.err >conftest.er1
     cat conftest.er1 >&5
-    rm -f conftest.er1 conftest.err
-  fi
+  fi
+  rm -f conftest.er1 conftest.err
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }
 done
@@ -17455,6 +17482,21 @@
 
 fi
 
+case "$opsys" in
+  *cygwin* ) for ac_func in cygwin_conv_path
+do :
+  ac_fn_c_check_func "$LINENO" "cygwin_conv_path" "ac_cv_func_cygwin_conv_path"
+if test "x$ac_cv_func_cygwin_conv_path" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_CYGWIN_CONV_PATH 1
+_ACEOF
+
+fi
+done
+
+	 ;;
+esac
+
 
 for ac_func in cbrt closedir dup2 eaccess fmod fpathconf frexp fsync ftime ftruncate getaddrinfo gethostname getnameinfo getpagesize getrlimit gettimeofday getcwd link logb lrand48 matherr mkdir mktime perror poll random readlink rename res_init rint rmdir select setitimer setpgid setsid sigblock sighold sigprocmask snprintf strerror strlwr strupr symlink tzset ulimit umask usleep vlimit vsnprintf waitpid wcscmp wcslen
 do :
@@ -21519,7 +21561,7 @@
 # values after options handling.
 ac_log="
 This file was extended by XEmacs $as_me 21.5, which was
-generated by GNU Autoconf 2.64.  Invocation command line was
+generated by GNU Autoconf 2.65.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
@@ -21559,6 +21601,7 @@
 
   -h, --help       print this help, then exit
   -V, --version    print version number and configuration settings, then exit
+      --config     print configuration, then exit
   -q, --quiet, --silent
                    do not print progress messages
   -d, --debug      don't remove temporary files
@@ -21581,10 +21624,11 @@
 
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
 XEmacs config.status 21.5
-configured by $0, generated by GNU Autoconf 2.64,
-  with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
+configured by $0, generated by GNU Autoconf 2.65,
+  with options \\"\$ac_cs_config\\"
 
 Copyright (C) 2009 Free Software Foundation, Inc.
 This config.status script is free software; the Free Software Foundation
@@ -21620,6 +21664,8 @@
     ac_cs_recheck=: ;;
   --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
     $as_echo "$ac_cs_version"; exit ;;
+  --config | --confi | --conf | --con | --co | --c )
+    $as_echo "$ac_cs_config"; exit ;;
   --debug | --debu | --deb | --de | --d | -d )
     debug=: ;;
   --file | --fil | --fi | --f )
@@ -21814,7 +21860,7 @@
 t delim
 :nl
 h
-s/\(.\{148\}\).*/\1/
+s/\(.\{148\}\)..*/\1/
 t more1
 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
 p
@@ -21828,7 +21874,7 @@
 t nl
 :delim
 h
-s/\(.\{148\}\).*/\1/
+s/\(.\{148\}\)..*/\1/
 t more2
 s/["\\]/\\&/g; s/^/"/; s/$/"/
 p
--- a/configure.ac	Sun Jan 10 01:06:15 2010 -0600
+++ b/configure.ac	Tue Jan 12 01:38:04 2010 -0600
@@ -4291,6 +4291,12 @@
   XE_COMPUTE_RUNPATH()
 fi
 
+dnl Check for UTF-8 path-conversion functions in Cygwin 1.7 and on
+case "$opsys" in
+  *cygwin* ) AC_CHECK_FUNCS(cygwin_conv_path)
+	 ;;
+esac
+
 dnl ----------------------------------------------------------------
 dnl Check for POSIX functions.
 dnl ----------------------------------------------------------------
--- a/lisp/ChangeLog	Sun Jan 10 01:06:15 2010 -0600
+++ b/lisp/ChangeLog	Tue Jan 12 01:38:04 2010 -0600
@@ -1,3 +1,9 @@
+2010-01-10  Ben Wing  <ben@xemacs.org>
+
+	* mule/mule-cmds.el (get-native-coding-system-from-language-environment):
+	Under Cygwin, force utf-8 if we are using Cygwin 1.7 or later
+	(making use of the magic feature 'cygwin-use-utf-8).
+
 2010-01-09  Didier Verna  <didier@xemacs.org>
 
 	* x-faces.el (x-init-global-faces): Deactivate obsolete code.
--- a/lisp/mule/mule-cmds.el	Sun Jan 10 01:06:15 2010 -0600
+++ b/lisp/mule/mule-cmds.el	Tue Jan 12 01:38:04 2010 -0600
@@ -1191,21 +1191,24 @@
 can't set the text encoding used to communicate with the OS.  To get around
 this, we use Unicode whenever available, i.e. on Windows NT always and on
 Windows 9x whenever a Unicode version of a system call is available.)"
-  (if (eq system-type 'windows-nt)
-      ;; should not apply to Cygwin, I don't think
-      'mswindows-multibyte-system-default
-    (let ((ncod (get-language-info langenv 'native-coding-system)))
-      (if (or (functionp ncod) (not (listp ncod)))
-	  (setq ncod (list ncod)))
-      (let ((native
-	     (dolist (try-native ncod)
-	       (let ((result
-		      (if (functionp try-native)
-			  (funcall try-native locale)
-			try-native)))
-		 (if result (return result))))))
-	(or native (car (get-language-info langenv 'coding-system))
-	    'raw-text)))))
+  (cond ((eq system-type 'windows-nt)
+	 ;; should not apply to Cygwin, I don't think
+	 'mswindows-multibyte-system-default)
+	((featurep 'cygwin-use-utf-8)
+	 'utf-8)
+	(t
+	 (let ((ncod (get-language-info langenv 'native-coding-system)))
+	   (if (or (functionp ncod) (not (listp ncod)))
+	       (setq ncod (list ncod)))
+	   (let ((native
+		  (dolist (try-native ncod)
+		    (let ((result
+			   (if (functionp try-native)
+			       (funcall try-native locale)
+			     try-native)))
+		      (if result (return result))))))
+	     (or native (car (get-language-info langenv 'coding-system))
+		 'raw-text))))))
 
 (defun get-coding-system-from-locale (locale)
   "Return the coding system corresponding to a locale string."
--- a/lisp/unicode.el	Sun Jan 10 01:06:15 2010 -0600
+++ b/lisp/unicode.el	Tue Jan 12 01:38:04 2010 -0600
@@ -333,33 +333,14 @@
 supported.  "
    unicode-type ucs-4 little-endian t))
 
-(make-coding-system
- 'utf-8 'unicode
- "UTF-8"
- '(mnemonic "UTF8"
-   documentation "
-UTF-8 Unicode encoding -- ASCII-compatible 8-bit variable-width encoding
-sharing the following principles with the Mule-internal encoding:
-
-  -- All ASCII characters (codepoints 0 through 127) are represented
-     by themselves (i.e. using one byte, with the same value as the
-     ASCII codepoint), and these bytes are disjoint from bytes
-     representing non-ASCII characters.
+;; Now defined in unicode.c.
 
-     This means that any 8-bit clean application can safely process
-     UTF-8-encoded text as it were ASCII, with no corruption (e.g. a
-     '/' byte is always a slash character, never the second byte of
-     some other character, as with Big5, so a pathname encoded in
-     UTF-8 can safely be split up into components and reassembled
-     again using standard ASCII processes).
-
-  -- Leading bytes and non-leading bytes in the encoding of a
-     character are disjoint, so moving backwards is easy.
-
-  -- Given only the leading byte, you know how many following bytes
-     are present.
-"
-   unicode-type utf-8))
+;;(make-coding-system
+;; 'utf-8 'unicode
+;; "UTF-8"
+;; '(mnemonic "UTF8"
+;;   documentation "..."
+;;   unicode-type utf-8))
 
 (make-coding-system
  'utf-8-bom 'unicode
--- a/src/ChangeLog	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/ChangeLog	Tue Jan 12 01:38:04 2010 -0600
@@ -1,3 +1,251 @@
+2010-01-11  Ben Wing  <ben@xemacs.org>
+
+	* database.c:
+	* intl-encap-win32.c (qxeUpdateICMRegKey):
+	Cosmetic fixes.
+	
+	* device-x.c (signal_if_x_error):
+	* editfns.c (Fformat_time_string):
+	* editfns.c (Fencode_time):
+	* editfns.c (Fcurrent_time_zone):
+	* editfns.c (Fset_time_zone_rule):
+	* event-gtk.c (gtk_reset_key_mapping):
+	* fileio.c (Fsysnetunam):
+	* font-mgr.c:
+	* font-mgr.c (Ffc_config_app_font_add_dir):
+	* font-mgr.c (Ffc_config_filename):
+	* glyphs-eimage.c (my_jpeg_output_message):
+	* glyphs-eimage.c (jpeg_instantiate):
+	* glyphs-shared.c (read_bitmap_data_from_file):
+	* glyphs-x.c (x_redisplay_widget):
+	* glyphs-x.c (x_widget_instantiate):
+	* glyphs-x.c (x_widget_property):
+	* glyphs-x.c (x_tab_control_redisplay):
+	* hpplay.c (player_error_internal):
+	* hpplay.c (play_sound_file):
+	* hpplay.c (play_sound_data):
+	* process-unix.c:
+	* process-unix.c (unix_canonicalize_host_name):
+	* process.c (init_xemacs_process):
+	* sound.h (sound_perror):
+	* sysdep.c:
+	* sysdep.c (qxe_execve):
+	* sysdep.c (copy_in_passwd):
+	* sysdep.c (qxe_getpwnam):
+	* sysdep.c (qxe_ctime):
+	* sysdll.c (dll_error):
+	* sysdll.c (dll_open):
+	* tooltalk.c (check_status):
+	* tooltalk.c (Fadd_tooltalk_message_arg):
+	* tooltalk.c (Fadd_tooltalk_pattern_attribute):
+	* tooltalk.c (Fadd_tooltalk_pattern_arg):
+	Change all occurrences of Qnative to some more specific encoding.
+	Create Qtime_function_encoding, Qtime_zone_encoding,
+	Quser_name_encoding, Qerror_message_encoding,
+	Qjpeg_error_message_encoding, Qtooltalk_encoding, Qgtk_encoding,
+	Qx_error_message_encoding.
+
+	* intl-win32.c (init_intl_win32):
+	Provide cygwin-use-utf-8 if this is the case.
+
+	* fileio.c (Ffile_truename):
+	* realpath.c:
+	* syswindows.h (LOCAL_FILE_FORMAT_TO_TSTR):
+	* syswindows.h (TSTR_TO_LOCAL_FILE_FORMAT):
+	* syswindows.h (LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN):
+	* syswindows.h (INTERNAL_MSWIN_TO_LOCAL_FILE_FORMAT):
+	* syswindows.h (LISP_LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR):
+	* win32.c (urlify_filename):
+	* win32.c (tstr_to_local_file_format):
+	* win32.c (Fmswindows_cygwin_to_win32_path):
+	Rename LOCAL_FILE_FORMAT_TO_INTERNAL_WIN32 and
+	INTERNAL_WIN32_TO_LOCAL_FILE_FORMAT to
+	LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN and
+	INTERNAL_MSWIN_TO_LOCAL_FILE_FORMAT, since "win32" is a misnomer.
+
+2010-01-11  Ben Wing  <ben@xemacs.org>
+
+	* config.h.in:
+	Add def for HAVE_CYGWIN_CONV_PATH.
+	
+	* dialog-msw.c (handle_directory_dialog_box):
+	* dialog-msw.c (handle_file_dialog_box):
+	* fileio.c:
+	* fileio.c (Ffile_truename):
+	* syswindows.h:
+	* syswindows.h (CCP_POSIX_TO_WIN_T):
+	* syswindows.h (LISP_LOCAL_FILE_FORMAT_TO_TSTR):
+	* syswindows.h (INTERNAL_WIN32_TO_LOCAL_FILE_FORMAT):
+	* syswindows.h (LISP_LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR):
+	* win32.c (urlify_filename):
+	* win32.c (tstr_to_local_file_format):
+	* win32.c (Fmswindows_shell_execute):
+	* win32.c (Fmswindows_cygwin_to_win32_path):
+	Rename LOCAL_FILE_FORMAT_TO_TSTR to LISP_LOCAL_FILE_FORMAT_TO_TSTR.
+	Rename LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR to
+	LISP_LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR.  Both of these renames
+	reflect the fact that their 'in' argument is a Lisp object.
+
+	Create new LOCAL_FILE_FORMAT_TO_TSTR that accepts an Ibyte *.
+
+	Rename LOCAL_TO_WIN32_FILE_FORMAT to
+	LOCAL_FILE_FORMAT_TO_INTERNAL_WIN32; rename WIN32_TO_LOCAL_FILE_FORMAT
+	to INTERNAL_WIN32_TO_LOCAL_FILE_FORMAT similarly.
+	This clarifies the fact that the result is a file in MS-Windows format
+	rather than POSIX format, but still in internal-format instead of
+	UTF-16.
+
+	Fix up the *LOCAL_FILE_FORMAT* functions to use cygwin_conv_path()
+	if available.  This converts between a UTF-8 POSIX path and a
+	UTF-16 Windows path (or ANSI Windows path, in the increasingly
+	unlikely situation that we're using Windows 9x).  Previously, we
+	used an old API and operated on internal-format data, because the
+	external format was unpredictable.  This doesn't work any more,
+	even with the old API (it tries to convert to UTF-8).  So instead,
+	when the new API is available we use the new API and operate on
+	external-format data.  This necessitates that if we want to convert
+	to/from internal-format Windows-style paths, we need to first convert
+	to external format, do the conversion, and convert back to
+	internal format.  To avoid this, we change some callers of the
+	macros to use the right version (internal or external format
+	destination) and avoid doing the internal/external conversions
+	themselves.
+
+	* realpath.c:
+	* fileio.c (check_writable):
+	Cosmetic fixes to check_writable.
+
+	Avoid directly calling cygwin_conv_to_full_win32_path
+	(fileio.c:check_writable did this) or cygwin_posix_to_win32_path_list
+	(realpath.c:readlink_or_correct_case did this); use the
+	*LOCAL_FILE_FORMAT* macros instead.
+
+	* fileio.c (Ffile_exists_p):
+	* glyphs-msw.c (mswindows_resource_instantiate):
+	* sysdll.c (dll_open):
+	* sysfile.h:
+	* sysfile.h (PATHNAME_CONVERT_OUT_TSTR):
+	Add PATHNAME_CONVERT_OUT_TSTR and PATHNAME_CONVERT_OUT_UTF_8 for
+	conversion involving specified coding systems rather than `file-name'.
+	Use them in *LOCAL_FILE_FORMAT* macros.
+
+	* emacs.c (main_1):
+	* symsinit.h:
+	* unicode.c:
+	New function complex_vars_of_unicode().  In it, create the utf-8
+	coding system.  Call it appropriately in emacs.c.  Sort the
+	prototypes of complex_vars_of_*() in symsinit.h, for cosmetic
+	reasons.
+	
+
+2010-01-11  Ben Wing  <ben@xemacs.org>
+
+	* regex.c (re_compile_fastmap):
+	The code to compute the fastmap in charset_mule_not was totally
+	messed up.  I'm surprised it hasn't led to more visible bugs.
+
+2010-01-11  Ben Wing  <ben@xemacs.org>
+
+	* rangetab.c:
+	* rangetab.c (external_to_internal_adjust_ends):
+	* rangetab.c (put_range_table):
+	* rangetab.c (Fmap_range_table):
+	* rangetab.c (struct unified_range_table):
+	* rangetab.c (unified_range_table_copy_data):
+	* rangetab.c (unified_range_table_get_range):
+	Add an entry to unified range tables to keep track of their type.
+	Factor out code to adjust the endpoints of ranges between the
+	external format (either end can be open or closed) and internal
+	format (always closed/open).  Use code also when returning
+	ranges out of unified range tables.  Fixes an off-by-one error
+	in regex.c where it was getting ranges with an end one greater
+	than expected, since it creates closed-closed range tables and
+	was getting passed the internal-format ranges.
+
+2010-01-11  Ben Wing  <ben@xemacs.org>
+
+	* file-coding.c (default_query_method):
+	OOOOOPS!  Had = instead of ==.
+
+2010-01-11  Ben Wing  <ben@xemacs.org>
+
+	* config.h.in:
+	* config.h.in (ERROR_CHECK_GLYPHS):
+	Trying to avoid link errors referring to the ERROR_CHECK_TYPES
+	functions, either in eldap.o (if we don't include references to
+	ERROR_CHECK_TYPES in xemacs.def.in.in) or xemacs-export.o (if
+	we do include such references):
+	
+	Add line for USE_GPLUSPLUS, set by configure.
+	Define INLINE_HEADERS_ARE_STATIC when we add static to inline headers.
+	(Possibly used when setting NEED_ERROR_CHECK_TYPES_INLINES.)
+	Currently, set NEED_ERROR_CHECK_TYPES_INLINES when ERROR_CHECK_TYPES
+	and USE_GPLUSPLUS.
+	
+	* xemacs.def.in.in:
+	Use NEED_ERROR_CHECK_TYPES_INLINES here to bracket things like
+	`error_check_cons' instead of just ERROR_CHECK_TYPES.
+
+	* faces.c (complex_vars_of_faces):
+	Bracket various font variables with defined(USE_XFT or MULE) to
+	avoid warnings.
+	
+	* fileio.c:
+	Make sure the `expand-file-name' handler returns a string, to
+	avoid a potential crash.
+	
+	* floatfns.c (round_one_bigfloat_1):
+	#if-0 out an assert that can never be triggered and which
+	generates warnings "dereferencing type-punned pointer will break
+	strict-aliasing rules".
+	
+	* redisplay-x.c (separate_textual_runs_nomule):
+	Remove unused variable in non-Mule case.
+	
+	* specifier.c (charset_matches_specifier_tag_set_p):
+	Variable CHARSET is unused when not Mule.
+	
+	* specifier.c (specifier_instance_from_inst_list):
+	Add a comment questioning why font-specific stuff is littering
+	specifier.c.
+	
+	* syswindows.h:
+	Expand on the comments on a #if 0 I added in a previous patch.
+	
+	* vdb-win32.c:
+	* vdb-win32.c (win32_fault_handler):
+	* vdb-win32.c (vdb_install_signal_handler):
+	Change return type to LONG instead of DWORD to avoid warning or
+	error.
+	
+2010-01-11  Ben Wing  <ben@xemacs.org>
+
+	* database.c: Cygwin prototypes in ndbm.h are incomplete and
+	cause C++ compile errors; fix them.
+	
+	* fileio.c (check_writable):
+	Fix compile errors.  Also move the call to C_STRING_TO_TSTR
+	earlier, which is probably wrong, but fixed in a later patch.
+	
+	* intl-encap-win32.c (qxeGetICMProfile):
+	Ifdef out a fix to work around a previous bogosity in Cygwin
+	header files which has now been fixed.  Keeping in the fix
+	led to compile errors. #### Proper way to do it is to figure
+	out when it got fixed, perhaps put in a configure test, but it
+	seems not worth it.
+	
+	* intl-encap-win32.c (qxeUpdateICMRegKey):
+	Cosmetic change, undone in a later patch.
+	* mule-charset.c (Fset_charset_ccl_program):
+	Remove unused variable.
+	* nas.c:
+	#if-0 out some unused static code to avoid a warning.
+	* syswindows.h:
+	Don't declare prototypes for GetCurrentFiber and GetFiberData,
+	it causes a compile error.
+	* unicode.c (unicode_query):
+	invalid_lower_limit might have been used uninitted, so initialize it.
+
 2010-01-09  Didier Verna  <didier@xemacs.org>
 
 	* glyphs.c (query_string_font): Use proper domain for cachel
--- a/src/config.h.in	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/config.h.in	Tue Jan 12 01:38:04 2010 -0600
@@ -375,6 +375,9 @@
 /* Is scanf() broken? (Under certain versions of Cygwin) */
 #undef CYGWIN_SCANF_BUG
 
+/* UTF-8-aware path-conversion function in Cygwin 1.7 and on */
+#undef HAVE_CYGWIN_CONV_PATH
+
 #undef HAVE_MMAP
 #undef HAVE_STRCOLL
 #undef HAVE_GETPGRP
--- a/src/device-x.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/device-x.c	Tue Jan 12 01:38:04 2010 -0600
@@ -1203,14 +1203,14 @@
   XGetErrorDatabaseText (last_error.display, "XRequest", (char *) num, "",
 			 buf, sizeof (buf));
   if (*buf)
-    data = Fcons (build_ext_string (buf, Qnative), data);
+    data = Fcons (build_ext_string (buf, Qx_error_message_encoding), data);
   else
     {
       qxesprintf (num, "Request-%d", last_error.request_code);
       data = Fcons (build_intstring (num), data);
     }
   XGetErrorText (last_error.display, last_error.error_code, buf, sizeof (buf));
-  data = Fcons (build_ext_string (buf, Qnative), data);
+  data = Fcons (build_ext_string (buf, Qx_error_message_encoding), data);
  again:
   Fsignal (Qx_error, data);
   if (! resumable_p) goto again;
--- a/src/dialog-msw.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/dialog-msw.c	Tue Jan 12 01:38:04 2010 -0600
@@ -394,7 +394,7 @@
     BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT | BIF_EDITBOX | BIF_NEWDIALOGSTYLE;
   bi.lpfn = handle_directory_proc;
   
-  LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (build_string (""), Qnil),
+  LISP_LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (build_string (""), Qnil),
 			     pd.fname);
   
   {
@@ -406,7 +406,7 @@
 	    LISP_STRING_TO_EXTERNAL (value, bi.lpszTitle, Qmswindows_tstr);
 	  }
 	else if (EQ (key, Q_initial_directory))
-	  LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (value, Qnil),
+	  LISP_LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (value, Qnil),
 				     pd.fname);
 	else if (EQ (key, Q_initial_filename))
 	  ;			/* do nothing */
@@ -468,7 +468,7 @@
   ofn.nMaxFile = sizeof (fnbuf) / XETCHAR_SIZE;
   qxetcscpy (fnbuf, XETEXT (""));
   
-  LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (build_string (""), Qnil),
+  LISP_LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (build_string (""), Qnil),
 			     ofn.lpstrInitialDir);
   
   {
@@ -479,7 +479,7 @@
 	    Extbyte *fnout;
 	    
 	    CHECK_STRING (value);
-	    LOCAL_FILE_FORMAT_TO_TSTR (value, fnout);
+	    LISP_LOCAL_FILE_FORMAT_TO_TSTR (value, fnout);
 	    qxetcscpy (fnbuf, fnout);
 	  }
 	else if (EQ (key, Q_title))
@@ -488,7 +488,7 @@
 	    LISP_STRING_TO_TSTR (value, ofn.lpstrTitle);
 	  }
 	else if (EQ (key, Q_initial_directory))
-	  LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (value, Qnil),
+	  LISP_LOCAL_FILE_FORMAT_TO_TSTR (Fexpand_file_name (value, Qnil),
 				     ofn.lpstrInitialDir);
 	else if (EQ (key, Q_file_must_exist))
 	  {
--- a/src/editfns.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/editfns.c	Tue Jan 12 01:38:04 2010 -0600
@@ -1074,10 +1074,11 @@
 
       /* !!#### this use of external here is not totally safe, and
 	 potentially data lossy. */
-      LISP_STRING_TO_EXTERNAL (format_string, formext, Qnative);
+      LISP_STRING_TO_EXTERNAL (format_string, formext,
+			       Qtime_function_encoding);
       if (emacs_strftime (buf, size, formext, &tm)
 	  || !*buf)
-	return build_ext_string (buf, Qnative);
+	return build_ext_string (buf, Qtime_function_encoding);
       /* If buffer was too small, make it bigger.  */
       size *= 2;
     }
@@ -1187,7 +1188,7 @@
       Extbyte **oldenv = environ, **newenv;
 
       if (STRINGP (zone))
-	LISP_STRING_TO_EXTERNAL (zone, tzstring, Qnative);
+	LISP_STRING_TO_EXTERNAL (zone, tzstring, Qtime_zone_encoding);
       else if (INTP (zone))
 	{
 	  int abszone = abs (XINT (zone));
@@ -1319,7 +1320,7 @@
 #endif
 #endif /* not HAVE_TM_ZONE */
       if (s)
-	tem = build_ext_string (s, Qnative);
+	tem = build_ext_string (s, Qtime_zone_encoding);
       else
 	{
 	  Ibyte buf[6];
@@ -1433,7 +1434,7 @@
   else
     {
       CHECK_STRING (tz);
-      LISP_STRING_TO_EXTERNAL (tz, tzstring, Qnative);
+      LISP_STRING_TO_EXTERNAL (tz, tzstring, Qtime_zone_encoding);
     }
 
   set_time_zone_rule (tzstring);
--- a/src/emacs.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/emacs.c	Tue Jan 12 01:38:04 2010 -0600
@@ -2414,8 +2414,11 @@
 	 then we suddenly have dependence on the previous call. */
       complex_vars_of_file_coding ();
 #ifdef WIN32_ANY
+      /* Define MS-Windows Unicode coding systems */
       complex_vars_of_intl_win32 ();
 #endif
+      /* Define UTF-8 coding system */
+      complex_vars_of_unicode ();
 
       /* At this point we should be able to do conversion operations.
          We have initialized things to the point that we can create Lisp
--- a/src/event-gtk.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/event-gtk.c	Tue Jan 12 01:38:04 2010 -0600
@@ -1787,8 +1787,8 @@
 	Lisp_Object sym = gtk_keysym_to_emacs_keysym (keysym[0], 0);
 	if (name)
 	  {
-	    Fputhash (build_ext_string (name, Qnative), Qsans_modifiers,
-		      hashtable);
+	    Fputhash (build_ext_string (name, Qx_keysym_encoding),
+		      Qsans_modifiers, hashtable);
 	    Fputhash (sym, Qsans_modifiers, hashtable);
 	  }
       }
@@ -1802,7 +1802,8 @@
 	      Lisp_Object sym = gtk_keysym_to_emacs_keysym (keysym[j], 0);
 	      if (name && NILP (Fgethash (sym, hashtable, Qnil)))
 		{
-		  Fputhash (build_ext_string (name, Qnative), Qt, hashtable);
+		  Fputhash (build_ext_string (name, Qx_keysym_encoding),
+			    Qt, hashtable);
 		  Fputhash (sym, Qt, hashtable);
 		}
 	    }
--- a/src/fileio.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/fileio.c	Tue Jan 12 01:38:04 2010 -0600
@@ -1,6 +1,6 @@
 /* File IO for XEmacs.
    Copyright (C) 1985-1988, 1992-1995 Free Software Foundation, Inc.
-   Copyright (C) 1996, 2001, 2002, 2003, 2004 Ben Wing.
+   Copyright (C) 1996, 2001, 2002, 2003, 2004, 2010 Ben Wing.
 
 This file is part of XEmacs.
 
@@ -1388,7 +1388,7 @@
        detect that c:/windows == /windows for example. */
     if (! (IS_DIRECTORY_SEP (path[0]) && IS_DIRECTORY_SEP (path[1])))
       {
-	LOCAL_TO_WIN32_FILE_FORMAT (path, p);
+	LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN (path, p);
 	path = p;
       }
 #endif
@@ -2271,7 +2271,7 @@
      encapsulated. */
 
   LISP_STRING_TO_EXTERNAL (path, path_ext, Qfile_name);
-  LISP_STRING_TO_EXTERNAL (login, login_ext, Qnative);
+  LISP_STRING_TO_EXTERNAL (login, login_ext, Quser_name_encoding);
 
   netresult = netunam (path_ext, login_ext);
 
@@ -2324,82 +2324,73 @@
 static int
 check_writable (const Ibyte *filename)
 {
-#if defined(WIN32_NATIVE) || defined(CYGWIN)
-#ifdef CYGWIN
-    Extbyte filename_buffer[PATH_MAX];
-#endif
-	// Since this has to work for a directory, we can't just call 'CreateFile'
-	PSECURITY_DESCRIPTOR pDesc; /* Must be freed with LocalFree */
-	/* these need not be freed, they point into pDesc */
-	PSID psidOwner;
-	PSID psidGroup;
-	PACL pDacl;
-	PACL pSacl;
-	/* end of insides of descriptor */
-	DWORD error;
-	DWORD attributes;
-	HANDLE tokenHandle;
-	GENERIC_MAPPING genericMapping;
-	DWORD accessMask;
-	PRIVILEGE_SET PrivilegeSet;
-    DWORD dwPrivSetSize = sizeof( PRIVILEGE_SET );
-    BOOL fAccessGranted = FALSE;
-    DWORD dwAccessAllowed;
-    Extbyte *fnameext;
-
-    C_STRING_TO_TSTR(filename, fnameext);
-
-#ifdef CYGWIN
-    cygwin_conv_to_full_win32_path(fnameext, filename_buffer);
-    fnameext = filename_buffer;
-#endif
-
-    // First check for a normal file with the old-style readonly bit
+#ifdef WIN32_ANY
+  // Since this has to work for a directory, we can't just call 'CreateFile'
+  PSECURITY_DESCRIPTOR pDesc; /* Must be freed with LocalFree */
+  /* these need not be freed, they point into pDesc */
+  PSID psidOwner;
+  PSID psidGroup;
+  PACL pDacl;
+  PACL pSacl;
+  /* end of insides of descriptor */
+  DWORD error;
+  DWORD attributes;
+  HANDLE tokenHandle;
+  GENERIC_MAPPING genericMapping;
+  DWORD accessMask;
+  PRIVILEGE_SET PrivilegeSet;
+  DWORD dwPrivSetSize = sizeof( PRIVILEGE_SET );
+  BOOL fAccessGranted = FALSE;
+  DWORD dwAccessAllowed;
+  Extbyte *fnameext;
+
+  LOCAL_FILE_FORMAT_TO_TSTR (filename, fnameext);
+
+  // First check for a normal file with the old-style readonly bit
+  attributes = qxeGetFileAttributes(fnameext);
+  if (FILE_ATTRIBUTE_READONLY == (attributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_READONLY)))
+    return 0;
+
+  /* Win32 prototype lacks const. */
+  error = qxeGetNamedSecurityInfo(fnameext, SE_FILE_OBJECT, 
+				  DACL_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|OWNER_SECURITY_INFORMATION,
+				  &psidOwner, &psidGroup, &pDacl, &pSacl, &pDesc);
+  if(error != ERROR_SUCCESS) { // FAT?
     attributes = qxeGetFileAttributes(fnameext);
-    if (FILE_ATTRIBUTE_READONLY == (attributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_READONLY)))
+    return (attributes & FILE_ATTRIBUTE_DIRECTORY) || (0 == (attributes & FILE_ATTRIBUTE_READONLY));
+  }
+
+  genericMapping.GenericRead = FILE_GENERIC_READ;
+  genericMapping.GenericWrite = FILE_GENERIC_WRITE;
+  genericMapping.GenericExecute = FILE_GENERIC_EXECUTE;
+  genericMapping.GenericAll = FILE_ALL_ACCESS;
+
+  if(!ImpersonateSelf(SecurityDelegation)) {
+    return 0;
+  }
+  if(!OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, TRUE, &tokenHandle)) {
+    return 0;
+  }
+
+  accessMask = GENERIC_WRITE;
+  MapGenericMask(&accessMask, &genericMapping);
+
+  if(!AccessCheck(pDesc, tokenHandle, accessMask, &genericMapping,
+		  &PrivilegeSet,       // receives privileges used in check
+		  &dwPrivSetSize,      // size of PrivilegeSet buffer
+		  &dwAccessAllowed,    // receives mask of allowed access rights
+		  &fAccessGranted)) 
+    {
+      CloseHandle(tokenHandle);
+      RevertToSelf();
+      LocalFree(pDesc);
       return 0;
-
-	/* Win32 prototype lacks const. */
-	error = qxeGetNamedSecurityInfo(fnameext, SE_FILE_OBJECT, 
-                                    DACL_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|OWNER_SECURITY_INFORMATION,
-                                    &psidOwner, &psidGroup, &pDacl, &pSacl, &pDesc);
-	if(error != ERROR_SUCCESS) { // FAT?
-		attributes = qxeGetFileAttributes(fnameext);
-		return (attributes & FILE_ATTRIBUTE_DIRECTORY) || (0 == (attributes & FILE_ATTRIBUTE_READONLY));
-	}
-
-	genericMapping.GenericRead = FILE_GENERIC_READ;
-    genericMapping.GenericWrite = FILE_GENERIC_WRITE;
-    genericMapping.GenericExecute = FILE_GENERIC_EXECUTE;
-    genericMapping.GenericAll = FILE_ALL_ACCESS;
-
-	if(!ImpersonateSelf(SecurityDelegation)) {
-		return 0;
-	}
-	if(!OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, TRUE, &tokenHandle)) {
-		return 0;
-	}
-
-	accessMask = GENERIC_WRITE;
-	MapGenericMask(&accessMask, &genericMapping);
-
-	if(!AccessCheck(pDesc, tokenHandle, accessMask, &genericMapping,
-					&PrivilegeSet,       // receives privileges used in check
-					&dwPrivSetSize,      // size of PrivilegeSet buffer
-					&dwAccessAllowed,    // receives mask of allowed access rights
-					&fAccessGranted)) 
-	{
-		CloseHandle(tokenHandle);
-		RevertToSelf();
-		LocalFree(pDesc);
-		return 0;
-	}
-	CloseHandle(tokenHandle);
-	RevertToSelf();
-	LocalFree(pDesc);
-	return fAccessGranted == TRUE;
-#else
-#ifdef HAVE_EACCESS
+    }
+  CloseHandle(tokenHandle);
+  RevertToSelf();
+  LocalFree(pDesc);
+  return fAccessGranted == TRUE;
+#elif defined (HAVE_EACCESS)
   return (qxe_eaccess (filename, W_OK) >= 0);
 #else
   /* Access isn't quite right because it uses the real uid
@@ -2408,8 +2399,7 @@
      Opening with O_WRONLY could work for an ordinary file,
      but would lose for directories.  */
   return (qxe_access (filename, W_OK) >= 0);
-#endif
-#endif
+#endif /* (not) defined (HAVE_EACCESS) */
 }
 
 DEFUN ("file-exists-p", Ffile_exists_p, 1, 1, 0, /*
--- a/src/font-mgr.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/font-mgr.c	Tue Jan 12 01:38:04 2010 -0600
@@ -782,8 +782,8 @@
   CHECK_STRING (file);
   if (FcConfigAppFontAddFile
       (XFCCONFIG_PTR (config),
-       /* #### FIXME! is this really Qnative? */
-       (FcChar8 *) NEW_LISP_STRING_TO_EXTERNAL ((file), Qnative)) == FcFalse)
+       /* #### FIXME! is Qfile_name right? */
+       (FcChar8 *) NEW_LISP_STRING_TO_EXTERNAL (file, Qfile_name) == FcFalse)
     return Qnil;
   else
     return Qt;
@@ -801,8 +801,8 @@
   CHECK_STRING (dir);
   if (FcConfigAppFontAddDir
       (XFCCONFIG_PTR (config),
-       /* #### FIXME! is this really Qnative? */
-       (FcChar8 *) NEW_LISP_STRING_TO_EXTERNAL ((dir), Qnative)) == FcFalse)
+       /* #### FIXME! is Qfile_name right? */
+       (FcChar8 *) NEW_LISP_STRING_TO_EXTERNAL (dir), Qfile_name) == FcFalse)
     return Qnil;
   else
     return Qt;
@@ -844,8 +844,8 @@
   if (!NILP (name))
     {
       CHECK_STRING (name);
-      /* #### FIXME! is this really Qnative? */
-      fcname = NEW_LISP_STRING_TO_EXTERNAL (name, Qnative);
+       /* #### FIXME! is Qfile_name right? */
+      fcname = NEW_LISP_STRING_TO_EXTERNAL (name, Qfile_name);
     }
   return (build_fcapi_string (FcConfigFilename ((FcChar8 *) fcname)));
 }
--- a/src/glyphs-eimage.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/glyphs-eimage.c	Tue Jan 12 01:38:04 2010 -0600
@@ -321,7 +321,7 @@
 
   /* Create the message */
   (*cinfo->err->format_message) (cinfo, buffer);
-  EXTERNAL_TO_C_STRING (buffer, intbuf, Qnative);
+  EXTERNAL_TO_C_STRING (buffer, intbuf, Qjpeg_error_message_encoding);
   warn_when_safe (Qjpeg, Qinfo, "%s", intbuf);
 }
 
@@ -375,7 +375,7 @@
 
 	/* Create the message */
 	(*cinfo.err->format_message) ((j_common_ptr) &cinfo, buffer);
-	errstring = build_ext_string (buffer, Qnative);
+	errstring = build_ext_string (buffer, Qjpeg_error_message_encoding);
 
 	signal_image_error_2 ("JPEG decoding error",
 			      errstring, instantiator);
--- a/src/glyphs-msw.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/glyphs-msw.c	Tue Jan 12 01:38:04 2010 -0600
@@ -1243,7 +1243,7 @@
     {
       Extbyte *fname;
 
-      LOCAL_FILE_FORMAT_TO_TSTR (file, fname);
+      LISP_LOCAL_FILE_FORMAT_TO_TSTR (file, fname);
 
       if (NILP (resource_id))
 	resid = fname;
--- a/src/glyphs-shared.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/glyphs-shared.c	Tue Jan 12 01:38:04 2010 -0600
@@ -328,7 +328,7 @@
   int status;
   Extbyte *fileext;
 
-  LISP_STRING_TO_EXTERNAL (filename, fileext, Qnative);
+  LISP_PATHNAME_CONVERT_OUT (filename, fileext);
   if ((fstream = fopen (fileext, "r")) == NULL)
     return BitmapOpenFailed;
   status = read_bitmap_data (fstream, width, height, datap, x_hot, y_hot);
--- a/src/glyphs-x.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/glyphs-x.c	Tue Jan 12 01:38:04 2010 -0600
@@ -2201,7 +2201,7 @@
     {
       Extbyte* str;
       Lisp_Object val = IMAGE_INSTANCE_WIDGET_TEXT (p);
-      LISP_STRING_TO_EXTERNAL (val, str, Qnative);
+      LISP_STRING_TO_EXTERNAL (val, str, Qlwlib_encoding);
       wv->value = str;
     }
 
@@ -2469,7 +2469,8 @@
   IMAGE_INSTANCE_TYPE (ii) = IMAGE_WIDGET;
 
   if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
-    LISP_STRING_TO_EXTERNAL (IMAGE_INSTANCE_WIDGET_TEXT (ii), nm, Qnative);
+    LISP_STRING_TO_EXTERNAL (IMAGE_INSTANCE_WIDGET_TEXT (ii), nm,
+			     Qlwlib_encoding);
 
   ii->data = xnew_and_zero (struct x_subwindow_data);
 
@@ -2560,7 +2561,7 @@
   if (EQ (prop, Q_text))
     {
       widget_value* wv = lw_get_all_values (IMAGE_INSTANCE_X_WIDGET_LWID (ii));
-      return build_ext_string (wv->value, Qnative);
+      return build_ext_string (wv->value, Qlwlib_encoding);
     }
   return Qunbound;
 }
@@ -2776,7 +2777,7 @@
 		  Widget* children;
 
 		  LISP_STRING_TO_EXTERNAL (XGUI_ITEM (XCAR (rest))->name,
-					   name, Qnative);
+					   name, Qlwlib_encoding);
 		  /* The name may contain a `.' which confuses
 		     XtNameToWidget, so we do it ourselves. */
 		  children =
--- a/src/hpplay.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/hpplay.c	Tue Jan 12 01:38:04 2010 -0600
@@ -73,7 +73,7 @@
   Ibyte *interr;
 
   AGetErrorText (audio, errorCode, errorbuff, 131);
-  EXTERNAL_TO_C_STRING (errorbuf, interr, Qnative);
+  EXTERNAL_TO_C_STRING (errorbuf, interr, Qerror_message_encoding);
   
   signal_error (Qsound_error, text, build_string (interr));
 }
@@ -148,7 +148,8 @@
   Extbyte *server;
 
   if (STRINGP (Vhp_play_server))
-    LISP_STRING_TO_EXTERNAL (Vhp_play_server, server, Qnative);
+    LISP_STRING_TO_EXTERNAL (Vhp_play_server, server,
+			     Qunix_host_name_encoding);
   else
     server = "";
 
@@ -201,7 +202,8 @@
        
     
   if (STRINGP (Vhp_play_server))
-    LISP_STRING_TO_EXTERNAL (Vhp_play_server, server, Qnative);
+    LISP_STRING_TO_EXTERNAL (Vhp_play_server, server,
+			     Qunix_host_name_encoding);
   else
     server = "";
 
--- a/src/intl-win32.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/intl-win32.c	Tue Jan 12 01:38:04 2010 -0600
@@ -2393,6 +2393,10 @@
   set_current_lcid (GetUserDefaultLCID ());
 #endif /* MULE */
 
+#ifdef HAVE_CYGWIN_CONV_PATH
+  Fprovide (intern ("cygwin-use-utf-8"));
+#endif
+
   if (initialized)
     /* If not initialized, we also call this, but early -- see the
        previous function. */
--- a/src/process-unix.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/process-unix.c	Tue Jan 12 01:38:04 2010 -0600
@@ -525,7 +525,7 @@
 
 	  CHECK_STRING (tail_port);
 	  TO_EXTERNAL_FORMAT (LISP_STRING, tail_port, C_STRING_ALLOCA,
-			      tailportext, Qnative);
+			      tailportext, Qunix_service_name_encoding);
 
 	  svc_info = getservbyname (tailportext, proto);
 	  if ((svc_info != 0) && (svc_info->s_port == port))
@@ -1816,7 +1816,7 @@
 #endif
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_protocol = 0;
-  LISP_STRING_TO_EXTERNAL (host, ext_host, Qnative);
+  LISP_STRING_TO_EXTERNAL (host, ext_host, Qunix_host_name_encoding);
   retval = getaddrinfo (ext_host, NULL, &hints, &res);
   if (retval != 0)
     {
@@ -1833,7 +1833,8 @@
       int gni = getnameinfo (res->ai_addr, res->ai_addrlen,
 			     addrbuf, sizeof(addrbuf),
 			     NULL, 0, NI_NUMERICHOST);
-      canonname = gni ? host : build_ext_string (addrbuf, Qnative);
+      canonname = gni ? host : build_ext_string (addrbuf,
+						 Qunix_host_name_encoding);
 
       freeaddrinfo (res);
     }
--- a/src/process.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/process.c	Tue Jan 12 01:38:04 2010 -0600
@@ -2439,7 +2439,8 @@
 #else
     for (envp = environ; envp && *envp; envp++)
       Vprocess_environment =
-	Fcons (build_ext_string (*envp, Qnative), Vprocess_environment);
+	Fcons (build_ext_string (*envp, Qenvironment_variable_encoding),
+	       Vprocess_environment);
 #endif
     /* This gets set back to 0 in disksave_object_finalization() */
     env_initted = 1;
--- a/src/realpath.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/realpath.c	Tue Jan 12 01:38:04 2010 -0600
@@ -140,17 +140,13 @@
 #endif /* REALPATH_CORRECTS_CASE */
 #else /* defined (WIN32_ANY) */
 # ifdef CYGWIN
-  Ibyte *tmp;
   int n = qxe_readlink (name, buf, (size_t) size);
   if (n >= 0 || errno != EINVAL)
     return n;
 
   /* The file may exist, but isn't a symlink. Try to find the
      right name. */
-  tmp =
-    alloca_ibytes (cygwin_posix_to_win32_path_list_buf_size ((char *) name));
-  cygwin_posix_to_win32_path_list ((char *) name, (char *) tmp);
-  name = tmp;
+  LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN (name, name);
 # else
   if (mswindows_shortcuts_are_symlinks)
     {
--- a/src/sound.h	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/sound.h	Tue Jan 12 01:38:04 2010 -0600
@@ -35,12 +35,13 @@
   Ibyte *errmess;							 \
   Ibyte *string_int;							 \
   GET_STRERROR (errmess, errno);					 \
-  EXTERNAL_TO_C_STRING (string, string_int, Qnative);			 \
+  EXTERNAL_TO_C_STRING (string, string_int, Qerror_message_encoding);	 \
   warn_when_safe (Qsound, Qerror, "audio: %s, %s", string_int, errmess); \
 } while (0)
 # define sound_warn(string)					\
 do {								\
   Ibyte *string_int;						\
-  EXTERNAL_TO_C_STRING (GETTEXT (string), string_int, Qnative);	\
+  EXTERNAL_TO_C_STRING (GETTEXT (string), string_int,		\
+                        Qerror_message_encoding);		\
   warn_when_safe (Qsound, Qwarning, "audio: %s", string_int);	\
 } while (0)
--- a/src/symsinit.h	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/symsinit.h	Tue Jan 12 01:38:04 2010 -0600
@@ -464,29 +464,30 @@
    #### The reinit_() functions should be called from emacs.c, not the
    corresponding complex_vars_of_(). */
 
-void complex_vars_of_faces (void);
-void complex_vars_of_mule_charset (void);
-void complex_vars_of_file_coding (void);
-void complex_vars_of_intl_win32 (void);
-void complex_vars_of_glyphs (void);
-void complex_vars_of_glyphs_x (void);
-void complex_vars_of_glyphs_mswindows (void);
 void complex_vars_of_alloc (void);
-void complex_vars_of_menubar (void);
-void complex_vars_of_scrollbar (void);
-void complex_vars_of_frame (void);
-void complex_vars_of_syntax (void);
+void complex_vars_of_buffer (void);
 void complex_vars_of_casetab (void);
 void complex_vars_of_chartab (void);
-void complex_vars_of_buffer (void);
-void reinit_complex_vars_of_buffer_runtime_only (void);
 void complex_vars_of_console (void);
-void reinit_complex_vars_of_console_runtime_only (void);
 void complex_vars_of_emacs (void);
+void complex_vars_of_faces (void);
+void complex_vars_of_file_coding (void);
+void complex_vars_of_font_mgr (void);
+void complex_vars_of_frame (void);
+void complex_vars_of_glyphs (void);
+void complex_vars_of_glyphs_mswindows (void);
+void complex_vars_of_glyphs_x (void);
+void complex_vars_of_intl_win32 (void);
+void complex_vars_of_keymap (void);
+void complex_vars_of_menubar (void);
 void complex_vars_of_minibuf (void);
+void complex_vars_of_mule_charset (void);
+void complex_vars_of_scrollbar (void);
+void complex_vars_of_syntax (void);
+void complex_vars_of_unicode (void);
+void reinit_complex_vars_of_buffer_runtime_only (void);
+void reinit_complex_vars_of_console_runtime_only (void);
 void reinit_complex_vars_of_minibuf (void);
-void complex_vars_of_keymap (void);
-void complex_vars_of_font_mgr (void);
 
 /* Late initialization -- stuff pertaining only to interactive usage,
    I/O, or Lisp reading. (Dump-time and run-time, but the code itself
--- a/src/sysdep.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/sysdep.c	Tue Jan 12 01:38:04 2010 -0600
@@ -3092,14 +3092,15 @@
     ;
   new_argv = alloca_array (Extbyte *, argc + 1);
   for (i = 0; i < argc; i++)
-    C_STRING_TO_EXTERNAL (argv[i], new_argv[i], Qnative);
+    C_STRING_TO_EXTERNAL (argv[i], new_argv[i], Qcommand_argument_encoding);
   new_argv[argc] = NULL;
 
   for (envc = 0; envp[envc]; envc++)
     ;
   new_envp = alloca_array (Extbyte *, envc + 1);
   for (i = 0; i < envc; i++)
-    C_STRING_TO_EXTERNAL (envp[i], new_envp[i], Qnative);
+    C_STRING_TO_EXTERNAL (envp[i], new_envp[i],
+			  Qenvironment_variable_encoding);
   new_envp[envc] = NULL;
 
 #if defined (WIN32_NATIVE)
@@ -3146,13 +3147,16 @@
   cached_pwd = *pwd;
   if (cached_pwd.pw_name)
     TO_INTERNAL_FORMAT (C_STRING, cached_pwd.pw_name,
-			C_STRING_MALLOC, cached_pwd.pw_name, Qnative);
+			C_STRING_MALLOC, cached_pwd.pw_name,
+			Quser_name_encoding);
   if (cached_pwd.pw_passwd)
     TO_INTERNAL_FORMAT (C_STRING, cached_pwd.pw_passwd,
-			C_STRING_MALLOC, cached_pwd.pw_passwd, Qnative);
+			C_STRING_MALLOC, cached_pwd.pw_passwd,
+			Quser_name_encoding);
   if (cached_pwd.pw_gecos)
     TO_INTERNAL_FORMAT (C_STRING, cached_pwd.pw_gecos,
-			C_STRING_MALLOC, cached_pwd.pw_gecos, Qnative);
+			C_STRING_MALLOC, cached_pwd.pw_gecos,
+			Quser_name_encoding);
   if (cached_pwd.pw_dir)
     TO_INTERNAL_FORMAT (C_STRING, cached_pwd.pw_dir,
 			C_STRING_MALLOC, cached_pwd.pw_dir, Qfile_name);
@@ -3170,7 +3174,7 @@
   return getpwnam (name);
 #else
   Extbyte *nameext;
-  C_STRING_TO_EXTERNAL (name, nameext, Qnative);
+  C_STRING_TO_EXTERNAL (name, nameext, Quser_name_encoding);
 
   return copy_in_passwd (getpwnam (nameext));
 #endif /* WIN32_NATIVE */
@@ -3210,7 +3214,7 @@
     return (Ibyte *) "Sun Jan 01 00:00:00 1970";
   if (ctime_static)
     xfree (ctime_static, Ibyte *);
-  EXTERNAL_TO_C_STRING_MALLOC (str, ctime_static, Qnative);
+  EXTERNAL_TO_C_STRING_MALLOC (str, ctime_static, Qtime_function_encoding);
   return ctime_static;
 }
 
--- a/src/sysdll.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/sysdll.c	Tue Jan 12 01:38:04 2010 -0600
@@ -109,7 +109,7 @@
 #else
   msg = (const Extbyte *) "Shared library error";
 #endif
-  return build_ext_string (msg, Qnative);
+  return build_ext_string (msg, Qerror_message_encoding);
 }
 
 #elif defined(HAVE_SHL_LOAD)
@@ -164,7 +164,8 @@
 {
   /* #### WTF?!  Shouldn't this at least attempt to get strerror or
      something?  --hniksic */
-  return build_string ("Generic shared library error", Qnative);
+  return build_string ("Generic shared library error",
+		       Qerror_message_encoding);
 }
 
 #elif defined (WIN32_NATIVE) || defined (CYGWIN)
@@ -183,7 +184,7 @@
     }
   else
     {
-      LOCAL_FILE_FORMAT_TO_TSTR (fname, soname);
+      LISP_LOCAL_FILE_FORMAT_TO_TSTR (fname, soname);
     }
   return (dll_handle) qxeLoadLibrary (soname);
 }
@@ -431,7 +432,7 @@
   int errorNumber;
   const CIbyte *fileNameWithError, *errorString;
   NSLinkEditError(&c, &errorNumber, &fileNameWithError, &errorString);
-  return build_ext_string (errorString, Qnative);
+  return build_ext_string (errorString, Qerror_message_encoding);
 }
 #elif HAVE_LTDL
 /* Libtool's libltdl */
@@ -476,7 +477,7 @@
 Lisp_Object
 dll_error ()
 {
-  return build_ext_string (lt_dlerror (), Qnative);
+  return build_ext_string (lt_dlerror (), Qerror_message_encoding);
 }
 #else
 /* Catchall if we don't know about this system's method of dynamic loading */
--- a/src/sysfile.h	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/sysfile.h	Tue Jan 12 01:38:04 2010 -0600
@@ -579,14 +579,25 @@
    false, because they just call the native Win32 routines directly, which
    always use the system-default encoding (which is what Qmswindows_tstr
    will give us when not XEUNICODE_P). */
+#define PATHNAME_CONVERT_OUT_TSTR(path, pathout)	\
+do							\
+{							\
+  const Ibyte *_pco_path_;				\
+  PATHNAME_RESOLVE_LINKS (path, _pco_path_);		\
+  C_STRING_TO_TSTR (_pco_path_, pathout);		\
+} while (0)
+
+#define PATHNAME_CONVERT_OUT_UTF_8(path, pathout)	\
+do							\
+{							\
+  const Ibyte *_pco_path_;				\
+  PATHNAME_RESOLVE_LINKS (path, _pco_path_);		\
+  C_STRING_TO_EXTERNAL (_pco_path_, pathout, Qutf_8);	\
+} while (0)
+
 #ifdef WIN32_NATIVE
-# define PATHNAME_CONVERT_OUT(path, pathout)	\
-do						\
-{						\
-  const Ibyte *_pco_path_;			\
-  PATHNAME_RESOLVE_LINKS (path, _pco_path_);	\
-  C_STRING_TO_TSTR (_pco_path_, pathout);	\
-} while (0)
+#define PATHNAME_CONVERT_OUT(path, pathout) \
+  PATHNAME_CONVERT_OUT_TSTR (path, pathout)
 #else
 # define PATHNAME_CONVERT_OUT(path, pathout) \
   C_STRING_TO_EXTERNAL (path, pathout, Qfile_name)
--- a/src/syswindows.h	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/syswindows.h	Tue Jan 12 01:38:04 2010 -0600
@@ -1,5 +1,5 @@
 /* Copyright (C) 2000 Free Software Foundation, Inc.
-   Copyright (C) 2000, 2001, 2002, 2004 Ben Wing.
+   Copyright (C) 2000, 2001, 2002, 2004, 2010 Ben Wing.
 
 This file is part of XEmacs.
 
@@ -137,6 +137,7 @@
 
 #include <cygwin/stat.h> /* for struct stat */
 #include <w32api.h> /* for version info */
+#include <sys/cygwin.h> /* path conversion functions */
 
 /* Test for a specific version of w32api */
 #define W32API_VER(major,minor) (((major) << 16) + (minor))
@@ -931,28 +932,68 @@
 
 #ifdef CYGWIN
 
-BEGIN_C_DECLS
+/* We should just remove the Windows 9x support */
 
-void cygwin_win32_to_posix_path_list (const char *, char *);
-int cygwin_win32_to_posix_path_list_buf_size (const char *);
-void cygwin_posix_to_win32_path_list (const char *, char *);
-int cygwin_posix_to_win32_path_list_buf_size (const char *);
-extern int cygwin_conv_to_full_win32_path (const char *, char *);
-
-END_C_DECLS
+#define CCP_POSIX_TO_WIN_T \
+  (XEUNICODE_P ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A)
+#define CCP_WIN_T_TO_POSIX \
+  (XEUNICODE_P ? CCP_WIN_W_TO_POSIX : CCP_WIN_A_TO_POSIX)
 
 #endif
 
-#define LOCAL_FILE_FORMAT_TO_TSTR(path, out)			\
-do {								\
-  Ibyte *lttff;							\
-								\
-  LOCAL_TO_WIN32_FILE_FORMAT (XSTRING_DATA (path), lttff);	\
-  PATHNAME_CONVERT_OUT (lttff, out);				\
+#ifdef HAVE_CYGWIN_CONV_PATH
+#define LOCAL_FILE_FORMAT_TO_TSTR(path, out)				\
+do {									\
+  const Ibyte *lfftt = (path);						\
+  if (isalpha (lfftt[0]) && (IS_DEVICE_SEP (lfftt[1])))			\
+    PATHNAME_CONVERT_OUT_TSTR (lfftt, out);				\
+  else									\
+    {									\
+      int lfftt_size;							\
+      Extbyte *lfftt_utf8_path;						\
+      Extbyte *lfftt_tstr_path;						\
+									\
+      PATHNAME_CONVERT_OUT_UTF_8 (lfftt, lfftt_utf8_path);		\
+      lfftt_size = cygwin_conv_path (CCP_POSIX_TO_WIN_T | CCP_RELATIVE,	\
+				     lfftt_utf8_path, NULL, 0);		\
+      lfftt_tstr_path = alloca_extbytes (lfftt_size);			\
+      cygwin_conv_path (CCP_POSIX_TO_WIN_T | CCP_RELATIVE,		\
+			lfftt_utf8_path, lfftt_tstr_path, lfftt_size);	\
+      * (Extbyte **) &(out) = lfftt_tstr_path;				\
+    }									\
 } while (0)
+#define TSTR_TO_LOCAL_FILE_FORMAT(path, out)				\
+do {									\
+  const Extbyte *ttlff = (path);					\
+  int ttlff_size;							\
+  Extbyte *ttlff_utf8_path;						\
+									\
+  ttlff_size = cygwin_conv_path (CCP_WIN_T_TO_POSIX | CCP_RELATIVE,	\
+				 ttlff, NULL, 0);			\
+  ttlff_utf8_path = alloca_extbytes (ttlff_size);			\
+  cygwin_conv_path (CCP_WIN_T_TO_POSIX | CCP_RELATIVE,			\
+		    ttlff, ttlff_utf8_path, ttlff_size);		\
+  EXTERNAL_TO_C_STRING (ttlff_utf8_path, out, Qutf_8);			\
+} while (0)
+#else /* not HAVE_CYGWIN_CONV_PATH */
+#define LOCAL_FILE_FORMAT_TO_TSTR(path, out)		\
+do {							\
+  Ibyte *lfftt;						\
+							\
+  LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN (path, lfftt);	\
+  PATHNAME_CONVERT_OUT_TSTR (lfftt, out);		\
+} while (0)
+#define TSTR_TO_LOCAL_FILE_FORMAT(path, out)		\
+do {							\
+  Ibyte *ttlff;						\
+							\
+  TSTR_TO_C_STRING (path, ttlff);			\
+  INTERNAL_MSWIN_TO_LOCAL_FILE_FORMAT (ttlff, out);	\
+} while (0)
+#endif /* (not) HAVE_CYGWIN_CONV_PATH */
 
-Lisp_Object tstr_to_local_file_format (Extbyte *pathout);
-
+#define LISP_LOCAL_FILE_FORMAT_TO_TSTR(path, out) \
+  LOCAL_FILE_FORMAT_TO_TSTR (XSTRING_DATA (path), out)
 /* Convert from local file format, as used in XEmacs, to valid win32
    filenames as can be given to Windows API routines.  Under native XEmacs,
    this is a no-op, but under Cygwin, the local names look different --
@@ -962,36 +1003,50 @@
    check, look for letter plus colon at beginning of name) and do nothing
    in that case. */
 
-#ifdef CYGWIN
-#define LOCAL_TO_WIN32_FILE_FORMAT(path, pathout)			   \
-do {									   \
-  /* NOTE: It is a bit evil that here and below we are passing		   \
-     internal-format data to a function that (nominally) should work	   \
-     with external-format data.  But in point of fact, the Cygwin	   \
-     conversion functions are *NOT* localized, and will fail if they	   \
-     get 7-bit ISO2022-encoded data.  We know that our internal format	   \
-     is ASCII-compatible, and so these functions will work fine with	   \
-     this data. */							   \
-  Ibyte *ltwffp = (path);						   \
-  if (isalpha (ltwffp[0]) && (IS_DEVICE_SEP (ltwffp[1])))		   \
-    pathout = ltwffp;							   \
-  else									   \
-    {									   \
-      int ltwff2 =							   \
-        cygwin_posix_to_win32_path_list_buf_size ((char *) ltwffp);	   \
-      pathout = alloca_ibytes (ltwff2);				   \
-      cygwin_posix_to_win32_path_list ((char *) ltwffp, (char *) pathout); \
-    }									   \
+#ifdef HAVE_CYGWIN_CONV_PATH
+/* When Cygwin uses UTF-8, we can't just manipulate internal-format data
+   with its routines because it will mangle the high bytes, so we need to
+   convert to UTF-8 first, then to Win32 TSTR format (i.e. UTF-16, on
+   Windows NT), then back to internal format.  Routines that want external
+   format should avoid this by using LISP_LOCAL_FILE_FORMAT_TO_TSTR().
+   Same thing applies going the other direction. */
+#define LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN(path, pathout)	\
+do								\
+  {								\
+    Extbyte *lfftiwp;						\
+								\
+    LOCAL_FILE_FORMAT_TO_TSTR (path, lfftiwp);			\
+    TSTR_TO_C_STRING (lfftiwp, pathout);			\
+  }								\
+while (0)
+#define INTERNAL_MSWIN_TO_LOCAL_FILE_FORMAT(path, pathout)	\
+do {								\
+  Extbyte *iwtlffp;						\
+  C_STRING_TO_TSTR (path, iwtlffp);				\
+  TSTR_TO_LOCAL_FILE_FORMAT (iwtlffp, pathout);			\
 } while (0)
-#else
-#define LOCAL_TO_WIN32_FILE_FORMAT(path, pathout)	\
-do {							\
-  (pathout) = (path);					\
+#elif defined (CYGWIN)
+#define LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN(path, pathout)		\
+do {									\
+  /* NOTE: It is a bit evil that here and below we are passing		\
+     internal-format data to a function that (nominally) should work	\
+     with external-format data.  But in point of fact, the Cygwin	\
+     conversion functions are *NOT* localized, and will fail if they	\
+     get 7-bit ISO2022-encoded data.  We know that our internal format	\
+     is ASCII-compatible, and so these functions will work fine with	\
+     this data. */							\
+  Ibyte *lfftiwp = (path);						\
+  if (isalpha (lfftiwp[0]) && (IS_DEVICE_SEP (lfftiwp[1])))		\
+    pathout = lfftiwp;							\
+  else									\
+    {									\
+      int lfftiw2 =							\
+        cygwin_posix_to_win32_path_list_buf_size ((char *) lfftiwp);	\
+      pathout = alloca_ibytes (lfftiw2);				\
+      cygwin_posix_to_win32_path_list ((char *) lfftiwp, (char *) pathout); \
+    }									\
 } while (0)
-#endif
-
-#ifdef CYGWIN
-#define WIN32_TO_LOCAL_FILE_FORMAT(path, pathout)			\
+#define INTERNAL_MSWIN_TO_LOCAL_FILE_FORMAT(path, pathout)		\
 do {									\
   Ibyte *wtlff1 = (path);						\
   int wtlff2 =								\
@@ -1000,19 +1055,25 @@
   cygwin_win32_to_posix_path_list ((char *) wtlff1, (char *) wtlff3);	\
   (pathout) = wtlff3;							\
 } while (0)
-#else
-#define WIN32_TO_LOCAL_FILE_FORMAT(path, pathout)	\
-do {							\
-  (pathout) = (path);					\
+#else /* not defined (CYGWIN) */
+#define LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN(path, pathout)	\
+do {								\
+  (pathout) = (path);						\
 } while (0)
-#endif
+#define INTERNAL_MSWIN_TO_LOCAL_FILE_FORMAT(path, pathout)	\
+do {								\
+  (pathout) = (path);						\
+} while (0)
+#endif /* (not) defined (CYGWIN) */
+
+Lisp_Object tstr_to_local_file_format (Extbyte *pathout);
 
 /* Convert a local-format file name or URL in internal format into a Win32
    file name or URL in tstr format. */
 
 #ifdef CYGWIN
 
-#define LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR(lispstr, pathout)		\
+#define LISP_LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR(lispstr, pathout)	\
 do									\
 {									\
   Ibyte *lffmutt_fname1;						\
@@ -1027,7 +1088,8 @@
       if (qxestrncasecmp_ascii (lffmutt_pathint, "file://", 7) == 0)	\
 	{								\
 	  Ibyte *lffmutt_path1, *lffmutt_path2;				\
-	  LOCAL_TO_WIN32_FILE_FORMAT (lffmutt_pathint + 7, lffmutt_path1); \
+	  LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN (lffmutt_pathint + 7,	\
+                                               lffmutt_path1);		\
 	  if (lffmutt_path1 == lffmutt_pathint + 7) /* Optimization */	\
 	    lffmutt_path2 = lffmutt_pathint;				\
 	  else								\
@@ -1045,14 +1107,14 @@
     }									\
   else									\
     /* Not URL-style, must be a straight filename. */			\
-    LOCAL_FILE_FORMAT_TO_TSTR (lispstr, pathout);			\
+    LISP_LOCAL_FILE_FORMAT_TO_TSTR (lispstr, pathout);			\
 } while (0)
 
 #else /* not CYGWIN */
 
   /* URL's (and everything else) are already in the right format */
-#define LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR(lispstr, pathout) \
-   LOCAL_FILE_FORMAT_TO_TSTR (lispstr, pathout)
+#define LISP_LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR(lispstr, pathout) \
+   LISP_LOCAL_FILE_FORMAT_TO_TSTR (lispstr, pathout)
 
 #endif /* not CYGWIN */
 
--- a/src/text.h	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/text.h	Tue Jan 12 01:38:04 2010 -0600
@@ -2974,8 +2974,15 @@
 #endif
 #define Qunix_host_name_encoding Qnative
 #define Qunix_service_name_encoding Qnative
+#define Qtime_function_encoding Qnative
+#define Qtime_zone_encoding Qtime_function_encoding
 #define Qmswindows_host_name_encoding Qmswindows_multibyte
 #define Qmswindows_service_name_encoding Qmswindows_multibyte
+#define Quser_name_encoding Qnative
+#define Qerror_message_encoding Qnative
+#define Qjpeg_error_message_encoding Qerror_message_encoding
+#define Qtooltalk_encoding Qnative
+#define Qgtk_encoding Qnative
 
 /* Wexttext functions.  The type of Wexttext is selected at compile time
    and will sometimes be wchar_t, sometimes char. */
@@ -3107,6 +3114,7 @@
    Qenvironment_variable_encoding */
 #define Qx_display_name_encoding Qx_hpc_encoding
 #define Qx_xpm_data_encoding Qx_hpc_encoding
+#define Qx_error_message_encoding Qx_hpc_encoding
 
 /* !!#### Verify these! */
 #define Qxt_widget_arg_encoding Qnative
--- a/src/tooltalk.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/tooltalk.c	Tue Jan 12 01:38:04 2010 -0600
@@ -314,7 +314,7 @@
     {
       CIbyte *err;
 
-      EXTERNAL_TO_C_STRING (tt_status_message (st), err, Qnative);
+      EXTERNAL_TO_C_STRING (tt_status_message (st), err, Qtooltalk_encoding);
       signal_error (Qtooltalk_error, err, Qunbound);
     }
 }
@@ -777,7 +777,7 @@
       CHECK_STRING (value);
       TO_EXTERNAL_FORMAT (LISP_STRING, value,
 			  ALLOCA, (value_ext, value_ext_len),
-			  Qnative);
+			  Qtooltalk_encoding);
       tt_message_arg_bval_set (m, n, (unsigned char *) value_ext, value_ext_len);
     }
   else if (EQ (attribute, Qtt_arg_ival))
@@ -789,7 +789,7 @@
     {
       const char *value_ext;
       CHECK_STRING (value);
-      LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
+      LISP_STRING_TO_EXTERNAL (value, value_ext, Qtooltalk_encoding);
       tt_message_arg_val_set (m, n, value_ext);
     }
   else if (EQ (attribute, Qtt_status))
@@ -814,7 +814,7 @@
     {
       const char *value_ext;
       CHECK_STRING (value);
-      LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
+      LISP_STRING_TO_EXTERNAL (value, value_ext, Qtooltalk_encoding);
       (*fun_str) (m, value_ext);
     }
 
@@ -930,13 +930,13 @@
   {
     const char *vtype_ext;
 
-    LISP_STRING_TO_EXTERNAL (vtype, vtype_ext, Qnative);
+    LISP_STRING_TO_EXTERNAL (vtype, vtype_ext, Qtooltalk_encoding);
     if (NILP (value))
       tt_message_arg_add (m, n, vtype_ext, NULL);
     else if (STRINGP (value))
       {
 	const char *value_ext;
-	LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
+	LISP_STRING_TO_EXTERNAL (value, value_ext, Qtooltalk_encoding);
 	tt_message_arg_add (m, n, vtype_ext, value_ext);
       }
     else if (INTP (value))
@@ -1041,28 +1041,28 @@
     {
       const char *value_ext;
       CHECK_STRING (value);
-      LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
+      LISP_STRING_TO_EXTERNAL (value, value_ext, Qtooltalk_encoding);
       tt_pattern_file_add (p, value_ext);
     }
   else if (EQ (attribute, Qtt_object))
     {
       const char *value_ext;
       CHECK_STRING (value);
-      LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
+      LISP_STRING_TO_EXTERNAL (value, value_ext, Qtooltalk_encoding);
       tt_pattern_object_add (p, value_ext);
     }
   else if (EQ (attribute, Qtt_op))
     {
       const char *value_ext;
       CHECK_STRING (value);
-      LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
+      LISP_STRING_TO_EXTERNAL (value, value_ext, Qtooltalk_encoding);
       tt_pattern_op_add (p, value_ext);
     }
   else if (EQ (attribute, Qtt_otype))
     {
       const char *value_ext;
       CHECK_STRING (value);
-      LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
+      LISP_STRING_TO_EXTERNAL (value, value_ext, Qtooltalk_encoding);
       tt_pattern_otype_add (p, value_ext);
     }
   else if (EQ (attribute, Qtt_scope))
@@ -1074,21 +1074,21 @@
     {
       const char *value_ext;
       CHECK_STRING (value);
-      LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
+      LISP_STRING_TO_EXTERNAL (value, value_ext, Qtooltalk_encoding);
       tt_pattern_sender_add (p, value_ext);
     }
   else if (EQ (attribute, Qtt_sender_ptype))
     {
       const char *value_ext;
       CHECK_STRING (value);
-      LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
+      LISP_STRING_TO_EXTERNAL (value, value_ext, Qtooltalk_encoding);
       tt_pattern_sender_ptype_add (p, value_ext);
     }
   else if (EQ (attribute, Qtt_session))
     {
       const char *value_ext;
       CHECK_STRING (value);
-      LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
+      LISP_STRING_TO_EXTERNAL (value, value_ext, Qtooltalk_encoding);
       tt_pattern_session_add (p, value_ext);
     }
   else if (EQ (attribute, Qtt_state))
@@ -1129,13 +1129,13 @@
   {
     const char *vtype_ext;
 
-    LISP_STRING_TO_EXTERNAL (vtype, vtype_ext, Qnative);
+    LISP_STRING_TO_EXTERNAL (vtype, vtype_ext, Qtooltalk_encoding);
     if (NILP (value))
       tt_pattern_arg_add (p, n, vtype_ext, NULL);
     else if (STRINGP (value))
       {
 	const char *value_ext;
-	LISP_STRING_TO_EXTERNAL (value, value_ext, Qnative);
+	LISP_STRING_TO_EXTERNAL (value, value_ext, Qtooltalk_encoding);
 	tt_pattern_arg_add (p, n, vtype_ext, value_ext);
       }
     else if (INTP (value))
--- a/src/unicode.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/unicode.c	Tue Jan 12 01:38:04 2010 -0600
@@ -1,5 +1,5 @@
 /* Code to handle Unicode conversion.
-   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Ben Wing.
+   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2010 Ben Wing.
 
 This file is part of XEmacs.
 
@@ -3290,3 +3290,38 @@
   Vutf_8_invalid_string = Qnil;
 #endif /* MULE */
 }
+
+void
+complex_vars_of_unicode (void)
+{
+  /* We used to define this in unicode.el.  But we need it early for
+     Cygwin 1.7 -- used in LOCAL_FILE_FORMAT_TO_TSTR() et al. */
+  Fmake_coding_system_internal
+    (Qutf_8, Qunicode,
+     build_msg_string ("UTF-8"),
+     nconc2 (list4 (Qdocumentation,
+		    build_msg_string (
+"UTF-8 Unicode encoding -- ASCII-compatible 8-bit variable-width encoding\n"
+"sharing the following principles with the Mule-internal encoding:\n"
+"\n"
+"  -- All ASCII characters (codepoints 0 through 127) are represented\n"
+"     by themselves (i.e. using one byte, with the same value as the\n"
+"     ASCII codepoint), and these bytes are disjoint from bytes\n"
+"     representing non-ASCII characters.\n"
+"\n"
+"     This means that any 8-bit clean application can safely process\n"
+"     UTF-8-encoded text as it were ASCII, with no corruption (e.g. a\n"
+"     '/' byte is always a slash character, never the second byte of\n"
+"     some other character, as with Big5, so a pathname encoded in\n"
+"     UTF-8 can safely be split up into components and reassembled\n"
+"     again using standard ASCII processes).\n"
+"\n"
+"  -- Leading bytes and non-leading bytes in the encoding of a\n"
+"     character are disjoint, so moving backwards is easy.\n"
+"\n"
+"  -- Given only the leading byte, you know how many following bytes\n"
+"     are present.\n"
+),
+		    Qmnemonic, build_string ("UTF8")),
+	     list2 (Qunicode_type, Qutf_8)));
+}
--- a/src/win32.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/win32.c	Tue Jan 12 01:38:04 2010 -0600
@@ -70,7 +70,7 @@
 {
   Ibyte *pseudo_url;
   
-  WIN32_TO_LOCAL_FILE_FORMAT (filename, filename);
+  INTERNAL_MSWIN_TO_LOCAL_FILE_FORMAT (filename, filename);
   pseudo_url = xnew_array (Ibyte, 5 + qxestrlen (filename) + 1);
   qxestrcpy_ascii (pseudo_url, "file:");
   qxestrcat (pseudo_url, filename);
@@ -93,7 +93,7 @@
   Ibyte *ttlff;
 
   TSTR_TO_C_STRING (path, ttlff);
-  WIN32_TO_LOCAL_FILE_FORMAT (ttlff, ttlff);
+  INTERNAL_MSWIN_TO_LOCAL_FILE_FORMAT (ttlff, ttlff);
 
   return build_intstring (ttlff);
 }
@@ -350,9 +350,9 @@
     if (STRINGP (parameters))
       LISP_STRING_TO_TSTR (parameters, parmext);
     if (STRINGP (current_dir))
-      LOCAL_FILE_FORMAT_TO_TSTR (current_dir, path);
+      LISP_LOCAL_FILE_FORMAT_TO_TSTR (current_dir, path);
     if (STRINGP (document))
-      LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR (document, doc);
+      LISP_LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR (document, doc);
 
     ret = (int) qxeShellExecute (NULL, opext, doc, parmext, path,
 				 (INTP (show_flag) ?
@@ -404,7 +404,7 @@
     return path;
 
   /* Use mule and cygwin-safe APIs top get at file data. */
-  LOCAL_TO_WIN32_FILE_FORMAT (p, p);
+  LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN (p, p);
   return build_intstring (p);
 }
 #endif
--- a/tests/ChangeLog	Sun Jan 10 01:06:15 2010 -0600
+++ b/tests/ChangeLog	Tue Jan 12 01:38:04 2010 -0600
@@ -1,3 +1,8 @@
+2010-01-11  Ben Wing  <ben@xemacs.org>
+
+	* automated/mule-tests.el (featurep):
+	Use utf-8 as file-name-coding-system under Cygwin 1.7+.
+
 2010-01-01  Aidan Kehoe  <kehoea@parhasard.net>
 
 	* automated/lisp-tests.el: 
--- a/tests/automated/mule-tests.el	Sun Jan 10 01:06:15 2010 -0600
+++ b/tests/automated/mule-tests.el	Tue Jan 12 01:38:04 2010 -0600
@@ -385,7 +385,8 @@
 	 (file-name-coding-system
 	  ;; 'iso-8859-X doesn't work on darwin (as of "Panther" 10.3), it
 	  ;; seems to know that file-name-coding-system is definitely utf-8
-	  (if (string-match "darwin" system-configuration)
+	  (if (or (string-match "darwin" system-configuration)
+		  (featurep 'cygwin-use-utf-8))
 	      'utf-8
 	    'iso-8859-2))
          ;; make-temp-name does stat(), which on OS X requires that you