home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-05-29 | 28.5 KB | 1,138 lines |
- Newsgroups: comp.sources.misc
- From: david@bdt.com (David Beckemeyer)
- Subject: v37i091: ulayers - Unix/X client to MacLayers, Part03/03
- Message-ID: <1993May29.181146.21923@sparky.imd.sterling.com>
- X-Md4-Signature: 9f38e589243d64c0a181ea62267e4ea4
- Sender: kent@sparky.imd.sterling.com (Kent Landfield)
- Organization: Sterling Software
- Date: Sat, 29 May 1993 18:11:46 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: david@bdt.com (David Beckemeyer)
- Posting-number: Volume 37, Issue 91
- Archive-name: ulayers/part03
- Environment: UNIX, X11, PTY
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # Contents: conf.h dial.c makefile numbers.c reply.sh term.c
- # ul_numbers ulayers.h ulterm.cmdtool ulterm.xterm
- # Wrapped by kent@sparky on Sat May 29 13:04:06 1993
- PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 3 (of 3)."'
- if test -f 'conf.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'conf.h'\"
- else
- echo shar: Extracting \"'conf.h'\" \(996 characters\)
- sed "s/^X//" >'conf.h' <<'END_OF_FILE'
- X#ifndef CONF_INCLUDED
- X#define CONF_INCLUDED
- X
- X/* Are we running on a Sequent? (untested) */
- X#undef SEQUENT
- X
- X/* The path to the directory where UUCP locks are found */
- X#define LOCK_DIR "/usr/spool/locks"
- X
- X/* Use the new SVR4 lock format? */
- X#undef SVR4_LOCKS
- X
- X/* Do the lock files use ASCII encoded PID's? */
- X#define ASCII_PID
- X
- X/* Do wse have usleep()? */
- X#define USLEEP
- X
- X/* if no usleep(), shall we use gettimeofday()? */
- X#undef GETTIMEOFDAY
- X
- X/* Define this if you are only going to be using xterm windows */
- X#undef XTERM_TITLE
- X
- X/* The path to the Modem and Port databases */
- X#define LIB_DIR "/usr/local/lib/ulayers"
- X
- X/* Use V7 (BSD) style TTY ioctls? */
- X#undef V7TTY
- X
- X/* If you param.h doesn't have MAXPID, set the maximum legal PID */
- X/* #define MAX_PID 30000 */
- X
- X/* Dialing sequence meta-charcaters */
- X#define PAUSE_CHAR '~' /* pause */
- X#define CR_CHAR '!' /* return */
- X#define CTRL_CHAR '^' /* control */
- X#define ESC_CHAR '|' /* ESC */
- X#define BRK_CHAR '%' /* BREAK */
- X
- X#endif
- END_OF_FILE
- if test 996 -ne `wc -c <'conf.h'`; then
- echo shar: \"'conf.h'\" unpacked with wrong size!
- fi
- # end of 'conf.h'
- fi
- if test -f 'dial.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'dial.c'\"
- else
- echo shar: Extracting \"'dial.c'\" \(7260 characters\)
- sed "s/^X//" >'dial.c' <<'END_OF_FILE'
- X/*
- X * The routines that dial the modem and listen for the return codes.
- X */
- X
- X#define HZ 60
- X
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include <sys/times.h>
- X#include <sys/time.h>
- X#include "conf.h"
- X
- X#define ESC '\033'
- X
- X#define MODEMS "ul_modems"
- X#define PORTS "ul_ports"
- X
- X/* C Libs */
- Xextern char *strtok();
- X
- X/* Default Dialer configuration (minimum Hayes) */
- Xstatic char *DefInitStr = "!~ATE1V1X1Q0S2=255S12=255!";
- Xstatic char *DefConnectStr = "CONNECT";
- Xstatic char *DefDialPrefix = "~~ATDT";
- Xstatic char *DefDialSuffix = "!";
- X
- Xstatic char *InitStr;
- Xstatic char *ConnectStr;
- Xstatic char *DialPrefix;
- Xstatic char *DialSuffix;
- X
- X/*
- X * Get the dial string ready, send it to the modem. The parameter is not
- X * the actual entry number, it is an index into the queue.
- X */
- X
- Xvoid
- Xdial_it(port, modem, number)
- Xchar *port, *modem, *number;
- X{
- X char s[100], *strcpy(), *strcat(), *strchr();
- X void send_str();
- X
- X /*
- X * Setup for this port/modem
- X */
- X SetupPort(port, modem);
- X
- X /*
- X * Send the modem init string
- X */
- X send_str(InitStr, 1);
- X
- X /*
- X * Create the string to be sent to the modem.
- X */
- X s[0] = '\0';
- X strcpy(s, DialPrefix);
- X strcat(s, number);
- X strcat(s, DialSuffix);
- X#ifdef DEBUG
- X fprintf(stderr, "raw dial string: \"%s\"\n", s);
- X#endif /* DEBUG */
- X
- X
- X send_str(s, 1);
- X return;
- X}
- X
- X/*
- X * Send a string to the modem. Performs all the character synonym
- X * translations.
- X */
- X
- Xvoid
- Xsend_str(s, slow)
- Xchar *s;
- Xint slow;
- X{
- X int skip, has_pause;
- X char *strchr();
- X unsigned int sleep();
- X static void do_pause();
- X /* empty string? */
- X if (s == NULL || *s == '\0')
- X return;
- X
- X /* contains a pause? */
- X has_pause = 0;
- X if (strchr(s, '~'))
- X has_pause++;
- X
- X /*
- X * Change the character synonyms to their real values. Writes
- X * the characters to the modem. To remove the special meaning
- X * of one of the characters, prepend a "\" to it.
- X */
- X skip = 0;
- X while (*s) {
- X /* send the literal character */
- X if (skip) {
- X skip = 0;
- X tty_putc(*s);
- X tty_flush();
- X if (slow)
- X do_pause();
- X#ifdef DEBUG
- X fprintf(stderr, "send_str: \"%c\", %02x, %03o, %d\n", *s, *s, *s, *s);
- X#endif /* DEBUG */
- X s++;
- X continue;
- X }
- X /* turn off the special meaning */
- X if (*s == '\\') {
- X skip++;
- X s++;
- X continue;
- X }
- X /* pause synonym */
- X if (*s == PAUSE_CHAR) {
- X sleep(1);
- X s++;
- X continue;
- X }
- X /* carriage return synonym */
- X if (*s == CR_CHAR)
- X *s = '\r';
- X /* 2 character control sequence */
- X if (*s == CTRL_CHAR) {
- X s++;
- X /* premature EOF? */
- X if (*s == '\0')
- X break;
- X /* upper and lower case */
- X if (*s > '_')
- X *s -= 96;
- X else
- X *s -= 64;
- X }
- X /* escape synonym */
- X if (*s == ESC_CHAR)
- X *s = ESC;
- X /* modem break synonym */
- X if (*s == BRK_CHAR) {
- X tty_break();
- X sleep(1);
- X s++;
- X continue;
- X }
- X
- X tty_putc(*s);
- X#ifdef DEBUG
- X fprintf(stderr, "send_str: \"%c\", %02x, %03o, %d\n", *s, *s, *s, *s);
- X#endif /* DEBUG */
- X /*
- X * Because the pause char makes the timing critical, we
- X * wait until the buffer is clear before we continue.
- X */
- X if (has_pause || slow)
- X tty_flush();
- X if (slow)
- X do_pause();
- X s++;
- X }
- X return;
- X}
- X
- X/*
- X * Read the result codes coming back from the modem. Test for the
- X * "connect" string.
- X */
- X
- Xint rc_index;
- X
- Xread_codes()
- X{
- X int i;
- X static int match();
- X char c;
- X static char rc_buf[512];
- X /* search for key words */
- X for (; rc_index<511; rc_index++) {
- X if ((i = getc_line(45)) <= 0) {
- X#ifdef DEBUG
- X fprintf(stderr, "getc_line: returns error\n");
- X#endif
- X break;
- X }
- X c = i & 0x7f;
- X#ifdef DEBUG
- X fprintf(stderr, "read_codes: \"%c\", %02x, %03o, %d\n", c, c, c, c);
- X#endif /* DEBUG */
- X /* no NULLs please */
- X if (c == '\0') {
- X if (rc_index)
- X rc_index--;
- X continue;
- X }
- X rc_buf[rc_index] = c;
- X rc_buf[rc_index+1] = '\0';
- X /* the connect strings */
- X if (match(rc_buf, ConnectStr))
- X return(0);
- X }
- X /* ran out of buffer? */
- X return(-1);
- X}
- X
- X/*
- X * Test for a match between two character strings. A non-zero return code
- X * means that s2 was found at the end of s1.
- X */
- X
- Xstatic int
- Xmatch(s1, s2)
- Xchar *s1, *s2;
- X{
- X register int i;
- X int skip, diff;
- X char new[40];
- X /* if no string to match */
- X if (*s2 == '\0')
- X return(0);
- X /* translate synonyms */
- X i = 0;
- X skip = 0;
- X while (*s2) {
- X /* literal character */
- X if (skip) {
- X skip = 0;
- X new[i++] = *s2;
- X s2++;
- X continue;
- X }
- X /* turn off the special meaning */
- X if (*s2 == '\\') {
- X skip++;
- X s2++;
- X continue;
- X }
- X /* carriage return synonym */
- X if (*s2 == CR_CHAR)
- X *s2 = '\r';
- X
- X /* 2 character control sequence */
- X if (*s2 == CTRL_CHAR) {
- X s2++;
- X if (*s2 == '\0')
- X break;
- X if (*s2 > '_')
- X *s2 -= 96;
- X else
- X *s2 -= 64;
- X }
- X /* escape synonym */
- X if (*s2 == ESC_CHAR)
- X *s2 = ESC;
- X
- X new[i++] = *s2;
- X s2++;
- X }
- X new[i] = '\0';
- X
- X diff = strlen(s1) - strlen(new);
- X /* is it possible? */
- X if (diff < 0)
- X return(0);
- X /* test it out */
- X if (!strcmp(&s1[diff], new))
- X return(1);
- X return(0);
- X}
- X
- X/*
- X * Apparently some modems can't take input at the rated speed while
- X * in the command mode. Therefore, a 0.10 sec pause a required between
- X * characters.
- X */
- X
- Xstatic void
- Xdo_pause()
- X{
- X#ifdef USLEEP
- X usleep(100000);
- X#else /* USLEEP */
- X /* Hey! I know these routines are a hack */
- X#ifdef GETTIMEOFDAY
- X struct timeval tv;
- X struct timezone tz;
- X double t1;
- X
- X gettimeofday(&tv, &tz);
- X t1 = tv.tv_sec + (tv.tv_usec / 1000000.0);
- X do
- X gettimeofday(&tv, &tz);
- X while ((tv.tv_sec + (tv.tv_usec / 1000000.0) - t1) < 0.1);
- X#else /* GETTIMEOFDAY */
- X struct tms t;
- X long t1;
- X
- X t1 = times(&t);
- X while ((times(&t) - t1) < HZ/10)
- X ;
- X#endif /* GETTIMEOFDAY */
- X#endif /* USLEEP */
- X return;
- X}
- X
- X
- Xstatic
- XSetupPort(port, modem)
- Xchar *port, *modem;
- X{
- X char fname[512], line[512];
- X FILE *fp;
- X char *p;
- X char modemname[64];
- X
- Xstatic char Init[64], Connect[64], Prefix[64], Suffix[64];
- X
- X /* Assume defaults */
- X InitStr = DefInitStr;
- X ConnectStr = DefConnectStr;
- X DialPrefix = DefDialPrefix;
- X DialSuffix = DefDialSuffix;
- X
- X /* see if explicit modem specified */
- X if (!modem) {
- X /* no modem specified, open ports database */
- X sprintf(fname, "%s/%s", LIB_DIR, PORTS);
- X fp = fopen(fname, "r");
- X if (!fp)
- X return;
- X p = 0;
- X while (fgets(line, 512, fp)) {
- X if (line[0] == '#' || line[0] == '\n')
- X continue;
- X p = strtok(line, ":");
- X if (!p)
- X continue;
- X if (strcmp(p, port) == 0) {
- X p = strtok((char *)0, ":\n");
- X if (p)
- X break; /* Found a modem entry */
- X }
- X p = 0;
- X }
- X fclose(fp);
- X /* not found */
- X if (!p)
- X return;
- X
- X strcpy(modemname, p);
- X modem = modemname;
- X
- X }
- X /* Open modems database */
- X sprintf(fname, "%s/%s", LIB_DIR, MODEMS);
- X fp = fopen(fname, "r");
- X if (!fp)
- X return;
- X while (fgets(line, 512, fp)) {
- X if (line[0] == '#' || line[0] == '\n')
- X continue;
- X p = strtok(line, ":");
- X if (!p)
- X continue;
- X if (strcmp(modem, p) == 0) {
- X /* Found the modem entry */
- X p = strtok((char *)0, ":");
- X if (!p)
- X break;
- X strcpy(Init, p);
- X p = strtok((char *)0, ":");
- X if (!p)
- X break;
- X strcpy(Prefix, p);
- X p = strtok((char *)0, ":");
- X if (!p)
- X break;
- X strcpy(Suffix, p);
- X p = strtok((char *)0, ":\n");
- X if (!p)
- X break;
- X strcpy(Connect, p);
- X InitStr = Init;
- X DialPrefix = Prefix;
- X DialSuffix = Suffix;
- X ConnectStr = Connect;
- X break;
- X }
- X }
- X fclose(fp);
- X}
- X
- X
- END_OF_FILE
- if test 7260 -ne `wc -c <'dial.c'`; then
- echo shar: \"'dial.c'\" unpacked with wrong size!
- fi
- # end of 'dial.c'
- fi
- if test -f 'makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'makefile'\"
- else
- echo shar: Extracting \"'makefile'\" \(1609 characters\)
- sed "s/^X//" >'makefile' <<'END_OF_FILE'
- X# Makefile for ulayers 0.1
- X
- XBIN = /usr/local/bin
- XMANDIR = /usr/local/manl
- X
- XVERS = 1.0
- XPGM = ulayers
- XPGM2 = ulslave
- XPGM3 = ulterm
- XMS = l
- X#
- X# CONFIGURATION
- X#
- X# Add a -DUSG if on System V to CFLAGS.
- X# See conf.h for other compile-time options.
- X#
- XCFLAGS = -O
- XCFILES = ulayers.c startup.c connect.c term.c dial.c numbers.c
- XOFILES = ulayers.o startup.o connect.o term.o dial.o numbers.o
- XDIST = README ulayers.1 CHANGES $(CFILES) makefile ulayers.h conf.h \
- X ulslave.c ulterm.xterm ulterm.cmdtool reply.sh \
- X ul_ports ul_modems ul_numbers
- X
- Xall: $(PGM) $(PGM2) $(PGM3)
- X
- X$(PGM): $(OFILES)
- X $(CC) $(CFLAGS) -o $(PGM) $(OFILES)
- X
- X$(OFILES): ulayers.h
- X
- X$(PGM2): ulslave.o
- X $(CC) $(CFLAGS) -o $(PGM2) ulslave.o
- X
- X$(PGM3):
- X @echo "You must copy either ulterm.xterm or ulterm.cmdtool"
- X @echo "to 'ulterm' or write your own 'ulterm' script."
- X @exit 1
- X
- Xinstallsetuid: $(PGM) $(PGM2) $(PGM3) $(PGM4)
- X rm -f $(BIN)/$(PGM)
- X install -c -s -o root -g daemon -m 4711 $(PGM) $(BIN)/$(PGM)
- X install -c -s $(PGM2) $(BIN)/$(PGM2)
- X install -c $(PGM3) $(BIN)/$(PGM3)
- X @reply.sh
- X
- Xinstallnosetuid: $(PGM) $(PGM2) $(PGM3) $(PGM4)
- X rm -f $(BIN)/$(PGM)
- X install -c -s $(PGM) $(BIN)/$(PGM)
- X install -c -s $(PGM2) $(BIN)/$(PGM2)
- X install -c $(PGM3) $(BIN)/$(PGM3)
- X @reply.sh
- X
- Xmanpage: ulayers.1
- X rm -f $(MANDIR)/$(PGM).$(MS)
- X cp ulayers.1 $(MANDIR)/$(PGM).$(MS)
- X chmod 664 $(MANDIR)/$(PGM).$(MS)
- X
- Xclean:
- X rm -f a.out core $(PGM) $(PGM2) *.o
- X
- Xtar:
- X tar cvf ulayers.tar $(DIST)
- X
- Xshar:
- X shar $(DIST) >ulayers.shar
- X
- Xnetshar:
- X shar -F -a -n ulayers_$(VERS) -L 30 -o ulayers.shar $(DIST)
- X
- XDIST:
- X echo $(DIST) >DIST
- END_OF_FILE
- if test 1609 -ne `wc -c <'makefile'`; then
- echo shar: \"'makefile'\" unpacked with wrong size!
- fi
- # end of 'makefile'
- fi
- if test -f 'numbers.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'numbers.c'\"
- else
- echo shar: Extracting \"'numbers.c'\" \(1752 characters\)
- sed "s/^X//" >'numbers.c' <<'END_OF_FILE'
- X#include <stdio.h>
- X#include "ulayers.h"
- X
- Xextern char *getenv(), *strtok(), *malloc();
- X
- X#define UL_NUMBERS ".ul_numbers"
- X/* #define UL_MODEMS ".ul_modems" */
- X
- Xstruct dial_entry {
- X struct dial_entry *d_next;
- X char d_system[16];
- X char d_phone[16];
- X char d_baud[16];
- X char d_port[16];
- X};
- X
- Xstruct dial_entry *d_head, *d_tail;
- X
- XReadStartup()
- X{
- X char fname[512];
- X char *home;
- X
- X home = getenv("HOME");
- X if (!home)
- X home = ".";
- X sprintf(fname, "%s/%s", home, UL_NUMBERS);
- X ReadNumbers(fname);
- X
- X#ifdef UL_MODEMS
- X sprintf(fname, "%s/%s", home, UL_MODEMS);
- X ReadModems(fname);
- X#endif
- X}
- X
- XReadNumbers(f)
- Xchar *f;
- X{
- X FILE *fp;
- X char line[512];
- X char *sys, *num, *set, *port;
- X struct dial_entry *d;
- X
- X fp = fopen(f, "r");
- X if (!fp)
- X return;
- X while (fgets(line, 512, fp)) {
- X if (line[0] == '#')
- X continue;
- X sys = strtok(line, "\t ");
- X if (!sys)
- X continue;
- X set = strtok((char *)0, "\t ");
- X if (!set)
- X continue;
- X port = strtok((char *)0, "\t \n");
- X if (!port)
- X continue;
- X num = strtok((char *)0, "\t \n");
- X d = (struct dial_entry *)malloc(sizeof(struct dial_entry));
- X if (!d)
- X return;
- X
- X strcpy(d->d_system, sys);
- X if (num)
- X strcpy(d->d_phone, num);
- X else
- X d->d_phone[0] = 0;
- X strcpy(d->d_baud, set);
- X strcpy(d->d_port, port);
- X if (d_tail)
- X d_tail->d_next = d;
- X else
- X d_head = d;
- X d_tail = d;
- X d->d_next = 0;
- X }
- X fclose(fp);
- X}
- X
- XGetNumber(s, flag)
- Xchar *s;
- Xint flag;
- X{
- X struct dial_entry *d;
- Xstatic struct dial_entry *dot;
- X
- X if (flag)
- X d = d_head;
- X else
- X d = dot;
- X while (d) {
- X if (strcmp(d->d_system, s) == 0) {
- X ServerPort = d->d_port;
- X TtySpeed = d->d_baud;
- X if (d->d_phone[0])
- X ServerNumber = d->d_phone;
- X else
- X ServerNumber = 0;
- X dot = d->d_next;
- X return(0);
- X }
- X d = d->d_next;
- X }
- X dot = 0;
- X return(-1);
- X}
- END_OF_FILE
- if test 1752 -ne `wc -c <'numbers.c'`; then
- echo shar: \"'numbers.c'\" unpacked with wrong size!
- fi
- # end of 'numbers.c'
- fi
- if test -f 'reply.sh' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'reply.sh'\"
- else
- echo shar: Extracting \"'reply.sh'\" \(1151 characters\)
- sed "s/^X//" >'reply.sh' <<'END_OF_FILE'
- Xecho
- Xecho "The author would like to receive a mail message reporting"
- Xecho "that you are using Ulayers."
- Xecho "Type "n" if you already sent or don't want to send such message."
- Xecho
- Xecho "Shall I send a mail to david@bdt.com ? "
- X
- Xset ans = "y"
- Xread ans
- X
- Xif test "$ans" != "n" -a "$ans" != "N" -a "$ans" != "no"
- Xthen
- X echo
- X echo "Sending a NewUser report to the author..."
- X if [ -r /usr/ucb/mail ] ; then
- X /usr/ucb/mail -s "ULAYERS NewUser" david@bdt.com << END
- XUlayers Version `./ulayers -v 2> /dev/null`
- X---------------------
- XPackage installed on `date 2> /dev/null`:
- X
- X User - $USER / $LOGNAME / `logname 2> /dev/null`
- X Architecture - `arch 2> /dev/null`
- X Uname/UUname - `uname -a 2> /dev/null`
- X
- XEND
- X else
- X mail david@bdt.com << END
- XUlayers Version `./ulayers -v 2>/dev/null`
- X---------------------
- XPackage installed on `date 2> /dev/null`:
- X
- X User - $USER / $LOGNAME / `logname 2> /dev/null`
- X Architecture - `arch 2> /dev/null`
- X Uname/UUname - `uname -a 2> /dev/null`
- X
- XEND
- X fi
- Xelse
- X echo
- X echo "No message was sent."
- X echo "You won't automaticaly receive upgrades..."
- Xfi
- X
- Xecho
- END_OF_FILE
- if test 1151 -ne `wc -c <'reply.sh'`; then
- echo shar: \"'reply.sh'\" unpacked with wrong size!
- fi
- chmod +x 'reply.sh'
- # end of 'reply.sh'
- fi
- if test -f 'term.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'term.c'\"
- else
- echo shar: Extracting \"'term.c'\" \(5002 characters\)
- sed "s/^X//" >'term.c' <<'END_OF_FILE'
- X/******** term.c
- X*********
- X********* This is a quick & dirty implementation of the
- X********* MacLayers protocol client-side for Unix. It
- X********* Basically is an emulation of the MacLayers
- X********* Macintosh application for Unix, except that
- X********* Ulayers is a bare-bones program, a far cry
- X********* from the polished and professional MacLayers.
- X*********
- X********* The hacks to produce Ulayers were made by me,
- X********* David Beckemeyer david@bdt.com. Essentially
- X********* the entire credit for this goes to the original
- X********* authors however, and all the contributors
- X********* copyright messages appear below. On the
- X********* the other hand, the "real" Maclayers authors
- X********* are not to blame for the shoddy hacks I made
- X********* to their code either, and so I'm putting my
- X********* here because I'm sure they don't want their
- X********* name associatyed with this mess!
- X*********
- X********* Most of the code for Ulayers came straight from
- X********* the Unix-side of the MacLayers implementation,
- X********* the copyright messages to which follow:
- X*********
- X********* Layers - MacLayers Multiwindow BSD Socket Driver
- X*********
- X********* Dave Trissel oakhill!davet
- X*********
- X********* The sockets handling portion of this control module is based
- X********* upon 'screen' by Oliver Laumann whose copyright remains below.
- X********* The rest is
- X *
- X * Copyright (C) 1989 by David W. Trissel
- X *
- X * Not derived from licensed software.
- X *
- X * Permission is granted to freely use, copy, modify, and redistribute
- X * this software, provided that no attempt is made to gain profit from it,
- X * the author is not construed to be liable for any results of using the
- X * software, alterations are clearly marked as such, and this notice is
- X * not modified.
- X *
- X */
- X
- X
- X/* Copyright (c) 1987,1988 Oliver Laumann, Technical University of Berlin.
- X * Not derived from licensed software.
- X *
- X * Permission is granted to freely use, copy, modify, and redistribute
- X * this software, provided that no attempt is made to gain profit from it,
- X * the author is not construed to be liable for any results of using the
- X * software, alterations are clearly marked as such, and this notice is
- X * not modified.
- X *
- X * Modified by Patrick Wolfe (pat@kai.com, kailand!pat)
- X * Do whatever you want with (my modifications of) this program, but
- X * don't claim you wrote them, don't try to make money from them, and
- X * don't remove this notice.
- X */
- X#include <stdio.h>
- X#include <sgtty.h>
- X#include <signal.h>
- X#include <errno.h>
- X#include <ctype.h>
- X#include <pwd.h>
- X#include <nlist.h>
- X#include <fcntl.h>
- X#include <sys/types.h>
- X#include <sys/time.h>
- X#include <sys/file.h>
- X#include <sys/wait.h>
- X#include <sys/socket.h>
- X#include <utmp.h>
- X#ifndef USG
- X#include <sys/un.h>
- X#endif
- X#include <sys/stat.h>
- X#include <sys/dir.h>
- X#include <sys/ioctl.h>
- X
- X#include "ulayers.h"
- X
- Xextern int errno;
- X
- Xstatic char *TermArgs[4];
- X
- X#define ULTERM "ulterm"
- X
- XStartTerm(f, chan)
- Xint f, chan;
- X{
- X int tf, lpid, rr, i;
- X int DevTty;
- X char buf[32], pidbuf[16], ascchan[4];
- X char *ulterm, *getenv();
- X
- X DO DEBUG("StartTerm() pty = %d, chan = %d\n", f, chan);
- X
- X if ((DevTty = open ("/dev/tty", O_RDWR|O_NDELAY)) == -1)
- X Msg (errno, "/dev/tty");
- X ulterm = getenv("ULTERM");
- X if (ulterm == 0)
- X ulterm = ULTERM;
- X switch ((lpid = fork())) {
- X case -1:
- X DO DEBUG("fork failed\n");
- X return(-1);
- X /* NOT REACHED */
- X case 0:
- X /* child */
- X setuid(getuid());
- X DO DEBUG("child %d running uid = %d\n", getpid(), getuid());
- X
- X#ifdef USG
- X setpgrp();
- X#else
- X#ifdef TIOCNOTTY
- X ioctl (DevTty, TIOCNOTTY, (char *)0);
- X#else
- X setpgrp(0, 0);
- X#endif
- X#endif
- X sprintf(ascchan, "%d", chan);
- X DO DEBUG("executing: %s %s\n", ulterm, TtyName);
- X TermArgs[0] = ulterm;
- X TermArgs[1] = TtyName;
- X TermArgs[2] = ascchan;
- X TermArgs[3] = NULL;
- X execvp(ulterm, TermArgs);
- X perror("execvp failed");
- X exit(1);
- X break;
- X
- X default:
- X /* parent */
- X signal(SIGALRM, SIG_IGN);
- X /* wait for ACK from slave */
- X tf = 0;
- X i = 0;
- X do {
- X rr = read(f, buf, 16);
- X if (rr > 0) {
- X strncpy(pidbuf+i, buf, rr);
- X i += rr;
- X pidbuf[i] = 0;
- X if (buf[rr-1] == 'T') {
- X DO DEBUG("Slave reports '%s'\n", pidbuf);
- X pidbuf[--i] = 0;
- X return(atoi(pidbuf));
- X }
- X }
- X else if (rr < 0) {
- X DO DEBUG("read xterm startup error %d\n", errno);
- X#ifdef USG
- X if (errno != EIO && errno != EAGAIN) {
- X#else
- X if (errno != EIO && errno != EWOULDBLOCK) {
- X
- X#endif
- X alarm(0);
- X kill(lpid, SIGTERM);
- X return(-1);
- X }
- X }
- X sleep(1);
- X } while (++tf < 12);
- X DO DEBUG("Slave TIMEOUT!\n");
- X return(-1);
- X }
- X /* NOT REACHED */
- X}
- END_OF_FILE
- if test 5002 -ne `wc -c <'term.c'`; then
- echo shar: \"'term.c'\" unpacked with wrong size!
- fi
- # end of 'term.c'
- fi
- if test -f 'ul_numbers' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ul_numbers'\"
- else
- echo shar: Extracting \"'ul_numbers'\" \(358 characters\)
- sed "s/^X//" >'ul_numbers' <<'END_OF_FILE'
- X#
- X# Phone number database for Ulayers
- X#
- X# This file should reside in your home directory and be called .ul_numbers
- X#
- X# Syntax:
- X# system baud port phone-number
- X#
- X# E.g.:
- X# netcom 19200-N /dev/cua1 865-9004
- Xnetcom 19200-N-8-1 /dev/cua1 865-9004
- Xwesco 19200-N-8-1 /dev/cua1 746-8783
- Xhoptoad 19200-N-8-1 /dev/cua0 14152215909
- Xhoney 19200-N-8-1 /dev/cua1 9306840
- END_OF_FILE
- if test 358 -ne `wc -c <'ul_numbers'`; then
- echo shar: \"'ul_numbers'\" unpacked with wrong size!
- fi
- # end of 'ul_numbers'
- fi
- if test -f 'ulayers.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ulayers.h'\"
- else
- echo shar: Extracting \"'ulayers.h'\" \(3765 characters\)
- sed "s/^X//" >'ulayers.h' <<'END_OF_FILE'
- X/*
- X * Derived from Maclayers layers.h which is:
- X *
- X * Copyright (C) 1989 by David W. Trissel
- X *
- X * Not derived from licensed software.
- X *
- X * Permission is granted to freely use, copy, modify, and redistribute
- X * this software, provided that no attempt is made to gain profit from it,
- X * the author is not construed to be liable for any results of using the
- X * software, alterations are clearly marked as such, and this notice is
- X * not modified.
- X *
- X */
- X
- X#include "conf.h"
- X
- X#define HOSTPROTOCOL 2 /* current host protocol */
- X
- X#define MAXPCHAN 7 /* maximum layers supported */
- X
- X#define MAXSTR 200
- X#define MAXARGS 64
- X#define MAXLINE 1024
- X#define IOSIZE 800 /* data gulp handling size */
- X
- X/* WARNING - packet sizes must be insured to never match the ESCAPE char */
- X#define ESCAPE '}' /* datalink escape character */
- X
- X#define EXITNORMAL 0 /* normal exit - connection succeeded */
- X#define EXITNOMACLAYERS 1 /* MacLayers server error */
- X#define EXITABNORMAL 2 /* something wrong generic error */
- X#define EXITSIGQUIT 3 /* TERM or QUIT signal got us */
- X#define EXITSIGHUP 4 /* HUP signal got us */
- X
- X#define ATTRSIZE 15
- X
- X#define DO if (Dflag) /* for debugging */
- X
- X/* Shape structure passed between MacLayers and ourselves */
- Xstruct Shape
- X{ short worigv; /* verical window bit origin */
- X short worigh; /* horizontal window bit origin */
- X short wlines; /* window height */
- X short wchars; /* window width */
- X short wfont; /* window font size */
- X short wattr; /* window attributes */
- X};
- X
- Xstruct Kbuff
- X { struct Kbuff * next; /* next buffer in chain (or NULL) */
- X int size; /* size of data in this buffer */
- X int offset; /* start of first data in buffer */
- X unsigned char text[IOSIZE]; /* text buffer itself */
- X };
- X /* World layer definition */
- Xstruct Layer {
- X int chan; /* channel represented by this layer */
- X int allocated; /* layer allocated */
- X int ptyfd; /* psuedo tty */
- X int ptymask; /* mask for pty descriptor */
- X int lpid; /* layer head process ID */
- X struct Kbuff *kbuff; /* keyboard input buffers */
- X struct Shape shape; /* Shape structure to/from MacLayers */
- X char tty[MAXSTR]; /* psuedo tty ID */
- X };
- X
- X/* miscelaneous common data */
- Xextern int Dflag; /* debug dump indicator flag */
- Xextern int Serverversion; /* server's version number */
- Xextern int Protocollevel; /* effective protocol level */
- Xextern int Serverlevel; /* server's protocol level */
- Xextern int TtyMask; /* Serial link mask */
- Xextern int TtyFd; /* Serial link handle */
- Xextern int flowctl; /* Flow control indicater */
- Xextern char PtyName[32], TtyName[32];
- Xextern char *OldMode, *NewMode;
- Xextern int Abortonmsg;
- Xextern struct Layer World[MAXPCHAN]; /* all layer< structures */
- Xextern char *ServerPort;
- Xextern char *TtySpeed;
- Xextern char *ServerNumber;
- Xextern char *ModemName;
- Xextern char *ServerName;
- X#define Wa_shell 0x01 /* window is a shell */
- X
- X
- Xextern void DEBUG();
- Xextern int OpenPTY();
- Xextern char *Filename();
- Xextern int SetTTY();
- Xextern int InitConnect();
- X
- Xextern void FQuit(/* exitcode */);
- Xextern void ReceiveQuit();
- Xextern void ReceiveNew(/* chanid, shape */);
- Xextern void ReceiveDelete(/* chanid */);
- Xextern void ReceiveReshape(/*chanid, shape */);
- END_OF_FILE
- if test 3765 -ne `wc -c <'ulayers.h'`; then
- echo shar: \"'ulayers.h'\" unpacked with wrong size!
- fi
- # end of 'ulayers.h'
- fi
- if test -f 'ulterm.cmdtool' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ulterm.cmdtool'\"
- else
- echo shar: Extracting \"'ulterm.cmdtool'\" \(549 characters\)
- sed "s/^X//" >'ulterm.cmdtool' <<'END_OF_FILE'
- X#!/bin/sh
- X#
- X# This is an example Layers terminal startup command.
- X#
- X# Layers executes this script with two arguments, the name of
- X# the PTY that ulslave should use and the channel number.
- X# The job of this module is to start up a terminal emulator,
- X# running the ulslave program.
- X#
- X# This sample module starts cmdtool. You could write your own
- X# to start ulslave using another emulator, on a separate tty
- X# or virtual console.
- X#
- Xif [ $# -ne 2 ] ; then
- X echo "usage: ulterm pty chan"
- X exit 1
- Xfi
- XSLAVE=ulslave
- XTITLE="Layer $2"
- Xexec cmdtool $SLAVE $1
- END_OF_FILE
- if test 549 -ne `wc -c <'ulterm.cmdtool'`; then
- echo shar: \"'ulterm.cmdtool'\" unpacked with wrong size!
- fi
- chmod +x 'ulterm.cmdtool'
- # end of 'ulterm.cmdtool'
- fi
- if test -f 'ulterm.xterm' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ulterm.xterm'\"
- else
- echo shar: Extracting \"'ulterm.xterm'\" \(584 characters\)
- sed "s/^X//" >'ulterm.xterm' <<'END_OF_FILE'
- X#!/bin/sh
- X#
- X# This is an example Layers terminal startup command.
- X#
- X# Layers executes this script with two arguments, the name of
- X# the PTY that ulslave should use and the channel number.
- X# The job of this module is to start up a terminal emulator,
- X# running the ulslave program.
- X#
- X# This sample module starts xterm. You could write your own
- X# to start ulslave using another emulator, on a separate tty
- X# or virtual console.
- X#
- Xif [ $# -ne 2 ] ; then
- X echo "usage: ulterm pty chan"
- X exit 1
- Xfi
- XSLAVE=ulslave
- XTITLE="Layer $2"
- Xexec xterm -ut -geometry 80x25 -title "$TITLE" -e $SLAVE $1
- END_OF_FILE
- if test 584 -ne `wc -c <'ulterm.xterm'`; then
- echo shar: \"'ulterm.xterm'\" unpacked with wrong size!
- fi
- chmod +x 'ulterm.xterm'
- # end of 'ulterm.xterm'
- fi
- echo shar: End of archive 3 \(of 3\).
- cp /dev/null ark3isdone
- MISSING=""
- for I in 1 2 3 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 3 archives.
- rm -f ark[1-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-