From: Alan Cox Date: Sun, 10 May 2015 21:38:21 +0000 (+0100) Subject: sh: ident the code so it turns back into C X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=9919c1da0f4324f5caac6b78e9e5bc8c539c1361;p=FUZIX.git sh: ident the code so it turns back into C --- diff --git a/Applications/V7/cmd/sh/args.c b/Applications/V7/cmd/sh/args.c index c6a90cc6..78488985 100644 --- a/Applications/V7/cmd/sh/args.c +++ b/Applications/V7/cmd/sh/args.c @@ -14,127 +14,149 @@ #include "defs.h" static STRING *copyargs(); -static DOLPTR dolh; +static DOLPTR dolh; -CHAR flagadr[10]; +CHAR flagadr[10]; -CHAR flagchar[] = { - 'x', 'n', 'v', 't', 's', 'i', 'e', 'r', 'k', 'u', 0 +CHAR flagchar[] = { + 'x', 'n', 'v', 't', 's', 'i', 'e', 'r', 'k', 'u', 0 }; -INT flagval[] = { - execpr, noexec, readpr, oneflg, stdflg, intflg, errflg, rshflg, keyflg, setflg, 0 + +INT flagval[] = { + execpr, noexec, readpr, oneflg, stdflg, intflg, errflg, rshflg, + keyflg, setflg, 0 }; /* ======== option handling ======== */ -INT options(argc,argv) - STRING *argv; - INT argc; +INT options(argc, argv) +STRING *argv; +INT argc; { - register STRING cp; - register STRING *argp=argv; - register STRING flagc; - STRING flagp; - - if (argc>1 && *argp[1]=='-' - ) { cp=argp[1]; - flags &= ~(execpr|readpr); - while(*++cp - ){flagc=flagchar; - - while(*flagc && *flagc != *cp ){flagc++ ;} - if (*cp == *flagc - ) { flags |= flagval[flagc-flagchar]; - } else if (*cp=='c' && argc>2 && comdiv==0 - ) { comdiv=argp[2]; - argp[1]=argp[0]; argp++; argc--; - } else { failed(argv[1],badopt); - ;} - ;} - argp[1]=argp[0]; argc--; - ;} + register STRING cp; + register STRING *argp = argv; + register STRING flagc; + STRING flagp; + + if (argc > 1 && *argp[1] == '-') { + cp = argp[1]; + flags &= ~(execpr | readpr); + while (*++cp) { + flagc = flagchar; + + while (*flagc && *flagc != *cp) { + flagc++; + } + if (*cp == *flagc) { + flags |= flagval[flagc - flagchar]; + } else if (*cp == 'c' && argc > 2 && comdiv == 0) { + comdiv = argp[2]; + argp[1] = argp[0]; + argp++; + argc--; + } else { + failed(argv[1], badopt); + ; + } + ; + } + argp[1] = argp[0]; + argc--; + ; + } /* set up $- */ - flagc=flagchar; - flagp=flagadr; - while(*flagc - ){if (flags&flagval[flagc-flagchar] - ) { *flagp++ = *flagc; - ;} - flagc++; - ;} - *flagp++=0; - - return(argc); + flagc = flagchar; + flagp = flagadr; + while (*flagc) { + if (flags & flagval[flagc - flagchar] + ) { + *flagp++ = *flagc; + ; + } + flagc++; + ; + } + *flagp++ = 0; + + return (argc); } -void setargs(argi) - STRING argi[]; +void setargs(argi) +STRING argi[]; { /* count args */ - register STRING *argp=argi; - register INT argn=0; + register STRING *argp = argi; + register INT argn = 0; - while(Rcheat(*argp++)!=ENDARGS ){argn++ ;} + while (Rcheat(*argp++) != ENDARGS) { + argn++; + } /* free old ones unless on for loop chain */ freeargs(dolh); - dolh=(DOLPTR)copyargs(argi,argn); /* sets dolv */ - assnum(&dolladr,dolc=argn-1); + dolh = (DOLPTR) copyargs(argi, argn); /* sets dolv */ + assnum(&dolladr, dolc = argn - 1); } -DOLPTR -freeargs(blk) - DOLPTR blk; +DOLPTR freeargs(blk) +DOLPTR blk; { - register STRING *argp; - register DOLPTR argr=0; - register DOLPTR argblk; - - if (argblk=blk - ) { argr = argblk->dolnxt; - if ((--argblk->doluse)==0 - ) { for ( argp=(STRING *)argblk->dolarg; Rcheat(*argp)!=ENDARGS; argp++ - ){free(*argp) ;} + register STRING *argp; + register DOLPTR argr = 0; + register DOLPTR argblk; + + if (argblk = blk) { + argr = argblk->dolnxt; + if ((--argblk->doluse) == 0) { + for (argp = (STRING *) argblk->dolarg; + Rcheat(*argp) != ENDARGS; argp++) { + free(*argp); + } free(argblk); - ;} - ;} - return(argr); + ; + }; + } + return (argr); } -static STRING * copyargs(from, n) - STRING from[]; +static STRING *copyargs(from, n) +STRING from[]; { - register STRING * np=(STRING *)alloc(sizeof(STRING*)*n+3*BYTESPERWORD); - register STRING * fp=from; - register STRING * pp=np; - - ((DOLPTR)np)->doluse=1; /* use count */ - np=(STRING *)((DOLPTR)np)->dolarg; - dolv=np; - - while(n-- - ){*np++ = make(*fp++) ;} + register STRING *np = + (STRING *) alloc(sizeof(STRING *) * n + 3 * BYTESPERWORD); + register STRING *fp = from; + register STRING *pp = np; + + ((DOLPTR) np)->doluse = 1; /* use count */ + np = (STRING *) ((DOLPTR) np)->dolarg; + dolv = np; + + while (n--) { + *np++ = make(*fp++); + } *np++ = ENDARGS; - return(pp); + return (pp); } clearup() { /* force `for' $* lists to go away */ - while(argfor=freeargs(argfor) ); + while (argfor = freeargs(argfor)); /* clean up io files */ - while(pop() ); + while (pop()); } -DOLPTR useargs() +DOLPTR useargs() { - if (dolh - ) { dolh->doluse++; - dolh->dolnxt=argfor; - return(argfor=dolh); - } else { return(0); - ;} + if (dolh) { + dolh->doluse++; + dolh->dolnxt = argfor; + return (argfor = dolh); + } else { + return (0); + ; + } } diff --git a/Applications/V7/cmd/sh/blok.c b/Applications/V7/cmd/sh/blok.c index 34a86414..237186e9 100644 --- a/Applications/V7/cmd/sh/blok.c +++ b/Applications/V7/cmd/sh/blok.c @@ -21,59 +21,71 @@ #define BUSY 01 #define busy(x) (Rcheat((x)->word)&BUSY) -POS brkincr=BRKINCR; -BLKPTR blokp; /*current search pointer*/ -BLKPTR bloktop=BLK(end); /*top of arena (last blok)*/ +POS brkincr = BRKINCR; +BLKPTR blokp; /*current search pointer */ +BLKPTR bloktop = BLK(end); /*top of arena (last blok) */ -ADDRESS alloc(nbytes) - POS nbytes; +ADDRESS alloc(nbytes) +POS nbytes; { - register POS rbytes = round(nbytes+BYTESPERWORD,BYTESPERWORD); - - for (;;) { INT c=0; - register BLKPTR p = blokp; - register BLKPTR q; - do { if(!busy(p) - ) { while(!busy(q = p->word) ){p->word = q->word ;} - if(ADR(q)-ADR(p) >= rbytes - ) { blokp = BLK(ADR(p)+rbytes); - if(q > blokp - ) { blokp->word = p->word; - ;} - p->word=BLK(Rcheat(blokp)|BUSY); - return(ADR(p+1)); - ;} - ;} - q = p; p = BLK(Rcheat(p->word)&~BUSY); - } while ( p>q || (c++)==0 ); + register POS rbytes = round(nbytes + BYTESPERWORD, BYTESPERWORD); + + for (;;) { + INT c = 0; + register BLKPTR p = blokp; + register BLKPTR q; + do { + if (!busy(p) + ) { + while (!busy(q = p->word)) { + p->word = q->word; + } + if (ADR(q) - ADR(p) >= rbytes) { + blokp = BLK(ADR(p) + rbytes); + if (q > blokp) { + blokp->word = p->word; + ; + } + p->word = + BLK(Rcheat(blokp) | BUSY); + return (ADR(p + 1)); + ; + }; + } + q = p; + p = BLK(Rcheat(p->word) & ~BUSY); + } while (p > q || (c++) == 0); addblok(rbytes); } } -void addblok(reqd) - POS reqd; +void addblok(reqd) +POS reqd; { - if(stakbas!=staktop - ) { register STKPTR rndstak; - register BLKPTR blokstak; + if (stakbas != staktop) { + register STKPTR rndstak; + register BLKPTR blokstak; pushstak(0); - rndstak=(STKPTR)round(staktop,BYTESPERWORD); - blokstak=BLK(stakbas)-1; - blokstak->word=stakbsy; stakbsy=blokstak; - bloktop->word=BLK(Rcheat(rndstak)|BUSY); - bloktop=BLK(rndstak); - ;} - reqd += brkincr; reqd &= ~(brkincr-1); - blokp=bloktop; - bloktop=bloktop->word=BLK(Rcheat(bloktop)+reqd); - bloktop->word=BLK(ADR(end)+1); + rndstak = (STKPTR) round(staktop, BYTESPERWORD); + blokstak = BLK(stakbas) - 1; + blokstak->word = stakbsy; + stakbsy = blokstak; + bloktop->word = BLK(Rcheat(rndstak) | BUSY); + bloktop = BLK(rndstak); + ; + } + reqd += brkincr; + reqd &= ~(brkincr - 1); + blokp = bloktop; + bloktop = bloktop->word = BLK(Rcheat(bloktop) + reqd); + bloktop->word = BLK(ADR(end) + 1); { - register STKPTR stakadr=STK(bloktop+2); - staktop=movstr(stakbot,stakadr); - stakbas=stakbot=stakadr; + register STKPTR stakadr = STK(bloktop + 2); + staktop = movstr(stakbot, stakadr); + stakbas = stakbot = stakadr; } } @@ -81,33 +93,50 @@ void free(void *ap) { BLKPTR p; - if((p=ap) && pword) &= ~BUSY; - ;} + if ((p = ap) && p < bloktop) { + Lcheat((--p)->word) &= ~BUSY; + ; + } } #ifdef DEBUG chkbptr(ptr) - BLKPTR ptr; +BLKPTR ptr; { - INT exf=0; - register BLKPTR p = end; - register BLKPTR q; - INT us=0, un=0; + INT exf = 0; + register BLKPTR p = end; + register BLKPTR q; + INT us = 0, un = 0; for (;;) { - q = Rcheat(p->word)&~BUSY; - if(p==ptr ) { exf++ ;} - if(qbloktop ) { abort(3) ;} - if(p==bloktop ) { break ;} - if(busy(p) - ) { us += q-p; - } else { un += q-p; - ;} - if(p>=q ) { abort(4) ;} - p=q; + q = Rcheat(p->word) & ~BUSY; + if (p == ptr) { + exf++; + } + if (q < end || q > bloktop) { + abort(3); + } + if (p == bloktop) { + break; + } + if (busy(p) + ) { + us += q - p; + } else { + un += q - p; + ; + } + if (p >= q) { + abort(4); + } + p = q; + } + if (exf == 0) { + abort(1); } - if(exf==0 ) { abort(1) ;} - prn(un); prc(SP); prn(us); prc(NL); + prn(un); + prc(SP); + prn(us); + prc(NL); } #endif diff --git a/Applications/V7/cmd/sh/builtin.c b/Applications/V7/cmd/sh/builtin.c index 50aca079..47de3efe 100644 --- a/Applications/V7/cmd/sh/builtin.c +++ b/Applications/V7/cmd/sh/builtin.c @@ -1,4 +1,6 @@ /* UNIX V7 source code: see /COPYRIGHT or www.tuhs.org for details. */ builtin() -{return(0);} +{ + return (0); +} diff --git a/Applications/V7/cmd/sh/cmd.c b/Applications/V7/cmd/sh/cmd.c index d49983a7..a31b4edb 100644 --- a/Applications/V7/cmd/sh/cmd.c +++ b/Applications/V7/cmd/sh/cmd.c @@ -13,17 +13,17 @@ #include "defs.h" #include "sym.h" -static IOPTR inout(); -static void chkword(); -static void chksym(); -static TREPTR term(); -static TREPTR makelist(); -static TREPTR list(); -static REGPTR syncase(); -static TREPTR item(); -static int skipnl(); -static void prsym(); -static void synbad(); +static IOPTR inout(); +static void chkword(); +static void chksym(); +static TREPTR term(); +static TREPTR makelist(); +static TREPTR list(); +static REGPTR syncase(); +static TREPTR item(); +static int skipnl(); +static void prsym(); +static void synbad(); /* ======== command line decoding ========*/ @@ -31,32 +31,35 @@ static void synbad(); -TREPTR makefork(flgs, i) - INT flgs; - TREPTR i; +TREPTR makefork(flgs, i) +INT flgs; +TREPTR i; { - register FORKPTR t; + register FORKPTR t; - t=(FORKPTR)getstak(FORKTYPE); - t->forktyp=flgs|TFORK; - t->forktre=i; - t->forkio=0; - return(TREPTR)(t); + t = (FORKPTR) getstak(FORKTYPE); + t->forktyp = flgs | TFORK; + t->forktre = i; + t->forkio = 0; + return (TREPTR) (t); } -static TREPTR makelist(type,i,r) - INT type; - TREPTR i, r; +static TREPTR makelist(type, i, r) +INT type; +TREPTR i, r; { - register LSTPTR t; + register LSTPTR t; - if (i==0 || r==0 - ) { synbad(); - } else { t = (LSTPTR)getstak(LSTTYPE); + if (i == 0 || r == 0) { + synbad(); + } else { + t = (LSTPTR) getstak(LSTTYPE); t->lsttyp = type; - t->lstlef = i; t->lstrit = r; - ;} - return(TREPTR)(t); + t->lstlef = i; + t->lstrit = r; + ; + } + return (TREPTR) (t); } /* @@ -67,48 +70,57 @@ static TREPTR makelist(type,i,r) * list [ ; cmd ] */ -TREPTR cmd(sym,flg) - register INT sym; - INT flg; +TREPTR cmd(sym, flg) +register INT sym; +INT flg; { - register TREPTR i, e; + register TREPTR i, e; i = list(flg); - if (wdval==NL - ) { if (flg&NLFLG - ) { wdval=';'; chkpr(NL); - ;} - } else if ( i==0 && (flg&MTFLG)==0 - ) { synbad(); - ;} - - switch(wdval) { - - case '&': - if (i - ) { i = makefork(FINT|FPRS|FAMP, i); - } else { synbad(); - ;} - - case ';': - if (e=cmd(sym,flg|MTFLG) - ) { i=makelist(TLST, i, e); - ;} + if (wdval == NL) { + if (flg & NLFLG) { + wdval = ';'; + chkpr(NL); + ; + } + } else if (i == 0 && (flg & MTFLG) == 0) { + synbad(); + ; + } + + switch (wdval) { + + case '&': + if (i) { + i = makefork(FINT | FPRS | FAMP, i); + } else { + synbad(); + ; + } + + case ';': + if (e = cmd(sym, flg | MTFLG) + ) { + i = makelist(TLST, i, e); + ; + } break; - case EOFSYM: - if (sym==NL - ) { break; - ;} + case EOFSYM: + if (sym == NL) { + break; + ; + } - default: - if (sym - ) { chksym(sym); - ;} + default: + if (sym) { + chksym(sym); + ; + } } - return(i); + return (i); } /* @@ -118,16 +130,18 @@ TREPTR cmd(sym,flg) * list || term */ -static TREPTR list(flg) +static TREPTR list(flg) { - register TREPTR r; - register INT b; + register TREPTR r; + register INT b; r = term(flg); - while(r && ((b=(wdval==ANDFSYM)) || wdval==ORFSYM) - ){r = makelist((b ? TAND : TORF), r, term(NLFLG)); - ;} - return(r); + while (r && ((b = (wdval == ANDFSYM)) || wdval == ORFSYM) + ) { + r = makelist((b ? TAND : TORF), r, term(NLFLG)); + ; + } + return (r); } /* @@ -136,49 +150,64 @@ static TREPTR list(flg) * item |^ term */ -static TREPTR term(flg) +static TREPTR term(flg) { - register TREPTR t; + register TREPTR t; reserv++; - if (flg&NLFLG - ) { skipnl(); - } else { word(); - ;} - - if ((t=item(TRUE)) && (wdval=='^' || wdval=='|') - ) { return(makelist(TFIL, makefork(FPOU,t), makefork(FPIN|FPCL,term(NLFLG)))); - } else { return(t); - ;} + if (flg & NLFLG) { + skipnl(); + } else { + word(); + ; + } + + if ((t = item(TRUE)) && (wdval == '^' || wdval == '|') + ) { + return (makelist + (TFIL, makefork(FPOU, t), + makefork(FPIN | FPCL, term(NLFLG)))); + } else { + return (t); + ; + } } -static REGPTR syncase(esym) - register INT esym; +static REGPTR syncase(esym) +register INT esym; { skipnl(); - if (wdval==esym - ) { return(0); - } else { register REGPTR r=(REGPTR)getstak(REGTYPE); - r->regptr=0; - for(;;) { - wdarg->argnxt=r->regptr; - r->regptr=wdarg; - if (wdval || ( word()!=')' && wdval!='|' ) - ) { synbad(); - ;} - if (wdval=='|' - ) { word(); - } else { break; - ;} + if (wdval == esym) { + return (0); + } else { + register REGPTR r = (REGPTR) getstak(REGTYPE); + r->regptr = 0; + for (;;) { + wdarg->argnxt = r->regptr; + r->regptr = wdarg; + if (wdval || (word() != ')' && wdval != '|') + ) { + synbad(); + ; + } + if (wdval == '|') { + word(); + } else { + break; + ; + } } - r->regcom=cmd(0,NLFLG|MTFLG); - if (wdval==ECSYM - ) { r->regnxt=syncase(esym); - } else { chksym(esym); - r->regnxt=0; - ;} - return(r); - ;} + r->regcom = cmd(0, NLFLG | MTFLG); + if (wdval == ECSYM) { + r->regnxt = syncase(esym); + } else { + chksym(esym); + r->regnxt = 0; + ; + } + return (r); + ; + } } /* @@ -192,226 +221,283 @@ static REGPTR syncase(esym) * begin ... end */ -static TREPTR item(flag) - BOOL flag; +static TREPTR item(flag) +BOOL flag; { - register TREPTR t; - register IOPTR io; - - if (flag - ) { io=inout((IOPTR)0); - } else { io=0; - ;} + register TREPTR t; + register IOPTR io; + + if (flag) { + io = inout((IOPTR) 0); + } else { + io = 0; + ; + } - switch(wdval) { + switch (wdval) { - case CASYM: + case CASYM: { - t=(TREPTR)getstak(SWTYPE); - chkword(); - ((SWPTR)t)->swarg=wdarg->argval; - skipnl(); chksym(INSYM|BRSYM); - ((SWPTR)t)->swlst=syncase(wdval==INSYM?ESSYM:KTSYM); - ((SWPTR)t)->swtyp=TSW; - break; + t = (TREPTR) getstak(SWTYPE); + chkword(); + ((SWPTR) t)->swarg = wdarg->argval; + skipnl(); + chksym(INSYM | BRSYM); + ((SWPTR) t)->swlst = + syncase(wdval == INSYM ? ESSYM : KTSYM); + ((SWPTR) t)->swtyp = TSW; + break; } - case IFSYM: + case IFSYM: { - register INT w; - t=(TREPTR)getstak(IFTYPE); - ((IFPTR)t)->iftyp=TIF; - ((IFPTR)t)->iftre=cmd(THSYM,NLFLG); - ((IFPTR)t)->thtre=cmd(ELSYM|FISYM|EFSYM,NLFLG); - ((IFPTR)t)->eltre=((w=wdval)==ELSYM ? cmd(FISYM,NLFLG) : (w==EFSYM ? (wdval=IFSYM, item(0)) : 0)); - if (w==EFSYM ) { return(t) ;} - break; + register INT w; + t = (TREPTR) getstak(IFTYPE); + ((IFPTR) t)->iftyp = TIF; + ((IFPTR) t)->iftre = cmd(THSYM, NLFLG); + ((IFPTR) t)->thtre = + cmd(ELSYM | FISYM | EFSYM, NLFLG); + ((IFPTR) t)->eltre = + ((w = + wdval) == ELSYM ? cmd(FISYM, + NLFLG) : (w == + EFSYM + ? (wdval = + IFSYM, + item(0)) : + 0)); + if (w == EFSYM) { + return (t); + } + break; } - case FORSYM: + case FORSYM: { - t=(TREPTR)getstak(FORTYPE); - ((FORPTR)t)->fortyp=TFOR; - ((FORPTR)t)->forlst=0; - chkword(); - ((FORPTR)t)->fornam=wdarg->argval; - if (skipnl()==INSYM - ) { chkword(); - ((FORPTR)t)->forlst=(COMPTR)item(0); - if (wdval!=NL && wdval!=';' - ) { synbad(); - ;} - chkpr(wdval); skipnl(); - ;} - chksym(DOSYM|BRSYM); - ((FORPTR)t)->fortre=cmd(wdval==DOSYM?ODSYM:KTSYM,NLFLG); - break; + t = (TREPTR) getstak(FORTYPE); + ((FORPTR) t)->fortyp = TFOR; + ((FORPTR) t)->forlst = 0; + chkword(); + ((FORPTR) t)->fornam = wdarg->argval; + if (skipnl() == INSYM) { + chkword(); + ((FORPTR) t)->forlst = (COMPTR) item(0); + if (wdval != NL && wdval != ';') { + synbad(); + ; + } + chkpr(wdval); + skipnl(); + ; + } + chksym(DOSYM | BRSYM); + ((FORPTR) t)->fortre = + cmd(wdval == DOSYM ? ODSYM : KTSYM, NLFLG); + break; } - case WHSYM: - case UNSYM: + case WHSYM: + case UNSYM: { - t=(TREPTR)getstak(WHTYPE); - ((WHPTR)t)->whtyp=(wdval==WHSYM ? TWH : TUN); - ((WHPTR)t)->whtre = cmd(DOSYM,NLFLG); - ((WHPTR)t)->dotre = cmd(ODSYM,NLFLG); - break; + t = (TREPTR) getstak(WHTYPE); + ((WHPTR) t)->whtyp = (wdval == WHSYM ? TWH : TUN); + ((WHPTR) t)->whtre = cmd(DOSYM, NLFLG); + ((WHPTR) t)->dotre = cmd(ODSYM, NLFLG); + break; } - case BRSYM: - t=cmd(KTSYM,NLFLG); + case BRSYM: + t = cmd(KTSYM, NLFLG); break; - case '(': + case '(': { - register PARPTR p; - p=(PARPTR)getstak(PARTYPE); - p->partre=cmd(')',NLFLG); - p->partyp=TPAR; - t=makefork(0,p); - break; + register PARPTR p; + p = (PARPTR) getstak(PARTYPE); + p->partre = cmd(')', NLFLG); + p->partyp = TPAR; + t = makefork(0, p); + break; } - default: - if (io==0 - ) { return(0); - ;} + default: + if (io == 0) { + return (0); + ; + } - case 0: + case 0: { - register ARGPTR argp; - register ARGPTR *argtail; - register ARGPTR *argset=0; - INT keywd=1; - t=(TREPTR)getstak(COMTYPE); - ((COMPTR)t)->comio=io; /*initial io chain*/ - argtail = &(((COMPTR)t)->comarg); - while(wdval==0 - ){argp = wdarg; - if (wdset && keywd - ) { argp->argnxt=(ARGPTR)argset; - argset=(ARGPTR *)argp; - } else { *argtail=argp; argtail = &(argp->argnxt); keywd=flags&keyflg; - ;} - word(); - if (flag - ) { ((COMPTR)t)->comio=inout(((COMPTR)t)->comio); - ;} - ;} - - ((COMPTR)t)->comtyp=TCOM; - ((COMPTR)t)->comset=(ARGPTR)argset; - *argtail=0; - return(t); + register ARGPTR argp; + register ARGPTR *argtail; + register ARGPTR *argset = 0; + INT keywd = 1; + t = (TREPTR) getstak(COMTYPE); + ((COMPTR) t)->comio = io; /*initial io chain */ + argtail = &(((COMPTR) t)->comarg); + while (wdval == 0) { + argp = wdarg; + if (wdset && keywd) { + argp->argnxt = (ARGPTR) argset; + argset = (ARGPTR *) argp; + } else { + *argtail = argp; + argtail = &(argp->argnxt); + keywd = flags & keyflg; + ; + } + word(); + if (flag) { + ((COMPTR) t)->comio = + inout(((COMPTR) t)->comio); + ; + }; + } + + ((COMPTR) t)->comtyp = TCOM; + ((COMPTR) t)->comset = (ARGPTR) argset; + *argtail = 0; + return (t); } } - reserv++; word(); - if (io=inout(io) - ) { t=makefork(0,t); t->treio=io; - ;} - return(t); + reserv++; + word(); + if (io = inout(io) + ) { + t = makefork(0, t); + t->treio = io; + ; + } + return (t); } -static int skipnl() +static int skipnl() { - while((reserv++, word()==NL) ){chkpr(NL) ;} - return(wdval); + while ((reserv++, word() == NL)) { + chkpr(NL); + } + return (wdval); } -static IOPTR inout(lastio) - IOPTR lastio; +static IOPTR inout(lastio) +IOPTR lastio; { - register INT iof; - register IOPTR iop; - register CHAR c; + register INT iof; + register IOPTR iop; + register CHAR c; - iof=wdnum; + iof = wdnum; - switch(wdval) { + switch (wdval) { - case DOCSYM: - iof |= IODOC; break; + case DOCSYM: + iof |= IODOC; + break; - case APPSYM: - case '>': - if (wdnum==0 ) { iof |= 1 ;} + case APPSYM: + case '>': + if (wdnum == 0) { + iof |= 1; + } iof |= IOPUT; - if (wdval==APPSYM - ) { iof |= IOAPP; break; - ;} - - case '<': - if ((c=nextc(0))=='&' - ) { iof |= IOMOV; - } else if ( c=='>' - ) { iof |= IORDW; - } else { peekc=c|MARK; - ;} + if (wdval == APPSYM) { + iof |= IOAPP; + break; + ; + } + + case '<': + if ((c = nextc(0)) == '&') { + iof |= IOMOV; + } else if (c == '>') { + iof |= IORDW; + } else { + peekc = c | MARK; + ; + } break; - default: - return(lastio); + default: + return (lastio); } chkword(); - iop=(IOPTR)getstak(IOTYPE); - iop->ioname=wdarg->argval; - iop->iofile=iof; - if (iof&IODOC - ) { iop->iolst=iopend; iopend=iop; - ;} - word(); iop->ionxt=inout(lastio); - return(iop); + iop = (IOPTR) getstak(IOTYPE); + iop->ioname = wdarg->argval; + iop->iofile = iof; + if (iof & IODOC) { + iop->iolst = iopend; + iopend = iop; + ; + } + word(); + iop->ionxt = inout(lastio); + return (iop); } -static void chkword() +static void chkword() { if (word() - ) { synbad(); - ;} + ) { + synbad(); + ; + } } -static void chksym(sym) +static void chksym(sym) { - register INT x = sym&wdval; - if (((x&SYMFLG) ? x : sym) != wdval - ) { synbad(); - ;} + register INT x = sym & wdval; + if (((x & SYMFLG) ? x : sym) != wdval) { + synbad(); + ; + } } -static void prsym(sym) +static void prsym(sym) { - if (sym&SYMFLG - ) { register SYSPTR sp=reserved; - while(sp->sysval - && sp->sysval!=sym - ){sp++ ;} + if (sym & SYMFLG) { + register SYSPTR sp = reserved; + while (sp->sysval && sp->sysval != sym) { + sp++; + } prs(sp->sysnam); - } else if ( sym==EOFSYM - ) { prs(endoffile); - } else { if (sym&SYMREP ) { prc(sym) ;} - if (sym==NL - ) { prs("newline"); - } else { prc(sym); - ;} - ;} + } else if (sym == EOFSYM) { + prs(endoffile); + } else { + if (sym & SYMREP) { + prc(sym); + } + if (sym == NL) { + prs("newline"); + } else { + prc(sym); + ; + } + ; + } } -static void synbad() +static void synbad() { - prp(); prs(synmsg); - if ((flags&ttyflg)==0 - ) { prs(atline); prn(standin->flin); - ;} + prp(); + prs(synmsg); + if ((flags & ttyflg) == 0) { + prs(atline); + prn(standin->flin); + ; + } prs(colon); prc(LQ); - if (wdval - ) { prsym(wdval); - } else { prs(wdarg->argval); - ;} - prc(RQ); prs(unexpected); + if (wdval) { + prsym(wdval); + } else { + prs(wdarg->argval); + ; + } + prc(RQ); + prs(unexpected); newline(); exitsh(SYNBAD); } diff --git a/Applications/V7/cmd/sh/ctype.c b/Applications/V7/cmd/sh/ctype.c index d7eadc8f..26f59e00 100644 --- a/Applications/V7/cmd/sh/ctype.c +++ b/Applications/V7/cmd/sh/ctype.c @@ -12,100 +12,99 @@ #include "defs.h" -char _ctype1[] = { +char _ctype1[] = { /* 000 001 002 003 004 005 006 007 */ - _EOF, 0, 0, 0, 0, 0, 0, 0, + _EOF, 0, 0, 0, 0, 0, 0, 0, /* bs ht nl vt np cr so si */ - 0, _TAB, _EOR, 0, 0, 0, 0, 0, + 0, _TAB, _EOR, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* sp ! " # $ % & ' */ - _SPC, 0, _DQU, 0, _DOL1, 0, _AMP, 0, + _SPC, 0, _DQU, 0, _DOL1, 0, _AMP, 0, /* ( ) * + , - . / */ - _BRA, _KET, 0, 0, 0, 0, 0, 0, + _BRA, _KET, 0, 0, 0, 0, 0, 0, /* 0 1 2 3 4 5 6 7 */ - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* 8 9 : ; < = > ? */ - 0, 0, 0, _SEM, _LT, 0, _GT, 0, + 0, 0, 0, _SEM, _LT, 0, _GT, 0, /* @ A B C D E F G */ - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* H I J K L M N O */ - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* P Q R S T U V W */ - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* X Y Z [ \ ] ^ _ */ - 0, 0, 0, 0, _BSL, 0, _HAT, 0, + 0, 0, 0, 0, _BSL, 0, _HAT, 0, /* ` a b c d e f g */ - _LQU, 0, 0, 0, 0, 0, 0, 0, + _LQU, 0, 0, 0, 0, 0, 0, 0, /* h i j k l m n o */ - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* p q r s t u v w */ - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* x y z { | } ~ del */ - 0, 0, 0, 0, _BAR, 0, 0, 0 + 0, 0, 0, 0, _BAR, 0, 0, 0 }; -char _ctype2[] = { +char _ctype2[] = { /* 000 001 002 003 004 005 006 007 */ - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* bs ht nl vt np cr so si */ - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* sp ! " # $ % & ' */ - 0, _PCS, 0, _NUM, _DOL2, 0, 0, 0, + 0, _PCS, 0, _NUM, _DOL2, 0, 0, 0, /* ( ) * + , - . / */ - 0, 0, _AST, _PLS, 0, _MIN, 0, 0, + 0, 0, _AST, _PLS, 0, _MIN, 0, 0, /* 0 1 2 3 4 5 6 7 */ - _DIG, _DIG, _DIG, _DIG, _DIG, _DIG, _DIG, _DIG, + _DIG, _DIG, _DIG, _DIG, _DIG, _DIG, _DIG, _DIG, /* 8 9 : ; < = > ? */ - _DIG, _DIG, 0, 0, 0, _EQ, 0, _QU, + _DIG, _DIG, 0, 0, 0, _EQ, 0, _QU, /* @ A B C D E F G */ - _AT, _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, + _AT, _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, /* H I J K L M N O */ - _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, + _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, /* P Q R S T U V W */ - _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, + _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, _UPC, /* X Y Z [ \ ] ^ _ */ - _UPC, _UPC, _UPC, _SQB, 0, 0, 0, _UPC, + _UPC, _UPC, _UPC, _SQB, 0, 0, 0, _UPC, /* ` a b c d e f g */ - 0, _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, + 0, _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, /* h i j k l m n o */ - _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, + _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, /* p q r s t u v w */ - _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, + _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, _LPC, /* x y z { | } ~ del */ - _LPC, _LPC, _LPC, _CBR, 0, _CKT, 0, 0 + _LPC, _LPC, _LPC, _CBR, 0, _CKT, 0, 0 }; - diff --git a/Applications/V7/cmd/sh/ctype.h b/Applications/V7/cmd/sh/ctype.h index f295606a..d375a31b 100644 --- a/Applications/V7/cmd/sh/ctype.h +++ b/Applications/V7/cmd/sh/ctype.h @@ -68,7 +68,7 @@ #define _IDCH (T_IDC|T_DIG) #define _META (T_SPC|T_DIP|T_MET|T_EOR) -extern char _ctype1[]; +extern char _ctype1[]; /* nb these args are not call by value !!!! */ #define space(c) (((c)"E)==0 && _ctype1[c]&(T_SPC)) @@ -79,7 +79,7 @@ extern char _ctype1[]; #define subchar(c) (((c)"E)==0 && _ctype1[c]&(T_SUB|T_QOT)) #define escchar(c) (((c)"E)==0 && _ctype1[c]&(T_ESC)) -extern char _ctype2[]; +extern char _ctype2[]; #define digit(c) (((c)"E)==0 && _ctype2[c]&(T_DIG)) #define fngchar(c) (((c)"E)==0 && _ctype2[c]&(T_FNG)) diff --git a/Applications/V7/cmd/sh/defs.h b/Applications/V7/cmd/sh/defs.h index a4619535..49ef8185 100644 --- a/Applications/V7/cmd/sh/defs.h +++ b/Applications/V7/cmd/sh/defs.h @@ -89,30 +89,30 @@ extern STRING *sh_setenv(void); #define alloc malloc -ADDRESS alloc(); -void addblok(); -STRING make(); -STRING movstr(); -TREPTR cmd(); -TREPTR makefork(); -NAMPTR lookup(); -void setname(); -void setargs(); -DOLPTR useargs(); -DOLPTR freeargs(); -REAL expr(); -STRING catpath(); -STRING getpath(); -STRING *scan(); -STRING mactrim(); -STRING macro(); -void await(); -void post(); -void exname(); -void printnam(); -void printflg(); -void prs(); -void prc(); +ADDRESS alloc(); +void addblok(); +STRING make(); +STRING movstr(); +TREPTR cmd(); +TREPTR makefork(); +NAMPTR lookup(); +void setname(); +void setargs(); +DOLPTR useargs(); +DOLPTR freeargs(); +REAL expr(); +STRING catpath(); +STRING getpath(); +STRING *scan(); +STRING mactrim(); +STRING macro(); +void await(); +void post(); +void exname(); +void printnam(); +void printflg(); +void prs(); +void prc(); #define attrib(n,f) (n->namflg |= f) #define round(a,b) (((int)((ADR(a)+b)-1))&~((b)-1)) @@ -122,16 +122,16 @@ void prc(); #define assert(x) ; /* temp files and io */ -extern UFD output; -extern INT ioset; -extern IOPTR iotemp; /* files to be deleted sometime */ -extern IOPTR iopend; /* documents waiting to be read at NL */ +extern UFD output; +extern INT ioset; +extern IOPTR iotemp; /* files to be deleted sometime */ +extern IOPTR iopend; /* documents waiting to be read at NL */ /* substitution */ -extern INT dolc; -extern STRING *dolv; -extern DOLPTR argfor; -extern ARGPTR gchain; +extern INT dolc; +extern STRING *dolv; +extern DOLPTR argfor; +extern ARGPTR gchain; /* stack */ #define BLK(x) ((BLKPTR)(x)) @@ -154,12 +154,12 @@ extern const char endoffile[]; extern const char synmsg[]; /* name tree and words */ -extern SYSTAB reserved; -extern INT wdval; -extern INT wdnum; -extern ARGPTR wdarg; -extern INT wdset; -extern BOOL reserv; +extern SYSTAB reserved; +extern INT wdval; +extern INT wdnum; +extern ARGPTR wdarg; +extern INT wdset; +extern BOOL reserv; /* prompting */ extern const char stdprompt[]; @@ -167,21 +167,21 @@ extern const char supprompt[]; extern const char profile[]; /* built in names */ -extern NAMNOD fngnod; -extern NAMNOD ifsnod; -extern NAMNOD homenod; -extern NAMNOD mailnod; -extern NAMNOD pathnod; -extern NAMNOD ps1nod; -extern NAMNOD ps2nod; +extern NAMNOD fngnod; +extern NAMNOD ifsnod; +extern NAMNOD homenod; +extern NAMNOD mailnod; +extern NAMNOD pathnod; +extern NAMNOD ps1nod; +extern NAMNOD ps2nod; /* special names */ extern char flagadr[10]; -extern STRING cmdadr; -extern STRING exitadr; -extern STRING dolladr; -extern STRING pcsadr; -extern STRING pidadr; +extern STRING cmdadr; +extern STRING exitadr; +extern STRING dolladr; +extern STRING pcsadr; +extern STRING pidadr; extern const char defpath[]; @@ -195,15 +195,15 @@ extern const char ps1name[]; extern const char ps2name[]; /* transput */ -extern CHAR tmpout[]; -extern STRING tmpnam; -extern INT serial; +extern CHAR tmpout[]; +extern STRING tmpnam; +extern INT serial; #define TMPNAM 7 -extern FILE standin; +extern FILE standin; #define input (standin->fdes) #define eof (standin->feof) -extern INT peekc; -extern STRING comdiv; +extern INT peekc; +extern STRING comdiv; extern const char devnull[]; /* flags */ @@ -221,16 +221,16 @@ extern const char devnull[]; #define execpr 04000 #define readpr 010000 #define keyflg 020000 -extern INT flags; +extern INT flags; /* error exits from various parts of shell */ #include -extern jmp_buf subshell; -extern jmp_buf errshell; +extern jmp_buf subshell; +extern jmp_buf errshell; /* fault handling */ #include "brkincr.h" -extern POS brkincr; +extern POS brkincr; #define MINTRAP 0 #define MAXTRAP 17 @@ -244,22 +244,22 @@ extern POS brkincr; #define SIGSET 4 #define SIGMOD 8 -void fault(); -extern BOOL trapnote; -extern STRING trapcom[]; -extern BOOL trapflg[]; +void fault(); +extern BOOL trapnote; +extern STRING trapcom[]; +extern BOOL trapflg[]; /* name tree and words */ -extern STRING *environ; -extern CHAR numbuf[]; +extern STRING *environ; +extern CHAR numbuf[]; extern const char export[]; extern const char readonly[]; /* execflgs */ -extern INT exitval; -extern BOOL execbrk; -extern INT loopcnt; -extern INT breakcnt; +extern INT exitval; +extern BOOL execbrk; +extern INT loopcnt; +extern INT breakcnt; /* messages */ extern const char mailmsg[]; @@ -288,7 +288,6 @@ extern const char badexec[]; extern const char notfound[]; extern const char badfile[]; -extern address end[]; +extern address end[]; #include "ctype.h" - diff --git a/Applications/V7/cmd/sh/error.c b/Applications/V7/cmd/sh/error.c index 445e3c3b..8627b1b9 100644 --- a/Applications/V7/cmd/sh/error.c +++ b/Applications/V7/cmd/sh/error.c @@ -16,7 +16,7 @@ exitset() { - assnum(&exitadr,exitval); + assnum(&exitadr, exitval); } sigchk() @@ -25,29 +25,34 @@ sigchk() * `trapnote' is set to SIGSET when fault is seen and * no trap has been set. */ - if (trapnote&SIGSET - ) { exitsh(SIGFAIL); - ;} + if (trapnote & SIGSET) { + exitsh(SIGFAIL); + ; + } } -failed(s1,s2) - STRING s1, s2; +failed(s1, s2) +STRING s1, s2; { - prp(); prs(s1); - if (s2 - ) { prs(colon); prs(s2); - ;} - newline(); exitsh(ERROR); + prp(); + prs(s1); + if (s2) { + prs(colon); + prs(s2); + ; + } + newline(); + exitsh(ERROR); } error(s) - STRING s; +STRING s; { - failed(s,NIL); + failed(s, NIL); } exitsh(xno) - INT xno; +INT xno; { /* Arrive here from `FATAL' errors * a) exit command, @@ -56,31 +61,35 @@ exitsh(xno) * * Action is to return to command level or exit. */ - exitval=xno; - if ((flags & (forked|errflg|ttyflg)) != ttyflg - ) { done(); + exitval = xno; + if ((flags & (forked | errflg | ttyflg)) != ttyflg) { + done(); } else { clearup(); - longjmp(errshell,1); - ;} + longjmp(errshell, 1); + ; + } } done() { - register STRING t; - if (t=trapcom[0] - ) { trapcom[0]=0; /*should free but not long */ - execexp(t,0); - ;} + register STRING t; + if (t = trapcom[0] + ) { + trapcom[0] = 0; /*should free but not long */ + execexp(t, 0); + ; + } rmtemp(0); exit(exitval); } rmtemp(base) - IOPTR base; +IOPTR base; { - while(iotemp>base - ){ unlink(iotemp->ioname); - iotemp=iotemp->iolst; - ;} + while (iotemp > base) { + unlink(iotemp->ioname); + iotemp = iotemp->iolst; + ; + } } diff --git a/Applications/V7/cmd/sh/expand.c b/Applications/V7/cmd/sh/expand.c index fcd31b81..186fe67b 100644 --- a/Applications/V7/cmd/sh/expand.c +++ b/Applications/V7/cmd/sh/expand.c @@ -27,167 +27,221 @@ * */ -static void addg(); +static void addg(); -INT expand(as,rflg) - STRING as; +INT expand(as, rflg) +STRING as; { - INT count, dirf; - BOOL dir=0; - STRING rescan = 0; - register STRING s, cs; - ARGPTR schain = gchain; - struct dirent entry; - STATBUF statb; - - if (trapnote&SIGSET ) { return(0); ;} + INT count, dirf; + BOOL dir = 0; + STRING rescan = 0; + register STRING s, cs; + ARGPTR schain = gchain; + struct dirent entry; + STATBUF statb; + + if (trapnote & SIGSET) { + return (0);; + } - s=cs=as; entry.d_name[DIRSIZ-1]=0; /* to end the string */ + s = cs = as; + entry.d_name[DIRSIZ - 1] = 0; /* to end the string */ /* check for meta chars */ { - register BOOL slash; slash=0; - while(!fngchar(*cs) - ){if (*cs++==0 - ) { if (rflg && slash ) { break; } else { return(0) ;} - } else if ( *cs=='/' - ) { slash++; - ;} - ;} + register BOOL slash; + slash = 0; + while (!fngchar(*cs) + ) { + if (*cs++ == 0) { + if (rflg && slash) { + break; + } else { + return (0); + } + } else if (*cs == '/') { + slash++; + ; + }; + } } - for(;;) { if (cs==s - ) { s=nullstr; + for (;;) { + if (cs == s) { + s = nullstr; break; - } else if ( *--cs == '/' - ) { *cs=0; - if (s==cs ) { s="/" ;} + } else if (*--cs == '/') { + *cs = 0; + if (s == cs) { + s = "/"; + } break; - ;} + ; + } + } + if (stat(s, &statb) >= 0 + && (statb.st_mode & S_IFMT) == S_IFDIR + && (dirf = open(s, 0)) > 0) { + dir++; + ; } - if (stat(s,&statb)>=0 - && (statb.st_mode&S_IFMT)==S_IFDIR - && (dirf=open(s,0))>0 - ) { dir++; - ;} - count=0; - if (*cs==0 ) { *cs++=0200 ;} - if (dir - ) { /* check for rescan */ - register STRING rs; rs=cs; - - do { if (*rs=='/' ) { rescan=rs; *rs=0; gchain=0 ;} - } while(*rs++ ); + count = 0; + if (*cs == 0) { + *cs++ = 0200; + } + if (dir) { /* check for rescan */ + register STRING rs; + rs = cs; + + do { + if (*rs == '/') { + rescan = rs; + *rs = 0; + gchain = 0; + } + } while (*rs++); // FIXME: readdir - while(read(dirf, (void *)&entry, 32) == 32 && (trapnote&SIGSET) == 0 - ){if (entry.d_ino==0 || - (*entry.d_name=='.' && *cs!='.') - ) { continue; - ;} + while (read(dirf, (void *) &entry, 32) == 32 + && (trapnote & SIGSET) == 0) { + if (entry.d_ino == 0 + || (*entry.d_name == '.' && *cs != '.') + ) { + continue; + ; + } if (gmatch(entry.d_name, cs) - ) { addg(s,entry.d_name,rescan); count++; - ;} - ;} + ) { + addg(s, entry.d_name, rescan); + count++; + ; + }; + } close(dirf); - if (rescan - ) { register ARGPTR rchain; - rchain=gchain; gchain=schain; - if (count - ) { count=0; - while(rchain - ){count += expand(rchain->argval,1); - rchain=rchain->argnxt; - ;} - ;} - *rescan='/'; - ;} - ;} + if (rescan) { + register ARGPTR rchain; + rchain = gchain; + gchain = schain; + if (count) { + count = 0; + while (rchain) { + count += expand(rchain->argval, 1); + rchain = rchain->argnxt; + ; + } + ; + } + *rescan = '/'; + ; + }; + } { - register CHAR c; - s=as; - while(c = *s - ){*s++=(c&STRIP?c:'/') ;} + register CHAR c; + s = as; + while (c = *s) { + *s++ = (c & STRIP ? c : '/'); + } } - return(count); + return (count); } gmatch(s, p) - register STRING s, p; +register STRING s, p; { - register INT scc; - CHAR c; - - if (scc = *s++ - ) { if ((scc &= STRIP)==0 - ) { scc=0200; - ;} - ;} - switch(c = *p++) { - case '[': - {BOOL ok; INT lc; - ok=0; lc=077777; - while(c = *p++ - ){if (c==']' - ) { return(ok?gmatch(s,p):0); - } else if ( c==MINUS - ) { if (lc<=scc && scc<=(*p++) ) { ok++ ;} - } else { if (scc==(lc=(c&STRIP)) ) { ok++ ;} - ;} - ;} - return(0); + register INT scc; + CHAR c; + + if (scc = *s++) { + if ((scc &= STRIP) == 0) { + scc = 0200; + ; + }; + } + switch (c = *p++) { + case '[': + { + BOOL ok; + INT lc; + ok = 0; + lc = 077777; + while (c = *p++) { + if (c == ']') { + return (ok ? gmatch(s, p) : 0); + } else if (c == MINUS) { + if (lc <= scc && scc <= (*p++)) { + ok++; + } + } else { + if (scc == (lc = (c & STRIP))) { + ok++; + }; + } + ; + } + return (0); } - default: - if ((c&STRIP)!=scc ) { return(0) ;} + default: + if ((c & STRIP) != scc) { + return (0); + } - case '?': - return(scc?gmatch(s,p):0); + case '?': + return (scc ? gmatch(s, p) : 0); - case '*': - if (*p==0 ) { return(1) ;} + case '*': + if (*p == 0) { + return (1); + } --s; - while(*s - ){ if (gmatch(s++,p) ) { return(1) ;} ;} - return(0); + while (*s) { + if (gmatch(s++, p)) { + return (1); + }; + } + return (0); - case 0: - return(scc==0); + case 0: + return (scc == 0); } } -static void addg(as1,as2,as3) - STRING as1, as2, as3; +static void addg(as1, as2, as3) +STRING as1, as2, as3; { - register STRING s1, s2; - register INT c; + register STRING s1, s2; + register INT c; - s2 = locstak()+BYTESPERWORD; + s2 = locstak() + BYTESPERWORD; - s1=as1; - while(c = *s1++ - ){if ((c &= STRIP)==0 - ) { *s2++='/'; + s1 = as1; + while (c = *s1++) { + if ((c &= STRIP) == 0) { + *s2++ = '/'; break; - ;} - *s2++=c; - ;} - s1=as2; - while(*s2 = *s1++ ){s2++ ;} - if (s1=as3 - ) { *s2++='/'; - while(*s2++ = *++s1 ); - ;} + ; + } + *s2++ = c; + ; + } + s1 = as2; + while (*s2 = *s1++) { + s2++; + } + if (s1 = as3) { + *s2++ = '/'; + while (*s2++ = *++s1); + ; + } makearg(endstak(s2)); } makearg(args) - register STRING args; +register STRING args; { - ((ARGPTR)args)->argnxt=gchain; - gchain=(ARGPTR)args; + ((ARGPTR) args)->argnxt = gchain; + gchain = (ARGPTR) args; } - diff --git a/Applications/V7/cmd/sh/fault.c b/Applications/V7/cmd/sh/fault.c index cbd6b6a0..c1fbaede 100644 --- a/Applications/V7/cmd/sh/fault.c +++ b/Applications/V7/cmd/sh/fault.c @@ -13,30 +13,34 @@ #include "defs.h" -STRING trapcom[MAXTRAP]; -BOOL trapflg[MAXTRAP]; +STRING trapcom[MAXTRAP]; +BOOL trapflg[MAXTRAP]; /* ======== fault handling routines ======== */ -void fault(sig) - register INT sig; +void fault(sig) +register INT sig; { - register INT flag; - - signal(sig,fault); - if(sig==MEMF - ) { if(setbrk(brkincr) == -1 - ) { error(nospace); - ;} - } else if (sig==ALARM - ) { if(flags&waiting - ) { done(); - ;} - } else { flag = (trapcom[sig] ? TRAPSET : SIGSET); + register INT flag; + + signal(sig, fault); + if (sig == MEMF) { + if (setbrk(brkincr) == -1) { + error(nospace); + ; + } + } else if (sig == ALARM) { + if (flags & waiting) { + done(); + ; + } + } else { + flag = (trapcom[sig] ? TRAPSET : SIGSET); trapnote |= flag; trapflg[sig] |= flag; - ;} + ; + } } stdsigs() @@ -49,66 +53,75 @@ stdsigs() ignsig(n) { - register INT s, i; + register INT s, i; #if 0 - // FIXME: need to do proper SIG_IGN checks/handling - if((s=signal(i=n,1)&01)==0 - ) { trapflg[i] |= SIGMOD; - ;} -#endif - return(s); + // FIXME: need to do proper SIG_IGN checks/handling + if ((s = signal(i = n, 1) & 01) == 0) { + trapflg[i] |= SIGMOD; + ; + } +#endif + return (s); } getsig(n) { - register INT i; + register INT i; - if(trapflg[i=n]&SIGMOD || ignsig(i)==0 - ) { signal(i,fault); - ;} + if (trapflg[i = n] & SIGMOD || ignsig(i) == 0) { + signal(i, fault); + ; + } } oldsigs() { - register INT i; - register STRING t; - - i=MAXTRAP; - while(i-- - ){ t=trapcom[i]; - if(t==0 || *t - ) { clrsig(i); - ;} - trapflg[i]=0; - ;} - trapnote=0; + register INT i; + register STRING t; + + i = MAXTRAP; + while (i--) { + t = trapcom[i]; + if (t == 0 || *t) { + clrsig(i); + ; + } + trapflg[i] = 0; + ; + } + trapnote = 0; } clrsig(i) - INT i; +INT i; { - free(trapcom[i]); trapcom[i]=0; - if(trapflg[i]&SIGMOD - ) { signal(i,fault); + free(trapcom[i]); + trapcom[i] = 0; + if (trapflg[i] & SIGMOD) { + signal(i, fault); trapflg[i] &= ~SIGMOD; - ;} + ; + } } chktrap() { /* check for traps */ - register INT i=MAXTRAP; - register STRING t; + register INT i = MAXTRAP; + register STRING t; trapnote &= ~TRAPSET; - while(--i - ){if(trapflg[i]&TRAPSET - ) { trapflg[i] &= ~TRAPSET; - if(t=trapcom[i] - ) { INT savxit=exitval; - execexp(t,0); - exitval=savxit; exitset(); - ;} - ;} - ;} + while (--i) { + if (trapflg[i] & TRAPSET) { + trapflg[i] &= ~TRAPSET; + if (t = trapcom[i] + ) { + INT savxit = exitval; + execexp(t, 0); + exitval = savxit; + exitset(); + ; + }; + }; + } } diff --git a/Applications/V7/cmd/sh/glob.c b/Applications/V7/cmd/sh/glob.c index a9ed719a..fd083b46 100644 --- a/Applications/V7/cmd/sh/glob.c +++ b/Applications/V7/cmd/sh/glob.c @@ -36,5 +36,10 @@ jmp_buf errshell; /* FIXME */ -int setjmp(jmp_buf bar) {} -void longjmp(jmp_buf bar, int foo) {} \ No newline at end of file +int setjmp(jmp_buf bar) +{ +} + +void longjmp(jmp_buf bar, int foo) +{ +} diff --git a/Applications/V7/cmd/sh/io.c b/Applications/V7/cmd/sh/io.c index 3f13a62d..b5054d80 100644 --- a/Applications/V7/cmd/sh/io.c +++ b/Applications/V7/cmd/sh/io.c @@ -16,121 +16,149 @@ /* ======== input output and file copying ======== */ initf(fd) - UFD fd; +UFD fd; { - register FILE f=standin; - - f->fdes=fd; f->fsiz=((flags&(oneflg|ttyflg))==0 ? BUFSIZ : 1); - f->fnxt=f->fend=f->fbuf; f->feval=0; f->flin=1; - f->feof=FALSE; + register FILE f = standin; + + f->fdes = fd; + f->fsiz = ((flags & (oneflg | ttyflg)) == 0 ? BUFSIZ : 1); + f->fnxt = f->fend = f->fbuf; + f->feval = 0; + f->flin = 1; + f->feof = FALSE; } estabf(s) - register STRING s; +register STRING s; { - register FILE f; + register FILE f; - (f=standin)->fdes = -1; - f->fend=length(s)+(f->fnxt=s); - f->flin=1; - return(f->feof=(s==0)); + (f = standin)->fdes = -1; + f->fend = length(s) + (f->fnxt = s); + f->flin = 1; + return (f->feof = (s == 0)); } push(af) - FILE af; +FILE af; { - register FILE f; + register FILE f; - (f=af)->fstak=standin; - f->feof=0; f->feval=0; - standin=f; + (f = af)->fstak = standin; + f->feof = 0; + f->feval = 0; + standin = f; } pop() { - register FILE f; - - if((f=standin)->fstak - ) { if(f->fdes>=0 ) { close(f->fdes) ;} - standin=f->fstak; - return(TRUE); - } else { return(FALSE); - ;} + register FILE f; + + if ((f = standin)->fstak) { + if (f->fdes >= 0) { + close(f->fdes); + } + standin = f->fstak; + return (TRUE); + } else { + return (FALSE); + ; + } } chkpipe(pv) - INT *pv; +INT *pv; { - if(pipe(pv)<0 || pv[INPIPE]<0 || pv[OTPIPE]<0 - ) { error(piperr); - ;} + if (pipe(pv) < 0 || pv[INPIPE] < 0 || pv[OTPIPE] < 0) { + error(piperr); + ; + } } chkopen(idf) - STRING idf; +STRING idf; { - register INT rc; - - if((rc=open(idf,0))<0 - ) { failed(idf,badopen); - } else { return(rc); - ;} + register INT rc; + + if ((rc = open(idf, 0)) < 0) { + failed(idf, badopen); + } else { + return (rc); + ; + } } -sh_rename(f1,f2) - register INT f1, f2; +sh_rename(f1, f2) +register INT f1, f2; { - if(f1!=f2 - ) { dup2(f1, f2); + if (f1 != f2) { + dup2(f1, f2); close(f1); - if(f2==0 ) { ioset|=1 ;} - ;} + if (f2 == 0) { + ioset |= 1; + }; + } } create(s) - STRING s; +STRING s; { - register INT rc; - - if((rc=creat(s,0666))<0 - ) { failed(s,badcreate); - } else { return(rc); - ;} + register INT rc; + + if ((rc = creat(s, 0666)) < 0) { + failed(s, badcreate); + } else { + return (rc); + ; + } } tmpfil() { - itos(serial++); movstr(numbuf,tmpnam); - return(create(tmpout)); + itos(serial++); + movstr(numbuf, tmpnam); + return (create(tmpout)); } /* set by trim */ -BOOL nosubst; +BOOL nosubst; copy(ioparg) - IOPTR ioparg; +IOPTR ioparg; { - CHAR c, *ends; - register CHAR *cline, *clinep; - INT fd; - register IOPTR iop; - - if(iop=ioparg - ) { copy(iop->iolst); - ends=mactrim(iop->ioname); if(nosubst ) { iop->iofile &= ~IODOC ;} - fd=tmpfil(); - iop->ioname=cpystak(tmpout); - iop->iolst=iotemp; iotemp=iop; - cline=locstak(); + CHAR c, *ends; + register CHAR *cline, *clinep; + INT fd; + register IOPTR iop; + + if (iop = ioparg) { + copy(iop->iolst); + ends = mactrim(iop->ioname); + if (nosubst) { + iop->iofile &= ~IODOC; + } + fd = tmpfil(); + iop->ioname = cpystak(tmpout); + iop->iolst = iotemp; + iotemp = iop; + cline = locstak(); for (;;) { - clinep=cline; chkpr(NL); - while((c = (nosubst ? readc() : nextc(*ends)), !eolchar(c)) ){*clinep++ = c ;} - *clinep=0; - if(eof || eq(cline,ends) ) { break ;} - *clinep++=NL; - write(fd,cline,clinep-cline); + clinep = cline; + chkpr(NL); + while ((c = + (nosubst ? readc() : nextc(*ends)), + !eolchar(c))) { + *clinep++ = c; + } + *clinep = 0; + if (eof || eq(cline, ends)) { + break; + } + *clinep++ = NL; + write(fd, cline, clinep - cline); } close(fd); - ;} + ; + } } diff --git a/Applications/V7/cmd/sh/macro.c b/Applications/V7/cmd/sh/macro.c index ab489b26..a8b5eca6 100644 --- a/Applications/V7/cmd/sh/macro.c +++ b/Applications/V7/cmd/sh/macro.c @@ -13,228 +13,311 @@ #include "defs.h" #include "sym.h" -static CHAR quote; /* used locally */ -static CHAR quoted; /* used locally */ +static CHAR quote; /* used locally */ +static CHAR quoted; /* used locally */ static getch(); static comsubst(); static flush(); -static STRING copyto(endch) - register CHAR endch; +static STRING copyto(endch) +register CHAR endch; { - register CHAR c; + register CHAR c; - while((c=getch(endch))!=endch && c - ){pushstak(c|quote) ;} + while ((c = getch(endch)) != endch && c) { + pushstak(c | quote); + } zerostak(); - if(c!=endch ) { error(badsub) ;} + if (c != endch) { + error(badsub); + } } static skipto(endch) - register CHAR endch; +register CHAR endch; { /* skip chars up to } */ - register CHAR c; - while((c=readc()) && c!=endch - ){ switch(c) { + register CHAR c; + while ((c = readc()) && c != endch) { + switch (c) { - case SQUOTE: skipto(SQUOTE); break; + case SQUOTE: + skipto(SQUOTE); + break; - case DQUOTE: skipto(DQUOTE); break; + case DQUOTE: + skipto(DQUOTE); + break; - case DOLLAR: if(readc()==BRACE - ) { skipto('}'); - ;} + case DOLLAR: + if (readc() == BRACE) { + skipto('}'); + ; + } } - ;} - if(c!=endch ) { error(badsub) ;} + ; + } + if (c != endch) { + error(badsub); + } } static getch(endch) - CHAR endch; +CHAR endch; { - register CHAR d; - -retry: - d=readc(); - if(!subchar(d) - ) { return(d); - ;} - if(d==DOLLAR - ) { register INT c; - if((c=readc(), dolchar(c)) - ) { NAMPTR n=(NAMPTR)NIL; - INT dolg=0; - BOOL bra; - register STRING argp, v; - CHAR idb[2]; - STRING id=idb; - - if(bra=(c==BRACE) ) { c=readc() ;} - if(letter(c) - ) { argp=(STRING)relstak(); - while(alphanum(c) ){pushstak(c); c=readc() ;} + register CHAR d; + + retry: + d = readc(); + if (!subchar(d) + ) { + return (d); + ; + } + if (d == DOLLAR) { + register INT c; + if ((c = readc(), dolchar(c)) + ) { + NAMPTR n = (NAMPTR) NIL; + INT dolg = 0; + BOOL bra; + register STRING argp, v; + CHAR idb[2]; + STRING id = idb; + + if (bra = (c == BRACE)) { + c = readc(); + } + if (letter(c) + ) { + argp = (STRING) relstak(); + while (alphanum(c)) { + pushstak(c); + c = readc(); + } zerostak(); - n=lookup(absstak(argp)); setstak(argp); - v = n->namval; id = n->namid; - peekc = c|MARK;; - } else if ( digchar(c) - ) { *id=c; idb[1]=0; - if(astchar(c) - ) { dolg=1; c='1'; - ;} + n = lookup(absstak(argp)); + setstak(argp); + v = n->namval; + id = n->namid; + peekc = c | MARK;; + } else if (digchar(c) + ) { + *id = c; + idb[1] = 0; + if (astchar(c) + ) { + dolg = 1; + c = '1'; + ; + } c -= '0'; - v=((c==0) ? cmdadr : (c<=dolc) ? dolv[c] : (STRING)(dolg=0)); - } else if ( c=='$' - ) { v=pidadr; - } else if ( c=='!' - ) { v=pcsadr; - } else if ( c=='#' - ) { v=dolladr; - } else if ( c=='?' - ) { v=exitadr; - } else if ( c=='-' - ) { v=flagadr; - } else if ( bra ) { error(badsub); - } else { goto retry; - ;} + v = ((c == 0) ? cmdadr : (c <= + dolc) ? dolv[c] + : (STRING) (dolg = 0)); + } else if (c == '$') { + v = pidadr; + } else if (c == '!') { + v = pcsadr; + } else if (c == '#') { + v = dolladr; + } else if (c == '?') { + v = exitadr; + } else if (c == '-') { + v = flagadr; + } else if (bra) { + error(badsub); + } else { + goto retry; + ; + } c = readc(); - if(!defchar(c) && bra - ) { error(badsub); - ;} - argp=0; - if(bra - ) { if(c!='}' - ) { argp=(STRING)relstak(); - if((v==0)^(setchar(c)) - ) { copyto('}'); - } else { skipto('}'); - ;} - argp=absstak(argp); - ;} - } else { peekc = c|MARK; c = 0; - ;} - if(v - ) { if(c!='+' - ) { for (;;) { - while(c = *v++ - ){pushstak(c|quote); ;} - if(dolg==0 || (++dolg>dolc) - ) { break; - } else { v=dolv[dolg]; pushstak(SP|(*id=='*' ? quote : 0)); - ;} + if (!defchar(c) && bra) { + error(badsub); + ; + } + argp = 0; + if (bra) { + if (c != '}') { + argp = (STRING) relstak(); + if ((v == 0) ^ (setchar(c)) + ) { + copyto('}'); + } else { + skipto('}'); + ; + } + argp = absstak(argp); + ; + } + } else { + peekc = c | MARK; + c = 0; + ; + } + if (v) { + if (c != '+') { + for (;;) { + while (c = *v++) { + pushstak(c | + quote);; + } + if (dolg == 0 + || (++dolg > dolc) + ) { + break; + } else { + v = dolv[dolg]; + pushstak(SP | + (*id == + '*' ? + quote : + 0)); + ; + } + } + ; + } + } else if (argp) { + if (c == '?') { + failed(id, + *argp ? argp : badparam); + } else if (c == '=') { + if (n) { + assign(n, argp); + } else { + error(badsub); + ; } - ;} - } else if ( argp - ) { if(c=='?' - ) { failed(id,*argp?argp:badparam); - } else if ( c=='=' - ) { if(n - ) { assign(n,argp); - } else { error(badsub); - ;} - ;} - } else if ( flags&setflg - ) { failed(id,badparam); - ;} + ; + } + } else if (flags & setflg) { + failed(id, badparam); + ; + } goto retry; - } else { peekc=c|MARK; - ;} - } else if ( d==endch - ) { return(d); - } else if ( d==SQUOTE - ) { comsubst(); goto retry; - } else if ( d==DQUOTE - ) { quoted++; quote^=QUOTE; goto retry; - ;} - return(d); + } else { + peekc = c | MARK; + ; + } + } else if (d == endch) { + return (d); + } else if (d == SQUOTE) { + comsubst(); + goto retry; + } else if (d == DQUOTE) { + quoted++; + quote ^= QUOTE; + goto retry; + ; + } + return (d); } -STRING macro(as) - STRING as; +STRING macro(as) +STRING as; { /* Strip "" and do $ substitution * Leaves result on top of stack */ - register BOOL savqu =quoted; - register CHAR savq = quote; - FILEHDR fb; + register BOOL savqu = quoted; + register CHAR savq = quote; + FILEHDR fb; - push(&fb); estabf(as); + push(&fb); + estabf(as); usestak(); - quote=0; quoted=0; + quote = 0; + quoted = 0; copyto(0); pop(); - if(quoted && (stakbot==staktop) ) { pushstak(QUOTE) ;} - quote=savq; quoted=savqu; - return(fixstak()); + if (quoted && (stakbot == staktop)) { + pushstak(QUOTE); + } + quote = savq; + quoted = savqu; + return (fixstak()); } static comsubst() { /* command substn */ - FILEBLK cb; - register CHAR d; - register STKPTR savptr = fixstak(); + FILEBLK cb; + register CHAR d; + register STKPTR savptr = fixstak(); usestak(); - while((d=readc())!=SQUOTE && d - ){pushstak(d) ;} + while ((d = readc()) != SQUOTE && d) { + pushstak(d); + } { - register STRING argc; - trim(argc=fixstak()); - push(&cb); estabf(argc); + register STRING argc; + trim(argc = fixstak()); + push(&cb); + estabf(argc); } { - register TREPTR t = makefork(FPOU,cmd(EOFSYM,MTFLG|NLFLG)); - INT pv[2]; - - /* this is done like this so that the pipe - * is open only when needed - */ - chkpipe(pv); - initf(pv[INPIPE]); - execute(t, 0, 0, pv); - close(pv[OTPIPE]); + register TREPTR t = + makefork(FPOU, cmd(EOFSYM, MTFLG | NLFLG)); + INT pv[2]; + + /* this is done like this so that the pipe + * is open only when needed + */ + chkpipe(pv); + initf(pv[INPIPE]); + execute(t, 0, 0, pv); + close(pv[OTPIPE]); + } + tdystak(savptr); + staktop = movstr(savptr, stakbot); + while (d = readc()) { + pushstak(d | quote); } - tdystak(savptr); staktop=movstr(savptr,stakbot); - while(d=readc() ){pushstak(d|quote) ;} await(0); - while(stakbot!=staktop - ){ if((*--staktop&STRIP)!=NL - ) { ++staktop; break; - ;} - ;} + while (stakbot != staktop) { + if ((*--staktop & STRIP) != NL) { + ++staktop; + break; + ; + }; + } pop(); } #define CPYSIZ 512 -subst(in,ot) - INT in, ot; +subst(in, ot) +INT in, ot; { - register CHAR c; - FILEBLK fb; - register INT count=CPYSIZ; + register CHAR c; + FILEBLK fb; + register INT count = CPYSIZ; - push(&fb); initf(in); + push(&fb); + initf(in); /* DQUOTE used to stop it from quoting */ - while(c=(getch(DQUOTE)&STRIP) - ){pushstak(c); - if(--count == 0 - ) { flush(ot); count=CPYSIZ; - ;} - ;} + while (c = (getch(DQUOTE) & STRIP) + ) { + pushstak(c); + if (--count == 0) { + flush(ot); + count = CPYSIZ; + ; + }; + } flush(ot); pop(); } static flush(ot) { - write(ot,stakbot,staktop-stakbot); - if(flags&execpr ) { write(output,stakbot,staktop-stakbot) ;} - staktop=stakbot; + write(ot, stakbot, staktop - stakbot); + if (flags & execpr) { + write(output, stakbot, staktop - stakbot); + } + staktop = stakbot; } diff --git a/Applications/V7/cmd/sh/main.c b/Applications/V7/cmd/sh/main.c index 92d061c4..1642cc2f 100644 --- a/Applications/V7/cmd/sh/main.c +++ b/Applications/V7/cmd/sh/main.c @@ -20,27 +20,27 @@ #include #include -UFD output = 2; -static BOOL beenhere = FALSE; -CHAR tmpout[20] = "/tmp/sh-"; -FILEBLK stdfile; -FILE standin = &stdfile; +UFD output = 2; +static BOOL beenhere = FALSE; +CHAR tmpout[20] = "/tmp/sh-"; +FILEBLK stdfile; +FILE standin = &stdfile; -static void exfile(); +static void exfile(); main(c, v) - INT c; - STRING v[]; +INT c; +STRING v[]; { - register INT rflag=ttyflg; + register INT rflag = ttyflg; /* initialise storage allocation */ stdsigs(); setbrk(BRKINCR); - addblok((POS)0); + addblok((POS) 0); /* set names from userenv */ sh_getenv(); @@ -49,19 +49,23 @@ main(c, v) /* if(c>0 && any('r', *v) ) { rflag=0 ;} */ /* look for options */ - dolc=options(c,v); - if(dolc<2 ) { flags |= stdflg ;} - if((flags&stdflg)==0 - ) { dolc--; - ;} - dolv=v+c-dolc; dolc--; + dolc = options(c, v); + if (dolc < 2) { + flags |= stdflg; + } + if ((flags & stdflg) == 0) { + dolc--; + ; + } + dolv = v + c - dolc; + dolc--; /* return here for shell file execution */ setjmp(subshell); /* number of positional parameters */ - assnum(&dolladr,dolc); - cmdadr=dolv[0]; + assnum(&dolladr, dolc); + cmdadr = dolv[0]; /* set pidname */ assnum(&pidadr, getpid()); @@ -72,109 +76,137 @@ main(c, v) /* default ifs */ dfault(&ifsnod, sptbnl); - if((beenhere++)==FALSE - ) { /* ? profile */ - if(*cmdadr=='-' - && (input=pathopen(nullstr, profile))>=0 - ) { exfile(rflag); flags &= ~ttyflg; - ;} - if(rflag==0 ) { flags |= rshflg ;} + if ((beenhere++) == FALSE) { /* ? profile */ + if (*cmdadr == '-' + && (input = pathopen(nullstr, profile)) >= 0) { + exfile(rflag); + flags &= ~ttyflg; + ; + } + if (rflag == 0) { + flags |= rshflg; + } /* open input file if specified */ - if(comdiv - ) { estabf(comdiv); input = -1; - } else { input=((flags&stdflg) ? 0 : chkopen(cmdadr)); + if (comdiv) { + estabf(comdiv); + input = -1; + } else { + input = ((flags & stdflg) ? 0 : chkopen(cmdadr)); comdiv--; - ;} -// } else { *execargs=(char *)dolv; /* for `ps' cmd */ - ;} + ; + } +// } else { *execargs=(char *)dolv; /* for `ps' cmd */ + ; + } exfile(0); done(); } -static void exfile(prof) -BOOL prof; +static void exfile(prof) +BOOL prof; { - register L_INT mailtime = 0; - register INT userid; - struct stat statb; + register L_INT mailtime = 0; + register INT userid; + struct stat statb; /* move input */ - if(input>0 - ) { Ldup(input,INIO); - input=INIO; - ;} + if (input > 0) { + Ldup(input, INIO); + input = INIO; + ; + } /* move output to safe place */ - if(output==2 - ) { Ldup(dup(2),OTIO); - output=OTIO; - ;} + if (output == 2) { + Ldup(dup(2), OTIO); + output = OTIO; + ; + } - userid=getuid(); + userid = getuid(); /* decide whether interactive */ - if((flags&intflg) || ((flags&oneflg)==0 && isatty(output) && isatty(input)) - ) { dfault(&ps1nod, (userid?stdprompt:supprompt)); + if ((flags & intflg) + || ((flags & oneflg) == 0 && isatty(output) && isatty(input)) + ) { + dfault(&ps1nod, (userid ? stdprompt : supprompt)); dfault(&ps2nod, readmsg); - flags |= ttyflg|prompt; ignsig(KILL); + flags |= ttyflg | prompt; + ignsig(KILL); } else { - flags |= prof; flags &= ~prompt; - ;} + flags |= prof; + flags &= ~prompt; + ; + } - if(setjmp(errshell) && prof - ) { close(input); return; - ;} + if (setjmp(errshell) && prof) { + close(input); + return; + ; + } /* error return here */ - loopcnt=breakcnt=peekc=0; iopend=0; - if(input>=0 ) { initf(input) ;} + loopcnt = breakcnt = peekc = 0; + iopend = 0; + if (input >= 0) { + initf(input); + } /* command loop */ - for(;;) { + for (;;) { tdystak(0); - stakchk(); /* may reduce sbrk */ + stakchk(); /* may reduce sbrk */ exitset(); - if((flags&prompt) && standin->fstak==0 && !eof - ) { if(mailnod.namval - && stat(mailnod.namval,&statb)>=0 && statb.st_size + if ((flags & prompt) && standin->fstak == 0 && !eof) { + if (mailnod.namval + && stat(mailnod.namval, &statb) >= 0 + && statb.st_size && (statb.st_mtime != mailtime) - && mailtime - ) { prs(mailmsg) - ;} - mailtime=statb.st_mtime; - prs(ps1nod.namval); alarm(TIMEOUT); flags |= waiting; - ;} - - trapnote=0; peekc=readc(); - if(eof - ) { return; - ;} - alarm(0); flags &= ~waiting; - execute(cmd(NL,MTFLG),0); - eof |= (flags&oneflg); + && mailtime) { + prs(mailmsg); + } + mailtime = statb.st_mtime; + prs(ps1nod.namval); + alarm(TIMEOUT); + flags |= waiting; + ; + } + + trapnote = 0; + peekc = readc(); + if (eof) { + return; + ; + } + alarm(0); + flags &= ~waiting; + execute(cmd(NL, MTFLG), 0); + eof |= (flags & oneflg); } } chkpr(eor) char eor; { - if((flags&prompt) && standin->fstak==0 && eor==NL - ) { prs(ps2nod.namval); - ;} + if ((flags & prompt) && standin->fstak == 0 && eor == NL) { + prs(ps2nod.namval); + ; + } } settmp() { - itos(getpid()); serial=0; - tmpnam=movstr(numbuf,&tmpout[TMPNAM]); + itos(getpid()); + serial = 0; + tmpnam = movstr(numbuf, &tmpout[TMPNAM]); } Ldup(fa, fb) - register INT fa, fb; +register INT fa, fb; { dup2(fa, fb); close(fa); - fcntl(fb, F_SETFD, FD_CLOEXEC); + fcntl(fb, F_SETFD, FD_CLOEXEC); } diff --git a/Applications/V7/cmd/sh/mode.h b/Applications/V7/cmd/sh/mode.h index b7c8d0bc..47d42534 100644 --- a/Applications/V7/cmd/sh/mode.h +++ b/Applications/V7/cmd/sh/mode.h @@ -9,39 +9,39 @@ #define BYTESPERWORD (sizeof(char *)) -typedef char CHAR; -typedef char BOOL; -typedef int UFD; -typedef int INT; -typedef float REAL; -typedef void *ADDRESS; -typedef long int L_INT; -typedef unsigned POS; -typedef char *STRING; -typedef int PIPE[]; -typedef char *STKPTR; -typedef char *BYTPTR; - -typedef struct stat STATBUF; /* defined in /usr/sys/stat.h */ -typedef struct blk *BLKPTR; -typedef struct fileblk FILEBLK; -typedef struct filehdr FILEHDR; -typedef struct fileblk *FILE; -typedef struct trenod *TREPTR; -typedef struct forknod *FORKPTR; -typedef struct comnod *COMPTR; -typedef struct swnod *SWPTR; -typedef struct regnod *REGPTR; -typedef struct parnod *PARPTR; -typedef struct ifnod *IFPTR; -typedef struct whnod *WHPTR; -typedef struct fornod *FORPTR; -typedef struct lstnod *LSTPTR; -typedef struct argnod *ARGPTR; -typedef struct dolnod *DOLPTR; -typedef struct ionod *IOPTR; -typedef struct namnod NAMNOD; -typedef struct namnod *NAMPTR; +typedef char CHAR; +typedef char BOOL; +typedef int UFD; +typedef int INT; +typedef float REAL; +typedef void *ADDRESS; +typedef long int L_INT; +typedef unsigned POS; +typedef char *STRING; +typedef int PIPE[]; +typedef char *STKPTR; +typedef char *BYTPTR; + +typedef struct stat STATBUF; /* defined in /usr/sys/stat.h */ +typedef struct blk *BLKPTR; +typedef struct fileblk FILEBLK; +typedef struct filehdr FILEHDR; +typedef struct fileblk *FILE; +typedef struct trenod *TREPTR; +typedef struct forknod *FORKPTR; +typedef struct comnod *COMPTR; +typedef struct swnod *SWPTR; +typedef struct regnod *REGPTR; +typedef struct parnod *PARPTR; +typedef struct ifnod *IFPTR; +typedef struct whnod *WHPTR; +typedef struct fornod *FORPTR; +typedef struct lstnod *LSTPTR; +typedef struct argnod *ARGPTR; +typedef struct dolnod *DOLPTR; +typedef struct ionod *IOPTR; +typedef struct namnod NAMNOD; +typedef struct namnod *NAMPTR; #define NIL ((char*)0) @@ -56,138 +56,138 @@ typedef struct namnod *NAMPTR; /* address puns for storage allocation */ typedef union { - FORKPTR _forkptr; - COMPTR _comptr; - PARPTR _parptr; - IFPTR _ifptr; - WHPTR _whptr; - FORPTR _forptr; - LSTPTR _lstptr; - BLKPTR _blkptr; - NAMPTR _namptr; - BYTPTR _bytptr; - } address; + FORKPTR _forkptr; + COMPTR _comptr; + PARPTR _parptr; + IFPTR _ifptr; + WHPTR _whptr; + FORPTR _forptr; + LSTPTR _lstptr; + BLKPTR _blkptr; + NAMPTR _namptr; + BYTPTR _bytptr; +} address; /* heap storage */ struct blk { - BLKPTR word; + BLKPTR word; }; #define BUFSIZ 64 struct fileblk { - UFD fdes; - POS flin; - BOOL feof; - CHAR fsiz; - STRING fnxt; - STRING fend; - STRING *feval; - FILE fstak; - CHAR fbuf[BUFSIZ]; + UFD fdes; + POS flin; + BOOL feof; + CHAR fsiz; + STRING fnxt; + STRING fend; + STRING *feval; + FILE fstak; + CHAR fbuf[BUFSIZ]; }; /* for files not used with file descriptors */ struct filehdr { - UFD fdes; - POS flin; - BOOL feof; - CHAR fsiz; - STRING fnxt; - STRING fend; - STRING *feval; - FILE fstak; - CHAR _fbuf[1]; + UFD fdes; + POS flin; + BOOL feof; + CHAR fsiz; + STRING fnxt; + STRING fend; + STRING *feval; + FILE fstak; + CHAR _fbuf[1]; }; struct sysnod { - STRING sysnam; - INT sysval; + STRING sysnam; + INT sysval; }; -typedef struct sysnod SYSNOD; -typedef struct sysnod *SYSPTR; -typedef struct sysnod SYSTAB[]; +typedef struct sysnod SYSNOD; +typedef struct sysnod *SYSPTR; +typedef struct sysnod SYSTAB[]; /* this node is a proforma for those that follow */ struct trenod { - INT tretyp; - IOPTR treio; + INT tretyp; + IOPTR treio; }; /* dummy for access only */ struct argnod { - ARGPTR argnxt; - CHAR argval[1]; + ARGPTR argnxt; + CHAR argval[1]; }; struct dolnod { - DOLPTR dolnxt; - INT doluse; - CHAR dolarg[1]; + DOLPTR dolnxt; + INT doluse; + CHAR dolarg[1]; }; struct forknod { - INT forktyp; - IOPTR forkio; - TREPTR forktre; + INT forktyp; + IOPTR forkio; + TREPTR forktre; }; struct comnod { - INT comtyp; - IOPTR comio; - ARGPTR comarg; - ARGPTR comset; + INT comtyp; + IOPTR comio; + ARGPTR comarg; + ARGPTR comset; }; struct ifnod { - INT iftyp; - TREPTR iftre; - TREPTR thtre; - TREPTR eltre; + INT iftyp; + TREPTR iftre; + TREPTR thtre; + TREPTR eltre; }; struct whnod { - INT whtyp; - TREPTR whtre; - TREPTR dotre; + INT whtyp; + TREPTR whtre; + TREPTR dotre; }; struct fornod { - INT fortyp; - TREPTR fortre; - STRING fornam; - COMPTR forlst; + INT fortyp; + TREPTR fortre; + STRING fornam; + COMPTR forlst; }; struct swnod { - INT swtyp; - STRING swarg; - REGPTR swlst; + INT swtyp; + STRING swarg; + REGPTR swlst; }; struct regnod { - ARGPTR regptr; - TREPTR regcom; - REGPTR regnxt; + ARGPTR regptr; + TREPTR regcom; + REGPTR regnxt; }; struct parnod { - INT partyp; - TREPTR partre; + INT partyp; + TREPTR partre; }; struct lstnod { - INT lsttyp; - TREPTR lstlef; - TREPTR lstrit; + INT lsttyp; + TREPTR lstlef; + TREPTR lstrit; }; struct ionod { - INT iofile; - STRING ioname; - IOPTR ionxt; - IOPTR iolst; + INT iofile; + STRING ioname; + IOPTR ionxt; + IOPTR iolst; }; #define FORKTYPE (sizeof(struct forknod)) diff --git a/Applications/V7/cmd/sh/msg.c b/Applications/V7/cmd/sh/msg.c index 53a1c7e6..9e4d48a7 100644 --- a/Applications/V7/cmd/sh/msg.c +++ b/Applications/V7/cmd/sh/msg.c @@ -14,126 +14,127 @@ #include "defs.h" #include "sym.h" -const char version[] = "\nVERSION sys137 DATE 1978 Nov 6 14:29:22\n"; +const char version[] = + "\nVERSION sys137 DATE 1978 Nov 6 14:29:22\n"; /* error messages */ -const char badopt[] = "bad option(s)"; -const char mailmsg[] = "you have mail\n"; -const char nospace[] = "no space"; -const char synmsg[] = "syntax error"; +const char badopt[] = "bad option(s)"; +const char mailmsg[] = "you have mail\n"; +const char nospace[] = "no space"; +const char synmsg[] = "syntax error"; -const char badnum[] = "bad number"; -const char badparam[] = "parameter not set"; -const char badsub[] = "bad substitution"; -const char badcreate[] = "cannot create"; -const char illegal[] = "illegal io"; -const char restricted[] = "restricted"; -const char piperr[] = "cannot make pipe"; -const char badopen[] = "cannot open"; -const char coredump[] = " - core dumped"; -const char arglist[] = "arg list too long"; -const char txtbsy[] = "text busy"; -const char toobig[] = "too big"; -const char badexec[] = "cannot execute"; -const char notfound[] = "not found"; -const char badfile[] = "bad file number"; -const char badshift[] = "cannot shift"; -const char baddir[] = "bad directory"; -const char badtrap[] = "bad trap"; -const char wtfailed[] = "is read only"; -const char notid[] = "is not an identifier"; +const char badnum[] = "bad number"; +const char badparam[] = "parameter not set"; +const char badsub[] = "bad substitution"; +const char badcreate[] = "cannot create"; +const char illegal[] = "illegal io"; +const char restricted[] = "restricted"; +const char piperr[] = "cannot make pipe"; +const char badopen[] = "cannot open"; +const char coredump[] = " - core dumped"; +const char arglist[] = "arg list too long"; +const char txtbsy[] = "text busy"; +const char toobig[] = "too big"; +const char badexec[] = "cannot execute"; +const char notfound[] = "not found"; +const char badfile[] = "bad file number"; +const char badshift[] = "cannot shift"; +const char baddir[] = "bad directory"; +const char badtrap[] = "bad trap"; +const char wtfailed[] = "is read only"; +const char notid[] = "is not an identifier"; /* built in names */ -const char pathname[] = "PATH"; -const char homename[] = "HOME"; -const char mailname[] = "MAIL"; -const char fngname[] = "FILEMATCH"; -const char ifsname[] = "IFS"; -const char ps1name[] = "PS1"; -const char ps2name[] = "PS2"; +const char pathname[] = "PATH"; +const char homename[] = "HOME"; +const char mailname[] = "MAIL"; +const char fngname[] = "FILEMATCH"; +const char ifsname[] = "IFS"; +const char ps1name[] = "PS1"; +const char ps2name[] = "PS2"; /* string constants */ -const char nullstr[] = ""; -const char sptbnl[] = " \t\n"; -const char defpath[] = ":/bin:/usr/bin"; -const char colon[] = ": "; -const char minus[] = "-"; -const char endoffile[] = "end of file"; -const char unexpected[] = " unexpected"; -const char atline[] = " at line "; -const char devnull[] = "/dev/null"; -const char execpmsg[] = "+ "; -const char readmsg[] = "> "; -const char stdprompt[] = "$ "; -const char supprompt[] = "# "; -const char profile[] = ".profile"; +const char nullstr[] = ""; +const char sptbnl[] = " \t\n"; +const char defpath[] = ":/bin:/usr/bin"; +const char colon[] = ": "; +const char minus[] = "-"; +const char endoffile[] = "end of file"; +const char unexpected[] = " unexpected"; +const char atline[] = " at line "; +const char devnull[] = "/dev/null"; +const char execpmsg[] = "+ "; +const char readmsg[] = "> "; +const char stdprompt[] = "$ "; +const char supprompt[] = "# "; +const char profile[] = ".profile"; /* tables */ SYSTAB reserved = { - {"in", INSYM}, - {"esac", ESSYM}, - {"case", CASYM}, - {"for", FORSYM}, - {"done", ODSYM}, - {"if", IFSYM}, - {"while", WHSYM}, - {"do", DOSYM}, - {"then", THSYM}, - {"else", ELSYM}, - {"elif", EFSYM}, - {"fi", FISYM}, - {"until", UNSYM}, - { "{", BRSYM}, - { "}", KTSYM}, - {0, 0}, + {"in", INSYM}, + {"esac", ESSYM}, + {"case", CASYM}, + {"for", FORSYM}, + {"done", ODSYM}, + {"if", IFSYM}, + {"while", WHSYM}, + {"do", DOSYM}, + {"then", THSYM}, + {"else", ELSYM}, + {"elif", EFSYM}, + {"fi", FISYM}, + {"until", UNSYM}, + {"{", BRSYM}, + {"}", KTSYM}, + {0, 0}, }; -STRING sysmsg[] = { - 0, - "Hangup", - 0, /* Interrupt */ - "Quit", - "Illegal instruction", - "Trace/BPT trap", - "IOT trap", - "EMT trap", - "Floating exception", - "Killed", - "Bus error", - "Memory fault", - "Bad system call", - 0, /* Broken pipe */ - "Alarm call", - "Terminated", - "Signal 16", +STRING sysmsg[] = { + 0, + "Hangup", + 0, /* Interrupt */ + "Quit", + "Illegal instruction", + "Trace/BPT trap", + "IOT trap", + "EMT trap", + "Floating exception", + "Killed", + "Bus error", + "Memory fault", + "Bad system call", + 0, /* Broken pipe */ + "Alarm call", + "Terminated", + "Signal 16", }; const char export[] = "export"; const char readonly[] = "readonly"; -SYSTAB commands = { - {"cd", SYSCD}, - {"read", SYSREAD}, +SYSTAB commands = { + {"cd", SYSCD}, + {"read", SYSREAD}, /* {"[", SYSTST}, */ - {"set", SYSSET}, - {":", SYSNULL}, - {"trap", SYSTRAP}, - {"login", SYSLOGIN}, - {"wait", SYSWAIT}, - {"eval", SYSEVAL}, - {".", SYSDOT}, - {"newgrp", SYSLOGIN}, - {readonly, SYSRDONLY}, - {export, SYSXPORT}, - {"chdir", SYSCD}, - {"break", SYSBREAK}, - {"continue", SYSCONT}, - {"shift", SYSSHFT}, - {"exit", SYSEXIT}, - {"exec", SYSEXEC}, - {"times", SYSTIMES}, - {"umask", SYSUMASK}, - {0, 0}, + {"set", SYSSET}, + {":", SYSNULL}, + {"trap", SYSTRAP}, + {"login", SYSLOGIN}, + {"wait", SYSWAIT}, + {"eval", SYSEVAL}, + {".", SYSDOT}, + {"newgrp", SYSLOGIN}, + {readonly, SYSRDONLY}, + {export, SYSXPORT}, + {"chdir", SYSCD}, + {"break", SYSBREAK}, + {"continue", SYSCONT}, + {"shift", SYSSHFT}, + {"exit", SYSEXIT}, + {"exec", SYSEXEC}, + {"times", SYSTIMES}, + {"umask", SYSUMASK}, + {0, 0}, }; diff --git a/Applications/V7/cmd/sh/name.c b/Applications/V7/cmd/sh/name.c index f2408af8..e61ca192 100644 --- a/Applications/V7/cmd/sh/name.c +++ b/Applications/V7/cmd/sh/name.c @@ -12,314 +12,378 @@ #include "defs.h" -static BOOL chkid(); -static void namwalk(); +static BOOL chkid(); +static void namwalk(); -NAMNOD ps2nod = {(NAMPTR)NIL, (NAMPTR)NIL, ps2name}, - fngnod = {(NAMPTR)NIL, (NAMPTR)NIL, fngname}, - pathnod = {(NAMPTR)NIL, (NAMPTR)NIL, pathname}, - ifsnod = {(NAMPTR)NIL, (NAMPTR)NIL, ifsname}, - ps1nod = {&pathnod, &ps2nod, ps1name}, - homenod = {&fngnod, &ifsnod, homename}, - mailnod = {&homenod, &ps1nod, mailname}; +NAMNOD ps2nod = { (NAMPTR) NIL, (NAMPTR) NIL, ps2name }, fngnod = { +(NAMPTR) NIL, (NAMPTR) NIL, fngname}, pathnod = { +(NAMPTR) NIL, (NAMPTR) NIL, pathname}, ifsnod = { +(NAMPTR) NIL, (NAMPTR) NIL, ifsname}, ps1nod = { +&pathnod, &ps2nod, ps1name}, homenod = { +&fngnod, &ifsnod, homename}, mailnod = { +&homenod, &ps1nod, mailname}; -NAMPTR namep = &mailnod; +NAMPTR namep = &mailnod; /* ======== variable and string handling ======== */ -syslook(w,syswds) - STRING w; - SYSTAB syswds; +syslook(w, syswds) +STRING w; +SYSTAB syswds; { - register CHAR first; - register STRING s; - register SYSPTR syscan; - - syscan=syswds; first = *w; - - while(s=syscan->sysnam - ){ if (first == *s - && eq(w,s) - ) { return(syscan->sysval); - ;} - syscan++; - ;} - return(0); + register CHAR first; + register STRING s; + register SYSPTR syscan; + + syscan = syswds; + first = *w; + + while (s = syscan->sysnam) { + if (first == *s && eq(w, s) + ) { + return (syscan->sysval); + ; + } + syscan++; + ; + } + return (0); } -setlist(arg,xp) - register ARGPTR arg; - INT xp; +setlist(arg, xp) +register ARGPTR arg; +INT xp; { - while(arg - ){register STRING s=mactrim(arg->argval); - setname(s, xp); - arg=arg->argnxt; - if (flags&execpr - ) { prs(s); - if (arg ) { blank(); } else { newline(); ;} - ;} - ;} + while (arg) { + register STRING s = mactrim(arg->argval); + setname(s, xp); + arg = arg->argnxt; + if (flags & execpr) { + prs(s); + if (arg) { + blank(); + } else { + newline();; + } + ; + }; + } } -void setname(argi, xp) - STRING argi; - INT xp; +void setname(argi, xp) +STRING argi; +INT xp; { - register STRING argscan=argi; - register NAMPTR n; + register STRING argscan = argi; + register NAMPTR n; if (letter(*argscan) - ) { while(alphanum(*argscan) ){argscan++ ;} - if (*argscan=='=' - ) { *argscan = 0; - n=lookup(argi); + ) { + while (alphanum(*argscan)) { + argscan++; + } + if (*argscan == '=') { + *argscan = 0; + n = lookup(argi); *argscan++ = '='; attrib(n, xp); - if (xp&N_ENVNAM - ) { n->namenv = n->namval = argscan; - } else { assign(n, argscan); - ;} + if (xp & N_ENVNAM) { + n->namenv = n->namval = argscan; + } else { + assign(n, argscan); + ; + } return; - ;} - ;} - failed(argi,notid); + ; + }; + } + failed(argi, notid); } replace(a, v) - register STRING *a; - STRING v; +register STRING *a; +STRING v; { - free(*a); *a=make(v); + free(*a); + *a = make(v); } -dfault(n,v) - NAMPTR n; - STRING v; +dfault(n, v) +NAMPTR n; +STRING v; { - if (n->namval==0 - ) { assign(n,v) - ;} + if (n->namval == 0) { + assign(n, v); + } } -assign(n,v) - NAMPTR n; - STRING v; +assign(n, v) +NAMPTR n; +STRING v; { - if (n->namflg&N_RDONLY - ) { failed(n->namid,wtfailed); - } else { replace(&n->namval,v); - ;} + if (n->namflg & N_RDONLY) { + failed(n->namid, wtfailed); + } else { + replace(&n->namval, v); + ; + } } -INT readvar(names) - STRING *names; +INT readvar(names) +STRING *names; { - FILEBLK fb; - register FILE f = &fb; - register CHAR c; - register INT rc=0; - NAMPTR n=lookup(*names++); /* done now to avoid storage mess */ - STKPTR rel=(STKPTR)relstak(); - - push(f); initf(dup(0)); - if (lseek(0,0L,1)==-1 - ) { f->fsiz=1; - ;} - - for(;;) { - c=nextc(0); + FILEBLK fb; + register FILE f = &fb; + register CHAR c; + register INT rc = 0; + NAMPTR n = lookup(*names++); /* done now to avoid storage mess */ + STKPTR rel = (STKPTR) relstak(); + + push(f); + initf(dup(0)); + if (lseek(0, 0L, 1) == -1) { + f->fsiz = 1; + ; + } + + for (;;) { + c = nextc(0); if ((*names && any(c, ifsnod.namval)) || eolchar(c) - ) { zerostak(); - assign(n,absstak(rel)); setstak(rel); - if (*names - ) { n=lookup(*names++); - } else { n=0; - ;} + ) { + zerostak(); + assign(n, absstak(rel)); + setstak(rel); + if (*names) { + n = lookup(*names++); + } else { + n = 0; + ; + } if (eolchar(c) - ) { break; - ;} - } else { pushstak(c); - ;} + ) { + break; + ; + } + } else { + pushstak(c); + ; + } + } + while (n) { + assign(n, nullstr); + if (*names) { + n = lookup(*names++); + } else { + n = 0;; + } + ; } - while(n - ){assign(n, nullstr); - if (*names ) { n=lookup(*names++); } else { n=0; ;} - ;} - if (eof ) { rc=1 ;} - lseek(0, (long)(f->fnxt-f->fend), 1); + if (eof) { + rc = 1; + } + lseek(0, (long) (f->fnxt - f->fend), 1); pop(); - return(rc); + return (rc); } assnum(p, i) - STRING *p; - INT i; +STRING *p; +INT i; { - itos(i); replace(p,numbuf); + itos(i); + replace(p, numbuf); } -STRING make(v) - STRING v; +STRING make(v) +STRING v; { - register STRING p; - - if (v - ) { movstr(v,p=alloc(length(v))); - return(p); - } else { return(0); - ;} + register STRING p; + + if (v) { + movstr(v, p = alloc(length(v))); + return (p); + } else { + return (0); + ; + } } -NAMPTR lookup(nam) - register STRING nam; +NAMPTR lookup(nam) +register STRING nam; { - register NAMPTR nscan=namep; - register NAMPTR *prev; - INT LR; + register NAMPTR nscan = namep; + register NAMPTR *prev; + INT LR; if (!chkid(nam) - ) { failed(nam,notid); - ;} - while(nscan - ){ if ((LR=cf(nam,nscan->namid))==0 - ) { return(nscan); - } else if ( LR<0 - ) { prev = &(nscan->namlft); - } else { prev = &(nscan->namrgt); - ;} + ) { + failed(nam, notid); + ; + } + while (nscan) { + if ((LR = cf(nam, nscan->namid)) == 0) { + return (nscan); + } else if (LR < 0) { + prev = &(nscan->namlft); + } else { + prev = &(nscan->namrgt); + ; + } nscan = *prev; - ;} + ; + } /* add name node */ - nscan=(NAMPTR)alloc(sizeof *nscan); - nscan->namlft=nscan->namrgt=(NAMPTR)NIL; - nscan->namid=make(nam); - nscan->namval=0; nscan->namflg=N_DEFAULT; nscan->namenv=0; - return(*prev = nscan); + nscan = (NAMPTR) alloc(sizeof *nscan); + nscan->namlft = nscan->namrgt = (NAMPTR) NIL; + nscan->namid = make(nam); + nscan->namval = 0; + nscan->namflg = N_DEFAULT; + nscan->namenv = 0; + return (*prev = nscan); } -static BOOL chkid(nam) - STRING nam; +static BOOL chkid(nam) +STRING nam; { - register CHAR * cp=nam; + register CHAR *cp = nam; if (!letter(*cp) - ) { return(FALSE); - } else { while(*++cp - ){if (!alphanum(*cp) - ) { return(FALSE); - ;} - ;} - ;} - return(TRUE); + ) { + return (FALSE); + } else { + while (*++cp) { + if (!alphanum(*cp) + ) { + return (FALSE); + ; + }; + } + ; + } + return (TRUE); } -static void (*namfn)(); +static void (*namfn) (); namscan(fn) - void (*fn)(); +void (*fn) (); { - namfn=fn; + namfn = fn; namwalk(namep); } -static void namwalk(np) - register NAMPTR np; +static void namwalk(np) +register NAMPTR np; { - if (np - ) { namwalk(np->namlft); - (*namfn)(np); + if (np) { + namwalk(np->namlft); + (*namfn) (np); namwalk(np->namrgt); - ;} + ; + } } -void printnam(n) - NAMPTR n; +void printnam(n) +NAMPTR n; { - register STRING s; + register STRING s; sigchk(); - if (s=n->namval - ) { prs(n->namid); - prc('='); prs(s); + if (s = n->namval) { + prs(n->namid); + prc('='); + prs(s); newline(); - ;} + ; + } } -static STRING staknam(n) - register NAMPTR n; +static STRING staknam(n) +register NAMPTR n; { - register STRING p; + register STRING p; - p=movstr(n->namid,staktop); - p=movstr("=",p); - p=movstr(n->namval,p); - return(getstak(p+1-ADR(stakbot))); + p = movstr(n->namid, staktop); + p = movstr("=", p); + p = movstr(n->namval, p); + return (getstak(p + 1 - ADR(stakbot))); } -void exname(n) - register NAMPTR n; +void exname(n) +register NAMPTR n; { - if (n->namflg&N_EXPORT - ) { free(n->namenv); + if (n->namflg & N_EXPORT) { + free(n->namenv); n->namenv = make(n->namval); - } else { free(n->namval); + } else { + free(n->namval); n->namval = make(n->namenv); - ;} + ; + } } -void printflg(n) - register NAMPTR n; +void printflg(n) +register NAMPTR n; { - if (n->namflg&N_EXPORT - ) { prs(export); blank(); - ;} - if (n->namflg&N_RDONLY - ) { prs(readonly); blank(); - ;} - if (n->namflg&(N_EXPORT|N_RDONLY) - ) { prs(n->namid); newline(); - ;} + if (n->namflg & N_EXPORT) { + prs(export); + blank(); + ; + } + if (n->namflg & N_RDONLY) { + prs(readonly); + blank(); + ; + } + if (n->namflg & (N_EXPORT | N_RDONLY) + ) { + prs(n->namid); + newline(); + ; + } } -void sh_getenv(void) +void sh_getenv(void) { - register STRING *e=environ; + register STRING *e = environ; - while(*e - ){setname(*e++, N_ENVNAM) ;} + while (*e) { + setname(*e++, N_ENVNAM); + } } -static INT namec; +static INT namec; -void countnam(n) - NAMPTR n; +void countnam(n) +NAMPTR n; { namec++; } -static STRING *argnam; +static STRING *argnam; -void pushnam(n) - NAMPTR n; +void pushnam(n) +NAMPTR n; { - if (n->namval - ) { *argnam++ = staknam(n); - ;} + if (n->namval) { + *argnam++ = staknam(n); + ; + } } -STRING *sh_setenv(void) +STRING *sh_setenv(void) { - register STRING *er; + register STRING *er; - namec=0; + namec = 0; namscan(countnam); - argnam = er = (STRING *)getstak(namec*BYTESPERWORD+BYTESPERWORD); + argnam = er = + (STRING *) getstak(namec * BYTESPERWORD + BYTESPERWORD); namscan(pushnam); *argnam++ = 0; - return(er); + return (er); } diff --git a/Applications/V7/cmd/sh/name.h b/Applications/V7/cmd/sh/name.h index c444fae1..8f27a1f5 100644 --- a/Applications/V7/cmd/sh/name.h +++ b/Applications/V7/cmd/sh/name.h @@ -18,10 +18,10 @@ #define N_DEFAULT 0 struct namnod { - NAMPTR namlft; - NAMPTR namrgt; - STRING namid; - STRING namval; - STRING namenv; - INT namflg; + NAMPTR namlft; + NAMPTR namrgt; + STRING namid; + STRING namval; + STRING namenv; + INT namflg; }; diff --git a/Applications/V7/cmd/sh/print.c b/Applications/V7/cmd/sh/print.c index 4a486d24..b5e7095e 100644 --- a/Applications/V7/cmd/sh/print.c +++ b/Applications/V7/cmd/sh/print.c @@ -11,89 +11,112 @@ #include "defs.h" -CHAR numbuf[6]; +CHAR numbuf[6]; /* printing and io conversion */ newline() -{ prc(NL); +{ + prc(NL); } blank() -{ prc(SP); +{ + prc(SP); } prp() { - if ((flags&prompt)==0 && cmdadr - ) { prs(cmdadr); prs(colon); - ;} + if ((flags & prompt) == 0 && cmdadr) { + prs(cmdadr); + prs(colon); + ; + } } -void prs(as) - STRING as; +void prs(as) +STRING as; { - register STRING s; + register STRING s; - if (s=as - ) { write(output,s,length(s)-1); - ;} + if (s = as) { + write(output, s, length(s) - 1); + ; + } } -void prc(c) - CHAR c; +void prc(c) +CHAR c; { - if (c - ) { write(output,&c,1); - ;} + if (c) { + write(output, &c, 1); + ; + } } prt(t) - L_INT t; +L_INT t; { - register INT hr, min, sec; - - t += 30; t /= 60; - sec=t%60; t /= 60; - min=t%60; - if (hr=t/60 - ) { prn(hr); prc('h'); - ;} - prn(min); prc('m'); - prn(sec); prc('s'); + register INT hr, min, sec; + + t += 30; + t /= 60; + sec = t % 60; + t /= 60; + min = t % 60; + if (hr = t / 60) { + prn(hr); + prc('h'); + ; + } + prn(min); + prc('m'); + prn(sec); + prc('s'); } prn(n) - INT n; +INT n; { - itos(n); prs(numbuf); + itos(n); + prs(numbuf); } itos(n) { - register char *abuf; register POS a, i; INT pr, d; - abuf=numbuf; pr=FALSE; a=n; - for (i=10000; i!=1; i/=10 - ){ if ((pr |= (d=a/i)) ) { *abuf++=d+'0' ;} + register char *abuf; + register POS a, i; + INT pr, d; + abuf = numbuf; + pr = FALSE; + a = n; + for (i = 10000; i != 1; i /= 10) { + if ((pr |= (d = a / i))) { + *abuf++ = d + '0'; + } a %= i; - ;} - *abuf++=a+'0'; - *abuf++=0; + ; + } + *abuf++ = a + '0'; + *abuf++ = 0; } stoi(icp) -STRING icp; +STRING icp; { - register CHAR *cp = icp; - register INT r = 0; - register CHAR c; - - while((c = *cp, digit(c)) && c && r>=0 - ){ r = r*10 + c - '0'; cp++ ;} - if (r<0 || cp==icp - ) { failed(icp,badnum); - } else { return(r); - ;} + register CHAR *cp = icp; + register INT r = 0; + register CHAR c; + + while ((c = *cp, digit(c)) && c && r >= 0) { + r = r * 10 + c - '0'; + cp++; + } + if (r < 0 || cp == icp) { + failed(icp, badnum); + } else { + return (r); + ; + } } - diff --git a/Applications/V7/cmd/sh/service.c b/Applications/V7/cmd/sh/service.c index b6e9fb01..82e4e400 100644 --- a/Applications/V7/cmd/sh/service.c +++ b/Applications/V7/cmd/sh/service.c @@ -13,14 +13,14 @@ #include "defs.h" -static STRING execs(); -static void gsort(); -static INT split(); +static STRING execs(); +static void gsort(); +static INT split(); #define ARGMK 01 -INT errno; -STRING sysmsg[]; +INT errno; +STRING sysmsg[]; /* fault handling */ #define ENOMEM 12 @@ -33,338 +33,424 @@ STRING sysmsg[]; /* service routines for `execute' */ -void initio(iop) - IOPTR iop; +void initio(iop) +IOPTR iop; { - register STRING ion; - register INT iof, fd; - - if(iop - ) { iof=iop->iofile; - ion=mactrim(iop->ioname); - if(*ion && (flags&noexec)==0 - ) { if(iof&IODOC - ) { subst(chkopen(ion),(fd=tmpfil())); - close(fd); fd=chkopen(tmpout); unlink(tmpout); - } else if ( iof&IOMOV - ) { if(eq(minus,ion) - ) { fd = -1; - close(iof&IOUFD); - } else if ( (fd=stoi(ion))>=USERIO - ) { failed(ion,badfile); - } else { fd=dup(fd); - ;} - } else if ( (iof&IOPUT)==0 - ) { fd=chkopen(ion); - } else if ( flags&rshflg - ) { failed(ion,restricted); - } else if ( iof&IOAPP && (fd=open(ion,1))>=0 - ) { lseek(fd, 0L, 2); - } else { fd=create(ion); - ;} - if(fd>=0 - ) { sh_rename(fd,iof&IOUFD); - ;} - ;} + register STRING ion; + register INT iof, fd; + + if (iop) { + iof = iop->iofile; + ion = mactrim(iop->ioname); + if (*ion && (flags & noexec) == 0) { + if (iof & IODOC) { + subst(chkopen(ion), (fd = tmpfil())); + close(fd); + fd = chkopen(tmpout); + unlink(tmpout); + } else if (iof & IOMOV) { + if (eq(minus, ion) + ) { + fd = -1; + close(iof & IOUFD); + } else if ((fd = stoi(ion)) >= USERIO) { + failed(ion, badfile); + } else { + fd = dup(fd); + ; + } + } else if ((iof & IOPUT) == 0) { + fd = chkopen(ion); + } else if (flags & rshflg) { + failed(ion, restricted); + } else if (iof & IOAPP && (fd = open(ion, 1)) >= 0) { + lseek(fd, 0L, 2); + } else { + fd = create(ion); + ; + } + if (fd >= 0) { + sh_rename(fd, iof & IOUFD); + ; + }; + } initio(iop->ionxt); - ;} + ; + } } -STRING getpath(s) - STRING s; +STRING getpath(s) +STRING s; { - register STRING path; - if(any('/',s) - ) { if(flags&rshflg - ) { failed(s, restricted); - } else { return(nullstr); - ;} - } else if ( (path = pathnod.namval)==0 - ) { return(defpath); - } else { return(cpystak(path)); - ;} + register STRING path; + if (any('/', s) + ) { + if (flags & rshflg) { + failed(s, restricted); + } else { + return (nullstr); + ; + } + } else if ((path = pathnod.namval) == 0) { + return (defpath); + } else { + return (cpystak(path)); + ; + } } -INT pathopen(path, name) - register STRING path, name; +INT pathopen(path, name) +register STRING path, name; { - register UFD f; + register UFD f; - do { path=catpath(path,name); - } while ( (f=open(curstak(),0))<0 && path ); - return(f); + do { + path = catpath(path, name); + } while ((f = open(curstak(), 0)) < 0 && path); + return (f); } -STRING catpath(path,name) - register STRING path; - STRING name; +STRING catpath(path, name) +register STRING path; +STRING name; { /* leaves result on top of stack */ - register STRING scanp = path, - argp = locstak(); - - while(*scanp && *scanp!=COLON ){*argp++ = *scanp++ ;} - if(scanp!=path ) { *argp++='/' ;} - if(*scanp==COLON ) { scanp++ ;} - path=(*scanp ? scanp : 0); scanp=name; - while((*argp++ = *scanp++) ); - return(path); + register STRING scanp = path, argp = locstak(); + + while (*scanp && *scanp != COLON) { + *argp++ = *scanp++; + } + if (scanp != path) { + *argp++ = '/'; + } + if (*scanp == COLON) { + scanp++; + } + path = (*scanp ? scanp : 0); + scanp = name; + while ((*argp++ = *scanp++)); + return (path); } -static STRING xecmsg; -static STRING *xecenv; +static STRING xecmsg; +static STRING *xecenv; -void execa(at) - STRING at[]; +void execa(at) +STRING at[]; { - register STRING path; - register STRING *t = at; + register STRING path; + register STRING *t = at; - if((flags&noexec)==0 - ) { xecmsg=notfound; path=getpath(*t); + if ((flags & noexec) == 0) { + xecmsg = notfound; + path = getpath(*t); namscan(exname); - xecenv=sh_setenv(); - while(path=execs(path,t) ); - failed(*t,xecmsg); - ;} + xecenv = sh_setenv(); + while (path = execs(path, t)); + failed(*t, xecmsg); + ; + } } -static STRING execs(ap,t) - STRING ap; - register STRING t[]; +static STRING execs(ap, t) +STRING ap; +register STRING t[]; { - register STRING p, prefix; + register STRING p, prefix; - prefix=catpath(ap,t[0]); - trim(p=curstak()); + prefix = catpath(ap, t[0]); + trim(p = curstak()); sigchk(); - execve(p, &t[0] ,xecenv); - switch(errno) { - case ENOEXEC: - flags=0; - comdiv=0; ioset=0; - clearup(); /* remove open files and for loop junk */ - if(input ) { close(input) ;} - close(output); output=2; - input=chkopen(p); + execve(p, &t[0], xecenv); + switch (errno) { + case ENOEXEC: + flags = 0; + comdiv = 0; + ioset = 0; + clearup(); /* remove open files and for loop junk */ + if (input) { + close(input); + } + close(output); + output = 2; + input = chkopen(p); /* set up new args */ setargs(t); - longjmp(subshell,1); + longjmp(subshell, 1); - case ENOMEM: - failed(p,toobig); + case ENOMEM: + failed(p, toobig); - case E2BIG: - failed(p,arglist); + case E2BIG: + failed(p, arglist); - case ETXTBSY: - failed(p,txtbsy); + case ETXTBSY: + failed(p, txtbsy); - default: - xecmsg=badexec; - case ENOENT: - return(prefix); + default: + xecmsg = badexec; + case ENOENT: + return (prefix); } } /* for processes to be waited for */ #define MAXP 20 -static INT pwlist[MAXP]; -static INT pwc; +static INT pwlist[MAXP]; +static INT pwc; postclr() { - register INT *pw = pwlist; + register INT *pw = pwlist; - while(pw <= &pwlist[pwc] - ){*pw++ = 0 ;} - pwc=0; + while (pw <= &pwlist[pwc] + ) { + *pw++ = 0; + } + pwc = 0; } -void post(pcsid) - INT pcsid; +void post(pcsid) +INT pcsid; { - register INT *pw = pwlist; - - if(pcsid - ) { while(*pw ){pw++ ;} - if(pwc >= MAXP-1 - ) { pw--; - } else { pwc++; - ;} + register INT *pw = pwlist; + + if (pcsid) { + while (*pw) { + pw++; + } + if (pwc >= MAXP - 1) { + pw--; + } else { + pwc++; + ; + } *pw = pcsid; - ;} + ; + } } -void await(i) - INT i; +void await(i) +INT i; { - INT rc=0, wx=0; - INT w; - INT ipwc = pwc; + INT rc = 0, wx = 0; + INT w; + INT ipwc = pwc; post(i); - while(pwc - ){ register INT p; - register INT sig; - INT w_hi; + while (pwc) { + register INT p; + register INT sig; + INT w_hi; { - register INT *pw=pwlist; - p=wait(&w); - while(pw <= &pwlist[ipwc] - ){if(*pw==p - ) { *pw=0; pwc--; - } else { pw++; - ;} - ;} + register INT *pw = pwlist; + p = wait(&w); + while (pw <= &pwlist[ipwc] + ) { + if (*pw == p) { + *pw = 0; + pwc--; + } else { + pw++; + ; + } + ; + } } - if(p == -1 ) { continue ;} + if (p == -1) { + continue; + } - w_hi = (w>>8)&LOBYTE; + w_hi = (w >> 8) & LOBYTE; - if(sig = w&0177 - ) { if(sig == 0177 /* ptrace! return */ - ) { prs("ptrace: "); + if (sig = w & 0177) { + if (sig == 0177 /* ptrace! return */ + ) { + prs("ptrace: "); sig = w_hi; - ;} - if(sysmsg[sig] - ) { if(i!=p || (flags&prompt)==0 ) { prp(); prn(p); blank() ;} + ; + } + if (sysmsg[sig] + ) { + if (i != p || (flags & prompt) == 0) { + prp(); + prn(p); + blank(); + } prs(sysmsg[sig]); - if(w&0200 ) { prs(coredump) ;} - ;} + if (w & 0200) { + prs(coredump); + }; + } newline(); - ;} + ; + } - if(rc==0 - ) { rc = (sig ? sig|SIGFLG : w_hi); - ;} + if (rc == 0) { + rc = (sig ? sig | SIGFLG : w_hi); + ; + } wx |= w; - ;} + ; + } - if(wx && flags&errflg - ) { exitsh(rc); - ;} - exitval=rc; exitset(); + if (wx && flags & errflg) { + exitsh(rc); + ; + } + exitval = rc; + exitset(); } -BOOL nosubst; +BOOL nosubst; trim(at) - STRING at; +STRING at; { - register STRING p; - register CHAR c; - register CHAR q=0; - - if(p=at - ) { while(c = *p - ){*p++=c&STRIP; q |= c ;} - ;} - nosubst=q"E; + register STRING p; + register CHAR c; + register CHAR q = 0; + + if (p = at) { + while (c = *p) { + *p++ = c & STRIP; + q |= c; + } + ; + } + nosubst = q & QUOTE; } -STRING mactrim(s) - STRING s; +STRING mactrim(s) +STRING s; { - register STRING t=macro(s); + register STRING t = macro(s); trim(t); - return(t); + return (t); } -STRING *scan(argn) - INT argn; +STRING *scan(argn) +INT argn; { - register ARGPTR argp = (ARGPTR)(Rcheat(gchain)&~ARGMK); - register STRING *comargn, *comargm; - - comargn=(STRING *)getstak(BYTESPERWORD*argn+BYTESPERWORD); comargm = comargn += argn; *comargn = ENDARGS; - - while(argp - ){ *--comargn = argp->argval; - if(argp = argp->argnxt - ) { trim(*comargn); - ;} - if(argp==0 || Rcheat(argp)&ARGMK - ) { gsort(comargn,comargm); + register ARGPTR argp = (ARGPTR) (Rcheat(gchain) & ~ARGMK); + register STRING *comargn, *comargm; + + comargn = (STRING *) getstak(BYTESPERWORD * argn + BYTESPERWORD); + comargm = comargn += argn; + *comargn = ENDARGS; + + while (argp) { + *--comargn = argp->argval; + if (argp = argp->argnxt) { + trim(*comargn); + ; + } + if (argp == 0 || Rcheat(argp) & ARGMK) { + gsort(comargn, comargm); comargm = comargn; - ;} + ; + } /* Lcheat(argp) &= ~ARGMK; */ - argp = (ARGPTR)(Rcheat(argp)&~ARGMK); - ;} - return(comargn); + argp = (ARGPTR) (Rcheat(argp) & ~ARGMK); + ; + } + return (comargn); } -static void gsort(from,to) - STRING from[], to[]; +static void gsort(from, to) +STRING from[], to[]; { - INT k, m, n; - register INT i, j; - - if((n=to-from)<=1 ) { return ;} - - for (j=1; j<=n; j*=2 ); - - for (m=2*j-1; m/=2; - ){ k=n-m; - for (j=0; j=0; i-=m - ){ register STRING *fromi; fromi = &from[i]; - if(cf(fromi[m],fromi[0])>0 - ) { break; - } else { STRING s; s=fromi[m]; fromi[m]=fromi[0]; fromi[0]=s; - ;} - ;} - ;} - ;} + INT k, m, n; + register INT i, j; + + if ((n = to - from) <= 1) { + return; + } + + for (j = 1; j <= n; j *= 2); + + for (m = 2 * j - 1; m /= 2;) { + k = n - m; + for (j = 0; j < k; j++) { + for (i = j; i >= 0; i -= m) { + register STRING *fromi; + fromi = &from[i]; + if (cf(fromi[m], fromi[0]) > 0) { + break; + } else { + STRING s; + s = fromi[m]; + fromi[m] = fromi[0]; + fromi[0] = s; + ; + } + ; + } + ; + } + ; + } } /* Argument list generation */ -INT getarg(ac) - COMPTR ac; +INT getarg(ac) +COMPTR ac; { - register ARGPTR argp; - register INT count=0; - register COMPTR c; - - if(c=ac - ) { argp=c->comarg; - while(argp - ){ count += split(macro(argp->argval)); - argp=argp->argnxt; - ;} - ;} - return(count); + register ARGPTR argp; + register INT count = 0; + register COMPTR c; + + if (c = ac) { + argp = c->comarg; + while (argp) { + count += split(macro(argp->argval)); + argp = argp->argnxt; + ; + } + ; + } + return (count); } -static INT split(s) - register STRING s; +static INT split(s) +register STRING s; { - register STRING argp; - register INT c; - INT count=0; - - for(;;) { - sigchk(); argp=locstak()+BYTESPERWORD; - while((c = *s++, !any(c,ifsnod.namval) && c) - ){*argp++ = c ;} - if(argp==staktop+BYTESPERWORD - ) { if(c - ) { continue; - } else { return(count); - ;} - } else if (c==0 - ) { s--; - ;} - if(c=expand(((ARGPTR)(argp=endstak(argp)))->argval,0) - ) { count += c; + register STRING argp; + register INT c; + INT count = 0; + + for (;;) { + sigchk(); + argp = locstak() + BYTESPERWORD; + while ((c = *s++, !any(c, ifsnod.namval) && c) + ) { + *argp++ = c; + } + if (argp == staktop + BYTESPERWORD) { + if (c) { + continue; + } else { + return (count); + ; + } + } else if (c == 0) { + s--; + ; + } + if (c = + expand(((ARGPTR) (argp = endstak(argp)))->argval, 0) + ) { + count += c; } else { /* assign(&fngnod, argp->argval); */ - makearg(argp); count++; - ;} + makearg(argp); + count++; + ; + } Lcheat(gchain) |= ARGMK; } } diff --git a/Applications/V7/cmd/sh/stak.c b/Applications/V7/cmd/sh/stak.c index 80abf6fe..9926d372 100644 --- a/Applications/V7/cmd/sh/stak.c +++ b/Applications/V7/cmd/sh/stak.c @@ -12,73 +12,78 @@ #include "defs.h" -STKPTR stakbot=nullstr; +STKPTR stakbot = nullstr; /* ======== storage allocation ======== */ -STKPTR getstak(asize) - INT asize; -{ /* allocate requested stack */ - register STKPTR oldstak; - register INT size; +STKPTR getstak(asize) +INT asize; +{ /* allocate requested stack */ + register STKPTR oldstak; + register INT size; - size=round(asize,BYTESPERWORD); - oldstak=stakbot; + size = round(asize, BYTESPERWORD); + oldstak = stakbot; staktop = stakbot += size; - return(oldstak); + return (oldstak); } -STKPTR locstak() -{ /* set up stack for local use - * should be followed by `endstak' - */ - if(brkend-stakbotADR(x) - ){free(stakbsy); - stakbsy = stakbsy->word; - ;} - staktop=stakbot=max(ADR(x),ADR(stakbas)); + while (ADR(stakbsy) > ADR(x) + ) { + free(stakbsy); + stakbsy = stakbsy->word; + ; + } + staktop = stakbot = max(ADR(x), ADR(stakbas)); rmtemp(x); } stakchk() { - if((brkend-stakbas)>BRKINCR+BRKINCR - ) { setbrk(-BRKINCR); - ;} + if ((brkend - stakbas) > BRKINCR + BRKINCR) { + setbrk(-BRKINCR); + ; + } } -STKPTR cpystak(x) - STKPTR x; +STKPTR cpystak(x) +STKPTR x; { - return(endstak(movstr(x,locstak()))); + return (endstak(movstr(x, locstak()))); } diff --git a/Applications/V7/cmd/sh/stak.h b/Applications/V7/cmd/sh/stak.h index 115b92b3..f110c9d4 100644 --- a/Applications/V7/cmd/sh/stak.h +++ b/Applications/V7/cmd/sh/stak.h @@ -36,7 +36,7 @@ /* for local use only since it hands * out a real address for the stack top */ -STKPTR locstak(); +STKPTR locstak(); /* Will allocate the item being used and return its * address (safe now). @@ -46,33 +46,33 @@ STKPTR locstak(); /* For use after `locstak' to hand back * new stack top and then allocate item */ -STKPTR endstak(); +STKPTR endstak(); /* Copy a string onto the stack and * allocate the space. */ -STKPTR cpystak(); +STKPTR cpystak(); /* Allocate given ammount of stack space */ -STKPTR getstak(); +STKPTR getstak(); /* A chain of ptrs of stack blocks that * have become covered by heap allocation. * `tdystak' will return them to the heap. */ -BLKPTR stakbsy; +BLKPTR stakbsy; /* Base of the entire stack */ -STKPTR stakbas; +STKPTR stakbas; /* Top of entire stack */ -STKPTR brkend; +STKPTR brkend; /* Base of current item */ -STKPTR stakbot; +STKPTR stakbot; /* Top of current item */ -STKPTR staktop; +STKPTR staktop; /* Used with tdystak */ -STKPTR savstak(); +STKPTR savstak(); diff --git a/Applications/V7/cmd/sh/string.c b/Applications/V7/cmd/sh/string.c index ddd15913..691eb049 100644 --- a/Applications/V7/cmd/sh/string.c +++ b/Applications/V7/cmd/sh/string.c @@ -15,43 +15,47 @@ /* ======== general purpose string handling ======== */ -STRING movstr(a,b) - register STRING a, b; +STRING movstr(a, b) +register STRING a, b; { - while(*b++ = *a++ ); - return(--b); + while (*b++ = *a++); + return (--b); } -INT any(c,s) - register CHAR c; - STRING s; +INT any(c, s) +register CHAR c; +STRING s; { register CHAR d; - while(d = *s++ - ){if(d==c - ) { return(TRUE); - ;} - ;} - return(FALSE); + while (d = *s++) { + if (d == c) { + return (TRUE); + ; + }; + } + return (FALSE); } -INT cf(s1, s2) - register STRING s1, s2; +INT cf(s1, s2) +register STRING s1, s2; { - while(*s1++ == *s2 - ){if(*s2++==0 - ) { return(0); - ;} - ;} - return(*--s1 - *s2); + while (*s1++ == *s2) { + if (*s2++ == 0) { + return (0); + ; + }; + } + return (*--s1 - *s2); } -INT length(as) - STRING as; +INT length(as) +STRING as; { register STRING s; - if(s=as ) { while(*s++ ); ;} - return(s-as); + if (s = as) { + while (*s++);; + } + return (s - as); } diff --git a/Applications/V7/cmd/sh/word.c b/Applications/V7/cmd/sh/word.c index cbb4eada..40de5bd9 100644 --- a/Applications/V7/cmd/sh/word.c +++ b/Applications/V7/cmd/sh/word.c @@ -21,109 +21,170 @@ static readb(); word() { - register CHAR c, d; - register CHAR *argp=locstak()+BYTESPERWORD; - INT alpha=1; - - wdnum=0; wdset=0; - - while((c=nextc(0), space(c)) ); - if(!eofmeta(c) - ) { do { if(c==LITERAL - ) { *argp++=(DQUOTE); - while((c=readc()) && c!=LITERAL - ){*argp++=(c|QUOTE); chkpr(c) ;} - *argp++=(DQUOTE); - } else { *argp++=(c); - if(c=='=' ) { wdset |= alpha ;} - if(!alphanum(c) ) { alpha=0 ;} - if(qotchar(c) - ) { d=c; - while((*argp++=(c=nextc(d))) && c!=d - ){chkpr(c) ;} - ;} - ;} - } while ( (c=nextc(0), !eofmeta(c)) ); - argp=endstak(argp); - if(!letter(((ARGPTR)argp)->argval[0]) ) { wdset=0 ;} - - peekc=c|MARK; - if(((ARGPTR)argp)->argval[1]==0 && (d=((ARGPTR)argp)->argval[0], digit(d)) && (c=='>' || c=='<') - ) { word(); wdnum=d-'0'; - } else { /*check for reserved words*/ - if(reserv==FALSE || (wdval=syslook(((ARGPTR)argp)->argval,reserved))==0 - ) { wdarg=(ARGPTR)argp; wdval=0; - ;} - ;} - - } else if ( dipchar(c) - ) { if((d=nextc(0))==c - ) { wdval = c|SYMREP; - } else { peekc = d|MARK; wdval = c; - ;} - } else { if((wdval=c)==EOF - ) { wdval=EOFSYM; - ;} - if(iopend && eolchar(c) - ) { copy(iopend); iopend=0; - ;} - ;} - reserv=FALSE; - return(wdval); + register CHAR c, d; + register CHAR *argp = locstak() + BYTESPERWORD; + INT alpha = 1; + + wdnum = 0; + wdset = 0; + + while ((c = nextc(0), space(c))); + if (!eofmeta(c) + ) { + do { + if (c == LITERAL) { + *argp++ = (DQUOTE); + while ((c = readc()) && c != LITERAL) { + *argp++ = (c | QUOTE); + chkpr(c); + } + *argp++ = (DQUOTE); + } else { + *argp++ = (c); + if (c == '=') { + wdset |= alpha; + } + if (!alphanum(c)) { + alpha = 0; + } + if (qotchar(c) + ) { + d = c; + while ((*argp++ = (c = nextc(d))) + && c != d) { + chkpr(c); + } + ; + }; + } + } while ((c = nextc(0), !eofmeta(c))); + argp = endstak(argp); + if (!letter(((ARGPTR) argp)->argval[0])) { + wdset = 0; + } + + peekc = c | MARK; + if (((ARGPTR) argp)->argval[1] == 0 + && (d = ((ARGPTR) argp)->argval[0], digit(d)) + && (c == '>' || c == '<') + ) { + word(); + wdnum = d - '0'; + } else { /*check for reserved words */ + if (reserv == FALSE + || (wdval = + syslook(((ARGPTR) argp)->argval, + reserved)) == 0) { + wdarg = (ARGPTR) argp; + wdval = 0; + ; + }; + } + + } else if (dipchar(c) + ) { + if ((d = nextc(0)) == c) { + wdval = c | SYMREP; + } else { + peekc = d | MARK; + wdval = c; + ; + } + } else { + if ((wdval = c) == EOF) { + wdval = EOFSYM; + ; + } + if (iopend && eolchar(c) + ) { + copy(iopend); + iopend = 0; + ; + }; + } + reserv = FALSE; + return (wdval); } nextc(quote) - CHAR quote; +CHAR quote; { - register CHAR c, d; - if((d=readc())==ESCAPE - ) { if((c=readc())==NL - ) { chkpr(NL); d=nextc(quote); - } else if ( quote && c!=quote && !escchar(c) - ) { peekc=c|MARK; - } else { d = c|QUOTE; - ;} - ;} - return(d); + register CHAR c, d; + if ((d = readc()) == ESCAPE) { + if ((c = readc()) == NL) { + chkpr(NL); + d = nextc(quote); + } else if (quote && c != quote && !escchar(c) + ) { + peekc = c | MARK; + } else { + d = c | QUOTE; + ; + } + ; + } + return (d); } readc() { - register CHAR c; - register INT len; - register FILE f; - -retry: - if(peekc - ) { c=peekc; peekc=0; - } else if ( (f=standin, f->fnxt!=f->fend) - ) { if((c = *f->fnxt++)==0 - ) { if(f->feval - ) { if(estabf(*f->feval++) - ) { c=EOF; - } else { c=SP; - ;} - } else { goto retry; /* = c=readc(); */ - ;} - ;} - if(flags&readpr && standin->fstak==0 ) { prc(c) ;} - if(c==NL ) { f->flin++ ;} - } else if ( f->feof || f->fdes<0 - ) { c=EOF; f->feof++; - } else if ( (len=readb())<=0 - ) { close(f->fdes); f->fdes = -1; c=EOF; f->feof++; - } else { f->fend = (f->fnxt = f->fbuf)+len; + register CHAR c; + register INT len; + register FILE f; + + retry: + if (peekc) { + c = peekc; + peekc = 0; + } else if ((f = standin, f->fnxt != f->fend) + ) { + if ((c = *f->fnxt++) == 0) { + if (f->feval) { + if (estabf(*f->feval++) + ) { + c = EOF; + } else { + c = SP; + ; + } + } else { + goto retry; /* = c=readc(); */ + ; + } + ; + } + if (flags & readpr && standin->fstak == 0) { + prc(c); + } + if (c == NL) { + f->flin++; + } + } else if (f->feof || f->fdes < 0) { + c = EOF; + f->feof++; + } else if ((len = readb()) <= 0) { + close(f->fdes); + f->fdes = -1; + c = EOF; + f->feof++; + } else { + f->fend = (f->fnxt = f->fbuf) + len; goto retry; - ;} - return(c); + ; + } + return (c); } static readb() { - register FILE f=standin; - register INT len; - - do { if(trapnote&SIGSET ) { newline(); sigchk() ;} - } while ( (len=read(f->fdes,f->fbuf,f->fsiz))<0 && trapnote ); - return(len); + register FILE f = standin; + register INT len; + + do { + if (trapnote & SIGSET) { + newline(); + sigchk(); + } + } while ((len = read(f->fdes, f->fbuf, f->fsiz)) < 0 && trapnote); + return (len); } diff --git a/Applications/V7/cmd/sh/xec.c b/Applications/V7/cmd/sh/xec.c index 68456a78..c50fd88a 100644 --- a/Applications/V7/cmd/sh/xec.c +++ b/Applications/V7/cmd/sh/xec.c @@ -13,9 +13,9 @@ #include "defs.h" #include "sym.h" -static INT parent; +static INT parent; -extern SYSTAB commands; +extern SYSTAB commands; @@ -23,147 +23,225 @@ extern SYSTAB commands; execute(argt, execflg, pf1, pf2) - TREPTR argt; - INT *pf1, *pf2; +TREPTR argt; +INT *pf1, *pf2; { /* `stakbot' is preserved by this routine */ - register TREPTR t; - STKPTR sav=savstak(); + register TREPTR t; + STKPTR sav = savstak(); sigchk(); - if( (t=argt) && execbrk==0 - ) { register INT treeflgs; - INT oldexit, type; - register STRING *com; + if ((t = argt) && execbrk == 0) { + register INT treeflgs; + INT oldexit, type; + register STRING *com; - treeflgs = t->tretyp; type = treeflgs&COMMSK; - oldexit=exitval; exitval=0; + treeflgs = t->tretyp; + type = treeflgs & COMMSK; + oldexit = exitval; + exitval = 0; - switch(type) { + switch (type) { case TCOM: { - STRING a1; - INT argn, internal; - ARGPTR schain=gchain; - IOPTR io=t->treio; - gchain=0; - argn = getarg(t); - com=scan(argn); - a1=com[1]; gchain=schain; - - if( (internal=syslook(com[0],commands)) || argn==0 - ) { setlist(((COMPTR)t)->comset, 0); - ;} - - if( argn && (flags&noexec)==0 - ) { /* print command if execpr */ - if( flags&execpr - ) { argn=0; prs(execpmsg); - while(com[argn]!=ENDARGS - ){prs(com[argn++]); blank() ;} - newline(); - ;} - - switch(internal) { - - case SYSDOT: - if( a1 - ) { register INT f; - - if( (f=pathopen(getpath(a1), a1)) < 0 - ) { failed(a1,notfound); - } else { execexp(0,f); - ;} - ;} - break; - - case SYSTIMES: - { - L_INT t[4]; times(t); - prt(t[2]); blank(); prt(t[3]); newline(); + STRING a1; + INT argn, internal; + ARGPTR schain = gchain; + IOPTR io = t->treio; + gchain = 0; + argn = getarg(t); + com = scan(argn); + a1 = com[1]; + gchain = schain; + + if ((internal = syslook(com[0], commands)) + || argn == 0) { + setlist(((COMPTR) t)->comset, 0); + ; + } + + if (argn && (flags & noexec) == 0) { /* print command if execpr */ + if (flags & execpr) { + argn = 0; + prs(execpmsg); + while (com[argn] != + ENDARGS) { + prs(com[argn++]); + blank(); + } + newline(); + ; } - break; - - case SYSEXIT: - exitsh(a1?stoi(a1):oldexit); - - case SYSNULL: - io=0; - break; - - case SYSCONT: - execbrk = -loopcnt; break; - - case SYSBREAK: - if( (execbrk=loopcnt) && a1 - ) { breakcnt=stoi(a1); - ;} - break; - - case SYSTRAP: - if( a1 - ) { BOOL clear; - if( (clear=digit(*a1))==0 - ) { ++com; - ;} - while(*++com - ){INT i; - if( (i=stoi(*com))>=MAXTRAP || i= + MAXTRAP + || i < + MINTRAP) + { + failed + (*com, + badtrap); + } else + if + (clear) + { + clrsig + (i); + } else { + replace + (&trapcom + [i], + a1); + if (*a1) { + getsig + (i); + } else { + ignsig + (i); + ; + } + ; + } + ; + } + } else { /* print out current traps */ + INT i; + + for (i = 0; + i < MAXTRAP; + i++) { + if (trapcom + [i] + ) { + prn(i); + prs(colon); + prs(trapcom[i]); + newline + (); + ; + }; + } + ; + } + break; + + case SYSEXEC: + com++; + initio(io); + ioset = 0; + io = 0; + if (a1 == 0) { + break; + } + + case SYSLOGIN: + flags |= forked; + oldsigs(); + execa(com); + done(); + + case SYSCD: + if (flags & rshflg) { + failed(com[0], + restricted); + } else + if ((a1 == 0 + && (a1 = + homenod. + namval) == 0) + || chdir(a1) < 0) { + failed(a1, baddir); + ; + } + break; + + case SYSSHFT: + if (dolc < 1) { + error(badshift); + } else { + dolv++; + dolc--; + ; + } + assnum(&dolladr, dolc); + break; + + case SYSWAIT: + await(-1); + break; + + case SYSREAD: + exitval = readvar(&com[1]); + break; /* case SYSTST: @@ -171,98 +249,142 @@ execute(argt, execflg, pf1, pf2) break; */ - case SYSSET: - if( a1 - ) { INT argc; - argc = options(argn,com); - if( argc>1 - ) { setargs(com+argn-argc); - ;} - } else if ( ((COMPTR)t)->comset==0 - ) { /*scan name chain and print*/ - namscan(printnam); - ;} - break; - - case SYSRDONLY: - exitval=N_RDONLY; - case SYSXPORT: - if( exitval==0 ) { exitval=N_EXPORT; ;} - - if( a1 - ) { while(*++com - ){attrib(lookup(*com), exitval) ;} - } else { namscan(printflg); - ;} - exitval=0; - break; - - case SYSEVAL: - if( a1 - ) { execexp(a1,&com[2]); - ;} - break; - - case SYSUMASK: - if (a1) { - int c, i; - i = 0; - while ((c = *a1++) >= '0' && - c <= '7') - i = (i << 3) + c - '0'; - umask(i); - } else { - int i, j; - umask(i = umask(0)); - prc('0'); - for (j = 6; j >= 0; j -= 3) - prc(((i>>j)&07) + '0'); - newline(); - } - break; - - default: - internal=builtin(argn,com); + case SYSSET: + if (a1) { + INT argc; + argc = + options(argn, + com); + if (argc > 1) { + setargs(com + + + argn + - + argc); + ; + } + } else if (((COMPTR) t)->comset == 0) { /*scan name chain and print */ + namscan(printnam); + ; + } + break; + + case SYSRDONLY: + exitval = N_RDONLY; + case SYSXPORT: + if (exitval == 0) { + exitval = + N_EXPORT;; + } + + if (a1) { + while (*++com) { + attrib + (lookup + (*com), + exitval); + } + } else { + namscan(printflg); + ; + } + exitval = 0; + break; + + case SYSEVAL: + if (a1) { + execexp(a1, + &com[2]); + ; + } + break; + + case SYSUMASK: + if (a1) { + int c, i; + i = 0; + while ((c = + *a1++) >= + '0' + && c <= '7') + i = (i << + 3) + + c - + '0'; + umask(i); + } else { + int i, j; + umask(i = + umask(0)); + prc('0'); + for (j = 6; j >= 0; + j -= 3) + prc(((i >> + j) & + 07) + + '0'); + newline(); + } + break; + + default: + internal = + builtin(argn, com); - } + } - if( internal - ) { if( io ) { error(illegal) ;} - chktrap(); + if (internal) { + if (io) { + error(illegal); + } + chktrap(); + break; + ; + } + } else if (t->treio == 0) { break; - ;} - } else if ( t->treio==0 - ) { break; - ;} + ; + } } - + case TFORK: - if( execflg && (treeflgs&(FAMP|FPOU))==0 - ) { parent=0; - } else { while((parent=fork()) == -1 - ){sigchk(); alarm(10); pause() ;} - ;} - - if( parent - ) { /* This is the parent branch of fork; */ + if (execflg && (treeflgs & (FAMP | FPOU)) == 0) { + parent = 0; + } else { + while ((parent = fork()) == -1) { + sigchk(); + alarm(10); + pause(); + } + ; + } + + if (parent) { /* This is the parent branch of fork; */ /* it may or may not wait for the child. */ - if( treeflgs&FPRS && flags&ttyflg - ) { prn(parent); newline(); - ;} - if( treeflgs&FPCL ) { closepipe(pf1) ;} - if( (treeflgs&(FAMP|FPOU))==0 - ) { await(parent); - } else if ( (treeflgs&FAMP)==0 - ) { post(parent); - } else { assnum(&pcsadr, parent); - ;} + if (treeflgs & FPRS && flags & ttyflg) { + prn(parent); + newline(); + ; + } + if (treeflgs & FPCL) { + closepipe(pf1); + } + if ((treeflgs & (FAMP | FPOU)) == 0) { + await(parent); + } else if ((treeflgs & FAMP) == 0) { + post(parent); + } else { + assnum(&pcsadr, parent); + ; + } chktrap(); break; } else { /* this is the forked branch (child) of execute */ - flags |= forked; iotemp=0; + flags |= forked; + iotemp = 0; postclr(); settmp(); @@ -270,155 +392,211 @@ execute(argt, execflg, pf1, pf2) /* Reset ramaining signals to parent */ /* except for those `lost' by trap */ oldsigs(); - if( treeflgs&FINT - ) { signal(INTR,1); signal(QUIT,1); - ;} + if (treeflgs & FINT) { + signal(INTR, 1); + signal(QUIT, 1); + ; + } /* pipe in or out */ - if( treeflgs&FPIN - ) { sh_rename(pf1[INPIPE],0); + if (treeflgs & FPIN) { + sh_rename(pf1[INPIPE], 0); close(pf1[OTPIPE]); - ;} - if( treeflgs&FPOU - ) { sh_rename(pf2[OTPIPE],1); + ; + } + if (treeflgs & FPOU) { + sh_rename(pf2[OTPIPE], 1); close(pf2[INPIPE]); - ;} + ; + } /* default std input for & */ - if( treeflgs&FINT && ioset==0 - ) { sh_rename(chkopen(devnull),0); - ;} + if (treeflgs & FINT && ioset == 0) { + sh_rename(chkopen(devnull), 0); + ; + } /* io redirection */ initio(t->treio); - if( type!=TCOM - ) { execute(((FORKPTR)t)->forktre,1); - } else if ( com[0]!=ENDARGS - ) { setlist(((COMPTR)t)->comset,N_EXPORT); + if (type != TCOM) { + execute(((FORKPTR) t)->forktre, 1); + } else if (com[0] != ENDARGS) { + setlist(((COMPTR) t)->comset, + N_EXPORT); execa(com); - ;} + ; + } done(); - ;} + ; + } case TPAR: - sh_rename(dup(2),output); - execute(((PARPTR)t)->partre,execflg); + sh_rename(dup(2), output); + execute(((PARPTR) t)->partre, execflg); done(); case TFIL: { - INT pv[2]; chkpipe(pv); - if( execute(((LSTPTR)t)->lstlef, 0, pf1, pv)==0 - ) { execute(((LSTPTR)t)->lstrit, execflg, pv, pf2); - } else { closepipe(pv); - ;} + INT pv[2]; + chkpipe(pv); + if (execute + (((LSTPTR) t)->lstlef, 0, pf1, + pv) == 0) { + execute(((LSTPTR) t)->lstrit, + execflg, pv, pf2); + } else { + closepipe(pv); + ; + } } break; case TLST: - execute(((LSTPTR)t)->lstlef,0); - execute(((LSTPTR)t)->lstrit,execflg); + execute(((LSTPTR) t)->lstlef, 0); + execute(((LSTPTR) t)->lstrit, execflg); break; case TAND: - if( execute(((LSTPTR)t)->lstlef,0)==0 - ) { execute(((LSTPTR)t)->lstrit,execflg); - ;} + if (execute(((LSTPTR) t)->lstlef, 0) == 0) { + execute(((LSTPTR) t)->lstrit, execflg); + ; + } break; case TORF: - if( execute(((LSTPTR)t)->lstlef,0)!=0 - ) { execute(((LSTPTR)t)->lstrit,execflg); - ;} + if (execute(((LSTPTR) t)->lstlef, 0) != 0) { + execute(((LSTPTR) t)->lstrit, execflg); + ; + } break; case TFOR: { - NAMPTR n = lookup(((FORPTR)t)->fornam); - STRING *args; - DOLPTR argsav=0; - - if( ((FORPTR)t)->forlst==0 - ) { args=dolv+1; - argsav=useargs(); - } else { ARGPTR schain=gchain; - gchain=0; - trim((args=scan(getarg(((FORPTR)t)->forlst)))[0]); - gchain=schain; - ;} - loopcnt++; - while(*args!=ENDARGS && execbrk==0 - ){assign(n,*args++); - execute(((FORPTR)t)->fortre,0); - if( execbrk<0 ) { execbrk=0 ;} - ;} - if( breakcnt ) { breakcnt-- ;} - execbrk=breakcnt; loopcnt--; - argfor=freeargs(argsav); + NAMPTR n = lookup(((FORPTR) t)->fornam); + STRING *args; + DOLPTR argsav = 0; + + if (((FORPTR) t)->forlst == 0) { + args = dolv + 1; + argsav = useargs(); + } else { + ARGPTR schain = gchain; + gchain = 0; + trim((args = + scan(getarg + (((FORPTR) t)-> + forlst)))[0]); + gchain = schain; + ; + } + loopcnt++; + while (*args != ENDARGS && execbrk == 0) { + assign(n, *args++); + execute(((FORPTR) t)->fortre, 0); + if (execbrk < 0) { + execbrk = 0; + }; + } + if (breakcnt) { + breakcnt--; + } + execbrk = breakcnt; + loopcnt--; + argfor = freeargs(argsav); } break; case TWH: case TUN: { - INT i=0; - - loopcnt++; - while(execbrk==0 && (execute(((WHPTR)t)->whtre,0)==0)==(type==TWH) - ){i=execute(((WHPTR)t)->dotre,0); - if( execbrk<0 ) { execbrk=0 ;} - ;} - if( breakcnt ) { breakcnt-- ;} - execbrk=breakcnt; loopcnt--; exitval=i; + INT i = 0; + + loopcnt++; + while (execbrk == 0 + && (execute(((WHPTR) t)->whtre, 0) + == 0) == (type == TWH) + ) { + i = execute(((WHPTR) t)->dotre, 0); + if (execbrk < 0) { + execbrk = 0; + }; + } + if (breakcnt) { + breakcnt--; + } + execbrk = breakcnt; + loopcnt--; + exitval = i; } break; case TIF: - if( execute(((IFPTR)t)->iftre,0)==0 - ) { execute(((IFPTR)t)->thtre,execflg); - } else { execute(((IFPTR)t)->eltre,execflg); - ;} + if (execute(((IFPTR) t)->iftre, 0) == 0) { + execute(((IFPTR) t)->thtre, execflg); + } else { + execute(((IFPTR) t)->eltre, execflg); + ; + } break; case TSW: { - register STRING r = mactrim(((SWPTR)t)->swarg); - t=(TREPTR)((SWPTR)t)->swlst; - while(t - ){ARGPTR rex=((REGPTR)t)->regptr; - while(rex - ){register STRING s; - if( gmatch(r,s=macro(rex->argval)) || (trim(s), eq(r,s)) - ) { execute(((REGPTR)t)->regcom,0); - t=0; break; - } else { rex=((ARGPTR)rex)->argnxt; - ;} - ;} - if( t ) { t=(TREPTR)((REGPTR)t)->regnxt ;} - ;} + register STRING r = + mactrim(((SWPTR) t)->swarg); + t = (TREPTR) ((SWPTR) t)->swlst; + while (t) { + ARGPTR rex = ((REGPTR) t)->regptr; + while (rex) { + register STRING s; + if (gmatch + (r, s = + macro(rex->argval)) + || (trim(s), eq(r, s)) + ) { + execute(((REGPTR) + t)-> + regcom, 0); + t = 0; + break; + } else { + rex = + ((ARGPTR) + rex)->argnxt; + ; + } + ; + } + if (t) { + t = (TREPTR) ((REGPTR) t)-> + regnxt; + }; + } } break; } exitset(); - ;} + ; + } sigchk(); tdystak(sav); - return(exitval); + return (exitval); } -execexp(s,f) - STRING s; - UFD f; +execexp(s, f) +STRING s; +UFD f; { - FILEBLK fb; + FILEBLK fb; push(&fb); - if( s - ) { estabf(s); fb.feval=(STRING *)f; - } else if ( f>=0 - ) { initf(f); - ;} - execute(cmd(NL, NLFLG|MTFLG),0); + if (s) { + estabf(s); + fb.feval = (STRING *) f; + } else if (f >= 0) { + initf(f); + ; + } + execute(cmd(NL, NLFLG | MTFLG), 0); pop(); }