diff options
author | 2020-06-10 21:03:56 +0000 | |
---|---|---|
committer | 2020-06-10 21:03:56 +0000 | |
commit | f81b289f59b9fdc7f7af92e6c9ff037f7daf0da3 (patch) | |
tree | 31e38ece9282b84102aa006c26f68115017fd231 | |
parent | Update awk to Oct 24, 2019 version. (diff) | |
download | wireguard-openbsd-f81b289f59b9fdc7f7af92e6c9ff037f7daf0da3.tar.xz wireguard-openbsd-f81b289f59b9fdc7f7af92e6c9ff037f7daf0da3.zip |
Update awk to Nov 10, 2019 version.
-rw-r--r-- | usr.bin/awk/FIXES | 14 | ||||
-rw-r--r-- | usr.bin/awk/awk.h | 18 | ||||
-rw-r--r-- | usr.bin/awk/awkgram.y | 10 | ||||
-rw-r--r-- | usr.bin/awk/b.c | 40 | ||||
-rw-r--r-- | usr.bin/awk/lex.c | 14 | ||||
-rw-r--r-- | usr.bin/awk/lib.c | 65 | ||||
-rw-r--r-- | usr.bin/awk/main.c | 15 | ||||
-rw-r--r-- | usr.bin/awk/proto.h | 12 | ||||
-rw-r--r-- | usr.bin/awk/run.c | 16 | ||||
-rw-r--r-- | usr.bin/awk/tran.c | 30 |
10 files changed, 130 insertions, 104 deletions
diff --git a/usr.bin/awk/FIXES b/usr.bin/awk/FIXES index 4bf883ea167..700e5519f47 100644 --- a/usr.bin/awk/FIXES +++ b/usr.bin/awk/FIXES @@ -1,4 +1,4 @@ -/* $OpenBSD: FIXES,v 1.28 2020/06/10 21:03:36 millert Exp $ */ +/* $OpenBSD: FIXES,v 1.29 2020/06/10 21:03:56 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -26,6 +26,18 @@ THIS SOFTWARE. This file lists all bug fixes, changes, etc., made since the AWK book was sent to the printers in August, 1987. +November 10, 2019: + Convert a number of Boolean integer variables into + actual bools. Convert compile_time variable into an + enum and simplify some of the related code. Thanks + to Arnold Robbins. + +November 8, 2019: + Fix from Ori Bernstein to get UTF-8 characters instead of + bytes when FS = "". This is currently the only bit of + the One True Awk that understands multibyte characters. + From Arnold Robbins, apply some cleanups in the test suite. + October 25, 2019: More fixes and cleanups from NetBSD, courtesy of Christos Zoulas. Merges PRs 54 and 55. diff --git a/usr.bin/awk/awk.h b/usr.bin/awk/awk.h index ca64bd02306..ba604cae6a6 100644 --- a/usr.bin/awk/awk.h +++ b/usr.bin/awk/awk.h @@ -1,4 +1,4 @@ -/* $OpenBSD: awk.h,v 1.20 2020/06/10 21:03:36 millert Exp $ */ +/* $OpenBSD: awk.h,v 1.21 2020/06/10 21:03:56 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -25,6 +25,7 @@ THIS SOFTWARE. #include <assert.h> #include <stdint.h> +#include <stdbool.h> typedef double Awkfloat; @@ -49,8 +50,13 @@ typedef unsigned char uschar; # define DPRINTF(x) #endif -extern int compile_time; /* 1 if compiling, 0 if running */ -extern int safe; /* 0 => unsafe, 1 => safe */ +extern enum compile_states { + RUNNING, + COMPILING, + ERROR_PRINTING +} compile_time; + +extern bool safe; /* false => unsafe, true => safe */ #define RECSIZE (8 * 1024) /* sets limit on records, fields, etc., etc. */ extern int recsize; /* size of current record, orig RECSIZE */ @@ -71,8 +77,8 @@ extern Awkfloat *RLENGTH; extern char *record; /* points to $0 */ extern int lineno; /* line number in awk program */ extern int errorflag; /* 1 if error has occurred */ -extern int donefld; /* 1 if record broken into fields */ -extern int donerec; /* 1 if record is valid (no fld has changed */ +extern bool donefld; /* true if record broken into fields */ +extern bool donerec; /* true if record is valid (no fld has changed */ extern char inputFS[]; /* FS at time of input, for field splitting */ extern int dbg; @@ -244,7 +250,7 @@ typedef struct fa { uschar *restr; int **posns; int state_count; - int anchor; + bool anchor; int use; int initstat; int curstat; diff --git a/usr.bin/awk/awkgram.y b/usr.bin/awk/awkgram.y index cf131a4388a..9a59fc785aa 100644 --- a/usr.bin/awk/awkgram.y +++ b/usr.bin/awk/awkgram.y @@ -1,4 +1,4 @@ -/* $OpenBSD: awkgram.y,v 1.11 2020/06/10 21:02:33 millert Exp $ */ +/* $OpenBSD: awkgram.y,v 1.12 2020/06/10 21:03:56 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -33,8 +33,8 @@ int yywrap(void) { return(1); } Node *beginloc = 0; Node *endloc = 0; -int infunc = 0; /* = 1 if in arglist or body of func */ -int inloop = 0; /* = 1 if in while, for, do */ +bool infunc = false; /* = true if in arglist or body of func */ +int inloop = 0; /* >= 1 if in while, for, do; can't be bool, since loops can next */ char *curfname = 0; /* current function name */ Node *arglist = 0; /* list of args for current function */ %} @@ -183,8 +183,8 @@ pa_stat: { beginloc = linkum(beginloc, $3); $$ = 0; } | XEND lbrace stmtlist '}' { endloc = linkum(endloc, $3); $$ = 0; } - | FUNC funcname '(' varlist rparen {infunc++;} lbrace stmtlist '}' - { infunc--; curfname=0; defn((Cell *)$2, $4, $8); $$ = 0; } + | FUNC funcname '(' varlist rparen {infunc = true;} lbrace stmtlist '}' + { infunc = false; curfname=0; defn((Cell *)$2, $4, $8); $$ = 0; } ; pa_stats: diff --git a/usr.bin/awk/b.c b/usr.bin/awk/b.c index 60317607645..85ed2d28300 100644 --- a/usr.bin/awk/b.c +++ b/usr.bin/awk/b.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b.c,v 1.28 2020/06/10 21:03:36 millert Exp $ */ +/* $OpenBSD: b.c,v 1.29 2020/06/10 21:03:56 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -149,7 +149,7 @@ out: overflo(__func__); } -fa *makedfa(const char *s, int anchor) /* returns dfa for reg expr s */ +fa *makedfa(const char *s, bool anchor) /* returns dfa for reg expr s */ { int i, use, nuse; fa *pfa; @@ -159,7 +159,7 @@ fa *makedfa(const char *s, int anchor) /* returns dfa for reg expr s */ allocsetvec(__func__); } - if (compile_time) /* a constant for sure */ + if (compile_time != RUNNING) /* a constant for sure */ return mkdfa(s, anchor); for (i = 0; i < nfatab; i++) /* is it there already? */ if (fatab[i]->anchor == anchor @@ -187,7 +187,7 @@ fa *makedfa(const char *s, int anchor) /* returns dfa for reg expr s */ return pfa; } -fa *mkdfa(const char *s, int anchor) /* does the real work of making a dfa */ +fa *mkdfa(const char *s, bool anchor) /* does the real work of making a dfa */ /* anchor = 1 for anchored matches, else 0 */ { Node *p, *p1; @@ -222,7 +222,7 @@ fa *mkdfa(const char *s, int anchor) /* does the real work of making a dfa */ return f; } -int makeinit(fa *f, int anchor) +int makeinit(fa *f, bool anchor) { int i, k; @@ -653,11 +653,11 @@ int nematch(fa *f, const char *p0) /* non-empty match, for sub */ * a match is found, patbeg and patlen are set appropriately. * * RETURN VALUES - * 0 No match found. - * 1 Match found. + * false No match found. + * true Match found. */ -int fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum) +bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum) { char *buf = *pbuf; int bufsize = *pbufsize; @@ -723,10 +723,10 @@ int fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum) FATAL("unable to ungetc '%c'", buf[k]); while (k > i + patlen); buf[k] = 0; - return 1; + return true; } else - return 0; + return false; } Node *reparse(const char *p) /* parses regular expression pointed to by p */ @@ -915,7 +915,7 @@ replace_repeat(const uschar *reptok, int reptoklen, const uschar *atom, int i, j; uschar *buf = NULL; int ret = 1; - int init_q = (firstnum==0); /* first added char will be ? */ + int init_q = (firstnum == 0); /* first added char will be ? */ int n_q_reps = secondnum-firstnum; /* m>n, so reduce until {1,m-n} left */ int prefix_length = reptok - basestr; /* prefix includes first rep */ int suffix_length = strlen((const char *) reptok) - reptoklen; /* string after rep specifier */ @@ -949,8 +949,9 @@ replace_repeat(const uschar *reptok, int reptoklen, const uschar *atom, if (special_case == REPEAT_PLUS_APPENDED) { buf[j++] = '+'; } else if (special_case == REPEAT_WITH_Q) { - if (init_q) buf[j++] = '?'; - for (i=0; i < n_q_reps; i++) { /* copy x? reps */ + if (init_q) + buf[j++] = '?'; + for (i = 0; i < n_q_reps; i++) { /* copy x? reps */ memcpy(&buf[j], atom, atomlen); j += atomlen; buf[j++] = '?'; @@ -1024,7 +1025,8 @@ int relex(void) /* lexical analyzer for reparse */ uschar *bp; struct charclass *cc; int i; - int num, m, commafound, digitfound; + int num, m; + bool commafound, digitfound; const uschar *startreptok; static int parens = 0; @@ -1158,8 +1160,8 @@ rescan: if (isdigit(*(prestr))) { num = 0; /* Process as a repetition */ n = -1; m = -1; - commafound = 0; - digitfound = 0; + commafound = false; + digitfound = false; startreptok = prestr-1; /* Remember start of previous atom here ? */ } else { /* just a { char, not a repetition */ @@ -1206,15 +1208,15 @@ rescan: lastre); } else if (isdigit(c)) { num = 10 * num + c - '0'; - digitfound = 1; + digitfound = true; } else if (c == ',') { if (commafound) FATAL("illegal repetition expression: class %.20s", lastre); /* looking for {n,} or {n,m} */ - commafound = 1; + commafound = true; n = num; - digitfound = 0; /* reset */ + digitfound = false; /* reset */ num = 0; } else { FATAL("illegal repetition expression: class %.20s", diff --git a/usr.bin/awk/lex.c b/usr.bin/awk/lex.c index 746e1e4978f..6a1400a7ca2 100644 --- a/usr.bin/awk/lex.c +++ b/usr.bin/awk/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.15 2020/06/10 21:03:36 millert Exp $ */ +/* $OpenBSD: lex.c,v 1.16 2020/06/10 21:03:56 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -175,8 +175,8 @@ int gettok(char **pbuf, int *psz) /* get next input token */ int word(char *); int string(void); int regexpr(void); -int sc = 0; /* 1 => return a } right now */ -int reg = 0; /* 1 => return a REGEXPR now */ +bool sc = false; /* true => return a } right now */ +bool reg = false; /* true => return a REGEXPR now */ int yylex(void) { @@ -187,11 +187,11 @@ int yylex(void) if (buf == NULL && (buf = malloc(bufsize)) == NULL) FATAL( "out of space in yylex" ); if (sc) { - sc = 0; + sc = false; RET('}'); } if (reg) { - reg = 0; + reg = false; return regexpr(); } for (;;) { @@ -338,7 +338,7 @@ int yylex(void) case '}': if (--bracecnt < 0) SYNTAX( "extra }" ); - sc = 1; + sc = true; RET(';'); case ']': if (--brackcnt < 0) @@ -511,7 +511,7 @@ int word(char *w) void startreg(void) /* next call to yylex will return a regular expression */ { - reg = 1; + reg = true; } int regexpr(void) diff --git a/usr.bin/awk/lib.c b/usr.bin/awk/lib.c index 175e39bc663..ee3e187aa77 100644 --- a/usr.bin/awk/lib.c +++ b/usr.bin/awk/lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib.c,v 1.31 2020/06/10 21:03:36 millert Exp $ */ +/* $OpenBSD: lib.c,v 1.32 2020/06/10 21:03:56 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -47,8 +47,8 @@ char inputFS[100] = " "; #define MAXFLD 2 int nfields = MAXFLD; /* last allocated slot for $i */ -int donefld; /* 1 = implies rec broken into fields */ -int donerec; /* 1 = record is valid (no flds have changed) */ +bool donefld; /* true = implies rec broken into fields */ +bool donerec; /* true = record is valid (no flds have changed) */ int lastfld = 0; /* last used field */ int argno = 1; /* current input argument number */ @@ -123,9 +123,9 @@ void savefs(void) strlcpy(inputFS, *FS, sizeof(inputFS)); } -static int firsttime = 1; +static bool firsttime = true; -int getrec(char **pbuf, int *pbufsize, int isrecord) /* get next input record */ +int getrec(char **pbuf, int *pbufsize, bool isrecord) /* get next input record */ { /* note: cares whether buf == record */ int c; char *buf = *pbuf; @@ -133,14 +133,14 @@ int getrec(char **pbuf, int *pbufsize, int isrecord) /* get next input record */ int bufsize = *pbufsize, savebufsize = bufsize; if (firsttime) { - firsttime = 0; + firsttime = false; initgetrec(); } DPRINTF( ("RS=<%s>, FS=<%s>, ARGC=%g, FILENAME=%s\n", *RS, *FS, *ARGC, *FILENAME) ); if (isrecord) { - donefld = 0; - donerec = 1; + donefld = false; + donerec = true; savefs(); } saveb0 = buf[0]; @@ -212,7 +212,7 @@ int readrec(char **pbuf, int *pbufsize, FILE *inf) /* read one record into buf * char *rs = getsval(rsloc); if (*rs && rs[1]) { - int found; + bool found; fa *pfa = makedfa(rs, 1); found = fnematch(pfa, inf, &buf, &bufsize, recsize); @@ -334,15 +334,19 @@ void fldbld(void) /* create fields from current record */ } *fr = 0; } else if ((sep = *inputFS) == 0) { /* new: FS="" => 1 char/field */ - for (i = 0; *r != 0; r++) { - char buf[2]; + for (i = 0; *r != '\0'; r += n) { + char buf[MB_CUR_MAX + 1]; + i++; if (i > nfields) growfldtab(i); if (freeable(fldtab[i])) xfree(fldtab[i]->sval); - buf[0] = *r; - buf[1] = 0; + n = mblen(r, MB_CUR_MAX); + if (n < 0) + n = 1; + memcpy(buf, r, n); + buf[n] = '\0'; fldtab[i]->sval = tostring(buf); fldtab[i]->tval = FLD | STR; } @@ -375,7 +379,7 @@ void fldbld(void) /* create fields from current record */ FATAL("record `%.30s...' has too many fields; can't happen", r); cleanfld(i+1, lastfld); /* clean out junk from previous record */ lastfld = i; - donefld = 1; + donefld = true; for (j = 1; j <= lastfld; j++) { p = fldtab[j]; if(is_number(p->sval)) { @@ -384,7 +388,7 @@ void fldbld(void) /* create fields from current record */ } } setfval(nfloc, (Awkfloat) lastfld); - donerec = 1; /* restore */ + donerec = true; /* restore */ if (dbg) { for (j = 0; j <= lastfld; j++) { p = fldtab[j]; @@ -511,7 +515,7 @@ void recbld(void) /* create $0 from $1..$NF if necessary */ char *r, *p; char *sep = getsval(ofsloc); - if (donerec == 1) + if (donerec) return; r = record; for (i = 1; i <= *NF; i++) { @@ -539,7 +543,7 @@ void recbld(void) /* create $0 from $1..$NF if necessary */ DPRINTF( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, (void*)fldtab[0]) ); DPRINTF( ("recbld = |%s|\n", record) ); - donerec = 1; + donerec = true; } int errorflag = 0; @@ -564,7 +568,7 @@ void SYNTAX(const char *fmt, ...) fprintf(stderr, " at source line %d", lineno); if (curfname != NULL) fprintf(stderr, " in function %s", curfname); - if (compile_time == 1 && cursource() != NULL) + if (compile_time == COMPILING && cursource() != NULL) fprintf(stderr, " source file %s", cursource()); fprintf(stderr, "\n"); errorflag = 2; @@ -660,17 +664,20 @@ void error() extern Node *curnode; fprintf(stderr, "\n"); - if (compile_time != 2 && NR && *NR > 0) { - fprintf(stderr, " input record number %d", (int) (*FNR)); - if (strcmp(*FILENAME, "-") != 0) - fprintf(stderr, ", file %s", *FILENAME); - fprintf(stderr, "\n"); + if (compile_time != ERROR_PRINTING) { + if (NR && *NR > 0) { + fprintf(stderr, " input record number %d", (int) (*FNR)); + if (strcmp(*FILENAME, "-") != 0) + fprintf(stderr, ", file %s", *FILENAME); + fprintf(stderr, "\n"); + } + if (curnode) + fprintf(stderr, " source line number %d", curnode->lineno); + else if (lineno) + fprintf(stderr, " source line number %d", lineno); } - if (compile_time != 2 && curnode) - fprintf(stderr, " source line number %d", curnode->lineno); - else if (compile_time != 2 && lineno) - fprintf(stderr, " source line number %d", lineno); - if (compile_time == 1 && cursource() != NULL) + + if (compile_time == COMPILING && cursource() != NULL) fprintf(stderr, " source file %s", cursource()); fprintf(stderr, "\n"); eprint(); @@ -683,7 +690,7 @@ void eprint(void) /* try to print context around error */ static int been_here = 0; extern char ebuf[], *ep; - if (compile_time == 2 || compile_time == 0 || been_here++ > 0 || ebuf == ep) + if (compile_time != COMPILING || been_here++ > 0 || ebuf == ep) return; p = ep - 1; if (p > ebuf && *p == '\n') diff --git a/usr.bin/awk/main.c b/usr.bin/awk/main.c index eca436d48de..2b83de5a2e2 100644 --- a/usr.bin/awk/main.c +++ b/usr.bin/awk/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.33 2020/06/10 21:03:36 millert Exp $ */ +/* $OpenBSD: main.c,v 1.34 2020/06/10 21:03:56 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. ****************************************************************/ -const char *version = "version 20191025"; +const char *version = "version 20191110"; #define DEBUG #include <stdio.h> @@ -46,8 +46,7 @@ char *cmdname; /* gets argv[0] for error messages */ extern FILE *yyin; /* lex input file */ char *lexprog; /* points to program argument if it exists */ extern int errorflag; /* non-zero if any syntax errors; set by yyerror */ -int compile_time = 2; /* for error printing: */ - /* 2 = cmdline, 1 = compile, 0 = running */ +enum compile_states compile_time = ERROR_PRINTING; #define MAX_PFILE 20 /* max number of -f's */ @@ -55,7 +54,7 @@ char *pfile[MAX_PFILE]; /* program filenames from -f's */ int npfile = 0; /* number of filenames */ int curpfile = 0; /* current filename */ -int safe = 0; /* 1 => "safe" mode */ +bool safe = false; /* true => "safe" mode */ int main(int argc, char *argv[]) { @@ -90,7 +89,7 @@ int main(int argc, char *argv[]) switch (argv[1][1]) { case 's': if (strcmp(argv[1], "-safe") == 0) - safe = 1; + safe = true; break; case 'f': /* next argument is program filename */ if (argv[1][2] != 0) { /* arg is -fsomething */ @@ -178,7 +177,7 @@ int main(int argc, char *argv[]) } recinit(recsize); syminit(); - compile_time = 1; + compile_time = COMPILING; argv[0] = cmdname; /* put prog name at front of arglist */ DPRINTF( ("argc=%d, argv[0]=%s\n", argc, argv[0]) ); arginit(argc, argv); @@ -190,7 +189,7 @@ int main(int argc, char *argv[]) *FS = qstring(fs, '\0'); DPRINTF( ("errorflag=%d\n", errorflag) ); if (errorflag == 0) { - compile_time = 0; + compile_time = RUNNING; run(winner); } else bracecheck(); diff --git a/usr.bin/awk/proto.h b/usr.bin/awk/proto.h index ef48003c2af..e38508fd316 100644 --- a/usr.bin/awk/proto.h +++ b/usr.bin/awk/proto.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proto.h,v 1.15 2020/06/10 21:03:36 millert Exp $ */ +/* $OpenBSD: proto.h,v 1.16 2020/06/10 21:03:56 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -39,9 +39,9 @@ extern int yylook(void); extern int yyback(int *, int); extern int yyinput(void); -extern fa *makedfa(const char *, int); -extern fa *mkdfa(const char *, int); -extern int makeinit(fa *, int); +extern fa *makedfa(const char *, bool); +extern fa *mkdfa(const char *, bool); +extern int makeinit(fa *, bool); extern void penter(Node *); extern void freetr(Node *); extern int hexstr(const uschar **); @@ -55,7 +55,7 @@ extern int member(int, const char *); extern int match(fa *, const char *); extern int pmatch(fa *, const char *); extern int nematch(fa *, const char *); -extern int fnematch(fa *, FILE *, char **, int *, int); +extern bool fnematch(fa *, FILE *, char **, int *, int); extern Node *reparse(const char *); extern Node *regexp(void); extern Node *primary(void); @@ -120,7 +120,7 @@ extern void initgetrec(void); extern void makefields(int, int); extern void growfldtab(int n); extern void savefs(void); -extern int getrec(char **, int *, int); +extern int getrec(char **, int *, bool); extern void nextfile(void); extern int readrec(char **buf, int *bufsize, FILE *inf); extern char *getargv(int); diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index b74723ea89e..2b2a775c703 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.53 2020/06/10 21:03:36 millert Exp $ */ +/* $OpenBSD: run.c,v 1.54 2020/06/10 21:03:56 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -192,7 +192,7 @@ Cell *program(Node **a, int n) /* execute an awk program */ tempfree(x); } if (a[1] || a[2]) - while (getrec(&record, &recsize, 1) > 0) { + while (getrec(&record, &recsize, true) > 0) { x = execute(a[1]); if (isexit(x)) break; @@ -442,9 +442,9 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */ } } else { /* bare getline; use current input */ if (a[0] == NULL) /* getline */ - n = getrec(&record, &recsize, 1); + n = getrec(&record, &recsize, true); else { /* getline var */ - n = getrec(&buf, &bufsize, 0); + n = getrec(&buf, &bufsize, false); x = execute(a[0]); setsval(x, buf); if (is_number(x->sval)) { @@ -461,7 +461,7 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */ Cell *getnf(Node **a, int n) /* get NF */ { - if (donefld == 0) + if (!donefld) fldbld(); return (Cell *) a[0]; } @@ -825,15 +825,15 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co #define FMTSZ(a) (fmtsz - ((a) - fmt)) #define BUFSZ(a) (bufsize - ((a) - buf)) - static int first = 1; - static int have_a_format = 0; + static bool first = true; + static bool have_a_format = false; if (first) { char buf[100]; snprintf(buf, sizeof(buf), "%a", 42.0); have_a_format = (strcmp(buf, "0x1.5p+5") == 0); - first = 0; + first = false; } os = s; diff --git a/usr.bin/awk/tran.c b/usr.bin/awk/tran.c index f4c989e2e8e..6bd93b34e69 100644 --- a/usr.bin/awk/tran.c +++ b/usr.bin/awk/tran.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tran.c,v 1.23 2020/06/10 21:03:36 millert Exp $ */ +/* $OpenBSD: tran.c,v 1.24 2020/06/10 21:03:56 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -307,21 +307,21 @@ Awkfloat setfval(Cell *vp, Awkfloat f) /* set float val of a Cell */ if ((vp->tval & (NUM | STR)) == 0) funnyvar(vp, "assign to"); if (isfld(vp)) { - donerec = 0; /* mark $0 invalid */ + donerec = false; /* mark $0 invalid */ fldno = atoi(vp->nval); if (fldno > *NF) newfld(fldno); DPRINTF( ("setting field %d to %g\n", fldno, f) ); } else if (&vp->fval == NF) { - donerec = 0; /* mark $0 invalid */ + donerec = false; /* mark $0 invalid */ setlastfld(f); DPRINTF( ("setting NF to %g\n", f) ); } else if (isrec(vp)) { - donefld = 0; /* mark $1... invalid */ - donerec = 1; + donefld = false; /* mark $1... invalid */ + donerec = true; savefs(); } else if (vp == ofsloc) { - if (donerec == 0) + if (!donerec) recbld(); } if (freeable(vp)) @@ -356,17 +356,17 @@ char *setsval(Cell *vp, const char *s) /* set string val of a Cell */ if ((vp->tval & (NUM | STR)) == 0) funnyvar(vp, "assign to"); if (isfld(vp)) { - donerec = 0; /* mark $0 invalid */ + donerec = false; /* mark $0 invalid */ fldno = atoi(vp->nval); if (fldno > *NF) newfld(fldno); DPRINTF( ("setting field %d to %s (%p)\n", fldno, s, s) ); } else if (isrec(vp)) { - donefld = 0; /* mark $1... invalid */ - donerec = 1; + donefld = false; /* mark $1... invalid */ + donerec = true; savefs(); } else if (vp == ofsloc) { - if (donerec == 0) + if (!donerec) recbld(); } t = s ? tostring(s) : tostring(""); /* in case it's self-assign */ @@ -380,7 +380,7 @@ char *setsval(Cell *vp, const char *s) /* set string val of a Cell */ (void*)vp, NN(vp->nval), t, t, vp->tval, donerec, donefld) ); vp->sval = t; if (&vp->fval == NF) { - donerec = 0; /* mark $0 invalid */ + donerec = false; /* mark $0 invalid */ f = getfval(vp); setlastfld(f); DPRINTF( ("setting NF to %g\n", f) ); @@ -393,9 +393,9 @@ Awkfloat getfval(Cell *vp) /* get float val of a Cell */ { if ((vp->tval & (NUM | STR)) == 0) funnyvar(vp, "read value of"); - if (isfld(vp) && donefld == 0) + if (isfld(vp) && !donefld) fldbld(); - else if (isrec(vp) && donerec == 0) + else if (isrec(vp) && !donerec) recbld(); if (!isnum(vp)) { /* not a number */ vp->fval = atof(vp->sval); /* best guess */ @@ -414,9 +414,9 @@ static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cel if ((vp->tval & (NUM | STR)) == 0) funnyvar(vp, "read value of"); - if (isfld(vp) && donefld == 0) + if (isfld(vp) && ! donefld) fldbld(); - else if (isrec(vp) && donerec == 0) + else if (isrec(vp) && ! donerec) recbld(); /* |