1 /****************************************************************
2 Copyright (C) Lucent Technologies 1997
5 Permission to use, copy, modify, and distribute this software and
6 its documentation for any purpose and without fee is hereby
7 granted, provided that the above copyright notice appear in all
8 copies and that both that the copyright notice and this
9 permission notice and warranty disclaimer appear in supporting
10 documentation, and that the name Lucent Technologies or any of
11 its entities not be used in advertising or publicity pertaining
12 to distribution of the software without specific, written prior
15 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
17 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
18 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
20 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
23 ****************************************************************/
25 This file lists all bug fixes, changes, etc., made since the AWK book
26 was sent to the printers in August, 1987.
29 changed types in posix chars structure to quiet solaris cc.
32 fflush() or fflush("") flushes all files and pipes.
34 length(arrayname) returns number of elements; thanks to
35 arnold robbins for suggestion.
37 added a makefile.win to make it easier to build on windows.
38 based on dan allen's buildwin.bat.
41 added support for posix character class names like [:digit:],
42 which are not exactly shorter than [0-9] and perhaps no more
43 portable. thanks to dag-erling smorgrav for code.
46 removed -m option; no longer needed, and it was actually
47 broken (noted thanks to volker kiefel).
50 fixed an appalling bug in gettok: any sequence of digits, +,-, E, e,
51 and period was accepted as a valid number if it started with a period.
52 this would never have happened with the lex version.
54 other 1-character botches, now fixed, include a bare $ and a
55 bare " at the end of the input.
58 more (const char *) casts in b.c and tran.c to silence warnings.
61 fixed a bug introduced in august 1997 that caused expressions
62 like $f[1] to be syntax errors. thanks to arnold robbins for
63 noticing this and providing a fix.
66 fixed some nextfile bugs: not handling all cases. thanks to
67 arnold robbins for pointing this out. new regressions added.
69 close() is now a function. it returns whatever the library
70 fclose returns, and -1 for closing a file or pipe that wasn't
74 permit \n explicitly in character classes; won't work right
75 if comes in as "[\n]" but ok as /[\n]/, because of multiple
76 processing of \'s. thanks to arnold robbins.
79 minor fiddles in tran.c to keep compilers happy about uschar.
80 thanks to norman wilson.
83 yet another attempt at making 8-bit input work, with another
84 band-aid in b.c (member()), and some (uschar) casts to head
85 off potential errors in subscripts (like isdigit). also
86 changed HAT to NCHARS-2. thanks again to santiago vila.
88 changed maketab.c to ignore apparently out of range definitions
89 instead of halting; new freeBSD generates one. thanks to
90 jon snader <jsnader@ix.netcom.com> for pointing out the problem.
93 fixed an 8-bit problem in b.c by making several char*'s into
94 unsigned char*'s. not clear i have them all yet. thanks to
95 Santiago Vila <sanvila@unex.es> for the bug report.
98 finally found and fixed a memory leak in function call; it's
99 been there since functions were added ~1983. thanks to
100 jon bentley for the test case that found it.
102 added test in envinit to catch environment "variables" with
103 names begining with '='; thanks to Berend Hasselman.
106 added test in defn() to catch function foo(foo), which
107 otherwise recurses until core dump. thanks to arnold
108 robbins for noticing this.
111 added *bp in gettok in lex.c; appears possible to exit function
112 without terminating the string. thanks to russ cox.
115 added function stdinit() to run to initialize files[] array,
116 in case stdin, etc., are not constants; some compilers care.
119 replaced the ERROR ... FATAL, etc., macros with functions
120 based on vprintf, to avoid problems caused by overrunning
121 fixed-size errbuf array. thanks to ralph corderoy for the
122 impetus, and for pointing out a string termination bug in
126 fixed bug that caused occasional core dumps with commandline
127 variable with value ending in \. (thanks to nelson beebe for
131 with code kindly provided by Bruce Lilly, awk now parses
132 /=/ and similar constructs more sensibly in more places.
133 Bruce also provided some helpful test cases.
136 changed true/false to True/False in run.c to make it
137 easier to compile with C++. Added some casts on malloc
138 and realloc to be honest about casts; ditto. changed
139 ltype int to long in struct rrow to reduce some 64-bit
140 complaints; other changes scattered throughout for the
141 same purpose. thanks to Nelson Beebe for these portability
144 removed some horrible pointer-int casting in b.c and elsewhere
145 by adding ptoi and itonp to localize the casts, which are
146 all benign. fixed one incipient bug that showed up on sgi
149 reset lineno for new source file; include filename in error
150 message. also fixed line number error in continuation lines.
151 (thanks to Nelson Beebe for both of these.)
154 Nelson Beebe notes that irix 5.3 yacc dies with a bogus
155 error; use a newer version or switch to bison, since sgi
156 is unlikely to fix it.
159 changed isnumber to is_number to avoid the problem caused by
160 versions of ctype.h that include the name isnumber.
162 distribution now includes a script for building on a Mac,
166 fixed memory leaks in run.c (call) and tran.c (setfval).
167 thanks to Stephen Nutt for finding these and providing the fixes.
170 replaced srand argument by (unsigned int) in run.c;
171 avoids problem on Mac and potentially on Unix & Windows.
174 added a few (int) casts to silence useless compiler warnings.
175 e.g., errorflag= in run.c jump().
177 added proctab.c to the bundle outout; one less thing
178 to have to compile out of the box.
180 added calls to _popen and _pclose to the win95 stub for
181 pipes (thanks to Steve Adams for this helpful suggestion).
182 seems to work, though properties are not well understood
183 by me, and it appears that under some circumstances the
184 pipe output is truncated. Be careful.
187 fixed a couple of bugs in getrec: could fail to update $0
188 after a getline var; because inputFS wasn't initialized,
189 could split $0 on every character, a misleading diversion.
191 fixed caching bug in makedfa: LRU was actually removing
194 thanks to ross ridge for finding these, and for providing
198 fixed potential bug in readrec: might fail to update record
199 pointer after growing. thanks to dan levy for spotting this
200 and suggesting the fix.
203 added -V to print version number and die.
206 subtle silent bug in lex.c: if the program ended with a number
207 longer than 1 digit, part of the input would be pushed back and
208 parsed again because token buffer wasn't terminated right.
209 example: awk 'length($0) > 10'. blush. at least i found it
213 s/adelete/awkdelete/: SGI uses this in malloc.h.
214 thanks to nelson beebe for pointing this one out.
217 fixed some bugs in sub and gsub when replacement includes \\.
218 this is a dark, horrible corner, but at least now i believe that
219 the behavior is the same as gawk and the intended posix standard.
220 thanks to arnold robbins for advice here.
223 somewhat regretfully, replaced the ancient lex-based lexical
224 analyzer with one written in C. it's longer, generates less code,
225 and more portable; the old one depended too much on mysterious
226 properties of lex that were not preserved in other environments.
227 in theory these recognize the same language.
229 now using strtod to test whether a string is a number, instead of
230 the convoluted original function. should be more portable and
231 reliable if strtod is implemented right.
233 removed now-pointless optimization in makefile that tries to avoid
234 recompilation when awkgram.y is changed but symbols are not.
236 removed most fixed-size arrays, though a handful remain, some
237 of which are unchecked. you have been warned.
240 with some trepidation, replaced the ancient code that managed
241 fields and $0 in fixed-size arrays with arrays that grow on
242 demand. there is still some tension between trying to make this
243 run fast and making it clean; not sure it's right yet.
245 the ill-conceived -mr and -mf arguments are now useful only
246 for debugging. previous dynamic string code removed.
248 numerous other minor cleanups along the way.
251 using code provided by dan levy (to whom profuse thanks), replaced
252 fixed-size arrays and awkward kludges by a fairly uniform mechanism
253 to grow arrays as needed for printf, sub, gsub, etc.
256 falling off the end of a function returns "" and 0, not 0.
257 thanks to arnold robbins.
260 replaced several fixed-size arrays by dynamically-created ones
261 in run.c; added overflow tests to some previously unchecked cases.
262 getline, toupper, tolower.
264 getline code is still broken in that recursive calls may wind
265 up using the same space. [fixed later]
267 increased RECSIZE to 8192 to push problems further over the horizon.
269 added \r to \n as input line separator for programs, not data.
272 modified format() to permit explicit printf("%c", 0) to include
273 a null byte in output. thanks to ken stailey for the fix.
275 added a "-safe" argument that disables file output (print >,
276 print >>), process creation (cmd|getline, print |, system), and
277 access to the environment (ENVIRON). this is a first approximation
278 to a "safe" version of awk, but don't rely on it too much. thanks
279 to joan feigenbaum and matt blaze for the inspiration long ago.
282 fixed long-standing bug in sub, gsub(/a/, "\\\\&"); thanks to
286 fixed awful bug in new field splitting; didn't get all the places
287 where input was done.
290 changed field-splitting to conform to posix definition: fields are
291 split using the value of FS at the time of input; it used to be
292 the value when the field or NF was first referred to, a much less
293 predictable definition. thanks to arnold robbins for encouragement
294 to do the right thing.
297 fixed appalling but apparently unimportant bug in parsing octal
298 numbers in reg exprs.
300 explicit hex in reg exprs now limited to 2 chars: \xa, \xaa.
303 cleaned up some declarations so gcc -Wall is now almost silent.
305 makefile now includes backup copies of ytab.c and lexyy.c in case
306 one makes before looking; it also avoids recreating lexyy.c unless
309 s/aprintf/awkprint, s/asprintf/awksprintf/ to avoid some name clashes
310 with unwisely-written header files.
312 thanks to jeffrey friedl for several of these.
315 an attempt to rationalize the (unsigned) char issue. almost all
316 instances of unsigned char have been removed; the handful of places
317 in b.c where chars are used as table indices have been hand-crafted.
318 added some latin-1 tests to the regression, but i'm not confident;
319 none of my compilers seem to care much. thanks to nelson beebe for
320 pointing out some others that do care.
323 removed all register declarations.
325 enhanced split(), as in gawk, etc: split(s, a, "") splits s into
326 a[1]...a[length(s)] with each character a single element.
328 made the same changes for field-splitting if FS is "".
330 added nextfile, as in gawk: causes immediate advance to next
331 input file. (thanks to arnold robbins for inspiration and code).
333 small fixes to regexpr code: can now handle []], [[], and
334 variants; [] is now a syntax error, rather than matching
335 everything; [z-a] is now empty, not z. far from complete
336 or correct, however. (thanks to jeffrey friedl for pointing out
337 some awful behaviors.)
340 replaced uchar by uschar everwhere; apparently some compilers
341 usurp this name and this causes conflicts.
343 fixed call to time in run.c (bltin); arg is time_t *.
345 replaced horrible pointer/long punning in b.c by a legitimate
346 union. should be safer on 64-bit machines and cleaner everywhere.
347 (thanks to nelson beebe for pointing out some of these problems.)
349 replaced nested comments by #if 0...#endif in run.c, lib.c.
351 removed getsval, setsval, execute macros from run.c and lib.c.
352 machines are 100x faster than they were when these macros were
355 revised filenames: awk.g.y => awkgram.y, awk.lx.l => awklex.l,
356 y.tab.[ch] => ytab.[ch], lex.yy.c => lexyy.c, all in the aid of
357 portability to nameless systems.
359 "make bundle" now includes yacc and lex output files for recipients
360 who don't have yacc or lex.
363 initialized Cells in setsymtab more carefully; some fields
364 were not set. (thanks to purify, all of whose complaints i
365 think i now understand.)
367 fixed at least one error in gsub that looked at -1-th element
368 of an array when substituting for a null match (e.g., $).
370 delete arrayname is now legal; it clears the elements but leaves
371 the array, which may not be the right behavior.
373 modified makefile: my current make can't cope with the test used
374 to avoid unnecessary yacc invocations.
377 added dynamically growing strings to awk.lx.l and b.c
378 to permit regular expressions to be much bigger.
379 the state arrays can still overflow.
382 detect duplicate arguments in function definitions (mdm).
385 trivial fix to printf to limit string size in sub().
388 fixed yet another subtle self-assignment problem:
389 $1 = $2; $1 = $1 clobbered $1.
391 Regression tests now use private echo, to avoid quoting problems.
394 changed error() to print line number as %d, not %g.
397 cosmetic changes: increased sizes of some arrays,
398 reworded some error messages.
400 added CONVFMT as in posix (just replaced OFMT in getsval)
402 FILENAME is now "" until the first thing that causes a file
406 deleted yyunput and yyoutput from proto.h;
407 different versions of lex give these different declarations.
410 added -mr N and -mf N options: more record and fields.
411 these really ought to adjust automatically.
413 cleaned up some error messages; "out of space" now means
414 malloc returned NULL in all cases.
416 changed rehash so that if it runs out, it just returns;
417 things will continue to run slow, but maybe a bit longer.
420 remove redundant close of stdin when using -f -.
422 got rid of core dump with -d; awk -d just prints date.
425 added explicit check for /dev/std(in,out,err) in redirection.
426 unlike gawk, no /dev/fd/n yet.
428 added (file/pipe) builtin. hard to test satisfactorily.
432 recompile after abortive changes; should be unchanged.
435 die-casting time: converted to ansi C, installed that.
438 fixed storage leak in freefa, failing to recover [N]CCL.
439 thanks to Bill Jones (jones@cs.usask.ca)
442 use RAND_MAX instead of literal in builtin().
445 cranked up some fixed-size arrays in b.c, and added a test for
446 overflow in penter. thanks to mark larsen.
449 increased buffer in gsub. a very crude fix to a general problem.
453 enforce variable name syntax for commandline variables: has to
454 start with letter or _.
457 allow newline after ; in for statements.
460 fixed so that in self-assignment like $1=$1, side effects
461 like recomputing $0 take place. (this is getting subtle.)
464 better test for detecting too-long output record.
467 better defense against very long printf strings.
468 made break and continue illegal outside of loops.
471 removed extra arg on gettemp, tempfree. minor error message rewording.
474 fixed silly bug in hex parsing in hexstr().
475 removed an apparently unnecessary test in isnumber().
476 warn about weird printf conversions.
477 fixed unchecked array overwrite in relex().
479 changed for (i in array) to access elements in sorted order.
480 then unchanged it -- it really does run slower in too many cases.
481 left the code in place, commented out.
484 check error status on all writes, to avoid banging on full disks.
487 awk -f - reads the program from stdin.
490 failed to set numeric state on $0 in cmd|getline context in run.c.
493 fixed sleazy test for integrality in getsval; use modf.
496 fixed sleazy buggy code in lib.c that looked (incorrectly) for
497 too long input lines.
500 fixed the bug on p. 198 in which it couldn't deduce that an
501 argument was an array in some contexts. replaced the error
502 message in intest() by code that damn well makes it an array.
505 fixed horrible bug: types and values were not preserved in
506 some kinds of self-assignment. (in assign().)
509 changed NCHARS to 256 to handle 8-bit characters in strings
510 presented to match(), etc.
513 changed struct rrow (awk.h) to use long instead of int for lval,
514 since cfoll() stores a pointer in it. now works better when int's
515 are smaller than pointers!
518 AVA fixed the grammar so that ! is uniformly of the same precedence as
519 unary + and -. This renders illegal some constructs like !x=y, which
520 now has to be parenthesized as !(x=y), and makes others work properly:
521 !x+y is (!x)+y, and x!y is x !y, not two pattern-action statements.
522 (These problems were pointed out by Bob Lenk of Posix.)
524 Added \x to regular expressions (already in strings).
525 Limited octal to octal digits; \8 and \9 are not octal.
526 Centralized the code for parsing escapes in regular expressions.
527 Added a bunch of tests to T.re and T.sub to verify some of this.
530 fixed null pointer dereference bug in main.c: -F[nothing]. sigh.
532 restored srand behavior: it returns the current seed.
535 srand now returns previous seed value (0 to start).
538 fix potential problem in tran.c -- something was freed,
539 then used in freesymtab.
542 another try to get the max number of open files set with
543 relatively machine-independent code.
545 small fix to input() in case of multiple reads after EOF.
548 FILENAME is now defined in the BEGIN block -- too many old
551 "-" means stdin in getline as well as on the commandline.
553 added a bunch of casts to the code to tell the truth about
554 char * vs. unsigned char *, a right royal pain. added a
555 setlocale call to the front of main, though probably no one
556 has it usefully implemented yet.
559 removed redundant relational tests against nullnode if parse
560 tree already had a relational at that point.
563 fixed bug: commandline variable assignment has to look like
564 var=something. (consider the man page for =, in file =.1)
566 changed number of arguments to functions to static arrays
567 to avoid repeated malloc calls.
570 restored -F (space) separator
573 added -v x=1 y=2 ... for immediate commandline variable assignment;
574 done before the BEGIN block for sure. they have to precede the
575 program if the program is on the commandline.
576 Modified Aug 2 to require a separate -v for each assignment.
579 fixed ref-thru-zero bug in environment code in tran.c
582 add newline to usage message.
585 added some missing ansi printf conversion letters: %i %X %E %G.
586 no sensible meaning for h or L, so they may not do what one expects.
588 made %* conversions work.
590 changed x^y so that if n is a positive integer, it's done
591 by explicit multiplication, thus achieving maximum accuracy.
592 (this should be done by pow() but it seems not to be locally.)
593 done to x ^= y as well.
596 ENVIRON array contains environment: if shell variable V=thing,
597 ENVIRON["V"] is "thing"
599 multiple -f arguments permitted. error reporting is naive.
600 (they were permitted before, but only the last was used.)
602 fixed a really stupid botch in the debugging macro dprintf
604 fixed order of evaluation of commandline assignments to match
605 what the book claims: an argument of the form x=e is evaluated
606 at the time it would have been opened if it were a filename (p 63).
607 this invalidates the suggested answer to ex 4-1 (p 195).
609 removed some code that permitted -F (space) fieldseparator,
610 since it didn't quite work right anyway. (restored aug 2)
613 Line number now accumulated correctly for comment lines.
616 Debugging output now includes a version date,
617 if one compiles it into the source each time.
620 Changed grammar to prohibit constants as 3rd arg of sub and gsub;
621 prevents class of overwriting-a-constant errors. (Last one?)
622 This invalidates the "banana" example on page 43 of the book.
624 Added \a ("alert"), \v (vertical tab), \xhhh (hexadecimal),
625 as in ANSI, for strings. Rescinded the sloppiness that permitted
626 non-octal digits in \ooo. Warning: not all compilers and libraries
627 will be able to deal with \x correctly.
630 Fixed bug that caused tempcell list to contain a duplicate.
634 Catches some more commandline errors in main.
635 Removed redundant decl of modf in run.c (confuses some compilers).
636 Warning: there's no single declaration of malloc, etc., in awk.h
637 that seems to satisfy all compilers.
640 Added a bit of code to error printing to avoid printing nulls.
641 (Not clear that it actually would.)
644 With fear and trembling, modified the grammar to permit
645 multiple pattern-action statements on one line without
646 an explicit separator. By definition, this capitulation
647 to the ghost of ancient implementations remains undefined
648 and thus subject to change without notice or apology.
652 Fixed bug in call() that failed to recover storage.
654 A warning is now generated if there are more arguments
655 in the call than in the definition (in lieu of fixing
656 another storage leak).
659 Fixed %c: if expr is numeric, use numeric value;
660 otherwise print 1st char of string value. still
661 doesn't work if the value is 0 -- won't print \0.
663 Added a few more checks for running out of malloc.
666 Fixed bug in call() that freed local arrays twice.
668 Fixed to handle deletion of non-existent array right;
669 complains about attempt to delete non-array element.
672 Now guarantees to evaluate all arguments of built-in
673 functions, as in C; the appearance is that arguments
674 are evaluated before the function is called. Places
675 affected are sub (gsub was ok), substr, printf, and
676 all the built-in arithmetic functions in bltin().
677 A warning is generated if a bltin() is called with
678 the wrong number of arguments.
680 This requires changing makeprof on p167 of the book.
683 setting FILENAME in BEGIN caused core dump, apparently
684 because it was freeing space not allocated by malloc.
687 fixed egregious error in toupper/tolower functions.
688 still subject to rescinding, however.
691 flush stdout before opening file or pipe
694 performance bug in b.c/cgoto(): not freeing some sets of states.
695 partial fix only right now, and the number of states increased
696 to make it less obvious.
699 check error status on close
702 srand returns seed value it's using.
706 Removed limit on depth of function calls.
709 Fixed lib.c to permit _ in commandline variable names.
712 main.c fixed to recognize -- as terminator of command-
713 line options. Illegal options flagged.
714 Error reporting slightly cleaned up.
717 Newer C compilers apply a strict scope rule to extern
718 declarations within functions. Two extern declarations in
719 lib.c and tran.c have been moved to obviate this problem.
722 Reluctantly added toupper and tolower functions.
723 Subject to rescinding without notice.
726 Error-message printer had printf(s) instead of
727 printf("%s",s); got core dumps when the message
731 Very long printf strings caused core dump;
732 fixed aprintf, asprintf, format to catch them.
733 Can still get a core dump in printf itself.