From 696ad2caeee50cabfdbdf65c6cfb41aa532b7dca Mon Sep 17 00:00:00 2001 From: millert Date: Sun, 6 Apr 1997 06:31:45 +0000 Subject: [PATCH] Use long, not int when casting pointers and storing as integers. Now compiles on alpha w/o warnings. --- usr.bin/awk/awk.h | 8 ++++---- usr.bin/awk/awkgram.y | 2 +- usr.bin/awk/b.c | 35 ++++++++++++++++---------------- usr.bin/awk/lexyy.c | 4 ++-- usr.bin/awk/run.c | 46 +++++++++++++++++++++---------------------- 5 files changed, 48 insertions(+), 47 deletions(-) diff --git a/usr.bin/awk/awk.h b/usr.bin/awk/awk.h index 213e43302c8..23d1823c4ec 100644 --- a/usr.bin/awk/awk.h +++ b/usr.bin/awk/awk.h @@ -193,7 +193,7 @@ extern Node *nullnode; #define NFIELD 4 -extern int pairstack[], paircnt; +extern long pairstack[], paircnt; #define notlegal(n) (n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN] == nullproc) #define isvalue(n) ((n)->ntype == NVALUE) @@ -221,13 +221,13 @@ extern int pairstack[], paircnt; #define NSTATES 32 typedef struct rrow { - int ltype; + long ltype; union { int i; Node *np; char *up; } lval; /* because Al stores a pointer in it! */ - int *lfollow; + long *lfollow; } rrow; typedef struct fa { @@ -235,7 +235,7 @@ typedef struct fa { int anchor; int use; uschar gototab[NSTATES][NCHARS]; - int *posns[NSTATES]; + long *posns[NSTATES]; uschar out[NSTATES]; int initstat; int curstat; diff --git a/usr.bin/awk/awkgram.y b/usr.bin/awk/awkgram.y index e1cb9f6e6fe..60ad49891c1 100644 --- a/usr.bin/awk/awkgram.y +++ b/usr.bin/awk/awkgram.y @@ -41,7 +41,7 @@ Node *arglist = 0; /* list of args for current function */ %union { Node *p; Cell *cp; - int i; + long i; char *s; } diff --git a/usr.bin/awk/b.c b/usr.bin/awk/b.c index 9952d94ed35..3ec883ee171 100644 --- a/usr.bin/awk/b.c +++ b/usr.bin/awk/b.c @@ -59,13 +59,13 @@ int *tmpset; int maxsetvec = 0; int rtok; /* next token in current re */ -int rlxval; +long rlxval; char *rlxstr; char *prestr; /* current position in current re */ char *lastre; /* origin of last re */ -static int setcnt; -static int poscnt; +static long setcnt; +static long poscnt; char *patbeg; int patlen; @@ -134,9 +134,9 @@ fa *mkdfa(char *s, int anchor) /* does the real work of making a dfa */ f->accept = poscnt-1; /* penter has computed number of positions in re */ cfoll(f, p1); /* set up follow sets */ freetr(p1); - if ((f->posns[0] = (int *) calloc(1, *(f->re[0].lfollow)*sizeof(int))) == NULL) + if ((f->posns[0] = (long *) calloc(1, *(f->re[0].lfollow)*sizeof(int))) == NULL) overflo("out of space in makedfa"); - if ((f->posns[1] = (int *) calloc(1, sizeof(int))) == NULL) + if ((f->posns[1] = (long *) calloc(1, sizeof(int))) == NULL) overflo("out of space in makedfa"); *f->posns[1] = 0; f->initstat = makeinit(f, anchor); @@ -154,7 +154,7 @@ int makeinit(fa *f, int anchor) f->reset = 0; k = *(f->re[0].lfollow); xfree(f->posns[2]); - if ((f->posns[2] = (int *) calloc(1, (k+1)*sizeof(int))) == NULL) + if ((f->posns[2] = (long *) calloc(1, (k+1)*sizeof(int))) == NULL) overflo("out of space in makeinit"); for (i=0; i <= k; i++) { (f->posns[2])[i] = (f->re[0].lfollow)[i]; @@ -329,12 +329,12 @@ void overflo(char *s) void cfoll(fa *f, Node *v) /* enter follow set of each leaf of vertex v into lfollow[leaf] */ { int i; - int *p; + long *p; switch (type(v)) { LEAF - f->re[(int) left(v)].ltype = type(v); - f->re[(int) left(v)].lval.np = right(v); + f->re[(long) left(v)].ltype = type(v); + f->re[(long) left(v)].lval.np = right(v); while (f->accept >= maxsetvec) { /* guessing here! */ maxsetvec *= 4; setvec = (int *) realloc(setvec, maxsetvec * sizeof(int)); @@ -347,9 +347,9 @@ void cfoll(fa *f, Node *v) /* enter follow set of each leaf of vertex v into lfo setvec[i] = 0; setcnt = 0; follow(v); /* computes setvec and setcnt */ - if ((p = (int *) calloc(1, (setcnt+1)*sizeof(int))) == NULL) + if ((p = (long *) calloc(1, (setcnt+1)*sizeof(int))) == NULL) overflo("out of space building follow set"); - f->re[(int) left(v)].lfollow = p; + f->re[(long) left(v)].lfollow = p; *p = setcnt; for (i = f->accept; i >= 0; i--) if (setvec[i] == 1) @@ -371,11 +371,12 @@ void cfoll(fa *f, Node *v) /* enter follow set of each leaf of vertex v into lfo int first(Node *p) /* collects initially active leaves of p into setvec */ /* returns 1 if p matches empty string */ { - int b, lp; + int b; + long lp; switch (type(p)) { LEAF - lp = (int) left(p); /* look for high-water mark of subscripts */ + lp = (long) left(p); /* look for high-water mark of subscripts */ while (setcnt >= maxsetvec || lp >= maxsetvec) { /* guessing here! */ maxsetvec *= 4; setvec = (int *) realloc(setvec, maxsetvec * sizeof(int)); @@ -507,7 +508,7 @@ int pmatch(fa *f, char *p0) /* longest match, for sub */ for (i = 2; i <= f->curstat; i++) xfree(f->posns[i]); k = *f->posns[0]; - if ((f->posns[2] = (int *) calloc(1, (k+1)*sizeof(int))) == NULL) + if ((f->posns[2] = (long *) calloc(1, (k+1)*sizeof(int))) == NULL) overflo("out of space in pmatch"); for (i = 0; i <= k; i++) (f->posns[2])[i] = (f->posns[0])[i]; @@ -557,7 +558,7 @@ int nematch(fa *f, char *p0) /* non-empty match, for sub */ for (i = 2; i <= f->curstat; i++) xfree(f->posns[i]); k = *f->posns[0]; - if ((f->posns[2] = (int *) calloc(1, (k+1)*sizeof(int))) == NULL) + if ((f->posns[2] = (long *) calloc(1, (k+1)*sizeof(int))) == NULL) overflo("out of state space"); for (i = 0; i <= k; i++) (f->posns[2])[i] = (f->posns[0])[i]; @@ -736,7 +737,7 @@ int relex(void) /* lexical analyzer for reparse */ int cgoto(fa *f, int s, int c) { int i, j, k; - int *p, *q; + long *p, *q; if (c < 0) ERROR "can't happen: neg char %d in cgoto", c FATAL; @@ -809,7 +810,7 @@ int cgoto(fa *f, int s, int c) for (i = 0; i < NCHARS; i++) f->gototab[f->curstat][i] = 0; xfree(f->posns[f->curstat]); - if ((p = (int *) calloc(1, (setcnt+1)*sizeof(int))) == NULL) + if ((p = (long *) calloc(1, (setcnt+1)*sizeof(int))) == NULL) overflo("out of space in cgoto"); f->posns[f->curstat] = p; diff --git a/usr.bin/awk/lexyy.c b/usr.bin/awk/lexyy.c index e58761ae0f9..a2e74470d0d 100644 --- a/usr.bin/awk/lexyy.c +++ b/usr.bin/awk/lexyy.c @@ -1902,7 +1902,7 @@ yylook(void){ } # endif yyr = yyt; - if ( (int)yyt > (int)yycrank){ + if ( (long)yyt > (long)yycrank){ yyt = yyr + yych; if (yyt <= yytop && yyt->verify+yysvec == yystate){ if(yyt->advance+yysvec == YYLERR) /* error transitions */ @@ -1912,7 +1912,7 @@ yylook(void){ } } # ifdef YYOPTIM - else if((int)yyt < (int)yycrank) { /* r < yycrank */ + else if((long)yyt < (long)yycrank) { /* r < yycrank */ yyt = yyr = yycrank+(yycrank-yyt); # ifdef LEXDEBUG if(debug)fprintf(yyout,"compressed state\n"); diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index 5e03a0421ee..04ee33e603e 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.10 1997/01/29 18:33:56 kstailey Exp $ */ +/* $OpenBSD: run.c,v 1.11 1997/04/06 06:31:51 millert Exp $ */ /**************************************************************** Copyright (C) AT&T and Lucent Technologies 1996 All Rights Reserved @@ -66,8 +66,8 @@ void tempfree(Cell *p) { jmp_buf env; #define PA2NUM 29 /* max number of pat,pat patterns allowed */ -int paircnt; /* number of them in use */ -int pairstack[PA2NUM]; /* state of each pat,pat */ +long paircnt; /* number of them in use */ +long pairstack[PA2NUM]; /* state of each pat,pat */ Node *winner = NULL; /* root of parse tree */ Cell *tmps; /* free temporary cells for execution */ @@ -201,7 +201,7 @@ Cell *call(Node **a, int n) /* function call. very kludgy and fragile */ } for (ncall = 0, x = a[1]; x != NULL; x = x->nnext) /* args in call */ ncall++; - ndef = (int) fcn->fval; /* args in defn */ + ndef = (long) fcn->fval; /* args in defn */ dprintf( ("calling %s, %d args (%d in defn), fp=%d\n", s, ncall, ndef, fp-frame) ); if (ncall > ndef) ERROR "function %s called with %d args, uses only %d", @@ -290,7 +290,7 @@ Cell *copycell(Cell *x) /* make a copy of a cell in a temp */ Cell *arg(Node **a, int n) /* nth argument of a function */ { - n = (int) a[0]; /* argument number, counting from 0 */ + n = (long) a[0]; /* argument number, counting from 0 */ dprintf( ("arg(%d), fp->nargs=%d\n", n, fp->nargs) ); if (n+1 > fp->nargs) ERROR "argument #%d of function %s was not supplied", @@ -352,9 +352,9 @@ Cell *getline(Node **a, int n) /* get next line from specific input */ r = gettemp(); if (a[1] != NULL) { /* getline < file */ x = execute(a[2]); /* filename */ - if ((int) a[1] == '|') /* input pipe */ + if ((long) a[1] == '|') /* input pipe */ a[1] = (Node *) LE; /* arbitrary flag */ - fp = openfile((int) a[1], getsval(x)); + fp = openfile((long) a[1], getsval(x)); tempfree(x); if (fp == NULL) n = -1; @@ -750,7 +750,7 @@ int format(char *buf, int bufsize, char *s, Node *a) if (*s == '*') { x = execute(a); a = a->nnext; - sprintf((char *)t-1, "%d", (int) getfval(x)); + sprintf((char *)t-1, "%ld", (long) getfval(x)); t = fmt + strlen(fmt); tempfree(x); } @@ -794,7 +794,7 @@ int format(char *buf, int bufsize, char *s, Node *a) break; case 1: sprintf((char *)p, (char *)fmt, getfval(x)); break; case 2: sprintf((char *)p, (char *)fmt, (long) getfval(x)); break; - case 3: sprintf((char *)p, (char *)fmt, (int) getfval(x)); break; + case 3: sprintf((char *)p, (char *)fmt, (long) getfval(x)); break; case 4: t = getsval(x); n = strlen(t); @@ -806,7 +806,7 @@ int format(char *buf, int bufsize, char *s, Node *a) case 5: isnum(x) ? (getfval(x) ? - sprintf((char *)p, (char *)fmt, (int) getfval(x)) + sprintf((char *)p, (char *)fmt, (long) getfval(x)) : (*p++ = '\0')) : sprintf((char *)p, (char *)fmt, getsval(x)[0]); break; @@ -818,7 +818,7 @@ int format(char *buf, int bufsize, char *s, Node *a) *p = '\0'; for ( ; a; a = a->nnext) /* evaluate any remaining args */ execute(a); - return ((int)(p - buf)); + return ((long)(p - buf)); } Cell *awksprintf(Node **a, int n) /* sprintf(a[0]) */ @@ -857,7 +857,7 @@ Cell *awkprintf(Node **a, int n) /* printf */ if (ferror(stdout)) ERROR "write error on stdout" FATAL; } else { - fp = redirect((int)a[1], a[2]); + fp = redirect((long)a[1], a[2]); fwrite(buf, len, 1, fp); fflush(fp); if (ferror(fp)) @@ -907,7 +907,7 @@ Cell *arith(Node **a, int n) /* a[0] + a[1], etc. also -a[0] */ break; case POWER: if (j >= 0 && modf(j, &v) == 0.0) /* pos integer exponent */ - i = ipow(i, (int) j); + i = ipow(i, (long) j); else i = errcheck(pow(i, j), "pow"); break; @@ -1001,7 +1001,7 @@ Cell *assign(Node **a, int n) /* a[0] = a[1], a[0] += a[1], etc. */ break; case POWEQ: if (yf >= 0 && modf(yf, &v) == 0.0) /* pos integer exponent */ - xf = ipow(xf, (int) yf); + xf = ipow(xf, (long) yf); else xf = errcheck(pow(xf, yf), "pow"); break; @@ -1061,7 +1061,7 @@ Cell *dopa2(Node **a, int n) /* a[0], a[1] { a[2] } */ Cell *x; int pair; - pair = (int) a[3]; + pair = (long) a[3]; if (pairstack[pair] == 0) { x = execute(a[0]); if (istrue(x)) @@ -1091,10 +1091,10 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */ s = getsval(y); if (a[2] == 0) /* fs string */ fs = *FS; - else if ((int) a[3] == STRING) { /* split(str,arr,"string") */ + else if ((long) a[3] == STRING) { /* split(str,arr,"string") */ x = execute(a[2]); fs = getsval(x); - } else if ((int) a[3] == REGEXPR) + } else if ((long) a[3] == REGEXPR) fs = (char*) "(regexpr)"; /* split(str,arr,/regexpr/) */ else ERROR "illegal type of split()" FATAL; @@ -1107,9 +1107,9 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */ ap->sval = (char *) makesymtab(NSYMTAB); n = 0; - if ((*s != '\0' && strlen(fs) > 1) || (int) a[3] == REGEXPR) { /* reg expr */ + if ((*s != '\0' && strlen(fs) > 1) || (long) a[3] == REGEXPR) { /* reg expr */ fa *pfa; - if ((int) a[3] == REGEXPR) { /* it's ready already */ + if ((long) a[3] == REGEXPR) { /* it's ready already */ pfa = (fa *) a[2]; } else { pfa = makedfa(fs, 1); @@ -1199,7 +1199,7 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */ } tempfree(ap); tempfree(y); - if (a[2] != 0 && (int) a[3] == STRING) + if (a[2] != 0 && (long) a[3] == STRING) tempfree(x); x = gettemp(); x->tval = NUM; @@ -1395,7 +1395,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis Node *nextarg; FILE *fp; - t = (int) a[0]; + t = (long) a[0]; x = execute(a[1]); nextarg = a[1]->nnext; switch (t) { @@ -1437,7 +1437,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis u = time((time_t *)0); else u = getfval(x); - srand((int) u); u = (int) u; + srand((long) u); u = (long) u; break; case FTOUPPER: case FTOLOWER: @@ -1485,7 +1485,7 @@ Cell *printstat(Node **a, int n) /* print a[0] */ if (a[1] == 0) /* a[1] is redirection operator, a[2] is file */ fp = stdout; else - fp = redirect((int)a[1], a[2]); + fp = redirect((long)a[1], a[2]); for (x = a[0]; x != NULL; x = x->nnext) { y = execute(x); fputs((char *)getsval(y), fp); -- 2.20.1