summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1999-04-18 17:06:32 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1999-04-18 17:06:32 +0000
commit44df8b77706890435e485c323ff5be8bec119bcb (patch)
tree39bcf9f33f3c403bffd9afa17348950c0329b622 /usr.bin
parent47e793c291239affc066833827fbcdb12825e582 (diff)
March 5, 1999 version of the "one true awk"
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/awk/FIXES821
-rw-r--r--usr.bin/awk/OpenBSD-PATCHES10
-rw-r--r--usr.bin/awk/README25
-rw-r--r--usr.bin/awk/b.c9
-rw-r--r--usr.bin/awk/lex.c6
-rw-r--r--usr.bin/awk/lib.c38
-rw-r--r--usr.bin/awk/main.c14
-rw-r--r--usr.bin/awk/maketab.c4
-rw-r--r--usr.bin/awk/proto.h6
-rw-r--r--usr.bin/awk/run.c27
-rw-r--r--usr.bin/awk/tran.c10
11 files changed, 519 insertions, 451 deletions
diff --git a/usr.bin/awk/FIXES b/usr.bin/awk/FIXES
index 20ab0d20d41..72e432fa4d8 100644
--- a/usr.bin/awk/FIXES
+++ b/usr.bin/awk/FIXES
@@ -1,4 +1,4 @@
-/* $OpenBSD: FIXES,v 1.6 1997/08/25 16:17:07 kstailey Exp $ */
+/* $OpenBSD: FIXES,v 1.7 1999/04/18 17:06:29 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -26,522 +26,583 @@ THIS SOFTWARE.
This file lists all bug fixes, changes, etc., made since the AWK book
was sent to the printers in August, 1987.
-Sep 12, 1987:
- Very long printf strings caused core dump;
- fixed aprintf, asprintf, format to catch them.
- Can still get a core dump in printf itself.
+Mar 5, 1999:
+ after hearing from yet another innocent victim, changed
+ isnumber to is_number to avoid the problem caused by
+ freeBSD gratuitously and incorrectly including the name
+ isnumber in the standard header file ctype.h.
-Sep 17, 1987:
- Error-message printer had printf(s) instead of
- printf("%s",s); got core dumps when the message
- included a %.
+ distribution now includes a script for building on a Mac,
+ thanks to Dan Allen.
-Oct xx, 1987:
- Reluctantly added toupper and tolower functions.
- Subject to rescinding without notice.
+Feb 20, 1999:
+ fixed memory leaks in run.c (call) and tran.c (setfval).
+ thanks to Stephen Nutt for finding these and providing the fixes.
-Dec 2, 1987:
- Newer C compilers apply a strict scope rule to extern
- declarations within functions. Two extern declarations in
- lib.c and tran.c have been moved to obviate this problem.
+Jan 13, 1999:
+ replaced srand argument by (unsigned int) in run.c;
+ avoids problem on Mac and potentially on Unix & Windows.
+ thanks to Dan Allen.
-Mar 25, 1988:
- main.c fixed to recognize -- as terminator of command-
- line options. Illegal options flagged.
- Error reporting slightly cleaned up.
+ added a few (int) casts to silence useless compiler warnings.
+ e.g., errorflag= in run.c jump().
-May 10, 1988:
- Fixed lib.c to permit _ in commandline variable names.
+ added proctab.c to the bundle outout; one less thing
+ to have to compile out of the box.
-May 22, 1988:
- Removed limit on depth of function calls.
+ added calls to _popen and _pclose to the win95 stub for
+ pipes (thanks to Steve Adams for this helpful suggestion).
+ seems to work, though properties are not well understood
+ by me, and it appears that under some circumstances the
+ pipe output is truncated. Be careful.
-May 28, 1988:
- srand returns seed value it's using.
- see 1/18/90
+Oct 19, 1998:
+ fixed a couple of bugs in getrec: could fail to update $0
+ after a getline var; because inputFS wasn't initialized,
+ could split $0 on every character, a misleading diversion.
-June 1, 1988:
- check error status on close
+ fixed caching bug in makedfa: LRU was actually removing
+ least often used.
-July 2, 1988:
- performance bug in b.c/cgoto(): not freeing some sets of states.
- partial fix only right now, and the number of states increased
- to make it less obvious.
+ thanks to ross ridge for finding these, and for providing
+ great bug reports.
-July 2, 1988:
- flush stdout before opening file or pipe
+May 12, 1998:
+ fixed potential bug in readrec: might fail to update record
+ pointer after growing. thanks to dan levy for spotting this
+ and suggesting the fix.
-July 24, 1988:
- fixed egregious error in toupper/tolower functions.
- still subject to rescinding, however.
+Mar 12, 1998:
+ added -V to print version number and die.
-Aug 23, 1988:
- setting FILENAME in BEGIN caused core dump, apparently
- because it was freeing space not allocated by malloc.
+Feb 11, 1998:
+ subtle silent bug in lex.c: if the program ended with a number
+ longer than 1 digit, part of the input would be pushed back and
+ parsed again because token buffer wasn't terminated right.
+ example: awk 'length($0) > 10'. blush. at least i found it
+ myself.
-Sep 30, 1988:
- Now guarantees to evaluate all arguments of built-in
- functions, as in C; the appearance is that arguments
- are evaluated before the function is called. Places
- affected are sub (gsub was ok), substr, printf, and
- all the built-in arithmetic functions in bltin().
- A warning is generated if a bltin() is called with
- the wrong number of arguments.
+Aug 31, 1997:
+ s/adelete/awkdelete/: SGI uses this in malloc.h.
+ thanks to nelson beebe for pointing this one out.
- This requires changing makeprof on p167 of the book.
+Aug 21, 1997:
+ fixed some bugs in sub and gsub when replacement includes \\.
+ this is a dark, horrible corner, but at least now i believe that
+ the behavior is the same as gawk and the intended posix standard.
+ thanks to arnold robbins for advice here.
-Oct 12, 1988:
- Fixed bug in call() that freed local arrays twice.
+Aug 9, 1997:
+ somewhat regretfully, replaced the ancient lex-based lexical
+ analyzer with one written in C. it's longer, generates less code,
+ and more portable; the old one depended too much on mysterious
+ properties of lex that were not preserved in other environments.
+ in theory these recognize the same language.
- Fixed to handle deletion of non-existent array right;
- complains about attempt to delete non-array element.
+ now using strtod to test whether a string is a number, instead of
+ the convoluted original function. should be more portable and
+ reliable if strtod is implemented right.
-Oct 20, 1988:
- Fixed %c: if expr is numeric, use numeric value;
- otherwise print 1st char of string value. still
- doesn't work if the value is 0 -- won't print \0.
+ removed now-pointless optimization in makefile that tries to avoid
+ recompilation when awkgram.y is changed but symbols are not.
- Added a few more checks for running out of malloc.
+ removed most fixed-size arrays, though a handful remain, some
+ of which are unchecked. you have been warned.
-Oct 30, 1988:
- Fixed bug in call() that failed to recover storage.
+Aug 4, 1997:
+ with some trepidation, replaced the ancient code that managed
+ fields and $0 in fixed-size arrays with arrays that grow on
+ demand. there is still some tension between trying to make this
+ run fast and making it clean; not sure it's right yet.
- A warning is now generated if there are more arguments
- in the call than in the definition (in lieu of fixing
- another storage leak).
+ the ill-conceived -mr and -mf arguments are now useful only
+ for debugging. previous dynamic string code removed.
-Nov 27, 1988:
- With fear and trembling, modified the grammar to permit
- multiple pattern-action statements on one line without
- an explicit separator. By definition, this capitulation
- to the ghost of ancient implementations remains undefined
- and thus subject to change without notice or apology.
- DO NOT COUNT ON IT.
+ numerous other minor cleanups along the way.
-Dec 7, 1988:
- Added a bit of code to error printing to avoid printing nulls.
- (Not clear that it actually would.)
+Jul 30, 1997:
+ using code provided by dan levy (to whom profuse thanks), replaced
+ fixed-size arrays and awkward kludges by a fairly uniform mechanism
+ to grow arrays as needed for printf, sub, gsub, etc.
-Dec 17, 1988:
- Catches some more commandline errors in main.
- Removed redundant decl of modf in run.c (confuses some compilers).
- Warning: there's no single declaration of malloc, etc., in awk.h
- that seems to satisfy all compilers.
+Jul 23, 1997:
+ falling off the end of a function returns "" and 0, not 0.
+ thanks to arnold robbins.
-Jan 9, 1989:
- Fixed bug that caused tempcell list to contain a duplicate.
- The fix is kludgy.
+Jun 17, 1997:
+ replaced several fixed-size arrays by dynamically-created ones
+ in run.c; added overflow tests to some previously unchecked cases.
+ getline, toupper, tolower.
-Apr 9, 1989:
- Changed grammar to prohibit constants as 3rd arg of sub and gsub;
- prevents class of overwriting-a-constant errors. (Last one?)
- This invalidates the "banana" example on page 43 of the book.
+ getline code is still broken in that recursive calls may wind
+ up using the same space. [fixed later]
- Added \a ("alert"), \v (vertical tab), \xhhh (hexadecimal),
- as in ANSI, for strings. Rescinded the sloppiness that permitted
- non-octal digits in \ooo. Warning: not all compilers and libraries
- will be able to deal with \x correctly.
+ increased RECSIZE to 8192 to push problems further over the horizon.
-Apr 26, 1989:
- Debugging output now includes a version date,
- if one compiles it into the source each time.
+ added \r to \n as input line separator for programs, not data.
+ damn CRLFs.
-Apr 27, 1989:
- Line number now accumulated correctly for comment lines.
+ modified format() to permit explicit printf("%c", 0) to include
+ a null byte in output. thanks to ken stailey for the fix.
-Jun 4, 1989:
- ENVIRON array contains environment: if shell variable V=thing,
- ENVIRON["V"] is "thing"
+ added a "-safe" argument that disables file output (print >,
+ print >>), process creation (cmd|getline, print |, system), and
+ access to the environment (ENVIRON). this is a first approximation
+ to a "safe" version of awk, but don't rely on it too much. thanks
+ to joan feigenbaum and matt blaze for the inspiration long ago.
- multiple -f arguments permitted. error reporting is naive.
- (they were permitted before, but only the last was used.)
+Jul 8, 1996:
+ fixed long-standing bug in sub, gsub(/a/, "\\\\&"); thanks to
+ ralph corderoy.
- fixed a really stupid botch in the debugging macro dprintf
+Jun 29, 1996:
+ fixed awful bug in new field splitting; didn't get all the places
+ where input was done.
- fixed order of evaluation of commandline assignments to match
- what the book claims: an argument of the form x=e is evaluated
- at the time it would have been opened if it were a filename (p 63).
- this invalidates the suggested answer to ex 4-1 (p 195).
+Jun 28, 1996:
+ changed field-splitting to conform to posix definition: fields are
+ split using the value of FS at the time of input; it used to be
+ the value when the field or NF was first referred to, a much less
+ predictable definition. thanks to arnold robbins for encouragement
+ to do the right thing.
- removed some code that permitted -F (space) fieldseparator,
- since it didn't quite work right anyway. (restored aug 2)
+May 28, 1996:
+ fixed appalling but apparently unimportant bug in parsing octal
+ numbers in reg exprs.
-Jun 14, 1989:
- added some missing ansi printf conversion letters: %i %X %E %G.
- no sensible meaning for h or L, so they may not do what one expects.
+ explicit hex in reg exprs now limited to 2 chars: \xa, \xaa.
- made %* conversions work.
+May 27, 1996:
+ cleaned up some declarations so gcc -Wall is now almost silent.
- changed x^y so that if n is a positive integer, it's done
- by explicit multiplication, thus achieving maximum accuracy.
- (this should be done by pow() but it seems not to be locally.)
- done to x ^= y as well.
+ makefile now includes backup copies of ytab.c and lexyy.c in case
+ one makes before looking; it also avoids recreating lexyy.c unless
+ really needed.
-Jun 23, 1989:
- add newline to usage message.
+ s/aprintf/awkprint, s/asprintf/awksprintf/ to avoid some name clashes
+ with unwisely-written header files.
-Jul 10, 1989:
- fixed ref-thru-zero bug in environment code in tran.c
+ thanks to jeffrey friedl for several of these.
-Jul 30, 1989:
- added -v x=1 y=2 ... for immediate commandline variable assignment;
- done before the BEGIN block for sure. they have to precede the
- program if the program is on the commandline.
- Modified Aug 2 to require a separate -v for each assignment.
+May 26, 1996:
+ an attempt to rationalize the (unsigned) char issue. almost all
+ instances of unsigned char have been removed; the handful of places
+ in b.c where chars are used as table indices have been hand-crafted.
+ added some latin-1 tests to the regression, but i'm not confident;
+ none of my compilers seem to care much. thanks to nelson beebe for
+ pointing out some others that do care.
-Aug 2, 1989:
- restored -F (space) separator
+May 2, 1996:
+ removed all register declarations.
-Aug 11, 1989:
- fixed bug: commandline variable assignment has to look like
- var=something. (consider the man page for =, in file =.1)
+ enhanced split(), as in gawk, etc: split(s, a, "") splits s into
+ a[1]...a[length(s)] with each character a single element.
- changed number of arguments to functions to static arrays
- to avoid repeated malloc calls.
+ made the same changes for field-splitting if FS is "".
-Aug 24, 1989:
- removed redundant relational tests against nullnode if parse
- tree already had a relational at that point.
+ added nextfile, as in gawk: causes immediate advance to next
+ input file. (thanks to arnold robbins for inspiration and code).
-Oct 11, 1989:
- FILENAME is now defined in the BEGIN block -- too many old
- programs broke.
+ small fixes to regexpr code: can now handle []], [[], and
+ variants; [] is now a syntax error, rather than matching
+ everything; [z-a] is now empty, not z. far from complete
+ or correct, however. (thanks to jeffrey friedl for pointing out
+ some awful behaviors.)
- "-" means stdin in getline as well as on the commandline.
+Apr 29, 1996:
+ replaced uchar by uschar everwhere; apparently some compilers
+ usurp this name and this causes conflicts.
- added a bunch of casts to the code to tell the truth about
- char * vs. unsigned char *, a right royal pain. added a
- setlocale call to the front of main, though probably no one
- has it usefully implemented yet.
+ fixed call to time in run.c (bltin); arg is time_t *.
-Oct 18, 1989:
- another try to get the max number of open files set with
- relatively machine-independent code.
+ replaced horrible pointer/long punning in b.c by a legitimate
+ union. should be safer on 64-bit machines and cleaner everywhere.
+ (thanks to nelson beebe for pointing out some of these problems.)
- small fix to input() in case of multiple reads after EOF.
+ replaced nested comments by #if 0...#endif in run.c, lib.c.
-Jan 5, 1990:
- fix potential problem in tran.c -- something was freed,
- then used in freesymtab.
+ removed getsval, setsval, execute macros from run.c and lib.c.
+ machines are 100x faster than they were when these macros were
+ first used.
-Jan 18, 1990:
- srand now returns previous seed value (0 to start).
+ revised filenames: awk.g.y => awkgram.y, awk.lx.l => awklex.l,
+ y.tab.[ch] => ytab.[ch], lex.yy.c => lexyy.c, all in the aid of
+ portability to nameless systems.
-Feb 9, 1990:
- fixed null pointer dereference bug in main.c: -F[nothing]. sigh.
+ "make bundle" now includes yacc and lex output files for recipients
+ who don't have yacc or lex.
- restored srand behavior: it returns the current seed.
+Aug 15, 1995:
+ initialized Cells in setsymtab more carefully; some fields
+ were not set. (thanks to purify, all of whose complaints i
+ think i now understand.)
-May 6, 1990:
- AVA fixed the grammar so that ! is uniformly of the same precedence as
- unary + and -. This renders illegal some constructs like !x=y, which
- now has to be parenthesized as !(x=y), and makes others work properly:
- !x+y is (!x)+y, and x!y is x !y, not two pattern-action statements.
- (These problems were pointed out by Bob Lenk of Posix.)
+ fixed at least one error in gsub that looked at -1-th element
+ of an array when substituting for a null match (e.g., $).
- Added \x to regular expressions (already in strings).
- Limited octal to octal digits; \8 and \9 are not octal.
- Centralized the code for parsing escapes in regular expressions.
- Added a bunch of tests to T.re and T.sub to verify some of this.
+ delete arrayname is now legal; it clears the elements but leaves
+ the array, which may not be the right behavior.
-Jun 26, 1990:
- changed struct rrow (awk.h) to use long instead of int for lval,
- since cfoll() stores a pointer in it. now works better when int's
- are smaller than pointers!
+ modified makefile: my current make can't cope with the test used
+ to avoid unnecessary yacc invocations.
-Aug 24, 1990:
- changed NCHARS to 256 to handle 8-bit characters in strings
- presented to match(), etc.
+Jul 17, 1995:
+ added dynamically growing strings to awk.lx.l and b.c
+ to permit regular expressions to be much bigger.
+ the state arrays can still overflow.
-Oct 8, 1990:
- fixed horrible bug: types and values were not preserved in
- some kinds of self-assignment. (in assign().)
+Aug 24, 1994:
+ detect duplicate arguments in function definitions (mdm).
-Oct 14, 1990:
- fixed the bug on p. 198 in which it couldn't deduce that an
- argument was an array in some contexts. replaced the error
- message in intest() by code that damn well makes it an array.
+May 11, 1994:
+ trivial fix to printf to limit string size in sub().
-Oct 29, 1990:
- fixed sleazy buggy code in lib.c that looked (incorrectly) for
- too long input lines.
+Apr 22, 1994:
+ fixed yet another subtle self-assignment problem:
+ $1 = $2; $1 = $1 clobbered $1.
-Nov 2, 1990:
- fixed sleazy test for integrality in getsval; use modf.
+ Regression tests now use private echo, to avoid quoting problems.
-Jan 11, 1991:
- failed to set numeric state on $0 in cmd|getline context in run.c.
+Feb 2, 1994:
+ changed error() to print line number as %d, not %g.
-Jan 28, 1991:
- awk -f - reads the program from stdin.
+Jul 23, 1993:
+ cosmetic changes: increased sizes of some arrays,
+ reworded some error messages.
-Feb 10, 1991:
- check error status on all writes, to avoid banging on full disks.
+ added CONVFMT as in posix (just replaced OFMT in getsval)
-May 6, 1991:
- fixed silly bug in hex parsing in hexstr().
- removed an apparently unnecessary test in isnumber().
- warn about weird printf conversions.
- fixed unchecked array overwrite in relex().
+ FILENAME is now "" until the first thing that causes a file
+ to be opened.
- changed for (i in array) to access elements in sorted order.
- then unchanged it -- it really does run slower in too many cases.
- left the code in place, commented out.
+Nov 28, 1992:
+ deleted yyunput and yyoutput from proto.h;
+ different versions of lex give these different declarations.
-May 13, 1991:
- removed extra arg on gettemp, tempfree. minor error message rewording.
+May 31, 1992:
+ added -mr N and -mf N options: more record and fields.
+ these really ought to adjust automatically.
-Jun 2, 1991:
- better defense against very long printf strings.
- made break and continue illegal outside of loops.
+ cleaned up some error messages; "out of space" now means
+ malloc returned NULL in all cases.
-Jun 30, 1991:
- better test for detecting too-long output record.
+ changed rehash so that if it runs out, it just returns;
+ things will continue to run slow, but maybe a bit longer.
-Jul 21, 1991:
- fixed so that in self-assignment like $1=$1, side effects
- like recomputing $0 take place. (this is getting subtle.)
+Apr 24, 1992:
+ remove redundant close of stdin when using -f -.
-Jul 27, 1991:
- allow newline after ; in for statements.
+ got rid of core dump with -d; awk -d just prints date.
-Aug 18, 1991:
- enforce variable name syntax for commandline variables: has to
- start with letter or _.
+Apr 12, 1992:
+ added explicit check for /dev/std(in,out,err) in redirection.
+ unlike gawk, no /dev/fd/n yet.
-Sep 24, 1991:
- increased buffer in gsub. a very crude fix to a general problem.
- and again on Sep 26.
+ added (file/pipe) builtin. hard to test satisfactorily.
+ not posix.
+
+Feb 20, 1992:
+ recompile after abortive changes; should be unchanged.
+
+Dec 2, 1991:
+ die-casting time: converted to ansi C, installed that.
+
+Nov 30, 1991:
+ fixed storage leak in freefa, failing to recover [N]CCL.
+ thanks to Bill Jones (jones@cs.usask.ca)
+
+Nov 19, 1991:
+ use RAND_MAX instead of literal in builtin().
Nov 12, 1991:
cranked up some fixed-size arrays in b.c, and added a test for
overflow in penter. thanks to mark larsen.
-Nov 19, 1991:
- use RAND_MAX instead of literal in builtin().
+Sep 24, 1991:
+ increased buffer in gsub. a very crude fix to a general problem.
+ and again on Sep 26.
-Nov 30, 1991:
- fixed storage leak in freefa, failing to recover [N]CCL.
- thanks to Bill Jones (jones@skorpio.usask.ca)
+Aug 18, 1991:
+ enforce variable name syntax for commandline variables: has to
+ start with letter or _.
-Dec 2, 1991:
- die-casting time: converted to ansi C, installed that.
+Jul 27, 1991:
+ allow newline after ; in for statements.
-Feb 20, 1992:
- recompile after abortive changes; should be unchanged.
+Jul 21, 1991:
+ fixed so that in self-assignment like $1=$1, side effects
+ like recomputing $0 take place. (this is getting subtle.)
-Apr 12, 1992:
- added explicit check for /dev/std(in,out,err) in redirection.
- unlike gawk, no /dev/fd/n yet.
+Jun 30, 1991:
+ better test for detecting too-long output record.
- added (file/pipe) builtin. hard to test satisfactorily.
- not posix.
+Jun 2, 1991:
+ better defense against very long printf strings.
+ made break and continue illegal outside of loops.
-Apr 24, 1992:
- remove redundant close of stdin when using -f -.
+May 13, 1991:
+ removed extra arg on gettemp, tempfree. minor error message rewording.
- got rid of core dump with -d; awk -d just prints date.
+May 6, 1991:
+ fixed silly bug in hex parsing in hexstr().
+ removed an apparently unnecessary test in isnumber().
+ warn about weird printf conversions.
+ fixed unchecked array overwrite in relex().
-May 31, 1992:
- added -mr N and -mf N options: more record and fields.
- these really ought to adjust automatically.
+ changed for (i in array) to access elements in sorted order.
+ then unchanged it -- it really does run slower in too many cases.
+ left the code in place, commented out.
- cleaned up some error messages; "out of space" now means
- malloc returned NULL in all cases.
+Feb 10, 1991:
+ check error status on all writes, to avoid banging on full disks.
- changed rehash so that if it runs out, it just returns;
- things will continue to run slow, but maybe a bit longer.
+Jan 28, 1991:
+ awk -f - reads the program from stdin.
-Nov 28, 1992:
- deleted yyunput and yyoutput from proto.h;
- different versions of lex give these different declarations.
+Jan 11, 1991:
+ failed to set numeric state on $0 in cmd|getline context in run.c.
-Jul 23, 1993:
- cosmetic changes: increased sizes of some arrays,
- reworded some error messages.
+Nov 2, 1990:
+ fixed sleazy test for integrality in getsval; use modf.
- added CONVFMT as in posix (just replaced OFMT in getsval)
+Oct 29, 1990:
+ fixed sleazy buggy code in lib.c that looked (incorrectly) for
+ too long input lines.
- FILENAME is now "" until the first thing that causes a file
- to be opened.
+Oct 14, 1990:
+ fixed the bug on p. 198 in which it couldn't deduce that an
+ argument was an array in some contexts. replaced the error
+ message in intest() by code that damn well makes it an array.
-Feb 2, 1994:
- changed error() to print line number as %d, not %g.
+Oct 8, 1990:
+ fixed horrible bug: types and values were not preserved in
+ some kinds of self-assignment. (in assign().)
-Apr 22, 1994:
- fixed yet another subtle self-assignment problem:
- $1 = $2; $1 = $1 clobbered $1.
+Aug 24, 1990:
+ changed NCHARS to 256 to handle 8-bit characters in strings
+ presented to match(), etc.
- Regression tests now use private echo, to avoid quoting problems.
+Jun 26, 1990:
+ changed struct rrow (awk.h) to use long instead of int for lval,
+ since cfoll() stores a pointer in it. now works better when int's
+ are smaller than pointers!
-May 11, 1994:
- trivial fix to printf to limit string size in sub().
+May 6, 1990:
+ AVA fixed the grammar so that ! is uniformly of the same precedence as
+ unary + and -. This renders illegal some constructs like !x=y, which
+ now has to be parenthesized as !(x=y), and makes others work properly:
+ !x+y is (!x)+y, and x!y is x !y, not two pattern-action statements.
+ (These problems were pointed out by Bob Lenk of Posix.)
-Aug 24, 1994:
- detect duplicate arguments in function definitions (mdm).
+ Added \x to regular expressions (already in strings).
+ Limited octal to octal digits; \8 and \9 are not octal.
+ Centralized the code for parsing escapes in regular expressions.
+ Added a bunch of tests to T.re and T.sub to verify some of this.
-Jul 17, 1995:
- added dynamically growing strings to awk.lx.l and b.c
- to permit regular expressions to be much bigger.
- the state arrays can still overflow.
+Feb 9, 1990:
+ fixed null pointer dereference bug in main.c: -F[nothing]. sigh.
-Aug 15, 1995:
- initialized Cells in setsymtab more carefully; some fields
- were not set. (thanks to purify, all of whose complaints i
- think i now understand.)
+ restored srand behavior: it returns the current seed.
- fixed at least one error in gsub that looked at -1-th element
- of an array when substituting for a null match (e.g., $).
+Jan 18, 1990:
+ srand now returns previous seed value (0 to start).
- delete arrayname is now legal; it clears the elements but leaves
- the array, which may not be the right behavior.
+Jan 5, 1990:
+ fix potential problem in tran.c -- something was freed,
+ then used in freesymtab.
- modified makefile: my current make can't cope with the test used
- to avoid unnecessary yacc invocations.
+Oct 18, 1989:
+ another try to get the max number of open files set with
+ relatively machine-independent code.
-Apr 29, 1996:
- replaced uchar by uschar everwhere; apparently some compilers
- usurp this name and this causes conflicts.
+ small fix to input() in case of multiple reads after EOF.
- fixed call to time in run.c (bltin); arg is time_t *.
+Oct 11, 1989:
+ FILENAME is now defined in the BEGIN block -- too many old
+ programs broke.
- replaced horrible pointer/long punning in b.c by a legitimate
- union. should be safer on 64-bit machines and cleaner everywhere.
- (thanks to nelson beebe for pointing out some of these problems.)
+ "-" means stdin in getline as well as on the commandline.
- replaced nested comments by #if 0...#endif in run.c, lib.c.
+ added a bunch of casts to the code to tell the truth about
+ char * vs. unsigned char *, a right royal pain. added a
+ setlocale call to the front of main, though probably no one
+ has it usefully implemented yet.
- removed getsval, setsval, execute macros from run.c and lib.c.
- machines are 100x faster than they were when these macros were
- first used.
+Aug 24, 1989:
+ removed redundant relational tests against nullnode if parse
+ tree already had a relational at that point.
- revised filenames: awk.g.y => awkgram.y, awk.lx.l => awklex.l,
- y.tab.[ch] => ytab.[ch], lex.yy.c => lexyy.c, all in the aid of
- portability to nameless systems.
+Aug 11, 1989:
+ fixed bug: commandline variable assignment has to look like
+ var=something. (consider the man page for =, in file =.1)
- "make bundle" now includes yacc and lex output files for recipients
- who don't have yacc or lex.
+ changed number of arguments to functions to static arrays
+ to avoid repeated malloc calls.
-May 2, 1996:
- removed all register declarations.
+Aug 2, 1989:
+ restored -F (space) separator
- enhanced split(), as in gawk, etc: split(s, a, "") splits s into
- a[1]...a[length(s)] with each character a single element.
+Jul 30, 1989:
+ added -v x=1 y=2 ... for immediate commandline variable assignment;
+ done before the BEGIN block for sure. they have to precede the
+ program if the program is on the commandline.
+ Modified Aug 2 to require a separate -v for each assignment.
- made the same changes for field-splitting if FS is "".
+Jul 10, 1989:
+ fixed ref-thru-zero bug in environment code in tran.c
- added nextfile, as in gawk: causes immediate advance to next
- input file. (thanks to arnold robbins for inspiration and code).
+Jun 23, 1989:
+ add newline to usage message.
- small fixes to regexpr code: can now handle []], [[], and
- variants; [] is now a syntax error, rather than matching
- everything; [z-a] is now empty, not z. far from complete
- or correct, however. (thanks to jeffrey friedl for pointing out
- some awful behaviors.)
+Jun 14, 1989:
+ added some missing ansi printf conversion letters: %i %X %E %G.
+ no sensible meaning for h or L, so they may not do what one expects.
-May 26, 1996:
- an attempt to rationalize the (unsigned) char issue. almost all
- instances of unsigned char have been removed; the handful of places
- in b.c where chars are used as table indices have been hand-crafted.
- added some latin-1 tests to the regression, but i'm not confident;
- none of my compilers seem to care much. thanks to nelson beebe for
- pointing out some others that do care.
+ made %* conversions work.
-May 27, 1996:
- cleaned up some declarations so gcc -Wall is now almost silent.
+ changed x^y so that if n is a positive integer, it's done
+ by explicit multiplication, thus achieving maximum accuracy.
+ (this should be done by pow() but it seems not to be locally.)
+ done to x ^= y as well.
- makefile now includes backup copies of ytab.c and lexyy.c in case
- one makes before looking; it also avoids recreating lexyy.c unless
- really needed.
+Jun 4, 1989:
+ ENVIRON array contains environment: if shell variable V=thing,
+ ENVIRON["V"] is "thing"
- s/aprintf/awkprint, s/asprintf/awksprintf/ to avoid some name clashes
- with unwisely-written header files.
+ multiple -f arguments permitted. error reporting is naive.
+ (they were permitted before, but only the last was used.)
- thanks to jeffrey friedl for several of these.
+ fixed a really stupid botch in the debugging macro dprintf
-May 28, 1996:
- fixed appalling but apparently unimportant bug in parsing octal
- numbers in reg exprs.
+ fixed order of evaluation of commandline assignments to match
+ what the book claims: an argument of the form x=e is evaluated
+ at the time it would have been opened if it were a filename (p 63).
+ this invalidates the suggested answer to ex 4-1 (p 195).
- explicit hex in reg exprs now limited to 2 chars: \xa, \xaa.
+ removed some code that permitted -F (space) fieldseparator,
+ since it didn't quite work right anyway. (restored aug 2)
-Jun 28, 1996:
- changed field-splitting to conform to posix definition: fields are
- split using the value of FS at the time of input; it used to be
- the value when the field or NF was first referred to, a much less
- predictable definition. thanks to arnold robbins for encouragement
- to do the right thing.
+Apr 27, 1989:
+ Line number now accumulated correctly for comment lines.
-Jun 29, 1996:
- fixed awful bug in new field splitting; didn't get all the places
- where input was done.
+Apr 26, 1989:
+ Debugging output now includes a version date,
+ if one compiles it into the source each time.
-Jul 8, 1996:
- fixed long-standing bug in sub, gsub(/a/, "\\\\&"); thanks to
- ralph corderoy.
+Apr 9, 1989:
+ Changed grammar to prohibit constants as 3rd arg of sub and gsub;
+ prevents class of overwriting-a-constant errors. (Last one?)
+ This invalidates the "banana" example on page 43 of the book.
-Jun 17, 1997:
- replaced several fixed-size arrays by dynamically-created ones
- in run.c; added overflow tests to some previously unchecked cases.
- getline, toupper, tolower.
+ Added \a ("alert"), \v (vertical tab), \xhhh (hexadecimal),
+ as in ANSI, for strings. Rescinded the sloppiness that permitted
+ non-octal digits in \ooo. Warning: not all compilers and libraries
+ will be able to deal with \x correctly.
- getline code is still broken in that recursive calls may wind
- up using the same space. [fixed later]
+Jan 9, 1989:
+ Fixed bug that caused tempcell list to contain a duplicate.
+ The fix is kludgy.
- increased RECSIZE to 8192 to push problems further over the horizon.
+Dec 17, 1988:
+ Catches some more commandline errors in main.
+ Removed redundant decl of modf in run.c (confuses some compilers).
+ Warning: there's no single declaration of malloc, etc., in awk.h
+ that seems to satisfy all compilers.
- added \r to \n as input line separator for programs, not data.
- damn CRLFs.
+Dec 7, 1988:
+ Added a bit of code to error printing to avoid printing nulls.
+ (Not clear that it actually would.)
- modified format() to permit explicit printf("%c", 0) to include
- a null byte in output. thanks to ken stailey for the fix.
+Nov 27, 1988:
+ With fear and trembling, modified the grammar to permit
+ multiple pattern-action statements on one line without
+ an explicit separator. By definition, this capitulation
+ to the ghost of ancient implementations remains undefined
+ and thus subject to change without notice or apology.
+ DO NOT COUNT ON IT.
- added a "-safe" argument that disables file output (print >,
- print >>), process creation (cmd|getline, print |, system), and
- access to the environment (ENVIRON). this is a first approximation
- to a "safe" version of awk, but don't rely on it too much. thanks
- to joan feigenbaum and matt blaze for the inspiration long ago.
+Oct 30, 1988:
+ Fixed bug in call() that failed to recover storage.
-Jul 23, 1997:
- falling off the end of a function returns "" and 0, not 0.
- thanks to arnold robbins.
+ A warning is now generated if there are more arguments
+ in the call than in the definition (in lieu of fixing
+ another storage leak).
-Jul 30, 1997:
- using code provided by dan levy (to whom profuse thanks), replaced
- fixed-size arrays and awkward kludges by a fairly uniform mechanism
- to grow arrays as needed for printf, sub, gsub, etc.
+Oct 20, 1988:
+ Fixed %c: if expr is numeric, use numeric value;
+ otherwise print 1st char of string value. still
+ doesn't work if the value is 0 -- won't print \0.
-Aug 4, 1997:
- with some trepidation, replaced the ancient code that managed
- fields and $0 in fixed-size arrays with arrays that grow on
- demand. there is still some tension between trying to make this
- run fast and making it clean; not sure it's right yet.
+ Added a few more checks for running out of malloc.
- the ill-conceived -mr and -mf arguments are now useful only
- for debugging. previous dynamic string code removed.
+Oct 12, 1988:
+ Fixed bug in call() that freed local arrays twice.
- numerous other minor cleanups along the way.
+ Fixed to handle deletion of non-existent array right;
+ complains about attempt to delete non-array element.
-Aug 9, 1997:
- somewhat regretfully, replaced the ancient lex-based lexical
- analyzer with one written in C. it's longer, generates less code,
- and more portable; the old one depended too much on mysterious
- properties of lex that were not preserved in other environments.
- in theory these recognize the same language.
+Sep 30, 1988:
+ Now guarantees to evaluate all arguments of built-in
+ functions, as in C; the appearance is that arguments
+ are evaluated before the function is called. Places
+ affected are sub (gsub was ok), substr, printf, and
+ all the built-in arithmetic functions in bltin().
+ A warning is generated if a bltin() is called with
+ the wrong number of arguments.
- now using strtod to test whether a string is a number, instead of
- the convoluted original function. should be more portable and
- reliable if strtod is implemented right.
+ This requires changing makeprof on p167 of the book.
- removed now-pointless optimization in makefile that tries to avoid
- recompilation when awkgram.y is changed but symbols are not.
+Aug 23, 1988:
+ setting FILENAME in BEGIN caused core dump, apparently
+ because it was freeing space not allocated by malloc.
- removed most fixed-size arrays, though a handful remain, some
- of which are unchecked. you have been warned.
+July 24, 1988:
+ fixed egregious error in toupper/tolower functions.
+ still subject to rescinding, however.
+
+July 2, 1988:
+ flush stdout before opening file or pipe
+
+July 2, 1988:
+ performance bug in b.c/cgoto(): not freeing some sets of states.
+ partial fix only right now, and the number of states increased
+ to make it less obvious.
+
+June 1, 1988:
+ check error status on close
+
+May 28, 1988:
+ srand returns seed value it's using.
+ see 1/18/90
+
+May 22, 1988:
+ Removed limit on depth of function calls.
+
+May 10, 1988:
+ Fixed lib.c to permit _ in commandline variable names.
+
+Mar 25, 1988:
+ main.c fixed to recognize -- as terminator of command-
+ line options. Illegal options flagged.
+ Error reporting slightly cleaned up.
+
+Dec 2, 1987:
+ Newer C compilers apply a strict scope rule to extern
+ declarations within functions. Two extern declarations in
+ lib.c and tran.c have been moved to obviate this problem.
+
+Oct xx, 1987:
+ Reluctantly added toupper and tolower functions.
+ Subject to rescinding without notice.
+
+Sep 17, 1987:
+ Error-message printer had printf(s) instead of
+ printf("%s",s); got core dumps when the message
+ included a %.
+
+Sep 12, 1987:
+ Very long printf strings caused core dump;
+ fixed aprintf, asprintf, format to catch them.
+ Can still get a core dump in printf itself.
-Aug 21, 1997:
- fixed some bugs in sub and gsub when replacement includes \\.
- this is a dark, horrible corner, but at least now i believe that
- the behavior is the same as gawk and the intended posix standard.
- thanks to arnold robbins for advice here.
diff --git a/usr.bin/awk/OpenBSD-PATCHES b/usr.bin/awk/OpenBSD-PATCHES
index ca34ad04f60..f64aee79124 100644
--- a/usr.bin/awk/OpenBSD-PATCHES
+++ b/usr.bin/awk/OpenBSD-PATCHES
@@ -1,12 +1,12 @@
-/* $OpenBSD: OpenBSD-PATCHES,v 1.2 1997/08/25 16:17:08 kstailey Exp $ */
+/* $OpenBSD: OpenBSD-PATCHES,v 1.3 1999/04/18 17:06:29 millert Exp $ */
-I merged the August 1997 version of the "one true awk" from Brian Kernighan's
+I merged the March 5, 1999 version of the "one true awk" from Brian Kernighan's
web page http://cm.bell-labs.com/who/bwk/
Mods to the distribution sources:
1) OpenBSD tags in all files.
-2) setlocate(3) call added to main().
-3) slashes in argv[0] stripped from program name in main().
+2) setlocale(3) call added to main().
+3) Use __progname instead of argv[0] to determine name.
4) left out win95 bits, distribution makefile, backup copies of yacc generated
files.
@@ -38,7 +38,7 @@ Let me know if you find more problems.
--- /home/millert/tmp/awk/awk.1 Sun Jan 19 18:06:25 1997
+++ awk.1 Sun Jan 19 17:51:39 1997
@@ -1,3 +1,4 @@
-+.\" $OpenBSD: OpenBSD-PATCHES,v 1.2 1997/08/25 16:17:08 kstailey Exp $
++.\" $OpenBSD: OpenBSD-PATCHES,v 1.3 1999/04/18 17:06:29 millert Exp $
.de EX
.nf
.ft CW
diff --git a/usr.bin/awk/README b/usr.bin/awk/README
index cd45a87bbe2..d05de5906c2 100644
--- a/usr.bin/awk/README
+++ b/usr.bin/awk/README
@@ -1,4 +1,4 @@
-/* $OpenBSD: README,v 1.2 1997/08/25 16:17:08 kstailey Exp $ */
+/* $OpenBSD: README,v 1.3 1999/04/18 17:06:29 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -54,13 +54,14 @@ conflicts: 42 shift/reduce, 83 reduce/reduce
cc -O -c lex.c
cc -O ytab.o b.o main.o parse.o proctab.o tran.o lib.o run.o lex.o -lm
-This produces an executable a.out; you will eventually
-want to move this to some place like /usr/bin/awk.
+This produces an executable a.out; you will eventually want to
+move this to some place like /usr/bin/awk.
If your system is does not have yacc or bison (the GNU
equivalent), you must compile the pieces manually. We have
included yacc output in ytab.c and ytab.h, and backup copies in
-case you overwrite them.
+case you overwrite them. We have also included a copy of
+proctab.c so you do not need to run maketab.
NOTE: This version uses ANSI C, as you should also. We have
compiled this without any changes using gcc -Wall and/or local C
@@ -68,12 +69,16 @@ compilers on a variety of systems, but new systems or compilers
may raise some new complaint; reports of difficulties are
welcome.
-This also compiles with Visual C++ 4.1 on Windows 95 and
-presumably Windows NT, *if* you provide versions of popen and
-pclose. The file missing95.c contains do-nothing versions that
-can be used to get started with. It is too much trouble to
-figure out how to make these work for real.
+This also compiles with Visual C++ on Windows 95 and Windows NT,
+*if* you provide versions of popen and pclose. The file
+missing95.c contains versions that can be used to get started
+with, though the underlying support has mysterious properties,
+the symptom of which can be truncated pipe output. Beware.
+
+This is also said to compile on Macintosh systems, using the
+file "buildmac" provided by Dan Allen (danallen@microsoft.com),
+to whom many thanks. Dan also provided buildwin.bat, a simple
+script for compiling on NT if you prefer.
The version of malloc that comes with some systems is sometimes
astonishly slow. If awk seems slow, you might try fixing that.
-
diff --git a/usr.bin/awk/b.c b/usr.bin/awk/b.c
index 8778c980d18..0553dedbdda 100644
--- a/usr.bin/awk/b.c
+++ b/usr.bin/awk/b.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: b.c,v 1.5 1997/08/25 16:17:10 kstailey Exp $ */
+/* $OpenBSD: b.c,v 1.6 1999/04/18 17:06:30 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -79,6 +79,7 @@ fa *makedfa(char *s, int anchor) /* returns dfa for reg expr s */
{
int i, use, nuse;
fa *pfa;
+ static int now = 1;
if (setvec == 0) { /* first time through any RE */
maxsetvec = MAXLIN;
@@ -93,13 +94,13 @@ fa *makedfa(char *s, int anchor) /* returns dfa for reg expr s */
for (i = 0; i < nfatab; i++) /* is it there already? */
if (fatab[i]->anchor == anchor
&& strcmp(fatab[i]->restr, s) == 0) {
- fatab[i]->use++;
+ fatab[i]->use = now++;
return fatab[i];
}
pfa = mkdfa(s, anchor);
if (nfatab < NFA) { /* room for another */
fatab[nfatab] = pfa;
- fatab[nfatab]->use = 1;
+ fatab[nfatab]->use = now++;
nfatab++;
return pfa;
}
@@ -112,7 +113,7 @@ fa *makedfa(char *s, int anchor) /* returns dfa for reg expr s */
}
freefa(fatab[nuse]);
fatab[nuse] = pfa;
- pfa->use = 1;
+ pfa->use = now++;
return pfa;
}
diff --git a/usr.bin/awk/lex.c b/usr.bin/awk/lex.c
index cb89504c0c5..688128bdc7a 100644
--- a/usr.bin/awk/lex.c
+++ b/usr.bin/awk/lex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lex.c,v 1.1 1997/08/25 16:17:11 kstailey Exp $ */
+/* $OpenBSD: lex.c,v 1.2 1999/04/18 17:06:30 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -97,7 +97,7 @@ Keyword keywords[] ={ /* keep sorted: binary searched */
#define RET(x) return(x)
#endif
-int peek()
+int peek(void)
{
int c = input();
unput(c);
@@ -144,11 +144,11 @@ int gettok(char **pbuf, int *psz) /* get next input token */
|| c == '.' || c == '+' || c == '-')
*bp++ = c;
else {
- *bp = 0;
unput(c);
break;
}
}
+ *bp = 0;
strtod(buf, &rem); /* parse the number */
unputstr(rem); /* put rest back for later */
rem[0] = 0;
diff --git a/usr.bin/awk/lib.c b/usr.bin/awk/lib.c
index 6d32b05ff07..38660b4fac3 100644
--- a/usr.bin/awk/lib.c
+++ b/usr.bin/awk/lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lib.c,v 1.4 1997/08/25 16:17:11 kstailey Exp $ */
+/* $OpenBSD: lib.c,v 1.5 1999/04/18 17:06:30 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -40,7 +40,7 @@ char *fields;
int fieldssize = RECSIZE;
Cell **fldtab; /* pointers to Cells */
-char inputFS[100];
+char inputFS[100] = " ";
#define MAXFLD 200
int nfields = MAXFLD; /* last allocated slot for $i */
@@ -114,8 +114,10 @@ int getrec(char **pbuf, int *pbufsize, int isrecord) /* get next input record */
}
dprintf( ("RS=<%s>, FS=<%s>, ARGC=%g, FILENAME=%s\n",
*RS, *FS, *ARGC, *FILENAME) );
- donefld = 0;
- donerec = 1;
+ if (isrecord) {
+ donefld = 0;
+ donerec = 1;
+ }
buf[0] = 0;
while (argno < *ARGC || infile == stdin) {
dprintf( ("argno=%d, file=|%s|\n", argno, file) );
@@ -145,7 +147,7 @@ int getrec(char **pbuf, int *pbufsize, int isrecord) /* get next input record */
xfree(fldtab[0]->sval);
fldtab[0]->sval = buf; /* buf == record */
fldtab[0]->tval = REC | STR | DONTFREE;
- if (isnumber(fldtab[0]->sval)) {
+ if (is_number(fldtab[0]->sval)) {
fldtab[0]->fval = atof(fldtab[0]->sval);
fldtab[0]->tval |= NUM;
}
@@ -240,7 +242,7 @@ void setclvar(char *s) /* set var=value from s */
p = qstring(p, '\0');
q = setsymtab(s, p, 0.0, STR, symtab);
setsval(q, p);
- if (isnumber(q->sval)) {
+ if (is_number(q->sval)) {
q->fval = atof(q->sval);
q->tval |= NUM;
}
@@ -329,7 +331,7 @@ void fldbld(void) /* create fields from current record */
donefld = 1;
for (j = 1; j <= lastfld; j++) {
p = fldtab[j];
- if(isnumber(p->sval)) {
+ if(is_number(p->sval)) {
p->fval = atof(p->sval);
p->tval |= NUM;
}
@@ -439,34 +441,28 @@ void recbld(void) /* create $0 from $1..$NF if necessary */
{
int i;
char *r, *p;
- char *buf = record;
- int bufsize = recsize;
if (donerec == 1)
return;
- r = buf;
+ r = record;
for (i = 1; i <= *NF; i++) {
p = getsval(fldtab[i]);
- if (!adjbuf(&buf, &bufsize, 1+strlen(p)+r-buf, recsize, &r, "recbld 1"))
- ERROR "created $0 `%.30s...' too long", buf FATAL;
+ if (!adjbuf(&record, &recsize, 1+strlen(p)+r-record, recsize, &r, "recbld 1"))
+ ERROR "created $0 `%.30s...' too long", record FATAL;
while ((*r = *p++) != 0)
r++;
if (i < *NF) {
- if (!adjbuf(&buf, &bufsize, 2+strlen(*OFS)+r-buf, recsize, &r, "recbld 2"))
- ERROR "created $0 `%.30s...' too long", buf FATAL;
+ if (!adjbuf(&record, &recsize, 2+strlen(*OFS)+r-record, recsize, &r, "recbld 2"))
+ ERROR "created $0 `%.30s...' too long", record FATAL;
for (p = *OFS; (*r = *p++) != 0; )
r++;
}
}
- if (!adjbuf(&buf, &bufsize, 2+r-buf, recsize, &r, "recbld 3"))
- ERROR "built giant record `%.30s...'", buf FATAL;
+ if (!adjbuf(&record, &recsize, 2+r-record, recsize, &r, "recbld 3"))
+ ERROR "built giant record `%.30s...'", record FATAL;
*r = '\0';
dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, fldtab[0]) );
- if (buf != record) { /* increased size of record */
- record = buf; /* BUG? memory leak? */
- recsize = bufsize;
- }
if (freeable(fldtab[0]))
xfree(fldtab[0]->sval);
fldtab[0]->tval = REC | STR | DONTFREE;
@@ -635,7 +631,7 @@ int isclvar(char *s) /* is s of form var=something ? */
/* strtod is supposed to be a proper test of what's a valid number */
#include <math.h>
-int isnumber(char *s)
+int is_number(char *s)
{
double r;
char *ep;
diff --git a/usr.bin/awk/main.c b/usr.bin/awk/main.c
index 4a3a708fd84..7fb6b080da5 100644
--- a/usr.bin/awk/main.c
+++ b/usr.bin/awk/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.5 1998/03/03 01:56:01 angelos Exp $ */
+/* $OpenBSD: main.c,v 1.6 1999/04/18 17:06:30 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -23,7 +23,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
****************************************************************/
-char *version = "version 970821";
+char *version = "version 990305";
#define DEBUG
#include <stdio.h>
@@ -37,6 +37,7 @@ char *version = "version 970821";
extern char **environ;
extern int nfields;
+extern char *__progname;
int dbg = 0;
char *cmdname; /* gets argv[0] for error messages */
@@ -59,10 +60,7 @@ int main(int argc, char *argv[])
setlocale(LC_ALL, "");
- if ((cmdname = strrchr(argv[0], '/')) != NULL)
- cmdname++;
- else
- cmdname = argv[0];
+ cmdname = __progname;
if (argc == 1) {
fprintf(stderr, "Usage: %s [-f programfile | 'program'] [-Ffieldsep] [-v var=value] [-safe] [-mrn] [-mfn] [files]\n", cmdname);
exit(1);
@@ -129,6 +127,10 @@ int main(int argc, char *argv[])
dbg = 1;
printf("awk %s\n", version);
break;
+ case 'V': /* added for exptools "standard" */
+ printf("awk %s\n", version);
+ exit(0);
+ break;
default:
ERROR "unknown option %s ignored", argv[1] WARNING;
break;
diff --git a/usr.bin/awk/maketab.c b/usr.bin/awk/maketab.c
index 6d00aa055ef..8cdc86b804e 100644
--- a/usr.bin/awk/maketab.c
+++ b/usr.bin/awk/maketab.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: maketab.c,v 1.2 1997/08/25 16:17:12 kstailey Exp $ */
+/* $OpenBSD: maketab.c,v 1.3 1999/04/18 17:06:30 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -78,7 +78,7 @@ struct xx
{ PRINTF, "awkprintf", "printf" },
{ PRINT, "printstat", "print" },
{ CLOSE, "closefile", "closefile" },
- { DELETE, "adelete", "adelete" },
+ { DELETE, "awkdelete", "awkdelete" },
{ SPLIT, "split", "split" },
{ ASSIGN, "assign", " = " },
{ ADDEQ, "assign", " += " },
diff --git a/usr.bin/awk/proto.h b/usr.bin/awk/proto.h
index 183fcffc602..4c109137d11 100644
--- a/usr.bin/awk/proto.h
+++ b/usr.bin/awk/proto.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proto.h,v 1.3 1997/08/25 16:17:13 kstailey Exp $ */
+/* $OpenBSD: proto.h,v 1.4 1999/04/18 17:06:30 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -133,7 +133,7 @@ extern void eprint(void);
extern void bclass(int);
extern double errcheck(double, char *);
extern int isclvar(char *);
-extern int isnumber(char *);
+extern int is_number(char *);
extern int adjbuf(char **pb, int *sz, int min, int q, char **pbp, char *what);
extern void run(Node *);
@@ -146,7 +146,7 @@ extern Cell *jump(Node **, int);
extern Cell *getline(Node **, int);
extern Cell *getnf(Node **, int);
extern Cell *array(Node **, int);
-extern Cell *adelete(Node **, int);
+extern Cell *awkdelete(Node **, int);
extern Cell *intest(Node **, int);
extern Cell *matchop(Node **, int);
extern Cell *boolop(Node **, int);
diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c
index 56444eca3e9..9a1c96c8b66 100644
--- a/usr.bin/awk/run.c
+++ b/usr.bin/awk/run.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: run.c,v 1.13 1997/08/25 16:17:14 kstailey Exp $ */
+/* $OpenBSD: run.c,v 1.14 1999/04/18 17:06:31 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -283,6 +283,7 @@ Cell *call(Node **a, int n) /* function call. very kludgy and fragile */
if (i >= ncall) {
freesymtab(t);
t->csub = CTEMP;
+ tempfree(t);
} else {
oargs[i]->tval = t->tval;
oargs[i]->tval &= ~(STR|NUM|DONTFREE);
@@ -338,7 +339,7 @@ Cell *jump(Node **a, int n) /* break, continue, next, nextfile, return */
case EXIT:
if (a[0] != NULL) {
y = execute(a[0]);
- errorflag = getfval(y);
+ errorflag = (int) getfval(y);
tempfree(y);
}
longjmp(env, 1);
@@ -405,7 +406,7 @@ Cell *getline(Node **a, int n) /* get next line from specific input */
tempfree(x);
} else { /* getline <file */
setsval(fldtab[0], buf);
- if (isnumber(fldtab[0]->sval)) {
+ if (is_number(fldtab[0]->sval)) {
fldtab[0]->fval = atof(fldtab[0]->sval);
fldtab[0]->tval |= NUM;
}
@@ -472,7 +473,7 @@ Cell *array(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */
return(z);
}
-Cell *adelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */
+Cell *awkdelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */
{
Cell *x, *y;
Node *np;
@@ -697,8 +698,8 @@ Cell *indirect(Node **a, int n) /* $( a[0] ) */
char *s;
x = execute(a[0]);
- m = getfval(x);
- if (m == 0 && !isnumber(s = getsval(x))) /* suspicion! */
+ m = (int) getfval(x);
+ if (m == 0 && !is_number(s = getsval(x))) /* suspicion! */
ERROR "illegal field $(%s), name \"%s\"", s, x->nval FATAL;
/* BUG: can x->nval ever be null??? */
tempfree(x);
@@ -730,14 +731,14 @@ Cell *substr(Node **a, int nnn) /* substr(a[0], a[1], a[2]) */
setsval(x, "");
return(x);
}
- m = getfval(y);
+ m = (int) getfval(y);
if (m <= 0)
m = 1;
else if (m > k)
m = k;
tempfree(y);
if (a[2] != 0) {
- n = getfval(z);
+ n = (int) getfval(z);
tempfree(z);
} else
n = k - 1;
@@ -1223,7 +1224,7 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
sprintf(num, "%d", n);
temp = *patbeg;
*patbeg = '\0';
- if (isnumber(s))
+ if (is_number(s))
setsymtab(num, s, atof(s), STR|NUM, (Array *) ap->sval);
else
setsymtab(num, s, 0.0, STR, (Array *) ap->sval);
@@ -1240,7 +1241,7 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
}
n++;
sprintf(num, "%d", n);
- if (isnumber(s))
+ if (is_number(s))
setsymtab(num, s, atof(s), STR|NUM, (Array *) ap->sval);
else
setsymtab(num, s, 0.0, STR, (Array *) ap->sval);
@@ -1260,7 +1261,7 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
temp = *s;
*s = '\0';
sprintf(num, "%d", n);
- if (isnumber(t))
+ if (is_number(t))
setsymtab(num, t, atof(t), STR|NUM, (Array *) ap->sval);
else
setsymtab(num, t, 0.0, STR, (Array *) ap->sval);
@@ -1289,7 +1290,7 @@ Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
temp = *s;
*s = '\0';
sprintf(num, "%d", n);
- if (isnumber(t))
+ if (is_number(t))
setsymtab(num, t, atof(t), STR|NUM, (Array *) ap->sval);
else
setsymtab(num, t, 0.0, STR, (Array *) ap->sval);
@@ -1482,7 +1483,7 @@ 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);
- srand((int) u); u = (int) u;
+ srand((unsigned int) u);
break;
case FTOUPPER:
case FTOLOWER:
diff --git a/usr.bin/awk/tran.c b/usr.bin/awk/tran.c
index ec26449be42..cbbb00778ec 100644
--- a/usr.bin/awk/tran.c
+++ b/usr.bin/awk/tran.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tran.c,v 1.3 1997/08/25 16:17:14 kstailey Exp $ */
+/* $OpenBSD: tran.c,v 1.4 1999/04/18 17:06:31 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -108,7 +108,7 @@ void arginit(int ac, char **av) /* set up ARGV and ARGC */
cp->sval = (char *) ARGVtab;
for (i = 0; i < ac; i++) {
sprintf(temp, "%d", i);
- if (isnumber(*av))
+ if (is_number(*av))
setsymtab(temp, *av, atof(*av), STR|NUM, ARGVtab);
else
setsymtab(temp, *av, 0.0, STR, ARGVtab);
@@ -128,7 +128,7 @@ void envinit(char **envp) /* set up ENVIRON variable */
if ((p = strchr(*envp, '=')) == NULL)
continue;
*p++ = 0; /* split into two strings at = */
- if (isnumber(p))
+ if (is_number(p))
setsymtab(*envp, p, atof(p), STR|NUM, ENVtab);
else
setsymtab(*envp, p, 0.0, STR, ENVtab);
@@ -288,6 +288,8 @@ Awkfloat setfval(Cell *vp, Awkfloat f) /* set float val of a Cell */
donefld = 0; /* mark $1... invalid */
donerec = 1;
}
+ if (freeable(vp))
+ 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, vp->nval, f, vp->tval) );
@@ -342,7 +344,7 @@ Awkfloat getfval(Cell *vp) /* get float val of a Cell */
recbld();
if (!isnum(vp)) { /* not a number */
vp->fval = atof(vp->sval); /* best guess */
- if (isnumber(vp->sval) && !(vp->tval&CON))
+ if (is_number(vp->sval) && !(vp->tval&CON))
vp->tval |= NUM; /* make NUM only sparingly */
}
dprintf( ("getfval %p: %s = %g, t=%o\n", vp, vp->nval, vp->fval, vp->tval) );