Pre-ansification changes for lib/cpp
authorNick Downing <downing.nick@gmail.com>
Thu, 2 Feb 2017 12:34:18 +0000 (23:34 +1100)
committerNick Downing <downing.nick@gmail.com>
Thu, 2 Feb 2017 13:46:29 +0000 (00:46 +1100)
env.sh
lib/cpp/Makefile
lib/cpp/conflicts.txt [new file with mode: 0644]
lib/cpp/cpp.c
lib/cpp/cpp.h [new file with mode: 0644]
lib/cpp/cpy.c [new file with mode: 0644]
lib/cpp/cpy.y
lib/cpp/groups.txt [new file with mode: 0644]
lib/cpp/yylex.c [deleted file]
scripts/ansify.sh
scripts/nouses.sh

diff --git a/env.sh b/env.sh
index aa7e08d..d45c936 100644 (file)
--- a/env.sh
+++ b/env.sh
@@ -1,8 +1,8 @@
 export ROOT=`pwd`
 
-export INCLUDE=$ROOT/cross/usr/include
 export SCRIPTS=$ROOT/scripts
 export STAGE0=$ROOT/stage0
 export STAGE1=$ROOT/stage1
 
+export INCLUDE=$STAGE0/usr/include
 export PATH=$SCRIPTS:$PATH
index 41f90eb..6d60551 100644 (file)
@@ -1,25 +1,29 @@
+YACC=yacc
 #      Makefile        1.2     83/07/02
 #
 
 CFLAGS=-O -Dunix=1 -DFLEXNAMES
 
-cpp :  cpp.o cpy.o rodata.o
-       $(CC) $(CFLAGS) -o cpp rodata.o cpp.o cpy.o  
+cpp :  cpp.o cpy.o
+# rodata.o
+       $(CC) $(CFLAGS) -o cpp cpp.o cpy.o
+# rodata.o
 
 cpy.c : cpy.y
-       yacc cpy.y
-       ../pcc/:yyfix yyexca yyact yypact yypgo yyr1 yyr2 yychk yydef
+       ${YACC} cpy.y
+#      ../pcc/:yyfix yyexca yyact yypact yypgo yyr1 yyr2 yychk yydef
        mv y.tab.c cpy.c
-cpy.o :        cpy.c yylex.c
-rodata.o : cpy.c
-       $(CC) $(CFLAGS) -R -c rodata.c
+cpy.o :        cpy.c cpp.h
+#rodata.o : cpy.c
+#      $(CC) $(CFLAGS) -R -c rodata.c
 
 clean :
-       rm -f *.s *.o cpy.c rodata.c
+       rm -f *.s *.o cpy.c
+# rodata.c
 
 install :
        install -s cpp $(DESTDIR)/lib
 
-sources : cpp.c cpy.y yylex.c README
-cpp.c cpy.y yylex.c README :
+sources : cpp.c cpy.y README
+cpp.c cpy.y README :
        sccs get $@
diff --git a/lib/cpp/conflicts.txt b/lib/cpp/conflicts.txt
new file mode 100644 (file)
index 0000000..2e1c342
--- /dev/null
@@ -0,0 +1,2 @@
+cpp.c arpa/telnet.h
+cpp.c sys/dkbad.h
index 9029a4f..edd0649 100644 (file)
@@ -10,13 +10,14 @@ static char sccsid[] = "@(#)cpp.c   1.14 4/27/86";
 
 # include "stdio.h"
 # include "ctype.h"
+# include "varargs.h"
+# include "cpp.h"
+
 /* C command
 /* written by John F. Reiser
 /* July/August 1978
 */
 
-#define STATIC
-
 #define FIRSTOPEN -2
 #define STDIN 0
 #define READ 0
@@ -139,71 +140,68 @@ int macdam;       /* offset to macforw due to buffer shifting */
 int tgpscan;   /* flag for dump(); */
 #endif
 
-STATIC int     inctop[MAXINC];
-STATIC char    *fnames[MAXINC];
-STATIC char    *dirnams[MAXINC];       /* actual directory of #include files */
-STATIC int     fins[MAXINC];
-STATIC int     lineno[MAXINC];
+int    inctop[MAXINC];
+char   *fnames[MAXINC];
+char   *dirnams[MAXINC];       /* actual directory of #include files */
+int    fins[MAXINC];
+int    lineno[MAXINC];
 
-STATIC char    *dirs[10];      /* -I and <> directories */
+char   *dirs[10];      /* -I and <> directories */
 char *strdex(), *copy(), *subst(), *trmdir();
 struct symtab *stsym();
-STATIC int     fin     = FIRSTOPEN;
-STATIC FILE    *fout   = stdout;
-STATIC int     nd      = 1;
-STATIC int     pflag;  /* don't put out lines "# 12 foo.c" */
+int    fin     = FIRSTOPEN;
+FILE   *fout   = stdout;
+int    nd      = 1;
+int    pflag;  /* don't put out lines "# 12 foo.c" */
 int    passcom;        /* don't delete comments */
 int    incomment;      /* True if parsing a comment */
-STATIC int rflag;      /* allow macro recursion */
-STATIC int mflag;      /* generate makefile dependencies */
-STATIC char *infile;   /* name of .o file to build dependencies from */
-STATIC         FILE *mout;     /* file to place dependencies on */
+int rflag;     /* allow macro recursion */
+int mflag;     /* generate makefile dependencies */
+char *infile;  /* name of .o file to build dependencies from */
+FILE *mout;    /* file to place dependencies on */
 #define START 1
 #define CONT  2
 #define BACK  3
-STATIC int     ifno;
+int    ifno;
 # define NPREDEF 20
-STATIC char *prespc[NPREDEF];
-STATIC char **predef = prespc;
-STATIC char *punspc[NPREDEF];
-STATIC char **prund = punspc;
-STATIC int     exfail;
-struct symtab {
-       char    *name;
-       char    *value;
-} *lastsym, *lookup(), *slookup();
-
-# if gcos
-#include <setjmp.h>
-static jmp_buf env;
-# define main  mainpp
-# undef exit
-# define exit(S)       longjmp(env, 1)
-# define open(S,D)     fileno(fopen(S, "r"))
-# define close(F)      fclose(_f[F])
-extern FILE *_f[];
-# define symsiz 500
-# else
+char *prespc[NPREDEF];
+char **predef = prespc;
+char *punspc[NPREDEF];
+char **prund = punspc;
+int    exfail;
+struct symtab *lastsym;
+
+/*# if gcos*/
+/*#include <setjmp.h>*/
+/*static jmp_buf env;*/
+/*# define main        mainpp*/
+/*# undef exit*/
+/*# define exit(S)     longjmp(env, 1)*/
+/*# define open(S,D)   fileno(fopen(S, "r"))*/
+/*# define close(F)    fclose(_f[F])*/
+/*extern FILE *_f[];*/
+/*# define symsiz 500*/
+/*# else*/
 # define symsiz 2000           /* std = 500, wnj aug 1979 */
-# endif
-STATIC struct symtab stab[symsiz];
-
-STATIC struct symtab *defloc;
-STATIC struct symtab *udfloc;
-STATIC struct symtab *incloc;
-STATIC struct symtab *ifloc;
-STATIC struct symtab *elsloc;
-STATIC struct symtab *eifloc;
-STATIC struct symtab *ifdloc;
-STATIC struct symtab *ifnloc;
-STATIC struct symtab *ysysloc;
-STATIC struct symtab *varloc;
-STATIC struct symtab *lneloc;
-STATIC struct symtab *ulnloc;
-STATIC struct symtab *uflloc;
-STATIC struct symtab *identloc;        /* Sys 5r3 compatibility */
-STATIC int     trulvl;
-STATIC int     flslvl;
+/*# endif*/
+struct symtab stab[symsiz];
+
+struct symtab *defloc;
+struct symtab *udfloc;
+struct symtab *incloc;
+struct symtab *ifloc;
+struct symtab *elsloc;
+struct symtab *eifloc;
+struct symtab *ifdloc;
+struct symtab *ifnloc;
+struct symtab *ysysloc;
+struct symtab *varloc;
+struct symtab *lneloc;
+struct symtab *ulnloc;
+struct symtab *uflloc;
+struct symtab *identloc;       /* Sys 5r3 compatibility */
+int    trulvl;
+int    flslvl;
 
 sayline(where)
        int where;
@@ -882,8 +880,7 @@ ppsym(s) char *s; {/* kluge */
        cinit=0; return(sp);
 }
 
-/* VARARGS1 */
-pperror(s,x,y) char *s; {
+vpperror(s,argp) char *s; va_list argp; {
        if (fnames[ifno][0]) fprintf(stderr,
 # if gcos
                        "*%c*   \"%s\", line ", exfail >= 0 ? 'F' : 'W',
@@ -892,19 +889,35 @@ pperror(s,x,y) char *s; {
 # endif
                                 fnames[ifno]);
        fprintf(stderr, "%d: ",lineno[ifno]);
-       fprintf(stderr, s, x, y);
+       vfprintf(stderr, s, argp);
        fprintf(stderr,"\n");
        ++exfail;
 }
 
-yyerror(s,a,b) char *s; {
-       pperror(s,a,b);
+pperror(s,va_alist) char *s; va_dcl {
+       va_list argp;
+
+       va_start(argp);
+       vpperror(s,argp);
+       va_end(argp);
 }
 
-ppwarn(s,x) char *s; {
+yyerror(s,va_alist) char *s; va_dcl {
+       va_list argp;
+
+       va_start(argp);
+       vpperror(s,argp);
+       va_end(argp);
+}
+
+ppwarn(s,va_alist) char *s; va_dcl {
+       va_list argp;
+
        int fail = exfail;
        exfail = -1;
-       pperror(s,x);
+       va_start(argp);
+       vpperror(s,argp);
+       va_end(argp);
        exfail = fail;
 }
 
@@ -1044,7 +1057,7 @@ trmdir(s) register char *s; {
        return(s);
 }
 
-STATIC char *
+char *
 copy(s) register char *s; {
        register char *old;
 
@@ -1128,10 +1141,11 @@ main(argc,argv)
                        {
                        case '-':
 # if gcos
-                       switch(toupper(argv[i][1])) /* case-independent on GCOS */
+                       switch(toupper(argv[i][1])) /* case-independent on GCOS */
 # else
-                       switch(argv[i][1]) {
+                       switch(argv[i][1])
 # endif
+                       {
                                case 'M': mflag++;
                                case 'P': pflag++;
                                case 'E': continue;
@@ -1169,18 +1183,20 @@ main(argc,argv)
                                        fnames[ifno]=copy(argv[i]);
                                        infile=copy(argv[i]);
                                        dirs[0]=dirnams[ifno]=trmdir(argv[i]);
+                               }
 # ifndef gcos
 /* too dangerous to have file name in same syntactic position
    be input or output file depending on file redirections,
    so force output to stdout, willy-nilly
        [i don't see what the problem is.  jfr]
 */
-                               else if (fout==stdout) {
+                               else if (fout==stdout) {
                                        if (NULL==(fout=fopen(argv[i], "w"))) {
                                                pperror("Can't create %s", argv[i]); exit(8);
                                        } else fclose(stdout);
+                               }
 # endif
-                               else pperror("extraneous name %s", argv[i]);
+                               else pperror("extraneous name %s", argv[i]);
                        }
                }
        if (fin == FIRSTOPEN)
diff --git a/lib/cpp/cpp.h b/lib/cpp/cpp.h
new file mode 100644 (file)
index 0000000..618f4cf
--- /dev/null
@@ -0,0 +1,12 @@
+struct symtab {
+       char    *name;
+       char    *value;
+};
+
+extern char fastab[];
+extern char *outp,*inp,*newp;
+extern int flslvl;
+extern int passcom;
+
+char *skipbl(); 
+struct symtab *lookup(), *slookup();
diff --git a/lib/cpp/cpy.c b/lib/cpp/cpy.c
new file mode 100644 (file)
index 0000000..7d3f8a1
--- /dev/null
@@ -0,0 +1,474 @@
+# define number 257
+# define stop 258
+# define DEFINED 259
+# define EQ 260
+# define NE 261
+# define LE 262
+# define GE 263
+# define LS 264
+# define RS 265
+# define ANDAND 266
+# define OROR 267
+# define UMINUS 268
+#define yyclearin yychar = -1
+#define yyerrok yyerrflag = 0
+extern int yychar;
+extern short yyerrflag;
+#ifndef YYMAXDEPTH
+#define YYMAXDEPTH 150
+#endif
+#ifndef YYSTYPE
+#define YYSTYPE int
+#endif
+YYSTYPE yylval, yyval;
+# define YYERRCODE 256
+
+# line 82 "cpy.y"
+
+# include "cpp.h"
+
+#define isid(a)  ((fastab+COFF)[a]&IB)
+#define IB 1
+/*     #if '\377' < 0          it would be nice if this worked properly!!!!! */
+#if pdp11 | vax | mc68000
+#define COFF 128
+#else
+#define COFF 0
+#endif
+
+yylex() {
+       static int ifdef=0;
+       static char *op2[]={"||",  "&&" , ">>", "<<", ">=", "<=", "!=", "=="};
+       static int  val2[]={OROR, ANDAND,  RS,   LS,   GE,   LE,   NE,   EQ};
+       static char *opc="b\bt\tn\nf\fr\r\\\\";
+       register char savc, *s; int val;
+       register char **p2;
+       struct symtab *sp;
+
+for (;;) {
+       int opt_passcom = passcom;      /* this crap makes #if's work */
+       passcom = 0;                    /* even with -C option */
+       newp=skipbl(newp);              /* (else comments make syntax errs) */
+       passcom = opt_passcom;          /* nb: lint uses -C so its useful! */
+       if (*inp=='\n') return(stop);   /* end of #if */
+       savc= *newp; *newp='\0';
+       for (p2=op2+8; --p2>=op2; )     /* check 2-char ops */
+               if (0==strcmp(*p2,inp)) {val=val2[p2-op2]; goto ret;}
+       s="+-*/%<>&^|?:!~(),";  /* check 1-char ops */
+       while (*s) if (*s++== *inp) {val= *--s; goto ret;}
+       if (*inp<='9' && *inp>='0') {/* a number */
+               if (*inp=='0') yylval= (inp[1]=='x' || inp[1]=='X') ?
+                       tobinary(inp+2,16) : tobinary(inp+1,8);
+               else yylval=tobinary(inp,10);
+               val=number;
+       } else if (isid(*inp)) {
+               if (0==strcmp(inp,"defined")) {ifdef=1; ++flslvl; val=DEFINED;}
+               else {
+                       sp=lookup(inp,-1); if (ifdef!=0) {ifdef=0; --flslvl;}
+                       yylval= (sp->value==0) ? 0 : 1;
+                       val=number;
+               }
+       } else  if (*inp=='\'') {/* character constant */
+               val=number;
+               if (inp[1]=='\\') {/* escaped */
+                       char c; if (newp[-1]=='\'') newp[-1]='\0';
+                       s=opc;
+                       while (*s) if (*s++!=inp[2]) ++s; else {yylval= *s; goto ret;}
+                       if (inp[2]<='9' && inp[2]>='0') yylval=c=tobinary(inp+2,8);
+                       else yylval=inp[2];
+               } else yylval=inp[1];
+       } else if (0==strcmp("\\\n",inp)) {*newp=savc; continue;}
+       else {
+               *newp=savc; pperror("Illegal character %c in preprocessor if", *inp);
+               continue;
+       }
+ret:
+       *newp=savc; outp=inp=newp; return(val);
+}
+}
+
+tobinary(st, b) char *st; {
+       int n, c, t;
+       char *s;
+       n=0;
+       s=st;
+       while (c = *s++) {
+       switch(c) {
+               case '0': case '1': case '2': case '3': case '4': 
+               case '5': case '6': case '7': case '8': case '9': 
+                       t = c-'0'; break;
+               case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 
+                       t = c-'a'+10; if (b>10) break;
+               case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 
+                       t = c - 'A'+10; if (b>10) break;
+               default:
+                       t = -1;
+                       if ( c=='l' || c=='L') if (*s=='\0') break;
+                       pperror("Illegal number %s", st);
+       }
+       if (t<0) break;
+       n = n*b+t;
+       }
+return(n);
+}
+short yyexca[] ={
+-1, 1,
+       0, -1,
+       -2, 0,
+-1, 44,
+       262, 0,
+       263, 0,
+       60, 0,
+       62, 0,
+       -2, 9,
+-1, 45,
+       262, 0,
+       263, 0,
+       60, 0,
+       62, 0,
+       -2, 10,
+-1, 46,
+       262, 0,
+       263, 0,
+       60, 0,
+       62, 0,
+       -2, 11,
+-1, 47,
+       262, 0,
+       263, 0,
+       60, 0,
+       62, 0,
+       -2, 12,
+-1, 48,
+       260, 0,
+       261, 0,
+       -2, 13,
+-1, 49,
+       260, 0,
+       261, 0,
+       -2, 14,
+       };
+# define YYNPROD 30
+# define YYLAST 363
+short yyact[]={
+
+  13,  24,  35,  58,  13,  11,  14,  30,  15,  11,
+  12,  60,  13,  24,  12,   1,  57,  11,  14,  30,
+  15,  59,  12,  18,  13,  19,  29,   0,   0,  11,
+  14,   0,  15,   0,  12,  18,   3,  19,  29,  13,
+  24,  31,  32,  33,  11,  14,  30,  15,   0,  12,
+  13,  24,   0,   0,   0,  11,  14,  25,  15,   5,
+  12,   0,  18,   0,  19,  29,   7,   0,   0,  25,
+   0,   4,   0,  18,   0,  19,  29,   0,  13,  24,
+   0,   0,   0,  11,  14,   0,  15,  26,  12,   0,
+   0,   0,  13,  24,   0,   0,  25,  11,  14,  26,
+  15,  18,  12,  19,  13,  24,   0,  25,   0,  11,
+  14,   0,  15,  13,  12,  18,   0,  19,  11,  14,
+   0,  15,   0,  12,   0,   0,  26,  18,   0,  19,
+   0,   0,   0,   0,  13,  25,  18,  26,  19,  11,
+  14,   0,  15,   0,  12,  13,   0,   0,   0,  25,
+  11,  14,   6,  15,   0,  12,   0,  18,   0,  19,
+   0,   0,   0,   0,   0,  26,   0,   0,   0,   0,
+   0,   0,   2,   0,   0,   0,   0,   0,   0,  26,
+  34,   0,   0,   0,  37,  38,  39,  40,  41,  42,
+  43,  44,  45,  46,  47,  48,  49,  50,  51,  52,
+  53,  54,  55,  56,   0,   0,   0,   0,   0,   0,
+   0,   0,   0,   0,   0,   0,   0,   0,   0,  36,
+   0,   0,   0,  22,  23,  20,  21,  16,  17,  27,
+  28,   0,  61,   0,   0,  22,  23,  20,  21,  16,
+  17,  27,  28,   0,   0,   0,   0,   0,   0,   0,
+   0,  16,  17,   0,   0,   0,   0,   0,   0,   0,
+  10,   0,  22,  23,  20,  21,  16,  17,  27,  28,
+   0,   0,   0,  22,  23,  20,  21,  16,  17,  27,
+  28,   0,   0,   9,   0,   8,   0,   0,   0,   0,
+   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
+   0,  22,  23,  20,  21,  16,  17,  27,   0,   0,
+   0,   0,   0,   0,   0,  22,  23,  20,  21,  16,
+  17,   0,   0,   0,   0,   0,   0,  22,  23,  20,
+  21,  16,  17,   0,   0,   0,  22,  23,  20,  21,
+  16,  17,   0,   0,   0,   0,   0,   0,   0,   0,
+   0,   0,   0,   0,   0,   0,   0,   0,   0,  20,
+  21,  16,  17 };
+short yypact[]={
+
+  26,-1000,   2,-1000,  26,  26,  26,  26, -38,-1000,
+-1000,  26,  26,  26,  26,  26,  26,  26,  26,  26,
+  26,  26,  26,  26,  26,  26,  26,  26,  26,  26,
+  26,-1000,-1000,-1000, -25,-254,-1000,-1000,-1000,-1000,
+ -33, -33, 108, 108, -13, -13, -13, -13,  97,  97,
+  76,  67,  67,  55,  41, -37,  13,-1000, -30,  26,
+-1000,  13 };
+short yypgo[]={
+
+   0,  15, 172,  36 };
+short yyr1[]={
+
+   0,   1,   2,   2,   2,   2,   2,   2,   2,   2,
+   2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
+   2,   2,   2,   3,   3,   3,   3,   3,   3,   3 };
+short yyr2[]={
+
+   0,   2,   3,   3,   3,   3,   3,   3,   3,   3,
+   3,   3,   3,   3,   3,   3,   3,   3,   3,   3,
+   5,   3,   1,   2,   2,   2,   3,   4,   2,   1 };
+short yychk[]={
+
+-1000,  -1,  -2,  -3,  45,  33, 126,  40, 259, 257,
+ 258,  42,  47,  37,  43,  45, 264, 265,  60,  62,
+ 262, 263, 260, 261,  38,  94, 124, 266, 267,  63,
+  44,  -3,  -3,  -3,  -2,  40, 257,  -2,  -2,  -2,
+  -2,  -2,  -2,  -2,  -2,  -2,  -2,  -2,  -2,  -2,
+  -2,  -2,  -2,  -2,  -2,  -2,  -2,  41, 257,  58,
+  41,  -2 };
+short yydef[]={
+
+   0,  -2,   0,  22,   0,   0,   0,   0,   0,  29,
+   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,
+   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
+   0,  23,  24,  25,   0,   0,  28,   2,   3,   4,
+   5,   6,   7,   8,  -2,  -2,  -2,  -2,  -2,  -2,
+  15,  16,  17,  18,  19,   0,  21,  26,   0,   0,
+  27,  20 };
+#pragma ifdef __GNUC__
+#pragma pragma GCC diagnostic ignored "-Wunused-label"
+#pragma endif
+#if defined(DOSCCS) && !defined(lint)
+static char yaccpar_sccsid[] = "@(#)yaccpar    4.1     (Berkeley)      2/11/83";
+#endif
+
+#
+# define YYFLAG -1000
+# define YYERROR goto yyerrlab
+# define YYACCEPT return(0)
+# define YYABORT return(1)
+
+/*     parser for yacc output  */
+
+#ifdef YYDEBUG
+int yydebug = 0; /* 1 for debugging */
+#endif
+YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
+int yychar = -1; /* current input token number */
+int yynerrs = 0;  /* number of errors */
+short yyerrflag = 0;  /* error recovery flag */
+
+int yyparse() {
+
+       short yys[YYMAXDEPTH];
+       short yyj, yym;
+       register YYSTYPE *yypvt;
+       register short yystate, *yyps, yyn;
+       register YYSTYPE *yypv;
+       register short *yyxi;
+
+       yystate = 0;
+       yychar = -1;
+       yynerrs = 0;
+       yyerrflag = 0;
+       yyps= &yys[-1];
+       yypv= &yyv[-1];
+
+ yystack:    /* put a state and value onto the stack */
+
+#ifdef YYDEBUG
+       if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
+#endif
+               if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
+               *yyps = yystate;
+               ++yypv;
+               *yypv = yyval;
+
+ yynewstate:
+
+       yyn = yypact[yystate];
+
+       if( yyn<= YYFLAG ) goto yydefault; /* simple state */
+
+       if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
+       if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
+
+       if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
+               yychar = -1;
+               yyval = yylval;
+               yystate = yyn;
+               if( yyerrflag > 0 ) --yyerrflag;
+               goto yystack;
+               }
+
+ yydefault:
+       /* default state action */
+
+       if( (yyn=yydef[yystate]) == -2 ) {
+               if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
+               /* look through exception table */
+
+               for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
+
+               while( *(yyxi+=2) >= 0 ){
+                       if( *yyxi == yychar ) break;
+                       }
+               if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
+               }
+
+       if( yyn == 0 ){ /* error */
+               /* error ... attempt to resume parsing */
+
+               switch( yyerrflag ){
+
+               case 0:   /* brand new error */
+
+                       yyerror( "syntax error" );
+               yyerrlab:
+                       ++yynerrs;
+
+               case 1:
+               case 2: /* incompletely recovered error ... try again */
+
+                       yyerrflag = 3;
+
+                       /* find a state where "error" is a legal shift action */
+
+                       while ( yyps >= yys ) {
+                          yyn = yypact[*yyps] + YYERRCODE;
+                          if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
+                             yystate = yyact[yyn];  /* simulate a shift of "error" */
+                             goto yystack;
+                             }
+                          yyn = yypact[*yyps];
+
+                          /* the current yyps has no shift onn "error", pop stack */
+
+#ifdef YYDEBUG
+                          if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
+#endif
+                          --yyps;
+                          --yypv;
+                          }
+
+                       /* there is no state on the stack with an error shift ... abort */
+
+       yyabort:
+                       return(1);
+
+
+               case 3:  /* no shift yet; clobber input char */
+
+#ifdef YYDEBUG
+                       if( yydebug ) printf( "error recovery discards char %d\n", yychar );
+#endif
+
+                       if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
+                       yychar = -1;
+                       goto yynewstate;   /* try again in the same state */
+
+                       }
+
+               }
+
+       /* reduction by production yyn */
+
+#ifdef YYDEBUG
+               if( yydebug ) printf("reduce %d\n",yyn);
+#endif
+               yyps -= yyr2[yyn];
+               yypvt = yypv;
+               yypv -= yyr2[yyn];
+               yyval = yypv[1];
+               yym=yyn;
+                       /* consult goto table to find next state */
+               yyn = yyr1[yyn];
+               yyj = yypgo[yyn] + *yyps + 1;
+               if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
+               switch(yym){
+                       
+case 1:
+# line 22 "cpy.y"
+{return(yypvt[-1]);} break;
+case 2:
+# line 26 "cpy.y"
+{yyval = yypvt[-2] * yypvt[-0];} break;
+case 3:
+# line 28 "cpy.y"
+{yyval = yypvt[-2] / yypvt[-0];} break;
+case 4:
+# line 30 "cpy.y"
+{yyval = yypvt[-2] % yypvt[-0];} break;
+case 5:
+# line 32 "cpy.y"
+{yyval = yypvt[-2] + yypvt[-0];} break;
+case 6:
+# line 34 "cpy.y"
+{yyval = yypvt[-2] - yypvt[-0];} break;
+case 7:
+# line 36 "cpy.y"
+{yyval = yypvt[-2] << yypvt[-0];} break;
+case 8:
+# line 38 "cpy.y"
+{yyval = yypvt[-2] >> yypvt[-0];} break;
+case 9:
+# line 40 "cpy.y"
+{yyval = yypvt[-2] < yypvt[-0];} break;
+case 10:
+# line 42 "cpy.y"
+{yyval = yypvt[-2] > yypvt[-0];} break;
+case 11:
+# line 44 "cpy.y"
+{yyval = yypvt[-2] <= yypvt[-0];} break;
+case 12:
+# line 46 "cpy.y"
+{yyval = yypvt[-2] >= yypvt[-0];} break;
+case 13:
+# line 48 "cpy.y"
+{yyval = yypvt[-2] == yypvt[-0];} break;
+case 14:
+# line 50 "cpy.y"
+{yyval = yypvt[-2] != yypvt[-0];} break;
+case 15:
+# line 52 "cpy.y"
+{yyval = yypvt[-2] & yypvt[-0];} break;
+case 16:
+# line 54 "cpy.y"
+{yyval = yypvt[-2] ^ yypvt[-0];} break;
+case 17:
+# line 56 "cpy.y"
+{yyval = yypvt[-2] | yypvt[-0];} break;
+case 18:
+# line 58 "cpy.y"
+{yyval = yypvt[-2] && yypvt[-0];} break;
+case 19:
+# line 60 "cpy.y"
+{yyval = yypvt[-2] || yypvt[-0];} break;
+case 20:
+# line 62 "cpy.y"
+{yyval = yypvt[-4] ? yypvt[-2] : yypvt[-0];} break;
+case 21:
+# line 64 "cpy.y"
+{yyval = yypvt[-0];} break;
+case 22:
+# line 66 "cpy.y"
+{yyval = yypvt[-0];} break;
+case 23:
+# line 69 "cpy.y"
+{yyval = -yypvt[-0];} break;
+case 24:
+# line 71 "cpy.y"
+{yyval = !yypvt[-0];} break;
+case 25:
+# line 73 "cpy.y"
+{yyval = ~yypvt[-0];} break;
+case 26:
+# line 75 "cpy.y"
+{yyval = yypvt[-1];} break;
+case 27:
+# line 77 "cpy.y"
+{yyval= yypvt[-1];} break;
+case 28:
+# line 79 "cpy.y"
+{yyval = yypvt[-0];} break;
+case 29:
+# line 81 "cpy.y"
+{yyval= yypvt[-0];} break;
+               }
+               goto yystack;  /* stack new state and value */
+
+       }
index d593a16..c180f6c 100644 (file)
@@ -80,4 +80,89 @@ term:
        | number
                ={$$= $1;}
 %%
-# include "yylex.c"
+# include "cpp.h"
+
+#define isid(a)  ((fastab+COFF)[a]&IB)
+#define IB 1
+/*     #if '\377' < 0          it would be nice if this worked properly!!!!! */
+#if pdp11 | vax | mc68000
+#define COFF 128
+#else
+#define COFF 0
+#endif
+
+yylex() {
+       static int ifdef=0;
+       static char *op2[]={"||",  "&&" , ">>", "<<", ">=", "<=", "!=", "=="};
+       static int  val2[]={OROR, ANDAND,  RS,   LS,   GE,   LE,   NE,   EQ};
+       static char *opc="b\bt\tn\nf\fr\r\\\\";
+       register char savc, *s; int val;
+       register char **p2;
+       struct symtab *sp;
+
+for (;;) {
+       int opt_passcom = passcom;      /* this crap makes #if's work */
+       passcom = 0;                    /* even with -C option */
+       newp=skipbl(newp);              /* (else comments make syntax errs) */
+       passcom = opt_passcom;          /* nb: lint uses -C so its useful! */
+       if (*inp=='\n') return(stop);   /* end of #if */
+       savc= *newp; *newp='\0';
+       for (p2=op2+8; --p2>=op2; )     /* check 2-char ops */
+               if (0==strcmp(*p2,inp)) {val=val2[p2-op2]; goto ret;}
+       s="+-*/%<>&^|?:!~(),";  /* check 1-char ops */
+       while (*s) if (*s++== *inp) {val= *--s; goto ret;}
+       if (*inp<='9' && *inp>='0') {/* a number */
+               if (*inp=='0') yylval= (inp[1]=='x' || inp[1]=='X') ?
+                       tobinary(inp+2,16) : tobinary(inp+1,8);
+               else yylval=tobinary(inp,10);
+               val=number;
+       } else if (isid(*inp)) {
+               if (0==strcmp(inp,"defined")) {ifdef=1; ++flslvl; val=DEFINED;}
+               else {
+                       sp=lookup(inp,-1); if (ifdef!=0) {ifdef=0; --flslvl;}
+                       yylval= (sp->value==0) ? 0 : 1;
+                       val=number;
+               }
+       } else  if (*inp=='\'') {/* character constant */
+               val=number;
+               if (inp[1]=='\\') {/* escaped */
+                       char c; if (newp[-1]=='\'') newp[-1]='\0';
+                       s=opc;
+                       while (*s) if (*s++!=inp[2]) ++s; else {yylval= *s; goto ret;}
+                       if (inp[2]<='9' && inp[2]>='0') yylval=c=tobinary(inp+2,8);
+                       else yylval=inp[2];
+               } else yylval=inp[1];
+       } else if (0==strcmp("\\\n",inp)) {*newp=savc; continue;}
+       else {
+               *newp=savc; pperror("Illegal character %c in preprocessor if", *inp);
+               continue;
+       }
+ret:
+       *newp=savc; outp=inp=newp; return(val);
+}
+}
+
+tobinary(st, b) char *st; {
+       int n, c, t;
+       char *s;
+       n=0;
+       s=st;
+       while (c = *s++) {
+       switch(c) {
+               case '0': case '1': case '2': case '3': case '4': 
+               case '5': case '6': case '7': case '8': case '9': 
+                       t = c-'0'; break;
+               case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 
+                       t = c-'a'+10; if (b>10) break;
+               case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 
+                       t = c - 'A'+10; if (b>10) break;
+               default:
+                       t = -1;
+                       if ( c=='l' || c=='L') if (*s=='\0') break;
+                       pperror("Illegal number %s", st);
+       }
+       if (t<0) break;
+       n = n*b+t;
+       }
+return(n);
+}
diff --git a/lib/cpp/groups.txt b/lib/cpp/groups.txt
new file mode 100644 (file)
index 0000000..dc5cc37
--- /dev/null
@@ -0,0 +1,2 @@
+cpp.c cpp.h
+cpy.c cpp.h
diff --git a/lib/cpp/yylex.c b/lib/cpp/yylex.c
deleted file mode 100644 (file)
index e2d4c73..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-#ifndef lint
-static char sccsid[] = "@(#)yylex.c    1.3 7/1/83";
-#endif lint
-
-#define isid(a)  ((fastab+COFF)[a]&IB)
-#define IB 1
-/*     #if '\377' < 0          it would be nice if this worked properly!!!!! */
-#if pdp11 | vax | mc68000
-#define COFF 128
-#else
-#define COFF 0
-#endif
-
-yylex() {
-       static int ifdef=0;
-       static char *op2[]={"||",  "&&" , ">>", "<<", ">=", "<=", "!=", "=="};
-       static int  val2[]={OROR, ANDAND,  RS,   LS,   GE,   LE,   NE,   EQ};
-       static char *opc="b\bt\tn\nf\fr\r\\\\";
-       extern char fastab[];
-       extern char *outp,*inp,*newp; extern int flslvl;
-       register char savc, *s; char *skipbl(); int val;
-       register char **p2;
-       struct symtab {
-               char *name;
-               char *value;
-       } *sp, *lookup();
-
-for (;;) {
-       extern int passcom;             /* this crap makes #if's work */
-       int opt_passcom = passcom;      /* even with -C option */
-       passcom = 0;                    /* (else comments make syntax errs) */
-       newp=skipbl(newp);
-       passcom = opt_passcom;          /* nb: lint uses -C so its useful! */
-       if (*inp=='\n') return(stop);   /* end of #if */
-       savc= *newp; *newp='\0';
-       for (p2=op2+8; --p2>=op2; )     /* check 2-char ops */
-               if (0==strcmp(*p2,inp)) {val=val2[p2-op2]; goto ret;}
-       s="+-*/%<>&^|?:!~(),";  /* check 1-char ops */
-       while (*s) if (*s++== *inp) {val= *--s; goto ret;}
-       if (*inp<='9' && *inp>='0') {/* a number */
-               if (*inp=='0') yylval= (inp[1]=='x' || inp[1]=='X') ?
-                       tobinary(inp+2,16) : tobinary(inp+1,8);
-               else yylval=tobinary(inp,10);
-               val=number;
-       } else if (isid(*inp)) {
-               if (0==strcmp(inp,"defined")) {ifdef=1; ++flslvl; val=DEFINED;}
-               else {
-                       sp=lookup(inp,-1); if (ifdef!=0) {ifdef=0; --flslvl;}
-                       yylval= (sp->value==0) ? 0 : 1;
-                       val=number;
-               }
-       } else  if (*inp=='\'') {/* character constant */
-               val=number;
-               if (inp[1]=='\\') {/* escaped */
-                       char c; if (newp[-1]=='\'') newp[-1]='\0';
-                       s=opc;
-                       while (*s) if (*s++!=inp[2]) ++s; else {yylval= *s; goto ret;}
-                       if (inp[2]<='9' && inp[2]>='0') yylval=c=tobinary(inp+2,8);
-                       else yylval=inp[2];
-               } else yylval=inp[1];
-       } else if (0==strcmp("\\\n",inp)) {*newp=savc; continue;}
-       else {
-               *newp=savc; pperror("Illegal character %c in preprocessor if", *inp);
-               continue;
-       }
-ret:
-       *newp=savc; outp=inp=newp; return(val);
-}
-}
-
-tobinary(st, b) char *st; {
-       int n, c, t;
-       char *s;
-       n=0;
-       s=st;
-       while (c = *s++) {
-       switch(c) {
-               case '0': case '1': case '2': case '3': case '4': 
-               case '5': case '6': case '7': case '8': case '9': 
-                       t = c-'0'; break;
-               case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 
-                       t = c-'a'+10; if (b>10) break;
-               case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 
-                       t = c - 'A'+10; if (b>10) break;
-               default:
-                       t = -1;
-                       if ( c=='l' || c=='L') if (*s=='\0') break;
-                       pperror("Illegal number %s", st);
-       }
-       if (t<0) break;
-       n = n*b+t;
-       }
-return(n);
-}
index 18ec653..4b70a1f 100755 (executable)
@@ -3,7 +3,7 @@
 ROOT=`dirname $0`/..
 #ROOT=../..
 ROOT=`cd $ROOT && pwd`
-INCLUDE=$ROOT/cross/usr/include
+INCLUDE=$ROOT/stage0/usr/include
 SCRIPTS=$ROOT/scripts
 
 all_c=`echo *.c`
@@ -141,10 +141,50 @@ then
   grep '\.h:' oldprotos.txt >oldprotos.temp
 
   sed -e 's/^[A-Za-z_].*__P.*;$/\/\*AAA&\*\//' -i $std_h
-  mv $INCLUDE/varargs.h $INCLUDE/varargs.h.save
-  echo "#define va_list char *" >$INCLUDE/varargs.h
-  echo "#define va_list char *" >$INCLUDE/stdarg.h
+  if ! test -f $INCLUDE/setjmp.h.save
+  then
+    mv $INCLUDE/setjmp.h $INCLUDE/setjmp.h.save
+    mv $INCLUDE/stdarg.h $INCLUDE/stdarg.h.save
+    mv $INCLUDE/stdint.h $INCLUDE/stdint.h.save
+    mv $INCLUDE/varargs.h $INCLUDE/varargs.h.save
+  fi
+  cat <<EOF >$INCLUDE/setjmp.h
+#ifndef _SETJMP_H_
+#define _SETJMP_H_
+typedef int jmp_buf;
+#endif
+EOF
+#  cat <<EOF >$INCLUDE/stdarg.h
+##ifndef _STDARG_H_
+##define _STDARG_H_
+#typedef int va_list;
+##endif
+#EOF
+  touch $INCLUDE/stdarg.h
+#  cat <<EOF >$INCLUDE/stdint.h
+##ifndef _STDINT_H_
+##define _STDINT_H_
+#typedef int int8_t;
+#typedef int int16_t;
+#typedef int int32_t;
+#typedef int int64_t;
+#typedef int intptr_t;
+#typedef int ssize_t;
+#typedef int uint8_t;
+#typedef int uint16_t;
+#typedef int uint32_t;
+#typedef int uint64_t;
+#typedef int uintptr_t;
+#typedef int size_t;
+##endif
+#EOF
   touch $INCLUDE/stdint.h
+  cat <<EOF >$INCLUDE/varargs.h
+#ifndef _VARARGS_H_
+#define _VARARGS_H_
+typedef int va_list;
+#endif
+EOF
   for i in $all_c
   do
     echo "i=$i"
@@ -214,7 +254,9 @@ EOF
       fi
     fi
   done
-  rm $INCLUDE/stdint.h $INCLUDE/stdarg.h
+  mv $INCLUDE/setjmp.h.save $INCLUDE/setjmp.h
+  mv $INCLUDE/stdarg.h.save $INCLUDE/stdarg.h
+  mv $INCLUDE/stdint.h.save $INCLUDE/stdint.h
   mv $INCLUDE/varargs.h.save $INCLUDE/varargs.h
   sed -e 's/^\/\*AAA\(.*\)\*\/$/\1/' -i $std_h
 fi >>ansify.log
@@ -257,10 +299,58 @@ then
     fi
   done
 
+  if ! test -f $INCLUDE/setjmp.h.save
+  then
+    mv $INCLUDE/setjmp.h $INCLUDE/setjmp.h.save
+    mv $INCLUDE/stdarg.h $INCLUDE/stdarg.h.save
+    mv $INCLUDE/stdint.h $INCLUDE/stdint.h.save
+    mv $INCLUDE/varargs.h $INCLUDE/varargs.h.save
+  fi
+  cat <<EOF >$INCLUDE/setjmp.h
+#ifndef _SETJMP_H_
+#define _SETJMP_H_
+typedef int jmp_buf;
+#endif
+EOF
+#  cat <<EOF >$INCLUDE/stdarg.h
+##ifndef _STDARG_H_
+##define _STDARG_H_
+#typedef int va_list;
+##endif
+#EOF
+  touch $INCLUDE/stdarg.h
+#  cat <<EOF >$INCLUDE/stdint.h
+##ifndef _STDINT_H_
+##define _STDINT_H_
+#typedef int int8_t;
+#typedef int int16_t;
+#typedef int int32_t;
+#typedef int int64_t;
+#typedef int intptr_t;
+#typedef int ssize_t;
+#typedef int uint8_t;
+#typedef int uint16_t;
+#typedef int uint32_t;
+#typedef int uint64_t;
+#typedef int uintptr_t;
+#typedef int size_t;
+##endif
+#EOF
+  touch $INCLUDE/stdint.h
+  cat <<EOF >$INCLUDE/varargs.h
+#ifndef _VARARGS_H_
+#define _VARARGS_H_
+typedef int va_list;
+#endif
+EOF
   for i in $std_h
   do
     $SCRIPTS/nocomment <$i |$SCRIPTS/nostring >$i.nocomm
   done
+  mv $INCLUDE/setjmp.h.save $INCLUDE/setjmp.h
+  mv $INCLUDE/stdarg.h.save $INCLUDE/stdarg.h
+  mv $INCLUDE/stdint.h.save $INCLUDE/stdint.h
+  mv $INCLUDE/varargs.h.save $INCLUDE/varargs.h
 
   if test -f conflicts.txt
   then
@@ -644,7 +734,6 @@ then
   fi
 
   # removing useless extra header inclusions that are pulled in anyway
-  touch $INCLUDE/stdarg.h
   rm -f a
   for i in $all_h $std_h
   do
@@ -686,7 +775,7 @@ then
       fi
     fi
   done
-  rm -f $INCLUDE/stdarg.h temp.c
+  rm -f temp.c
   tsort <a >b
 fi >>ansify.log
 
index c16f51f..bda5f9f 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 ROOT=`dirname $0`/..
 ROOT=`cd $ROOT && pwd`
-INCLUDE=$ROOT/cross/usr/include
+INCLUDE=$ROOT/stage0/usr/include
 grep -H "^$INCLUDE/$1$" *.uses |sed -e "s:\.uses\:.*: $1:" >>conflicts.txt
 LC_ALL=C sort <conflicts.txt |uniq >a
 mv a conflicts.txt