summaryrefslogtreecommitdiff
path: root/contrib/one-true-awk
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@FreeBSD.org>2011-08-09 12:54:43 +0000
committerRuslan Ermilov <ru@FreeBSD.org>2011-08-09 12:54:43 +0000
commitd86a0988d2ea55252f08da2dfc8db09d7f8aba1b (patch)
tree079bb7a8384dfb47f51838c84776481fb07cf770 /contrib/one-true-awk
parent477a63a86420b6d3f922cf248c0d3fd325c665bf (diff)
parent9cb3faa6600faf227157090f70a6ec850ac1ef75 (diff)
downloadsrc-test-d86a0988d2ea55252f08da2dfc8db09d7f8aba1b.tar.gz
src-test-d86a0988d2ea55252f08da2dfc8db09d7f8aba1b.zip
Update to a 7-Aug-2011 release.
Approved by: re (kib)
Notes
Notes: svn path=/head/; revision=224731
Diffstat (limited to 'contrib/one-true-awk')
-rw-r--r--contrib/one-true-awk/FIXES18
-rw-r--r--contrib/one-true-awk/awkgram.y4
-rw-r--r--contrib/one-true-awk/b.c14
-rw-r--r--contrib/one-true-awk/lex.c2
-rw-r--r--contrib/one-true-awk/lib.c9
-rw-r--r--contrib/one-true-awk/main.c20
-rw-r--r--contrib/one-true-awk/makefile2
-rw-r--r--contrib/one-true-awk/proto.h4
-rw-r--r--contrib/one-true-awk/run.c52
-rw-r--r--contrib/one-true-awk/tran.c16
10 files changed, 98 insertions, 43 deletions
diff --git a/contrib/one-true-awk/FIXES b/contrib/one-true-awk/FIXES
index e6edc5309cc1f..a802ad418783b 100644
--- a/contrib/one-true-awk/FIXES
+++ b/contrib/one-true-awk/FIXES
@@ -25,6 +25,24 @@ THIS SOFTWARE.
This file lists all bug fixes, changes, etc., made since the AWK book
was sent to the printers in August, 1987.
+Aug 7, 2011:
+ split(s, a, //) now behaves the same as split(s, a, "")
+
+Jun 12, 2011:
+ /pat/, \n /pat/ {...} is now legal, though bad style to use.
+
+ added checks to new -v code that permits -vnospace; thanks to
+ ruslan ermilov for spotting this and providing the patch.
+
+ removed fixed limit on number of open files; thanks to aleksey
+ cheusov and christos zoulos.
+
+ fixed day 1 bug that resurrected deleted elements of ARGV when
+ used as filenames (in lib.c).
+
+ minor type fiddles to make gcc -Wall -pedantic happier (but not
+ totally so); turned on -fno-strict-aliasing in makefile.
+
May 6, 2011:
added #ifdef for isblank.
now allows -ffoo as well as -f foo arguments.
diff --git a/contrib/one-true-awk/awkgram.y b/contrib/one-true-awk/awkgram.y
index 91b62571b8a93..5b5c461b3eedf 100644
--- a/contrib/one-true-awk/awkgram.y
+++ b/contrib/one-true-awk/awkgram.y
@@ -174,8 +174,8 @@ pa_pat:
pa_stat:
pa_pat { $$ = stat2(PASTAT, $1, stat2(PRINT, rectonode(), NIL)); }
| pa_pat lbrace stmtlist '}' { $$ = stat2(PASTAT, $1, $3); }
- | pa_pat ',' pa_pat { $$ = pa2stat($1, $3, stat2(PRINT, rectonode(), NIL)); }
- | pa_pat ',' pa_pat lbrace stmtlist '}' { $$ = pa2stat($1, $3, $5); }
+ | pa_pat ',' opt_nl pa_pat { $$ = pa2stat($1, $4, stat2(PRINT, rectonode(), NIL)); }
+ | pa_pat ',' opt_nl pa_pat lbrace stmtlist '}' { $$ = pa2stat($1, $4, $6); }
| lbrace stmtlist '}' { $$ = stat2(PASTAT, NIL, $2); }
| XBEGIN lbrace stmtlist '}'
{ beginloc = linkum(beginloc, $3); $$ = 0; }
diff --git a/contrib/one-true-awk/b.c b/contrib/one-true-awk/b.c
index c05e0f3586324..4479935219759 100644
--- a/contrib/one-true-awk/b.c
+++ b/contrib/one-true-awk/b.c
@@ -234,7 +234,7 @@ void freetr(Node *p) /* free parse tree */
/* in the parsing of regular expressions, metacharacters like . have */
/* to be seen literally; \056 is not a metacharacter. */
-int hexstr(char **pp) /* find and eval hex string at pp, return new p */
+int hexstr(uschar **pp) /* find and eval hex string at pp, return new p */
{ /* only pick up one 8-bit byte (2 chars) */
uschar *p;
int n = 0;
@@ -248,16 +248,16 @@ int hexstr(char **pp) /* find and eval hex string at pp, return new p */
else if (*p >= 'A' && *p <= 'F')
n = 16 * n + *p - 'A' + 10;
}
- *pp = (char *) p;
+ *pp = (uschar *) p;
return n;
}
#define isoctdigit(c) ((c) >= '0' && (c) <= '7') /* multiple use of arg */
-int quoted(char **pp) /* pick up next thing after a \\ */
+int quoted(uschar **pp) /* pick up next thing after a \\ */
/* and increment *pp */
{
- char *p = *pp;
+ uschar *p = *pp;
int c;
if ((c = *p++) == 't')
@@ -314,13 +314,13 @@ char *cclenter(const char *argp) /* add a character class */
bp = buf;
for (i = 0; (c = *p++) != 0; ) {
if (c == '\\') {
- c = quoted((char **) &p);
+ c = quoted(&p);
} else if (c == '-' && i > 0 && bp[-1] != 0) {
if (*p != 0) {
c = bp[-1];
c2 = *p++;
if (c2 == '\\')
- c2 = quoted((char **) &p);
+ c2 = quoted(&p);
if (collate_range_cmp(c, c2) > 0) {
bp--;
i--;
@@ -807,7 +807,7 @@ int relex(void) /* lexical analyzer for reparse */
case ')':
return c;
case '\\':
- rlxval = quoted((char **) &prestr);
+ rlxval = quoted(&prestr);
return CHAR;
default:
rlxval = c;
diff --git a/contrib/one-true-awk/lex.c b/contrib/one-true-awk/lex.c
index 49d7c5ca74e82..d09f5507e3d2a 100644
--- a/contrib/one-true-awk/lex.c
+++ b/contrib/one-true-awk/lex.c
@@ -411,7 +411,7 @@ int string(void)
}
*px = 0;
unput(c);
- sscanf(xbuf, "%x", &n);
+ sscanf(xbuf, "%x", (unsigned int *) &n);
*bp++ = n;
break;
}
diff --git a/contrib/one-true-awk/lib.c b/contrib/one-true-awk/lib.c
index d7eee31db43f4..5da601aa8e7ed 100644
--- a/contrib/one-true-awk/lib.c
+++ b/contrib/one-true-awk/lib.c
@@ -124,7 +124,7 @@ int getrec(char **pbuf, int *pbufsize, int isrecord) /* get next input record */
dprintf( ("argno=%d, file=|%s|\n", argno, file) );
if (infile == NULL) { /* have to open a new file */
file = getargv(argno);
- if (*file == '\0') { /* it's been zapped */
+ if (file == NULL || *file == '\0') { /* deleted or zapped */
argno++;
continue;
}
@@ -187,6 +187,7 @@ int readrec(char **pbuf, int *pbufsize, FILE *inf) /* read one record into buf *
if (strlen(*FS) >= sizeof(inputFS))
FATAL("field separator %.10s... is too long", *FS);
+ /*fflush(stdout); avoids some buffering problem but makes it 25% slower*/
strcpy(inputFS, *FS); /* for subsequent field splitting */
if ((sep = **RS) == 0) {
sep = '\n';
@@ -227,6 +228,8 @@ char *getargv(int n) /* get ARGV[n] */
extern Array *ARGVtab;
sprintf(temp, "%d", n);
+ if (lookup(temp, ARGVtab) == NULL)
+ return NULL;
x = setsymtab(temp, "", 0.0, STR, ARGVtab);
s = getsval(x);
dprintf( ("getargv(%d) returns |%s|\n", n, s) );
@@ -477,14 +480,14 @@ void recbld(void) /* create $0 from $1..$NF if necessary */
if (!adjbuf(&record, &recsize, 2+r-record, recsize, &r, "recbld 3"))
FATAL("built giant record `%.30s...'", record);
*r = '\0';
- dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, fldtab[0]) );
+ dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, (void*)fldtab[0]) );
if (freeable(fldtab[0]))
xfree(fldtab[0]->sval);
fldtab[0]->tval = REC | STR | DONTFREE;
fldtab[0]->sval = record;
- dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, fldtab[0]) );
+ dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, (void*)fldtab[0]) );
dprintf( ("recbld = |%s|\n", record) );
donerec = 1;
}
diff --git a/contrib/one-true-awk/main.c b/contrib/one-true-awk/main.c
index b40a39d3e7887..61063b13c9c4d 100644
--- a/contrib/one-true-awk/main.c
+++ b/contrib/one-true-awk/main.c
@@ -25,7 +25,7 @@ THIS SOFTWARE.
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-const char *version = "version 20110506 (FreeBSD)";
+const char *version = "version 20110807 (FreeBSD)";
#define DEBUG
#include <stdio.h>
@@ -125,10 +125,20 @@ int main(int argc, char *argv[])
WARNING("field separator FS is empty");
break;
case 'v': /* -v a=1 to be done NOW. one -v for each */
- if (argv[1][2] == '\0' && --argc > 1 && isclvar((++argv)[1]))
- setclvar(argv[1]);
- else if (argv[1][2] != '\0')
- setclvar(&argv[1][2]);
+ if (argv[1][2] != 0) { /* arg is -vsomething */
+ if (isclvar(&argv[1][2]))
+ setclvar(&argv[1][2]);
+ else
+ FATAL("invalid -v option argument: %s", &argv[1][2]);
+ } else { /* arg is -v something */
+ argc--; argv++;
+ if (argc <= 1)
+ FATAL("no variable name");
+ if (isclvar(argv[1]))
+ setclvar(argv[1]);
+ else
+ FATAL("invalid -v option argument: %s", argv[1]);
+ }
break;
case 'd':
dbg = atoi(&argv[1][2]);
diff --git a/contrib/one-true-awk/makefile b/contrib/one-true-awk/makefile
index f93f0a8bdb875..52c7424b34c17 100644
--- a/contrib/one-true-awk/makefile
+++ b/contrib/one-true-awk/makefile
@@ -30,7 +30,7 @@ CC = gcc -Wall -g
CC = cc
CC = gcc -Wall -g -Wwrite-strings
CC = gcc -fprofile-arcs -ftest-coverage # then gcov f1.c; cat f1.c.gcov
-CC = gcc -O4
+CC = gcc -O4 -Wall -pedantic -fno-strict-aliasing
YACC = bison -y
YACC = yacc
diff --git a/contrib/one-true-awk/proto.h b/contrib/one-true-awk/proto.h
index 0a68b3a813f8a..e4de112723f49 100644
--- a/contrib/one-true-awk/proto.h
+++ b/contrib/one-true-awk/proto.h
@@ -43,8 +43,8 @@ extern fa *mkdfa(const char *, int);
extern int makeinit(fa *, int);
extern void penter(Node *);
extern void freetr(Node *);
-extern int hexstr(char **);
-extern int quoted(char **);
+extern int hexstr(uschar **);
+extern int quoted(uschar **);
extern char *cclenter(const char *);
extern void overflo(const char *);
extern void cfoll(fa *, Node *);
diff --git a/contrib/one-true-awk/run.c b/contrib/one-true-awk/run.c
index 82c29ceabaf80..942f25013a74b 100644
--- a/contrib/one-true-awk/run.c
+++ b/contrib/one-true-awk/run.c
@@ -1239,6 +1239,12 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
ap->sval = (char *) makesymtab(NSYMTAB);
n = 0;
+ if (arg3type == REGEXPR && strlen((char*)((fa*)a[2])->restr) == 0) {
+ /* split(s, a, //); have to arrange that it looks like empty sep */
+ arg3type = 0;
+ fs = "";
+ sep = 0;
+ }
if (*s != '\0' && (strlen(fs) > 1 || arg3type == REGEXPR)) { /* reg expr */
fa *pfa;
if (arg3type == REGEXPR) { /* it's ready already */
@@ -1621,17 +1627,25 @@ struct files {
FILE *fp;
const char *fname;
int mode; /* '|', 'a', 'w' => LE/LT, GT */
-} files[FOPEN_MAX] ={
- { NULL, "/dev/stdin", LT }, /* watch out: don't free this! */
- { NULL, "/dev/stdout", GT },
- { NULL, "/dev/stderr", GT }
-};
+} *files;
+
+int nfiles;
void stdinit(void) /* in case stdin, etc., are not constants */
{
- files[0].fp = stdin;
- files[1].fp = stdout;
- files[2].fp = stderr;
+ nfiles = FOPEN_MAX;
+ files = calloc(nfiles, sizeof(*files));
+ if (files == NULL)
+ FATAL("can't allocate file memory for %u files", nfiles);
+ files[0].fp = stdin;
+ files[0].fname = "/dev/stdin";
+ files[0].mode = LT;
+ files[1].fp = stdout;
+ files[1].fname = "/dev/stdout";
+ files[1].mode = GT;
+ files[2].fp = stderr;
+ files[2].fname = "/dev/stderr";
+ files[2].mode = GT;
}
FILE *openfile(int a, const char *us)
@@ -1642,7 +1656,7 @@ FILE *openfile(int a, const char *us)
if (*s == '\0')
FATAL("null file name in print or getline");
- for (i=0; i < FOPEN_MAX; i++)
+ 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;
@@ -1652,11 +1666,19 @@ FILE *openfile(int a, const char *us)
if (a == FFLUSH) /* didn't find it, so don't create it! */
return NULL;
- for (i=0; i < FOPEN_MAX; i++)
+ for (i=0; i < nfiles; i++)
if (files[i].fp == 0)
break;
- if (i >= FOPEN_MAX)
- FATAL("%s makes too many open files", s);
+ if (i >= nfiles) {
+ struct files *nf;
+ int nnf = nfiles + FOPEN_MAX;
+ nf = realloc(files, nnf * sizeof(*nf));
+ if (nf == NULL)
+ FATAL("cannot grow files for %s and %d files", s, nnf);
+ memset(&nf[nfiles], 0, FOPEN_MAX * sizeof(*nf));
+ nfiles = nnf;
+ files = nf;
+ }
fflush(stdout); /* force a semblance of order */
m = a;
if (a == GT) {
@@ -1684,7 +1706,7 @@ const char *filename(FILE *fp)
{
int i;
- for (i = 0; i < FOPEN_MAX; i++)
+ for (i = 0; i < nfiles; i++)
if (fp == files[i].fp)
return files[i].fname;
return "???";
@@ -1699,7 +1721,7 @@ Cell *closefile(Node **a, int n)
x = execute(a[0]);
getsval(x);
stat = -1;
- for (i = 0; i < FOPEN_MAX; i++) {
+ for (i = 0; i < nfiles; i++) {
if (files[i].fname && strcmp(x->sval, files[i].fname) == 0) {
if (ferror(files[i].fp))
WARNING( "i/o error occurred on %s", files[i].fname );
@@ -1743,7 +1765,7 @@ void flush_all(void)
{
int i;
- for (i = 0; i < FOPEN_MAX; i++)
+ for (i = 0; i < nfiles; i++)
if (files[i].fp)
fflush(files[i].fp);
}
diff --git a/contrib/one-true-awk/tran.c b/contrib/one-true-awk/tran.c
index c19ce94302a2f..e9d77506a34d9 100644
--- a/contrib/one-true-awk/tran.c
+++ b/contrib/one-true-awk/tran.c
@@ -212,7 +212,7 @@ Cell *setsymtab(const char *n, const char *s, Awkfloat f, unsigned t, Array *tp)
if (n != NULL && (p = lookup(n, tp)) != NULL) {
dprintf( ("setsymtab found %p: n=%s s=\"%s\" f=%g t=%o\n",
- p, NN(p->nval), NN(p->sval), p->fval, p->tval) );
+ (void*)p, NN(p->nval), NN(p->sval), p->fval, p->tval) );
return(p);
}
p = (Cell *) malloc(sizeof(Cell));
@@ -231,7 +231,7 @@ Cell *setsymtab(const char *n, const char *s, Awkfloat f, unsigned t, Array *tp)
p->cnext = tp->tab[h];
tp->tab[h] = p;
dprintf( ("setsymtab set %p: n=%s s=\"%s\" f=%g t=%o\n",
- p, p->nval, p->sval, p->fval, p->tval) );
+ (void*)p, p->nval, p->sval, p->fval, p->tval) );
return(p);
}
@@ -298,7 +298,7 @@ Awkfloat setfval(Cell *vp, Awkfloat f) /* set float val of a Cell */
xfree(vp->sval); /* free any previous string */
vp->tval &= ~STR; /* mark string invalid */
vp->tval |= NUM; /* mark number ok */
- dprintf( ("setfval %p: %s = %g, t=%o\n", vp, NN(vp->nval), f, vp->tval) );
+ dprintf( ("setfval %p: %s = %g, t=%o\n", (void*)vp, NN(vp->nval), f, vp->tval) );
return vp->fval = f;
}
@@ -318,7 +318,7 @@ char *setsval(Cell *vp, const char *s) /* set string val of a Cell */
int fldno;
dprintf( ("starting setsval %p: %s = \"%s\", t=%o, r,f=%d,%d\n",
- vp, NN(vp->nval), s, vp->tval, donerec, donefld) );
+ (void*)vp, NN(vp->nval), s, vp->tval, donerec, donefld) );
if ((vp->tval & (NUM | STR)) == 0)
funnyvar(vp, "assign to");
if (isfld(vp)) {
@@ -338,7 +338,7 @@ char *setsval(Cell *vp, const char *s) /* set string val of a Cell */
vp->tval |= STR;
vp->tval &= ~DONTFREE;
dprintf( ("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n",
- vp, NN(vp->nval), t,t, vp->tval, donerec, donefld) );
+ (void*)vp, NN(vp->nval), t,t, vp->tval, donerec, donefld) );
return(vp->sval = t);
}
@@ -355,7 +355,8 @@ Awkfloat getfval(Cell *vp) /* get float val of a Cell */
if (is_number(vp->sval) && !(vp->tval&CON))
vp->tval |= NUM; /* make NUM only sparingly */
}
- dprintf( ("getfval %p: %s = %g, t=%o\n", vp, NN(vp->nval), vp->fval, vp->tval) );
+ dprintf( ("getfval %p: %s = %g, t=%o\n",
+ (void*)vp, NN(vp->nval), vp->fval, vp->tval) );
return(vp->fval);
}
@@ -381,7 +382,8 @@ static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cel
vp->tval &= ~DONTFREE;
vp->tval |= STR;
}
- dprintf( ("getsval %p: %s = \"%s (%p)\", t=%o\n", vp, NN(vp->nval), vp->sval, vp->sval, vp->tval) );
+ dprintf( ("getsval %p: %s = \"%s (%p)\", t=%o\n",
+ (void*)vp, NN(vp->nval), vp->sval, vp->sval, vp->tval) );
return(vp->sval);
}