diff options
author | zoulasc <zoulasc@users.noreply.github.com> | 2020-02-28 06:23:54 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 13:23:54 +0200 |
commit | ffee7780fe08fa77f662a0903477545d9e26334f (patch) | |
tree | bdeafcbb782b3892f53cad636082292f1aae773a /run.c | |
parent | 91eaf7f7015ba2223e993532f5d65dfda4d1f33f (diff) | |
download | one-true-awk-ffee7780fe08fa77f662a0903477545d9e26334f.tar.gz |
3 more fixes (#75)
* LC_NUMERIC radix issue.
According to https://pubs.opengroup.org/onlinepubs/7990989775/xcu/awk.html
The period character is the character recognized in processing awk
programs. Make it so that during output we also print the period
character, since this is what other awk implementations do, and it
makes sense from an interoperability point of view.
* print "T.builtin" in the error message
* Fix backslash continuation line handling.
* Keep track of RS processing so we apply the regex properly only once
per record.
Diffstat (limited to 'run.c')
-rw-r--r-- | run.c | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -405,6 +405,7 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */ char *buf; int bufsize = recsize; int mode; + bool newflag; if ((buf = malloc(bufsize)) == NULL) FATAL("out of memory in getline"); @@ -416,12 +417,12 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */ 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 */ @@ -1658,7 +1659,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis 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); @@ -1718,7 +1719,7 @@ FILE *redirect(int a, Node *b) /* set up all i/o redirections */ 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); @@ -1750,7 +1751,7 @@ static void stdinit(void) /* in case stdin, etc., are not constants */ 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; @@ -1760,11 +1761,12 @@ FILE *openfile(int a, const char *us) 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; @@ -1801,6 +1803,8 @@ FILE *openfile(int a, const char *us) 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); } |