diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2001-09-08 00:12:41 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2001-09-08 00:12:41 +0000 |
commit | 63bf6a6ce49fd2e45c947f6b6105a958365f6858 (patch) | |
tree | 4f5c4ab654cf0758536b2dfa6be6789218301d47 | |
parent | 9ba2ab292e66a71b170f4de3e910e8c47673b4a4 (diff) |
Update to latest version of the One True Awk. See the FIXES file
for details.
-rw-r--r-- | usr.bin/awk/FIXES | 53 | ||||
-rw-r--r-- | usr.bin/awk/README | 4 | ||||
-rw-r--r-- | usr.bin/awk/awk.h | 9 | ||||
-rw-r--r-- | usr.bin/awk/awkgram.y | 4 | ||||
-rw-r--r-- | usr.bin/awk/b.c | 71 | ||||
-rw-r--r-- | usr.bin/awk/lex.c | 14 | ||||
-rw-r--r-- | usr.bin/awk/lib.c | 8 | ||||
-rw-r--r-- | usr.bin/awk/main.c | 4 | ||||
-rw-r--r-- | usr.bin/awk/maketab.c | 6 | ||||
-rw-r--r-- | usr.bin/awk/parse.c | 7 | ||||
-rw-r--r-- | usr.bin/awk/run.c | 34 | ||||
-rw-r--r-- | usr.bin/awk/tran.c | 15 |
12 files changed, 151 insertions, 78 deletions
diff --git a/usr.bin/awk/FIXES b/usr.bin/awk/FIXES index 10183f2eec6..878cf8b302e 100644 --- a/usr.bin/awk/FIXES +++ b/usr.bin/awk/FIXES @@ -1,4 +1,4 @@ -/* $OpenBSD: FIXES,v 1.9 1999/12/08 23:09:45 millert Exp $ */ +/* $OpenBSD: FIXES,v 1.10 2001/09/08 00:12:40 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -26,6 +26,56 @@ THIS SOFTWARE. This file lists all bug fixes, changes, etc., made since the AWK book was sent to the printers in August, 1987. +Nov 15, 2000: + fixed a bug introduced in august 1997 that caused expressions + like $f[1] to be syntax errors. thanks to arnold robbins for + noticing this and providing a fix. + +Oct 30, 2000: + fixed some nextfile bugs: not handling all cases. thanks to + arnold robbins for pointing this out. new regressions added. + + close() is now a function. it returns whatever the library + fclose returns, and -1 for closing a file or pipe that wasn't + opened. + +Sep 24, 2000: + permit \n explicitly in character classes; won't work right + if comes in as "[\n]" but ok as /[\n]/, because of multiple + processing of \'s. thanks to arnold robbins. + +July 5, 2000: + minor fiddles in tran.c to keep compilers happy about uschar. + thanks to norman wilson. + +May 25, 2000: + yet another attempt at making 8-bit input work, with another + band-aid in b.c (member()), and some (uschar) casts to head + off potential errors in subscripts (like isdigit). also + changed HAT to NCHARS-2. thanks again to santiago vila. + + changed maketab.c to ignore apparently out of range definitions + instead of halting; new freeBSD generates one. thanks to + jon snader <jsnader@ix.netcom.com> for pointing out the problem. + +May 2, 2000: + fixed an 8-bit problem in b.c by making several char*'s into + unsigned char*'s. not clear i have them all yet. thanks to + Santiago Vila <sanvila@unex.es> for the bug report. + +Apr 21, 2000: + finally found and fixed a memory leak in function call; it's + been there since functions were added ~1983. thanks to + jon bentley for the test case that found it. + + added test in envinit to catch environment "variables" with + names begining with '='; thanks to Berend Hasselman. + +Jul 28, 1999: + added test in defn() to catch function foo(foo), which + otherwise recurses until core dump. thanks to arnold + robbins for noticing this. + Jun 20, 1999: added *bp in gettok in lex.c; appears possible to exit function without terminating the string. thanks to russ cox. @@ -49,6 +99,7 @@ Apr 21, 1999: Apr 16, 1999: with code kindly provided by Bruce Lilly, awk now parses /=/ and similar constructs more sensibly in more places. + Bruce also provided some helpful test cases. Apr 5, 1999: changed true/false to True/False in run.c to make it diff --git a/usr.bin/awk/README b/usr.bin/awk/README index d05de5906c2..39ad4d77920 100644 --- a/usr.bin/awk/README +++ b/usr.bin/awk/README @@ -1,4 +1,4 @@ -/* $OpenBSD: README,v 1.3 1999/04/18 17:06:29 millert Exp $ */ +/* $OpenBSD: README,v 1.4 2001/09/08 00:12:40 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -38,7 +38,7 @@ which should produce a sequence of messages roughly like this: yacc -d awkgram.y -conflicts: 42 shift/reduce, 83 reduce/reduce +conflicts: 43 shift/reduce, 85 reduce/reduce mv y.tab.c ytab.c mv y.tab.h ytab.h cc -O -c ytab.c diff --git a/usr.bin/awk/awk.h b/usr.bin/awk/awk.h index 2d42eb2a842..9762944b892 100644 --- a/usr.bin/awk/awk.h +++ b/usr.bin/awk/awk.h @@ -1,4 +1,4 @@ -/* $OpenBSD: awk.h,v 1.8 1999/12/08 23:09:45 millert Exp $ */ +/* $OpenBSD: awk.h,v 1.9 2001/09/08 00:12:40 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -182,8 +182,7 @@ extern int pairstack[], paircnt; #define isexit(n) ((n)->csub == JEXIT) #define isbreak(n) ((n)->csub == JBREAK) #define iscont(n) ((n)->csub == JCONT) -#define isnext(n) ((n)->csub == JNEXT) -#define isnextfile(n) ((n)->csub == JNEXTFILE) +#define isnext(n) ((n)->csub == JNEXT || (n)->csub == JNEXTFILE) #define isret(n) ((n)->csub == JRET) #define isrec(n) ((n)->tval & REC) #define isfld(n) ((n)->tval & FLD) @@ -208,7 +207,7 @@ typedef struct rrow { union { int i; Node *np; - char *up; + uschar *up; } lval; /* because Al stores a pointer in it! */ int *lfollow; } rrow; @@ -216,7 +215,7 @@ typedef struct rrow { typedef struct fa { uschar gototab[NSTATES][NCHARS]; uschar out[NSTATES]; - char *restr; + uschar *restr; int *posns[NSTATES]; int anchor; int use; diff --git a/usr.bin/awk/awkgram.y b/usr.bin/awk/awkgram.y index 686ecad66bd..03a872fd045 100644 --- a/usr.bin/awk/awkgram.y +++ b/usr.bin/awk/awkgram.y @@ -1,4 +1,4 @@ -/* $OpenBSD: awkgram.y,v 1.6 1999/12/08 23:09:45 millert Exp $ */ +/* $OpenBSD: awkgram.y,v 1.7 2001/09/08 00:12:40 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -317,7 +317,6 @@ st: stmt: BREAK st { if (!inloop) SYNTAX("break illegal outside of loops"); $$ = stat1(BREAK, NIL); } - | CLOSE pattern st { $$ = stat1(CLOSE, $2); } | CONTINUE st { if (!inloop) SYNTAX("continue illegal outside of loops"); $$ = stat1(CONTINUE, NIL); } | do {inloop++;} stmt {--inloop;} WHILE '(' pattern ')' st @@ -366,6 +365,7 @@ term: | BLTIN { $$ = op2(BLTIN, itonp($1), rectonode()); } | CALL '(' ')' { $$ = op2(CALL, celltonode($1,CVAR), NIL); } | CALL '(' patlist ')' { $$ = op2(CALL, celltonode($1,CVAR), $3); } + | CLOSE term { $$ = op1(CLOSE, $2); } | DECR var { $$ = op1(PREDECR, $2); } | INCR var { $$ = op1(PREINCR, $2); } | var DECR { $$ = op1(POSTDECR, $1); } diff --git a/usr.bin/awk/b.c b/usr.bin/awk/b.c index b3cacd4515f..288d022cffe 100644 --- a/usr.bin/awk/b.c +++ b/usr.bin/awk/b.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b.c,v 1.9 2001/07/12 05:16:53 deraadt Exp $ */ +/* $OpenBSD: b.c,v 1.10 2001/09/08 00:12:40 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -34,7 +34,7 @@ THIS SOFTWARE. #include "awk.h" #include "ytab.h" -#define HAT (NCHARS-1) /* matches ^ in regular expr */ +#define HAT (NCHARS-2) /* matches ^ in regular expr */ /* NCHARS is 2**n */ #define MAXLIN 22 @@ -62,9 +62,9 @@ int maxsetvec = 0; int rtok; /* next token in current re */ int rlxval; -char *rlxstr; -char *prestr; /* current position in current re */ -char *lastre; /* origin of last re */ +static uschar *rlxstr; +static uschar *prestr; /* current position in current re */ +static uschar *lastre; /* origin of last re */ static int setcnt; static int poscnt; @@ -97,7 +97,7 @@ fa *makedfa(char *s, int anchor) /* returns dfa for reg expr s */ && strcmp(fatab[i]->restr, s) == 0) { fatab[i]->use = now++; return fatab[i]; - } + } pfa = mkdfa(s, anchor); if (nfatab < NFA) { /* room for another */ fatab[nfatab] = pfa; @@ -144,7 +144,7 @@ fa *mkdfa(char *s, int anchor) /* does the real work of making a dfa */ *f->posns[1] = 0; f->initstat = makeinit(f, anchor); f->anchor = anchor; - f->restr = tostring(s); + f->restr = (uschar *) tostring(s); return f; } @@ -231,11 +231,11 @@ void freetr(Node *p) /* free parse tree */ int hexstr(char **pp) /* find and eval hex string at pp, return new p */ { /* only pick up one 8-bit byte (2 chars) */ - char *p; + uschar *p; int n = 0; int i; - for (i = 0, p = *pp; i < 2 && isxdigit(*p); i++, p++) { + for (i = 0, p = (uschar *) *pp; i < 2 && isxdigit(*p); i++, p++) { if (isdigit(*p)) n = 16 * n + *p - '0'; else if (*p >= 'a' && *p <= 'f') @@ -243,7 +243,7 @@ int hexstr(char **pp) /* find and eval hex string at pp, return new p */ else if (*p >= 'A' && *p <= 'F') n = 16 * n + *p - 'A' + 10; } - *pp = p; + *pp = (char *) p; return n; } @@ -283,33 +283,34 @@ int quoted(char **pp) /* pick up next thing after a \\ */ return c; } -char *cclenter(char *p) /* add a character class */ +char *cclenter(char *argp) /* add a character class */ { int i, c, c2; - char *op, *bp; - static char *buf = 0; + uschar *p = (uschar *) argp; + uschar *op, *bp; + static uschar *buf = 0; static int bufsz = 100; op = p; - if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL) + if (buf == 0 && (buf = (uschar *) malloc(bufsz)) == NULL) FATAL("out of space for character class [%.10s...] 1", p); bp = buf; for (i = 0; (c = *p++) != 0; ) { if (c == '\\') { - c = quoted(&p); + c = quoted((char **) &p); } else if (c == '-' && i > 0 && bp[-1] != 0) { if (*p != 0) { c = bp[-1]; c2 = *p++; if (c2 == '\\') - c2 = quoted(&p); + c2 = quoted((char **) &p); if (c > c2) { /* empty; ignore */ bp--; i--; continue; } while (c < c2) { - if (!adjbuf(&buf, &bufsz, bp-buf+2, 100, &bp, 0)) + if (!adjbuf((char **) &buf, &bufsz, bp-buf+2, 100, (char **) &bp, 0)) FATAL("out of space for character class [%.10s...] 2", p); *bp++ = ++c; i++; @@ -317,7 +318,7 @@ char *cclenter(char *p) /* add a character class */ continue; } } - if (!adjbuf(&buf, &bufsz, bp-buf+2, 100, &bp, 0)) + if (!adjbuf((char **) &buf, &bufsz, bp-buf+2, 100, (char **) &bp, 0)) FATAL("out of space for character class [%.10s...] 3", p); *bp++ = c; i++; @@ -325,7 +326,7 @@ char *cclenter(char *p) /* add a character class */ *bp = 0; dprintf( ("cclenter: in = |%s|, out = |%s|\n", op, buf) ); xfree(op); - return(tostring(buf)); + return (char *) tostring((char *) buf); } void overflo(char *s) @@ -446,8 +447,10 @@ void follow(Node *v) /* collects leaves that can follow v into setvec */ } } -int member(int c, char *s) /* is c in s? */ +int member(int c, char *sarg) /* is c in s? */ { + uschar *s = (uschar *) sarg; + while (*s) if (c == *s++) return(1); @@ -583,7 +586,7 @@ Node *reparse(char *p) /* parses regular expression pointed to by p */ Node *np; dprintf( ("reparse <%s>\n", p) ); - lastre = prestr = p; /* prestr points to string to be parsed */ + lastre = prestr = (uschar *) p; /* prestr points to string to be parsed */ rtok = relex(); if (rtok == '\0') FATAL("empty regular expression"); @@ -614,11 +617,11 @@ Node *primary(void) rtok = relex(); return (unary(op2(DOT, NIL, NIL))); case CCL: - np = op2(CCL, NIL, (Node*) cclenter(rlxstr)); + np = op2(CCL, NIL, (Node*) cclenter((char *) rlxstr)); rtok = relex(); return (unary(np)); case NCCL: - np = op2(NCCL, NIL, (Node *) cclenter(rlxstr)); + np = op2(NCCL, NIL, (Node *) cclenter((char *) rlxstr)); rtok = relex(); return (unary(np)); case '^': @@ -685,9 +688,9 @@ int relex(void) /* lexical analyzer for reparse */ { int c, n; int cflag; - static char *buf = 0; + static uschar *buf = 0; static int bufsz = 100; - char *bp; + uschar *bp; switch (c = *prestr++) { case '|': return OR; @@ -702,13 +705,13 @@ int relex(void) /* lexical analyzer for reparse */ case ')': return c; case '\\': - rlxval = quoted(&prestr); + rlxval = quoted((char **) &prestr); return CHAR; default: rlxval = c; return CHAR; case '[': - if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL) + if (buf == 0 && (buf = (uschar *) malloc(bufsz)) == NULL) FATAL("out of space in reg expr %.10s..", lastre); bp = buf; if (*prestr == '^') { @@ -718,7 +721,7 @@ int relex(void) /* lexical analyzer for reparse */ else cflag = 0; n = 2 * strlen(prestr)+1; - if (!adjbuf(&buf, &bufsz, n, n, &bp, 0)) + if (!adjbuf((char **) &buf, &bufsz, n, n, (char **) &bp, 0)) FATAL("out of space for reg expr %.10s...", lastre); for (; ; ) { if ((c = *prestr++) == '\\') { @@ -726,15 +729,15 @@ int relex(void) /* lexical analyzer for reparse */ if ((c = *prestr++) == '\0') FATAL("nonterminated character class %.20s...", lastre); *bp++ = c; - } else if (c == '\n') { - FATAL("newline in character class %.20s...", lastre); + /* } else if (c == '\n') { */ + /* FATAL("newline in character class %.20s...", lastre); */ } else if (c == '\0') { FATAL("nonterminated character class %.20s", lastre); } else if (bp == buf) { /* 1st char is special */ *bp++ = c; } else if (c == ']') { *bp++ = 0; - rlxstr = tostring(buf); + rlxstr = (uschar *) tostring((char *) buf); if (cflag == 0) return CCL; else @@ -750,7 +753,7 @@ int cgoto(fa *f, int s, int c) int i, j, k; int *p, *q; - if (c < 0) + if (c < 0 || c > 255) FATAL("can't happen: neg char %d in cgoto", c); while (f->accept >= maxsetvec) { /* guessing here! */ maxsetvec *= 4; @@ -769,8 +772,8 @@ int cgoto(fa *f, int s, int c) if ((k == CHAR && c == ptoi(f->re[p[i]].lval.np)) || (k == DOT && c != 0 && c != HAT) || (k == ALL && c != 0) - || (k == CCL && member(c, f->re[p[i]].lval.up)) - || (k == NCCL && !member(c, f->re[p[i]].lval.up) && c != 0 && c != HAT)) { + || (k == CCL && member(c, (char *) f->re[p[i]].lval.up)) + || (k == NCCL && !member(c, (char *) f->re[p[i]].lval.up) && c != 0 && c != HAT)) { q = f->re[p[i]].lfollow; for (j = 1; j <= *q; j++) { if (q[j] >= maxsetvec) { diff --git a/usr.bin/awk/lex.c b/usr.bin/awk/lex.c index 99ff3bb55a4..809e190af8f 100644 --- a/usr.bin/awk/lex.c +++ b/usr.bin/awk/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.4 1999/12/08 23:09:45 millert Exp $ */ +/* $OpenBSD: lex.c,v 1.5 2001/09/08 00:12:40 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -296,18 +296,20 @@ int yylex(void) input(); yylval.i = POWEQ; RET(ASGNOP); } else RET(POWER); - + case '$': /* BUG: awkward, if not wrong */ c = gettok(&buf, &bufsize); - if (c == '(' || c == '[' || (infunc && isarg(buf) >= 0)) { - unputstr(buf); - RET(INDIRECT); - } else if (isalpha(c)) { + if (isalpha(c)) { if (strcmp(buf, "NF") == 0) { /* very special */ unputstr("(NF)"); RET(INDIRECT); } + c = peek(); + if (c == '(' || c == '[' || (infunc && isarg(buf) >= 0)) { + unputstr(buf); + RET(INDIRECT); + } yylval.cp = setsymtab(buf, "", 0.0, STR|NUM, symtab); RET(IVAR); } else { diff --git a/usr.bin/awk/lib.c b/usr.bin/awk/lib.c index 54eb5245f3f..ef409d5d4ee 100644 --- a/usr.bin/awk/lib.c +++ b/usr.bin/awk/lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib.c,v 1.7 1999/12/08 23:09:45 millert Exp $ */ +/* $OpenBSD: lib.c,v 1.8 2001/09/08 00:12:40 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -653,15 +653,17 @@ int isclvar(char *s) /* is s of form var=something ? */ { char *os = s; - if (!isalpha(*s) && *s != '_') + if (!isalpha((uschar) *s) && *s != '_') return 0; for ( ; *s; s++) - if (!(isalnum(*s) || *s == '_')) + if (!(isalnum((uschar) *s) || *s == '_')) break; return *s == '=' && s > os && *(s+1) != '='; } /* strtod is supposed to be a proper test of what's a valid number */ +/* appears to be broken in gcc on linux: thinks 0x123 is a valid FP number */ +/* wrong: violates 4.10.1.4 of ansi C standard */ #include <math.h> int is_number(char *s) diff --git a/usr.bin/awk/main.c b/usr.bin/awk/main.c index 00a02677736..8215d56a282 100644 --- a/usr.bin/awk/main.c +++ b/usr.bin/awk/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.10 2000/11/21 14:08:22 aaron Exp $ */ +/* $OpenBSD: main.c,v 1.11 2001/09/08 00:12:40 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -23,7 +23,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ****************************************************************/ -char *version = "version 19990620"; +char *version = "version 20001115"; #define DEBUG #include <stdio.h> diff --git a/usr.bin/awk/maketab.c b/usr.bin/awk/maketab.c index 8cdc86b804e..9cafbc7d2a1 100644 --- a/usr.bin/awk/maketab.c +++ b/usr.bin/awk/maketab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: maketab.c,v 1.3 1999/04/18 17:06:30 millert Exp $ */ +/* $OpenBSD: maketab.c,v 1.4 2001/09/08 00:12:40 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -136,8 +136,8 @@ int main(int argc, char *argv[]) if (c != '#' || (n != 4 && strcmp(def,"define") != 0)) /* not a valid #define */ continue; if (tok < FIRSTTOKEN || tok > LASTTOKEN) { - fprintf(stderr, "maketab funny token %d %s\n", tok, buf); - exit(1); + fprintf(stderr, "maketab funny token %d %s ignored\n", tok, buf); + continue; } names[tok-FIRSTTOKEN] = (char *) malloc(strlen(name)+1); strcpy(names[tok-FIRSTTOKEN], name); diff --git a/usr.bin/awk/parse.c b/usr.bin/awk/parse.c index 95eb5051c65..698bb4cda1d 100644 --- a/usr.bin/awk/parse.c +++ b/usr.bin/awk/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.4 1999/12/08 23:09:46 millert Exp $ */ +/* $OpenBSD: parse.c,v 1.5 2001/09/08 00:12:40 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -240,6 +240,11 @@ void defn(Cell *v, Node *vl, Node *st) /* turn on FCN bit in definition, */ SYNTAX( "`%s' is an array name and a function name", v->nval ); return; } + if (isarg(v->nval) != -1) { + SYNTAX( "`%s' is both function name and argument name", v->nval ); + return; + } + v->tval = FCN; v->sval = (char *) st; n = 0; /* count arguments */ diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index 52bd9a3cd99..76f25d45035 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.16 1999/12/08 23:09:46 millert Exp $ */ +/* $OpenBSD: run.c,v 1.17 2001/09/08 00:12:40 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -300,7 +300,7 @@ Cell *call(Node **a, int n) /* function call. very kludgy and fragile */ } } tempfree(fcn); - if (isexit(y) || isnext(y) || isnextfile(y)) + if (isexit(y) || isnext(y)) return y; tempfree(y); /* this can free twice! */ z = fp->retval; /* return value */ @@ -316,7 +316,8 @@ Cell *copycell(Cell *x) /* make a copy of a cell in a temp */ y = gettemp(); y->csub = CCOPY; /* prevents freeing until call is over */ y->nval = x->nval; /* BUG? */ - y->sval = x->sval ? tostring(x->sval) : NULL; + if (isstr(x)) + y->sval = tostring(x->sval); y->fval = x->fval; y->tval = x->tval & ~(CON|FLD|REC|DONTFREE); /* copy is not constant or field */ /* is DONTFREE right? */ @@ -730,8 +731,9 @@ Cell *substr(Node **a, int nnn) /* substr(a[0], a[1], a[2]) */ if (k <= 1) { tempfree(x); tempfree(y); - if (a[2] != 0) + if (a[2] != 0) { tempfree(z); + } x = gettemp(); setsval(x, ""); return(x); @@ -823,7 +825,7 @@ int format(char **pbuf, int *pbufsize, char *s, Node *a) /* printf-like conversi for (t = fmt; (*t++ = *s) != '\0'; s++) { if (!adjbuf(&fmt, &fmtsz, MAXNUMSIZE+1+t-fmt, recsize, &t, 0)) FATAL("format item %.30s... ran format() out of memory", os); - if (isalpha(*s) && *s != 'l' && *s != 'h' && *s != 'L') + if (isalpha((uschar)*s) && *s != 'l' && *s != 'h' && *s != 'L') break; /* the ansi panoply */ if (*s == '*') { x = execute(a); @@ -1282,7 +1284,7 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */ sprintf(num, "%d", n); buf[0] = *s; buf[1] = 0; - if (isdigit(buf[0])) + if (isdigit((uschar)buf[0])) setsymtab(num, buf, atof(buf), STR|NUM, (Array *) ap->sval); else setsymtab(num, buf, 0.0, STR, (Array *) ap->sval); @@ -1307,8 +1309,9 @@ 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 && arg3type == STRING) + if (a[2] != 0 && arg3type == STRING) { tempfree(x); + } x = gettemp(); x->tval = NUM; x->fval = n; @@ -1373,7 +1376,7 @@ Cell *dostat(Node **a, int n) /* do a[0]; while(a[1]) */ x = execute(a[0]); if (isbreak(x)) return True; - if (isnext(x) || isnextfile(x) || isexit(x) || isret(x)) + if (isnext(x) || isexit(x) || isret(x)) return(x); tempfree(x); x = execute(a[1]); @@ -1496,11 +1499,11 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis buf = tostring(getsval(x)); if (t == FTOUPPER) { for (p = buf; *p; p++) - if (islower(*p)) + if (islower((uschar) *p)) *p = toupper(*p); } else { for (p = buf; *p; p++) - if (isupper(*p)) + if (isupper((uschar) *p)) *p = tolower(*p); } tempfree(x); @@ -1659,7 +1662,8 @@ Cell *closefile(Node **a, int n) n = n; x = execute(a[0]); getsval(x); - for (i = 0; i < FOPEN_MAX; i++) + stat = -1; + for (i = 0; i < FOPEN_MAX; i++) { if (files[i].fname && strcmp(x->sval, files[i].fname) == 0) { if (ferror(files[i].fp)) WARNING( "i/o error occurred on %s", files[i].fname ); @@ -1674,15 +1678,18 @@ Cell *closefile(Node **a, int n) files[i].fname = NULL; /* watch out for ref thru this */ files[i].fp = NULL; } + } tempfree(x); - return(True); + x = gettemp(); + setfval(x, (Awkfloat) stat); + return(x); } void closeall(void) { int i, stat; - for (i = 0; i < FOPEN_MAX; i++) + for (i = 0; i < FOPEN_MAX; i++) { if (files[i].fp) { if (ferror(files[i].fp)) WARNING( "i/o error occurred on %s", files[i].fname ); @@ -1693,6 +1700,7 @@ void closeall(void) if (stat == EOF) WARNING( "i/o error occurred while closing %s", files[i].fname ); } + } } void backsub(char **pb_ptr, char **sptr_ptr); diff --git a/usr.bin/awk/tran.c b/usr.bin/awk/tran.c index 7d9e791b5b9..9c910f52572 100644 --- a/usr.bin/awk/tran.c +++ b/usr.bin/awk/tran.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tran.c,v 1.6 1999/12/08 23:09:46 millert Exp $ */ +/* $OpenBSD: tran.c,v 1.7 2001/09/08 00:12:40 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -127,6 +127,8 @@ void envinit(char **envp) /* set up ENVIRON variable */ for ( ; *envp; envp++) { if ((p = strchr(*envp, '=')) == NULL) continue; + if( p == *envp ) /* no left hand side name in env string */ + continue; *p++ = 0; /* split into two strings at = */ if (is_number(p)) setsymtab(*envp, p, atof(p), STR|NUM, ENVtab); @@ -388,13 +390,14 @@ char *tostring(char *s) /* make a copy of string s */ return(p); } -char *qstring(char *s, int delim) /* collect string up to next delim */ +char *qstring(char *is, int delim) /* collect string up to next delim */ { - char *os = s; + char *os = is; int c, n; - char *buf, *bp; + uschar *s = (uschar *) is; + uschar *buf, *bp; - if ((buf = (char *) malloc(strlen(s)+3)) == NULL) + if ((buf = (uschar *) malloc(strlen(s)+3)) == NULL) FATAL( "out of space in qstring(%s)", s); for (bp = buf; (c = *s) != delim; s++) { if (c == '\n') @@ -431,5 +434,5 @@ char *qstring(char *s, int delim) /* collect string up to next delim */ } } *bp++ = 0; - return buf; + return (char *) buf; } |