Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/historical/nawk/dist Fix failing unittests (by rest...



details:   https://anonhg.NetBSD.org/src/rev/30f991b73d0f
branches:  trunk
changeset: 745010:30f991b73d0f
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Feb 20 19:59:12 2020 +0000

description:
Fix failing unittests (by restoring old changes).

diffstat:

 external/historical/nawk/dist/lex.c   |   1 +
 external/historical/nawk/dist/lib.c   |  17 ++++++++++++++---
 external/historical/nawk/dist/main.c  |   2 ++
 external/historical/nawk/dist/proto.h |   4 ++--
 external/historical/nawk/dist/run.c   |  24 ++++++++++++++----------
 5 files changed, 33 insertions(+), 15 deletions(-)

diffs (180 lines):

diff -r ff6fbeb06705 -r 30f991b73d0f external/historical/nawk/dist/lex.c
--- a/external/historical/nawk/dist/lex.c       Thu Feb 20 18:24:20 2020 +0000
+++ b/external/historical/nawk/dist/lex.c       Thu Feb 20 19:59:12 2020 +0000
@@ -401,6 +401,7 @@
                case '\\':
                        c = input();
                        switch (c) {
+                       case '\n': break;
                        case '"': *bp++ = '"'; break;
                        case 'n': *bp++ = '\n'; break;
                        case 't': *bp++ = '\t'; break;
diff -r ff6fbeb06705 -r 30f991b73d0f external/historical/nawk/dist/lib.c
--- a/external/historical/nawk/dist/lib.c       Thu Feb 20 18:24:20 2020 +0000
+++ b/external/historical/nawk/dist/lib.c       Thu Feb 20 19:59:12 2020 +0000
@@ -39,6 +39,7 @@
 
 char   EMPTY[] = { '\0' };
 FILE   *infile = NULL;
+bool   innew;          /* true = infile has not been read by readrec */
 char   *file   = EMPTY;
 char   *record;
 int    recsize = RECSIZE;
@@ -110,6 +111,7 @@
                argno++;
        }
        infile = stdin;         /* no filenames, so use stdin */
+       innew = true;
 }
 
 /*
@@ -179,7 +181,9 @@
                                FATAL("can't open file %s", file);
                        setfval(fnrloc, 0.0);
                }
-               c = readrec(&buf, &bufsize, infile);
+               c = readrec(&buf, &bufsize, infile, innew);
+               if (innew)
+                       innew = false;
                if (c != 0 || buf[0] != '\0') { /* normal record */
                        if (isrecord) {
                                if (freeable(fldtab[0]))
@@ -217,7 +221,7 @@
        argno++;
 }
 
-int readrec(char **pbuf, int *pbufsize, FILE *inf)     /* read one record into buf */
+int readrec(char **pbuf, int *pbufsize, FILE *inf, bool newflag)       /* read one record into buf */
 {
        int sep, c, isrec;
        char *rr, *buf = *pbuf;
@@ -228,7 +232,14 @@
                bool found;
 
                fa *pfa = makedfa(rs, 1);
-               found = fnematch(pfa, inf, &buf, &bufsize, recsize);
+               if (newflag)
+                       found = fnematch(pfa, inf, &buf, &bufsize, recsize);
+               else {
+                       int tempstat = pfa->initstat;
+                       pfa->initstat = 2;
+                       found = fnematch(pfa, inf, &buf, &bufsize, recsize);
+                       pfa->initstat = tempstat;
+               }
                if (found)
                        setptr(patbeg, '\0');
        } else {
diff -r ff6fbeb06705 -r 30f991b73d0f external/historical/nawk/dist/main.c
--- a/external/historical/nawk/dist/main.c      Thu Feb 20 18:24:20 2020 +0000
+++ b/external/historical/nawk/dist/main.c      Thu Feb 20 19:59:12 2020 +0000
@@ -218,7 +218,9 @@
        if (!safe)
                envinit(environ);
        yyparse();
+#if 0
        setlocale(LC_NUMERIC, ""); /* back to whatever it is locally */
+#endif
        if (fs)
                *FS = qstring(fs, '\0');
           dprintf( ("errorflag=%d\n", errorflag) );
diff -r ff6fbeb06705 -r 30f991b73d0f external/historical/nawk/dist/proto.h
--- a/external/historical/nawk/dist/proto.h     Thu Feb 20 18:24:20 2020 +0000
+++ b/external/historical/nawk/dist/proto.h     Thu Feb 20 19:59:12 2020 +0000
@@ -124,7 +124,7 @@
 extern void    savefs(void);
 extern int     getrec(char **, int *, bool);
 extern void    nextfile(void);
-extern int     readrec(char **, int *, FILE *);
+extern int     readrec(char **, int *, FILE *, bool);
 extern char    *getargv(int);
 extern void    setclvar(char *);
 extern void    fldbld(void);
@@ -193,7 +193,7 @@
 extern Cell    *printstat(Node **, int);
 extern Cell    *nullproc(Node **, int);
 extern FILE    *redirect(int, Node *);
-extern FILE    *openfile(int, const char *);
+extern FILE    *openfile(int, const char *, bool *);
 extern const char      *filename(FILE *);
 extern Cell    *closefile(Node **, int);
 extern void    closeall(void);
diff -r ff6fbeb06705 -r 30f991b73d0f external/historical/nawk/dist/run.c
--- a/external/historical/nawk/dist/run.c       Thu Feb 20 18:24:20 2020 +0000
+++ b/external/historical/nawk/dist/run.c       Thu Feb 20 19:59:12 2020 +0000
@@ -409,6 +409,7 @@
        char *buf;
        int bufsize = recsize;
        int mode;
+       bool newflag;
 
        if ((buf = malloc(bufsize)) == NULL)
                FATAL("out of memory in getline");
@@ -420,12 +421,12 @@
                mode = ptoi(a[1]);
                if (mode == '|')                /* input pipe */
                        mode = LE;      /* arbitrary flag */
-               fp = openfile(mode, getsval(x));
+               fp = openfile(mode, getsval(x), &newflag);
                tempfree(x);
                if (fp == NULL)
                        n = -1;
                else
-                       n = readrec(&buf, &bufsize, fp);
+                       n = readrec(&buf, &bufsize, fp, newflag);
                if (n <= 0) {
                        ;
                } else if (a[0] != NULL) {      /* getline var <file */
@@ -1722,7 +1723,7 @@
                if (isrec(x) || strlen(getsval(x)) == 0) {
                        flush_all();    /* fflush() or fflush("") -> all */
                        u = 0;
-               } else if ((fp = openfile(FFLUSH, getsval(x))) == NULL)
+               } else if ((fp = openfile(FFLUSH, getsval(x), NULL)) == NULL)
                        u = EOF;
                else
                        u = fflush(fp);
@@ -1817,7 +1818,7 @@
 
        x = execute(b);
        fname = getsval(x);
-       fp = openfile(a, fname);
+       fp = openfile(a, fname, NULL);
        if (fp == NULL)
                FATAL("can't open file %s", fname);
        tempfree(x);
@@ -1849,7 +1850,7 @@
        files[2].mode = GT;
 }
 
-FILE *openfile(int a, const char *us)
+FILE *openfile(int a, const char *us, bool *pnewflag)
 {
        const char *s = us;
        size_t i;
@@ -1859,11 +1860,12 @@
        if (*s == '\0')
                FATAL("null file name in print or getline");
        for (i = 0; i < nfiles; i++)
-               if (files[i].fname && strcmp(s, files[i].fname) == 0) {
-                       if (a == files[i].mode || (a==APPEND && files[i].mode==GT))
-                               return files[i].fp;
-                       if (a == FFLUSH)
-                               return files[i].fp;
+               if (files[i].fname && strcmp(s, files[i].fname) == 0 &&
+                   (a == files[i].mode || (a==APPEND && files[i].mode==GT) ||
+                    a == FFLUSH)) {
+                       if (pnewflag)
+                               *pnewflag = false;
+                       return files[i].fp;
                }
        if (a == FFLUSH)        /* didn't find it, so don't create it! */
                return NULL;
@@ -1900,6 +1902,8 @@
                files[i].fname = tostring(s);
                files[i].fp = fp;
                files[i].mode = m;
+               if (pnewflag)
+                       *pnewflag = true;
                if (fp != stdin && fp != stdout && fp != stderr)
                        (void) fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
        }



Home | Main Index | Thread Index | Old Index