MFV r300961: one-true-awk: replace 0 with NULL for pointers

Also remove a redundant semicolon.

Also had to rebase on upstream pull.

git-svn-id: svn+ssh://svn.freebsd.org/base/head@301289 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
This commit is contained in:
pfg 2016-06-03 21:23:11 +00:00 committed by Arnold D. Robbins
parent b8e0827095
commit 524219409a
6 changed files with 42 additions and 42 deletions

20
b.c
View File

@ -88,11 +88,11 @@ fa *makedfa(const char *s, int anchor) /* returns dfa for reg expr s */
fa *pfa; fa *pfa;
static int now = 1; static int now = 1;
if (setvec == 0) { /* first time through any RE */ if (setvec == NULL) { /* first time through any RE */
maxsetvec = MAXLIN; maxsetvec = MAXLIN;
setvec = (int *) malloc(maxsetvec * sizeof(int)); setvec = (int *) malloc(maxsetvec * sizeof(int));
tmpset = (int *) malloc(maxsetvec * sizeof(int)); tmpset = (int *) malloc(maxsetvec * sizeof(int));
if (setvec == 0 || tmpset == 0) if (setvec == NULL || tmpset == NULL)
overflo("out of space initializing makedfa"); overflo("out of space initializing makedfa");
} }
@ -302,11 +302,11 @@ char *cclenter(const char *argp) /* add a character class */
int i, c, c2; int i, c, c2;
uschar *p = (uschar *) argp; uschar *p = (uschar *) argp;
uschar *op, *bp; uschar *op, *bp;
static uschar *buf = 0; static uschar *buf = NULL;
static int bufsz = 100; static int bufsz = 100;
op = p; op = p;
if (buf == 0 && (buf = (uschar *) malloc(bufsz)) == NULL) if (buf == NULL && (buf = (uschar *) malloc(bufsz)) == NULL)
FATAL("out of space for character class [%.10s...] 1", p); FATAL("out of space for character class [%.10s...] 1", p);
bp = buf; bp = buf;
for (i = 0; (c = *p++) != 0; ) { for (i = 0; (c = *p++) != 0; ) {
@ -362,7 +362,7 @@ void cfoll(fa *f, Node *v) /* enter follow set of each leaf of vertex v into lfo
maxsetvec *= 4; maxsetvec *= 4;
setvec = (int *) realloc(setvec, maxsetvec * sizeof(int)); setvec = (int *) realloc(setvec, maxsetvec * sizeof(int));
tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int)); tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int));
if (setvec == 0 || tmpset == 0) if (setvec == NULL || tmpset == NULL)
overflo("out of space in cfoll()"); overflo("out of space in cfoll()");
} }
for (i = 0; i <= f->accept; i++) for (i = 0; i <= f->accept; i++)
@ -403,7 +403,7 @@ int first(Node *p) /* collects initially active leaves of p into setvec */
maxsetvec *= 4; maxsetvec *= 4;
setvec = (int *) realloc(setvec, maxsetvec * sizeof(int)); setvec = (int *) realloc(setvec, maxsetvec * sizeof(int));
tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int)); tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int));
if (setvec == 0 || tmpset == 0) if (setvec == NULL || tmpset == NULL)
overflo("out of space in first()"); overflo("out of space in first()");
} }
if (type(p) == EMPTYRE) { if (type(p) == EMPTYRE) {
@ -905,7 +905,7 @@ int relex(void) /* lexical analyzer for reparse */
{ {
int c, n; int c, n;
int cflag; int cflag;
static uschar *buf = 0; static uschar *buf = NULL;
static int bufsz = 100; static int bufsz = 100;
uschar *bp; uschar *bp;
struct charclass *cc; struct charclass *cc;
@ -945,7 +945,7 @@ rescan:
rlxval = c; rlxval = c;
return CHAR; return CHAR;
case '[': case '[':
if (buf == 0 && (buf = (uschar *) malloc(bufsz)) == NULL) if (buf == NULL && (buf = (uschar *) malloc(bufsz)) == NULL)
FATAL("out of space in reg expr %.10s..", lastre); FATAL("out of space in reg expr %.10s..", lastre);
bp = buf; bp = buf;
if (*prestr == '^') { if (*prestr == '^') {
@ -1121,7 +1121,7 @@ int cgoto(fa *f, int s, int c)
maxsetvec *= 4; maxsetvec *= 4;
setvec = (int *) realloc(setvec, maxsetvec * sizeof(int)); setvec = (int *) realloc(setvec, maxsetvec * sizeof(int));
tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int)); tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int));
if (setvec == 0 || tmpset == 0) if (setvec == NULL || tmpset == NULL)
overflo("out of space in cgoto()"); overflo("out of space in cgoto()");
} }
for (i = 0; i <= f->accept; i++) for (i = 0; i <= f->accept; i++)
@ -1143,7 +1143,7 @@ int cgoto(fa *f, int s, int c)
maxsetvec *= 4; maxsetvec *= 4;
setvec = (int *) realloc(setvec, maxsetvec * sizeof(int)); setvec = (int *) realloc(setvec, maxsetvec * sizeof(int));
tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int)); tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int));
if (setvec == 0 || tmpset == 0) if (setvec == NULL || tmpset == NULL)
overflo("cgoto overflow"); overflo("cgoto overflow");
} }
if (setvec[q[j]] == 0) { if (setvec[q[j]] == 0) {

14
lex.c
View File

@ -170,10 +170,10 @@ int reg = 0; /* 1 => return a REGEXPR now */
int yylex(void) int yylex(void)
{ {
int c; int c;
static char *buf = 0; static char *buf = NULL;
static int bufsize = 5; /* BUG: setting this small causes core dump! */ static int bufsize = 5; /* BUG: setting this small causes core dump! */
if (buf == 0 && (buf = (char *) malloc(bufsize)) == NULL) if (buf == NULL && (buf = (char *) malloc(bufsize)) == NULL)
FATAL( "out of space in yylex" ); FATAL( "out of space in yylex" );
if (sc) { if (sc) {
sc = 0; sc = 0;
@ -360,10 +360,10 @@ int string(void)
{ {
int c, n; int c, n;
char *s, *bp; char *s, *bp;
static char *buf = 0; static char *buf = NULL;
static int bufsz = 500; static int bufsz = 500;
if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL) if (buf == NULL && (buf = (char *) malloc(bufsz)) == NULL)
FATAL("out of space for strings"); FATAL("out of space for strings");
for (bp = buf; (c = input()) != '"'; ) { for (bp = buf; (c = input()) != '"'; ) {
if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, "string")) if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, "string"))
@ -507,11 +507,11 @@ void startreg(void) /* next call to yylex will return a regular expression */
int regexpr(void) int regexpr(void)
{ {
int c; int c;
static char *buf = 0; static char *buf = NULL;
static int bufsz = 500; static int bufsz = 500;
char *bp; char *bp;
if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL) if (buf == NULL && (buf = (char *) malloc(bufsz)) == NULL)
FATAL("out of space for rex expr"); FATAL("out of space for rex expr");
bp = buf; bp = buf;
for ( ; (c = input()) != '/' && c != 0; ) { for ( ; (c = input()) != '/' && c != 0; ) {
@ -543,7 +543,7 @@ char ebuf[300];
char *ep = ebuf; char *ep = ebuf;
char yysbuf[100]; /* pushback buffer */ char yysbuf[100]; /* pushback buffer */
char *yysptr = yysbuf; char *yysptr = yysbuf;
FILE *yyin = 0; FILE *yyin = NULL;
int input(void) /* get next lexical input character */ int input(void) /* get next lexical input character */
{ {

View File

@ -156,7 +156,7 @@ int main(int argc, char *argv[])
table[p->token-FIRSTTOKEN] = p->name; table[p->token-FIRSTTOKEN] = p->name;
printf("\nCell *(*proctab[%d])(Node **, int) = {\n", SIZE); printf("\nCell *(*proctab[%d])(Node **, int) = {\n", SIZE);
for (i=0; i<SIZE; i++) for (i=0; i<SIZE; i++)
if (table[i]==0) if (table[i]==NULL)
printf("\tnullproc,\t/* %s */\n", names[i]); printf("\tnullproc,\t/* %s */\n", names[i]);
else else
printf("\t%s,\t/* %s */\n", table[i], names[i]); printf("\t%s,\t/* %s */\n", table[i], names[i]);

View File

@ -259,7 +259,7 @@ int isarg(const char *s) /* is s in argument list for current function? */
Node *p = arglist; Node *p = arglist;
int n; int n;
for (n = 0; p != 0; p = p->nnext, n++) for (n = 0; p != NULL; p = p->nnext, n++)
if (strcmp(((Cell *)(p->narg[0]))->nval, s) == 0) if (strcmp(((Cell *)(p->narg[0]))->nval, s) == 0)
return n; return n;
return -1; return -1;

44
run.c
View File

@ -517,7 +517,7 @@ Cell *awkdelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts *
} }
if (!isarr(x)) if (!isarr(x))
return True; return True;
if (a[1] == 0) { /* delete the elements, not the table */ if (a[1] == NULL) { /* delete the elements, not the table */
freesymtab(x); freesymtab(x);
x->tval &= ~STR; x->tval &= ~STR;
x->tval |= ARR; x->tval |= ARR;
@ -603,7 +603,7 @@ Cell *matchop(Node **a, int n) /* ~ and match() */
} }
x = execute(a[1]); /* a[1] = target text */ x = execute(a[1]); /* a[1] = target text */
s = getsval(x); s = getsval(x);
if (a[0] == 0) /* a[1] == 0: already-compiled reg expr */ if (a[0] == NULL) /* a[1] == 0: already-compiled reg expr */
i = (*mf)((fa *) a[2], s); i = (*mf)((fa *) a[2], s);
else { else {
y = execute(a[2]); /* a[2] = regular expr */ y = execute(a[2]); /* a[2] = regular expr */
@ -719,7 +719,7 @@ Cell *gettemp(void) /* get a tempcell */
FATAL("out of space for temporaries"); FATAL("out of space for temporaries");
for(i = 1; i < 100; i++) for(i = 1; i < 100; i++)
tmps[i-1].cnext = &tmps[i]; tmps[i-1].cnext = &tmps[i];
tmps[i-1].cnext = 0; tmps[i-1].cnext = NULL;
} }
x = tmps; x = tmps;
tmps = x->cnext; tmps = x->cnext;
@ -754,18 +754,18 @@ Cell *substr(Node **a, int nnn) /* substr(a[0], a[1], a[2]) */
int k, m, n; int k, m, n;
char *s; char *s;
int temp; int temp;
Cell *x, *y, *z = 0; Cell *x, *y, *z = NULL;
x = execute(a[0]); x = execute(a[0]);
y = execute(a[1]); y = execute(a[1]);
if (a[2] != 0) if (a[2] != NULL)
z = execute(a[2]); z = execute(a[2]);
s = getsval(x); s = getsval(x);
k = strlen(s) + 1; k = strlen(s) + 1;
if (k <= 1) { if (k <= 1) {
tempfree(x); tempfree(x);
tempfree(y); tempfree(y);
if (a[2] != 0) { if (a[2] != NULL) {
tempfree(z); tempfree(z);
} }
x = gettemp(); x = gettemp();
@ -778,7 +778,7 @@ Cell *substr(Node **a, int nnn) /* substr(a[0], a[1], a[2]) */
else if (m > k) else if (m > k)
m = k; m = k;
tempfree(y); tempfree(y);
if (a[2] != 0) { if (a[2] != NULL) {
n = (int) getfval(z); n = (int) getfval(z);
tempfree(z); tempfree(z);
} else } else
@ -1219,7 +1219,7 @@ Cell *pastat(Node **a, int n) /* a[0] { a[1] } */
{ {
Cell *x; Cell *x;
if (a[0] == 0) if (a[0] == NULL)
x = execute(a[1]); x = execute(a[1]);
else { else {
x = execute(a[0]); x = execute(a[0]);
@ -1256,9 +1256,9 @@ Cell *dopa2(Node **a, int n) /* a[0], a[1] { a[2] } */
Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
{ {
Cell *x = 0, *y, *ap; Cell *x = NULL, *y, *ap;
char *s, *origs; char *s, *origs;
char *fs, *origfs = NULL; char *fs = NULL, *origfs = NULL;
int sep; int sep;
char *t, temp, num[50]; char *t, temp, num[50];
int n, tempstat, arg3type; int n, tempstat, arg3type;
@ -1266,7 +1266,7 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
y = execute(a[0]); /* source string */ y = execute(a[0]); /* source string */
origs = s = strdup(getsval(y)); origs = s = strdup(getsval(y));
arg3type = ptoi(a[3]); arg3type = ptoi(a[3]);
if (a[2] == 0) /* fs string */ if (a[2] == NULL) /* fs string */
fs = getsval(fsloc); fs = getsval(fsloc);
else if (arg3type == STRING) { /* split(str,arr,"string") */ else if (arg3type == STRING) { /* split(str,arr,"string") */
x = execute(a[2]); x = execute(a[2]);
@ -1416,7 +1416,7 @@ Cell *ifstat(Node **a, int n) /* if (a[0]) a[1]; else a[2] */
if (istrue(x)) { if (istrue(x)) {
tempfree(x); tempfree(x);
x = execute(a[1]); x = execute(a[1]);
} else if (a[2] != 0) { } else if (a[2] != NULL) {
tempfree(x); tempfree(x);
x = execute(a[2]); x = execute(a[2]);
} }
@ -1468,7 +1468,7 @@ Cell *forstat(Node **a, int n) /* for (a[0]; a[1]; a[2]) a[3] */
x = execute(a[0]); x = execute(a[0]);
tempfree(x); tempfree(x);
for (;;) { for (;;) {
if (a[1]!=0) { if (a[1]!=NULL) {
x = execute(a[1]); x = execute(a[1]);
if (!istrue(x)) return(x); if (!istrue(x)) return(x);
else tempfree(x); else tempfree(x);
@ -1551,7 +1551,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
case FCOS: case FCOS:
u = cos(getfval(x)); break; u = cos(getfval(x)); break;
case FATAN: case FATAN:
if (nextarg == 0) { if (nextarg == NULL) {
WARNING("atan2 requires two arguments; returning 1.0"); WARNING("atan2 requires two arguments; returning 1.0");
u = 1.0; u = 1.0;
} else { } else {
@ -1625,7 +1625,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
tempfree(x); tempfree(x);
x = gettemp(); x = gettemp();
setfval(x, u); setfval(x, u);
if (nextarg != 0) { if (nextarg != NULL) {
WARNING("warning: function has too many arguments"); WARNING("warning: function has too many arguments");
for ( ; nextarg; nextarg = nextarg->nnext) for ( ; nextarg; nextarg = nextarg->nnext)
execute(nextarg); execute(nextarg);
@ -1639,7 +1639,7 @@ Cell *printstat(Node **a, int n) /* print a[0] */
Cell *y; Cell *y;
FILE *fp; FILE *fp;
if (a[1] == 0) /* a[1] is redirection operator, a[2] is file */ if (a[1] == NULL) /* a[1] is redirection operator, a[2] is file */
fp = stdout; fp = stdout;
else else
fp = redirect(ptoi(a[1]), a[2]); fp = redirect(ptoi(a[1]), a[2]);
@ -1652,7 +1652,7 @@ Cell *printstat(Node **a, int n) /* print a[0] */
else else
fputs(getsval(ofsloc), fp); fputs(getsval(ofsloc), fp);
} }
if (a[1] != 0) if (a[1] != NULL)
fflush(fp); fflush(fp);
if (ferror(fp)) if (ferror(fp))
FATAL("write error on %s", filename(fp)); FATAL("write error on %s", filename(fp));
@ -1709,7 +1709,7 @@ FILE *openfile(int a, const char *us)
{ {
const char *s = us; const char *s = us;
int i, m; int i, m;
FILE *fp = 0; FILE *fp = NULL;
if (*s == '\0') if (*s == '\0')
FATAL("null file name in print or getline"); FATAL("null file name in print or getline");
@ -1724,7 +1724,7 @@ FILE *openfile(int a, const char *us)
return NULL; return NULL;
for (i=0; i < nfiles; i++) for (i=0; i < nfiles; i++)
if (files[i].fp == 0) if (files[i].fp == NULL)
break; break;
if (i >= nfiles) { if (i >= nfiles) {
struct files *nf; struct files *nf;
@ -1840,7 +1840,7 @@ Cell *sub(Node **a, int nnn) /* substitute command */
FATAL("out of memory in sub"); FATAL("out of memory in sub");
x = execute(a[3]); /* target string */ x = execute(a[3]); /* target string */
t = getsval(x); t = getsval(x);
if (a[0] == 0) /* 0 => a[1] is already-compiled regexpr */ if (a[0] == NULL) /* 0 => a[1] is already-compiled regexpr */
pfa = (fa *) a[1]; /* regular expression */ pfa = (fa *) a[1]; /* regular expression */
else { else {
y = execute(a[1]); y = execute(a[1]);
@ -1880,7 +1880,7 @@ Cell *sub(Node **a, int nnn) /* substitute command */
if (pb > buf + bufsz) if (pb > buf + bufsz)
FATAL("sub result2 %.30s too big; can't happen", buf); FATAL("sub result2 %.30s too big; can't happen", buf);
setsval(x, buf); /* BUG: should be able to avoid copy */ setsval(x, buf); /* BUG: should be able to avoid copy */
result = True;; result = True;
} }
tempfree(x); tempfree(x);
tempfree(y); tempfree(y);
@ -1903,7 +1903,7 @@ Cell *gsub(Node **a, int nnn) /* global substitute */
num = 0; num = 0;
x = execute(a[3]); /* target string */ x = execute(a[3]); /* target string */
t = getsval(x); t = getsval(x);
if (a[0] == 0) /* 0 => a[1] is already-compiled regexpr */ if (a[0] == NULL) /* 0 => a[1] is already-compiled regexpr */
pfa = (fa *) a[1]; /* regular expression */ pfa = (fa *) a[1]; /* regular expression */
else { else {
y = execute(a[1]); y = execute(a[1]);

2
tran.c
View File

@ -194,7 +194,7 @@ void freesymtab(Cell *ap) /* free a symbol table */
free(cp); free(cp);
tp->nelem--; tp->nelem--;
} }
tp->tab[i] = 0; tp->tab[i] = NULL;
} }
if (tp->nelem != 0) if (tp->nelem != 0)
WARNING("can't happen: inconsistent element count freeing %s", ap->nval); WARNING("can't happen: inconsistent element count freeing %s", ap->nval);