head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.1
	netbsd-11-0-RC3:1.1.1.1
	netbsd-11-0-RC2:1.1.1.1
	netbsd-11-0-RC1:1.1.1.1
	netbsd-11:1.1.1.1.0.8
	netbsd-11-base:1.1.1.1
	xterm-397:1.1.1.1
	netbsd-10-1-RELEASE:1.1.1.1
	xterm-392:1.1.1.1
	netbsd-8-3-RELEASE:1.1.1.1.4.2
	netbsd-9-4-RELEASE:1.1.1.1.2.2
	netbsd-10-0-RELEASE:1.1.1.1
	netbsd-10-0-RC6:1.1.1.1
	netbsd-10-0-RC5:1.1.1.1
	netbsd-10-0-RC4:1.1.1.1
	netbsd-10-0-RC3:1.1.1.1
	netbsd-10-0-RC2:1.1.1.1
	netbsd-10-0-RC1:1.1.1.1
	xterm-382:1.1.1.1
	netbsd-10:1.1.1.1.0.6
	netbsd-10-base:1.1.1.1
	netbsd-9-3-RELEASE:1.1.1.1.2.2
	xterm-372:1.1.1.1
	xterm-370:1.1.1.1
	xterm-368:1.1.1.1
	netbsd-9-2-RELEASE:1.1.1.1.2.2
	xterm-367:1.1.1.1
	netbsd-8:1.1.1.1.0.4
	netbsd-9:1.1.1.1.0.2
	xterm-366:1.1.1.1
	xorg:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2021.02.11.12.19.55;	author mrg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	uqdG3YuikH8o0iHC;

1.1.1.1
date	2021.02.11.12.19.55;	author mrg;	state Exp;
branches
	1.1.1.1.2.1
	1.1.1.1.4.1;
next	;
commitid	uqdG3YuikH8o0iHC;

1.1.1.1.2.1
date	2021.02.11.12.19.55;	author martin;	state dead;
branches;
next	1.1.1.1.2.2;
commitid	BI7YP4R11SXiW2IC;

1.1.1.1.2.2
date	2021.02.17.09.45.01;	author martin;	state Exp;
branches;
next	;
commitid	BI7YP4R11SXiW2IC;

1.1.1.1.4.1
date	2021.02.11.12.19.55;	author martin;	state dead;
branches;
next	1.1.1.1.4.2;
commitid	AiVLYHEHTDVpY2IC;

1.1.1.1.4.2
date	2021.02.17.09.48.39;	author martin;	state Exp;
branches;
next	;
commitid	AiVLYHEHTDVpY2IC;


desc
@@


1.1
log
@Initial revision
@
text
@#!/usr/bin/env perl
# $XTermId: mouse-codes,v 1.7 2020/12/13 15:07:02 tom Exp $
# -----------------------------------------------------------------------------
# this file is part of xterm
#
# Copyright 2018-2019,2020 by Thomas E. Dickey
#
#                         All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name(s) of the above copyright
# holders shall not be used in advertising or otherwise to promote the
# sale, use or other dealings in this Software without prior written
# authorization.
# -----------------------------------------------------------------------------
# Imitate xterm's BtnCode() function, to enumerate the possible inputs (button,
# event state) versus output (xterm mouse-code).
use strict;
use warnings;

use Getopt::Std;

our ( $opt_b, $opt_i, $opt_x );

# Typically,
# -	Buttons 1, 2, and 3 are left-to-right assignments on a 3-button mouse.
# -	Buttons 4 and 5 are (by convention) assigned to a wheel mouse's
#	up/down events.
# -	Buttons 6 and 7 may happen to work, e.g., as left/right events from a
#	tiltable wheel mouse.  There is no explicit support for these (there
#	are no related symbols in Xt), so it is not possible to use them in the
#	translations resource.
our $maxbutton = 7;

# xterm uses code 3 internally for release-events.
sub ButtonName($) {
    my $code   = shift;
    my $result = "";
    if ( $code < 0 ) {
        $result = "release";
    }
    else {
        $result = sprintf "Button%d", ( $code > 3 ) ? $code : ( $code + 1 );
    }
    return $result;
}

# Combine the modifier state as bits:
#  shift key   -> 1
#  meta key    -> 2 (Mod1 came from X11R1, but was adapted from X10)
#  control key -> 4
our $maxstates = 7;

sub KeyState($) {
    my $mask   = shift;
    my $result = "";
    $result .= " + shift"   if ( ( $mask & 1 ) != 0 );
    $result .= " + meta"    if ( ( $mask & 2 ) != 0 );
    $result .= " + control" if ( ( $mask & 4 ) != 0 );
    return $result;
}

sub Motion($) {
    my $code   = shift;
    my $result = "";
    $result = " + motion" if ( $code != 0 );
    return $result;
}

sub report() {
    my $button;
    my $states;
    my $motion;
    my %encoded;
    my %reports;
    for $states ( 0 .. $maxstates ) {
        for $motion ( 0 .. 1 ) {
            for $button ( -1 .. $maxbutton ) {
                next if ( $button == 3 );
                my $result = ( 32 + ( $states << 2 ) );
                $result += 32 if ( $motion != 0 );
                if ( $button < 0 ) {
                    $result += 3;
                }
                else {
                    $result += $button & 3;
                    if ( $button & 4 ) {
                        $result += 64;
                    }
                    if ( $button & 8 ) {
                        $result += 128;
                    }
                }
                my $code   = sprintf "%3d",    $result;
                my $report = sprintf "%s%s%s", &ButtonName($button),
                  &KeyState($states), &Motion($motion);
                if ( defined $encoded{$code} ) {
                    printf "OOPS %s ->%s versus %s\n", $code, $report,
                      $encoded{$code};
                }
                elsif ( $result > 255 and not defined $opt_x ) {
                    printf "OOPS %s ->%s\n", $code, $report;
                }
                $encoded{$code}   = $report;
                $reports{$report} = $result;
            }
        }
    }
    if ($opt_i) {
        foreach my $report ( sort keys %reports ) {
            printf "%s = %s\n", $report, $reports{$report};
        }
    }
    else {
        foreach my $code ( sort keys %encoded ) {
            printf "%s = %s\n", $code, $encoded{$code};
        }
    }
}

sub main::HELP_MESSAGE() {
    printf STDERR <<EOF
Usage: $0 [options]

Options:
	-b NUM	set the number of buttons (default: 7)
	-i	invert the report to show code for each combination
	-x	eliminate 1-byte limit for codes
EOF
      ;
    exit 1;
}
$Getopt::Std::STANDARD_HELP_VERSION = 1;
&getopts('b:ix') || &main::HELP_MESSAGE;
$maxbutton = $opt_b if ( defined $opt_b );
&main::HELP_MESSAGE if ( $maxbutton !~ /^\d+$/ );
$#ARGV < 0 || &main::HELP_MESSAGE;

&report;

1;
@


1.1.1.1
log
@initial import of xterm-366
@
text
@@


1.1.1.1.4.1
log
@file mouse-codes was added on branch netbsd-8 on 2021-02-17 09:48:39 +0000
@
text
@d1 159
@


1.1.1.1.4.2
log
@Pull up the following

	xsrc/external/mit/xterm/dist/package/debian/xterm-dev.lintian-overrides up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/freebsd/distinfo up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/freebsd/pkg-message.wchar up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/pkgsrc/Makefile up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/pkgsrc/DESCR    up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/pkgsrc/distinfo up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/pkgsrc/PLIST    up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/pkgsrc/options.mk up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/closest-rgb.pl  up to 1.1.1.2
	xsrc/external/mit/xterm/dist/vttests/query-status.pl up to 1.1.1.2
	xsrc/external/mit/xterm/dist/vttests/modify-keys.pl  up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/mouse-codes     up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/other-sgr.sh    up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/print-vt-chars.pl up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/query-dynamic.pl up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/query-xres.pl   up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/report-sgr.pl   up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/sgrPushPop.pl   up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/sgrPushPop2.pl  up to 1.1.1.1
	xsrc/external/mit/xterm/dist/COPYING                 up to 1.1.1.1
	xsrc/external/mit/xterm/dist/gen-charsets.pl         up to 1.1.1.1
	xsrc/external/mit/xterm/include/Tekparse.hin         delete
	xsrc/external/mit/xterm/include/VTparse.hin          delete
	xsrc/external/mit/xterm/dist/INSTALL                 up to 1.1.1.12
	xsrc/external/mit/xterm/dist/Imakefile               up to 1.1.1.10
	xsrc/external/mit/xterm/dist/MANIFEST                up to 1.1.1.16
	xsrc/external/mit/xterm/dist/Makefile.in             up to 1.1.1.13
	xsrc/external/mit/xterm/dist/NEWS                    up to 1.1.1.3
	xsrc/external/mit/xterm/dist/THANKS                  up to 1.1.1.9
	xsrc/external/mit/xterm/dist/TekPrsTbl.c             up to 1.1.1.2
	xsrc/external/mit/xterm/dist/Tekproc.c               up to 1.1.1.14
	xsrc/external/mit/xterm/dist/UXTerm.ad               up to 1.1.1.3
	xsrc/external/mit/xterm/dist/VTPrsTbl.c              up to 1.1.1.9
	xsrc/external/mit/xterm/dist/VTparse.def             up to 1.1.1.8
	xsrc/external/mit/xterm/dist/VTparse.h               up to 1.1.1.10
	xsrc/external/mit/xterm/dist/XTerm.ad                up to 1.11
	xsrc/external/mit/xterm/dist/aclocal.m4              up to 1.1.1.14
	xsrc/external/mit/xterm/dist/button.c                up to 1.1.1.16
	xsrc/external/mit/xterm/dist/cachedGCs.c             up to 1.1.1.11
	xsrc/external/mit/xterm/dist/charclass.c             up to 1.1.1.6
	xsrc/external/mit/xterm/dist/charclass.h             up to 1.1.1.3
	xsrc/external/mit/xterm/dist/charproc.c              up to 1.1.1.15
	xsrc/external/mit/xterm/dist/charsets.c              up to 1.1.1.6
	xsrc/external/mit/xterm/dist/config.guess            up to 1.1.1.12
	xsrc/external/mit/xterm/dist/config.sub              up to 1.1.1.12
	xsrc/external/mit/xterm/dist/configure               up to 1.1.1.14
	xsrc/external/mit/xterm/dist/configure.in            up to 1.1.1.13
	xsrc/external/mit/xterm/dist/ctlseqs.ms              up to 1.1.1.15
	xsrc/external/mit/xterm/dist/ctlseqs.txt             up to 1.1.1.15
	xsrc/external/mit/xterm/dist/cursor.c                up to 1.1.1.9
	xsrc/external/mit/xterm/dist/data.c                  up to 1.1.1.7
	xsrc/external/mit/xterm/dist/data.h                  up to 1.1.1.10
	xsrc/external/mit/xterm/dist/df-install.in           up to 1.1.1.3
	xsrc/external/mit/xterm/dist/doublechr.c             up to 1.1.1.9
	xsrc/external/mit/xterm/dist/error.h                 up to 1.1.1.6
	xsrc/external/mit/xterm/dist/fontutils.c             up to 1.8
	xsrc/external/mit/xterm/dist/fontutils.h             up to 1.1.1.10
	xsrc/external/mit/xterm/dist/graphics.c              up to 1.1.1.6
	xsrc/external/mit/xterm/dist/graphics_regis.c        up to 1.1.1.5
	xsrc/external/mit/xterm/dist/graphics_sixel.c        up to 1.1.1.4
	xsrc/external/mit/xterm/dist/html.c                  up to 1.1.1.3
	xsrc/external/mit/xterm/dist/input.c                 up to 1.1.1.13
	xsrc/external/mit/xterm/dist/keysym2ucs.c            up to 1.1.1.3
	xsrc/external/mit/xterm/dist/koi8rxterm              up to 1.1.1.3
	xsrc/external/mit/xterm/dist/koi8rxterm.man          up to 1.1.1.3
	xsrc/external/mit/xterm/dist/linedata.c              up to 1.6
	xsrc/external/mit/xterm/dist/main.c                  up to 1.1.1.13
	xsrc/external/mit/xterm/dist/main.h                  up to 1.1.1.6
	xsrc/external/mit/xterm/dist/menu.c                  up to 1.1.1.13
	xsrc/external/mit/xterm/dist/menu.h                  up to 1.1.1.12
	xsrc/external/mit/xterm/dist/minstall.in             up to 1.1.1.5
	xsrc/external/mit/xterm/dist/misc.c                  up to 1.17
	xsrc/external/mit/xterm/dist/plink.sh                up to 1.1.1.5
	xsrc/external/mit/xterm/dist/print.c                 up to 1.1.1.11
	xsrc/external/mit/xterm/dist/ptydata.c               up to 1.1.1.9
	xsrc/external/mit/xterm/dist/ptyx.h                  up to 1.15
	xsrc/external/mit/xterm/dist/resize.c                up to 1.1.1.9
	xsrc/external/mit/xterm/dist/resize.man              up to 1.1.1.5
	xsrc/external/mit/xterm/dist/run-tic.sh              up to 1.1.1.3
	xsrc/external/mit/xterm/dist/screen.c                up to 1.1.1.12
	xsrc/external/mit/xterm/dist/scrollback.c            up to 1.6
	xsrc/external/mit/xterm/dist/scrollbar.c             up to 1.1.1.11
	xsrc/external/mit/xterm/dist/svg.c                   up to 1.1.1.2
	xsrc/external/mit/xterm/dist/tabs.c                  up to 1.1.1.6
	xsrc/external/mit/xterm/dist/termcap                 up to 1.1.1.6
	xsrc/external/mit/xterm/dist/terminfo                up to 1.1.1.7
	xsrc/external/mit/xterm/dist/testxmc.c               up to 1.1.1.7
	xsrc/external/mit/xterm/dist/trace.c                 up to 1.1.1.13
	xsrc/external/mit/xterm/dist/trace.h                 up to 1.1.1.13
	xsrc/external/mit/xterm/dist/util.c                  up to 1.1.1.13
	xsrc/external/mit/xterm/dist/uxterm                  up to 1.1.1.3
	xsrc/external/mit/xterm/dist/uxterm.desktop          up to 1.1.1.5
	xsrc/external/mit/xterm/dist/uxterm.man              up to 1.1.1.3
	xsrc/external/mit/xterm/dist/version.c               up to 1.1.1.5
	xsrc/external/mit/xterm/dist/version.h               up to 1.1.1.16
	xsrc/external/mit/xterm/dist/vms.c                   up to 1.1.1.4
	xsrc/external/mit/xterm/dist/wcwidth.c               up to 1.1.1.6
	xsrc/external/mit/xterm/dist/wcwidth.h               up to 1.1.1.2
	xsrc/external/mit/xterm/dist/xcharmouse.h            up to 1.1.1.5
	xsrc/external/mit/xterm/dist/xstrings.c              up to 1.1.1.10
	xsrc/external/mit/xterm/dist/xstrings.h              up to 1.1.1.6
	xsrc/external/mit/xterm/dist/xterm.appdata.xml       up to 1.1.1.3
	xsrc/external/mit/xterm/dist/xterm.dat               up to 1.1.1.3
	xsrc/external/mit/xterm/dist/xterm.h                 up to 1.3
	xsrc/external/mit/xterm/dist/xterm.log.html          up to 1.1.1.16
	xsrc/external/mit/xterm/dist/xterm.man               up to 1.17
	xsrc/external/mit/xterm/dist/xterm_io.h              up to 1.1.1.7
	xsrc/external/mit/xterm/dist/xtermcap.c              up to 1.1.1.9
	xsrc/external/mit/xterm/dist/xtermcfg.hin            up to 1.1.1.13
	xsrc/external/mit/xterm/dist/xutf8.c                 up to 1.1.1.6
	xsrc/external/mit/xterm/dist/icons/filled-xterm.svg  up to 1.1.1.2
	xsrc/external/mit/xterm/dist/icons/mini.xterm.svg    up to 1.1.1.2
	xsrc/external/mit/xterm/dist/icons/terminal_48x48.svg up to 1.1.1.2
	xsrc/external/mit/xterm/dist/icons/xterm-color.svg   up to 1.1.1.2
	xsrc/external/mit/xterm/dist/icons/xterm.svg         up to 1.1.1.2
	xsrc/external/mit/xterm/dist/package/xterm.spec      up to 1.1.1.11
	xsrc/external/mit/xterm/dist/package/debian/changelog up to 1.1.1.11
	xsrc/external/mit/xterm/dist/package/debian/compat   up to 1.1.1.2
	xsrc/external/mit/xterm/dist/package/debian/control  up to 1.1.1.5
	xsrc/external/mit/xterm/dist/package/debian/copyright up to 1.1.1.7
	xsrc/external/mit/xterm/dist/package/debian/rules    up to 1.1.1.8
	xsrc/external/mit/xterm/dist/package/debian/watch    up to 1.1.1.2
	xsrc/external/mit/xterm/dist/package/debian/xterm-dev.docs up to 1.1.1.2
	xsrc/external/mit/xterm/dist/package/debian/xterm-dev.menu up to 1.1.1.2
	xsrc/external/mit/xterm/dist/package/freebsd/Makefile up to 1.1.1.7
	xsrc/external/mit/xterm/dist/package/freebsd/pkg-descr up to 1.1.1.2
	xsrc/external/mit/xterm/dist/unicode/convmap.pl      up to 1.1.1.3
	xsrc/external/mit/xterm/dist/unicode/keysym.map      up to 1.1.1.3
	xsrc/external/mit/xterm/dist/vttests/256colors.pl    up to 1.1.1.4
	xsrc/external/mit/xterm/dist/vttests/256colors2.pl   up to 1.1.1.6
	xsrc/external/mit/xterm/dist/vttests/88colors.pl     up to 1.1.1.4
	xsrc/external/mit/xterm/dist/vttests/88colors2.pl    up to 1.1.1.6
	xsrc/external/mit/xterm/dist/vttests/dynamic.pl      up to 1.1.1.4
	xsrc/external/mit/xterm/dist/vttests/paste64.pl      up to 1.1.1.5
	xsrc/external/mit/xterm/dist/vttests/query-color.pl  up to 1.1.1.4
	xsrc/external/mit/xterm/dist/vttests/query-fonts.pl  up to 1.1.1.3
	xsrc/external/mit/xterm/dist/vttests/resize.pl       up to 1.1.1.5
	xsrc/external/mit/xterm/dist/vttests/tcapquery.pl    up to 1.1.1.6
	xsrc/external/mit/xterm/include/xtermcfg.h           up to 1.15

Import Xterm 366, changes too numerous to list, main fix is for CVE-2021-27135:
 * correct upper-limit for selection buffer, accounting for combining
   characters
@
text
@a0 159
#!/usr/bin/env perl
# $XTermId: mouse-codes,v 1.7 2020/12/13 15:07:02 tom Exp $
# -----------------------------------------------------------------------------
# this file is part of xterm
#
# Copyright 2018-2019,2020 by Thomas E. Dickey
#
#                         All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name(s) of the above copyright
# holders shall not be used in advertising or otherwise to promote the
# sale, use or other dealings in this Software without prior written
# authorization.
# -----------------------------------------------------------------------------
# Imitate xterm's BtnCode() function, to enumerate the possible inputs (button,
# event state) versus output (xterm mouse-code).
use strict;
use warnings;

use Getopt::Std;

our ( $opt_b, $opt_i, $opt_x );

# Typically,
# -	Buttons 1, 2, and 3 are left-to-right assignments on a 3-button mouse.
# -	Buttons 4 and 5 are (by convention) assigned to a wheel mouse's
#	up/down events.
# -	Buttons 6 and 7 may happen to work, e.g., as left/right events from a
#	tiltable wheel mouse.  There is no explicit support for these (there
#	are no related symbols in Xt), so it is not possible to use them in the
#	translations resource.
our $maxbutton = 7;

# xterm uses code 3 internally for release-events.
sub ButtonName($) {
    my $code   = shift;
    my $result = "";
    if ( $code < 0 ) {
        $result = "release";
    }
    else {
        $result = sprintf "Button%d", ( $code > 3 ) ? $code : ( $code + 1 );
    }
    return $result;
}

# Combine the modifier state as bits:
#  shift key   -> 1
#  meta key    -> 2 (Mod1 came from X11R1, but was adapted from X10)
#  control key -> 4
our $maxstates = 7;

sub KeyState($) {
    my $mask   = shift;
    my $result = "";
    $result .= " + shift"   if ( ( $mask & 1 ) != 0 );
    $result .= " + meta"    if ( ( $mask & 2 ) != 0 );
    $result .= " + control" if ( ( $mask & 4 ) != 0 );
    return $result;
}

sub Motion($) {
    my $code   = shift;
    my $result = "";
    $result = " + motion" if ( $code != 0 );
    return $result;
}

sub report() {
    my $button;
    my $states;
    my $motion;
    my %encoded;
    my %reports;
    for $states ( 0 .. $maxstates ) {
        for $motion ( 0 .. 1 ) {
            for $button ( -1 .. $maxbutton ) {
                next if ( $button == 3 );
                my $result = ( 32 + ( $states << 2 ) );
                $result += 32 if ( $motion != 0 );
                if ( $button < 0 ) {
                    $result += 3;
                }
                else {
                    $result += $button & 3;
                    if ( $button & 4 ) {
                        $result += 64;
                    }
                    if ( $button & 8 ) {
                        $result += 128;
                    }
                }
                my $code   = sprintf "%3d",    $result;
                my $report = sprintf "%s%s%s", &ButtonName($button),
                  &KeyState($states), &Motion($motion);
                if ( defined $encoded{$code} ) {
                    printf "OOPS %s ->%s versus %s\n", $code, $report,
                      $encoded{$code};
                }
                elsif ( $result > 255 and not defined $opt_x ) {
                    printf "OOPS %s ->%s\n", $code, $report;
                }
                $encoded{$code}   = $report;
                $reports{$report} = $result;
            }
        }
    }
    if ($opt_i) {
        foreach my $report ( sort keys %reports ) {
            printf "%s = %s\n", $report, $reports{$report};
        }
    }
    else {
        foreach my $code ( sort keys %encoded ) {
            printf "%s = %s\n", $code, $encoded{$code};
        }
    }
}

sub main::HELP_MESSAGE() {
    printf STDERR <<EOF
Usage: $0 [options]

Options:
	-b NUM	set the number of buttons (default: 7)
	-i	invert the report to show code for each combination
	-x	eliminate 1-byte limit for codes
EOF
      ;
    exit 1;
}
$Getopt::Std::STANDARD_HELP_VERSION = 1;
&getopts('b:ix') || &main::HELP_MESSAGE;
$maxbutton = $opt_b if ( defined $opt_b );
&main::HELP_MESSAGE if ( $maxbutton !~ /^\d+$/ );
$#ARGV < 0 || &main::HELP_MESSAGE;

&report;

1;
@


1.1.1.1.2.1
log
@file mouse-codes was added on branch netbsd-9 on 2021-02-17 09:45:01 +0000
@
text
@d1 159
@


1.1.1.1.2.2
log
@Pull up the following

	xsrc/external/mit/xterm/dist/package/debian/xterm-dev.lintian-overrides up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/freebsd/distinfo up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/freebsd/pkg-message.wchar up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/pkgsrc/Makefile up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/pkgsrc/DESCR    up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/pkgsrc/distinfo up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/pkgsrc/PLIST    up to 1.1.1.1
	xsrc/external/mit/xterm/dist/package/pkgsrc/options.mk up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/modify-keys.pl  up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/mouse-codes     up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/other-sgr.sh    up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/print-vt-chars.pl up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/query-dynamic.pl up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/query-xres.pl   up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/report-sgr.pl   up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/sgrPushPop.pl   up to 1.1.1.1
	xsrc/external/mit/xterm/dist/vttests/sgrPushPop2.pl  up to 1.1.1.1
	xsrc/external/mit/xterm/dist/COPYING                 up to 1.1.1.1
	xsrc/external/mit/xterm/dist/gen-charsets.pl         up to 1.1.1.1
	xsrc/external/mit/xterm/dist/INSTALL                 up to 1.1.1.12
	xsrc/external/mit/xterm/dist/Imakefile               up to 1.1.1.10
	xsrc/external/mit/xterm/dist/MANIFEST                up to 1.1.1.16
	xsrc/external/mit/xterm/dist/Makefile.in             up to 1.1.1.13
	xsrc/external/mit/xterm/dist/NEWS                    up to 1.1.1.3
	xsrc/external/mit/xterm/dist/THANKS                  up to 1.1.1.9
	xsrc/external/mit/xterm/dist/TekPrsTbl.c             up to 1.1.1.2
	xsrc/external/mit/xterm/dist/Tekproc.c               up to 1.1.1.14
	xsrc/external/mit/xterm/dist/UXTerm.ad               up to 1.1.1.3
	xsrc/external/mit/xterm/dist/VTPrsTbl.c              up to 1.1.1.9
	xsrc/external/mit/xterm/dist/VTparse.def             up to 1.1.1.8
	xsrc/external/mit/xterm/dist/VTparse.h               up to 1.1.1.10
	xsrc/external/mit/xterm/dist/XTerm.ad                up to 1.11
	xsrc/external/mit/xterm/dist/aclocal.m4              up to 1.1.1.14
	xsrc/external/mit/xterm/dist/button.c                up to 1.1.1.16
	xsrc/external/mit/xterm/dist/cachedGCs.c             up to 1.1.1.11
	xsrc/external/mit/xterm/dist/charclass.c             up to 1.1.1.6
	xsrc/external/mit/xterm/dist/charclass.h             up to 1.1.1.3
	xsrc/external/mit/xterm/dist/charproc.c              up to 1.1.1.15
	xsrc/external/mit/xterm/dist/charsets.c              up to 1.1.1.6
	xsrc/external/mit/xterm/dist/config.guess            up to 1.1.1.12
	xsrc/external/mit/xterm/dist/config.sub              up to 1.1.1.12
	xsrc/external/mit/xterm/dist/configure               up to 1.1.1.14
	xsrc/external/mit/xterm/dist/configure.in            up to 1.1.1.13
	xsrc/external/mit/xterm/dist/ctlseqs.ms              up to 1.1.1.15
	xsrc/external/mit/xterm/dist/ctlseqs.txt             up to 1.1.1.15
	xsrc/external/mit/xterm/dist/cursor.c                up to 1.1.1.9
	xsrc/external/mit/xterm/dist/data.c                  up to 1.1.1.7
	xsrc/external/mit/xterm/dist/data.h                  up to 1.1.1.10
	xsrc/external/mit/xterm/dist/df-install.in           up to 1.1.1.3
	xsrc/external/mit/xterm/dist/doublechr.c             up to 1.1.1.9
	xsrc/external/mit/xterm/dist/error.h                 up to 1.1.1.6
	xsrc/external/mit/xterm/dist/fontutils.c             up to 1.8
	xsrc/external/mit/xterm/dist/fontutils.h             up to 1.1.1.10
	xsrc/external/mit/xterm/dist/graphics.c              up to 1.1.1.6
	xsrc/external/mit/xterm/dist/graphics_regis.c        up to 1.1.1.5
	xsrc/external/mit/xterm/dist/graphics_sixel.c        up to 1.1.1.4
	xsrc/external/mit/xterm/dist/html.c                  up to 1.1.1.3
	xsrc/external/mit/xterm/dist/input.c                 up to 1.1.1.13
	xsrc/external/mit/xterm/dist/keysym2ucs.c            up to 1.1.1.3
	xsrc/external/mit/xterm/dist/koi8rxterm              up to 1.1.1.3
	xsrc/external/mit/xterm/dist/koi8rxterm.man          up to 1.1.1.3
	xsrc/external/mit/xterm/dist/linedata.c              up to 1.6
	xsrc/external/mit/xterm/dist/main.c                  up to 1.1.1.13
	xsrc/external/mit/xterm/dist/main.h                  up to 1.1.1.6
	xsrc/external/mit/xterm/dist/menu.c                  up to 1.1.1.13
	xsrc/external/mit/xterm/dist/menu.h                  up to 1.1.1.12
	xsrc/external/mit/xterm/dist/minstall.in             up to 1.1.1.5
	xsrc/external/mit/xterm/dist/misc.c                  up to 1.17
	xsrc/external/mit/xterm/dist/plink.sh                up to 1.1.1.5
	xsrc/external/mit/xterm/dist/print.c                 up to 1.1.1.11
	xsrc/external/mit/xterm/dist/ptydata.c               up to 1.1.1.9
	xsrc/external/mit/xterm/dist/ptyx.h                  up to 1.15
	xsrc/external/mit/xterm/dist/resize.c                up to 1.1.1.9
	xsrc/external/mit/xterm/dist/resize.man              up to 1.1.1.5
	xsrc/external/mit/xterm/dist/run-tic.sh              up to 1.1.1.3
	xsrc/external/mit/xterm/dist/screen.c                up to 1.1.1.12
	xsrc/external/mit/xterm/dist/scrollback.c            up to 1.6
	xsrc/external/mit/xterm/dist/scrollbar.c             up to 1.1.1.11
	xsrc/external/mit/xterm/dist/svg.c                   up to 1.1.1.2
	xsrc/external/mit/xterm/dist/tabs.c                  up to 1.1.1.6
	xsrc/external/mit/xterm/dist/termcap                 up to 1.1.1.6
	xsrc/external/mit/xterm/dist/terminfo                up to 1.1.1.7
	xsrc/external/mit/xterm/dist/testxmc.c               up to 1.1.1.7
	xsrc/external/mit/xterm/dist/trace.c                 up to 1.1.1.13
	xsrc/external/mit/xterm/dist/trace.h                 up to 1.1.1.13
	xsrc/external/mit/xterm/dist/util.c                  up to 1.1.1.13
	xsrc/external/mit/xterm/dist/uxterm                  up to 1.1.1.3
	xsrc/external/mit/xterm/dist/uxterm.desktop          up to 1.1.1.5
	xsrc/external/mit/xterm/dist/uxterm.man              up to 1.1.1.3
	xsrc/external/mit/xterm/dist/version.c               up to 1.1.1.5
	xsrc/external/mit/xterm/dist/version.h               up to 1.1.1.16
	xsrc/external/mit/xterm/dist/vms.c                   up to 1.1.1.4
	xsrc/external/mit/xterm/dist/wcwidth.c               up to 1.1.1.6
	xsrc/external/mit/xterm/dist/xcharmouse.h            up to 1.1.1.5
	xsrc/external/mit/xterm/dist/xstrings.c              up to 1.1.1.10
	xsrc/external/mit/xterm/dist/xterm.appdata.xml       up to 1.1.1.3
	xsrc/external/mit/xterm/dist/xterm.dat               up to 1.1.1.3
	xsrc/external/mit/xterm/dist/xterm.h                 up to 1.3
	xsrc/external/mit/xterm/dist/xterm.log.html          up to 1.1.1.16
	xsrc/external/mit/xterm/dist/xterm.man               up to 1.17
	xsrc/external/mit/xterm/dist/xterm_io.h              up to 1.1.1.7
	xsrc/external/mit/xterm/dist/xtermcap.c              up to 1.1.1.9
	xsrc/external/mit/xterm/dist/xtermcfg.hin            up to 1.1.1.13
	xsrc/external/mit/xterm/dist/xutf8.c                 up to 1.1.1.6
	xsrc/external/mit/xterm/dist/icons/filled-xterm.svg  up to 1.1.1.2
	xsrc/external/mit/xterm/dist/icons/mini.xterm.svg    up to 1.1.1.2
	xsrc/external/mit/xterm/dist/icons/terminal_48x48.svg up to 1.1.1.2
	xsrc/external/mit/xterm/dist/icons/xterm-color.svg   up to 1.1.1.2
	xsrc/external/mit/xterm/dist/icons/xterm.svg         up to 1.1.1.2
	xsrc/external/mit/xterm/dist/package/xterm.spec      up to 1.1.1.11
	xsrc/external/mit/xterm/dist/package/debian/changelog up to 1.1.1.11
	xsrc/external/mit/xterm/dist/package/debian/compat   up to 1.1.1.2
	xsrc/external/mit/xterm/dist/package/debian/control  up to 1.1.1.5
	xsrc/external/mit/xterm/dist/package/debian/copyright up to 1.1.1.7
	xsrc/external/mit/xterm/dist/package/debian/rules    up to 1.1.1.8
	xsrc/external/mit/xterm/dist/package/debian/watch    up to 1.1.1.2
	xsrc/external/mit/xterm/dist/package/freebsd/Makefile up to 1.1.1.7
	xsrc/external/mit/xterm/dist/package/freebsd/pkg-descr up to 1.1.1.2
	xsrc/external/mit/xterm/dist/unicode/convmap.pl      up to 1.1.1.3
	xsrc/external/mit/xterm/dist/unicode/keysym.map      up to 1.1.1.3
	xsrc/external/mit/xterm/dist/vttests/256colors2.pl   up to 1.1.1.6
	xsrc/external/mit/xterm/dist/vttests/88colors2.pl    up to 1.1.1.6
	xsrc/external/mit/xterm/dist/vttests/closest-rgb.pl  up to 1.1.1.2
	xsrc/external/mit/xterm/dist/vttests/dynamic.pl      up to 1.1.1.4
	xsrc/external/mit/xterm/dist/vttests/paste64.pl      up to 1.1.1.5
	xsrc/external/mit/xterm/dist/vttests/query-color.pl  up to 1.1.1.4
	xsrc/external/mit/xterm/dist/vttests/query-fonts.pl  up to 1.1.1.3
	xsrc/external/mit/xterm/dist/vttests/query-status.pl up to 1.1.1.2
	xsrc/external/mit/xterm/dist/vttests/tcapquery.pl    up to 1.1.1.6
	xsrc/external/mit/xterm/include/xtermcfg.h           up to 1.15

Import Xterm 366, changes too numerous to list, main fix is for CVE-2021-27135:
 * correct upper-limit for selection buffer, accounting for combining
   characters
@
text
@a0 159
#!/usr/bin/env perl
# $XTermId: mouse-codes,v 1.7 2020/12/13 15:07:02 tom Exp $
# -----------------------------------------------------------------------------
# this file is part of xterm
#
# Copyright 2018-2019,2020 by Thomas E. Dickey
#
#                         All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name(s) of the above copyright
# holders shall not be used in advertising or otherwise to promote the
# sale, use or other dealings in this Software without prior written
# authorization.
# -----------------------------------------------------------------------------
# Imitate xterm's BtnCode() function, to enumerate the possible inputs (button,
# event state) versus output (xterm mouse-code).
use strict;
use warnings;

use Getopt::Std;

our ( $opt_b, $opt_i, $opt_x );

# Typically,
# -	Buttons 1, 2, and 3 are left-to-right assignments on a 3-button mouse.
# -	Buttons 4 and 5 are (by convention) assigned to a wheel mouse's
#	up/down events.
# -	Buttons 6 and 7 may happen to work, e.g., as left/right events from a
#	tiltable wheel mouse.  There is no explicit support for these (there
#	are no related symbols in Xt), so it is not possible to use them in the
#	translations resource.
our $maxbutton = 7;

# xterm uses code 3 internally for release-events.
sub ButtonName($) {
    my $code   = shift;
    my $result = "";
    if ( $code < 0 ) {
        $result = "release";
    }
    else {
        $result = sprintf "Button%d", ( $code > 3 ) ? $code : ( $code + 1 );
    }
    return $result;
}

# Combine the modifier state as bits:
#  shift key   -> 1
#  meta key    -> 2 (Mod1 came from X11R1, but was adapted from X10)
#  control key -> 4
our $maxstates = 7;

sub KeyState($) {
    my $mask   = shift;
    my $result = "";
    $result .= " + shift"   if ( ( $mask & 1 ) != 0 );
    $result .= " + meta"    if ( ( $mask & 2 ) != 0 );
    $result .= " + control" if ( ( $mask & 4 ) != 0 );
    return $result;
}

sub Motion($) {
    my $code   = shift;
    my $result = "";
    $result = " + motion" if ( $code != 0 );
    return $result;
}

sub report() {
    my $button;
    my $states;
    my $motion;
    my %encoded;
    my %reports;
    for $states ( 0 .. $maxstates ) {
        for $motion ( 0 .. 1 ) {
            for $button ( -1 .. $maxbutton ) {
                next if ( $button == 3 );
                my $result = ( 32 + ( $states << 2 ) );
                $result += 32 if ( $motion != 0 );
                if ( $button < 0 ) {
                    $result += 3;
                }
                else {
                    $result += $button & 3;
                    if ( $button & 4 ) {
                        $result += 64;
                    }
                    if ( $button & 8 ) {
                        $result += 128;
                    }
                }
                my $code   = sprintf "%3d",    $result;
                my $report = sprintf "%s%s%s", &ButtonName($button),
                  &KeyState($states), &Motion($motion);
                if ( defined $encoded{$code} ) {
                    printf "OOPS %s ->%s versus %s\n", $code, $report,
                      $encoded{$code};
                }
                elsif ( $result > 255 and not defined $opt_x ) {
                    printf "OOPS %s ->%s\n", $code, $report;
                }
                $encoded{$code}   = $report;
                $reports{$report} = $result;
            }
        }
    }
    if ($opt_i) {
        foreach my $report ( sort keys %reports ) {
            printf "%s = %s\n", $report, $reports{$report};
        }
    }
    else {
        foreach my $code ( sort keys %encoded ) {
            printf "%s = %s\n", $code, $encoded{$code};
        }
    }
}

sub main::HELP_MESSAGE() {
    printf STDERR <<EOF
Usage: $0 [options]

Options:
	-b NUM	set the number of buttons (default: 7)
	-i	invert the report to show code for each combination
	-x	eliminate 1-byte limit for codes
EOF
      ;
    exit 1;
}
$Getopt::Std::STANDARD_HELP_VERSION = 1;
&getopts('b:ix') || &main::HELP_MESSAGE;
$maxbutton = $opt_b if ( defined $opt_b );
&main::HELP_MESSAGE if ( $maxbutton !~ /^\d+$/ );
$#ARGV < 0 || &main::HELP_MESSAGE;

&report;

1;
@


