=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/awk/run.c,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- src/usr.bin/awk/run.c 2020/06/10 20:59:06 1.46 +++ src/usr.bin/awk/run.c 2020/06/10 21:00:01 1.47 @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.46 2020/06/10 20:59:06 millert Exp $ */ +/* $OpenBSD: run.c,v 1.47 2020/06/10 21:00:01 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include "awk.h" #include "ytab.h" @@ -326,14 +328,18 @@ { Cell *y; + /* copy is not constant or field */ + y = gettemp(); + y->tval = x->tval & ~(CON|FLD|REC); y->csub = CCOPY; /* prevents freeing until call is over */ y->nval = x->nval; /* BUG? */ - if (isstr(x)) + if (isstr(x) /* || x->ctype == OCELL */) { y->sval = tostring(x->sval); + y->tval &= ~DONTFREE; + } else + y->tval |= DONTFREE; y->fval = x->fval; - y->tval = x->tval & ~(CON|FLD|REC|DONTFREE); /* copy is not constant or field */ - /* is DONTFREE right? */ return y; } @@ -820,6 +826,17 @@ char *buf = *pbuf; int bufsize = *pbufsize; + static int first = 1; + static int have_a_format = 0; + + if (first) { + char buf[100]; + + snprintf(buf, sizeof(buf), "%a", 42.0); + have_a_format = (strcmp(buf, "0x1.5p+5") == 0); + first = 0; + } + os = s; p = buf; if ((fmt = (char *) malloc(fmtsz)) == NULL) @@ -864,6 +881,12 @@ adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format4"); switch (*s) { + case 'a': case 'A': + if (have_a_format) + flag = *s; + else + flag = 'f'; + break; case 'f': case 'e': case 'g': case 'E': case 'G': flag = 'f'; break; @@ -907,6 +930,8 @@ p += strlen(p); snprintf(p, buf + bufsize - p, "%s", t); break; + case 'a': + case 'A': case 'f': snprintf(p, buf + bufsize - p, fmt, getfval(x)); break; case 'd': snprintf(p, buf + bufsize - p, fmt, (long) getfval(x)); break; case 'u': snprintf(p, buf + bufsize - p, fmt, (int) getfval(x)); break; @@ -1009,7 +1034,7 @@ x = execute(a[0]); i = getfval(x); tempfree(x); - if (n != UMINUS) { + if (n != UMINUS && n != UPLUS) { y = execute(a[1]); j = getfval(y); tempfree(y); @@ -1039,6 +1064,8 @@ case UMINUS: i = -i; break; + case UPLUS: /* handled by getfval(), above */ + break; case POWER: if (j >= 0 && modf(j, &v) == 0.0) /* pos integer exponent */ i = ipow(i, (int) j); @@ -1492,6 +1519,7 @@ char *p, *buf; Node *nextarg; FILE *fp; + int status = 0; t = ptoi(a[0]); x = execute(a[1]); @@ -1589,7 +1617,20 @@ break; case FSYSTEM: fflush(stdout); /* in case something is buffered already */ - u = (Awkfloat) system(getsval(x)) / 256; /* 256 is unix-dep */ + status = system(getsval(x)); + u = status; + if (status != -1) { + if (WIFEXITED(status)) { + u = WEXITSTATUS(status); + } else if (WIFSIGNALED(status)) { + u = WTERMSIG(status) + 256; +#ifdef WCOREDUMP + if (WCOREDUMP(status)) + u += 256; +#endif + } else /* something else?!? */ + u = 0; + } break; case FRAND: u = (Awkfloat) (random() & RAND_MAX) / ((u_int)RAND_MAX + 1);