Update vendor branch to gawk-3.0.6.

This commit is contained in:
Sheldon Hearn 2000-08-15 10:02:07 +00:00
parent 7513a7dcd4
commit 4192247c04
144 changed files with 33603 additions and 294 deletions

View File

@ -1,3 +1,297 @@
Mon Aug 7 15:23:00 2000 Arnold D. Robbins <arnold@skeeve.com>
* Release 3.0.6: Release tar file made.
Thu Aug 3 17:47:53 2000 Greg McGary <greg@mcgary.org>
* regex.c: patches for gcc bounded pointer handling.
Thu Aug 3 13:09:09 2000 Arnold D. Robbins <arnold@skeeve.com>
* array.c (in_array, do_delete): fix tests for index equality
when searching through the array to work correctly when
index is "".
Fri Jul 14 21:40:17 2000 Pat Rankin <rankin@eql.caltech.edu>
* builtin.c (format_tree): Workaround a DEC C V5.7 bug by
splitting `strcpy() + 3' into two expressions (the builtin
inline strcpy evidently has erroneous return type of void *
instead of char *; reputedly fixed in V6.1).
* eval.c (C): New macro.
[casetable]: Use it to add explicit casts for the character
values outside the range of 0 to 127.
* missing/strncasecmp.c [C, charmap]: Likewise.
* io.c (redirect): Add EIO check on failed open for VMS.
Fri Jul 14 11:57:23 2000 Arnold D. Robbins <arnold@skeeve.com>
Efficiency hack: turn `for (iggy in foo) delete foo[iggy]'
into moral equivalent of `delete foo'.
* array.c (do_delete_loop): new routine.
* awk.h [NODETYPE]: new Node_K_delete_loop value.
Add declaration of do_delete_loop.
* awk.y [LEX_FOR]: Fix code to recognize special case.
* eval.c (nodetypes): new entry for Node_K_delete_loop.
(interpret): add case for Node_K_delete_loop, add more
diagnostic info in default (cant_happen) case.
Tue Jul 11 22:15:10 2000 Pat Rankin <rankin@eql.caltech.edu>
* awk.y (nextc): Recast unsigned char values back to int to
prevent VAX C from truncating EOF to 255.
Tue Jul 11 14:08:23 2000 Arnold D. Robbins <arnold@skeeve.com>
* array.c (do_delete): switch to string comparison, not
cmp_nodes.
(assoc_find): add call to force_string on subscript.
* eval.c (interpret): Case Node_K_arrayfor: check for
Node_array_ref and fetch original_array. Yowser.
Fri Jun 30 21:57:00 2000 Arnold D. Robbins <arnold@skeeve.com>
* array.c (assoc_lookup): Don't force the subscript
to be a string. Not a good idea after the change
to using dupnode.
Sun Jun 25 15:08:19 2000 Arnold D. Robbins <arnold@skeeve.com>
* Release 3.0.5: Release tar file made.
Wed Jun 14 13:03:45 2000 Arnold D. Robbins <arnold@skeeve.com>
* field.c (set_record): manage a private buffer for $0.
Keeps things safe in case `getline var' rearranges the
IOBUF's contents that $0 is still pointing into.
Tue Jun 13 16:27:55 2000 Paul Eggert <eggert@twinsun.com>
Upgrade to latest and greatest version of largefile code.
* configure.in (AC_CANONICAL_HOST): Remove.
(GAWK_AC_SYS_LARGEFILE): Defer until after AC_MINIX,
to avoid autoconf warnings.
Rewrite largefile configuration so that we don't need to run
getconf and don't need AC_CANONICAL_HOST.
* config.guess, config.sub: Remove these files.
* Makefile.in (MISC): Remove config.guess, config.sub.
* m4/largefile.m4 (GAWK_AC_SYS_LARGEFILE_FLAGS,
GAWK_AC_SYS_LARGEFILE_SPACE_APPEND): Remove.
(GAWK_AC_SYS_LARGEFILE_TEST_INCLUDES): New macro.
(GAWK_AC_SYS_LARGEFILE_MACRO_VALUE): Change arguments from
CODE-TO-SET-DEFAULT to VALUE, INCLUDES, FUNCTION-BODY.
All uses changed.
Instead of inspecting the output of getconf, try to compile the
test program without and with the macro definition.
(GAWK_AC_SYS_LARGEFILE): Do not require AC_CANONICAL_HOST or check
for getconf. Instead, check for the needed flags by compiling
test programs.
(GAWK_AC_SYS_LARGEFILE): Define _XOPEN_SOURCE to be 500 to
work around glibc 2.1.3 bug.
(GAWK_AC_SYS_LARGEFILE_FLAGS): Don't use -n32 on IRIX if the
installer said otherwise.
(GAWK_AC_SYS_LARGEFILE_FLAGS): Work around a bug in the QNX shell,
which doesn't propagate exit status of failed commands inside
shell assignments.
Wed Jun 7 13:23:09 2000 Arnold D. Robbins <arnold@skeeve.com>
* Updated copyright dates in appropriate files.
Mon May 22 17:29:43 2000 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (clean): get `*/core' too.
Sun May 7 16:33:05 2000 Arnold D. Robbins <arnold@skeeve.com>
* array.c (concat_exp): Change ref to `lnode->stlen' and
`lnode->stptr' for SUBSEP to use `var_value->...'.
Tue May 2 09:54:29 2000 Arnold D. Robbins <arnold@skeeve.com>
Fix referencing freed memory as shown by test/arynocls.* tests.
* awk.h [Node_array_ref]: new node type.
[orig_array]: new macro element in NODE structure.
* field.c (do_split): handle case for Node_array_ref, fetch
the original array.
* array.c (in_array, do_delete): ditto.
* eval.c (nodetypes[]): add Node_array_ref string.
(r_tree_eval): handle case for Node_array_ref.
(push_args): push arrays as Node_array_ref, and pass them on.
(pop_fcall): don't unref lnode if it's an array when releasing
local arguments. Check for both Node_array and Node_array_ref.
(r_get_lhs): choke on Node_array_ref as for Node_array.
For Node_subscript, handle Node_array_ref.
Tue May 2 09:52:12 2000 Bruno Haible <haible@clisp.cons.org>
* io.c (redirect): After reopening a `struct redirect', move it to
the head of the list.
Sun Apr 2 17:51:40 2000 Arnold D. Robbins <arnold@skeeve.com>
* re.c (re_update): Check if IGNORECASE has changed, and
if so recompute the re. See test/igncdym.awk.
Mon Mar 20 16:18:34 2000 Arnold D. Robbins <arnold@skeeve.com>
* io.c (set_RS): Added a lint warning about multicharacter RS,
per suggestion from Akim DeMaille (akim@epita.fr).
Sun Feb 13 14:40:32 2000 Arnold D. Robbins <arnold@skeeve.com>
* eval.c (push_args): Fix from Nide Naoyuki <nide@ics.nara-wu.ac.jp>,
re-assign `f' in case tree_eval moved fcall_list around.
Sun Feb 6 11:39:33 2000 Arnold D. Robbins <arnold@skeeve.com>
* eval.c (op_assign): Fix it right. For ++ and --, get the lhs
in the operations, do the op, and then return. For += etc,
get the rhs FIRST, since the lhs can move around as a result,
*then* get the lhs and do the operation. See test/opasnidx.awk.
Tue Feb 1 18:41:40 2000 Arnold D. Robbins <arnold@skeeve.com>
* eval.c (op_assign): reget the rval after regetting
the left hand side. See test/opasnslf.awk for why.
Thu Jan 27 18:06:31 2000 Arnold D. Robbins <arnold@skeeve.com>
* awk.y (yylex): Made ']' not one of the characters
that sets `want_assign' to false. `a[i] /= 2' was
broken. Per bug report from Kristofer T. Karas
<ktk@ktk.bidmc.harvard.edu>.
Wed Dec 22 15:06:37 1999 Arnold D. Robbins <arnold@skeeve.com>
* awk.y: Removed declarations of functions before
definition of `tokentab[]'. They're redundant with
what's in awk.h.
Thu Dec 9 17:01:07 1999 Arnold D. Robbins <arnold@skeeve.com>
* node.c (parse_escape): Add lint warning for unrecognized
escape sequences.
Mon Dec 6 15:17:34 1999 Arnold D. Robbins <arnold@skeeve.com>
* main.c (usage): Changed bug reporting email addresses to
be a reference to `Bugs' node in the online and printed
doc, instead.
Thu Dec 2 13:08:18 1999 Arnold D. Robbins <arnold@skeeve.com>
* builtin.c (do_compl): test `d' for negative inside the do_lint
test, not uval. Ooops.
Fri Nov 26 10:58:36 1999 Arnold D. Robbins <arnold@skeeve.com>
* array.c (assoc_find): ALWAYS compare indexes as strings,
don't use cmp_nodes in case they are numeric. Oh my.
Talk about a Day 1 bug!
Tue Nov 23 11:58:53 1999 Arnold D. Robbins <arnold@skeeve.com>
* regex.c (SYNTAX): cast argument to `unsigned char' instead of
&-ing with 0xFF. Hopefully somewhat more portable, ala 21 Nov 99
changes to awk.y.
Sun Nov 21 22:25:27 1999 Paul Eggert <eggert@twinsun.com>
* aclocal.m4 (AC_SYS_LARGEFILE_FLAGS): Work around a
problem with the QNX 4.25 shell, which doesn't propagate exit
status of failed commands inside shell assignments.
Sun Nov 21 20:33:35 1999 Arnold D. Robbins <arnold@skeeve.com>
* awk.h (nextc): remove declaration, don't need it here.
awk.y (nextc): Cast values to unsigned char so that latin-1
characters in strings don't turn themselves into EOF.
Most notably y-umlaut, which is decimal 255.
Mon Nov 1 20:00:25 1999 Arnold D. Robbins <arnold@skeeve.com>
* regex.c (init_syntax_once): move below definition of
ISALNUM etc., then use ISALNUM to init the table, so that
the word ops will work if i18n'ed.
(SYNTAX): And subscript with 0xFF for Latin-1 characters.
Mon Oct 25 18:37:13 1999 Arnold D. Robbins <arnold@skeeve.com>
* awk.h, main.c, io.c: undo previous changes (22 Oct 1999).
* main.c (main): move call to `init_fields()' to before
arg parsing. This allows `-v NF=blah' to work ok.
Fri Oct 22 17:43:40 1999 Arnold D. Robbins <arnold@skeeve.com>
* main.c (arg_assign): Add new arg, `initing' for icky special
casing of -v of special variables. Use it to check for NF.
May need to add other cases later.
(pre_assign): change call arg_assign, passing initing=TRUE;
io.c (nextfile): change call arg_assign, passing initing=FALSE;
awk.h: Change prototype for arg_assign.
Tue Oct 19 16:06:48 1999 Paul Eggert <eggert@twinsun.com>
* io.c (close_redir): Don't munge errno between setting it and
using it.
Wed Oct 6 17:47:47 1999 Arnold D. Robbins <arnold@skeeve.com>
* main.c (arg_assign): return NULL on bad variable. Allows
things like `./3x=stuff' to work as a filename.
Thu Sep 23 21:35:46 1999 Paul Eggert <eggert@twinsun.com>
* aclocal.m4 (GAWK_AC_SYS_LARGEFILE_FLAGS): Work around GCC
2.95.1 bug in HP-UX 10.20 or later. (Had to fix the fix. ADR. :-)
Tue Sep 21 13:31:36 1999 Arnold D. Robbins <arnold@skeeve.com>
* builtin.c (format_tree): For '0', only set zero_flag if we
haven't seen the field width or precision yet.
Mon Aug 9 13:06:01 1999 Arnold D. Robbins <arnold@skeeve.com>
* array.c (assoc_lookup): Removed code that gave each array
a private copy of each index. Balloons memory usage for
no good reason that I can see. Just use dupnode in all
cases.
* configure.in: check for $srcdir/.developing adds extra
defines for my testing/debugging use. Yes, hack alert.
Sun Aug 1 11:02:02 1999 Arnold D. Robbins <arnold@skeeve.com>
* node.c (dupnode): turn off FIELD when copying nodes.
* array.c (do_adump, assoc_dump): new functions for array debugging.
* awk.y (tokentab): conditionally add "adump" function for debugging.
* awk.h: delcare new functions.
Thu Jul 29 23:26:40 1999 Arnold D. Robbins <arnold@skeeve.com>
From wsanchez@apple.com:
* Makefile.in (install-strip): new target, coding stds. compatibility.
* config.guess, config.sub: Add MacOS X recognition.
Thu Jul 29 19:09:19 1999 Arnold D. Robbins <arnold@skeeve.com>
* awk.y (func_install): make `function foo(foo)' a fatal error.
eval.c (r_tree_eval): diagnose use of a function name as a
variable inside the function.
Sun Jul 4 16:53:14 1999 Arnold D. Robbins <arnold@skeeve.com>
* eval.c (eval_condition): add extra braces to avoid
gcc warning. I'm not going to bother for the library
code like dfa and regex.
Wed Jun 30 16:14:36 1999 Arnold D. Robbins <arnold@gnu.org>
* Release 3.0.4: Release tar file made. This time for sure.
@ -103,7 +397,7 @@ Wed Apr 28 12:27:49 1999 Arnold D. Robbins <arnold@gnu.org>
Sun Apr 25 13:39:16 1999 Arnold D. Robbins <arnold@gnu.org>
* Makefile.in (gawk): add $(CFLAGS) to linking step.
* configure.in: correctly do AC_FUNC_GETPRGP on HP systems too.
* configure.in: correctly do AC_FUNC_GETPGRP on HP systems too.
Tue Apr 13 20:21:00 1999 Arnold D. Robbins <arnold@gnu.org>
@ -149,7 +443,7 @@ Sun Nov 1 15:24:52 1998 Arnold D. Robbins <arnold@gnu.org>
Wed Oct 28 20:40:17 1998 Arnold D. Robbins <arnold@gnu.org>
* eval.c (r_tree_eval): Case for Node_concat. Get lengthes
* eval.c (r_tree_eval): Case for Node_concat. Get lengths
separately, in case one expression has a side effect that
that changes another. Ugly, but it keeps gawk from core
dumping. See test/nasty.awk.
@ -418,7 +712,7 @@ Mon Apr 7 18:22:37 1997 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* awk.h: Add decls of new routines do_compl() and set_loc().
* awk.y (tokentab): add entry for "compl" function.
* builtin.c (do_compl): new functionto do ones complement.
* builtin.c (do_compl): new function to do ones complement.
(do_substr): rationalized yet again, now notices negative start
and length parameters.
* eval.c (push_args): fix if call_list gets realloc'ed in the
@ -517,7 +811,7 @@ Wed Feb 19 23:29:02 1997 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
Fri Feb 14 09:47:31 1997 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* io.c [#include "awk.h"]: undef HAVE_MMAP to just use thoe old code.
* io.c [#include "awk.h"]: undef HAVE_MMAP to just use the old code.
Something is causing a file descriptor leak, and this is getting to
be just too much hair. I reserve the right to rip out the mmap
code entirely at a future date.
@ -616,7 +910,7 @@ Wed Dec 18 10:09:44 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* configure.in [AC_PREREQ]: Update to 2.12 in order to switch to
autoconf 2.12. Lots of other files will be rebuilt automatically.
[AM_SANITY_CHECK_CC]: Removed, autoconf does it now.
* alocal.m4 [AM_SANITY_CHECK_CC]: Removed, autoconf does it now.
* aclocal.m4 [AM_SANITY_CHECK_CC]: Removed, autoconf does it now.
Tue Dec 17 22:23:16 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
@ -808,7 +1102,7 @@ Fri Sep 20 17:35:54 1996 Pat Rankin <rankin@eql.caltech.edu>
Fri Sep 20 11:54:31 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* builtin.c (do_print): evaluate all the expressions first and
then print them. Avoids suprising behavior. See test/prtoeval.awk
then print them. Avoids surprising behavior. See test/prtoeval.awk
for an example.
Tue Sep 10 06:21:40 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
@ -976,7 +1270,7 @@ Fri May 17 08:46:07 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
Wed May 15 02:34:55 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* Makefile.in (awklib/all): now depends on gawk, fixes problem
with parrallel make.
with parallel make.
Tue May 14 15:02:52 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
@ -1027,7 +1321,7 @@ Thu Mar 7 08:08:51 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* field.c (set_NF): If NF is decremented, clear fields between
NF and parse_high_water, otherwise if NF incremented, clear
fields between parse_high_water and NF.
* eval.c (nodetype2str): new function, used for diganostics.
* eval.c (nodetype2str): new function, used for diagnostics.
eval.c (interpret): use nodetype2str when finding invalid node.
Mon Mar 4 09:02:28 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
@ -1066,7 +1360,7 @@ Thu Feb 1 08:56:46 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
Sun Jan 28 07:00:56 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* builtin.c (do_substr): rationalized handling of missing length
argument, as well as various accompagnying lint warnings. Previous
argument, as well as various accompanying lint warnings. Previous
code was slightly bogus. Talk about your Day 1 bugs.
Thu Jan 25 14:09:11 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>

286
contrib/awk/Makefile.in Normal file
View File

@ -0,0 +1,286 @@
# Makefile for GNU Awk.
#
# Copyright (C) 1986, 1988-2000 the Free Software Foundation, Inc.
#
# This file is part of GAWK, the GNU implementation of the
# AWK Programming Language.
#
# GAWK is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# GAWK is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
@SET_MAKE@
MAKEINFO = makeinfo --no-split
srcdir = @srcdir@
VPATH = @srcdir@
CC = @CC@
YACC = @YACC@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
ALLOCA = @ALLOCA@
LN = ln
LN_S = @LN_S@
exec_prefix = @exec_prefix@
prefix = @prefix@
binprefix =
manprefix =
bindir = @bindir@
libdir = @libdir@
manexta = 1
mandir = @mandir@/man$(manexta)
manext = .$(manexta)
infodir = @infodir@
datadir = @datadir@/awk
libexecdir = @libexecdir@/awk
DEFPATH = ".:$(datadir)"
SHELL = /bin/sh
CPPFLAGS = @CPPFLAGS@
CFLAGS = @CFLAGS@
COMPFLAGS = -DGAWK -I. -I$(srcdir) $(CPPFLAGS) @DEFS@ $(CFLAGS)
# object files
AWKOBJS = array.o builtin.o eval.o field.o gawkmisc.o io.o main.o \
missing.o msg.o node.o re.o version.o
ALLOBJS = $(AWKOBJS) awktab.o
# LIBOBJS
# GNU and other stuff that gawk uses as library routines.
LIBOBJS= getopt.o getopt1.o regex.o dfa.o random.o $(ALLOCA)
# source and documentation files
SRC = array.c builtin.c eval.c field.c gawkmisc.c io.c main.c \
missing.c msg.c node.c re.c version.c
ALLSRC= $(SRC) awktab.c
AWKSRC= awk.h awk.y custom.h $(ALLSRC) patchlevel.h protos.h random.h
LIBSRC = alloca.c dfa.c dfa.h regex.c regex.h getopt.h getopt.c getopt1.c random.c
COPIES = missing/system.c missing/tzset.c \
missing/memcmp.c missing/memcpy.c missing/memset.c \
missing/strncasecmp.c missing/strchr.c \
missing/strerror.c missing/strtod.c \
missing/strftime.c missing/strftime.3
DOCS= doc/gawk.1 doc/gawk.texi doc/texinfo.tex
TEXFILES= doc/gawk.aux doc/gawk.cp doc/gawk.cps doc/gawk.fn doc/gawk.fns \
doc/gawk.ky doc/gawk.kys doc/gawk.pg doc/gawk.pgs doc/gawk.toc \
doc/gawk.tp doc/gawk.tps doc/gawk.vr doc/gawk.vrs
MISC = NEWS COPYING FUTURES Makefile.in PROBLEMS README PORTS POSIX.STD \
configure configure.in acconfig.h configh.in ACKNOWLEDGMENT \
ChangeLog INSTALL LIMITATIONS install-sh mkinstalldirs aclocal.m4 \
stamp-h.in
OTHERS= doc pc atari vms README_d posix awklib
ALLDOC= doc/gawk.dvi $(TEXFILES) doc/gawk.info*
MAKEFILEIN = Makefile.in awklib/Makefile.in doc/Makefile.in test/Makefile.in
# Release of gawk. There can be no leading or trailing white space here!
REL=3.0
# clear out suffixes list
.SUFFIXES:
.SUFFIXES: .c .o
.c.o:
$(CC) -c $(COMPFLAGS) $<
# rules to build gawk
all: gawk awklib/all doc/all
# stuff to make sure that configure has been run.
$(srcdir)/configure: configure.in aclocal.m4
cd $(srcdir) && autoconf
# autoheader might not change confh.in, so touch a stamp file
$(srcdir)/configh.in: stamp-h.in
$(srcdir)/stamp-h.in: configure.in aclocal.m4 acconfig.h
cd $(srcdir) && autoheader
date > $(srcdir)/stamp-h.in
config.h: stamp-h
stamp-h: configh.in config.status
$(SHELL) ./config.status
Makefile: $(MAKEFILEIN) config.status
$(SHELL) ./config.status
config.status: configure
$(SHELL) ./config.status --recheck
# Note: if you need something at both compile time and link time, like -pg,
# you will have to edit the Makefile manually to set LDFLAGS.
gawk: $(ALLOBJS) $(LIBOBJS) $(REOBJS)
$(CC) -o gawk $(CFLAGS) $(LDFLAGS) $(ALLOBJS) $(LIBOBJS) $(REOBJS) $(LIBS)
$(ALLOBJS): awk.h dfa.h regex.h config.h custom.h
$(LIBOBJS): config.h custom.h
# SunOS make's (at least) VPATH doesn't do subdirectories...
# Solaris make doesn't allow $< in the actual rule
gawkmisc.o: $(srcdir)/atari/gawkmisc.atr \
$(srcdir)/pc/gawkmisc.pc $(srcdir)/posix/gawkmisc.c \
$(srcdir)/vms/gawkmisc.vms
$(CC) -c $(COMPFLAGS) -DDEFPATH='$(DEFPATH)' $(srcdir)/gawkmisc.c
getopt.o: getopt.h
getopt1.o: getopt.h
builtin.o: random.h
main.o: patchlevel.h
awktab.c: awk.y
$(YACC) -v $(srcdir)/awk.y && \
if test -f y.tab.c ; then mv y.tab.c ytab.c ; else true ; fi && \
sed '/^extern char .malloc(), .realloc();$$/d' ytab.c >awktab.c && \
rm ytab.c
# VMS POSIX make won't apply the default .c.o rule to awktab.o for some reason
awktab.o: awktab.c awk.h
$(CC) -c $(COMPFLAGS) $(srcdir)/awktab.c
alloca.o: alloca.c
install: gawk info installdirs
-rm -f $(bindir)/gawk
fullname=gawk-$(REL).`./gawk '{print $$3}' $(srcdir)/patchlevel.h` ; \
$(INSTALL_PROGRAM) gawk $(bindir)/$$fullname ; \
(cd $(bindir); $(LN) $$fullname gawk)
(cd $(bindir); \
if [ ! -f awk ]; \
then $(LN_S) gawk awk; \
fi; exit 0)
cd doc && $(MAKE) install
cd awklib && $(MAKE) install
installdirs: mkinstalldirs
$(srcdir)/mkinstalldirs $(bindir) $(datadir) \
$(libdir) $(infodir) $(mandir) $(libexecdir)
install-strip:
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
uninstall:
(cd $(bindir); \
if [ -f awk ] && cmp awk gawk > /dev/null; then rm -f awk; fi)
(fullname=gawk-$(REL).`gawk '{print $$3}' $(srcdir)/patchlevel.h` ; \
cd $(bindir); \
if cmp gawk $$fullname; then rm -f gawk; fi ; \
rm -f $(bindir)/$$fullname)
cd doc && $(MAKE) uninstall
cd awklib && $(MAKE) uninstall
-rmdir $(datadir) $(libexecdir)
# auxiliary rules for release maintenance
lint: $(ALLSRC)
lint -hcbax $(COMPFLAGS) $(ALLSRC)
xref:
cxref -c $(COMPFLAGS) $(ALLSRC) | grep -v ' /' >xref
mostlyclean:
: mostly clean does nothing for gawk
: use "make clean" to really clean things out
clean:
rm -rf gawk *.o core */core y.output
cd doc && $(MAKE) clean
cd test && $(MAKE) clean
cd awklib && $(MAKE) clean
local-distclean:
rm -f Makefile *.orig *.rej */*.orig */*.rej awk.output \
gmon.out make.out config.h config.status config.cache \
config.log stamp-h tags TAGS *~
distclean: clean local-distclean
cd doc && $(MAKE) distclean
cd awklib && $(MAKE) distclean
cd test && $(MAKE) distclean
maintainer-clean: clean local-distclean
@echo "This command is intended for maintainers to use; it"
@echo "deletes files that may require special tools to rebuild."
rm -f awktab.c
cd doc && $(MAKE) maintainer-clean
cd test && $(MAKE) maintainer-clean
cd awklib && $(MAKE) maintainer-clean
clobber: maintainer-clean
TAGS:
etags $(AWKSRC)
tags:
ctags $(AWKSRC)
dvi: $(srcdir)/doc/gawk.texi
cd doc && $(MAKE) dvi
info: $(srcdir)/doc/gawk.texi
cd doc && $(MAKE) info
doc/all:
cd doc && $(MAKE) all
awklib/all: gawk
cd awklib && $(MAKE) CFLAGS="$(CFLAGS)" all
dist: $(AWKSRC) $(LIBSRC) $(DOCS) $(MISC) $(COPIES) awklib/stamp-eg info distclean
-rm -rf gawk-$(REL)*
dir=gawk-$(REL).`gawk '{print $$3}' patchlevel.h` && \
mkdir $$dir && \
cp -pr $(AWKSRC) $(LIBSRC) $(MISC) $$dir && \
mkdir $$dir/missing && \
cp -p $(COPIES) $$dir/missing && \
for i in $(OTHERS); \
do \
cp -pr $$i $$dir ; \
done && \
cp -pr test $$dir && \
find $$dir -type d -exec chmod 777 {} ';' && \
find $$dir -print | doschk && \
tar -cf - $$dir | gzip > $$dir.tar.gz && \
rm -fr $$dir
awklib/stamp-eg:
cd awklib ; $(MAKE) stamp-eg
check: gawk
cd test; $(MAKE) -k
test: check

View File

@ -1,3 +1,74 @@
Changes from 3.0.5 to 3.0.6
---------------------------
This is a bug fix release only, pending further development on 3.1.0.
Bugs fixed and changes made:
1. Subscripting an array with a variable that is just a number no
longer magically converts the variable into a string.
2. Similarly, running a `for (iggy in foo)' loop where `foo' is a
function parameter now works correctly.
3. Similarly, `i = ""; v[i] = a; if (v in a) ...' now works again.
4. Gawk now special cases `for (iggy in foo) delete foo[iggy]' and
treats it as the moral equivalent of `delete foo'. This should be
a major efficiency win when portably deleting large arrays.
5. VMS port brought up to date.
Changes from 3.0.4 to 3.0.5
---------------------------
This is a bug fix release only, pending further development on 3.1.0.
Bugs Fixed:
1. `function foo(foo)' is now a fatal error.
2. Array indexing is now much more efficient: where possible, only one
copy of an index string is kept, even if used in multiple arrays.
3. Support was added for MacOS X and an `install-strip' target.
4. [s]printf formatting for `0' flag and floating point formats now
works correctly.
5. HP-UX large file support with GCC 2.95.1 now works.
6. Arguments that contain `=' but that aren't syntactically valid are
now treated as filenames, instead of as fatal errors.
7. `-v NF=foo' now works.
8. Non-ascii alphanumeric characters are now treated as such in the
right locales by regex.c. Similarly, a Latin-1 y-umlaut (decimal
value 255) in the program text no longer acts like EOF.
9. Array indexes are always compared as strings; fixes an obscure bug
when user input gets used for the `x in array' test.
10. The usage message now points users to the documentation for how
to report bugs.
11. `/=' now works after an array.
12. `b += b += 1' now works correctly.
13. IGNORECASE changing with calls match() now works better. (Fix for
semi-obscure bug.)
14. Multicharacter values for RS now generate a lint warning.
15. The gawk open file caching is now much more efficient.
16. Global arrays passed to functions are now managed better. In particular,
test/arynocls.awk won't crash referencing freed memory.
17. In obscure cases, `getline var' can no longer clobber $0.
Changes from 3.0.3 to 3.0.4
---------------------------

View File

@ -1,27 +1,29 @@
Gawk 3.0.4 has been successfully compiled and run "make test"
Gawk 3.0.5 has been successfully compiled and run "make test"
on the following:
Linux 2.2.5 gcc 2.7.2.3
Linux 2.0.33 gcc 2.7.2.1
IRIX64 6.4 gcc 2.8.1
IRIX 5.3 gcc 2.7.2.2
UNIX_SV maxion OS 4.2MP gcc 2.7.2
IRIX 6.2 gcc 2.7.2.2
CYGWIN_95-4.0 20.1 (0.3/1/1) egcs-2.91.66 (has minor problems due to env.)
Linux 2.2.14 gcc 2.95.2
Linux 2.2.13-SMP egcs-2.91.66 make test -j5
IRIX64 6.5 gcc 2.8.1
IRIX 5.3 gcc 2.7.2.2
SunOS 5.3 gcc 2.5.8
Linux 2.0.33 gcc 2.7.2.1
IRIX64 6.5 gcc 2.95.1
The builds of gawk-3.0.45, and validation and installation, were
successful on these systems:
DEC Alpha OSF/1 3.2
Apple Macintosh PPC G3 Rhapsody 5.5
DEC Alpha OSF/1 4.0F
DEC Alpha Linux
HP 9000/735 HP-UX 10.01
HP PA 1.1 HP-UX 11.00
IBM PowerPC AIX 4.2
Intel Pentium II MMX GNU/Linux 2.0.35
Intel Pentium III GNU/Linux 2.2.12-20smp (Redhat 6.1)
NeXT Turbostation Mach 3.3
SGI Indigo/2 IRIX 5.3
SGI O2 R10000-SC IRIX 6.3
SGI MIPS IRIX 6.3
SGI Origin 200 IRIX 6.5
Sun SPARC GNU/Linux 2.2.12-42smp (Redhat 6.1)
Sun SPARC Solaris 2.6
Sun SPARC Solaris 2.7
On
SGI Origin 200 IRIX 6.4
a build with gcc-2.8.1 succeeded, but several tests failed; a rebuild
with c89 fixed the problem.
DEC Alpha OpenVMS
DEC Vax VMS DEC C
OS/2 EMX GCC

View File

@ -1,10 +1,10 @@
README:
This is GNU Awk 3.0.4. It should be upwardly compatible with the Bell
This is GNU Awk 3.0.6. It should be upwardly compatible with the Bell
Labs research version of awk. It is almost completely compliant with
the 1993 POSIX 1003.2 standard for awk. (See the note below about POSIX.)
Patches 1 through 4 just fix bugs -- see NEWS and ChangeLog for details.
Patches 1 through 5 just fix bugs -- see NEWS and ChangeLog for details.
See the file INSTALL for installation instructions.

View File

@ -0,0 +1,46 @@
Date: Sat, 22 Apr 2000 06:07:06 -0600 (MDT)
From: "Nelson H. F. Beebe" <beebe@math.utah.edu>
To: arnold@gnu.org
Cc: beebe@math.utah.edu, sysstaff@math.utah.edu, othmer@math.utah.edu
Subject: gawk-3.0.4 and a GNU/Linux gotcha
Yesterday, I was assisting a colleague install some software on his
GNU/Linux machine for which uname -r reports 2.2.14.
A (mis)feature of this system, which I've never encountered before,
broke the build of one of my programs, and also of gawk-3.0.4.
Namely, the kernel will not execute anything that resides in /tmp,
though it will if the same script is in /usr/tmp!
% cat /tmp/foo.sh
#! /bin/sh
echo hello
ls -l /tmp/foo.sh
-rwxr-xr-x 1 othmer math 22 Apr 21 10:34 /tmp/foo.sh*
% /tmp/foo.sh
bash: /tmp/foo.sh: Permission denied
% cp /tmp/foo.sh /usr/tmp
% /usr/tmp/foo.sh
hello
Thus, programs that do a temporary install in /tmp, as some of mine do
in order to run the validation suite, will fail.
gawk-3.0.4, and likely other gawk versions, hits this problem too. It
fails because test/poundbang starts with
#! /tmp/gawk -f
I tracked down where it comes from:
% grep /tmp /etc/fstab
/dev/hda3 /tmp ext2 rw,nosuid,noexec,nouser,auto,async,nodev 1 1
!!!!!!
Since this is done via a mount command, potentially ANY directory tree
could be mounted with noexec.

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1995-1999 the Free Software Foundation, Inc.
* Copyright (C) 1995-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.

129
contrib/awk/aclocal.m4 vendored Normal file
View File

@ -0,0 +1,129 @@
dnl
dnl aclocal.m4 --- autoconf input file for gawk
dnl
dnl Copyright (C) 1995, 1996, 1998, 1999, 2000 the Free Software Foundation, Inc.
dnl
dnl This file is part of GAWK, the GNU implementation of the
dnl AWK Progamming Language.
dnl
dnl GAWK is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2 of the License, or
dnl (at your option) any later version.
dnl
dnl GAWK is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
dnl
dnl gawk-specific macros for autoconf. one day hopefully part of autoconf
AC_DEFUN(GAWK_AC_C_STRINGIZE, [
AC_REQUIRE([AC_PROG_CPP])
AC_MSG_CHECKING([for ANSI stringizing capability])
AC_CACHE_VAL(gawk_cv_c_stringize,
AC_EGREP_CPP([#teststring],[
#define x(y) #y
char *s = x(teststring);
], gawk_cv_c_stringize=no, gawk_cv_c_stringize=yes))
if test "${gawk_cv_c_stringize}" = yes
then
AC_DEFINE(HAVE_STRINGIZE)
fi
AC_MSG_RESULT([${gawk_cv_c_stringize}])
])dnl
dnl By default, many hosts won't let programs access large files;
dnl one must use special compiler options to get large-file access to work.
dnl For more details about this brain damage please see:
dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
dnl Written by Paul Eggert <eggert@twinsun.com>.
dnl Internal subroutine of GAWK_AC_SYS_LARGEFILE.
dnl GAWK_AC_SYS_LARGEFILE_TEST_INCLUDES
AC_DEFUN(GAWK_AC_SYS_LARGEFILE_TEST_INCLUDES,
[[#include <sys/types.h>
int a[(off_t) 9223372036854775807 == 9223372036854775807 ? 1 : -1];
]])
dnl Internal subroutine of GAWK_AC_SYS_LARGEFILE.
dnl GAWK_AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR, COMMENT, INCLUDES, FUNCTION-BODY)
AC_DEFUN(GAWK_AC_SYS_LARGEFILE_MACRO_VALUE,
[AC_CACHE_CHECK([for $1 value needed for large files], $3,
[$3=no
AC_TRY_COMPILE(GAWK_AC_SYS_LARGEFILE_TEST_INCLUDES
$5
,
[$6],
,
[AC_TRY_COMPILE([#define $1 $2]
GAWK_AC_SYS_LARGEFILE_TEST_INCLUDES
$5
,
[$6],
[$3=$2])])])
if test "[$]$3" != no; then
AC_DEFINE_UNQUOTED([$1], [$]$3, [$4])
fi])
AC_DEFUN(GAWK_AC_SYS_LARGEFILE,
[AC_ARG_ENABLE(largefile,
[ --disable-largefile omit support for large files])
if test "$enable_largefile" != no; then
AC_CACHE_CHECK([for special C compiler options needed for large files],
gawk_cv_sys_largefile_CC,
[gawk_cv_sys_largefile_CC=no
if test "$GCC" != yes; then
# IRIX 6.2 and later do not support large files by default,
# so use the C compiler's -n32 option if that helps.
AC_TRY_COMPILE(GAWK_AC_SYS_LARGEFILE_TEST_INCLUDES, , ,
[ac_save_CC="$CC"
CC="$CC -n32"
AC_TRY_COMPILE(GAWK_AC_SYS_LARGEFILE_TEST_INCLUDES, ,
gawk_cv_sys_largefile_CC=' -n32')
CC="$ac_save_CC"])
fi])
if test "$gawk_cv_sys_largefile_CC" != no; then
CC="$CC$gawk_cv_sys_largefile_CC"
fi
GAWK_AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64,
gawk_cv_sys_file_offset_bits,
[Number of bits in a file offset, on hosts where this is settable.])
GAWK_AC_SYS_LARGEFILE_MACRO_VALUE(_LARGEFILE_SOURCE, 1,
gawk_cv_sys_largefile_source,
[Define to make ftello visible on some hosts (e.g. HP-UX 10.20).],
[#include <stdio.h>], [return !ftello;])
GAWK_AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1,
gawk_cv_sys_large_files,
[Define for large files, on AIX-style hosts.])
GAWK_AC_SYS_LARGEFILE_MACRO_VALUE(_XOPEN_SOURCE, 500,
gawk_cv_sys_xopen_source,
[Define to make ftello visible on some hosts (e.g. glibc 2.1.3).],
[#include <stdio.h>], [return !ftello;])
fi
])
dnl Check for AIX and add _XOPEN_SOURCE_EXTENDED
AC_DEFUN(GAWK_AC_AIX_TWEAK, [
AC_MSG_CHECKING([for AIX compilation hacks])
AC_CACHE_VAL(gawk_cv_aix_hack, [
if test -d /lpp/bos
then
CFLAGS="$CFLAGS -D_XOPEN_SOURCE_EXTENDED=1"
gawk_cv_aix_hack=yes
else
gawk_cv_aix_hack=no
fi
])dnl
AC_MSG_RESULT([${gawk_cv_aix_hack}])
])dnl

496
contrib/awk/alloca.c Normal file
View File

@ -0,0 +1,496 @@
/* alloca.c -- allocate automatically reclaimed memory
(Mostly) portable public-domain implementation -- D A Gwyn
This implementation of the PWB library alloca function,
which is used to allocate space off the run-time stack so
that it is automatically reclaimed upon procedure exit,
was inspired by discussions with J. Q. Johnson of Cornell.
J.Otto Tennant <jot@cray.com> contributed the Cray support.
There are some preprocessor constants that can
be defined when compiling for your specific system, for
improved efficiency; however, the defaults should be okay.
The general concept of this implementation is to keep
track of all alloca-allocated blocks, and reclaim any
that are found to be deeper in the stack than the current
invocation. This heuristic does not reclaim storage as
soon as it becomes invalid, but it will do so eventually.
As a special case, alloca(0) reclaims storage without
allocating any. It is a good idea to use alloca(0) in
your main control loop, etc. to force garbage collection. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef emacs
#include "blockinput.h"
#endif
/* If compiling with GCC 2, this file's not needed. */
#if !defined (__GNUC__) || __GNUC__ < 2
/* If someone has defined alloca as a macro,
there must be some other way alloca is supposed to work. */
#ifndef alloca
#ifdef emacs
#ifdef static
/* actually, only want this if static is defined as ""
-- this is for usg, in which emacs must undefine static
in order to make unexec workable
*/
#ifndef STACK_DIRECTION
you
lose
-- must know STACK_DIRECTION at compile-time
#endif /* STACK_DIRECTION undefined */
#endif /* static */
#endif /* emacs */
/* If your stack is a linked list of frames, you have to
provide an "address metric" ADDRESS_FUNCTION macro. */
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
long i00afunc ();
#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
#else
#define ADDRESS_FUNCTION(arg) &(arg)
#endif
#if __STDC__
typedef void *pointer;
#else
typedef char *pointer;
#endif
#ifndef NULL
#define NULL 0
#endif
#ifndef malloc
/* Different portions of Emacs need to call different versions of
malloc. The Emacs executable needs alloca to call xmalloc, because
ordinary malloc isn't protected from input signals. On the other
hand, the utilities in lib-src need alloca to call malloc; some of
them are very simple, and don't have an xmalloc routine.
Non-Emacs programs expect this to call xmalloc.
Callers below should use malloc. */
#ifndef emacs
#define malloc xmalloc
#endif
extern pointer malloc ();
#endif /* malloc */
/* Define STACK_DIRECTION if you know the direction of stack
growth for your system; otherwise it will be automatically
deduced at run-time.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
#ifndef STACK_DIRECTION
#define STACK_DIRECTION 0 /* Direction unknown. */
#endif
#if STACK_DIRECTION != 0
#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
#else /* STACK_DIRECTION == 0; need run-time code. */
static int stack_dir; /* 1 or -1 once known. */
#define STACK_DIR stack_dir
static void
find_stack_direction ()
{
static char *addr = NULL; /* Address of first `dummy', once known. */
auto char dummy; /* To get stack address. */
if (addr == NULL)
{ /* Initial entry. */
addr = ADDRESS_FUNCTION (dummy);
find_stack_direction (); /* Recurse once. */
}
else
{
/* Second entry. */
if (ADDRESS_FUNCTION (dummy) > addr)
stack_dir = 1; /* Stack grew upward. */
else
stack_dir = -1; /* Stack grew downward. */
}
}
#endif /* STACK_DIRECTION == 0 */
/* An "alloca header" is used to:
(a) chain together all alloca'ed blocks;
(b) keep track of stack depth.
It is very important that sizeof(header) agree with malloc
alignment chunk size. The following default should work okay. */
#ifndef ALIGN_SIZE
#define ALIGN_SIZE sizeof(double)
#endif
typedef union hdr
{
char align[ALIGN_SIZE]; /* To force sizeof(header). */
struct
{
union hdr *next; /* For chaining headers. */
char *deep; /* For stack depth measure. */
} h;
} header;
static header *last_alloca_header = NULL; /* -> last alloca header. */
/* Return a pointer to at least SIZE bytes of storage,
which will be automatically reclaimed upon exit from
the procedure that called alloca. Originally, this space
was supposed to be taken from the current stack frame of the
caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */
pointer
alloca (size)
unsigned size;
{
auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION (probe);
#if STACK_DIRECTION == 0
if (STACK_DIR == 0) /* Unknown growth direction. */
find_stack_direction ();
#endif
/* Reclaim garbage, defined as all alloca'd storage that
was allocated from deeper in the stack than currently. */
{
register header *hp; /* Traverses linked list. */
#ifdef emacs
BLOCK_INPUT;
#endif
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
|| (STACK_DIR < 0 && hp->h.deep < depth))
{
register header *np = hp->h.next;
free ((pointer) hp); /* Collect garbage. */
hp = np; /* -> next header. */
}
else
break; /* Rest are not deeper. */
last_alloca_header = hp; /* -> last valid storage. */
#ifdef emacs
UNBLOCK_INPUT;
#endif
}
if (size == 0)
return NULL; /* No allocation required. */
/* Allocate combined header + user data storage. */
{
register pointer new = malloc (sizeof (header) + size);
/* Address of header. */
((header *) new)->h.next = last_alloca_header;
((header *) new)->h.deep = depth;
last_alloca_header = (header *) new;
/* User storage begins just after header. */
return (pointer) ((char *) new + sizeof (header));
}
}
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
#ifdef DEBUG_I00AFUNC
#include <stdio.h>
#endif
#ifndef CRAY_STACK
#define CRAY_STACK
#ifndef CRAY2
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
struct stack_control_header
{
long shgrow:32; /* Number of times stack has grown. */
long shaseg:32; /* Size of increments to stack. */
long shhwm:32; /* High water mark of stack. */
long shsize:32; /* Current size of stack (all segments). */
};
/* The stack segment linkage control information occurs at
the high-address end of a stack segment. (The stack
grows from low addresses to high addresses.) The initial
part of the stack segment linkage control information is
0200 (octal) words. This provides for register storage
for the routine which overflows the stack. */
struct stack_segment_linkage
{
long ss[0200]; /* 0200 overflow words. */
long sssize:32; /* Number of words in this segment. */
long ssbase:32; /* Offset to stack base. */
long:32;
long sspseg:32; /* Offset to linkage control of previous
segment of stack. */
long:32;
long sstcpt:32; /* Pointer to task common address block. */
long sscsnm; /* Private control structure number for
microtasking. */
long ssusr1; /* Reserved for user. */
long ssusr2; /* Reserved for user. */
long sstpid; /* Process ID for pid based multi-tasking. */
long ssgvup; /* Pointer to multitasking thread giveup. */
long sscray[7]; /* Reserved for Cray Research. */
long ssa0;
long ssa1;
long ssa2;
long ssa3;
long ssa4;
long ssa5;
long ssa6;
long ssa7;
long sss0;
long sss1;
long sss2;
long sss3;
long sss4;
long sss5;
long sss6;
long sss7;
};
#else /* CRAY2 */
/* The following structure defines the vector of words
returned by the STKSTAT library routine. */
struct stk_stat
{
long now; /* Current total stack size. */
long maxc; /* Amount of contiguous space which would
be required to satisfy the maximum
stack demand to date. */
long high_water; /* Stack high-water mark. */
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
long hits; /* Number of internal buffer hits. */
long extends; /* Number of block extensions. */
long stko_mallocs; /* Block allocations by $STKOFEN. */
long underflows; /* Number of stack underflow calls ($STKRETN). */
long stko_free; /* Number of deallocations by $STKRETN. */
long stkm_free; /* Number of deallocations by $STKMRET. */
long segments; /* Current number of stack segments. */
long maxs; /* Maximum number of stack segments so far. */
long pad_size; /* Stack pad size. */
long current_address; /* Current stack segment address. */
long current_size; /* Current stack segment size. This
number is actually corrupted by STKSTAT to
include the fifteen word trailer area. */
long initial_address; /* Address of initial segment. */
long initial_size; /* Size of initial segment. */
};
/* The following structure describes the data structure which trails
any stack segment. I think that the description in 'asdef' is
out of date. I only describe the parts that I am sure about. */
struct stk_trailer
{
long this_address; /* Address of this block. */
long this_size; /* Size of this block (does not include
this trailer). */
long unknown2;
long unknown3;
long link; /* Address of trailer block of previous
segment. */
long unknown5;
long unknown6;
long unknown7;
long unknown8;
long unknown9;
long unknown10;
long unknown11;
long unknown12;
long unknown13;
long unknown14;
};
#endif /* CRAY2 */
#endif /* not CRAY_STACK */
#ifdef CRAY2
/* Determine a "stack measure" for an arbitrary ADDRESS.
I doubt that "lint" will like this much. */
static long
i00afunc (long *address)
{
struct stk_stat status;
struct stk_trailer *trailer;
long *block, size;
long result = 0;
/* We want to iterate through all of the segments. The first
step is to get the stack status structure. We could do this
more quickly and more directly, perhaps, by referencing the
$LM00 common block, but I know that this works. */
STKSTAT (&status);
/* Set up the iteration. */
trailer = (struct stk_trailer *) (status.current_address
+ status.current_size
- 15);
/* There must be at least one stack segment. Therefore it is
a fatal error if "trailer" is null. */
if (trailer == 0)
abort ();
/* Discard segments that do not contain our argument address. */
while (trailer != 0)
{
block = (long *) trailer->this_address;
size = trailer->this_size;
if (block == 0 || size == 0)
abort ();
trailer = (struct stk_trailer *) trailer->link;
if ((block <= address) && (address < (block + size)))
break;
}
/* Set the result to the offset in this segment and add the sizes
of all predecessor segments. */
result = address - block;
if (trailer == 0)
{
return result;
}
do
{
if (trailer->this_size <= 0)
abort ();
result += trailer->this_size;
trailer = (struct stk_trailer *) trailer->link;
}
while (trailer != 0);
/* We are done. Note that if you present a bogus address (one
not in any segment), you will get a different number back, formed
from subtracting the address of the first block. This is probably
not what you want. */
return (result);
}
#else /* not CRAY2 */
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
Determine the number of the cell within the stack,
given the address of the cell. The purpose of this
routine is to linearize, in some sense, stack addresses
for alloca. */
static long
i00afunc (long address)
{
long stkl = 0;
long size, pseg, this_segment, stack;
long result = 0;
struct stack_segment_linkage *ssptr;
/* Register B67 contains the address of the end of the
current stack segment. If you (as a subprogram) store
your registers on the stack and find that you are past
the contents of B67, you have overflowed the segment.
B67 also points to the stack segment linkage control
area, which is what we are really interested in. */
stkl = CRAY_STACKSEG_END ();
ssptr = (struct stack_segment_linkage *) stkl;
/* If one subtracts 'size' from the end of the segment,
one has the address of the first word of the segment.
If this is not the first segment, 'pseg' will be
nonzero. */
pseg = ssptr->sspseg;
size = ssptr->sssize;
this_segment = stkl - size;
/* It is possible that calling this routine itself caused
a stack overflow. Discard stack segments which do not
contain the target address. */
while (!(this_segment <= address && address <= stkl))
{
#ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
#endif
if (pseg == 0)
break;
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
this_segment = stkl - size;
}
result = address - this_segment;
/* If you subtract pseg from the current end of the stack,
you get the address of the previous stack segment's end.
This seems a little convoluted to me, but I'll bet you save
a cycle somewhere. */
while (pseg != 0)
{
#ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o\n", pseg, size);
#endif
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
result += size;
}
return (result);
}
#endif /* not CRAY2 */
#endif /* CRAY */
#endif /* no alloca */
#endif /* not GCC version 2 */

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
* Copyright (C) 1986, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@ -61,8 +61,8 @@ register NODE *tree;
r = force_string(tree_eval(tree->lnode));
if (tree->rnode == NULL)
return r;
subseplen = SUBSEP_node->lnode->stlen;
subsep = SUBSEP_node->lnode->stptr;
subseplen = SUBSEP_node->var_value->stlen;
subsep = SUBSEP_node->var_value->stptr;
len = r->stlen + subseplen + 2;
emalloc(str, char *, len, "concat_exp");
memcpy(str, r->stptr, r->stlen+1);
@ -214,11 +214,23 @@ register NODE *subs;
int hash1;
{
register NODE *bucket;
NODE *s1, *s2;
for (bucket = symbol->var_array[hash1]; bucket != NULL;
bucket = bucket->ahnext) {
if (cmp_nodes(bucket->ahname, subs) == 0)
return bucket;
/*
* This used to use cmp_nodes() here. That's wrong.
* Array indexes are strings; compare as such, always!
*/
s1 = bucket->ahname;
s1 = force_string(s1);
s2 = subs;
if (s1->stlen == s2->stlen) {
if (s1->stlen == 0 /* "" is a valid index */
|| STREQN(s1->stptr, s2->stptr, s1->stlen))
return bucket;
}
}
return NULL;
}
@ -234,6 +246,8 @@ NODE *symbol, *subs;
if (symbol->type == Node_param_list)
symbol = stack_ptr[symbol->param_cnt];
if (symbol->type == Node_array_ref)
symbol = symbol->orig_array;
if ((symbol->flags & SCALAR) != 0)
fatal("attempt to use scalar as array");
/*
@ -266,6 +280,8 @@ NODE *symbol, *subs;
register int hash1;
register NODE *bucket;
assert(symbol->type == Node_var_array || symbol->type == Node_var);
(void) force_string(subs);
if ((symbol->flags & SCALAR) != 0)
@ -308,20 +324,9 @@ NODE *symbol, *subs;
getnode(bucket);
bucket->type = Node_ahash;
if (subs->flags & TEMP)
bucket->ahname = dupnode(subs);
else {
unsigned int saveflags = subs->flags;
subs->flags &= ~MALLOC;
bucket->ahname = dupnode(subs);
subs->flags = saveflags;
}
bucket->ahname = dupnode(subs);
free_temp(subs);
/* array subscripts are strings */
bucket->ahname->flags &= ~NUMBER;
bucket->ahname->flags |= STRING;
bucket->ahvalue = Nnull_string;
bucket->ahnext = symbol->var_array[hash1];
symbol->var_array[hash1] = bucket;
@ -343,6 +348,8 @@ NODE *symbol, *tree;
if (symbol->type == Node_var)
return;
}
if (symbol->type == Node_array_ref)
symbol = symbol->orig_array;
if (symbol->type == Node_var_array) {
if (symbol->var_array == NULL)
return;
@ -360,9 +367,24 @@ NODE *symbol, *tree;
last = NULL;
for (bucket = symbol->var_array[hash1]; bucket != NULL;
last = bucket, bucket = bucket->ahnext)
if (cmp_nodes(bucket->ahname, subs) == 0)
break;
last = bucket, bucket = bucket->ahnext) {
/*
* This used to use cmp_nodes() here. That's wrong.
* Array indexes are strings; compare as such, always!
*/
NODE *s1, *s2;
s1 = bucket->ahname;
s1 = force_string(s1);
s2 = subs;
if (s1->stlen == s2->stlen) {
if (s1->stlen == 0 /* "" is a valid index */
|| STREQN(s1->stptr, s2->stptr, s1->stlen))
break;
}
}
if (bucket == NULL) {
if (do_lint)
warning("delete: index `%s' not in array `%s'",
@ -389,6 +411,50 @@ NODE *symbol, *tree;
}
}
/* do_delete_loop --- simulate ``for (iggy in foo) delete foo[iggy]'' */
/*
* The primary hassle here is that `iggy' needs to have some arbitrary
* array index put in it before we can clear the array, we can't
* just replace the loop with `delete foo'.
*/
void
do_delete_loop(symbol, tree)
NODE *symbol, *tree;
{
size_t i;
NODE *n, **lhs;
Func_ptr after_assign = NULL;
if (symbol->type == Node_param_list) {
symbol = stack_ptr[symbol->param_cnt];
if (symbol->type == Node_var)
return;
}
if (symbol->type == Node_array_ref)
symbol = symbol->orig_array;
if (symbol->type == Node_var_array) {
if (symbol->var_array == NULL)
return;
} else
fatal("delete: illegal use of variable `%s' as array",
symbol->vname);
/* get first index value */
for (i = 0; i < symbol->array_size; i++) {
if (symbol->var_array[i] != NULL) {
lhs = get_lhs(tree->lnode, & after_assign);
unref(*lhs);
*lhs = dupnode(symbol->var_array[i]->ahname);
break;
}
}
/* blast the array in one shot */
assoc_clear(symbol);
}
/* assoc_scan --- start a ``for (iggy in foo)'' loop */
void
@ -528,3 +594,82 @@ done:
symbol->var_array = new;
symbol->array_size = newsize;
}
/* pr_node --- print simple node info */
static void
pr_node(n)
NODE *n;
{
if ((n->flags & (NUM|NUMBER)) != 0)
printf("%g", n->numbr);
else
printf("%.*s", (int) n->stlen, n->stptr);
}
/* assoc_dump --- dump the contents of an array */
NODE *
assoc_dump(symbol)
NODE *symbol;
{
int i;
NODE *bucket;
if (symbol->var_array == NULL) {
printf("%s: empty (null)\n", symbol->vname);
return tmp_number((AWKNUM) 0);
}
if (symbol->table_size == 0) {
printf("%s: empty (zero)\n", symbol->vname);
return tmp_number((AWKNUM) 0);
}
printf("%s: table_size = %d, array_size = %d\n", symbol->vname,
symbol->table_size, symbol->array_size);
for (i = 0; i < symbol->array_size; i++) {
for (bucket = symbol->var_array[i]; bucket != NULL;
bucket = bucket->ahnext) {
printf("%s: I: [(%p, %ld, %s) len %d <%.*s>] V: [",
symbol->vname,
bucket->ahname,
bucket->ahname->stref,
flags2str(bucket->ahname->flags),
(int) bucket->ahname->stlen,
(int) bucket->ahname->stlen,
bucket->ahname->stptr);
pr_node(bucket->ahvalue);
printf("]\n");
}
}
return tmp_number((AWKNUM) 0);
}
/* do_adump --- dump an array: interface to assoc_dump */
NODE *
do_adump(tree)
NODE *tree;
{
NODE *r, *a;
a = tree->lnode;
if (a->type == Node_param_list) {
printf("%s: is paramater\n", a->vname);
a = stack_ptr[a->param_cnt];
}
if (a->type == Node_array_ref) {
printf("%s: array_ref to %s\n", a->vname,
a->orig_array->vname);
a = a->orig_array;
}
r = assoc_dump(a);
return r;
}

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
* Copyright (C) 1986, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@ -293,6 +293,7 @@ typedef enum nodevals {
Node_K_do, /* lnode is conditional, rnode stuff to run */
Node_K_return, /* lnode is return value */
Node_K_delete, /* lnode is array, rnode is subscript */
Node_K_delete_loop, /* lnode is array, rnode is subscript */
Node_K_getline, /* lnode is opt var, rnode is redirection */
Node_K_function, /* lnode is statement list, rnode is params */
Node_K_nextfile, /* no subs */
@ -332,6 +333,7 @@ typedef enum nodevals {
Node_regex, /* a regexp, text, compiled, flags, etc */
Node_hashnode, /* an identifier in the symbol table */
Node_ahash, /* an array element */
Node_array_ref, /* array passed by ref as parameter */
Node_NF, /* variables recognized in the grammar */
Node_NR,
Node_FNR,
@ -457,6 +459,8 @@ typedef struct exp_node {
#define array_size sub.nodep.l.ll
#define table_size sub.nodep.x.xl
#define orig_array sub.nodep.x.extra
#define condpair lnode
#define triggered sub.nodep.r.r_ent
@ -715,16 +719,19 @@ extern unsigned int hash P((const char *s, size_t len, unsigned long hsize));
extern int in_array P((NODE *symbol, NODE *subs));
extern NODE **assoc_lookup P((NODE *symbol, NODE *subs));
extern void do_delete P((NODE *symbol, NODE *tree));
extern void do_delete_loop P((NODE *symbol, NODE *tree));
extern void assoc_scan P((NODE *symbol, struct search *lookat));
extern void assoc_next P((struct search *lookat));
extern NODE *assoc_dump P((NODE *symbol));
extern NODE *do_adump P((NODE *tree));
/* awktab.c */
extern char *tokexpand P((void));
extern char nextc P((void));
extern NODE *node P((NODE *left, NODETYPE op, NODE *right));
extern NODE *install P((char *name, NODE *value));
extern NODE *lookup P((const char *name));
extern NODE *variable P((char *name, int can_free, NODETYPE type));
extern int yyparse P((void));
extern NODE *stopme P((NODE *tree));
/* builtin.c */
extern double double_to_int P((double d));
extern NODE *do_exp P((NODE *tree));
@ -775,6 +782,7 @@ void set_OFS P((void));
void set_ORS P((void));
void set_OFMT P((void));
void set_CONVFMT P((void));
extern char *flags2str P((int));
/* field.c */
extern void init_fields P((void));
extern void set_record P((char *buf, int cnt, int freeold));

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
* Copyright (C) 1986, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@ -385,9 +385,30 @@ statement
{ $$ = node($6, Node_K_do, $3); }
| LEX_FOR '(' NAME LEX_IN NAME r_paren opt_nls statement
{
$$ = node($8, Node_K_arrayfor,
make_for_loop(variable($3, CAN_FREE, Node_var),
(NODE *) NULL, variable($5, CAN_FREE, Node_var_array)));
/*
* Efficiency hack. Recognize the special case of
*
* for (iggy in foo)
* delete foo[iggy]
*
* and treat it as if it were
*
* delete foo
*
* Check that the body is a `delete a[i]' statement,
* and that both the loop var and array names match.
*/
if ($8->type == Node_K_delete
&& $8->rnode != NULL
&& strcmp($3, $8->rnode->var_value->vname) == 0
&& strcmp($5, $8->lnode->vname) == 0) {
$8->type = Node_K_delete_loop;
$$ = $8;
} else {
$$ = node($8, Node_K_arrayfor,
make_for_loop(variable($3, CAN_FREE, Node_var),
(NODE *) NULL, variable($5, CAN_FREE, Node_var_array)));
}
}
| LEX_FOR '(' opt_exp semi exp semi opt_exp r_paren opt_nls statement
{
@ -883,20 +904,16 @@ struct token {
NODE *(*ptr)(); /* function that implements this keyword */
};
extern NODE
*do_exp(), *do_getline(), *do_index(), *do_length(),
*do_sqrt(), *do_log(), *do_sprintf(), *do_substr(),
*do_split(), *do_system(), *do_int(), *do_close(),
*do_atan2(), *do_sin(), *do_cos(), *do_rand(),
*do_srand(), *do_match(), *do_tolower(), *do_toupper(),
*do_sub(), *do_gsub(), *do_strftime(), *do_systime(),
*do_fflush();
/* Tokentab is sorted ascii ascending order, so it can be binary searched. */
/* Function pointers come from declarations in awk.h. */
static struct token tokentab[] = {
{"BEGIN", Node_illegal, LEX_BEGIN, 0, 0},
{"END", Node_illegal, LEX_END, 0, 0},
#ifdef ARRAYDEBUG
{"adump", Node_builtin, LEX_BUILTIN, GAWKX|A(1), do_adump},
#endif
#ifdef BITOPS
{"and", Node_builtin, LEX_BUILTIN, GAWKX|A(2), do_and},
#endif /* BITOPS */
@ -947,6 +964,9 @@ static struct token tokentab[] = {
{"sprintf", Node_builtin, LEX_BUILTIN, 0, do_sprintf},
{"sqrt", Node_builtin, LEX_BUILTIN, A(1), do_sqrt},
{"srand", Node_builtin, LEX_BUILTIN, NOT_OLD|A(0)|A(1), do_srand},
#ifdef ARRAYDEBUG
{"stopme", Node_builtin, LEX_BUILTIN, GAWKX|A(0), stopme},
#endif
{"strftime", Node_builtin, LEX_BUILTIN, GAWKX|A(0)|A(1)|A(2), do_strftime},
#ifdef BITOPS
{"strtonum", Node_builtin, LEX_BUILTIN, GAWKX|A(1), do_strtonum},
@ -1217,9 +1237,9 @@ nextc()
int c;
if (lexptr && lexptr < lexend)
c = *lexptr++;
c = (int) (unsigned char) *lexptr++;
else if (get_src_buf())
c = *lexptr++;
c = (int) (unsigned char) *lexptr++;
else
c = EOF;
@ -1227,8 +1247,8 @@ nextc()
}
#else
#define nextc() ((lexptr && lexptr < lexend) ? \
*lexptr++ : \
(get_src_buf() ? *lexptr++ : EOF) \
((int) (unsigned char) *lexptr++) : \
(get_src_buf() ? ((int) (unsigned char) *lexptr++) : EOF) \
)
#endif
@ -1457,7 +1477,6 @@ retry:
return lasttok = c;
case ')':
case ']':
case '(':
case ';':
case '{':
@ -1465,6 +1484,7 @@ retry:
want_assign = FALSE;
/* fall through */
case '[':
case ']':
return lasttok = c;
case '*':
@ -2143,6 +2163,14 @@ NODE *params;
NODE *def;
{
NODE *r;
NODE *n;
/* check for function foo(foo) { ... }. bleh. */
for (n = params->rnode; n != NULL; n = n->rnode) {
if (strcmp(n->param, params->param) == 0)
fatal("function `%s': can't use function name as parameter name",
params->param);
}
pop_params(params->rnode);
pop_var(params, FALSE);
@ -2441,3 +2469,11 @@ register NODE *n;
}
return FALSE;
}
/* for debugging */
NODE *
stopme(tree)
NODE *tree;
{
return tmp_number((AWKNUM) 0.0);
}

View File

@ -0,0 +1,54 @@
Mon Aug 7 15:23:00 2000 Arnold D. Robbins <arnold@skeeve.com>
* Release 3.0.6: Release tar file made.
Sun Jun 25 15:08:19 2000 Arnold D. Robbins <arnold@skeeve.com>
* Release 3.0.5: Release tar file made.
Wed Jun 30 16:14:36 1999 Arnold D. Robbins <arnold@gnu.org>
* Release 3.0.4: Release tar file made. This time for sure.
Thu May 15 12:49:08 1997 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* Release 3.0.3: Release tar file made.
Fri Apr 18 07:55:47 1997 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* BETA Release 3.0.34: Release tar file made.
Sun Apr 13 15:40:55 1997 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* Makefile.in (install): fix second for loop to use $$i. Sigh.
Wed Dec 25 11:25:22 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* Release 3.0.2: Release tar file made.
Wed Dec 25 11:17:32 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* Makefile.in (install): remove chmod command; let
$(INSTALL_PROGRAM) use -m.
Tue Dec 17 22:29:49 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* Makefile.in (install): fix installation of files in eg/lib.
Tue Dec 10 23:09:26 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* Release 3.0.1: Release tar file made.
Sun Oct 20 12:30:41 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* Makefile.in (install): minor tweaks for portability.
Fri Mar 15 06:33:38 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* Makefile.in (pwcat, grcat): Add $(LDFLAGS).
(clean): add `*~' to list of files to be removed.
Wed Jan 24 10:06:16 1996 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* Makefile.in (clean): Remove $(AUXAWK).
(maintainer-clean): Depend on distclean, not the other way around.

View File

@ -0,0 +1,99 @@
# Makefile for GNU Awk support library.
#
# Copyright (C) 1995-1998 the Free Software Foundation, Inc.
#
# This file is part of GAWK, the GNU implementation of the
# AWK Programming Language.
#
# GAWK is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# GAWK is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
SHELL = /bin/sh
srcdir = @srcdir@
VPATH = @srcdir@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
CC = @CC@
CFLAGS = @CFLAGS@
prefix = @prefix@
exec_prefix = @exec_prefix@
binprefix =
manprefix =
bindir = @bindir@
libdir = @libdir@
mandir = @mandir@/man1
manext = .1
infodir = @infodir@
datadir = @datadir@/awk
libexecdir = @libexecdir@/awk
AUXPROGS = pwcat grcat
AUXAWK = passwd.awk group.awk
all: stamp-eg $(AUXPROGS) igawk $(AUXAWK)
stamp-eg: $(srcdir)/../doc/gawk.texi
rm -fr eg stamp-eg
../gawk -f $(srcdir)/extract.awk $(srcdir)/../doc/gawk.texi
@echo 'some makes are stupid and will not check a directory' > stamp-eg
@echo 'against a file, so this file is a place holder. gack.' >> stamp-eg
pwcat: $(srcdir)/eg/lib/pwcat.c
$(CC) $(CFLAGS) $(srcdir)/eg/lib/pwcat.c $(LDFLAGS) -o $@
grcat: $(srcdir)/eg/lib/grcat.c
$(CC) $(CFLAGS) $(srcdir)/eg/lib/grcat.c $(LDFLAGS) -o $@
igawk: $(srcdir)/eg/prog/igawk.sh
cp $(srcdir)/eg/prog/igawk.sh $@ ; chmod 755 $@
passwd.awk: $(srcdir)/eg/lib/passwdawk.in
(cd $(srcdir)/eg/lib ; \
sed 's;/usr/local/libexec/awk;$(libexecdir);' < passwdawk.in) > passwd.awk
group.awk: $(srcdir)/eg/lib/groupawk.in
(cd $(srcdir)/eg/lib ; \
sed 's;/usr/local/libexec/awk;$(libexecdir);' < groupawk.in) > group.awk
install: igawk $(AUXPROGS) $(AUXAWK)
$(INSTALL_PROGRAM) igawk $(bindir)/igawk
for i in $(AUXPROGS) ; do \
$(INSTALL_PROGRAM) $$i $(libexecdir)/$$i ; \
done
for i in $(AUXAWK) $(srcdir)/eg/lib/*.awk ; do \
progname=`echo $$i | sed 's;.*/;;'` ; \
$(INSTALL_DATA) $$i $(datadir)/$$progname ; \
done
# libexecdir and datadir are removed in the top level Makefile's uninstall
uninstall:
rm -fr $(libexecdir)/* $(datadir)/*
rm -f $(bindir)/igawk
clean:
rm -f $(AUXPROGS) $(AUXAWK) igawk *~
distclean: clean
rm -f Makefile
maintainer-clean: distclean
@echo "This command is intended for maintainers to use; it"
@echo "deletes files that may require special tools to rebuild."
rm -fr eg stamp-eg

View File

@ -0,0 +1,11 @@
aardvark 555-5553 1200/300 B
alpo-net 555-3412 2400/1200/300 A
barfly 555-7685 1200/300 A
bites 555-1675 2400/1200/300 A
camelot 555-0542 300 C
core 555-2912 1200/300 C
fooey 555-1234 2400/1200/300 B
foot 555-6699 1200/300 B
macfoo 555-6480 1200/300 A
sdace 555-3430 2400/1200/300 A
sabafoo 555-2127 1200/300 C

View File

@ -0,0 +1,17 @@
Jan 13 25 15 115
Feb 15 32 24 226
Mar 15 24 34 228
Apr 31 52 63 420
May 16 34 29 208
Jun 31 42 75 492
Jul 24 34 67 436
Aug 15 34 47 316
Sep 13 55 37 277
Oct 29 54 68 525
Nov 20 87 82 577
Dec 17 35 61 401
Jan 21 36 64 620
Feb 26 58 80 652
Mar 24 75 70 495
Apr 21 70 74 514

View File

@ -0,0 +1,18 @@
# assert --- assert that a condition is true. Otherwise exit.
# Arnold Robbins, arnold@gnu.org, Public Domain
# May, 1993
function assert(condition, string)
{
if (! condition) {
printf("%s:%d: assertion failed: %s\n",
FILENAME, FNR, string) > "/dev/stderr"
_assert_exit = 1
exit 1
}
}
END {
if (_assert_exit)
exit 1
}

View File

@ -0,0 +1,11 @@
# ctime.awk
#
# awk version of C ctime(3) function
function ctime(ts, format)
{
format = "%a %b %d %H:%M:%S %Z %Y"
if (ts == 0)
ts = systime() # use current time as default
return strftime(format, ts)
}

View File

@ -0,0 +1,15 @@
# ftrans.awk --- handle data file transitions
#
# user supplies beginfile() and endfile() functions
#
# Arnold Robbins, arnold@gnu.org, November 1992
# Public Domain
FNR == 1 {
if (_filename_ != "")
endfile(_filename_)
_filename_ = FILENAME
beginfile(FILENAME)
}
END { endfile(_filename_) }

View File

@ -0,0 +1,82 @@
# getopt --- do C library getopt(3) function in awk
#
# arnold@gnu.org
# Public domain
#
# Initial version: March, 1991
# Revised: May, 1993
# External variables:
# Optind -- index of ARGV for first non-option argument
# Optarg -- string value of argument to current option
# Opterr -- if non-zero, print our own diagnostic
# Optopt -- current option letter
# Returns
# -1 at end of options
# ? for unrecognized option
# <c> a character representing the current option
# Private Data
# _opti index in multi-flag option, e.g., -abc
function getopt(argc, argv, options, optl, thisopt, i)
{
optl = length(options)
if (optl == 0) # no options given
return -1
if (argv[Optind] == "--") { # all done
Optind++
_opti = 0
return -1
} else if (argv[Optind] !~ /^-[^: \t\n\f\r\v\b]/) {
_opti = 0
return -1
}
if (_opti == 0)
_opti = 2
thisopt = substr(argv[Optind], _opti, 1)
Optopt = thisopt
i = index(options, thisopt)
if (i == 0) {
if (Opterr)
printf("%c -- invalid option\n",
thisopt) > "/dev/stderr"
if (_opti >= length(argv[Optind])) {
Optind++
_opti = 0
} else
_opti++
return "?"
}
if (substr(options, i + 1, 1) == ":") {
# get option argument
if (length(substr(argv[Optind], _opti + 1)) > 0)
Optarg = substr(argv[Optind], _opti + 1)
else
Optarg = argv[++Optind]
_opti = 0
} else
Optarg = ""
if (_opti == 0 || _opti >= length(argv[Optind])) {
Optind++
_opti = 0
} else
_opti++
return thisopt
}
BEGIN {
Opterr = 1 # default is to diagnose
Optind = 1 # skip ARGV[0]
# test program
if (_getopt_test) {
while ((_go_c = getopt(ARGC, ARGV, "ab:cd")) != -1)
printf("c = <%c>, optarg = <%s>\n",
_go_c, Optarg)
printf("non-option arguments:\n")
for (; Optind < ARGC; Optind++)
printf("\tARGV[%d] = <%s>\n",
Optind, ARGV[Optind])
}
}

View File

@ -0,0 +1,61 @@
# gettimeofday --- get the time of day in a usable format
# Arnold Robbins, arnold@gnu.org, Public Domain, May 1993
#
# Returns a string in the format of output of date(1)
# Populates the array argument time with individual values:
# time["second"] -- seconds (0 - 59)
# time["minute"] -- minutes (0 - 59)
# time["hour"] -- hours (0 - 23)
# time["althour"] -- hours (0 - 12)
# time["monthday"] -- day of month (1 - 31)
# time["month"] -- month of year (1 - 12)
# time["monthname"] -- name of the month
# time["shortmonth"] -- short name of the month
# time["year"] -- year within century (0 - 99)
# time["fullyear"] -- year with century (19xx or 20xx)
# time["weekday"] -- day of week (Sunday = 0)
# time["altweekday"] -- day of week (Monday = 0)
# time["weeknum"] -- week number, Sunday first day
# time["altweeknum"] -- week number, Monday first day
# time["dayname"] -- name of weekday
# time["shortdayname"] -- short name of weekday
# time["yearday"] -- day of year (0 - 365)
# time["timezone"] -- abbreviation of timezone name
# time["ampm"] -- AM or PM designation
function gettimeofday(time, ret, now, i)
{
# get time once, avoids unnecessary system calls
now = systime()
# return date(1)-style output
ret = strftime("%a %b %d %H:%M:%S %Z %Y", now)
# clear out target array
for (i in time)
delete time[i]
# fill in values, force numeric values to be
# numeric by adding 0
time["second"] = strftime("%S", now) + 0
time["minute"] = strftime("%M", now) + 0
time["hour"] = strftime("%H", now) + 0
time["althour"] = strftime("%I", now) + 0
time["monthday"] = strftime("%d", now) + 0
time["month"] = strftime("%m", now) + 0
time["monthname"] = strftime("%B", now)
time["shortmonth"] = strftime("%b", now)
time["year"] = strftime("%y", now) + 0
time["fullyear"] = strftime("%Y", now) + 0
time["weekday"] = strftime("%w", now) + 0
time["altweekday"] = strftime("%u", now) + 0
time["dayname"] = strftime("%A", now)
time["shortdayname"] = strftime("%a", now)
time["yearday"] = strftime("%j", now) + 0
time["timezone"] = strftime("%Z", now)
time["ampm"] = strftime("%p", now)
time["weeknum"] = strftime("%U", now) + 0
time["altweeknum"] = strftime("%W", now) + 0
return ret
}

View File

@ -0,0 +1,34 @@
/*
* grcat.c
*
* Generate a printable version of the group database
*
* Arnold Robbins, arnold@gnu.org
* May 1993
* Public Domain
*/
#include <stdio.h>
#include <grp.h>
int
main(argc, argv)
int argc;
char **argv;
{
struct group *g;
int i;
while ((g = getgrent()) != NULL) {
printf("%s:%s:%d:", g->gr_name, g->gr_passwd,
g->gr_gid);
for (i = 0; g->gr_mem[i] != NULL; i++) {
printf("%s", g->gr_mem[i]);
if (g->gr_mem[i+1] != NULL)
putchar(',');
}
putchar('\n');
}
endgrent();
exit(0);
}

View File

@ -0,0 +1,80 @@
# group.awk --- functions for dealing with the group file
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
BEGIN \
{
# Change to suit your system
_gr_awklib = "/usr/local/libexec/awk/"
}
function _gr_init( oldfs, oldrs, olddol0, grcat, n, a, i)
{
if (_gr_inited)
return
oldfs = FS
oldrs = RS
olddol0 = $0
FS = ":"
RS = "\n"
grcat = _gr_awklib "grcat"
while ((grcat | getline) > 0) {
if ($1 in _gr_byname)
_gr_byname[$1] = _gr_byname[$1] "," $4
else
_gr_byname[$1] = $0
if ($3 in _gr_bygid)
_gr_bygid[$3] = _gr_bygid[$3] "," $4
else
_gr_bygid[$3] = $0
n = split($4, a, "[ \t]*,[ \t]*")
for (i = 1; i <= n; i++)
if (a[i] in _gr_groupsbyuser)
_gr_groupsbyuser[a[i]] = \
_gr_groupsbyuser[a[i]] " " $1
else
_gr_groupsbyuser[a[i]] = $1
_gr_bycount[++_gr_count] = $0
}
close(grcat)
_gr_count = 0
_gr_inited++
FS = oldfs
RS = oldrs
$0 = olddol0
}
function getgrnam(group)
{
_gr_init()
if (group in _gr_byname)
return _gr_byname[group]
return ""
}
function getgrgid(gid)
{
_gr_init()
if (gid in _gr_bygid)
return _gr_bygid[gid]
return ""
}
function getgruser(user)
{
_gr_init()
if (user in _gr_groupsbyuser)
return _gr_groupsbyuser[user]
return ""
}
function getgrent()
{
_gr_init()
if (++_gr_count in _gr_bycount)
return _gr_bycount[_gr_count]
return ""
}
function endgrent()
{
_gr_count = 0
}

View File

@ -0,0 +1,15 @@
# join.awk --- join an array into a string
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
function join(array, start, end, sep, result, i)
{
if (sep == "")
sep = " "
else if (sep == SUBSEP) # magic value
sep = ""
result = array[start]
for (i = start + 1; i <= end; i++)
result = result sep array[i]
return result
}

View File

@ -0,0 +1,105 @@
# mktime.awk --- convert a canonical date representation
# into a timestamp
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
BEGIN \
{
# Initialize table of month lengths
_tm_months[0,1] = _tm_months[1,1] = 31
_tm_months[0,2] = 28; _tm_months[1,2] = 29
_tm_months[0,3] = _tm_months[1,3] = 31
_tm_months[0,4] = _tm_months[1,4] = 30
_tm_months[0,5] = _tm_months[1,5] = 31
_tm_months[0,6] = _tm_months[1,6] = 30
_tm_months[0,7] = _tm_months[1,7] = 31
_tm_months[0,8] = _tm_months[1,8] = 31
_tm_months[0,9] = _tm_months[1,9] = 30
_tm_months[0,10] = _tm_months[1,10] = 31
_tm_months[0,11] = _tm_months[1,11] = 30
_tm_months[0,12] = _tm_months[1,12] = 31
}
# decide if a year is a leap year
function _tm_isleap(year, ret)
{
ret = (year % 4 == 0 && year % 100 != 0) ||
(year % 400 == 0)
return ret
}
# convert a date into seconds
function _tm_addup(a, total, yearsecs, daysecs,
hoursecs, i, j)
{
hoursecs = 60 * 60
daysecs = 24 * hoursecs
yearsecs = 365 * daysecs
total = (a[1] - 1970) * yearsecs
# extra day for leap years
for (i = 1970; i < a[1]; i++)
if (_tm_isleap(i))
total += daysecs
j = _tm_isleap(a[1])
for (i = 1; i < a[2]; i++)
total += _tm_months[j, i] * daysecs
total += (a[3] - 1) * daysecs
total += a[4] * hoursecs
total += a[5] * 60
total += a[6]
return total
}
# mktime --- convert a date into seconds,
# compensate for time zone
function mktime(str, res1, res2, a, b, i, j, t, diff)
{
i = split(str, a, " ") # don't rely on FS
if (i != 6)
return -1
# force numeric
for (j in a)
a[j] += 0
# validate
if (a[1] < 1970 ||
a[2] < 1 || a[2] > 12 ||
a[3] < 1 || a[3] > 31 ||
a[4] < 0 || a[4] > 23 ||
a[5] < 0 || a[5] > 59 ||
a[6] < 0 || a[6] > 60 )
return -1
res1 = _tm_addup(a)
t = strftime("%Y %m %d %H %M %S", res1)
if (_tm_debug)
printf("(%s) -> (%s)\n", str, t) > "/dev/stderr"
split(t, b, " ")
res2 = _tm_addup(b)
diff = res1 - res2
if (_tm_debug)
printf("diff = %d seconds\n", diff) > "/dev/stderr"
res1 += diff
return res1
}
BEGIN {
if (_tm_test) {
printf "Enter date as yyyy mm dd hh mm ss: "
getline _tm_test_date
t = mktime(_tm_test_date)
r = strftime("%Y %m %d %H %M %S", t)
printf "Got back (%s)\n", r
}
}

View File

@ -0,0 +1,15 @@
# nextfile --- skip remaining records in current file
# correctly handle successive occurrences of the same file
# Arnold Robbins, arnold@gnu.org, Public Domain
# May, 1993
# this should be read in before the "main" awk program
function nextfile() { _abandon_ = FILENAME; next }
_abandon_ == FILENAME {
if (FNR == 1)
_abandon_ = ""
else
next
}

View File

@ -0,0 +1,54 @@
# ord.awk --- do ord and chr
#
# Global identifiers:
# _ord_: numerical values indexed by characters
# _ord_init: function to initialize _ord_
#
# Arnold Robbins
# arnold@gnu.org
# Public Domain
# 16 January, 1992
# 20 July, 1992, revised
BEGIN { _ord_init() }
function _ord_init( low, high, i, t)
{
low = sprintf("%c", 7) # BEL is ascii 7
if (low == "\a") { # regular ascii
low = 0
high = 127
} else if (sprintf("%c", 128 + 7) == "\a") {
# ascii, mark parity
low = 128
high = 255
} else { # ebcdic(!)
low = 0
high = 255
}
for (i = low; i <= high; i++) {
t = sprintf("%c", i)
_ord_[t] = i
}
}
function ord(str, c)
{
# only first character is of interest
c = substr(str, 1, 1)
return _ord_[c]
}
function chr(c)
{
# force c to be numeric by adding 0
return sprintf("%c", c + 0)
}
#### test code ####
# BEGIN \
# {
# for (;;) {
# printf("enter a character: ")
# if (getline var <= 0)
# break
# printf("ord(%s) = %d\n", var, ord(var))
# }
# }

View File

@ -0,0 +1,56 @@
# passwd.awk --- access password file information
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
BEGIN {
# tailor this to suit your system
_pw_awklib = "/usr/local/libexec/awk/"
}
function _pw_init( oldfs, oldrs, olddol0, pwcat)
{
if (_pw_inited)
return
oldfs = FS
oldrs = RS
olddol0 = $0
FS = ":"
RS = "\n"
pwcat = _pw_awklib "pwcat"
while ((pwcat | getline) > 0) {
_pw_byname[$1] = $0
_pw_byuid[$3] = $0
_pw_bycount[++_pw_total] = $0
}
close(pwcat)
_pw_count = 0
_pw_inited = 1
FS = oldfs
RS = oldrs
$0 = olddol0
}
function getpwnam(name)
{
_pw_init()
if (name in _pw_byname)
return _pw_byname[name]
return ""
}
function getpwuid(uid)
{
_pw_init()
if (uid in _pw_byuid)
return _pw_byuid[uid]
return ""
}
function getpwent()
{
_pw_init()
if (_pw_count < _pw_total)
return _pw_bycount[++_pw_count]
return ""
}
function endpwent()
{
_pw_count = 0
}

View File

@ -0,0 +1,29 @@
/*
* pwcat.c
*
* Generate a printable version of the password database
*
* Arnold Robbins
* arnold@gnu.org
* May 1993
* Public Domain
*/
#include <stdio.h>
#include <pwd.h>
int
main(argc, argv)
int argc;
char **argv;
{
struct passwd *p;
while ((p = getpwent()) != NULL)
printf("%s:%s:%d:%d:%s:%s:%s\n",
p->pw_name, p->pw_passwd, p->pw_uid,
p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell);
endpwent();
exit(0);
}

View File

@ -0,0 +1,32 @@
# round --- do normal rounding
#
# Arnold Robbins, arnold@gnu.org, August, 1996
# Public Domain
function round(x, ival, aval, fraction)
{
ival = int(x) # integer part, int() truncates
# see if fractional part
if (ival == x) # no fraction
return x
if (x < 0) {
aval = -x # absolute value
ival = int(aval)
fraction = aval - ival
if (fraction >= .5)
return int(x) - 1 # -2.5 --> -3
else
return int(x) # -2.3 --> -2
} else {
fraction = x - ival
if (fraction >= .5)
return ival + 1
else
return ival
}
}
# test harness
{ print $0, round($0) }

View File

@ -0,0 +1,10 @@
{
if ($1 > max)
max = $1
arr[$1] = $0
}
END {
for (x = 1; x <= max; x++)
print arr[x]
}

View File

@ -0,0 +1,5 @@
5 I am the Five man
2 Who are you? The new number two!
4 . . . And four on the floor
1 Who is number one?
3 I three you.

View File

@ -0,0 +1,7 @@
FIND ru+n
My program runs
but not very quickly
FIND Melvin
JF+KM
This line is property of Reality Engineering Co.
Melvin was here.

View File

@ -0,0 +1,10 @@
awk '{
if ($1 == "FIND")
regex = $2
else {
where = match($0, regex)
if (where != 0)
print "Match of", regex, "found at", \
where, "in", $0
}
}'

View File

@ -0,0 +1,81 @@
# alarm --- set an alarm
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
# usage: alarm time [ "message" [ count [ delay ] ] ]
BEGIN \
{
# Initial argument sanity checking
usage1 = "usage: alarm time ['message' [count [delay]]]"
usage2 = sprintf("\t(%s) time ::= hh:mm", ARGV[1])
if (ARGC < 2) {
print usage > "/dev/stderr"
exit 1
} else if (ARGC == 5) {
delay = ARGV[4] + 0
count = ARGV[3] + 0
message = ARGV[2]
} else if (ARGC == 4) {
count = ARGV[3] + 0
message = ARGV[2]
} else if (ARGC == 3) {
message = ARGV[2]
} else if (ARGV[1] !~ /[0-9]?[0-9]:[0-9][0-9]/) {
print usage1 > "/dev/stderr"
print usage2 > "/dev/stderr"
exit 1
}
# set defaults for once we reach the desired time
if (delay == 0)
delay = 180 # 3 minutes
if (count == 0)
count = 5
if (message == "")
message = sprintf("\aIt is now %s!\a", ARGV[1])
else if (index(message, "\a") == 0)
message = "\a" message "\a"
# split up dest time
split(ARGV[1], atime, ":")
hour = atime[1] + 0 # force numeric
minute = atime[2] + 0 # force numeric
# get current broken down time
gettimeofday(now)
# if time given is 12-hour hours and it's after that
# hour, e.g., `alarm 5:30' at 9 a.m. means 5:30 p.m.,
# then add 12 to real hour
if (hour < 12 && now["hour"] > hour)
hour += 12
# set target time in seconds since midnight
target = (hour * 60 * 60) + (minute * 60)
# get current time in seconds since midnight
current = (now["hour"] * 60 * 60) + \
(now["minute"] * 60) + now["second"]
# how long to sleep for
naptime = target - current
if (naptime <= 0) {
print "time is in the past!" > "/dev/stderr"
exit 1
}
# zzzzzz..... go away if interrupted
if (system(sprintf("sleep %d", naptime)) != 0)
exit 1
# time to notify!
command = sprintf("sleep %d", delay)
for (i = 1; i <= count; i++) {
print message
# if sleep command interrupted, go away
if (system(command) != 0)
break
}
exit 0
}

View File

@ -0,0 +1,31 @@
# awksed.awk --- do s/foo/bar/g using just print
# Thanks to Michael Brennan for the idea
# Arnold Robbins, arnold@gnu.org, Public Domain
# August 1995
function usage()
{
print "usage: awksed pat repl [files...]" > "/dev/stderr"
exit 1
}
BEGIN {
# validate arguments
if (ARGC < 3)
usage()
RS = ARGV[1]
ORS = ARGV[2]
# don't use arguments as files
ARGV[1] = ARGV[2] = ""
}
# look ma, no hands!
{
if (RT == "")
printf "%s", $0
else
print
}

View File

@ -0,0 +1,136 @@
# cut.awk --- implement cut in awk
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
# Options:
# -f list Cut fields
# -d c Field delimiter character
# -c list Cut characters
#
# -s Suppress lines without the delimiter character
function usage( e1, e2)
{
e1 = "usage: cut [-f list] [-d c] [-s] [files...]"
e2 = "usage: cut [-c list] [files...]"
print e1 > "/dev/stderr"
print e2 > "/dev/stderr"
exit 1
}
BEGIN \
{
FS = "\t" # default
OFS = FS
while ((c = getopt(ARGC, ARGV, "sf:c:d:")) != -1) {
if (c == "f") {
by_fields = 1
fieldlist = Optarg
} else if (c == "c") {
by_chars = 1
fieldlist = Optarg
OFS = ""
} else if (c == "d") {
if (length(Optarg) > 1) {
printf("Using first character of %s" \
" for delimiter\n", Optarg) > "/dev/stderr"
Optarg = substr(Optarg, 1, 1)
}
FS = Optarg
OFS = FS
if (FS == " ") # defeat awk semantics
FS = "[ ]"
} else if (c == "s")
suppress++
else
usage()
}
for (i = 1; i < Optind; i++)
ARGV[i] = ""
if (by_fields && by_chars)
usage()
if (by_fields == 0 && by_chars == 0)
by_fields = 1 # default
if (fieldlist == "") {
print "cut: needs list for -c or -f" > "/dev/stderr"
exit 1
}
if (by_fields)
set_fieldlist()
else
set_charlist()
}
function set_fieldlist( n, m, i, j, k, f, g)
{
n = split(fieldlist, f, ",")
j = 1 # index in flist
for (i = 1; i <= n; i++) {
if (index(f[i], "-") != 0) { # a range
m = split(f[i], g, "-")
if (m != 2 || g[1] >= g[2]) {
printf("bad field list: %s\n",
f[i]) > "/dev/stderr"
exit 1
}
for (k = g[1]; k <= g[2]; k++)
flist[j++] = k
} else
flist[j++] = f[i]
}
nfields = j - 1
}
function set_charlist( field, i, j, f, g, t,
filler, last, len)
{
field = 1 # count total fields
n = split(fieldlist, f, ",")
j = 1 # index in flist
for (i = 1; i <= n; i++) {
if (index(f[i], "-") != 0) { # range
m = split(f[i], g, "-")
if (m != 2 || g[1] >= g[2]) {
printf("bad character list: %s\n",
f[i]) > "/dev/stderr"
exit 1
}
len = g[2] - g[1] + 1
if (g[1] > 1) # compute length of filler
filler = g[1] - last - 1
else
filler = 0
if (filler)
t[field++] = filler
t[field++] = len # length of field
last = g[2]
flist[j++] = field - 1
} else {
if (f[i] > 1)
filler = f[i] - last - 1
else
filler = 0
if (filler)
t[field++] = filler
t[field++] = 1
last = f[i]
flist[j++] = field - 1
}
}
FIELDWIDTHS = join(t, 1, field - 1)
nfields = j - 1
}
{
if (by_fields && suppress && $0 !~ FS)
next
for (i = 1; i <= nfields; i++) {
if ($flist[i] != "") {
printf "%s", $flist[i]
if (i < nfields && $flist[i+1] != "")
printf "%s", OFS
}
}
print ""
}

View File

@ -0,0 +1,16 @@
# dupword --- find duplicate words in text
# Arnold Robbins, arnold@gnu.org, Public Domain
# December 1991
{
$0 = tolower($0)
gsub(/[^A-Za-z0-9 \t]/, "");
if ($1 == prev)
printf("%s:%d: duplicate %s\n",
FILENAME, FNR, $1)
for (i = 2; i <= NF; i++)
if ($i == $(i-1))
printf("%s:%d: duplicate %s\n",
FILENAME, FNR, $i)
prev = $NF
}

View File

@ -0,0 +1,96 @@
# egrep.awk --- simulate egrep in awk
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
# Options:
# -c count of lines
# -s silent - use exit value
# -v invert test, success if no match
# -i ignore case
# -l print filenames only
# -e argument is pattern
BEGIN {
while ((c = getopt(ARGC, ARGV, "ce:svil")) != -1) {
if (c == "c")
count_only++
else if (c == "s")
no_print++
else if (c == "v")
invert++
else if (c == "i")
IGNORECASE = 1
else if (c == "l")
filenames_only++
else if (c == "e")
pattern = Optarg
else
usage()
}
if (pattern == "")
pattern = ARGV[Optind++]
for (i = 1; i < Optind; i++)
ARGV[i] = ""
if (Optind >= ARGC) {
ARGV[1] = "-"
ARGC = 2
} else if (ARGC - Optind > 1)
do_filenames++
# if (IGNORECASE)
# pattern = tolower(pattern)
}
#{
# if (IGNORECASE)
# $0 = tolower($0)
#}
function beginfile(junk)
{
fcount = 0
}
function endfile(file)
{
if (! no_print && count_only)
if (do_filenames)
print file ":" fcount
else
print fcount
total += fcount
}
{
matches = ($0 ~ pattern)
if (invert)
matches = ! matches
fcount += matches # 1 or 0
if (! matches)
next
if (no_print && ! count_only)
nextfile
if (filenames_only && ! count_only) {
print FILENAME
nextfile
}
if (do_filenames && ! count_only)
print FILENAME ":" $0
else if (! count_only)
print
}
END \
{
if (total == 0)
exit 1
exit 0
}
function usage( e)
{
e = "Usage: egrep [-csvil] [-e pat] [files ...]"
print e > "/dev/stderr"
exit 1
}

View File

@ -0,0 +1,71 @@
# extract.awk --- extract files and run programs
# from texinfo files
# Arnold Robbins, arnold@gnu.org, Public Domain, May 1993
BEGIN { IGNORECASE = 1 }
/^@c(omment)?[ \t]+system/ \
{
if (NF < 3) {
e = (FILENAME ":" FNR)
e = (e ": badly formed `system' line")
print e > "/dev/stderr"
next
}
$1 = ""
$2 = ""
stat = system($0)
if (stat != 0) {
e = (FILENAME ":" FNR)
e = (e ": warning: system returned " stat)
print e > "/dev/stderr"
}
}
/^@c(omment)?[ \t]+file/ \
{
if (NF != 3) {
e = (FILENAME ":" FNR ": badly formed `file' line")
print e > "/dev/stderr"
next
}
if ($3 != curfile) {
if (curfile != "")
close(curfile)
curfile = $3
}
for (;;) {
if ((getline line) <= 0)
unexpected_eof()
if (line ~ /^@c(omment)?[ \t]+endfile/)
break
else if (line ~ /^@(end[ \t]+)?group/)
continue
if (index(line, "@") == 0) {
print line > curfile
continue
}
n = split(line, a, "@")
# if a[1] == "", means leading @,
# don't add one back in.
for (i = 2; i <= n; i++) {
if (a[i] == "") { # was an @@
a[i] = "@"
if (a[i+1] == "")
i++
}
}
print join(a, 1, n, SUBSEP) > curfile
}
}
function unexpected_eof()
{
printf("%s:%d: unexpected EOF or error\n", \
FILENAME, FNR) > "/dev/stderr"
exit 1
}
END {
if (curfile)
close(curfile)
}

View File

@ -0,0 +1,14 @@
# histsort.awk --- compact a shell history file
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
# Thanks to Byron Rakitzis for the general idea
{
if (data[$0]++ == 0)
lines[++count] = $0
}
END {
for (i = 1; i <= count; i++)
print lines[i]
}

View File

@ -0,0 +1,69 @@
# id.awk --- implement id in awk
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
# output is:
# uid=12(foo) euid=34(bar) gid=3(baz) \
# egid=5(blat) groups=9(nine),2(two),1(one)
BEGIN \
{
if ((getline < "/dev/user") < 0) {
err = "id: no /dev/user support - cannot run"
print err > "/dev/stderr"
exit 1
}
close("/dev/user")
uid = $1
euid = $2
gid = $3
egid = $4
printf("uid=%d", uid)
pw = getpwuid(uid)
if (pw != "") {
split(pw, a, ":")
printf("(%s)", a[1])
}
if (euid != uid) {
printf(" euid=%d", euid)
pw = getpwuid(euid)
if (pw != "") {
split(pw, a, ":")
printf("(%s)", a[1])
}
}
printf(" gid=%d", gid)
pw = getgrgid(gid)
if (pw != "") {
split(pw, a, ":")
printf("(%s)", a[1])
}
if (egid != gid) {
printf(" egid=%d", egid)
pw = getgrgid(egid)
if (pw != "") {
split(pw, a, ":")
printf("(%s)", a[1])
}
}
if (NF > 4) {
printf(" groups=");
for (i = 5; i <= NF; i++) {
printf("%d", $i)
pw = getgrgid($i)
if (pw != "") {
split(pw, a, ":")
printf("(%s)", a[1])
}
if (i < NF)
printf(",")
}
}
print ""
}

View File

@ -0,0 +1,129 @@
#! /bin/sh
# igawk --- like gawk but do @include processing
# Arnold Robbins, arnold@gnu.org, Public Domain
# July 1993
if [ "$1" = debug ]
then
set -x
shift
else
# cleanup on exit, hangup, interrupt, quit, termination
trap 'rm -f /tmp/ig.[se].$$' 0 1 2 3 15
fi
while [ $# -ne 0 ] # loop over arguments
do
case $1 in
--) shift; break;;
-W) shift
set -- -W"$@"
continue;;
-[vF]) opts="$opts $1 '$2'"
shift;;
-[vF]*) opts="$opts '$1'" ;;
-f) echo @include "$2" >> /tmp/ig.s.$$
shift;;
-f*) f=`echo "$1" | sed 's/-f//'`
echo @include "$f" >> /tmp/ig.s.$$ ;;
-?file=*) # -Wfile or --file
f=`echo "$1" | sed 's/-.file=//'`
echo @include "$f" >> /tmp/ig.s.$$ ;;
-?file) # get arg, $2
echo @include "$2" >> /tmp/ig.s.$$
shift;;
-?source=*) # -Wsource or --source
t=`echo "$1" | sed 's/-.source=//'`
echo "$t" >> /tmp/ig.s.$$ ;;
-?source) # get arg, $2
echo "$2" >> /tmp/ig.s.$$
shift;;
-?version)
echo igawk: version 1.0 1>&2
gawk --version
exit 0 ;;
-[W-]*) opts="$opts '$1'" ;;
*) break;;
esac
shift
done
if [ ! -s /tmp/ig.s.$$ ]
then
if [ -z "$1" ]
then
echo igawk: no program! 1>&2
exit 1
else
echo "$1" > /tmp/ig.s.$$
shift
fi
fi
# at this point, /tmp/ig.s.$$ has the program
gawk -- '
# process @include directives
function pathto(file, i, t, junk)
{
if (index(file, "/") != 0)
return file
for (i = 1; i <= ndirs; i++) {
t = (pathlist[i] "/" file)
if ((getline junk < t) > 0) {
# found it
close(t)
return t
}
}
return ""
}
BEGIN {
path = ENVIRON["AWKPATH"]
ndirs = split(path, pathlist, ":")
for (i = 1; i <= ndirs; i++) {
if (pathlist[i] == "")
pathlist[i] = "."
}
stackptr = 0
input[stackptr] = ARGV[1] # ARGV[1] is first file
for (; stackptr >= 0; stackptr--) {
while ((getline < input[stackptr]) > 0) {
if (tolower($1) != "@include") {
print
continue
}
fpath = pathto($2)
if (fpath == "") {
printf("igawk:%s:%d: cannot find %s\n", \
input[stackptr], FNR, $2) > "/dev/stderr"
continue
}
if (! (fpath in processed)) {
processed[fpath] = input[stackptr]
input[++stackptr] = fpath
} else
print $2, "included in", input[stackptr], \
"already included in", \
processed[fpath] > "/dev/stderr"
}
close(input[stackptr])
}
}' /tmp/ig.s.$$ > /tmp/ig.e.$$
eval gawk -f /tmp/ig.e.$$ $opts -- "$@"
exit $?

View File

@ -0,0 +1,53 @@
# labels.awk
# Arnold Robbins, arnold@gnu.org, Public Domain
# June 1992
# Program to print labels. Each label is 5 lines of data
# that may have blank lines. The label sheets have 2
# blank lines at the top and 2 at the bottom.
BEGIN { RS = "" ; MAXLINES = 100 }
function printpage( i, j)
{
if (Nlines <= 0)
return
printf "\n\n" # header
for (i = 1; i <= Nlines; i += 10) {
if (i == 21 || i == 61)
print ""
for (j = 0; j < 5; j++) {
if (i + j > MAXLINES)
break
printf " %-41s %s\n", line[i+j], line[i+j+5]
}
print ""
}
printf "\n\n" # footer
for (i in line)
line[i] = ""
}
# main rule
{
if (Count >= 20) {
printpage()
Count = 0
Nlines = 0
}
n = split($0, a, "\n")
for (i = 1; i <= n; i++)
line[++Nlines] = a[i]
for (; i <= 5; i++)
line[++Nlines] = ""
Count++
}
END \
{
printpage()
}

View File

@ -0,0 +1,53 @@
# split.awk --- do split in awk
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
# usage: split [-num] [file] [outname]
BEGIN {
outfile = "x" # default
count = 1000
if (ARGC > 4)
usage()
i = 1
if (ARGV[i] ~ /^-[0-9]+$/) {
count = -ARGV[i]
ARGV[i] = ""
i++
}
# test argv in case reading from stdin instead of file
if (i in ARGV)
i++ # skip data file name
if (i in ARGV) {
outfile = ARGV[i]
ARGV[i] = ""
}
s1 = s2 = "a"
out = (outfile s1 s2)
}
{
if (++tcount > count) {
close(out)
if (s2 == "z") {
if (s1 == "z") {
printf("split: %s is too large to split\n", \
FILENAME) > "/dev/stderr"
exit 1
}
s1 = chr(ord(s1) + 1)
s2 = "a"
} else
s2 = chr(ord(s2) + 1)
out = (outfile s1 s2)
tcount = 1
}
print > out
}
function usage( e)
{
e = "usage: split [-num] [file] [outname]"
print e > "/dev/stderr"
exit 1
}

View File

@ -0,0 +1,38 @@
# tee.awk --- tee in awk
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
# Revised December 1995
BEGIN \
{
for (i = 1; i < ARGC; i++)
copy[i] = ARGV[i]
if (ARGV[1] == "-a") {
append = 1
delete ARGV[1]
delete copy[1]
ARGC--
}
if (ARGC < 2) {
print "usage: tee [-a] file ..." > "/dev/stderr"
exit 1
}
ARGV[1] = "-"
ARGC = 2
}
{
# moving the if outside the loop makes it run faster
if (append)
for (i in copy)
print >> copy[i]
else
for (i in copy)
print > copy[i]
print
}
END \
{
for (i in copy)
close(copy[i])
}

View File

@ -0,0 +1,46 @@
# translate --- do tr like stuff
# Arnold Robbins, arnold@gnu.org, Public Domain
# August 1989
# bugs: does not handle things like: tr A-Z a-z, it has
# to be spelled out. However, if `to' is shorter than `from',
# the last character in `to' is used for the rest of `from'.
function stranslate(from, to, target, lf, lt, t_ar, i, c)
{
lf = length(from)
lt = length(to)
for (i = 1; i <= lt; i++)
t_ar[substr(from, i, 1)] = substr(to, i, 1)
if (lt < lf)
for (; i <= lf; i++)
t_ar[substr(from, i, 1)] = substr(to, lt, 1)
for (i = 1; i <= lf; i++) {
c = substr(from, i, 1)
if (index(target, c) > 0)
gsub(c, t_ar[c], target)
}
return target
}
function translate(from, to)
{
return $0 = stranslate(from, to, $0)
}
# main program
BEGIN {
if (ARGC < 3) {
print "usage: translate from to" > "/dev/stderr"
exit
}
FROM = ARGV[1]
TO = ARGV[2]
ARGC = 2
ARGV[1] = "-"
}
{
translate(FROM, TO)
print
}

View File

@ -0,0 +1,116 @@
# uniq.awk --- do uniq in awk
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
function usage( e)
{
e = "Usage: uniq [-udc [-n]] [+n] [ in [ out ]]"
print e > "/dev/stderr"
exit 1
}
# -c count lines. overrides -d and -u
# -d only repeated lines
# -u only non-repeated lines
# -n skip n fields
# +n skip n characters, skip fields first
BEGIN \
{
count = 1
outputfile = "/dev/stdout"
opts = "udc0:1:2:3:4:5:6:7:8:9:"
while ((c = getopt(ARGC, ARGV, opts)) != -1) {
if (c == "u")
non_repeated_only++
else if (c == "d")
repeated_only++
else if (c == "c")
do_count++
else if (index("0123456789", c) != 0) {
# getopt requires args to options
# this messes us up for things like -5
if (Optarg ~ /^[0-9]+$/)
fcount = (c Optarg) + 0
else {
fcount = c + 0
Optind--
}
} else
usage()
}
if (ARGV[Optind] ~ /^\+[0-9]+$/) {
charcount = substr(ARGV[Optind], 2) + 0
Optind++
}
for (i = 1; i < Optind; i++)
ARGV[i] = ""
if (repeated_only == 0 && non_repeated_only == 0)
repeated_only = non_repeated_only = 1
if (ARGC - Optind == 2) {
outputfile = ARGV[ARGC - 1]
ARGV[ARGC - 1] = ""
}
}
function are_equal( n, m, clast, cline, alast, aline)
{
if (fcount == 0 && charcount == 0)
return (last == $0)
if (fcount > 0) {
n = split(last, alast)
m = split($0, aline)
clast = join(alast, fcount+1, n)
cline = join(aline, fcount+1, m)
} else {
clast = last
cline = $0
}
if (charcount) {
clast = substr(clast, charcount + 1)
cline = substr(cline, charcount + 1)
}
return (clast == cline)
}
NR == 1 {
last = $0
next
}
{
equal = are_equal()
if (do_count) { # overrides -d and -u
if (equal)
count++
else {
printf("%4d %s\n", count, last) > outputfile
last = $0
count = 1 # reset
}
next
}
if (equal)
count++
else {
if ((repeated_only && count > 1) ||
(non_repeated_only && count == 1))
print last > outputfile
last = $0
count = 1
}
}
END {
if (do_count)
printf("%4d %s\n", count, last) > outputfile
else if ((repeated_only && count > 1) ||
(non_repeated_only && count == 1))
print last > outputfile
}

View File

@ -0,0 +1,67 @@
# wc.awk --- count lines, words, characters
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
# Options:
# -l only count lines
# -w only count words
# -c only count characters
#
# Default is to count lines, words, characters
BEGIN {
# let getopt print a message about
# invalid options. we ignore them
while ((c = getopt(ARGC, ARGV, "lwc")) != -1) {
if (c == "l")
do_lines = 1
else if (c == "w")
do_words = 1
else if (c == "c")
do_chars = 1
}
for (i = 1; i < Optind; i++)
ARGV[i] = ""
# if no options, do all
if (! do_lines && ! do_words && ! do_chars)
do_lines = do_words = do_chars = 1
print_total = (ARGC - i > 2)
}
function beginfile(file) {
chars = lines = words = 0
fname = FILENAME
}
function endfile(file)
{
tchars += chars
tlines += lines
twords += words
if (do_lines)
printf "\t%d", lines
if (do_words)
printf "\t%d", words
if (do_chars)
printf "\t%d", chars
printf "\t%s\n", fname
}
# do per line
{
chars += length($0) + 1 # get newline
lines++
words += NF
}
END {
if (print_total) {
if (do_lines)
printf "\t%d", tlines
if (do_words)
printf "\t%d", twords
if (do_chars)
printf "\t%d", tchars
print "\ttotal"
}
}

View File

@ -0,0 +1,13 @@
# Print list of word frequencies
{
$0 = tolower($0) # remove case distinctions
gsub(/[^a-z0-9_ \t]/, "", $0) # remove punctuation
for (i = 1; i <= NF; i++)
freq[$i]++
}
END {
sort = "sort +1 -nr"
for (word in freq)
printf "%s\t%d\n", word, freq[word] | sort
close(sort)
}

View File

@ -0,0 +1,87 @@
# extract.awk --- extract files and run programs
# from texinfo files
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
BEGIN { IGNORECASE = 1 }
/^@c(omment)?[ \t]+system/ \
{
if (NF < 3) {
e = (FILENAME ":" FNR)
e = (e ": badly formed `system' line")
print e > "/dev/stderr"
next
}
$1 = ""
$2 = ""
stat = system($0)
if (stat != 0) {
e = (FILENAME ":" FNR)
e = (e ": warning: system returned " stat)
print e > "/dev/stderr"
}
}
/^@c(omment)?[ \t]+file/ \
{
if (NF != 3) {
e = (FILENAME ":" FNR ": badly formed `file' line")
print e > "/dev/stderr"
next
}
if ($3 != curfile) {
if (curfile != "")
close(curfile)
curfile = $3
}
for (;;) {
if ((getline line) <= 0)
unexpected_eof()
if (line ~ /^@c(omment)?[ \t]+endfile/)
break
else if (line ~ /^@(end[ \t]+)?group/)
continue
if (index(line, "@") == 0) {
print line > curfile
continue
}
n = split(line, a, "@")
# if a[1] == "", means leading @,
# don't add one back in.
for (i = 2; i <= n; i++) {
if (a[i] == "") { # was an @@
a[i] = "@"
if (a[i+1] == "")
i++
}
}
print join(a, 1, n, SUBSEP) > curfile
}
}
function unexpected_eof()
{
printf("%s:%d: unexpected EOF or error\n", \
FILENAME, FNR) > "/dev/stderr"
exit 1
}
END {
if (curfile)
close(curfile)
}
# join.awk --- join an array into a string
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
function join(array, start, end, sep, result, i)
{
if (sep == "")
sep = " "
else if (sep == SUBSEP) # magic value
sep = ""
result = array[start]
for (i = start + 1; i <= end; i++)
result = result sep array[i]
return result
}

View File

@ -0,0 +1,2 @@
some makes are stupid and will not check a directory
against a file, so this file is a place holder. gack.

3983
contrib/awk/awktab.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
* Copyright (C) 1986, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@ -811,7 +811,8 @@ check_pos:
*cp++ = '#';
if (zero_flag)
*cp++ = '0';
cp = strcpy(cp, "*.*") + 3;
strcpy(cp, "*.*");
cp += 3;
*cp++ = cs1;
*cp = '\0';
#ifndef GFMT_WORKAROUND

225
contrib/awk/configh.in Normal file
View File

@ -0,0 +1,225 @@
/* configh.in. Generated automatically from configure.in by autoheader. */
/*
* acconfig.h -- configuration definitions for gawk.
*/
/*
* Copyright (C) 1995-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
*
* GAWK is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GAWK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* Define if on AIX 3.
System headers sometimes define this.
We just want to avoid a redefinition error message. */
#ifndef _ALL_SOURCE
#undef _ALL_SOURCE
#endif
/* Define if using alloca.c. */
#undef C_ALLOCA
/* Define if type char is unsigned and you are not using gcc. */
#ifndef __CHAR_UNSIGNED__
#undef __CHAR_UNSIGNED__
#endif
/* Define to empty if the keyword does not work. */
#undef const
/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems.
This function is required for alloca.c support on those systems. */
#undef CRAY_STACKSEG_END
/* Define to the type of elements in the array set by `getgroups'.
Usually this is either `int' or `gid_t'. */
#undef GETGROUPS_T
/* Define if the `getpgrp' function takes no argument. */
#undef GETPGRP_VOID
/* Define to `int' if <sys/types.h> doesn't define. */
#undef gid_t
/* Define if you have alloca, as a function or macro. */
#undef HAVE_ALLOCA
/* Define if you have <alloca.h> and it should be used (not on Ultrix). */
#undef HAVE_ALLOCA_H
/* Define if you don't have vprintf but do have _doprnt. */
#undef HAVE_DOPRNT
/* Define if you have a working `mmap' system call. */
#undef HAVE_MMAP
/* Define if your struct stat has st_blksize. */
#undef HAVE_ST_BLKSIZE
/* Define if you have the ANSI # stringizing operator in cpp. */
#undef HAVE_STRINGIZE
/* Define if you have <sys/wait.h> that is POSIX.1 compatible. */
#undef HAVE_SYS_WAIT_H
/* Define if your struct tm has tm_zone. */
#undef HAVE_TM_ZONE
/* Define if you don't have tm_zone but do have the external array
tzname. */
#undef HAVE_TZNAME
/* Define if you have the vprintf function. */
#undef HAVE_VPRINTF
/* Define if on MINIX. */
#undef _MINIX
/* Define to `int' if <sys/types.h> doesn't define. */
#undef pid_t
/* Define if the system does not provide POSIX.1 features except
with this defined. */
#undef _POSIX_1_SOURCE
/* Define if you need to in order for stat and other things to work. */
#undef _POSIX_SOURCE
/* Define as the return type of signal handlers (int or void). */
#undef RETSIGTYPE
/* Define to `unsigned' if <sys/types.h> doesn't define. */
#undef size_t
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
automatically deduced at run-time.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown
*/
#undef STACK_DIRECTION
/* Define if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
/* Define if your <sys/time.h> declares struct tm. */
#undef TM_IN_SYS_TIME
/* Define to `int' if <sys/types.h> doesn't define. */
#undef uid_t
#undef HAVE_STRINGIZE /* can use ANSI # operator in cpp */
#undef REGEX_MALLOC /* use malloc instead of alloca in regex.c */
#undef SPRINTF_RET /* return type of sprintf */
#undef BITOPS /* bitwise ops (undocumented feature) */
#undef NONDECDATA /* non-decimal input data (undocumented feature) */
#undef _FILE_OFFSET_BITS /* bits in a file offset, where this matters */
#undef _LARGEFILE_SOURCE /* makes fseeko etc. visible on some hosts */
#undef _LARGE_FILES /* emables large files on AIX-style hosts */
/* Define if you have the fmod function. */
#undef HAVE_FMOD
/* Define if you have the getpagesize function. */
#undef HAVE_GETPAGESIZE
/* Define if you have the madvise function. */
#undef HAVE_MADVISE
/* Define if you have the memcmp function. */
#undef HAVE_MEMCMP
/* Define if you have the memcpy function. */
#undef HAVE_MEMCPY
/* Define if you have the memset function. */
#undef HAVE_MEMSET
/* Define if you have the setlocale function. */
#undef HAVE_SETLOCALE
/* Define if you have the strchr function. */
#undef HAVE_STRCHR
/* Define if you have the strerror function. */
#undef HAVE_STRERROR
/* Define if you have the strftime function. */
#undef HAVE_STRFTIME
/* Define if you have the strncasecmp function. */
#undef HAVE_STRNCASECMP
/* Define if you have the strtod function. */
#undef HAVE_STRTOD
/* Define if you have the system function. */
#undef HAVE_SYSTEM
/* Define if you have the tzset function. */
#undef HAVE_TZSET
/* Define if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H
/* Define if you have the <locale.h> header file. */
#undef HAVE_LOCALE_H
/* Define if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define if you have the <signum.h> header file. */
#undef HAVE_SIGNUM_H
/* Define if you have the <stdarg.h> header file. */
#undef HAVE_STDARG_H
/* Define if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define if you have the <sys/param.h> header file. */
#undef HAVE_SYS_PARAM_H
/* Define if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define if you have the m library (-lm). */
#undef HAVE_LIBM
/* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS
/* Define to make ftello visible on some hosts (e.g. HP-UX 10.20). */
#undef _LARGEFILE_SOURCE
/* Define for large files, on AIX-style hosts. */
#undef _LARGE_FILES
/* Define to make ftello visible on some hosts (e.g. glibc 2.1.3). */
#undef _XOPEN_SOURCE
#include <custom.h> /* overrides for stuff autoconf can't deal with */

3685
contrib/awk/configure vendored Executable file

File diff suppressed because it is too large Load Diff

165
contrib/awk/configure.in Normal file
View File

@ -0,0 +1,165 @@
dnl
dnl configure.in --- autoconf input file for gawk
dnl
dnl Copyright (C) 1995-2000 the Free Software Foundation, Inc.
dnl
dnl This file is part of GAWK, the GNU implementation of the
dnl AWK Programming Language.
dnl
dnl GAWK is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2 of the License, or
dnl (at your option) any later version.
dnl
dnl GAWK is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
dnl
dnl Process this file with autoconf to produce a configure script.
dnl this makes sure that the local install-sh gets found
dnl define(AC_CONFIG_AUX_DIR,)
dnl This is the configure.in script proper
AC_INIT(awk.h)
AC_PREREQ(2.12)
AC_CONFIG_HEADER(config.h:configh.in)
dnl Additional argument stuff
AC_ARG_ENABLE(bitops, [ --enable-bitops Enable Octal and Hex constants and bit functions], AC_DEFINE(BITOPS))
AC_ARG_ENABLE(non-decimal-data, [ --enable-non-decimal-data Enable Octal and Hex constants as valid input data], AC_DEFINE(NONDECDATA))
dnl checks for programs
AC_PROG_YACC
AC_PROG_LN_S
AC_PROG_CC
AC_PROG_CPP
# This is a hack. Different versions of install on different systems
# are just too different. Chuck it and use install-sh.
INSTALL="$srcdir/install-sh -c"; export INSTALL
AC_PROG_INSTALL
AC_PROG_MAKE_SET
if test "$CFLAGS" = ""
then
dnl no user provided CFLAGS, feel free to do this our way
if test "$GCC" = yes
then
CFLAGS="-g -O"
else
dnl go for speed, not debugging. :-)
CFLAGS="-O"
fi
fi
# This is mainly for my use during testing and development.
# Yes, it's a bit of a hack.
if test -f $srcdir/.developing
then
AC_DEFINE(BITOPS)
AC_DEFINE(NONDECDATA)
CFLAGS="$CFLAGS -DARRAYDEBUG"
fi
AC_SUBST(CFLAGS)
dnl checks for systems
AC_AIX
AC_ISC_POSIX
AC_MINIX
GAWK_AC_SYS_LARGEFILE
GAWK_AC_AIX_TWEAK
if test "$ISC" = 1 # will be set by test for ISC
then
dnl need -D_SYSV3 for ISC
CFLAGS="$CFLAGS -D_SYSV3"
fi
dnl checks for header files
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(limits.h locale.h stdarg.h unistd.h signum.h sys/param.h string.h)
if test "$ac_cv_header_string_h" = yes
then
AC_CHECK_HEADERS(memory.h)
else
AC_CHECK_HEADERS(strings.h)
fi
dnl checks for typedefs
AC_TYPE_PID_T
AC_TYPE_SIGNAL
AC_SIZE_T
AC_TYPE_GETGROUPS
AC_EGREP_HEADER([int.*sprintf], stdio.h,
AC_DEFINE(SPRINTF_RET, int),
AC_DEFINE(SPRINTF_RET, char *))
dnl checks for functions
if test "$YACC" = "bison -y" ||
{ test -f $srcdir/awktab.c && grep 'alloca *(' $srcdir/awktab.c > /dev/null; }
then
AC_FUNC_ALLOCA
fi
AC_DEFINE(REGEX_MALLOC)
AC_FUNC_VPRINTF
AC_CHECK_LIB(m, fmod)
AC_CHECK_FUNCS(madvise memset memcpy memcmp fmod setlocale strchr strerror \
strftime strncasecmp strtod system tzset)
dnl see if we have mmap
AC_FUNC_MMAP
dnl check for how to use getpgrp
dnl have to hardwire it for VMS POSIX. Sigh.
if (uname) > /dev/null 2>&1
then
case `uname` in
*VMS*|*BeOS*)
AC_DEFINE(GETPGRP_VOID)
;;
*HP-UX*) # not getpgrp related
if test "$GCC" = yes
then
:
else
# stupid HP linker leaves the output file
# around even when a link fails. This confuses
# the alloca tests, so we have to do this
# manually. Sucks big time.
LIBS="$LIBS -lPW"
fi
# have to do the getpgrp test since won't
# fall into the default
AC_FUNC_GETPGRP
;;
*) AC_FUNC_GETPGRP
;;
esac
else
AC_FUNC_GETPGRP
fi
dnl checks for structure members
AC_STRUCT_ST_BLKSIZE
AC_HEADER_TIME
AC_STRUCT_TM
AC_STRUCT_TIMEZONE
dnl checks for compiler characteristics
AC_C_CHAR_UNSIGNED
AC_C_CONST
GAWK_AC_C_STRINGIZE
AC_OUTPUT(Makefile doc/Makefile test/Makefile awklib/Makefile, [date > stamp-h])

View File

@ -11,7 +11,7 @@
*/
/*
* Copyright (C) 1995-1999 the Free Software Foundation, Inc.
* Copyright (C) 1995-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.

View File

@ -1,3 +1,56 @@
Mon Aug 7 15:23:00 2000 Arnold D. Robbins <arnold@skeeve.com>
* Release 3.0.6: Release tar file made.
Sun Jun 25 15:08:19 2000 Arnold D. Robbins <arnold@skeeve.com>
* Release 3.0.5: Release tar file made.
Wed May 17 19:04:54 2000 Arnold D. Robbins <arnold@skeeve.com>
* gawk.texi, gawk.1, awkcard.in: Documented %u. Ooops.
Tue May 2 11:44:13 2000 Arnold D. Robbins <arnold@skeeve.com>
* texinfo.tex: Updated to version 1999-10-01.07.
* gawk.texi: Redid page breaking for new texinfo.tex.
Thu Apr 6 12:32:49 2000 Arnold D. Robbins <arnold@skeeve.com>
* gawk.texi: Change info dir file entry to `(gawk)' from
`(gawk.info)'.
* Makefile.in [$(infodir)/gawk.info]: Fix grep test is
accordance with above.
Sun Feb 13 15:36:32 2000 Paul Eggert <eggert@twinsun.com>
* gawk.texi: Mention that arithmetic is done in double
precision floating point, and point to Goldberg's paper for
people who want to know more. Fix some other minor floating
point discussion issues.
Wed Nov 3 17:04:35 1999 Arnold D. Robbins <arnold@skeeve.com>
* gawk.1: Lots of troff ``lint'' from Paul Eggert. Not all
of his changes, just the ones I thought worth doing.
Mon Oct 11 16:53:54 1999 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (gawk.dvi): Put $(srcdir) first in TEXINPUTS,
and also just use texi2dvi, don't run texindex and tex
manually. Doing so is no longer necessary.
Mon Aug 9 13:06:01 1999 Arnold D. Robbins <arnold@skeeve.com>
* gawk.texi: New node `Array Efficiency' on the best use
of subscripting to avoid memory bloat.
Thu Jul 29 23:15:34 1999 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in ($(infodir)/gawk.info): Removed loop around
$(INSTALL_DATA), since there's only one Info file to install,
install it directly.
Wed Jun 30 16:14:36 1999 Arnold D. Robbins <arnold@gnu.org>
* Release 3.0.4: Release tar file made. This time for sure.

129
contrib/awk/doc/Makefile.in Normal file
View File

@ -0,0 +1,129 @@
# Makefile for GNU Awk documentation.
#
# Copyright (C) 1993-2000 the Free Software Foundation, Inc.
#
# This file is part of GAWK, the GNU implementation of the
# AWK Programming Language.
#
# GAWK is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# GAWK is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
SHELL = /bin/sh
srcdir = @srcdir@
VPATH = @srcdir@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
prefix = @prefix@
exec_prefix = @exec_prefix@
binprefix =
manprefix =
bindir = @bindir@
libdir = @libdir@
mandir = @mandir@/man1
manext = .1
infodir = @infodir@
datadir = @datadir@/awk
TEXI2DVI = texi2dvi
TEX = tex
MAKEINFO = makeinfo --no-split
TROFF = groff -t -Tps
SEDME = sed -e "s/^level0 restore/level0 restore flashme 100 72 moveto (Copyright `date '+%m-%d-%y %T'`, FSF, Inc. (all)) show/" \
-e "s/^\/level0 save def/\/level0 save def 30 -48 translate/"
DOCS= gawk.1 igawk.1 gawk.texi
TEXFILES= gawk.aux gawk.cp gawk.cps gawk.fn gawk.fns gawk.ky gawk.kys \
gawk.pg gawk.pgs gawk.toc gawk.tp gawk.tps gawk.vr gawk.vrs
ALLDOC= gawk.dvi $(TEXFILES) gawk.log awkcard.tr
CARDSRC = $(srcdir)/macros $(srcdir)/cardfonts $(srcdir)/colors awkcard.tr
CARDSRC_N = $(srcdir)/macros $(srcdir)/cardfonts $(srcdir)/no.colors awkcard.tr
CARDFILES= $(CARDSRC) ad.block awkcard.in setter.outline
# Use this if your troff can correctly handle macros from 'colors' file
AWKCARD = awkcard.ps
# Uncomment the following definition of AWKCARD if your troff can produce
# Postscript but still has troubles with macros from 'colors'. As this
# is not groff you will have to change TROFF macro as well. Do not forget
# to ensure that awkcard.tr is processed by tbl.
#AWKCARD = awkcard.nc
all: $(DOCS) info
install: $(mandir)/gawk$(manext) $(mandir)/igawk$(manext) $(infodir)/gawk.info
$(infodir)/gawk.info::
-if test -f gawk.info; then d=.; \
else d=$(srcdir); fi; \
if [ -f $(infodir)/dir -a -f $(infodir)/gawk.info ] \
&& cmp $$d/gawk.info $(infodir)/gawk.info > /dev/null \
&& grep '(gawk)' $(infodir)/dir > /dev/null; then \
exit 0; \
fi; \
$(INSTALL_DATA) $$d/gawk.info $(infodir)/gawk.info ; \
if $(SHELL) -c 'install-info --version' > /dev/null 2>&1 ; \
then install-info --info-dir=$(infodir) gawk.info ; \
else true ; fi; exit 0
$(mandir)/gawk$(manext):: gawk.1
$(INSTALL_DATA) $(srcdir)/gawk.1 $(mandir)/gawk$(manext)
$(mandir)/igawk$(manext):: igawk.1
$(INSTALL_DATA) $(srcdir)/igawk.1 $(mandir)/igawk$(manext)
uninstall:
rm -f $(mandir)/gawk$(manext) $(mandir)/igawk$(manext) $(infodir)/gawk.info*
dvi: gawk.dvi
gawk.dvi: gawk.texi
-TEXINPUTS=$(srcdir):$$TEXINPUTS $(TEXI2DVI) $(srcdir)/gawk.texi
info: gawk.info
gawk.info: gawk.texi
$(MAKEINFO) $(srcdir)/gawk.texi
postscript: dvi gawk.1 igawk.1 $(AWKCARD)
-groff -man $(srcdir)/gawk.1 > gawk.1.ps
-groff -man $(srcdir)/igawk.1 > igawk.1.ps
dvips -o gawk.ps gawk.dvi
awkcard.tr: awkcard.in
sed 's:SRCDIR:$(srcdir):' < $(srcdir)/awkcard.in > awkcard.tr
awkcard.ps: $(CARDFILES)
$(TROFF) $(CARDSRC) | $(SEDME) | cat $(srcdir)/setter.outline - > awkcard.ps
awkcard.nc: $(CARDFILES)
$(TROFF) $(CARDSRC_N) | $(SEDME) | cat $(srcdir)/setter.outline - > awkcard.ps && touch awkcard.nc
clean:
rm -f *.ps $(ALLDOC) *~ awkcard.nc
distclean: clean
rm -f Makefile
maintainer-clean: distclean
@echo "This command is intended for maintainers to use; it"
@echo "deletes files that may require special tools to rebuild."
rm -f gawk.info

View File

@ -0,0 +1,19 @@
Mon Dec 9 12:45:48 EST 1996
The AWK reference card included here requires a modern version of troff
(ditroff). GNU Troff (groff) is known to work.
If your troff is able to produce Postscript but does not know how to
properly use the macros from `colors' file then try to uncomment in
Makefile the defintion which sets AWKCARD to awkcard.nc (no colors).
This will definitely require changes to the TROFF macro and you have to
ensure that the tbl preprocessor is called. For example, the following
modifications on NeXT:
TROFF = tbl
SEDME = ptroff -t | sed -e \
"s/^level0 restore/level0 restore flashme 100 72 moveto\
(Copyright `date`, FSF, Inc. (all)) show/" \
-e "s/^\/level0 save def/\/level0 save def 30 -48 translate/"
will produce a correctly formatted, albeit monochromatic, reference card.

49
contrib/awk/doc/ad.block Normal file
View File

@ -0,0 +1,49 @@
.\" AWK Reference Card --- Arnold Robbins, arnold@gnu.org
.\" This file is the Ad block (included in cover)
.\"
.\" Copyright (C) 1996, 98 Free Software Foundation, Inc.
.\"
.\" Permission is granted to make and distribute verbatim copies of
.\" this reference card provided the copyright notice and this permission
.\" notice are preserved on all copies.
.\"
.\" Permission is granted to process this file through troff and print the
.\" results, provided the printed document carries copying permission
.\" notice identical to this one except for the removal of this paragraph
.\" (this paragraph not being relevant to the printed reference card).
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" reference card under the conditions for verbatim copying, provided that
.\" the entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Permission is granted to copy and distribute translations of this
.\" reference card into another language, under the above conditions for
.\" modified versions, except that this permission notice may be stated in
.\" a translation approved by the Foundation.
.\"
.ft HB
.ps 10
.vs 12
.ES
.nf
.ce 7
\*(CBFree Software Foundation, Inc.
.ft H
59 Temple Place \(em Suite 330
Boston, MA 02111-1307 USA
Phone: +1-617-542-5942
Fax (including Japan): +1-617-542-2652
E-mail: gnu@gnu.org
URL: http://www.gnu.org
.ce 7
.ft HB
\*(CGFree Software
Source Distributions on CD-ROM
Deluxe Distributions
Emacs, Gawk, Make and GDB Manuals
Emacs and GDB References\*(CX
.EB "\f(HBOTHER FSF PRODUCTS:\*(FR"
.ps
.vs

1550
contrib/awk/doc/awkcard.in Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,150 @@
Draft for ACM SIGPLAN Patterns (Language Trends)
1996
Why GAWK for AI?
Ronald P. Loui
Most people are surprised when I tell them what language we use in our
undergraduate AI programming class. That's understandable. We use
GAWK. GAWK, Gnu's version of Aho, Weinberger, and Kernighan's old
pattern scanning language isn't even viewed as a programming language by
most people. Like PERL and TCL, most prefer to view it as a "scripting
language." It has no objects; it is not functional; it does no built-in
logic programming. Their surprise turns to puzzlement when I confide
that (a) while the students are allowed to use any language they want;
(b) with a single exception, the best work consistently results from
those working in GAWK. (footnote: The exception was a PASCAL
programmer who is now an NSF graduate fellow getting a Ph.D. in
mathematics at Harvard.) Programmers in C, C++, and LISP haven't even
been close (we have not seen work in PROLOG or JAVA).
Why GAWK?
There are some quick answers that have to do with the pragmatics of
undergraduate programming. Then there are more instructive answers that
might be valuable to those who debate programming paradigms or to those
who study the history of AI languages. And there are some deep
philosophical answers that expose the nature of reasoning and symbolic
AI. I think the answers, especially the last ones, can be even more
surprising than the observed effectiveness of GAWK for AI.
First it must be confessed that PERL programmers can cobble together AI
projects well, too. Most of GAWK's attractiveness is reproduced in
PERL, and the success of PERL forebodes some of the success of GAWK.
Both are powerful string-processing languages that allow the programmer
to exploit many of the features of a UNIX environment. Both provide
powerful constructions for manipulating a wide variety of data in
reasonably efficient ways. Both are interpreted, which can reduce
development time. Both have short learning curves. The GAWK manual can
be consumed in a single lab session and the language can be mastered by
the next morning by the average student. GAWK's automatic
initialization, implicit coercion, I/O support and lack of pointers
forgive many of the mistakes that young programmers are likely to make.
Those who have seen C but not mastered it are happy to see that GAWK
retains some of the same sensibilities while adding what must be
regarded as spoonsful of syntactic sugar. Some will argue that
PERL has superior functionality, but for quick AI applications, the
additional functionality is rarely missed. In fact, PERL's terse syntax
is not friendly when regular expressions begin to proliferate and
strings contain fragments of HTML, WWW addresses, or shell commands.
PERL provides new ways of doing things, but not necessarily ways of
doing new things.
In the end, despite minor difference, both PERL and GAWK minimize
programmer time. Neither really provides the programmer the setting in
which to worry about minimizing run-time.
There are further simple answers. Probably the best is the fact that
increasingly, undergraduate AI programming is involving the Web. Oren
Etzioni (University of Washington, Seattle) has for a while been arguing
that the "softbot" is replacing the mechanical engineers' robot as the
most glamorous AI testbed. If the artifact whose behavior needs to be
controlled in an intelligent way is the software agent, then a language
that is well-suited to controlling the software environment is the
appropriate language. That would imply a scripting language. If the
robot is KAREL, then the right language is "turn left; turn right." If
the robot is Netscape, then the right language is something that can
generate "netscape -remote 'openURL(http://cs.wustl.edu/~loui)'" with
elan.
Of course, there are deeper answers. Jon Bentley found two pearls in
GAWK: its regular expressions and its associative arrays. GAWK asks
the programmer to use the file system for data organization and the
operating system for debugging tools and subroutine libraries. There is
no issue of user-interface. This forces the programmer to return to the
question of what the program does, not how it looks. There is no time
spent programming a binsort when the data can be shipped to /bin/sort
in no time. (footnote: I am reminded of my IBM colleague Ben Grosof's
advice for Palo Alto: Don't worry about whether it's highway 101 or 280.
Don't worry if you have to head south for an entrance to go north. Just
get on the highway as quickly as possible.)
There are some similarities between GAWK and LISP that are illuminating.
Both provided a powerful uniform data structure (the associative array
implemented as a hash table for GAWK and the S-expression, or list of
lists, for LISP). Both were well-supported in their environments (GAWK
being a child of UNIX, and LISP being the heart of lisp machines). Both
have trivial syntax and find their power in the programmer's willingness
to use the simple blocks to build a complex approach.
Deeper still, is the nature of AI programming. AI is about
functionality and exploratory programming. It is about bottom-up design
and the building of ambitions as greater behaviors can be demonstrated.
Woe be to the top-down AI programmer who finds that the bottom-level
refinements, "this subroutine parses the sentence," cannot actually be
implemented. Woe be to the programmer who perfects the data structures
for that heapsort when the whole approach to the high-level problem
needs to be rethought, and the code is sent to the junkheap the next day.
AI programming requires high-level thinking. There have always been a few
gifted programmers who can write high-level programs in assembly language.
Most however need the ambient abstraction to have a higher floor.
Now for the surprising philosophical answers. First, AI has discovered
that brute-force combinatorics, as an approach to generating intelligent
behavior, does not often provide the solution. Chess, neural nets, and
genetic programming show the limits of brute computation. The
alternative is clever program organization. (footnote: One might add
that the former are the AI approaches that work, but that is easily
dismissed: those are the AI approaches that work in general, precisely
because cleverness is problem-specific.) So AI programmers always want
to maximize the content of their program, not optimize the efficiency
of an approach. They want minds, not insects. Instead of enumerating
large search spaces, they define ways of reducing search, ways of
bringing different knowledge to the task. A language that maximizes
what the programmer can attempt rather than one that provides tremendous
control over how to attempt it, will be the AI choice in the end.
Second, inference is merely the expansion of notation. No matter whether
the logic that underlies an AI program is fuzzy, probabilistic, deontic,
defeasible, or deductive, the logic merely defines how strings can be
transformed into other strings. A language that provides the best
support for string processing in the end provides the best support for
logic, for the exploration of various logics, and for most forms of
symbolic processing that AI might choose to call "reasoning" instead of
"logic." The implication is that PROLOG, which saves the AI programmer
from having to write a unifier, saves perhaps two dozen lines of GAWK
code at the expense of strongly biasing the logic and representational
expressiveness of any approach.
I view these last two points as news not only to the programming language
community, but also to much of the AI community that has not reflected on
the past decade's lessons.
In the puny language, GAWK, which Aho, Weinberger, and Kernighan thought
not much more important than grep or sed, I find lessons in AI's trends,
AI's history, and the foundations of AI. What I have found not only
surprising but also hopeful, is that when I have approached the AI
people who still enjoy programming, some of them are not the least bit
surprised.
R. Loui (loui@ai.wustl.edu) is Associate Professor of Computer Science,
at Washington University in St. Louis. He has published in AI Journal,
Computational Intelligence, ACM SIGART, AI Magazine, AI and Law, the ACM
Computing Surveys Symposium on AI, Cognitive Science, Minds and
Machines, Journal of Philosophy, and is on this year's program
committees for AAAI (National AI conference) and KR (Knowledge
Representation and Reasoning).

37
contrib/awk/doc/cardfonts Normal file
View File

@ -0,0 +1,37 @@
.\" AWK Reference Card --- Arnold Robbins, arnold@gnu.org
.\" cardfonts --- this file sets the fonts to use for the reference card
.\"
.\" Copyright (C) 1996 Free Software Foundation, Inc.
.\"
.\" Permission is granted to make and distribute verbatim copies of
.\" this reference card provided the copyright notice and this permission
.\" notice are preserved on all copies.
.\"
.\" Permission is granted to process this file through troff and print the
.\" results, provided the printed document carries copying permission
.\" notice identical to this one except for the removal of this paragraph
.\" (this paragraph not being relevant to the printed reference card).
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" reference card under the conditions for verbatim copying, provided that
.\" the entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Permission is granted to copy and distribute translations of this
.\" reference card into another language, under the above conditions for
.\" modified versions, except that this permission notice may be stated in
.\" a translation approved by the Foundation.
.\"
.ig
Strings for inline font change.
FR - font roman
FI - font italic
FC - font courier
..
.ds FR \fR
.ds FI \fI
.ds FC \f(CB
.ds RN Times Roman
.ds IN Times Italic
.ds CN Courier Bold
.ds AM \fIThe GNU Awk User's Guide\fP

39
contrib/awk/doc/colors Normal file
View File

@ -0,0 +1,39 @@
.\" AWK Reference Card --- Arnold Robbins, arnold@gnu.org
.\" This file sets the colors to use.
.\"
.\" Copyright (C) 1996,97,99 Free Software Foundation, Inc.
.\"
.\" Permission is granted to make and distribute verbatim copies of
.\" this reference card provided the copyright notice and this permission
.\" notice are preserved on all copies.
.\"
.\" Permission is granted to process this file through troff and print the
.\" results, provided the printed document carries copying permission
.\" notice identical to this one except for the removal of this paragraph
.\" (this paragraph not being relevant to the printed reference card).
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" reference card under the conditions for verbatim copying, provided that
.\" the entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Permission is granted to copy and distribute translations of this
.\" reference card into another language, under the above conditions for
.\" modified versions, except that this permission notice may be stated in
.\" a translation approved by the Foundation.
.\"
.ig
Strings for inline color change.
CR - color red
CG - color green
CL - color light blue
CB - color blue
CD - color dark, i.e. black
CX - color boX, i.e. for the surrounding boxes (red for now)
..
.ds CR \X'ps: exec 0 .96 .65 0 setcmykcolor'
.ds CG \X'ps: exec 1.0 0 .51 .43 setcmykcolor'
.ds CL \X'ps: exec .69 .34 0 0 setcmykcolor'
.ds CB \X'ps: exec 1 .72 0 .06 setcmykcolor'
.ds CD \X'ps: exec 1 1 1 1 setcmykcolor'
.ds CX \*(CG

2657
contrib/awk/doc/gawk.1 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@
@c I hope this is the right category
@dircategory Programming Languages
@direntry
* Gawk: (gawk.info). A Text Scanning and Processing Language.
* Gawk: (gawk). A Text Scanning and Processing Language.
@end direntry
@end ifinfo
@ -21,10 +21,10 @@
@c applies to, and when the document was updated.
@set TITLE Effective AWK Programming
@set SUBTITLE A User's Guide for GNU Awk
@set PATCHLEVEL 4
@set PATCHLEVEL 6
@set EDITION 1.0.@value{PATCHLEVEL}
@set VERSION 3.0
@set UPDATE-MONTH April, 1999
@set UPDATE-MONTH July, 2000
@iftex
@set DOCUMENT book
@end iftex
@ -74,7 +74,7 @@ particular records in a file and perform operations upon them.
This is Edition @value{EDITION} of @cite{@value{TITLE}},
for the @value{VERSION}.@value{PATCHLEVEL} version of the GNU implementation of AWK.
Copyright (C) 1989, 1991, 92, 93, 96, 97, 98, 99 Free Software Foundation, Inc.
Copyright (C) 1989, 1991, 1992, 1993, 1996-2000 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@ -138,31 +138,27 @@ Corporation. @*
Registered Trademark of Paramount Pictures Corporation. @*
@c sorry, i couldn't resist
@sp 3
Copyright @copyright{} 1989, 1991, 92, 93, 96, 97, 98, 99 Free Software Foundation, Inc.
Copyright @copyright{} 1989, 1991, 1992, 1993, 1996-2000 Free Software Foundation, Inc.
@sp 2
This is Edition @value{EDITION} of @cite{@value{TITLE}}, @*
for the @value{VERSION}.@value{PATCHLEVEL} (or later) version of the GNU implementation of AWK.
@sp 2
@center Published jointly by:
Published by:
@multitable {Specialized Systems Consultants, Inc. (SSC)} {Boston, MA 02111-1307 USA}
@item Specialized Systems Consultants, Inc. (SSC) @tab Free Software Foundation
@item PO Box 55549 @tab 59 Temple Place --- Suite 330
@item Seattle, WA 98155 USA @tab Boston, MA 02111-1307 USA
@item Phone: +1-206-782-7733 @tab Phone: +1-617-542-5942
@item Fax: +1-206-782-7191 @tab Fax: +1-617-542-2652
@item E-mail: @code{sales@@ssc.com} @tab E-mail: @code{gnu@@gnu.org}
@item URL: @code{http://www.ssc.com/} @tab URL: @code{http://www.fsf.org/}
@end multitable
Free Software Foundation @*
59 Temple Place --- Suite 330 @*
Boston, MA 02111-1307 USA @*
Phone: +1-617-542-5942 @*
Fax: +1-617-542-2652 @*
Email: @code{gnu@@gnu.org} @*
URL: @code{http://www.gnu.org/} @*
@sp 1
@c this ISBN can change! Check with SSC
@c this ISBN can change!
@c This one is correct for gawk 3.0 and edition 1.0 from the FSF
ISBN 1-882114-26-4 @*
@c This one is correct for gawk 3.0.3 and edition 1.0.3 from SSC
@c ISBN 1-57831-000-8 @*
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@ -178,8 +174,7 @@ into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation approved
by the Foundation.
@sp 2
@c Cover art by Etienne Suvasa.
Cover art by Amy Wells Wood.
Cover art by Etienne Suvasa.
@end titlepage
@c Thanks to Bob Chassell for directions on doing dedications.
@ -195,6 +190,8 @@ Cover art by Amy Wells Wood.
@center @i{To Rivka, for the exponential increase.}
@sp 1
@center @i{To Nachum, for the added dimension.}
@sp 1
@center @i{To Malka, for the new beginning.}
@page
@w{ }
@page
@ -540,6 +537,8 @@ of AWK.
@center To Rivka, for the exponential increase.
@sp 1
@center To Nachum, for the added dimension.
@sp 1
@center To Malka, for the new beginning.
@end ifinfo
@node Preface, What Is Awk, Top, Top
@ -2686,7 +2685,7 @@ control how @code{gawk} interprets characters in regexps.
@table @asis
@item No options
In the default case, @code{gawk} provide all the facilities of
In the default case, @code{gawk} provides all the facilities of
POSIX regexps and the GNU regexp operators described
@iftex
above.
@ -2843,7 +2842,6 @@ $ echo aaaabcd | awk '@{ sub(/a+/, "<A>"); print @}'
@end example
For simple match/no-match tests, this is not so important. But when doing
regexp-based field and record splitting, and
text matching and substitutions with the @code{match}, @code{sub}, @code{gsub},
and @code{gensub} functions, it is very important.
@ifinfo
@ -2871,7 +2869,7 @@ regexp. A regexp that is computed in this way is called a @dfn{dynamic
regexp}. For example:
@example
BEGIN @{ identifier_regexp = "[A-Za-z_][A-Za-z_0-9]+" @}
BEGIN @{ identifier_regexp = "[A-Za-z_][A-Za-z_0-9]*" @}
$0 ~ identifier_regexp @{ print @}
@end example
@ -2879,6 +2877,12 @@ $0 ~ identifier_regexp @{ print @}
sets @code{identifier_regexp} to a regexp that describes @code{awk}
variable names, and tests if the input record matches this regexp.
@ignore
Do we want to use "^[A-Za-z_][A-Za-z_0-9]*$" to restrict the entire
record to just identifiers? Doing that also would disrupt the flow of
the text.
@end ignore
@strong{Caution:} When using the @samp{~} and @samp{!~}
operators, there is a difference between a regexp constant
enclosed in slashes, and a string constant enclosed in double quotes.
@ -3070,8 +3074,10 @@ is one field, consisting of a newline. The value of the built-in
variable @code{NF} is the number of fields in the current record.
@example
@group
$ echo | awk 'BEGIN @{ RS = "a" @} ; @{ print NF @}'
@print{} 1
@end group
@end example
@cindex dark corner
@ -3219,6 +3225,8 @@ when the record has only seven fields, you get the empty string.
a special case: it represents the whole input record. @code{$0} is
used when you are not interested in fields.
@c NEEDED
@page
Here are some more examples:
@example
@ -3613,8 +3621,10 @@ the record, and then decide where the fields are.
For example, the following pipeline prints @samp{b}:
@example
@group
$ echo ' a b c d ' | awk '@{ print $2 @}'
@print{} b
@end group
@end example
@noindent
@ -3914,17 +3924,19 @@ idle time. (This program uses a number of @code{awk} features that
haven't been introduced yet.)
@example
@group
BEGIN @{ FIELDWIDTHS = "9 6 10 6 7 7 35" @}
NR > 2 @{
idle = $4
sub(/^ */, "", idle) # strip leading spaces
if (idle == "")
idle = 0
@group
if (idle ~ /:/) @{
split(idle, t, ":")
idle = t[1] * 60 + t[2]
@}
@end group
@group
if (idle ~ /days/)
idle *= 24 * 60 * 60
@ -4042,6 +4054,8 @@ A practical example of a data file organized this way might be a mailing
list, where each entry is separated by blank lines. If we have a mailing
list in a file named @file{addresses}, that looks like this:
@c NEEDED
@page
@example
Jane Doe
123 Main Street
@ -4050,7 +4064,6 @@ Anywhere, SE 12345-6789
John Smith
456 Tree-lined Avenue
Smallville, MW 98765-4321
@dots{}
@end example
@ -4426,8 +4439,6 @@ each one.
@c Exercise!!
@c This example is unrealistic, since you could just use system
@c NEEDED
@page
Given the input:
@example
@ -4974,6 +4985,12 @@ the decimal number eight is represented as @samp{10} in octal.)
@item s
This prints a string.
@item u
This prints an unsigned decimal number.
(This format is of marginal use, since all numbers in @code{awk}
are floating point. It is provided primarily for compatibility
with C.)
@item x
@itemx X
This prints an unsigned hexadecimal integer.
@ -5525,7 +5542,7 @@ is important to @emph{not} close any of the files related to file descriptors
0, 1, and 2. If you do close one of these files, unpredictable behavior
will result.
The special files that provide process-related information may disappear
The special files that provide process-related information will disappear
in a future version of @code{gawk}.
@xref{Future Extensions, ,Probable Future Extensions}.
@ -5624,6 +5641,8 @@ really do its work until the pipe is closed. For example, if you
redirect output to the @code{mail} program, the message is not
actually sent until the pipe is closed.
@c NEEDED
@page
@item
To run the same program a second time, with the same arguments.
This is not the same thing as giving more input to the first run!
@ -6017,8 +6036,8 @@ specifier.
@code{CONVFMT}'s default value is @code{"%.6g"}, which prints a value with
at least six significant digits. For some applications you will want to
change it to specify more precision. Double precision on most modern
machines gives you 16 or 17 decimal digits of precision.
change it to specify more precision. On most modern machines, you must
print 17 digits to capture a floating point number's value exactly.
Strange results can happen if you set @code{CONVFMT} to a string that doesn't
tell @code{sprintf} how to format floating point numbers in a useful way.
@ -6069,7 +6088,12 @@ for more information on the @code{print} statement.
The @code{awk} language uses the common arithmetic operators when
evaluating expressions. All of these arithmetic operators follow normal
precedence rules, and work as you would expect them to.
precedence rules, and work as you would expect them to. Arithmetic
operations are evaluated using double precision floating point, which
has the usual problems of inexactness and exceptions.@footnote{David
Goldberg, @uref{http://www.validgh.com/goldberg/paper.ps, @cite{What Every
Computer Scientist Should Know About Floating-point Arithmetic}},
@cite{ACM Computing Surveys} @strong{23}, 1 (1991-03), 5-48.}
Here is a file @file{grades} containing a list of student names and
three test scores per student (it's a small class):
@ -6117,7 +6141,7 @@ Multiplication.
@item @var{x} / @var{y}
Division. Since all numbers in @code{awk} are
real numbers, the result is not rounded to an integer: @samp{3 / 4}
floating point numbers, the result is not rounded to an integer: @samp{3 / 4}
has the value 0.75.
@item @var{x} % @var{y}
@ -6976,8 +7000,8 @@ x > 0 ? x : -x
@end example
Each time the conditional expression is computed, exactly one of
@var{if-true-exp} and @var{if-false-exp} is computed; the other is ignored.
This is important when the expressions contain side effects. For example,
@var{if-true-exp} and @var{if-false-exp} is used; the other is ignored.
This is important when the expressions have side effects. For example,
this conditional expression examines element @code{i} of either array
@code{a} or array @code{b}, and increments @code{i}.
@ -7975,9 +7999,11 @@ identifies prime numbers:
@example
awk '# find smallest divisor of num
@{ num = $1
@group
for (div = 2; div*div <= num; div++)
if (num % div == 0)
break
@end group
if (num % div == 0)
printf "Smallest divisor of %d is %d\n", num, div
else
@ -8049,8 +8075,8 @@ of the loop altogether.
@ignore
In Texinfo source files, text that the author wishes to ignore can be
enclosed between lines that start with @samp{@@ignore} and end with
@samp{@@end ignore}. Here is a program that strips out lines between
@samp{@@ignore} and @samp{@@end ignore} pairs.
@samp{@atend ignore}. Here is a program that strips out lines between
@samp{@@ignore} and @samp{@atend ignore} pairs.
@example
BEGIN @{
@ -8069,7 +8095,7 @@ BEGIN @{
@end example
When an @samp{@@ignore} is seen, the @code{ignoring} flag is set to one (true).
When @samp{@@end ignore} is seen, the flag is reset to zero (false). As long
When @samp{@atend ignore} is seen, the flag is reset to zero (false). As long
as the flag is true, the input record is not printed, because the
@code{continue} restarts the @code{while} loop, skipping over the @code{print}
statement.
@ -8778,6 +8804,7 @@ same @code{awk} program.
* Multi-dimensional:: Emulating multi-dimensional arrays in
@code{awk}.
* Multi-scanning:: Scanning multi-dimensional arrays.
* Array Efficiency:: Implementation-specific tips.
@end menu
@node Array Intro, Reference to Elements, Arrays, Arrays
@ -9008,12 +9035,14 @@ It is a very simple program, and gets confused if it encounters repeated
numbers, gaps, or lines that don't begin with a number.
@example
@group
@c file eg/misc/arraymax.awk
@{
if ($1 > max)
max = $1
arr[$1] = $0
@}
@end group
END @{
for (x = 1; x <= max; x++)
@ -9308,7 +9337,7 @@ output!
At first glance, this program should have worked. The variable @code{lines}
is uninitialized, and uninitialized variables have the numeric value zero.
So, the value of @code{l[0]} should have been printed.
So, @code{awk} should have printed the value of @code{l[0]}.
The issue here is that subscripts for @code{awk} arrays are @strong{always}
strings. And uninitialized variables, when used as strings, have the
@ -9445,7 +9474,7 @@ it produces:
@end group
@end example
@node Multi-scanning, , Multi-dimensional, Arrays
@node Multi-scanning, Array Efficiency, Multi-dimensional, Arrays
@section Scanning Multi-dimensional Arrays
There is no special @code{for} statement for scanning a
@ -9492,6 +9521,34 @@ The result of this is to set @code{separate[1]} to @code{"1"} and
@code{separate[2]} to @code{"foo"}. Presto, the original sequence of
separate indices has been recovered.
@node Array Efficiency, , Multi-scanning, Arrays
@section Using Array Memory Efficiently
This section applies just to @code{gawk}.
It is often useful to use the same bit of data as an index
into multiple arrays.
Due to the way @code{gawk} implements associative arrays,
when you need to use input data as an index for multiple
arrays, it is much more effecient to assign the input field
to a separate variable, and then use that variable as the index.
@example
@{
name = $1
ssn = $2
nkids = $3
@dots{}
seniority[name]++ # better than seniority[$1]++
kids[name] = nkids # better than kids[$1] = nkids
@}
@end example
Using separate variables with mnemonic names for the input fields
makes programs more readable, in any case.
It is an eventual goal to make @code{gawk}'s array indexing as efficient
as possible, no matter what the source of the index value.
@node Built-in, User-defined, Arrays, Top
@chapter Built-in Functions
@ -9625,7 +9682,7 @@ function randint(n) @{
@end example
@noindent
The multiplication produces a random real number greater than zero and less
The multiplication produces a random number greater than zero and less
than @code{n}. We then make it an integer (using @code{int}) between zero
and @code{n} @minus{} 1, inclusive.
@ -9915,10 +9972,10 @@ Here is another example:
@example
awk 'BEGIN @{
str = "daabaaa"
sub(/a*/, "c&c", str)
sub(/a+/, "C&C", str)
print str
@}'
@print{} dcaacbaaa
@print{} dCaaCbaaa
@end example
@noindent
@ -10229,7 +10286,8 @@ backslash.@footnote{This consequence was certainly unintended.}
@end enumerate
The POSIX standard is under revision.@footnote{As of @value{UPDATE-MONTH},
with final approval and publication hopefully sometime in 1997.}
with final approval and publication as part of the Austin Group
Standards hopefully sometime in 2001.}
Because of the above problems, proposed text for the revised standard
reverts to rules that correspond more closely to the original existing
practice. The proposed rules have special cases that make it possible
@ -10981,6 +11039,8 @@ in an array and start over with a new list of elements
Instead of having
to repeat this loop everywhere in your program that you need to clear out
an array, your program can just call @code{delarray}.
(This guarantees portability. The usage @samp{delete @var{array}} to delete
the contents of an entire array is a non-standard extension.)
Here is an example of a recursive function. It takes a string
as an input parameter, and returns the string in backwards order.
@ -11012,11 +11072,11 @@ formatted in a well known fashion. Here is an @code{awk} version:
@example
@c file eg/lib/ctime.awk
@group
# ctime.awk
#
# awk version of C ctime(3) function
@group
function ctime(ts, format)
@{
format = "%a %b %d %H:%M:%S %Z %Y"
@ -11113,10 +11173,12 @@ doing.} For example:
@end iftex
@example
@group
function changeit(array, ind, nvalue)
@{
array[ind] = nvalue
@}
@end group
BEGIN @{
a[1] = 1; a[2] = 2; a[3] = 3
@ -11355,6 +11417,11 @@ The @samp{-v} option can only set one variable, but you can use
it more than once, setting another variable each time, like this:
@samp{awk @w{-v foo=1} @w{-v bar=2} @dots{}}.
@strong{Caution:} Using @samp{-v} to set the values of the builtin
variables may lead to suprising results. @code{awk} will reset the
values of those variables as it needs to, possibly ignoring any
predefined value you may have given.
@item -mf @var{NNN}
@itemx -mr @var{NNN}
Set various memory limits to the value @var{NNN}. The @samp{f} flag sets
@ -11656,7 +11723,7 @@ separated by colons. @code{gawk} gets its search path from the
@code{AWKPATH} environment variable. If that variable does not exist,
@code{gawk} uses a default path, which is
@samp{.:/usr/local/share/awk}.@footnote{Your version of @code{gawk}
may use a directory that is different than @file{/usr/local/share/awk}; it
may use a different directory; it
will depend upon how @code{gawk} was built and installed. The actual
directory will be the value of @samp{$(datadir)} generated when
@code{gawk} was configured. You probably don't need to worry about this
@ -11958,7 +12025,6 @@ it should stop when it gets to the end of the first occurrence.
Here is a second version of @code{nextfile} that remedies this problem.
@example
@group
@c file eg/lib/nextfile.awk
# nextfile --- skip remaining records in current file
# correctly handle successive occurrences of the same file
@ -11969,14 +12035,15 @@ Here is a second version of @code{nextfile} that remedies this problem.
function nextfile() @{ _abandon_ = FILENAME; next @}
@group
_abandon_ == FILENAME @{
if (FNR == 1)
_abandon_ = ""
else
next
@}
@c endfile
@end group
@c endfile
@end example
The @code{nextfile} function has not changed. It sets @code{_abandon_}
@ -12029,6 +12096,8 @@ print a diagnostic message describing the condition that should have
been true but was not, and then it kills the program. In C, using
@code{assert} looks this:
@c NEEDED
@page
@example
#include <assert.h>
@ -12093,6 +12162,8 @@ program's @code{END} rules will execute.
For all of this to work correctly, @file{assert.awk} must be the
first source file read by @code{awk}.
@c NEEDED
@page
You would use this function in your programs this way:
@example
@ -12158,10 +12229,12 @@ function round(x, ival, aval, fraction)
aval = -x # absolute value
ival = int(aval)
fraction = aval - ival
@group
if (fraction >= .5)
return int(x) - 1 # -2.5 --> -3
else
return int(x) # -2.3 --> -2
@end group
@} else @{
fraction = x - ival
if (fraction >= .5)
@ -12283,7 +12356,7 @@ function chr(c)
@c endfile
@end group
@c @group
@group
@c file eg/lib/ord.awk
#### test code ####
# BEGIN \
@ -12296,7 +12369,7 @@ function chr(c)
# @}
# @}
@c endfile
@c @end group
@end group
@end example
An obvious improvement to these functions would be to move the code for the
@ -12381,7 +12454,11 @@ date into a timestamp.
It would appear at first glance that @code{gawk} would have to supply a
@code{mktime} built-in function that was simply a ``hook'' to the C language
version. In fact though, @code{mktime} can be implemented entirely in
@code{awk}.
@code{awk}.@footnote{@value{UPDATE-MONTH}: Actually, I was mistaken when
I wrote this. The version presented here doesn't always work correctly,
and the next major version of @code{gawk} will provide @code{mktime}
as a built-in function.}
@c sigh.
Here is a version of @code{mktime} for @code{awk}. It takes a simple
representation of the date and time, and converts it into a timestamp.
@ -12630,13 +12707,14 @@ to the original result. An example demonstrating this is presented below.
Finally, there is a ``main'' program for testing the function.
@example
@c there used to be a blank line after the getline,
@c squished out for page formatting reasons
@c @group
@c file eg/lib/mktime.awk
BEGIN @{
if (_tm_test) @{
printf "Enter date as yyyy mm dd hh mm ss: "
getline _tm_test_date
t = mktime(_tm_test_date)
r = strftime("%Y %m %d %H %M %S", t)
printf "Got back (%s)\n", r
@ -12722,7 +12800,6 @@ time formatted in the same way as the @code{date} utility.
# time["timezone"] -- abbreviation of timezone name
# time["ampm"] -- AM or PM designation
@group
function gettimeofday(time, ret, now, i)
@{
# get time once, avoids unnecessary system calls
@ -12734,9 +12811,7 @@ function gettimeofday(time, ret, now, i)
# clear out target array
for (i in time)
delete time[i]
@end group
@group
# fill in values, force numeric values to be
# numeric by adding 0
time["second"] = strftime("%S", now) + 0
@ -12761,7 +12836,6 @@ function gettimeofday(time, ret, now, i)
return ret
@}
@end group
@c endfile
@end example
@ -13569,9 +13643,11 @@ char **argv;
int i;
@end group
@group
while ((g = getgrent()) != NULL) @{
printf("%s:%s:%d:", g->gr_name, g->gr_passwd,
g->gr_gid);
@end group
for (i = 0; g->gr_mem[i] != NULL; i++) @{
printf("%s", g->gr_mem[i]);
if (g->gr_mem[i+1] != NULL)
@ -14074,11 +14150,11 @@ BEGIN \
if (c == "f") @{
by_fields = 1
fieldlist = Optarg
@group
@} else if (c == "c") @{
by_chars = 1
fieldlist = Optarg
OFS = ""
@group
@} else if (c == "d") @{
if (length(Optarg) > 1) @{
printf("Using first character of %s" \
@ -14304,8 +14380,6 @@ Normally, @code{egrep} prints the
lines that matched. If multiple file names are provided on the command
line, each output line is preceded by the name of the file and a colon.
@c NEEDED
@page
The options are:
@table @code
@ -14457,7 +14531,7 @@ processed. Finally, @code{fcount} is added to @code{total}, so that we
know how many lines altogether matched the pattern.
@example
@c @group
@group
@c file eg/prog/egrep.awk
function endfile(file)
@{
@ -14470,7 +14544,7 @@ function endfile(file)
total += fcount
@}
@c endfile
@c @end group
@end group
@end example
This rule does most of the work of matching lines. The variable
@ -14520,10 +14594,8 @@ necessary.
fcount += matches # 1 or 0
@group
if (! matches)
next
@end group
if (no_print && ! count_only)
nextfile
@ -14535,8 +14607,10 @@ necessary.
if (do_filenames && ! count_only)
print FILENAME ":" $0
@group
else if (! count_only)
print
@end group
@}
@c endfile
@c @end group
@ -15032,7 +15106,6 @@ standard output, @file{/dev/stdout}.
@findex uniq.awk
@example
@c @group
@c file eg/prog/uniq.awk
# uniq.awk --- do uniq in awk
# Arnold Robbins, arnold@@gnu.org, Public Domain
@ -15047,15 +15120,13 @@ function usage( e)
@}
@end group
@group
# -c count lines. overrides -d and -u
# -d only repeated lines
# -u only non-repeated lines
# -n skip n fields
# +n skip n characters, skip fields first
@end group
BEGIN \
BEGIN \
@{
count = 1
outputfile = "/dev/stdout"
@ -15072,10 +15143,12 @@ BEGIN \
# this messes us up for things like -5
if (Optarg ~ /^[0-9]+$/)
fcount = (c Optarg) + 0
@group
else @{
fcount = c + 0
Optind--
@}
@end group
@} else
usage()
@}
@ -15091,14 +15164,12 @@ BEGIN \
if (repeated_only == 0 && non_repeated_only == 0)
repeated_only = non_repeated_only = 1
@group
if (ARGC - Optind == 2) @{
outputfile = ARGV[ARGC - 1]
ARGV[ARGC - 1] = ""
@}
@}
@c endfile
@end group
@end example
The following function, @code{are_equal}, compares the current line,
@ -15315,23 +15386,22 @@ for the file that was just read. It relies on @code{beginfile} to reset the
numbers for the following data file.
@example
@c @group
@c left brace on line with `function' because of page breaking
@c file eg/prog/wc.awk
function beginfile(file)
@{
@group
function beginfile(file) @{
chars = lines = words = 0
fname = FILENAME
@}
@end group
function endfile(file)
@{
tchars += chars
tlines += lines
twords += words
@group
if (do_lines)
printf "\t%d", lines
@end group
if (do_words)
printf "\t%d", words
if (do_chars)
@ -15339,7 +15409,6 @@ function endfile(file)
printf "\t%s\n", fname
@}
@c endfile
@c @end group
@end example
There is one rule that is executed for each line. It adds the length of the
@ -15565,11 +15634,12 @@ message in a loop, again using @code{sleep} to delay for however many
seconds are necessary.
@example
@c @group
@c file eg/prog/alarm.awk
@group
# zzzzzz..... go away if interrupted
if (system(sprintf("sleep %d", naptime)) != 0)
exit 1
@end group
# time to notify!
command = sprintf("sleep %d", delay)
@ -15583,7 +15653,6 @@ seconds are necessary.
exit 0
@}
@c endfile
@c @end group
@end example
@node Translate Program, Labels Program, Alarm Program, Miscellaneous Programs
@ -15625,7 +15694,7 @@ functions
(@pxref{String Functions, ,Built-in Functions for String Manipulation}).@footnote{This
program was written before @code{gawk} acquired the ability to
split each character in a string into separate array elements.
How might this ability simplify the program?}
How might you use this new feature to simplify the program?}
There are two functions. The first, @code{stranslate}, takes three
arguments.
@ -15683,19 +15752,19 @@ function stranslate(from, to, target, lf, lt, t_ar, i, c)
return target
@}
@group
function translate(from, to)
@{
return $0 = stranslate(from, to, $0)
@}
@end group
@group
# main program
BEGIN @{
if (ARGC < 3) @{
print "usage: translate from to" > "/dev/stderr"
exit
@}
@end group
FROM = ARGV[1]
TO = ARGV[2]
ARGC = 2
@ -15852,10 +15921,12 @@ awk '
freq[$i]++
@}
@group
END @{
for (word in freq)
printf "%s\t%d\n", word, freq[word]
@}'
@end group
@end example
The first thing to notice about this program is that it has two rules. The
@ -15914,10 +15985,12 @@ the program:
@}
@c endfile
@group
END @{
for (word in freq)
printf "%s\t%d\n", word, freq[word]
@}
@end group
@end example
Assuming we have saved this program in a file named @file{wordfreq.awk},
@ -16126,8 +16199,7 @@ exited with a zero exit status, signifying OK.
@c file eg/prog/extract.awk
# extract.awk --- extract files and run programs
# from texinfo files
# Arnold Robbins, arnold@@gnu.org, Public Domain
# May 1993
# Arnold Robbins, arnold@@gnu.org, Public Domain, May 1993
BEGIN @{ IGNORECASE = 1 @}
@ -16315,18 +16387,18 @@ are provided, the standard input is used.
# Arnold Robbins, arnold@@gnu.org, Public Domain
# August 1995
@group
function usage()
@{
print "usage: awksed pat repl [files...]" > "/dev/stderr"
exit 1
@}
@end group
@group
BEGIN @{
# validate arguments
if (ARGC < 3)
usage()
@end group
RS = ARGV[1]
ORS = ARGV[2]
@ -16515,7 +16587,6 @@ argument (e.g., @samp{--file=}).
The source text is echoed into @file{/tmp/ig.s.$$}.
@item --version
@itemx --version
@itemx -Wversion
@code{igawk} prints its version number, and runs @samp{gawk --version}
to get the @code{gawk} version information, and then exits.
@ -16660,11 +16731,13 @@ slower.
@end ignore
@example
@c @group
@c file eg/prog/igawk.sh
gawk -- '
# process @@include directives
@c endfile
@group
@c file eg/prog/igawk.sh
function pathto(file, i, t, junk)
@{
if (index(file, "/") != 0)
@ -16681,7 +16754,7 @@ function pathto(file, i, t, junk)
return ""
@}
@c endfile
@c @end group
@end group
@end example
The main program is contained inside one @code{BEGIN} rule. The first thing it
@ -18068,19 +18141,19 @@ Prints expressions, sending the output down a pipe to @var{command}.
The pipeline to the command stays open until the @code{close} function
is called.
@item printf @var{fmt, expr-list}
@item printf @var{fmt}, @var{expr-list}
Format and print.
@item printf @var{fmt, expr-list} > file
@item printf @var{fmt}, @var{expr-list} > @var{file}
Format and print to @var{file}. If @var{file} does not exist, it is
created. If it does exist, its contents are deleted the first time the
@code{printf} is executed.
@item printf @var{fmt, expr-list} >> @var{file}
@item printf @var{fmt}, @var{expr-list} >> @var{file}
Format and print to @var{file}. The previous contents of @var{file}
are retained, and the output of @code{printf} is appended to the file.
@item printf @var{fmt, expr-list} | @var{command}
@item printf @var{fmt}, @var{expr-list} | @var{command}
Format and print, sending the output down a pipe to @var{command}.
The pipeline to the command stays open until the @code{close} function
is called.
@ -18128,7 +18201,10 @@ string, with non-significant zeros suppressed.
@samp{%G} will use @samp{%E} instead of @samp{%e}.
@item %o
An unsigned octal number (again, an integer).
An unsigned octal number (also an integer).
@item %u
An unsigned decimal number (again, an integer).
@item %s
A character string.
@ -18256,6 +18332,8 @@ provides the motivation for this feature.
@code{awk} provides a number of built-in functions for performing
numeric operations, string related operations, and I/O related operations.
@c NEEDED
@page
The built-in arithmetic functions are:
@table @code
@ -18592,7 +18670,8 @@ Free Software Foundation @*
Boston, MA 02111-1307 USA @*
Phone: +1-617-542-5942 @*
Fax (including Japan): +1-617-542-2652 @*
E-mail: @code{gnu@@gnu.org} @*
Email: @code{gnu@@gnu.org} @*
URL: @code{http://www.gnu.org/} @*
@end quotation
@noindent
@ -18617,6 +18696,8 @@ You should use a site that is geographically close to you.
@itemx utsun.s.u-tokyo.ac.jp:/ftpsync/prep
@end table
@c NEEDED
@page
@item Australia:
@table @code
@item archie.au:/gnu
@ -19412,22 +19493,13 @@ some idea of what kind of Unix system you're using, and the exact results
@code{gawk} gave you. Also say what you expected to occur; this will help
us decide whether the problem was really in the documentation.
Once you have a precise problem, there are two e-mail addresses you
can send mail to.
Once you have a precise problem, send email to @email{bug-gawk@@gnu.org}.
@table @asis
@item Internet:
@samp{bug-gnu-utils@@gnu.org}
@item UUCP:
@samp{uunet!gnu.org!bug-gnu-utils}
@end table
Please include the
version number of @code{gawk} you are using. You can get this information
with the command @samp{gawk --version}.
You should send a carbon copy of your mail to Arnold Robbins, who can
be reached at @samp{arnold@@gnu.org}.
Please include the version number of @code{gawk} you are using.
You can get this information with the command @samp{gawk --version}.
Using this address will automatically send a carbon copy of your
mail to Arnold Robbins. If necessary, he can be reached directly at
@email{arnold@@gnu.org}.
@cindex @code{comp.lang.awk}
@strong{Important!} Do @emph{not} try to report bugs in @code{gawk} by
@ -19514,8 +19586,8 @@ retrieve @file{awk.bundle.gz}.
This is a shell archive that has been compressed with the GNU @code{gzip}
utility. It can be uncompressed with the @code{gunzip} utility.
You can also retrieve this version via the World Wide Web from
@uref{http://cm.bell-labs.com/who/bwk, Brian Kernighan's home page}.
You can also retrieve this version via the World Wide Web from his
@uref{http://cm.bell-labs.com/who/bwk, home page}.
This version requires an ANSI C compiler; GCC (the GNU C compiler)
works quite nicely.
@ -19729,6 +19801,11 @@ Using this format makes it easy for me to apply your changes to the
master version of the @code{gawk} source code (using @code{patch}).
If I have to apply the changes manually, using a text editor, I may
not do so, particularly if there are lots of changes.
@item
Include an entry for the @file{ChangeLog} file with your submission.
This further helps minimize the amount of work I have to do,
making it easier for me to accept patches.
@end enumerate
Although this sounds like a lot of work, please remember that while you
@ -19736,6 +19813,7 @@ may write the new code, I have to maintain it and support it, and if it
isn't possible for me to do that with a minimum of extra work, then I
probably will not.
@node New Ports, , Adding Code, Additions
@appendixsubsec Porting @code{gawk} to a New Operating System
@ -19900,7 +19978,7 @@ It may be possible to map a GDBM/NDBM/SDBM file into an @code{awk} array.
@item A @code{PROCINFO} Array
The special files that provide process-related information
(@pxref{Special Files, ,Special File Names in @code{gawk}})
may be superseded by a @code{PROCINFO} array that would provide the same
will be superseded by a @code{PROCINFO} array that would provide the same
information, in an easier to access fashion.
@item More @code{lint} warnings
@ -20771,7 +20849,7 @@ the ``copyright'' line and a pointer to where the full notice is found.
@smallexample
@var{one line to give the program's name and an idea of what it does.}
Copyright (C) 19@var{yy} @var{name of author}
Copyright (C) @var{year} @var{name of author}
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -20794,7 +20872,7 @@ If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
@smallexample
Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
Gnomovision version 69, Copyright (C) @var{year} @var{name of author}
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
type `show w'. This is free software, and you are welcome
to redistribute it under certain conditions; type `show c'

73
contrib/awk/doc/igawk.1 Normal file
View File

@ -0,0 +1,73 @@
.TH IGAWK 1 "Nov 3 1999" "Free Software Foundation" "Utility Commands"
.SH NAME
igawk \- gawk with include files
.SH SYNOPSIS
.B igawk
[ all
.I gawk
options ]
.B \-f
.I program-file
[
.B \-\^\-
] file .\^.\^.
.br
.B igawk
[ all
.I gawk
options ]
[
.B \-\^\-
]
.I program-text
file .\^.\^.
.SH DESCRIPTION
.I Igawk
is a simple shell script that adds the ability to have ``include files'' to
.IR gawk (1).
.PP
AWK programs for
.I igawk
are the same as for
.IR gawk ,
except that, in addition, you may have lines like
.RS
.sp
.ft B
@include getopt.awk
.ft R
.sp
.RE
in your program to include the file
.B getopt.awk
from either the current directory or one of the other directories
in the search path.
.SH OPTIONS
See
.IR gawk (1)
for a full description of the AWK language and the options that
.I gawk
supports.
.SH EXAMPLES
.nf
.ft B
cat << EOF > test.awk
@include getopt.awk
.sp
BEGIN {
while (getopt(ARGC, ARGV, "am:q") != \-1)
\&.\^.\^.
}
EOF
.sp
igawk \-f test.awk
.ft R
.fi
.SH SEE ALSO
.IR gawk (1)
.PP
.IR "Effective AWK Programming" ,
Edition 1.0, published by the Free Software Foundation, 1995.
.SH AUTHOR
Arnold Robbins
.RB ( arnold@skeeve.com ).

211
contrib/awk/doc/macros Normal file
View File

@ -0,0 +1,211 @@
.\" SSC Reference card macros
.\"
.\" Copyright (C) 1996, Specialized System Consultants Inc. (SSC)
.\"
.\" These macros are free software; you can redistribute them and/or modify
.\" them under the terms of the GNU General Public License as published by
.\" the Free Software Foundation; either version 2 of the License, or
.\" (at your option) any later version.
.\"
.\" These macros are distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program; if not, write to the Free Software
.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
.\"
.\" Generic SSC "card" macros
.\" based on lots of other macros
.\" Last update: 4-25-91 ph
.\" attempting to get margins in the boxes Aug 3 09:43:48 PDT 1994
.ll 3i \" length of text line
.lt 3.2i \" length of title line
.de BT \" bottom of page trap
.sp |8.2i \" go to where we put footer
.ie \\n(CL=1 \{\
. nr CL 2
.tl ''\\*(CD\\n+(PN'' \" footer is just page number
. po 4i \" go to second column
.TP \" print header if any
\}
.el \{\
. nr CL 1
.tl ''\\*(CD\\n+(PN'' \" footer is just page number
. po .5i \" go to first column
. bp \" force a new page (which will force header)
. TP
\}
..
.de TP \" top of page
.\" .sp |.2i
.sp |0
.\" put page header stuff here
.\" for example: .tl ''WOW!''
.\".sp
..
.\" .wh 8.1i BT \" set bottom of column trap
.nf \" don't fill lines
.nh \" no hyphenation
.nr CL 1 \" start with column = 1
.po .5i \" offset for first column
.vs 9 \" line spacing
.ps 8 \" point size
.de ST \" set tabs to normal places
.ta .2i .78i 1.2i 1.7i \" set tabs
..
.ig
From: bryang@chinet.chi.il.us (Bryan Glennon)
Box macro. Do a .mk z where the box is to start, and a .eb
where it is to end. Optional argument is a title to be centered
within the top box line.
Usage:
.mk z
Text, etc to be boxed...
.eb "Optional title goes here"
~or~
.mk z
Text, etc to be boxed...
.eb
Some explanation:
The macro name is eb <.de eb>. First thing we do is to go up on line
<.sp -1> and turn off fill mode <.nf>. Now it gets interesting: the
.ie is the if/else construct. We check the number of arguments provided
to the macro <\\n(.$> and if it is greater than 0 (meaning we have a title),
we do the rest of the .ie line, as follows:
\h'-.5n' - move left one-half of an n
\L'|\\nzu-1' - draw a vertical line <\L> to the
absolute position (|) given by \\nzu-1,
which is the position set with the .mk
command into register z <\\nz> in base
units <u> minus 1.
\l'(\\n(.lu+1n-\w'\\$1'u/2u)\(ul' - Draw a horizontal line <\l> with length
equal to the current line length
<\\n(.l> in base units <u> plus the
space required for an 'n' <1n>, minus
the width <\w> of the title string
<\\$1> in base units <u> divided by 2
<in base units <u>>. Draw the line
using the underline character, <\(ul>.
\v'.3m'\|\\$1\|\v'-.3m' - Move down the page 3/10 of an m,
<\v'.3m'>, output a 1/6 of an m space
<\|>, output the title <\\$1>, another
1/6 of an m space <\|>, and then move
up the page 3/10 of an m <\v'-.3m'>.
\l'...\(ul' - Draw the second part of the line, just
like the corresponding left half done
before.
\L'-|\\nzu+1' - Draw a verticle line <\L> going down
the absolute distance <-|> from where
the macro was given to where the start
point was marked <\\nz> in base units
<u> plus one line <+1>
\l'|0u-.5n\(ul' - Draw a horizontal line to the absolute
position (|0) when the macro was
invoked, minus half an n <-.5n> using
the underline character <\(ul>.
The .el beings the else part, which is identical to the above, except
the string dosen't get printed. This makes the printing of the top
line much easier: just draw a line <\l> with width equal to the
current line plus the witdh of an n <\\n(.l+1n> using the underline
character <.\(ul>.
..
.de ES \" start "text in a box"
.mk z
.in +.5n
.ll -.5n
.sp 1.3
..
.de EB \" end "text in a box" -- optional box title as argument
.sp -.6
.nf
.in -.5n
.ll +.5n
.ie \\n(.$\
\L'|\\nzu'\
\l'(\\n(.lu-\w'\\$1'u)/2u-.33m\(ul'\
\v'.3m'\|\\$1\|\v'-.3m'\
\l'(\\n(.lu-\w'\\$1'u)/2u\(ul'\
\L'-|\\nzu'\
\l'|0u\(ul'
.el \h'-.5n'\L'|\\nzu-1'\l'\\n(.lu+1n\(ul'\L'-|\\nzu+1'\l'|0u-.5n\(ul'
.in 0
..
.de SL \" draw single line (works in non-fill mode only)
.sp -.8
.ti 0
\l'\\n(.lu\(ul'
..
.de Hl \" draw horizontal line
.br
.ti 0
\l'\\n(.lu-\\n(.iu'
.br
..
.de DL \" draw double line (works in non-fill mode only)
.sp -.8
.ti 0
\l'\\n(.lu\(ul'
.sp -.8
.ti 0
\l'\\n(.lu\(ul'
..
.ST
.nr PN 0 1 \" sets starting page number and auto-increment
.\" must define page header (if any) before here
.TP
.ds 3) \|\v'3p'\s+5\z\(sq\s0\v'-3p'\h'1.25p'\v'-.5p'3\v'.5p'\h'2p'
.\" old one .ds 2) \h'-1.5p'\v'1p'\s+4\z\(ci\s0\v'-1p'\h'3.25p'2
.ds 2) \|\v'-2.4p'\D'c.095id'\h'-5.15p'\v'2.4p'2\h'1.9p'
.ds dC \v'1p'\s+5\(bu\s0\v'-1p'\" for development commands
.ds tC \s+2\(dm\s0\" (for DWB) should be a triangle
.ds tP \s+2\(dm\s0\" (for other text processing) should be a triangle
.\" various trademark symbols
.ds Tm \v'-0.5m'\s8TM\s0\v'0.5m'
.ds Ts \v'-0.5m'\s4TM\s0\v'0.5m'
.ig ++
.\" mount Serifa fonts
.fp 5 SR
.fp 6 SB
.fp 4 Si
.++
.\" other assorted junk
.lg 0
.\" Fl requires extended version of troff
.de Fl \" draw fat horizontal line
.br
.ti 0
.ruw 1.5p
\l'\\n(.lu-\\n(.iu'
.br
.ruw
..
.de Bx \" box for keys in text
\\$3\&\|\&\c
\s-3\(br\|\fH\v'.18n'\\$1\v'-.18n\fP\|\(br\l'|0\(rn'\l'|0\(ul'\&\s0\|\\$2
..
.de Fn \" function name - left justified, gray background
.\" bold with gray for function name
.ns
.br
\
.ns
.br
\!! gsave ( ) stringwidth neg 0 rmoveto
\!! /Serifa-Bold findfont 8 scalefont setfont
\!! (\\$1) dup stringwidth pop 6 gsave dup 0 exch rlineto neg exch 0 rlineto
\!! 0 exch rlineto closepath .9 setgray fill grestore show
\!! grestore
.nf
.rs
..
.rs

31
contrib/awk/doc/no.colors Normal file
View File

@ -0,0 +1,31 @@
.\" AWK Reference Card --- Arnold Robbins, arnold@gnu.org
.\" This file is for troff which does not know what to do
.\" with a literal Poscript and cannot use macros from 'colors'.
.\"
.\" Copyright (C) 1996 Free Software Foundation, Inc.
.\"
.\" Permission is granted to make and distribute verbatim copies of
.\" this reference card provided the copyright notice and this permission
.\" notice are preserved on all copies.
.\"
.\" Permission is granted to process this file through troff and print the
.\" results, provided the printed document carries copying permission
.\" notice identical to this one except for the removal of this paragraph
.\" (this paragraph not being relevant to the printed reference card).
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" reference card under the conditions for verbatim copying, provided that
.\" the entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Permission is granted to copy and distribute translations of this
.\" reference card into another language, under the above conditions for
.\" modified versions, except that this permission notice may be stated in
.\" a translation approved by the Foundation.
.\"
.ds CR
.ds CG
.ds CL
.ds CB
.ds CD
.ds CX

View File

@ -0,0 +1,77 @@
%!PS-Adobe-3.0
% SSC Reference card typesetter outline / cut marks
%
% Copyright (C) 1996, Specialized System Consultants Inc. (SSC)
%
% This file is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This file is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
%
%! page cut marks and stuff for Pocket References - 10-26-88 - ph
%! modified to move the cut marks onto the page
%! center a string
/inch {72 mul} def
/cshow % stk: string
% center string in space (space us variable)
{
dup stringwidth pop % get length of string
space exch sub 2 div % compute initial space needed
0 rmoveto % move over
show
} def
/flashme
{ /space 612 def
0 0 0 setrgbcolor % always print this stuff
/Helvetica findfont 12 scalefont setfont
gsave
% for groff (I hope)
-6 -6 translate
0.2 setlinewidth
0.25 inch 10.5 inch moveto
0.5 inch 10.5 inch lineto
.75 inch 10.75 inch moveto
.75 inch 11 inch lineto
stroke
0.25 inch 2 inch moveto
0.5 inch 2 inch lineto
.75 inch 1.75 inch moveto
.75 inch 1.50 inch lineto
stroke
4.25 inch 11 inch moveto
4.25 inch 10.75 inch lineto
stroke
4.25 inch 1.75 inch moveto
4.25 inch 1.5 inch lineto
stroke
7.75 inch 1.5 inch moveto
7.75 inch 1.75 inch lineto
8 inch 2 inch moveto
8.25 inch 2 inch lineto
stroke
7.75 inch 11 inch moveto
7.75 inch 10.75 inch lineto
8 inch 10.5 inch moveto
8.25 inch 10.5 inch lineto
stroke
grestore
} def
% actually do something

5992
contrib/awk/doc/texinfo.tex Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
* Copyright (C) 1986, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@ -66,6 +66,11 @@ static int func_tag_valid = FALSE;
static jmp_buf func_tag;
extern int exiting, exit_val;
/* This rather ugly macro is for VMS C */
#ifdef C
#undef C
#endif
#define C(c) ((char)c)
/*
* This table is used by the regexp routines to do case independant
* matching. Basically, every ascii character maps to itself, except
@ -108,45 +113,47 @@ char casetable[] = {
/* 'x' 'y' 'z' '{' '|' '}' '~' */
'\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
#ifndef USE_PURE_ASCII
'\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
'\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
'\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
'\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
'\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
'\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
'\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
'\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\327',
'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\337',
'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
C('\200'), C('\201'), C('\202'), C('\203'), C('\204'), C('\205'), C('\206'), C('\207'),
C('\210'), C('\211'), C('\212'), C('\213'), C('\214'), C('\215'), C('\216'), C('\217'),
C('\220'), C('\221'), C('\222'), C('\223'), C('\224'), C('\225'), C('\226'), C('\227'),
C('\230'), C('\231'), C('\232'), C('\233'), C('\234'), C('\235'), C('\236'), C('\237'),
C('\240'), C('\241'), C('\242'), C('\243'), C('\244'), C('\245'), C('\246'), C('\247'),
C('\250'), C('\251'), C('\252'), C('\253'), C('\254'), C('\255'), C('\256'), C('\257'),
C('\260'), C('\261'), C('\262'), C('\263'), C('\264'), C('\265'), C('\266'), C('\267'),
C('\270'), C('\271'), C('\272'), C('\273'), C('\274'), C('\275'), C('\276'), C('\277'),
C('\340'), C('\341'), C('\342'), C('\343'), C('\344'), C('\345'), C('\346'), C('\347'),
C('\350'), C('\351'), C('\352'), C('\353'), C('\354'), C('\355'), C('\356'), C('\357'),
C('\360'), C('\361'), C('\362'), C('\363'), C('\364'), C('\365'), C('\366'), C('\327'),
C('\370'), C('\371'), C('\372'), C('\373'), C('\374'), C('\375'), C('\376'), C('\337'),
C('\340'), C('\341'), C('\342'), C('\343'), C('\344'), C('\345'), C('\346'), C('\347'),
C('\350'), C('\351'), C('\352'), C('\353'), C('\354'), C('\355'), C('\356'), C('\357'),
C('\360'), C('\361'), C('\362'), C('\363'), C('\364'), C('\365'), C('\366'), C('\367'),
C('\370'), C('\371'), C('\372'), C('\373'), C('\374'), C('\375'), C('\376'), C('\377'),
#else
'\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
'\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
'\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
'\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
'\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
'\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
'\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
'\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
'\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
'\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
'\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
'\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
C('\200'), C('\201'), C('\202'), C('\203'), C('\204'), C('\205'), C('\206'), C('\207'),
C('\210'), C('\211'), C('\212'), C('\213'), C('\214'), C('\215'), C('\216'), C('\217'),
C('\220'), C('\221'), C('\222'), C('\223'), C('\224'), C('\225'), C('\226'), C('\227'),
C('\230'), C('\231'), C('\232'), C('\233'), C('\234'), C('\235'), C('\236'), C('\237'),
C('\240'), C('\241'), C('\242'), C('\243'), C('\244'), C('\245'), C('\246'), C('\247'),
C('\250'), C('\251'), C('\252'), C('\253'), C('\254'), C('\255'), C('\256'), C('\257'),
C('\260'), C('\261'), C('\262'), C('\263'), C('\264'), C('\265'), C('\266'), C('\267'),
C('\270'), C('\271'), C('\272'), C('\273'), C('\274'), C('\275'), C('\276'), C('\277'),
C('\300'), C('\301'), C('\302'), C('\303'), C('\304'), C('\305'), C('\306'), C('\307'),
C('\310'), C('\311'), C('\312'), C('\313'), C('\314'), C('\315'), C('\316'), C('\317'),
C('\320'), C('\321'), C('\322'), C('\323'), C('\324'), C('\325'), C('\326'), C('\327'),
C('\330'), C('\331'), C('\332'), C('\333'), C('\334'), C('\335'), C('\336'), C('\337'),
C('\340'), C('\341'), C('\342'), C('\343'), C('\344'), C('\345'), C('\346'), C('\347'),
C('\350'), C('\351'), C('\352'), C('\353'), C('\354'), C('\355'), C('\356'), C('\357'),
C('\360'), C('\361'), C('\362'), C('\363'), C('\364'), C('\365'), C('\366'), C('\367'),
C('\370'), C('\371'), C('\372'), C('\373'), C('\374'), C('\375'), C('\376'), C('\377'),
#endif
};
#else
#include "You lose. You will need a translation table for your character set."
#endif
#undef C
/*
* This table maps node types to strings for debugging.
* KEEP IN SYNC WITH awk.h!!!!
@ -205,6 +212,7 @@ static char *nodetypes[] = {
"Node_K_do",
"Node_K_return",
"Node_K_delete",
"Node_K_delete_loop",
"Node_K_getline",
"Node_K_function",
"Node_K_nextfile",
@ -225,6 +233,7 @@ static char *nodetypes[] = {
"Node_regex",
"Node_hashnode",
"Node_ahash",
"Node_array_ref",
"Node_NF",
"Node_NR",
"Node_FNR",
@ -480,6 +489,8 @@ register NODE *volatile tree;
t = tree->arrvar;
if (t->type == Node_param_list)
t = stack_ptr[t->param_cnt];
if (t->type == Node_array_ref)
t = t->orig_array;
stable_tree = tree;
if ((t->flags & SCALAR) != 0)
fatal("attempt to use scalar as array");
@ -563,6 +574,10 @@ register NODE *volatile tree;
do_delete(tree->lnode, tree->rnode);
break;
case Node_K_delete_loop:
do_delete_loop(tree->lnode, tree->rnode);
break;
case Node_K_next:
if (in_begin_rule)
fatal("`next' cannot be called from a BEGIN rule");
@ -659,12 +674,18 @@ int iscond;
if (tree->type == Node_param_list) {
int paramnum = tree->param_cnt + 1;
if ((tree->flags & FUNC) != 0)
fatal("can't use function name `%s' as variable or array",
tree->vname);
tree = stack_ptr[tree->param_cnt];
if (tree == NULL)
return Nnull_string;
sprintf(namebuf, "parameter #%d", paramnum);
tree->vname = namebuf;
}
}
if (tree->type == Node_array_ref)
tree = tree->orig_array;
switch (tree->type) {
case Node_var:
@ -984,11 +1005,12 @@ register NODE *tree;
* able to begin and end on a single input record, so this
* isn't an ELSE IF, as noted above.
*/
if (! tree->triggered)
if (! tree->triggered) {
if (! eval_condition(tree->condpair->lnode))
return FALSE;
else
tree->triggered = TRUE;
}
/* Else we are triggered */
if (eval_condition(tree->condpair->rnode))
tree->triggered = FALSE;
@ -1069,16 +1091,17 @@ register NODE *tree;
NODE *tmp;
Func_ptr after_assign = NULL;
lhs = get_lhs(tree->lnode, &after_assign);
lval = force_number(*lhs);
/*
* Can't unref *lhs until we know the type; doing so
* too early breaks x += x sorts of things.
* For ++ and --, get the lhs when doing the op and then
* return. For += etc, do the rhs first, since it can
* rearrange things, and *then* get the lhs.
*/
switch(tree->type) {
case Node_preincrement:
case Node_predecrement:
lhs = get_lhs(tree->lnode, &after_assign);
lval = force_number(*lhs);
unref(*lhs);
*lhs = make_number(lval +
(tree->type == Node_preincrement ? 1.0 : -1.0));
@ -1089,6 +1112,8 @@ register NODE *tree;
case Node_postincrement:
case Node_postdecrement:
lhs = get_lhs(tree->lnode, &after_assign);
lval = force_number(*lhs);
unref(*lhs);
*lhs = make_number(lval +
(tree->type == Node_postincrement ? 1.0 : -1.0));
@ -1100,16 +1125,16 @@ register NODE *tree;
break; /* handled below */
}
/*
* It's a += kind of thing. Do the rhs, then the lhs.
*/
tmp = tree_eval(tree->rnode);
rval = force_number(tmp);
free_temp(tmp);
/*
* Do this again; the lhs and the rhs could both be fields.
* Accessing the rhs could cause the lhs to have moved around.
* (Yet another special case. Gack.)
*/
lhs = get_lhs(tree->lnode, &after_assign);
lval = force_number(*lhs);
unref(*lhs);
switch(tree->type) {
@ -1225,7 +1250,7 @@ pop_fcall()
if (arg->type == Node_param_list)
arg = stack_ptr[arg->param_cnt];
n = *sp++;
if ((arg->type == Node_var || arg->type == Node_var_array)
if ((arg->type == Node_var /* || arg->type == Node_var_array */)
&& n->type == Node_var_array) {
/* should we free arg->var_value ? */
arg->var_array = n->var_array;
@ -1235,7 +1260,7 @@ pop_fcall()
arg->flags = n->flags;
}
/* n->lnode overlays the array size, don't unref it if array */
if (n->type != Node_var_array)
if (n->type != Node_var_array && n->type != Node_array_ref)
unref(n->lnode);
freenode(n);
count--;
@ -1245,7 +1270,9 @@ pop_fcall()
/* if n is a local array, all the elements should be freed */
if (n->type == Node_var_array)
assoc_clear(n);
unref(n->lnode);
/* n->lnode overlays the array size, don't unref it if array */
if (n->type != Node_var_array && n->type != Node_array_ref)
unref(n->lnode);
freenode(n);
}
if (f->stack)
@ -1305,11 +1332,19 @@ char *func_name;
r->type = Node_var;
/* call by reference for arrays; see below also */
if (arg->type == Node_param_list)
if (arg->type == Node_param_list) {
/* we must also reassign f here; see below */
f = & fcall_list[curfcall];
arg = f->prevstack[arg->param_cnt];
if (arg->type == Node_var_array)
}
if (arg->type == Node_var_array) {
r->type = Node_array_ref;
r->flags &= ~SCALAR;
r->orig_array = arg;
r->vname = arg->vname;
} else if (arg->type == Node_array_ref) {
*r = *arg;
else {
} else {
n = tree_eval(arg);
r->lnode = dupnode(n);
r->rnode = (NODE *) NULL;
@ -1443,6 +1478,7 @@ Func_ptr *assign;
}
switch (ptr->type) {
case Node_array_ref:
case Node_var_array:
fatal("attempt to use array `%s' in a scalar context",
ptr->vname);
@ -1565,7 +1601,12 @@ Func_ptr *assign;
n = stack_ptr[n->param_cnt];
if ((n->flags & SCALAR) != 0)
fatal("attempt to use scalar parameter %d as an array", i);
} else if (n->type == Node_func) {
}
if (n->type == Node_array_ref) {
n = n->orig_array;
assert(n->type == Node_var_array || n->type == Node_var);
}
if (n->type == Node_func) {
fatal("attempt to use function `%s' as array",
n->lnode->param);
}
@ -1579,6 +1620,8 @@ Func_ptr *assign;
case Node_builtin:
fatal("assignment is not allowed to result of builtin function");
default:
fprintf(stderr, "type = %s\n", nodetype2str(ptr->type));
fflush(stderr);
cant_happen();
}
return aptr;

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
* Copyright (C) 1986, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@ -219,6 +219,11 @@ rebuild_record()
* set_record:
* setup $0, but defer parsing rest of line until reference is made to $(>0)
* or to NF. At that point, parse only as much as necessary.
*
* Manage a private buffer for the contents of $0. Doing so keeps us safe
* if `getline var' decides to rearrange the contents of the IOBUF that
* $0 might have been pointing into. The cost is the copying of the buffer;
* but better correct than fast.
*/
void
set_record(buf, cnt, freeold)
@ -228,6 +233,10 @@ int freeold;
{
register int i;
NODE *n;
static char *databuf;
static unsigned long databuf_size;
#define INITIAL_SIZE 512
#define MAX_SIZE ((unsigned long) ~0) /* maximally portable ... */
NF = -1;
for (i = 1; i <= parse_high_water; i++) {
@ -248,9 +257,24 @@ int freeold;
save_FS = dupnode(FS_node->var_value);
}
if (freeold) {
/* buffer management: */
if (databuf_size == 0) { /* first time */
emalloc(databuf, char *, INITIAL_SIZE, "set_record");
databuf_size = INITIAL_SIZE;
}
/* make sure there's enough room */
if (cnt > databuf_size) {
while (cnt > databuf_size && databuf_size <= MAX_SIZE)
databuf_size *= 2;
erealloc(databuf, char *, databuf_size, "set_record");
}
/* copy the data */
memcpy(databuf, buf, cnt);
/* manage field 0: */
unref(fields_arr[0]);
getnode(n);
n->stptr = buf;
n->stptr = databuf;
n->stlen = cnt;
n->stref = 1;
n->type = Node_val;
@ -260,6 +284,9 @@ int freeold;
}
fields_arr[0]->flags |= MAYBE_NUM;
field0_valid = TRUE;
#undef INITIAL_SIZE
#undef MAX_SIZE
}
/* reset_record --- start over again with current $0 */
@ -759,6 +786,8 @@ NODE *tree;
if (arr->type == Node_param_list)
arr = stack_ptr[arr->param_cnt];
if (arr->type == Node_array_ref)
arr = arr->orig_array;
if (arr->type != Node_var && arr->type != Node_var_array)
fatal("second argument of split is not an array");
arr->type = Node_var_array;

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
* Copyright (C) 1986, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.

238
contrib/awk/install-sh Executable file
View File

@ -0,0 +1,238 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch.
#
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
tranformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1976, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
* Copyright (C) 1976, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@ -477,6 +477,15 @@ int *errflg;
}
if (rp->fp != NULL && isatty(fd))
rp->flag |= RED_NOBUF;
/* Move rp to the head of the list. */
if (red_head != rp) {
if ((rp->prev->next = rp->next) != NULL)
rp->next->prev = rp->prev;
red_head->prev = rp;
rp->prev = NULL;
rp->next = red_head;
red_head = rp;
}
}
}
if (rp->fp == NULL && rp->iop == NULL) {
@ -488,6 +497,13 @@ int *errflg;
/* it is also needed for MINGW32 */
else if (errno == 0) /* HACK! */
close_one();
#endif
#ifdef VMS
/* Alpha/VMS V7.1's C RTL is returning this instead
of EMFILE (haven't tried other post-V6.2 systems) */
#define SS$_EXQUOTA 0x001C
else if (errno == EIO && vaxc$errno == SS$_EXQUOTA)
close_one();
#endif
else {
/*
@ -626,10 +642,6 @@ int exitwarn;
what = ((rp->flag & RED_PIPE) != 0) ? "pipe" : "file";
if (exitwarn)
warning("no explicit close of %s `%s' provided",
what, rp->value);
/* SVR4 awk checks and warns about status of close */
if (status != 0) {
char *s = strerror(errno);
@ -648,6 +660,11 @@ int exitwarn;
ERRNO_node->var_value = make_string(s, strlen(s));
}
}
if (exitwarn)
warning("no explicit close of %s `%s' provided",
what, rp->value);
if (rp->next != NULL)
rp->next->prev = rp->prev;
if (rp->prev != NULL)
@ -1951,8 +1968,16 @@ set_RS()
}
if (RS->stlen == 0)
RS_is_null = TRUE;
else if (RS->stlen > 1)
else if (RS->stlen > 1) {
static int warned = FALSE;
RS_regexp = make_regexp(RS->stptr, RS->stlen, IGNORECASE, TRUE);
if (do_lint && ! warned) {
warning("multicharacter value of `RS' is not portable");
warned = TRUE;
}
}
set_FS_if_not_FIELDWIDTHS();
}

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
* Copyright (C) 1986, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@ -175,10 +175,17 @@ char **argv;
/* Set up the special variables */
/*
* Note that this must be done BEFORE arg parsing else -F
* breaks horribly
* breaks horribly.
*/
init_vars();
/* Set up the field variables */
/*
* Do this before arg parsing so that `-v NF=blah' won't
* break anything.
*/
init_fields();
/* worst case */
emalloc(srcfiles, struct src *, argc * sizeof(struct src), "main");
memset(srcfiles, '\0', argc * sizeof(struct src));
@ -377,9 +384,6 @@ out:
(void) alloca(0);
#endif
/* Set up the field variables */
init_fields();
if (do_lint && begin_block == NULL && expression_value == NULL
&& end_block == NULL)
warning("no program");
@ -439,8 +443,9 @@ FILE *fp;
fputs("\t-W traditional\t\t--traditional\n", fp);
fputs("\t-W usage\t\t--usage\n", fp);
fputs("\t-W version\t\t--version\n", fp);
fputs("\nReport bugs to bug-gnu-utils@gnu.org,\n", fp);
fputs("with a Cc: to arnold@gnu.org\n", fp);
fputs("\nTo report bugs, see node `Bugs' in `gawk.info', which\n", fp);
fputs("is section `Reporting Problems and Bugs' in the\n", fp);
fputs("printed version.\n", fp);
exit(exitval);
}
@ -450,7 +455,7 @@ static void
copyleft()
{
static char blurb_part1[] =
"Copyright (C) 1989, 1991-1999 Free Software Foundation.\n\
"Copyright (C) 1989, 1991-2000 Free Software Foundation.\n\
\n\
This program is free software; you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
@ -652,8 +657,13 @@ char *arg;
badvar = TRUE;
break;
}
if (badvar)
fatal("illegal name `%s' in variable assignment", arg);
if (badvar) {
if (do_lint)
warning("illegal name `%s' in variable assignment", arg);
*--cp = '='; /* restore original text of ARGV */
return NULL;
}
/*
* Recent versions of nawk expand escapes inside assignments.

32
contrib/awk/mkinstalldirs Executable file
View File

@ -0,0 +1,32 @@
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
# Last modified: 1994-03-25
# Public domain
errstatus=0
for file in ${1+"$@"} ; do
set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
shift
pathcomp=
for d in ${1+"$@"} ; do
pathcomp="$pathcomp$d"
case "$pathcomp" in
-* ) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp" 1>&2
mkdir "$pathcomp" || errstatus=$?
fi
pathcomp="$pathcomp/"
done
done
exit $errstatus
# mkinstalldirs ends here

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
* Copyright (C) 1986, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
* Copyright (C) 1986, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@ -203,8 +203,10 @@ register NODE *s;
cant_happen();
if (s->type != Node_val)
cant_happen();
/*
if ((s->flags & NUM) == 0)
cant_happen();
*/
if (s->stref <= 0)
cant_happen();
if ((s->flags & STR) != 0
@ -239,7 +241,7 @@ NODE *n;
}
getnode(r);
*r = *n;
r->flags &= ~(PERM|TEMP);
r->flags &= ~(PERM|TEMP|FIELD);
r->flags |= MALLOC;
if (n->type == Node_val && (n->flags & STR) != 0) {
r->stref = 1;
@ -511,6 +513,18 @@ char **string_ptr;
}
return i;
default:
if (do_lint) {
static short warned[256];
unsigned char uc = (unsigned char) c;
/* N.B.: use unsigned char here to avoid Latin-1 problems */
if (! warned[uc]) {
warned[uc] = TRUE;
warning("escape sequence `\\%c' treated as plain `%c'", uc, uc);
}
}
return c;
}
}

View File

@ -1 +1 @@
#define PATCHLEVEL 4
#define PATCHLEVEL 6

View File

@ -1,3 +1,11 @@
Mon Aug 7 15:23:00 2000 Arnold D. Robbins <arnold@skeeve.com>
* Release 3.0.6: Release tar file made.
Sun Jun 25 15:08:19 2000 Arnold D. Robbins <arnold@skeeve.com>
* Release 3.0.5: Release tar file made.
Wed Jun 30 16:14:36 1999 Arnold D. Robbins <arnold@gnu.org>
* Release 3.0.4: Release tar file made. This time for sure.

128
contrib/awk/protos.h Normal file
View File

@ -0,0 +1,128 @@
/*
* protos.h -- function prototypes for when the headers don't have them.
*/
/*
* Copyright (C) 1991 - 2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
*
* GAWK is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GAWK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef __STDC__
#define aptr_t void * /* arbitrary pointer type */
#else
#define aptr_t char *
#endif
extern aptr_t malloc P((MALLOC_ARG_T));
extern aptr_t realloc P((aptr_t, MALLOC_ARG_T));
extern aptr_t calloc P((MALLOC_ARG_T, MALLOC_ARG_T));
extern void free P((aptr_t));
extern char *getenv P((const char *));
#if ! defined(HAVE_STRING_H) && ! defined(HAVE_STRINGS_H)
extern char *strcpy P((char *, const char *));
extern char *strcat P((char *, const char *));
extern char *strncpy P((char *, const char *, size_t));
extern int strcmp P((const char *, const char *));
extern int strncmp P((const char *, const char *, size_t));
extern char *strchr P((const char *, int));
extern char *strrchr P((const char *, int));
extern char *strstr P((const char *s1, const char *s2));
extern size_t strlen P((const char *));
extern long strtol P((const char *, char **, int));
extern aptr_t memset P((aptr_t, int, size_t));
extern aptr_t memcpy P((aptr_t, const aptr_t, size_t));
extern aptr_t memmove P((aptr_t, const aptr_t, size_t));
extern aptr_t memchr P((const aptr_t, int, size_t));
extern int memcmp P((const aptr_t, const aptr_t, size_t));
#endif /* ! defined(HAVE_STRING_H) && ! defined(HAVE_STRINGS_H) */
#ifndef VMS
extern char *strerror P((int));
#else
extern char *strerror P((int,...));
#endif
#if ! defined(_MSC_VER) && ! defined(__GNU_LIBRARY__)
extern size_t strftime P((char *, size_t, const char *, const struct tm *));
#endif
#ifdef __STDC__
extern time_t time P((time_t *));
#else
extern long time();
#endif
extern FILE *fdopen P((int, const char *));
extern int fprintf P((FILE *, const char *, ...));
#if ! defined(MSDOS) && ! defined(__GNU_LIBRARY__)
#ifdef __STDC__
extern size_t fwrite P((const aptr_t, size_t, size_t, FILE *));
#else
extern int fwrite();
#endif
extern int fputs P((const char *, FILE *));
extern int unlink P((const char *));
#endif
extern int fflush P((FILE *));
extern int fclose P((FILE *));
extern FILE *popen P((const char *, const char *));
extern int pclose P((FILE *));
extern void abort P(());
extern int isatty P((int));
extern void exit P((int));
extern int system P((const char *));
extern int sscanf P((const char *, const char *, ...));
#ifndef toupper
extern int toupper P((int));
#endif
#ifndef tolower
extern int tolower P((int));
#endif
extern double pow P((double x, double y));
extern double atof P((const char *));
extern double strtod P((const char *, char **));
extern int fstat P((int, struct stat *));
extern int stat P((const char *, struct stat *));
extern off_t lseek P((int, off_t, int));
extern int fseek P((FILE *, long, int));
extern int close P((int));
extern int creat P((const char *, mode_t));
extern int open P((const char *, int, ...));
extern int pipe P((int *));
extern int dup P((int));
extern int dup2 P((int,int));
extern int fork P(());
extern int execl P((const char *, const char *, ...));
#ifndef __STDC__
extern int read P((int, void *, unsigned int));
#endif
#ifndef HAVE_SYS_WAIT_H
extern int wait P((int *));
#endif
extern void _exit P((int));
#ifndef __STDC__
extern long time P((long *));
#endif
extern SPRINTF_RET sprintf P((char *, const char *, ...));
#undef aptr_t

View File

@ -3,7 +3,7 @@
*/
/*
* Copyright (C) 1991-1996 the Free Software Foundation, Inc.
* Copyright (C) 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@ -216,7 +216,6 @@ NODE *t;
{
NODE *t1;
/* # define CASE 1 */
if ((t->re_flags & CASE) == IGNORECASE) {
if ((t->re_flags & CONST) != 0)
return t->re_reg;
@ -237,7 +236,7 @@ NODE *t;
t->re_cnt++;
if (t->re_cnt > 10)
t->re_cnt = 0;
if (t->re_text == NULL) {
if (t->re_text == NULL || (t->re_flags & CASE) != IGNORECASE) {
t1 = force_string(tree_eval(t->re_exp));
t->re_text = dupnode(t1);
free_temp(t1);

5744
contrib/awk/regex.c Normal file

File diff suppressed because it is too large Load Diff

1
contrib/awk/stamp-h.in Normal file
View File

@ -0,0 +1 @@
Mon Jun 12 15:56:11 IDT 2000

View File

@ -1,3 +1,134 @@
Mon Aug 7 15:23:00 2000 Arnold D. Robbins <arnold@skeeve.com>
* Release 3.0.6: Release tar file made.
Thu Aug 3 17:51:56 2000 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (nlstrina): new test case.
* nlstrina.awk, nlstrina.ok: new files.
Tue Jul 11 14:22:55 2000 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (fnparydl): new test case.
* fnparydl.awk, fnparydl.ok: new files.
Fri Jun 30 22:00:03 2000 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (arysubnm): new test case.
* arysubnm.awk, arysubnm.ok: new files.
Sun Jun 25 15:08:19 2000 Arnold D. Robbins <arnold@skeeve.com>
* Release 3.0.5: Release tar file made.
Wed Jun 14 13:17:59 2000 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (getlnbuf): new test case.
* getlnbuf.awk, gtlnbufv.awk, getlnbuf.in, getlnbuf.ok: new files.
Mon Jun 5 15:51:39 2000 Arnold D. Robbins <arnold@skeeve.com>
* pipeio2.awk: Change use of tr to sed, fixes problems
on SCO OS5.
* pipeio2.ok: Updated to reflect use of sed.
Tue May 2 13:28:04 2000 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (strftime): moved test code into a separate
file for the PC guys.
* strftime.awk: new file.
Mon Apr 10 15:58:13 2000 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (longwrds): Add setting LC_ALL=C to sort
call to preserve traditional output. (Theme from the
Twilight Zone plays eerily in the background...)
Sun Apr 2 17:51:40 2000 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (igncdym): new test case.
* igncdym.awk, igncdym.in, igncdym.ok: new files.
Wed Mar 8 13:43:44 2000 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (arynocls): new test case.
* arynocls.awk, arynocls.in, arynocls.ok: new files.
Sun Feb 6 11:45:15 2000 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (opasnidx): new test case.
* opasnidx.awk, opasnidx.ok: new files.
Tue Feb 1 18:40:45 2000 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (opasnslf): new test case.
* opasnslf.awk, opasnslf.ok: new files.
Thu Jan 27 18:09:18 2000 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (subslash): new test case.
* subslash.awk, subslash.ok: new files.
Fri Nov 26 11:03:07 1999 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (numindex): new test case.
* numindex.awk, numindex.in, numindex.ok: new files.
Sun Oct 24 08:46:16 1999 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (strftime): Add tweak for $NF that should
hopefully avoid cygwin problems with lack of timezone.
Thu Jul 29 19:25:02 1999 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.in (fsmnam, fnamedat): new test cases.
* fsmnam.awk, fsmnam.ok: new files.
* fnamedat.awk, fnamedat.in, fnamedat.ok: new files.
Wed Jun 30 16:14:36 1999 Arnold D. Robbins <arnold@gnu.org>
* Release 3.0.4: Release tar file made. This time for sure.
Tue May 25 16:37:50 1999 Arnold D. Robbins <arnold@gnu.org>
* Makefile.in (printf1): new test case.
* printf1.awk, printf1.ok: new files.
Wed May 19 15:32:09 1999 Arnold D. Robbins <arnold@gnu.org>
* reg/*: moved exp and log tests to new `Obsolete' directory; they
would only succeed under SunOS 4.x.
Mon May 3 11:53:33 1999 Arnold D. Robbins <arnold@gnu.org>
* Makefile.in (gawk.extensions): removed `nondec' until the
associated features get documented in 3.1.
Tue Nov 3 16:46:39 1998 Arnold D. Robbins <arnold@gnu.org>
* Makefile.in (getnr2tm, getnr2tb): new test cases.
* getnr2tm.awk, getnr2tm.in, getnr2tm.ok: new files.
* getnr2tb.awk, getnr2tb.in, getnr2tb.ok: new files.
Sun Nov 1 13:20:08 1998 Arnold D. Robbins <arnold@gnu.org>
* Makefile.in (zeroflag): new test case.
* zeroflag.awk, zeroflag.ok: new files
Wed Oct 28 18:44:19 1998 Arnold D. Robbins <arnold@gnu.org>
* Makefile.in (nasty): new test case.
* nasty.awk, nasty.ok: new files
Sun Nov 16 20:08:59 1997 Arnold D. Robbins <arnold@gnu.org>
* gsubtest.awk, gsubtest.ok: fix for count of matches in gsub
from Geert.Debyser@esat.kuleuven.ac.be.
Sun Nov 16 19:54:50 1997 Arnold D. Robbins <arnold@gnu.org>
* Makefile.in (strftime): fix a typo (LANC -> LANG).
Thu May 15 12:49:08 1997 Arnold D. Robbins <arnold@skeeve.atl.ga.us>
* Release 3.0.3: Release tar file made.

View File

@ -1,6 +1,6 @@
# Makefile for GNU Awk test suite.
#
# Copyright (C) 1988-1997 the Free Software Foundation, Inc.
# Copyright (C) 1988-2000 the Free Software Foundation, Inc.
#
# This file is part of GAWK, the GNU implementation of the
# AWK Programming Language.
@ -37,12 +37,16 @@ basic: msg swaplns messages argarray longwrds \
sprintfc backgsub tweakfld clsflnam mmap8k fnarray \
dynlj substr eofsplit prt1eval gsubasgn prtoeval gsubtest splitwht \
back89 tradanch nlfldsep splitvar intest nfldstr nors fnarydel \
noparms funstack clobber delarprm prdupval
noparms funstack clobber delarprm prdupval nasty zeroflag \
getnr2tm getnr2tb printf1 funsmnam fnamedat numindex subslash \
opasnslf opasnidx arynocls getlnbuf arysubnm fnparydl nlstrina
unix-tests: poundbang fflush getlnhd pipeio1 pipeio2 strftlng pid
gawk.extensions: fieldwdth ignrcase posix manyfiles igncfs argtest \
badargs strftime gensub gnureops reint nondec
badargs strftime gensub gnureops reint igncdym
# add this back for 3.1
# nondec
extra: regtest inftest
@ -89,7 +93,7 @@ igncfs::
$(CMP) $(srcdir)/igncfs.ok _$@ && rm -f _$@
longwrds::
@$(AWK) -f $(srcdir)/longwrds.awk $(srcdir)/manpage | sort >_$@
@$(AWK) -f $(srcdir)/longwrds.awk $(srcdir)/manpage | (LC_ALL=C sort) >_$@
$(CMP) $(srcdir)/longwrds.ok _$@ && rm -f _$@
fieldwdth::
@ -211,10 +215,8 @@ nofmtch::
strftime::
: this test could fail on slow machines or on a second boundary,
: so if it does, double check the actual results
@LC_ALL=C; export LC_ALL; LANC=C; export LANG; \
date | $(AWK) '{ $$3 = sprintf("%02d", $$3 + 0) ; \
print > "strftime.ok" ; \
print strftime() > "'_$@'" }'
@LC_ALL=C; export LC_ALL; LANG=C; export LANG; \
date | $(AWK) -v OUTPUT=_$@ -f $(srcdir)/strftime.awk
$(CMP) strftime.ok _$@ && rm -f _$@ strftime.ok || exit 0
litoct::
@ -442,6 +444,75 @@ nondec::
fi
$(CMP) $(srcdir)/nondec.ok _$@ && rm -f _$@
nasty::
@$(AWK) -f $(srcdir)/nasty.awk >_$@
$(CMP) $(srcdir)/nasty.ok _$@ && rm -f _$@
zeroflag::
@$(AWK) -f $(srcdir)/zeroflag.awk >_$@
$(CMP) $(srcdir)/zeroflag.ok _$@ && rm -f _$@
getnr2tm::
@$(AWK) -f $(srcdir)/getnr2tm.awk $(srcdir)/getnr2tm.in >_$@
$(CMP) $(srcdir)/getnr2tm.ok _$@ && rm -f _$@
getnr2tb::
@$(AWK) -f $(srcdir)/getnr2tb.awk $(srcdir)/getnr2tb.in >_$@
$(CMP) $(srcdir)/getnr2tb.ok _$@ && rm -f _$@
printf1::
@$(AWK) -f $(srcdir)/printf1.awk >_$@
$(CMP) $(srcdir)/printf1.ok _$@ && rm -f _$@
funsmnam::
@-AWKPATH=$(srcdir) $(AWK) -f funsmnam.awk >_$@ 2>&1 || exit 0
$(CMP) $(srcdir)/funsmnam.ok _$@ && rm -f _$@
fnamedat::
@-AWKPATH=$(srcdir) $(AWK) -f fnamedat.awk < $(srcdir)/fnamedat.in >_$@ 2>&1 || exit 0
$(CMP) $(srcdir)/fnamedat.ok _$@ && rm -f _$@
numindex::
@-AWKPATH=$(srcdir) $(AWK) -f numindex.awk < $(srcdir)/numindex.in >_$@ 2>&1 || exit 0
$(CMP) $(srcdir)/numindex.ok _$@ && rm -f _$@
subslash::
@-AWKPATH=$(srcdir) $(AWK) -f subslash.awk >_$@ 2>&1 || exit 0
$(CMP) $(srcdir)/subslash.ok _$@ && rm -f _$@
opasnslf::
@-AWKPATH=$(srcdir) $(AWK) -f opasnslf.awk >_$@ 2>&1 || exit 0
$(CMP) $(srcdir)/opasnslf.ok _$@ && rm -f _$@
opasnidx::
@-AWKPATH=$(srcdir) $(AWK) -f opasnidx.awk >_$@ 2>&1 || exit 0
$(CMP) $(srcdir)/opasnidx.ok _$@ && rm -f _$@
arynocls::
@-AWKPATH=$(srcdir) $(AWK) -v INPUT=$(srcdir)/arynocls.in -f arynocls.awk >_$@
$(CMP) $(srcdir)/arynocls.ok _$@ && rm -f _$@
igncdym::
@-AWKPATH=$(srcdir) $(AWK) -f igncdym.awk $(srcdir)/igncdym.in >_$@
$(CMP) $(srcdir)/igncdym.ok _$@ && rm -f _$@
getlnbuf::
@-AWKPATH=$(srcdir) $(AWK) -f getlnbuf.awk $(srcdir)/getlnbuf.in > _$@
@-AWKPATH=$(srcdir) $(AWK) -f gtlnbufv.awk $(srcdir)/getlnbuf.in > _2$@
$(CMP) $(srcdir)/getlnbuf.ok _$@ && $(CMP) $(srcdir)/getlnbuf.ok _2$@ && rm -f _$@ _2$@
arysubnm::
@-AWKPATH=$(srcdir) $(AWK) -f arysubnm.awk >_$@
$(CMP) $(srcdir)/arysubnm.ok _$@ && rm -f _$@
fnparydl::
@-AWKPATH=$(srcdir) $(AWK) -f fnparydl.awk >_$@
$(CMP) $(srcdir)/fnparydl.ok _$@ && rm -f _$@
nlstrina::
@-AWKPATH=$(srcdir) $(AWK) -f nlstrina.awk >_$@
$(CMP) $(srcdir)/nlstrina.ok _$@ && rm -f _$@
clean:
rm -fr _* core junk out1 out2 out3 strftime.ok test1 test2 seq *~

View File

@ -0,0 +1,95 @@
#To: bug-gnu-utils@gnu.org
#From: Kristján Jónasson <kristjan@decode.is>
#Subject: Gawk bug
#Cc: arnold@gnu.org
#
#Hi!
#
#The following seems to be a bug in gawk. I have tried as I could to
#minimize the bug-causing program, so of course it does not seem to do
#anything useful in its present form. The error message received is:
#
#gawk: test.awk:15: fatal error: internal error
#Aborted
#
#Note that there is an attached file that the program reads, called "a". I
#played with the program a fair bit and my feeling is that the error is
#related with the delete statement, and not the reading of the file and the
#close statement. At one point I was able to remove the file reading and
#still obtain the error. If, for example, I remove the close statement and
#make two copies of the file instead, (reading one copy in sub1 and the
#other in sub2), the error still occurs.
#
#The operating system is Red Hat Linux, version 6.0, the gawk is version
#3.0.4, and the gawk was obtained from an rpm file gawk-3.0.4-1.i386.rpm.
#
#The program is:
#
# Wed Mar 8 13:41:34 IST 2000
# ADR: modified to use INPUT, so can set it from command line.
# When run, no output is produced, but it shouldn't core
# dump, either.
#
# The program bug is to not close the file in sub2.
function sub1(x) {
# while (getline < "a" == 1) i++
while (getline < INPUT == 1) i++
# close("a")
close(INPUT)
}
function sub2(x) {
i=0
delete y
# while (getline < "a" == 1) z[++i] = $1
while (getline < INPUT == 1) z[++i] = $1
for(i in z) y[i] = x[i] + z[i]
}
function sub3(x, y, z) {
sub2(x)
for(i=1; i<=4; i++) z[i] = y[i]
}
BEGIN {
sub1(x)
sub2(x)
sub3(x, y, z)
}
#
#And the data file is:
#
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
# 32.440 3.830 3.383700000000000 10.08 298 865
#
#

View File

@ -0,0 +1,30 @@
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865
32.440 3.830 3.383700000000000 10.08 298 865

View File

View File

@ -0,0 +1 @@
BEGIN { n = 11 ; foo[n] = n; print (2 <= n) }

View File

@ -0,0 +1 @@
1

View File

@ -19,5 +19,6 @@ POSIX options: GNU long options:
-W usage --usage
-W version --version
Report bugs to bug-gnu-utils@prep.ai.mit.edu,
with a Cc: to arnold@gnu.ai.mit.edu
To report bugs, see node `Bugs' in `gawk.info', which
is section `Reporting Problems and Bugs' in the
printed version.

View File

@ -0,0 +1 @@
function foo() { print foo } {foo()}

View File

@ -0,0 +1 @@
foo

View File

@ -0,0 +1 @@
gawk: fnamedat.awk:1: (FILENAME=- FNR=1) fatal: can't use function name `foo' as variable or array

View File

@ -0,0 +1,31 @@
# fnparydl.awk --- check that deleting works with arrays
# that are parameters.
#
# Tue Jul 11 14:20:58 EDT 2000
function delit(a, k)
{
print "BEFORE LOOP"
for (k in a) {
print "DELETING KEY", k
delete a[k]
}
print "AFTER LOOP"
}
BEGIN {
for (i = 1 ; i <= 7; i++) {
q[i] = sprintf("element %d", i)
x[i] = i
y[i] = q[i]
}
# adump(q)
delit(q)
# for (i in q)
# delete q[i]
j = 0;
for (i in q)
j++
print j, "elements still in q[]"
# adump(q)
}

Some files were not shown because too many files have changed in this diff Show More