# ftp://invisible-island.net/temp/vile-9.7u4.patch.gz
# patch by Thomas E. Dickey <dickey@invisible-island.net>
# created  Sun Sep 27 22:22:49 UTC 2009
# ------------------------------------------------------------------------------
# CHANGES          |   15 +++++++++
# aclocal.m4       |    6 +--
# config.guess     |   81 +++++++++++++++++++--------------------------------
# config.sub       |   36 +++++++++++++++++-----
# configure        |    2 -
# filters/c-filt.c |    6 +--
# filters/objc.key |    3 +
# patchlev.h       |    2 -
# vile-9.7.spec    |    9 ++++-
# x11.c            |   83 ++++++++++++++++++++++++++++++-----------------------
# 10 files changed, 138 insertions(+), 105 deletions(-)
# ------------------------------------------------------------------------------
Index: CHANGES
--- vile-9.7u+/CHANGES	2009-08-25 00:37:43.000000000 +0000
+++ vile-9.7u4/CHANGES	2009-09-27 22:12:21.000000000 +0000
@@ -1,5 +1,20 @@
 Changes for vile 9.8 (released ??? ??? ?? ????)
 
+ 200909?? (v)
+	> Tom Dickey:
+	+ bypass symbols for XA_COMPOUND_TEXT() and XA_UTF8_STRING() in xvile,
+	  to resolve portability issues with older X headers/libraries (report
+	  by David Rolfe).
+	+ correct handling of retries for different selection types in xvile
+	  broken in 9.7u (report by Steven Lembark).
+	+ update configure check for lex version to work with reflex 20090902's
+	  inclusion of patch-date.
+	+ fix objc.key to reset symbol table (from "cpre" to "objc") before
+	  merging in "c" keywords (overlooked in 9.7q).
+	+ correct list of options for c-filter, to make objcmode work with
+	  external syntax filter.
+	+ update config.guess, config.sub
+	
  20090824 (u)
 	> Mike Mackovitch:
 	+ use temporary bp variable in calls to writeout() to ensure that the
Index: aclocal.m4
Prereq:  1.192 
--- vile-9.7u+/aclocal.m4	2009-08-24 10:43:59.000000000 +0000
+++ vile-9.7u4/aclocal.m4	2009-09-03 09:15:41.000000000 +0000
@@ -1,6 +1,6 @@
 dnl vile's local definitions for autoconf.
 dnl
-dnl $Header: /usr/build/vile/vile/RCS/aclocal.m4,v 1.192 2009/08/24 10:43:59 tom Exp $
+dnl $Header: /usr/build/vile/vile/RCS/aclocal.m4,v 1.193 2009/09/03 09:15:41 tom Exp $
 dnl
 dnl ---------------------------------------------------------------------------
 dnl ---------------------------------------------------------------------------
@@ -2105,7 +2105,7 @@
 fi
 ])dnl
 dnl ---------------------------------------------------------------------------
-dnl CF_LEX_VERSION version: 2 updated: 2007/11/26 06:57:56
+dnl CF_LEX_VERSION version: 3 updated: 2009/09/03 05:12:44
 dnl --------------
 dnl Check if "lex" is really "flex", and if so, set $LEX_VERSION to show its
 dnl version.
@@ -2118,7 +2118,7 @@
 then
 	AC_MSG_RESULT(yes)
 	AC_MSG_CHECKING(version of $LEX)
-	LEX_VERSION=`$LEX --version </dev/null 2>&1 | sed -e 's/^.* //;s/^[[^0-9]]*//'`
+	LEX_VERSION=`$LEX --version </dev/null 2>&1 | sed -e 's/^.* \([[0-9]]\)/\\1/;s/ .*$//;s/^[[^0-9]]*//'`
 	AC_MSG_RESULT($LEX_VERSION)
 else
 	AC_MSG_RESULT(no)
Index: config.guess
--- vile-9.7u+/config.guess	2008-12-19 01:02:46.000000000 +0000
+++ vile-9.7u4/config.guess	2009-08-25 10:39:56.000000000 +0000
@@ -1,10 +1,10 @@
 #! /bin/sh
 # Attempt to guess a canonical system name.
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
 #   Free Software Foundation, Inc.
 
-timestamp='2008-12-19'
+timestamp='2009-08-19'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -27,16 +27,16 @@
 # the same distribution terms that you use for the rest of that program.
 
 
-# Originally written by Per Bothner <per@bothner.com>.
-# Please send patches to <config-patches@gnu.org>.  Submit a context
-# diff and a properly formatted ChangeLog entry.
+# Originally written by Per Bothner.  Please send patches (context
+# diff format) to <config-patches@gnu.org> and include a ChangeLog
+# entry.
 #
 # This script attempts to guess a canonical system name similar to
 # config.sub.  If it succeeds, it prints the system name on stdout, and
 # exits with 0.  Otherwise, it exits with 1.
 #
-# The plan is that this can be called by configure scripts if you
-# don't specify an explicit build system type.
+# You can get the latest version of this script from:
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
 
 me=`echo "$0" | sed -e 's,.*/,,'`
 
@@ -170,7 +170,7 @@
 	    arm*|i386|m68k|ns32k|sh3*|sparc|vax)
 		eval $set_cc_for_build
 		if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
-			| grep __ELF__ >/dev/null
+			| grep -q __ELF__
 		then
 		    # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
 		    # Return netbsd for either.  FIX?
@@ -324,6 +324,9 @@
 	case `/usr/bin/uname -p` in
 	    sparc) echo sparc-icl-nx7; exit ;;
 	esac ;;
+    s390x:SunOS:*:*)
+	echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
     sun4H:SunOS:5.*:*)
 	echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
 	exit ;;
@@ -653,7 +656,7 @@
 	    # => hppa64-hp-hpux11.23
 
 	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
-		grep __LP64__ >/dev/null
+		grep -q __LP64__
 	    then
 		HP_ARCH="hppa2.0w"
 	    else
@@ -819,6 +822,9 @@
     [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
 	echo i${UNAME_MACHINE}-pc-mks
 	exit ;;
+    8664:Windows_NT:*)
+	echo x86_64-pc-mks
+	exit ;;
     i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
 	# How do we know it's Interix rather than the generic POSIX subsystem?
 	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
@@ -879,40 +885,17 @@
     m68*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
 	exit ;;
-    mips:Linux:*:*)
+    mips:Linux:*:* | mips64:Linux:*:*)
 	eval $set_cc_for_build
 	sed 's/^	//' << EOF >$dummy.c
 	#undef CPU
-	#undef mips
-	#undef mipsel
+	#undef ${UNAME_MACHINE}
+	#undef ${UNAME_MACHINE}el
 	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
-	CPU=mipsel
+	CPU=${UNAME_MACHINE}el
 	#else
 	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
-	CPU=mips
-	#else
-	CPU=
-	#endif
-	#endif
-EOF
-	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
-	    /^CPU/{
-		s: ::g
-		p
-	    }'`"
-	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
-	;;
-    mips64:Linux:*:*)
-	eval $set_cc_for_build
-	sed 's/^	//' << EOF >$dummy.c
-	#undef CPU
-	#undef mips64
-	#undef mips64el
-	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
-	CPU=mips64el
-	#else
-	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
-	CPU=mips64
+	CPU=${UNAME_MACHINE}
 	#else
 	CPU=
 	#endif
@@ -944,7 +927,7 @@
 	  EV67)  UNAME_MACHINE=alphaev67 ;;
 	  EV68*) UNAME_MACHINE=alphaev68 ;;
         esac
-	objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
+	objdump --private-headers /bin/sh | grep -q ld.so.1
 	if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
 	echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
 	exit ;;
@@ -998,14 +981,6 @@
 	  elf32-i386)
 		TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu"
 		;;
-	  a.out-i386-linux)
-		echo "${UNAME_MACHINE}-pc-linux-gnuaout"
-		exit ;;
-	  "")
-		# Either a pre-BFD a.out linker (linux-gnuoldld) or
-		# one that does not give us useful --help.
-		echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
-		exit ;;
 	esac
 	# Determine whether the default compiler is a.out or elf
 	eval $set_cc_for_build
@@ -1071,7 +1046,7 @@
     i*86:syllable:*:*)
 	echo ${UNAME_MACHINE}-pc-syllable
 	exit ;;
-    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
+    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
 	echo i386-unknown-lynxos${UNAME_RELEASE}
 	exit ;;
     i*86:*DOS:*:*)
@@ -1115,8 +1090,11 @@
     pc:*:*:*)
 	# Left here for compatibility:
         # uname -m prints for DJGPP always 'pc', but it prints nothing about
-        # the processor, so we play safe by assuming i386.
-	echo i386-pc-msdosdjgpp
+        # the processor, so we play safe by assuming i586.
+	# Note: whatever this is, it MUST be the same as what config.sub
+	# prints for the "djgpp" host, or else GDB configury will decide that
+	# this is a cross-build.
+	echo i586-pc-msdosdjgpp
         exit ;;
     Intel:Mach:3*:*)
 	echo i386-pc-mach3
@@ -1176,7 +1154,7 @@
     rs6000:LynxOS:2.*:*)
 	echo rs6000-unknown-lynxos${UNAME_RELEASE}
 	exit ;;
-    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
+    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
 	echo powerpc-unknown-lynxos${UNAME_RELEASE}
 	exit ;;
     SM[BE]S:UNIX_SV:*:*)
@@ -1350,6 +1328,9 @@
     i*86:rdos:*:*)
 	echo ${UNAME_MACHINE}-pc-rdos
 	exit ;;
+    i*86:AROS:*:*)
+	echo ${UNAME_MACHINE}-pc-aros
+	exit ;;
 esac
 
 #echo '(No uname command or uname output not recognized.)' 1>&2
Index: config.sub
--- vile-9.7u+/config.sub	2008-12-19 01:02:46.000000000 +0000
+++ vile-9.7u4/config.sub	2009-08-25 10:39:42.000000000 +0000
@@ -1,10 +1,10 @@
 #! /bin/sh
 # Configuration validation subroutine script.
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
 #   Free Software Foundation, Inc.
 
-timestamp='2008-12-11'
+timestamp='2009-08-19'
 
 # This file is (in principle) common to ALL GNU software.
 # The presence of a machine in this file suggests that SOME GNU software
@@ -32,13 +32,16 @@
 
 
 # Please send patches to <config-patches@gnu.org>.  Submit a context
-# diff and a properly formatted ChangeLog entry.
+# diff and a properly formatted GNU ChangeLog entry.
 #
 # Configuration subroutine to validate and canonicalize a configuration type.
 # Supply the specified configuration type as an argument.
 # If it is invalid, we print an error message on stderr and exit with code 1.
 # Otherwise, we print the canonical config type on stdout and succeed.
 
+# You can get the latest version of this script from:
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
 # This file is supposed to be the same for all GNU packages
 # and recognize all the CPU types, system types and aliases
 # that are meaningful with *any* GNU software.
@@ -122,6 +125,7 @@
 case $maybe_os in
   nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
   uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
+  kopensolaris*-gnu* | \
   storm-chaos* | os2-emx* | rtmk-nova*)
     os=-$maybe_os
     basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
@@ -148,10 +152,13 @@
 	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
 	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
 	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
-	-apple | -axis | -knuth | -cray)
+	-apple | -axis | -knuth | -cray | -microblaze)
 		os=
 		basic_machine=$1
 		;;
+        -bluegene*)
+	        os=-cnk
+		;;
 	-sim | -cisco | -oki | -wec | -winbond)
 		os=
 		basic_machine=$1
@@ -271,6 +278,7 @@
 	| mipsisa64sr71k | mipsisa64sr71kel \
 	| mipstx39 | mipstx39el \
 	| mn10200 | mn10300 \
+	| moxie \
 	| mt \
 	| msp430 \
 	| nios | nios2 \
@@ -335,7 +343,7 @@
 	| lm32-* \
 	| m32c-* | m32r-* | m32rle-* \
 	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
-	| m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
+	| m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \
 	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
 	| mips16-* \
 	| mips64-* | mips64el-* \
@@ -445,6 +453,10 @@
 		basic_machine=m68k-apollo
 		os=-bsd
 		;;
+	aros)
+		basic_machine=i386-pc
+		os=-aros
+		;;
 	aux)
 		basic_machine=m68k-apple
 		os=-aux
@@ -461,6 +473,10 @@
 		basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
 		os=-linux
 		;;
+	bluegene*)
+		basic_machine=powerpc-ibm
+		os=-cnk
+		;;
 	c90)
 		basic_machine=c90-cray
 		os=-unicos
@@ -713,6 +729,9 @@
 		basic_machine=ns32k-utek
 		os=-sysv
 		;;
+        microblaze)
+		basic_machine=microblaze-xilinx
+		;;
 	mingw32)
 		basic_machine=i386-pc
 		os=-mingw32
@@ -1254,10 +1273,11 @@
 	# Each alternative MUST END IN A *, to match a version number.
 	# -sysv* is not here because it comes later, after sysvr4.
 	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
-	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
+	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
 	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
+	      | -kopensolaris* \
 	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
-	      | -aos* \
+	      | -aos* | -aros* \
 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
 	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
@@ -1606,7 +1626,7 @@
 			-sunos*)
 				vendor=sun
 				;;
-			-aix*)
+			-cnk*|-aix*)
 				vendor=ibm
 				;;
 			-beos*)
Index: configure
--- vile-9.7u+/configure	2009-08-24 10:44:03.000000000 +0000
+++ vile-9.7u4/configure	2009-09-03 09:16:24.000000000 +0000
@@ -4185,7 +4185,7 @@
 echo "${ECHO_T}yes" >&6
 	echo "$as_me:4186: checking version of $LEX" >&5
 echo $ECHO_N "checking version of $LEX... $ECHO_C" >&6
-	LEX_VERSION=`$LEX --version </dev/null 2>&1 | sed -e 's/^.* //;s/^[^0-9]*//'`
+	LEX_VERSION=`$LEX --version </dev/null 2>&1 | sed -e 's/^.* \([0-9]\)/\\1/;s/ .*$//;s/^[^0-9]*//'`
 	echo "$as_me:4189: result: $LEX_VERSION" >&5
 echo "${ECHO_T}$LEX_VERSION" >&6
 else
Index: filters/c-filt.c
Prereq:  1.80 
--- vile-9.7u+/filters/c-filt.c	2009-05-12 22:47:25.000000000 +0000
+++ vile-9.7u4/filters/c-filt.c	2009-09-03 00:11:06.000000000 +0000
@@ -6,20 +6,20 @@
  *		string literal ("Literal") support --  ben stoltz
  *		factor-out hashing and file I/O - tom dickey
  *
- * $Header: /usr/build/vile/vile/filters/RCS/c-filt.c,v 1.80 2009/05/12 22:47:25 tom Exp $
+ * $Header: /usr/build/vile/vile/filters/RCS/c-filt.c,v 1.81 2009/09/03 00:11:06 tom Exp $
  *
  * Usage: refer to vile.hlp and doc/filters.doc .
  *
  * Options:
  *	-j	java special cases
  *	-o	objc has '@' directives
- *	-p	suppress preprocessor suppoer
+ *	-p	suppress preprocessor support
  *	-s	javascript special cases
  */
 
 #include <filters.h>
 
-DefineOptFilter("c", "jps");
+DefineOptFilter("c", "jops");
 
 #define UPPER(c) isalpha(CharOf(c)) ? toupper(CharOf(c)) : c
 
Index: filters/objc.key
Prereq:  1.3 
--- vile-9.7u+/filters/objc.key	2008-08-29 00:03:31.000000000 +0000
+++ vile-9.7u4/filters/objc.key	2009-09-03 00:25:42.000000000 +0000
@@ -1,4 +1,4 @@
-: $Id: objc.key,v 1.3 2008/08/29 00:03:31 tom Exp $
+: $Id: objc.key,v 1.4 2009/09/03 00:25:42 tom Exp $
 : see http://objc.toodarkpark.net/summary.html
 : see http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/ObjC.pdf
 
@@ -47,4 +47,5 @@
 import
 .default
 :
+.table
 .merge c
Index: patchlev.h
--- vile-9.7u+/patchlev.h	2009-07-04 16:07:48.000000000 +0000
+++ vile-9.7u4/patchlev.h	2009-09-03 00:31:18.000000000 +0000
@@ -1,3 +1,3 @@
 #define VILE_RELEASE "9"
 #define VILE_VERSION "7"
-#define VILE_PATCHLEVEL "u"
+#define VILE_PATCHLEVEL "v"
Index: vile-9.7.spec
Prereq:  1.23 
--- vile-9.7u+/vile-9.7.spec	2009-07-04 16:07:48.000000000 +0000
+++ vile-9.7u4/vile-9.7.spec	2009-09-03 00:31:18.000000000 +0000
@@ -1,7 +1,7 @@
 Summary: VILE VI Like Emacs editor
-# $Header: /usr/build/vile/vile/RCS/vile-9.7.spec,v 1.23 2009/07/04 16:07:48 tom Exp $
+# $Header: /usr/build/vile/vile/RCS/vile-9.7.spec,v 1.24 2009/09/03 00:31:18 tom Exp $
 Name: vile
-Version: 9.7u
+Version: 9.7v
 # each patch should update the version
 Release: 1
 License: GPLv2
@@ -29,6 +29,7 @@
 Patch19: vile-9.7s.patch.gz
 Patch20: vile-9.7t.patch.gz
 Patch21: vile-9.7u.patch.gz
+Patch22: vile-9.7v.patch.gz
 # each patch should add itself to this list
 Packager: Thomas Dickey <dickey@invisible-island.net>
 BuildRoot: %{_tmppath}/%{name}-root
@@ -62,6 +63,7 @@
 %patch19 -p1
 %patch20 -p1
 %patch21 -p1
+%patch22 -p1
 # each patch should add itself to this list
 
 %build
@@ -114,6 +116,9 @@
 %changelog
 # each patch should add its ChangeLog entries here
 
+* Wed Sep 02 2009 Thomas Dickey
+- added patch for 9.7v
+
 * Sat Jul 04 2009 Thomas Dickey
 - added patch for 9.7u
 
Index: x11.c
Prereq:  1.333 
--- vile-9.7u+/x11.c	2009-08-24 10:18:42.000000000 +0000
+++ vile-9.7u4/x11.c	2009-09-27 22:11:02.000000000 +0000
@@ -2,7 +2,7 @@
  *	X11 support, Dave Lemke, 11/91
  *	X Toolkit support, Kevin Buettner, 2/94
  *
- * $Header: /usr/build/vile/vile/RCS/x11.c,v 1.333 2009/08/24 10:18:42 tom Exp $
+ * $Header: /usr/build/vile/vile/RCS/x11.c,v 1.337 2009/09/27 22:11:02 tom Exp $
  *
  */
 
@@ -449,6 +449,11 @@
 
 } TextWindowRec, *TextWindow;
 
+typedef struct {
+    Atom *targets;
+    Time time;
+} SelectionList;
+
 static Display *dpy;
 
 static TextWindowRec cur_win_rec;
@@ -474,6 +479,8 @@
 static Atom atom_TIMESTAMP;
 static Atom atom_TEXT;
 static Atom atom_CLIPBOARD;
+static Atom atom_COMPOUND_TEXT;
+static Atom atom_UTF8_STRING;
 
 #if OPT_KEV_SCROLLBARS || OPT_XAW_SCROLLBARS
 static Cursor curs_sb_v_double_arrow;
@@ -2758,10 +2765,8 @@
 	result = "XA_ATOM";
     else if (value == atom_CLIPBOARD)
 	result = "XA_CLIPBOARD";
-#ifdef XA_COMPOUND_TEXT
-    else if (value == XA_COMPOUND_TEXT(dpy))
+    else if (value == atom_COMPOUND_TEXT)
 	result = "XA_COMPOUND_TEXT";
-#endif
     else if (value == atom_MULTIPLE)
 	result = "MULTIPLE";
     else if (value == XA_PRIMARY)
@@ -2774,10 +2779,8 @@
 	result = "XA_TEXT";
     else if (value == atom_TIMESTAMP)
 	result = "XA_TIMESTAMP";
-#ifdef XA_UTF8_STRING
-    else if (value == XA_UTF8_STRING(dpy))
+    else if (value == atom_UTF8_STRING)
 	result = "XA_UTF8_STRING";
-#endif
     else
 	result = "unknown";
     return result;
@@ -3811,6 +3814,8 @@
     atom_TIMESTAMP = XInternAtom(dpy, "TIMESTAMP", False);
     atom_TEXT = XInternAtom(dpy, "TEXT", False);
     atom_CLIPBOARD = XInternAtom(dpy, "CLIPBOARD", False);
+    atom_COMPOUND_TEXT = XInternAtom(dpy, "COMPOUND_TEXT", False);
+    atom_UTF8_STRING = XInternAtom(dpy, "UTF8_STRING", False);
 
     set_pointer(XtWindow(cur_win->screen), cur_win->normal_pointer);
 
@@ -4312,8 +4317,8 @@
 	XtDestroyWidget(cur_win->top_widget);
 #endif
 	cur_win->top_widget = 0;
-	XtCloseDisplay(dpy);	/* need this if $xshell left subprocesses */
 	CloseInputMethod();
+	XtCloseDisplay(dpy);	/* need this if $xshell left subprocesses */
     }
 }
 
@@ -5039,12 +5044,8 @@
     if (result[0] == 0) {
 	Atom *tp = result;
 #if OPT_MULTIBYTE
-#ifdef XA_UTF8_STRING
-	*tp++ = XA_UTF8_STRING(dpy);
-#endif
-#ifdef XA_COMPOUND_TEXT
-	*tp++ = XA_COMPOUND_TEXT(dpy);
-#endif
+	*tp++ = atom_UTF8_STRING;
+	*tp++ = atom_COMPOUND_TEXT;
 #endif
 	*tp++ = atom_TEXT;
 	*tp++ = XA_STRING;
@@ -5082,13 +5083,15 @@
 /* ARGSUSED */
 static void
 x_get_selection(Widget w GCC_UNUSED,
-		XtPointer cldat GCC_UNUSED,
+		XtPointer cldat,
 		Atom * selection,
 		Atom * target,
 		XtPointer value,
 		ULONG * length,
 		int *format)
 {
+    SelectionList *list = (SelectionList *) cldat;
+
     TRACE(("x_get_selection(selection %s, target %s, format %d, length %lu)\n",
 	   visibleAtoms(*selection),
 	   visibleAtoms(*target),
@@ -5098,19 +5101,13 @@
     if (length != 0 && value != NULL) {
 	if (*format != 8) {
 	    kbd_alarm();	/* can't handle incoming data */
-	} else if (*target == XA_STRING) {
+	} else if (*target == XA_STRING || *target == atom_TEXT) {
 	    insert_selection(selection, (char *) value, (size_t) *length);
 	    XtFree((char *) value);
 	} else
 #if OPT_MULTIBYTE
-	    if (0
-#ifdef XA_COMPOUND_TEXT
-		|| (*target == XA_COMPOUND_TEXT(dpy))
-#endif
-#ifdef XA_UTF8_STRING
-		|| (*target == XA_UTF8_STRING(dpy))
-#endif
-	    ) {
+	    if ((*target == atom_COMPOUND_TEXT)
+		|| (*target == atom_UTF8_STRING)) {
 	    XTextProperty text_prop;
 	    char **text_list = NULL;
 	    int text_list_count, n;
@@ -5152,6 +5149,21 @@
 	{
 	    kbd_alarm();	/* can't handle incoming data */
 	}
+	XtFree((char *) list);
+    } else if (cldat != 0) {
+	if (list->targets[0] != None) {
+	    Atom newTarget = list->targets[0];
+
+	    list->targets++;
+	    XtGetSelectionValue(cur_win->top_widget,
+				*selection,
+				newTarget,
+				x_get_selection,
+				(XtPointer) (list),	/* client data */
+				list->time);
+	} else {
+	    XtFree((char *) list);
+	}
     }
 }
 
@@ -5176,12 +5188,17 @@
 			(XtPointer) data, &len_ul, &format);
     } else {
 	Atom *targets = GetSelectionTargets();
+	SelectionList *list = XtNew(SelectionList);
+	Time ev_time = XtLastTimestampProcessed(dpy);
+
+	list->targets = targets + 1;
+	list->time = ev_time;
 	XtGetSelectionValue(cur_win->top_widget,
 			    selection,
 			    targets[0],
 			    x_get_selection,
-			    (XtPointer) (targets + 1),	/* client data */
-			    XtLastTimestampProcessed(dpy));
+			    (XtPointer) (list),		/* client data */
+			    ev_time);
     }
 }
 
@@ -5258,10 +5275,9 @@
     Boolean result = False;
 
     TRACE((T_CALLED
-	   "x_convert_selection(selection %s, target %s, length %ld)\n",
+	   "x_convert_selection(selection %s, target %s)\n",
 	   visibleAtoms(*selection),
-	   visibleAtoms(*target),
-	   *length));
+	   visibleAtoms(*target)));
 
     if (!cur_win->have_selection && IsPrimary(*selection))
 	returnCode(False);
@@ -5307,18 +5323,14 @@
 	    result = x_get_clipboard_text((UCHAR **) value, (size_t *) length);
     }
 #if OPT_MULTIBYTE
-#ifdef XA_UTF8_STRING
-    else if (*target == XA_UTF8_STRING(dpy)) {
+    else if (*target == atom_UTF8_STRING) {
 	*type = *target;
 	*format = 8;
 	if (IsPrimary(*selection))
 	    result = x_get_selected_text((UCHAR **) value, (size_t *) length);
 	else			/* CLIPBOARD */
 	    result = x_get_clipboard_text((UCHAR **) value, (size_t *) length);
-    }
-#endif
-#ifdef XA_COMPOUND_TEXT
-    else if (*target == XA_COMPOUND_TEXT(dpy)) {
+    } else if (*target == atom_COMPOUND_TEXT) {
 	*type = *target;
 	*format = 8;
 	if (IsPrimary(*selection))
@@ -5326,7 +5338,6 @@
 	else			/* CLIPBOARD */
 	    result = x_get_clipboard_text((UCHAR **) value, (size_t *) length);
     }
-#endif
 #endif /* OPT_MULTIBYTE */
 
     returnCode(result);
