summaryrefslogtreecommitdiffstats
path: root/contrib/one-true-awk/run.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2002-02-19 09:35:25 +0000
committerdes <des@FreeBSD.org>2002-02-19 09:35:25 +0000
commit15169bd09781aa4d3f09d050d40b381b29c965a4 (patch)
tree24b656463efaffbd4264824c36a5e66e8ada0979 /contrib/one-true-awk/run.c
parent4faba9a77fb780a1126a1292d4b156a42537db50 (diff)
downloadFreeBSD-src-15169bd09781aa4d3f09d050d40b381b29c965a4.zip
FreeBSD-src-15169bd09781aa4d3f09d050d40b381b29c965a4.tar.gz
Vendor import of bwk's 2002-02-18 release. Most significant update is the
inclusion of my character class patch.
Diffstat (limited to 'contrib/one-true-awk/run.c')
-rw-r--r--contrib/one-true-awk/run.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/contrib/one-true-awk/run.c b/contrib/one-true-awk/run.c
index 2d71766..2f60a37 100644
--- a/contrib/one-true-awk/run.c
+++ b/contrib/one-true-awk/run.c
@@ -1448,13 +1448,18 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
char *p, *buf;
Node *nextarg;
FILE *fp;
+ void flush_all(void);
t = ptoi(a[0]);
x = execute(a[1]);
nextarg = a[1]->nnext;
switch (t) {
case FLENGTH:
- u = strlen(getsval(x)); break;
+ if (isarr(x))
+ u = ((Array *) x->sval)->nelem; /* GROT. should be function*/
+ else
+ u = strlen(getsval(x));
+ break;
case FLOG:
u = errcheck(log(getfval(x)), "log"); break;
case FINT:
@@ -1511,7 +1516,10 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
free(buf);
return x;
case FFLUSH:
- if ((fp = openfile(FFLUSH, getsval(x))) == NULL)
+ if (isrec(x) || strlen(getsval(x)) == 0) {
+ flush_all(); /* fflush() or fflush("") -> all */
+ u = 0;
+ } else if ((fp = openfile(FFLUSH, getsval(x))) == NULL)
u = EOF;
else
u = fflush(fp);
@@ -1702,6 +1710,15 @@ void closeall(void)
}
}
+void flush_all(void)
+{
+ int i;
+
+ for (i = 0; i < FOPEN_MAX; i++)
+ if (files[i].fp)
+ fflush(files[i].fp);
+}
+
void backsub(char **pb_ptr, char **sptr_ptr);
Cell *sub(Node **a, int nnn) /* substitute command */
OpenPOWER on IntegriCloud