Update cmd/sh.

This commit is contained in:
Serge
2022-05-28 00:39:33 -07:00
parent 97dfd3ae89
commit f6602a8a6d
27 changed files with 466 additions and 299 deletions

View File

@@ -22,21 +22,28 @@ clean:
args.o: args.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
blok.o: blok.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
builtin.o: builtin.c
cmd.o: cmd.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h sym.h
ctype.o: ctype.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
defs.o: defs.c mode.h name.h
echo.o: echo.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
error.o: error.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
expand.o: expand.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
fault.o: fault.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
io.o: io.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
func.o: func.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
hash.o: hash.c hash.h defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
hashserv.o: hashserv.c hash.h defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
io.o: io.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h dup.h
macro.o: macro.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h sym.h
main.o: main.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h sym.h timeout.h
main.o: main.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h sym.h timeout.h dup.h
msg.o: msg.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h sym.h
name.o: name.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
print.o: print.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
profile.o: profile.c
pwd.o: pwd.c mac.h defs.h mode.h name.h stak.h brkincr.h ctype.h
service.o: service.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
setbrk.o: setbrk.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
stak.o: stak.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
string.o: string.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
test.o: test.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h
word.o: word.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h sym.h
xec.o: xec.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h sym.h
xec.o: xec.c defs.h mac.h mode.h name.h stak.h brkincr.h ctype.h sym.h hash.h

View File

@@ -5,9 +5,6 @@
*/
#include "defs.h"
static struct dolnod *copyargs();
static struct dolnod *freedolh();
extern struct dolnod *freeargs();
static struct dolnod *dolh;
char flagadr[14];
@@ -48,12 +45,15 @@ long flagval[] =
0
};
static void freedolh(void);
static struct dolnod *copyargs(char *from[], int n);
/* ======== option handling ======== */
options(argc,argv)
char **argv;
int
options(argc, argv)
int argc;
char **argv;
{
register char *cp;
register char **argp = argv;
@@ -160,6 +160,7 @@ options(argc,argv)
/*
* sets up positional parameters
*/
void
setargs(argi)
char *argi[];
{
@@ -176,14 +177,13 @@ setargs(argi)
dolc = argn - 1;
}
static struct dolnod *
static void
freedolh()
{
register char **argp;
register struct dolnod *argblk;
if (argblk = dolh)
if ((argblk = dolh))
{
if ((--argblk->doluse) == 0)
{
@@ -203,7 +203,7 @@ freeargs(blk)
register struct dolnod *argblk;
int cnt;
if (argblk = blk)
if ((argblk = blk))
{
argr = argblk->dolnxt;
cnt = --argblk->doluse;
@@ -255,7 +255,7 @@ clean_args(blk)
register struct dolnod *argr = NIL;
register struct dolnod *argblk;
if (argblk = blk)
if ((argblk = blk))
{
argr = argblk->dolnxt;
@@ -271,12 +271,13 @@ clean_args(blk)
return(argr);
}
void
clearup()
{
/*
* force `for' $* lists to go away
*/
while (argfor = clean_args(argfor))
while ((argfor = clean_args(argfor)))
;
/*
* clean up io files

View File

@@ -97,7 +97,7 @@ addblok(reqd)
void
free(ap)
struct blk *ap;
void *ap;
{
register struct blk *p;

View File

@@ -34,7 +34,7 @@ makefork(flgs, i)
return((struct trenod *)t);
}
static int
static void
prsym(sym)
{
if (sym & SYMFLG)
@@ -58,7 +58,7 @@ prsym(sym)
}
}
static int
static void
synbad()
{
prp();
@@ -107,7 +107,7 @@ skipnl()
return(wdval);
}
static int
static void
chksym(sym)
{
register int x = sym & wdval;
@@ -159,7 +159,7 @@ register int esym;
}
}
static int
static void
chkword()
{
if (word())
@@ -344,7 +344,7 @@ item(flag)
p = (struct parnod *)getstor(sizeof(struct parnod));
p->partre = cmd(')', NLFLG);
p->partyp = TPAR;
r = makefork(0, p);
r = makefork(0, (struct trenod *) p);
break;
}
@@ -453,8 +453,7 @@ item(flag)
}
reserv++;
word();
if (io = inout(io))
{
if ((io = inout(io))) {
r = makefork(0,r);
r->treio = io;
}
@@ -542,7 +541,7 @@ cmd(sym, flg)
synbad();
case ';':
if (e = cmd(sym, flg | MTFLG))
if ((e = cmd(sym, flg | MTFLG)))
i = makelist(TLST, i, e);
else if (i == NIL)
synbad();

View File

@@ -84,7 +84,7 @@ extern char _ctype2[];
#define astchar(c) (((c)&QUOTE)==0 && _ctype2[c]&(T_AST))
extern char _ctype3[];
char cj;
extern char cj;
#define qmask(c) (cj=(c),( (cj&0200) ||(_ctype3[cj]) ==0)? cj : _ctype3[cj])
#define smask(c) (cj=(c),cj=QST(cj),((!(cj&0200))||(_ctype3[cii(cj)]) ==0)? cj : _ctype3[cii(cj)])

View File

@@ -337,5 +337,121 @@ void addblok(unsigned reqd);
char *movstr(char *a, char *b);
char *setbrk(int incr);
void error(char *s);
void free(struct blk *ap);
char *alloc(unsigned nbytes);
void free(void *ap);
void rmtemp(struct ionod *base);
void prs(char *as);
void prc(char c);
void prp(void);
void prn(int n);
void prs_cntl(char *s);
void exitsh(int xno);
int word(void);
void chkpr(void);
int length(char *as);
struct trenod *cmd(int sym, int flg);
int nextc(char quote);
char *make(char *v);
struct trenod *makefork(int flgs, struct trenod *i);
int skipc(void);
short pathlook(char *com, int flg, struct argnod *arg);
void done(void);
void clrsig(int i);
void failed(char *s1, char *s2);
void execexp(char *s, void *f);
void dfault(struct namnod *n, char *v);
int ignsig(int n);
void setmail(char *mailpath);
void initf(int fd);
void tdystak(char *x);
void stakchk(void);
void prprompt(char *as);
int readc(void);
int execute(struct trenod *argt, int exec_link, int errorflg, int *pf1, int *pf2);
void stdsigs(void);
void setup_env(void);
struct namnod *findnam(char *nam);
int any(char c, char *s);
char *simple(char *s);
void hcreate(void);
void set_dotpath(void);
int options(int argc, char **argv);
void replace(char **a, char *v);
void assnum(char **p, int i);
void settmp(void);
int stoi(char *icp);
int pathopen(char *path, char *name);
int estabf(char *s);
int chkopen(char *idf);
void itos(int n);
int syslook(char *w, struct sysnod syswds[], int n);
void copy(struct ionod *ioparg);
void chktrap(void);
void clearup(void);
int cf(char *s1, char *s2);
char *mactrim(char *s);
struct namnod *lookup(char *nam);
void assign(struct namnod *n, char *v);
void func_unhash(char *name);
void freefunc(struct namnod *n);
void zaphash(void);
void push(struct fileblk *af);
int pop(void);
void prs_buff(char *s);
void prc_buff(char c);
void prf(struct trenod *t);
void namscan(void (*fn)(struct namnod *));
int poptemp(void);
void hash_func(char *name);
int getarg(struct comnod *ac);
char **scan(int argn);
void setlist(struct argnod *arg, int xp);
int initio(struct ionod *iop, int save);
char *getpath(char *s);
void prt(long t);
void getsig(int n);
void prn_buff(int n);
void oldsigs(void);
void execa(char *at[], short pos);
char *catpath(char *path, char *name);
void cwd(char *dir);
void zapcd(void);
void await(int i, int bckg);
int readvar(char **names);
void setargs(char *argi[]);
void printnam(struct namnod *n);
void printro(struct namnod *n);
void printexp(struct namnod *n);
int test(int argn, char *com[]);
int echo(int argc, char **argv);
short hash_cmd(char *name);
void hashpr(void);
void cwdprint(void);
void what_is_path(char *name);
void unset_name(char *name);
void flushb(void);
void restore(int last);
void link_iodocs(struct ionod *i);
void post(int pcsid);
void swap_iodoc_nm(struct ionod *i);
void postclr(void);
void rename(int f1, int f2);
void chkpipe(int *pv);
struct dolnod *useargs(void);
void trim(char *at);
struct dolnod *freeargs(struct dolnod *blk);
int gmatch(char *s, char *p);
char *macro(char *as);
int savefd(int fd);
void subst(int in, int ot);
int tmpfil(struct tempblk *tb);
int create(char *s);
char **setenvv(void);
int expand(char *as, int rcnt);
void makearg(struct argnod *args);
void clear_buff(void);
char *movstrn(char *a, char *b, int n);
void reset_dir(void);
void hscan(void (*uscan)());
char *nextpath(char *path);
struct direct *getdir(int dirf);

View File

@@ -9,6 +9,7 @@
extern int exitval;
int
echo(argc, argv)
char **argv;
{

View File

@@ -5,6 +5,8 @@
*/
#include "defs.h"
void rmfunctmp(void);
/* ======== error handling ======== */
void
failed(s1, s2)
@@ -59,7 +61,7 @@ done()
{
register char *t;
if (t = trapcom[0])
if ((t = trapcom[0]))
{
trapcom[0] = NIL;
execexp(t, 0);

View File

@@ -7,8 +7,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/dir.h>
struct direct *getdir();
#include <fcntl.h>
static char entry[MAXNAMLEN+1];
@@ -16,7 +15,7 @@ static DIR dirbuf;
#define XXX 0200
static int
static void
addg(as1, as2, as3)
char *as1, *as2, *as3;
{
@@ -25,7 +24,7 @@ char *as1, *as2, *as3;
s2 = locstak() + BYTESPERWORD;
s1 = as1;
while (c = /* @@@ *s1++ */ cii(*s1++))
while ((c = /* @@@ *s1++ */ cii(*s1++)))
{
if (/* @@@ (c &= STRIP)*/ (c=smask(c)) == 0)
{
@@ -35,14 +34,14 @@ char *as1, *as2, *as3;
*s2++ = c;
}
s1 = as2;
while (*s2 = *s1++)
while ((*s2 = *s1++))
s2++;
if (s1 = as3)
if ((s1 = as3))
{
*s2++ = '/';
while (*s2++ = *++s1);
while ((*s2++ = *++s1));
}
makearg(endstak(s2));
makearg((struct argnod *) endstak(s2));
}
/*
@@ -54,6 +53,7 @@ char *as1, *as2, *as3;
* "[...a-z...]" in params matches a through z.
*
*/
int
expand(as, rcnt)
char *as;
{
@@ -208,14 +208,14 @@ expand(as, rcnt)
register char c;
s = as;
while (c = *s)
while ((c = *s))
/* @@@ *s++ = (c & STRIP ? c : '/'); */
*s++ = smask(c) ? c: '/';
}
return(count);
}
void
reset_dir()
{
dirbuf.dd_loc = 0;
@@ -227,7 +227,6 @@ reset_dir()
* and ignore inode == 0
*
*/
struct direct *
getdir(dirf)
{
@@ -254,14 +253,14 @@ getdir(dirf)
}
}
int
gmatch(s, p)
register char *s, *p;
{
register int scc;
char c;
if (scc = /* @@@ *s++ */ cii( *s++))
if ((scc = /* @@@ *s++ */ cii(*s++)))
{
if ( /* @@@ (scc &= STRIP) */ smask(scc) == 0)
scc=XXX;
@@ -281,7 +280,7 @@ register char *s, *p;
notflag = 1;
p++;
}
while (c = /* @@@ *p++ */ cii(*p++))
while ((c = /* @@@ *p++ */ cii(*p++)))
{
if (c == ']')
return(ok ? gmatch(s, p) : 0);
@@ -348,6 +347,7 @@ register char *s, *p;
}
}
void
makearg(args)
register struct argnod *args;
{

View File

@@ -35,6 +35,61 @@ BOOL trapflg[MAXTRAP] =
0, /* 23 tint */
};
/* ======== fault handling routines ======== */
void
fault(sig)
register int sig;
{
register int flag;
signal(sig, fault);
if (sig == SIGSEGV)
{
if (setbrk(brkincr) == (char*)-1)
error(nospace);
}
else if (sig == SIGALRM)
{
if (flags & waiting)
done();
}
else
{
flag = (trapcom[sig] ? TRAPSET : SIGSET);
trapnote |= flag;
trapflg[sig] |= flag;
if (sig == SIGINT)
wasintr++;
}
}
int
ignsig(n)
{
register int s, i;
if ((i = n) == SIGSEGV)
{
clrsig(i);
failed(badtrap, "cannot trap 11");
}
else if ((s = (signal(i, SIG_IGN) == SIG_IGN)) == 0)
{
trapflg[i] |= SIGMOD;
}
return(s);
}
void
getsig(n)
{
register int i;
if (trapflg[i = n] & SIGMOD || ignsig(i) == 0)
signal(i, fault);
}
void (*sigval[])() = {
0,
done,
@@ -62,35 +117,16 @@ void (*sigval[])() = {
SIG_DFL,
};
/* ======== fault handling routines ======== */
void
fault(sig)
register int sig;
setsig(n)
{
register int flag;
register int i;
signal(sig, fault);
if (sig == SIGSEGV)
{
if (setbrk(brkincr) == -1)
error(nospace);
}
else if (sig == SIGALRM)
{
if (flags & waiting)
done();
}
else
{
flag = (trapcom[sig] ? TRAPSET : SIGSET);
trapnote |= flag;
trapflg[sig] |= flag;
if (sig == SIGINT)
wasintr++;
}
if (ignsig(i = n) == 0)
signal(i, sigval[i]);
}
void
stdsigs()
{
setsig(SIGHUP);
@@ -115,39 +151,7 @@ stdsigs()
#endif
}
ignsig(n)
{
register int s, i;
if ((i = n) == SIGSEGV)
{
clrsig(i);
failed(badtrap, "cannot trap 11");
}
else if ((s = (signal(i, SIG_IGN) == SIG_IGN)) == 0)
{
trapflg[i] |= SIGMOD;
}
return(s);
}
getsig(n)
{
register int i;
if (trapflg[i = n] & SIGMOD || ignsig(i) == 0)
signal(i, fault);
}
setsig(n)
{
register int i;
if (ignsig(i = n) == 0)
signal(i, sigval[i]);
}
void
oldsigs()
{
register int i;
@@ -164,6 +168,7 @@ oldsigs()
trapnote = 0;
}
void
clrsig(i)
int i;
{
@@ -179,6 +184,7 @@ int i;
/*
* check for traps
*/
void
chktrap()
{
register int i = MAXTRAP;
@@ -190,7 +196,7 @@ chktrap()
if (trapflg[i] & TRAPSET)
{
trapflg[i] &= ~TRAPSET;
if (t = trapcom[i])
if ((t = trapcom[i]))
{
int savxit = exitval;

View File

@@ -5,13 +5,21 @@
*/
#include "defs.h"
static void freetree(struct trenod *t);
static void freeio(struct ionod *iop);
static void free_arg(struct argnod *argp);
static void freereg(struct regnod *regp);
static void prarg(struct argnod *argp);
static void prio(struct ionod *iop);
void
freefunc(n)
struct namnod *n;
{
freetree((struct trenod *)(n->namenv));
}
static void
freetree(t)
register struct trenod *t;
{
@@ -94,6 +102,7 @@ freetree(t)
}
}
static void
free_arg(argp)
register struct argnod *argp;
{
@@ -107,7 +116,7 @@ free_arg(argp)
}
}
static void
freeio(iop)
register struct ionod *iop;
{
@@ -146,7 +155,7 @@ freeio(iop)
}
}
static void
freereg(regp)
register struct regnod *regp;
{
@@ -162,7 +171,7 @@ freereg(regp)
}
}
void
prf(t)
register struct trenod *t;
{
@@ -328,6 +337,7 @@ prf(t)
sigchk();
}
static void
prarg(argp)
register struct argnod *argp;
{
@@ -339,7 +349,7 @@ prarg(argp)
}
}
static void
prio(iop)
register struct ionod *iop;
{

View File

@@ -30,6 +30,7 @@ static unsigned int shift;
static unsigned int crunch();
void
hcreate()
{
#ifdef NOTDEF
@@ -58,8 +59,8 @@ hcreate()
shift = (bitsper * sizeof(int)) - LOG2LEN;
}
void hscan(uscan)
void
hscan(uscan)
void (*uscan)();
{
struct node *p, *nxt;
@@ -77,8 +78,6 @@ void hscan(uscan)
}
}
ENTRY *
hfind(str)
char *str;
@@ -129,7 +128,6 @@ henter(item)
return(&(p->item));
}
static unsigned int
crunch(key)
char *key;

View File

@@ -19,7 +19,6 @@
#define hashtype(x) (x & 0x1F00)
#define hashdata(x) (x & 0x00FF)
typedef struct entry
{
char *key;
@@ -29,6 +28,6 @@ typedef struct entry
struct entry *next;
} ENTRY;
extern ENTRY *hfind();
extern ENTRY *henter();
extern int hcreate();
ENTRY *hfind();
ENTRY *henter();
void hcreate(void);

View File

@@ -16,6 +16,10 @@ static int dotpath;
static int multrel;
static struct entry *relcmd = NIL;
static int findpath(char *name, int oldpath);
static void pr_path(char *name, int count);
static int chk_access(char *name);
static int
argpath(arg)
register struct argnod *arg;
@@ -110,7 +114,7 @@ pathlook(com, flg, arg)
h->cost = 0;
}
if (i = syslook(name, commands, no_commands))
if ((i = syslook(name, commands, no_commands)))
{
hentry.data = (BUILTIN | i);
count = 1;
@@ -155,7 +159,6 @@ pathsrch:
}
}
static void
zapentry(h)
ENTRY *h;
@@ -180,7 +183,6 @@ zapcd()
}
}
static void
hashout(h)
ENTRY *h;
@@ -214,7 +216,7 @@ hashpr()
hscan(hashout);
}
void
set_dotpath()
{
register char *path;
@@ -244,7 +246,7 @@ set_dotpath()
multrel = 0;
}
void
hash_func(name)
char *name;
{
@@ -265,7 +267,7 @@ hash_func(name)
{
int i;
if (i = syslook(name, commands, no_commands))
if ((i = syslook(name, commands, no_commands)))
hentry.data = (BUILTIN | i);
else
hentry.data = FUNCTION;
@@ -278,6 +280,7 @@ hash_func(name)
}
}
void
func_unhash(name)
char *name;
{
@@ -289,7 +292,6 @@ func_unhash(name)
h->data = NOTFOUND;
}
short
hash_cmd(name)
char *name;
@@ -312,7 +314,7 @@ hash_cmd(name)
return(pathlook(name, 0, NIL));
}
void
what_is_path(name)
register char *name;
{
@@ -340,7 +342,7 @@ what_is_path(name)
prs_buff(" is a function\n");
prs_buff(name);
prs_buff("(){\n");
prf(n->namenv);
prf((struct trenod *) n->namenv);
prs_buff("\n}\n");
return;
}
@@ -386,7 +388,7 @@ what_is_path(name)
prs_buff(" not found\n");
}
static int
findpath(name, oldpath)
register char *name;
int oldpath;
@@ -439,7 +441,7 @@ findpath(name, oldpath)
return(ok ? -e_code : count);
}
static int
chk_access(name)
register char *name;
{
@@ -450,7 +452,7 @@ chk_access(name)
return(errno == EACCES ? 3 : 1);
}
static void
pr_path(name, count)
register char *name;
int count;
@@ -460,7 +462,7 @@ pr_path(name, count)
path = getpath(name);
while (--count && path)
path = nextpath(path, name);
path = nextpath(path);
catpath(path, name);
prs_buff(curstak());

View File

@@ -5,13 +5,13 @@
*/
#include "defs.h"
#include "dup.h"
#include <sys/fcntl.h>
#include <fcntl.h>
#include <sys/param.h>
short topfd;
/* ======== input output and file copying ======== */
void
initf(fd)
int fd;
{
@@ -25,6 +25,7 @@ int fd;
f->feof = FALSE;
}
int
estabf(s)
register char *s;
{
@@ -36,6 +37,7 @@ register char *s;
return(f->feof = (s == NIL));
}
void
push(af)
struct fileblk *af;
{
@@ -47,6 +49,7 @@ struct fileblk *af;
standin = f;
}
int
pop()
{
register struct fileblk *f;
@@ -64,6 +67,7 @@ pop()
struct tempblk *tmpfptr;
void
pushtemp(fd,tb)
int fd;
struct tempblk *tb;
@@ -73,6 +77,7 @@ pushtemp(fd,tb)
tmpfptr = tb;
}
int
poptemp()
{
if (tmpfptr)
@@ -85,6 +90,7 @@ poptemp()
return(FALSE);
}
void
chkpipe(pv)
int *pv;
{
@@ -92,6 +98,7 @@ int *pv;
error(piperr);
}
int
chkopen(idf)
char *idf;
{
@@ -99,27 +106,16 @@ char *idf;
if ((rc = open(idf, 0)) < 0)
failed(idf, badopen);
else
return(rc);
return(rc);
}
void
rename(f1, f2)
register int f1, f2;
{
#if defined(RES) || defined(pdp11)
if (f1 != f2)
{
dup(f1 | DUPFLG, f2);
close(f1);
if (f2 == 0)
ioset |= 1;
}
#else
int fs;
if (f1 != f2)
{
fs = fcntl(f2, F_GETFD, 0);
int fs = fcntl(f2, F_GETFD, 0);
close(f2);
fcntl(f1, F_DUPFD, f2);
close(f1);
@@ -128,9 +124,9 @@ register int f1, f2;
if (f2 == 0)
ioset |= 1;
}
#endif
}
int
create(s)
char *s;
{
@@ -138,10 +134,10 @@ char *s;
if ((rc = creat(s, 0666)) < 0)
failed(s, badcreate);
else
return(rc);
return(rc);
}
int
tmpfil(tb)
struct tempblk *tb;
{
@@ -158,8 +154,9 @@ tmpfil(tb)
* set by trim
*/
extern BOOL nosubst;
#define CPYSIZ 512
#define CPYSIZ 512
void
copy(ioparg)
struct ionod *ioparg;
{
@@ -173,8 +170,7 @@ struct ionod *ioparg;
int i;
int stripflg;
if (iop = ioparg)
if ((iop = ioparg))
{
struct tempblk tb;
@@ -254,7 +250,7 @@ struct ionod *ioparg;
}
}
void
link_iodocs(i)
struct ionod *i;
{
@@ -271,7 +267,7 @@ link_iodocs(i)
}
}
void
swap_iodoc_nm(i)
struct ionod *i;
{
@@ -285,7 +281,7 @@ swap_iodoc_nm(i)
}
}
int
savefd(fd)
int fd;
{
@@ -295,7 +291,7 @@ savefd(fd)
return(f);
}
void
restore(last)
register int last;
{

View File

@@ -11,7 +11,7 @@ static char quoted; /* used locally */
static int getch();
static char *
static void
copyto(endch)
register char endch;
{
@@ -24,7 +24,7 @@ register char endch;
error(badsub);
}
static
static void
skipto(endch)
register char endch;
{
@@ -54,7 +54,7 @@ register char endch;
error(badsub);
}
static
static void
comsubst()
{
/*
@@ -89,7 +89,7 @@ comsubst()
}
tdystak(savptr);
staktop = movstr(savptr, stakbot);
while (d = readc())
while ((d = readc()))
/* @@@ pushstak(d | quote); */
pushstak( quote ? qmask(d) : d );
@@ -130,7 +130,7 @@ retry:
char idb[2];
char *id = idb;
if (bra = (c == BRACE))
if ((bra = (c == BRACE)))
c = cii(readc()); /* @@@ */
if (letter(c))
{
@@ -221,7 +221,7 @@ retry:
pushstak(QUOTE);
else
{
while (c = *v++)
while ((c = *v++))
/* @@@ pushstak(c | quote); */
pushstak( quote ? qmask(c) : c );
}
@@ -286,7 +286,7 @@ char *as;
register char savq = quote;
struct filehdr fb;
push(&fb);
push((struct fileblk *) &fb);
estabf(as);
usestak();
quote = 0;
@@ -303,7 +303,7 @@ char *as;
return(fixstak());
}
static
static void
flush(ot)
{
write(ot, stakbot, staktop - stakbot);
@@ -314,6 +314,7 @@ flush(ot)
#define CPYSIZ 512
void
subst(in, ot)
int in, ot;
{
@@ -326,7 +327,7 @@ int in, ot;
/*
* DQUOTE used to stop it from quoting
*/
while (c = /* @@@ (getch(DQUOTE) & STRIP)*/ smask(getch(DQUOTE)) )
while ((c = /* @@@ (getch(DQUOTE) & STRIP)*/ smask(getch(DQUOTE))))
{
pushstak(c);
if (--count == 0)

View File

@@ -9,7 +9,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "dup.h"
#include <sys/fcntl.h>
#include <fcntl.h>
#include <sys/param.h>
#ifdef RES
@@ -30,9 +30,10 @@ static long *mod_time = (long *)NIL;
#include <sgtty.h>
#endif
extern char *simple();
void Ldup(int fa, int fb);
void chkmail(void);
static int
static void
exfile(prof)
BOOL prof;
{
@@ -50,7 +51,8 @@ BOOL prof;
}
userid = geteuid();
if( userid ) defpath[ENDPATH] = '\0'; /* no /etc */
if (userid)
defpath[ENDPATH] = '\0'; /* no /etc */
/*
* decide whether interactive
@@ -135,11 +137,12 @@ BOOL prof;
flags &= ~waiting;
execute(cmd(NL, MTFLG), 0, eflag);
execute(cmd(NL, MTFLG), 0, eflag, NULL, NULL);
eof |= (flags & oneflg);
}
}
int
main(c, v, e)
int c;
char **v;
@@ -169,7 +172,7 @@ char **e;
* set in environment and contains an'r' in
* the simple file part of the value.
*/
if (n = findnam("SHELL"))
if ((n = findnam("SHELL")))
{
if (any('r', simple(n->namval)))
rsflag = 0;
@@ -285,12 +288,14 @@ char **e;
done();
}
void
chkpr()
{
if ((flags & prompt) && standin->fstak == NIL)
prs(ps2nod.namval);
}
void
settmp()
{
itos(getpid());
@@ -298,6 +303,7 @@ settmp()
tmpnam = movstr(numbuf, &tmpout[TMPNAM]);
}
void
Ldup(fa, fb)
register int fa, fb;
{
@@ -316,7 +322,7 @@ register int fa, fb;
#endif
}
void
chkmail()
{
register char *s = mailp;
@@ -380,6 +386,7 @@ chkmail()
}
}
void
setmail(mailpath)
char *mailpath;
{
@@ -389,7 +396,7 @@ setmail(mailpath)
long *ptr;
free(mod_time);
if (mailp = mailpath)
if ((mailp = mailpath))
{
while (*s)
{

View File

@@ -5,8 +5,6 @@
*/
#include "defs.h"
extern BOOL chkid();
extern char *simple();
extern int mailchk;
struct namnod ps2nod =
@@ -70,11 +68,13 @@ struct namnod mailpnod =
mailpname
};
struct namnod *namep = &mchknod;
/* ======== variable and string handling ======== */
void setname(char *argi, int xp);
BOOL chkid(char *nam);
/* ======== variable and string handling ======== */
int
syslook(w, syswds, n)
register char *w;
register struct sysnod syswds[];
@@ -105,6 +105,7 @@ syslook(w, syswds, n)
return(0);
}
void
setlist(arg, xp)
register struct argnod *arg;
int xp;
@@ -128,7 +129,7 @@ int xp;
}
}
void
setname(argi, xp) /* does parameter assignments */
char *argi;
int xp;
@@ -158,6 +159,7 @@ int xp;
failed(argi, notid);
}
void
replace(a, v)
register char **a;
char *v;
@@ -166,6 +168,7 @@ char *v;
*a = make(v);
}
void
dfault(n, v)
struct namnod *n;
char *v;
@@ -174,6 +177,7 @@ char *v;
assign(n, v);
}
void
assign(n, v)
struct namnod *n;
char *v;
@@ -222,6 +226,7 @@ char *v;
}
}
int
readvar(names)
char **names;
{
@@ -298,6 +303,7 @@ char **names;
return(rc);
}
void
assnum(p, i)
char **p;
int i;
@@ -321,7 +327,6 @@ char *v;
return(NIL);
}
struct namnod *
lookup(nam)
register char *nam;
@@ -375,9 +380,9 @@ char *nam;
return(TRUE);
}
static int (*namfn)();
static void (*namfn)(struct namnod *);
static int
static void
namwalk(np)
register struct namnod *np;
{
@@ -389,13 +394,15 @@ register struct namnod *np;
}
}
void
namscan(fn)
int (*fn)();
void (*fn)(struct namnod *);
{
namfn = fn;
namwalk(namep);
}
void
printnam(n)
struct namnod *n;
{
@@ -407,10 +414,10 @@ struct namnod *n;
{
prs_buff(n->namid);
prs_buff("(){\n");
prf(n->namenv);
prf((struct trenod *) n->namenv);
prs_buff("\n}\n");
}
else if (s = n->namval)
else if ((s = n->namval))
{
prs_buff(n->namid);
prc_buff('=');
@@ -433,6 +440,7 @@ register struct namnod *n;
static int namec;
void
exname(n)
register struct namnod *n;
{
@@ -462,6 +470,7 @@ exname(n)
}
void
printro(n)
register struct namnod *n;
{
@@ -474,6 +483,7 @@ register struct namnod *n;
}
}
void
printexp(n)
register struct namnod *n;
{
@@ -486,6 +496,7 @@ register struct namnod *n;
}
}
void
setup_env()
{
register char **e = environ;
@@ -494,9 +505,9 @@ setup_env()
setname(*e++, N_ENVNAM);
}
static char **argnam;
void
pushnam(n)
struct namnod *n;
{
@@ -539,13 +550,13 @@ findnam(nam)
return(NIL);
}
void
unset_name(name)
register char *name;
{
register struct namnod *n;
if (n = findnam(name))
if ((n = findnam(name)))
{
if (n->namflg & N_RDONLY)
failed(name, wtfailed);

View File

@@ -6,8 +6,6 @@
#include "defs.h"
#include <sys/param.h>
extern char *getenv();
#define BUFLEN 256
int hz = (-1);
@@ -16,15 +14,10 @@ static char buffer[BUFLEN];
static int index = 0;
char numbuf[12];
extern void prc_buff();
extern void prs_buff();
extern void prn_buff();
extern void prs_cntl();
extern void prn_buff();
/*
* printing and io conversion
*/
void
prp()
{
if ((flags & prompt) == 0 && cmdadr)
@@ -34,30 +27,33 @@ prp()
}
}
void
prs(as)
char *as;
{
register char *s;
if (s = as)
if ((s = as))
write(output, s, length(s) - 1);
}
/* print a prompt */
/* it's a subject for future expansion @@@ */
void
prprompt(as)
char *as;
{
prs(as);
}
prc(c)
char c;
void
prc(char c)
{
if (c)
write(output, &c, 1);
}
void
prt(t)
long t;
{
@@ -66,8 +62,10 @@ long t;
if( hz < 0 ){
s = getenv( "HZ" );
if( s ) hz = atoi( s );
else hz = HZ;
if (s)
hz = atoi( s );
else
hz = HZ;
}
t += hz / 2;
@@ -76,7 +74,7 @@ long t;
t /= HZ;
min = t % hz;
if (hr = t / hz)
if ((hr = t / hz))
{
prn_buff(hr);
prc_buff('h');
@@ -88,6 +86,7 @@ long t;
prc_buff('s');
}
void
prn(n)
int n;
{
@@ -96,6 +95,7 @@ prn(n)
prs(numbuf);
}
void
itos(n)
{
register char *abuf;
@@ -116,6 +116,7 @@ itos(n)
*abuf++ = 0;
}
int
stoi(icp)
char *icp;
{
@@ -130,10 +131,10 @@ char *icp;
}
if (r < 0 || cp == icp)
failed(icp, badnum);
else
return(r);
return(r);
}
void
prl(n)
long n;
{
@@ -161,8 +162,7 @@ flushb()
}
void
prc_buff(c)
char c;
prc_buff(char c)
{
if (c)
{
@@ -196,13 +196,12 @@ prs_buff(s)
}
}
void
clear_buff()
{
index = 0;
}
void
prs_cntl(s)
char *s;
@@ -239,7 +238,6 @@ prs_cntl(s)
prs(buffer);
}
void
prn_buff(n)
int n;

View File

@@ -5,6 +5,7 @@
*/
#include "mac.h"
#include "defs.h"
#include <fcntl.h>
#define DOT '.'
#define NULL 0
@@ -19,7 +20,7 @@ static int didpwd = FALSE;
/*
* This routine will remove repeated slashes from string.
*/
static
static void
rmslash(string)
char *string;
{
@@ -48,6 +49,7 @@ rmslash(string)
return;
}
void
cwd(dir)
register char *dir;
{
@@ -157,10 +159,7 @@ cwd(dir)
static char dotdots[] =
"../../../../../../../../../../../../../../../../../../../../../../../..";
extern struct direct *getdir();
extern char *movstrn();
static
static void
pwd()
{
struct stat cdir; /* current directory status */
@@ -270,6 +269,7 @@ pwd()
/*
* Print the current working directory.
*/
void
prcwd()
{
if (didpwd == FALSE)
@@ -277,6 +277,7 @@ prcwd()
prs_buff(cwdname);
}
void
cwdprint()
{
prcwd();

View File

@@ -6,16 +6,19 @@
#include "defs.h"
#include <errno.h>
#include <sys/wait.h>
#include <fcntl.h>
#define ARGMK 01
extern char *sysmsg[];
extern short topfd;
void gocsh(char **t, char *cp, char **xecenv);
/*
* service routines for `execute'
*/
int
initio(iop, save)
struct ionod *iop;
int save;
@@ -106,12 +109,12 @@ getpath(s)
{
register char *path;
if (any('/', s) || any(('/' | QUOTE), s))
if (any('/', s) || any(('/' | (char)QUOTE), s))
{
if (flags & rshflg)
if (flags & rshflg) {
failed(s, restricted);
else
return(nullstr);
}
return(nullstr);
}
else if ((path = pathnod.namval) == NIL)
return(defpath);
@@ -119,6 +122,7 @@ getpath(s)
return(cpystak(path));
}
int
pathopen(path, name)
register char *path, *name;
{
@@ -204,12 +208,12 @@ register char *t[];
* else sh
*/
char s[2];
if( !isatty(input)){
if (!isatty(input)) {
s[1] = 0; s[0] = 0;
read ( input, s, 2 );
if( s[0] == '#' && s[1] != '!' )
gocsh( t, p, xecenv );
lseek( input, (long)0, 0 );
read(input, s, 2);
if (s[0] == '#' && s[1] != '!')
gocsh(t, p, xecenv);
lseek(input, (long)0, 0);
}
}
@@ -240,9 +244,8 @@ register char *t[];
}
}
int execa(at, pos)
char *at[];
short pos;
void
execa(char *at[], short pos)
{
register char *path;
register char **t = at;
@@ -265,25 +268,26 @@ int execa(at, pos)
execs(path, t);
path = getpath(*t);
}
while (path = execs(path,t))
while ((path = execs(path,t)))
;
failed(*t, xecmsg);
}
}
gocsh( t, cp, xecenv )
void
gocsh(t, cp, xecenv)
register char **t, *cp, **xecenv;
{
char *newt[ 1000 ];
register char **p;
register int i;
for( i=0; t[i] ; i++ )
newt[ i+1 ] = t[ i ];
newt[ i+1 ] = NIL;
newt[ 0 ] = "/bin/csh";
newt[ 1 ] = cp;
execve( "/bin/csh", newt, xecenv );
for (i=0; t[i]; i++)
newt[i+1] = t[i];
newt[i+1] = NIL;
newt[0] = "/bin/csh";
newt[1] = cp;
execve("/bin/csh", newt, xecenv);
exit(33);
}
@@ -294,6 +298,7 @@ gocsh( t, cp, xecenv )
static int pwlist[MAXP];
static int pwc;
void
postclr()
{
register int *pw = pwlist;
@@ -303,6 +308,7 @@ postclr()
pwc = 0;
}
void
post(pcsid)
int pcsid;
{
@@ -320,6 +326,7 @@ int pcsid;
}
}
void
await(i, bckg)
int i, bckg;
{
@@ -376,7 +383,7 @@ int i, bckg;
continue;
}
w_hi = w.w_retcode;
if (sig = w.w_termsig)
if ((sig = w.w_termsig))
{
if (sig == 0177) /* ptrace! return */
{
@@ -414,6 +421,7 @@ int i, bckg;
BOOL nosubst;
void
trim(at)
char *at;
{
@@ -422,13 +430,13 @@ char *at;
register char c;
register char q = 0;
if (p = at)
if ((p = at))
{
ptr = p;
while (c = *p++)
while ((c = *p++))
{
/* @@@ if (*ptr = c & STRIP) */
if( *ptr = smask(c))
if ((*ptr = smask(c)))
++ptr;
q |= c;
}
@@ -449,7 +457,7 @@ char *s;
return(t);
}
static int
static void
gsort(from, to)
char *from[], *to[];
{
@@ -553,7 +561,7 @@ register char *s;
count += c;
else
{
makearg(argp);
makearg((struct argnod *) argp);
count++;
}
gchain = (struct argnod *)((int)gchain | ARGMK);
@@ -563,6 +571,7 @@ register char *s;
/*
* Argument list generation
*/
int
getarg(ac)
struct comnod *ac;
{
@@ -570,7 +579,7 @@ struct comnod *ac;
register int count = 0;
register struct comnod *c;
if (c = ac)
if ((c = ac))
{
argp = c->comarg;
while (argp)
@@ -590,7 +599,6 @@ struct comnod *ac;
struct acct sabuf;
struct tms buffer;
extern long times();
static long before;
static int shaccton; /* 0 implies do not write record on exit
1 implies write acct record on exit
@@ -600,12 +608,13 @@ static int shaccton; /* 0 implies do not write record on exit
/*
* suspend accounting until turned on by preacct()
*/
void
suspacct()
{
shaccton = 0;
}
void
preacct(cmdadr)
char *cmdadr;
{
@@ -622,8 +631,8 @@ preacct(cmdadr)
}
}
#include <fcntl.h>
#include <fcntl.h>
void
doacct()
{
int fd;
@@ -648,7 +657,7 @@ doacct()
* Produce a pseudo-floating point representation
* with 3 bits base-8 exponent, 13 bits fraction
*/
int
compress(t)
register time_t t;
{

View File

@@ -11,17 +11,16 @@ char *
movstr(a, b)
register char *a, *b;
{
while (*b++ = *a++);
while ((*b++ = *a++));
return(--b);
}
any(c, s)
register char c;
char *s;
int
any(char c, char *s)
{
register char d;
while (d = *s++)
while ((d = *s++))
{
if (d == c)
return(TRUE);
@@ -29,6 +28,7 @@ char *s;
return(FALSE);
}
int
cf(s1, s2)
register char *s1, *s2;
{
@@ -38,12 +38,13 @@ register char *s1, *s2;
return *--s1 - *s2;
}
int
length(as)
char *as;
{
register char *s;
if (s = as)
if ((s = as))
while (*s++);
return(s - as);
}

View File

@@ -9,6 +9,17 @@
int ap, ac;
char **av;
int exp0(void);
int e1(void);
int e2(void);
int e3(void);
int tio(char *a, int f);
int filtyp(char *f, int field);
int ftype(char *f, int field);
int fsizep(char *f);
void bfailed(char *s1, char *s2, char *s3);
int
test(argn, com)
char *com[];
int argn;
@@ -42,6 +53,7 @@ nxtarg(mt)
return(av[ap++]);
}
int
exp0()
{
int p1;
@@ -61,6 +73,7 @@ exp0()
return(p1);
}
int
e1()
{
int p1;
@@ -75,6 +88,7 @@ e1()
return(p1);
}
int
e2()
{
if (eq(nxtarg(0), "!"))
@@ -83,6 +97,7 @@ e2()
return(e3());
}
int
e3()
{
int p1;
@@ -125,7 +140,7 @@ e3()
return(ftype(nxtarg(0), S_ISVTX));
if (eq(a, "-p"))
return(filtyp(nxtarg(0),S_IFIFO));
if (eq(a, "-s"))
if (eq(a, "-s"))
return(fsizep(nxtarg(0)));
if (eq(a, "-t"))
{
@@ -173,9 +188,11 @@ e3()
return(int1 <= int2);
bfailed(btest, badop, p2);
/* NOTREACHED */
/* NOTREACHED */
return 0;
}
int
tio(a, f)
char *a;
int f;
@@ -186,6 +203,7 @@ int f;
return(0);
}
int
ftype(f, field)
char *f;
int field;
@@ -199,6 +217,7 @@ int field;
return(0);
}
int
filtyp(f,field)
char *f;
int field;
@@ -213,8 +232,7 @@ int field;
return(0);
}
int
fsizep(f)
char *f;
{
@@ -229,6 +247,7 @@ char *f;
* fake diagnostics to continue to look like original
* test(1) diagnostics
*/
void
bfailed(s1, s2, s3)
char *s1;
char *s2;

View File

@@ -1,32 +0,0 @@
#include <stdio.h>
#include <varargs.h>
#include <sys/fcntl.h>
#include "dup.h"
/* Debugging routines */
#define TRACEF "/usr/abs/sh/trace"
static int fp = (-1);
unsigned was_traced = 0;
trace( fmt, va_alist )
char *fmt;
va_dcl
{
va_list args;
char buf[256];
if( fp < 0){
fp = creat( TRACEF, 0644 );
if( fp < 0 ) exit(13);
fcntl( fp, F_SETFD, EXCLOSE );
}
va_start( args );
/* vsprintf( buf, fmt, args ); */
strcpy( buf, fmt );
write( fp, buf, strlen(buf));
va_end( args );
was_traced++;
}

View File

@@ -6,8 +6,12 @@
#include "defs.h"
#include "sym.h"
/* ======== character handling for command lines ========*/
char cj;
int readb(void);
/* ======== character handling for command lines ========*/
int
word()
{
register char c, d;
@@ -122,6 +126,7 @@ word()
return(wdval);
}
int
skipc()
{
register char c;
@@ -131,8 +136,8 @@ skipc()
return(c);
}
nextc(quote)
char quote;
int
nextc(char quote)
{
register char c, d;
@@ -153,6 +158,7 @@ retry:
return(d);
}
int
readc()
{
register char c;
@@ -211,6 +217,7 @@ retry:
return(c);
}
int
readb()
{
register struct fileblk *f = standin;

View File

@@ -5,13 +5,17 @@
*/
#include "defs.h"
#include <errno.h>
#include <sys/times.h>
#include <sys/stat.h>
#include "sym.h"
#include "hash.h"
static int parent;
/* ======== command execution ========*/
static void execprint(char **com);
/* ======== command execution ========*/
int
execute(argt, exec_link, errorflg, pf1, pf2)
struct trenod *argt;
int *pf1, *pf2;
@@ -85,7 +89,7 @@ int *pf1, *pf2;
exitval = 0;
gchain = NIL;
argn = getarg(t);
argn = getarg((struct comnod *) t);
com = scan(argn);
a1 = com[1];
gchain = schain;
@@ -142,18 +146,18 @@ int *pf1, *pf2;
if ((f = pathopen(getpath(a1), a1)) < 0)
failed(a1, notfound);
else
execexp(NIL, f);
execexp(NIL, (void *) f);
}
break;
case SYSTIMES:
{
long int t[4];
struct tms t;
times(t);
prt(t[2]);
times(&t);
prt(t.tms_cutime); /* user time, children */
prc_buff(SP);
prt(t[3]);
prt(t.tms_cstime); /* system time, children */
prc_buff(NL);
}
break;
@@ -842,9 +846,10 @@ int *pf1, *pf2;
return(exitval);
}
void
execexp(s, f)
char *s;
int f;
char *s;
void *f;
{
struct fileblk fb;
@@ -852,14 +857,15 @@ int f;
if (s)
{
estabf(s);
fb.feval = (char **)(f);
fb.feval = (char **) f;
}
else if (f >= 0)
initf(f);
execute(cmd(NL, NLFLG | MTFLG), 0, (int)(flags & errflg));
initf((int) f);
execute(cmd(NL, NLFLG | MTFLG), 0, (int)(flags & errflg), NULL, NULL);
pop();
}
static void
execprint(com)
char **com;
{

View File

@@ -15,3 +15,5 @@ struct tms {
time_t tms_cutime; /* user time, children */
time_t tms_cstime; /* system time, children */
};
int times(struct tms *buf);