home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
unix
/
uw_shar.sit
/
uw-42-part1.shar
next >
Wrap
Text File
|
1989-09-14
|
57KB
|
2,121 lines
# ARPANET/MILNET: jdb@mordor.s1.gov
#
# UUCP: {lll-crg,decwrl,caip}!mordor!jdb
#
# U.S. Mail: John Bruner
# Lawrence Livermore National Laboratory
# P.O. Box 5503, L-276
# Livermore, CA 94550
#
#These are comments. You can remove everything above the next
#blank line if you wish.
: This is a shar archive. Extract with sh, not csh.
if test ! -d misc; then
echo mkdir misc
mkdir misc
fi
if test ! -d utility; then
echo mkdir utility
mkdir utility
fi
echo x - README
sed -e 's/^X//' > README << '!EOF!README!'
X UW Version 4.2
X 31 January 1988
X
XThis is version 4.2 of UW, a multiple-window interface to UNIX for
Xthe Macintosh computer. The distribution for UW consists of two
Xbinary files for the Macintosh (in BinHex 4.0 format) and a number
Xof source files for the (BSD) UNIX server.
X
XThe distribution includes the following directories:
X
X h - all UW include files
X server - source code for the UW server
X lib - source code for the UW programmer's library
X utility - source code for miscellaneous utility programs
X doc - [nt]roff documentation (-ms and -man formats)
X hqx - Macintosh binary files
X misc - other things of possible interest
X
XThe two Macintosh files are "uw.hqx", which is the executable binary
Xand "uw.doc.hqx", which is a MacWrite-format document describing the
XMacintosh user interface.
X
XUW was developed alternately on a Sun 3 and 4.3BSD VAX. It also
Xhas been tested (more briefly) on a Sun 2 (release 2.0), Integrated
XSolutions VME 68020 (release 3.05), and a Pyramid. It depends quite a
Xbit upon BSD-specific features such as interprocess communication and
Xwill not run without modification on a System V UNIX system.
X
XThis distribution, like the version 3.4 distribution, includes
Xmake files for both 4.2BSD and 4.3BSD. The choice of make files
Xand other configuration options is determined by the top-level
X"Makefile". Comments in that file describe the configuration options.
X
XA "make install" in the top-level directory will compile and install
Xall of the (UNIX) pieces of the UW distribution. As distributed,
Xthis will create a link between the directory name "/usr/include/uw"
Xand the "h" subdirectory and will create a "/usr/local/bin/libuw.a"
Xlibrary file. These two steps allow application program to use
X #include <uw/uwlib.h>
Xand
X cc -o xyzzy xyzzy.o -luw
Xfor greater convenience in creating programs that use the UW library.
X
XIf you do not have the "getopt" library routine, you will find the
Xsource in "misc/getopt.c" This source code was publicly distributed by
XAT&T and is also available in the "mod.sources" archive. You should
Xcompile it and install it in your machine's "/lib/libc.a" (Note that
Xsince it uses "strchr", you should compile it on a BSD system with the
Xcommand "cc -O -c getopt.c -Dstrchr=index".) [Sorry, I can't find a
Xmanual page which I can (legally) include.] If you can't change
X"libc.a", then you should add it to the makefiles in the "server"
Xand "lib" directories.
X
XVersion 4.2 is primarily a maintenance release. Because of constraints
Xon the author's time, few things have changed since version 4.1. Some
Xof the differences are:
X
X 1) UW v4.2 is compatible with Multifinder. It understands background
X events, so it can receive input and update windows even when
X another application's window is active.
X
X 2) Some problems relating to keyboard mapping have been fixed.
X UW recognizes the Control and ESC keys. The mapping for the
X numeric keypad still seems to be incomplete. The author is
X hampered by the fact that his development machine still has
X its original 512K Mac keyboard. (He dislikes the Mac+ and
X SE keyboards.)
X
X 3) A new window type -- plot -- has been defined. This type of
X window can only be created by the host. It interprets output
X in UNIX v7 plot(5) format.
X
X 4) Windows may use 7, 9, 10, or 12 point fixed-width fonts.
X UW includes non-Apple-copyrighted Mishawaka fonts for these sizes.
X
XUW is not public domain. It is copyrighted. However, permission to
Xcopy UW is given provided that the copies are not sold and that the
Xcopyright notices are retained.
X
XComments about UW can be sent to the author (me) at the following
Xaddresses:
X
X ARPANET/MILNET: jdb@mordor.s1.gov
X
X UUCP: {lll-crg,decwrl,caip}!mordor!jdb
X
X U.S. Mail: John Bruner
X Lawrence Livermore National Laboratory
X P.O. Box 5503, L-276
X Livermore, CA 94550
X
XI try to answer all mail, but sometimes am unable to do so for reasons
Xbeyond my control (e.g. incomplete or incorrect return addresses,
Xfinicky mailers).
!EOF!README!
echo x - Makefile
sed -e 's/^X//' > Makefile << '!EOF!Makefile!'
X#! /bin/make -f
X#
X# Makefile for UW version 4.2
X#
X# Specify VERSION 4.3 for 4.3BSD, 4.2 for 4.2BSD (including Sun 3.x)
X#
X# DEFINES is a list of the site-dependent compile-time options:
X# -DUTMP attempt to update "/etc/utmp" (who) file
X# -DV7TTYS V7-format "/etc/ttys" (pre-4.3BSD)
X# -DSETOWN_BUG fcntl(fd, F_SETOWN, pgrp) is broken (pre-4.3BSD)
X# -Dvoid=int kludge around broken C compilers
X#
X# UTMP specifies that UW should attempt to update the "/etc/utmp" file.
X# On some (foolish) systems this file is world-writeable. Other
X# installations may wish AFTER CAREFUL EXAMINATION OF THE ISSUES to
X# install the UW server with group write access to the utmp file.
X#
X# V7TTYS should be used for V7-derived systems that do not have 4.3BSD's
X# "/etc/ttys" file. This includes 4.2BSD and Sun UNIX. There is no
X# support for USG's "/etc/inittab".
X#
X# SETOWN_BUG should be defined if the fcntl(fd, F_SETOWN, pgrp) system
X# call is broken (as it is in 4.2BSD and Sun 3.0 UNIX). On those
X# machines the third argument must be negative to specify a process ID
X# and positive to specify a process group.
X#
X# Some C compilers do not understand pointers to void functions. The
X# common kludge around this problem is to substitute "int" for "void"
X# everywhere. "lint" doesn't like this, but the program will compile
X# into working code.
X#
XBINDIR = /usr/local/bin
XINCDIR = /usr/include/uw
XLIBDIR = /usr/local/lib
XVERSION = 4.3
X
XDEFINES = -DUTMP
X
XMKFILES = server/Makefile lib/Makefile utility/Makefile hqx/Makefile
X
Xall: DEFINES $(MKFILES)
X cd server; make
X cd lib; make
X cd utility; make
X cd hqx; make
X
Xdepend:
X cd server; make depend
X cd lib; make depend
X cd utility; make depend
X
Xinstall: all
X ln -s `pwd`/h $(INCDIR)
X install -s server/uw $(BINDIR)/uw
X install -s utility/uwtool $(BINDIR)/uwtool
X install -s utility/uwtitle $(BINDIR)/uwtitle
X install -s utility/uwterm $(BINDIR)/uwterm
X install -s utility/uwplot $(BINDIR)/uwplot
X cp lib/libuw.a $(LIBDIR); ranlib $(LIBDIR)/libuw.a
X
Xclean:
X cd server; make clean
X cd lib; make clean
X cd utility; make clean
X
XDEFINES: Makefile
X echo "" $(DEFINES) > DEFINES
X
Xserver/Makefile: Makefile server/Makefile_$(VERSION)
X cd server; cp Makefile_$(VERSION) Makefile; make depend
X
Xlib/Makefile: Makefile lib/Makefile_$(VERSION)
X cd lib; cp Makefile_$(VERSION) Makefile; make depend
X
Xutility/Makefile: Makefile utility/Makefile_$(VERSION)
X cd utility; cp Makefile_$(VERSION) Makefile; make depend
!EOF!Makefile!
echo x - utility/Makefile_4.2
sed -e 's/^X//' > utility/Makefile_4.2 << '!EOF!utility/Makefile_4.2!'
X#! /bin/make -f
X#
X# uw utility makefile (4.2BSD)
X#
X# INCDIR should be set to the directory containing header files.
X#
X# LIBUW should be set to the name of the library file (or, if it is
X# installed in a system directory, "-luw").
X#
X# Note: in order for "uwterm" to work on remote machines it is
X# necessary for it to be installed in a directly where "rsh"
X# will find it. The #defined symbol UWTERM in the source can
X# be set to the desired absolute pathname, if necessary.
X#
X
XINCDIR = ../h
X
XLIBUW = ../lib/libuw.a
X
XUWTOOL_OBJS = uwtool.o
XUWTITLE_OBJS = uwtitle.o
XUWTERM_OBJS = uwterm.o
XUWPLOT_OBJS = uwplot.o
X
XOBJECTS = $(UWTOOL_OBJS) $(UWTITLE_OBJS) $(UWTERM_OBJS) $(UWPLOT_OBJS)
X
XSOURCES = `echo $(OBJECTS) | sed -e 's/\\.o/\\.c/g'`
X
XDEFINES = `cat ../DEFINES`
X
XCFLAGS = -O -I$(INCDIR) $(DEFINES)
XLFLAGS =
X
Xall: uwtool uwtitle uwterm uwplot
X
Xuwtool: $(UWTOOL_OBJS)
X $(CC) -o $@ $(LFLAGS) $(UWTOOL_OBJS) $(LIBUW)
X
Xuwtitle: $(UWTITLE_OBJS)
X $(CC) -o $@ $(LFLAGS) $(UWTITLE_OBJS) $(LIBUW)
X
Xuwterm: $(UWTERM_OBJS)
X $(CC) -o $@ $(LFLAGS) $(UWTERM_OBJS) $(LIBUW)
X
Xuwplot: $(UWPLOT_OBJS)
X $(CC) -o $@ $(LFLAGS) $(UWPLOT_OBJS) $(LIBUW)
X
Xlint:
X for src in $(SOURCES); \
X do echo $$src:; lint -hubx -I$(INCDIR) $(DEFINES) $$src; done
X
Xtags:
X ctags $(SOURCES)
X
Xdepend:
X grep '^#include' $(SOURCES) | \
X sed -e '/</d' \
X -e 's/:[^"]*"\([^"]*\)".*/: ..\/h\/\1/' \
X -e 's,^../[a-zA-Z0-9]*/\([^\.]*\)\.[cs],\1.o \1.L,' | \
X awk ' { if ($$1 != prev) { print rec; rec = $$0; prev = $$1; } \
X else { if (length(rec $$3) > 78) { print rec; rec = $$0; } \
X else rec = rec " " $$3 } } \
X END { print rec } ' > makedep
X echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
X echo '$$r makedep' >>eddep
X echo 'w' >>eddep
X cp Makefile Makefile.bak
X ex - Makefile < eddep
X rm eddep makedep
X
Xclean:
X -rm -f *.o
X
X# DO NOT DELETE THIS LINE (or the following blank line) -- make depend uses it
X
!EOF!utility/Makefile_4.2!
echo x - utility/Makefile_4.3
sed -e 's/^X//' > utility/Makefile_4.3 << '!EOF!utility/Makefile_4.3!'
X#! /bin/make -f
X#
X# uw utility makefile (4.3BSD)
X#
X# INCDIR should be set to the directory containing header files.
X#
X# LIBUW should be set to the name of the library file (or, if it is
X# installed in a system directory, "-luw").
X#
X# Note: in order for "uwterm" to work on remote machines it is
X# necessary for it to be installed in a directly where "rsh"
X# will find it. The #defined symbol UWTERM in the source can
X# be set to the desired absolute pathname, if necessary.
X#
X
XINCDIR = ../h
X
XLIBUW = ../lib/libuw.a
X
XUWTOOL_OBJS = uwtool.o
XUWTITLE_OBJS = uwtitle.o
XUWTERM_OBJS = uwterm.o
XUWPLOT_OBJS = uwplot.o
X
XOBJECTS = $(UWTOOL_OBJS) $(UWTITLE_OBJS) $(UWTERM_OBJS) $(UWPLOT_OBJS)
X
XSOURCES = `echo $(OBJECTS) | sed -e 's/\\.o/\\.c/g'`
X
XDEFINES = `cat ../DEFINES`
X
XCFLAGS = -O -I$(INCDIR) $(DEFINES)
XLFLAGS =
X
Xall: uwtool uwtitle uwterm uwplot
X
Xuwtool: $(UWTOOL_OBJS)
X $(CC) -o $@ $(LFLAGS) $(UWTOOL_OBJS) $(LIBUW)
X
Xuwtitle: $(UWTITLE_OBJS)
X $(CC) -o $@ $(LFLAGS) $(UWTITLE_OBJS) $(LIBUW)
X
Xuwterm: $(UWTERM_OBJS)
X $(CC) -o $@ $(LFLAGS) $(UWTERM_OBJS) $(LIBUW)
X
Xuwplot: $(UWPLOT_OBJS)
X $(CC) -o $@ $(LFLAGS) $(UWPLOT_OBJS) $(LIBUW)
X
Xlint:
X for src in $(SOURCES); \
X do echo $$src:; lint -hubx -I$(INCDIR) $(DEFINES) $$src; done
X
Xtags:
X ctags $(SOURCES)
X
Xdepend:
X $(CC) -M -I$(INCDIR) $(DEFINES) $(SOURCES) | \
X sed -e ':loop' \
X -e 's/\.\.\/[^ /]*\/\.\./../' \
X -e 't loop' | \
X awk ' { if ($$1 != prev) { print rec; rec = $$0; prev = $$1; } \
X else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
X else rec = rec " " $$2 } } \
X END { print rec } ' >> makedep
X echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
X echo '$$r makedep' >>eddep
X echo 'w' >>eddep
X cp Makefile Makefile.bak
X ex - Makefile < eddep
X rm eddep makedep
X
Xclean:
X -rm -f *.o
X
X# DO NOT DELETE THIS LINE (or the following blank line) -- make depend uses it
X
!EOF!utility/Makefile_4.3!
echo x - utility/uwplot.c
sed -e 's/^X//' > utility/uwplot.c << '!EOF!utility/uwplot.c!'
X/*
X * uwplot
X *
X * Copyright 1986 by John D. Bruner. All rights reserved. Permission to
X * copy this program is given provided that the copy is not sold and that
X * this copyright notice is included.
X */
X
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X#include <sys/signal.h>
X#include <sys/errno.h>
X#include <ctype.h>
X#include <stdio.h>
X
X#include "uwlib.h"
X
Xchar *argv0;
XUWIN uwin;
X
Xmain(argc, argv)
Xchar **argv;
X{
X register int c, len;
X register char *cp;
X register char *title;
X register struct sockaddr_in *sin;
X auto struct sockaddr_in sa;
X auto char buf[4096];
X extern char *optarg;
X extern int errno;
X extern onintr();
X
X /*
X * Options which are recognized directly are:
X *
X * -ninet connect to server at address "inet"
X * -ttitle label window with "title" (default is argv[0])
X */
X argv0 = argv[0];
X sin = (struct sockaddr_in *)0;
X title = argv0;
X while ((c = getopt(argc, argv, "n:t:")) != EOF) {
X switch (c) {
X case 'n':
X sa.sin_family = AF_INET;
X sa.sin_addr.s_addr = 0;
X sa.sin_port = 0;
X bzero(sa.sin_zero, sizeof sa.sin_zero);
X for (cp=optarg; isxdigit(c = *cp); cp++) {
X /* Pyramid compiler botch */
X /* sa.sin_addr.s_addr *= 16; */
X sa.sin_addr.s_addr <<= 4;
X if (isdigit(c))
X sa.sin_addr.s_addr += c - '0';
X else if (islower(c))
X sa.sin_addr.s_addr += c-'a' + 10;
X else
X sa.sin_addr.s_addr += c-'A' + 10;
X }
X if (c == '.')
X for (cp++; isdigit(c = *cp); cp++)
X sa.sin_port = sa.sin_port*10 + c-'0';
X if (sa.sin_addr.s_addr == 0 || sa.sin_port == 0) {
X fprintf(stderr,
X "%s: bad Internet address: %s\n",
X argv0, optarg);
X return(1);
X }
X sa.sin_addr.s_addr = htonl(sa.sin_addr.s_addr);
X sa.sin_port = htons(sa.sin_port);
X sin = &sa;
X break;
X case 't':
X title = optarg;
X break;
X }
X }
X
X /*
X * Catch hangup, interrupt, quit, and termination signals. Kill
X * the window if one of these is received.
X */
X (void)signal(SIGHUP, onintr);
X (void)signal(SIGINT, onintr);
X (void)signal(SIGQUIT, onintr);
X (void)signal(SIGTERM, onintr);
X
X /*
X * Create a new plot window, title it, and make it visible.
X */
X if ((uwin = uw_new(UWT_PLOT, sin)) == (UWIN)0) {
X uw_perror(argv[0], uwerrno, errno);
X return(1);
X }
X (void)uw_stitle(uwin, title);
X (void)uw_svis(uwin, 1);
X
X /*
X * Copy the standard input to the plot window.
X */
X while ((len = read(0, buf, sizeof buf)) > 0 ||
X (len < 0 && errno == EINTR)) {
X if (len > 0)
X (void)write(UW_DATAFD(uwin), buf, len);
X }
X
X /*
X * This is something of a hack. We don't expect to be able to
X * read anything from the window. The read will hang until the
X * window is killed.
X */
X while ((len = read(UW_DATAFD(uwin), buf, sizeof buf)) > 0 ||
X len < 0 && errno == EINTR)
X ;
X return(0);
X}
X
Xonintr()
X{
X uw_kill(uwin);
X exit(0);
X}
!EOF!utility/uwplot.c!
echo x - utility/uwterm.c
sed -e 's/^X//' > utility/uwterm.c << '!EOF!utility/uwterm.c!'
X/*
X * uwterm
X *
X * Copyright 1986 by John D. Bruner. All rights reserved. Permission to
X * copy this program is given provided that the copy is not sold and that
X * this copyright notice is included.
X */
X#include <sys/types.h>
X#include <sys/file.h>
X#include <sys/ioctl.h>
X#include <sys/socket.h>
X#include <sys/time.h>
X#include <sys/resource.h>
X#include <sys/wait.h>
X#include <netinet/in.h>
X#include <signal.h>
X#include <strings.h>
X#include <ctype.h>
X#include <errno.h>
X#include <stdio.h>
X
X#include "openpty.h"
X#include "uwlib.h"
X
X#ifndef UWTERM
X#define UWTERM "uwterm"
X#endif
X
X#define CTL(c) ((c)&037)
X
X#ifndef FD_SET
X/* 4.2 retrofit: better definitions for these are in 4.3BSD's <sys/types.h> */
X#define FD_SET(n,p) ((p)->fds_bits[0] |= (1 << (n)))
X#define FD_CLR(n,p) ((p)->fds_bits[0] &= ~(1 << (n)))
X#define FD_ISSET(n,p) ((p)->fds_bits[0] & (1 << (n)))
X#define FD_ZERO(p) ((p)->fds_bits[0] = 0)
X#define FD_SETSIZE (NBBY*sizeof(long))
X#endif
X
Xextern int optind;
Xextern char *optarg;
Xextern char *getenv();
Xextern char *malloc();
Xextern deadkid();
Xextern int errno;
X
X#ifndef htons
X/* These should have been defined in <netinet/in.h>, but weren't (in 4.2BSD) */
Xextern unsigned short htons(), ntohs();
Xextern unsigned long htonl(), ntohl();
X#endif
X
Xchar *argv0;
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X register char *cp;
X register int c;
X int wflag;
X uwtype_t wtype;
X char *term, *title, *server, *login;
X struct sockaddr_in sa, *sin;
X char hostname[32];
X
X /*
X * If called with no arguments, create a new window using the
X * current shell according to the SHELL environment variable
X * (or "/bin/sh" if that doesn't exist).
X *
X * Options which are recognized directly are:
X *
X * -ninet connect to server at address "inet"
X * -wtype create window with emulation "type"
X * -ttitle label window with "title"
X * -llogin use login name "login" on remote machine
X *
X * If no explicit title is specified, the command name is used.
X */
X argv0 = argv[0];
X sin = (struct sockaddr_in *)0;
X server = (char *)0;
X login = (char *)0;
X title = (char *)0;
X wflag = 0;
X term = (char *)0;
X while ((c = getopt(argc, argv, "l:n:t:w:")) != EOF) {
X switch (c) {
X case 'l':
X if (optarg[0] == '\0') {
X fprintf(stderr,
X "%s: \"-l\" requires user name\n", argv0);
X } else
X login = optarg;
X break;
X case 'n':
X server = optarg;
X sa.sin_family = AF_INET;
X sa.sin_addr.s_addr = 0;
X sa.sin_port = 0;
X bzero(sa.sin_zero, sizeof sa.sin_zero);
X for (cp=optarg; isxdigit(c = *cp); cp++) {
X /* Pyramid compiler botch */
X /* sa.sin_addr.s_addr *= 16; */
X sa.sin_addr.s_addr <<= 4;
X if (isdigit(c))
X sa.sin_addr.s_addr += c - '0';
X else if (islower(c))
X sa.sin_addr.s_addr += c-'a' + 10;
X else
X sa.sin_addr.s_addr += c-'A' + 10;
X }
X if (c == '.')
X for (cp++; isdigit(c = *cp); cp++)
X sa.sin_port = sa.sin_port*10 + c-'0';
X if (sa.sin_addr.s_addr == 0 || sa.sin_port == 0) {
X fprintf(stderr,
X "%s: bad Internet address: %s\n",
X argv0, optarg);
X return(1);
X }
X sa.sin_addr.s_addr = htonl(sa.sin_addr.s_addr);
X sa.sin_port = htons(sa.sin_port);
X sin = &sa;
X break;
X case 'w':
X wflag++;
X term = optarg;
X wtype = uw_ttype(optarg);
X break;
X case 't':
X title = optarg;
X break;
X }
X }
X
X gethostname(hostname, sizeof hostname);
X if (title == (char *)0) {
X /*
X * If there was no "-t" argument, then "title" will still
X * be NULL. In this case we use the host name.
X */
X if (optind == argc)
X title = hostname;
X else
X title = argv[optind];
X }
X
X if (!term) {
X /*
X * If there was no "-w" argument, fetch the window
X * type from the environment. If that fails, use
X * a default.
X */
X if ((term=getenv("TERM")) != (char *)0)
X wtype = uw_ttype(term);
X else
X wtype = UWT_ADM31;
X }
X
X if (optind == argc-1) {
X /*
X * The remaining argument is the host name. Fork an "rsh"
X * to execute this on the remote machine.
X */
X return(doremote(argv[optind], server, title, term, login));
X } else if (optind == argc) {
X /*
X * There are no other arguments. Set up the connection
X * to this machine.
X */
X return(dolocal(sin, title, wtype, term));
X } else {
X fprintf(stderr,
X "Usage: \"%s [-ttitle] [-wtype] [-naddr] [-llogin] host\"\n",
X argv0);
X return(1);
X }
X}
X
Xdoremote(host, server, title, term, login)
Xchar *host;
Xchar *server;
Xchar *title;
Xchar *term;
Xchar *login;
X{
X register int fd, i, pid;
X register char *cp;
X char *av[16];
X
X /*
X * Invoke a remote "uwterm" via "rsh".
X */
X i = 0;
X av[i++] = "rsh";
X av[i++] = host;
X av[i++] = "-n";
X if (login != NULL) {
X av[i++] = "-l";
X av[i++] = login;
X }
X av[i++] = UWTERM;
X if (server == (char *)0) {
X if ((server = getenv("UW_INET")) == (char *)0) {
X fprintf(stderr,"%s: Can't find window server\n",argv0);
X return(1);
X }
X }
X if ((cp = malloc(3+strlen(server))) == (char *)0) {
X fprintf(stderr, "%s: out of memory\n", argv0);
X return(1);
X }
X (void)strcat(strcpy(cp, "-n"), server);
X av[i++] = cp;
X
X if (title != (char *)0) {
X if ((cp = malloc(3+strlen(title))) == (char *)0) {
X fprintf(stderr, "%s: out of memory\n", argv0);
X return(1);
X }
X (void)strcat(strcpy(cp, "-t"), title);
X av[i++] = cp;
X }
X
X if (term != (char *)0) {
X if ((cp = malloc(3+strlen(term))) == (char *)0) {
X fprintf(stderr, "%s: out of memory\n", argv0);
X return(1);
X }
X (void)strcat(strcpy(cp, "-w"), term);
X av[i++] = cp;
X }
X
X av[i] = (char *)0;
X
X for (fd=getdtablesize()-1; fd > 2; fd--)
X (void)fcntl(fd, F_SETFD, 1);
X (void)execvp(av[0], av);
X (void)execv("/usr/ucb/rsh", av); /* last-ditch try */
X perror(av[0]);
X return(1);
X}
X
X
Xdolocal(sin, title, wtype, term)
Xstruct sockaddr_in *sin;
Xchar *title;
Xuwtype_t wtype;
Xchar *term;
X{
X register UWIN uwin;
X register int fd;
X register int s;
X struct ptydesc pt;
X
X /*
X * Create and initialize a pseudo-terminal.
X */
X if (openpty(&pt) < 0) {
X fprintf(stderr, "No pseudo-terminals are available\n");
X return(1);
X }
X ttyinit(pt.pt_tfd);
X
X
X /*
X * Make fd's 0 and 1 be "/dev/null". We'd like to force a known
X * definition for fd 2 at this point, but we may need it for
X * uw_perror() if uw_new() fails.
X */
X if ((fd = open("/dev/null", O_RDWR)) >= 0) { /* should be zero */
X if (fd != 0 && pt.pt_tfd != 0 && pt.pt_pfd != 0)
X dup2(fd, 0);
X if (fd != 1 && pt.pt_tfd != 1 && pt.pt_pfd != 1)
X dup2(fd, 1);
X if (fd > 2)
X (void)close(fd);
X }
X
X /*
X * Create and title the window. Make it visible.
X */
X if ((uwin = uw_new(wtype, sin)) == (UWIN)0) {
X uw_perror(argv0, uwerrno, errno);
X return(1);
X }
X (void)uw_stitle(uwin, title);
X (void)uw_svis(uwin, 1);
X
X /*
X * We no longer have use for fd 2, so make it "/dev/null" (the
X * same as fd 0.
X */
X (void)dup2(0, 2);
X
X /*
X * Adjust the environment to contain the correct values of TERM,
X * UW_ID, and UW_INET. These will be inherited by the child
X * we will create next.
X */
X adjenv(term, sin, UW_ID(uwin));
X
X /*
X * Create a process to execute the command connected to the pty.
X */
X runcmd(pt.pt_tfd, pt.pt_tname);
X
X /*
X * Ignore signals that might cause us trouble. We do NOT ignore
X * SIGTSTP so that the user can move us from the foreground into
X * the background if desired.
X */
X signal(SIGINT, SIG_IGN);
X signal(SIGQUIT, SIG_IGN);
X signal(SIGCHLD, deadkid);
X
X#if defined(TIOCSWINSZ) || defined(TIOCSSIZE)
X /*
X * Install an option handling routine to catch window size
X * changes from the Mac and make the appropriate changes to
X * the pseudo-terminal.
X */
X setresize(uwin, pt.pt_pfd);
X#endif
X
X /*
X * Close the slave side of the pty. Copy data between the pty
X * and the window. The return value from copy() is the exit
X * status.
X */
X (void)close(pt.pt_tfd);
X s = copy(pt.pt_pfd, UW_DATAFD(uwin));
X uw_kill(uwin);
X return(s);
X}
X
Xttyinit(ptyfd)
Xregister int ptyfd;
X{
X register int ttyfd;
X struct sgttyb sg;
X struct tchars tc;
X struct ltchars ltc;
X int ldisc;
X int lmode;
X
X /*
X * Initialize the modes of the terminal whose file descriptor
X * is "ptyfd" to the same modes as the current terminal. If there
X * isn't a "current terminal" handy, then use hardcoded defaults.
X */
X for (ttyfd=0; ttyfd < 3 && ioctl(ttyfd, TIOCGETD, &ldisc) < 0; ttyfd++)
X ;
X if (ttyfd < 3) {
X (void)ioctl(ttyfd, TIOCGETP, &sg);
X (void)ioctl(ttyfd, TIOCGETC, &tc);
X (void)ioctl(ttyfd, TIOCGLTC, <c);
X (void)ioctl(ttyfd, TIOCLGET, &lmode);
X } else {
X ldisc = NTTYDISC;
X
X sg.sg_ispeed = sg.sg_ospeed = 13; /* doesn't really matter */
X sg.sg_erase = 0177; /* ugh */
X sg.sg_kill = CTL('u'); /* ugh */
X sg.sg_flags = ECHO|CRMOD|ANYP;
X
X tc.t_intrc = CTL('c'); /* yuck, should be 0177 */
X tc.t_quitc = CTL('\\');
X tc.t_startc = CTL('q');
X tc.t_stopc = CTL('s');
X tc.t_eofc = CTL('d');
X tc.t_brkc = -1;
X
X ltc.t_suspc = CTL('z');
X ltc.t_dsuspc = CTL('y');
X ltc.t_rprntc = CTL('r');
X ltc.t_flushc = CTL('o');
X ltc.t_werasc = CTL('w');
X ltc.t_lnextc = CTL('v');
X
X lmode = LCRTBS|LCRTERA|LCRTKIL|LCTLECH;
X }
X (void)ioctl(ptyfd, TIOCSETD, &ldisc);
X (void)ioctl(ptyfd, TIOCSETP, &sg);
X (void)ioctl(ptyfd, TIOCSETC, &tc);
X (void)ioctl(ptyfd, TIOCSLTC, <c);
X (void)ioctl(ptyfd, TIOCLSET, &lmode);
X}
X
Xadjenv(term, sin, wid)
Xchar *term;
Xstruct sockaddr_in *sin;
Xuwid_t wid;
X{
X char *env[4];
X static char ttype[sizeof "TERM=" + 16];
X static char inet[sizeof INET_ENV + 16];
X static char idstr[sizeof "UW_ID=" + 20];
X
X /*
X * Redefine the environment variable UW_ID. Redefine UW_INET
X * if "sin" is non-NULL. Redefine TERM.
X */
X (void)sprintf(ttype, "TERM=%.15s", term);
X env[0] = ttype;
X
X (void)sprintf(idstr, "UW_ID=%ld", wid);
X env[1] = idstr;
X
X if (sin != NULL) {
X (void)sprintf(inet, "%s=%08lx.%d", INET_ENV,
X ntohl(sin->sin_addr.s_addr), ntohs(sin->sin_port));
X env[2] = inet;
X env[3] = (char *)0;
X } else
X env[2] = (char *)0;
X env_set(env);
X}
X
Xruncmd(fd, tname)
Xint fd;
Xchar *tname;
X{
X register int pid;
X register char *shell;
X
X /*
X * Figure out the name of the user's shell. If unknown,
X * use a default.
X */
X if ((shell = getenv("SHELL")) == (char *)0)
X shell = "/bin/sh";
X
X /*
X * Fork a new process and attach "fd" to fd's 0, 1, and 2 of
X * that new process. Disassociate the current controlling
X * terminal and attach the new one (whose name is "tname").
X */
X while ((pid = fork()) < 0)
X sleep(5);
X if (pid == 0) {
X if (fd != 0)
X dup2(fd, 0);
X if (fd != 1)
X dup2(fd, 1);
X if (fd != 2)
X dup2(fd, 2);
X if ((fd = open("/dev/tty", O_RDWR)) >= 0) {
X (void)ioctl(fd, TIOCNOTTY, (char *)0);
X (void)close(fd);
X } else
X setpgrp(0, 0);
X (void)open(tname, O_RDWR);
X for (fd=getdtablesize()-1; fd > 2; fd--)
X (void)fcntl(fd, F_SETFD, 1);
X execlp(shell, "-", (char *)0);
X execl(shell, "-", (char *)0);
X _exit(1);
X }
X}
X
Xcopy(fd1, fd2)
Xint fd1, fd2;
X{
X struct fdinfo {
X int fi_fd; /* associated file descriptor */
X int fi_size; /* amount of data in buffer */
X char *fi_ptr; /* pointer to data in fi_buf */
X char fi_buf[1024];
X };
X register struct fdinfo *fi, *fo;
X register int n, nfds, len;
X struct fdinfo fdinfo[2];
X struct fd_set rdmask[2], wtmask[2], exmask[2];
X struct timeval tv;
X
X /*
X * Copy data between file descriptors fd1 and fd2. Return when an
X * EOF is read or an I/O error (other than an interrupted system
X * call or non-blocking I/O message) is encountered.
X */
X FD_ZERO(&rdmask[1]);
X FD_ZERO(&wtmask[1]);
X FD_ZERO(&exmask[1]);
X
X fdinfo[0].fi_fd = fd1;
X fdinfo[0].fi_size = 0;
X fdinfo[1].fi_fd = fd2;
X fdinfo[1].fi_size = 0;
X
X FD_SET(fd1, &rdmask[1]);
X FD_SET(fd2, &rdmask[1]);
X
X (void)fcntl(fd1, F_SETFL, FNDELAY);
X (void)fcntl(fd2, F_SETFL, FNDELAY);
X
X nfds = ((fd1 > fd2) ? fd1 : fd2) + 1;
X
X while (1) {
X rdmask[0] = rdmask[1];
X wtmask[0] = wtmask[1];
X exmask[0] = exmask[1];
X errno = 0;
X if (fdinfo[0].fi_size != 0 || fdinfo[1].fi_size != 0) {
X /*
X * Select does not work correctly for writes on
X * some machines, so we must fake it. If a write
X * is pending, we time out after 1/50 second and
X * pretend that select told us that writes could
X * now be performed. The code below will do the
X * correct thing if the write would still block.
X */
X tv.tv_sec = 0;
X tv.tv_usec = 1000000 / 50;
X n = select(nfds, rdmask, wtmask, exmask, &tv);
X wtmask[0] = wtmask[1];
X } else
X n = select(nfds, rdmask, wtmask, exmask, (struct timeval *)0);
X if (n < 0 && errno == EINTR) {
X continue;
X } else if (n <= 0) {
X perror("select");
X return(1);
X }
X for (fi=fdinfo; fi < fdinfo+2; fi++) {
X fo = fdinfo + !(fi - fdinfo);
X if (FD_ISSET(fi->fi_fd, rdmask)) {
X /* data available for reading */
X len = read(fi->fi_fd, fi->fi_buf,
X sizeof fi->fi_buf);
X if (len > 0) {
X fi->fi_size = len;
X fi->fi_ptr = fi->fi_buf;
X FD_CLR(fi->fi_fd, &rdmask[1]);
X FD_SET(fo->fi_fd, &wtmask[1]);
X FD_SET(fo->fi_fd, &wtmask[0]);
X } else if (len == 0) {
X /* EOF, exit */
X return(0);
X } else if (errno != EWOULDBLOCK &&
X errno != EINTR) {
X /* error, exit */
X return(1);
X }
X }
X if (FD_ISSET(fo->fi_fd, wtmask)) {
X /* data ready for writing */
X errno = 0;
X len = write(fo->fi_fd, fi->fi_ptr, fi->fi_size);
X if (len > 0) {
X fi->fi_ptr += len;
X fi->fi_size -= len;
X if (fi->fi_size == 0) {
X FD_SET(fi->fi_fd, &rdmask[1]);
X FD_CLR(fo->fi_fd, &wtmask[1]);
X }
X } else if (errno != EWOULDBLOCK &&
X errno != EINTR) {
X /* error, exit */
X return(1);
X }
X }
X }
X }
X}
X
Xdeadkid()
X{
X register int pid;
X
X /*
X * Collect dead children. Don't bother with their exit status
X * or resource usage.
X */
X while ((pid = wait3((union wait *)0, WNOHANG, (struct rusage *)0)) > 0)
X ;
X}
X
X#if defined(TIOCSWINSZ) || defined(TIOCSSIZE)
Xstatic int ptyfd;
X
X#ifdef TIOCSWINSZ
Xstatic struct winsize winsz;
X
Xvoid
Xdoresize(uwin, optnum, optcmd, uwoptval)
XUWIN uwin;
Xuwopt_t optnum;
Xuwoptcmd_t optcmd;
Xunion uwoptval *uwoptval;
X{
X uwtype_t wtype;
X
X /*
X * 4.3BSD-style window resizing
X */
X if (uw_gtype(uwin, &wtype) < 0)
X wtype = UWT_ADM31; /* probably wrong to do this here */
X if (optcmd == UWOC_SET) {
X switch (optnum) {
X case UWOP_WSIZE:
X winsz.ws_ypixel = uwoptval->uwov_point.v;
X winsz.ws_xpixel = uwoptval->uwov_point.h;
X break;
X case UWOP_TSIZE:
X if (wtype <= UWT_ANSI) {
X winsz.ws_row = uwoptval->uwov_point.v;
X winsz.ws_col = uwoptval->uwov_point.h;
X }
X break;
X }
X if (wtype <= UWT_ANSI &&
X (optnum == UWOP_WSIZE || optnum == UWOP_TSIZE))
X (void)ioctl(ptyfd, TIOCSWINSZ, &winsz);
X }
X}
X
Xsetresize(uwin, fd)
XUWIN uwin;
Xint fd;
X{
X struct uwpoint pt;
X uwtype_t wtype;
X
X /*
X * Set up the option-handling routine "doresize".
X */
X ptyfd = fd;
X uw_optfn(uwin, UWOP_TSIZE, doresize);
X uw_optfn(uwin, UWOP_WSIZE, doresize);
X winsz.ws_row = 24; /* default to standard terminal size */
X winsz.ws_col = 80;
X if (uw_gwsize(uwin, &pt) == 0) {
X winsz.ws_ypixel = pt.uwp_v;
X winsz.ws_xpixel = pt.uwp_h;
X } else {
X /* make up something plausible */
X winsz.ws_ypixel = 8 * winsz.ws_row;
X winsz.ws_xpixel = 8 * winsz.ws_col;
X }
X
X if (uw_gtype(uwin, &wtype) == 0 && wtype <= UWT_ANSI)
X (void)uw_optcmd(uwin, UWOP_TSIZE, UWOC_DO, (union uwoptval *)0);
X}
X
X#else
X#ifdef TIOCSSIZE
Xvoid
Xdoresize(uwin, optnum, optcmd, uwoptval)
XUWIN uwin;
Xuwopt_t optnum;
Xuwoptcmd_t optcmd;
Xunion uwoptval *uwoptval;
X{
X struct ttysize ts;
X uwtype_t wtype;
X
X /*
X * Sun-style window resizing
X */
X if (uw_gtype(uwin, &wtype) < 0)
X wtype = UWT_ADM31; /* probably wrong to do this here */
X if (wtype <= UWT_ANSI && optnum == UWOP_TSIZE && optcmd == UWOC_SET) {
X ts.ts_lines = uwoptval->uwov_point.v;
X ts.ts_cols = uwoptval->uwov_point.h;
X (void)ioctl(ptyfd, TIOCSSIZE, &ts);
X }
X}
X
Xsetresize(uwin, fd)
XUWIN uwin;
Xint fd;
X{
X uwtype_t wtype;
X
X /*
X * Set up the option-handling routine "doresize".
X */
X ptyfd = fd;
X uw_optfn(uwin, UWOP_TSIZE, doresize);
X
X if (uw_gtype(uwin, &wtype) == 0 && wtype <= UWT_ANSI)
X (void)uw_optcmd(uwin, UWOP_TSIZE, UWOC_DO, (union uwoptval *)0);
X}
X#endif
X#endif
X#endif
!EOF!utility/uwterm.c!
echo x - utility/uwtitle.c
sed -e 's/^X//' > utility/uwtitle.c << '!EOF!utility/uwtitle.c!'
X/*
X * uwtitle
X *
X * Copyright 1986 by John D. Bruner. All rights reserved. Permission to
X * copy this program is given provided that the copy is not sold and that
X * this copyright notice is included.
X */
X#include <strings.h>
X#include <stdio.h>
X
X#include "uwlib.h"
X
Xextern char *optarg;
Xextern int optind;
Xextern int errno;
X
Xextern char *getenv();
Xextern long atol();
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X register int c;
X register char *cp, *cq, **av;
X register uwid_t uwid;
X char *argv0;
X char *cqlimit;
X union uwoptval uwoptval;
X
X /*
X * If called with no arguments, print a syntax message. Otherwise,
X * set the title of the current window to argv[1..argc-1]. The
X * window ID is obtained from the environment or the "-i" argument.
X */
X argv0 = argv[0];
X uwid = 0;
X while ((c = getopt(argc, argv, "i:")) != EOF) {
X switch (c) {
X case 'i':
X if ((uwid = atol(optarg)) == 0) {
X fprintf(stderr,
X "%s: malformed \"-i\" argument\n", argv0);
X return(1);
X }
X break;
X }
X }
X if (optind >= argc) {
X fprintf(stderr, "Syntax: \"%s [-iID] title ...\"\n", *argv);
X return(1);
X }
X
X if (uwid == 0) {
X if ((cp = getenv("UW_ID")) == NULL) {
X fprintf(stderr,
X "%s: can't determine window ID\n", argv0);
X return(1);
X }
X
X if ((uwid = (uwid_t)atol(cp)) == 0) {
X fprintf(stderr,
X "%s: garbaged window ID in environment: %s",
X argv0, cp);
X return(1);
X }
X }
X
X /*
X * Copy the argv list into "uwoptval" and change the title.
X */
X av = argv + optind - 1;
X cq = uwoptval.uwov_string;
X cqlimit = uwoptval.uwov_string + sizeof uwoptval.uwov_string;
X while ((cp = *++av) != NULL && cq < cqlimit) {
X while (cq < cqlimit && (*cq++ = *cp++) != '\0')
X ;
X cq[-1] = ' ';
X }
X cq[-1] = '\0';
X
X if (uw_rsetopt(uwid, UWOP_TITLE, &uwoptval) < 0) {
X uw_perror("uw_rsetopt", uwerrno, errno);
X return(1);
X } else
X return(0);
X}
!EOF!utility/uwtitle.c!
echo x - utility/uwtool.c
sed -e 's/^X//' > utility/uwtool.c << '!EOF!utility/uwtool.c!'
X/*
X * uwtool
X *
X * Copyright 1986 by John D. Bruner. All rights reserved. Permission to
X * copy this program is given provided that the copy is not sold and that
X * this copyright notice is included.
X */
X#include <strings.h>
X#include <stdio.h>
X
X#include "uwlib.h"
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X register uwid_t uwid;
X register char *fname, *term;
X register int c;
X register uwtype_t wtype;
X char *argv0;
X char *av[2];
X int vflag;
X int wflag;
X char *title;
X union uwoptval uwoptval;
X extern int errno;
X extern int optind;
X extern char *optarg;
X extern char *getenv();
X
X /*
X * If called with no arguments, create a new window using the
X * current shell according to the SHELL environment variable
X * (or "/bin/sh" if that doesn't exist). If called with
X * arguments, argv[optind] through argv[argc-1] are the arguments
X * to the command.
X *
X * Options which are recognized directly are:
X *
X * -v (verbose) print new window ID on stdout
X * -wtype create window with emulation "type"
X * -ttitle label window with "title"
X *
X * If no explicit title is specified, the command name is used.
X */
X argv0 = argv[0];
X wflag = 0;
X vflag = 0;
X title = (char *)0;
X while ((c = getopt(argc, argv, "vw:t:")) != EOF) {
X switch (c) {
X case 'v':
X vflag++;
X break;
X case 'w':
X wflag++;
X wtype = uw_ttype(optarg);
X break;
X case 't':
X title = optarg;
X break;
X }
X }
X
X if (optind < argc) {
X /*
X * Adjust the "argv" pointer according to the number of
X * arguments we've processed.
X */
X argv += optind;
X fname = *argv;
X } else {
X /*
X * No (non-option) arguments -- use SHELL
X */
X if ((fname = getenv("SHELL")) == (char *)0)
X fname = "/bin/sh";
X av[0] = fname;
X av[1] = (char *)0;
X argv = av;
X }
X
X if (title == (char *)0) {
X /*
X * If there was no "-t" argument, then "title" will still
X * be NULL. In this case we use the command name as
X * the title.
X */
X title = fname;
X }
X
X if (!wflag) {
X /*
X * If there was no "-w" argument, fetch the window
X * type from the environment. If that fails, use
X * a default.
X */
X if ((term=getenv("TERM")) != (char *)0)
X wtype = uw_ttype(term);
X else
X wtype = UWT_ADM31;
X }
X
X if ((uwid = uw_cmd(wtype, fname, argv)) > 0) {
X (void)strncpy(uwoptval.uwov_string, title,
X sizeof uwoptval.uwov_string);
X (void)uw_rsetopt(uwid, UWOP_TITLE, &uwoptval);
X if (vflag)
X printf("%d\n", uwid);
X return(0);
X } else {
X if (uwerrno != UWE_NXSERV)
X uw_perror(fname, uwerrno, errno);
X else
X uw_perror(argv0, uwerrno, errno);
X return(1);
X }
X}
!EOF!utility/uwtool.c!
echo x - misc/README
sed -e 's/^X//' > misc/README << '!EOF!misc/README!'
XThis directory contains three items that may be of interest:
X
X
X getopt.c The AT&T version of the getopt() library
X routine (for command-line processing). This
X version, to the best of my knowledge, was
X placed into the public domain by AT&T.
X
X
X macmouse.ml A package for use with Gosling's EMACS
X which intreprets encoded mouse-down and
X mouse-up events within windows to perform
X various operations.
X
X Author: Chris Kent (kent@decwrl.dec.com)
X
X
X macmouse.el A similar macro package for GNU EMACS.
X
X Author: Gregory Lauer (glauer@bbn.arpa)
X
X
XThe two EMACS macro packages were developed for a previous version of
XUW (version 2.10). Since I (John Bruner) am not an EMACS user, I do
Xnot know how well they will work with UW v4.2.
!EOF!misc/README!
echo x - misc/getopt.c
sed -e 's/^X//' > misc/getopt.c << '!EOF!misc/getopt.c!'
X/*LINTLIBRARY*/
X#define NULL 0
X#define EOF (-1)
X#define ERR(s, c) if(opterr){\
X extern int strlen(), write();\
X char errbuf[2];\
X errbuf[0] = c; errbuf[1] = '\n';\
X (void) write(2, argv[0], (unsigned)strlen(argv[0]));\
X (void) write(2, s, (unsigned)strlen(s));\
X (void) write(2, errbuf, 2);}
X
Xextern int strcmp();
Xextern char *strchr();
X
Xint opterr = 1;
Xint optind = 1;
Xint optopt;
Xchar *optarg;
X
Xint
Xgetopt(argc, argv, opts)
Xint argc;
Xchar **argv, *opts;
X{
X static int sp = 1;
X register int c;
X register char *cp;
X
X if(sp == 1)
X if(optind >= argc ||
X argv[optind][0] != '-' || argv[optind][1] == '\0')
X return(EOF);
X else if(strcmp(argv[optind], "--") == NULL) {
X optind++;
X return(EOF);
X }
X optopt = c = argv[optind][sp];
X if(c == ':' || (cp=strchr(opts, c)) == NULL) {
X ERR(": illegal option -- ", c);
X if(argv[optind][++sp] == '\0') {
X optind++;
X sp = 1;
X }
X return('?');
X }
X if(*++cp == ':') {
X if(argv[optind][sp+1] != '\0')
X optarg = &argv[optind++][sp+1];
X else if(++optind >= argc) {
X ERR(": option requires an argument -- ", c);
X sp = 1;
X return('?');
X } else
X optarg = argv[optind++];
X sp = 1;
X } else {
X if(argv[optind][++sp] == '\0') {
X sp = 1;
X optind++;
X }
X optarg = NULL;
X }
X return(c);
X}
!EOF!misc/getopt.c!
echo x - misc/macmouse.el
sed -e 's/^X//' > misc/macmouse.el << '!EOF!misc/macmouse.el!'
X;;; macmouse.el (Version: 2.0)
X
X;;; Copyright (C) Gregory S. Lauer (glauer@bbn), 1985.
X;;; Please send suggestions and corrections to the above address.
X;;;
X;;; This file contains macmouse, a GNU Emacs mouse package for UW.
X
X
X;;
X;; GNU Emacs is distributed in the hope that it will be useful,
X;; but without any warranty. No author or distributor
X;; accepts responsibility to anyone for the consequences of using it
X;; or for whether it serves any particular purpose or works at all,
X;; unless he says so in writing.
X
X;; Everyone is granted permission to copy, modify and redistribute
X;; GNU Emacs, but only under the conditions described in the
X;; document "GNU Emacs copying permission notice". An exact copy
X;; of the document is supposed to have been given to you along with
X;; GNU Emacs so that you can know how you may redistribute it all.
X;; It should be in a file named COPYING. Among other things, the
X;; copyright notice and this notice must be preserved on all copies.
X
X
X;;; Original version for Gosling emacs by Chris Kent, Purdue University 1985.
X;;; Modified by Gregory Lauer, BBN, Novemeber 1985.
X;
X;
X;
X; Macmouse provides the following features:
X; Up or down mouse button in a window selects that window
X;
X; A scroll bar/thumbing area for each window with the following features:
X; the mode lines are horizontal scroll bars
X; (running from rightmost column to under leftmost column)
X; the unused right window bar and the dividing lines between
X; windows are vertical scroll bars
X; (running from top of window THRU modeline
X; for vertical scroll bars:
X; click at line 1 does previous page
X; click at last line does next page
X; click anywhere else "thumbs" to the relative portion of the buffer.
X; shift-click at line 1 scrolls one line down
X; shift-click at last line scrolls one line up
X; shift-click elsewhere moves line to top of window
X; option-shift-click elsewhere moves line to bottom of window
X; for horizontal scroll bars:
X; click at column 1 does scroll right one window width
X; click at last column does scroll left one window width
X; click anywhere else moves to that "percent" of the buffer width
X; shift-click at column 1 scrolls one column right
X; shift-click at last column scrolls one column left
X; shift-click elsewhere moves column to right of window
X; option-shift-click elsewhere moves column to left of window
X;
X; There is also basic positioning and kill-buffer support:
X; click in a buffer moves dot there and selects that buffer
X; drag copies the dragged region to the kill buffer
X; shift-drag deletes the dragged region to the kill buffer
X;
X; It is possible to use the scrolling and thumbing area to make the region
X; larger than a single screen; just click, scroll, release. Make sure
X; that the last scroll is just a down event; the up must be in the buffer.
X; The last mouse position is remembered for each different buffer (not
X; window), and thus you can start a drag in one buffer, select another,
X; go back to the first buffer, etc.
X;
X; option-click yanks from the kill buffer
X; option-shift-click similarly yanks from a named buffer.
X;
X
X(defconst mouse-max-x 95 "Maximum UW column returned on mouse click")
X(defconst mouse-max-y 95 "Maximum UW row returned on mouse click")
X
X(make-variable-buffer-local 'mouse-last-x) ; x of last event
X(set-default 'mouse-last-x 0)
X
X(make-variable-buffer-local 'mouse-last-y) ; y of last event
X(set-default 'mouse-last-y 0)
X
X(make-variable-buffer-local 'mouse-last-b) ; buttons at last event
X(set-default 'mouse-last-b 0)
X
X(make-variable-buffer-local 'mouse-last-dot) ; dot after last event
X(set-default 'mouse-last-dot 0)
X
X(make-variable-buffer-local 'scrolling-p)
X(set-default 'scrolling-p nil)
X
X(defun move-mac-cursor ()
X (interactive)
X (let (savest b x y up down lock shift option command)
X (setq savest stack-trace-on-error)
X (setq stack-trace-on-error nil)
X ; decode everything
X (setq y (- (read-char) 32))
X (setq x (- (read-char) 32))
X (setq b (- (read-char) 32))
X (setq command (< 0 (logand b 1))) ; command key
X (setq shift (< 0 (logand b 2))) ; shift
X (setq lock (< 0 (logand b 4))) ; caps-lock
X (setq option (< 0 (logand b 8))) ; option
X (setq down (< 0 (logand b 16))) ; mouse down
X (setq up (< 0 (logand b 32))) ; mouse up
X (condition-case ()
X (progn
X (select-window-containing-x-and-y x y) ; side-effect sets scrolling-p
X (if scrolling-p
X (mouse-scroll-region b x y)
X (progn
X (move-to-window-x-y x y) ; move cursor to mouse-dot always
X (if down (setq mouse-last-dot (dot)))
X (mouse-edit-action))))
X (error (message "Click not in selectable window")
X (sit-for 1)
X (message "")))
X (setq stack-trace-on-error savest)
X (if down
X (progn
X (setq mouse-last-x x)
X (setq mouse-last-y y)
X (setq mouse-last-b b))
X (progn
X (setq mouse-last-x 0)
X (setq mouse-last-y 0)
X (setq mouse-last-b 0)))))
X
X(defun mouse-edit-action ()
X ;marking and editing actions on buttons:
X ; if no movement, nothing.
X ; if movement, save mouse-last-dot,
X ; and edit.
X ; editing (on upstrokes):
X ; unmodified, copy to kill buffer.
X ; SHIFTed, delete (cut) to kill buffer.
X ;
X ; option-click yanks from kill buffer;
X ; shift-option-click from named buffer.
X (let ((fun (get 'mouse-function b)))
X (if fun (apply fun nil))))
X
X
X ; individual button bindings
X ; generally will only need up mouse button: mouse-last-dot
X ; is saved automatically on down mouse button
X
X; only need to define functions for keys that get used
X
X(put 'mouse-function 32 ; up
X '(lambda ()
X (if (and (not (mouse-click-p))
X (not scrolling-p))
X (copy-region-as-kill (dot) mouse-last-dot))))
X
X(put 'mouse-function 34 ; up/shift
X '(lambda ()
X (if (and (not (mouse-click-p))
X (not scrolling-p))
X (kill-region (dot) mouse-last-dot))))
X
X(put 'mouse-function 40 ; up/option
X '(lambda ()
X (if (mouse-click-p)
X (progn
X (yank)
X (exchange-dot-and-mark)))))
X
X(put 'mouse-function 42
X '(lambda () ; up/option/shift
X (if (mouse-click-p)
X (insert-buffer (read-buffer "Insert contents of buffer: ")))))
X
X(defun mouse-click-p ()
X (= (dot) mouse-last-dot))
X
X(defun set-window-boundaries ()
X (let ((edges (window-edges)))
X (setq xl (1+ (car edges)))
X (setq yt (1+ (car (cdr edges))))
X (let ((temp (car (cdr (cdr edges)))))
X (setq xr (if (= (screen-width) temp) mouse-max-x temp)))
X (let ((temp (car (cdr (cdr (cdr edges))))))
X (setq yb (if (= (screen-height) temp) mouse-max-y temp )))))
X
X(defun select-window-containing-x-and-y (x y)
X (let ((starting-window (selected-window)))
X (set-window-boundaries)
X (while (not (point-in-window x y))
X (other-window 1)
X (if (eq (selected-window) starting-window)
X (error nil)
X (set-window-boundaries)))
X (if (or (= x xr) (= y yb))
X (setq scrolling-p t)
X (setq scrolling-p nil))))
X
X(defun point-in-window (x y)
X (and (<= xl x)(<= x xr)(<= yt y)(<= y yb)))
X
X(defun move-to-window-x-y (x y)
X (move-to-window-line (- y yt))
X (move-to-window-column (- x xl)))
X
X(defun move-to-window-column (x)
X (move-to-column (+ (max 0 (- (window-hscroll) 1)) x)))
X
X(defun mouse-scroll-region (b x y)
X (if down
X (if shift
X (do-lines b x y)
X (do-pages b x y)))
X (if (and up
X (or (/= x mouse-last-x)
X (/= y mouse-last-y)))
X (if shift
X (do-lines b x y)
X (do-pages b x y))))
X
X(defun do-lines (b x y) ; fine control over lines
X (if (= x xr)
X (cond ((= y yt)(scroll-down 1))
X ((= y yb)(scroll-up 1))
X (t (if option
X (scroll-down (- yb y 1))
X (scroll-up (- y yt))))))
X (if (and (= y yb) (/= x xr))
X (cond ((<= x xl)(scroll-right 1))
X ((>= x (1- xr))(scroll-left 1))
X (t (if option
X (move-column-right x)
X (move-column-left x))))))
X
X(defun move-column-left (x) ;need to mess about a bit because
X (scroll-left ;first scroll left of 1 just writes
X (if (= (window-hscroll) 0) ;a column of $s in column 1
X (- x xl)
X (- x xl 1))))
X
X(defun move-column-right (x)
X (scroll-right (- xr x 2)))
X
X
X(defun do-pages (b x y) ; large motions via pages and thumbing
X (if (= x xr)
X (cond ((= y yt)(scroll-down nil))
X ((= y yb)(scroll-up nil))
X (t (goto-percent (/ (* (- y yt 1) 100)
X (- yb yt 2))))))
X (if (and (= y yb)(/= x xr))
X (cond ((<= x xl)(scroll-right (- (window-width)
X next-screen-context-lines)))
X ((>= x (1- xr))(scroll-left (- (window-width)
X next-screen-context-lines)))
X (t (goto-horizontal-percent (/ (* (- x xl 1) 100)
X (- xr xl 2)))))))
X
X(defun goto-percent (p)
X (goto-char (/ (* (- (dot-max) (dot-min)) p) 100)))
X
X(defun goto-horizontal-percent (p) ;try to put this percent of columns
X (let ((window-offset (window-hscroll));in the center column of the window
X delta) ;unless that would move the first or
X (setq delta ;last column past the window edge
X (- window-offset
X (min (max 0 (- (/ (* (screen-width) p) 100)
X (/ (- xr xl) 2)))
X (- (screen-width) (- xr xl)))))
X (scroll-right delta)))
X
X
X(global-set-key "\em" 'move-mac-cursor)
!EOF!misc/macmouse.el!
echo x - misc/macmouse.ml
sed -e 's/^X//' > misc/macmouse.ml << '!EOF!misc/macmouse.ml!'
X; $Header: /c/cak/lib/mlisp/RCS/macmouse.ml,v 1.5 85/11/05 14:01:44 cak Rel $
X;
X; Macintosh mouse routines for use with John Bruner's uw program.
X; Chris Kent, Purdue University Fri Oct 25 1985
X; Copyright 1985 by Christopher A. Kent. All rights reserved.
X; Permission to copy is given provided that the copy is not
X; sold and this copyright notice is included.
X;
X; Provides a scroll bar/thumbing area in the unused scroll bar with the
X; following features:
X; click at line 1 does previous page
X; click at line 24 does next page
X; click anywhere else "thumbs" to the relative portion of the buffer.
X; shift-click at line 1 scrolls one line down
X; shift-click at line 24 scrolls one line up
X; shift-click elsewhere moves line to top of window
X; option-shift-click elsewhere moves line to bottom of window
X;
X; There is also basic positioning and kill-buffer support:
X; click in a buffer moves dot there
X; drag copies the dragged region to the kill buffer (mark is left
X; at the beginning of the region.)
X; shift-drag deletes the dragged region to the kill buffer
X; it is possible to use the scrolling and thumbing area to make the region
X; larger than a single screen; just click, scroll, release. Make sure
X; that the last scroll is just a down event; the up must be in the buffer.
X;
X; option-click yanks from the kill buffer, doesn't affect mark.
X; option-shift-click similarly yanks from a named buffer.
X;
X
X(declare-global
X #mouse-last-x ; x of last event
X #mouse-last-y ; y of last event
X #mouse-last-b ; buttons at last event
X #mouse-last-dot ; dot after last event
X #mouse-last-action ; whether last was scroll (1) or edit (2)
X)
X
X(defun
X (move-mac-cursor savest b x y up down lock shift option command saveb
X (setq savest stack-trace-on-error)
X (setq stack-trace-on-error 0)
X ; decode everything
X (setq y (- (get-tty-character) 32))
X (setq x (- (get-tty-character) 32))
X (setq b (- (get-tty-character) 32))
X (setq saveb b)
X (setq command (% b 2))(setq b (/ b 2)) ; command key
X (setq shift (% b 2))(setq b (/ b 2)) ; shift
X (setq lock (% b 2))(setq b (/ b 2)) ; caps-lock
X (setq option (% b 2))(setq b (/ b 2)) ; option
X (setq down (% b 2))(setq b (/ b 2)) ; mouse down
X (setq up (% b 2))
X
X (if (= x 81) ; right margin -- move-dot-to-x-y is wrong
X (progn
X (#mouse-scroll-region)
X (setq #mouse-last-action 1))
X (if (error-occurred
X (if (= #mouse-last-action 2) ; not if just scrolled
X (setq #mouse-last-dot (dot)))
X (move-dot-to-x-y x y)
X (backward-character)(forward-character)
X (#mouse-edit-action)
X (setq #mouse-last-action 2)
X )
X (progn
X (#mouse-scroll-region b x y)
X (setq #mouse-last-action 1))
X ))
X (setq stack-trace-on-error savest)
X (if (= down 1)
X (progn
X (setq #mouse-last-x x)
X (setq #mouse-last-y y)
X (setq #mouse-last-b saveb))
X (progn
X (setq #mouse-last-x 0)
X (setq #mouse-last-y 0)
X (setq #mouse-last-b 0)))
X )
X
X (#mouse-edit-action ; marking and editing actions on buttons:
X ; if no movement, nothing.
X ; if movement, put mark at #mouse-last-dot,
X ; leave dot here,and edit.
X ; editing (on upstrokes):
X ; unmodified, copy to kill buffer.
X ; SHIFTed, delete (cut) to kill buffer.
X ;
X ; option-click yanks from kill buffer;
X ; shift-option-click from named buffer.
X (if (= saveb 16)
X (#mouse-d))
X (if (= saveb 17)
X (#mouse-dc))
X (if (= saveb 18)
X (#mouse-ds))
X (if (= saveb 19)
X (#mouse-dsc))
X (if (= saveb 20)
X (#mouse-dl))
X (if (= saveb 21)
X (#mouse-dlc))
X (if (= saveb 22)
X (#mouse-dls))
X (if (= saveb 23)
X (#mouse-dlsc))
X (if (= saveb 24)
X (#mouse-do))
X (if (= saveb 25)
X (#mouse-doc))
X (if (= saveb 26)
X (#mouse-dos))
X (if (= saveb 27)
X (#mouse-dosc))
X (if (= saveb 28)
X (#mouse-dol))
X (if (= saveb 29)
X (#mouse-dolc))
X (if (= saveb 30)
X (#mouse-dols))
X (if (= saveb 31)
X (#mouse-dolsc))
X (if (= saveb 32)
X (#mouse-u))
X (if (= saveb 33)
X (#mouse-uc))
X (if (= saveb 34)
X (#mouse-us))
X (if (= saveb 35)
X (#mouse-usc))
X (if (= saveb 36)
X (#mouse-ul))
X (if (= saveb 37)
X (#mouse-ulc))
X (if (= saveb 38)
X (#mouse-uls))
X (if (= saveb 39)
X (#mouse-ulsc))
X (if (= saveb 40)
X (#mouse-uo))
X (if (= saveb 41)
X (#mouse-uoc))
X (if (= saveb 42)
X (#mouse-uos))
X (if (= saveb 43)
X (#mouse-uosc))
X (if (= saveb 44)
X (#mouse-uol))
X (if (= saveb 45)
X (#mouse-uolc))
X (if (= saveb 46)
X (#mouse-uols))
X (if (= saveb 47)
X (#mouse-uolsc))
X )
X
X ; individual button bindings
X
X (#mouse-u ; up
X (if (! (#mouse-click-p))
X (progn
X (#mouse-set-region)
X (Copy-region-to-kill-buffer)
X ))
X )
X
X (#mouse-uc ; up/command
X )
X
X (#mouse-us ; up/shift
X (if (! (#mouse-click-p))
X (progn
X (#mouse-set-region)
X (delete-to-killbuffer)
X ))
X )
X
X (#mouse-usc ; up/shift/command
X )
X
X (#mouse-ul ; up/lock
X )
X
X (#mouse-ulc ; up/lock/command
X )
X
X (#mouse-uls ; up/lock/shift
X )
X
X (#mouse-ulsc ; up/lock/shift/command
X )
X
X (#mouse-uo ; up/option
X (if (#mouse-click-p)
X (yank-from-killbuffer)
X )
X )
X
X (#mouse-uoc ; up/option/command
X )
X
X (#mouse-uos ; up/option/shift
X (if (#mouse-click-p) ; click
X (yank-buffer (get-tty-buffer "Insert contents of buffer: "))
X )
X )
X
X (#mouse-uosc ; up/option/shift
X )
X
X (#mouse-uol ; up/option/lock
X )
X
X (#mouse-uolc ; up/option/lock
X )
X
X (#mouse-uols ; up/option/lock/shift
X )
X
X (#mouse-uolsc ; up/option/lock/shift/command
X )
X
X (#mouse-d ; down
X )
X
X (#mouse-dc ; down/command
X )
X
X (#mouse-ds ; down/shift
X )
X
X (#mouse-dsc ; down/shift/command
X )
X
X (#mouse-dl ; down/lock
X )
X
X (#mouse-dlc ; down/lock/command
X )
X
X (#mouse-dls ; down/lock/shift
X )
X
X (#mouse-dlsc ; down/lock/shift/command
X )
X
X (#mouse-do ; down/option
X )
X
X (#mouse-doc ; down/option/command
X )
X
X (#mouse-dos ; down/option/shift
X )
X
X (#mouse-dosc ; down/option/shift
X )
X
X (#mouse-dol ; down/option/lock
X )
X
X (#mouse-dolc ; down/option/lock
X )
X
X (#mouse-dols ; down/option/lock/shift
X )
X
X (#mouse-dolsc ; down/option/lock/shift/command
X )
X
X (#mouse-set-region ; set the region to be from last dot to dot.
X (set-mark)
X (goto-character #mouse-last-dot)
X (exchange-dot-and-mark)
X )
X
X (#mouse-click-p clickp
X (if (= (dot) #mouse-last-dot)
X (setq clickp 1)
X (setq clickp 0)
X ))
X
X (#mouse-scroll-region ; out of range actions:
X ; left margin -- hard to generate, ignored
X ; right margin -- simulate scroll bar
X ; line 1 -- previous page
X ; line 24/25 -- next page
X ; other lines -- thumbing
X ; top margin -- previous page
X ; bottom margin -- next page
X ;
X ; if shifted, deal with lines.
X ; line 1 scrolls one line down
X ; line 24/25 scrolls one line up
X ; else line to top; with option to bottom.
X ;
X ; if up stroke is in same place as down
X ; stroke, don't do anything, so clicks in
X ; the scroll region don't do the action
X ; twice.
X (if (= down 1)
X (if (= shift 1)
X (do-lines)
X (do-pages))
X )
X (if (& (= up 1)
X (| (!= x #mouse-last-x) (!= y #mouse-last-y)))
X (if (= shift 1)
X (do-lines)
X (do-pages)
X )
X )
X (#mouse-set-region)
X )
X
X (do-pages ; large motions via pages and thumbing
X (if (| (= y 0) (= y 1) (= y 24) (= y 25))
X (progn
X (if (| (= y 0) (= y 1))
X (previous-page)
X (Next-Page)
X ))
X (if (= x 81)
X (goto-percent (/ (* y 100) 25))
X )
X ))
X
X (do-lines ; fine control over lines
X (if (= x 81)
X (if (| (= y 1) (= y 24) (= y 25))
X (if (| (= y 0) (= y 1))
X (scroll-one-line-down)
X (scroll-one-line-up)
X )
X (progn
X (move-dot-to-x-y 1 y)
X (if (= option 0)
X (line-to-top-of-window)
X (line-to-bottom-of-window))
X )
X )
X )
X )
X
X (line-to-bottom-of-window nlines i
X (line-to-top-of-window)
X (setq i 0)
X (setq nlines (- (window-height) 1))
X (while (< i nlines)
X (scroll-one-line-down)
X (setq i (+ i 1))
X )
X )
X
X (goto-percent
X (goto-character (/ (* (buffer-size) (arg 1)) 100))
X )
X)
X
X(bind-to-key "move-mac-cursor" "\em")
!EOF!misc/macmouse.ml!
exit 0
: end of shell archive