[comp.sources.amiga] v89i178: vt100 - terminal emulator v2.9, Part01/09

page%swap@Sun.COM (Bob Page) (10/20/89)

Submitted-by: acs@pccuts.pcc.amdahl.com (Tony Sumrall)
Posting-number: Volume 89, Issue 178
Archive-name: comm/vt100r29.1

This is version 2.9 of VT100.  This version adds an AREXX port, new
script and AREXX commands, some bug fixes and the ability to use
external protocol modules.  This is NOT an implementation of the XPR
spec by Willy Langeveld of SLAC but a prior incarnation of a similar
idea -- a program external to VT100 which handles a file transfer
protocol (or protocols) -- see vt100.doc for more info.  Also included
are sample AREXX scripts and an implementation of Zmodem by Frank
Anthes.

The distributed version of VT100 assumes you have AREXX.  If you don't
have it and use the distributed version you will get some messages about
AREXX not being around.  The Makefile details how to make a non-AREXX
version.

# This is a shell archive.
# Remove anything above and including the cut line.
# Then run the rest of the file through 'sh'.
# Unpacked files will be owned by you and have default permissions.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar: SHell ARchive
# Run the following text through 'sh' to create:
#	GNU-Emacs/amiga.el
#	Makefile
# This is archive 1 of a 9-part kit.
# This archive created: Thu Oct 19 22:30:28 1989
if `test ! -d GNU-Emacs`
then
  mkdir GNU-Emacs
  echo "mkdir GNU-Emacs"
fi
echo "extracting GNU-Emacs/amiga.el"
sed 's/^X//' << \SHAR_EOF > GNU-Emacs/amiga.el
X;;;
X;;; mg-mouse.el
X;;; Mic Kaczmarczik (mic@emx.cc.utexas.edu)
X;;; 07-Sep-1987
X;;;
X;;; Modifications:
X;;;	11-Sep-1987 MPK		Remember last mouse click in order to set
X;;;				the mark if you click twice on same spot.
X;;;				Implement mg-mouse-set-mark-and-kill to be
X;;;				more intuitive (thanks, Mike)
X;;;
X;;;	20-Sep-1987 MPK		Put gadgets in left hand side of mode line
X;;;	19-Jun-1989 MWM		Take gadgets out of mode line
X;;;
X;;; Makes Emacs respond to mouse click input, based on Mike Meyer's hack
X;;; to VT100 2.6 and x-mouse.el.  Things work like the hot mouse in mg
X;;; (formerly known as MicroGNUEmacs) -- you get different results,
X;;; depending on whether you click on the text in a window, a mode line,
X;;; or the minibuffer down at the bottom of the screen.  See the
X;;; documentation string for mg-mouse-command for the default bindings.
X;;;
X;;; This code doesn't need the GNU X-windows code to work, which Mike's
X;;; original amiga-mouse code did.  Thanks to Mike for the inspiration
X;;; and his documentation (which I have shamelessly quoted from in places).
X;;;
X;;; I'm looking for an easier way for users to rebind what happens when
X;;; they click in a particular area.  Right now you have to manually
X;;; change an a-list, but there's *got* to be a better way.  Oh well, at
X;;; least it works :-)
X;;;
X;;; VT100 mouse hack format:
X;;; 
X;;;	<ESC> M (yes, a real capital M) quals column line
X;;;
X;;; column and line are bytes that just hold the column/line number,
X;;; zero-based and offset by 32. quals is like so:
X;;;
X;;;	bit 0	control key
X;;;	bit 1	shift key
X;;;	bit 2	meta (alt) key
X;;;	bit 3	caps lock
X;;;	bit 4	mouse down event
X;;;	bit 5	mouse up event
X;;;
X;;; Quals is offset by 64, so a shifted downward mouse click on row 1,
X;;; column 1 results in the escape sequence
X;;;	<ESC> M R <SPC> <SPC>
X;;;
X
X;;; 
X;;; Qualifier bit definitions
X;;;
X
X(defconst mg-mouse-vanilla 0)
X(defconst mg-mouse-ctrl 1)
X(defconst mg-mouse-shift 2)
X(defconst mg-mouse-ctrl-shift 3)
X(defconst mg-mouse-alt 4)
X(defconst mg-mouse-ctrl-alt 5)
X(defconst mg-mouse-shift-alt 6)
X(defconst mg-mouse-ctrl-shift-alt 7)
X(defconst mg-mouse-qual-mask 15)
X
X(defconst mg-mouse-capslock 8)
X(defconst mg-mouse-select-down 16)
X(defconst mg-mouse-select-up 32)
X
X;;;
X;;; Actions to take when the mouse is clicked.  When you click in
X;;; the window, mg-mouse-command moves point to where you clicked,
X;;; then calls the action routine as an interactive command.  You can
X;;; rebind these functions by prepending items to the a-list. (Is
X;;; there a better way to do this?)
X;;;
X
X(defvar mg-mouse-previous-click nil
X  "(x, y) position of next-to-last mouse click")
X
X(defvar mg-mouse-click nil
X  "(x, y) position of last mouse click")
X
X(defvar mg-mouse-last-point nil
X  "Position of point just before mg-mouse-set-point moved it.")
X
X;;;
X;;; Things to do...
X;;;
X
X(defvar mg-mouse-window-actions nil
X   "A-list of functions to call when the mouse is clicked in an Emacs window.")
X
X(setq mg-mouse-window-actions
X      (list
X       (cons mg-mouse-vanilla		'mg-mouse-maybe-set-mark)
X       (cons mg-mouse-shift		'top-and-redisplay)
X       (cons mg-mouse-ctrl		'delete-char)
X       (cons mg-mouse-ctrl-shift	'delete-horizontal-space)
X       (cons mg-mouse-alt		'kill-word)
X       (cons mg-mouse-shift-alt		'kill-line)
X       (cons mg-mouse-ctrl-alt		'mg-mouse-set-mark-and-kill)
X       (cons mg-mouse-ctrl-shift-alt	'yank)))
X
X;;;
X;;; Things to do when you click on the mode line of a window.  The
X;;; window is selected, then the function is called interactively.
X;;;
X
X(defvar mg-mouse-mode-actions nil
X   "A-list of functions to call when the mouse is clicked in a mode line.")
X
X(setq mg-mouse-mode-actions
X      (list
X       (cons mg-mouse-vanilla		'mg-mouse-vanilla-mode-line)
X       (cons mg-mouse-shift		'mg-mouse-shift-mode-line)
X       (cons mg-mouse-ctrl		'beginning-of-buffer)
X       (cons mg-mouse-ctrl-shift	'end-of-buffer)
X       (cons mg-mouse-alt		'split-window)
X       (cons mg-mouse-shift-alt		'delete-window)
X       (cons mg-mouse-ctrl-alt		'enlarge-window)
X       (cons mg-mouse-ctrl-shift-alt	'shrink-window)))
X
X;;;
X;;; Things to do when you click in the echo line.
X;;;
X
X(defvar mg-mouse-echo-actions nil
X   "A-list of functions to call when the mouse is clicked in the minibuffer")
X
X(setq mg-mouse-echo-actions
X      (list
X       (cons mg-mouse-vanilla		'save-buffer)
X       (cons mg-mouse-shift		'kill-buffer)
X       (cons mg-mouse-ctrl		'suspend-emacs)
X       (cons mg-mouse-ctrl-shift	'save-buffers-kill-emacs)
X       (cons mg-mouse-alt		'describe-key)
X       (cons mg-mouse-shift-alt		'describe-bindings)
X       (cons mg-mouse-ctrl-alt		'list-buffers)
X       (cons mg-mouse-ctrl-shift-alt	'buffer-menu)))
X
X;;;
X;;; Handle the user's mouse click.  We only pay attention to when
X;;; the mouse button is pressed, not when it is released.
X;;;
X
X(defun mg-mouse-command ()
X"Interpret Amiga mouse clicks from the VT100 program.  The bindings are:
X
X Qualifiers  |			Area clicked
X             |
XC  A  Shift  |	Text window		Mode line	Echo line
X-------------+---------------------------------------------------------
X	     |	dot to mouse		forward page	switch to buffer 
X      X	     |	recenter		back page	kill buffer
X   X	     |	delete word		split window	describe key
X   X  X	     |	kill line		delete window	describe bindings
XX	     |	delete char		goto bob	suspend emacs
XX     X      |	delete whitespace	goto eob	save buffers kill emacs
XX  X	     |	kill region		enlarge window	list buffers
XX  X  X	     |	yank			shrink window	buffer menu
X
XNotice that the Status and Echo groups come in pairs; the shifted
Xversion of a key is in some sense the opposite of the unshifted version.
X
XThere is no opposite for display buffers, so that key is bound to
Xbuffer-menu (it's bound to an Amiga-specific function in Amiga mg).
X"
X  (interactive)
X  (let* ((qual (- (read-char) 64))		;; read the qualifier,
X	 (x (- (read-char) 32))			;; x & y sequentially
X	 (y (- (read-char ) 32))
X	 (click nil)
X	 (actions nil)
X	 (action-routine nil))
X
X    (if (not (zerop (logand qual mg-mouse-select-down)))
X	(progn
X	  (setq click (mg-mouse-select-and-examine (list x y)))
X	  (setq qual (logand qual mg-mouse-qual-mask))
X
X	  ;; get a-list of action routines based on where the click was
X	  (if (not click)
X	      (setq actions mg-mouse-echo-actions)	;; no window
X	    (if (eq (car click) 'mode-line)
X		(setq actions mg-mouse-mode-actions)	;; mode line
X	      (progn
X		(mg-mouse-set-point (cdr click))	;; in text area
X		(setq actions mg-mouse-window-actions))))
X
X	  (setq mg-mouse-previous-click mg-mouse-click)
X	  (setq mg-mouse-click (cdr click))
X
X	  ;; function to call? do it.
X	  (if (setq action-routine (cdr (assoc qual actions)))
X	      (call-interactively action-routine))))))
X      
X(defun mg-mouse-set-point (arg)
X  "Select Emacs window mouse is on, and move point to mouse position."
X  (let* ((rel-x (car arg))
X	 (rel-y (car (cdr arg))))
X
X    (setq mg-mouse-last-point (point))
X    (move-to-window-line rel-y)
X    (move-to-column (+ rel-x (current-column)))))
X
X(defun mg-mouse-select-and-examine (arg)
X  "Select Emacs window the mouse is on, returning a triplet signifying
X   information about where exactly the click took place."
X  (let ((start-w (selected-window))
X	(done nil)
X	(where nil)
X	(w (selected-window))
X	(mouse-click-data nil))
X    (while (and (not done)
X		(null (setq mouse-click-data
X			    (mg-coordinates-in-window-p arg w))))
X      (setq w (next-window w))
X      (if (eq w start-w)
X	  (setq done t)))
X    (select-window w)
X    mouse-click-data))
X
X(defun mg-coordinates-in-window-p (pos w)
X  "Checks coordinate pair POS to see if it falls within window W.
XIf the pair is inside the window, returns a list in the format
X(WHERE REL-X REL-Y), where WHERE is either 'mode-line or
X'inside-window, and REL-X and REL-Y denote the click's coordinates
Xrelative to the window's origin."
X
X  (let* ((edges (window-edges w))
X	 (wl (nth 0 edges)) (wt (nth 1 edges))
X	 (wr (nth 2 edges)) (wb (nth 3 edges))
X	 (x (nth 0 pos))    (y (nth 1 pos)))
X    (if (and (and (>= x wl) (< x wr))
X	     (and (>= y wt) (< y wb)))
X	(list (if (= y (1- wb))
X		  'mode-line 'inside)
X	      (- x wl) (- y wt))
X      nil)))
X
X;;;
X;;; Command functions for special things.  These are commands so we can
X;;; use call-interactively uniformly.
X;;;
X
X(defun mg-mouse-vanilla-mode-line nil
X  "Do a vanilla mode line click: scroll up one page"
X  (interactive)
X  (scroll-up))
X
X(defun mg-mouse-shift-mode-line nil
X  "Do a shifted mode line click: scroll down one page"
X  (interactive)
X  (scroll-down))
X
X(defun mg-mouse-maybe-set-mark nil
X  "Set point if the current and previous clicks in a window were in the
Xsame spot.  This is somewhat naive but usually sufficient :-)."
X  (interactive)
X  (if (equal mg-mouse-previous-click mg-mouse-click)
X      (call-interactively 'set-mark-command)))
X
X(defun mg-mouse-set-mark-and-kill nil
X  "Set mark at old point, set point at where you clicked, then kill the region"
X  (interactive)
X  (set-mark mg-mouse-last-point)
X  (kill-region mg-mouse-last-point (point)))
X
X;;;
X;;; Set up to react to the mouse "key"
X;;;
X
X(global-set-key "\eM" 'mg-mouse-command)
SHAR_EOF
echo "extracting Makefile"
sed 's/^X//' << \SHAR_EOF > Makefile
X######################################################################
X#				:ts=8
X#
X# Makefile to build vt100 terminal emulator
X#
X#	v2.9 ACS - Add newkermit module and AREXX support
X#	v2.8a 880331 ACS - Add CFLAGS and LNFLAGS
X#	v2.7 870825 ACS - See the README file
X#	v2.6 870227 DBW - bug fixes for all the stuff in v2.5
X#	v2.5 870214 DBW - more additions (see readme file)
X#	v2.4 861214 DBW - lots of fixes/additions (see readme file)
X#	v2.3 861101 DBW - minor bug fixes
X#	v2.2 861012 DBW	- more of the same
X#	v2.1 860915 DBW - new features (see README)
X#	     860823 DBW - Integrated and rewrote lots of code
X#	v2.0 860809 DBW	- Major release.. LOTS of changes
X# 	v1.1 860720 DBW	- Switches, 80 cols, colors, bug fixes
X# 	v1.0 860712 DBW	- First version released
X#
X#
X# Don't forget to define the right compiler (MANX or LATTICE) in VT100.H
X#
X# Say:
X#	make CCFLAGS=-n LNFLAGS=-g vt100         -or-
X#	make CCFLAGS=-n LNFLAGS=-g vt100-w
X# for Manx SDB.
X# Say:
X#	make vt100nk
X# to use the new kermit modules.  Likewise, vt100nk-w, as above, for
X# Manx SDB.
X#
X######################################################################
X
X#   Use the following 2 lines if you want AREXX support included
XAREXX 	= -DAREXX
XREXXOBJ = rexxglue.o
X#   Use the following line if you don't have AREXX or you don't want AREXX
X# AREXX	=
X# REXXOBJ =
X
XCFLAGS	= $(CCFLAGS) $(AREXX)
X
XOBJS	= vt100.o init.o window.o xmodem.o remote.o \
X	  kermit.o script.o expand.o rexx.o $(REXXOBJ)
X
XNOBJS	= vt100.o init.o window.o xmodem.o remote.o \
X	  newkermit.o kermitproto.o script.o expand.o rexx.o $(REXXOBJ)
X
Xvt100	: vt100.syms $(OBJS)
X	ln +q -o vt100 $(OBJS) -lc
X
Xvt100nk : vt100.syms $(NOBJS)
X	ln +q -o vt100nk $(NOBJS) -lc
X
Xvt100-w	: vt100.syms $(OBJS)
X	ln +q $(LNFLAGS) -o vt100-w $(OBJS) -lc
X
Xvt100nk-w : vt100.syms $(NOBJS)
X	ln +q $(LNFLAGS) -o vt100nk-w $(NOBJS) -lc
X
Xvt100.syms : vt100.h
X	cc -A +Hvt100.syms $(CFLAGS) vt100.h
X
Xvt100.o	: vt100.c vt100.syms
X	cc +Ivt100.syms $(CFLAGS) vt100.c
X
Xinit.o	: init.c vt100.syms
X	cc +Ivt100.syms $(CFLAGS) init.c
X
Xwindow.o : window.c vt100.syms
X	cc +Ivt100.syms $(CFLAGS) window.c
X
Xxmodem.o : xmodem.c vt100.syms
X	cc +Ivt100.syms $(CFLAGS) xmodem.c
X
Xremote.o : remote.c vt100.syms
X	cc +Ivt100.syms $(CFLAGS) remote.c
X
Xkermit.o : kermit.c vt100.syms
X	cc +Ivt100.syms $(CFLAGS) kermit.c
X
Xnewkermit.o : newkermit.c vt100.syms
X	cc +Ivt100.syms $(CFLAGS) newkermit.c
X
Xkermitproto.o : kermitproto.c kermitproto.h
X	cc $(CFLAGS) kermitproto.c
X
Xscript.o : script.c vt100.syms
X	cc +Ivt100.syms $(CFLAGS) script.c
X
Xexpand.o : expand.c vt100.syms
X	cc +Ivt100.syms $(CFLAGS) expand.c
X
Xrexx.o : rexx.c vt100.syms
X	cc +Ivt100.syms $(CFLAGS) rexx.c
SHAR_EOF
echo "End of archive 1 (of 9)"
# if you want to concatenate archives, remove anything after this line
exit