Vendor import of bwk's 1-May-2011 release.

This commit is contained in:
Ruslan Ermilov 2011-05-03 11:37:03 +00:00
parent d9859a0e4b
commit bd726c262e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/one-true-awk/dist/; revision=221379
svn path=/vendor/one-true-awk/20110501/; revision=221380; tag=vendor/one-true-awk/20110501
7 changed files with 54 additions and 15 deletions

26
FIXES
View File

@ -25,6 +25,32 @@ THIS SOFTWARE.
This file lists all bug fixes, changes, etc., made since the AWK book
was sent to the printers in August, 1987.
May 1, 2011:
after advice from todd miller, kevin lo, ruslan ermilov,
and arnold robbins, changed srand() to return the previous
seed (which is 1 on the first call of srand). the seed is
an Awkfloat internally though converted to unsigned int to
pass to the library srand(). thanks, everyone.
fixed a subtle (and i hope low-probability) overflow error
in fldbld, by adding space for one extra \0. thanks to
robert bassett for spotting this one and providing a fix.
removed the files related to compilation on windows. i no
longer have anything like a current windows environment, so
i can't test any of it.
May 23, 2010:
fixed long-standing overflow bug in run.c; many thanks to
nelson beebe for spotting it and providing the fix.
fixed bug that didn't parse -vd=1 properly; thanks to santiago
vila for spotting it.
Feb 8, 2010:
i give up. replaced isblank with isspace in b.c; there are
no consistent header files.
Nov 26, 2009:
fixed a long-standing issue with when FS takes effect. a
change to FS is now noticed immediately for subsequent splits.

2
README
View File

@ -29,7 +29,7 @@ by Al Aho, Brian Kernighan, and Peter Weinberger
Changes, mostly bug fixes and occasional enhancements, are listed
in FIXES. If you distribute this code further, please please please
distribute FIXES with it. If you find errors, please report them
to bwk@bell-labs.com. Thanks.
to bwk@cs.princeton.edu. Thanks.
The program itself is created by
make

4
b.c
View File

@ -734,7 +734,7 @@ Node *unary(Node *np)
/* #define HAS_ISBLANK */
#ifndef HAS_ISBLANK
int (isblank)(int c)
int (xisblank)(int c)
{
return c==' ' || c=='\t';
}
@ -748,7 +748,7 @@ struct charclass {
} charclasses[] = {
{ "alnum", 5, isalnum },
{ "alpha", 5, isalpha },
{ "blank", 5, isblank },
{ "blank", 5, isspace }, /* was isblank */
{ "cntrl", 5, iscntrl },
{ "digit", 5, isdigit },
{ "graph", 5, isgraph },

3
lib.c
View File

@ -256,6 +256,7 @@ void fldbld(void) /* create fields from current record */
{
/* this relies on having fields[] the same length as $0 */
/* the fields are all stored in this one array with \0's */
/* possibly with a final trailing \0 not associated with any field */
char *r, *fr, sep;
Cell *p;
int i, j, n;
@ -268,7 +269,7 @@ void fldbld(void) /* create fields from current record */
n = strlen(r);
if (n > fieldssize) {
xfree(fields);
if ((fields = (char *) malloc(n+1)) == NULL)
if ((fields = (char *) malloc(n+2)) == NULL) /* possibly 2 final \0s */
FATAL("out of space for fields in fldbld %d", n);
fieldssize = n;
}

9
main.c
View File

@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
****************************************************************/
const char *version = "version 20091126";
const char *version = "version 20110501";
#define DEBUG
#include <stdio.h>
@ -38,6 +38,7 @@ extern char **environ;
extern int nfields;
int dbg = 0;
Awkfloat srand_seed = 1;
char *cmdname; /* gets argv[0] for error messages */
extern FILE *yyin; /* lex input file */
char *lexprog; /* points to program argument if it exists */
@ -67,6 +68,10 @@ int main(int argc, char *argv[])
exit(1);
}
signal(SIGFPE, fpecatch);
srand_seed = 1;
srand(srand_seed);
yyin = NULL;
symtab = makesymtab(NSYMTAB/NSYMTAB);
while (argc > 1 && argv[1][0] == '-' && argv[1][1] != '\0') {
@ -113,6 +118,8 @@ int main(int argc, char *argv[])
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]);
break;
case 'd':
dbg = atoi(&argv[1][2]);

View File

@ -26,13 +26,12 @@ CFLAGS = -g
CFLAGS = -O2
CFLAGS =
CC = gcc -Wall -g -Wwrite-strings
CC = gcc -fprofile-arcs -ftest-coverage # then gcov f1.c; cat f1.c.gcov
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
YACC = bison -y
YACC = yacc
YFLAGS = -d
@ -40,13 +39,13 @@ YFLAGS = -d
OFILES = b.o main.o parse.o proctab.o tran.o lib.o run.o lex.o
SOURCE = awk.h ytab.c ytab.h proto.h awkgram.y lex.c b.c main.c \
maketab.c parse.c lib.c run.c tran.c proctab.c missing95.c
maketab.c parse.c lib.c run.c tran.c proctab.c
LISTING = awk.h proto.h awkgram.y lex.c b.c main.c maketab.c parse.c \
lib.c run.c tran.c missing95.c
lib.c run.c tran.c
SHIP = README FIXES $(SOURCE) ytab[ch].bak makefile makefile.win \
vcvars32.bat buildwin.bat awk.1
SHIP = README FIXES $(SOURCE) ytab[ch].bak makefile \
awk.1
a.out: ytab.o $(OFILES)
$(CC) $(CFLAGS) ytab.o $(OFILES) $(ALLOC) -lm

12
run.c
View File

@ -66,6 +66,7 @@ void tempfree(Cell *p) {
jmp_buf env;
extern int pairstack[];
extern Awkfloat srand_seed;
Node *winner = NULL; /* root of parse tree */
Cell *tmps; /* free temporary cells for execution */
@ -1466,6 +1467,7 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
Cell *x, *y;
Awkfloat u;
int t;
Awkfloat tmp;
char *p, *buf;
Node *nextarg;
FILE *fp;
@ -1517,7 +1519,10 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
u = time((time_t *)0);
else
u = getfval(x);
tmp = u;
srand((unsigned int) u);
u = srand_seed;
srand_seed = tmp;
break;
case FTOUPPER:
case FTOLOWER:
@ -1887,9 +1892,10 @@ Cell *gsub(Node **a, int nnn) /* global substitute */
adjbuf(&buf, &bufsz, 1+strlen(sptr)+pb-buf, 0, &pb, "gsub");
while ((*pb++ = *sptr++) != 0)
;
done: if (pb > buf + bufsz)
FATAL("gsub result2 %.30s too big; can't happen", buf);
*pb = '\0';
done: if (pb < buf + bufsz)
*pb = '\0';
else if (*(pb-1) != '\0')
FATAL("gsub result2 %.30s truncated; can't happen", buf);
setsval(x, buf); /* BUG: should be able to avoid copy + free */
pfa->initstat = tempstat;
}