ast@cs.vu.nl (Andy Tanenbaum) (05/30/88)
: This is a shar archive. Extract with sh, not csh. : This archive ends with exit, so do not worry about trailing junk. : --------------------------- cut here -------------------------- PATH=/bin:/usr/bin:/usr/ucb echo Extracting 'amoeba.c.new' sed 's/^X//' > 'amoeba.c.new' << '+ END-OF-FILE ''amoeba.c.new' X/* X * Library routines for Amoeba Transactions X * compile with cc -c -LIB -Di8088 amoeba.c X */ X X#define AMOEBA X X#include "lib.h" X#include <minix/com.h> X#include <amoeba.h> X#include <amparam.h> X Xstatic unshort Timeout = 300; /* default timeout = 30 seconds */ X XPRIVATE message mess; X XPUBLIC unshort Xtrans(h1, b1, c1, h2, b2, c2) Xheader * h1; Xbufptr b1; Xunshort c1; Xheader * h2; Xbufptr b2; Xunshort c2; X{ X int r; X Trpar params; X X/* set up parameter block */ X params.tp_par[0].p_hdr = h1; X params.tp_par[0].p_buf = b1; X params.tp_par[0].p_cnt = c1; X params.tp_par[1].p_hdr = h2; X params.tp_par[1].p_buf = b2; X params.tp_par[1].p_cnt = c2; X params.tp_maxloc = Timeout; X/* set up message to send to fileserver */ X mess.m_type = AM_SYSCALL; X mess.AM_OP = AM_TRANS; X mess.AM_ADDRESS = (char *)¶ms; X mess.AM_COUNT = sizeof params; X if ((r = sendrec(MM, &mess)) != OK) X return r; X return (unshort)mess.m_type; X} X X XPUBLIC unshort Xgetreq(h, b, c) Xheader * h; Xbufptr b; Xunshort c; X{ X int r; X Trpar params; X X/* set up parameter block */ X params.tp_par[0].p_hdr = h; X params.tp_par[0].p_buf = b; X params.tp_par[0].p_cnt = c; X/* set up message to send to fileserver */ X mess.m_type = AM_SYSCALL; X mess.AM_OP = AM_GETREQ; X mess.AM_ADDRESS = (char *)¶ms; X mess.AM_COUNT = sizeof params; X if ((r = sendrec(MM, &mess)) != OK) X return r; X return (unshort)mess.m_type; X} X X XPUBLIC unshort Xputrep(h, b, c) Xheader * h; Xbufptr b; Xunshort c; X{ X int r; X Trpar params; X X/* set up parameter block */ X params.tp_par[0].p_hdr = h; X params.tp_par[0].p_buf = b; X params.tp_par[0].p_cnt = c; X/* set up message to send to fileserver */ X mess.m_type = AM_SYSCALL; X mess.AM_OP = AM_PUTREP; X mess.AM_ADDRESS = (char *)¶ms; X mess.AM_COUNT = sizeof params; X if ((r = sendrec(MM, &mess)) != OK) X return r; X return (unshort)mess.m_type; X} X X XPUBLIC unshort Xtimeout(t) /* set locate timeout in milliseconds */ Xunshort t; X{ X unshort oldtimeout = Timeout; X X if (t >=0 ) X Timeout = t; X return oldtimeout; X} + END-OF-FILE amoeba.c.new chmod 'u=rw,g=rw,o=rw' 'amoeba.c.new' set `wc -c 'amoeba.c.new'` count=$1 case $count in 2103) :;; *) echo 'Bad character count in ''amoeba.c.new' >&2 echo 'Count should be 2103' >&2 esac echo Extracting 'fdopen.c.new' sed 's/^X//' > 'fdopen.c.new' << '+ END-OF-FILE ''fdopen.c.new' X/* fdopen - YAH (yet another hack) hacked from fopen.c */ X X#include <stdio.h> X X#define PMODE 0644 X X XFILE *fdopen(fd,mode) Xint fd; Xchar *mode; X{ X register int i; X FILE *fp; X char *malloc(); X int flags = 0; X X for (i = 0; _io_table[i] != 0 ; i++) X if ( i >= NFILES ) X return(NULL); X X switch(*mode){ X X case 'w': X flags |= WRITEMODE; X break; X X case 'a': X flags |= WRITEMODE; X lseek(fd,0L,2); X break; X X case 'r': X flags |= READMODE; X break; X X default: X return(NULL); X } X X X if (( fp = (FILE *) malloc (sizeof( FILE))) == NULL ) X return(NULL); X X X fp->_count = 0; X fp->_fd = fd; X fp->_flags = flags; X fp->_buf = malloc( BUFSIZ ); X if ( fp->_buf == NULL ) X fp->_flags |= UNBUFF; X else X fp->_flags |= IOMYBUF; X X fp->_ptr = fp->_buf; X _io_table[i] = fp; X return(fp); X} + END-OF-FILE fdopen.c.new chmod 'u=rw,g=rw,o=rw' 'fdopen.c.new' set `wc -c 'fdopen.c.new'` count=$1 case $count in 830) :;; *) echo 'Bad character count in ''fdopen.c.new' >&2 echo 'Count should be 830' >&2 esac echo Extracting 'gtty.c.new' sed 's/^X//' > 'gtty.c.new' << '+ END-OF-FILE ''gtty.c.new' X#include <sgtty.h> X Xgtty(fd, argp) Xint fd; Xchar *argp; X{ X return ioctl(fd, TIOCGETP, argp); X} X + END-OF-FILE gtty.c.new chmod 'u=r,g=r,o=r' 'gtty.c.new' set `wc -c 'gtty.c.new'` count=$1 case $count in 96) :;; *) echo 'Bad character count in ''gtty.c.new' >&2 echo 'Count should be 96' >&2 esac echo Extracting 'lib.h.new' sed 's/^X//' > 'lib.h.new' << '+ END-OF-FILE ''lib.h.new' X#include <minix/const.h> X#include <minix/type.h> X#include <minix/callnr.h> X#include <errno.h> X Xextern message M; X X#define MM 0 X#define FS 1 X Xextern int callm1(), callm3(), callx(), len(); Xextern int errno; Xextern int begsig(); /* interrupts all vector here */ + END-OF-FILE lib.h.new chmod 'u=r,g=r,o=r' 'lib.h.new' set `wc -c 'lib.h.new'` count=$1 case $count in 293) :;; *) echo 'Bad character count in ''lib.h.new' >&2 echo 'Count should be 293' >&2 esac echo Extracting 'stty.c.new' sed 's/^X//' > 'stty.c.new' << '+ END-OF-FILE ''stty.c.new' X#include <sgtty.h> X Xstty(fd, argp) Xint fd; Xchar *argp; X{ X return ioctl(fd, TIOCSETP, argp); X} X + END-OF-FILE stty.c.new chmod 'u=r,g=r,o=r' 'stty.c.new' set `wc -c 'stty.c.new'` count=$1 case $count in 96) :;; *) echo 'Bad character count in ''stty.c.new' >&2 echo 'Count should be 96' >&2 esac echo Extracting 'termcap.c.new' sed 's/^X//' > 'termcap.c.new' << '+ END-OF-FILE ''termcap.c.new' X/* X * termcap.c 1.1 20/7/87 agc Joypace Ltd X * X * Copyright Joypace Ltd, London, UK, 1987. All rights reserved. X * This file may be freely distributed provided that this notice X * remains attached. X * X * A public domain implementation of the termcap(3) routines. X */ X#include <stdio.h> X X#define CAPABLEN 2 X X#define ISSPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n') X#define ISDIGIT(x) ((x) >= '0' && (x) <= '9') X Xextern short ospeed; /* output speed */ Xextern char PC; /* padding character */ Xextern char *BC; /* back cursor movement */ Xextern char *UP; /* up cursor movement */ X Xchar *capab; /* the capability itself */ Xint incr; /* set by %i flag */ X Xextern char *getenv(); /* new, improved getenv */ Xextern FILE *fopen(); /* old fopen */ X X/* X * tgetent - get the termcap entry for terminal name, and put it X * in bp (which must be an array of 1024 chars). Returns 1 if X * termcap entry found, 0 if not found, and -1 if file not found. X */ Xint Xtgetent(bp, name) Xchar *bp; Xchar *name; X{ X FILE *fp; X char *file; X char *cp; X short len = strlen(name); X X capab = bp; X if ((file = getenv("TERMCAP")) != (char *) NULL) { X if (*file != '/' && X (cp = getenv("TERM")) != NULL && strcmp(name, cp) == 0) { X (void) strcpy(bp, file); X return(1); X } X } else X file = "/etc/termcap"; X if ((fp = fopen(file, "r")) == (FILE *) NULL) X return(-1); X while (fgets(bp, 1024, fp) != NULL) { X /* skip V6 two letter name */ X for (cp = bp ; *cp != '|' ; cp++) X ; X for (++cp ; ISSPACE(*cp) ; cp++) X ; X if (strncmp(name, cp, len) == 0) { X while (*(cp = &bp[strlen(bp) - 2]) == '\\') X fgets(cp, 1024, fp); X fclose(fp); X return(1); X } X } X fclose(fp); X return(0); X X} X X/* X * tgetnum - get the numeric terminal capability corresponding X * to id. Returns the value, -1 if invalid. X */ Xint Xtgetnum(id) Xchar *id; X{ X char *cp; X int ret; X X if ((cp = capab) == NULL || id == NULL) X return(-1); X while (*++cp != ':') X ; X for (++cp ; *cp ; cp++) { X while (ISSPACE(*cp)) X cp++; X if (strncmp(cp, id, CAPABLEN) == 0) { X while (*cp && *cp != ':' && *cp != '#') X cp++; X if (*cp != '#') X return(-1); X for (ret = 0, cp++ ; *cp && ISDIGIT(*cp) ; cp++) X ret = ret * 10 + *cp - '0'; X return(ret); X } X while (*cp && *cp != ':') X cp++; X } X return(-1); X} X X/* X * tgetflag - get the boolean flag corresponding to id. Returns -1 X * if invalid, 0 if the flag is not in termcap entry, or 1 if it is X * present. X */ Xint Xtgetflag(id) Xchar *id; X{ X char *cp; X X if ((cp = capab) == NULL || id == NULL) X return(-1); X while (*++cp != ':') X ; X for (++cp ; *cp ; cp++) { X while (ISSPACE(*cp)) X cp++; X if (strncmp(cp, id, CAPABLEN) == 0) X return(1); X while (*cp && *cp != ':') X cp++; X } X return(0); X} X X/* X * tgetstr - get the string capability corresponding to id and place X * it in area (advancing area at same time). Expand escape sequences X * etc. Returns the string, or NULL if it can't do it. X */ Xchar * Xtgetstr(id, area) Xchar *id; Xchar **area; X{ X char *cp; X char *ret; X int i; X X if ((cp = capab) == NULL || id == NULL) X return(NULL); X while (*++cp != ':') X ; X for (++cp ; *cp ; cp++) { X while (ISSPACE(*cp)) X cp++; X if (strncmp(cp, id, CAPABLEN) == 0) { X while (*cp && *cp != ':' && *cp != '=') X cp++; X if (*cp != '=') X return(NULL); X for (ret = *area, cp++; *cp && *cp != ':' ; (*area)++, cp++) X switch(*cp) { X case '^' : X **area = *++cp - 'A'; X break; X case '\\' : X switch(*++cp) { X case 'E' : X **area = '\033'; X break; X case 'n' : X **area = '\n'; X break; X case 'r' : X **area = '\r'; X break; X case 't' : X **area = '\t'; X break; X case 'b' : X **area = '\b'; X break; X case 'f' : X **area = '\f'; X break; X case '0' : X case '1' : X case '2' : X case '3' : X for (i=0 ; *cp && ISDIGIT(*cp) ; cp++) X i = i * 8 + *cp - '0'; X **area = i; X cp--; X break; X case '^' : X case '\\' : X **area = *cp; X break; X } X break; X default : X **area = *cp; X } X *(*area)++ = '\0'; X return(ret); X } X while (*cp && *cp != ':') X cp++; X } X return(NULL); X} X X/* X * tgoto - given the cursor motion string cm, make up the string X * for the cursor to go to (destcol, destline), and return the string. X * Returns "OOPS" if something's gone wrong, or the string otherwise. X */ Xchar * Xtgoto(cm, destcol, destline) Xchar *cm; Xint destcol; Xint destline; X{ X register char *rp; X static char ret[24]; X int *dp = &destcol; X int argno = 0, numval; X X for (rp = ret ; *cm ; cm++) { X switch(*cm) { X case '%' : X switch(*++cm) { X case '+' : X if (dp == NULL) X return("OOPS"); X *rp++ = *dp + *++cm; X dp = (dp == &destcol) ? &destline : NULL; X break; X X case '%' : X *rp++ = '%'; X break; X X case 'i' : X X incr = 1; X break; X X case 'd' : X numval = (argno == 0 ? destline : destcol); X numval += incr; X argno++; X *rp++ = '0' + (numval/10); X *rp++ = '0' + (numval%10); X break; X } X X break; X default : X *rp++ = *cm; X } X } X *rp = '\0'; X return(ret); X} X X/* X * tputs - put the string cp out onto the terminal, using the function X * outc. This should do padding for the terminal, but I can't find a X * terminal that needs padding at the moment... X */ Xint Xtputs(cp, affcnt, outc) Xregister char *cp; Xint affcnt; Xint (*outc)(); X{ X if (cp == NULL) X return(1); X /* do any padding interpretation - left null for MINIX just now */ X while (*cp) X (*outc)(*cp++); X return(1); X} X X/* X * That's all, folks... X */ + END-OF-FILE termcap.c.new chmod 'u=r,g=r,o=r' 'termcap.c.new' set `wc -c 'termcap.c.new'` count=$1 case $count in 5543) :;; *) echo 'Bad character count in ''termcap.c.new' >&2 echo 'Count should be 5543' >&2 esac echo Extracting 'uniqport.c.new' sed 's/^X//' > 'uniqport.c.new' << '+ END-OF-FILE ''uniqport.c.new' X#include <amoeba.h> X Xuniqport(p) Xport *p; X{ X register char *c; X register short r; X register n; X static been_here; X X if (!been_here) { X long t, time(); X X time(&t); X srand(getpid() + (int)((t>>16) + t)); X been_here = 1; X } X do { X c = (char *) p; X n = PORTSIZE / 2; X do { X r = rand(); X *c++ ^= r >> 8; X *c++ ^= r & 0377; X } while (--n); X } while (NullPort(p)); X} + END-OF-FILE uniqport.c.new chmod 'u=rw,g=rw,o=rw' 'uniqport.c.new' set `wc -c 'uniqport.c.new'` count=$1 case $count in 374) :;; *) echo 'Bad character count in ''uniqport.c.new' >&2 echo 'Count should be 374' >&2 esac exit 0