Pre-ansification changes for bin/sh
authorNick Downing <downing.nick@gmail.com>
Mon, 30 Jan 2017 00:09:26 +0000 (11:09 +1100)
committerNick Downing <downing.nick@gmail.com>
Mon, 30 Jan 2017 05:10:55 +0000 (16:10 +1100)
41 files changed:
.gitignore
bin/csh/Makefile
bin/csh/sh.c
bin/csh/sh.end.c [deleted file]
bin/csh/sh.h
bin/csh/sh.misc.c
bin/sh/Makefile
bin/sh/_ctype.h [moved from bin/sh/ctype.h with 97% similarity]
bin/sh/args.c
bin/sh/blok.c
bin/sh/builtin.c
bin/sh/cmd.c
bin/sh/conflicts.txt [new file with mode: 0644]
bin/sh/ctype.c
bin/sh/defs.h
bin/sh/demac.sed
bin/sh/dup.h
bin/sh/error.c
bin/sh/expand.c
bin/sh/fault.c
bin/sh/groups.txt [new file with mode: 0644]
bin/sh/io.c
bin/sh/macro.c
bin/sh/main.c
bin/sh/mode.h
bin/sh/msg.c
bin/sh/name.c
bin/sh/name.h
bin/sh/print.c
bin/sh/service.c
bin/sh/setbrk.c
bin/sh/stak.c
bin/sh/stak.h
bin/sh/string.c
bin/sh/sym.h
bin/sh/timeout.h
bin/sh/uniqify.sed [new file with mode: 0644]
bin/sh/word.c
bin/sh/xec.c
cproto-4.6/lex.l
scripts/ansify.sh

index 49cf472..2dc9feb 100644 (file)
@@ -9,6 +9,7 @@
 *.usedby
 *.uses
 .xify
+ansify.log
 bin/adb/adb
 bin/adb/instrs.adb
 bin/ar
index 34e1982..4e14011 100644 (file)
@@ -21,10 +21,10 @@ CTAGS=      /usr/ucb/ctags
 LIBES=
 SCCS=  sccs
 
-OBJS=  malloc.o doprnt.o printf.o vprintf.o sh.o sh.char.o sh.data.o \
-       sh.dir.o sh.dol.o sh.err.o sh.exec.o sh.exp.o sh.file.o sh.func.o \
-       sh.glob.o sh.hist.o sh.init.o sh.lex.o sh.misc.o sh.parse.o \
-       sh.print.o sh.proc.o sh.sem.o sh.set.o sh.time.o sh.end.o
+OBJS=  doprnt.o malloc.o printf.o sh.char.o sh.data.o sh.dir.o sh.dol.o \
+       sh.err.o sh.exec.o sh.exp.o sh.file.o sh.func.o sh.glob.o sh.hist.o \
+       sh.init.o sh.lex.o sh.misc.o sh.o sh.parse.o sh.print.o sh.proc.o \
+       sh.sem.o sh.set.o sh.time.o vprintf.o
 
 # do things the standard way for Linux hosted version, fix this properly later
 csh: ${OBJS}
index f13ba7f..51cad05 100644 (file)
@@ -55,11 +55,15 @@ bool        enterhist = 0;
 /*extern       gid_t getegid(), getgid();*/
 /*extern       uid_t geteuid(), getuid();*/
 
+/* end of data segment, formerly done by linker using dummy array "end" */
+char   *end;
+
 void main(c, av) int c; char **av; {
        register char **v, *cp;
        register int f;
        struct sigvec osv;
 
+       end = (char *)sbrk(0);
        settimes();                     /* Immed. estab. timing base */
        v = av;
        if (eq(v[0], "a.out"))          /* A.out's are quittable */
diff --git a/bin/csh/sh.end.c b/bin/csh/sh.end.c
deleted file mode 100644 (file)
index 0ddd16d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-char end[0];
index c320420..7165f6c 100644 (file)
@@ -405,7 +405,6 @@ extern char HISTSUB;                        /* auto-substitute character */
  * In lines for frequently called functions
  */
 #define XFREE(cp) { \
-       extern char end[]; \
        char stack; \
        if ((cp) >= end && (cp) < &stack) \
                free(cp); \
@@ -494,6 +493,9 @@ extern struct       mesg {
        char    *pname;         /* print name */
 } mesg[];
 
+/* end of data segment, formerly done by linker using dummy array "end" */
+extern char    *end;
+
 #ifndef NORETURN
 #ifdef __GNUC__
 #define NORETURN __attribute__ ((__noreturn__))
index ae40114..1ab3d9f 100644 (file)
@@ -32,14 +32,10 @@ int any(c, s) register int c; register char *s; {
 }
 
 int onlyread(cp) char *cp; {
-       extern char end[];
-
        return (cp < end);
 }
 
 void xfree(cp) char *cp; {
-       extern char end[];
-
        if (cp >= end && cp < (char *) &cp)
                free(cp);
 }
index 1f52a7e..b733cc6 100644 (file)
@@ -1,5 +1,8 @@
 #      Makefile        4.5     83/07/01
 #
+OBJS=  args.o blok.o builtin.o cmd.o ctype.o error.o expand.o fault.o io.o \
+       macro.o main.o msg.o name.o print.o service.o setbrk.o stak.o \
+       string.o word.o xec.o
 CFLAGS = -O -w
 
 all:   sh
@@ -12,20 +15,13 @@ cmp:        sh
        cmp sh /bin/sh
        rm sh *.o
 
-sh:    setbrk.o
-sh:    builtin.o blok.o stak.o
-sh:    cmd.o fault.o main.o
-sh:    word.o string.o name.o args.o
-sh:    xec.o service.o error.o io.o
-sh:    print.o macro.o expand.o
-sh:    ctype.o msg.o
 blok.o:                brkincr.h
 fault.o:       brkincr.h
 main.o:                brkincr.h
 stak.o:                brkincr.h
 
-sh:
-       cc -o sh *.o
+sh: ${OBJS}
+       ${CC} -o sh ${OBJS}
 
 install:
        install -s sh $(DESTDIR)/bin
similarity index 97%
rename from bin/sh/ctype.h
rename to bin/sh/_ctype.h
index afe9ee5..7aa92eb 100644 (file)
@@ -1,6 +1,5 @@
 /*     ctype.h 4.1     82/05/07        */
 
-#
 /*
  *     UNIX shell
  *
@@ -68,7 +67,7 @@
 #define _IDCH  (T_IDC|T_DIG)
 #define _META  (T_SPC|T_DIP|T_MET|T_EOR)
 
-char   _ctype1[];
+extern char    _ctype1[];
 
 /* nb these args are not call by value !!!! */
 #define        space(c)        (((c)&0200)==0 && _ctype1[c]&(T_SPC))
@@ -79,7 +78,7 @@ char  _ctype1[];
 #define subchar(c)     (((c)&0200)==0 && _ctype1[c]&(T_SUB|T_QOT))
 #define escchar(c)     (((c)&0200)==0 && _ctype1[c]&(T_ESC))
 
-char   _ctype2[];
+extern char    _ctype2[];
 
 #define        digit(c)        (((c)&0200)==0 && _ctype2[c]&(T_DIG))
 #define fngchar(c)     (((c)&0200)==0 && _ctype2[c]&(T_FNG))
index fedc8a8..65a246b 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)args.c     4.4 7/31/85";
 #endif
 
-#
 /*
  * UNIX shell
  *
@@ -13,17 +12,17 @@ static char sccsid[] = "@(#)args.c  4.4 7/31/85";
 
 #include       "defs.h"
 
-extern char **copyargs();
+static struct dolnod   *copyargs();
 static struct dolnod   *dolh;
 
 char   flagadr[10];
 
 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
-}
+};
 
 /* ========    option handling ======== */
 
@@ -104,15 +103,14 @@ freeargs(blk)
        return(argr);
 }
 
-static char ** copyargs(from, n)
+static struct dolnod   *copyargs(from, n)
        char            *from[];
 {
-       register char **        np=alloc(sizeof(char **)*n+3*BYTESPERWORD);
+       register struct dolnod *pp = (struct dolnod *)alloc(sizeof(struct dolnod)+n*sizeof(char **));
+       register char **        np=pp->dolarg;
        register char **        fp=from;
-       register char **        pp=np;
 
-       np->doluse=1;   /* use count */
-       np=np->dolarg;
+       pp->doluse=1;   /* use count */
        dolv=np;
 
        while (n--) { *np++ = make(*fp++); }
index 2992895..53c4e30 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)blok.c     4.2 8/11/83";
 #endif
 
-#
 /*
  *     UNIX shell
  *
@@ -24,7 +23,7 @@ static char sccsid[] = "@(#)blok.c    4.2 8/11/83";
 
 unsigned               brkincr=BRKINCR;
 struct blk             *blokp;                 /*current search pointer*/
-struct blk             *bloktop=(struct blk *)(end);   /*top of arena (last blok)*/
+struct blk             *bloktop/*=(struct blk *)(end)*/;       /*top of arena (last blok)*/
 
 
 
@@ -40,8 +39,8 @@ void  *alloc(nbytes)
                do {
                        if (!busy(p)) {
                                while (!busy(q = p->word)) { p->word = q->word; }
-                               if ((void *)(q)-(void *)(p) >= rbytes) {
-                                       blokp = (struct blk *)((void *)(p)+rbytes);
+                               if ((char *)(q)-(char *)(p) >= rbytes) {
+                                       blokp = (struct blk *)((char *)(p)+rbytes);
                                        if (q > blokp) {
                                                blokp->word = p->word;
                                        }
@@ -82,13 +81,13 @@ void        addblok(reqd)
 }
 
 void   free(ap)
-       struct blk              *ap;
+       void            *ap;
 {
-       register struct blk     *p;
-
-       if ((p=ap) && p<bloktop) {
-               Lcheat((--p)->word) &= ~BUSY;
+#define p ((struct blk *)ap)
+       if (p && p<bloktop) {
+               Lcheat(p[-1].word) &= ~BUSY;
        }
+#undef p
 }
 
 #ifdef DEBUG
index 92b0569..d2f9fde 100644 (file)
@@ -2,5 +2,7 @@
 static char sccsid[] = "@(#)builtin.c  4.2 8/11/83";
 #endif
 
-builtin()
+builtin(argn, com)
+int argn;
+char **com;
 {return(0);}
index b6f839a..3fbacde 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)cmd.c      4.2 8/11/83";
 #endif
 
-#
 /*
  * UNIX shell
  *
@@ -15,16 +14,16 @@ static char sccsid[] = "@(#)cmd.c   4.2 8/11/83";
 #include       "sym.h"
 
 extern struct ionod    *inout();
-extern void    chkword();
-extern void    chksym();
+extern void            chkword();
+extern void            chksym();
 extern struct trenod   *term();
 extern struct trenod   *makelist();
 extern struct trenod   *list();
 extern struct regnod   *syncase();
 extern struct trenod   *item();
-extern void    skipnl();
-extern void    prsym();
-extern void    synbad();
+extern int             skipnl();
+extern void            prsym();
+extern void            synbad();
 
 
 /* ========    command line decoding   ========*/
@@ -36,28 +35,28 @@ struct trenod       *makefork(flgs, i)
        int             flgs;
        struct trenod           *i;
 {
-       register struct trenod  *t;
+       register struct forknod *t;
 
-       t=getstak(sizeof(struct forknod));
+       t=(struct forknod *)getstak(sizeof(struct forknod));
        t->forktyp=flgs|TFORK; t->forktre=i; t->forkio=0;
-       return(t);
+       return((struct trenod *)t);
 }
 
 static struct trenod   *makelist(type,i,r)
        int             type;
        struct trenod           *i, *r;
 {
-       register struct trenod  *t;
+       register struct lstnod  *t;
 
        if (i==0 || r==0) {
                synbad();
        }
        else {
-               t = getstak(sizeof(struct lstnod));
+               t = (struct lstnod *)getstak(sizeof(struct lstnod));
                t->lsttyp = type;
                t->lstlef = i; t->lstrit = r;
        }
-       return(t);
+       return((struct trenod *)t);
 }
 
 /*
@@ -169,7 +168,7 @@ static struct regnod        *syncase(esym)
                return(0);
        }
        else {
-               register struct regnod  *r=getstak(sizeof(struct regnod));
+               register struct regnod  *r=(struct regnod *)getstak(sizeof(struct regnod));
                r->regptr=0;
                for(;;) {
                     wdarg->argnxt=r->regptr;
@@ -210,7 +209,7 @@ static struct regnod        *syncase(esym)
 static struct trenod   *item(flag)
        bool            flag;
 {
-       register struct trenod  *t;
+       struct trenod   *_t;
        register struct ionod   *io;
 
        if (flag) {
@@ -225,33 +224,35 @@ static struct trenod      *item(flag)
 
            case CASYM:
                {
-                    
-                  t=getstak(sizeof(struct swnod));
+#define t (*(struct swnod **)&_t)
+                  t=(struct swnod *)getstak(sizeof(struct swnod));
                   chkword();
                   t->swarg=wdarg->argval;
                   skipnl(); chksym(INSYM|BRSYM);
                   t->swlst=syncase(wdval==INSYM?ESSYM:KTSYM);
                   t->swtyp=TSW;
                   break;
+#undef t
                }
 
            case IFSYM:
                {
-                    
+#define t (*(struct ifnod **)&_t)
                   register int w;
-                  t=getstak(sizeof(struct ifnod));
+                  t=(struct ifnod *)getstak(sizeof(struct ifnod));
                   t->iftyp=TIF;
                   t->iftre=cmd(THSYM,NLFLG);
                   t->thtre=cmd(ELSYM|FISYM|EFSYM,NLFLG);
                   t->eltre=((w=wdval)==ELSYM ? cmd(FISYM,NLFLG) : (w==EFSYM ? (wdval=IFSYM, item(0)) : 0));
                   if (w==EFSYM) { return(t); }
                   break;
+#undef t
                }
 
            case FORSYM:
                {
-                    
-                  t=getstak(sizeof(struct fornod));
+#define t (*(struct fornod **)&_t)
+                  t=(struct fornod *)getstak(sizeof(struct fornod));
                   t->fortyp=TFOR;
                   t->forlst=0;
                   chkword();
@@ -267,31 +268,32 @@ static struct trenod      *item(flag)
                   chksym(DOSYM|BRSYM);
                   t->fortre=cmd(wdval==DOSYM?ODSYM:KTSYM,NLFLG);
                   break;
+#undef t
                }
 
            case WHSYM:
            case UNSYM:
                {
-                    
-                  t=getstak(sizeof(struct whnod));
+#define t (*(struct whnod **)&_t)
+                  t=(struct whnod *)getstak(sizeof(struct whnod));
                   t->whtyp=(wdval==WHSYM ? TWH : TUN);
                   t->whtre = cmd(DOSYM,NLFLG);
                   t->dotre = cmd(ODSYM,NLFLG);
                   break;
+#undef t
                }
 
            case BRSYM:
-               t=cmd(KTSYM,NLFLG);
+               _t=cmd(KTSYM,NLFLG);
                break;
 
            case '(':
                {
-                    
                   register struct parnod        *p;
-                  p=getstak(sizeof(struct parnod));
+                  p=(struct parnod *)getstak(sizeof(struct parnod));
                   p->partre=cmd(')',NLFLG);
                   p->partyp=TPAR;
-                  t=makefork(0,p);
+                  _t=makefork(0,p);
                   break;
                }
 
@@ -302,12 +304,12 @@ static struct trenod      *item(flag)
 
            case 0:
                {
-                    
+#define t (*(struct comnod **)&_t)
                   register struct argnod       *argp;
                   register struct argnod       **argtail;
                   register struct argnod       **argset=0;
                   int          keywd=1;
-                  t=getstak(sizeof(struct comnod));
+                  t=(struct comnod *)getstak(sizeof(struct comnod));
                   t->comio=io; /*initial io chain*/
                   argtail = &(t->comarg);
                   while (wdval==0) {
@@ -326,18 +328,19 @@ static struct trenod      *item(flag)
 
                   t->comtyp=TCOM; t->comset=argset; *argtail=0;
                   return(t);
+#undef t
                }
 
        }
        reserv++; word();
        if (io=inout(io)) {
-               t=makefork(0,t); t->treio=io;
+               _t=makefork(0,_t); _t->treio=io;
        }
-       return(t);
+       return(_t);
 }
 
 
-static void    skipnl()
+static int     skipnl()
 {
        while ((reserv++, word()=='\n')) { chkpr('\n'); }
        return(wdval);
@@ -383,7 +386,7 @@ static struct ionod *inout(lastio)
        }
 
        chkword();
-       iop=getstak(sizeof(struct ionod)); iop->ioname=wdarg->argval; iop->iofile=iof;
+       iop=(struct ionod *)getstak(sizeof(struct ionod)); iop->ioname=wdarg->argval; iop->iofile=iof;
        if (iof&IODOC) {
             iop->iolst=iopend; iopend=iop;
        }
diff --git a/bin/sh/conflicts.txt b/bin/sh/conflicts.txt
new file mode 100644 (file)
index 0000000..66069b1
--- /dev/null
@@ -0,0 +1,11 @@
+defs.h arpa/ftp.h
+defs.h arpa/tftp.h
+defs.h assert.h
+defs.h stdio.h
+error.c arpa/ftp.h
+error.c arpa/tftp.h
+error.c stdio.h
+io.c stdio.h
+mode.h stdio.h
+stak.c assert.h
+word.c stdio.h
index 0ea55c6..20ef52f 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)ctype.c    4.2 8/11/83";
 #endif
 
-#
 /*
  *     UNIX shell
  *
@@ -13,7 +12,7 @@ static char sccsid[] = "@(#)ctype.c   4.2 8/11/83";
 
 #include       "defs.h"
 
-char   _ctype1[] {
+char   _ctype1[] {
 /*     000     001     002     003     004     005     006     007     */
        _EOF,   0,      0,      0,      0,      0,      0,      0,
 
@@ -59,10 +58,10 @@ char        _ctype1[] {
 
 /*     x       y       z       {       |       }       ~       del     */
        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,
 
@@ -108,5 +107,4 @@ char        _ctype2[] {
 
 /*     x       y       z       {       |       }       ~       del     */
        _LPC,   _LPC,   _LPC,   _CBR,   0,      _CKT,   0,      0
-}
-
+};
index d273b91..83c8631 100644 (file)
@@ -1,6 +1,5 @@
 /*     defs.h  4.4     85/03/19        */
 
-#
 /*
  *     UNIX shell
  */
 
 
 /* result type declarations */
-#define alloc malloc
 void           *alloc();
 void           addblok();
 char           *make();
 char           *movstr();
-struct trenod          *cmd();
-struct trenod          *makefork();
-struct namnod          *lookup();
+struct trenod  *cmd();
+struct trenod  *makefork();
+struct namnod  *lookup();
 void           setname();
 void           setargs();
-struct dolnod          *useargs();
+struct dolnod  *useargs();
 float          expr();
 char           *catpath();
 char           *getpath();
@@ -116,83 +114,83 @@ char              **setenv();
 #define assert(x)      ;
 
 /* temp files and io */
-int            output;
-int            ioset;
-struct ionod           *iotemp;                /* files to be deleted sometime */
-struct ionod           *iopend;                /* documents waiting to be read at '\n' */
+extern int             output;
+extern int             ioset;
+extern struct ionod    *iotemp;                /* files to be deleted sometime */
+extern struct ionod    *iopend;                /* documents waiting to be read at '\n' */
 
 /* substitution */
-int            dolc;
-char           **dolv;
-struct dolnod          *argfor;
-struct argnod          *gchain;
+extern int             dolc;
+extern char            **dolv;
+extern struct dolnod   *argfor;
+extern struct argnod   *gchain;
 
 /* stak stuff */
 #include       "stak.h"
 
 /* string constants */
-char           atline[];
-char           readmsg[];
-char           colon[];
-char           minus[];
-char           nullstr[];
-char           sptbnl[];
-char           unexpected[];
-char           endoffile[];
-char           synmsg[];
+extern char            atline[];
+extern char            readmsg[];
+extern char            colon[];
+extern char            minus[];
+extern char            nullstr[];
+extern char            sptbnl[];
+extern char            unexpected[];
+extern char            endoffile[];
+extern char            synmsg[];
 
 /* name tree and words */
-struct sysnod          reserved[];
-int            wdval;
-int            wdnum;
-struct argnod          *wdarg;
-int            wdset;
-bool           reserv;
+extern struct sysnod   reserved[];
+extern int             wdval;
+extern int             wdnum;
+extern struct argnod   *wdarg;
+extern int             wdset;
+extern bool            reserv;
 
 /* prompting */
-char           stdprompt[];
-char           supprompt[];
-char           profile[];
+extern char            stdprompt[];
+extern char            supprompt[];
+extern char            profile[];
 
 /* built in names */
-struct namnod          fngnod;
-struct namnod          ifsnod;
-struct namnod          homenod;
-struct namnod          mailnod;
-struct namnod          pathnod;
-struct namnod          ps1nod;
-struct namnod          ps2nod;
+extern struct namnod   fngnod;
+extern struct namnod   ifsnod;
+extern struct namnod   homenod;
+extern struct namnod   mailnod;
+extern struct namnod   pathnod;
+extern struct namnod   ps1nod;
+extern struct namnod   ps2nod;
 
 /* special names */
-char           flagadr[];
-char           *cmdadr;
-char           *exitadr;
-char           *dolladr;
-char           *pcsadr;
-char           *pidadr;
+extern char            flagadr[];
+extern char            *cmdadr;
+extern char            *exitadr;
+extern char            *dolladr;
+extern char            *pcsadr;
+extern char            *pidadr;
 
-char           defpath[];
+extern char            defpath[];
 
 /* names always present */
-char           mailname[];
-char           homename[];
-char           pathname[];
-char           fngname[];
-char           ifsname[];
-char           ps1name[];
-char           ps2name[];
+extern char            mailname[];
+extern char            homename[];
+extern char            pathname[];
+extern char            fngname[];
+extern char            ifsname[];
+extern char            ps1name[];
+extern char            ps2name[];
 
 /* transput */
-char           tmpout[];
-char           *tmpnam;
-int            serial;
+extern char            tmpout[];
+extern char            *tmpnam;
+extern int             serial;
 #define                TMPNAM 7
-struct fileblk         *standin;
+extern struct fileblk  *standin;
 #define input  (standin->fdes)
 #define eof    (standin->feof)
-int            peekc;
-char           *comdiv;
-char           devnull[];
+extern int             peekc;
+extern char            *comdiv;
+extern char            devnull[];
 
 /* flags */
 #define                noexec  01
@@ -210,17 +208,19 @@ char              devnull[];
 #define                readpr  010000
 #define                keyflg  020000
 #define                batchflg        040000
-int            flags;
+extern int             flags;
 
 /* error exits from various parts of shell */
 #include       <setjmp.h>
-jmp_buf                subshell;
-jmp_buf                errshell;
-jmp_buf                INTbuf;
+extern jmp_buf         subshell;
+extern jmp_buf         errshell;
+extern jmp_buf         INTbuf;
 
 /* fault handling */
 #include       "brkincr.h"
-unsigned               brkincr;
+extern unsigned                brkincr;
+extern struct blk      *blokp;                 /*current search pointer*/
+extern struct blk      *bloktop;               /*top of arena (last blok)*/
 
 #define MINTRAP        0
 #define MAXTRAP        32
@@ -235,51 +235,51 @@ unsigned          brkincr;
 #define SIGMOD 8
 
 void           fault();
-bool           trapnote;
-char           *trapcom[];
-bool           trapflg[];
-bool           trapjmp[];
+extern bool            trapnote;
+extern char            *trapcom[];
+extern bool            trapflg[];
+extern bool            trapjmp[];
 
 /* name tree and words */
-char           **environ;
-char           numbuf[];
-char           export[];
-char           readonly[];
+extern char            **environ;
+extern char            numbuf[];
+extern char            export[];
+extern char            readonly[];
 
 /* execflgs */
-int            exitval;
-bool           execbrk;
-int            loopcnt;
-int            breakcnt;
+extern int             exitval;
+extern bool            execbrk;
+extern int             loopcnt;
+extern int             breakcnt;
 
 /* messages */
-char           mailmsg[];
-char           coredump[];
-char           badopt[];
-char           badparam[];
-char           badsub[];
-char           nospace[];
-char           notfound[];
-char           badtrap[];
-char           baddir[];
-char           badshift[];
-char           illegal[];
-char           restricted[];
-char           execpmsg[];
-char           notid[];
-char           wtfailed[];
-char           badcreate[];
-char           piperr[];
-char           badopen[];
-char           badnum[];
-char           arglist[];
-char           txtbsy[];
-char           toobig[];
-char           badexec[];
-char           notfound[];
-char           badfile[];
-
-address        end[];
-
-#include       "ctype.h"
-
+extern char            mailmsg[];
+extern char            coredump[];
+extern char            badopt[];
+extern char            badparam[];
+extern char            badsub[];
+extern char            nospace[];
+extern char            notfound[];
+extern char            badtrap[];
+extern char            baddir[];
+extern char            badshift[];
+extern char            illegal[];
+extern char            restricted[];
+extern char            execpmsg[];
+extern char            notid[];
+extern char            wtfailed[];
+extern char            badcreate[];
+extern char            piperr[];
+extern char            badopen[];
+extern char            badnum[];
+extern char            arglist[];
+extern char            txtbsy[];
+extern char            toobig[];
+extern char            badexec[];
+extern char            notfound[];
+extern char            badfile[];
+
+/* end of data segment, formerly done by linker using dummy array "end" */
+extern struct blk      *end;
+
+#include       "_ctype.h"
index d025bb0..2791344 100644 (file)
@@ -94,6 +94,7 @@ s/@NAMPTR@/@struct namnod*CHECKME@/g
 s/@SYSNOD@/@struct sysnod@/g
 s/@SYSPTR@/@struct sysnod*CHECKME@/g
 s/@SYSTAB@/@struct sysnod[]CHECKME@/g
+s/@NIL@/@NULL@/g
 
 s/@FORKTYPE@/@sizeof(struct forknod)@/g
 s/@COMTYPE@/@sizeof(struct comnod)@/g
index a0049f4..66948c5 100644 (file)
@@ -1,6 +1,5 @@
 /*     dup.h   4.1     82/05/07        */
 
-#
 /*
  *     UNIX shell
  *
index 2987cb6..a686c6f 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)error.c    4.2 8/11/83";
 #endif
 
-#
 /*
  * UNIX shell
  *
@@ -45,7 +44,7 @@ failed(s1,s2)
 error(s)
        char    *s;
 {
-       failed(s,NIL);
+       failed(s,NULL);
 }
 
 exitsh(xno)
@@ -76,7 +75,8 @@ done()
                execexp(t,0);
        }
        rmtemp(0);
-       exit(exitval);
+       /* formerly exit(), may have been an oversight as we do not use stdio */
+       _exit(exitval);
 }
 
 rmtemp(base)
index c6bee1c..3c43609 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)expand.c   4.5 8/11/83";
 #endif
 
-#
 /*
  *     UNIX shell
  *
@@ -196,9 +195,8 @@ static void addg(as1,as2,as3)
 }
 
 makearg(args)
-       register char   *args;
+       register struct argnod  *args;
 {
        args->argnxt=gchain;
        gchain=args;
 }
-
index 152194b..16e715c 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)fault.c    4.3 8/11/83";
 #endif
 
-#
 /*
  * UNIX shell
  *
@@ -56,11 +55,13 @@ stdsigs()
        getsig(ALARM);
 }
 
-ignsig(n)
+void
+(*ignsig(n))()
 {
-       register int            s, i;
+       register void   (*s)();
+       register int    i;
 
-       if ((s=signal(i=n,1)&01)==0) {
+       if ((s=signal(i=n,SIG_IGN))!=SIG_IGN) {
                trapflg[i] |= SIGMOD;
        }
        return(s);
@@ -70,7 +71,7 @@ getsig(n)
 {
        register int            i;
 
-       if (trapflg[i=n]&SIGMOD || ignsig(i)==0) {
+       if (trapflg[i=n]&SIGMOD || ignsig(i)==SIG_DFL) {
                signal(i,fault);
        }
 }
diff --git a/bin/sh/groups.txt b/bin/sh/groups.txt
new file mode 100644 (file)
index 0000000..3a5b802
--- /dev/null
@@ -0,0 +1,20 @@
+args.c defs.h
+blok.c defs.h
+builtin.c defs.h
+cmd.c defs.h
+ctype.c defs.h
+error.c defs.h
+expand.c defs.h
+fault.c defs.h
+io.c defs.h
+macro.c defs.h
+main.c defs.h
+msg.c defs.h
+name.c defs.h
+print.c defs.h
+service.c defs.h
+setbrk.c defs.h
+stak.c stak.h
+string.c defs.h
+word.c defs.h
+xec.c defs.h
index e6687ae..19f361b 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)io.c       4.3 3/19/85";
 #endif
 
-#
 /*
  * UNIX shell
  *
index 8ceb346..73eeedf 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)macro.c    4.3 8/11/83";
 #endif
 
-#
 /*
  * UNIX shell
  *
@@ -62,7 +61,7 @@ retry:
        if (d==DOLLAR) {
                register int    c;
                if ((c=readc(), dolchar(c))) {
-                       struct namnod           *n=NIL;
+                       struct namnod           *n=NULL;
                        int             dolg=0;
                        bool            bra;
                        register char   *argp, *v;
index 502c908..0ee8424 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)main.c     4.3 3/19/85";
 #endif
 
-#
 /*
  * UNIX shell
  *
@@ -19,14 +18,67 @@ static char sccsid[] = "@(#)main.c  4.3 3/19/85";
 #include       <sgtty.h>
 #include       <signal.h>
 
+/* moved here from defs.h, which now just declares them extern */
+/* temp files and io */
+int            output;
+int            ioset;
+struct ionod   *iotemp;                /* files to be deleted sometime */
+struct ionod   *iopend;                /* documents waiting to be read at '\n' */
+
+/* substitution */
+int            dolc;
+char           **dolv;
+struct dolnod  *argfor;
+struct argnod  *gchain;
+
+/* name tree and words */
+int            wdval;
+int            wdnum;
+struct argnod  *wdarg;
+int            wdset;
+bool           reserv;
+
+/* special names */
+char           flagadr[];
+char           *cmdadr;
+char           *exitadr;
+char           *dolladr;
+char           *pcsadr;
+char           *pidadr;
+
+/* transput */
+char           *tmpnam;
+int            serial;
+int            peekc;
+char           *comdiv;
+
+/* flags */
+int            flags;
+
+/* error exits from various parts of shell */
+jmp_buf                subshell;
+jmp_buf                errshell;
+jmp_buf                INTbuf;
+
+/* fault handling */
+unsigned       brkincr;
+
+bool           trapnote;
+
+/* execflgs */
+int            exitval;
+bool           execbrk;
+int            loopcnt;
+int            breakcnt;
+
+/* end of data segment, formerly done by linker using dummy array "end" */
+struct blk     *end;
+
 int            output = 2;
 static bool    beenhere = 0;
 char           tmpout[20] = "/tmp/sh-";
-struct fileblk         stdfile;
-struct fileblk         *standin = &stdfile;
-#ifdef stupid
-#include       <execargs.h>
-#endif
+struct fileblk stdfile;
+struct fileblk *standin = &stdfile;
 
 extern void    exfile();
 
@@ -41,7 +93,8 @@ main(c, v)
 
        /* initialise storage allocation */
        stdsigs();
-       setbrk(BRKINCR);
+       end = (struct blk *)setbrk(BRKINCR);
+       bloktop = end;
        addblok((unsigned)0);
 
        /* set names from userenv */
index ab2ad72..1983279 100644 (file)
@@ -1,49 +1,27 @@
 /*     mode.h  4.1     82/05/07        */
 
-#
 /*
  *     UNIX shell
  */
 
+typedef char bool;
 
-#define BYTESPERWORD   (sizeof(char *))
-
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
 
 /* the following nonsense is required
  * because casts turn an Lvalue
  * into an Rvalue so two cheats
  * are necessary, one for each context.
  */
-union { int _cheat;}
-#define Lcheat(a)      ((a)._cheat)
+#define Lcheat(a)      (*(int *)&(a))
 #define Rcheat(a)      ((int)(a))
 
-
-/* address puns for storage allocation */
-typedef union {
-       struct forknod  *_forkptr;
-       struct comnod   *_comptr;
-       struct parnod   *_parptr;
-       struct ifnod    *_ifptr;
-       struct whnod    *_whptr;
-       struct fornod   *_forptr;
-       struct lstnod   *_lstptr;
-       struct blk      *_blkptr;
-       struct namnod   *_namptr;
-       char    *_bytptr;
-       }       address;
-
-
-/* for functions that do not return values */
-/*
-struct void {int vvvvvvvv;}
-*/
-
-
 /* heap storage */
 struct blk {
        struct blk      *word;
-}
+};
 
 #define        BUFSIZ  64
 struct fileblk {
@@ -56,7 +34,7 @@ struct fileblk {
        char    **feval;
        struct fileblk  *fstak;
        char    fbuf[BUFSIZ];
-}
+};
 
 /* for files not used with file descriptors */
 struct filehdr {
@@ -69,90 +47,90 @@ struct filehdr {
        char    **feval;
        struct fileblk  *fstak;
        char    _fbuf[1];
-}
+};
 
 struct sysnod {
        char    *sysnam;
        int     sysval;
-}
+};
 
 /* this node is a proforma for those that follow */
 struct trenod {
        int     tretyp;
        struct ionod    *treio;
-}
+};
 
 /* dummy for access only */
 struct argnod {
        struct argnod   *argnxt;
        char    argval[1];
-}
+};
 
 struct dolnod {
        struct dolnod   *dolnxt;
        int     doluse;
        char    dolarg[1];
-}
+};
 
 struct forknod {
        int     forktyp;
        struct ionod    *forkio;
        struct trenod   *forktre;
-}
+};
 
 struct comnod {
        int     comtyp;
        struct ionod    *comio;
        struct argnod   *comarg;
        struct argnod   *comset;
-}
+};
 
 struct ifnod {
        int     iftyp;
        struct trenod   *iftre;
        struct trenod   *thtre;
        struct trenod   *eltre;
-}
+};
 
 struct whnod {
        int     whtyp;
        struct trenod   *whtre;
        struct trenod   *dotre;
-}
+};
 
 struct fornod {
        int     fortyp;
        struct trenod   *fortre;
        char    *fornam;
        struct comnod   *forlst;
-}
+};
 
 struct swnod {
        int     swtyp;
        char    *swarg;
        struct regnod   *swlst;
-}
+};
 
 struct regnod {
        struct argnod   *regptr;
        struct trenod   *regcom;
        struct regnod   *regnxt;
-}
+};
 
 struct parnod {
        int     partyp;
        struct trenod   *partre;
-}
+};
 
 struct lstnod {
        int     lsttyp;
        struct trenod   *lstlef;
        struct trenod   *lstrit;
-}
+};
 
 struct ionod {
        int     iofile;
        char    *ioname;
        struct ionod    *ionxt;
        struct ionod    *iolst;
-}
+};
index ab74648..2fbf5fe 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)msg.c      4.4 5/22/85";
 #endif
 
-#
 /*
  *     UNIX shell
  *
@@ -18,29 +17,29 @@ static char sccsid[] = "@(#)msg.c   4.4 5/22/85";
 char           version[] = "\nVERSION sys137   DATE 1978 Nov 6 14:29:22\n";
 
 /* error messages */
-char   badopt[]                = "bad option(s)";
-char   mailmsg[]               = "you have mail\n";
-char   nospace[]               = "no space";
-char   synmsg[]                = "syntax error";
+char   badopt[]        = "bad option(s)";
+char   mailmsg[]       = "you have mail\n";
+char   nospace[]       = "no space";
+char   synmsg[]        = "syntax error";
 
-char   badnum[]                = "bad number";
+char   badnum[]        = "bad number";
 char   badparam[]      = "parameter not set";
-char   badsub[]                = "bad substitution";
+char   badsub[]        = "bad substitution";
 char   badcreate[]     = "cannot create";
-char   illegal[]               = "illegal io";
+char   illegal[]       = "illegal io";
 char   restricted[]    = "restricted";
-char   piperr[]                = "cannot make pipe";
-char   badopen[]               = "cannot open";
+char   piperr[]        = "cannot make pipe";
+char   badopen[]       = "cannot open";
 char   coredump[]      = " - core dumped";
-char   arglist[]               = "arg list too long";
-char   txtbsy[]                = "text busy";
-char   toobig[]                = "too big";
-char   badexec[]               = "cannot execute";
+char   arglist[]       = "arg list too long";
+char   txtbsy[]        = "text busy";
+char   toobig[]        = "too big";
+char   badexec[]       = "cannot execute";
 char   notfound[]      = "not found";
-char   badfile[]               = "bad file number";
+char   badfile[]       = "bad file number";
 char   badshift[]      = "cannot shift";
-char   baddir[]                = "bad directory";
-char   badtrap[]               = "bad trap";
+char   baddir[]        = "bad directory";
+char   badtrap[]       = "bad trap";
 char   wtfailed[]      = "is read only";
 char   notid[]         = "is not an identifier";
 
@@ -48,30 +47,29 @@ char        notid[]         = "is not an identifier";
 char   pathname[]      = "PATH";
 char   homename[]      = "HOME";
 char   mailname[]      = "MAIL";
-char   fngname[]               = "FILEMATCH";
-char   ifsname[]               = "IFS";
-char   ps1name[]               = "PS1";
-char   ps2name[]               = "PS2";
+char   fngname[]       = "FILEMATCH";
+char   ifsname[]       = "IFS";
+char   ps1name[]       = "PS1";
+char   ps2name[]       = "PS2";
 
 /* string constants */
-char   nullstr[]               = "";
-char   sptbnl[]                = " \t\n";
-char   defpath[]               = ":/bin:/usr/bin";
+char   nullstr[]       = "";
+char   sptbnl[]        = " \t\n";
+char   defpath[]       = ":/bin:/usr/bin";
 char   colon[]         = ": ";
 char   minus[]         = "-";
 char   endoffile[]     = "end of file";
 char   unexpected[]    = " unexpected";
-char   atline[]                = " at line ";
-char   devnull[]               = "/dev/null";
+char   atline[]        = " at line ";
+char   devnull[]       = "/dev/null";
 char   execpmsg[]      = "+ ";
-char   readmsg[]               = "> ";
+char   readmsg[]       = "> ";
 char   stdprompt[]     = "$ ";
 char   supprompt[]     = "# ";
-char   profile[]               = ".profile";
-
+char   profile[]       = ".profile";
 
 /* tables */
-struct sysnod reserved[] {
+struct sysnod reserved[] {
                {"in",          INSYM},
                {"esac",        ESSYM},
                {"case",        CASYM},
@@ -85,12 +83,12 @@ struct sysnod reserved[] {
                {"elif",        EFSYM},
                {"fi",          FISYM},
                {"until",       UNSYM},
-               { "{",          BRSYM},
-               { "}",          KTSYM},
-               {0,     0},
-}
+               {"{",           BRSYM},
+               {"}",           KTSYM},
+               {0,             0}
+};
 
-char   *sysmsg[] {
+char   *sysmsg[] {
                0,
                "Hangup",
                0,      /* Interrupt */
@@ -123,18 +121,16 @@ char      *sysmsg[] {
                "Signal 29",
                "User defined signal 1",
                "User defined signal 2",
-               "Signal 32",
-}
+               "Signal 32"
+};
 int            num_sysmsg = (sizeof sysmsg / sizeof sysmsg[0]);
 
 char           export[] = "export";
 char           readonly[] = "readonly";
-struct sysnod  commands[] {
+struct sysnod  commands[] {
                {"cd",          SYSCD},
                {"read",        SYSREAD},
-/*
-               {"[",           SYSTST},
-*/
+               /*{"[",         SYSTST},*/
                {"set",         SYSSET},
                {":",           SYSNULL},
                {"trap",        SYSTRAP},
@@ -152,5 +148,5 @@ struct sysnod       commands[] {
                {"exec",        SYSEXEC},
                {"times",       SYSTIMES},
                {"umask",       SYSUMASK},
-               {0,     0},
-}
+               {0,             0}
+};
index b6440aa..bbaa9a1 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)name.c     4.4 10/31/85";
 #endif
 
-#
 /*
  * UNIX shell
  *
@@ -16,15 +15,15 @@ static char sccsid[] = "@(#)name.c  4.4 10/31/85";
 extern bool    chkid();
 
 
-struct namnod  ps2nod  = {     NIL,            NIL,            ps2name},
-       fngnod  = {     NIL,            NIL,            fngname},
-       pathnod = {     NIL,            NIL,            pathname},
-       ifsnod  = {     NIL,            NIL,            ifsname},
-       ps1nod  = {     &pathnod,       &ps2nod,        ps1name},
-       homenod = {     &fngnod,        &ifsnod,        homename},
-       mailnod = {     &homenod,       &ps1nod,        mailname}
+struct namnod  ps2nod  = {     NULL,           NULL,           ps2name},
+               fngnod  = {     NULL,           NULL,           fngname},
+               pathnod = {     NULL,           NULL,           pathname},
+               ifsnod  = {     NULL,           NULL,           ifsname},
+               ps1nod  = {     &pathnod,       &ps2nod,        ps1name},
+               homenod = {     &fngnod,        &ifsnod,        homename},
+               mailnod = {     &homenod,       &ps1nod,        mailname};
 
-struct namnod          *namep = &mailnod;
+struct namnod  *namep = &mailnod;
 
 
 /* ========    variable and string handling    ======== */
@@ -222,7 +221,7 @@ struct namnod               *lookup(nam)
 
        /* add name node */
        nscan=alloc(sizeof *nscan);
-       nscan->namlft=nscan->namrgt=NIL;
+       nscan->namlft=nscan->namrgt=NULL;
        nscan->namid=make(nam);
        nscan->namval=0; nscan->namflg=N_DEFAULT; nscan->namenv=0;
        return(*prev = nscan);
@@ -285,7 +284,7 @@ static char *staknam(n)
        p=movstr(n->namid,staktop);
        p=movstr("=",p);
        p=movstr(n->namval,p);
-       return(getstak(p+1-(void *)(stakbot)));
+       return(getstak(p+1-stakbot));
 }
 
 void   exname(n)
index 8d59e84..42f5ad3 100644 (file)
@@ -1,6 +1,5 @@
 /*     name.h  4.1     82/05/07        */
 
-#
 /*
  *     UNIX shell
  *
@@ -24,4 +23,4 @@ struct namnod {
        char    *namval;
        char    *namenv;
        int     namflg;
-}
+};
index 2f51ba4..fb47b6c 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)print.c    4.2 8/11/83";
 #endif
 
-#
 /*
  * UNIX shell
  *
index 8f8b510..1ab342e 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)service.c  4.4 3/19/85";
 #endif
 
-#
 /*
  * UNIX shell
  *
@@ -418,7 +417,7 @@ static int  split(s)
                else if (c==0) {
                        s--;
                }
-               if (c=expand((argp=endstak(argp))->argval,0)) {
+               if (c=expand(((struct argnod *)(argp=endstak(argp)))->argval,0)) {
                        count += c;
                }
                else {
index 8842f64..4636e04 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)setbrk.c   4.2 8/11/83";
 #endif
 
-#
 /*
  *     UNIX shell
  *
index fb91613..a2ae897 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)stak.c     4.2 8/11/83";
 #endif
 
-#
 /*
  * UNIX shell
  *
@@ -13,6 +12,12 @@ static char sccsid[] = "@(#)stak.c   4.2 8/11/83";
 
 #include       "defs.h"
 
+/* moved here from stak.h, which now just declares them extern */
+struct blk     *stakbsy;
+char           *stakbas;
+char           *brkend;
+char           *staktop;
+
 char           *stakbot=nullstr;
 
 
index 50a7e0f..92cf15e 100644 (file)
@@ -1,6 +1,5 @@
 /*     stak.h  4.1     82/05/07        */
 
-#
 /*
  *     UNIX shell
  *
@@ -60,19 +59,19 @@ char                *getstak();
  * have become covered by heap allocation.
  * `tdystak' will return them to the heap.
  */
-struct blk             *stakbsy;
+extern struct blk      *stakbsy;
 
 /* Base of the entire stack */
-char           *stakbas;
+extern char            *stakbas;
 
 /* Top of entire stack */
-char           *brkend;
+extern char            *brkend;
 
 /* Base of current item */
-char           *stakbot;
+extern char            *stakbot;
 
 /* Top of current item */
-char           *staktop;
+extern char            *staktop;
 
 /* Used with tdystak */
 char           *savstak();
index 7aedcc5..202a3b3 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)string.c   4.2 8/11/83";
 #endif
 
-#
 /*
  * UNIX shell
  *
index 217e842..6fb8d5e 100644 (file)
@@ -1,6 +1,5 @@
 /*     sym.h   4.1     82/05/07        */
 
-#
 /*
  *     UNIX shell
  */
 
 /* for peekc */
 #define MARK   0100000
-
-/* odd chars */
-#define DQUOTE '"'
-#define SQUOTE '`'
-#define LITERAL        '\''
-#define DOLLAR '$'
-#define ESCAPE '\\'
-#define BRACE  '{'
index fde1e20..b40606e 100644 (file)
@@ -1,6 +1,5 @@
 /*     timeout.h       4.1     82/05/07        */
 
-#
 /*
  *     UNIX shell
  *
diff --git a/bin/sh/uniqify.sed b/bin/sh/uniqify.sed
new file mode 100644 (file)
index 0000000..2588ed6
--- /dev/null
@@ -0,0 +1,22 @@
+s/@/ATSIGN/g
+s/^/@/
+s/$/@/
+s/[^A-Za-z0-9_]\+/@&@/g
+
+# defs.h
+s/@alloc@/@malloc@/g
+s/@rename@/@_rename@/g
+
+# mode.h
+s/@BYTESPERWORD@/@sizeof(char *)@/g
+
+# sym.h
+s/@DQUOTE@/@'"'@/g
+s/@SQUOTE@/@'`'@/g
+s/@LITERAL@/@'\\''@/g
+s/@DOLLAR@/@'$'@/g
+s/@ESCAPE@/@'\\\\'@/g
+s/@BRACE@/@'{'@/g
+
+s/@//g
+s/ATSIGN/@/g
index 8ad9036..1ad1007 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)word.c     4.6 10/31/85";
 #endif
 
-#
 /*
  * UNIX shell
  *
@@ -52,16 +51,16 @@ word()
                        }
                } while ((c=nextc(0), !eofmeta(c)));
                argp=endstak(argp);
-               if (!letter(argp->argval[0])) { wdset=0; }
+               if (!letter(((struct argnod *)argp)->argval[0])) { wdset=0; }
 
                peekc=c|MARK;
-               if (argp->argval[1]==0 && (d=argp->argval[0], digit(d)) && (c=='>' || c=='<')) {
+               if (((struct argnod *)argp)->argval[1]==0 && (d=((struct argnod *)argp)->argval[0], digit(d)) && (c=='>' || c=='<')) {
                        word(); wdnum=d-'0';
                }
                else {
                        /*check for reserved words*/
-                       if (reserv==0 || (wdval=syslook(argp->argval,reserved))==0) {
-                               wdarg=argp; wdval=0;
+                       if (reserv==0 || (wdval=syslook(((struct argnod *)argp)->argval,reserved))==0) {
+                               wdarg=(struct argnod *)argp; wdval=0;
                        }
                }
 
index 2a32c37..ec1e445 100644 (file)
@@ -2,7 +2,6 @@
 static char sccsid[] = "@(#)xec.c      4.3 8/11/83";
 #endif
 
-#
 /*
  * UNIX shell
  *
@@ -16,7 +15,7 @@ static char sccsid[] = "@(#)xec.c     4.3 8/11/83";
 
 static int     parent;
 
-struct sysnod          commands[];
+extern struct sysnod   commands[];
 
 
 
@@ -28,29 +27,29 @@ execute(argt, execflg, pf1, pf2)
        int             *pf1, *pf2;
 {
        /* `stakbot' is preserved by this routine */
-       register struct trenod  *t;
+       register struct trenod  *_t;
        char            *sav=savstak();
 
        sigchk();
 
-       if ((t=argt) && execbrk==0) {
-               register int            treeflgs;
+       if ((_t=argt) && execbrk==0) {
+               register int    treeflgs;
                int             oldexit, type;
                register char   **com;
 
-               treeflgs = t->tretyp; type = treeflgs&COMMSK;
+               treeflgs = _t->tretyp; type = treeflgs&COMMSK;
                oldexit=exitval; exitval=0;
 
                switch (type) {
                  
 
                case TCOM:
+#define t ((struct comnod *)_t)
                        {
-                            
                        char            *a1;
                        int             argn, internal;
                        struct argnod           *schain=gchain;
-                       struct ionod            *io=t->treio;
+                       struct ionod            *io=t->comio;
                        gchain=0;
                        argn = getarg(t);
                        com=scan(argn);
@@ -86,8 +85,8 @@ execute(argt, execflg, pf1, pf2)
        
                                case SYSTIMES:
                                        {
-                                       long    t[4]; times(t);
-                                       prt(t[2]); blank(); prt(t[3]); newline();
+                                       long    tm[4]; times(tm);
+                                       prt(tm[2]); blank(); prt(tm[3]); newline();
                                        }
                                        break;
        
@@ -222,7 +221,7 @@ execute(argt, execflg, pf1, pf2)
 
                                case SYSUMASK:
                                        if (a1) {
-                                               int c, i
+                                               int c, i;
                                                i = 0;
                                                while ((c = *a1++) >= '0' &&
                                                        c <= '7')
@@ -249,10 +248,11 @@ execute(argt, execflg, pf1, pf2)
                                        break;
                                }
                        }
-                       else if (t->treio==0) {
+                       else if (t->comio==0) {
                                break;
                        }
                        }
+                       /* fallthru */
        
                case TFORK:
                        if (execflg && (treeflgs&(FAMP|FPOU))==0) {
@@ -295,7 +295,7 @@ execute(argt, execflg, pf1, pf2)
                                /* except for those `lost' by trap   */
                                oldsigs();
                                if (treeflgs&FINT) {
-                                       signal(INTR,1); signal(QUIT,1);
+                                       signal(INTR,SIG_IGN); signal(QUIT,SIG_IGN);
                                }
 
                                /* pipe in or out */
@@ -314,9 +314,9 @@ execute(argt, execflg, pf1, pf2)
                                }
 
                                /* io redirection */
-                               initio(t->treio);
+                               initio(t->comio);
                                if (type!=TCOM) {
-                                       execute(t->forktre,1);
+                                       execute(((struct forknod *)t)->forktre,1);
                                }
                                else if (com[0]!=ENDARGS) {
                                        setlist(t->comset,N_EXPORT);
@@ -324,15 +324,18 @@ execute(argt, execflg, pf1, pf2)
                                }
                                done();
                        }
+#undef t
 
                case TPAR:
+#define t ((struct parnod *)_t)
                        rename(dup(2),output);
                        execute(t->partre,execflg);
                        done();
+#undef t
 
                case TFIL:
+#define t ((struct lstnod *)_t)
                        {
-                            
                           int pv[2]; chkpipe(pv);
                           if (execute(t->lstlef, 0, pf1, pv)==0) {
                                execute(t->lstrit, execflg, pv, pf2);
@@ -342,27 +345,34 @@ execute(argt, execflg, pf1, pf2)
                           }
                        }
                        break;
+#undef t
 
                case TLST:
+#define t ((struct lstnod *)_t)
                        execute(t->lstlef,0);
                        execute(t->lstrit,execflg);
                        break;
+#undef t
 
                case TAND:
+#define t ((struct lstnod *)_t)
                        if (execute(t->lstlef,0)==0) {
                                execute(t->lstrit,execflg);
                        }
                        break;
+#undef t
 
                case TORF:
+#define t ((struct lstnod *)_t)
                        if (execute(t->lstlef,0)!=0) {
                                execute(t->lstrit,execflg);
                        }
                        break;
+#undef t
 
                case TFOR:
+#define t ((struct fornod *)_t)
                        {
-                            
                           struct namnod        *n = lookup(t->fornam);
                           char **args;
                           struct dolnod        *argsav=0;
@@ -388,11 +398,12 @@ execute(argt, execflg, pf1, pf2)
                           argfor=freeargs(argsav);
                        }
                        break;
+#undef t
 
                case TWH:
                case TUN:
+#define t ((struct whnod *)_t)
                        {
-                            
                           int          i=0;
 
                           loopcnt++;
@@ -404,8 +415,10 @@ execute(argt, execflg, pf1, pf2)
                           execbrk=breakcnt; loopcnt--; exitval=i;
                        }
                        break;
+#undef t
 
                case TIF:
+#define t ((struct ifnod *)_t)
                        if (execute(t->iftre,0)==0) {
                                execute(t->thtre,execflg);
                        }
@@ -413,28 +426,30 @@ execute(argt, execflg, pf1, pf2)
                                execute(t->eltre,execflg);
                        }
                        break;
+#undef t
 
                case TSW:
+#define t ((struct swnod *)_t)
                        {
-                            
                           register char        *r = mactrim(t->swarg);
-                          t=t->swlst;
-                          while (t) {
-                               struct argnod           *rex=t->regptr;
+                          struct regnod        *u = t->swlst;
+                          while (u) {
+                               struct argnod           *rex=u->regptr;
                                while (rex) {
                                        register char   *s;
                                        if (gmatch(r,s=macro(rex->argval)) || (trim(s), eq(r,s))) {
-                                               execute(t->regcom,0);
-                                               t=0; break;
+                                               execute(u->regcom,0);
+                                               u=0; break;
                                        }
                                        else {
                                                rex=rex->argnxt;
                                        }
                                }
-                               if (t) { t=t->regnxt; }
+                               if (u) { u=u->regnxt; }
                           }
                        }
                        break;
+#undef t
                }
                exitset();
        }
index 61014ef..d91a65f 100644 (file)
@@ -121,9 +121,13 @@ ID         {LETTER}({LETTER}|{DIGIT})*
 QUOTE          [\"\']
 
 %s CPP1 INIT1 INIT2 CURLY LEXYACC ASM CPP_INLINE
+
+/* Nick has hacked in a start condition check on the newline below, */
+/* so that if CPP1 we can do the same thing but also BEGIN INITIAL */
+
 %%
 
-\n                     { save_text(); cur_file->line_num++;
+<INITIAL,INIT1,INIT2,CURLY,LEXYACC,ASM,CPP_INLINE>\n                   { save_text(); cur_file->line_num++;
                            cur_declarator = NULL; }
 
 "/*"                   { save_text(); get_comment(); }
@@ -202,6 +206,8 @@ QUOTE               [\"\']
                            finishCpp();
                        }
 
+<CPP1>\n               { save_text(); cur_file->line_num++;
+                           cur_declarator = NULL; BEGIN INITIAL; /* Nick */ }
 <CPP1>.                { save_text(); get_cpp_directive(NULL, 0); }
 
 <INITIAL>"("           { save_text_offset(); return '('; }
index 4610076..18ec653 100755 (executable)
@@ -22,6 +22,8 @@ fi
 #all_h=`find . -type f -name '*.h' -print |sed -e 's:^\./::' |LC_ALL=C sort`
 #all_h=`find $INCLUDE -type f -name '*.h' -print |LC_ALL=C sort`
 
+rm -f ansify.log
+
 if test -z "$1" || test $1 -eq 0
 then
   echo "===stage 0==="
@@ -65,7 +67,7 @@ then
     #mkdir -p $INCLUDE
     #(cd $ROOT/include && $SCRIPTS/make.sh SHARED=copies install)
   fi
-fi
+fi >>ansify.log
 
 all_c=`echo *.c`
 if test "$all_c" = "*.c"
@@ -215,7 +217,7 @@ EOF
   rm $INCLUDE/stdint.h $INCLUDE/stdarg.h
   mv $INCLUDE/varargs.h.save $INCLUDE/varargs.h
   sed -e 's/^\/\*AAA\(.*\)\*\/$/\1/' -i $std_h
-fi
+fi >>ansify.log
 
 all_h=`echo *.h`
 if test "$all_h" = "*.h"
@@ -434,7 +436,7 @@ then
       fi
     fi
   done
-fi
+fi >>ansify.log
 
 if test -z "$1" || test $1 -eq 3
 then
@@ -624,7 +626,7 @@ EOF
     ) |$SCRIPTS/newline >b
     mv b $i
   done
-fi
+fi >>ansify.log
 
 if test -z "$1" || test $1 -eq 4
 then
@@ -686,7 +688,7 @@ then
   done
   rm -f $INCLUDE/stdarg.h temp.c
   tsort <a >b
-fi
+fi >>ansify.log
 
 #if test -z "$1" || test $1 -eq 5
 #then
@@ -719,4 +721,4 @@ fi
 #    echo "i=$i"
 #    cp $INCLUDE/sys/`basename $i` $ROOT/sys/h
 #  done
-#fi
+#fi >>ansify.log