[comp.sources.misc] v04i030: GNU Emacs Mouse Editing on tty-5620 - Part 1 of 3

heiser@ethz.UUCP (Gernot Heiser) (08/13/88)

Posting-number: Volume 4, Issue 30
Submitted-by: "Gernot Heiser" <heiser@ethz.UUCP>
Archive-name: gnumacs-blit/Part1

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 3)."
# Contents:  5620m 5620m/5620.h 5620m/5620m 5620m/5620mstty.c
#   5620m/5620mtset 5620m/Makefile 5620m/menu.c 5620m/out.c
#   5620m/term.c MANIFEST README emacs emacs/term emacs/term/5620x.el
# Wrapped by heiser@eiger on Sun Aug  7 14:15:57 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test ! -d '5620m' ; then
    echo shar: Creating directory \"'5620m'\"
    mkdir '5620m'
fi
if test -f '5620m/5620.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'5620m/5620.h'\"
else
echo shar: Extracting \"'5620m/5620.h'\" \(6151 characters\)
sed "s/^X//" >'5620m/5620.h' <<'END_OF_FILE'
X/*
X * 5620_mouse - A layers program able to send mouse coordinates but otherwise
X *              behaving like a normal layer
X *
X * Version 2.2
X *
X * Public domain software.
X * Written by Gernot Heiser (heiser@ethz.uucp) in April 1987
X * based on the vt100 terminal emulator by Leif Samuelsson
X *    as modified by Peter Lamb
X * History :
X *   Version 1.3, Gernot Heiser, Stefan Zeiger, July 1987:
X *      selection feedback
X *   Version 1.4, Gernot Heiser, August 1987:
X *      different selection kinds; special ESC-sequence for selection
X *   Version 1.5, Gernot Heiser, September 1987:
X *      define characteristics of layers to clone in startup file
X *      ensure mouse coordinates are sent "as seen"
X *      box cursor when layer is inactive
X *   Version 1.6, Gernot Heiser, September 1987:
X *      scroll bars
X *   Version 2.0, Gernot Heiser, 1988-02-27:
X *      adapted to mux
X *   Version 2.2, Gernot Heiser, 1988-07-13:
X *      compressed mouse sequences, small fixes
X */
X
X/* include file containing global definitions */
X
X#ifdef MUX
X
X#include <jerq.h>
X#include <layer.h>
X#include <jerqproc.h>
X#include <msgs.h>
X#include <font.h>
X
X#else
X
X#define PANDORA
X#include <dmd.h>
X#include <layer.h>	/* to keep lint quiet */
X#include <dmdproc.h>
X#include <msgs.h>
X#include <font.h>
X#define mpxnewwind
X#define newwindow
X#define dellayer
X#define newlayer
X#define newproc
X#define upfront
X#include <pandora.h>
X
X#endif
X
X#undef button1
X#undef button2
X#undef button3
X#undef button123
X#undef display
X
X#define Mouse		(((struct udata *)P->data)->mouse)
X#define r_butt()        (Mouse.buttons & 4)
X#define m_butt()        (Mouse.buttons & 2)
X#define l_butt()        (Mouse.buttons & 1)
X#define any_butt()      (Mouse.buttons & 7)
X#define D_rect		(((struct udata *)P->data)->Drect)
X#define display		(*(P->layer))
X
X#define send_string(s)  sendnchars (strlen (s), s)
X
X#define FALSE 0
X#define TRUE  1
X
Xtypedef short Bool;
X
X#define J_BORDER   8
X#define INSET	   5
X#define BORDER	   2
X#define XMIN     101
X#define YMIN      51
X
Xtypedef Bool int;
X
Xextern int cloned;
Xextern struct tstat clone_info;
Xextern int charwidth;
Xextern int charheight;
X
X
X/* selection kinds: */
X
X#define select        1
X#define copy          2
X#define delete        3
X#define move          4
X#define inv_copy      5   /* these are the inverse patterns */
X#define inv_delete    6
X#define inv_move      7
X#define nbr_patterns  7
X
X
X#define BUFS            32
X
X#define NMENU		5
X
X/* arow is absolute row, taking top_margin into account */
X#define arow	(row + (origin_mode ? (top_margin - 1) : 0))
X
X#define REV	(1<<0)
X#define BOLD	(1<<1)
X#define UNDER	(1<<2)
X
Xstruct tstat {
X	/* Size of screen */
X	int	t_nrows;
X	int	t_ncols;
X
X	/* Cursor and margins */
X	int	t_row;
X	int	t_col;
X	int	t_top_margin;
X	int	t_bottom_margin;
X
X	/* Terminal modes */
X	int	t_graph_att;
X	Bool	t_origin_mode;
X	Bool	t_wrap;
X	Bool	t_kbd_lock;
X	Bool	t_insert_mode;
X	Bool	t_nl_mode;
X	Bool	t_mouse_en;      /* mouse active if in open mode        */
X	Bool    t_scroll_en;     /* scroll bars if in open mode         */
X	Bool    t_open_mode;     /* editing facilities active           */
X	Bool    t_mouse_active;  /* t_open_mode && t_mouse_en           */
X	Bool    t_scroll_active; /* t_open_mode && t_scroll_en          */
X	Bool    t_is_current;
X
X	/* cursor/attribute save area */
X	int	t_save_row;
X	int	t_save_col;
X	int	t_save_graph_att;
X
X	/* Tabs definition */
X	char	t_tabs[132];
X
X	/* input/output buffers */
X	char    t_out_buf[BUFS+1];
X	int     t_buf_ptr;
X	int     t_peek_ch;
X
X	/* Ansi argument parse scratch */
X	int	t_arg[10];
X	int	t_argno;
X
X	/* Bitmap data */
X	Rectangle t_Srect;       /* usable screen area                  */
X	Rectangle t_Trect;       /* screen area proper: Srect-scrollbar */
X	Code	t_clr, t_or;
X
X	/* Menu */
X
X	Menu	t_menu;
X	char	*t_menustrs[NMENU+1];
X
X	/* Buttons */
X
X	int     t_sel_but;     /* selection            */
X	int     t_copy_but;    /* .. .copy selection   */
X	int     t_del_but;     /* ... delete selection */
X	int     t_menu_but;    /* display menu         */
X        int     t_tot_buts;    /* sum of depressed buttons */
X	int     t_select_kind; /* kind of current selection */
X	int     t_cancel;      /* current mouse op is cancelled */
X
X	/* Variables that should be statics (and were once...) */
X	int     t_tock;
X	int	t_cursc;
X	int	t_cursr;
X	int	t_mcol;		/* Mouse cursor variables */
X	int	t_mrow;
X        int     t_mcol_0; 
X	int     t_mrow_0;
X	int     t_mcol_old;
X	int     t_mrow_old;
X	int	t_mcursc;
X	int	t_mcursr;
X	int	t_mbuts;
X
X};
X
X#define nrows		t->t_nrows
X#define ncols		t->t_ncols
X#define row		t->t_row
X#define col		t->t_col
X#define top_margin	t->t_top_margin
X#define bottom_margin	t->t_bottom_margin
X#define origin_mode	t->t_origin_mode
X#define kbd_lock	t->t_kbd_lock
X#define insert_mode	t->t_insert_mode
X#define nl_mode		t->t_nl_mode
X#define graph_att	t->t_graph_att
X#define wrap		t->t_wrap
X#define mouse_en	t->t_mouse_en
X#define scroll_en       t->t_scroll_en
X#define open_mode       t->t_open_mode
X#define mouse_active    t->t_mouse_active
X#define scroll_active   t->t_scroll_active
X#define is_current      t->t_is_current
X#define save_row	t->t_save_row
X#define save_col	t->t_save_col
X#define save_graph_att	t->t_save_graph_att
X#define tabs		t->t_tabs
X#define out_buf         t->t_out_buf
X#define buf_ptr         t->t_buf_ptr
X#define peek_ch         t->t_peek_ch
X#define arg		t->t_arg
X#define argno		t->t_argno
X#define Srect		t->t_Srect
X#define Trect		t->t_Trect
X#define clr		t->t_clr
X#define or		t->t_or
X#define menu		t->t_menu
X#define menustrs	t->t_menustrs
X#define sel_but         t->t_sel_but
X#define copy_but        t->t_copy_but
X#define del_but         t->t_del_but
X#define menu_but        t->t_menu_but
X#define tot_buts        t->t_tot_buts
X#define select_kind     t->t_select_kind
X#define cancel          t->t_cancel
X#define tock            t->t_tock
X#define cursc		t->t_cursc
X#define cursr		t->t_cursr
X#define mcol		t->t_mcol
X#define mrow		t->t_mrow
X#define mcol_0          t->t_mcol_0
X#define mrow_0          t->t_mrow_0
X#define mcol_old        t->t_mcol_old
X#define mrow_old        t->t_mrow_old
X#define mcursc		t->t_mcursc
X#define mcursr		t->t_mcursr
X#define mbuts		t->t_mbuts
END_OF_FILE
if test 6151 -ne `wc -c <'5620m/5620.h'`; then
    echo shar: \"'5620m/5620.h'\" unpacked with wrong size!
fi
# end of '5620m/5620.h'
fi
if test -f '5620m/5620m' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'5620m/5620m'\"
else
echo shar: Extracting \"'5620m/5620m'\" \(1112 characters\)
sed "s/^X//" >'5620m/5620m' <<'END_OF_FILE'
X#!/bin/sh
X# 5620m Gernot Heiser (heiser@iis.uucp), 1988-07-16
X
XVERSION="5620m Version 2.2"
X
XJERQDIR=/usr/jerq
XJERQLIB=${JERQDIR}/mbin
XJERQBIN=${JERQDIR}/bin
X
Xld="${JERQBIN}/32ld ${JERQLIB}/5620m.m"
X
Xdebug=no
Xusefile=no
Xdoit=yes
Xcmd=
X
Xwhile true
Xdo
X   case $1 in
X   -d)	debug=yes
X	shift;;
X   -D)	set -vx
X	shift;;
X   -f)	shift
X	file=$1
X	shift
X	if [ -f $file ]; then
X		usefile=yes
X	fi
X	break;;
X   -n)	cmd=echo
X	shift;;
X   *)	break;;
X   esac
Xdone
X
Xif ismux - ; then
X   :
Xelse
X   echo -n "$0: Error: must be run under mux" 1>&2
X   exit 1
Xfi
X
Xstart_cmd='eval `5620mtset -f`'
Xcase $SHELL in
Xcsh|*/csh|nsh|*/nsh)
X   start_cmd="set noglob;${start_cmd}" ;;
Xesac
X
Xtrap "stty crt; exit 1" 2 3 4 9 10 11 12
X
Xstatus=0
Xif [ $usefile = "yes" ]; then
X#   $ld -a "$start_cmd" -c "`cat $file`" "$@"
X   $cmd $ld -a "$start_cmd" -c "`cat $file`"
X   status=$?
Xelse
X   $cmd $ld -a "$start_cmd"
X   status=$?
Xfi
X
Xif [ $status != 0 ]; then
X   stty echo
X   exit $status
Xfi
X
Xif [ "$cmd" = "" ]; then
X   eval `5620mtset -s`
Xelse
X   echo 'eval `5620mtset -s`'
Xfi
Xecho $VERSION
X
Xif [ $# != 0 ]; then
X   $cmd $SHELL -c "$*"
Xfi
X$cmd exec $SHELL
END_OF_FILE
if test 1112 -ne `wc -c <'5620m/5620m'`; then
    echo shar: \"'5620m/5620m'\" unpacked with wrong size!
fi
chmod +x '5620m/5620m'
# end of '5620m/5620m'
fi
if test -f '5620m/5620mstty.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'5620m/5620mstty.c'\"
else
echo shar: Extracting \"'5620m/5620mstty.c'\" \(280 characters\)
sed "s/^X//" >'5620m/5620mstty.c' <<'END_OF_FILE'
X /*
X  * 5620mstty Gernot Heiser (heiser@iis.uucp) 1988-07-16
X  *
X  * Fix terminal in a mux layer. Do an `stty crt echo' afterwards for the usual
X  * tty settings.
X  */
X
X#include <sys/ioctl.h>
X#include <sys/jioctl.h>
X
Xmain ()
X{
X   int x = 0;
X   return ioctl (0, JIOCTL, &x) < 0;
X}
END_OF_FILE
if test 280 -ne `wc -c <'5620m/5620mstty.c'`; then
    echo shar: \"'5620m/5620mstty.c'\" unpacked with wrong size!
fi
# end of '5620m/5620mstty.c'
fi
if test -f '5620m/5620mtset' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'5620m/5620mtset'\"
else
echo shar: Extracting \"'5620m/5620mtset'\" \(1915 characters\)
sed "s/^X//" >'5620m/5620mtset' <<'END_OF_FILE'
X#!/bin/sh
X#	5620mtset Gernot Heiser (heiser@iis.uucp) 1988-07-16
X#
X# This program writes to the standard output the commands required to
X# correctly set the terminal environment in a 5620m layer. The program
X# should therefore be installed on all machines, not only the ones
X# where mux is installed.
X#
X# The normal (interactive) use, e.g. to set TERMCAP after an rlogin,
X# is
X#	eval `5620mtset`
X# Note that csh users must
X#	set noglob
X# first.
X#
X# The -f option is used by 5620m to initially setup the terminal in
X# the layer. It causes the terminal to be reverted from a funny mux
X# state to usual settings (echo, crt). The latter is done by the
X# program `5620mstty'. Note that the -f option is only needed for
X# initial setup, therefore `5620mstty' needs only to be installed
X# where mux is installed.
X#
X# The -c and -s options force the commands to be in /bin/csh or
X# /bin/sh format respectively. This is useful in shell scripts
X# executed by a shell other than the user's default shell.
X#
X# Warning: This program is rather tricky and, after lots of trial and
X# error, appears to be working now. Don't change it, unless you are
X# sure to know what you are doing!!!
X#
X
Xexport SHELL
Xfixtty=no
X
Xwhile true; do
X   case $1 in
X   -c)	SHELL=/bin/csh
X	shift;;
X   -f)  fixtty=yes
X	shift;;
X   -s)	SHELL=/bin/sh
X	shift;;
X   *)	break;;
X   esac
Xdone
X
Xif [ $# != 0 ]; then
X   echo usage: eval \`$0 [-c -e -f -s]\` 1>&2
X   exit 1
Xfi
X
Xif [ $fixtty != "yes" ]; then
X   stty -echo > /dev/tty
Xfi
X
Xecho -n "[?C" > /dev/tty
Xcmd=
Xread temp
Xwhile true; do
X	case $temp in
X		\[\?[0-9]*\;[0-9]*C)
X			break;;
X		*)
X			cmd="${cmd};$temp"
X			read temp ;;
X	esac
Xdone
X
Xsize="`echo $temp | \
X	sed -e 's/\[?\([0-9][0-9]*\);\([0-9][0-9]*\)C/co#\2:li#\1/`"
X
Xtset -s -Q 5620x | sed -e "s/co#[0-9][0-9]*:li#[0-9][0-9]*/${size}/"
Xif [ "$cmd" != "" ]; then
X   echo "$cmd"
Xfi
X
Xif [ $fixtty = "yes" ]; then
X   5620mstty
Xfi
Xstty echo crt > /dev/tty
END_OF_FILE
echo shar: 3 control characters may be missing from \"'5620m/5620mtset'\"
if test 1915 -ne `wc -c <'5620m/5620mtset'`; then
    echo shar: \"'5620m/5620mtset'\" unpacked with wrong size!
fi
chmod +x '5620m/5620mtset'
# end of '5620m/5620mtset'
fi
if test -f '5620m/Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'5620m/Makefile'\"
else
echo shar: Extracting \"'5620m/Makefile'\" \(455 characters\)
sed "s/^X//" >'5620m/Makefile' <<'END_OF_FILE'
XBIN=/usr/local/bin
XMAN=/usr/local/man
XDMD=/usr/jerq
XJERQLIB=$(DMD)/mbin
XJERQBIN=$(DMD)/bin
X
XCC=$(DMD)/bin/3cc
XCFLAGS=-DMUXTERM
X
Xall: 5620m.m 5620mstty
X
XOBJS=5620.o out.o term.o menu.o
X
X5620m.m: $(OBJS)
X	$(CC) -o 5620m.m $(OBJS)
X
X5620mstty:	5620mstty.c
X	/bin/cc -o $@ $*.c
X
Xinstall: 5620m.m 5620mstty
X	cp 5620m $(JERQBIN)
X	cp 5620m.m $(JERQLIB)
X	cp 5620mstty 5620mtset $(BIN)
X	cp 5620m.9 $(MAN)/man9
X
Xclean:
X	rm $(OBJS) 5620m.m 5620mstty
X	
X$(OBJS): 5620.h
END_OF_FILE
if test 455 -ne `wc -c <'5620m/Makefile'`; then
    echo shar: \"'5620m/Makefile'\" unpacked with wrong size!
fi
# end of '5620m/Makefile'
fi
if test -f '5620m/menu.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'5620m/menu.c'\"
else
echo shar: Extracting \"'5620m/menu.c'\" \(2187 characters\)
sed "s/^X//" >'5620m/menu.c' <<'END_OF_FILE'
X/*
X * 5620_mouse - A layers program able to send mouse coordinates but otherwise
X *              behaving like a normal layer
X *
X * Version 2.2
X *
X * Public domain software.
X * Written by Gernot Heiser (heiser@ethz.uucp) in April 1987
X * based on the vt100 terminal emulator by Leif Samuelsson
X *    as modified by Peter Lamb
X * History :
X *   Version 1.3, Gernot Heiser, Stefan Zeiger, July 1987:
X *      selection feedback
X *   Version 1.4, Gernot Heiser, August 1987:
X *      different selection kinds; special ESC-sequence for selection
X *   Version 1.5, Gernot Heiser, September 1987:
X *      define characteristics of layers to clone in startup file
X *      ensure mouse coordinates are sent "as seen"
X *      box cursor when layer is inactive
X *   Version 1.6, Gernot Heiser, September 1987:
X *      scroll bars
X *   Version 2.1, Gernot Heiser, 1988-05-29:
X *      fixed several problems with mux version
X *   Version 2.2, Gernot Heiser, 1988-07-13:
X *      small fixes
X */
X
X/* 5620 menu stuff */
X
X#include "5620.h"
X
X#define CLONE 0
X#define INVERT 1
X#define RESET 2
X#if FALSE
X#define SENDSN 3
X#define EXIT 4
X#else /* ! FALSE */
X#define EXIT 3
X#endif /* ! FALSE */
X
Xchar Clone[]   = "clone";
Xchar Invert[]  = "invert";
Xchar Reset[]   = "reset";
Xchar Send[]    = "send";
Xchar Exit[]    = "exit";
X
Xinit_menu(t)
Xregister struct tstat *t;
X{
X	menu.item   = menustrs;
X	menu.prevhit = menu.prevtop = 0;
X	menu.generator = 0;
X	menustrs[CLONE]  = Clone;
X	menustrs[INVERT] = Invert;
X#ifdef MUX
X	menustrs[RESET]  = Reset;
X#if FALSE
X        menustrs[SENDSN] = Send;
X#endif /* FALSE */
X        menustrs[EXIT]   = Exit;
X#else
X	menustrs[RESET]  = 0;
X        menustrs[EXIT]   = 0;
X#endif
X        menustrs[NMENU]  = 0;
X}
X
Xdo_menu(t, n)
Xregister struct tstat *t;
X{
X	extern void clone_0();
X
X	switch(menuhit(&menu, n)) {
X	case CLONE:
X		if (!cloned)
X			((char **)P->text)[-1] = 0;
X		clone_info = *t;
X		newwindow (clone_0);
X		break;
X	case INVERT:
X		inverse_vid (t, clr == F_CLR);
X		break;
X        case RESET:
X                do_reset (t);
X		break;
X#if FALSE
X#ifdef MUX
X        case SENDSN:
X                send_snarf (t);
X		break;
X#endif /* MUX */
X#endif /* FALSE */
X	case EXIT:
X		exit ();
X		break;
X	}
X}
END_OF_FILE
if test 2187 -ne `wc -c <'5620m/menu.c'`; then
    echo shar: \"'5620m/menu.c'\" unpacked with wrong size!
fi
# end of '5620m/menu.c'
fi
if test -f '5620m/out.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'5620m/out.c'\"
else
echo shar: Extracting \"'5620m/out.c'\" \(15796 characters\)
sed "s/^X//" >'5620m/out.c' <<'END_OF_FILE'
X/*
X * 5620_mouse - A layers program able to send mouse coordinates but otherwise
X *              behaving like a normal layer
X *
X * Version 2.2
X *
X * Public domain software.
X * Written by Gernot Heiser (heiser@ethz.uucp) in April 1987
X * based on the vt100 terminal emulator by Leif Samuelsson
X *    as modified by Peter Lamb
X * History :
X *   Version 1.1, Gernot Heiser, added scroll-region, repeat-char
X *   Version 1.3, Gernot Heiser July 1987:
X *     selection feedback
X *   Version 1.4, Gernot Heiser, August 1987:
X *      different selection kinds; special ESC-sequence for selection
X *   Version 1.5, Gernot Heiser, September 1987:
X *      define characteristics of layers to clone in startup file
X *      ensure mouse coordinates are sent "as seen"
X *      box cursor when layer is inactive
X *   Version 1.6, Gernot Heiser, September 1987:
X *      scroll bars
X *   Version 1.8, Gernot Heiser, October 1987:
X *      fixed reset bug, set layer size in TERMCAP string
X *   Version 1.9, Gernot Heiser, 1988-02-02:
X *      automatically report layer resize
X *   Version 2.2, Gernot Heiser, 1988-07-13:
X *      compressed mouse sequences, small fixes
X */
X
X/* 5620 terminal output routines */
X
X/* not yet implemented:
X      "Set PF Key" (ESC [ k;n q string)
X   additional (non-5620) features:
X      received codes:
X         clear_bos, clear_bol,
X         parameters for cursor movements
X         send-terminal-id  (\ez [identical to \e[c])
X         set-scroll-region (\e[%i%d;%dr)
X         repeat-char       (\e[R%.%dR [this is not ANSI])
X	 send-window-size  (\e[?C)
X         mouse on/off      (\e[?%dm          mouse_en  = par!=0)
X         scrollbar on/off  (\e[?%ds          scroll_en = par!=0)
X         open mode on/off  (\e[?%dh \e[?%dl)
X         define buttons    (\e[?%d;%d;%db)
X        <send-snarf-buffer (\e[?%dp [not implemented])>
X        <set-snarf-buffer  (\e[?%dP%s [not implemented])>
X      sent codes:
X         window-size       (\e[?%d;%dC)
X	<mouse-cursor      (\e[?%i%d;%i%d;%dR [no longer sent])>
X	 mouse-cursor      (\e[?%i%d;%d;%d;%d;%dQ [from pt, to pt, buts])
X	 selection-region  (\e[?%i%d;%d;%d;%d;%dS)
X	 resized           (\e[?c\n)
X */
X
X#include "5620.h"
X
X
X
Xstatic char i_am_5620[]  = "\033[??8;7;5c";
X
X/* nextch - read output and interpret control characters (as far as interpreted
X            by 5620).
X *	    Return first 5620 graphic character.
X */
Xint nextch(t)
Xregister struct tstat *t;
X{
X	register int ch;
X
X    while ((ch = wreceive(t)) >= 0) {
X	switch (ch) {
X	    case '\007':		/* Bell */
X		ringbell();
X		break;
X	    case '\b':			/* BackSpace */
X		    if (col > 1) {
X			col--;
X		    }
X		break;
X	    case '\t':			/* Tab */
X		while (col < ncols && !tabs[col++]);
X		break;
X	    case '\n':			/* Line Feed */
X		do_linefeed(t);
X		if(!nl_mode)
X			break;
X		/* Otherwise FALL THROUGH!! */
X	    case '\r':			/* Carriage Return */
X		if (col > 1) {
X		    col = 1;
X		}
X		break;
X	    case '\021':		/* Ignore ^Q/^S */
X	    case '\023':
X	        break;
X	    default:
X		    return(ch);
X	}
X    }
X    return(ch);
X} /* nextch */
X
X
X/* handle_output - Main loop of output process.
X *		   Reads and dispatches characters from output stream.
X */
Xhandle_output(t)
Xregister struct tstat *t;
X{
Xregister int ch;
X
X    while ((ch = nextch(t)) >= 0) {
X	if (ch == '\033') {		/* Escape character */
X	    do_ansi_escape(t);
X	}
X	else {          		/* 5620 printing character */
X	    if (col >= ncols) {
X		splat(t, ch);
X		if (wrap) {
X		    col = 1;
X		    do_linefeed(t);
X		  }
X	    }
X	    else {                     /* receive (and buffer) chars as     */
X	        buf_ptr = 1;           /* available and fit on line, then   */
X		out_buf[0] = ch;       /* output the whole string           */
X		ch = -1;
X		while (col+buf_ptr < ncols && buf_ptr < BUFS
X		       && (ch = rcvchar()) >= ' ' && ch < '\177') {
X			  out_buf[buf_ptr++] = ch;
X			  ch = -1;
X		}
X		out_buf [buf_ptr] = '\0';
X		peek_ch = ch;
X		splat_n(t);
X		col += buf_ptr;
X	    }
X	}
X    }
X} /* handle_output */
X
X
X/* do_ansi_escape - reads and interprets an ANSI escape sequence
X */
X
Xdo_ansi_escape(t)
Xregister struct tstat *t;
X{
Xregister int ch;
X
X    if ((ch = nextch(t)) < 0)
X	return;
X    switch (ch) {
X	case '7':
X	    save_row = row;
X	    save_col = col;
X	    save_graph_att = graph_att;
X	    break;
X	case '8':
X	    if (save_row > 0) {
X		row = save_row;
X		col = save_col;
X	        graph_att = save_graph_att;
X	    } break;
X
X	case '[':
X	    do_csi(t); break;
X
X	case 'c':
X	    do_reset(t); break;
X
X	case 'z':
X	    sendnchars(sizeof i_am_5620 - 1, i_am_5620); break;
X
X    }
X} /* do_ansi_escape */
X
X
X/* do_csi - the real ANSI interpreter
X */
Xdo_csi(t)
Xregister struct tstat *t;
X{
Xregister int i, ch;
Xint private;
X
X    if ((ch = nextch(t)) < 0)
X	return;
X
X    /* Check if private 5620 ESC sequence */
X    private = 0;
X    if (ch == '?') {
X	private++;
X	if ((ch = nextch(t)) < 0)
X	    return;
X    }
X
X    if((ch = do_args(t, ch)) < 0)
X	return;
X
X    if (private) {
X	switch (ch) {
X	   case 'b':         /* define buttons */
X	                     /* "m;s;c"  m=menu, s=selection, c=copy */
X	                     /*    = 0: feature disabled,            */
X	                     /*    > 7: leave previous setting       */
X	      if ((i=argno) > 0) {
X		 if (arg[0] < 7) {
X		    menu_but = arg[0];
X		    if (sel_but & menu_but) {
X		       sel_but = 0;
X		     }
X		  }
X	       }
X	      if (i > 1) {
X		 if (arg[1] < 7) {
X		    sel_but = arg[1];
X		    if (sel_but != 0 && copy_but != 0) {
X		       if (copy_but & sel_but) {
X			  copy_but = 0;
X			  del_but  = 0;
X			}
X		       else {
X			  del_but = 7 & ~(sel_but|copy_but);
X			}
X		     }
X		    if (menu_but == copy_but) {
X		       menu_but = 0;
X		     }
X		  }
X	       }
X	      if (i > 2) {
X		 if (arg[2] < 7) {
X		    copy_but = arg[2];
X		    if (copy_but & sel_but) {
X		       sel_but = 0;
X		     }
X		    if (copy_but == 0 || sel_but == 0) {
X		       del_but = 0;
X		     }
X		    else {
X		       del_but  = 7 & ~(sel_but|copy_but);
X		     }
X		  }
X	       }
X	      break;
X	   case 'C':
X	      send_window_size (t);
X	      break;
X	   case 'h':                    /* start open mode */
X	   case 'l':                    /* end   open mode */
X	      if (argno > 1)
X		 return;
X	      if (open_mode = ch == 'h') {
X		 mcursc = mcursr = -1;
X	      }
X	      if (scroll_active != (open_mode && scroll_en)) {
X		 if (scroll_active = !scroll_active)
X		    install_scrollbar (t);
X		 else
X		    remove_scrollbar (t);
X	      }
X	      mouse_active = open_mode && mouse_en;
X	      break;
X	   case 'm':                    /* enable/disable mouse */
X	      if (argno > 1)
X		 return;
X	      mouse_en     = argno && arg[0];
X	      mouse_active = open_mode   &&  mouse_en;
X	      break;
X#if FALSE
X#ifdef MUX
X           case 'p':                    /* send snarf buffer */
X	      if (argno > 0)
X		 return;
X	      send_snarf (t);
X              break;
X           case 'P':                    /* set snarf buffer */
X	      if (argno != 1)
X		 return;
X              while (arg[0]--) {
X                 while ((ch = wreceive (t)) >= 0) { /* for now dump them */
X                 }                                  /* on the floor */
X              }
X#endif /* MUX */
X#endif /* FALSE */
X	   case 's':                    /* enable/disable scroll bar */
X	      if (argno > 1)
X		 return;
X	      scroll_en    = argno && arg[0];
X	      if (scroll_active != (open_mode && scroll_en)) {
X		 if (scroll_active = !scroll_active)
X		    install_scrollbar (t);
X		 else
X		    remove_scrollbar (t);
X	      }
X	      break;
X	}
X    }
X    else {
X	switch (ch) {
X	    case 'A':
X		i = (argno == 1 && arg[0] > 0) ? arg[0] : 1;
X		while (i-- && row > 1) {
X		    row--;
X		} break;
X
X	    case 'B':
X		i = (argno == 1 && arg[0] > 0) ? arg[0] : 1;
X		while (i-- && row < bottom_margin-top_margin+1) {
X		    row++;
X		} break;
X
X	    case 'C':
X		i = (argno == 1 && arg[0] > 0) ? arg[0] : 1;
X		while (i-- && col < ncols) {
X		    col++;
X		} break;
X
X	    case 'D':
X		i = (argno == 1 && arg[0] > 0) ? arg[0] : 1;
X		while (i-- && col > 1) {
X		    col--;
X		} break;
X
X	    case 'H':
X	    case 'f':
X		do_set_cursor(t); break;
X	    case 'J':
X		do_erase_in_display(t); break;
X	    case 'K':
X		do_erase_in_line(t); break;
X	    case 'L':
X		do_insert_line(t); break;
X	    case 'M':
X		do_delete_line(t); break;
X	    case 'P':
X		do_delete_char(t); break;
X	    case '@':
X		do_insert_char(t); break;
X	    case 'm':
X		do_attributes(t); break;
X	    case 'r':
X		do_set_scroll_region(t); break;
X	    case 'R':
X		if ((ch = nextch(t)) < 0)
X		   return;
X		if (do_args(t, nextch(t)) != 'R')
X		   return;
X		do_repeat_char(t, ch); break;
X	    case 'S':
X		do_scroll(t, TRUE); break;
X	    case 'T':
X		do_scroll(t, FALSE); break;
X	    case 'c':
X		switch (arg[0]) {
X		    case 0:
X			sendnchars(sizeof i_am_5620 - 1, i_am_5620); break;
X		} break;
X	}
X    }
X} /* do_csi */
X
X
Xdo_args(t, ch)
Xregister struct tstat *t;
Xregister int ch;
X{
X    /* Parse arguments */
X    argno = 0;
X    while ((ch >= '0' && ch <= '9') || ch == ';') {
X	arg[argno] = 0;
X	while (ch >= '0' && ch <= '9') {
X	    arg[argno] = arg[argno] * 10 + (ch - '0');
X	    if ((ch = nextch(t)) < 0)
X		return -1;
X	}
X	if (ch == ';')
X	    if ((ch = nextch(t)) < 0)
X		return -1;
X	argno++;
X    }
X
X    return ch;
X} /* do_args */
X
X
Xdo_set_cursor(t)
Xregister struct tstat *t;
X{
X    if (arg[0] == 0)
X	arg[0]++;
X    if (arg[1] == 0)
X	arg[1]++;
X    switch (argno) {
X	case 0:
X	    arg[0] = 1;
X	    argno++;
X	    /* Fall through */
X
X	case 1:
X	    arg[1] = 1;		/* Correct? */
X	    argno++;
X	    /* Fall through... */
X
X	case 2:
X	    row = arg[0];
X	    if (row>bottom_margin) row=bottom_margin;
X	    col = arg[1];
X	    if (col>ncols) col=ncols;
X	    break;
X    }
X} /* do_set_cursor */
X
X
Xsend_reshaped (t)
Xregister struct tstat *t;
X{
X   send_string ("\033[?c\n");
X} /* send_reshaped */
X
X
Xsend_window_size(t)
Xregister struct tstat *t;
X{
X	sendnchars(3, "\033[?");
X	send_num(nrows);
X	sendchar(';');
X	send_num(ncols + (int)scroll_active);
X	sendchar('C');
X        if (! open_mode) {
X           sendchar ('\n');
X        }
X} /* send_window_size */
X
X
Xsend_curs(t)
Xregister struct tstat *t;
X{
X	sendnchars(2, "\033[");
X	send_num(row);
X	sendchar(';');
X	send_num(col);
X	sendchar('R');
X} /* send_curs */
X
X
X#if FALSE
Xsend_mcurs(t, c, r, b)
Xregister struct tstat *t;
X{ /* note that rows and columns are zero-relative but sent one-relative! */
X	sendnchars(3, "\033[?");
X	send_num(r+1);
X	sendchar(';');
X	send_num(c+1);
X	sendchar(';');
X	send_num(b);
X	sendchar('R');
X} /* send_mcurs */
X#endif /* FALSE */
X
X
Xvoid send_region(t, row_0, col_0, row_1, col_1, kind, selection)
Xregister struct tstat *t;
Xint                   row_0, col_0, row_1, col_1, kind;
XBool                  selection;
X{ /* note that rows and columns are zero-relative but sent one-relative! */
X	sendnchars (3, "\033[?");
X	send_num (row_0+1);
X	sendchar (';');
X	send_num (col_0+1);
X	sendchar (';');
X	send_num (row_1+1);
X	sendchar (';');
X	send_num (col_1+1);
X	sendchar (';');
X	sendchar (kind + '0');
X        if (selection) {
X           sendchar ('S');
X        }
X        else {
X           sendchar ('Q');
X        }
X} /* send_region */
X
X
Xsend_num(n)
Xregister int n;
X{
X	register int i;
X	if(i = n/10)
X		send_num(i);
X	sendchar(n%10+'0');
X} /* send_num */
X
X
X#if FALSE
X#ifdef MUX
Xsend_snarf (t)
Xregister struct tstat *t;
X{
X   if (! open_mode) { /* if not open mode append newline */
X      sendchar ('\n');
X   }
X} /* send_snarf */
X#endif /* MUX */
X#endif /* FALSE */
X
X
Xdo_erase_in_display(t)
Xregister struct tstat *t;
X{
X    switch (argno) {
X	case 0:
X	    arg[0] = 0;
X	    argno++;
X	    /* Fall through */
X	case 1:
X	    switch (arg[0]) {
X		case 0:
X		    clear_eos(t);
X		    break;
X		case 1:    /* not really a 5620 sequence, but doesn't harm */
X		    clear_bos(t, col-1, arow-1);
X		    break;
X		case 2:
X		    clear_screen(t);
X		    break;
X	    }
X	    break;
X    }
X} /* do_erase_in_display */
X
X
Xdo_erase_in_line(t)
Xregister struct tstat *t;
X{
X    switch(argno) {
X	case 0:
X	    arg[0] = 0;
X	    argno++;
X	    /* fall through */
X	case 1:
X	    switch (arg[0]) {
X		case 0:
X		    clear_eol(t, col-1, arow-1);
X		    break;
X		case 1:    /* not really a 5620 sequence, but doesn't harm */
X		    clear_bol(t, col-1, arow-1);
X		    break;
X		case 2:    /* not really a 5620 sequence, but doesn't harm */
X		    clear_eol(t, 0, arow-1);
X		    break;
X	    } break;
X    }
X} /* do_erase_in_line */
X
X
X#if FALSE
Xdo_clear_tabs(t)
Xregister struct tstat *t;
X{
Xregister int i;
X
X    if (argno == 0)
X	arg[argno++] = 0;
X    switch (arg[0]) {
X	case 0:
X	    tabs[col-1] = 0; break;
X	case 3:
X	    for (i = 0; i<ncols; i++)
X		tabs[i] = 0; break;
X    } 
X} /* do_clear_tabs */
X#endif
X
X
Xdo_attributes(t)
Xregister struct tstat *t;
X{
Xregister int i;
X
X    if (argno == 0) {
X	arg[0] = 0;
X	argno++;
X    }
X    for (i=0; i<argno; i++) {
X	switch (arg[i]) {
X	    case 0:
X		graph_att = 0;
X		break;
X	    case 1:    /* not really a 5620 sequence, but doesn't harm */
X		graph_att |= BOLD; break;
X
X	    case 4:
X		graph_att |= UNDER; break;
X
X	    case 7:
X		graph_att |= REV; break;
X	}
X    }
X} /* do_attributes */
X
X
Xdo_set_scroll_region(t)
Xregister struct tstat *t;
X{
X    if (arg[0] == 0)
X	arg[0]++;
X    if (arg[1] == 0)
X	arg[1]++;
X    switch (argno) {
X	case 0:
X	    arg[0] = 1;
X	    /* Fall through */
X
X	case 1:
X	    arg[1] = nrows;
X	    argno = 2;
X	    /* Fall through */
X
X	case 2:
X	    top_margin = arg[0];
X	    bottom_margin = arg[1];
X	    col = row = 1;
X	    break;
X    }
X} /* do_set_scroll_region */
X
X
Xdo_repeat_char(t, ch)
X      register struct tstat *t;
X      register int ch;
X{
X   if (argno == 0)
X      return;
X   while (arg[0] > 0) {
X      buf_ptr = 0;
X      while (arg[0] > 0 && col+buf_ptr < ncols && buf_ptr < BUFS) {
X	 out_buf [buf_ptr++] = ch;
X	 arg[0]--;
X      }
X      out_buf [buf_ptr] = '\0';
X      splat_n(t);
X      col += buf_ptr;
X      if (col >= ncols && wrap) {
X	 col = 1;
X	 do_linefeed(t);
X      }
X   }
X} /* do_repeat_char */
X
X
Xdo_linefeed(t)
Xregister struct tstat *t;
X{
X    if (arow == bottom_margin) {
X	scroll_region(t, top_margin-1, bottom_margin-1, 1, TRUE);
X    }
X    else if (arow < nrows) {
X	row++;
X    }
X} /* do_linefeed */
X
X
X#if FALSE
Xdo_reverse_lf(t)
Xregister struct tstat *t;
X{
X    if (arow == top_margin) {
X	scroll_region(t, top_margin-1, bottom_margin-1, 1, FALSE);
X    }
X    else if (arow > 1) {
X	row--;
X    }
X} /* do_reverse_lf */
X#endif
X
X
X/* do_reset - Reset emulator and screen */
Xdo_reset(t)
Xregister struct tstat *t;
X{
X    register int i;
X    void         reshape ();
X
X    graph_att     =
X    sel_but       =
X    copy_but      =
X    del_but       =
X    menu_but      =
X    mbuts         = 0;
X    save_row      = -1;			/* So we know we haven't saved */
X    origin_mode   =
X    kbd_lock      =
X    insert_mode   =
X    nl_mode       =
X    cancel        =
X    mouse_en      =
X    scroll_en     =
X    open_mode     =
X    mouse_active  =
X    scroll_active = FALSE;
X    wrap          = TRUE;
X    reshape (t, FALSE);
X    for (i=0; i<ncols; i++)
X	tabs[i] = ((i/8)*8 == i);
X    inverse_vid (t, FALSE);
X    init_menu (t);
X    clear_screen (t);
X    cursc = cursr = mcursc = mcursr = -1;
X} /* do_reset */
X
X
Xdo_scroll(t, upward)
Xregister struct tstat *t;
Xint upward;
X{
X  scroll_region (t, top_margin-1, bottom_margin-1,
X		 (argno == 1 && arg[0] > 0) ? arg[0] : 1,
X		 upward);
X} /* do_scroll */
X
X
Xdo_insert_line(t)
Xregister struct tstat *t;
X{
X	scroll_region(t, arow-1, bottom_margin-1,
X		      (argno == 1 && arg[0] > 0) ? arg[0] : 1,
X		      FALSE);
X} /* do_insert_line */
X
X
Xdo_delete_line(t)
Xregister struct tstat *t;
X{
X	scroll_region(t, arow-1, bottom_margin-1,
X		      (argno == 1 && arg[0] > 0) ? arg[0] : 1,
X		      TRUE);
X} /* do_delete_line */
X
X
Xdo_insert_char(t)
Xregister struct tstat *t;
X{
X	register int i;
X	i = (argno == 1 && arg[0] > 0) ? arg[0] : 1;
X	ins_nchar(t, i);
X} /* do_insert_char */
X
X
Xdo_delete_char(t)
Xregister struct tstat *t;
X{
X	register int i;
X	i = (argno == 1 && arg[0] > 0) ? arg[0] : 1;
X	del_nchar(t, i);
X} /* do_delete_char */
END_OF_FILE
if test 15796 -ne `wc -c <'5620m/out.c'`; then
    echo shar: \"'5620m/out.c'\" unpacked with wrong size!
fi
# end of '5620m/out.c'
fi
if test -f '5620m/term.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'5620m/term.c'\"
else
echo shar: Extracting \"'5620m/term.c'\" \(12224 characters\)
sed "s/^X//" >'5620m/term.c' <<'END_OF_FILE'
X/*
X * 5620_mouse - A layers program able to send mouse coordinates but otherwise
X *              behaving like a normal layer
X *
X * Version 2.1
X *
X * Public domain software.
X * Written by Gernot Heiser (heiser@ethz.uucp) in April 1987
X * based on the vt100 terminal emulator by Leif Samuelsson
X *    as modified by Peter Lamb
X * History :
X *   Version 1.3, Gernot Heiser, Stefan Zeiger, July 1987:
X *      selection feedback
X *   Version 1.4, Gernot Heiser, August 1987:
X *      different selection kinds; special ESC-sequence for selection
X *   Version 1.5, Gernot Heiser, September 1987:
X *      define characteristics of layers to clone in startup file
X *      ensure mouse coordinates are sent "as seen"
X *      box cursor when layer is inactive
X *   Version 1.6, Gernot Heiser, September 1987:
X *      scroll bars
X *   Version 1.9, Gernot Heiser, 1988-02-02:
X *      test for valid parameters in scroll_region
X *   Version 2.0, Gernot Heiser, 1988-02-27:
X *      adapted to mux
X *   Version 2.1, Gernot Heiser, 1988-05-29:
X *      fixed several problems with mux version
X */
X
X
X/* This module contains termcap and tty routines */
X
X#include "5620.h"
X
X#ifdef MUX
X
XTexture T_grey = {
X	0xaaaa, 0xffff, 0xaaaa, 0xffff, 0xaaaa, 0xffff, 0xaaaa, 0xffff,
X	0xaaaa, 0xffff, 0xaaaa, 0xffff, 0xaaaa, 0xffff, 0xaaaa, 0xffff
X};
X#endif
X
X#define rowy(r)		(Trect.origin.y + (r) * charheight)
X#define colx(c)		(Trect.origin.x + (c) * charwidth)
X
X   /* bitmaps for selection feedback patterns */
Xstatic struct Bitmap feedback_bm [nbr_patterns+1]; /* note: [0] unused! */
X
Xextern
Xvoid init_term(t)
Xregister struct tstat *t;
X{
X#define WordsPerLine ((XMAX-1) / WORDSIZE + 1)
X#define RowsPerLine  20    /* >= charheight */
X
X   /* bitmap storage for selection feedback patterns */
X   static Word feedback_bm_storage [nbr_patterns][RowsPerLine][WordsPerLine];
X
X   int bm, r, i;
X
X   clr = F_CLR; or = F_OR;
X#ifdef MUX
X   charwidth  = P->defaultfont->info['0'].width;
X   charheight = P->defaultfont->height;
X#else
X   charwidth  = defont.info['A'+1].x - defont.info['A'].x;
X   charheight = defont.height + 2;
X#endif
X
X
X   if (cloned)
X      return;
X
X   /* init selection feedback bitmap storage.
X      The first two rows of copy and move bitmaps as well as the last
X      two rows of the delete and copy bitmap are to be filled with the
X      ragged pattern (already contained in the first row of the copy bitmap.
X      All the other rows are to be initialized with all ones bits. */
X
X#define ragged_pat  0xF0F0F0F0
X#define solid_pat   0xFFFFFFFF
X#define ragged_rows 3
X   
X   if (charheight > RowsPerLine) {      /* feedback bitmap too small */
X      exit();
X   }
X
X   for (bm = select; bm <= nbr_patterns; bm++) {
X      for (r = 0; r < charheight; r++) {
X	 for (i=0; i < WordsPerLine; i++) {
X	    if (bm==copy    &&  r <  ragged_rows ||
X		bm==delete  &&  r >= charheight-ragged_rows) {
X		   feedback_bm_storage [bm-1][r][i] =
X		                         ragged_pat;
X	     } else if (bm == move) {   /* move pattern is copy & delete */
X		   feedback_bm_storage [bm-1][r][i] =
X		                         feedback_bm_storage [copy-1][r][i] &
X		                         feedback_bm_storage [delete-1][r][i];
X	     } else if (bm > move) {    /* inverse patterns */
X		   feedback_bm_storage [bm-1][r][i] =
X		                        ~feedback_bm_storage [bm-3-1][r][i];
X	     } else {
X		   feedback_bm_storage [bm-1][r][i] =
X		                         solid_pat;
X	     }
X	  }
X       }
X      feedback_bm [bm].base          = (Word*) feedback_bm_storage [bm-1];
X      feedback_bm [bm].width         = WordsPerLine;
X      feedback_bm [bm].rect.origin.x = 0;
X      feedback_bm [bm].rect.origin.y = 0;
X      feedback_bm [bm].rect.corner.x = XMAX;
X      feedback_bm [bm].rect.corner.y = charheight;
X    }
X}
X
X
X/* clear_bos - clear from beginning of screen to cursor
X */
Xextern
Xclear_bos(t, c, r)
Xregister struct tstat *t;
Xint c,r;
X{
X    cursor_off(t);
X    rectf(&display,
X	Rect(Trect.origin.x, Trect.origin.y, colx(ncols), rowy(r)), clr);
X    clear_bol(t, c,r);
X}
X
X
X/* clear_eos - Clear from cursor to end of screen.
X */
Xextern
Xclear_eos(t)
Xregister struct tstat *t;
X{
X    cursor_off(t);
X    clear_eol(t, col-1,arow-1);
X    rectf(&display,
X	Rect(colx(0), rowy(arow), Trect.corner.x, Trect.corner.y), clr);
X}
X
X
X/* clear_bol - Clear from beginning of line to cursor.
X */
Xextern
Xclear_bol(t, c,r)
Xregister struct tstat *t;
Xint c,r;
X{
X    cursor_off(t);
X    rectf(&display, Rect(colx(0), rowy(r), colx(c), rowy(r+1)), clr);
X}
X
X
X/* clear_eol - Clear from cursor to end of line.
X */
Xextern
Xclear_eol(t, c, r)
Xregister struct tstat *t;
Xint c, r;
X{
X    cursor_off(t);
X    rectf(&display, Rect(colx(c), rowy(r), colx(ncols), rowy(r+1)), clr);
X}
X
X/* Scroll region between lin1 and lin2 inclusive n lines up or down
X */
Xextern
Xvoid scroll_region(t, lin1, lin2, n, upward) 
X      register struct tstat *t;
X      int lin1, lin2, n;
X{
X   cursor_off(t);
X   lin2 = lin2 > bottom_margin-1 ? bottom_margin-1 : lin2;
X   n    = n    > lin2+1-lin1     ? lin2+1-lin1     : n;
X   if (upward) {
X      if (n > 0) {
X         bitblt(&display,
X                Rect(Trect.origin.x, rowy(lin1+n),
X                     Trect.corner.x, rowy(lin2+1)),
X                &display,
X                Pt(Trect.origin.x, rowy(lin1)), F_STORE);
X         rectf(&display, Rect(Trect.origin.x, rowy(lin2+1-n),
X                              Trect.corner.x, rowy(lin2+1)),   clr);
X      }
X   } else {
X      if (n > 0) {
X         bitblt(&display,
X                Rect(Trect.origin.x, rowy(lin1),
X                     Trect.corner.x, rowy(lin2+1-n)),
X                &display,
X                Pt(Trect.origin.x, rowy(lin1+n)), F_STORE);
X         rectf(&display, Rect(Trect.origin.x, rowy(lin1),
X                              Trect.corner.x, rowy(lin1+n)),   clr);
X      }
X   }
X}
X
X
X#define swap(a, b)   {int temp; temp=a; a=b; b=temp;}
X
Xextern
Xvoid hilight_region(t, from_row, from_col, to_row, to_col, kind)
X      register struct tstat *t;
X      int from_row, from_col, to_row, to_col, kind;
X{
X   int t_c;
X   
X   if (from_row>to_row || from_row==to_row && from_col>to_col) {
X      swap (from_row, to_row);
X      swap (from_col, to_col);
X   }
X   
X   for (t_c = ncols; from_row <= to_row; from_row++) {
X      if (from_row == to_row)
X	 t_c = to_col;
X      
X      bitblt (&feedback_bm [kind],
X	      Rect (from_col*charwidth, 0, t_c*charwidth, charheight),
X	      &display,
X	      Pt (colx (from_col), rowy (from_row)),
X	      F_XOR);
X      from_col = 0;
X   }
X}
X
X
Xextern
Xclear_screen(t)
X      register struct tstat *t;
X{
X   cursor_off(t);
X   rectf(&display, Trect, clr);
X   if (scroll_active)
X      rectf  (&display,                           /* redraw scrollbar     */
X	      Rect (Trect.origin.x-BORDER-2, Trect.origin.y,
X		    Trect.origin.x-BORDER-1, Trect.corner.y),   or);
X}
X
X
Xextern
Xcursor_off(t)
X      register struct tstat *t;
X{
X   single_cursor_off(t, &cursc, &cursr, is_current);
X   single_cursor_off(t, &mcursc, &mcursr, &T_grey);
X}
X
X
Xextern
Xcursor_on(t)
X      register struct tstat *t;
X{
X   int r = arow-1, c = col-1;
X   
X   if (is_current != ((own()&MOUSE) != 0)) {
X      single_cursor_off (t, &cursc, &cursr, is_current);
X      is_current = !is_current;
X   }
X   if (is_current && tock || !is_current)
X      single_cursor_on(t, c, r, &cursc, &cursr, is_current);
X   else
X      single_cursor_off(t, &cursc, &cursr, is_current);
X   if (mouse_en && mbuts && !select_kind)  /* not for selection */
X      single_cursor_on(t, mcol, mrow, &mcursc, &mcursr, &T_grey);
X   else
X      single_cursor_off(t, &mcursc, &mcursr, &T_grey);
X}
X
X
Xextern
Xmcursor_off(t)
X      register struct tstat *t;
X{
X   single_cursor_off(t, &mcursc, &mcursr, &T_grey);
X}
X
X
X/* In the following procedures (lastr < 0) indicates the cursor is off.
X   Note that (lastc < 0) means the cursor is in the scroll bar!         */
X
Xstatic
Xsingle_cursor_on(t, c, r, lastc, lastr, tex)
X      register struct tstat *t;
X      int *lastc, *lastr;
X      Texture *tex;
X{
X   if(*lastr >= 0 && (*lastc != c || *lastr != r)) {
X      xcursor(t, *lastc, *lastr, tex);
X      *lastr = -1;
X   }
X   if(*lastr < 0)
X      xcursor(t, *lastc = c, *lastr = r, tex);
X}
X
X
Xstatic
Xsingle_cursor_off(t, lastc, lastr, tex)
X      register struct tstat *t;
X      int *lastc, *lastr;
X      Texture *tex;
X{
X   if(*lastr >= 0) {
X      xcursor(t, *lastc, *lastr, tex);
X      *lastr = -1;
X   }
X}
X
X
Xstatic
Xxcursor(t, c, r, tex)
X      register struct tstat *t;
X      Texture *tex;
X{
X   Rectangle curs_r;
X   if (c < 0) {     /* in scroll bar */
X      curs_r.origin.x = Srect.origin.x - 2;
X      curs_r.corner.x = Trect.origin.x - BORDER - 3;
X   }
X   else {
X      curs_r.origin.x = colx (c);
X      curs_r.corner.x = colx (c+1);
X   }
X   curs_r.origin.y = rowy (r);
X   curs_r.corner.y = rowy (r+1);
X   if (tex == 0 || tex == (Texture *)1) {  /* warning: ugly hack! (gh) */
X      rectf(&display, curs_r, F_XOR);
X      if (tex == 0)
X	 rectf (&display, inset (curs_r, 1), F_XOR);
X   }
X   else
X      texture(&display, curs_r, tex, F_XOR);
X}
X
X
Xextern
Xsplat(t, ch)
X      register struct tstat *t;
X{
X   out_buf[0] = ch;
X   out_buf[1] = '\0';
X   buf_ptr    = 1;
X   splat_n (t);
X}
X
X
Xextern
Xsplat_n(t)
X      register struct tstat *t;
X{
X   Rectangle crect;
X   cursor_off(t);
X   crect.origin.x = colx(col-1);
X   crect.origin.y = rowy(arow-1);
X   crect.corner.x = colx(col-1+buf_ptr);
X   crect.corner.y = rowy(arow);
X   if(insert_mode)
X      bitblt(&display,
X	     Rect(crect.origin.x, crect.origin.y,
X		  Trect.corner.x-charwidth, crect.corner.y),
X	     &display,
X	     Pt(crect.corner.x, crect.origin.y), F_STORE);
X   
X   rectf(&display, crect, clr);
X   string(&defont, out_buf, &display, crect.origin, or);
X   if(graph_att & BOLD)
X      string(&defont, out_buf, &display,
X	     Pt(crect.origin.x+1, crect.origin.y+1), or);
X   if(graph_att & UNDER)
X      rectf(&display,
X	    Rect(crect.origin.x, crect.origin.y+defont.ascent+2,
X		 crect.corner.x, crect.origin.y+defont.ascent+3), or);
X   if(graph_att & REV)
X      rectf(&display, crect, F_XOR);
X}
X
X
Xextern
Xins_nchar(t, n)
X      register struct tstat *t;
X      register int n;
X{
X   Rectangle crect;
X   cursor_off(t);
X   crect.origin.x = colx(col-1);
X   crect.origin.y = rowy(arow-1);
X   crect.corner.x = colx(col-1+n);
X   crect.corner.y = rowy(arow);
X   bitblt(&display,
X	  Rect (crect.origin.x, crect.origin.y,
X		Trect.corner.x-n*charwidth, crect.corner.y),
X	  &display,
X	  Pt(crect.corner.x, crect.origin.y), F_STORE);
X   rectf(&display, crect, clr);
X}
X
X
Xextern
Xdel_nchar(t, n)
X      register struct tstat *t;
X      register int n;
X{
X   Rectangle crect;
X   cursor_off(t);
X   crect.origin.x = colx(col-1);
X   crect.origin.y = rowy(arow-1);
X   crect.corner.x = colx(col-1+n);
X   crect.corner.y = rowy(arow);
X   bitblt(&display,
X	  Rect(crect.corner.x, crect.origin.y,
X	       Trect.corner.x, crect.corner.y),
X	  &display,
X	  Pt(crect.origin.x, crect.origin.y), F_STORE);
X   rectf(&display, Rect(colx(ncols-n), crect.origin.y,
X			Trect.corner.x, crect.corner.y), clr);
X}
X
X
Xextern
Xinverse_vid(t, inv)
X      register struct tstat *t;
X{
X   if(inv && clr == F_CLR) {
X      clr = F_OR; or = F_CLR;
X      goto flip;;
X   } else  if(!inv && clr != F_CLR) {
X      clr = F_CLR; or = F_OR;
X    flip:
X      rectf(&display, D_rect, F_XOR);
X   }
X}
X
X
Xextern
Xinstall_scrollbar (t)
X      register struct tstat *t;
X{
X   Trect.origin.x = Srect.origin.x + Srect.corner.x - colx (--ncols);
X   bitblt (&display,
X	   Rpt (Srect.origin,
X		Pt (Srect.corner.x - (Trect.origin.x - Srect.origin.x),
X		    Srect.corner.y)),
X	   &display, Trect.origin, F_STORE);   /* move screen contents */
X   rectf  (&display, Rpt (Srect.origin, Pt (Trect.origin.x, Trect.corner.y)),
X	   clr);                               /* clear scrollbar      */
X   rectf  (&display,                           /* draw line            */
X	   Rect (Trect.origin.x-BORDER-2, Trect.origin.y,
X		 Trect.origin.x-BORDER-1, Trect.corner.y),   or);
X} /* install_scrollbar */
X
X
Xextern
Xremove_scrollbar (t)
X      register struct tstat *t;
X{
X   bitblt (&display, Trect, &display, Srect.origin, F_STORE);   /* move */
X   Trect.origin.x = Srect.origin.x;
X   rectf  (&display,                            /* clear right column   */
X	   Rpt (Pt (colx (ncols++), Trect.origin.y), Trect.corner), clr);
X} /* remove_scrollbar */
END_OF_FILE
if test 12224 -ne `wc -c <'5620m/term.c'`; then
    echo shar: \"'5620m/term.c'\" unpacked with wrong size!
fi
# end of '5620m/term.c'
fi
if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(672 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X 5620m                      1	
X 5620m/5620.c               2	
X 5620m/5620.h               1	
X 5620m/5620m                1	
X 5620m/5620m.9              2	
X 5620m/5620mstty.c          1	
X 5620m/5620mtset            1	
X 5620m/Makefile             1	
X 5620m/menu.c               1	
X 5620m/out.c                1	
X 5620m/term.c               1	
X MANIFEST                   1	This shipping list
X README                     1	
X emacs                      1	
X emacs/mega-lilith.el       3	
X emacs/mega-lilith.tex      3	
X emacs/term                 1	
X emacs/term/5620x.el        1	
END_OF_FILE
if test 672 -ne `wc -c <'MANIFEST'`; then
    echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(2071 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XThis is a package that allows mouse editing with GNU Emacs (version 18.48 or
Xlater) on a Teletype 5620 terminal running layers or mux.
X
XThe package consists of two parts: The 5620m directory contains the terminal
Xemulator program to be run on the 5620. The emacs directory contains an Emacs
Xelisp program.
X
XThe terminal emulator (among others) encodes mouse button events into escape
Xsequences and sens them down to the host. The elisp program interprets the
Xescape sequences and performs the appropriate editing commands.
X
XThe editing capabilities provided by this package are far superiour to what the
XEmacstool offers for Suntools users. It would be nice to have these features on
Xother terminals or workstations than just the rather rare 5620. Maybe one day
Xsomebody writes something similiar for X-Windows.
X
X
XINSTALLATION
X============
X
X1. Terminal Emulator
X
Xa) adapt the Makefile to local conventions regarding placement of sources,
X   binaries and manuals. If you are using layers, not mux, you will also have
X   to adapt the compiler name in the Makefile and the loder name in the load
X   script 5620m. Some further (minor) modifications may be necessary in this
X   case, the latest version has not been tested under layers.
X
Xb) type "make install"
X
Xc) Adapt $JERQ/bin/term to support loading 5620m. Use the supplied term as a
X   template. (In case you have no other local dmd programs you can just replace
X   $JERQ/bin/term by the supplied term.)
X
XThe last step does not apply to layers versions, nor is it essential for mux.
XIf it is ommitted, the emulator cannot be downloaded in the normal mux fashion
X(i.e. "term 5620m"), it can always be downloaded as "5620m".
X
X2. Elisp Program
X
Xa) copy the files mega-lilith.el into the emacs library $GNUEMACS/lisp
X   and term/5620x.el into $GNUEMACS/lisp/term
X
Xb) byte-compile $GNUEMACS/lisp/mega-lilith.el
X
X
XDOCUMENTATION
X=============
X
X5620m.9 is the troffable UNIX manual describing the terminal emulator.
Xmega-lilith.tex is a TeX report describing the elisp program and the mouse
Xediting capabilities of the package.
END_OF_FILE
if test 2071 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test ! -d 'emacs' ; then
    echo shar: Creating directory \"'emacs'\"
    mkdir 'emacs'
fi
if test ! -d 'emacs/term' ; then
    echo shar: Creating directory \"'emacs/term'\"
    mkdir 'emacs/term'
fi
if test -f 'emacs/term/5620x.el' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'emacs/term/5620x.el'\"
else
echo shar: Extracting \"'emacs/term/5620x.el'\" \(907 characters\)
sed "s/^X//" >'emacs/term/5620x.el' <<'END_OF_FILE'
X;; 5620_mouse terminal initialization (for Mux)
X;;
X;; unbind "\e[" if bound to a function and bind the arrow and clear keys
X;; on the numeric keypad
X;;
X(let ((binding (global-key-binding "\e[")))
X  (cond
X   ((and (not (null binding))
X	 (not (keymapp binding)))
X    (global-unset-key "\e["))))
X;;
X;;
X(global-set-key "\e[D"     'backward-char)         ; left arrow key
X(global-set-key "\e[C"     'forward-char)          ; right arrow key
X(global-set-key "\e[A"     'previous-line)         ; up arrow key
X(global-set-key "\e[B"     'next-line)             ; down arrow key
X(global-set-key "\e[H"     'beginning-of-buffer)   ; home arrow key
X(global-set-key "\e[F"     'end-of-buffer)         ; home down arrow key
X(global-set-key "\e[70;1H" 'end-of-buffer)         ; home down arrow key
X(global-set-key "\e[2J"    'redraw-display)        ; clear key
X;;
X;; load the mouse handling stuff
X;;
X(load "mega-lilith")
END_OF_FILE
if test 907 -ne `wc -c <'emacs/term/5620x.el'`; then
    echo shar: \"'emacs/term/5620x.el'\" unpacked with wrong size!
fi
# end of 'emacs/term/5620x.el'
fi
echo shar: End of archive 1 \(of 3\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 3 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Gernot Heiser <heiser@iis.UUCP> Phone:       +41 1/256 23 48
Integrated Systems Laboratory   CSNET/ARPA:  heiser%ifi.ethz.ch@relay.cs.net
ETH Zuerich                     EARN/BITNET: GRIDFILE@CZHETH5A
CH-8092 Zuerich, Switzerland    EUNET/UUCP:  {uunet,mcvax,...}!iis!heiser