diff options
-rw-r--r-- | usr.bin/awk/FIXES | 29 | ||||
-rw-r--r-- | usr.bin/awk/OpenBSD-PATCHES | 6 | ||||
-rw-r--r-- | usr.bin/awk/awk.h | 16 | ||||
-rw-r--r-- | usr.bin/awk/awkgram.y | 27 | ||||
-rw-r--r-- | usr.bin/awk/b.c | 27 | ||||
-rw-r--r-- | usr.bin/awk/lex.c | 21 | ||||
-rw-r--r-- | usr.bin/awk/lib.c | 12 | ||||
-rw-r--r-- | usr.bin/awk/main.c | 13 | ||||
-rw-r--r-- | usr.bin/awk/parse.c | 14 | ||||
-rw-r--r-- | usr.bin/awk/proto.h | 7 | ||||
-rw-r--r-- | usr.bin/awk/run.c | 151 | ||||
-rw-r--r-- | usr.bin/awk/tran.c | 6 |
12 files changed, 191 insertions, 138 deletions
diff --git a/usr.bin/awk/FIXES b/usr.bin/awk/FIXES index 72e432fa4d8..57adced3156 100644 --- a/usr.bin/awk/FIXES +++ b/usr.bin/awk/FIXES @@ -1,4 +1,4 @@ -/* $OpenBSD: FIXES,v 1.7 1999/04/18 17:06:29 millert Exp $ */ +/* $OpenBSD: FIXES,v 1.8 1999/04/20 17:31:25 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -26,6 +26,33 @@ THIS SOFTWARE. This file lists all bug fixes, changes, etc., made since the AWK book was sent to the printers in August, 1987. +Apr 16, 1999: + with code kindly provided by Bruce Lilly, awk now parses + /=/ and similar constructs more sensibly in more places. + +Apr 5, 1999: + changed true/false to True/False in run.c to make it + easier to compile with C++. Added some casts on malloc + and realloc to be honest about casts; ditto. changed + ltype int to long in struct rrow to reduce some 64-bit + complaints; other changes scattered throughout for the + same purpose. thanks to Nelson Beebe for these portability + improvements. + + removed some horrible pointer-int casting in b.c and elsewhere + by adding ptoi and itonp to localize the casts, which are + all benign. fixed one incipient bug that showed up on sgi + in 64-bit mode. + + reset lineno for new source file; include filename in error + message. also fixed line number error in continuation lines. + (thanks to Nelson Beebe for both of these.) + +Mar 24, 1999: + Nelson Beebe notes that irix 5.3 yacc dies with a bogus + error; use a newer version or switch to bison, since sgi + is unlikely to fix it. + Mar 5, 1999: after hearing from yet another innocent victim, changed isnumber to is_number to avoid the problem caused by diff --git a/usr.bin/awk/OpenBSD-PATCHES b/usr.bin/awk/OpenBSD-PATCHES index f64aee79124..7349b5d801d 100644 --- a/usr.bin/awk/OpenBSD-PATCHES +++ b/usr.bin/awk/OpenBSD-PATCHES @@ -1,6 +1,6 @@ -/* $OpenBSD: OpenBSD-PATCHES,v 1.3 1999/04/18 17:06:29 millert Exp $ */ +/* $OpenBSD: OpenBSD-PATCHES,v 1.4 1999/04/20 17:31:28 millert Exp $ */ -I merged the March 5, 1999 version of the "one true awk" from Brian Kernighan's +I merged the April 16, 1999 version of the "one true awk" from Brian Kernighan's web page http://cm.bell-labs.com/who/bwk/ Mods to the distribution sources: @@ -38,7 +38,7 @@ Let me know if you find more problems. --- /home/millert/tmp/awk/awk.1 Sun Jan 19 18:06:25 1997 +++ awk.1 Sun Jan 19 17:51:39 1997 @@ -1,3 +1,4 @@ -+.\" $OpenBSD: OpenBSD-PATCHES,v 1.3 1999/04/18 17:06:29 millert Exp $ ++.\" $OpenBSD: OpenBSD-PATCHES,v 1.4 1999/04/20 17:31:28 millert Exp $ .de EX .nf .ft CW diff --git a/usr.bin/awk/awk.h b/usr.bin/awk/awk.h index 3a391239334..a1285e5ed90 100644 --- a/usr.bin/awk/awk.h +++ b/usr.bin/awk/awk.h @@ -1,4 +1,4 @@ -/* $OpenBSD: awk.h,v 1.5 1997/08/25 16:17:09 kstailey Exp $ */ +/* $OpenBSD: awk.h,v 1.6 1999/04/20 17:31:28 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -84,7 +84,7 @@ typedef struct Cell { char *nval; /* name, for variables only */ char *sval; /* string value */ Awkfloat fval; /* value as number */ - unsigned tval; /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */ + int tval; /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */ struct Cell *cnext; /* ptr to next if chained */ } Cell; @@ -137,7 +137,7 @@ typedef struct Node { struct Node *nnext; int lineno; int nobj; - struct Node *narg[1]; /* variable: actual size set by calling malloc */ + struct Node *narg[1]; /* variable: actual size set by calling malloc */ } Node; #define NIL ((Node *) 0) @@ -210,7 +210,7 @@ extern int pairstack[], paircnt; #define NSTATES 32 typedef struct rrow { - int ltype; + long ltype; /* long avoids pointer warnings on 64-bit */ union { int i; Node *np; @@ -220,17 +220,17 @@ typedef struct rrow { } rrow; typedef struct fa { + uschar gototab[NSTATES][NCHARS]; + uschar out[NSTATES]; char *restr; + int *posns[NSTATES]; int anchor; int use; - uschar gototab[NSTATES][NCHARS]; - int *posns[NSTATES]; - uschar out[NSTATES]; int initstat; int curstat; int accept; int reset; - struct rrow re[1]; + struct rrow re[1]; /* variable: actual size set by calling malloc */ } fa; diff --git a/usr.bin/awk/awkgram.y b/usr.bin/awk/awkgram.y index bd751e3e8f7..191fc8f9a5a 100644 --- a/usr.bin/awk/awkgram.y +++ b/usr.bin/awk/awkgram.y @@ -1,4 +1,4 @@ -/* $OpenBSD: awkgram.y,v 1.4 1997/08/25 16:17:09 kstailey Exp $ */ +/* $OpenBSD: awkgram.y,v 1.5 1999/04/20 17:31:29 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -241,10 +241,10 @@ pattern: | '(' plist ')' IN varname { $$ = op2(INTEST, $2, makearr($5)); } | pattern '|' GETLINE var { if (safe) ERROR "cmd | getline is unsafe" SYNTAX; - else $$ = op3(GETLINE, $4, (Node*)$2, $1); } + else $$ = op3(GETLINE, $4, itonp($2), $1); } | pattern '|' GETLINE { if (safe) ERROR "cmd | getline is unsafe" SYNTAX; - else $$ = op3(GETLINE, (Node*)0, (Node*)$2, $1); } + else $$ = op3(GETLINE, (Node*)0, itonp($2), $1); } | pattern term %prec CAT { $$ = op2(CAT, $1, $2); } | re | term @@ -295,13 +295,13 @@ rparen: simple_stmt: print prarg '|' term { if (safe) ERROR "print | is unsafe" SYNTAX; - else $$ = stat3($1, $2, (Node *) $3, $4); } + else $$ = stat3($1, $2, itonp($3), $4); } | print prarg APPEND term { if (safe) ERROR "print >> is unsafe" SYNTAX; - else $$ = stat3($1, $2, (Node *) $3, $4); } + else $$ = stat3($1, $2, itonp($3), $4); } | print prarg GT term { if (safe) ERROR "print > is unsafe" SYNTAX; - else $$ = stat3($1, $2, (Node *) $3, $4); } + else $$ = stat3($1, $2, itonp($3), $4); } | print prarg { $$ = stat3($1, $2, NIL, NIL); } | DELETE varname '[' patlist ']' { $$ = stat2(DELETE, makearr($2), $4); } | DELETE varname { $$ = stat2(DELETE, makearr($2), 0); } @@ -351,7 +351,8 @@ subop: ; term: - term '+' term { $$ = op2(ADD, $1, $3); } + term '/' ASGNOP term { $$ = op2(DIVEQ, $1, $4); } + | term '+' term { $$ = op2(ADD, $1, $3); } | term '-' term { $$ = op2(MINUS, $1, $3); } | term '*' term { $$ = op2(MULT, $1, $3); } | term '/' term { $$ = op2(DIVIDE, $1, $3); } @@ -360,17 +361,17 @@ term: | '-' term %prec UMINUS { $$ = op1(UMINUS, $2); } | '+' term %prec UMINUS { $$ = $2; } | NOT term %prec UMINUS { $$ = op1(NOT, notnull($2)); } - | BLTIN '(' ')' { $$ = op2(BLTIN, (Node *) $1, rectonode()); } - | BLTIN '(' patlist ')' { $$ = op2(BLTIN, (Node *) $1, $3); } - | BLTIN { $$ = op2(BLTIN, (Node *) $1, rectonode()); } + | BLTIN '(' ')' { $$ = op2(BLTIN, itonp($1), rectonode()); } + | BLTIN '(' patlist ')' { $$ = op2(BLTIN, itonp($1), $3); } + | BLTIN { $$ = op2(BLTIN, itonp($1), rectonode()); } | CALL '(' ')' { $$ = op2(CALL, celltonode($1,CVAR), NIL); } | CALL '(' patlist ')' { $$ = op2(CALL, celltonode($1,CVAR), $3); } | DECR var { $$ = op1(PREDECR, $2); } | INCR var { $$ = op1(PREINCR, $2); } | var DECR { $$ = op1(POSTDECR, $1); } | var INCR { $$ = op1(POSTINCR, $1); } - | GETLINE var LT term { $$ = op3(GETLINE, $2, (Node *)$3, $4); } - | GETLINE LT term { $$ = op3(GETLINE, NIL, (Node *)$2, $3); } + | GETLINE var LT term { $$ = op3(GETLINE, $2, itonp($3), $4); } + | GETLINE LT term { $$ = op3(GETLINE, NIL, itonp($2), $3); } | GETLINE var { $$ = op3(GETLINE, $2, NIL, NIL); } | GETLINE { $$ = op3(GETLINE, NIL, NIL, NIL); } | INDEX '(' pattern comma pattern ')' @@ -433,7 +434,7 @@ varlist: varname: VAR { $$ = celltonode($1, CVAR); } - | ARG { $$ = op1(ARG, (Node *) $1); } + | ARG { $$ = op1(ARG, itonp($1)); } | VARNF { $$ = op1(VARNF, (Node *) $1); } ; diff --git a/usr.bin/awk/b.c b/usr.bin/awk/b.c index 0553dedbdda..5722d3a30e1 100644 --- a/usr.bin/awk/b.c +++ b/usr.bin/awk/b.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b.c,v 1.6 1999/04/18 17:06:30 millert Exp $ */ +/* $OpenBSD: b.c,v 1.7 1999/04/20 17:31:29 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -38,7 +38,8 @@ THIS SOFTWARE. /* NCHARS is 2**n */ #define MAXLIN 22 -#define type(v) (v)->nobj +#define type(v) (v)->nobj /* badly overloaded here */ +#define info(v) (v)->ntype /* badly overloaded here */ #define left(v) (v)->narg[0] #define right(v) (v)->narg[1] #define parent(v) (v)->nnext @@ -183,7 +184,7 @@ void penter(Node *p) /* set up parent pointers and leaf indices */ { switch (type(p)) { LEAF - left(p) = (Node *) poscnt; + info(p) = poscnt; poscnt++; break; UNARY @@ -339,8 +340,8 @@ void cfoll(fa *f, Node *v) /* enter follow set of each leaf of vertex v into lfo switch (type(v)) { LEAF - f->re[(int) left(v)].ltype = type(v); - f->re[(int) left(v)].lval.np = right(v); + f->re[info(v)].ltype = type(v); + f->re[info(v)].lval.np = right(v); while (f->accept >= maxsetvec) { /* guessing here! */ maxsetvec *= 4; setvec = (int *) realloc(setvec, maxsetvec * sizeof(int)); @@ -354,7 +355,7 @@ void cfoll(fa *f, Node *v) /* enter follow set of each leaf of vertex v into lfo follow(v); /* computes setvec and setcnt */ if ((p = (int *) calloc(1, (setcnt+1)*sizeof(int))) == NULL) overflo("out of space building follow set"); - f->re[(int) left(v)].lfollow = p; + f->re[info(v)].lfollow = p; *p = setcnt; for (i = f->accept; i >= 0; i--) if (setvec[i] == 1) @@ -380,14 +381,13 @@ int first(Node *p) /* collects initially active leaves of p into setvec */ switch (type(p)) { LEAF - lp = (int) left(p); /* look for high-water mark of subscripts */ + lp = info(p); /* look for high-water mark of subscripts */ while (setcnt >= maxsetvec || lp >= maxsetvec) { /* guessing here! */ maxsetvec *= 4; setvec = (int *) realloc(setvec, maxsetvec * sizeof(int)); tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int)); - if (setvec == 0 || tmpset == 0) { abort(); + if (setvec == 0 || tmpset == 0) overflo("out of space in first()"); -} } if (setvec[lp] != 1) { setvec[lp] = 1; @@ -602,7 +602,7 @@ Node *primary(void) switch (rtok) { case CHAR: - np = op2(CHAR, NIL, (Node *) rlxval); + np = op2(CHAR, NIL, itonp(rlxval)); rtok = relex(); return (unary(np)); case ALL: @@ -621,7 +621,7 @@ Node *primary(void) return (unary(np)); case '^': rtok = relex(); - return (unary(op2(CHAR, NIL, (Node *) HAT))); + return (unary(op2(CHAR, NIL, itonp(HAT)))); case '$': rtok = relex(); return (unary(op2(CHAR, NIL, NIL))); @@ -754,9 +754,8 @@ int cgoto(fa *f, int s, int c) maxsetvec *= 4; setvec = (int *) realloc(setvec, maxsetvec * sizeof(int)); tmpset = (int *) realloc(tmpset, maxsetvec * sizeof(int)); - if (setvec == 0 || tmpset == 0) { abort(); + if (setvec == 0 || tmpset == 0) overflo("out of space in cgoto()"); -} } for (i = 0; i <= f->accept; i++) setvec[i] = 0; @@ -765,7 +764,7 @@ int cgoto(fa *f, int s, int c) p = f->posns[s]; for (i = 1; i <= *p; i++) { if ((k = f->re[p[i]].ltype) != FINAL) { - if ((k == CHAR && c == f->re[p[i]].lval.i) + 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)) diff --git a/usr.bin/awk/lex.c b/usr.bin/awk/lex.c index 688128bdc7a..5540056222c 100644 --- a/usr.bin/awk/lex.c +++ b/usr.bin/awk/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.2 1999/04/18 17:06:30 millert Exp $ */ +/* $OpenBSD: lex.c,v 1.3 1999/04/20 17:31:29 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -164,9 +164,9 @@ int regexpr(void); int sc = 0; /* 1 => return a } right now */ int reg = 0; /* 1 => return a REGEXPR now */ -int yylex() +int yylex(void) { - int c, n; + int c; static char *buf = 0; static int bufsize = 500; @@ -209,7 +209,7 @@ int yylex() RET(';'); case '\\': if (peek() == '\n') { - input(); lineno++; + input(); } else if (peek() == '\r') { input(); input(); /* \n */ lineno++; @@ -284,10 +284,7 @@ int yylex() } else RET('*'); case '/': - if (peek() == '=') { - input(); yylval.i = DIVEQ; RET(ASGNOP); - } else - RET('/'); + RET('/'); case '%': if (peek() == '=') { input(); yylval.i = MODEQ; RET(ASGNOP); @@ -302,7 +299,7 @@ int yylex() case '$': /* BUG: awkward, if not wrong */ c = gettok(&buf, &bufsize); - if (c == '(' || c == '[' || (infunc && (n=isarg(buf)) >= 0)) { + if (c == '(' || c == '[' || (infunc && isarg(buf) >= 0)) { unputstr(buf); RET(INDIRECT); } else if (isalpha(c)) { @@ -349,7 +346,7 @@ int yylex() } } -int string() +int string(void) { int c, n; char *s, *bp; @@ -378,7 +375,7 @@ int string() case 'r': *bp++ = '\r'; break; case 'b': *bp++ = '\b'; break; case 'v': *bp++ = '\v'; break; - case 'a': *bp++ = '\a'; break; + case 'a': *bp++ = '\007'; break; case '\\': *bp++ = '\\'; break; case '0': case '1': case '2': /* octal: \d \dd \ddd */ @@ -493,7 +490,7 @@ void startreg(void) /* next call to yyles will return a regular expression */ reg = 1; } -int regexpr() +int regexpr(void) { int c; static char *buf = 0; diff --git a/usr.bin/awk/lib.c b/usr.bin/awk/lib.c index 38660b4fac3..9706244dbc8 100644 --- a/usr.bin/awk/lib.c +++ b/usr.bin/awk/lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib.c,v 1.5 1999/04/18 17:06:30 millert Exp $ */ +/* $OpenBSD: lib.c,v 1.6 1999/04/20 17:31:29 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -487,6 +487,8 @@ void yyerror(char *s) fprintf(stderr, " at source line %d", lineno); if (curfname != NULL) fprintf(stderr, " in function %s", curfname); + if (compile_time == 1 && cursource() != NULL) + fprintf(stderr, " source file %s", cursource()); fprintf(stderr, "\n"); errorflag = 2; eprint(); @@ -541,9 +543,12 @@ void error(int f, char *s) fprintf(stderr, "\n"); } if (compile_time != 2 && curnode) - fprintf(stderr, " source line number %d\n", curnode->lineno); + fprintf(stderr, " source line number %d", curnode->lineno); else if (compile_time != 2 && lineno) - fprintf(stderr, " source line number %d\n", lineno); + fprintf(stderr, " source line number %d", lineno); + if (compile_time == 1 && cursource() != NULL) + fprintf(stderr, " source file %s", cursource()); + fprintf(stderr, "\n"); eprint(); if (f) { if (dbg > 1) /* core dump if serious debugging on */ @@ -602,7 +607,6 @@ void bclass(int c) double errcheck(double x, char *s) { - extern int errno; if (errno == EDOM) { errno = 0; diff --git a/usr.bin/awk/main.c b/usr.bin/awk/main.c index 7fb6b080da5..3cc45ba8ceb 100644 --- a/usr.bin/awk/main.c +++ b/usr.bin/awk/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.6 1999/04/18 17:06:30 millert Exp $ */ +/* $OpenBSD: main.c,v 1.7 1999/04/20 17:31:30 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 990305"; +char *version = "version 19990416"; #define DEBUG #include <stdio.h> @@ -182,6 +182,7 @@ int pgetc(void) /* get 1 character from awk program */ yyin = stdin; else if ((yyin = fopen(pfile[curpfile], "r")) == NULL) ERROR "can't open file %s", pfile[curpfile] FATAL; + lineno = 1; } if ((c = getc(yyin)) != EOF) return c; @@ -191,3 +192,11 @@ int pgetc(void) /* get 1 character from awk program */ curpfile++; } } + +char *cursource(void) /* current source file name */ +{ + if (npfile > 0) + return pfile[curpfile]; + else + return NULL; +} diff --git a/usr.bin/awk/parse.c b/usr.bin/awk/parse.c index 0fbe00d3e3d..429fdcaba7f 100644 --- a/usr.bin/awk/parse.c +++ b/usr.bin/awk/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.2 1997/08/25 16:17:13 kstailey Exp $ */ +/* $OpenBSD: parse.c,v 1.3 1999/04/20 17:31:30 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -208,7 +208,7 @@ Node *pa2stat(Node *a, Node *b, Node *c) /* pat, pat {...} */ { Node *x; - x = node4(PASTAT2, a, b, c, (Node *) paircnt); + x = node4(PASTAT2, a, b, c, itonp(paircnt)); if (paircnt++ >= PA2NUM) ERROR "limited to %d pat,pat statements", PA2NUM SYNTAX; x->ntype = NSTAT; @@ -260,3 +260,13 @@ int isarg(char *s) /* is s in argument list for current function? */ return n; return -1; } + +int ptoi(void *p) /* convert pointer to integer */ +{ + return (int) (long) p; /* swearing that p fits, of course */ +} + +Node *itonp(int i) /* and vice versa */ +{ + return (Node *) (long) i; +} diff --git a/usr.bin/awk/proto.h b/usr.bin/awk/proto.h index 4c109137d11..6e31c460320 100644 --- a/usr.bin/awk/proto.h +++ b/usr.bin/awk/proto.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proto.h,v 1.4 1999/04/18 17:06:30 millert Exp $ */ +/* $OpenBSD: proto.h,v 1.5 1999/04/20 17:31:30 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -66,6 +66,7 @@ extern int cgoto(fa *, int, int); extern void freefa(fa *); extern int pgetc(void); +extern char *cursource(void); extern Node *nodealloc(int); extern Node *exptostat(Node *); @@ -89,7 +90,9 @@ extern Node *linkum(Node *, Node *); extern void defn(Cell *, Node *, Node *); extern int isarg(char *); extern char *tokname(int); -extern Cell *(*proctab[])(Node **, int); +extern Cell *(*proctab[])(Node **, int); +extern int ptoi(void *); +extern Node *itonp(int); extern void syminit(void); extern void arginit(int, char **); diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index 9a1c96c8b66..aa664b3580e 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.14 1999/04/18 17:06:31 millert Exp $ */ +/* $OpenBSD: run.c,v 1.15 1999/04/20 17:31:30 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -70,9 +70,9 @@ Node *winner = NULL; /* root of parse tree */ Cell *tmps; /* free temporary cells for execution */ static Cell truecell ={ OBOOL, BTRUE, 0, 0, 1.0, NUM }; -Cell *true = &truecell; +Cell *True = &truecell; static Cell falsecell ={ OBOOL, BFALSE, 0, 0, 0.0, NUM }; -Cell *false = &falsecell; +Cell *False = &falsecell; static Cell breakcell ={ OJUMP, JBREAK, 0, 0, 0.0, NUM }; Cell *jbreak = &breakcell; static Cell contcell ={ OJUMP, JCONT, 0, 0, 0.0, NUM }; @@ -109,7 +109,7 @@ int adjbuf(char **pbuf, int *psiz, int minlen, int quantum, char **pbptr, /* round up to next multiple of quantum */ if (rminlen) minlen += quantum - rminlen; - tbuf = realloc(*pbuf, minlen); + tbuf = (char *) realloc(*pbuf, minlen); if (tbuf == NULL) { if (whatrtn) ERROR "out of memory in %s", whatrtn FATAL; @@ -136,7 +136,7 @@ Cell *execute(Node *u) /* execute a node of the parse tree */ Node *a; if (u == NULL) - return(true); + return(True); for (a = u; ; a = a->nnext) { curnode = a; if (isvalue(a)) { @@ -175,7 +175,7 @@ Cell *program(Node **a, int n) /* execute an awk program */ if (a[0]) { /* BEGIN */ x = execute(a[0]); if (isexit(x)) - return(true); + return(True); if (isjump(x)) ERROR "illegal break, continue, next or nextfile from BEGIN" FATAL; tempfree(x); @@ -197,7 +197,7 @@ Cell *program(Node **a, int n) /* execute an awk program */ tempfree(x); } ex1: - return(true); + return(True); } struct Frame { /* stack frame for awk function calls */ @@ -234,14 +234,14 @@ 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 */ - dprintf( ("calling %s, %d args (%d in defn), fp=%d\n", s, ncall, ndef, fp-frame) ); + dprintf( ("calling %s, %d args (%d in defn), fp=%d\n", s, ncall, ndef, (int) (fp-frame)) ); if (ncall > ndef) ERROR "function %s called with %d args, uses only %d", s, ncall, ndef WARNING; if (ncall + ndef > NARGS) ERROR "function %s has %d arguments, limit %d", s, ncall+ndef, NARGS FATAL; for (i = 0, x = a[1]; x != NULL; i++, x = x->nnext) { /* get call args */ - dprintf( ("evaluate args[%d], fp=%d:\n", i, fp-frame) ); + dprintf( ("evaluate args[%d], fp=%d:\n", i, (int) (fp-frame)) ); y = execute(x); oargs[i] = y; dprintf( ("args[%d]: %s %f <%s>, t=%o\n", @@ -272,9 +272,9 @@ Cell *call(Node **a, int n) /* function call. very kludgy and fragile */ fp->nargs = ndef; /* number defined with (excess are locals) */ fp->retval = gettemp(); - dprintf( ("start exec of %s, fp=%d\n", s, fp-frame) ); + dprintf( ("start exec of %s, fp=%d\n", s, (int) (fp-frame)) ); y = execute((Node *)(fcn->sval)); /* execute body */ - dprintf( ("finished exec of %s, fp=%d\n", s, fp-frame) ); + dprintf( ("finished exec of %s, fp=%d\n", s, (int) (fp-frame)) ); for (i = 0; i < ndef; i++) { Cell *t = fp->args[i]; @@ -323,7 +323,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 = ptoi(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", @@ -382,6 +382,7 @@ Cell *getline(Node **a, int n) /* get next line from specific input */ FILE *fp; char *buf; int bufsize = recsize; + int mode; if ((buf = (char *) malloc(bufsize)) == NULL) ERROR "out of memory in getline" FATAL; @@ -390,9 +391,10 @@ 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 */ - a[1] = (Node *) LE; /* arbitrary flag */ - fp = openfile((int) a[1], getsval(x)); + mode = ptoi(a[1]); + if (mode == '|') /* input pipe */ + mode = LE; /* arbitrary flag */ + fp = openfile(mode, getsval(x)); tempfree(x); if (fp == NULL) n = -1; @@ -442,7 +444,7 @@ Cell *array(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */ int bufsz = recsize; int nsub = strlen(*SUBSEP); - if ((buf = malloc(bufsz)) == NULL) + if ((buf = (char *) malloc(bufsz)) == NULL) ERROR "out of memory in array" FATAL; x = execute(a[0]); /* Cell* for symbol table */ @@ -482,7 +484,7 @@ Cell *awkdelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts * x = execute(a[0]); /* Cell* for symbol table */ if (!isarr(x)) - return true; + return True; if (a[1] == 0) { /* delete the elements, not the table */ freesymtab(x); x->tval &= ~STR; @@ -491,7 +493,7 @@ Cell *awkdelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts * } else { int bufsz = recsize; char *buf; - if ((buf = malloc(bufsz)) == NULL) + if ((buf = (char *) malloc(bufsz)) == NULL) ERROR "out of memory in adelete" FATAL; buf[0] = 0; for (np = a[1]; np; np = np->nnext) { @@ -508,7 +510,7 @@ Cell *awkdelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts * free(buf); } tempfree(x); - return true; + return True; } Cell *intest(Node **a, int n) /* a[0] is index (list), a[1] is symtab */ @@ -529,7 +531,7 @@ Cell *intest(Node **a, int n) /* a[0] is index (list), a[1] is symtab */ ap->tval |= ARR; ap->sval = (char *) makesymtab(NSYMTAB); } - if ((buf = malloc(bufsz)) == NULL) { + if ((buf = (char *) malloc(bufsz)) == NULL) { ERROR "out of memory in intest" FATAL; } buf[0] = 0; @@ -547,9 +549,9 @@ Cell *intest(Node **a, int n) /* a[0] is index (list), a[1] is symtab */ tempfree(ap); free(buf); if (k == NULL) - return(false); + return(False); else - return(true); + return(True); } @@ -588,9 +590,9 @@ Cell *matchop(Node **a, int n) /* ~ and match() */ x->fval = start; return x; } else if ((n == MATCH && i == 1) || (n == NOTMATCH && i == 0)) - return(true); + return(True); else - return(false); + return(False); } @@ -604,22 +606,22 @@ Cell *boolop(Node **a, int n) /* a[0] || a[1], a[0] && a[1], !a[0] */ tempfree(x); switch (n) { case BOR: - if (i) return(true); + if (i) return(True); y = execute(a[1]); i = istrue(y); tempfree(y); - if (i) return(true); - else return(false); + if (i) return(True); + else return(False); case AND: - if ( !i ) return(false); + if ( !i ) return(False); y = execute(a[1]); i = istrue(y); tempfree(y); - if (i) return(true); - else return(false); + if (i) return(True); + else return(False); case NOT: - if (i) return(false); - else return(true); + if (i) return(False); + else return(True); default: /* can't happen */ ERROR "unknown boolean operator %d", n FATAL; } @@ -643,18 +645,18 @@ Cell *relop(Node **a, int n) /* a[0 < a[1], etc. */ tempfree(x); tempfree(y); switch (n) { - case LT: if (i<0) return(true); - else return(false); - case LE: if (i<=0) return(true); - else return(false); - case NE: if (i!=0) return(true); - else return(false); - case EQ: if (i == 0) return(true); - else return(false); - case GE: if (i>=0) return(true); - else return(false); - case GT: if (i>0) return(true); - else return(false); + case LT: if (i<0) return(True); + else return(False); + case LE: if (i<=0) return(True); + else return(False); + case NE: if (i!=0) return(True); + else return(False); + case EQ: if (i == 0) return(True); + else return(False); + case GE: if (i>=0) return(True); + else return(False); + case GT: if (i>0) return(True); + else return(False); default: /* can't happen */ ERROR "unknown relational operator %d", n FATAL; } @@ -797,7 +799,7 @@ int format(char **pbuf, int *pbufsize, char *s, Node *a) /* printf-like conversi os = s; p = buf; - if ((fmt = malloc(fmtsz)) == NULL) + if ((fmt = (char *) malloc(fmtsz)) == NULL) ERROR "out of memory in format()" FATAL; while (*s) { adjbuf(&buf, &bufsize, MAXNUMSIZE+1+p-buf, recsize, &p, "format"); @@ -921,7 +923,7 @@ Cell *awksprintf(Node **a, int n) /* sprintf(a[0]) */ char *buf; int bufsz=3*recsize; - if ((buf=malloc(bufsz)) == NULL) + if ((buf = (char *) malloc(bufsz)) == NULL) ERROR "out of memory in awksprintf" FATAL; y = a[0]->nnext; x = execute(a[0]); @@ -944,7 +946,7 @@ Cell *awkprintf(Node **a, int n) /* printf */ int len; int bufsz=3*recsize; - if ((buf=malloc(bufsz)) == NULL) + if ((buf = (char *) malloc(bufsz)) == NULL) ERROR "out of memory in awkprintf" FATAL; y = a[0]->nnext; x = execute(a[0]); @@ -957,7 +959,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(ptoi(a[1]), a[2]); /* fputs(buf, fp); */ fwrite(buf, len, 1, fp); fflush(fp); @@ -965,7 +967,7 @@ Cell *awkprintf(Node **a, int n) /* printf */ ERROR "write error on %s", filename(fp) FATAL; } free(buf); - return(true); + return(True); } Cell *arith(Node **a, int n) /* a[0] + a[1], etc. also -a[0] */ @@ -1163,7 +1165,7 @@ Cell *dopa2(Node **a, int n) /* a[0], a[1] { a[2] } */ Cell *x; int pair; - pair = (int) a[3]; + pair = ptoi(a[3]); if (pairstack[pair] == 0) { x = execute(a[0]); if (istrue(x)) @@ -1178,7 +1180,7 @@ Cell *dopa2(Node **a, int n) /* a[0], a[1] { a[2] } */ x = execute(a[2]); return(x); } - return(false); + return(False); } Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */ @@ -1187,16 +1189,17 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */ char *s; int sep; char *t, temp, num[50], *fs = 0; - int n, tempstat; + int n, tempstat, arg3type; y = execute(a[0]); /* source string */ s = getsval(y); + arg3type = ptoi(a[3]); if (a[2] == 0) /* fs string */ fs = *FS; - else if ((int) a[3] == STRING) { /* split(str,arr,"string") */ + else if (arg3type == STRING) { /* split(str,arr,"string") */ x = execute(a[2]); fs = getsval(x); - } else if ((int) a[3] == REGEXPR) + } else if (arg3type == REGEXPR) fs = "(regexpr)"; /* split(str,arr,/regexpr/) */ else ERROR "illegal type of split" FATAL; @@ -1209,9 +1212,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) || arg3type == REGEXPR) { /* reg expr */ fa *pfa; - if ((int) a[3] == REGEXPR) { /* it's ready already */ + if (arg3type == REGEXPR) { /* it's ready already */ pfa = (fa *) a[2]; } else { pfa = makedfa(fs, 1); @@ -1301,7 +1304,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 && arg3type == STRING) tempfree(x); x = gettemp(); x->tval = NUM; @@ -1350,7 +1353,7 @@ Cell *whilestat(Node **a, int n) /* while (a[0]) a[1] */ tempfree(x); x = execute(a[1]); if (isbreak(x)) { - x = true; + x = True; return(x); } if (isnext(x) || isexit(x) || isret(x)) @@ -1366,7 +1369,7 @@ Cell *dostat(Node **a, int n) /* do a[0]; while(a[1]) */ for (;;) { x = execute(a[0]); if (isbreak(x)) - return true; + return True; if (isnext(x) || isnextfile(x) || isexit(x) || isret(x)) return(x); tempfree(x); @@ -1391,7 +1394,7 @@ Cell *forstat(Node **a, int n) /* for (a[0]; a[1]; a[2]) a[3] */ } x = execute(a[3]); if (isbreak(x)) /* turn off break */ - return true; + return True; if (isnext(x) || isexit(x) || isret(x)) return(x); tempfree(x); @@ -1409,7 +1412,7 @@ Cell *instat(Node **a, int n) /* for (a[0] in a[1]) a[2] */ vp = execute(a[0]); arrayp = execute(a[1]); if (!isarr(arrayp)) { - return true; + return True; } tp = (Array *) arrayp->sval; tempfree(arrayp); @@ -1420,7 +1423,7 @@ Cell *instat(Node **a, int n) /* for (a[0] in a[1]) a[2] */ x = execute(a[2]); if (isbreak(x)) { tempfree(vp); - return true; + return True; } if (isnext(x) || isexit(x) || isret(x)) { tempfree(vp); @@ -1429,7 +1432,7 @@ Cell *instat(Node **a, int n) /* for (a[0] in a[1]) a[2] */ tempfree(x); } } - return true; + return True; } Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg list */ @@ -1441,7 +1444,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 = ptoi(a[0]); x = execute(a[1]); nextarg = a[1]->nnext; switch (t) { @@ -1532,7 +1535,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(ptoi(a[1]), a[2]); for (x = a[0]; x != NULL; x = x->nnext) { y = execute(x); fputs(getsval(y), fp); @@ -1546,13 +1549,13 @@ Cell *printstat(Node **a, int n) /* print a[0] */ fflush(fp); if (ferror(fp)) ERROR "write error on %s", filename(fp) FATAL; - return(true); + return(True); } Cell *nullproc(Node **a, int n) { - n = 0; - a = 0; + n = n; + a = a; return 0; } @@ -1643,7 +1646,7 @@ Cell *closefile(Node **a, int n) Cell *x; int i, stat; - n = 0; + n = n; x = execute(a[0]); getsval(x); for (i = 0; i < FOPEN_MAX; i++) @@ -1662,7 +1665,7 @@ Cell *closefile(Node **a, int n) files[i].fp = NULL; } tempfree(x); - return(true); + return(True); } void closeall(void) @@ -1692,7 +1695,7 @@ Cell *sub(Node **a, int nnn) /* substitute command */ fa *pfa; int bufsz = recsize; - if ((buf=malloc(bufsz)) == NULL) + if ((buf = (char *) malloc(bufsz)) == NULL) ERROR "out of memory in sub" FATAL; x = execute(a[3]); /* target string */ t = getsval(x); @@ -1704,7 +1707,7 @@ Cell *sub(Node **a, int nnn) /* substitute command */ tempfree(y); } y = execute(a[2]); /* replacement string */ - result = false; + result = False; if (pmatch(pfa, t)) { sptr = t; adjbuf(&buf, &bufsz, 1+patbeg-sptr, recsize, 0, "sub"); @@ -1736,7 +1739,7 @@ Cell *sub(Node **a, int nnn) /* substitute command */ if (pb > buf + bufsz) ERROR "sub result2 %.30s too big; can't happen", buf FATAL; setsval(x, buf); /* BUG: should be able to avoid copy */ - result = true;; + result = True;; } tempfree(x); tempfree(y); @@ -1753,7 +1756,7 @@ Cell *gsub(Node **a, int nnn) /* global substitute */ int mflag, tempstat, num; int bufsz = recsize; - if ((buf=malloc(bufsz)) == NULL) + if ((buf = (char *) malloc(bufsz)) == NULL) ERROR "out of memory in gsub" FATAL; mflag = 0; /* if mflag == 0, can replace empty string */ num = 0; diff --git a/usr.bin/awk/tran.c b/usr.bin/awk/tran.c index cbbb00778ec..a35900df4be 100644 --- a/usr.bin/awk/tran.c +++ b/usr.bin/awk/tran.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tran.c,v 1.4 1999/04/18 17:06:31 millert Exp $ */ +/* $OpenBSD: tran.c,v 1.5 1999/04/20 17:31:31 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -262,11 +262,11 @@ void rehash(Array *tp) /* rehash items in small table into big one */ Cell *lookup(char *s, Array *tp) /* look for s in tp */ { - Cell *p, *prev = NULL; + Cell *p; int h; h = hash(s, tp->size); - for (p = tp->tab[h]; p != NULL; prev = p, p = p->cnext) + for (p = tp->tab[h]; p != NULL; p = p->cnext) if (strcmp(s, p->nval) == 0) return(p); /* found it */ return(NULL); /* not found */ |