# ftp://ftp.invisible-island.net/xterm/patches/xterm-359.patch.gz
# patch by Thomas E. Dickey <dickey@invisible-island.net>
# created  Mon Aug 17 22:59:10 UTC 2020
# ------------------------------------------------------------------------------
# INSTALL                  |   12 
# MANIFEST                 |    2 
# Makefile.in              |    4 
# aclocal.m4               |    6 
# button.c                 |   62 ++--
# charproc.c               |   10 
# config.guess             |   28 +-
# config.sub               |  588 ++++++++++++++++++++++++---------------------
# configure                |   54 ++--
# configure.in             |   10 
# ctlseqs.ms               |   16 -
# ctlseqs.txt              |   25 +
# df-install.in            |   76 ++++-
# graphics.c               |    9 
# graphics_regis.c         |  116 ++++++--
# graphics_sixel.c         |   12 
# misc.c                   |    7 
# package/debian/changelog |    6 
# package/debian/rules     |    1 
# package/freebsd/Makefile |    4 
# package/pkgsrc/Makefile  |    2 
# package/xterm.spec       |    8 
# ptydata.c                |   94 +++++--
# ptyx.h                   |    4 
# util.c                   |   19 +
# version.h                |    6 
# xcharmouse.h             |    8 
# xterm.appdata.xml        |    2 
# xterm.h                  |    4 
# xterm.log.html           |   45 +++
# xterm.man                |   17 +
# 31 files changed, 807 insertions(+), 450 deletions(-)
# ------------------------------------------------------------------------------
Index: INSTALL
--- xterm-358+/INSTALL	2019-07-19 00:46:40.000000000 +0000
+++ xterm-359/INSTALL	2020-07-25 17:58:05.000000000 +0000
@@ -1,6 +1,6 @@
--- $XTermId: INSTALL,v 1.183 2019/07/19 00:46:40 tom Exp $
+-- $XTermId: INSTALL,v 1.184 2020/07/25 17:58:05 tom Exp $
 -------------------------------------------------------------------------------
--- Copyright 1997-2018,2019 by Thomas E. Dickey
+-- Copyright 1997-2019,2020 by Thomas E. Dickey
 --
 --                         All Rights Reserved
 --
@@ -325,6 +325,10 @@
 	Do not install xterm using setuid/setgid permissions.  Drop setuid
 	permissions on startup.
 
+  --disable-sixel-graphics disable support for sixel-graphics
+
+  	Do not compile-in code to support sixel-graphics
+
   --disable-sun-fkeys
 
   	Do not compile-in code to support Sun-style function keys.
@@ -527,10 +531,6 @@
 
   	Compile-in code to support experimental ReGIS graphics
 
-  --enable-sixel-graphics enable support for sixel-graphics
-
-  	Compile-in code to support experimental sixel-graphics
-
   --enable-toolbar        enable pulldown menus on toolbar
 
   	Compile-in code that builds a toolbar with pulldown menus.  The
Index: MANIFEST
--- xterm-358+/MANIFEST	2020-07-06 00:35:21.000000000 +0000
+++ xterm-359/MANIFEST	2020-07-25 17:48:12.000000000 +0000
@@ -1,4 +1,4 @@
-MANIFEST for xterm-358, version xterm-358
+MANIFEST for xterm-359, version xterm-359
 --------------------------------------------------------------------------------
 MANIFEST                        this file
 256colres.h                     resource-definitions for 256-color mode
Index: Makefile.in
--- xterm-358+/Makefile.in	2020-07-12 16:00:49.000000000 +0000
+++ xterm-359/Makefile.in	2020-08-02 19:12:41.000000000 +0000
@@ -1,4 +1,4 @@
-## $XTermId: Makefile.in,v 1.252 2020/07/12 16:00:49 tom Exp $
+## $XTermId: Makefile.in,v 1.253 2020/08/02 19:12:41 tom Exp $
 # -----------------------------------------------------------------------------
 # this file is part of xterm
 #
@@ -530,7 +530,7 @@
 @desktop_utils@install-full ::
 @desktop_utils@	ACTUAL_XTERM=$(actual_xterm) \
 @desktop_utils@	$(SHELL) -c 'for n in $(DESKTOP_FILES); \
-@desktop_utils@		do $(SHELL) df-install $$ACTUAL_XTERM $(ICON_NAME) $(DESKTOP_FLAGS) $$n; \
+@desktop_utils@		do $(SHELL) df-install $$ACTUAL_XTERM $(ICON_NAME) DESTDIR="$(DESTDIR)" $(DESKTOP_FLAGS) $$n; \
 @desktop_utils@		done'
 ################################################################################
 check : $(TEST_PROGRAMS)
Index: aclocal.m4
--- xterm-358+/aclocal.m4	2020-06-03 00:19:38.000000000 +0000
+++ xterm-359/aclocal.m4	2020-07-11 23:09:29.000000000 +0000
@@ -1,4 +1,4 @@
-dnl $XTermId: aclocal.m4,v 1.460 2020/06/03 00:19:38 tom Exp $
+dnl $XTermId: aclocal.m4,v 1.461 2020/07/11 23:09:29 tom Exp $
 dnl
 dnl ---------------------------------------------------------------------------
 dnl
@@ -2169,7 +2169,7 @@
 AC_SUBST(LINT_OPTS)
 ])dnl
 dnl ---------------------------------------------------------------------------
-dnl CF_REGEX version: 13 updated: 2020/03/10 18:53:47
+dnl CF_REGEX version: 14 updated: 2020/07/11 19:09:29
 dnl --------
 dnl Attempt to determine if we've got one of the flavors of regular-expression
 dnl code that we can support.
@@ -2181,7 +2181,7 @@
 cf_regex_libs="regex re"
 case $host_os in
 (mingw*)
-	cf_regex_libs="gnurx $cf_regex_libs"
+	cf_regex_libs="systre gnurx $cf_regex_libs"
 	;;
 esac
 
Index: button.c
--- xterm-358+/button.c	2020-06-25 00:12:29.000000000 +0000
+++ xterm-359/button.c	2020-08-04 08:10:25.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: button.c,v 1.583 2020/06/25 00:12:29 tom Exp $ */
+/* $XTermId: button.c,v 1.585 2020/08/04 08:10:25 tom Exp $ */
 
 /*
  * Copyright 1999-2019,2020 by Thomas E. Dickey
@@ -209,6 +209,7 @@
 	break;
     case SET_SGR_EXT_MODE_MOUSE:
     case SET_URXVT_EXT_MODE_MOUSE:
+    case SET_PIXEL_POSITION_MOUSE:
 	mouse_limit = -1;
 	break;
     }
@@ -250,8 +251,8 @@
 	}
 	break;
     case SET_SGR_EXT_MODE_MOUSE:
-	/* FALLTHRU */
     case SET_URXVT_EXT_MODE_MOUSE:
+    case SET_PIXEL_POSITION_MOUSE:
 	count += (unsigned) sprintf((char *) line + count, "%d", value + 1);
 	break;
     }
@@ -264,6 +265,7 @@
     switch (screen->extend_coords) {
     case SET_SGR_EXT_MODE_MOUSE:
     case SET_URXVT_EXT_MODE_MOUSE:
+    case SET_PIXEL_POSITION_MOUSE:
 	line[count++] = ';';
 	break;
     }
@@ -2652,6 +2654,7 @@
 		    line[count++] = 't';
 		    break;
 		case SET_SGR_EXT_MODE_MOUSE:
+		case SET_PIXEL_POSITION_MOUSE:
 		    line[count++] = '<';
 		    break;
 		}
@@ -2663,6 +2666,7 @@
 		switch (screen->extend_coords) {
 		case SET_SGR_EXT_MODE_MOUSE:
 		case SET_URXVT_EXT_MODE_MOUSE:
+		case SET_PIXEL_POSITION_MOUSE:
 		    line[count++] = 't';
 		    break;
 		}
@@ -2675,6 +2679,7 @@
 		    line[count++] = 'T';
 		    break;
 		case SET_SGR_EXT_MODE_MOUSE:
+		case SET_PIXEL_POSITION_MOUSE:
 		    line[count++] = '<';
 		    break;
 		}
@@ -2694,6 +2699,7 @@
 		switch (screen->extend_coords) {
 		case SET_SGR_EXT_MODE_MOUSE:
 		case SET_URXVT_EXT_MODE_MOUSE:
+		case SET_PIXEL_POSITION_MOUSE:
 		    line[count++] = 'T';
 		    break;
 		}
@@ -4783,6 +4789,7 @@
 	line[count++] = CharOf(value);
 	break;
     case SET_SGR_EXT_MODE_MOUSE:
+    case SET_PIXEL_POSITION_MOUSE:
 	value -= 32;		/* encoding starts at zero */
 	/* FALLTHRU */
     case SET_URXVT_EXT_MODE_MOUSE:
@@ -4841,7 +4848,8 @@
 	if (button > 3)
 	    return;
     } else if (screen->extend_coords == SET_SGR_EXT_MODE_MOUSE
-	       || screen->extend_coords == SET_URXVT_EXT_MODE_MOUSE) {
+	       || screen->extend_coords == SET_URXVT_EXT_MODE_MOUSE
+	       || screen->extend_coords == SET_PIXEL_POSITION_MOUSE) {
 	if (button > 15) {
 	    return;
 	}
@@ -4851,27 +4859,32 @@
 	}
     }
 
-    /* Compute character position of mouse pointer */
-    row = (event->y - screen->border) / FontHeight(screen);
-    col = (event->x - OriginX(screen)) / FontWidth(screen);
-
-    /* Limit to screen dimensions */
-    if (row < 0)
-	row = 0;
-    else if (row > screen->max_row)
-	row = screen->max_row;
-
-    if (col < 0)
-	col = 0;
-    else if (col > screen->max_col)
-	col = screen->max_col;
+    if (screen->extend_coords == SET_PIXEL_POSITION_MOUSE) {
+	row = event->y;
+	col = event->x;
+    } else {
+	/* Compute character position of mouse pointer */
+	row = (event->y - screen->border) / FontHeight(screen);
+	col = (event->x - OriginX(screen)) / FontWidth(screen);
+
+	/* Limit to screen dimensions */
+	if (row < 0)
+	    row = 0;
+	else if (row > screen->max_row)
+	    row = screen->max_row;
 
-    if (mouse_limit > 0) {
-	/* Limit to representable mouse dimensions */
-	if (row > mouse_limit)
-	    row = mouse_limit;
-	if (col > mouse_limit)
-	    col = mouse_limit;
+	if (col < 0)
+	    col = 0;
+	else if (col > screen->max_col)
+	    col = screen->max_col;
+
+	if (mouse_limit > 0) {
+	    /* Limit to representable mouse dimensions */
+	    if (row > mouse_limit)
+		row = mouse_limit;
+	    if (col > mouse_limit)
+		col = mouse_limit;
+	}
     }
 
     /* Build key sequence starting with \E[M */
@@ -4896,6 +4909,7 @@
 	line[count++] = final;
 	break;
     case SET_SGR_EXT_MODE_MOUSE:
+    case SET_PIXEL_POSITION_MOUSE:
 	line[count++] = '<';
 	break;
     }
@@ -4930,6 +4944,7 @@
 	    if (button < 3 || button > 5) {
 		switch (screen->extend_coords) {
 		case SET_SGR_EXT_MODE_MOUSE:
+		case SET_PIXEL_POSITION_MOUSE:
 		    final = 'm';
 		    break;
 		default:
@@ -4971,6 +4986,7 @@
 	switch (screen->extend_coords) {
 	case SET_SGR_EXT_MODE_MOUSE:
 	case SET_URXVT_EXT_MODE_MOUSE:
+	case SET_PIXEL_POSITION_MOUSE:
 	    line[count++] = final;
 	    break;
 	}
Index: charproc.c
--- xterm-358+/charproc.c	2020-07-12 15:47:18.000000000 +0000
+++ xterm-359/charproc.c	2020-08-10 09:07:11.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: charproc.c,v 1.1770 2020/07/12 15:47:18 tom Exp $ */
+/* $XTermId: charproc.c,v 1.1772 2020/08/10 09:07:11 tom Exp $ */
 
 /*
  * Copyright 1999-2019,2020 by Thomas E. Dickey
@@ -772,6 +772,7 @@
     Bres(XtNmkWidth, XtCMkWidth, misc.mk_width, False),
     Bres(XtNprecompose, XtCPrecompose, screen.normalized_c, True),
     Bres(XtNutf8Latin1, XtCUtf8Latin1, screen.utf8_latin1, False),
+    Bres(XtNutf8Weblike, XtCUtf8Weblike, screen.utf8_weblike, False),
     Bres(XtNvt100Graphics, XtCVT100Graphics, screen.vt100_graphics, True),
     Bres(XtNwideChars, XtCWideChars, screen.wide_chars, False),
     Ires(XtNcombiningChars, XtCCombiningChars, screen.max_combining, 2),
@@ -6384,6 +6385,8 @@
 	case srm_SGR_EXT_MODE_MOUSE:
 	    /* FALLTHRU */
 	case srm_URXVT_EXT_MODE_MOUSE:
+	    /* FALLTHRU */
+	case srm_PIXEL_POSITION_MOUSE:
 	    /*
 	     * Rather than choose an arbitrary precedence among the coordinate
 	     * modes, they are mutually exclusive.  For consistency, a reset is
@@ -6692,6 +6695,8 @@
 	case srm_SGR_EXT_MODE_MOUSE:
 	    /* FALLTHRU */
 	case srm_URXVT_EXT_MODE_MOUSE:
+	    /* FALLTHRU */
+	case srm_PIXEL_POSITION_MOUSE:
 	    DoSM(DP_X_EXT_MOUSE, screen->extend_coords);
 	    break;
 	case srm_ALTERNATE_SCROLL:
@@ -7026,6 +7031,8 @@
 	case srm_SGR_EXT_MODE_MOUSE:
 	    /* FALLTHRU */
 	case srm_URXVT_EXT_MODE_MOUSE:
+	    /* FALLTHRU */
+	case srm_PIXEL_POSITION_MOUSE:
 	    DoRM(DP_X_EXT_MOUSE, screen->extend_coords);
 	    break;
 	case srm_ALLOW_ALTBUF:
@@ -9664,6 +9671,7 @@
     VTInitialize_locale(request);
     init_Bres(screen.normalized_c);
     init_Bres(screen.utf8_latin1);
+    init_Bres(screen.utf8_weblike);
 
 #if OPT_LUIT_PROG
     init_Bres(misc.callfilter);
Index: config.guess
--- xterm-358+/config.guess	2019-12-21 02:01:01.000000000 +0000
+++ xterm-359/config.guess	2020-07-12 08:21:33.000000000 +0000
@@ -1,8 +1,8 @@
 #! /bin/sh
 # Attempt to guess a canonical system name.
-#   Copyright 1992-2019 Free Software Foundation, Inc.
+#   Copyright 1992-2020 Free Software Foundation, Inc.
 
-timestamp='2019-12-21'
+timestamp='2020-07-12'
 
 # 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
@@ -50,7 +50,7 @@
 GNU config.guess ($timestamp)
 
 Originally written by Per Bothner.
-Copyright 1992-2019 Free Software Foundation, Inc.
+Copyright 1992-2020 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -1095,7 +1095,17 @@
 	echo "$UNAME_MACHINE"-dec-linux-"$LIBC"
 	exit ;;
     x86_64:Linux:*:*)
-	echo "$UNAME_MACHINE"-pc-linux-"$LIBC"
+	set_cc_for_build
+	LIBCABI=$LIBC
+	if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
+	    if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \
+		(CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
+		grep IS_X32 >/dev/null
+	    then
+		LIBCABI="$LIBC"x32
+	    fi
+	fi
+	echo "$UNAME_MACHINE"-pc-linux-"$LIBCABI"
 	exit ;;
     xtensa*:Linux:*:*)
 	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
@@ -1332,6 +1342,9 @@
     *:Rhapsody:*:*)
 	echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE"
 	exit ;;
+    arm64:Darwin:*:*)
+	echo aarch64-apple-darwin"$UNAME_RELEASE"
+	exit ;;
     *:Darwin:*:*)
 	UNAME_PROCESSOR=`uname -p`
 	case $UNAME_PROCESSOR in
@@ -1629,6 +1642,12 @@
   https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
 and
   https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
+EOF
+
+year=`echo $timestamp | sed 's,-.*,,'`
+# shellcheck disable=SC2003
+if test "`expr "\`date +%Y\`" - "$year"`" -lt 3 ; then
+   cat >&2 <<EOF
 
 If $0 has already been updated, send the following data and any
 information you think might be pertinent to config-patches@gnu.org to
@@ -1656,6 +1675,7 @@
 UNAME_SYSTEM  = "$UNAME_SYSTEM"
 UNAME_VERSION = "$UNAME_VERSION"
 EOF
+fi
 
 exit 1
 
Index: config.sub
--- xterm-358+/config.sub	2019-09-11 23:56:40.000000000 +0000
+++ xterm-359/config.sub	2020-07-10 06:01:38.000000000 +0000
@@ -1,8 +1,8 @@
 #! /bin/sh
 # Configuration validation subroutine script.
-#   Copyright 1992-2019 Free Software Foundation, Inc.
+#   Copyright 1992-2020 Free Software Foundation, Inc.
 
-timestamp='2019-06-30'
+timestamp='2020-07-10'
 
 # 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
@@ -67,7 +67,7 @@
 version="\
 GNU config.sub ($timestamp)
 
-Copyright 1992-2019 Free Software Foundation, Inc.
+Copyright 1992-2020 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -124,28 +124,27 @@
 		;;
 	*-*-*-*)
 		basic_machine=$field1-$field2
-		os=$field3-$field4
+		basic_os=$field3-$field4
 		;;
 	*-*-*)
 		# Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two
 		# parts
 		maybe_os=$field2-$field3
 		case $maybe_os in
-			nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc \
-			| linux-newlib* | linux-musl* | linux-uclibc* | uclinux-uclibc* \
+			nto-qnx* | linux-* | uclinux-uclibc* \
 			| uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \
 			| netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \
 			| storm-chaos* | os2-emx* | rtmk-nova*)
 				basic_machine=$field1
-				os=$maybe_os
+				basic_os=$maybe_os
 				;;
 			android-linux)
 				basic_machine=$field1-unknown
-				os=linux-android
+				basic_os=linux-android
 				;;
 			*)
 				basic_machine=$field1-$field2
-				os=$field3
+				basic_os=$field3
 				;;
 		esac
 		;;
@@ -154,7 +153,7 @@
 		case $field1-$field2 in
 			decstation-3100)
 				basic_machine=mips-dec
-				os=
+				basic_os=
 				;;
 			*-*)
 				# Second component is usually, but not always the OS
@@ -162,7 +161,7 @@
 					# Prevent following clause from handling this valid os
 					sun*os*)
 						basic_machine=$field1
-						os=$field2
+						basic_os=$field2
 						;;
 					# Manufacturers
 					dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \
@@ -175,11 +174,11 @@
 					| microblaze* | sim | cisco \
 					| oki | wec | wrs | winbond)
 						basic_machine=$field1-$field2
-						os=
+						basic_os=
 						;;
 					*)
 						basic_machine=$field1
-						os=$field2
+						basic_os=$field2
 						;;
 				esac
 			;;
@@ -191,447 +190,451 @@
 		case $field1 in
 			386bsd)
 				basic_machine=i386-pc
-				os=bsd
+				basic_os=bsd
 				;;
 			a29khif)
 				basic_machine=a29k-amd
-				os=udi
+				basic_os=udi
 				;;
 			adobe68k)
 				basic_machine=m68010-adobe
-				os=scout
+				basic_os=scout
 				;;
 			alliant)
 				basic_machine=fx80-alliant
-				os=
+				basic_os=
 				;;
 			altos | altos3068)
 				basic_machine=m68k-altos
-				os=
+				basic_os=
 				;;
 			am29k)
 				basic_machine=a29k-none
-				os=bsd
+				basic_os=bsd
 				;;
 			amdahl)
 				basic_machine=580-amdahl
-				os=sysv
+				basic_os=sysv
 				;;
 			amiga)
 				basic_machine=m68k-unknown
-				os=
+				basic_os=
 				;;
 			amigaos | amigados)
 				basic_machine=m68k-unknown
-				os=amigaos
+				basic_os=amigaos
 				;;
 			amigaunix | amix)
 				basic_machine=m68k-unknown
-				os=sysv4
+				basic_os=sysv4
 				;;
 			apollo68)
 				basic_machine=m68k-apollo
-				os=sysv
+				basic_os=sysv
 				;;
 			apollo68bsd)
 				basic_machine=m68k-apollo
-				os=bsd
+				basic_os=bsd
 				;;
 			aros)
 				basic_machine=i386-pc
-				os=aros
+				basic_os=aros
 				;;
 			aux)
 				basic_machine=m68k-apple
-				os=aux
+				basic_os=aux
 				;;
 			balance)
 				basic_machine=ns32k-sequent
-				os=dynix
+				basic_os=dynix
 				;;
 			blackfin)
 				basic_machine=bfin-unknown
-				os=linux
+				basic_os=linux
 				;;
 			cegcc)
 				basic_machine=arm-unknown
-				os=cegcc
+				basic_os=cegcc
 				;;
 			convex-c1)
 				basic_machine=c1-convex
-				os=bsd
+				basic_os=bsd
 				;;
 			convex-c2)
 				basic_machine=c2-convex
-				os=bsd
+				basic_os=bsd
 				;;
 			convex-c32)
 				basic_machine=c32-convex
-				os=bsd
+				basic_os=bsd
 				;;
 			convex-c34)
 				basic_machine=c34-convex
-				os=bsd
+				basic_os=bsd
 				;;
 			convex-c38)
 				basic_machine=c38-convex
-				os=bsd
+				basic_os=bsd
 				;;
 			cray)
 				basic_machine=j90-cray
-				os=unicos
+				basic_os=unicos
 				;;
 			crds | unos)
 				basic_machine=m68k-crds
-				os=
+				basic_os=
 				;;
 			da30)
 				basic_machine=m68k-da30
-				os=
+				basic_os=
 				;;
 			decstation | pmax | pmin | dec3100 | decstatn)
 				basic_machine=mips-dec
-				os=
+				basic_os=
 				;;
 			delta88)
 				basic_machine=m88k-motorola
-				os=sysv3
+				basic_os=sysv3
 				;;
 			dicos)
 				basic_machine=i686-pc
-				os=dicos
+				basic_os=dicos
 				;;
 			djgpp)
 				basic_machine=i586-pc
-				os=msdosdjgpp
+				basic_os=msdosdjgpp
 				;;
 			ebmon29k)
 				basic_machine=a29k-amd
-				os=ebmon
+				basic_os=ebmon
 				;;
 			es1800 | OSE68k | ose68k | ose | OSE)
 				basic_machine=m68k-ericsson
-				os=ose
+				basic_os=ose
 				;;
 			gmicro)
 				basic_machine=tron-gmicro
-				os=sysv
+				basic_os=sysv
 				;;
 			go32)
 				basic_machine=i386-pc
-				os=go32
+				basic_os=go32
 				;;
 			h8300hms)
 				basic_machine=h8300-hitachi
-				os=hms
+				basic_os=hms
 				;;
 			h8300xray)
 				basic_machine=h8300-hitachi
-				os=xray
+				basic_os=xray
 				;;
 			h8500hms)
 				basic_machine=h8500-hitachi
-				os=hms
+				basic_os=hms
 				;;
 			harris)
 				basic_machine=m88k-harris
-				os=sysv3
+				basic_os=sysv3
 				;;
 			hp300 | hp300hpux)
 				basic_machine=m68k-hp
-				os=hpux
+				basic_os=hpux
 				;;
 			hp300bsd)
 				basic_machine=m68k-hp
-				os=bsd
+				basic_os=bsd
 				;;
 			hppaosf)
 				basic_machine=hppa1.1-hp
-				os=osf
+				basic_os=osf
 				;;
 			hppro)
 				basic_machine=hppa1.1-hp
-				os=proelf
+				basic_os=proelf
 				;;
 			i386mach)
 				basic_machine=i386-mach
-				os=mach
+				basic_os=mach
 				;;
 			isi68 | isi)
 				basic_machine=m68k-isi
-				os=sysv
+				basic_os=sysv
 				;;
 			m68knommu)
 				basic_machine=m68k-unknown
-				os=linux
+				basic_os=linux
 				;;
 			magnum | m3230)
 				basic_machine=mips-mips
-				os=sysv
+				basic_os=sysv
 				;;
 			merlin)
 				basic_machine=ns32k-utek
-				os=sysv
+				basic_os=sysv
 				;;
 			mingw64)
 				basic_machine=x86_64-pc
-				os=mingw64
+				basic_os=mingw64
 				;;
 			mingw32)
 				basic_machine=i686-pc
-				os=mingw32
+				basic_os=mingw32
 				;;
 			mingw32ce)
 				basic_machine=arm-unknown
-				os=mingw32ce
+				basic_os=mingw32ce
 				;;
 			monitor)
 				basic_machine=m68k-rom68k
-				os=coff
+				basic_os=coff
 				;;
 			morphos)
 				basic_machine=powerpc-unknown
-				os=morphos
+				basic_os=morphos
 				;;
 			moxiebox)
 				basic_machine=moxie-unknown
-				os=moxiebox
+				basic_os=moxiebox
 				;;
 			msdos)
 				basic_machine=i386-pc
-				os=msdos
+				basic_os=msdos
 				;;
 			msys)
 				basic_machine=i686-pc
-				os=msys
+				basic_os=msys
 				;;
 			mvs)
 				basic_machine=i370-ibm
-				os=mvs
+				basic_os=mvs
 				;;
 			nacl)
 				basic_machine=le32-unknown
-				os=nacl
+				basic_os=nacl
 				;;
 			ncr3000)
 				basic_machine=i486-ncr
-				os=sysv4
+				basic_os=sysv4
 				;;
 			netbsd386)
 				basic_machine=i386-pc
-				os=netbsd
+				basic_os=netbsd
 				;;
 			netwinder)
 				basic_machine=armv4l-rebel
-				os=linux
+				basic_os=linux
 				;;
 			news | news700 | news800 | news900)
 				basic_machine=m68k-sony
-				os=newsos
+				basic_os=newsos
 				;;
 			news1000)
 				basic_machine=m68030-sony
-				os=newsos
+				basic_os=newsos
 				;;
 			necv70)
 				basic_machine=v70-nec
-				os=sysv
+				basic_os=sysv
 				;;
 			nh3000)
 				basic_machine=m68k-harris
-				os=cxux
+				basic_os=cxux
 				;;
 			nh[45]000)
 				basic_machine=m88k-harris
-				os=cxux
+				basic_os=cxux
 				;;
 			nindy960)
 				basic_machine=i960-intel
-				os=nindy
+				basic_os=nindy
 				;;
 			mon960)
 				basic_machine=i960-intel
-				os=mon960
+				basic_os=mon960
 				;;
 			nonstopux)
 				basic_machine=mips-compaq
-				os=nonstopux
+				basic_os=nonstopux
 				;;
 			os400)
 				basic_machine=powerpc-ibm
-				os=os400
+				basic_os=os400
 				;;
 			OSE68000 | ose68000)
 				basic_machine=m68000-ericsson
-				os=ose
+				basic_os=ose
 				;;
 			os68k)
 				basic_machine=m68k-none
-				os=os68k
+				basic_os=os68k
 				;;
 			paragon)
 				basic_machine=i860-intel
-				os=osf
+				basic_os=osf
 				;;
 			parisc)
 				basic_machine=hppa-unknown
-				os=linux
+				basic_os=linux
+				;;
+			psp)
+				basic_machine=mipsallegrexel-sony
+				basic_os=psp
 				;;
 			pw32)
 				basic_machine=i586-unknown
-				os=pw32
+				basic_os=pw32
 				;;
 			rdos | rdos64)
 				basic_machine=x86_64-pc
-				os=rdos
+				basic_os=rdos
 				;;
 			rdos32)
 				basic_machine=i386-pc
-				os=rdos
+				basic_os=rdos
 				;;
 			rom68k)
 				basic_machine=m68k-rom68k
-				os=coff
+				basic_os=coff
 				;;
 			sa29200)
 				basic_machine=a29k-amd
-				os=udi
+				basic_os=udi
 				;;
 			sei)
 				basic_machine=mips-sei
-				os=seiux
+				basic_os=seiux
 				;;
 			sequent)
 				basic_machine=i386-sequent
-				os=
+				basic_os=
 				;;
 			sps7)
 				basic_machine=m68k-bull
-				os=sysv2
+				basic_os=sysv2
 				;;
 			st2000)
 				basic_machine=m68k-tandem
-				os=
+				basic_os=
 				;;
 			stratus)
 				basic_machine=i860-stratus
-				os=sysv4
+				basic_os=sysv4
 				;;
 			sun2)
 				basic_machine=m68000-sun
-				os=
+				basic_os=
 				;;
 			sun2os3)
 				basic_machine=m68000-sun
-				os=sunos3
+				basic_os=sunos3
 				;;
 			sun2os4)
 				basic_machine=m68000-sun
-				os=sunos4
+				basic_os=sunos4
 				;;
 			sun3)
 				basic_machine=m68k-sun
-				os=
+				basic_os=
 				;;
 			sun3os3)
 				basic_machine=m68k-sun
-				os=sunos3
+				basic_os=sunos3
 				;;
 			sun3os4)
 				basic_machine=m68k-sun
-				os=sunos4
+				basic_os=sunos4
 				;;
 			sun4)
 				basic_machine=sparc-sun
-				os=
+				basic_os=
 				;;
 			sun4os3)
 				basic_machine=sparc-sun
-				os=sunos3
+				basic_os=sunos3
 				;;
 			sun4os4)
 				basic_machine=sparc-sun
-				os=sunos4
+				basic_os=sunos4
 				;;
 			sun4sol2)
 				basic_machine=sparc-sun
-				os=solaris2
+				basic_os=solaris2
 				;;
 			sun386 | sun386i | roadrunner)
 				basic_machine=i386-sun
-				os=
+				basic_os=
 				;;
 			sv1)
 				basic_machine=sv1-cray
-				os=unicos
+				basic_os=unicos
 				;;
 			symmetry)
 				basic_machine=i386-sequent
-				os=dynix
+				basic_os=dynix
 				;;
 			t3e)
 				basic_machine=alphaev5-cray
-				os=unicos
+				basic_os=unicos
 				;;
 			t90)
 				basic_machine=t90-cray
-				os=unicos
+				basic_os=unicos
 				;;
 			toad1)
 				basic_machine=pdp10-xkl
-				os=tops20
+				basic_os=tops20
 				;;
 			tpf)
 				basic_machine=s390x-ibm
-				os=tpf
+				basic_os=tpf
 				;;
 			udi29k)
 				basic_machine=a29k-amd
-				os=udi
+				basic_os=udi
 				;;
 			ultra3)
 				basic_machine=a29k-nyu
-				os=sym1
+				basic_os=sym1
 				;;
 			v810 | necv810)
 				basic_machine=v810-nec
-				os=none
+				basic_os=none
 				;;
 			vaxv)
 				basic_machine=vax-dec
-				os=sysv
+				basic_os=sysv
 				;;
 			vms)
 				basic_machine=vax-dec
-				os=vms
+				basic_os=vms
 				;;
 			vsta)
 				basic_machine=i386-pc
-				os=vsta
+				basic_os=vsta
 				;;
 			vxworks960)
 				basic_machine=i960-wrs
-				os=vxworks
+				basic_os=vxworks
 				;;
 			vxworks68)
 				basic_machine=m68k-wrs
-				os=vxworks
+				basic_os=vxworks
 				;;
 			vxworks29k)
 				basic_machine=a29k-wrs
-				os=vxworks
+				basic_os=vxworks
 				;;
 			xbox)
 				basic_machine=i686-pc
-				os=mingw32
+				basic_os=mingw32
 				;;
 			ymp)
 				basic_machine=ymp-cray
-				os=unicos
+				basic_os=unicos
 				;;
 			*)
 				basic_machine=$1
-				os=
+				basic_os=
 				;;
 		esac
 		;;
@@ -683,17 +686,17 @@
 	bluegene*)
 		cpu=powerpc
 		vendor=ibm
-		os=cnk
+		basic_os=cnk
 		;;
 	decsystem10* | dec10*)
 		cpu=pdp10
 		vendor=dec
-		os=tops10
+		basic_os=tops10
 		;;
 	decsystem20* | dec20*)
 		cpu=pdp10
 		vendor=dec
-		os=tops20
+		basic_os=tops20
 		;;
 	delta | 3300 | motorola-3300 | motorola-delta \
 	      | 3300-motorola | delta-motorola)
@@ -703,7 +706,7 @@
 	dpx2*)
 		cpu=m68k
 		vendor=bull
-		os=sysv3
+		basic_os=sysv3
 		;;
 	encore | umax | mmax)
 		cpu=ns32k
@@ -712,7 +715,7 @@
 	elxsi)
 		cpu=elxsi
 		vendor=elxsi
-		os=${os:-bsd}
+		basic_os=${basic_os:-bsd}
 		;;
 	fx2800)
 		cpu=i860
@@ -725,7 +728,7 @@
 	h3050r* | hiux*)
 		cpu=hppa1.1
 		vendor=hitachi
-		os=hiuxwe2
+		basic_os=hiuxwe2
 		;;
 	hp3k9[0-9][0-9] | hp9[0-9][0-9])
 		cpu=hppa1.0
@@ -768,36 +771,36 @@
 	i*86v32)
 		cpu=`echo "$1" | sed -e 's/86.*/86/'`
 		vendor=pc
-		os=sysv32
+		basic_os=sysv32
 		;;
 	i*86v4*)
 		cpu=`echo "$1" | sed -e 's/86.*/86/'`
 		vendor=pc
-		os=sysv4
+		basic_os=sysv4
 		;;
 	i*86v)
 		cpu=`echo "$1" | sed -e 's/86.*/86/'`
 		vendor=pc
-		os=sysv
+		basic_os=sysv
 		;;
 	i*86sol2)
 		cpu=`echo "$1" | sed -e 's/86.*/86/'`
 		vendor=pc
-		os=solaris2
+		basic_os=solaris2
 		;;
 	j90 | j90-cray)
 		cpu=j90
 		vendor=cray
-		os=${os:-unicos}
+		basic_os=${basic_os:-unicos}
 		;;
 	iris | iris4d)
 		cpu=mips
 		vendor=sgi
-		case $os in
+		case $basic_os in
 		    irix*)
 			;;
 		    *)
-			os=irix4
+			basic_os=irix4
 			;;
 		esac
 		;;
@@ -808,26 +811,26 @@
 	*mint | mint[0-9]* | *MiNT | *MiNT[0-9]*)
 		cpu=m68k
 		vendor=atari
-		os=mint
+		basic_os=mint
 		;;
 	news-3600 | risc-news)
 		cpu=mips
 		vendor=sony
-		os=newsos
+		basic_os=newsos
 		;;
 	next | m*-next)
 		cpu=m68k
 		vendor=next
-		case $os in
+		case $basic_os in
 		    openstep*)
 		        ;;
 		    nextstep*)
 			;;
 		    ns2*)
-		      os=nextstep2
+		      basic_os=nextstep2
 			;;
 		    *)
-		      os=nextstep3
+		      basic_os=nextstep3
 			;;
 		esac
 		;;
@@ -838,12 +841,12 @@
 	op50n-* | op60c-*)
 		cpu=hppa1.1
 		vendor=oki
-		os=proelf
+		basic_os=proelf
 		;;
 	pa-hitachi)
 		cpu=hppa1.1
 		vendor=hitachi
-		os=hiuxwe2
+		basic_os=hiuxwe2
 		;;
 	pbd)
 		cpu=sparc
@@ -880,12 +883,12 @@
 	sde)
 		cpu=mipsisa32
 		vendor=sde
-		os=${os:-elf}
+		basic_os=${basic_os:-elf}
 		;;
 	simso-wrs)
 		cpu=sparclite
 		vendor=wrs
-		os=vxworks
+		basic_os=vxworks
 		;;
 	tower | tower-32)
 		cpu=m68k
@@ -902,7 +905,7 @@
 	w89k-*)
 		cpu=hppa1.1
 		vendor=winbond
-		os=proelf
+		basic_os=proelf
 		;;
 	none)
 		cpu=none
@@ -955,11 +958,11 @@
 	# some cases the only manufacturer, in others, it is the most popular.
 	craynv-unknown)
 		vendor=cray
-		os=${os:-unicosmp}
+		basic_os=${basic_os:-unicosmp}
 		;;
 	c90-unknown | c90-cray)
 		vendor=cray
-		os=${os:-unicos}
+		basic_os=${Basic_os:-unicos}
 		;;
 	fx80-unknown)
 		vendor=alliant
@@ -1003,7 +1006,7 @@
 	dpx20-unknown | dpx20-bull)
 		cpu=rs6000
 		vendor=bull
-		os=${os:-bosx}
+		basic_os=${basic_os:-bosx}
 		;;
 
 	# Here we normalize CPU types irrespective of the vendor
@@ -1012,7 +1015,7 @@
 		;;
 	blackfin-*)
 		cpu=bfin
-		os=linux
+		basic_os=linux
 		;;
 	c54x-*)
 		cpu=tic54x
@@ -1025,7 +1028,7 @@
 		;;
 	e500v[12]-*)
 		cpu=powerpc
-		os=$os"spe"
+		basic_os=${basic_os}"spe"
 		;;
 	mips3*-*)
 		cpu=mips64
@@ -1035,7 +1038,7 @@
 		;;
 	m68knommu-*)
 		cpu=m68k
-		os=linux
+		basic_os=linux
 		;;
 	m9s12z-* | m68hcs12z-* | hcs12z-* | s12z-*)
 		cpu=s12z
@@ -1045,7 +1048,7 @@
 		;;
 	parisc-*)
 		cpu=hppa
-		os=linux
+		basic_os=linux
 		;;
 	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
 		cpu=i586
@@ -1101,11 +1104,14 @@
 	xscale-* | xscalee[bl]-*)
 		cpu=`echo "$cpu" | sed 's/^xscale/arm/'`
 		;;
+	arm64-*)
+		cpu=aarch64
+		;;
 
 	# Recognize the canonical CPU Types that limit and/or modify the
 	# company names they are paired with.
 	cr16-*)
-		os=${os:-elf}
+		basic_os=${basic_os:-elf}
 		;;
 	crisv32-* | etraxfs*-*)
 		cpu=crisv32
@@ -1116,7 +1122,7 @@
 		vendor=axis
 		;;
 	crx-*)
-		os=${os:-elf}
+		basic_os=${basic_os:-elf}
 		;;
 	neo-tandem)
 		cpu=neo
@@ -1138,16 +1144,12 @@
 		cpu=nsx
 		vendor=tandem
 		;;
-	s390-*)
-		cpu=s390
-		vendor=ibm
-		;;
-	s390x-*)
-		cpu=s390x
-		vendor=ibm
+	mipsallegrexel-sony)
+		cpu=mipsallegrexel
+		vendor=sony
 		;;
 	tile*-*)
-		os=${os:-linux-gnu}
+		basic_os=${basic_os:-linux-gnu}
 		;;
 
 	*)
@@ -1164,7 +1166,7 @@
 			| am33_2.0 \
 			| amdgcn \
 			| arc | arceb \
-			| arm  | arm[lb]e | arme[lb] | armv* \
+			| arm | arm[lb]e | arme[lb] | armv* \
 			| avr | avr32 \
 			| asmjs \
 			| ba \
@@ -1229,6 +1231,7 @@
 			| pyramid \
 			| riscv | riscv32 | riscv64 \
 			| rl78 | romp | rs6000 | rx \
+			| s390 | s390x \
 			| score \
 			| sh | shl \
 			| sh[1234] | sh[24]a | sh[24]ae[lb] | sh[23]e | she[lb] | sh[lb]e \
@@ -1275,8 +1278,43 @@
 
 # Decode manufacturer-specific aliases for certain operating systems.
 
-if [ x$os != x ]
+if [ x$basic_os != x ]
 then
+
+# First recognize some ad-hoc caes, or perhaps split kernel-os, or else just
+# set os.
+case $basic_os in
+	gnu/linux*)
+		kernel=linux
+		os=`echo $basic_os | sed -e 's|gnu/linux|gnu|'`
+		;;
+	nto-qnx*)
+		kernel=nto
+		os=`echo $basic_os | sed -e 's|nto-qnx|qnx|'`
+		;;
+	*-*)
+		# shellcheck disable=SC2162
+		IFS="-" read kernel os <<EOF
+$basic_os
+EOF
+		;;
+	# Default OS when just kernel was specified
+	nto*)
+		kernel=nto
+		os=`echo $basic_os | sed -e 's|nto|qnx|'`
+		;;
+	linux*)
+		kernel=linux
+		os=`echo $basic_os | sed -e 's|linux|gnu|'`
+		;;
+	*)
+		kernel=
+		os=$basic_os
+		;;
+esac
+
+# Now, normalize the OS (knowing we just have one component, it's not a kernel,
+# etc.)
 case $os in
 	# First match some system type aliases that might get confused
 	# with valid system types.
@@ -1296,9 +1334,6 @@
 	unixware*)
 		os=sysv4.2uw
 		;;
-	gnu/linux*)
-		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
-		;;
 	# es1800 is here to avoid being matched by es* (a different OS)
 	es1800*)
 		os=ose
@@ -1322,10 +1357,7 @@
 	sco3.2.[4-9]*)
 		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
 		;;
-	sco3.2v[4-9]* | sco5v6*)
-		# Don't forget version if it is 3.2v4 or newer.
-		;;
-	scout)
+	sco*v* | scout)
 		# Don't match below
 		;;
 	sco*)
@@ -1334,41 +1366,6 @@
 	psos*)
 		os=psos
 		;;
-	# Now accept the basic system types.
-	# The portable systems comes first.
-	# 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* | esix* | aix* | cnk* | sunos | sunos[34]*\
-	     | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \
-	     | sym* | kopensolaris* | plan9* \
-	     | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \
-	     | aos* | aros* | cloudabi* | sortix* | twizzler* \
-	     | nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \
-	     | clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \
-	     | knetbsd* | mirbsd* | netbsd* \
-	     | bitrig* | openbsd* | solidbsd* | libertybsd* | os108* \
-	     | ekkobsd* | kfreebsd* | freebsd* | riscix* | lynxos* \
-	     | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \
-	     | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \
-	     | udi* | eabi* | lites* | ieee* | go32* | aux* | hcos* \
-	     | chorusrdb* | cegcc* | glidix* \
-	     | cygwin* | msys* | pe* | moss* | proelf* | rtems* \
-	     | midipix* | mingw32* | mingw64* | linux-gnu* | linux-android* \
-	     | linux-newlib* | linux-musl* | linux-uclibc* \
-	     | uxpv* | beos* | mpeix* | udk* | moxiebox* \
-	     | interix* | uwin* | mks* | rhapsody* | darwin* \
-	     | openstep* | oskit* | conix* | pw32* | nonstopux* \
-	     | storm-chaos* | tops10* | tenex* | tops20* | its* \
-	     | os2* | vos* | palmos* | uclinux* | nucleus* \
-	     | morphos* | superux* | rtmk* | windiss* \
-	     | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \
-	     | skyos* | haiku* | rdos* | toppers* | drops* | es* \
-	     | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
-	     | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
-	     | nsk* | powerunix)
-	# Remember, each alternative MUST END IN *, to match a version number.
-		;;
 	qnx*)
 		case $cpu in
 		    x86 | i*86)
@@ -1381,31 +1378,19 @@
 	hiux*)
 		os=hiuxwe2
 		;;
-	nto-qnx*)
-		;;
-	nto*)
-		os=`echo $os | sed -e 's|nto|nto-qnx|'`
-		;;
-	sim | xray | os68k* | v88r* \
-	    | windows* | osx | abug | netware* | os9* \
-	    | macos* | mpw* | magic* | mmixware* | mon960* | lnews*)
-		;;
-	linux-dietlibc)
-		os=linux-dietlibc
-		;;
-	linux*)
-		os=`echo $os | sed -e 's|linux|linux-gnu|'`
-		;;
 	lynx*178)
 		os=lynxos178
 		;;
 	lynx*5)
 		os=lynxos5
 		;;
+	lynxos*)
+		# don't get caught up in next wildcard
+		;;
 	lynx*)
 		os=lynxos
 		;;
-	mac*)
+	mac[0-9]*)
 		os=`echo "$os" | sed -e 's|mac|macos|'`
 		;;
 	opened*)
@@ -1475,18 +1460,12 @@
 	sysvr4)
 		os=sysv4
 		;;
-	# This must come after sysvr4.
-	sysv*)
-		;;
 	ose*)
 		os=ose
 		;;
 	*mint | mint[0-9]* | *MiNT | MiNT[0-9]*)
 		os=mint
 		;;
-	zvmoe)
-		os=zvmoe
-		;;
 	dicos*)
 		os=dicos
 		;;
@@ -1503,19 +1482,11 @@
 			;;
 		esac
 		;;
-	nacl*)
-		;;
-	ios)
-		;;
-	none)
-		;;
-	*-eabi)
-		;;
 	*)
-		echo Invalid configuration \`"$1"\': system \`"$os"\' not recognized 1>&2
-		exit 1
+		# No normalization, but not necessarily accepted, that comes below.
 		;;
 esac
+
 else
 
 # Here we handle the default operating systems that come with various machines.
@@ -1528,6 +1499,7 @@
 # will signal an error saying that MANUFACTURER isn't an operating
 # system, and we'll never get to this point.
 
+kernel=
 case $cpu-$vendor in
 	score-*)
 		os=elf
@@ -1539,7 +1511,8 @@
 		os=riscix1.2
 		;;
 	arm*-rebel)
-		os=linux
+		kernel=linux
+		os=gnu
 		;;
 	arm*-semi)
 		os=aout
@@ -1705,84 +1678,169 @@
 		os=none
 		;;
 esac
+
 fi
 
+# Now, validate our (potentially fixed-up) OS.
+case $os in
+	# Sometimes we do "kernel-abi", so those need to count as OSes.
+	musl* | newlib* | uclibc*)
+		;;
+	# Likewise for "kernel-libc"
+	eabi | eabihf | gnueabi | gnueabihf)
+		;;
+	# Now accept the basic system types.
+	# The portable systems comes first.
+	# Each alternative MUST end in a * to match a version number.
+	gnu* | android* | bsd* | mach* | minix* | genix* | ultrix* | irix* \
+	     | *vms* | esix* | aix* | cnk* | sunos | sunos[34]* \
+	     | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \
+	     | sym* |  plan9* | psp* | sim* | xray* | os68k* | v88r* \
+	     | hiux* | abug | nacl* | netware* | windows* \
+	     | os9* | macos* | osx* | ios* \
+	     | mpw* | magic* | mmixware* | mon960* | lnews* \
+	     | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \
+	     | aos* | aros* | cloudabi* | sortix* | twizzler* \
+	     | nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \
+	     | clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \
+	     | mirbsd* | netbsd* | dicos* | openedition* | ose* \
+	     | bitrig* | openbsd* | solidbsd* | libertybsd* | os108* \
+	     | ekkobsd* | freebsd* | riscix* | lynxos* | os400* \
+	     | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \
+	     | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \
+	     | udi* | lites* | ieee* | go32* | aux* | hcos* \
+	     | chorusrdb* | cegcc* | glidix* \
+	     | cygwin* | msys* | pe* | moss* | proelf* | rtems* \
+	     | midipix* | mingw32* | mingw64* | mint* \
+	     | uxpv* | beos* | mpeix* | udk* | moxiebox* \
+	     | interix* | uwin* | mks* | rhapsody* | darwin* \
+	     | openstep* | oskit* | conix* | pw32* | nonstopux* \
+	     | storm-chaos* | tops10* | tenex* | tops20* | its* \
+	     | os2* | vos* | palmos* | uclinux* | nucleus* | morphos* \
+	     | scout* | superux* | sysv* | rtmk* | tpf* | windiss* \
+	     | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \
+	     | skyos* | haiku* | rdos* | toppers* | drops* | es* \
+	     | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
+	     | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
+	     | nsk* | powerunix* | genode* | zvmoe* )
+		;;
+	# This one is extra strict with allowed versions
+	sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
+		# Don't forget version if it is 3.2v4 or newer.
+		;;
+	none)
+		;;
+	*)
+		echo Invalid configuration \`"$1"\': OS \`"$os"\' not recognized 1>&2
+		exit 1
+		;;
+esac
+
+# As a final step for OS-related things, validate the OS-kernel combination
+# (given a valid OS), if there is a kernel.
+case $kernel-$os in
+	linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* | linux-musl* | linux-uclibc* )
+		;;
+	-dietlibc* | -newlib* | -musl* | -uclibc* )
+		# These are just libc implementations, not actual OSes, and thus
+		# require a kernel.
+		echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2
+		exit 1
+		;;
+	kfreebsd*-gnu* | kopensolaris*-gnu*)
+		;;
+	nto-qnx*)
+		;;
+	*-eabi* | *-gnueabi*)
+		;;
+	-*)
+		# Blank kernel with real OS is always fine.
+		;;
+	*-*)
+		echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2
+		exit 1
+		;;
+esac
+
 # Here we handle the case where we know the os, and the CPU type, but not the
 # manufacturer.  We pick the logical manufacturer.
 case $vendor in
 	unknown)
-		case $os in
-			riscix*)
+		case $cpu-$os in
+			*-riscix*)
 				vendor=acorn
 				;;
-			sunos*)
+			*-sunos*)
 				vendor=sun
 				;;
-			cnk*|-aix*)
+			*-cnk* | *-aix*)
 				vendor=ibm
 				;;
-			beos*)
+			*-beos*)
 				vendor=be
 				;;
-			hpux*)
+			*-hpux*)
 				vendor=hp
 				;;
-			mpeix*)
+			*-mpeix*)
 				vendor=hp
 				;;
-			hiux*)
+			*-hiux*)
 				vendor=hitachi
 				;;
-			unos*)
+			*-unos*)
 				vendor=crds
 				;;
-			dgux*)
+			*-dgux*)
 				vendor=dg
 				;;
-			luna*)
+			*-luna*)
 				vendor=omron
 				;;
-			genix*)
+			*-genix*)
 				vendor=ns
 				;;
-			clix*)
+			*-clix*)
 				vendor=intergraph
 				;;
-			mvs* | opened*)
+			*-mvs* | *-opened*)
+				vendor=ibm
+				;;
+			*-os400*)
 				vendor=ibm
 				;;
-			os400*)
+			s390-* | s390x-*)
 				vendor=ibm
 				;;
-			ptx*)
+			*-ptx*)
 				vendor=sequent
 				;;
-			tpf*)
+			*-tpf*)
 				vendor=ibm
 				;;
-			vxsim* | vxworks* | windiss*)
+			*-vxsim* | *-vxworks* | *-windiss*)
 				vendor=wrs
 				;;
-			aux*)
+			*-aux*)
 				vendor=apple
 				;;
-			hms*)
+			*-hms*)
 				vendor=hitachi
 				;;
-			mpw* | macos*)
+			*-mpw* | *-macos*)
 				vendor=apple
 				;;
-			*mint | mint[0-9]* | *MiNT | MiNT[0-9]*)
+			*-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*)
 				vendor=atari
 				;;
-			vos*)
+			*-vos*)
 				vendor=stratus
 				;;
 		esac
 		;;
 esac
 
-echo "$cpu-$vendor-$os"
+echo "$cpu-$vendor-${kernel:+$kernel-}$os"
 exit
 
 # Local variables:
Index: configure
--- xterm-358+/configure	2020-06-03 00:20:07.000000000 +0000
+++ xterm-359/configure	2020-08-02 21:29:21.000000000 +0000
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by Autoconf 2.52.20200111.
+# Generated by Autoconf 2.52.20200802.
 #
 # Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
 # Free Software Foundation, Inc.
@@ -803,7 +803,7 @@
   --enable-dec-locator    enable DECterm Locator support
   --disable-screen-dumps  disable XHTML and SVG screen dumps
   --enable-regis-graphics enable ReGIS graphics support
-  --enable-sixel-graphics enable sixel graphics support
+  --disable-sixel-graphics disable sixel graphics support
   --disable-rectangles    disable VT420 rectangle support
   --disable-ziconbeep     disable -ziconbeep option
 Testing/development Options:
@@ -885,7 +885,7 @@
 running configure, to aid debugging if configure makes a mistake.
 
 It was created by $as_me, which was
-generated by GNU Autoconf 2.52.20200111.  Invocation command line was
+generated by GNU Autoconf 2.52.20200802.  Invocation command line was
 
   $ $0 $@
 
@@ -20825,7 +20825,7 @@
 cf_regex_libs="regex re"
 case $host_os in
 (mingw*)
-	cf_regex_libs="gnurx $cf_regex_libs"
+	cf_regex_libs="systre gnurx $cf_regex_libs"
 	;;
 esac
 
@@ -21915,15 +21915,15 @@
 # Check whether --enable-sixel-graphics or --disable-sixel-graphics was given.
 if test "${enable_sixel_graphics+set}" = set; then
   enableval="$enable_sixel_graphics"
-  test "$enableval" != yes && enableval=no
-	if test "$enableval" != "no" ; then
-    enable_sixel_graphics=yes
+  test "$enableval" != no && enableval=yes
+	if test "$enableval" != "yes" ; then
+    enable_sixel_graphics=no
 	else
-		enable_sixel_graphics=no
+		enable_sixel_graphics=yes
 	fi
 else
-  enableval=no
-	enable_sixel_graphics=no
+  enableval=yes
+	enable_sixel_graphics=yes
 
 fi;
 echo "$as_me:21929: result: $enable_sixel_graphics" >&5
@@ -23928,6 +23928,8 @@
 SHELL=\${CONFIG_SHELL-$SHELL}
 ac_cs_invocation="\$0 \$@"
 
+CLICOLOR_FORCE= GREP_OPTIONS=
+unset CLICOLOR_FORCE GREP_OPTIONS
 _ACEOF
 
 cat >>$CONFIG_STATUS <<\_ACEOF
@@ -24044,7 +24046,7 @@
 cat >>$CONFIG_STATUS <<EOF
 ac_cs_version="\\
 config.status
-configured by $0, generated by GNU Autoconf 2.52.20200111,
+configured by $0, generated by GNU Autoconf 2.52.20200802,
   with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
 
 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
@@ -24088,7 +24090,7 @@
     echo "$ac_cs_version"; exit 0 ;;
   --he | --h)
     # Conflict between --help and --header
-    { { echo "$as_me:24091: error: ambiguous option: $1
+    { { echo "$as_me:24093: error: ambiguous option: $1
 Try \`$0 --help' for more information." >&5
 echo "$as_me: error: ambiguous option: $1
 Try \`$0 --help' for more information." >&2;}
@@ -24107,7 +24109,7 @@
     ac_need_defaults=false;;
 
   # This is an error.
-  -*) { { echo "$as_me:24110: error: unrecognized option: $1
+  -*) { { echo "$as_me:24112: error: unrecognized option: $1
 Try \`$0 --help' for more information." >&5
 echo "$as_me: error: unrecognized option: $1
 Try \`$0 --help' for more information." >&2;}
@@ -24126,7 +24128,7 @@
 ## Running config.status.  ##
 ## ----------------------- ##
 
-This file was extended by $as_me 2.52.20200111, executed with
+This file was extended by $as_me 2.52.20200802, executed with
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
   CONFIG_LINKS    = $CONFIG_LINKS
@@ -24146,7 +24148,7 @@
   "df-install" ) CONFIG_FILES="$CONFIG_FILES df-install" ;;
   "minstall" ) CONFIG_FILES="$CONFIG_FILES minstall:minstall.in" ;;
   "xtermcfg.h" ) CONFIG_HEADERS="$CONFIG_HEADERS xtermcfg.h:xtermcfg.hin" ;;
-  *) { { echo "$as_me:24149: error: invalid argument: $ac_config_target" >&5
+  *) { { echo "$as_me:24151: error: invalid argument: $ac_config_target" >&5
 echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
    { (exit 1); exit 1; }; };;
   esac
@@ -24459,7 +24461,7 @@
   esac
 
   if test x"$ac_file" != x-; then
-    { echo "$as_me:24462: creating $ac_file" >&5
+    { echo "$as_me:24464: creating $ac_file" >&5
 echo "$as_me: creating $ac_file" >&6;}
     rm -f "$ac_file"
   fi
@@ -24477,7 +24479,7 @@
       -) echo $tmp/stdin ;;
       [\\/$]*)
          # Absolute (can't be DOS-style, as IFS=:)
-         test -f "$f" || { { echo "$as_me:24480: error: cannot find input file: $f" >&5
+         test -f "$f" || { { echo "$as_me:24482: error: cannot find input file: $f" >&5
 echo "$as_me: error: cannot find input file: $f" >&2;}
    { (exit 1); exit 1; }; }
          echo $f;;
@@ -24490,7 +24492,7 @@
            echo $srcdir/$f
          else
            # /dev/null tree
-           { { echo "$as_me:24493: error: cannot find input file: $f" >&5
+           { { echo "$as_me:24495: error: cannot find input file: $f" >&5
 echo "$as_me: error: cannot find input file: $f" >&2;}
    { (exit 1); exit 1; }; }
          fi;;
@@ -24506,7 +24508,7 @@
       if test -n "$ac_seen"; then
         ac_used=`grep '@datarootdir@' $ac_item`
         if test -z "$ac_used"; then
-          { echo "$as_me:24509: WARNING: datarootdir was used implicitly but not set:
+          { echo "$as_me:24511: WARNING: datarootdir was used implicitly but not set:
 $ac_seen" >&5
 echo "$as_me: WARNING: datarootdir was used implicitly but not set:
 $ac_seen" >&2;}
@@ -24515,7 +24517,7 @@
       fi
       ac_seen=`grep '${datarootdir}' $ac_item`
       if test -n "$ac_seen"; then
-        { echo "$as_me:24518: WARNING: datarootdir was used explicitly but not set:
+        { echo "$as_me:24520: WARNING: datarootdir was used explicitly but not set:
 $ac_seen" >&5
 echo "$as_me: WARNING: datarootdir was used explicitly but not set:
 $ac_seen" >&2;}
@@ -24552,7 +24554,7 @@
             ac_init=`egrep '[ 	]*'$ac_name'[ 	]*=' $ac_file`
             if test -z "$ac_init"; then
               ac_seen=`echo "$ac_seen" |sed -e 's,^,'$ac_file':,'`
-              { echo "$as_me:24555: WARNING: Variable $ac_name is used but was not set:
+              { echo "$as_me:24557: WARNING: Variable $ac_name is used but was not set:
 $ac_seen" >&5
 echo "$as_me: WARNING: Variable $ac_name is used but was not set:
 $ac_seen" >&2;}
@@ -24563,7 +24565,7 @@
     egrep -n '@[A-Z_][A-Z_0-9]+@' $ac_file >>$tmp/out
     if test -s $tmp/out; then
       ac_seen=`sed -e 's,^,'$ac_file':,' < $tmp/out`
-      { echo "$as_me:24566: WARNING: Some variables may not be substituted:
+      { echo "$as_me:24568: WARNING: Some variables may not be substituted:
 $ac_seen" >&5
 echo "$as_me: WARNING: Some variables may not be substituted:
 $ac_seen" >&2;}
@@ -24612,7 +24614,7 @@
   * )   ac_file_in=$ac_file.in ;;
   esac
 
-  test x"$ac_file" != x- && { echo "$as_me:24615: creating $ac_file" >&5
+  test x"$ac_file" != x- && { echo "$as_me:24617: creating $ac_file" >&5
 echo "$as_me: creating $ac_file" >&6;}
 
   # First look for the input files in the build tree, otherwise in the
@@ -24623,7 +24625,7 @@
       -) echo $tmp/stdin ;;
       [\\/$]*)
          # Absolute (can't be DOS-style, as IFS=:)
-         test -f "$f" || { { echo "$as_me:24626: error: cannot find input file: $f" >&5
+         test -f "$f" || { { echo "$as_me:24628: error: cannot find input file: $f" >&5
 echo "$as_me: error: cannot find input file: $f" >&2;}
    { (exit 1); exit 1; }; }
          echo $f;;
@@ -24636,7 +24638,7 @@
            echo $srcdir/$f
          else
            # /dev/null tree
-           { { echo "$as_me:24639: error: cannot find input file: $f" >&5
+           { { echo "$as_me:24641: error: cannot find input file: $f" >&5
 echo "$as_me: error: cannot find input file: $f" >&2;}
    { (exit 1); exit 1; }; }
          fi;;
@@ -24754,7 +24756,7 @@
   rm -f $tmp/in
   if test x"$ac_file" != x-; then
     if cmp -s $ac_file $tmp/config.h 2>/dev/null; then
-      { echo "$as_me:24757: $ac_file is unchanged" >&5
+      { echo "$as_me:24759: $ac_file is unchanged" >&5
 echo "$as_me: $ac_file is unchanged" >&6;}
     else
       ac_dir=`$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
Index: configure.in
--- xterm-358+/configure.in	2020-01-11 20:06:47.000000000 +0000
+++ xterm-359/configure.in	2020-07-25 17:52:31.000000000 +0000
@@ -1,4 +1,4 @@
-dnl $XTermId: configure.in,v 1.368 2020/01/11 20:06:47 tom Exp $
+dnl $XTermId: configure.in,v 1.369 2020/07/25 17:52:31 tom Exp $
 dnl
 dnl -----------------------------------------------------------------------------
 dnl this file is part of xterm
@@ -1036,10 +1036,10 @@
 fi
 
 AC_MSG_CHECKING(if you want sixel graphics support)
-CF_ARG_ENABLE(sixel-graphics,
-	[  --enable-sixel-graphics enable sixel graphics support],
-	[enable_sixel_graphics=yes],
-	[enable_sixel_graphics=no])
+CF_ARG_DISABLE(sixel-graphics,
+	[  --disable-sixel-graphics disable sixel graphics support],
+	[enable_sixel_graphics=no],
+	[enable_sixel_graphics=yes])
 AC_MSG_RESULT($enable_sixel_graphics)
 if test "$enable_sixel_graphics" = yes ; then
 	AC_DEFINE(OPT_SIXEL_GRAPHICS,1,[Define to 1 to enable sixel graphics support])
Index: ctlseqs.ms
--- xterm-358+/ctlseqs.ms	2020-07-03 21:14:21.000000000 +0000
+++ xterm-359/ctlseqs.ms	2020-08-03 23:44:47.000000000 +0000
@@ -1,6 +1,6 @@
 .\"#! troff -ms $1		-*- Nroff -*-
 .\" "Xterm Control Sequences" document
-.\" $XTermId: ctlseqs.ms,v 1.592 2020/07/03 21:14:21 tom Exp $
+.\" $XTermId: ctlseqs.ms,v 1.594 2020/08/03 23:44:47 tom Exp $
 .\"
 .\"
 .\" Copyright 1996-2019,2020 by Thomas E. Dickey
@@ -69,8 +69,8 @@
 .\"
 .ds XT XTerm
 .ds xt xterm
-.ds LF Patch #357
-.ds RF 2020/07/03
+.ds LF Patch #359
+.ds RF 2020/08/03
 .\"
 .if n .pl 9999v		\" no page breaks in nroff
 .ND
@@ -1336,6 +1336,7 @@
   \*(Ps = \*1\*0\*1\*1 \(-> Scroll to bottom on key press (rxvt).
 This sets the \fBscrollKey\fP resource to \*(``true\*(''.
   \*(Ps = \*1\*0\*1\*5 \(-> Enable urxvt Mouse Mode.
+  \*(Ps = \*1\*0\*1\*6 \(-> Enable SGR Mouse PixelMode, \fI\*(xt\fP.
   \*(Ps = \*1\*0\*3\*4 \(-> Interpret \*(``meta\*('' key, \fI\*(xt\fP.
 This sets the eighth bit of keyboard input
 (and enables the \fBeightBitInput\fP resource).
@@ -1464,6 +1465,7 @@
   \*(Ps = \*1\*0\*1\*1 \(-> Don't scroll to bottom on key press (rxvt).
 This sets the \fBscrollKey\fP resource to \*(``false\*(''.
   \*(Ps = \*1\*0\*1\*5 \(-> Disable urxvt Mouse Mode.
+  \*(Ps = \*1\*0\*1\*6 \(-> Disable SGR Mouse Pixel-Mode, \fI\*(xt\fP.
   \*(Ps = \*1\*0\*3\*4 \(-> Don't interpret \*(``meta\*('' key, \fI\*(xt\fP.
 This disables the \fBeightBitInput\fP resource.
   \*(Ps = \*1\*0\*3\*5 \(-> Disable special modifiers for
@@ -3146,11 +3148,12 @@
 .sP
 #define SET_FOCUS_EVENT_MOUSE       1004
 .sP
+#define SET_ALTERNATE_SCROLL        1007
+.sP
 #define SET_EXT_MODE_MOUSE          1005
 #define SET_SGR_EXT_MODE_MOUSE      1006
 #define SET_URXVT_EXT_MODE_MOUSE    1015
-.sP
-#define SET_ALTERNATE_SCROLL        1007
+#define SET_PIXEL_POSITION_MOUSE    1016
 .ft 1
 .DE
 .br
@@ -3406,6 +3409,9 @@
 and the Window manipulation controls.
 For these reasons, the 1015 control is not recommended;
 it is not an improvement over 1006.
+.IP "SGR-Pixels (1016)"
+Use the same mouse response format as the 1006 control,
+but report position in \fIpixels\fP rather than character \fIcells\fP.
 .
 .Sh "Sixel Graphics"
 .LP
Index: ctlseqs.txt
--- xterm-358+/ctlseqs.txt	2020-07-03 21:14:57.000000000 +0000
+++ xterm-359/ctlseqs.txt	2020-08-03 23:46:49.000000000 +0000
@@ -21,7 +21,7 @@
                              Thomas Dickey
                       XFree86 Project (1996-2006)
                     invisible-island.net (2006-2020)
-               updated for XTerm Patch #357 (2020/07/03)
+               updated for XTerm Patch #359 (2020/08/03)
 
 
 
@@ -791,6 +791,7 @@
             Ps = 1 0 1 1  -> Scroll to bottom on key press (rxvt).  This
           sets the scrollKey resource to "true".
             Ps = 1 0 1 5  -> Enable urxvt Mouse Mode.
+            Ps = 1 0 1 6  -> Enable SGR Mouse PixelMode, xterm.
             Ps = 1 0 3 4  -> Interpret "meta" key, xterm.  This sets the
           eighth bit of keyboard input (and enables the eightBitInput
           resource).
@@ -914,6 +915,7 @@
             Ps = 1 0 1 1  -> Don't scroll to bottom on key press (rxvt).
           This sets the scrollKey resource to "false".
             Ps = 1 0 1 5  -> Disable urxvt Mouse Mode.
+            Ps = 1 0 1 6  -> Disable SGR Mouse Pixel-Mode, xterm.
             Ps = 1 0 3 4  -> Don't interpret "meta" key, xterm.  This
           disables the eightBitInput resource.
             Ps = 1 0 3 5  -> Disable special modifiers for Alt and Num-
@@ -2305,11 +2307,12 @@
 
      #define SET_FOCUS_EVENT_MOUSE       1004
 
+     #define SET_ALTERNATE_SCROLL        1007
+
      #define SET_EXT_MODE_MOUSE          1005
      #define SET_SGR_EXT_MODE_MOUSE      1006
      #define SET_URXVT_EXT_MODE_MOUSE    1015
-
-     #define SET_ALTERNATE_SCROLL        1007
+     #define SET_PIXEL_POSITION_MOUSE    1016
 
 The motion reporting modes are strictly xterm extensions, and are not
 part of any standard, though they are analogous to the DEC VT200 DECELR
@@ -2553,6 +2556,10 @@
           sons, the 1015 control is not recommended; it is not an
           improvement over 1006.
 
+SGR-Pixels (1016)
+          Use the same mouse response format as the 1006 control, but
+          report position in pixels rather than character cells.
+
 
 Sixel Graphics
 
@@ -3004,12 +3011,12 @@
         be used in termcap for vi, for example, to turn off saving of
         lines, but restore whatever the original state was on exit.
 
-    while the SCOSC/SCORC pair was added in 1995 by XFree86  (and  docu-
+    while  the  SCOSC/SCORC pair was added in 1995 by XFree86 (and docu-
     mented long afterwards).
 
 o   The aixterm manual page gives the format of the control sequence for
-    foreground and background colors 8-15, but  does  not  specify  what
-    those  colors  are.  That is implied by the description's mention of
+    foreground  and  background  colors  8-15, but does not specify what
+    those colors are.  That is implied by the description's  mention  of
     HFT:
 
         The aixterm command provides a standard terminal type for
@@ -3019,7 +3026,7 @@
         the -v flag.
 
     Unlike xterm, there are no resource names for the 16 colors, leaving
-    the  reader  to  assume that the mapping is hard-coded.  The control
-    sequences for colors 8-15 are not specified by ECMA-48,  but  rather
-    (as  done  in  other instances by xterm) chosen to not conflict with
+    the reader to assume that the mapping is  hard-coded.   The  control
+    sequences  for  colors 8-15 are not specified by ECMA-48, but rather
+    (as done in other instances by xterm) chosen to  not  conflict  with
     current or future standards.
Index: df-install.in
--- xterm-358+/df-install.in	2018-04-30 23:29:27.000000000 +0000
+++ xterm-359/df-install.in	2020-08-02 19:47:55.000000000 +0000
@@ -1,9 +1,9 @@
 #!/bin/sh
-# $XTermId: df-install.in,v 1.15 2018/04/30 23:29:27 tom Exp $
+# $XTermId: df-install.in,v 1.16 2020/08/02 19:47:55 tom Exp $
 # -----------------------------------------------------------------------------
 # this file is part of xterm
 #
-# Copyright 2011-2012,2018 by Thomas E. Dickey
+# Copyright 2011-2018,2020 by Thomas E. Dickey
 #
 #                         All Rights Reserved
 #
@@ -37,6 +37,12 @@
 #
 # Parameters are passed to the desktop-file-install program.  The last
 # parameter is the name of the ".desktop" file to install.
+
+failed() {
+	echo "? $*" >&2
+	exit 1
+}
+
 OPTS=
 
 if test $# != 0
@@ -51,6 +57,8 @@
 	shift 1
 fi
 
+TOOL=desktop-file-install
+
 CDPATH=:
 export CDPATH
 
@@ -65,6 +73,12 @@
 			OPTS="$OPTS $1"
 		fi
 		;;
+	.DESTDIR=*) #(vi
+		if test "$1" != "DESTDIR="
+		then
+			DESTDIR=`echo "$1" | sed -e 's,^DESTDIR=,,'`
+		fi
+		;;
 	*)
 		OPTS="$OPTS $1"
 		;;
@@ -72,17 +86,51 @@
 	shift 1
 done
 
+# If DESTDIR is set (either as an environment variable, or command-line
+# parameter), attempt to determine the full pathname (needed by the installer)
+# to tell it to use the alternate location.  Because the installer has no
+# useful options for this purpose, we search along the path to find the tool,
+# and from that get the prefix, and assume that was the extent of customization
+# when the tool was configured/installed.
+if test -n "$DESTDIR"
+then
+	if test -d "$DESTDIR"
+	then
+		prefix=
+
+		save_IFS="$IFS"
+		IFS=':'
+		for P in $PATH
+		do
+			test -z "$P" && P=.
+			if test -f "$P/$TOOL"
+			then
+				prefix=`echo "$P" | sed -e 's,/[^/]*$,,'`
+				break
+			fi
+		done
+		IFS="$save_IFS"
+
+		test -z "$prefix" && failed "could not find $TOOL in PATH"
+
+		TARGET="${DESTDIR}${prefix}/share/applications"
+		mkdir -p "$TARGET"
+
+		OPTS="$OPTS --dir=${TARGET}"
+	else
+		failed "DESTDIR is not a directory: $DESTDIR"
+	fi
+fi
+
 MY_TEMP=tempdir$$
 rm -rf $MY_TEMP
 
 if test -z "$OLD_FILE"
 then
-	echo "? not found: $OLD_FILE"
-	exit 1
+	failed "not found: $OLD_FILE"
 elif ! mkdir $MY_TEMP
 then
-	echo "? cannot mkdir: $MY_TEMP"
-	exit 1
+	failed "cannot mkdir: $MY_TEMP"
 fi
 
 # The newer dfi whines about deprecation of encoding, but no release provides
@@ -94,19 +142,19 @@
 	NO_ENCODING="Encoding"
 fi
 
-NEW_FILE=`basename $OLD_FILE`
+NEW_FILE=`basename "$OLD_FILE"`
 sed \
-	-e '/^Encoding=/s%Encoding%'$NO_ENCODING'%' \
-	-e '/^[^#]*Icon=/s%=.*%='$ICON_NAME'%' \
+	-e '/^Encoding=/s%Encoding%'"$NO_ENCODING"'%' \
+	-e '/^[^#]*Icon=/s%=.*%='"$ICON_NAME"'%' \
 	-e '/^[^#]*Category=/s%=.*%=@DESKTOP_CATEGORY@%' \
 	-e '/^[^#]*Categories=/s%=.*%=@DESKTOP_CATEGORY@%' \
-	-e '/^[^#]/s%xterm%'$APP_NAME'%g' \
+	-e '/^[^#]/s%xterm%'"$APP_NAME"'%g' \
 	-e '/^[^#]/s%XTerm%@APP_CLASS@%g' \
-	$OLD_FILE >$MY_TEMP/$NEW_FILE
-diff -u $OLD_FILE $MY_TEMP/$NEW_FILE
-cd $MY_TEMP
+	"$OLD_FILE" >"$MY_TEMP/$NEW_FILE"
+diff -u "$OLD_FILE" "$MY_TEMP/$NEW_FILE"
+cd $MY_TEMP || exit 1
 
-desktop-file-install $OPTS $NEW_FILE
+"$TOOL" $OPTS "$NEW_FILE"
 
 cd ..
 rm -rf $MY_TEMP
Index: graphics.c
--- xterm-358+/graphics.c	2020-07-03 17:35:06.000000000 +0000
+++ xterm-359/graphics.c	2020-08-06 19:57:58.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: graphics.c,v 1.87 2020/07/03 17:35:06 tom Exp $ */
+/* $XTermId: graphics.c,v 1.90 2020/08/06 19:57:58 tom Exp $ */
 
 /*
  * Copyright 2013-2019,2020 by Ross Combs
@@ -704,7 +704,7 @@
 					    graphic->max_height);
     unsigned i;
 
-    TRACE(("initializing graphic object\n"));
+    TRACE(("init_graphic at %d,%d\n", charrow, charcol));
 
     graphic->hidden = 0;
     graphic->dirty = 1;
@@ -1321,7 +1321,7 @@
     unsigned ii, jj;
     unsigned active_count;
     unsigned holes, non_holes;
-    int xx, yy, nn;
+    int xx, yy;
     ColorRegister *buffer;
 
     active_count = 0;
@@ -1490,7 +1490,7 @@
 	int y_max = draw_y_max - refresh_y;
 	int x_min = draw_x_min - refresh_x;
 	int x_max = draw_x_max - refresh_x;
-	const ColorRegister *base = buffer + y_min;
+	const ColorRegister *base = buffer + (y_min * refresh_w);
 
 	for (yy = y_min; yy <= y_max; yy++) {
 	    const ColorRegister *scan = base + x_min;
@@ -1597,6 +1597,7 @@
 	XImage *image;
 	char *imgdata;
 	unsigned image_w, image_h;
+	int nn;
 
 	memset(&xgcv, 0, sizeof(xgcv));
 	xgcv.graphics_exposures = False;
Index: graphics_regis.c
--- xterm-358+/graphics_regis.c	2020-07-03 17:35:06.000000000 +0000
+++ xterm-359/graphics_regis.c	2020-08-04 00:46:08.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: graphics_regis.c,v 1.120 2020/07/03 17:35:06 tom Exp $ */
+/* $XTermId: graphics_regis.c,v 1.121 2020/08/04 00:46:08 tom Exp $ */
 
 /*
  * Copyright 2014-2019,2020 by Ross Combs
@@ -552,7 +552,7 @@
 }
 
 static void
-draw_filled_polygon(RegisGraphicsContext *context)
+draw_shaded_polygon(RegisGraphicsContext *context)
 {
     unsigned p;
     int old_x, old_y;
@@ -560,18 +560,78 @@
     Char pixels[MAX_GLYPH_PIXELS];
     unsigned w = 1, h = 1;
 
-    if (context->temporary_write_controls.shading_character != '\0') {
-	char ch = context->temporary_write_controls.shading_character;
-	unsigned xmaxf = context->current_text_controls->character_unit_cell_w;
-	unsigned ymaxf = context->current_text_controls->character_unit_cell_h;
+    char ch = context->temporary_write_controls.shading_character;
+    unsigned xmaxf = context->current_text_controls->character_unit_cell_w;
+    unsigned ymaxf = context->current_text_controls->character_unit_cell_h;
 
-	get_bitmap_of_character(context, ch, xmaxf, ymaxf, pixels, &w, &h,
-				MAX_GLYPH_PIXELS);
-	if (w < 1U || h < 1U) {
-	    return;
+    get_bitmap_of_character(context, ch, xmaxf, ymaxf, pixels, &w, &h,
+			    MAX_GLYPH_PIXELS);
+    if (w < 1U || h < 1U) {
+	return;
+    }
+
+    qsort(context->fill_points, (size_t) context->fill_point_count,
+	  sizeof(context->fill_points[0]), sort_points);
+
+    old_x = DUMMY_STACK_X;
+    old_y = DUMMY_STACK_Y;
+    inside = 0;
+    for (p = 0U; p < context->fill_point_count; p++) {
+	int new_x = context->fill_points[p].x;
+	int new_y = context->fill_points[p].y;
+#if 0
+	printf("got %d,%d (%d,%d) inside=%d\n", new_x, new_y, old_x, old_y, inside);
+#endif
+
+	/*
+	 * FIXME: This is using pixels to represent lines which loses
+	 * information about exact slope and how many lines are present which
+	 * causes misbehavior with some inputs (especially complex polygons).
+	 * It also takes more room than remembering vertices, but I'd rather
+	 * not have to implement line segments for arcs.  Maybe store a count
+	 * at each vertex instead (doesn't fix the slope problem).
+	 */
+	/*
+	 * FIXME: Change this to only draw inside of polygons, and round
+	 * points in a uniform direction to avoid overlapping drawing.  As an
+	 * option we could continue to support drawing the outline.
+	 */
+	if (new_y != old_y) {
+	    if (inside) {
+		/*
+		 * Just draw the vertical line when there is not a matching
+		 * edge on the right side.
+		 */
+		shade_char_to_pixel(context, pixels, w, h,
+				    WRITE_SHADING_REF_X,
+				    old_x, old_x, old_y);
+	    }
+	    inside = 1;
+	} else {
+	    if (inside) {
+		shade_char_to_pixel(context, pixels, w, h,
+				    WRITE_SHADING_REF_X,
+				    old_x, new_x, new_y);
+	    }
+	    if (new_x > old_x + 1) {
+		inside = !inside;
+	    }
 	}
+
+	old_x = new_x;
+	old_y = new_y;
     }
 
+    context->destination_graphic->dirty = 1;
+}
+
+static void
+draw_filled_polygon(RegisGraphicsContext *context)
+{
+    unsigned p;
+    int old_x, old_y;
+    int inside;
+
     qsort(context->fill_points, (size_t) context->fill_point_count,
 	  sizeof(context->fill_points[0]), sort_points);
 
@@ -604,26 +664,14 @@
 		 * Just draw the vertical line when there is not a matching
 		 * edge on the right side.
 		 */
-		if (context->temporary_write_controls.shading_character != '\0') {
-		    shade_char_to_pixel(context, pixels, w, h,
-					WRITE_SHADING_REF_X,
-					old_x, old_x, old_y);
-		} else {
-		    shade_pattern_to_pixel(context, WRITE_SHADING_REF_X,
-					   old_x, old_x, old_y);
-		}
+		shade_pattern_to_pixel(context, WRITE_SHADING_REF_X,
+				       old_x, old_x, old_y);
 	    }
 	    inside = 1;
 	} else {
 	    if (inside) {
-		if (context->temporary_write_controls.shading_character != '\0') {
-		    shade_char_to_pixel(context, pixels, w, h,
-					WRITE_SHADING_REF_X,
-					old_x, new_x, new_y);
-		} else {
-		    shade_pattern_to_pixel(context, WRITE_SHADING_REF_X,
-					   old_x, new_x, new_y);
-		}
+		shade_pattern_to_pixel(context, WRITE_SHADING_REF_X,
+				       old_x, new_x, new_y);
 	    }
 	    if (new_x > old_x + 1) {
 		inside = !inside;
@@ -1635,8 +1683,9 @@
 	if (!FcCharSetHasChar(font->charset, ch))
 	    continue;
 
-	copy_bitmap_from_xft_font(display, font, ch, pixels,
-				  workw, workh, 0U, 0U);
+	if (!copy_bitmap_from_xft_font(display, font, ch, pixels,
+				       workw, workh, 0U, 0U))
+	    continue;
 
 	pixel_count = 0U;
 	char_minx = workh - 1U;
@@ -3195,6 +3244,7 @@
     if (!isdigit(CharOf(ch)) &&
 	ch != '+' &&
 	ch != '-') {
+	*out = 0;
 	return 0;
     }
 
@@ -7109,8 +7159,8 @@
 		for (byte = 0U; byte < bytew; byte++) {
 		    glyph[state->load_row * bytew + byte] =
 			(Char) (((val << unused_bits) >>
-					  ((bytew - (byte + 1U)) << 3U))
-					 & 255U);
+				 ((bytew - (byte + 1U)) << 3U))
+				& 255U);
 #ifdef DEBUG_LOAD
 		    TRACE(("bytew=%u val=%lx byte=%u output=%x\n",
 			   bytew, val,
@@ -7277,7 +7327,11 @@
 	    context->fill_point_count = 0U;
 	    while (!fragment_consumed(&state->input))
 		parse_regis_toplevel(state, context);
-	    draw_filled_polygon(context);
+	    if (context->temporary_write_controls.shading_character != '\0') {
+		draw_shaded_polygon(context);
+	    } else {
+		draw_filled_polygon(context);
+	    }
 	    context->fill_point_count = 0U;
 	    context->fill_mode = 0;
 	    state->command = 'f';
Index: graphics_sixel.c
--- xterm-358+/graphics_sixel.c	2020-07-04 01:07:27.000000000 +0000
+++ xterm-359/graphics_sixel.c	2020-08-06 20:32:33.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: graphics_sixel.c,v 1.25 2020/07/04 01:07:27 tom Exp $ */
+/* $XTermId: graphics_sixel.c,v 1.28 2020/08/06 20:32:33 Ben.Wong Exp $ */
 
 /*
  * Copyright 2014-2016,2020 by Ross Combs
@@ -256,9 +256,12 @@
 	    new_col = 0;
 	}
 
-	TRACE(("setting text position after %dx%d graphic starting on row=%d col=%d: cursor new_row=%d new_col=%d\n",
+	TRACE(("setting text position after %dx%d\t%.1f start (%d %d): cursor (%d,%d)\n",
 	       graphic->actual_width * graphic->pixw,
 	       graphic->actual_height * graphic->pixh,
+	       ((double) graphic->charrow
+		+ ((double) (graphic->actual_height * graphic->pixh)
+		   / (double) FontHeight(screen))),
 	       graphic->charrow,
 	       graphic->charcol,
 	       new_row, new_col));
@@ -471,7 +474,8 @@
 	    TRACE(("sixel NL\n"));
 	    scroll_lines = 0;
 	    while (graphic->charrow - scroll_lines +
-		   (((context.row + 6) * graphic->pixh
+		   (((context.row + Min(6, graphic->actual_height - context.row))
+		     * graphic->pixh
 		     + FontHeight(screen) - 1)
 		    / FontHeight(screen)) > screen->bot_marg) {
 		scroll_lines++;
@@ -500,7 +504,6 @@
 	    int Pcount;
 	    const char *start;
 	    int sixel;
-	    int i;
 
 	    start = ++string;
 	    for (;;) {
@@ -526,6 +529,7 @@
 		graphic->valid = 1;
 	    }
 	    if (sixel) {
+		int i;
 		for (i = 0; i < Pcount; i++) {
 		    set_sixel(graphic, &context, sixel);
 		    context.col++;
Index: misc.c
--- xterm-358+/misc.c	2020-07-05 19:30:28.000000000 +0000
+++ xterm-359/misc.c	2020-08-03 23:19:49.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: misc.c,v 1.950 2020/07/05 19:30:28 tom Exp $ */
+/* $XTermId: misc.c,v 1.952 2020/08/03 23:19:49 tom Exp $ */
 
 /*
  * Copyright 1999-2019,2020 by Thomas E. Dickey
@@ -3306,7 +3306,8 @@
 			screen->selection_time =
 			    XtLastTimestampProcessed(TScreenOf(xw)->display);
 
-			for (j = 0, buf = old; j < n; ++j) {
+			for (j = 0; j < n; ++j) {
+			    buf = old;
 			    ClearSelectionBuffer(screen, select_args[j]);
 			    while (*buf != '\0') {
 				AppendToSelectionBuffer(screen,
@@ -5144,6 +5145,8 @@
 	case srm_SGR_EXT_MODE_MOUSE:
 	    /* FALLTHRU */
 	case srm_URXVT_EXT_MODE_MOUSE:
+	    /* FALLTHRU */
+	case srm_PIXEL_POSITION_MOUSE:
 	    result = MdBool(screen->extend_coords == params[0]);
 	    break;
 	case srm_ALTERNATE_SCROLL:
Index: package/debian/changelog
--- xterm-358+/package/debian/changelog	2020-07-06 00:35:21.000000000 +0000
+++ xterm-359/package/debian/changelog	2020-07-25 17:48:12.000000000 +0000
@@ -1,3 +1,9 @@
+xterm-dev (359) unstable; urgency=low
+
+  * maintenance updates
+
+ -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 25 Jul 2020 13:48:12 -0400
+
 xterm-dev (358) unstable; urgency=low
 
   * maintenance updates
Index: package/debian/rules
--- xterm-358+/package/debian/rules	2020-03-08 23:41:14.000000000 +0000
+++ xterm-359/package/debian/rules	2020-07-25 18:18:20.000000000 +0000
@@ -75,7 +75,6 @@
 		--enable-mini-luit \
 		--enable-regis-graphics \
 		--enable-sco-fkeys \
-		--enable-sixel-graphics \
 		--enable-toolbar \
 		--enable-xmc-glitch \
 		--with-app-defaults=$(PKG_APPDEFAULTS) \
Index: package/freebsd/Makefile
--- xterm-358+/package/freebsd/Makefile	2020-07-06 00:35:21.000000000 +0000
+++ xterm-359/package/freebsd/Makefile	2020-07-25 17:48:12.000000000 +0000
@@ -1,4 +1,4 @@
-# $XTermId: Makefile,v 1.79 2020/07/06 00:35:21 tom Exp $
+# $XTermId: Makefile,v 1.80 2020/07/25 17:48:12 tom Exp $
 # $FreeBSD: head/x11/xterm/Makefile 492827 2019-02-13 06:43:36Z ehaupt $
 
 # This is adapted from the FreeBSD port, installing as "xterm-dev" with
@@ -7,7 +7,7 @@
 # and "make makesum".
 
 PORTNAME=	xterm
-PORTVERSION=	358
+PORTVERSION=	359
 CATEGORIES=	x11
 MASTER_SITES=	ftp://ftp.invisible-island.net/xterm/:src1 \
 		https://invisible-mirror.net/archives/xterm/:src1
Index: package/pkgsrc/Makefile
--- xterm-358+/package/pkgsrc/Makefile	2020-07-06 00:35:21.000000000 +0000
+++ xterm-359/package/pkgsrc/Makefile	2020-07-25 17:48:12.000000000 +0000
@@ -1,6 +1,6 @@
 # $NetBSD: Makefile,v 1.117 2018/03/12 11:18:00 wiz Exp $
 
-DISTNAME=	xterm-358
+DISTNAME=	xterm-359
 PKGREVISION=	1
 CATEGORIES=	x11
 MASTER_SITES=	ftp://ftp.invisible-island.net/xterm/
Index: package/xterm.spec
--- xterm-358+/package/xterm.spec	2020-07-06 00:35:21.000000000 +0000
+++ xterm-359/package/xterm.spec	2020-07-25 18:19:28.000000000 +0000
@@ -1,11 +1,11 @@
-# $XTermId: xterm.spec,v 1.132 2020/07/06 00:35:21 tom Exp $
+# $XTermId: xterm.spec,v 1.134 2020/07/25 18:19:28 tom Exp $
 Summary: X terminal emulator (development version)
 %global my_middle xterm
 %global my_suffix -dev
 %global fullname %{my_middle}%{my_suffix}
 %global my_class XTermDev
 Name: %{fullname}
-Version: 358
+Version: 359
 Release: 1
 License: X11
 Group: User Interface/X
@@ -123,7 +123,6 @@
         --enable-mini-luit \
         --enable-regis-graphics \
         --enable-sco-fkeys \
-        --enable-sixel-graphics \
         --enable-toolbar \
         --enable-xmc-glitch \
         --with-app-defaults=%{_xresdir} \
@@ -247,6 +246,9 @@
 
 %changelog
 
+* Sat Jul 25 2020 Thomas E. Dickey
+- sixels are enabled by default
+
 * Sun Mar 08 2020 Thomas E. Dickey
 - remove "--vendor" option from desktop-file-install
 
Index: ptydata.c
--- xterm-358+/ptydata.c	2020-07-06 07:56:56.000000000 +0000
+++ xterm-359/ptydata.c	2020-08-12 22:16:36.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: ptydata.c,v 1.146 2020/07/06 07:56:56 H.Merijn.Brand Exp $ */
+/* $XTermId: ptydata.c,v 1.148 2020/08/12 22:16:36 tom Exp $ */
 
 /*
  * Copyright 1999-2019,2020 by Thomas E. Dickey
@@ -107,6 +107,22 @@
 		data->utf_data = (IChar) (screen->c1_printable ? c : UCS_REPL);
 		data->utf_size = (i + 1);
 		break;
+	    } else if (screen->utf8_weblike
+		       && (utf_count == 3
+			   && utf_char == 0x04
+			   && c >= 0x90)) {
+		/* The encoding would form a code point beyond U+10FFFF. */
+		data->utf_size = i;
+		data->utf_data = UCS_REPL;
+		break;
+	    } else if (screen->utf8_weblike
+		       && (utf_count == 2
+			   && utf_char == 0x0d
+			   && c >= 0xa0)) {
+		/* The encoding would form a surrogate code point. */
+		data->utf_size = i;
+		data->utf_data = UCS_REPL;
+		break;
 	    } else {
 		/* Check for overlong UTF-8 sequences for which a shorter
 		 * encoding would exist and replace them with UCS_REPL.
@@ -119,7 +135,14 @@
 		 *   11111100 100000xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
 		 */
 		if (!utf_char && !((c & 0x7f) >> (7 - utf_count))) {
-		    utf_char = UCS_REPL;
+		    if (screen->utf8_weblike) {
+			/* overlong sequence continued */
+			data->utf_data = UCS_REPL;
+			data->utf_size = i;
+			break;
+		    } else {
+			utf_char = UCS_REPL;
+		    }
 		}
 		utf_char <<= 6;
 		utf_char |= (c & 0x3f);
@@ -146,32 +169,57 @@
 	} else {
 	    /* We received a sequence start byte */
 	    if (utf_count > 0) {
-		data->utf_data = UCS_REPL;	/* prev. sequence incomplete */
+		/* previous sequence is incomplete */
+		data->utf_data = UCS_REPL;
 		data->utf_size = i;
 		break;
 	    }
-	    if (c < 0xe0) {
-		utf_count = 1;
-		utf_char = (c & 0x1f);
-		if (!(c & 0x1e)) {
-		    utf_char = UCS_REPL;	/* overlong sequence */
+	    if (screen->utf8_weblike) {
+		if (c < 0xe0) {
+		    if (!(c & 0x1e)) {
+			/* overlong sequence start */
+			data->utf_data = UCS_REPL;
+			data->utf_size = (i + 1);
+			break;
+		    }
+		    utf_count = 1;
+		    utf_char = (c & 0x1f);
+		} else if (c < 0xf0) {
+		    utf_count = 2;
+		    utf_char = (c & 0x0f);
+		} else if (c < 0xf5) {
+		    utf_count = 3;
+		    utf_char = (c & 0x07);
+		} else {
+		    data->utf_data = UCS_REPL;
+		    data->utf_size = (i + 1);
+		    break;
 		}
-	    } else if (c < 0xf0) {
-		utf_count = 2;
-		utf_char = (c & 0x0f);
-	    } else if (c < 0xf8) {
-		utf_count = 3;
-		utf_char = (c & 0x07);
-	    } else if (c < 0xfc) {
-		utf_count = 4;
-		utf_char = (c & 0x03);
-	    } else if (c < 0xfe) {
-		utf_count = 5;
-		utf_char = (c & 0x01);
 	    } else {
-		data->utf_data = UCS_REPL;
-		data->utf_size = (i + 1);
-		break;
+		if (c < 0xe0) {
+		    utf_count = 1;
+		    utf_char = (c & 0x1f);
+		    if (!(c & 0x1e)) {
+			/* overlong sequence */
+			utf_char = UCS_REPL;
+		    }
+		} else if (c < 0xf0) {
+		    utf_count = 2;
+		    utf_char = (c & 0x0f);
+		} else if (c < 0xf8) {
+		    utf_count = 3;
+		    utf_char = (c & 0x07);
+		} else if (c < 0xfc) {
+		    utf_count = 4;
+		    utf_char = (c & 0x03);
+		} else if (c < 0xfe) {
+		    utf_count = 5;
+		    utf_char = (c & 0x01);
+		} else {
+		    data->utf_data = UCS_REPL;
+		    data->utf_size = (i + 1);
+		    break;
+		}
 	    }
 	}
     }
Index: ptyx.h
--- xterm-358+/ptyx.h	2020-07-04 01:06:46.000000000 +0000
+++ xterm-359/ptyx.h	2020-08-10 09:06:56.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: ptyx.h,v 1.1003 2020/07/04 01:06:46 tom Exp $ */
+/* $XTermId: ptyx.h,v 1.1005 2020/08/10 09:06:56 tom Exp $ */
 
 /*
  * Copyright 1999-2019,2020 by Thomas E. Dickey
@@ -1110,6 +1110,7 @@
     ,srm_EXT_MODE_MOUSE = SET_EXT_MODE_MOUSE
     ,srm_SGR_EXT_MODE_MOUSE = SET_SGR_EXT_MODE_MOUSE
     ,srm_URXVT_EXT_MODE_MOUSE = SET_URXVT_EXT_MODE_MOUSE
+    ,srm_PIXEL_POSITION_MOUSE = SET_PIXEL_POSITION_MOUSE
     ,srm_ALTERNATE_SCROLL = SET_ALTERNATE_SCROLL
     ,srm_RXVT_SCROLL_TTY_OUTPUT = 1010
     ,srm_RXVT_SCROLL_TTY_KEYPRESS = 1011
@@ -2309,6 +2310,7 @@
 	int		utf8_title;	/* use UTF-8 EWHM props: 0-2	*/
 	int		max_combining;	/* maximum # of combining chars	*/
 	Boolean		utf8_latin1;	/* use UTF-8 with Latin-1 bias	*/
+	Boolean		utf8_weblike;	/* use UTF-8 with browser bias	*/
 	int		latin9_mode;	/* poor man's luit, latin9	*/
 	int		unicode_font;	/* font uses unicode encoding	*/
 	int		utf_count;	/* state of utf_char		*/
Index: util.c
--- xterm-358+/util.c	2020-06-23 22:44:28.000000000 +0000
+++ xterm-359/util.c	2020-08-17 22:25:21.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: util.c,v 1.853 2020/06/23 22:44:28 tom Exp $ */
+/* $XTermId: util.c,v 1.856 2020/08/17 22:25:21 tom Exp $ */
 
 /*
  * Copyright 1999-2019,2020 by Thomas E. Dickey
@@ -1120,6 +1120,19 @@
 	&& ScrnIsRowInSelection(screen, INX2ROW(screen, screen->cur_row))) {
 	ScrnDisownSelection(xw);
     }
+#if OPT_ISO_COLORS
+    /* if colorBDMode is set, and enabled */
+    if (screen->colorBDMode &&
+	screen->boldColors &&
+	!hasDirectFG(attr_flags) &&
+    /* and bold foreground color on bold background color */
+	GetCellColorFG(fg_bg) > COLOR_7 &&
+	GetCellColorFG(fg_bg) < MIN_ANSI_COLORS &&
+    /* and both colors are the same */
+	GetCellColorFG(fg_bg) == GetCellColorBG(fg_bg))
+	/* clear BOLD flag, else it will be colorBD on bold background color */
+	UIntClr(attr_flags, BOLD);
+#endif
 
     /* if we are in insert-mode, reserve space for the new cells */
     if (attr_flags & INSERT) {
@@ -1152,8 +1165,8 @@
 
 	TRACE(("WriteText calling drawXtermText (%d) (%d,%d)\n",
 	       LineCharSet(screen, ld),
-	       screen->cur_col,
-	       screen->cur_row));
+	       screen->cur_row,
+	       screen->cur_col));
 
 	test = attr_flags;
 #if OPT_ISO_COLORS
Index: version.h
--- xterm-358+/version.h	2020-07-12 23:00:55.000000000 +0000
+++ xterm-359/version.h	2020-08-17 22:52:38.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: version.h,v 1.495 2020/07/12 23:00:55 tom Exp $ */
+/* $XTermId: version.h,v 1.497 2020/08/17 22:52:38 tom Exp $ */
 
 /*
  * Copyright 1998-2019,2020 by Thomas E. Dickey
@@ -38,8 +38,8 @@
  * version of X to which this version of xterm has been built.  The resulting
  * number in parentheses is my patch number (Thomas E. Dickey).
  */
-#define XTERM_PATCH   358
-#define XTERM_DATE    2020-07-12
+#define XTERM_PATCH   359
+#define XTERM_DATE    2020-08-17
 
 #ifndef __vendorversion__
 #define __vendorversion__ "XTerm"
Index: xcharmouse.h
--- xterm-358+/xcharmouse.h	2012-09-26 00:39:14.000000000 +0000
+++ xterm-359/xcharmouse.h	2020-08-03 23:14:06.000000000 +0000
@@ -1,8 +1,8 @@
-/* $XTermId: xcharmouse.h,v 1.18 2012/09/26 00:39:14 tom Exp $ */
+/* $XTermId: xcharmouse.h,v 1.19 2020/08/03 23:14:06 tom Exp $ */
 
 /************************************************************
 
-Copyright 1997-2011,2012 by Thomas E. Dickey
+Copyright 1997-2012,2020 by Thomas E. Dickey
 Copyright 1998 by Jason Bacon <acadix@execpc.com>
 
                         All Rights Reserved
@@ -50,12 +50,14 @@
 #define SET_FOCUS_EVENT_MOUSE       1004 /* can be combined with above */
 #endif
 
+#define SET_ALTERNATE_SCROLL        1007 /* wheel mouse may send cursor-keys */
+
 /* Extend mouse tracking for terminals wider(taller) than 223 cols(rows) */
 #define SET_EXT_MODE_MOUSE          1005 /* compatible with above */
 #define SET_SGR_EXT_MODE_MOUSE      1006
 #define SET_URXVT_EXT_MODE_MOUSE    1015
 
-#define SET_ALTERNATE_SCROLL        1007 /* wheel mouse may send cursor-keys */
+#define SET_PIXEL_POSITION_MOUSE    1016 /* like 1006, but pixels not chars */
 
 #define SET_BUTTON1_MOVE_POINT      2001 /* click1 emit Esc seq to move point*/
 #define SET_BUTTON2_MOVE_POINT      2002 /* press2 emit Esc seq to move point*/
Index: xterm.appdata.xml
--- xterm-358+/xterm.appdata.xml	2020-07-12 23:01:16.000000000 +0000
+++ xterm-359/xterm.appdata.xml	2020-08-17 22:53:08.000000000 +0000
@@ -35,7 +35,7 @@
     <keyword>terminal</keyword>
   </keywords>
   <releases>
-    <release version="358" date="2020-07-12"/>
+    <release version="359" date="2020-08-17"/>
   </releases>
   <url type="homepage">https://invisible-island.net/xterm/</url>
   <update_contact>dickey@invisible-island.net</update_contact>
Index: xterm.h
--- xterm-358+/xterm.h	2020-07-02 00:30:01.000000000 +0000
+++ xterm-359/xterm.h	2020-08-10 09:04:29.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: xterm.h,v 1.872 2020/07/02 00:30:01 tom Exp $ */
+/* $XTermId: xterm.h,v 1.873 2020/08/10 09:04:29 tom Exp $ */
 
 /*
  * Copyright 1999-2019,2020 by Thomas E. Dickey
@@ -622,6 +622,7 @@
 #define XtNutf8Latin1		"utf8Latin1"
 #define XtNutf8SelectTypes	"utf8SelectTypes"
 #define XtNutf8Title		"utf8Title"
+#define XtNutf8Weblike		"utf8Weblike"
 #define XtNveryBoldColors	"veryBoldColors"
 #define XtNvisualBell		"visualBell"
 #define XtNvisualBellDelay	"visualBellDelay"
@@ -815,6 +816,7 @@
 #define XtCUtf8Latin1		"Utf8Latin1"
 #define XtCUtf8SelectTypes	"Utf8SelectTypes"
 #define XtCUtf8Title		"Utf8Title"
+#define XtCUtf8Weblike		"Utf8Weblike"
 #define XtCVT100Graphics	"VT100Graphics"
 #define XtCVeryBoldColors	"VeryBoldColors"
 #define XtCVisualBell		"VisualBell"
Index: xterm.log.html
--- xterm-358+/xterm.log.html	2020-07-12 23:00:33.000000000 +0000
+++ xterm-359/xterm.log.html	2020-08-17 22:54:03.000000000 +0000
@@ -30,7 +30,7 @@
  * sale, use or other dealings in this Software without prior written        *
  * authorization.                                                            *
  *****************************************************************************
-  $XTermId: xterm.log.html,v 1.2218 2020/07/12 23:00:33 tom Exp $
+  $XTermId: xterm.log.html,v 1.2229 2020/08/17 22:54:03 tom Exp $
   -->
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
 
@@ -73,6 +73,8 @@
   CHANGELOG</a>).</p>
 
   <ul>
+    <li><a href="#xterm_359">Patch #359 - 2020/08/17</a></li>
+
     <li><a href="#xterm_358">Patch #358 - 2020/07/12</a></li>
 
     <li><a href="#xterm_357">Patch #357 - 2020/07/05</a></li>
@@ -997,6 +999,47 @@
     <li><a href="#xterm_01">Patch #1 - 1996/1/6</a></li>
   </ul>
 
+  <h1><a name="xterm_359" id="xterm_359">Patch #359 -
+  2020/08/17</a></h1>
+
+  <ul>
+    <li>add special case in <code>WriteText</code> to allow colors
+    8-15 to override <code>colorBDMode</code> (patch by Ingo
+    Br&uuml;ckl).</li>
+
+    <li>add <code>utf8Weblike</code> resource, to provide an
+    alternate scheme for handling ill-formed UTF-8 sequences
+    (adapted from patch by Dan Gohman).</li>
+
+    <li>improve computation for the number of lines needed to
+    scroll-up a SIXEL graphic (report/patch by Ben Wong).</li>
+
+    <li>correct manpage description for default value of
+    <code>disallowWindowOps</code> from changes in <a href=
+    "#xterm_331">xterm #331</a> (patch by Ben Wong).</li>
+
+    <li>correct a loop starting-point in
+    <code>refresh_graphics</code> from optimization in <a href=
+    "#xterm_358">patch #358</a> changes (report by Ben Wong).</li>
+
+    <li>add a new mouse mode 1016, which uses the same format as
+    mode 1006, but sends the mouse's position in pixels (suggested
+    by Igor van den Hoven).</li>
+
+    <li>fix an issue from <a href="#xterm_338">patch #338</a>
+    changes where only the first selection buffer specified in the
+    request would be updated using OSC 52 (patch by Michael
+    Gulick).</li>
+
+    <li>modify makefile/scripts to allow <code>DESTDIR</code> to
+    prefix the target directory for desktop-file-install (report by
+    Fred Heitkamp).</li>
+
+    <li>enable SIXEL feature by default.</li>
+
+    <li>update config.guess, config.sub</li>
+  </ul>
+
   <h1><a name="xterm_358" id="xterm_358">Patch #358 -
   2020/07/12</a></h1>
 
Index: xterm.man
--- xterm-358+/xterm.man	2020-07-03 23:05:42.000000000 +0000
+++ xterm-359/xterm.man	2020-08-10 13:50:37.000000000 +0000
@@ -1,5 +1,5 @@
 '\" t
-.\" $XTermId: xterm.man,v 1.809 2020/07/03 23:05:42 tom Exp $
+.\" $XTermId: xterm.man,v 1.811 2020/08/10 13:50:37 tom Exp $
 .\"
 .\" Copyright 1996-2019,2020 by Thomas E. Dickey
 .\"
@@ -3168,7 +3168,7 @@
 The default value is
 .NS
 20,21,SetXprop,SetSelection
-(i.e.\& no operations are allowed).
+(i.e., all except a few \*(``dangerous\*('' operations are allowed).
 .NE
 .IP
 The names are listed below.
@@ -4223,6 +4223,7 @@
 .RE
 .IP
 The \fI\*N\fP FAQ has an extended discussion of this feature, with examples:
+.sp
 .RS
 https://invisible\-island.net/xterm/modified\-keys.html
 .RE
@@ -5077,6 +5078,18 @@
 .IP
 The default is \*(``default\*(''.
 .TP 8
+.B "utf8Weblike\fP (class\fB Utf8Weblike\fP)"
+Provide an alternate error-handling scheme for ill-formed UTF-8 as recommended
+in a W3C document.
+The Unicode standard does not require this for conformance.
+Some additional information can be found here:
+.sp
+.RS
+https://invisible\-island.net/xterm/bad-utf8/
+.RE
+.IP
+The default is \*(``false\*(''.
+.TP 8
 .B "veryBoldColors\fP (class\fB VeryBoldColors\fP)"
 Specifies whether to combine video attributes with colors specified by
 \fBcolorBD\fR,
