Ansified lib/cpp
authorNick Downing <downing.nick@gmail.com>
Thu, 2 Feb 2017 13:46:55 +0000 (00:46 +1100)
committerNick Downing <downing.nick@gmail.com>
Thu, 2 Feb 2017 13:46:55 +0000 (00:46 +1100)
lib/cpp/cpp.c
lib/cpp/cpp.h
lib/cpp/cpy.c

index edd0649..36cd014 100644 (file)
@@ -1,6 +1,20 @@
-#ifndef lint
+/*#include <ctype.h> gen.h*/
+#include <gen.h>
+#include <stdio.h>
+/*#include <strings.h> gen.h*/
+#include <sys/file.h>
+#ifdef __STDC__
+#include <stdarg.h>
+#define _va_start(argp, arg) va_start(argp, arg)
+#else
+#include <varargs.h>
+#define _va_start(argp, arg) va_start(argp)
+#endif
+#include "cpp.h"
+
+#if defined(DOSCCS) && !defined(lint)
 static char sccsid[] = "@(#)cpp.c      1.14 4/27/86";
-#endif lint
+#endif
 
 #ifdef FLEXNAMES
 #define        NCPS    128
@@ -8,10 +22,10 @@ static char sccsid[] = "@(#)cpp.c    1.14 4/27/86";
 #define        NCPS    8
 #endif
 
-# include "stdio.h"
-# include "ctype.h"
-# include "varargs.h"
-# include "cpp.h"
+/*# include "stdio.h"*/
+/*# include "ctype.h"*/
+/*# include "varargs.h"*/
+/*# include "cpp.h"*/
 
 /* C command
 /* written by John F. Reiser
@@ -114,7 +128,7 @@ char buffer[NCPS+BUFSIZ+BUFSIZ+NCPS];
 
 char   *lastcopy;
 
-char *malloc(), *realloc();
+/*char *malloc(), *realloc();*/
 
 # define DROP 0xFE     /* special character not legal ASCII or EBCDIC */
 # define WARN DROP
@@ -147,8 +161,8 @@ int fins[MAXINC];
 int    lineno[MAXINC];
 
 char   *dirs[10];      /* -I and <> directories */
-char *strdex(), *copy(), *subst(), *trmdir();
-struct symtab *stsym();
+/*char *strdex(), *copy(), *subst(), *trmdir();*/
+/*struct symtab *stsym();*/
 int    fin     = FIRSTOPEN;
 FILE   *fout   = stdout;
 int    nd      = 1;
@@ -203,9 +217,7 @@ struct symtab *identloc;    /* Sys 5r3 compatibility */
 int    trulvl;
 int    flslvl;
 
-sayline(where)
-       int where;
-{
+int sayline(where) int where; {
        if (mflag && where==START) fprintf(mout, "%s: %s\n", infile, fnames[ifno]);
        if (pflag==0) fprintf(fout,"# %d \"%s\"\n", lineno[ifno], fnames[ifno]);
 }
@@ -263,7 +275,7 @@ sayline(where)
 /* are available for use.
 */
 
-dump() {
+int dump() {
 /* write part of buffer which lies between  outp  and  inp .
 /* this should be a direct call to 'write', but the system slows to a crawl
 /* if it has to do an unaligned copy.  thus we buffer.  this silly loop
@@ -305,8 +317,7 @@ dump() {
        outp=p1;
 }
 
-char *
-refill(p) register char *p; {
+char *refill(p) register char *p; {
 /* dump buffer.  save chars from inp to p.  read into buffer at pbuf,
 /* contiguous with p.  update pointers, return new p.
 */
@@ -356,8 +367,7 @@ refill(p) register char *p; {
 #define BEG 0
 #define LF 1
 
-char *
-cotoken(p) register char *p; {
+char *cotoken(p) register char *p; {
        register int c,i; char quoc;
        static int state = BEG;
 
@@ -520,14 +530,12 @@ prevlf:
 } /* end of infinite loop */
 }
 
-char *
-skipbl(p) register char *p; {/* get next non-blank token */
+char *skipbl(p) register char *p; {/* get next non-blank token */
        do {outp=inp=p; p=cotoken(p);} while ((toktyp+COFF)[*inp]==BLANK);
        return(p);
 }
 
-char *
-unfill(p) register char *p; {
+char *unfill(p) register char *p; {
 /* take <= BUFSIZ chars from right end of buffer and put them on instack .
 /* slide rest of buffer to the right, update pointers, return new p.
 */
@@ -552,8 +560,7 @@ unfill(p) register char *p; {
        d=np-outp; outp+=d; inp+=d; macdam+=d; return(p+d);
 }
 
-char *
-doincl(p) register char *p; {
+char *doincl(p) register char *p; {
        int filok,inctype;
        register char *cp; char **dirp,*nfil; char filname[BUFSIZ];
 
@@ -626,14 +633,13 @@ doincl(p) register char *p; {
        return(p);
 }
 
-equfrm(a,p1,p2) register char *a,*p1,*p2; {
+int equfrm(a, p1, p2) register char *a; register char *p1; register char *p2; {
        register char c; int flag;
        c= *p2; *p2='\0';
        flag=strcmp(a,p1); *p2=c; return(flag==SAME);
 }
 
-char *
-dodef(p) char *p; {/* process '#define' */
+char *dodef(p) char *p; {/* process '#define' */
        register char *pin,*psav,*cf;
        char **pf,**qf; int b,c,params; struct symtab *np;
        char *oldval;
@@ -744,8 +750,7 @@ dodef(p) char *p; {/* process '#define' */
 #define fasscan() ptrtab=fastab+COFF
 #define sloscan() ptrtab=slotab+COFF
 
-char *
-control(p) register char *p; {/* find and handle preprocessor control lines */
+char *control(p) register char *p; {/* find and handle preprocessor control lines */
        register struct symtab *np;
 for (;;) {
        fasscan(); p=cotoken(p); if (*inp=='\n') ++inp; dump();
@@ -841,10 +846,7 @@ for (;;) {
 }
 }
 
-char *
-savestring(start, finish)
-       register char *start, *finish;
-{
+char *savestring(start, finish) register char *start; register char *finish; {
        char *retbuf;
        register char *cp;
 
@@ -856,8 +858,7 @@ savestring(start, finish)
        return(retbuf);
 }
 
-struct symtab *
-stsym(s) register char *s; {
+struct symtab *stsym(s) register char *s; {
        char buf[BUFSIZ]; register char *p;
 
        /* make definition look exactly like end of #define line */
@@ -870,8 +871,7 @@ stsym(s) register char *s; {
        sloscan(); dodef(buf); return(lastsym);
 }
 
-struct symtab *
-ppsym(s) char *s; {/* kluge */
+struct symtab *ppsym(s) char *s; {/* kluge */
        register struct symtab *sp;
        register char *name;
 
@@ -880,7 +880,7 @@ ppsym(s) char *s; {/* kluge */
        cinit=0; return(sp);
 }
 
-vpperror(s,argp) char *s; va_list argp; {
+int vpperror(s, argp) char *s; va_list argp; {
        if (fnames[ifno][0]) fprintf(stderr,
 # if gcos
                        "*%c*   \"%s\", line ", exfail >= 0 ? 'F' : 'W',
@@ -894,37 +894,49 @@ vpperror(s,argp) char *s; va_list argp; {
        ++exfail;
 }
 
-pperror(s,va_alist) char *s; va_dcl {
+#ifdef __STDC__
+int pperror(char *s, ...)
+#else
+int pperror(s, va_alist) char *s; va_dcl
+#endif
+{
        va_list argp;
 
-       va_start(argp);
+       _va_start(argp, fmt);
        vpperror(s,argp);
        va_end(argp);
 }
 
-yyerror(s,va_alist) char *s; va_dcl {
+#ifdef __STDC__
+int yyerror(char *s, ...)
+#else
+int yyerror(s, va_alist) char *s; va_dcl
+#endif
+{
        va_list argp;
 
-       va_start(argp);
+       _va_start(argp, fmt);
        vpperror(s,argp);
        va_end(argp);
 }
 
-ppwarn(s,va_alist) char *s; va_dcl {
+#ifdef __STDC__
+int ppwarn(char *s, ...)
+#else
+int ppwarn(s, va_alist) char *s; va_dcl
+#endif
+{
        va_list argp;
 
        int fail = exfail;
        exfail = -1;
-       va_start(argp);
+       _va_start(argp, fmt);
        vpperror(s,argp);
        va_end(argp);
        exfail = fail;
 }
 
-struct symtab *
-lookup(namep, enterf)
-char *namep;
-{
+struct symtab *lookup(namep, enterf) char *namep; int enterf; {
        register char *np, *snp;
        register int c, i; int around;
        register struct symtab *sp;
@@ -948,8 +960,7 @@ char *namep;
        return(lastsym=sp);
 }
 
-struct symtab *
-slookup(p1,p2,enterf) register char *p1,*p2; int enterf;{
+struct symtab *slookup(p1, p2, enterf) register char *p1; register char *p2; int enterf; {
        register char *p3; char c2,c3; struct symtab *np;
                 c2= *p2; *p2='\0';     /* mark end of token */
        if ((p2-p1)>NCPS) p3=p1+NCPS; else p3=p2;
@@ -961,8 +972,7 @@ slookup(p1,p2,enterf) register char *p1,*p2; int enterf;{
        return(np);
 }
 
-char *
-subst(p,sp) register char *p; struct symtab *sp; {
+char *subst(p, sp) register char *p; struct symtab *sp; {
        static char match[]="%s: argument mismatch";
        register char *ca,*vp; int params;
        char *actual[MAXFRM]; /* actual[n] is text of nth actual   */
@@ -1043,11 +1053,7 @@ subst(p,sp) register char *p; struct symtab *sp; {
        return(p);
 }
 
-
-
-
-char *
-trmdir(s) register char *s; {
+char *trmdir(s) register char *s; {
        register char *p = s;
        while (*p++); --p; while (p>s && *--p!='/');
 # if unix
@@ -1057,8 +1063,7 @@ trmdir(s) register char *s; {
        return(s);
 }
 
-char *
-copy(s) register char *s; {
+char *copy(s) register char *s; {
        register char *old;
 
        old = malloc(strlen(s)+1);
@@ -1067,17 +1072,14 @@ copy(s) register char *s; {
        return(lastcopy=old);
 }
 
-char *
-strdex(s,c) char *s,c; {
+char *strdex(s, c) char *s; int c; {
        while (*s) if (*s++==c) return(--s);
        return(0);
 }
 
-yywrap(){ return(1); }
+int yywrap() { return(1); }
 
-main(argc,argv)
-       char *argv[];
-{
+int main(argc, argv) int argc; char *argv[]; {
        register int i,c;
        register char *p;
        char *tf,**cp2;
@@ -1135,10 +1137,8 @@ main(argc,argv)
        fnames[ifno=0] = (char *)inquire(stdin, _FILENAME);
        dirnams[0] = dirs[0] = trmdir(copy(fnames[0]));
 # endif
-       for(i=1; i<argc; i++)
-               {
-               switch(argv[i][0])
-                       {
+       for(i=1; i<argc; i++) {
+               switch(argv[i][0]) {
                        case '-':
 # if gcos
                        switch(toupper(argv[i][1])) /* case-independent on GCOS */
index 618f4cf..ecf223e 100644 (file)
@@ -1,3 +1,10 @@
+#ifndef _CPP_H_
+#define _CPP_H_
+
+#ifdef __STDC__
+#include <stdarg.h>
+#endif
+
 struct symtab {
        char    *name;
        char    *value;
@@ -8,5 +15,47 @@ extern char *outp,*inp,*newp;
 extern int flslvl;
 extern int passcom;
 
-char *skipbl(); 
-struct symtab *lookup(), *slookup();
+/*char *skipbl();*/ 
+/*struct symtab *lookup(), *slookup();*/
+
+#ifndef __P
+#ifdef __STDC__
+#define __P(args) args
+#else
+#define __P(args) ()
+#endif
+#endif
+
+/* cpp.c */
+int sayline __P((int where));
+int dump __P((void));
+char *refill __P((register char *p));
+char *cotoken __P((register char *p));
+char *skipbl __P((register char *p));
+char *unfill __P((register char *p));
+char *doincl __P((register char *p));
+int equfrm __P((register char *a, register char *p1, register char *p2));
+char *dodef __P((char *p));
+char *control __P((register char *p));
+char *savestring __P((register char *start, register char *finish));
+struct symtab *stsym __P((register char *s));
+struct symtab *ppsym __P((char *s));
+int vpperror __P((char *s, va_list argp));
+int pperror __P((char *s, ...));
+int yyerror __P((char *s, ...));
+int ppwarn __P((char *s, ...));
+struct symtab *lookup __P((char *namep, int enterf));
+struct symtab *slookup __P((register char *p1, register char *p2, int enterf));
+char *subst __P((register char *p, struct symtab *sp));
+char *trmdir __P((register char *s));
+char *copy __P((register char *s));
+char *strdex __P((char *s, int c));
+int yywrap __P((void));
+int main __P((int argc, char *argv[]));
+
+/* cpy.c */
+int yylex __P((void));
+int tobinary __P((char *st, int b));
+int yyparse __P((void));
+
+#endif
index 7d3f8a1..f62ffec 100644 (file)
@@ -1,3 +1,7 @@
+#include <stdio.h>
+#include <strings.h>
+#include "cpp.h"
+
 # define number 257
 # define stop 258
 # define DEFINED 259
@@ -25,7 +29,7 @@ YYSTYPE yylval, yyval;
 
 # line 82 "cpy.y"
 
-# include "cpp.h"
+/*# include "cpp.h"*/
 
 #define isid(a)  ((fastab+COFF)[a]&IB)
 #define IB 1
@@ -36,7 +40,7 @@ YYSTYPE yylval, yyval;
 #define COFF 0
 #endif
 
-yylex() {
+int yylex() {
        static int ifdef=0;
        static char *op2[]={"||",  "&&" , ">>", "<<", ">=", "<=", "!=", "=="};
        static int  val2[]={OROR, ANDAND,  RS,   LS,   GE,   LE,   NE,   EQ};
@@ -87,7 +91,7 @@ ret:
 }
 }
 
-tobinary(st, b) char *st; {
+int tobinary(st, b) char *st; int b; {
        int n, c, t;
        char *s;
        n=0;
@@ -350,7 +354,6 @@ int yyparse() {
        yyabort:
                        return(1);
 
-
                case 3:  /* no shift yet; clobber input char */
 
 #ifdef YYDEBUG