Convert variables to bool and enum.

This commit is contained in:
Arnold D. Robbins 2019-11-10 21:19:18 +02:00
parent c879fbf013
commit 108224b484
10 changed files with 106 additions and 90 deletions

6
FIXES
View File

@ -25,6 +25,12 @@ THIS SOFTWARE.
This file lists all bug fixes, changes, etc., made since the AWK book This file lists all bug fixes, changes, etc., made since the AWK book
was sent to the printers in August, 1987. 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: November 8, 2019:
Fix from Ori Bernstein to get UTF-8 characters instead of Fix from Ori Bernstein to get UTF-8 characters instead of
bytes when FS = "". This is currently the only bit of bytes when FS = "". This is currently the only bit of

16
awk.h
View File

@ -24,6 +24,7 @@ THIS SOFTWARE.
#include <assert.h> #include <assert.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
typedef double Awkfloat; typedef double Awkfloat;
@ -48,8 +49,13 @@ typedef unsigned char uschar;
# define dprintf(x) # define dprintf(x)
#endif #endif
extern int compile_time; /* 1 if compiling, 0 if running */ extern enum compile_states {
extern int safe; /* 0 => unsafe, 1 => safe */ RUNNING,
COMPILING,
ERROR_PRINTING
} compile_time;
extern bool safe; /* false => unsafe, true => safe */
#define RECSIZE (8 * 1024) /* sets limit on records, fields, etc., etc. */ #define RECSIZE (8 * 1024) /* sets limit on records, fields, etc., etc. */
extern int recsize; /* size of current record, orig RECSIZE */ extern int recsize; /* size of current record, orig RECSIZE */
@ -70,8 +76,8 @@ extern Awkfloat *RLENGTH;
extern char *record; /* points to $0 */ extern char *record; /* points to $0 */
extern int lineno; /* line number in awk program */ extern int lineno; /* line number in awk program */
extern int errorflag; /* 1 if error has occurred */ extern int errorflag; /* 1 if error has occurred */
extern int donefld; /* 1 if record broken into fields */ extern bool donefld; /* true if record broken into fields */
extern int donerec; /* 1 if record is valid (no fld has changed */ extern bool donerec; /* true if record is valid (no fld has changed */
extern char inputFS[]; /* FS at time of input, for field splitting */ extern char inputFS[]; /* FS at time of input, for field splitting */
extern int dbg; extern int dbg;
@ -237,7 +243,7 @@ typedef struct fa {
uschar *restr; uschar *restr;
int **posns; int **posns;
int state_count; int state_count;
int anchor; bool anchor;
int use; int use;
int initstat; int initstat;
int curstat; int curstat;

View File

@ -32,8 +32,8 @@ int yywrap(void) { return(1); }
Node *beginloc = 0; Node *beginloc = 0;
Node *endloc = 0; Node *endloc = 0;
int infunc = 0; /* = 1 if in arglist or body of func */ bool infunc = false; /* = true if in arglist or body of func */
int inloop = 0; /* = 1 if in while, for, do */ int inloop = 0; /* >= 1 if in while, for, do; can't be bool, since loops can next */
char *curfname = 0; /* current function name */ char *curfname = 0; /* current function name */
Node *arglist = 0; /* list of args for current function */ Node *arglist = 0; /* list of args for current function */
%} %}
@ -182,8 +182,8 @@ pa_stat:
{ beginloc = linkum(beginloc, $3); $$ = 0; } { beginloc = linkum(beginloc, $3); $$ = 0; }
| XEND lbrace stmtlist '}' | XEND lbrace stmtlist '}'
{ endloc = linkum(endloc, $3); $$ = 0; } { endloc = linkum(endloc, $3); $$ = 0; }
| FUNC funcname '(' varlist rparen {infunc++;} lbrace stmtlist '}' | FUNC funcname '(' varlist rparen {infunc = true;} lbrace stmtlist '}'
{ infunc--; curfname=0; defn((Cell *)$2, $4, $8); $$ = 0; } { infunc = false; curfname=0; defn((Cell *)$2, $4, $8); $$ = 0; }
; ;
pa_stats: pa_stats:

38
b.c
View File

@ -141,7 +141,7 @@ out:
overflo(__func__); 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; int i, use, nuse;
fa *pfa; fa *pfa;
@ -151,7 +151,7 @@ fa *makedfa(const char *s, int anchor) /* returns dfa for reg expr s */
resizesetvec(__func__); resizesetvec(__func__);
} }
if (compile_time) /* a constant for sure */ if (compile_time != RUNNING) /* a constant for sure */
return mkdfa(s, anchor); return mkdfa(s, anchor);
for (i = 0; i < nfatab; i++) /* is it there already? */ for (i = 0; i < nfatab; i++) /* is it there already? */
if (fatab[i]->anchor == anchor if (fatab[i]->anchor == anchor
@ -179,7 +179,7 @@ fa *makedfa(const char *s, int anchor) /* returns dfa for reg expr s */
return pfa; 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 */ /* anchor = 1 for anchored matches, else 0 */
{ {
Node *p, *p1; Node *p, *p1;
@ -214,7 +214,7 @@ fa *mkdfa(const char *s, int anchor) /* does the real work of making a dfa */
return f; return f;
} }
int makeinit(fa *f, int anchor) int makeinit(fa *f, bool anchor)
{ {
int i, k; int i, k;
@ -645,11 +645,11 @@ int nematch(fa *f, const char *p0) /* non-empty match, for sub */
* a match is found, patbeg and patlen are set appropriately. * a match is found, patbeg and patlen are set appropriately.
* *
* RETURN VALUES * RETURN VALUES
* 0 No match found. * false No match found.
* 1 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; char *buf = *pbuf;
int bufsize = *pbufsize; int bufsize = *pbufsize;
@ -715,10 +715,10 @@ int fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum)
FATAL("unable to ungetc '%c'", buf[k]); FATAL("unable to ungetc '%c'", buf[k]);
while (k > i + patlen); while (k > i + patlen);
buf[k] = 0; buf[k] = 0;
return 1; return true;
} }
else else
return 0; return false;
} }
Node *reparse(const char *p) /* parses regular expression pointed to by p */ Node *reparse(const char *p) /* parses regular expression pointed to by p */
@ -908,7 +908,7 @@ replace_repeat(const uschar *reptok, int reptoklen, const uschar *atom,
int i, j; int i, j;
uschar *buf = 0; uschar *buf = 0;
int ret = 1; 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 n_q_reps = secondnum-firstnum; /* m>n, so reduce until {1,m-n} left */
int prefix_length = reptok - basestr; /* prefix includes first rep */ int prefix_length = reptok - basestr; /* prefix includes first rep */
int suffix_length = strlen((const char *) reptok) - reptoklen; /* string after rep specifier */ int suffix_length = strlen((const char *) reptok) - reptoklen; /* string after rep specifier */
@ -942,8 +942,9 @@ replace_repeat(const uschar *reptok, int reptoklen, const uschar *atom,
if (special_case == REPEAT_PLUS_APPENDED) { if (special_case == REPEAT_PLUS_APPENDED) {
buf[j++] = '+'; buf[j++] = '+';
} else if (special_case == REPEAT_WITH_Q) { } else if (special_case == REPEAT_WITH_Q) {
if (init_q) buf[j++] = '?'; if (init_q)
for (i=0; i < n_q_reps; i++) { /* copy x? reps */ buf[j++] = '?';
for (i = 0; i < n_q_reps; i++) { /* copy x? reps */
memcpy(&buf[j], atom, atomlen); memcpy(&buf[j], atom, atomlen);
j += atomlen; j += atomlen;
buf[j++] = '?'; buf[j++] = '?';
@ -1017,7 +1018,8 @@ int relex(void) /* lexical analyzer for reparse */
uschar *bp; uschar *bp;
struct charclass *cc; struct charclass *cc;
int i; int i;
int num, m, commafound, digitfound; int num, m;
bool commafound, digitfound;
const uschar *startreptok; const uschar *startreptok;
static int parens = 0; static int parens = 0;
@ -1151,8 +1153,8 @@ rescan:
if (isdigit(*(prestr))) { if (isdigit(*(prestr))) {
num = 0; /* Process as a repetition */ num = 0; /* Process as a repetition */
n = -1; m = -1; n = -1; m = -1;
commafound = 0; commafound = false;
digitfound = 0; digitfound = false;
startreptok = prestr-1; startreptok = prestr-1;
/* Remember start of previous atom here ? */ /* Remember start of previous atom here ? */
} else { /* just a { char, not a repetition */ } else { /* just a { char, not a repetition */
@ -1199,15 +1201,15 @@ rescan:
lastre); lastre);
} else if (isdigit(c)) { } else if (isdigit(c)) {
num = 10 * num + c - '0'; num = 10 * num + c - '0';
digitfound = 1; digitfound = true;
} else if (c == ',') { } else if (c == ',') {
if (commafound) if (commafound)
FATAL("illegal repetition expression: class %.20s", FATAL("illegal repetition expression: class %.20s",
lastre); lastre);
/* looking for {n,} or {n,m} */ /* looking for {n,} or {n,m} */
commafound = 1; commafound = true;
n = num; n = num;
digitfound = 0; /* reset */ digitfound = false; /* reset */
num = 0; num = 0;
} else { } else {
FATAL("illegal repetition expression: class %.20s", FATAL("illegal repetition expression: class %.20s",

12
lex.c
View File

@ -164,8 +164,8 @@ int gettok(char **pbuf, int *psz) /* get next input token */
int word(char *); int word(char *);
int string(void); int string(void);
int regexpr(void); int regexpr(void);
int sc = 0; /* 1 => return a } right now */ bool sc = false; /* true => return a } right now */
int reg = 0; /* 1 => return a REGEXPR now */ bool reg = false; /* true => return a REGEXPR now */
int yylex(void) int yylex(void)
{ {
@ -176,11 +176,11 @@ int yylex(void)
if (buf == NULL && (buf = malloc(bufsize)) == NULL) if (buf == NULL && (buf = malloc(bufsize)) == NULL)
FATAL( "out of space in yylex" ); FATAL( "out of space in yylex" );
if (sc) { if (sc) {
sc = 0; sc = false;
RET('}'); RET('}');
} }
if (reg) { if (reg) {
reg = 0; reg = false;
return regexpr(); return regexpr();
} }
for (;;) { for (;;) {
@ -327,7 +327,7 @@ int yylex(void)
case '}': case '}':
if (--bracecnt < 0) if (--bracecnt < 0)
SYNTAX( "extra }" ); SYNTAX( "extra }" );
sc = 1; sc = true;
RET(';'); RET(';');
case ']': case ']':
if (--brackcnt < 0) if (--brackcnt < 0)
@ -500,7 +500,7 @@ int word(char *w)
void startreg(void) /* next call to yylex will return a regular expression */ void startreg(void) /* next call to yylex will return a regular expression */
{ {
reg = 1; reg = true;
} }
int regexpr(void) int regexpr(void)

51
lib.c
View File

@ -45,8 +45,8 @@ char inputFS[100] = " ";
#define MAXFLD 2 #define MAXFLD 2
int nfields = MAXFLD; /* last allocated slot for $i */ int nfields = MAXFLD; /* last allocated slot for $i */
int donefld; /* 1 = implies rec broken into fields */ bool donefld; /* true = implies rec broken into fields */
int donerec; /* 1 = record is valid (no flds have changed) */ bool donerec; /* true = record is valid (no flds have changed) */
int lastfld = 0; /* last used field */ int lastfld = 0; /* last used field */
int argno = 1; /* current input argument number */ int argno = 1; /* current input argument number */
@ -121,9 +121,9 @@ void savefs(void)
strcpy(inputFS, *FS); strcpy(inputFS, *FS);
} }
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 */ { /* note: cares whether buf == record */
int c; int c;
char *buf = *pbuf; char *buf = *pbuf;
@ -131,14 +131,14 @@ int getrec(char **pbuf, int *pbufsize, int isrecord) /* get next input record */
int bufsize = *pbufsize, savebufsize = bufsize; int bufsize = *pbufsize, savebufsize = bufsize;
if (firsttime) { if (firsttime) {
firsttime = 0; firsttime = false;
initgetrec(); initgetrec();
} }
dprintf( ("RS=<%s>, FS=<%s>, ARGC=%g, FILENAME=%s\n", dprintf( ("RS=<%s>, FS=<%s>, ARGC=%g, FILENAME=%s\n",
*RS, *FS, *ARGC, *FILENAME) ); *RS, *FS, *ARGC, *FILENAME) );
if (isrecord) { if (isrecord) {
donefld = 0; donefld = false;
donerec = 1; donerec = true;
savefs(); savefs();
} }
saveb0 = buf[0]; saveb0 = buf[0];
@ -210,7 +210,7 @@ int readrec(char **pbuf, int *pbufsize, FILE *inf) /* read one record into buf *
char *rs = getsval(rsloc); char *rs = getsval(rsloc);
if (*rs && rs[1]) { if (*rs && rs[1]) {
int found; bool found;
fa *pfa = makedfa(rs, 1); fa *pfa = makedfa(rs, 1);
found = fnematch(pfa, inf, &buf, &bufsize, recsize); found = fnematch(pfa, inf, &buf, &bufsize, recsize);
@ -377,7 +377,7 @@ void fldbld(void) /* create fields from current record */
FATAL("record `%.30s...' has too many fields; can't happen", r); FATAL("record `%.30s...' has too many fields; can't happen", r);
cleanfld(i+1, lastfld); /* clean out junk from previous record */ cleanfld(i+1, lastfld); /* clean out junk from previous record */
lastfld = i; lastfld = i;
donefld = 1; donefld = true;
for (j = 1; j <= lastfld; j++) { for (j = 1; j <= lastfld; j++) {
p = fldtab[j]; p = fldtab[j];
if(is_number(p->sval)) { if(is_number(p->sval)) {
@ -386,7 +386,7 @@ void fldbld(void) /* create fields from current record */
} }
} }
setfval(nfloc, (Awkfloat) lastfld); setfval(nfloc, (Awkfloat) lastfld);
donerec = 1; /* restore */ donerec = true; /* restore */
if (dbg) { if (dbg) {
for (j = 0; j <= lastfld; j++) { for (j = 0; j <= lastfld; j++) {
p = fldtab[j]; p = fldtab[j];
@ -513,7 +513,7 @@ void recbld(void) /* create $0 from $1..$NF if necessary */
char *r, *p; char *r, *p;
char *sep = getsval(ofsloc); char *sep = getsval(ofsloc);
if (donerec == 1) if (donerec)
return; return;
r = record; r = record;
for (i = 1; i <= *NF; i++) { for (i = 1; i <= *NF; i++) {
@ -541,7 +541,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( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, (void*)fldtab[0]) );
dprintf( ("recbld = |%s|\n", record) ); dprintf( ("recbld = |%s|\n", record) );
donerec = 1; donerec = true;
} }
int errorflag = 0; int errorflag = 0;
@ -566,7 +566,7 @@ void SYNTAX(const char *fmt, ...)
fprintf(stderr, " at source line %d", lineno); fprintf(stderr, " at source line %d", lineno);
if (curfname != NULL) if (curfname != NULL)
fprintf(stderr, " in function %s", curfname); 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, " source file %s", cursource());
fprintf(stderr, "\n"); fprintf(stderr, "\n");
errorflag = 2; errorflag = 2;
@ -640,17 +640,20 @@ void error()
extern Node *curnode; extern Node *curnode;
fprintf(stderr, "\n"); fprintf(stderr, "\n");
if (compile_time != 2 && NR && *NR > 0) { if (compile_time != ERROR_PRINTING) {
fprintf(stderr, " input record number %d", (int) (*FNR)); if (NR && *NR > 0) {
if (strcmp(*FILENAME, "-") != 0) fprintf(stderr, " input record number %d", (int) (*FNR));
fprintf(stderr, ", file %s", *FILENAME); if (strcmp(*FILENAME, "-") != 0)
fprintf(stderr, "\n"); 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); if (compile_time == COMPILING && cursource() != NULL)
else if (compile_time != 2 && lineno)
fprintf(stderr, " source line number %d", lineno);
if (compile_time == 1 && cursource() != NULL)
fprintf(stderr, " source file %s", cursource()); fprintf(stderr, " source file %s", cursource());
fprintf(stderr, "\n"); fprintf(stderr, "\n");
eprint(); eprint();
@ -663,7 +666,7 @@ void eprint(void) /* try to print context around error */
static int been_here = 0; static int been_here = 0;
extern char ebuf[], *ep; 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; return;
if (ebuf == ep) if (ebuf == ep)
return; return;

13
main.c
View File

@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE. THIS SOFTWARE.
****************************************************************/ ****************************************************************/
const char *version = "version 20191108"; const char *version = "version 20191110";
#define DEBUG #define DEBUG
#include <stdio.h> #include <stdio.h>
@ -43,8 +43,7 @@ char *cmdname; /* gets argv[0] for error messages */
extern FILE *yyin; /* lex input file */ extern FILE *yyin; /* lex input file */
char *lexprog; /* points to program argument if it exists */ char *lexprog; /* points to program argument if it exists */
extern int errorflag; /* non-zero if any syntax errors; set by yyerror */ extern int errorflag; /* non-zero if any syntax errors; set by yyerror */
int compile_time = 2; /* for error printing: */ enum compile_states compile_time = ERROR_PRINTING;
/* 2 = cmdline, 1 = compile, 0 = running */
#define MAX_PFILE 20 /* max number of -f's */ #define MAX_PFILE 20 /* max number of -f's */
@ -52,7 +51,7 @@ char *pfile[MAX_PFILE]; /* program filenames from -f's */
int npfile = 0; /* number of filenames */ int npfile = 0; /* number of filenames */
int curpfile = 0; /* current filename */ int curpfile = 0; /* current filename */
int safe = 0; /* 1 => "safe" mode */ bool safe = false; /* true => "safe" mode */
/* Can this work with recursive calls? I don't think so. /* Can this work with recursive calls? I don't think so.
void segvcatch(int n) void segvcatch(int n)
@ -96,7 +95,7 @@ int main(int argc, char *argv[])
switch (argv[1][1]) { switch (argv[1][1]) {
case 's': case 's':
if (strcmp(argv[1], "-safe") == 0) if (strcmp(argv[1], "-safe") == 0)
safe = 1; safe = true;
break; break;
case 'f': /* next argument is program filename */ case 'f': /* next argument is program filename */
if (argv[1][2] != 0) { /* arg is -fsomething */ if (argv[1][2] != 0) { /* arg is -fsomething */
@ -171,7 +170,7 @@ int main(int argc, char *argv[])
} }
recinit(recsize); recinit(recsize);
syminit(); syminit();
compile_time = 1; compile_time = COMPILING;
argv[0] = cmdname; /* put prog name at front of arglist */ argv[0] = cmdname; /* put prog name at front of arglist */
dprintf( ("argc=%d, argv[0]=%s\n", argc, argv[0]) ); dprintf( ("argc=%d, argv[0]=%s\n", argc, argv[0]) );
arginit(argc, argv); arginit(argc, argv);
@ -183,7 +182,7 @@ int main(int argc, char *argv[])
*FS = qstring(fs, '\0'); *FS = qstring(fs, '\0');
dprintf( ("errorflag=%d\n", errorflag) ); dprintf( ("errorflag=%d\n", errorflag) );
if (errorflag == 0) { if (errorflag == 0) {
compile_time = 0; compile_time = RUNNING;
run(winner); run(winner);
} else } else
bracecheck(); bracecheck();

10
proto.h
View File

@ -38,9 +38,9 @@ extern int yylook(void);
extern int yyback(int *, int); extern int yyback(int *, int);
extern int yyinput(void); extern int yyinput(void);
extern fa *makedfa(const char *, int); extern fa *makedfa(const char *, bool);
extern fa *mkdfa(const char *, int); extern fa *mkdfa(const char *, bool);
extern int makeinit(fa *, int); extern int makeinit(fa *, bool);
extern void penter(Node *); extern void penter(Node *);
extern void freetr(Node *); extern void freetr(Node *);
extern int hexstr(const uschar **); extern int hexstr(const uschar **);
@ -54,7 +54,7 @@ extern int member(int, const char *);
extern int match(fa *, const char *); extern int match(fa *, const char *);
extern int pmatch(fa *, const char *); extern int pmatch(fa *, const char *);
extern int nematch(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 *reparse(const char *);
extern Node *regexp(void); extern Node *regexp(void);
extern Node *primary(void); extern Node *primary(void);
@ -119,7 +119,7 @@ extern void initgetrec(void);
extern void makefields(int, int); extern void makefields(int, int);
extern void growfldtab(int n); extern void growfldtab(int n);
extern void savefs(void); extern void savefs(void);
extern int getrec(char **, int *, int); extern int getrec(char **, int *, bool);
extern void nextfile(void); extern void nextfile(void);
extern int readrec(char **buf, int *bufsize, FILE *inf); extern int readrec(char **buf, int *bufsize, FILE *inf);
extern char *getargv(int); extern char *getargv(int);

14
run.c
View File

@ -189,7 +189,7 @@ Cell *program(Node **a, int n) /* execute an awk program */
tempfree(x); tempfree(x);
} }
if (a[1] || a[2]) if (a[1] || a[2])
while (getrec(&record, &recsize, 1) > 0) { while (getrec(&record, &recsize, true) > 0) {
x = execute(a[1]); x = execute(a[1]);
if (isexit(x)) if (isexit(x))
break; break;
@ -438,9 +438,9 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */
} }
} else { /* bare getline; use current input */ } else { /* bare getline; use current input */
if (a[0] == NULL) /* getline */ if (a[0] == NULL) /* getline */
n = getrec(&record, &recsize, 1); n = getrec(&record, &recsize, true);
else { /* getline var */ else { /* getline var */
n = getrec(&buf, &bufsize, 0); n = getrec(&buf, &bufsize, false);
x = execute(a[0]); x = execute(a[0]);
setsval(x, buf); setsval(x, buf);
if (is_number(x->sval)) { if (is_number(x->sval)) {
@ -457,7 +457,7 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */
Cell *getnf(Node **a, int n) /* get NF */ Cell *getnf(Node **a, int n) /* get NF */
{ {
if (donefld == 0) if (!donefld)
fldbld(); fldbld();
return (Cell *) a[0]; return (Cell *) a[0];
} }
@ -821,15 +821,15 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co
#define FMTSZ(a) (fmtsz - ((a) - fmt)) #define FMTSZ(a) (fmtsz - ((a) - fmt))
#define BUFSZ(a) (bufsize - ((a) - buf)) #define BUFSZ(a) (bufsize - ((a) - buf))
static int first = 1; static bool first = true;
static int have_a_format = 0; static bool have_a_format = false;
if (first) { if (first) {
char buf[100]; char buf[100];
snprintf(buf, sizeof(buf), "%a", 42.0); snprintf(buf, sizeof(buf), "%a", 42.0);
have_a_format = (strcmp(buf, "0x1.5p+5") == 0); have_a_format = (strcmp(buf, "0x1.5p+5") == 0);
first = 0; first = false;
} }
os = s; os = s;

28
tran.c
View File

@ -306,21 +306,21 @@ Awkfloat setfval(Cell *vp, Awkfloat f) /* set float val of a Cell */
if ((vp->tval & (NUM | STR)) == 0) if ((vp->tval & (NUM | STR)) == 0)
funnyvar(vp, "assign to"); funnyvar(vp, "assign to");
if (isfld(vp)) { if (isfld(vp)) {
donerec = 0; /* mark $0 invalid */ donerec = false; /* mark $0 invalid */
fldno = atoi(vp->nval); fldno = atoi(vp->nval);
if (fldno > *NF) if (fldno > *NF)
newfld(fldno); newfld(fldno);
dprintf( ("setting field %d to %g\n", fldno, f) ); dprintf( ("setting field %d to %g\n", fldno, f) );
} else if (&vp->fval == NF) { } else if (&vp->fval == NF) {
donerec = 0; /* mark $0 invalid */ donerec = false; /* mark $0 invalid */
setlastfld(f); setlastfld(f);
dprintf( ("setting NF to %g\n", f) ); dprintf( ("setting NF to %g\n", f) );
} else if (isrec(vp)) { } else if (isrec(vp)) {
donefld = 0; /* mark $1... invalid */ donefld = false; /* mark $1... invalid */
donerec = 1; donerec = true;
savefs(); savefs();
} else if (vp == ofsloc) { } else if (vp == ofsloc) {
if (donerec == 0) if (!donerec)
recbld(); recbld();
} }
if (freeable(vp)) if (freeable(vp))
@ -355,17 +355,17 @@ char *setsval(Cell *vp, const char *s) /* set string val of a Cell */
if ((vp->tval & (NUM | STR)) == 0) if ((vp->tval & (NUM | STR)) == 0)
funnyvar(vp, "assign to"); funnyvar(vp, "assign to");
if (isfld(vp)) { if (isfld(vp)) {
donerec = 0; /* mark $0 invalid */ donerec = false; /* mark $0 invalid */
fldno = atoi(vp->nval); fldno = atoi(vp->nval);
if (fldno > *NF) if (fldno > *NF)
newfld(fldno); newfld(fldno);
dprintf( ("setting field %d to %s (%p)\n", fldno, s, s) ); dprintf( ("setting field %d to %s (%p)\n", fldno, s, s) );
} else if (isrec(vp)) { } else if (isrec(vp)) {
donefld = 0; /* mark $1... invalid */ donefld = false; /* mark $1... invalid */
donerec = 1; donerec = true;
savefs(); savefs();
} else if (vp == ofsloc) { } else if (vp == ofsloc) {
if (donerec == 0) if (!donerec)
recbld(); recbld();
} }
t = s ? tostring(s) : tostring(""); /* in case it's self-assign */ t = s ? tostring(s) : tostring(""); /* in case it's self-assign */
@ -379,7 +379,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) ); (void*)vp, NN(vp->nval), t, t, vp->tval, donerec, donefld) );
vp->sval = t; vp->sval = t;
if (&vp->fval == NF) { if (&vp->fval == NF) {
donerec = 0; /* mark $0 invalid */ donerec = false; /* mark $0 invalid */
f = getfval(vp); f = getfval(vp);
setlastfld(f); setlastfld(f);
dprintf( ("setting NF to %g\n", f) ); dprintf( ("setting NF to %g\n", f) );
@ -392,9 +392,9 @@ Awkfloat getfval(Cell *vp) /* get float val of a Cell */
{ {
if ((vp->tval & (NUM | STR)) == 0) if ((vp->tval & (NUM | STR)) == 0)
funnyvar(vp, "read value of"); funnyvar(vp, "read value of");
if (isfld(vp) && donefld == 0) if (isfld(vp) && !donefld)
fldbld(); fldbld();
else if (isrec(vp) && donerec == 0) else if (isrec(vp) && !donerec)
recbld(); recbld();
if (!isnum(vp)) { /* not a number */ if (!isnum(vp)) { /* not a number */
vp->fval = atof(vp->sval); /* best guess */ vp->fval = atof(vp->sval); /* best guess */
@ -413,9 +413,9 @@ static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cel
if ((vp->tval & (NUM | STR)) == 0) if ((vp->tval & (NUM | STR)) == 0)
funnyvar(vp, "read value of"); funnyvar(vp, "read value of");
if (isfld(vp) && donefld == 0) if (isfld(vp) && ! donefld)
fldbld(); fldbld();
else if (isrec(vp) && donerec == 0) else if (isrec(vp) && ! donerec)
recbld(); recbld();
/* /*