Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!decvax!ucbvax!dual!unisoft!lll-lcc!lll-crg!mordor!sri-spam!sri-unix!hplabs!felix!macintosh From: jdb@mordor.ARPA (John Bruner) Newsgroups: mod.mac.sources Subject: UW v3.4 (part 1 of 9) Message-ID: <1687@felix.UUCP> Date: Thu, 23-Oct-86 15:51:28 EDT Article-I.D.: felix.1687 Posted: Thu Oct 23 15:51:28 1986 Date-Received: Fri, 24-Oct-86 21:31:35 EDT Sender: macintosh@felix.UUCP Reply-To: macintosh@felix.UUCP (The Moderator) Organization: FileNet Corp., Costa Mesa, CA Lines: 1810 Approved: bytebug@felix.UUCP (Roger L. Long) : [UW v3.4 - part 1 of 9] : : This is a shar archive. Extract with sh, not csh. echo mkdir h mkdir h echo mkdir misc mkdir misc echo x - README sed -e 's/^X//' > README << '!EOF!README!' XThis is version 3.4 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 XPyramid users: the good news is that I was able to compile and run UW Xon a Pyramid. The bad news is that I ran into several problems. First, XPyramid uses the structure tag (and typedef name) "fdset_t" for the Xtype of a select() bitmask. The standard 4.[23]BSD name for this Xis "fd_set". To compile UW for a Pyramid, add "-Dfd_set=fdset_t" to Xthe CFLAGS macro in each of the makefiles. Second, the Pyramid C Xcompiler converts a multiply of an unsigned long by 16 into an Xarithmetic shift left of 4. Since the sign bit (apparently) Xdoesn't participate in the shift, this gives the wrong result for Xnumbers greater than 0x7ffffff. (It should perform a logical shift Xfor unsigned longs.) I've reluctantly changed the code so that Xmultiplies by 16 are explicitly expressed as left shifts (for which the XC compiler correctly generates logical shifts). X XThere are some differences in configuration for 4.2BSD and 4.3BSD. XThe VERSION parameter in the top-level "Makefile" should be set to X4.2 or 4.3 as appropriate. If your machine is a hybrid, you may need Xto consult the makefiles in the subdirectories. Sun 3.0 should be Xconsidered 4.2. (However, if you have Sun 3.2, you should remove the Xdefinition of SETOWN_BUG in "lib/Makefile_4.2".) 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 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 XThis version differs from the previous release (v2.10) in several Xsignificant ways: X X 1) Nearly everything has been reimplemented. The cursor-addressible X terminal emulations are faster. (Unfortunately, the Tek 4010 X emulation is slower.) X X 2) An optional extended protocol provides much greater Mac-host X interaction. The host can now examine and alter a number X of window characteristics (such as the window emulation type, X whether or not it is visible, its title, etc.). X X 3) If the host supports window resizing via ioctl() (4.3BSD and X Sun do), then window size changes on the Mac can optionally X be propagated to the host. As a result, programs such as X "more" and "vi" can be used in windows smaller (or larger) X than 24x80. X X 4) UW will not run on a 128K Mac at all. It is far too large now. X X 5) There is an ANSI-compatible terminal emulation. It works with X the "ansi" and "aa-24" termcap definitions, but it needs more X work. It does not have some of the more bizarre capabilities X of the VT-100. (The author still uses the ADM-31 emulation X almost exclusively.) X X 6) It is possible to exit UW without performing a "Shutdown", X use the Mac for something else, relaunch UW and perform a X "Startup". The host will recreate the windows on the Mac X (although the previous contents of the windows will be lost). X XUW wants to use a 7-point version of the Monaco font. Previous UW Xdistributions included such a font; however, although a lot of work Xwent into its creation, the font was originally derived from a 12-point XApple Monaco font. To avoid possibile license violations, the 7-point Xfont is no longer distributed with UW. 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@s1-c.arpa X X UUCP: {seismo,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 3 X# X# Specify VERSION 4.3 for 4.3BSD, 4.2 for 4.2BSD (including Sun 3.[01]) X# XBINDIR = /usr/local/bin XINCDIR = /usr/include/uw XLIBDIR = /usr/local/lib XVERSION = 4.2 X Xall: X cd server; make X cd lib; make X cd utility; make X cd hqx; make X Xdepend: X cd server; cp Makefile_$(VERSION) Makefile; make depend X cd lib; cp Makefile_$(VERSION) Makefile; make depend X cd utility; cp Makefile_$(VERSION) Makefile; make depend X Xinstall: depend 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 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 !EOF!Makefile! echo x - h/openpty.h sed -e 's/^X//' > h/openpty.h << '!EOF!h/openpty.h!' X/* X * This file defines the "ptydesc" structure which is returned X * by the routine "openpty". X */ X Xstruct ptydesc { X int pt_pfd; /* file descriptor of master side */ X int pt_tfd; /* file descriptor of slave side */ X char *pt_pname; /* master device name */ X char *pt_tname; /* slave device name */ X}; !EOF!h/openpty.h! echo x - h/uw_clk.h sed -e 's/^X//' > h/uw_clk.h << '!EOF!h/uw_clk.h!' X/* X * uw_clk - timer support for UW 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#ifndef UW_CLK X#define UW_CLK X X/* X * Events which are supposed to occur at a certain time are handled by X * setting "timeout"s. The list of timeouts is sorted in order of X * occurrence. The "alarm" mechanism is used to send SIGALRM when the X * first timeout expires. However, the timeout is not processed X * immediately. Instead, it will be processed upon exit from the X * select() in main(). This prevents timeouts from happening at X * inappropriate times. X * X * The resolution of timeouts is in seconds. The server doesn't need X * any better resolution, and this allows all of the hair associated with X * (struct timeval) and (struct itimerval) types to be avoided. X */ X X#define CLK_HZ 1 /* one tick/second */ X Xtypedef long toarg_t; X Xstruct timeout { X struct timeout *to_next; X time_t to_when; X void (*to_fn)(); X toarg_t to_arg; X}; X Xextern int timer_rdy; X X#define CLK_CHECK() if (timer_rdy) clk_service(); else X#endif !EOF!h/uw_clk.h! echo x - h/uw_err.h sed -e 's/^X//' > h/uw_err.h << '!EOF!h/uw_err.h!' X/* X * uw error codes 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#ifndef UW_ERR X#define UW_ERR X Xtypedef int uwerr_t; X X#define UWE_NONE 0 /* no error */ X#define UWE_ERRNO 1 /* system call error, consult errno */ X#define UWE_NXTYPE 2 /* nonexistent window type */ X#define UWE_DUPID 3 /* window ID duplicated (in use) */ X#define UWE_NOTIMPL 4 /* operation not implemented yet */ X#define UWE_NXSERV 5 /* non-existent server */ X#define UWE_NOMEM 6 /* unable to allocate required memory */ X#define UWE_INVAL 7 /* invalid argument to function */ X#define UWE_NOCTL 8 /* no control file descriptor */ X X#endif !EOF!h/uw_err.h! echo x - h/uw_fd.h sed -e 's/^X//' > h/uw_fd.h << '!EOF!h/uw_fd.h!' X/* X * uw_fd - file-descriptor/select data 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#ifndef UW_FD X#define UW_FD X X#include "uw_param.h" X X/* X * If FD_SET and friends aren't defined in , then we X * provide simple definitions here. X */ X#ifndef FD_SET 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 X/* X * We use file descriptors for several different things. "fdmap" associates X * a file descriptor number with its use. X */ Xtypedef enum { /* file descriptor type */ X FDT_NONE, /* not in use */ X FDT_DATA, /* data connection for window */ X FDT_CTL, /* control connection for window */ X FDT_MAC, /* tty line which talks to Mac */ X FDT_UDSOCK, /* UNIX-domain datagram socket */ X FDT_ISSOCK, /* Internet-domain stream sock */ X FDT_DEBUG, /* debugging use */ X FDT_OTHER /* other uses */ X} fdtype_t; X Xstruct fdmap { X fdtype_t f_type; /* file descriptor type */ X struct window *f_win; /* associate window (if any) */ X}; X Xstruct selmask { X struct fd_set sm_rd; X struct fd_set sm_wt; X struct fd_set sm_ex; X}; X Xextern struct fdmap fdmap[FD_SETSIZE]; Xextern fildes_t nfds; Xextern struct selmask selmask[2]; X#endif !EOF!h/uw_fd.h! echo x - h/uw_ipc.h sed -e 's/^X//' > h/uw_ipc.h << '!EOF!h/uw_ipc.h!' X/* X * uw IPC definitions 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#ifndef UW_IPC X#define UW_IPC X X/* X * UW accepts network connections in both the UNIX domain and the X * Internet domain. UNIX domain datagrams are used by processes on X * the local machine to create new windows and to change the value X * of window parameters (window options). TCP (Internet stream) X * connections are used by local and non-local processes which wish X * to handle their own host activity (e.g. pseudo-terminal handling). X * X * Some of the definitions in this file duplicate definitions in the X * UW server source code, because this file is also intended for use X * with the UW library. X * X * The code which performs byte-order conversions knows the size of the X * types defined in this file (since there is no typeof() operator). X */ X X#define UIPC_ENV "UW_UIPC" /* Unix-domain port environment var */ X#define INET_ENV "UW_INET" /* Internet-domain port environ var */ X Xtypedef long uwid_t; /* unique window identifier */ X Xtypedef short uwcmd_t; /* commands: */ X#define UWC_NEWW 0 /* create new window */ X#define UWC_NEWT 1 /* create new tty window */ X#define UWC_STATUS 2 /* creation status message */ X#define UWC_KILLW 3 /* kill existing window */ X#define UWC_OPTION 4 /* act upon window option */ X Xtypedef short uwoptcmd_t; /* option subcommands: */ X#define UWOC_SET 0 /* set value of option */ X#define UWOC_ASK 2 /* ask for value of option */ X#define UWOC_DO 4 /* report changes in value */ X#define UWOC_DONT 5 /* don't report changes */ X#define UWOC_WILL 6 /* will report changes */ X#define UWOC_WONT 7 /* won't report changes */ X Xtypedef short uwtype_t; /* window type (see also uw_win.h): */ X#define UWT_ADM31 0 /* ADM-31 */ X#define UWT_VT52 1 /* VT-52 */ X#define UWT_ANSI 2 /* ANSI */ X#define UWT_TEK4010 3 /* Tektronix 4010 */ X#define UWT_FTP 4 /* file transfer */ X#define UWT_PRINT 5 /* output to Macintosh printer */ X Xtypedef short uwopt_t; /* window option number: */ X#define UWOP_VIS 1 /* visibility */ X#define UWOP_TYPE 2 /* window type */ X#define UWOP_POS 3 /* window position */ X#define UWOP_TITLE 4 /* window title */ X#define UWOP_WSIZE 5 /* window size (in bits) */ X X#define UWOP_TSIZE 8 /* terminal size (row,col) */ X#define UWOP_TFONTSZ 9 /* small/large font size */ X#define UWOP_TCLIPB 10 /* clipboard/mouse encoding */ X#define UWOP_TBELL 11 /* audible, visual bell */ X#define UWOP_TCURS 12 /* cursor shape */ X Xunion uwoptval { X unsigned char uwov_1bit; X unsigned char uwov_6bit; X unsigned short uwov_12bit; X struct { X unsigned short v,h; X } uwov_point; X char uwov_string[256]; X}; X X X/* X * UWC_NEWW: create a new window X * X * This command is only valid when it is sent as the first message on an X * Internet stream socket. The remote port is the data fd for the window. X * If a control fd is desired, its port number is contained in "uwnt_ctlport" X */ Xstruct uwneww { X uwid_t uwnw_id; /* unique window identifier */ X uwtype_t uwnw_type; /* window type */ X short uwnw_ctlport; /* port number of control fd */ X}; X X/* X * UWC_NEWT: create a new tty window X * X * This command is only valid when it is sent as a datagram to the Unix-domain X * socket. It must be accompanied by an access right (file descriptor) for X * the master side of a pty. The server takes over all responsibilities for X * this window. "uwnt_pty" is variable-length. X */ Xstruct uwnewt { X uwid_t uwnt_id; /* unique window identifier */ X uwtype_t uwnt_type; /* window type */ X char uwnt_pty[1]; /* name of associated pty */ X}; X X/* X * UWC_STATUS: status report for UWC_NEWW X * X * This type of packet is sent by the server to the data fd in response X * to a UWC_NEWW. It specifies whether the window was successfully X * created and what unique ID was assigned. X */ Xstruct uwstatus { X uwid_t uwst_id; /* unique window identifier */ X short uwst_err; /* error status */ X short uwst_errno; /* UNIX error code (see ) */ X}; X X/* X * UWC_KILLW: kill the window X * X * This command may be sent to either the Unix-domain socket or the control X * file descriptor of an external window. In the latter case, "uwkw_id" X * must match the ID of the window associated with the file descriptor. X */ Xstruct uwkillw { X uwid_t uwkw_id; /* unique window identifier */ X}; X X/* X * UWC_OPTION: act upon window option X * X * This command may be sent to either the Unix-domain socket or the control X * file descriptor of an external window. In the former case, only the X * UWOC_SET command is processed. X */ Xstruct uwoption { X uwid_t uwop_id; /* unique window identifier */ X uwopt_t uwop_opt; /* option number */ X uwoptcmd_t uwop_cmd; /* option subcommand */ X union uwoptval uwop_val; /* option value (for UWOC_SET) */ X}; X Xstruct uwipc { X unsigned short uwip_len; /* length of this message */ X uwcmd_t uwip_cmd; /* command (message type) */ X union { X struct uwneww uwipu_neww; X struct uwnewt uwipu_newt; X struct uwstatus uwipu_status; X struct uwkillw uwipu_killw; X struct uwoption uwipu_option; X } uwip_u; X#define uwip_neww uwip_u.uwipu_neww X#define uwip_newt uwip_u.uwipu_newt X#define uwip_status uwip_u.uwipu_status X#define uwip_killw uwip_u.uwipu_killw X#define uwip_option uwip_u.uwipu_option X}; X X#endif !EOF!h/uw_ipc.h! echo x - h/uw_opt.h sed -e 's/^X//' > h/uw_opt.h << '!EOF!h/uw_opt.h!' X/* X * uw window options 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 * Some protocols support the transmission of window options. A window X * option is a parameter (or collection of related parameters) which X * describes the layout, appearance, or other characteristic of a X * window. Some options are common to all window types, while others X * are window emulation-specific. X * X * Window options may be "set" by one side on its own initiative or in X * response to an "inquiry" from the other side. In addition, one side X * may request that the other side "report" changes in options. X * X * Options are passed as part of a "new window" command or as part of X * an "option" command (as defined by the protocol, above). The option X * format has been chosen to minimize the need for protocol encoding X * of special or meta characters. X */ X X#ifndef UW_OPT X#define UW_OPT X Xtypedef unsigned int woptcmd_t; /* window option command: */ X#define WOC_SET 0 /* request current option value */ X#define WOC_INQUIRE 2 /* report current option value */ X#define WOC_DO 4 /* do report changes to option */ X#define WOC_DONT 5 /* don't report changes */ X#define WOC_WILL 6 /* will report changes */ X#define WOC_WONT 7 /* won't report changes */ X#define WOC_MASK 7 /* mask */ X#define WOC_BADCMD(n) ((n)==1 || (n)==3) X X/* X * Option commands include an option number specifier. If the option X * number is in the range 1-14 a short-form specifier can be used; X * otherwise, a long-form specifier must be used. Option (sub)command X * bytes consist of 7 bits of data. The lower order 3 bits specify the X * option command. The next higher 4 bits specify the option number. X * The value zero is reserved (as described below). If the option X * number is greater than 14, these four bits specify 017 (15) and the X * option number is specified in a second byte. The value is encoded X * by adding ' ' to the option number. Multiple options may be specified X * in one command -- the last option is followed by a reference to X * "option" 0 (as an endmarker). X */ X Xtypedef unsigned int woption_t; /* window option number: */ X#define WONUM_MIN 1 /* minimum option number */ X#define WONUM_GENERIC 7 /* maximum generic option number */ X#define WONUM_SHORT 14 /* maximum short option number */ X#define WONUM_MAX 31 /* maximum option number */ X#define WONUM_MASK (017<<3) /* mask for extraction */ X#define WONUM_USELONG(n) ((unsigned)(n) > WONUM_SHORT) X#define WONUM_SENCODE(n) (((n)&017)<<3) /* short encoding function */ X#define WONUM_SDECODE(b) (((b)>>3)&017) /* short decoding function */ X#define WONUM_LPREFIX (017<<3) /* long encoding prefix */ X#define WONUM_LENCODE(n) ((n)+' ') /* long encoding function */ X#define WONUM_LDECODE(c) (((c)&0177)-' ') /* long decoding function */ X X X/* X * The following option numbers are generic (recognized for all window X * types): X */ X#define WOG_END 0 /* [endmarker] */ X#define WOG_VIS 1 /* 0=invisible, 1=visible */ X#define WOG_TYPE 2 /* window emulation type (see below) */ X#define WOG_POS 3 /* window position on screen */ X#define WOG_TITLE 4 /* window title */ X#define WOG_SIZE 5 /* window size (in bits) */ X#define WOG_6 6 /* unassigned, reserved */ X#define WOG_7 7 /* unassigned, reserved */ X X/* X * Option arguments immediately follow option (sub)command bytes. They are X * encoded to prevent interference with flow-control and IAC recognition. X * Three types of options are recognized: non-graphic character strings of X * fixed length, general character strings of variable length, and binary X * numbers of fixed width. X * X * Non-graphic character strings are transmitted directly. They CANNOT X * include IAC, XON, or XOFF and should not include "meta" characters. X * X * General character strings are encoded in the UW protocol fashion: "meta" X * characters and special characters are escaped. The string is terminated X * with a null byte. The string may not exceed some predetermined maximum X * number of characters (which may be less than or equal to 256, including X * the terminating null byte). X * X * Binary numbers are transmitted in 6-bit chunks, least-significant bits X * first. The number of 6-bit chunks required depends upon the width of X * the number. The 0100 bit in each byte is always set to prevent X * collisions with special characters (such as flow control and IAC). X */ X X/* X * Implementation: X * X * Arrays of type "woptarg_t" are used to describe the arguments associated X * with each option. (Note that arguments are associated only with X * the "set" option subcommand.) X */ X Xtypedef unsigned woptarg_t; /* option argument type: */ X#define WOA_END 0 /* endmarker */ X#define WOA_CHARS(n) ((1<<8)|(n)) /* "n" untranslated characters */ X#define WOA_STRING(m) ((2<<8)|(m)) /* string of max length "m" */ X#define WOA_UDATA(b) ((3<<8)|(b)) /* binary number "b" bits wide */ X#define WOA_CMDMASK 0177400 /* command mask */ X Xtypedef long woptbmask_t; /* option bitmask (>= 32 bits wide) */ X#define WOPT_SET(mask,bit) ((mask) |= (1<<(bit))) X#define WOPT_CLR(mask,bit) ((mask) &= ~(1<<(bit))) X#define WOPT_ISSET(mask,bit) ((mask) & (1<<(bit))) X Xstruct woptdefn { X woptbmask_t wod_pending; /* pending notifications to Mac */ X woptbmask_t wod_inquire; /* pending inquiries from Mac */ X woptbmask_t wod_do; /* pending DO commands to Mac */ X woptbmask_t wod_dont; /* pending DONT commands to Mac */ X woptbmask_t wod_askrpt; /* reports (of changes) we ask for */ X struct woptlst { X woptarg_t *wol_argdefn; /* option argument definition */ X char *(*wol_get)(); /* called to get option value */ X void (*wol_set)(); /* called to set option value */ X void (*wol_ext)(); /* called for external window */ X } wod_optlst[WONUM_MAX+1]; X}; X X/* X * The following structure is used by routines that fetch and set option X * values. X */ Xunion optvalue { X unsigned char ov_udata1; X unsigned char ov_udata2; X unsigned char ov_udata6; X unsigned short ov_udata12; X struct { X unsigned short v,h; X } ov_point; X char ov_string[256]; X}; X X/* X * When it is necessary to convert between host byte order and network X * byte order, opt_netadj() is called. A pointer to the following X * structure is passed. X */ Xstruct netadj { X short (*na_short)(); X long (*na_long)(); X unsigned short (*na_ushort)(); X unsigned long (*na_ulong)(); X}; X X#endif !EOF!h/uw_opt.h! echo x - h/uw_param.h sed -e 's/^X//' > h/uw_param.h << '!EOF!h/uw_param.h!' X/* X * uw parameters 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/* X * This file exists because #include file definitions aren't in the same X * place on all machines. Also, it seems pointless to drag in all of X * just to define NULL. Finally, a few declarations are X * sufficiently global that this is the most logical place to put them. X * X * This file should be #included after all of the system include files X * (e.g. ) but before any other UW include files. X */ X#ifndef UW_PARAM X#define UW_PARAM X Xtypedef int fildes_t; /* this really should be in */ X X#ifndef NBBY /* this is in in 4.3BSD */ X#define NBBY 8 /* (number of bits/byte) */ X#endif X X#ifndef NULL X#define NULL 0 X#endif X Xextern char *malloc(); Xextern char *mktemp(); Xextern char *getenv(); Xextern void done(); Xextern void cwait(); X X#endif !EOF!h/uw_param.h! echo x - h/uw_pcl.h sed -e 's/^X//' > h/uw_pcl.h << '!EOF!h/uw_pcl.h!' X/* X * uw protocol X * X * Copyright 1985,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#ifndef UW_PCL X#define UW_PCL X X#include "uw_win.h" X X/* UW may operate over connections which speak one of several protocols. X * Internally these protocols are assigned numbers starting at zero. X * Three such protocols are currently defined: X * X * 0: no special protocol X * 1: original UW (v1.6, v2.10) protocol X * 2: extended protocol (v3.x) X */ X X/* X * Protocol 0: X * X * The connection between the Macintosh and the host is simply a serial X * line. Flow control may be enabled, but no special commands are X * recognized. Only one active window is supported. This "protocol" X * does not require the UW server; hence, there is no need to support it. X */ X X/* X * Protocol 1: (original UW protocol) X * X * Two types of information are exchanged through the 7-bit serial line: X * ordinary data and command bytes. Command bytes are preceeded by X * an IAC byte. IAC bytes and literal XON/XOFF characters (those which X * are not used for flow control) are sent by a P1_FN_CTLCH command. X * Characters with the eighth bit set (the "meta" bit) are prefixed with X * a P1_FN_META function. X * X * The next most-significant bit in the byte specifies the sender and X * recipient of the command. If this bit is clear (0), the command byte X * was sent from the host computer to the Macintosh; if it is set (1) X * the command byte was sent from the Macintosh to the host computer. X * This prevents confusion in the event that the host computer X * (incorrectly) echos a command back to the Macintosh. X * X * The remaining six bits are partitioned into two fields. The low-order X * three bits specify a window number from 1-7 (window 0 is reserved for X * other uses) or another type of command-dependent parameter. The next X * three bits specify the operation to be performed by the recipient of X * the command byte. X * X * Note that the choice of command bytes prevents the ASCII XON (021) and X * XOFF (023) characters from being sent as commands. P1_FN_ISELW commands X * are only sent by the Macintosh (and thus are tagged with the P1_DIR_MTOH X * bit). Since XON and XOFF data characters are handled via P1_FN_CTLCH, X * this allows them to be used for flow control purposes. X */ X#define P1_IAC 0001 /* interpret as command */ X#define P1_DIR 0100 /* command direction: */ X#define P1_DIR_HTOM 0000 /* from host to Mac */ X#define P1_DIR_MTOH 0100 /* from Mac to host */ X#define P1_FN 0070 /* function code: */ X#define P1_FN_NEWW 0000 /* new window */ X#define P1_FN_KILLW 0010 /* kill (delete) window */ X#define P1_FN_ISELW 0020 /* select window for input */ X#define P1_FN_OSELW 0030 /* select window for output */ X#define P1_FN_META 0050 /* add meta to next data char */ X#define P1_FN_CTLCH 0060 /* low 3 bits specify char */ X#define P1_FN_MAINT 0070 /* maintenance functions */ X#define P1_WINDOW 0007 /* window number mask */ X#define P1_CC 0007 /* control character specifier: */ X#define P1_CC_IAC 1 /* IAC */ X#define P1_CC_XON 2 /* XON */ X#define P1_CC_XOFF 3 /* XOFF */ X#define P1_MF 0007 /* maintenance functions: */ X#define P1_MF_ENTRY 0 /* beginning execution */ X#define P1_MF_ASKPCL 2 /* request protocol negotiation */ X#define P1_MF_CANPCL 3 /* suggest protocol */ X#define P1_MF_SETPCL 4 /* set current protocol */ X#define P1_MF_EXIT 7 /* execution terminating */ X#define P1_NWINDOW 7 /* maximum number of windows */ X X/* X * Protocol 2: (extended UW protocol) X * X * Protocol 2 is an extension of protocol 1. The P2_FN_NEWW command and X * the new command P2_FN_WOPT communicate window options between the host X * and the Macintosh. (See "uw_opt.h" for details.) X */ X#define P2_IAC P1_IAC /* interpret as command */ X#define P2_DIR P1_DIR /* command direction: */ X#define P2_DIR_HTOM P1_DIR_HTOM /* from host to Mac */ X#define P2_DIR_MTOH P1_DIR_MTOH /* from Mac to host */ X#define P2_FN P1_FN /* function code: */ X#define P2_FN_NEWW P1_FN_NEWW /* new window */ X#define P2_FN_KILLW P1_FN_KILLW /* kill (delete) window */ X#define P2_FN_ISELW P1_FN_ISELW /* select window for input */ X#define P2_FN_OSELW P1_FN_OSELW /* select window for output */ X#define P2_FN_WOPT 0040 /* communicate window options */ X#define P2_FN_META P1_FN_META /* add meta to next data char */ X#define P2_FN_CTLCH P1_FN_CTLCH /* low 3 bits specify char */ X#define P2_FN_MAINT P1_FN_MAINT /* maintenance functions */ X#define P2_WINDOW P1_WINDOW /* window number mask */ X#define P2_CC P1_CC /* control character specifier: */ X#define P2_CC_IAC P1_CC_IAC /* IAC */ X#define P2_CC_XON P1_CC_XON /* XON */ X#define P2_CC_XOFF P1_CC_XOFF /* XOFF */ X#define P2_MF P1_MF /* maintenance functions: */ X#define P2_MF_ENTRY P1_MF_ENTRY /* beginning execution */ X#define P2_MF_ASKPCL P1_MF_ASKPCL /* request protocol negotiation */ X#define P2_MF_CANPCL P1_MF_CANPCL /* suggest protocol */ X#define P2_MF_SETPCL P1_MF_SETPCL /* set current protocol */ X#define P2_MF_EXIT P1_MF_EXIT /* execution terminating */ X#define P2_NWINDOW P1_NWINDOW /* maximum number of windows */ X X/* X * Protocol negotiation X * X * The server is not used for protocol 0. For the other protocols, the X * Macintosh and the server negotiate to select the active protocol. The X * basic idea is that the Macintosh will express its desire for a protocol X * and the server will attempt to satisfy that desire. Until negotiations X * are complete, protocol 1 is used. X * X * Protocols are identified by single-character names which are formed by X * adding the ASCII code for a space (040) to the protocol number minus 1 X * (i.e. protocol 1 is ' ', protocol 2 is '!'). X * X * P1_FN_CANPCL and P1_FN_SETPCL are three-byte commands: P1_IAC, X * P1_FN_XXXPCL, protocol-name. X * X * Macintosh: X * If UW v2.10 is used on the Macintosh or if a newer Macintosh program X * wishes to use protocol 1, it will never initiate protocol negotiation. X * Hence, all interaction will use protocol 1 by default. X * X * If the Macintosh program is capable of supporting protocol 2 and the X * user requests its use, the Mac will remember this fact but will X * continue to use protocol 1. The Mac program will assume that no X * server is present until instructed otherwise by the user or until a X * P1_FN_ENTRY command is received (e.g. when the server starts up). X * At this time, the Mac program issues P1_FN_ASKPCL. If the server X * cannot support protocol 2 (i.e. it is an old server), then it will X * ignore the P1_FN_ASKPCL. The Macintosh will retry the P1_FN_ASKPCL X * a couple of times (about five seconds apart) and, if there is no X * response from the server, will abandon negotiations. Protocol 1 X * will be used for the remainder of the session. X * X * If the server recognizes the P1_FN_ASKPCL command it will respond X * with the name of the most complex protocol it can support (currently X * '!'). If this is acceptable to the Macintosh, it will instruct the X * server to use this protocol. If the Macintosh cannot support this X * protocol it will respond with a P1_FN_CANPCL suggesting a less-complex X * protocol. If the server agrees to this it will answer establish the X * protocol; otherwise, it will suggest an even weaker protocol. X * Eventually someone will suggest protocol 1 (which is universal) and X * the other side will issue a P1_FN_SETPCL command to establish its use. X * X * Host: X * If the host receives a P1_FN_ASKPCL it will respond with the most X * complex protocol it can support (using the P1_FN_CANPCL command). X * Negotiations will proceed as described above until one side X * establishes a new protocol with P1_FN_SETPCL. At this time, the X * host will switch to the new protocol. X * X * If the host receives a P1_FN_ENTRY (P2_FN_ENTRY) command, it will X * switch back to protocol 1. Receipt of this command indicates that X * the Macintosh program was restarted. The Macintosh must initiate X * protocol negotiations again. X */ X X/* X * Although many of the functions are identical (and the code is shared X * between them), each protocol is accessed through a (struct protocol) X * which specifies the functions for various operations. X * X * In theory, the main program knows nothing about the protocol in use. X * In practice, the externally-visible functions are accessed as macros X * for greater efficiency. X * X * The protocol layer is aware of the (struct window) data structures. X */ X Xstruct protocol { X char p_name; /* single-character protocol name */ X nwin_t p_maxwin; /* maximum window number */ X int *p_ctlch; /* control character map table */ X unsigned p_szctlch; /* size (# of entries) in ctlch table */ X void (*p_entry)(); /* start up (ENTRY maintenance fn) */ X void (*p_exit)(); /* shut down (EXIT maintenance fn) */ X void (*p_renew)(); /* renew (re-init) */ X struct window *(*p_neww)(); /* create new window */ X void (*p_killw)(); /* kill window */ X void (*p_xmit)(); /* transmit to specified window */ X void (*p_recv)(); /* receive from Macintosh */ X void (*p_chkopt)(); /* check for pending option output */ X void (*p_sendopt)(); /* send option string to Macintosh */ X void (*p_askpcl)(); /* send an ASKPCL maintenance command */ X void (*p_canpcl)(); /* send a CANPCL maintenance command */ X void (*p_setpcl)(); /* send a SETPCL maintenance command */ X}; X Xextern struct protocol *protocol; X X#define PCL_NEWW(mfd,class,wtype,wnum,wid,dfd,cfd) \ X (*protocol->p_neww)(mfd,class,wtype,wnum,(long)wid,dfd,cfd) X#define PCL_KILLW(mfd,w) (*protocol->p_killw)(mfd,w) X#define PCL_RECV(mfd,buf,len) (*protocol->p_recv)(mfd,buf,len) X#define PCL_XMIT(mfd,w) (*protocol->p_xmit)(mfd,w) X#define PCL_SENDOPT(mfd,fn,buf,len) \ X (protocol->p_sendopt ? (*protocol->p_sendopt)(mfd,fn,buf,len) : 0) X#endif !EOF!h/uw_pcl.h! echo x - h/uw_win.h sed -e 's/^X//' > h/uw_win.h << '!EOF!h/uw_win.h!' X/* X * uw window data definition 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#ifndef UW_WIN X#define UW_WIN X X#include "uw_opt.h" X X/* X * A "point" is a pair of 16-bit integers. This may specify the horizontal X * and vertical position or size of a window. X */ Xtypedef short npixel_t; /* number of pixels */ Xstruct point { X npixel_t v,h; X}; X X/* X * The type of a window determines how it responds to I/O and which X * window options it supports. I'd like to declare these with an "enum", X * but the stupid PCC screams if I use enums as array indices, so they X * are defined via #define's instead. X */ Xtypedef unsigned int wtype_t; /* window type: */ X#define WT_ADM31 0 /* ADM-31 terminal emulation */ X#define WT_VT52 1 /* VT52 terminal emulation */ X#define WT_ANSI 2 /* ANSI terminal emulation */ X#define WT_TEK4010 3 /* Tek4010 terminal emulation */ X#define WT_FTP 4 /* file transfer */ X#define WT_PRINT 5 /* output to printer */ X#define WT_MAXTYPE 5 /* maximum window type */ X Xextern wtype_t defwtype; /* default window type */ X X/* X * There are two basic classes of windows -- those which are processed X * directly by the server and those which are processed by outside X * programs. Directly-handled windows are always terminal emulations. X * Externally-handled windows may be any window type. X */ Xtypedef enum { /* window class: */ X WC_INTERNAL, /* processed directly */ X WC_EXTERNAL, /* processed externally */ X} wclass_t; X Xstruct window { X int w_alloc; /* window allocated if nonzero */ X long w_id; /* window unique ID */ X wtype_t w_type; /* window emulation type */ X wclass_t w_class; /* window class */ X fildes_t w_datafd; /* data file descriptor */ X union { X struct winint { X char wi_tty[32]; /* terminal name */ X } wu_int; X struct winext { X fildes_t we_ctlfd; /* control file descriptor */ X } wu_ext; X } w_un; X struct woptdefn w_optdefn; /* window option definitions */ X int w_visible; /* nonzero if window is visible */ X struct point w_position; /* position of window on screen */ X struct point w_size; /* size of window in pixels */ X char w_title[256]; /* window title */ X char *w_private; /* storage private to emulation type */ X}; X#define w_tty w_un.wu_int.wi_tty X#define w_ctlfd w_un.wu_ext.we_ctlfd X Xtypedef int nwin_t; /* window index data type */ X X/* X * Some operations upon windows depend upon the window type. For each X * emulation type there is a "emulation" structure which specifies X * emulation-specific data. X */ Xstruct emulation { X struct woptdefn we_optdefn; /* window option definitions */ X int (*we_start)(); /* emulation setup code */ X void (*we_stop)(); /* emulation shutdown code */ X void (*we_setext)(); /* make changes req'd for extern win */ X}; X Xextern struct window *win_neww(); /* create new window */ Xextern struct window *win_search(); /* convert window ID to window ptr */ X X/* X * The following macros convert between a window number and a pointer to X * the corresponding window structure (and vice versa). X * X * NWINDOW *must* be >= P1_NWINDOW and >= P2_NWINDOW (in "uw_pcl.h"). X */ X#define NWINDOW 7 /* maximum number of windows */ X#define WIN_NUM(wptr) ((wptr)-window+1) X#define WIN_PTR(wnum) (window+(wnum)-1) Xextern struct window window[]; /* window data structures */ X#endif !EOF!h/uw_win.h! echo x - h/uwlib.h sed -e 's/^X//' > h/uwlib.h << '!EOF!h/uwlib.h!' X/* X * uw library definitions 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 "uw_err.h" X#include "uw_ipc.h" X X#define UW_NUMOPTS 32 /* number of window options */ X#define UW_NWTYPES 6 /* number of window emulation types */ X X#ifndef NBBY /* this is in in 4.3BSD */ X#define NBBY 8 /* (number of bits/byte) */ X#endif X Xtypedef char uwtitle_t[256]; X Xstruct uwpoint { X unsigned uwp_v; /* vertical component */ X unsigned uwp_h; /* horizontal component */ X}; X Xstruct uw_info { X uwid_t uwi_id; /* unique window ID */ X int uwi_datafd; /* file descriptor for data */ X int uwi_ctlfd; /* file descriptor for control */ X uwerr_t uwi_uwerr; /* last error from UW */ X int uwi_errno; /* last error from system call */ X int uwi_vis; /* visiblility */ X uwtype_t uwi_type; /* window type */ X struct uwpoint uwi_pos; /* window position (in pixels) */ X uwtitle_t uwi_title; /* window title */ X struct uwpoint uwi_wsize; /* window size (in pixels) */ X struct { X void (*uwi_optfn)(); /* option handler */ X } uwi_options[UW_NUMOPTS]; X int uwi_ipclen; /* length of data in IPC buffer */ X struct uwipc uwi_ipcbuf; /* buffer for IPC messages */ X}; X X#define UW_DATAFD(uwin) (uwin)->uwi_datafd X#define UW_ID(uwin) (uwin)->uwi_id X#define UW_PERROR(uwin, mesg) \ X uw_perror(mesg, (uwin)->uwi_uwerr, (uwin)->uwi_errno) X Xtypedef struct uw_info *UWIN; Xtypedef void (*uwfnptr_t)(); X Xextern uwid_t uw_cmd(); Xextern UWIN uw_new(); Xextern uw_close(), uw_detach(); Xextern uw_optcmd(); Xextern uw_kill(); Xextern uwfnptr_t uw_optfn(); Xextern uw_rsetopt(); Xextern void uw_perror(); Xextern uwid_t uw_fork(), uw_cmd(), uw_shell(); X Xextern uw_gvis(), uw_svis(); Xextern uw_gtype(), uw_stype(); Xextern uw_gtitle(), uw_stitle(); Xextern uw_gwsize(), uw_swsize(); Xextern uw_gpos(), uw_spos(); X Xextern uwerr_t uwerrno; Xextern char *uwerrlist[]; Xextern unsigned uwnerr; !EOF!h/uwlib.h! 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 v3.4. !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(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 (= 80 temp) 81 temp))) X (let ((temp (car (cdr (cdr (cdr edges)))))) X (setq yb (if (= 24 temp) 25 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 80 columns X (let ((window-offset (window-hscroll));in the center column of the window X delta) ;unless that would move column 0 or 80 X (setq delta ;past the window edge X (- window-offset X (min (max 0 (- (/ (* 80 p) 100) X (/ (- xr xl) 2))) X (- 80 (- 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 (part 1 of 9)