Path: utzoo!mnetor!uunet!ccicpg!felix!dhw68k!macintosh From: jdb@mordor.s1.gov (John Bruner) Newsgroups: comp.sources.mac Subject: UW v4.2 (part 4 of 9) Message-ID: <6538@dhw68k.cts.com> Date: 6 Apr 88 02:12:37 GMT References: <6493@dhw68k.cts.com> <6497@dhw68k.cts.com> <6515@dhw68k.cts.com> Sender: macintosh@dhw68k.cts.com Organization: Lawrence Livermore National Laboratory, S-1 Project Lines: 1430 Approved: bytebug@dhw68k.cts.com (Roger L. Long) [UW v4.2 - part 4 of 9] --- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # lib/Makefile_4.2 # lib/Makefile_4.3 # lib/uw_close.c # lib/uw_cmd.c # lib/uw_detach.c # lib/uw_fork.c # lib/uw_gpos.c # lib/uw_gtitle.c # lib/uw_gtype.c # lib/uw_gvis.c # lib/uw_gwsize.c # lib/uw_kill.c # lib/uw_netadj.c # lib/uw_new.c # lib/uw_optcmd.c # This archive created: Mon Apr 4 07:51:53 1988 # By: Roger L. Long (macintosh@dhw68k.cts.com) export PATH; PATH=/bin:$PATH if test ! -d lib then echo shar: mkdir lib mkdir lib fi echo shar: extracting "'lib/Makefile_4.2'" '(1710 characters)' if test -f 'lib/Makefile_4.2' then echo shar: will not over-write existing file "'lib/Makefile_4.2'" else sed 's/^X//' << \SHAR_EOF > 'lib/Makefile_4.2' X#! /bin/make -f X# X# uw library makefile (4.2BSD) X# X# INCDIR names the directory in which header files are located. X# SERVERDIR names the directory containing the server source. X# SERVER_OBJS names the object files derived from sources in SERVERDIR. X# OBJECTS names all of the object files required for the library. X# XINCDIR = ../h X XSERVERDIR = ../server X XSERVER_OBJS = $(SERVERDIR)/openpty.o $(SERVERDIR)/uw_env.o X XOBJECTS = uw_cmd.o uw_close.o uw_detach.o uw_fork.o uw_kill.o \ X uw_netadj.o uw_new.o uw_optcmd.o uw_optfn.o uw_options.o \ X uw_perror.o uw_ttype.o \ X uw_rsetopt.o uw_shell.o \ X uw_gvis.o uw_gtype.o uw_gtitle.o uw_gwsize.o uw_gpos.o \ X $(SERVER_OBJS) X XSOURCES = `echo $(OBJECTS) | sed -e 's/\\.o/\\.c/g'` X XDEFINES = `cat ../DEFINES` X XCFLAGS = -O -I$(INCDIR) $(DEFINES) X XTARGET = libuw.a X X$(TARGET): $(OBJECTS) X ar cr $(TARGET) `lorder $(OBJECTS) | tsort` X ranlib $(TARGET) X -if [ ! -f uwlib.a ];then ln -s libuw.a uwlib.a;fi X X$(SERVER_OBJS): X cd $(SERVERDIR); make `basename $@` X Xlint: X lint -uhbx -I$(INCDIR) $(DEFINES) $(SOURCES) X Xtags: X ctags $(SOURCES) X Xdepend: X grep '^#include' $(SOURCES) | \ X sed -e '/ 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 *.o X X# DO NOT DELETE THIS LINE (or the following blank line) -- make depend uses it X SHAR_EOF if test 1710 -ne "`wc -c < 'lib/Makefile_4.2'`" then echo shar: error transmitting "'lib/Makefile_4.2'" '(should have been 1710 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/Makefile_4.3'" '(1678 characters)' if test -f 'lib/Makefile_4.3' then echo shar: will not over-write existing file "'lib/Makefile_4.3'" else sed 's/^X//' << \SHAR_EOF > 'lib/Makefile_4.3' X#! /bin/make -f X# X# uw library makefile (4.3BSD) X# X# INCDIR names the directory in which header files are located. X# SERVERDIR names the directory containing the server source. X# SERVER_OBJS names the object files derived from sources in SERVERDIR. X# OBJECTS names all of the object files required for the library. X# X XINCDIR = ../h X XSERVERDIR = ../server X XSERVER_OBJS = $(SERVERDIR)/openpty.o $(SERVERDIR)/uw_env.o X XOBJECTS = uw_cmd.o uw_close.o uw_detach.o uw_fork.o uw_kill.o \ X uw_netadj.o uw_new.o uw_optcmd.o uw_optfn.o uw_options.o \ X uw_perror.o uw_ttype.o \ X uw_rsetopt.o uw_shell.o \ X uw_gvis.o uw_gtype.o uw_gtitle.o uw_gwsize.o uw_gpos.o \ X $(SERVER_OBJS) X XSOURCES = `echo $(OBJECTS) | sed -e 's/\\.o/\\.c/g'` X XDEFINES = `cat ../DEFINES` X XCFLAGS = -O -I$(INCDIR) $(DEFINES) X XTARGET = libuw.a X X$(TARGET): $(OBJECTS) X ar cr $(TARGET) `lorder $(OBJECTS) | tsort` X ranlib $(TARGET) X -if [ ! -f uwlib.a ];then ln -s libuw.a uwlib.a;fi X X$(SERVER_OBJS): X cd $(SERVERDIR); make `basename $@` X Xlint: X lint -uhbx -I$(INCDIR) $(DEFINES) $(SOURCES) 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 *.o X X# DO NOT DELETE THIS LINE (or the following blank line) -- make depend uses it X SHAR_EOF if test 1678 -ne "`wc -c < 'lib/Makefile_4.3'`" then echo shar: error transmitting "'lib/Makefile_4.3'" '(should have been 1678 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_close.c'" '(575 characters)' if test -f 'lib/uw_close.c' then echo shar: will not over-write existing file "'lib/uw_close.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_close.c' X/* X * uw library - uw_close 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 "uwlib.h" X Xuw_close(uwin) XUWIN uwin; X{ X /* X * Close all connections to an existing window, but do not kill it. X */ X if (uwin != (UWIN)0) { X if (uwin->uwi_ctlfd >= 0) X (void)uw_detach(uwin); X if (uwin->uwi_datafd >= 0) X (void)close(uwin->uwi_datafd); X free((char *)uwin); X return(0); X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} SHAR_EOF if test 575 -ne "`wc -c < 'lib/uw_close.c'`" then echo shar: error transmitting "'lib/uw_close.c'" '(should have been 575 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_cmd.c'" '(799 characters)' if test -f 'lib/uw_cmd.c' then echo shar: will not over-write existing file "'lib/uw_cmd.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_cmd.c' X/* X * uw library - uw_cmd 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 "uwlib.h" X Xuwid_t Xuw_cmd(wtype, file, argv) Xuwtype_t wtype; Xchar *file; Xchar **argv; X{ X register uwid_t uwid; X X /* X * Create a new window (using uw_fork()) and run the specified X * command in it. Returns the window ID of the new window X * (or -1 if the window creation failed). There is no way to X * determine if the executed command failed (e.g. if the X * executable file did not exist). X */ X if ((uwid = uw_fork(wtype, (int *)0)) == 0) { X (void)execvp(file, argv); X uwerrno = UWE_ERRNO; X perror(file); X _exit(1); X /*NOTREACHED*/ X } else X return(uwid); X} SHAR_EOF if test 799 -ne "`wc -c < 'lib/uw_cmd.c'`" then echo shar: error transmitting "'lib/uw_cmd.c'" '(should have been 799 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_detach.c'" '(677 characters)' if test -f 'lib/uw_detach.c' then echo shar: will not over-write existing file "'lib/uw_detach.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_detach.c' X/* X * uw library - uw_detach 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 "uwlib.h" X Xuw_detach(uwin) XUWIN uwin; X{ X /* X * Detach the control file descriptor for a window, while still X * retaining access to the data file descriptor. X */ X if (uwin != (UWIN)0) { X if (uwin->uwi_ctlfd >= 0) { X uw_optdone(uwin->uwi_ctlfd); X (void)close(uwin->uwi_ctlfd); X uwin->uwi_ctlfd = -1; X return(0); X } else { X uwerrno = uwin->uwi_uwerr = UWE_NOCTL; X return(-1); X } X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} SHAR_EOF if test 677 -ne "`wc -c < 'lib/uw_detach.c'`" then echo shar: error transmitting "'lib/uw_detach.c'" '(should have been 677 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_fork.c'" '(4704 characters)' if test -f 'lib/uw_fork.c' then echo shar: will not over-write existing file "'lib/uw_fork.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_fork.c' X/* X * uw library - uw_fork 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 X#include X#include X#include X#include X#include X#include X#include X#include "openpty.h" X X#include "uwlib.h" X Xextern char *malloc(); Xextern char *getenv(); X Xuwid_t Xuw_fork(wtype, pidp) Xuwtype_t wtype; Xint *pidp; X{ X register int pid; X register int sd; X register struct uwipc *uwip; X register uwid_t wid; X auto int fd; X char *portal; X int lmode, ldisc; X struct sgttyb sg; X struct tchars tc; X struct ltchars ltc; X struct iovec iov; X struct msghdr msg; X struct sockaddr_un sa; X struct ptydesc pt; X char idstr[20]; X char *env[2]; X extern char *ltoa(); X X /* X * Create a new window attached to a pseudo-terminal. This routine X * returns twice -- once in the parent and once in the (new) child. X * The parent receives the window ID of the child (or -1 if the X * window creation failed). Zero is returned to the child. X * If "pidp" is a non-NULL pointer, the process ID from the fork() X * is stored there. X */ X X /* X * Get the terminal configuration for this tty. For now we X * assume that "/dev/tty" is defined. Eventually we'll have to X * provide defaults in case it is not. X */ X if ((fd = open("/dev/tty", O_RDWR)) >= 0) { X (void)ioctl(fd, (int)TIOCGETP, (char *)&sg); X (void)ioctl(fd, (int)TIOCGETC, (char *)&tc); X (void)ioctl(fd, (int)TIOCGLTC, (char *)<c); X (void)ioctl(fd, (int)TIOCLGET, (char *)&lmode); X (void)ioctl(fd, (int)TIOCGETD, (char *)&ldisc); X (void)close(fd); X } else { X /* ... */ X } X X /* X * Create a UNIX-domain socket. X */ X if (!(portal=getenv("UW_UIPC"))) { X uwerrno = UWE_NXSERV; X return(-1); X } X X if ((sd=socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) { X uwerrno = UWE_ERRNO; X return(-1); X } X sa.sun_family = AF_UNIX; X (void)strncpy(sa.sun_path, portal, sizeof sa.sun_path-1); X sa.sun_path[sizeof sa.sun_path-1] = '\0'; X X X /* X * Obtain a pseudo-tty and construct the datagram we will send later. X */ X if (openpty(&pt) < 0) { X uwerrno = UWE_ERRNO; X return(-1); X } X uwip = (struct uwipc *)malloc(sizeof(struct uwipc)+strlen(pt.pt_pname)); X env[0] = malloc(sizeof "UW_ID=" + sizeof idstr); X if (uwip == (struct uwipc *)0 || env[0] == (char *)0) { X uwerrno = UWE_NOMEM; X return(-1); X } X uwip->uwip_cmd = UWC_NEWT; X uwip->uwip_len = (char *)&uwip->uwip_newt - (char *)uwip + X sizeof(struct uwnewt) + strlen(pt.pt_pname); X uwip->uwip_newt.uwnt_type = wtype; X (void)strcpy(uwip->uwip_newt.uwnt_pty, pt.pt_pname); X X X /* X * Fork a child process using this pseudo-tty. Initialize the X * terminal modes on the pseudo-tty to match those of the parent X * tty. We really want a fork() here, not a vfork(). X */ X while ((pid=fork()) < 0) X sleep(5); X if (pidp != (int *)0) X *pidp = pid; X if (pid) { X wid = (long)pid << 16; X uwip->uwip_newt.uwnt_id = wid; X } else { X (void)setgid(getgid()); X (void)setuid(getuid()); X wid = (long)getpid() << 16; X (void)strcat(strcpy(env[0], "UW_ID="), X ltoa(wid, idstr, sizeof idstr)); X env[1] = (char *)0; X env_set(env); X (void)signal(SIGTSTP, SIG_IGN); X (void)ioctl(open("/dev/tty", 2), (int)TIOCNOTTY, (char *)0); X (void)close(open(pt.pt_tname, 0)); /*set new ctrl tty */ X (void)dup2(pt.pt_tfd, 0); X (void)dup2(0, 1); X (void)dup2(0, 2); X fd = getdtablesize(); X while (--fd > 2) X (void)close(fd); X (void)ioctl(fd, (int)TIOCSETD, (char *)&ldisc); X (void)ioctl(0, (int)TIOCSETN, (char *)&sg); X (void)ioctl(0, (int)TIOCSETC, (char *)&tc); X (void)ioctl(0, (int)TIOCSLTC, (char *)<c); X (void)ioctl(0, (int)TIOCLSET, (char *)&lmode); X uwerrno = UWE_NONE; X return(0); X } X X X /* X * Pass the file descriptor to the window server. X */ X iov.iov_base = (char *)uwip; X iov.iov_len = uwip->uwip_len; X msg.msg_name = (caddr_t)&sa; X msg.msg_namelen = sizeof sa.sun_family + strlen(sa.sun_path); X msg.msg_iov = &iov; X msg.msg_iovlen = 1; X msg.msg_accrights = (caddr_t)&pt.pt_pfd; X msg.msg_accrightslen = sizeof pt.pt_pfd; X if (sendmsg(sd, &msg, 0) < 0) { X free((char *)uwip); X uwerrno = UWE_ERRNO; X return(-1); X } X free((char *)uwip); X uwerrno = UWE_NONE; X return(wid); X} X Xstatic Xchar * Xltoa(l, buf, buflen) Xlong l; Xchar *buf; Xint buflen; X{ X register char *cp; X register unsigned long ul; X static char digits[] = "0123456789"; X X /* X * This routine replaces a call to sprintf() so that the library X * is independent of stdio. X */ X cp = buf+buflen; X *--cp = '\0'; X ul = l; X if (cp > buf) { X do { X *--cp = digits[ul%10]; X ul /= 10; X } while (cp > buf && ul != 0); X } X return(cp); X} SHAR_EOF if test 4704 -ne "`wc -c < 'lib/uw_fork.c'`" then echo shar: error transmitting "'lib/uw_fork.c'" '(should have been 4704 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_gpos.c'" '(1224 characters)' if test -f 'lib/uw_gpos.c' then echo shar: will not over-write existing file "'lib/uw_gpos.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_gpos.c' X/* X * uw library - uw_gpos, uw_spos 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 "uwlib.h" X Xuw_gpos(uwin, pp) Xregister UWIN uwin; Xregister struct uwpoint *pp; X{ X /* X * Get the position of window "uwin" and store it in the point X * whose address is "pp". X */ X if (uwin != (UWIN)0) { X if (pp != (struct uwpoint *)0) { X *pp = uwin->uwi_pos; X if (uwin->uwi_ctlfd > 0) { X return(0); X } else { X uwerrno = uwin->uwi_uwerr = UWE_NOCTL; X return(-1); X } X } else { X uwerrno = uwin->uwi_uwerr = UWE_INVAL; X return(-1); X } X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} X Xuw_spos(uwin, pp) Xregister UWIN uwin; Xstruct uwpoint *pp; X{ X union uwoptval optval; X X /* X * Set the position of window "uwin" to "pp". X */ X if (uwin != (UWIN)0) { X if (pp != (struct uwpoint *)0) { X uwin->uwi_pos = *pp; X optval.uwov_point.v = pp->uwp_v; X optval.uwov_point.h = pp->uwp_h; X return(uw_optcmd(uwin, UWOP_POS, UWOC_SET, &optval)); X } else { X uwerrno = uwin->uwi_uwerr = UWE_INVAL; X return(-1); X } X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} SHAR_EOF if test 1224 -ne "`wc -c < 'lib/uw_gpos.c'`" then echo shar: error transmitting "'lib/uw_gpos.c'" '(should have been 1224 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_gtitle.c'" '(1162 characters)' if test -f 'lib/uw_gtitle.c' then echo shar: will not over-write existing file "'lib/uw_gtitle.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_gtitle.c' X/* X * uw library - uw_gtitle, uw_stitle 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 X#include "uwlib.h" X Xuw_gtitle(uwin, ttl) Xregister UWIN uwin; Xuwtitle_t ttl; X{ X /* X * Get the title of window "uwin" and put it in "ttl". X */ X if (uwin != (UWIN)0) { X (void)strncpy(ttl, uwin->uwi_title, sizeof(uwtitle_t)); X if (uwin->uwi_ctlfd > 0) { X return(0); X } else { X uwerrno = uwin->uwi_uwerr = UWE_NOCTL; X return(-1); X } X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} X Xuw_stitle(uwin, ttl) Xregister UWIN uwin; Xuwtitle_t ttl; X{ X union uwoptval optval; X X /* X * Set the title of window "uwin" to "ttl". X */ X if (uwin != (UWIN)0) { X (void)strncpy(uwin->uwi_title, ttl, sizeof uwin->uwi_title); X uwin->uwi_title[sizeof uwin->uwi_title - 1] = '\0'; X (void)strncpy(optval.uwov_string,ttl,sizeof optval.uwov_string); X optval.uwov_string[sizeof optval.uwov_string - 1] = '\0'; X return(uw_optcmd(uwin, UWOP_TITLE, UWOC_SET, &optval)); X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} SHAR_EOF if test 1162 -ne "`wc -c < 'lib/uw_gtitle.c'`" then echo shar: error transmitting "'lib/uw_gtitle.c'" '(should have been 1162 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_gtype.c'" '(1182 characters)' if test -f 'lib/uw_gtype.c' then echo shar: will not over-write existing file "'lib/uw_gtype.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_gtype.c' X/* X * uw library - uw_gtype, uw_stype 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 "uwlib.h" X Xuw_gtype(uwin, tp) Xregister UWIN uwin; Xregister uwtype_t *tp; X{ X /* X * Get the type of the window "uwin". The window type is stored X * in the variable whose address is passed in "tp". X */ X if (uwin != (UWIN)0) { X if (tp != (uwtype_t *)0) { X *tp = uwin->uwi_type; X if (uwin->uwi_ctlfd > 0) { X return(0); X } else { X uwerrno = uwin->uwi_uwerr = UWE_NOCTL; X return(-1); X } X } else { X uwerrno = uwin->uwi_uwerr = UWE_INVAL; X return(-1); X } X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} X Xuw_stype(uwin, t) Xregister UWIN uwin; Xint t; X{ X union uwoptval optval; X X /* X * Set the type of window "uwin" to "t". X */ X X if (uwin != (UWIN)0) { X if (t < UW_NWTYPES) { X uwin->uwi_type = t; X optval.uwov_6bit = uwin->uwi_type; X return(uw_optcmd(uwin, UWOP_TYPE, UWOC_SET, &optval)); X } else { X uwerrno = uwin->uwi_uwerr = UWE_INVAL; X return(-1); X } X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} SHAR_EOF if test 1182 -ne "`wc -c < 'lib/uw_gtype.c'`" then echo shar: error transmitting "'lib/uw_gtype.c'" '(should have been 1182 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_gvis.c'" '(1093 characters)' if test -f 'lib/uw_gvis.c' then echo shar: will not over-write existing file "'lib/uw_gvis.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_gvis.c' X/* X * uw library - uw_gvis, uw_svis 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 "uwlib.h" X Xuw_gvis(uwin, vp) Xregister UWIN uwin; Xregister int *vp; X{ X /* X * Get the visibility status of the window "uwin". "vp" is a X * pointer to the integer where the status is returned. X */ X if (uwin != (UWIN)0) { X if (vp != (int *)0) { X *vp = uwin->uwi_vis; X if (uwin->uwi_ctlfd > 0) { X return(0); X } else { X uwerrno = uwin->uwi_uwerr = UWE_NOCTL; X return(-1); X } X } else { X uwerrno = uwin->uwi_uwerr = UWE_INVAL; X return(-1); X } X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} X Xuw_svis(uwin, v) Xregister UWIN uwin; Xint v; X{ X union uwoptval optval; X X /* X * Make window "uwin" visible (v != 0) or invisible (v == 0). X */ X if (uwin != (UWIN)0) { X uwin->uwi_vis = (v != 0); X optval.uwov_1bit = uwin->uwi_vis; X return(uw_optcmd(uwin, UWOP_VIS, UWOC_SET, &optval)); X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} SHAR_EOF if test 1093 -ne "`wc -c < 'lib/uw_gvis.c'`" then echo shar: error transmitting "'lib/uw_gvis.c'" '(should have been 1093 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_gwsize.c'" '(1246 characters)' if test -f 'lib/uw_gwsize.c' then echo shar: will not over-write existing file "'lib/uw_gwsize.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_gwsize.c' X/* X * uw library - uw_gwsize, uw_swsize 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 "uwlib.h" X Xuw_gwsize(uwin, pp) Xregister UWIN uwin; Xregister struct uwpoint *pp; X{ X /* X * Get the (pixel) size of window "uwin" and store it in the X * point whose address is "pp". X */ X if (uwin != (UWIN)0) { X if (pp != (struct uwpoint *)0) { X *pp = uwin->uwi_wsize; X if (uwin->uwi_ctlfd > 0) { X return(0); X } else { X uwerrno = uwin->uwi_uwerr = UWE_NOCTL; X return(-1); X } X } else { X uwerrno = uwin->uwi_uwerr = UWE_INVAL; X return(-1); X } X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} X Xuw_swsize(uwin, pp) Xregister UWIN uwin; Xstruct uwpoint *pp; X{ X union uwoptval optval; X X /* X * Set the (pixel) size of window "uwin" to "pp". X */ X if (uwin != (UWIN)0) { X if (pp != (struct uwpoint *)0) { X uwin->uwi_wsize = *pp; X optval.uwov_point.v = pp->uwp_v; X optval.uwov_point.h = pp->uwp_h; X return(uw_optcmd(uwin, UWOP_WSIZE, UWOC_SET, &optval)); X } else { X uwerrno = uwin->uwi_uwerr = UWE_INVAL; X return(-1); X } X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} SHAR_EOF if test 1246 -ne "`wc -c < 'lib/uw_gwsize.c'`" then echo shar: error transmitting "'lib/uw_gwsize.c'" '(should have been 1246 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_kill.c'" '(1341 characters)' if test -f 'lib/uw_kill.c' then echo shar: will not over-write existing file "'lib/uw_kill.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_kill.c' X/* X * uw library - uw_kill 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 X#include X X#include "uwlib.h" X X#ifndef htons X/* These should have been defined in , but weren't (in 4.2BSD) */ Xextern unsigned short htons(), ntohs(); Xextern unsigned long htonl(), ntohl(); X#endif X Xuw_kill(uwin) XUWIN uwin; X{ X register int len; X struct uwipc uwip; X extern int errno; X X /* X * Kill the window "uwin". After putting out the contract, X * destroy the evidence by closing all existing connections X * to the window. X */ X if (uwin != (UWIN)0) { X if (uwin->uwi_ctlfd >= 0) { X len = sizeof uwip.uwip_killw + X (char *)&uwip.uwip_killw - (char *)&uwip; X uwip.uwip_len = htons(len); X uwip.uwip_cmd = htons(UWC_KILLW); X uwip.uwip_killw.uwkw_id = htonl(uwin->uwi_id); X if (write(uwin->uwi_ctlfd, (char *)&uwip, len) < 0) { X uwin->uwi_errno = errno; X uwerrno = uwin->uwi_uwerr = UWE_ERRNO; X } else X uwerrno = uwin->uwi_uwerr = UWE_NONE; X (void)uw_detach(uwin); X } else X uwerrno = uwin->uwi_uwerr = UWE_NOCTL; X if (uwin->uwi_uwerr == UWE_NONE) X return(0); X else X return(-1); X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} SHAR_EOF if test 1341 -ne "`wc -c < 'lib/uw_kill.c'`" then echo shar: error transmitting "'lib/uw_kill.c'" '(should have been 1341 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_netadj.c'" '(4215 characters)' if test -f 'lib/uw_netadj.c' then echo shar: will not over-write existing file "'lib/uw_netadj.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_netadj.c' X/* X * uw library - uw_netadj 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 X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include "openpty.h" X X#include "uw_opt.h" /* I had hoped to avoid including this */ X#include "uwlib.h" X Xstatic woptarg_t woa_vis[] = { WOA_UDATA(1), WOA_END }; Xstatic woptarg_t woa_type[] = { WOA_UDATA(6), WOA_END }; Xstatic woptarg_t woa_pos[] = { WOA_UDATA(12), WOA_UDATA(12), WOA_END }; Xstatic woptarg_t woa_title[] = { WOA_STRING(255), WOA_END }; Xstatic woptarg_t woa_size[] = { WOA_UDATA(12), WOA_UDATA(12), WOA_END }; Xstatic woptarg_t woa_tsize[] = { WOA_UDATA(12), WOA_UDATA(12), WOA_END }; Xstatic woptarg_t woa_fontsz[] = { WOA_UDATA(6), WOA_END }; Xstatic woptarg_t woa_clipb[] = { WOA_UDATA(1), WOA_END }; Xstatic woptarg_t woa_bell[] = { WOA_UDATA(2), WOA_END }; Xstatic woptarg_t woa_curs[] = { WOA_UDATA(1), WOA_END }; Xstatic woptarg_t woa_chgsz[] = { WOA_UDATA(1), WOA_END }; X Xstatic woptarg_t *optargs[][WONUM_MAX+1] = { X /* window type 0 == adm31 */ X { X 0, woa_vis, woa_type, woa_pos, woa_title, woa_size, 0, 0, X woa_tsize, woa_fontsz, woa_clipb, woa_bell, woa_curs, woa_chgsz X }, X /* window type 1 == vt52 */ X { X 0, woa_vis, woa_type, woa_pos, woa_title, woa_size, 0, 0, X woa_tsize, woa_fontsz, woa_clipb, woa_bell, woa_curs, woa_chgsz X }, X /* window type 2 == ansi */ X { X 0, woa_vis, woa_type, woa_pos, woa_title, woa_size, 0, 0, X woa_tsize, woa_fontsz, woa_clipb, woa_bell, woa_curs, woa_chgsz X }, X /* window type 3 = tek4010 */ X { X 0, woa_vis, woa_type, woa_pos, woa_title, woa_size, 0, 0, X }, X /* window type 4 = file transfer */ X { X 0, woa_vis, woa_type, woa_pos, woa_title, woa_size, 0, 0, X }, X /* window type 5 = printer */ X { X 0, woa_vis, woa_type, woa_pos, woa_title, woa_size, 0, 0, X }, X /* window type 6 = plot */ X { X 0, woa_vis, woa_type, woa_pos, woa_title, woa_size, 0, 0, X }, X}; X X#ifdef htons Xuw_hton(wtype, optnum, data) Xuwtype_t wtype; Xuwopt_t optnum; Xchar *data; X{ X} X Xuw_ntoh(wtype, optnum, data) Xuwtype_t wtype; Xuwopt_t optnum; Xchar *data; X{ X} X X#else X/* These should have been defined in but weren't (in 4.2BSD) */ Xextern unsigned short htons(), ntohs(); Xextern unsigned long htonl(), ntohl(); X Xuw_hton(wtype, optnum, data) Xuwtype_t wtype; Xuwopt_t optnum; Xchar *data; X{ X static struct netadj na = { X (short (*)())htons, (long (*)())htonl, htons, htonl X }; X if (data != (char *)0 && wtype < sizeof optargs / sizeof optargs[0] && X optnum <= WONUM_MAX && optargs[wtype][optnum] != (woptarg_t *)0) { X netadj(optargs[wtype][optnum], data, &na); X } X} X Xuw_ntoh(wtype, optnum, data) Xuwtype_t wtype; Xuwopt_t optnum; Xchar *data; X{ X static struct netadj na = { X (short (*)())ntohs, (long (*)())ntohl, ntohs, ntohl X }; X if (data != (char *)0 && wtype < sizeof optargs / sizeof optargs[0] && X optnum <= WONUM_MAX && optargs[wtype][optnum] != (woptarg_t *)0) { X netadj(optargs[wtype][optnum], data, &na); X } X} X Xstatic Xnetadj(woa, data, na) Xregister woptarg_t *woa; Xchar *data; Xregister struct netadj *na; X{ X register char *cp; X register int cnt; X union { X struct { X char c1; X short s; X } cs; X struct { X char c2; X long l; X } cl; X } u; X X /* X * Convert an option between host byte order and network byte order. X */ X if (data && na) { X for (cp=data; *woa != WOA_END; woa++) { X cnt = *woa & ~WOA_CMDMASK; X switch (*woa & WOA_CMDMASK) { X case WOA_CHARS(0): X case WOA_STRING(0): X cp += cnt; X break; X case WOA_UDATA(0): X if (cnt <= NBBY) { X cp++; X } else if (cnt <= sizeof(short)*NBBY) { X while ((int)cp & ((char *)&u.cs.s-&u.cs.c1-1)) X cp++; X *(u_short *)cp = X (*na->na_ushort)(*(u_short *)cp); X cp += sizeof(short); X } else { X while ((int)cp & ((char *)&u.cl.l-&u.cl.c2-1)) X cp++; X *(u_short *)cp = X (*na->na_ushort)(*(u_short *)cp); X cp += sizeof(long); X } X } X } X } X} X#endif SHAR_EOF if test 4215 -ne "`wc -c < 'lib/uw_netadj.c'`" then echo shar: error transmitting "'lib/uw_netadj.c'" '(should have been 4215 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_new.c'" '(5791 characters)' if test -f 'lib/uw_new.c' then echo shar: will not over-write existing file "'lib/uw_new.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_new.c' X/* X * uw library - uw_new 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 X#include X#include X#include X#include X#include X#include X#include X#include "openpty.h" X X#include "uwlib.h" X Xextern char *malloc(); Xextern char *getenv(); X X#ifndef htons X/* These should have been defined in , but weren't (in 4.2BSD) */ Xextern unsigned short htons(), ntohs(); Xextern unsigned long htonl(), ntohl(); X#endif X XUWIN Xuw_new(uwtype, sin) Xuwtype_t uwtype; Xstruct sockaddr_in *sin; X{ X register UWIN uwin; X register char *cp, c; X register int len; X register int ctlfd; X int rdsz; X auto int namelen; X auto struct sockaddr_in sa, datasin, ctlsin; X auto struct uwipc uwip; X extern int errno; X X /* X * If our caller didn't supply an address for us to contact, X * look in the environment to find it. X */ X if (sin == (struct sockaddr_in *)0) { X if ((cp = getenv(INET_ENV)) == (char *)0) { X uwerrno = UWE_NXSERV; X return((UWIN)0); X } X sin = &sa; 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 ( ; isxdigit(c = *cp); cp++) { X /* Pyramid compiler blows this, must use left shift */ 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 } X if (sa.sin_addr.s_addr == 0 || sa.sin_port == 0 || X c != '\0') { X /* bad address */ X uwerrno = UWE_INVAL; X return((UWIN)0); X } X sa.sin_addr.s_addr = htonl(sa.sin_addr.s_addr); X sa.sin_port = htons(sa.sin_port); X } X X /* X * Allocate space for a new window structure. X */ X if ((uwin = (UWIN)malloc(sizeof(*uwin))) == (UWIN)0) { X uwerrno = UWE_NOMEM; X return((UWIN)0); X } X uwin->uwi_type = uwtype; X for (len=0; len < UW_NUMOPTS; len++) /* "len" is a convenient "int" */ X uwin->uwi_options[len].uwi_optfn = (uwfnptr_t)0; X X /* X * Create sockets for the data and control file descriptors. X */ X if ((uwin->uwi_datafd = socket(AF_INET, SOCK_STREAM, 0)) < 0 || X (uwin->uwi_ctlfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { X if (uwin->uwi_datafd >= 0) X (void)close(uwin->uwi_datafd); X return((UWIN)0); X } X X /* X * Bind these sockets to a local address. We figure out the X * local machine's host number and use it if possible; otherwise, X * we fall back to 127.0.0.1 (loopback device). After binding, X * we determine the port number for the control socket, since we X * must send that to the server. Connect to the server. X */ X datasin.sin_family = AF_INET; X datasin.sin_port = 0; X bzero(datasin.sin_zero, sizeof datasin.sin_zero); X getmyaddr(&datasin.sin_addr); X ctlsin.sin_family = AF_INET; X ctlsin.sin_port = 0; X bzero(ctlsin.sin_zero, sizeof ctlsin.sin_zero); X getmyaddr(&ctlsin.sin_addr); X if (bind(uwin->uwi_datafd, (struct sockaddr *)&datasin, sizeof datasin) < 0 || X bind(uwin->uwi_ctlfd, (struct sockaddr *)&ctlsin, sizeof ctlsin) < 0 || X listen(uwin->uwi_ctlfd, 1) < 0) { X uwerrno = UWE_ERRNO; X goto error; X } X namelen = sizeof ctlsin; X (void)getsockname(uwin->uwi_ctlfd, (char *)&ctlsin, &namelen); X X if (connect(uwin->uwi_datafd, sin, sizeof(struct sockaddr_in)) < 0) { X uwerrno = UWE_ERRNO; X goto error; X } X X /* X * Now we have enough information to build the new-window command X * and send it to the server. The initial command is sent to the X * data port. Next, we wait for a connection from the server to X * our data socket. Finally, we expect the server to send us a X * new window status message on the data fd. X */ X len = sizeof uwip.uwip_neww + (char *)&uwip.uwip_neww - (char *)&uwip; X uwip.uwip_len = htons(len); X uwip.uwip_cmd = htons(UWC_NEWW); X uwip.uwip_neww.uwnw_id = 0; /* let server choose this */ X uwip.uwip_neww.uwnw_type = htons(uwtype); X uwip.uwip_neww.uwnw_ctlport = ctlsin.sin_port;/* byte order correct */ X if (write(uwin->uwi_datafd, (char *)&uwip, len) < 0) { X uwerrno = UWE_ERRNO; X goto error; X } X X namelen = sizeof ctlsin; X if ((ctlfd = accept(uwin->uwi_ctlfd, (struct sockaddr_in *)&ctlsin, &namelen)) < 0) { X uwerrno = UWE_ERRNO; X goto error; X } X (void)close(uwin->uwi_ctlfd); X uwin->uwi_ctlfd = ctlfd; X uw_optinit(ctlfd, uwin); X X cp = (char *)&uwip.uwip_len; X rdsz = sizeof uwip.uwip_len; X while (rdsz > 0 && (len=read(uwin->uwi_datafd, cp, rdsz)) > 0) { X cp += len; X rdsz -= len; X } X if (len > 0) { X rdsz = htons(uwip.uwip_len) - sizeof uwip.uwip_len; X while (rdsz > 0 && (len=read(uwin->uwi_datafd, cp, rdsz)) > 0) { X cp += len; X rdsz -= len; X } X } X if (len <= 0) { X uwerrno = UWE_ERRNO; X goto error; X } X uwerrno = uwin->uwi_uwerr = ntohs(uwip.uwip_status.uwst_err); X errno = uwin->uwi_errno = ntohs(uwip.uwip_status.uwst_errno); X if (uwin->uwi_uwerr != UWE_NONE) X goto error; X uwin->uwi_id = ntohl(uwip.uwip_status.uwst_id); X return(uwin); X Xerror: X (void)close(uwin->uwi_datafd); X (void)close(uwin->uwi_ctlfd); X free((char *)uwin); X return((UWIN)0); X} X Xstatic Xgetmyaddr(addr) Xstruct in_addr *addr; X{ X register struct hostent *h; X char hostname[32]; X static int once = 1; X static struct in_addr myaddr; X X if (once) { X if (gethostname(hostname, sizeof hostname) < 0) { X (void)strncpy(hostname, "localhost", sizeof hostname-1); X hostname[sizeof hostname-1] = '\0'; X } X if ((h = gethostbyname(hostname)) != (struct hostent *)0) X myaddr = *(struct in_addr *)h->h_addr; X else X myaddr.s_addr = htonl(0x7f000001L); X once = 0; X } X *addr = myaddr; X} SHAR_EOF if test 5791 -ne "`wc -c < 'lib/uw_new.c'`" then echo shar: error transmitting "'lib/uw_new.c'" '(should have been 5791 characters)' fi fi # end of overwriting check echo shar: extracting "'lib/uw_optcmd.c'" '(1899 characters)' if test -f 'lib/uw_optcmd.c' then echo shar: will not over-write existing file "'lib/uw_optcmd.c'" else sed 's/^X//' << \SHAR_EOF > 'lib/uw_optcmd.c' X/* X * uw library - uw_optcmd 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 X#include X X#include "uwlib.h" X X#ifndef htons X/* These should have been defined in , but weren't (in 4.2BSD) */ Xextern unsigned short htons(), ntohs(); Xextern unsigned long htonl(), ntohl(); X#endif X Xuw_optcmd(uwin, optnum, optcmd, optval) XUWIN uwin; Xuwopt_t optnum; Xuwoptcmd_t optcmd; Xunion uwoptval *optval; X{ X register int len; X struct uwipc uwip; X extern int errno; X X /* X * Send an option command string to the server (and eventually X * to the Macintosh). X */ X if (uwin != (UWIN)0) { X if (uwin->uwi_ctlfd >= 0) { X if (optnum < UW_NUMOPTS) { X len = sizeof uwip; X uwip.uwip_len = htons(len); X uwip.uwip_cmd = htons(UWC_OPTION); X uwip.uwip_option.uwop_id = htonl(uwin->uwi_id); X uwip.uwip_option.uwop_opt = htons(optnum); X uwip.uwip_option.uwop_cmd = htons(optcmd); X switch (optcmd) { X case UWOC_SET: X if (optval == (union uwoptval *)0) { X uwin->uwi_uwerr = UWE_INVAL; X break; X } X uwip.uwip_option.uwop_val = *optval; X uw_hton(uwin->uwi_type, optnum, X (char *)&uwip.uwip_option.uwop_val); X /* no break */ X case UWOC_ASK: X case UWOC_DO: X case UWOC_DONT: X case UWOC_WILL: X case UWOC_WONT: X if (write(uwin->uwi_ctlfd, (char *)&uwip, X len) < 0) { X uwin->uwi_uwerr = UWE_ERRNO; X uwin->uwi_errno = errno; X } else X uwin->uwi_uwerr = UWE_NONE; X break; X default: X uwin->uwi_uwerr = UWE_INVAL; X break; X } X } else X uwin->uwi_uwerr = UWE_INVAL; X } X uwerrno = uwin->uwi_uwerr; X if (uwin->uwi_uwerr == UWE_NONE) X return(0); X else X return(-1); X } else { X uwerrno = UWE_INVAL; X return(-1); X } X} SHAR_EOF if test 1899 -ne "`wc -c < 'lib/uw_optcmd.c'`" then echo shar: error transmitting "'lib/uw_optcmd.c'" '(should have been 1899 characters)' fi fi # end of overwriting check # End of shell archive exit 0 --- end of part 4 ---