Browse Source

Plan 9 from Bell Labs 2013-03-02

David du Colombier 11 years ago
parent
commit
3fde0caef1

+ 2 - 0
sys/include/ape/limits.h

@@ -49,6 +49,7 @@
 #define	_POSIX_TIMER_MAX		32
 #define _POSIX_TZNAME_MAX		3
 
+
 /* pedagogy: those that standard allows omitting are commented out */
 /*#define AIO_LIST_MAX _POSIX_AIO_LIST_MAX */
 /*#define AIO_MAX _POSIX_AIO_MAX */
@@ -65,6 +66,7 @@
 #define NGROUPS_MAX 10
 /*#define OPEN_MAX _POSIX_OPEN_MAX */
 /*#define PAGESIZE 1 */
+#define PASS_MAX	64
 /*#define PATH_MAX _POSIX_PATH_MAX */
 /*#define PIPE_BUF _POSIX_PIPE_BUF */
 /*#define RTSIG_MAX _POSIX_RTSIG_MAX */

+ 1 - 1
sys/man/1/bind

@@ -198,7 +198,7 @@ is unmounted.
 To compile a program with the C library from July 16, 1992:
 .IP
 .EX
-mount /srv/boot /n/dump dump
+mount /srv/boot /n/dump main/archive
 bind /n/dump/1992/0716/mips/lib/libc.a /mips/lib/libc.a
 mk
 .EE

+ 1 - 8
sys/src/ape/lib/ap/plan9/_buf.c

@@ -289,15 +289,8 @@ select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeo
 		if((rfds && FD_ISSET(i, rfds)) || (efds && FD_ISSET(i, efds))){
 			f = &_fdinfo[i];
 			if(!(f->flags&FD_BUFFERED))
-				if(_startbuf(i) != 0) {
+				if(_startbuf(i) != 0)
 					return -1;
-				}
-			b = f->buf;
-			if(rfds && FD_ISSET(i,rfds) && b->eof && b->n == 0)
-			if(efds == 0 || !FD_ISSET(i,efds)) {
-				errno = EBADF;		/* how X tells a client is gone */
-				return -1;
-			}
 		}
 
 	/* check wfds;  for now, we'll say they are all ready */

+ 3 - 2
sys/src/ape/lib/v/plan9/getpass.c

@@ -2,6 +2,7 @@
 #define _RESEARCH_SOURCE
 #include <stdio.h>
 #include <signal.h>
+#include <limits.h>
 #include <libv.h>
 
 char *
@@ -10,7 +11,7 @@ getpass(char *prompt)
 	int c;
 	char *p;
 	FILE *fi;
-	static char pbuf[9];
+	static char pbuf[PASS_MAX];
 	void (*sig)(int);
 
 	if ((fi = fopen("/dev/cons", "r")) == NULL)
@@ -28,7 +29,7 @@ getpass(char *prompt)
 		else if (c == '\b') {
 			if (p > pbuf)
 				p--;
-		} else if (p < &pbuf[8])
+		} else if (p < &pbuf[sizeof(pbuf)-1])
 			*p++ = c;
 	*p = '\0';
 

+ 2 - 4
sys/src/cmd/rc/havefork.c

@@ -71,8 +71,6 @@ Xpipe(void)
 	}
 }
 
-enum { Wordmax = 8192, };
-
 /*
  * Who should wait for the exit from the fork?
  */
@@ -81,8 +79,8 @@ Xbackq(void)
 {
 	int c, pid;
 	int pfd[2];
-	char wd[Wordmax + 1];
-	char *s, *ewd = &wd[Wordmax], *stop;
+	char wd[NTOK + 1];
+	char *s, *ewd = &wd[NTOK], *stop;
 	struct io *f;
 	var *ifs = vlook("ifs");
 	word *v, *nextv;

+ 4 - 2
sys/src/cmd/rc/plan9.c

@@ -29,12 +29,14 @@ char *syssigname[] = {
 	"term",
 	0
 };
-char Rcmain[]="/rc/lib/rcmain";
-char Fdprefix[]="/fd/";
+char *Rcmain = "/rc/lib/rcmain";
+char *Fdprefix = "/fd/";
+
 void execfinit(void);
 void execbind(void);
 void execmount(void);
 void execnewpgrp(void);
+
 builtin Builtin[] = {
 	"cd",		execcd,
 	"whatis",	execwhatis,

+ 19 - 31
sys/src/cmd/rc/rc.h

@@ -1,38 +1,22 @@
 /*
- * Plan9 is defined for plan 9
- * Unix is defined for Unix
+ * Assume plan 9 by default; if Unix is defined, assume unix.
  * Please don't litter the code with ifdefs.  The six below should be enough.
  */
-#define	Plan9
-#ifdef	Plan9
+
+#ifndef Unix
+/* plan 9 */
 #include <u.h>
 #include <libc.h>
+
 #define	NSIG	32
 #define	SIGINT	2
 #define	SIGQUIT	3
-#endif
-
-#ifdef Unix
-#define _BSD_EXTENSION
-#define _PLAN9_SOURCE
-#define _POSIX_SOURCE
-#define _RESEARCH_SOURCE
-#define _SUSV2_SOURCE
-
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <lib9.h>
-#include <signal.h>
-#include <inttypes.h>
-
-#ifndef NSIG
-#define NSIG 32
-#endif
 
-#define uintptr uintptr_t
+#define fcntl(fd, op, arg)	/* unix compatibility */
+#define F_SETFD
+#define FD_CLOEXEC
+#else
+#include "unix.h"
 #endif
 
 #ifndef ERRMAX
@@ -40,9 +24,12 @@
 #endif
 
 #define	YYMAXDEPTH	500
+#ifndef YYPREFIX
 #ifndef PAREN
 #include "x.tab.h"
 #endif
+#endif
+
 typedef struct tree tree;
 typedef struct word word;
 typedef struct io io;
@@ -53,14 +40,14 @@ typedef struct redir redir;
 typedef struct thread thread;
 typedef struct builtin builtin;
 
-#ifdef Plan9
+#ifndef Unix
 #pragma incomplete word
 #pragma incomplete io
 #endif
 
 struct tree{
 	int	type;
-	int	rtype, fd0, fd1;		/* details of REDIR PIPE DUP tokens */
+	int	rtype, fd0, fd1;	/* details of REDIR PIPE DUP tokens */
 	char	*str;
 	int	quoted;
 	int	iskw;
@@ -90,7 +77,7 @@ union code{
 char *promptstr;
 int doprompt;
 
-#define	NTOK	8192
+#define	NTOK	8192		/* maximum bytes in a word (token) */
 
 char tok[NTOK];
 
@@ -123,7 +110,7 @@ void *emalloc(long);
 void *Malloc(ulong);
 void efree(void *);
 
-#define	NOFILE	128		/* should come from <param.h> */
+#define	NOFILE	128		/* should come from <sys/param.h> on unix */
 
 struct here{
 	tree	*tag;
@@ -161,7 +148,8 @@ int doprompt;		/* is it time for a prompt? */
  */
 #define	PRD	0
 #define	PWR	1
-char Rcmain[], Fdprefix[];
+
+char *Rcmain, *Fdprefix;
 /*
  * How many dot commands have we executed?
  * Used to ensure that -v flag doesn't print rcmain.

+ 0 - 0
sys/src/cmd/rc/unix/rcmain → sys/src/cmd/rc/rcmain.unix


+ 20 - 0
sys/src/cmd/rc/run.unix

@@ -0,0 +1,20 @@
+yacc -d syn.y
+cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
+cc -DUnix -c -I. code.c
+cc -DUnix -c -I. exec.c
+cc -DUnix -c -I. getflags.c
+cc -DUnix -c -I. glob.c
+cc -DUnix -c -I. here.c
+cc -DUnix -c -I. io.c
+cc -DUnix -c -I. lex.c
+cc -DUnix -c -I. pcmd.c
+cc -DUnix -c -I. pfnc.c
+cc -DUnix -c -I. simple.c
+cc -DUnix -c -I. subr.c
+cc -DUnix -c -I. trap.c
+cc -DUnix -c -I. tree.c
+cc -DUnix -c -I. var.c
+cc -DUnix -c -I. havefork.c
+cc -DUnix -c -I. unix.c
+cc -DUnix -c -I. y.tab.c
+cc  -o rc code.o exec.o getflags.o glob.o here.o io.o lex.o pcmd.o pfnc.o simple.o subr.o trap.o tree.o var.o havefork.o unix.o y.tab.o

+ 24 - 6
sys/src/cmd/rc/simple.c

@@ -145,12 +145,31 @@ dochdir(char *word)
 	if(flag['i']!=0){
 		if(wdirfd==-2)	/* try only once */
 			wdirfd = open("/dev/wdir", OWRITE|OCEXEC);
-		if(wdirfd>=0)
+		if(wdirfd>=0) {
+			fcntl(wdirfd, F_SETFD, FD_CLOEXEC);
 			write(wdirfd, word, strlen(word));
+		}
 	}
 	return 1;
 }
 
+static char *
+appfile(char *dir, char *comp)
+{
+	int dirlen, complen;
+	char *s, *p;
+
+	dirlen = strlen(dir);
+	complen = strlen(comp);
+	s = emalloc(dirlen + 1 + complen + 1);
+	memmove(s, dir, dirlen);
+	p = s + dirlen;
+	*p++ = '/';
+	memmove(p, comp, complen);
+	p[complen] = '\0';
+	return s;
+}
+
 void
 execcd(void)
 {
@@ -169,8 +188,7 @@ execcd(void)
 			cdpath = &nullpath;
 		for(; cdpath; cdpath = cdpath->next){
 			if(cdpath->word[0] != '\0')
-				dir = smprint("%s/%s", cdpath->word,
-					a->next->word);
+				dir = appfile(cdpath->word, a->next->word);
 			else
 				dir = strdup(a->next->word);
 
@@ -360,7 +378,7 @@ execdot(void)
 	fd = -1;
 	for(path = searchpath(zero); path; path = path->next){
 		if(path->word[0] != '\0')
-			file = smprint("%s/%s", path->word, zero);
+			file = appfile(path->word, zero);
 		else
 			file = strdup(zero);
 
@@ -477,8 +495,8 @@ execwhatis(void){	/* mildly wrong -- should fork before writing */
 				for(path = searchpath(a->word); path;
 				    path = path->next){
 					if(path->word[0] != '\0')
-						file = smprint("%s/%s",
-							path->word, a->word);
+						file = appfile(path->word,
+							a->word);
 					else
 						file = strdup(a->word);
 					if(Executable(file)){

+ 48 - 2
sys/src/cmd/rc/unix.c

@@ -9,8 +9,8 @@
 #include "getflags.h"
 #include <errno.h>
 
-char Rcmain[]="/usr/lib/rcmain";
-char Fdprefix[]="/dev/fd/";
+char *Rcmain = "/usr/lib/rcmain";
+char *Fdprefix = "/dev/fd/";
 
 void execfinit(void);
 
@@ -544,3 +544,49 @@ needsrcquote(int c)
 		return 1;
 	return 0;
 }
+
+int
+rfork(int bits)
+{
+	return fork();
+}
+
+int *waitpids;
+int nwaitpids;
+
+void
+addwaitpid(int pid)
+{
+	waitpids = realloc(waitpids, (nwaitpids+1)*sizeof waitpids[0]);
+	if(waitpids == 0)
+		panic("Can't realloc %d waitpids", nwaitpids+1);
+	waitpids[nwaitpids++] = pid;
+}
+
+void
+delwaitpid(int pid)
+{
+	int r, w;
+	
+	for(r=w=0; r<nwaitpids; r++)
+		if(waitpids[r] != pid)
+			waitpids[w++] = waitpids[r];
+	nwaitpids = w;
+}
+
+void
+clearwaitpids(void)
+{
+	nwaitpids = 0;
+}
+
+int
+havewaitpid(int pid)
+{
+	int i;
+
+	for(i=0; i<nwaitpids; i++)
+		if(waitpids[i] == pid)
+			return 1;
+	return 0;
+}

+ 53 - 0
sys/src/cmd/rc/unix.h

@@ -0,0 +1,53 @@
+#undef _BSD_EXTENSION		/* avoid multiple def'n if predefined */
+#undef _PLAN9_SOURCE
+#undef _POSIX_SOURCE
+#undef _RESEARCH_SOURCE
+#undef _SUSV2_SOURCE
+
+#define _BSD_EXTENSION
+#define _PLAN9_SOURCE
+#define _POSIX_SOURCE
+#define _RESEARCH_SOURCE
+#define _SUSV2_SOURCE
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <inttypes.h>
+
+#ifndef NSIG
+#define NSIG 32
+#endif
+
+/* plan 9 compatibility */
+#define RFPROC 1
+#define RFFDG 1
+#define RFNOTEG 1
+
+#define uintptr uintptr_t
+
+char *strdup(const char *);
+
+#define nil ((void*)0)
+
+/* in case uchar, etc. are built-in types */
+#define uchar	_fmtuchar
+#define ushort	_fmtushort
+#define uint	_fmtuint
+#define ulong	_fmtulong
+#define vlong	_fmtvlong
+#define uvlong	_fmtuvlong
+
+typedef unsigned char		uchar;
+typedef unsigned short		ushort;
+typedef unsigned int		uint;
+typedef unsigned long		ulong;
+typedef unsigned long long	uvlong;
+
+#define OREAD	O_RDONLY
+#define OWRITE	O_WRONLY
+#define ORDWR	O_RDWR
+#define OCEXEC	0

+ 0 - 217
sys/src/cmd/rc/unix/havefork.c

@@ -1,217 +0,0 @@
-#include "rc.h"
-#include "getflags.h"
-#include "exec.h"
-#include "io.h"
-#include "fns.h"
-
-int havefork = 1;
-
-void
-Xasync(void)
-{
-	int null = open("/dev/null", 0);
-	int pid;
-	char npid[10];
-	if(null<0){
-		Xerror("Can't open /dev/null\n");
-		return;
-	}
-#ifdef Unix
-	pid = fork();
-#else
-	pid = rfork(RFFDG|RFPROC|RFNOTEG);
-#endif
-	switch(pid){
-	case -1:
-		close(null);
-		Xerror("try again");
-		break;
-	case 0:
-		pushredir(ROPEN, null, 0);
-		start(runq->code, runq->pc+1, runq->local);
-		runq->ret = 0;
-		break;
-	default:
-		close(null);
-		runq->pc = runq->code[runq->pc].i;
-		inttoascii(npid, pid);
-		setvar("apid", newword(npid, (word *)0));
-		break;
-	}
-}
-
-void
-Xpipe(void)
-{
-	struct thread *p = runq;
-	int pc = p->pc, forkid;
-	int lfd = p->code[pc++].i;
-	int rfd = p->code[pc++].i;
-	int pfd[2];
-	if(pipe(pfd)<0){
-		Xerror("can't get pipe");
-		return;
-	}
-	switch(forkid = fork()){
-	case -1:
-		Xerror("try again");
-		break;
-	case 0:
-		start(p->code, pc+2, runq->local);
-		runq->ret = 0;
-		close(pfd[PRD]);
-		pushredir(ROPEN, pfd[PWR], lfd);
-		break;
-	default:
-		start(p->code, p->code[pc].i, runq->local);
-		close(pfd[PWR]);
-		pushredir(ROPEN, pfd[PRD], rfd);
-		p->pc = p->code[pc+1].i;
-		p->pid = forkid;
-		break;
-	}
-}
-
-/*
- * Who should wait for the exit from the fork?
- */
-void
-Xbackq(void)
-{
-	char wd[8193];
-	int c;
-	char *s, *ewd=&wd[8192], *stop;
-	struct io *f;
-	var *ifs = vlook("ifs");
-	word *v, *nextv;
-	int pfd[2];
-	int pid;
-	stop = ifs->val?ifs->val->word:"";
-	if(pipe(pfd)<0){
-		Xerror("can't make pipe");
-		return;
-	}
-	switch(pid = fork()){
-	case -1:
-		Xerror("try again");
-		close(pfd[PRD]);
-		close(pfd[PWR]);
-		return;
-	case 0:
-		close(pfd[PRD]);
-		start(runq->code, runq->pc+1, runq->local);
-		pushredir(ROPEN, pfd[PWR], 1);
-		return;
-	default:
-		close(pfd[PWR]);
-		f = openfd(pfd[PRD]);
-		s = wd;
-		v = 0;
-		while((c = rchr(f))!=EOF){
-			if(strchr(stop, c) || s==ewd){
-				if(s!=wd){
-					*s='\0';
-					v = newword(wd, v);
-					s = wd;
-				}
-			}
-			else *s++=c;
-		}
-		if(s!=wd){
-			*s='\0';
-			v = newword(wd, v);
-		}
-		closeio(f);
-		Waitfor(pid, 0);
-		/* v points to reversed arglist -- reverse it onto argv */
-		while(v){
-			nextv = v->next;
-			v->next = runq->argv->words;
-			runq->argv->words = v;
-			v = nextv;
-		}
-		runq->pc = runq->code[runq->pc].i;
-		return;
-	}
-}
-
-void
-Xpipefd(void)
-{
-	struct thread *p = runq;
-	int pc = p->pc;
-	char name[40];
-	int pfd[2];
-	int sidefd, mainfd;
-	if(pipe(pfd)<0){
-		Xerror("can't get pipe");
-		return;
-	}
-	if(p->code[pc].i==READ){
-		sidefd = pfd[PWR];
-		mainfd = pfd[PRD];
-	}
-	else{
-		sidefd = pfd[PRD];
-		mainfd = pfd[PWR];
-	}
-	switch(fork()){
-	case -1:
-		Xerror("try again");
-		break;
-	case 0:
-		start(p->code, pc+2, runq->local);
-		close(mainfd);
-		pushredir(ROPEN, sidefd, p->code[pc].i==READ?1:0);
-		runq->ret = 0;
-		break;
-	default:
-		close(sidefd);
-		pushredir(ROPEN, mainfd, mainfd);	/* isn't this a noop? */
-		strcpy(name, Fdprefix);
-		inttoascii(name+strlen(name), mainfd);
-		pushword(name);
-		p->pc = p->code[pc+1].i;
-		break;
-	}
-}
-
-void
-Xsubshell(void)
-{
-	int pid;
-	switch(pid = fork()){
-	case -1:
-		Xerror("try again");
-		break;
-	case 0:
-		start(runq->code, runq->pc+1, runq->local);
-		runq->ret = 0;
-		break;
-	default:
-		Waitfor(pid, 1);
-		runq->pc = runq->code[runq->pc].i;
-		break;
-	}
-}
-
-int
-execforkexec(void)
-{
-	int pid;
-	int n;
-	char buf[ERRMAX];
-
-	switch(pid = fork()){
-	case -1:
-		return -1;
-	case 0:
-		pushword("exec");
-		execexec();
-		strcpy(buf, "can't exec: ");
-		n = strlen(buf);
-		errstr(buf+n, ERRMAX-n);
-		Exit(buf);
-	}
-	return pid;
-}

+ 0 - 80
sys/src/cmd/rc/unix/include/bio.h

@@ -1,80 +0,0 @@
-#ifndef _BIOH_
-#define _BIOH_ 1
-
-#include <sys/types.h>	/* for off_t */
-#include <fcntl.h>	/* for O_RDONLY, O_WRONLY */
-
-typedef	struct	Biobuf	Biobuf;
-
-enum
-{
-	Bsize		= 8*1024,
-	Bungetsize	= 4,		/* space for ungetc */
-	Bmagic		= 0x314159,
-	Beof		= -1,
-	Bbad		= -2,
-
-	Binactive	= 0,		/* states */
-	Bractive,
-	Bwactive,
-	Bracteof,
-
-	Bend
-};
-
-struct	Biobuf
-{
-	int	icount;		/* neg num of bytes at eob */
-	int	ocount;		/* num of bytes at bob */
-	int	rdline;		/* num of bytes after rdline */
-	int	runesize;		/* num of bytes of last getrune */
-	int	state;		/* r/w/inactive */
-	int	fid;		/* open file */
-	int	flag;		/* magic if malloc'ed */
-	off_t	offset;		/* offset of buffer in file */
-	int	bsize;		/* size of buffer */
-	unsigned char*	bbuf;		/* pointer to beginning of buffer */
-	unsigned char*	ebuf;		/* pointer to end of buffer */
-	unsigned char*	gbuf;		/* pointer to good data in buf */
-	unsigned char	b[Bungetsize+Bsize];
-};
-
-#define	BGETC(bp)\
-	((bp)->icount?(bp)->bbuf[(bp)->bsize+(bp)->icount++]:Bgetc((bp)))
-#define	BPUTC(bp,c)\
-	((bp)->ocount?(bp)->bbuf[(bp)->bsize+(bp)->ocount++]=(c),0:Bputc((bp),(c)))
-#define	BOFFSET(bp)\
-	(((bp)->state==Bractive)?\
-		(bp)->offset + (bp)->icount:\
-	(((bp)->state==Bwactive)?\
-		(bp)->offset + ((bp)->bsize + (bp)->ocount):\
-		-1))
-#define	BLINELEN(bp)\
-	(bp)->rdline
-#define	BFILDES(bp)\
-	(bp)->fid
-
-int	Bbuffered(Biobuf*);
-int	Bfildes(Biobuf*);
-int	Bflush(Biobuf*);
-int	Bgetc(Biobuf*);
-int	Bgetd(Biobuf*, double*);
-int	Binit(Biobuf*, int, int);
-int	Binits(Biobuf*, int, int, unsigned char*, int);
-int	Blinelen(Biobuf*);
-off_t	Boffset(Biobuf*);
-Biobuf*	Bopen(char*, int);
-int	Bprint(Biobuf*, char*, ...);
-int	Bputc(Biobuf*, int);
-void*	Brdline(Biobuf*, int);
-long	Bread(Biobuf*, void*, long);
-off_t	Bseek(Biobuf*, off_t, int);
-int	Bterm(Biobuf*);
-int	Bungetc(Biobuf*);
-long	Bwrite(Biobuf*, void*, long);
-
-long	Bgetrune(Biobuf*);
-int	Bputrune(Biobuf*, long);
-int	Bungetrune(Biobuf*);
-
-#endif

+ 0 - 99
sys/src/cmd/rc/unix/include/fmt.h

@@ -1,99 +0,0 @@
-
-/*
- * The authors of this software are Rob Pike and Ken Thompson.
- *              Copyright (c) 2002 by Lucent Technologies.
- * Permission to use, copy, modify, and distribute this software for any
- * purpose without fee is hereby granted, provided that this entire notice
- * is included in all copies of any software which is or includes a copy
- * or modification of this software and in all copies of the supporting
- * documentation for such software.
- * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
- * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
- * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
- */
-
-#ifndef _FMTH_
-#define _FMTH_ 1
-
-#include <stdarg.h>
-
-#ifndef _UTFH_
-#include <utf.h>
-#endif
-
-typedef struct Fmt	Fmt;
-struct Fmt{
-	unsigned char	runes;		/* output buffer is runes or chars? */
-	void	*start;			/* of buffer */
-	void	*to;			/* current place in the buffer */
-	void	*stop;			/* end of the buffer; overwritten if flush fails */
-	int	(*flush)(Fmt *);	/* called when to == stop */
-	void	*farg;			/* to make flush a closure */
-	int	nfmt;			/* num chars formatted so far */
-	va_list	args;			/* args passed to dofmt */
-	int	r;			/* % format Rune */
-	int	width;
-	int	prec;
-	unsigned long	flags;
-};
-
-enum{
-	FmtWidth	= 1,
-	FmtLeft		= FmtWidth << 1,
-	FmtPrec		= FmtLeft << 1,
-	FmtSharp	= FmtPrec << 1,
-	FmtSpace	= FmtSharp << 1,
-	FmtSign		= FmtSpace << 1,
-	FmtZero		= FmtSign << 1,
-	FmtUnsigned	= FmtZero << 1,
-	FmtShort	= FmtUnsigned << 1,
-	FmtLong		= FmtShort << 1,
-	FmtVLong	= FmtLong << 1,
-	FmtComma	= FmtVLong << 1,
-	FmtByte		= FmtComma << 1,
-	FmtLDouble	= FmtByte << 1,
-
-	FmtFlag		= FmtLDouble << 1
-};
-
-extern	int	print(char*, ...);
-extern	char*	seprint(char*, char*, char*, ...);
-extern	char*	vseprint(char*, char*, char*, va_list);
-extern	int	snprint(char*, int, char*, ...);
-extern	int	vsnprint(char*, int, char*, va_list);
-extern	char*	smprint(char*, ...);
-extern	char*	vsmprint(char*, va_list);
-extern	int	sprint(char*, char*, ...);
-extern	int	fprint(int, char*, ...);
-extern	int	vfprint(int, char*, va_list);
-
-extern	int	runesprint(Rune*, char*, ...);
-extern	int	runesnprint(Rune*, int, char*, ...);
-extern	int	runevsnprint(Rune*, int, char*, va_list);
-extern	Rune*	runeseprint(Rune*, Rune*, char*, ...);
-extern	Rune*	runevseprint(Rune*, Rune*, char*, va_list);
-extern	Rune*	runesmprint(char*, ...);
-extern	Rune*	runevsmprint(char*, va_list);
-
-extern	int	fmtfdinit(Fmt*, int, char*, int);
-extern	int	fmtfdflush(Fmt*);
-extern	int	fmtstrinit(Fmt*);
-extern	char*	fmtstrflush(Fmt*);
-
-extern	int	quotestrfmt(Fmt *f);
-extern	void	quotefmtinstall(void);
-extern	int	(*fmtdoquote)(int);
-
-
-extern	int	fmtinstall(int, int (*)(Fmt*));
-extern	int	dofmt(Fmt*, char*);
-extern	int	fmtprint(Fmt*, char*, ...);
-extern	int	fmtvprint(Fmt*, char*, va_list);
-extern	int	fmtrune(Fmt*, int);
-extern	int	fmtstrcpy(Fmt*, char*);
-
-extern	double	fmtstrtod(const char *, char **);
-extern	double	fmtcharstod(int(*)(void*), void*);
-
-#endif

+ 0 - 23
sys/src/cmd/rc/unix/include/lib9.h

@@ -1,23 +0,0 @@
-#include <string.h>
-#include "utf.h"
-
-#define nil ((void*)0)
-
-#define uchar _fmtuchar
-#define ushort _fmtushort
-#define uint _fmtuint
-#define ulong _fmtulong
-#define vlong _fmtvlong
-// #define uvlong _fmtuvlong
-
-typedef unsigned char		uchar;
-typedef unsigned short		ushort;
-typedef unsigned int		uint;
-typedef unsigned long		ulong;
-
-typedef unsigned long long uvlong;
-
-#define OREAD O_RDONLY
-#define OWRITE O_WRONLY
-#define ORDWR O_RDWR
-#define OCEXEC 0

+ 0 - 71
sys/src/cmd/rc/unix/include/regexp9.h

@@ -1,71 +0,0 @@
-#ifndef _REGEXP9H_
-
-#define _REGEXP9H_ 1
-#include <utf.h>
-
-typedef struct Resub		Resub;
-typedef struct Reclass		Reclass;
-typedef struct Reinst		Reinst;
-typedef struct Reprog		Reprog;
-
-/*
- *	Sub expression matches
- */
-struct Resub{
-	union
-	{
-		char *sp;
-		Rune *rsp;
-	}s;
-	union
-	{
-		char *ep;
-		Rune *rep;
-	}e;
-};
-
-/*
- *	character class, each pair of rune's defines a range
- */
-struct Reclass{
-	Rune	*end;
-	Rune	spans[64];
-};
-
-/*
- *	Machine instructions
- */
-struct Reinst{
-	int	type;
-	union	{
-		Reclass	*cp;		/* class pointer */
-		Rune	r;		/* character */
-		int	subid;		/* sub-expression id for RBRA and LBRA */
-		Reinst	*right;		/* right child of OR */
-	}u1;
-	union {	/* regexp relies on these two being in the same union */
-		Reinst *left;		/* left child of OR */
-		Reinst *next;		/* next instruction for CAT & LBRA */
-	}u2;
-};
-
-/*
- *	Reprogram definition
- */
-struct Reprog{
-	Reinst	*startinst;	/* start pc */
-	Reclass	class[16];	/* .data */
-	Reinst	firstinst[5];	/* .text */
-};
-
-extern Reprog	*regcomp(char*);
-extern Reprog	*regcomplit(char*);
-extern Reprog	*regcompnl(char*);
-extern void	regerror(char*);
-extern int	regexec(Reprog*, char*, Resub*, int);
-extern void	regsub(char*, char*, int, Resub*, int);
-
-extern int	rregexec(Reprog*, Rune*, Resub*, int);
-extern void	rregsub(Rune*, Rune*, Resub*, int);
-
-#endif

+ 0 - 51
sys/src/cmd/rc/unix/include/utf.h

@@ -1,51 +0,0 @@
-#ifndef _UTFH_
-#define _UTFH_ 1
-
-typedef unsigned short Rune;	/* 16 bits */
-
-enum
-{
-	UTFmax		= 3,		/* maximum bytes per rune */
-	Runesync	= 0x80,		/* cannot represent part of a UTF sequence (<) */
-	Runeself	= 0x80,		/* rune and UTF sequences are the same (<) */
-	Runeerror	= 0x80,		/* decoding error in UTF */
-};
-
-/*
- * rune routines
- */
-extern	int	runetochar(char*, Rune*);
-extern	int	chartorune(Rune*, char*);
-extern	int	runelen(long);
-extern	int	runenlen(Rune*, int);
-extern	int	fullrune(char*, int);
-extern	int	utflen(char*);
-extern	int	utfnlen(char*, long);
-extern	char*	utfrune(char*, long);
-extern	char*	utfrrune(char*, long);
-extern	char*	utfutf(char*, char*);
-extern	char*	utfecpy(char*, char*, char*);
-
-extern	Rune*	runestrcat(Rune*, Rune*);
-extern	Rune*	runestrchr(Rune*, Rune);
-extern	int	runestrcmp(Rune*, Rune*);
-extern	Rune*	runestrcpy(Rune*, Rune*);
-extern	Rune*	runestrncpy(Rune*, Rune*, long);
-extern	Rune*	runestrecpy(Rune*, Rune*, Rune*);
-extern	Rune*	runestrdup(Rune*);
-extern	Rune*	runestrncat(Rune*, Rune*, long);
-extern	int	runestrncmp(Rune*, Rune*, long);
-extern	Rune*	runestrrchr(Rune*, Rune);
-extern	long	runestrlen(Rune*);
-extern	Rune*	runestrstr(Rune*, Rune*);
-
-extern	Rune	tolowerrune(Rune);
-extern	Rune	totitlerune(Rune);
-extern	Rune	toupperrune(Rune);
-extern	int	isalpharune(Rune);
-extern	int	islowerrune(Rune);
-extern	int	isspacerune(Rune);
-extern	int	istitlerune(Rune);
-extern	int	isupperrune(Rune);
-
-#endif

+ 0 - 64
sys/src/cmd/rc/unix/makefile

@@ -1,64 +0,0 @@
-O=o
-TARG=rc
-COMMONOFILES=\
-	code.$O\
-	exec.$O\
-	getflags.$O\
-	glob.$O\
-	here.$O\
-	io.$O\
-	lex.$O\
-	pcmd.$O\
-	pfnc.$O\
-	simple.$O\
-	subr.$O\
-	trap.$O\
-	tree.$O\
-	var.$O\
-	havefork.$O\
-
-PLAN9OFILES=plan9.$O\
-
-UNIXOFILES=unix.$O\
-
-OFILES=$(COMMONOFILES) $(UNIXOFILES) y.tab.$O
-
-HFILES=rc.h\
-	x.tab.h\
-	io.h\
-	exec.h\
-	fns.h\
-
-YFILES=syn.y
-
-BIN=/$objtype/bin
-
-UPDATE=\
-	mkfile\
-	$HFILES\
-	${COMMONOFILES:%.$O=%.c}\
-	${UNIXOFILES:%.$O=%.c}\
-	${PLAN9OFILES:%.$O=%.c}\
-	$YFILES\
-	${TARG:%=/386/bin/%}\
-
-CC=cc
-CFLAGS= -c -w -Iinclude
-LD=cc
-
-YFLAGS=-d -S
-
-rc: $(OFILES)
-	$(CC) -o rc $(OFILES)
-x.tab.h: y.tab.h
-	cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
-
-clean:
-	rm -f [$OS].out *.[$OS] [xy].tab.? y.debug $TARG
-
-regress: $O.out
-	cd test
-	mk
-
-unregress:
-	for(test in test/*.test) rc $test >$test.out

+ 0 - 68
sys/src/cmd/rc/unix/mkfile

@@ -1,68 +0,0 @@
-</$objtype/mkfile
-
-TARG=rc
-COMMONOFILES=\
-	code.$O\
-	exec.$O\
-	getflags.$O\
-	glob.$O\
-	here.$O\
-	io.$O\
-	lex.$O\
-	pcmd.$O\
-	pfnc.$O\
-	simple.$O\
-	subr.$O\
-	trap.$O\
-	tree.$O\
-	var.$O\
-	havefork.$O\
-
-PLAN9OFILES=plan9.$O\
-
-UNIXOFILES=unix.$O\
-
-OFILES=$COMMONOFILES $UNIXOFILES y.tab.$O
-
-HFILES=rc.h\
-	x.tab.h\
-	io.h\
-	exec.h\
-	fns.h\
-
-YFILES=syn.y
-
-BIN=/$objtype/bin
-
-UPDATE=\
-	mkfile\
-	$HFILES\
-	${COMMONOFILES:%.$O=%.c}\
-	${UNIXOFILES:%.$O=%.c}\
-	${PLAN9OFILES:%.$O=%.c}\
-	$YFILES\
-	${TARG:%=/386/bin/%}\
-
-CC=pcc
-CFLAGS= -c -B -Iinclude
-LD=pcc
-
-</sys/src/cmd/mkone
-
-YFLAGS=-d -S
-
-x.tab.h: y.tab.h
-	cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
-
-clean:V:
-	rm -f [$OS].out *.[$OS] [xy].tab.? y.debug $TARG
-
-regress: $O.out
-	cd test
-	mk
-
-unregress:V:
-	for(test in test/*.test) rc $test >$test.out
-
-listing:
-	pr mkfile $HFILES $FILES $FILES9 $FILESUNIX $YFILES|lp -du

+ 0 - 172
sys/src/cmd/rc/unix/rc.h

@@ -1,172 +0,0 @@
-/*
- * Plan9 is defined for plan 9
- * Unix is defined for Unix
- * Please don't litter the code with ifdefs.  The two below should be enough.
- */
-#define	Unix
-#ifdef	Plan9
-#include <u.h>
-#include <libc.h>
-#define	NSIG	32
-#define	SIGINT	2
-#define	SIGQUIT	3
-#endif
-
-#ifdef Unix
-#define _BSD_EXTENSION
-#define _PLAN9_SOURCE
-#define _POSIX_SOURCE
-#define _RESEARCH_SOURCE
-#define _SUSV2_SOURCE
-
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <lib9.h>
-#include <signal.h>
-#include <inttypes.h>
-
-#ifndef NSIG
-#define NSIG 32
-#endif
-
-#define uintptr uintptr_t
-#endif
-
-#ifndef ERRMAX
-#define ERRMAX 128
-#endif
-
-#define	YYMAXDEPTH	500
-#ifndef PAREN
-#include "x.tab.h"
-#endif
-typedef struct tree tree;
-typedef struct word word;
-typedef struct io io;
-typedef union code code;
-typedef struct var var;
-typedef struct list list;
-typedef struct redir redir;
-typedef struct thread thread;
-typedef struct builtin builtin;
-
-#ifdef Plan9
-#pragma incomplete word
-#pragma incomplete io
-#endif
-
-struct tree{
-	int	type;
-	int	rtype, fd0, fd1;		/* details of REDIR PIPE DUP tokens */
-	char	*str;
-	int	quoted;
-	int	iskw;
-	tree	*child[3];
-	tree	*next;
-};
-tree *newtree(void);
-tree *token(char*, int), *klook(char*), *tree1(int, tree*);
-tree *tree2(int, tree*, tree*), *tree3(int, tree*, tree*, tree*);
-tree *mung1(tree*, tree*), *mung2(tree*, tree*, tree*);
-tree *mung3(tree*, tree*, tree*, tree*), *epimung(tree*, tree*);
-tree *simplemung(tree*), *heredoc(tree*);
-void freetree(tree*);
-tree *cmdtree;
-
-/*
- * The first word of any code vector is a reference count.
- * Always create a new reference to a code vector by calling codecopy(.).
- * Always call codefree(.) when deleting a reference.
- */
-union code{
-	void	(*f)(void);
-	int	i;
-	char	*s;
-};
-
-char *promptstr;
-int doprompt;
-
-#define	NTOK	8192
-
-char tok[NTOK];
-
-#define	APPEND	1
-#define	WRITE	2
-#define	READ	3
-#define	HERE	4
-#define	DUPFD	5
-#define	CLOSE	6
-#define RDWR	7
-
-struct var{
-	char	*name;		/* ascii name */
-	word	*val;		/* value */
-	int	changed;
-	code	*fn;		/* pointer to function's code vector */
-	int	fnchanged;
-	int	pc;		/* pc of start of function */
-	var	*next;		/* next on hash or local list */
-};
-var *vlook(char*), *gvlook(char*), *newvar(char*, var*);
-
-#define	NVAR	521
-
-var *gvar[NVAR];		/* hash for globals */
-
-#define	new(type)	((type *)emalloc(sizeof(type)))
-
-void *emalloc(long);
-void *Malloc(ulong);
-void efree(void *);
-
-#define	NOFILE	128		/* should come from <param.h> */
-
-struct here{
-	tree	*tag;
-	char	*name;
-	struct here *next;
-};
-int mypid;
-
-/*
- * Glob character escape in strings:
- *	In a string, GLOB must be followed by *?[ or GLOB.
- *	GLOB* matches any string
- *	GLOB? matches any single character
- *	GLOB[...] matches anything in the brackets
- *	GLOBGLOB matches GLOB
- */
-#define	GLOB	((char)0x01)
-/*
- * onebyte(c), twobyte(c), threebyte(c)
- * Is c the first character of a one- two- or three-byte utf sequence?
- */
-#define	onebyte(c)	((c&0x80)==0x00)
-#define	twobyte(c)	((c&0xe0)==0xc0)
-#define	threebyte(c)	((c&0xf0)==0xe0)
-
-char **argp;
-char **args;
-int nerror;		/* number of errors encountered during compilation */
-int doprompt;		/* is it time for a prompt? */
-/*
- * Which fds are the reading/writing end of a pipe?
- * Unfortunately, this can vary from system to system.
- * 9th edition Unix doesn't care, the following defines
- * work on plan 9.
- */
-#define	PRD	0
-#define	PWR	1
-char Rcmain[], Fdprefix[];
-/*
- * How many dot commands have we executed?
- * Used to ensure that -v flag doesn't print rcmain.
- */
-int ndot;
-char *getstatus(void);
-int lastc;
-int lastword;

+ 0 - 20
sys/src/cmd/rc/unix/run

@@ -1,20 +0,0 @@
-yacc -d syn.y
-cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
-cc -w -c -Iinclude code.c
-cc -w -c -Iinclude exec.c
-cc -w -c -Iinclude getflags.c
-cc -w -c -Iinclude glob.c
-cc -w -c -Iinclude here.c
-cc -w -c -Iinclude io.c
-cc -w -c -Iinclude lex.c
-cc -w -c -Iinclude pcmd.c
-cc -w -c -Iinclude pfnc.c
-cc -w -c -Iinclude simple.c
-cc -w -c -Iinclude subr.c
-cc -w -c -Iinclude trap.c
-cc -w -c -Iinclude tree.c
-cc -w -c -Iinclude var.c
-cc -w -c -Iinclude havefork.c
-cc -w -c -Iinclude unix.c
-cc -w -c -Iinclude y.tab.c
-cc  -o rc code.o exec.o getflags.o glob.o here.o io.o lex.o pcmd.o pfnc.o simple.o subr.o trap.o tree.o var.o havefork.o unix.o y.tab.o

+ 0 - 508
sys/src/cmd/rc/unix/simple.c

@@ -1,508 +0,0 @@
-/*
- * Maybe `simple' is a misnomer.
- */
-#include "rc.h"
-#include "getflags.h"
-#include "exec.h"
-#include "io.h"
-#include "fns.h"
-/*
- * Search through the following code to see if we're just going to exit.
- */
-int
-exitnext(void){
-	union code *c=&runq->code[runq->pc];
-	while(c->f==Xpopredir) c++;
-	return c->f==Xexit;
-}
-
-void
-Xsimple(void)
-{
-	word *a;
-	thread *p = runq;
-	var *v;
-	struct builtin *bp;
-	int pid;
-	globlist();
-	a = runq->argv->words;
-	if(a==0){
-		Xerror1("empty argument list");
-		return;
-	}
-	if(flag['x'])
-		pfmt(err, "%v\n", p->argv->words); /* wrong, should do redirs */
-	v = gvlook(a->word);
-	if(v->fn)
-		execfunc(v);
-	else{
-		if(strcmp(a->word, "builtin")==0){
-			if(count(a)==1){
-				pfmt(err, "builtin: empty argument list\n");
-				setstatus("empty arg list");
-				poplist();
-				return;
-			}
-			a = a->next;
-			popword();
-		}
-		for(bp = Builtin;bp->name;bp++)
-			if(strcmp(a->word, bp->name)==0){
-				(*bp->fnc)();
-				return;
-			}
-		if(exitnext()){
-			/* fork and wait is redundant */
-			pushword("exec");
-			execexec();
-			Xexit();
-		}
-		else{
-			flush(err);
-			Updenv();	/* necessary so changes don't go out again */
-			if((pid = execforkexec()) < 0){
-				Xerror("try again");
-				return;
-			}
-
-			/* interrupts don't get us out */
-			poplist();
-			while(Waitfor(pid, 1) < 0)
-				;
-		}
-	}
-}
-struct word nullpath = { "", 0};
-
-void
-doredir(redir *rp)
-{
-	if(rp){
-		doredir(rp->next);
-		switch(rp->type){
-		case ROPEN:
-			if(rp->from!=rp->to){
-				Dup(rp->from, rp->to);
-				close(rp->from);
-			}
-			break;
-		case RDUP:
-			Dup(rp->from, rp->to);
-			break;
-		case RCLOSE:
-			close(rp->from);
-			break;
-		}
-	}
-}
-
-word*
-searchpath(char *w)
-{
-	word *path;
-	if(strncmp(w, "/", 1)==0
-	|| strncmp(w, "#", 1)==0
-	|| strncmp(w, "./", 2)==0
-	|| strncmp(w, "../", 3)==0
-	|| (path = vlook("path")->val)==0)
-		path=&nullpath;
-	return path;
-}
-
-void
-execexec(void)
-{
-	popword();	/* "exec" */
-	if(runq->argv->words==0){
-		Xerror1("empty argument list");
-		return;
-	}
-	doredir(runq->redir);
-	Execute(runq->argv->words, searchpath(runq->argv->words->word));
-	poplist();
-}
-
-void
-execfunc(var *func)
-{
-	word *starval;
-	popword();
-	starval = runq->argv->words;
-	runq->argv->words = 0;
-	poplist();
-	start(func->fn, func->pc, runq->local);
-	runq->local = newvar(strdup("*"), runq->local);
-	runq->local->val = starval;
-	runq->local->changed = 1;
-}
-
-int
-dochdir(char *word)
-{
-	/* report to /dev/wdir if it exists and we're interactive */
-	static int wdirfd = -2;
-	if(chdir(word)<0) return -1;
-	if(flag['i']!=0){
-		if(wdirfd==-2)	/* try only once */
-			wdirfd = open("/dev/wdir", OWRITE|OCEXEC);
-		if(wdirfd>=0) {
-#ifdef Unix
-			fcntl(wdirfd, F_SETFD, FD_CLOEXEC);
-#endif
-			write(wdirfd, word, strlen(word));
-		}
-	}
-	return 1;
-}
-
-void
-execcd(void)
-{
-	word *a = runq->argv->words;
-	word *cdpath;
-	char dir[512];
-	setstatus("can't cd");
-	cdpath = vlook("cdpath")->val;
-	switch(count(a)){
-	default:
-		pfmt(err, "Usage: cd [directory]\n");
-		break;
-	case 2:
-		if(a->next->word[0]=='/' || cdpath==0)
-			cdpath=&nullpath;
-		for(;cdpath;cdpath = cdpath->next){
-			strcpy(dir, cdpath->word);
-			if(dir[0])
-				strcat(dir, "/");
-			strcat(dir, a->next->word);
-			if(dochdir(dir)>=0){
-				if(strlen(cdpath->word)
-				&& strcmp(cdpath->word, ".")!=0)
-					pfmt(err, "%s\n", dir);
-				setstatus("");
-				break;
-			}
-		}
-		if(cdpath==0)
-			pfmt(err, "Can't cd %s: %r\n", a->next->word);
-		break;
-	case 1:
-		a = vlook("home")->val;
-		if(count(a)>=1){
-			if(dochdir(a->word)>=0)
-				setstatus("");
-			else
-				pfmt(err, "Can't cd %s: %r\n", a->word);
-		}
-		else
-			pfmt(err, "Can't cd -- $home empty\n");
-		break;
-	}
-	poplist();
-}
-
-void
-execexit(void)
-{
-	switch(count(runq->argv->words)){
-	default:
-		pfmt(err, "Usage: exit [status]\nExiting anyway\n");
-	case 2:
-		setstatus(runq->argv->words->next->word);
-	case 1:	Xexit();
-	}
-}
-
-void
-execshift(void)
-{
-	int n;
-	word *a;
-	var *star;
-	switch(count(runq->argv->words)){
-	default:
-		pfmt(err, "Usage: shift [n]\n");
-		setstatus("shift usage");
-		poplist();
-		return;
-	case 2:
-		n = atoi(runq->argv->words->next->word);
-		break;
-	case 1:
-		n = 1;
-		break;
-	}
-	star = vlook("*");
-	for(;n && star->val;--n){
-		a = star->val->next;
-		efree(star->val->word);
-		efree((char *)star->val);
-		star->val = a;
-		star->changed = 1;
-	}
-	setstatus("");
-	poplist();
-}
-
-int
-octal(char *s)
-{
-	int n = 0;
-	while(*s==' ' || *s=='\t' || *s=='\n') s++;
-	while('0'<=*s && *s<='7') n = n*8+*s++-'0';
-	return n;
-}
-
-int
-mapfd(int fd)
-{
-	redir *rp;
-	for(rp = runq->redir;rp;rp = rp->next){
-		switch(rp->type){
-		case RCLOSE:
-			if(rp->from==fd)
-				fd=-1;
-			break;
-		case RDUP:
-		case ROPEN:
-			if(rp->to==fd)
-				fd = rp->from;
-			break;
-		}
-	}
-	return fd;
-}
-union code rdcmds[4];
-
-void
-execcmds(io *f)
-{
-	static int first = 1;
-	if(first){
-		rdcmds[0].i = 1;
-		rdcmds[1].f = Xrdcmds;
-		rdcmds[2].f = Xreturn;
-		first = 0;
-	}
-	start(rdcmds, 1, runq->local);
-	runq->cmdfd = f;
-	runq->iflast = 0;
-}
-
-void
-execeval(void)
-{
-	char *cmdline, *s, *t;
-	int len = 0;
-	word *ap;
-	if(count(runq->argv->words)<=1){
-		Xerror1("Usage: eval cmd ...");
-		return;
-	}
-	eflagok = 1;
-	for(ap = runq->argv->words->next;ap;ap = ap->next)
-		len+=1+strlen(ap->word);
-	cmdline = emalloc(len);
-	s = cmdline;
-	for(ap = runq->argv->words->next;ap;ap = ap->next){
-		for(t = ap->word;*t;) *s++=*t++;
-		*s++=' ';
-	}
-	s[-1]='\n';
-	poplist();
-	execcmds(opencore(cmdline, len));
-	efree(cmdline);
-}
-union code dotcmds[14];
-
-void
-execdot(void)
-{
-	int iflag = 0;
-	int fd;
-	list *av;
-	thread *p = runq;
-	char *zero;
-	static int first = 1;
-	char file[512];
-	word *path;
-	if(first){
-		dotcmds[0].i = 1;
-		dotcmds[1].f = Xmark;
-		dotcmds[2].f = Xword;
-		dotcmds[3].s="0";
-		dotcmds[4].f = Xlocal;
-		dotcmds[5].f = Xmark;
-		dotcmds[6].f = Xword;
-		dotcmds[7].s="*";
-		dotcmds[8].f = Xlocal;
-		dotcmds[9].f = Xrdcmds;
-		dotcmds[10].f = Xunlocal;
-		dotcmds[11].f = Xunlocal;
-		dotcmds[12].f = Xreturn;
-		first = 0;
-	}
-	else
-		eflagok = 1;
-	popword();
-	if(p->argv->words && strcmp(p->argv->words->word, "-i")==0){
-		iflag = 1;
-		popword();
-	}
-	/* get input file */
-	if(p->argv->words==0){
-		Xerror1("Usage: . [-i] file [arg ...]");
-		return;
-	}
-	zero = strdup(p->argv->words->word);
-	popword();
-	fd=-1;
-	for(path = searchpath(zero);path;path = path->next){
-		strcpy(file, path->word);
-		if(file[0])
-			strcat(file, "/");
-		strcat(file, zero);
-		if((fd = open(file, 0))>=0) break;
-		if(strcmp(file, "/dev/stdin")==0){	/* for sun & ucb */
-			fd = Dup1(0);
-			if(fd>=0)
-				break;
-		}
-	}
-	if(fd<0){
-		pfmt(err, "%s: ", zero);
-		setstatus("can't open");
-		Xerror(".: can't open");
-		return;
-	}
-	/* set up for a new command loop */
-	start(dotcmds, 1, (struct var *)0);
-	pushredir(RCLOSE, fd, 0);
-	runq->cmdfile = zero;
-	runq->cmdfd = openfd(fd);
-	runq->iflag = iflag;
-	runq->iflast = 0;
-	/* push $* value */
-	pushlist();
-	runq->argv->words = p->argv->words;
-	/* free caller's copy of $* */
-	av = p->argv;
-	p->argv = av->next;
-	efree((char *)av);
-	/* push $0 value */
-	pushlist();
-	pushword(zero);
-	ndot++;
-}
-
-void
-execflag(void)
-{
-	char *letter, *val;
-	switch(count(runq->argv->words)){
-	case 2:
-		setstatus(flag[runq->argv->words->next->word[0]]?"":"flag not set");
-		break;
-	case 3:
-		letter = runq->argv->words->next->word;
-		val = runq->argv->words->next->next->word;
-		if(strlen(letter)==1){
-			if(strcmp(val, "+")==0){
-				flag[(uchar)letter[0]] = flagset;
-				break;
-			}
-			if(strcmp(val, "-")==0){
-				flag[(uchar)letter[0]] = 0;
-				break;
-			}
-		}
-	default:
-		Xerror1("Usage: flag [letter] [+-]");
-		return;
-	}
-	poplist();
-}
-
-void
-execwhatis(void){	/* mildly wrong -- should fork before writing */
-	word *a, *b, *path;
-	var *v;
-	struct builtin *bp;
-	char file[512];
-	struct io out[1];
-	int found, sep;
-	a = runq->argv->words->next;
-	if(a==0){
-		Xerror1("Usage: whatis name ...");
-		return;
-	}
-	setstatus("");
-	out->fd = mapfd(1);
-	out->bufp = out->buf;
-	out->ebuf = &out->buf[NBUF];
-	out->strp = 0;
-	for(;a;a = a->next){
-		v = vlook(a->word);
-		if(v->val){
-			pfmt(out, "%s=", a->word);
-			if(v->val->next==0)
-				pfmt(out, "%q\n", v->val->word);
-			else{
-				sep='(';
-				for(b = v->val;b && b->word;b = b->next){
-					pfmt(out, "%c%q", sep, b->word);
-					sep=' ';
-				}
-				pfmt(out, ")\n");
-			}
-			found = 1;
-		}
-		else
-			found = 0;
-		v = gvlook(a->word);
-		if(v->fn)
-			pfmt(out, "fn %s %s\n", v->name, v->fn[v->pc-1].s);
-		else{
-			for(bp = Builtin;bp->name;bp++)
-				if(strcmp(a->word, bp->name)==0){
-					pfmt(out, "builtin %s\n", a->word);
-					break;
-				}
-			if(!bp->name){
-				for(path = searchpath(a->word);path;path = path->next){
-					strcpy(file, path->word);
-					if(file[0])
-						strcat(file, "/");
-					strcat(file, a->word);
-					if(Executable(file)){
-						pfmt(out, "%s\n", file);
-						break;
-					}
-				}
-				if(!path && !found){
-					pfmt(err, "%s: not found\n", a->word);
-					setstatus("not found");
-				}
-			}
-		}
-	}
-	poplist();
-	flush(err);
-}
-
-void
-execwait(void)
-{
-	switch(count(runq->argv->words)){
-	default:
-		Xerror1("Usage: wait [pid]");
-		return;
-	case 2:
-		Waitfor(atoi(runq->argv->words->next->word), 0);
-		break;
-	case 1:
-		Waitfor(-1, 0);
-		break;
-	}
-	poplist();
-}

+ 0 - 8
sys/src/cmd/rc/unix/words

@@ -1,8 +0,0 @@
-How to build rc on unix:
-
-ramfs
-dircp .. /tmp
-cd /tmp/unix
-dircp . ..
-cd ..
-run

+ 3 - 2
sys/src/cmd/rc/win32.c

@@ -24,8 +24,9 @@ char *syssigname[] = {
 	"term",
 	0
 };
-char Rcmain[]="/rc/lib/rcmain";
-char Fdprefix[]="/fd/";
+char *Rcmain = "/rc/lib/rcmain";
+char *Fdprefix = "/fd/";
+
 void execfinit(void);
 void execbind(void);
 

+ 6 - 4
sys/src/libmach/map.c

@@ -84,7 +84,6 @@ attachproc(int pid, int kflag, int corefd, Fhdr *fp)
 	int fd;
 	Map *map;
 	uvlong n;
-	int mode;
 
 	map = newmap(0, 4);
 	if (!map)
@@ -93,10 +92,11 @@ attachproc(int pid, int kflag, int corefd, Fhdr *fp)
 		regs = "kregs";
 	else
 		regs = "regs";
-	mode = ORDWR;
 	if (mach->regsize) {
 		sprint(buf, "/proc/%d/%s", pid, regs);
-		fd = open(buf, mode);
+		fd = open(buf, ORDWR);
+		if(fd < 0)
+			fd = open(buf, OREAD);
 		if(fd < 0) {
 			free(map);
 			return 0;
@@ -105,7 +105,9 @@ attachproc(int pid, int kflag, int corefd, Fhdr *fp)
 	}
 	if (mach->fpregsize) {
 		sprint(buf, "/proc/%d/fpregs", pid);
-		fd = open(buf, mode);
+		fd = open(buf, ORDWR);
+		if(fd < 0)
+			fd = open(buf, OREAD);
 		if(fd < 0) {
 			close(map->seg[0].fd);
 			free(map);