home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gawk-2.15.6-diffs.gz / gawk-2.15.6-diffs
Text File  |  1996-10-13  |  602KB  |  15,800 lines

  1. This file contains patches that transform the baseline version into
  2. the amiga version.  Assuming that you have unarchived the baseline
  3. version in the current directory, just run the command:
  4.  
  5.     patch -p1 -E -b .pbak <diff-file
  6.  
  7. where 'diff-file' is this patch file.  After running patch you should
  8. remove all the generated *.pbak files, and look for any *.rej files
  9. that indicate a problem patching the baseline source.
  10.  
  11. diff -rup --new-file baseline/fsf/gawk/Makefile.in amiga/fsf/gawk/Makefile.in
  12. --- baseline/fsf/gawk/Makefile.in    Mon Mar  6 04:44:35 1995
  13. +++ amiga/fsf/gawk/Makefile.in    Sat Sep 28 00:00:00 1996
  14. @@ -22,78 +22,48 @@
  15.  # User tunable macros -- CHANGE THESE IN Makefile.in RATHER THAN IN 
  16.  # Makefile, OR configure WILL OVERWRITE YOUR CHANGES
  17.  
  18. -prefix = /usr/local
  19. +#### Start of system configuration section. ####
  20. +
  21. +VPATH = @srcdir@
  22. +srcdir = @srcdir@
  23. +
  24. +# Common prefix for machine-independent installed files.
  25. +prefix = /ade
  26. +# Common prefix for machine-dependent installed files.
  27.  exec_prefix = $(prefix)
  28. -binprefix =
  29. -manprefix =
  30.  
  31. +# Directory to install executables in.
  32.  bindir = $(exec_prefix)/bin
  33. +# Directory to install libraries in.
  34.  libdir = $(exec_prefix)/lib
  35. -mandir = $(prefix)/man/man1
  36. -manext = .1
  37. +# Directory to install the Info files in.
  38.  infodir = $(prefix)/info
  39. +# Directory to install the man page in.
  40. +mandir = $(prefix)/man/man$(manext)
  41. +# Number to put on the man page filename.
  42. +manext = 1
  43. +
  44. +# Program to install executables.
  45. +INSTALL_PROGRAM = @INSTALL_PROGRAM@
  46. +# Program to install data like man pages.
  47. +INSTALL_DATA = @INSTALL_DATA@
  48. +# Generic install program.
  49. +INSTALL = @INSTALL@
  50. +
  51. +CC = @CC@
  52. +DEFS = @DEFS@
  53. +CFLAGS = @CFLAGS@
  54.  
  55. -#    The provided "configure" is used to turn a config file (samples in
  56. -#    the "config" directory into commands to edit config.in into
  57. -#    a suitable config.h and to edit Makefile.in into Makefile.
  58. -#    To port GAWK, create an appropriate config file using the ones in
  59. -#    the config directory as examples and using the comments in config.in
  60. -#    as a guide.
  61. -
  62. -CC=         gcc -g
  63. -##MAKE_CC## CC = cc
  64. -
  65. -PROFILE=    #-pg
  66. -DEBUG=        #-DMALLOCDEBUG #-DDEBUG #-DFUNC_TRACE #-DMPROF
  67. -LINKSTATIC=    #-Bstatic
  68. -WARN=        #-W -Wunused -Wimplicit -Wreturn-type -Wcomment    # for gcc only
  69. -
  70. -# Parser to use on grammar - any one of the following will work
  71. -PARSER = bison -y
  72. -#PARSER = yacc
  73. -#PARSER = byacc
  74. -
  75. -# Set LIBS to any libraries that are machine specific
  76. -LIBS =
  77. -
  78. -# Cray 2 running Unicos 5.0.7
  79. -##MAKE_LIBNET## LIBS = -lnet
  80. -
  81. -
  82. -# Systems with alloca in /lib/libPW.a
  83. -##MAKE_ALLOCA_PW## LIBS = -lPW
  84. -
  85. -# ALLOCA - only needed if you use bison
  86. -#    Set equal to alloca.o if your system is S5 and you don't have
  87. -#    alloca. Uncomment one of the rules below to make alloca.o from
  88. -#    either alloca.s or alloca.c.
  89. -#    This should have already been done automatically by configure.
  90. -#
  91. -#    Some systems have alloca in libPW.a, so LIBS=-lPW may work, too.
  92. -##MAKE_ALLOCA_C## ALLOCA= alloca.o
  93. -##MAKE_ALLOCA_S## ALLOCA= alloca.o
  94. -
  95. -VFLAGS=
  96. -
  97. -# VMS POSIX, VAXC V3.2
  98. -##MAKE_VMS-Posix## VFLAGS = -UVMS -D__STDC__=0
  99. -
  100. -# HP/Apollo running cc version 6.7 or earlier
  101. -##MAKE_Apollo## VFLAGS = -U__STDC__ -A run,sys5.3
  102. -##MAKE_Apollo## LIBS = -A sys,any
  103. -
  104. -# SGI IRIX 4.0.5 cc flags
  105. -##MAKE_SGI## VFLAGS = -cckr -signed
  106. -##MAKE_SGI_GCC## VFLAGS =  -fsigned-char
  107. +LDFLAGS = @LDFLAGS@
  108. +LIBS = @LIBS@
  109.  
  110. -##MAKE_NeXT## VFLAGS = -DGFMT_WORKAROUND
  111. +YACC = @YACC@
  112.  
  113. -CFLAGS = -O
  114. -FLAGS = -DGAWK -DHAVE_CONFIG_H $(VFLAGS) $(DEBUG) $(PROFILE) $(WARN)
  115. -LDFLAGS = $(LINKSTATIC) $(PROFILE)
  116. +#### End of system configuration section. ####
  117.  
  118. +# "-I." is needed to find config.h in the build directory.
  119.  .c.o:
  120. -    $(CC) $(CFLAGS) $(FLAGS) -c $<
  121. +    $(CC) -c -I. -I$(srcdir) $(DEFS) $(CFLAGS) $<
  122.  
  123.  # object files
  124.  AWKOBJS = main.o eval.o builtin.o msg.o iop.o io.o field.o array.o \
  125. @@ -138,6 +108,8 @@ ALLDOC= gawk.dvi $(TEXFILES) gawk.info*
  126.  # Release of gawk.  There can be no leading or trailing white space here!
  127.  REL=2.15
  128.  
  129. +all:    gawk
  130. +
  131.  # rules to build gawk
  132.  gawk:    $(ALLOBJS) $(GNUOBJS) $(REOBJS)
  133.      $(CC) -o gawk $(LDFLAGS) $(ALLOBJS) $(GNUOBJS) $(REOBJS) -lm $(LIBS)
  134. @@ -151,26 +123,25 @@ getopt1.o:    getopt.h
  135.  main.o:    patchlevel.h
  136.  
  137.  awktab.c:    awk.y
  138. -    $(PARSER) -v awk.y
  139. -##MAKE_VMS-Posix##     sed '/^\#module/d' ytab.c >awktab.c && rm ytab.c
  140. -##MAKE_VMS-Posix## dummy.awk_tab.target:
  141. -    sed '/^extern char .malloc(), .realloc();$$/d' y.tab.c >awktab.c
  142. -    rm y.tab.c
  143. +    @echo "expect 40 shift/reduce conflicts"
  144. +    $(YACC) -v $(srcdir)/awk.y
  145. +    @sed '/extern char.*malloc/d' <y.tab.c >awktab.c
  146. +    @rm y.tab.c
  147.  
  148.  awktab.o:    awk.h
  149.  
  150. -config.h:    config.in
  151. -    @echo You must provide a config.h!
  152. -    @echo Run \"./configure\" to build it for known systems
  153. -    @echo or copy config.in to config.h and edit it.; exit 1
  154. +# On AmigaOS, there is no "native awk", so install gawk as both
  155. +# /bin/gawk and /bin/awk.
  156.  
  157.  install:    gawk gawk.info
  158. -    cp gawk $(bindir)/gawk && chmod 755 $(bindir)/gawk
  159. -    cp gawk.1 $(mandir)/gawk$(manext) && chmod 644 $(mandir)/gawk$(manext)
  160. -    cp gawk.info* $(infodir) && chmod 644 $(infodir)/gawk.info*
  161. +    $(INSTALL_PROGRAM) gawk $(bindir)/awk
  162. +    $(INSTALL_PROGRAM) gawk $(bindir)/gawk
  163. +    $(INSTALL_DATA) $(srcdir)/gawk.1 $(mandir)/gawk.$(manext)
  164. +    cd $(srcdir); for f in gawk.info*; \
  165. +    do $(INSTALL_DATA) $$f $(infodir)/$$f; done
  166.  
  167.  uninstall:
  168. -    rm -f $(bindir)/gawk $(mandir)/gawk$(manext) $(infodir)/gawk.info*
  169. +    rm -f $(bindir)/gawk $(mandir)/gawk.$(manext) $(infodir)/gawk.info*
  170.  
  171.  # ALLOCA: uncomment this if your system (notably System V boxen)
  172.  # does not have alloca in /lib/libc.a or /lib/libPW.a
  173. @@ -182,13 +153,6 @@ uninstall:
  174.  # One of these rules should have already been selected by running configure.
  175.  
  176.  
  177. -##MAKE_ALLOCA_S## alloca.o:    alloca.s
  178. -##MAKE_ALLOCA_S##     /lib/cpp < alloca.s | sed '/^#/d' > t.s
  179. -##MAKE_ALLOCA_S##     as t.s -o alloca.o
  180. -##MAKE_ALLOCA_S##     rm t.s
  181. -
  182. -##MAKE_ALLOCA_C## alloca.o:    alloca.c
  183. -
  184.  # auxiliary rules for release maintenance
  185.  lint:    $(ALLSRC)
  186.      lint -hcbax $(FLAGS) $(ALLSRC)
  187. @@ -216,14 +180,14 @@ clobber:    clean
  188.      rm -f $(ALLDOC) gawk.log config.h
  189.  
  190.  gawk.dvi:    gawk.texi
  191. -    cp support/texinfo.tex .
  192. -    tex gawk.texi; texindex gawk.??
  193. -    tex gawk.texi; texindex gawk.??
  194. -    tex gawk.texi
  195. +    cp $(srcdir)/support/texinfo.tex .
  196. +    tex $(srcdir)/gawk.texi; texindex gawk.??
  197. +    tex $(srcdir)/gawk.texi; texindex gawk.??
  198. +    tex $(srcdir)/gawk.texi
  199.      rm -f texinfo.tex
  200.  
  201.  gawk.info:    gawk.texi
  202. -    makeinfo gawk.texi
  203. +    makeinfo -I$(srcdir) $(srcdir)/gawk.texi -o gawk.info
  204.  
  205.  dist:    $(AWKSRC) $(GNUSRC) $(DOCS) $(MISC) $(COPIES) $(SUPPORT) distclean
  206.      -rm -rf gawk-$(REL)*
  207. @@ -265,3 +229,17 @@ test:    gawk
  208.  
  209.  check:    test
  210.  
  211. +Makefile:    config.status $(srcdir)/Makefile.in
  212. +        $(SHELL) config.status
  213. +
  214. +config.h:    stamp-config ;
  215. +
  216. +stamp-config:    config.status $(srcdir)/config.h.in
  217. +        $(SHELL) config.status
  218. +        touch stamp-config
  219. +
  220. +configure:    configure.in
  221. +        autoconf $(ACFLAGS)
  222. +
  223. +config.h.in:    configure.in
  224. +        autoheader $(ACFLAGS)
  225. diff -rup --new-file baseline/fsf/gawk/Product-Info amiga/fsf/gawk/Product-Info
  226. --- baseline/fsf/gawk/Product-Info    Wed Dec 31 17:00:00 1969
  227. +++ amiga/fsf/gawk/Product-Info    Sat Sep 28 00:00:00 1996
  228. @@ -0,0 +1,33 @@
  229. +.name
  230. +gawk
  231. +.fullname
  232. +GNU awk, pattern scanning and processing language
  233. +.type
  234. +Programmer Tool
  235. +.short
  236. +Pattern scanning & processing.
  237. +.description
  238. +Gawk is the GNU Project's implementation of the AWK programming
  239. +language.  It conforms to the definition of the language in the POSIX
  240. +1003.2 Command Language And Utilities Standard.  This version in turn
  241. +is based on the description in "The AWK Programming Language", by Aho,
  242. +Kernighan, and Weinberger, with the additional features defined in the
  243. +System V Release 4 version of UNIX awk.  Gawk also provides some
  244. +GNU-specific extensions.
  245. +
  246. +The command line consists of options to gawk itself, the AWK program
  247. +text (if not supplied via the -f or --file options), and values to be
  248. +made available in the ARGC and ARGV pre-defined AWK variables.
  249. +.version
  250. +2.15.6
  251. +.author
  252. +Paul Rubin
  253. +Jay Fenlason
  254. +David Trueman
  255. +Arnold Robbins
  256. +.requirements
  257. +Amiga binary requires ixemul.library.
  258. +.distribution
  259. +GNU Public License
  260. +.described-by
  261. +Fred Fish (fnf@amigalib.com)
  262. diff -rup --new-file baseline/fsf/gawk/README.amiga amiga/fsf/gawk/README.amiga
  263. --- baseline/fsf/gawk/README.amiga    Tue Jun  1 12:22:31 1993
  264. +++ amiga/fsf/gawk/README.amiga    Sat Sep 28 00:00:00 1996
  265. @@ -24,7 +24,7 @@ Only copy the following into config/amig
  266.  Amiga under AmigaOS with gcc
  267.  DOPRNT_MISSING 1
  268.  ENVSEP ','
  269. -DEFPATH  ".,/usr/local/lib"
  270. +DEFPATH  ".,/ade/lib"
  271.  HAVE_UNDERSCORE_SETJMP 1
  272.  SRANDOM_PROTO 1
  273.  STDC_HEADERS 1
  274. diff -rup --new-file baseline/fsf/gawk/awk.h amiga/fsf/gawk/awk.h
  275. --- baseline/fsf/gawk/awk.h    Thu Mar  9 09:26:41 1995
  276. +++ amiga/fsf/gawk/awk.h    Sat Sep 28 00:00:00 1996
  277. @@ -67,8 +67,8 @@ extern int errno;
  278.  #define const
  279.  #endif
  280.  
  281. -#ifndef SIGTYPE
  282. -#define SIGTYPE    void
  283. +#ifndef RETSIGTYPE
  284. +#define RETSIGTYPE    void
  285.  #endif
  286.  
  287.  #ifdef SIZE_T_MISSING
  288. @@ -195,7 +195,7 @@ extern int _text_read (int, char *, int)
  289.  #endif
  290.  
  291.  #ifndef DEFPATH
  292. -#define DEFPATH    ".:/usr/local/lib/awk:/usr/lib/awk"
  293. +#define DEFPATH    ".:/local/lib/awk:/ade/lib/awk"
  294.  #endif
  295.  
  296.  #ifndef ENVSEP
  297. @@ -728,7 +728,7 @@ extern int main P((int argc, char **argv
  298.  extern Regexp *mk_re_parse P((char *s, int ignorecase));
  299.  extern void load_environ P((void));
  300.  extern char *arg_assign P((char *arg));
  301. -extern SIGTYPE catchsig P((int sig, int code));
  302. +extern RETSIGTYPE catchsig P((int sig, int code));
  303.  /* msg.c */
  304.  extern void err P((const char *s, const char *emsg, va_list argp));
  305.  #if _MSC_VER == 510
  306. diff -rup --new-file baseline/fsf/gawk/config/amigaos amiga/fsf/gawk/config/amigaos
  307. --- baseline/fsf/gawk/config/amigaos    Wed Dec 31 17:00:00 1969
  308. +++ amiga/fsf/gawk/config/amigaos    Sat Sep 28 00:00:00 1996
  309. @@ -0,0 +1,6 @@
  310. +Amiga under AmigaOS with gcc
  311. +ENVSEP ','
  312. +DEFPATH  ".,/ade/lib"
  313. +HAVE_UNDERSCORE_SETJMP 1
  314. +SRANDOM_PROTO 1
  315. +STDC_HEADERS 1
  316. diff -rup --new-file baseline/fsf/gawk/config.h.in amiga/fsf/gawk/config.h.in
  317. --- baseline/fsf/gawk/config.h.in    Wed Dec 31 17:00:00 1969
  318. +++ amiga/fsf/gawk/config.h.in    Sat Sep 28 00:00:00 1996
  319. @@ -0,0 +1,290 @@
  320. +/*
  321. + * config.h -- configuration definitions for gawk.
  322. + *
  323. + * __SYSTEM__
  324. + */
  325. +
  326. +/* 
  327. + * Copyright (C) 1991, 1992, 1993 the Free Software Foundation, Inc.
  328. + * 
  329. + * This file is part of GAWK, the GNU implementation of the
  330. + * AWK Progamming Language.
  331. + * 
  332. + * GAWK is free software; you can redistribute it and/or modify
  333. + * it under the terms of the GNU General Public License as published by
  334. + * the Free Software Foundation; either version 2, or (at your option)
  335. + * any later version.
  336. + * 
  337. + * GAWK is distributed in the hope that it will be useful,
  338. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  339. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  340. + * GNU General Public License for more details.
  341. + * 
  342. + * You should have received a copy of the GNU General Public License
  343. + * along with GAWK; see the file COPYING.  If not, write to
  344. + * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  345. + */
  346. +
  347. +/*
  348. + * This file isolates configuration dependencies for gnu awk.
  349. + * You should know something about your system, perhaps by having
  350. + * a manual handy, when you edit this file.  You should copy config.h-dist
  351. + * to config.h, and edit config.h.  Do not modify config.h-dist, so that
  352. + * it will be easy to apply any patches that may be distributed.
  353. + *
  354. + * The general idea is that systems conforming to the various standards
  355. + * should need to do the least amount of changing.  Definining the various
  356. + * items in ths file usually means that your system is missing that
  357. + * particular feature.
  358. + *
  359. + * The order of preference in standard conformance is ANSI C, POSIX,
  360. + * and the SVID.
  361. + *
  362. + * If you have no clue as to what's going on with your system, try
  363. + * compiling gawk without editing this file and see what shows up
  364. + * missing in the link stage.  From there, you can probably figure out
  365. + * which defines to turn on.
  366. + */
  367. +
  368. +/**************************/
  369. +/* Miscellanious features */
  370. +/**************************/
  371. +
  372. +/*
  373. + * BLKSIZE_MISSING
  374. + *
  375. + * Check your /usr/include/sys/stat.h file.  If the stat structure
  376. + * does not have a member named st_blksize, define this.  (This will
  377. + * most likely be the case on most System V systems prior to V.4.)
  378. + */
  379. +#undef BLKSIZE_MISSING
  380. +
  381. +/*
  382. + * RETSIGTYPE
  383. + *
  384. + * The return type of the routines passed to the signal function.
  385. + * Modern systems use `void', older systems use `int'.
  386. + * If left undefined, it will default to void.
  387. + */
  388. +#undef RETSIGTYPE
  389. +
  390. +/*
  391. + * SIZE_T_MISSING
  392. + *
  393. + * If your system has no typedef for size_t, define this to get a default
  394. + */
  395. +#undef SIZE_T_MISSING
  396. +
  397. +/*
  398. + * CHAR_UNSIGNED
  399. + *
  400. + * If your machine uses unsigned characters (IBM RT and RS/6000 and others)
  401. + * then define this for use in regex.c
  402. + */
  403. +#undef CHAR_UNSIGNED
  404. +
  405. +/*
  406. + * HAVE_UNDERSCORE_SETJMP
  407. + *
  408. + * Check in your /usr/include/setjmp.h file.  If there are routines
  409. + * there named _setjmp and _longjmp, then you should define this.
  410. + * Typically only systems derived from Berkeley Unix have this.
  411. + */
  412. +
  413. +#undef HAVE_UNDERSCORE_SETJMP
  414. +
  415. +/***********************************************/
  416. +/* Missing library subroutines or system calls */
  417. +/***********************************************/
  418. +
  419. +/*
  420. + * MEMCMP_MISSING
  421. + * MEMCPY_MISSING
  422. + * MEMSET_MISSING
  423. + *
  424. + * These three routines are for manipulating blocks of memory. Most
  425. + * likely they will either all three be present or all three be missing,
  426. + * so they're grouped together.
  427. + */
  428. +
  429. +#undef MEMCMP_MISSING
  430. +#undef MEMCPY_MISSING
  431. +#undef MEMSET_MISSING
  432. +
  433. +/*
  434. + * RANDOM_MISSING
  435. + *
  436. + * Your system does not have the random(3) suite of random number
  437. + * generating routines.  These are different than the old rand(3)
  438. + * routines!
  439. + */
  440. +#undef RANDOM_MISSING
  441. +
  442. +/*
  443. + * STRCASE_MISSING
  444. + *
  445. + * Your system does not have the strcasemp() and strncasecmp()
  446. + * routines that originated in Berkeley Unix.
  447. + */
  448. +#undef STRCASE_MISSING
  449. +
  450. +/*
  451. + * STRCHR_MISSING
  452. + *
  453. + * Your system does not have the strchr() and strrchr() functions.
  454. + */
  455. +#undef STRCHR_MISSING
  456. +
  457. +/*
  458. + * STRERROR_MISSING
  459. + *
  460. + * Your system lacks the ANSI C strerror() routine for returning the
  461. + * strings associated with errno values.
  462. + */
  463. +#undef STRERROR_MISSING
  464. +
  465. +/*
  466. + * STRTOD_MISSING
  467. + *
  468. + * Your system does not have the strtod() routine for converting
  469. + * strings to double precision floating point values.
  470. + */
  471. +#undef STRTOD_MISSING
  472. +
  473. +/*
  474. + * STRFTIME_MISSING
  475. + *
  476. + * Your system lacks the ANSI C strftime() routine for formatting
  477. + * broken down time values.
  478. + */
  479. +#undef STRFTIME_MISSING
  480. +
  481. +/*
  482. + * TZSET_MISSING
  483. + *
  484. + * If you have a 4.2 BSD vintage system, then the strftime() routine
  485. + * supplied in the missing directory won't be enough, because it relies on the
  486. + * tzset() routine from System V / Posix.  Fortunately, there is an
  487. + * emulation for tzset() too that should do the trick.  If you don't
  488. + * have tzset(), define this.
  489. + */
  490. +#undef TZSET_MISSING
  491. +
  492. +/*
  493. + * TZNAME_MISSING
  494. + *
  495. + * Some systems do not support the external variables tzname and daylight.
  496. + * If this is the case *and* strftime() is missing, define this.
  497. + */
  498. +#undef TZNAME_MISSING
  499. +
  500. +/*
  501. + * STDC_HEADERS
  502. + *
  503. + * If your system does have ANSI compliant header files that
  504. + * provide prototypes for library routines, then define this.
  505. + */
  506. +#undef STDC_HEADERS
  507. +
  508. +/*
  509. + * NO_TOKEN_PASTING
  510. + *
  511. + * If your compiler define's __STDC__ but does not support token
  512. + * pasting (tok##tok), then define this.
  513. + */
  514. +#undef NO_TOKEN_PASTING
  515. +
  516. +/*****************************************************************/
  517. +/* Stuff related to the Standard I/O Library.             */
  518. +/*****************************************************************/
  519. +/* Much of this is (still, unfortunately) black magic in nature. */
  520. +/* You may have to use some or all of these together to get gawk */
  521. +/* to work correctly.                         */
  522. +/*****************************************************************/
  523. +
  524. +/*
  525. + * NON_STD_SPRINTF
  526. + *
  527. + * Look in your /usr/include/stdio.h file.  If the return type of the
  528. + * sprintf() function is NOT `int', define this.
  529. + */
  530. +#undef NON_STD_SPRINTF
  531. +
  532. +/*
  533. + * VPRINTF_MISSING
  534. + *
  535. + * Define this if your system lacks vprintf() and the other routines
  536. + * that go with it.  This will trigger an attempt to use _doprnt().
  537. + * If you don't have that, this attempt will fail and you are on your own.
  538. + */
  539. +#undef VPRINTF_MISSING
  540. +
  541. +/*
  542. + * Casts from size_t to int and back.  These will become unnecessary
  543. + * at some point in the future, but for now are required where the
  544. + * two types are a different representation.
  545. + */
  546. +#undef SZTC
  547. +#undef INTC
  548. +
  549. +/*
  550. + * SYSTEM_MISSING
  551. + *
  552. + * Define this if your library does not provide a system function
  553. + * or you are not entirely happy with it and would rather use
  554. + * a provided replacement (atari only).
  555. + */
  556. +#undef SYSTEM_MISSING
  557. +
  558. +/*
  559. + * FMOD_MISSING
  560. + *
  561. + * Define this if your system lacks the fmod() function and modf() will
  562. + * be used instead.
  563. + */
  564. +#undef FMOD_MISSING
  565. +
  566. +
  567. +/*******************************/
  568. +/* Gawk configuration options. */
  569. +/*******************************/
  570. +
  571. +/*
  572. + * DEFPATH
  573. + *
  574. + * The default search path for the -f option of gawk.  It is used
  575. + * if the AWKPATH environment variable is undefined.  The default
  576. + * definition is provided here.  Most likely you should not change
  577. + * this.
  578. + */
  579. +
  580. +#define DEFPATH    ".,/local/lib/awk,/ade/lib/awk"        /* HACK - fnf */
  581. +#define ENVSEP    ','                    /* HACK - fnf */
  582. +
  583. +/*
  584. + * alloca already has a prototype defined - don't redefine it
  585. + */
  586. +#undef ALLOCA_PROTO
  587. +
  588. +/*
  589. + * srandom already has a prototype defined - don't redefine it
  590. + */
  591. +#undef SRANDOM_PROTO
  592. +
  593. +/*
  594. + * getpgrp() in sysvr4 and POSIX takes no argument
  595. + */
  596. +#undef GETPGRP_NOARG
  597. +
  598. +/*
  599. + * define const to nothing if not __STDC__
  600. + */
  601. +#ifndef __STDC__
  602. +#define const
  603. +#endif
  604. +
  605. +/* If svr4 and not gcc */
  606. +#undef SVR4
  607. +#ifdef SVR4
  608. +#define __svr4__ 1
  609. +#endif
  610. diff -rup --new-file baseline/fsf/gawk/config.in amiga/fsf/gawk/config.in
  611. --- baseline/fsf/gawk/config.in    Sun May  1 15:20:10 1994
  612. +++ amiga/fsf/gawk/config.in    Sat Sep 28 00:00:00 1996
  613. @@ -272,7 +272,7 @@
  614.   * this.
  615.   */
  616.  
  617. -/* #define DEFPATH    ".:/usr/lib/awk:/usr/local/lib/awk" */
  618. +/* #define DEFPATH    ".:/local/lib/awk:/ade/lib/awk" */
  619.  /* #define ENVSEP    ':' */
  620.  
  621.  /*
  622. diff -rup --new-file baseline/fsf/gawk/configure amiga/fsf/gawk/configure
  623. --- baseline/fsf/gawk/configure    Tue May 18 09:34:04 1993
  624. +++ amiga/fsf/gawk/configure    Mon Sep 30 22:41:14 1996
  625. @@ -1,36 +1,1363 @@
  626.  #! /bin/sh
  627. +
  628. +# Guess values for system-dependent variables and create Makefiles.
  629. +# Generated automatically using autoconf version 2.10 
  630. +# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
  631.  #
  632. -# configure -- produce a config.h from a known configuration
  633. +# This configure script is free software; the Free Software Foundation
  634. +# gives unlimited permission to copy, distribute and modify it.
  635. +
  636. +# Defaults:
  637. +ac_help=
  638. +ac_default_prefix=/usr/local
  639. +# Any additions from configure.in:
  640. +
  641. +# Initialize some variables set by options.
  642. +# The variables have the same names as the options, with
  643. +# dashes changed to underlines.
  644. +build=NONE
  645. +cache_file=./config.cache
  646. +exec_prefix=NONE
  647. +host=NONE
  648. +no_create=
  649. +nonopt=NONE
  650. +no_recursion=
  651. +prefix=NONE
  652. +program_prefix=NONE
  653. +program_suffix=NONE
  654. +program_transform_name=s,x,x,
  655. +silent=
  656. +site=
  657. +srcdir=
  658. +target=NONE
  659. +verbose=
  660. +x_includes=NONE
  661. +x_libraries=NONE
  662. +bindir='${exec_prefix}/bin'
  663. +sbindir='${exec_prefix}/sbin'
  664. +libexecdir='${exec_prefix}/libexec'
  665. +datadir='${prefix}/share'
  666. +sysconfdir='${prefix}/etc'
  667. +sharedstatedir='${prefix}/com'
  668. +localstatedir='${prefix}/var'
  669. +libdir='${exec_prefix}/lib'
  670. +includedir='${prefix}/include'
  671. +oldincludedir='/usr/include'
  672. +infodir='${prefix}/info'
  673. +guidedir='${prefix}/guide'
  674. +psdir='${prefix}/ps'
  675. +dvidir='${prefix}/dvi'
  676. +mandir='${prefix}/man'
  677. +
  678. +# Initialize some other variables.
  679. +subdirs=
  680. +MFLAGS= MAKEFLAGS=
  681. +
  682. +ac_prev=
  683. +for ac_option
  684. +do
  685. +
  686. +  # If the previous option needs an argument, assign it.
  687. +  if test -n "$ac_prev"; then
  688. +    eval "$ac_prev=\$ac_option"
  689. +    ac_prev=
  690. +    continue
  691. +  fi
  692. +
  693. +  case "$ac_option" in
  694. +  -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  695. +  *) ac_optarg= ;;
  696. +  esac
  697. +
  698. +  # Accept the important Cygnus configure options, so we can diagnose typos.
  699. +
  700. +  case "$ac_option" in
  701. +
  702. +  -bindir | --bindir | --bindi | --bind | --bin | --bi)
  703. +    ac_prev=bindir ;;
  704. +  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
  705. +    bindir="$ac_optarg" ;;
  706. +
  707. +  -build | --build | --buil | --bui | --bu)
  708. +    ac_prev=build ;;
  709. +  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
  710. +    build="$ac_optarg" ;;
  711. +
  712. +  -cache-file | --cache-file | --cache-fil | --cache-fi \
  713. +  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
  714. +    ac_prev=cache_file ;;
  715. +  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
  716. +  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
  717. +    cache_file="$ac_optarg" ;;
  718. +
  719. +  -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
  720. +    ac_prev=datadir ;;
  721. +  -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
  722. +  | --da=*)
  723. +    datadir="$ac_optarg" ;;
  724. +
  725. +  -disable-* | --disable-*)
  726. +    ac_feature=`echo $ac_option|sed -e 's/-*disable-//'`
  727. +    # Reject names that are not valid shell variable names.
  728. +    if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then
  729. +      { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
  730. +    fi
  731. +    ac_feature=`echo $ac_feature| sed 's/-/_/g'`
  732. +    eval "enable_${ac_feature}=no" ;;
  733. +
  734. +  -enable-* | --enable-*)
  735. +    ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'`
  736. +    # Reject names that are not valid shell variable names.
  737. +    if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then
  738. +      { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
  739. +    fi
  740. +    ac_feature=`echo $ac_feature| sed 's/-/_/g'`
  741. +    case "$ac_option" in
  742. +      *=*) ;;
  743. +      *) ac_optarg=yes ;;
  744. +    esac
  745. +    eval "enable_${ac_feature}='$ac_optarg'" ;;
  746. +
  747. +  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
  748. +  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
  749. +  | --exec | --exe | --ex)
  750. +    ac_prev=exec_prefix ;;
  751. +  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
  752. +  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
  753. +  | --exec=* | --exe=* | --ex=*)
  754. +    exec_prefix="$ac_optarg" ;;
  755. +
  756. +  -gas | --gas | --ga | --g)
  757. +    # Obsolete; use --with-gas.
  758. +    with_gas=yes ;;
  759. +
  760. +  -help | --help | --hel | --he)
  761. +    # Omit some internal or obsolete options to make the list less imposing.
  762. +    # This message is too long to be a string in the A/UX 3.1 sh.
  763. +    cat << EOF
  764. +Usage: configure [options] [host]
  765. +Options: [defaults in brackets after descriptions]
  766. +Configuration:
  767. +  --cache-file=FILE       cache test results in FILE
  768. +  --help                  print this message
  769. +  --no-create             do not create output files
  770. +  --quiet, --silent       do not print \`checking...' messages
  771. +  --version               print the version of autoconf that created configure
  772. +Directory and file names:
  773. +  --prefix=PREFIX         install architecture-independent files in PREFIX
  774. +                          [$ac_default_prefix]
  775. +  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
  776. +                          [same as prefix]
  777. +  --bindir=DIR            user executables in DIR [EPREFIX/bin]
  778. +  --sbindir=DIR           system admin executables in DIR [EPREFIX/sbin]
  779. +  --libexecdir=DIR        program executables in DIR [EPREFIX/libexec]
  780. +  --datadir=DIR           read-only architecture-independent data in DIR
  781. +                          [PREFIX/share]
  782. +  --sysconfdir=DIR        read-only single-machine data in DIR [PREFIX/etc]
  783. +  --sharedstatedir=DIR    modifiable architecture-independent data in DIR
  784. +                          [PREFIX/com]
  785. +  --localstatedir=DIR     modifiable single-machine data in DIR [PREFIX/var]
  786. +  --libdir=DIR            object code libraries in DIR [EPREFIX/lib]
  787. +  --includedir=DIR        C header files in DIR [PREFIX/include]
  788. +  --oldincludedir=DIR     C header files for non-gcc in DIR [/usr/include]
  789. +  --infodir=DIR           info documentation in DIR [PREFIX/info]
  790. +  --guidedir=DIR          Amigaguide documentation in DIR [PREFIX/guide]
  791. +  --psdir=DIR             postscript documentation in DIR [PREFIX/ps]
  792. +  --dvidir=DIR            TeX dvi documentation in DIR [PREFIX/dvi]
  793. +  --mandir=DIR            man documentation in DIR [PREFIX/man]
  794. +  --srcdir=DIR            find the sources in DIR [configure dir or ..]
  795. +  --program-prefix=PREFIX prepend PREFIX to installed program names
  796. +  --program-suffix=SUFFIX append SUFFIX to installed program names
  797. +  --program-transform-name=PROGRAM
  798. +                          run sed PROGRAM on installed program names
  799. +EOF
  800. +    cat << EOF
  801. +Host type:
  802. +  --build=BUILD           configure for building on BUILD [BUILD=HOST]
  803. +  --host=HOST             configure for HOST [guessed]
  804. +  --target=TARGET         configure for TARGET [TARGET=HOST]
  805. +Features and packages:
  806. +  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  807. +  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  808. +  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  809. +  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  810. +  --x-includes=DIR        X include files are in DIR
  811. +  --x-libraries=DIR       X library files are in DIR
  812. +EOF
  813. +    if test -n "$ac_help"; then
  814. +      echo "--enable and --with options recognized:$ac_help"
  815. +    fi
  816. +    exit 0 ;;
  817. +
  818. +  -host | --host | --hos | --ho)
  819. +    ac_prev=host ;;
  820. +  -host=* | --host=* | --hos=* | --ho=*)
  821. +    host="$ac_optarg" ;;
  822. +
  823. +  -includedir | --includedir | --includedi | --included | --include \
  824. +  | --includ | --inclu | --incl | --inc)
  825. +    ac_prev=includedir ;;
  826. +  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
  827. +  | --includ=* | --inclu=* | --incl=* | --inc=*)
  828. +    includedir="$ac_optarg" ;;
  829. +
  830. +  -infodir | --infodir | --infodi | --infod | --info | --inf)
  831. +    ac_prev=infodir ;;
  832. +  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
  833. +    infodir="$ac_optarg" ;;
  834. +
  835. + -guidedir | --guidedir | --guidedi | --guided | --guide | --gui)
  836. +   ac_prev=guidedir ;;
  837. + -guidedir=* | --guidedir=* | --guidedi=* | --guided=* | --guide=* |--gui=*)+    guidedir="$ac_optarg" ;;
  838. +
  839. + -psdir | --psdir | --psdi | --psd | --ps)
  840. +   ac_prev=psdir ;;
  841. + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)+    psdir="$ac_optarg" ;;
  842. +
  843. + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
  844. +   ac_prev=dvidir ;;
  845. + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* |--dv=*)+    dvidir="$ac_optarg" ;;
  846. +
  847. +  -libdir | --libdir | --libdi | --libd)
  848. +    ac_prev=libdir ;;
  849. +  -libdir=* | --libdir=* | --libdi=* | --libd=*)
  850. +    libdir="$ac_optarg" ;;
  851. +
  852. +  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
  853. +  | --libexe | --libex | --libe)
  854. +    ac_prev=libexecdir ;;
  855. +  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
  856. +  | --libexe=* | --libex=* | --libe=*)
  857. +    libexecdir="$ac_optarg" ;;
  858. +
  859. +  -localstatedir | --localstatedir | --localstatedi | --localstated \
  860. +  | --localstate | --localstat | --localsta | --localst \
  861. +  | --locals | --local | --loca | --loc | --lo)
  862. +    ac_prev=localstatedir ;;
  863. +  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
  864. +  | --localstate=* | --localstat=* | --localsta=* | --localst=* \
  865. +  | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
  866. +    localstatedir="$ac_optarg" ;;
  867. +
  868. +  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
  869. +    ac_prev=mandir ;;
  870. +  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
  871. +    mandir="$ac_optarg" ;;
  872. +
  873. +  -nfp | --nfp | --nf)
  874. +    # Obsolete; use --without-fp.
  875. +    with_fp=no ;;
  876. +
  877. +  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
  878. +  | --no-cr | --no-c)
  879. +    no_create=yes ;;
  880. +
  881. +  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
  882. +  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
  883. +    no_recursion=yes ;;
  884. +
  885. +  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
  886. +  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
  887. +  | --oldin | --oldi | --old | --ol | --o)
  888. +    ac_prev=oldincludedir ;;
  889. +  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
  890. +  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
  891. +  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
  892. +    oldincludedir="$ac_optarg" ;;
  893. +
  894. +  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
  895. +    ac_prev=prefix ;;
  896. +  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
  897. +    prefix="$ac_optarg" ;;
  898. +
  899. +  -program-prefix | --program-prefix | --program-prefi | --program-pref \
  900. +  | --program-pre | --program-pr | --program-p)
  901. +    ac_prev=program_prefix ;;
  902. +  -program-prefix=* | --program-prefix=* | --program-prefi=* \
  903. +  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
  904. +    program_prefix="$ac_optarg" ;;
  905. +
  906. +  -program-suffix | --program-suffix | --program-suffi | --program-suff \
  907. +  | --program-suf | --program-su | --program-s)
  908. +    ac_prev=program_suffix ;;
  909. +  -program-suffix=* | --program-suffix=* | --program-suffi=* \
  910. +  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
  911. +    program_suffix="$ac_optarg" ;;
  912. +
  913. +  -program-transform-name | --program-transform-name \
  914. +  | --program-transform-nam | --program-transform-na \
  915. +  | --program-transform-n | --program-transform- \
  916. +  | --program-transform | --program-transfor \
  917. +  | --program-transfo | --program-transf \
  918. +  | --program-trans | --program-tran \
  919. +  | --progr-tra | --program-tr | --program-t)
  920. +    ac_prev=program_transform_name ;;
  921. +  -program-transform-name=* | --program-transform-name=* \
  922. +  | --program-transform-nam=* | --program-transform-na=* \
  923. +  | --program-transform-n=* | --program-transform-=* \
  924. +  | --program-transform=* | --program-transfor=* \
  925. +  | --program-transfo=* | --program-transf=* \
  926. +  | --program-trans=* | --program-tran=* \
  927. +  | --progr-tra=* | --program-tr=* | --program-t=*)
  928. +    program_transform_name="$ac_optarg" ;;
  929. +
  930. +  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
  931. +  | -silent | --silent | --silen | --sile | --sil)
  932. +    silent=yes ;;
  933. +
  934. +  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
  935. +    ac_prev=sbindir ;;
  936. +  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
  937. +  | --sbi=* | --sb=*)
  938. +    sbindir="$ac_optarg" ;;
  939. +
  940. +  -sharedstatedir | --sharedstatedir | --sharedstatedi \
  941. +  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
  942. +  | --sharedst | --shareds | --shared | --share | --shar \
  943. +  | --sha | --sh)
  944. +    ac_prev=sharedstatedir ;;
  945. +  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
  946. +  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
  947. +  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
  948. +  | --sha=* | --sh=*)
  949. +    sharedstatedir="$ac_optarg" ;;
  950. +
  951. +  -site | --site | --sit)
  952. +    ac_prev=site ;;
  953. +  -site=* | --site=* | --sit=*)
  954. +    site="$ac_optarg" ;;
  955. +
  956. +  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
  957. +    ac_prev=srcdir ;;
  958. +  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
  959. +    srcdir="$ac_optarg" ;;
  960. +
  961. +  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
  962. +  | --syscon | --sysco | --sysc | --sys | --sy)
  963. +    ac_prev=sysconfdir ;;
  964. +  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
  965. +  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
  966. +    sysconfdir="$ac_optarg" ;;
  967. +
  968. +  -target | --target | --targe | --targ | --tar | --ta | --t)
  969. +    ac_prev=target ;;
  970. +  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
  971. +    target="$ac_optarg" ;;
  972. +
  973. +  -v | -verbose | --verbose | --verbos | --verbo | --verb)
  974. +    verbose=yes ;;
  975. +
  976. +  -version | --version | --versio | --versi | --vers)
  977. +    echo "configure generated by autoconf version 2.10"
  978. +    exit 0 ;;
  979. +
  980. +  -with-* | --with-*)
  981. +    ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'`
  982. +    # Reject names that are not valid shell variable names.
  983. +    if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then
  984. +      { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
  985. +    fi
  986. +    ac_package=`echo $ac_package| sed 's/-/_/g'`
  987. +    case "$ac_option" in
  988. +      *=*) ;;
  989. +      *) ac_optarg=yes ;;
  990. +    esac
  991. +    eval "with_${ac_package}='$ac_optarg'" ;;
  992. +
  993. +  -without-* | --without-*)
  994. +    ac_package=`echo $ac_option|sed -e 's/-*without-//'`
  995. +    # Reject names that are not valid shell variable names.
  996. +    if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then
  997. +      { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
  998. +    fi
  999. +    ac_package=`echo $ac_package| sed 's/-/_/g'`
  1000. +    eval "with_${ac_package}=no" ;;
  1001. +
  1002. +  --x)
  1003. +    # Obsolete; use --with-x.
  1004. +    with_x=yes ;;
  1005. +
  1006. +  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
  1007. +  | --x-incl | --x-inc | --x-in | --x-i)
  1008. +    ac_prev=x_includes ;;
  1009. +  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
  1010. +  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
  1011. +    x_includes="$ac_optarg" ;;
  1012. +
  1013. +  -x-libraries | --x-libraries | --x-librarie | --x-librari \
  1014. +  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
  1015. +    ac_prev=x_libraries ;;
  1016. +  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
  1017. +  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
  1018. +    x_libraries="$ac_optarg" ;;
  1019. +
  1020. +  -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; }
  1021. +    ;;
  1022. +
  1023. +  *)
  1024. +    if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then
  1025. +      echo "configure: warning: $ac_option: invalid host type" 1>&2
  1026. +    fi
  1027. +    if test "x$nonopt" != xNONE; then
  1028. +      { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; }
  1029. +    fi
  1030. +    nonopt="$ac_option"
  1031. +    ;;
  1032. +
  1033. +  esac
  1034. +done
  1035. +
  1036. +if test -n "$ac_prev"; then
  1037. +  { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; }
  1038. +fi
  1039. +
  1040. +trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
  1041. +
  1042. +# File descriptor usage:
  1043. +# 0 standard input
  1044. +# 1 file creation
  1045. +# 2 errors and warnings
  1046. +# 3 some systems may open it to /dev/tty
  1047. +# 4 used on the Kubota Titan
  1048. +# 6 checking for... messages and results
  1049. +# 5 compiler messages saved in config.log
  1050. +if test "$silent" = yes; then
  1051. +  exec 6>/dev/null
  1052. +else
  1053. +  exec 6>&1
  1054. +fi
  1055. +exec 5>./config.log
  1056. +
  1057. +echo "\
  1058. +This file contains any messages produced by compilers while
  1059. +running configure, to aid debugging if configure makes a mistake.
  1060. +" 1>&5
  1061.  
  1062. -case "$#" in
  1063. -1)    ;;
  1064. -*)    echo "Usage:  $0 system_type" >&2
  1065. -    echo "Known systems:  `cd config; echo ;ls -C`" >&2
  1066. -    exit 2
  1067. -    ;;
  1068. -esac
  1069. -
  1070. -if [ -f config/$1 ]; then
  1071. -    sh ./mungeconf config/$1 config.in >config.h
  1072. -
  1073. -    # echo #echo lines to stdout
  1074. -    sed -n '/^#echo /s///p' config/$1
  1075. -
  1076. -    case "$1" in
  1077. -    bsd44)    ln -s Makefile.bsd44 Makefile ; exit 0 ;;
  1078. -    esac
  1079. -
  1080. -    sed -n '/^MAKE_.*/s//s,^##&## ,,/p' config/$1 >sedscr
  1081. -    if [ -s sedscr ]
  1082. -    then
  1083. -        sed -f sedscr Makefile.in >Makefile
  1084. -    else
  1085. -        cp Makefile.in Makefile
  1086. +# Strip out --no-create and --no-recursion so they do not pile up.
  1087. +# Also quote any args containing shell metacharacters.
  1088. +ac_configure_args=
  1089. +for ac_arg
  1090. +do
  1091. +  case "$ac_arg" in
  1092. +  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
  1093. +  | --no-cr | --no-c) ;;
  1094. +  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
  1095. +  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;;
  1096. +  *" "*|*"    "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*)
  1097. +  ac_configure_args="$ac_configure_args '$ac_arg'" ;;
  1098. +  *) ac_configure_args="$ac_configure_args $ac_arg" ;;
  1099. +  esac
  1100. +done
  1101. +
  1102. +# NLS nuisances.
  1103. +# Only set LANG and LC_ALL to C if already set.
  1104. +# These must not be set unconditionally because not all systems understand
  1105. +# e.g. LANG=C (notably SCO).
  1106. +if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
  1107. +if test "${LANG+set}"   = set; then LANG=C;   export LANG;   fi
  1108. +
  1109. +# confdefs.h avoids OS command line length limits that DEFS can exceed.
  1110. +rm -rf conftest* confdefs.h
  1111. +# AIX cpp loses on an empty file, so make sure it contains at least a newline.
  1112. +echo > confdefs.h
  1113. +
  1114. +# A filename unique to this package, relative to the directory that
  1115. +# configure is in, which we can look for to find out if srcdir is correct.
  1116. +ac_unique_file=awk.y
  1117. +
  1118. +# Find the source files, if location was not specified.
  1119. +if test -z "$srcdir"; then
  1120. +  ac_srcdir_defaulted=yes
  1121. +  # Try the directory containing this script, then its parent.
  1122. +  ac_prog=$0
  1123. +  ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'`
  1124. +  test "x$ac_confdir" = "x$ac_prog" && ac_confdir=.
  1125. +  srcdir=$ac_confdir
  1126. +  if test ! -r $srcdir/$ac_unique_file; then
  1127. +    srcdir=..
  1128. +  fi
  1129. +else
  1130. +  ac_srcdir_defaulted=no
  1131. +fi
  1132. +if test ! -r $srcdir/$ac_unique_file; then
  1133. +  if test "$ac_srcdir_defaulted" = yes; then
  1134. +    { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; }
  1135. +  else
  1136. +    { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; }
  1137. +  fi
  1138. +fi
  1139. +srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'`
  1140. +
  1141. +# Prefer explicitly selected file to automatically selected ones.
  1142. +if test -z "$CONFIG_SITE"; then
  1143. +  if test "x$prefix" != xNONE; then
  1144. +    CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
  1145. +  else
  1146. +    CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
  1147. +  fi
  1148. +fi
  1149. +for ac_site_file in $CONFIG_SITE; do
  1150. +  if test -r "$ac_site_file"; then
  1151. +    echo "loading site script $ac_site_file"
  1152. +    . "$ac_site_file"
  1153. +  fi
  1154. +done
  1155. +
  1156. +if test -r "$cache_file"; then
  1157. +  echo "loading cache $cache_file"
  1158. +  . $cache_file
  1159. +else
  1160. +  echo "creating cache $cache_file"
  1161. +  > $cache_file
  1162. +fi
  1163. +
  1164. +ac_ext=c
  1165. +# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
  1166. +ac_cpp='$CPP $CPPFLAGS'
  1167. +ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
  1168. +ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
  1169. +
  1170. +if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
  1171. +  # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
  1172. +  if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
  1173. +    ac_n= ac_c='
  1174. +' ac_t='    '
  1175. +  else
  1176. +    ac_n=-n ac_c= ac_t=
  1177. +  fi
  1178. +else
  1179. +  ac_n= ac_c='\c' ac_t=
  1180. +fi
  1181. +
  1182. +
  1183. +
  1184. +
  1185. +# We want these before the checks, so the checks can modify their values.
  1186. +test -z "$CFLAGS" && CFLAGS= auto_cflags=1
  1187. +test -z "$LDFLAGS" && LDFLAGS=
  1188. +
  1189. +# Extract the first word of "gcc", so it can be a program name with args.
  1190. +set dummy gcc; ac_word=$2
  1191. +echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
  1192. +if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
  1193. +  echo $ac_n "(cached) $ac_c" 1>&6
  1194. +else
  1195. +  if test -n "$CC"; then
  1196. +  ac_cv_prog_CC="$CC" # Let the user override the test.
  1197. +else
  1198. +  IFS="${IFS=     }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  1199. +  for ac_dir in $PATH; do
  1200. +    test -z "$ac_dir" && ac_dir=.
  1201. +    if test -f $ac_dir/$ac_word; then
  1202. +      ac_cv_prog_CC="gcc"
  1203. +      break
  1204. +    fi
  1205. +  done
  1206. +  IFS="$ac_save_ifs"
  1207. +fi
  1208. +fi
  1209. +CC="$ac_cv_prog_CC"
  1210. +if test -n "$CC"; then
  1211. +  echo "$ac_t""$CC" 1>&6
  1212. +else
  1213. +  echo "$ac_t""no" 1>&6
  1214. +fi
  1215. +
  1216. +if test -z "$CC"; then
  1217. +  # Extract the first word of "cc", so it can be a program name with args.
  1218. +set dummy cc; ac_word=$2
  1219. +echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
  1220. +if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
  1221. +  echo $ac_n "(cached) $ac_c" 1>&6
  1222. +else
  1223. +  if test -n "$CC"; then
  1224. +  ac_cv_prog_CC="$CC" # Let the user override the test.
  1225. +else
  1226. +  IFS="${IFS=     }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  1227. +  ac_prog_rejected=no
  1228. +  for ac_dir in $PATH; do
  1229. +    test -z "$ac_dir" && ac_dir=.
  1230. +    if test -f $ac_dir/$ac_word; then
  1231. +      if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then
  1232. +        ac_prog_rejected=yes
  1233. +    continue
  1234. +      fi
  1235. +      ac_cv_prog_CC="cc"
  1236. +      break
  1237. +    fi
  1238. +  done
  1239. +  IFS="$ac_save_ifs"
  1240. +if test $ac_prog_rejected = yes; then
  1241. +  # We found a bogon in the path, so make sure we never use it.
  1242. +  set dummy $ac_cv_prog_CC
  1243. +  shift
  1244. +  if test $# -gt 0; then
  1245. +    # We chose a different compiler from the bogus one.
  1246. +    # However, it has the same basename, so the bogon will be chosen
  1247. +    # first if we set CC to just the basename; use the full file name.
  1248. +    shift
  1249. +    set dummy "$ac_dir/$ac_word" "$@"
  1250. +    shift
  1251. +    ac_cv_prog_CC="$@"
  1252. +  fi
  1253. +fi
  1254. +fi
  1255. +fi
  1256. +CC="$ac_cv_prog_CC"
  1257. +if test -n "$CC"; then
  1258. +  echo "$ac_t""$CC" 1>&6
  1259. +else
  1260. +  echo "$ac_t""no" 1>&6
  1261. +fi
  1262. +
  1263. +  test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; }
  1264. +fi
  1265. +
  1266. +echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
  1267. +if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
  1268. +  echo $ac_n "(cached) $ac_c" 1>&6
  1269. +else
  1270. +  cat > conftest.c <<EOF
  1271. +#ifdef __GNUC__
  1272. +  yes;
  1273. +#endif
  1274. +EOF
  1275. +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:626: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
  1276. +  ac_cv_prog_gcc=yes
  1277. +else
  1278. +  ac_cv_prog_gcc=no
  1279. +fi
  1280. +fi
  1281. +
  1282. +echo "$ac_t""$ac_cv_prog_gcc" 1>&6
  1283. +if test $ac_cv_prog_gcc = yes; then
  1284. +  GCC=yes
  1285. +  if test "${CFLAGS+set}" != set; then
  1286. +    echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
  1287. +if eval "test \"`echo '$''{'ac_cv_prog_gcc_g'+set}'`\" = set"; then
  1288. +  echo $ac_n "(cached) $ac_c" 1>&6
  1289. +else
  1290. +  echo 'void f(){}' > conftest.c
  1291. +if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then
  1292. +  ac_cv_prog_gcc_g=yes
  1293. +else
  1294. +  ac_cv_prog_gcc_g=no
  1295. +fi
  1296. +rm -f conftest*
  1297. +
  1298. +fi
  1299. +
  1300. +echo "$ac_t""$ac_cv_prog_gcc_g" 1>&6
  1301. +    if test $ac_cv_prog_gcc_g = yes; then
  1302. +      CFLAGS="-g -O2"
  1303. +    else
  1304. +      CFLAGS="-O2"
  1305. +    fi
  1306. +  fi
  1307. +else
  1308. +  GCC=
  1309. +  test "${CFLAGS+set}" = set || CFLAGS="-g"
  1310. +fi
  1311. +
  1312. +
  1313. +# If we're using gcc and the user hasn't specified CFLAGS, add -O to CFLAGS.
  1314. +test -n "$GCC" && test -n "$auto_cflags" && CFLAGS="$CFLAGS -O2"
  1315. +
  1316. +
  1317. +echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
  1318. +# On Suns, sometimes $CPP names a directory.
  1319. +if test -n "$CPP" && test -d "$CPP"; then
  1320. +  CPP=
  1321. +fi
  1322. +if test -z "$CPP"; then
  1323. +if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then
  1324. +  echo $ac_n "(cached) $ac_c" 1>&6
  1325. +else
  1326. +    # This must be in double quotes, not single quotes, because CPP may get
  1327. +  # substituted into the Makefile and "${CC-cc}" will confuse make.
  1328. +  CPP="${CC-cc} -E"
  1329. +  # On the NeXT, cc -E runs the code through the compiler's parser,
  1330. +  # not just through cpp.
  1331. +  cat > conftest.$ac_ext <<EOF
  1332. +#line 683 "configure"
  1333. +#include "confdefs.h"
  1334. +#include <assert.h>
  1335. +Syntax Error
  1336. +EOF
  1337. +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
  1338. +{ (eval echo configure:689: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
  1339. +ac_err=`grep -v '^ *+' conftest.out`
  1340. +if test -z "$ac_err"; then
  1341. +  :
  1342. +else
  1343. +  echo "$ac_err" >&5
  1344. +  rm -rf conftest*
  1345. +  CPP="${CC-cc} -E -traditional-cpp"
  1346. +  cat > conftest.$ac_ext <<EOF
  1347. +#line 698 "configure"
  1348. +#include "confdefs.h"
  1349. +#include <assert.h>
  1350. +Syntax Error
  1351. +EOF
  1352. +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
  1353. +{ (eval echo configure:704: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
  1354. +ac_err=`grep -v '^ *+' conftest.out`
  1355. +if test -z "$ac_err"; then
  1356. +  :
  1357. +else
  1358. +  echo "$ac_err" >&5
  1359. +  rm -rf conftest*
  1360. +  CPP=/lib/cpp
  1361. +fi
  1362. +rm -f conftest*
  1363. +fi
  1364. +rm -f conftest*
  1365. +  ac_cv_prog_CPP="$CPP"
  1366. +fi
  1367. +  CPP="$ac_cv_prog_CPP"
  1368. +else
  1369. +  ac_cv_prog_CPP="$CPP"
  1370. +fi
  1371. +echo "$ac_t""$CPP" 1>&6
  1372. +
  1373. +if test $ac_cv_prog_gcc = yes; then
  1374. +    echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
  1375. +if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
  1376. +  echo $ac_n "(cached) $ac_c" 1>&6
  1377. +else
  1378. +    ac_pattern="Autoconf.*'x'"
  1379. +  cat > conftest.$ac_ext <<EOF
  1380. +#line 731 "configure"
  1381. +#include "confdefs.h"
  1382. +#include <sgtty.h>
  1383. +Autoconf TIOCGETP
  1384. +EOF
  1385. +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  1386. +  egrep "$ac_pattern" >/dev/null 2>&1; then
  1387. +  rm -rf conftest*
  1388. +  ac_cv_prog_gcc_traditional=yes
  1389. +else
  1390. +  rm -rf conftest*
  1391. +  ac_cv_prog_gcc_traditional=no
  1392. +fi
  1393. +rm -f conftest*
  1394. +
  1395. +
  1396. +  if test $ac_cv_prog_gcc_traditional = no; then
  1397. +    cat > conftest.$ac_ext <<EOF
  1398. +#line 749 "configure"
  1399. +#include "confdefs.h"
  1400. +#include <termio.h>
  1401. +Autoconf TCGETA
  1402. +EOF
  1403. +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  1404. +  egrep "$ac_pattern" >/dev/null 2>&1; then
  1405. +  rm -rf conftest*
  1406. +  ac_cv_prog_gcc_traditional=yes
  1407. +fi
  1408. +rm -f conftest*
  1409. +
  1410. +  fi
  1411. +fi
  1412. +
  1413. +echo "$ac_t""$ac_cv_prog_gcc_traditional" 1>&6
  1414. +  if test $ac_cv_prog_gcc_traditional = yes; then
  1415. +    CC="$CC -traditional"
  1416. +  fi
  1417. +fi
  1418. +
  1419. +ac_aux_dir=
  1420. +for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
  1421. +  if test -f $ac_dir/install-sh; then
  1422. +    ac_aux_dir=$ac_dir
  1423. +    ac_install_sh="$ac_aux_dir/install-sh -c"
  1424. +    break
  1425. +  elif test -f $ac_dir/install.sh; then
  1426. +    ac_aux_dir=$ac_dir
  1427. +    ac_install_sh="$ac_aux_dir/install.sh -c"
  1428. +    break
  1429. +  fi
  1430. +done
  1431. +if test -z "$ac_aux_dir"; then
  1432. +  { echo "configure: error: can not find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." 1>&2; exit 1; }
  1433. +fi
  1434. +ac_config_guess=$ac_aux_dir/config.guess
  1435. +ac_config_sub=$ac_aux_dir/config.sub
  1436. +ac_configure=$ac_aux_dir/configure # This should be Cygnus configure.
  1437. +
  1438. +# Find a good install program.  We prefer a C program (faster),
  1439. +# so one script is as good as another.  But avoid the broken or
  1440. +# incompatible versions:
  1441. +# SysV /etc/install, /usr/sbin/install
  1442. +# SunOS /usr/etc/install
  1443. +# IRIX /sbin/install
  1444. +# AIX /bin/install
  1445. +# AmigaOS /c/install
  1446. +# AFS /usr/afsws/bin/install, which mishandles nonexistent args
  1447. +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
  1448. +# ./install, which can be erroneously created by make from ./install.sh.
  1449. +echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
  1450. +if test -z "$INSTALL"; then
  1451. +if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
  1452. +  echo $ac_n "(cached) $ac_c" 1>&6
  1453. +else
  1454. +    IFS="${IFS=     }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  1455. +  for ac_dir in $PATH; do
  1456. +    # Account for people who put trailing slashes in PATH elements.
  1457. +    case "$ac_dir/" in
  1458. +    /|./|.//|/etc/*|/c/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;;
  1459. +    *)
  1460. +      # OSF1 and SCO ODT 3.0 have their own names for install.
  1461. +      for ac_prog in ginstall installbsd scoinst install; do
  1462. +        if test -f $ac_dir/$ac_prog; then
  1463. +      if test $ac_prog = install &&
  1464. +            grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
  1465. +        # AIX install.  It has an incompatible calling convention.
  1466. +        # OSF/1 installbsd also uses dspmsg, but is usable.
  1467. +        :
  1468. +      else
  1469. +        ac_cv_path_install="$ac_dir/$ac_prog -c"
  1470. +        break 2
  1471. +      fi
  1472.      fi
  1473. -    rm -f sedscr
  1474. +      done
  1475. +      ;;
  1476. +    esac
  1477. +  done
  1478. +  IFS="$ac_save_ifs"
  1479. +
  1480. +fi
  1481. +  if test "${ac_cv_path_install+set}" = set; then
  1482. +    INSTALL="$ac_cv_path_install"
  1483. +  else
  1484. +    # As a last resort, use the slow shell script.  We don't cache a
  1485. +    # path for INSTALL within a source directory, because that will
  1486. +    # break other packages using the cache if that directory is
  1487. +    # removed, or if the path is relative.
  1488. +    INSTALL="$ac_install_sh"
  1489. +  fi
  1490. +fi
  1491. +echo "$ac_t""$INSTALL" 1>&6
  1492. +
  1493. +# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
  1494. +# It thinks the first close brace ends the variable substitution.
  1495. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
  1496. +
  1497. +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
  1498. +
  1499. +for ac_prog in 'bison -y' byacc
  1500. +do
  1501. +# Extract the first word of "$ac_prog", so it can be a program name with args.
  1502. +set dummy $ac_prog; ac_word=$2
  1503. +echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
  1504. +if eval "test \"`echo '$''{'ac_cv_prog_YACC'+set}'`\" = set"; then
  1505. +  echo $ac_n "(cached) $ac_c" 1>&6
  1506. +else
  1507. +  if test -n "$YACC"; then
  1508. +  ac_cv_prog_YACC="$YACC" # Let the user override the test.
  1509. +else
  1510. +  IFS="${IFS=     }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  1511. +  for ac_dir in $PATH; do
  1512. +    test -z "$ac_dir" && ac_dir=.
  1513. +    if test -f $ac_dir/$ac_word; then
  1514. +      ac_cv_prog_YACC="$ac_prog"
  1515. +      break
  1516. +    fi
  1517. +  done
  1518. +  IFS="$ac_save_ifs"
  1519. +fi
  1520. +fi
  1521. +YACC="$ac_cv_prog_YACC"
  1522. +if test -n "$YACC"; then
  1523. +  echo "$ac_t""$YACC" 1>&6
  1524. +else
  1525. +  echo "$ac_t""no" 1>&6
  1526. +fi
  1527. +
  1528. +test -n "$YACC" && break
  1529. +done
  1530. +test -n "$YACC" || YACC="yacc"
  1531. +
  1532. +echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6
  1533. +if eval "test \"`echo '$''{'ac_cv_type_signal'+set}'`\" = set"; then
  1534. +  echo $ac_n "(cached) $ac_c" 1>&6
  1535. +else
  1536. +  cat > conftest.$ac_ext <<EOF
  1537. +#line 887 "configure"
  1538. +#include "confdefs.h"
  1539. +#include <sys/types.h>
  1540. +#include <signal.h>
  1541. +#ifdef signal
  1542. +#undef signal
  1543. +#endif
  1544. +#ifdef __cplusplus
  1545. +extern "C" void (*signal (int, void (*)(int)))(int);
  1546. +#else
  1547. +void (*signal ()) ();
  1548. +#endif
  1549. +
  1550. +int main() { return 0; }
  1551. +int t() {
  1552. +int i;
  1553. +; return 0; }
  1554. +EOF
  1555. +if { (eval echo configure:905: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
  1556. +  rm -rf conftest*
  1557. +  ac_cv_type_signal=void
  1558. +else
  1559. +  rm -rf conftest*
  1560. +  ac_cv_type_signal=int
  1561. +fi
  1562. +rm -f conftest*
  1563. +
  1564. +fi
  1565. +
  1566. +echo "$ac_t""$ac_cv_type_signal" 1>&6
  1567. +cat >> confdefs.h <<EOF
  1568. +#define RETSIGTYPE $ac_cv_type_signal
  1569. +EOF
  1570. +
  1571. +
  1572. +# If we cannot run a trivial program, we must be cross compiling.
  1573. +echo $ac_n "checking whether cross-compiling""... $ac_c" 1>&6
  1574. +if eval "test \"`echo '$''{'ac_cv_c_cross'+set}'`\" = set"; then
  1575. +  echo $ac_n "(cached) $ac_c" 1>&6
  1576. +else
  1577. +  if test "$cross_compiling" = yes; then
  1578. +  ac_cv_c_cross=yes
  1579. +else
  1580. +cat > conftest.$ac_ext <<EOF
  1581. +#line 931 "configure"
  1582. +#include "confdefs.h"
  1583. +main(){return(0);}
  1584. +EOF
  1585. +{ (eval echo configure:935: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
  1586. +if test -s conftest && (./conftest; exit) 2>/dev/null; then
  1587. +  ac_cv_c_cross=no
  1588. +else
  1589. +  ac_cv_c_cross=yes
  1590. +fi
  1591. +fi
  1592. +rm -fr conftest*
  1593. +fi
  1594. +
  1595. +echo "$ac_t""$ac_cv_c_cross" 1>&6
  1596. +cross_compiling=$ac_cv_c_cross
  1597. +
  1598. +echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
  1599. +if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
  1600. +  echo $ac_n "(cached) $ac_c" 1>&6
  1601. +else
  1602. +  cat > conftest.$ac_ext <<EOF
  1603. +#line 953 "configure"
  1604. +#include "confdefs.h"
  1605. +#include <stdlib.h>
  1606. +#include <stdarg.h>
  1607. +#include <string.h>
  1608. +#include <float.h>
  1609. +EOF
  1610. +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
  1611. +{ (eval echo configure:961: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
  1612. +ac_err=`grep -v '^ *+' conftest.out`
  1613. +if test -z "$ac_err"; then
  1614. +  rm -rf conftest*
  1615. +  ac_cv_header_stdc=yes
  1616. +else
  1617. +  echo "$ac_err" >&5
  1618. +  rm -rf conftest*
  1619. +  ac_cv_header_stdc=no
  1620. +fi
  1621. +rm -f conftest*
  1622. +
  1623. +if test $ac_cv_header_stdc = yes; then
  1624. +  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
  1625. +cat > conftest.$ac_ext <<EOF
  1626. +#line 976 "configure"
  1627. +#include "confdefs.h"
  1628. +#include <string.h>
  1629. +EOF
  1630. +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  1631. +  egrep "memchr" >/dev/null 2>&1; then
  1632. +  :
  1633. +else
  1634. +  rm -rf conftest*
  1635. +  ac_cv_header_stdc=no
  1636. +fi
  1637. +rm -f conftest*
  1638. +
  1639. +fi
  1640. +
  1641. +if test $ac_cv_header_stdc = yes; then
  1642. +  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
  1643. +cat > conftest.$ac_ext <<EOF
  1644. +#line 994 "configure"
  1645. +#include "confdefs.h"
  1646. +#include <stdlib.h>
  1647. +EOF
  1648. +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  1649. +  egrep "free" >/dev/null 2>&1; then
  1650. +  :
  1651. +else
  1652. +  rm -rf conftest*
  1653. +  ac_cv_header_stdc=no
  1654. +fi
  1655. +rm -f conftest*
  1656. +
  1657. +fi
  1658. +
  1659. +if test $ac_cv_header_stdc = yes; then
  1660. +  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
  1661. +if test "$cross_compiling" = yes; then
  1662. +  :
  1663. +else
  1664. +cat > conftest.$ac_ext <<EOF
  1665. +#line 1015 "configure"
  1666. +#include "confdefs.h"
  1667. +#include <ctype.h>
  1668. +#define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
  1669. +#define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
  1670. +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
  1671. +int main () { int i; for (i = 0; i < 256; i++)
  1672. +if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
  1673. +exit (0); }
  1674. +
  1675. +EOF
  1676. +{ (eval echo configure:1026: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
  1677. +if test -s conftest && (./conftest; exit) 2>/dev/null; then
  1678. +  :
  1679. +else
  1680. +  ac_cv_header_stdc=no
  1681. +fi
  1682. +fi
  1683. +rm -fr conftest*
  1684. +fi
  1685. +fi
  1686. +
  1687. +echo "$ac_t""$ac_cv_header_stdc" 1>&6
  1688. +if test $ac_cv_header_stdc = yes; then
  1689. +  cat >> confdefs.h <<\EOF
  1690. +#define STDC_HEADERS 1
  1691. +EOF
  1692. +
  1693. +fi
  1694. +
  1695. +
  1696. +echo "checking for _setjmp declaration in <setjmp.h>" 1>&6
  1697. +cat > conftest.$ac_ext <<EOF
  1698. +#line 1048 "configure"
  1699. +#include "confdefs.h"
  1700. +#include <setjmp.h>
  1701. +int main() { t(); return 0; }
  1702. +int t() {
  1703. +jmp_buf buf; _setjmp (buf)
  1704. +; return 0; }
  1705. +EOF
  1706. +if { (eval echo configure:1056: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
  1707. +  rm -rf conftest*
  1708. +  cat >> confdefs.h <<\EOF
  1709. +#define HAVE_UNDERSCORE_SETJMP 1
  1710. +EOF
  1711. +
  1712. +fi
  1713. +rm -f conftest*
  1714. +
  1715. +
  1716. +trap '' 1 2 15
  1717. +cat > confcache <<\EOF
  1718. +# This file is a shell script that caches the results of configure
  1719. +# tests run on this system so they can be shared between configure
  1720. +# scripts and configure runs.  It is not useful on other systems.
  1721. +# If it contains results you don't want to keep, you may remove or edit it.
  1722. +#
  1723. +# By default, configure uses ./config.cache as the cache file,
  1724. +# creating it if it does not exist already.  You can give configure
  1725. +# the --cache-file=FILE option to use a different cache file; that is
  1726. +# what configure does when it calls configure scripts in
  1727. +# subdirectories, so they share the cache.
  1728. +# Giving --cache-file=/dev/null disables caching, for debugging configure.
  1729. +# config.status only pays attention to the cache file if you give it the
  1730. +# --recheck option to rerun configure.
  1731. +#
  1732. +EOF
  1733. +# Ultrix sh set writes to stderr and can't be redirected directly,
  1734. +# and sets the high bit in the cache file unless we assign to the vars.
  1735. +(set) 2>&1 |
  1736. +  sed -n "s/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=\${\1='\2'}/p" \
  1737. +  >> confcache
  1738. +if cmp -s $cache_file confcache; then
  1739. +  :
  1740.  else
  1741. -    echo "\`$1' is not a known configuration."
  1742. -    echo "Either construct one based on the examples in the config directory,"
  1743. -    echo "or copy config.in to config.h and edit it."
  1744. -    exit 1
  1745. +  if test -w $cache_file; then
  1746. +    echo "updating cache $cache_file"
  1747. +    cat confcache > $cache_file
  1748. +  else
  1749. +    echo "not updating unwritable cache $cache_file"
  1750. +  fi
  1751.  fi
  1752. +rm -f confcache
  1753. +
  1754. +trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
  1755. +
  1756. +test "x$prefix" = xNONE && prefix=$ac_default_prefix
  1757. +# Let make expand exec_prefix.
  1758. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
  1759. +
  1760. +# Any assignment to VPATH causes Sun make to only execute
  1761. +# the first set of double-colon rules, so remove it if not needed.
  1762. +# If there is a colon in the path, we need to keep it.
  1763. +if test "x$srcdir" = x.; then
  1764. +  ac_vpsub='/^[     ]*VPATH[     ]*=[^:]*$/d'
  1765. +fi
  1766. +
  1767. +trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15
  1768. +
  1769. +DEFS=-DHAVE_CONFIG_H
  1770. +
  1771. +# Without the "./", some shells look in PATH for config.status.
  1772. +: ${CONFIG_STATUS=./config.status}
  1773. +
  1774. +echo creating $CONFIG_STATUS
  1775. +# Some systems, like AmigaOS, won't allow you to remove a script that is
  1776. +# being executed, so just move it out of the way instead.
  1777. +if test -f $CONFIG_STATUS; then mv $CONFIG_STATUS $CONFIG_STATUS.old; else true; fi
  1778. +cat > $CONFIG_STATUS <<EOF
  1779. +#! /bin/sh
  1780. +# Generated automatically by configure.
  1781. +# Run this file to recreate the current configuration.
  1782. +# This directory was configured as follows,
  1783. +# on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
  1784. +#
  1785. +# $0 $ac_configure_args
  1786. +#
  1787. +# Compiler output produced by configure, useful for debugging
  1788. +# configure, is in ./config.log if it exists.
  1789. +
  1790. +ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]"
  1791. +for ac_option
  1792. +do
  1793. +  case "\$ac_option" in
  1794. +  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
  1795. +    echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion"
  1796. +    exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;;
  1797. +  -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
  1798. +    echo "$CONFIG_STATUS generated by autoconf version 2.10"
  1799. +    exit 0 ;;
  1800. +  -help | --help | --hel | --he | --h)
  1801. +    echo "\$ac_cs_usage"; exit 0 ;;
  1802. +  *) echo "\$ac_cs_usage"; exit 1 ;;
  1803. +  esac
  1804. +done
  1805. +
  1806. +ac_given_srcdir=$srcdir
  1807. +ac_given_INSTALL="$INSTALL"
  1808. +
  1809. +trap 'rm -fr `echo "Makefile config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
  1810. +EOF
  1811. +cat >> $CONFIG_STATUS <<EOF
  1812. +
  1813. +# Protect against being on the right side of a sed subst in config.status.
  1814. +sed 's/%@/@@/; s/@%/@@/; s/%g\$/@g/; /@g\$/s/[\\\\&%]/\\\\&/g;
  1815. + s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF
  1816. +$ac_vpsub
  1817. +$extrasub
  1818. +s%@CFLAGS@%$CFLAGS%g
  1819. +s%@CPPFLAGS@%$CPPFLAGS%g
  1820. +s%@CXXFLAGS@%$CXXFLAGS%g
  1821. +s%@DEFS@%$DEFS%g
  1822. +s%@LDFLAGS@%$LDFLAGS%g
  1823. +s%@LIBS@%$LIBS%g
  1824. +s%@exec_prefix@%$exec_prefix%g
  1825. +s%@prefix@%$prefix%g
  1826. +s%@program_transform_name@%$program_transform_name%g
  1827. +s%@bindir@%$bindir%g
  1828. +s%@sbindir@%$sbindir%g
  1829. +s%@libexecdir@%$libexecdir%g
  1830. +s%@datadir@%$datadir%g
  1831. +s%@sysconfdir@%$sysconfdir%g
  1832. +s%@sharedstatedir@%$sharedstatedir%g
  1833. +s%@localstatedir@%$localstatedir%g
  1834. +s%@libdir@%$libdir%g
  1835. +s%@includedir@%$includedir%g
  1836. +s%@oldincludedir@%$oldincludedir%g
  1837. +s%@infodir@%$infodir%g
  1838. +s%@guidedir@%$guidedir%g
  1839. +s%@psdir@%$psdir%g
  1840. +s%@dvidir@%$dvidir%g
  1841. +s%@mandir@%$mandir%g
  1842. +s%@CC@%$CC%g
  1843. +s%@CPP@%$CPP%g
  1844. +s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
  1845. +s%@INSTALL_DATA@%$INSTALL_DATA%g
  1846. +s%@YACC@%$YACC%g
  1847. +
  1848. +CEOF
  1849. +EOF
  1850. +cat >> $CONFIG_STATUS <<EOF
  1851. +
  1852. +CONFIG_FILES=\${CONFIG_FILES-"Makefile"}
  1853. +EOF
  1854. +cat >> $CONFIG_STATUS <<\EOF
  1855. +for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then
  1856. +  # Support "outfile[:infile]", defaulting infile="outfile.in".
  1857. +  case "$ac_file" in
  1858. +  *:*) ac_file_in=`echo "$ac_file"|sed 's%.*:%%'`
  1859. +       ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
  1860. +  *) ac_file_in="${ac_file}.in" ;;
  1861. +  esac
  1862. +
  1863. +  # Adjust relative srcdir, etc. for subdirectories.
  1864. +
  1865. +  # Remove last slash and all that follows it.  Not all systems have dirname.
  1866. +  ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'`
  1867. +  if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
  1868. +    # The file is in a subdirectory.
  1869. +    test ! -d "$ac_dir" && mkdir "$ac_dir"
  1870. +    ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`"
  1871. +    # A "../" for each directory in $ac_dir_suffix.
  1872. +    ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'`
  1873. +  else
  1874. +    ac_dir_suffix= ac_dots=
  1875. +  fi
  1876. +
  1877. +  case "$ac_given_srcdir" in
  1878. +  .)  srcdir=.
  1879. +      if test -z "$ac_dots"; then top_srcdir=.
  1880. +      else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;;
  1881. +  /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;;
  1882. +  *) # Relative path.
  1883. +    srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix"
  1884. +    top_srcdir="$ac_dots$ac_given_srcdir" ;;
  1885. +  esac
  1886. +
  1887. +  case "$ac_given_INSTALL" in
  1888. +  [/$]*) INSTALL="$ac_given_INSTALL" ;;
  1889. +  *) INSTALL="$ac_dots$ac_given_INSTALL" ;;
  1890. +  esac
  1891. +  echo creating "$ac_file"
  1892. +  rm -f "$ac_file"
  1893. +  configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure."
  1894. +  case "$ac_file" in
  1895. +  *Makefile*) ac_comsub="1i\\
  1896. +# $configure_input" ;;
  1897. +  *) ac_comsub= ;;
  1898. +  esac
  1899. +  sed -e "$ac_comsub
  1900. +s%@configure_input@%$configure_input%g
  1901. +s%@srcdir@%$srcdir%g
  1902. +s%@top_srcdir@%$top_srcdir%g
  1903. +s%@INSTALL@%$INSTALL%g
  1904. +" -f conftest.subs $ac_given_srcdir/$ac_file_in > $ac_file
  1905. +fi; done
  1906. +rm -f conftest.subs
  1907. +
  1908. +# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where
  1909. +# NAME is the cpp macro being defined and VALUE is the value it is being given.
  1910. +#
  1911. +# ac_d sets the value in "#define NAME VALUE" lines.
  1912. +ac_dA='s%^\([     ]*\)#\([     ]*define[     ][     ]*\)'
  1913. +ac_dB='\([     ][     ]*\)[^     ]*%\1#\2'
  1914. +ac_dC='\3'
  1915. +ac_dD='%g'
  1916. +# ac_u turns "#undef NAME" with trailing blanks into "#define NAME VALUE".
  1917. +ac_uA='s%^\([     ]*\)#\([     ]*\)undef\([     ][     ]*\)'
  1918. +ac_uB='\([     ]\)%\1#\2define\3'
  1919. +ac_uC=' '
  1920. +ac_uD='\4%g'
  1921. +# ac_e turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
  1922. +ac_eA='s%^\([     ]*\)#\([     ]*\)undef\([     ][     ]*\)'
  1923. +ac_eB='$%\1#\2define\3'
  1924. +ac_eC=' '
  1925. +ac_eD='%g'
  1926. +
  1927. +CONFIG_HEADERS=${CONFIG_HEADERS-"config.h"}
  1928. +for ac_file in .. $CONFIG_HEADERS; do if test "x$ac_file" != x..; then
  1929. +  # Support "outfile[:infile]", defaulting infile="outfile.in".
  1930. +  case "$ac_file" in
  1931. +  *:*) ac_file_in=`echo "$ac_file"|sed 's%.*:%%'`
  1932. +       ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
  1933. +  *) ac_file_in="${ac_file}.in" ;;
  1934. +  esac
  1935. +
  1936. +  echo creating $ac_file
  1937. +
  1938. +  rm -f conftest.frag conftest.in conftest.out
  1939. +  cp $ac_given_srcdir/$ac_file_in conftest.in
  1940. +
  1941. +EOF
  1942. +
  1943. +# Transform confdefs.h into a sed script conftest.vals that substitutes
  1944. +# the proper values into config.h.in to produce config.h.  And first:
  1945. +# Protect against being on the right side of a sed subst in config.status.
  1946. +# Protect against being in an unquoted here document in config.status.
  1947. +rm -f conftest.vals
  1948. +cat > conftest.hdr <<\EOF
  1949. +s/[\\&%]/\\&/g
  1950. +s%[\\$`]%\\&%g
  1951. +s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp
  1952. +s%ac_d%ac_u%gp
  1953. +s%ac_u%ac_e%gp
  1954. +EOF
  1955. +sed -n -f conftest.hdr confdefs.h > conftest.vals
  1956. +rm -f conftest.hdr
  1957. +
  1958. +# This sed command replaces #undef with comments.  This is necessary, for
  1959. +# example, in the case of _POSIX_SOURCE, which is predefined and required
  1960. +# on some systems where configure will not decide to define it.
  1961. +cat >> conftest.vals <<\EOF
  1962. +s%^[     ]*#[     ]*undef[     ][     ]*[a-zA-Z_][a-zA-Z_0-9]*%/* & */%
  1963. +EOF
  1964. +
  1965. +# Break up conftest.vals because some shells have a limit on
  1966. +# the size of here documents, and old seds have small limits too.
  1967. +# Maximum number of lines to put in a single here document.
  1968. +ac_max_here_lines=12
  1969. +
  1970. +rm -f conftest.tail
  1971. +while :
  1972. +do
  1973. +  ac_lines=`grep -c . conftest.vals`
  1974. +  # grep -c gives empty output for an empty file on some AIX systems.
  1975. +  if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi
  1976. +  # Write a limited-size here document to conftest.frag.
  1977. +  echo '  cat > conftest.frag <<CEOF' >> $CONFIG_STATUS
  1978. +  sed ${ac_max_here_lines}q conftest.vals >> $CONFIG_STATUS
  1979. +  echo 'CEOF
  1980. +  sed -f conftest.frag conftest.in > conftest.out
  1981. +  rm -f conftest.in
  1982. +  mv conftest.out conftest.in
  1983. +' >> $CONFIG_STATUS
  1984. +  sed 1,${ac_max_here_lines}d conftest.vals > conftest.tail
  1985. +  rm -f conftest.vals
  1986. +  mv conftest.tail conftest.vals
  1987. +done
  1988. +rm -f conftest.vals
  1989. +
  1990. +cat >> $CONFIG_STATUS <<\EOF
  1991. +  rm -f conftest.frag conftest.h
  1992. +  echo "/* $ac_file.  Generated automatically by configure.  */" > conftest.h
  1993. +  cat conftest.in >> conftest.h
  1994. +  rm -f conftest.in
  1995. +  if cmp -s $ac_file conftest.h 2>/dev/null; then
  1996. +    echo "$ac_file is unchanged"
  1997. +    rm -f conftest.h
  1998. +  else
  1999. +    # Remove last slash and all that follows it.  Not all systems have dirname.
  2000. +      ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'`
  2001. +      if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
  2002. +      # The file is in a subdirectory.
  2003. +      test ! -d "$ac_dir" && mkdir "$ac_dir"
  2004. +    fi
  2005. +    rm -f $ac_file
  2006. +    mv conftest.h $ac_file
  2007. +  fi
  2008. +fi; done
  2009. +
  2010. +
  2011. +
  2012. +exit 0
  2013. +EOF
  2014. +chmod +x $CONFIG_STATUS
  2015. +rm -f CONFIG.STATUS.old
  2016. +rm -fr confdefs* $ac_clean_files
  2017. +test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1
  2018. +
  2019. diff -rup --new-file baseline/fsf/gawk/configure.in amiga/fsf/gawk/configure.in
  2020. --- baseline/fsf/gawk/configure.in    Wed Dec 31 17:00:00 1969
  2021. +++ amiga/fsf/gawk/configure.in    Sat Sep 28 00:00:00 1996
  2022. @@ -0,0 +1,28 @@
  2023. +dnl Process this file with autoconf to produce a configure script.
  2024. +AC_INIT(awk.y)
  2025. +AC_CONFIG_HEADER(config.h)
  2026. +
  2027. +# We want these before the checks, so the checks can modify their values.
  2028. +test -z "$CFLAGS" && CFLAGS= auto_cflags=1
  2029. +test -z "$LDFLAGS" && LDFLAGS=
  2030. +
  2031. +AC_PROG_CC
  2032. +
  2033. +# If we're using gcc and the user hasn't specified CFLAGS, add -O to CFLAGS.
  2034. +test -n "$GCC" && test -n "$auto_cflags" && CFLAGS="$CFLAGS -O2"
  2035. +
  2036. +AC_SUBST(CFLAGS)dnl
  2037. +AC_SUBST(LDFLAGS)dnl
  2038. +
  2039. +AC_PROG_CPP
  2040. +AC_GCC_TRADITIONAL
  2041. +AC_PROG_INSTALL
  2042. +AC_PROG_YACC
  2043. +AC_RETSIGTYPE
  2044. +AC_STDC_HEADERS
  2045. +
  2046. +AC_COMPILE_CHECK(_setjmp declaration in <setjmp.h>,
  2047. +         [#include <setjmp.h>], [jmp_buf buf; _setjmp (buf)],
  2048. +         AC_DEFINE(HAVE_UNDERSCORE_SETJMP))
  2049. +
  2050. +AC_OUTPUT(Makefile)
  2051. diff -rup --new-file baseline/fsf/gawk/dfa.h amiga/fsf/gawk/dfa.h
  2052. --- baseline/fsf/gawk/dfa.h    Tue Jan  4 14:18:17 1994
  2053. +++ amiga/fsf/gawk/dfa.h    Sat Sep 28 00:00:00 1996
  2054. @@ -23,13 +23,17 @@
  2055.     name space. */
  2056.  
  2057.  /* Number of bits in an unsigned char. */
  2058. +#ifndef CHARBITS
  2059.  #define CHARBITS 8
  2060. +#endif
  2061.  
  2062.  /* First integer value that is greater than any character code. */
  2063.  #define NOTCHAR (1 << CHARBITS)
  2064.  
  2065.  /* INTBITS need not be exact, just a lower bound. */
  2066. +#ifndef INTBITS
  2067.  #define INTBITS (CHARBITS * sizeof (int))
  2068. +#endif
  2069.  
  2070.  /* Number of ints required to hold a bit for every character. */
  2071.  #define CHARCLASS_INTS ((NOTCHAR + INTBITS - 1) / INTBITS)
  2072. diff -rup --new-file baseline/fsf/gawk/eval.c amiga/fsf/gawk/eval.c
  2073. --- baseline/fsf/gawk/eval.c    Thu Mar  9 09:27:27 1995
  2074. +++ amiga/fsf/gawk/eval.c    Sat Sep 28 00:00:00 1996
  2075. @@ -1096,7 +1096,9 @@ Func_ptr *assign;
  2076.      case Node_FS:
  2077.          aptr = &(FS_node->var_value);
  2078.          if (assign)
  2079. -            *assign = set_FS;
  2080. +          {
  2081. +            *assign = set_FS;
  2082. +          }
  2083.          break;
  2084.  
  2085.      case Node_FNR:
  2086. diff -rup --new-file baseline/fsf/gawk/gawk.1 amiga/fsf/gawk/gawk.1
  2087. --- baseline/fsf/gawk/gawk.1    Thu Jan  5 12:26:24 1995
  2088. +++ amiga/fsf/gawk/gawk.1    Sat Sep 28 00:00:00 1996
  2089. @@ -329,7 +329,7 @@ specifies a search path to use when find
  2090.  the 
  2091.  .B \-f
  2092.  option.  If this variable does not exist, the default path is
  2093. -\fB".:/usr/lib/awk:/usr/local/lib/awk"\fR.
  2094. +\fB".:/local/lib/awk:/ade/lib/awk"\fR.
  2095.  If a file name given to the
  2096.  .B \-f
  2097.  option contains a ``/'' character, no path search is performed.
  2098. diff -rup --new-file baseline/fsf/gawk/gawk.info amiga/fsf/gawk/gawk.info
  2099. --- baseline/fsf/gawk/gawk.info    Wed Dec 31 17:00:00 1969
  2100. +++ amiga/fsf/gawk/gawk.info    Sat Sep 28 00:00:00 1996
  2101. @@ -0,0 +1,204 @@
  2102. +This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  2103. +file /gnu-src/gawk-2.15.6/gawk.texi.
  2104. +
  2105. +   This file documents `awk', a program that you can use to select
  2106. +particular records in a file and perform operations upon them.
  2107. +
  2108. +   This is Edition 0.15 of `The GAWK Manual',
  2109. +for the 2.15 version of the GNU implementation
  2110. +of AWK.
  2111. +
  2112. +   Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  2113. +
  2114. +   Permission is granted to make and distribute verbatim copies of this
  2115. +manual provided the copyright notice and this permission notice are
  2116. +preserved on all copies.
  2117. +
  2118. +   Permission is granted to copy and distribute modified versions of
  2119. +this manual under the conditions for verbatim copying, provided that
  2120. +the entire resulting derived work is distributed under the terms of a
  2121. +permission notice identical to this one.
  2122. +
  2123. +   Permission is granted to copy and distribute translations of this
  2124. +manual into another language, under the above conditions for modified
  2125. +versions, except that this permission notice may be stated in a
  2126. +translation approved by the Foundation.
  2127. +
  2128. +
  2129. +Indirect:
  2130. +gawk.info-1: 1073
  2131. +gawk.info-2: 48269
  2132. +gawk.info-3: 98098
  2133. +gawk.info-4: 146769
  2134. +gawk.info-5: 195892
  2135. +gawk.info-6: 243615
  2136. +gawk.info-7: 291478
  2137. +gawk.info-8: 340856
  2138. +gawk.info-9: 380689
  2139. +
  2140. +Tag Table:
  2141. +(Indirect)
  2142. +Node: Top1073
  2143. +Node: Preface3984
  2144. +Node: History5577
  2145. +Node: Copying7920
  2146. +Node: This Manual27072
  2147. +Node: Sample Data Files28916
  2148. +Node: Getting Started31708
  2149. +Node: Very Simple33419
  2150. +Node: Two Rules35387
  2151. +Node: More Complex37471
  2152. +Node: Running gawk40457
  2153. +Node: One-shot41406
  2154. +Node: Read Terminal42542
  2155. +Node: Long43601
  2156. +Node: Executable Scripts44943
  2157. +Node: Comments47166
  2158. +Node: Statements/Lines48269
  2159. +Node: When51160
  2160. +Node: Reading Files53075
  2161. +Node: Records54802
  2162. +Node: Fields58036
  2163. +Node: Non-Constant Fields60649
  2164. +Node: Changing Fields62473
  2165. +Node: Field Separators65846
  2166. +Node: Constant Size75482
  2167. +Node: Multiple Line79030
  2168. +Node: Getline81426
  2169. +Node: Close Input91170
  2170. +Node: Printing92626
  2171. +Node: Print93625
  2172. +Node: Print Examples95759
  2173. +Node: Output Separators98098
  2174. +Node: OFMT99836
  2175. +Node: Printf100980
  2176. +Node: Basic Printf101884
  2177. +Node: Control Letters103309
  2178. +Node: Format Modifiers105123
  2179. +Node: Printf Examples107628
  2180. +Node: Redirection110310
  2181. +Node: File/Pipe Redirection111046
  2182. +Node: Close Output114519
  2183. +Node: Special Files117023
  2184. +Node: One-liners121957
  2185. +Node: Patterns124679
  2186. +Node: Kinds of Patterns125657
  2187. +Node: Regexp126662
  2188. +Node: Regexp Usage127606
  2189. +Node: Regexp Operators129635
  2190. +Node: Case-sensitivity135113
  2191. +Node: Comparison Patterns137423
  2192. +Node: Boolean Patterns139584
  2193. +Node: Expression Patterns141094
  2194. +Node: Ranges142534
  2195. +Node: BEGIN/END143944
  2196. +Node: Empty146498
  2197. +Node: Actions146769
  2198. +Node: Expressions149149
  2199. +Node: Constants151170
  2200. +Node: Variables156735
  2201. +Node: Assignment Options158344
  2202. +Node: Arithmetic Ops160028
  2203. +Node: Concatenation161694
  2204. +Node: Comparison Ops163042
  2205. +Node: Boolean Ops167467
  2206. +Node: Assignment Ops169930
  2207. +Node: Increment Ops174004
  2208. +Node: Conversion176500
  2209. +Node: Values179575
  2210. +Node: Conditional Exp182158
  2211. +Node: Function Calls183486
  2212. +Node: Precedence186250
  2213. +Node: Statements189633
  2214. +Node: If Statement191316
  2215. +Node: While Statement192844
  2216. +Node: Do Statement194807
  2217. +Node: For Statement195892
  2218. +Node: Break Statement199084
  2219. +Node: Continue Statement200693
  2220. +Node: Next Statement203316
  2221. +Node: Next File Statement205260
  2222. +Node: Exit Statement208306
  2223. +Node: Arrays209921
  2224. +Node: Array Intro211123
  2225. +Node: Reference to Elements214626
  2226. +Node: Assigning Elements216569
  2227. +Node: Array Example217071
  2228. +Node: Scanning an Array218802
  2229. +Node: Delete221102
  2230. +Node: Numeric Array Subscripts222082
  2231. +Node: Multi-dimensional223962
  2232. +Node: Multi-scanning227190
  2233. +Node: Built-in228812
  2234. +Node: Calling Built-in229769
  2235. +Node: Numeric Functions231033
  2236. +Node: String Functions234380
  2237. +Node: I/O Functions243615
  2238. +Node: Time Functions246239
  2239. +Node: User-defined254323
  2240. +Node: Definition Syntax255041
  2241. +Node: Function Example259033
  2242. +Node: Function Caveats260108
  2243. +Node: Return Statement263151
  2244. +Node: Built-in Variables265534
  2245. +Node: User-modified266570
  2246. +Node: Auto-set270847
  2247. +Node: Command Line276586
  2248. +Node: Options277511
  2249. +Node: Other Arguments284585
  2250. +Node: AWKPATH Variable286951
  2251. +Node: Obsolete289089
  2252. +Node: Undocumented290349
  2253. +Node: Language History290537
  2254. +Node: V7/S5R3.1291478
  2255. +Node: S5R4294182
  2256. +Node: POSIX295719
  2257. +Node: POSIX/GNU296437
  2258. +Node: Installation298068
  2259. +Node: Gawk Distribution298934
  2260. +Node: Extracting299387
  2261. +Node: Distribution contents300982
  2262. +Node: Unix Installation303786
  2263. +Node: Quick Installation304477
  2264. +Node: Configuration Philosophy305646
  2265. +Node: New Configurations307972
  2266. +Node: VMS Installation310074
  2267. +Node: VMS Compilation310633
  2268. +Node: VMS Installation Details312248
  2269. +Node: VMS Running313885
  2270. +Node: VMS POSIX315471
  2271. +Node: MS-DOS Installation316859
  2272. +Node: Atari Installation317787
  2273. +Node: Gawk Summary323549
  2274. +Node: Command Line Summary324310
  2275. +Node: Language Summary326743
  2276. +Node: Variables/Fields328828
  2277. +Node: Fields Summary329554
  2278. +Node: Built-in Summary331021
  2279. +Node: Arrays Summary334226
  2280. +Node: Data Type Summary335501
  2281. +Node: Rules Summary336974
  2282. +Node: Pattern Summary338623
  2283. +Node: Regexp Summary340856
  2284. +Node: Actions Summary342076
  2285. +Node: Operator Summary342991
  2286. +Node: Control Flow Summary344352
  2287. +Node: I/O Summary344958
  2288. +Node: Printf Summary346837
  2289. +Node: Special File Summary348663
  2290. +Node: Numeric Functions Summary350721
  2291. +Node: String Functions Summary351557
  2292. +Node: Time Functions Summary353389
  2293. +Node: String Constants Summary354153
  2294. +Node: Functions Summary355536
  2295. +Node: Historical Features356595
  2296. +Node: Sample Program357452
  2297. +Node: Bugs361706
  2298. +Node: Notes364554
  2299. +Node: Compatibility Mode365083
  2300. +Node: Future Extensions365916
  2301. +Node: Improvements368213
  2302. +Node: Glossary370248
  2303. +Node: Index380689
  2304. +
  2305. +End Tag Table
  2306. diff -rup --new-file baseline/fsf/gawk/gawk.info-1 amiga/fsf/gawk/gawk.info-1
  2307. --- baseline/fsf/gawk/gawk.info-1    Wed Dec 31 17:00:00 1969
  2308. +++ amiga/fsf/gawk/gawk.info-1    Sat Sep 28 00:00:00 1996
  2309. @@ -0,0 +1,1069 @@
  2310. +This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  2311. +file /gnu-src/gawk-2.15.6/gawk.texi.
  2312. +
  2313. +   This file documents `awk', a program that you can use to select
  2314. +particular records in a file and perform operations upon them.
  2315. +
  2316. +   This is Edition 0.15 of `The GAWK Manual',
  2317. +for the 2.15 version of the GNU implementation
  2318. +of AWK.
  2319. +
  2320. +   Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  2321. +
  2322. +   Permission is granted to make and distribute verbatim copies of this
  2323. +manual provided the copyright notice and this permission notice are
  2324. +preserved on all copies.
  2325. +
  2326. +   Permission is granted to copy and distribute modified versions of
  2327. +this manual under the conditions for verbatim copying, provided that
  2328. +the entire resulting derived work is distributed under the terms of a
  2329. +permission notice identical to this one.
  2330. +
  2331. +   Permission is granted to copy and distribute translations of this
  2332. +manual into another language, under the above conditions for modified
  2333. +versions, except that this permission notice may be stated in a
  2334. +translation approved by the Foundation.
  2335. +
  2336. +
  2337. +File: gawk.info,  Node: Top,  Next: Preface,  Prev: (dir),  Up: (dir)
  2338. +
  2339. +General Introduction
  2340. +********************
  2341. +
  2342. +   This file documents `awk', a program that you can use to select
  2343. +particular records in a file and perform operations upon them.
  2344. +
  2345. +   This is Edition 0.15 of `The GAWK Manual',
  2346. +for the 2.15 version of the GNU implementation
  2347. +of AWK.
  2348. +
  2349. +* Menu:
  2350. +
  2351. +* Preface::                     What you can do with `awk'; brief history
  2352. +                                and acknowledgements.
  2353. +* Copying::                     Your right to copy and distribute `gawk'.
  2354. +* This Manual::                 Using this manual.
  2355. +                                Includes sample input files that you can use.
  2356. +* Getting Started::             A basic introduction to using `awk'.
  2357. +                                How to run an `awk' program.
  2358. +                                Command line syntax.
  2359. +* Reading Files::               How to read files and manipulate fields.
  2360. +* Printing::                    How to print using `awk'.  Describes the
  2361. +                                `print' and `printf' statements.
  2362. +                                Also describes redirection of output.
  2363. +* One-liners::                  Short, sample `awk' programs.
  2364. +* Patterns::                    The various types of patterns
  2365. +                                explained in detail.
  2366. +* Actions::                     The various types of actions are
  2367. +                                introduced here.  Describes
  2368. +                                expressions and the various operators in
  2369. +                                detail.  Also describes comparison expressions.
  2370. +* Expressions::                 Expressions are the basic building
  2371. +                                blocks of statements.
  2372. +* Statements::                  The various control statements are
  2373. +                                described in detail.
  2374. +* Arrays::                      The description and use of arrays.
  2375. +                                Also includes array-oriented control
  2376. +                                statements.
  2377. +* Built-in::                    The built-in functions are summarized here.
  2378. +* User-defined::                User-defined functions are described in detail.
  2379. +* Built-in Variables::          Built-in Variables
  2380. +* Command Line::                How to run `gawk'.
  2381. +* Language History::            The evolution of the `awk' language.
  2382. +* Installation::                Installing `gawk' under
  2383. +                                various operating systems.
  2384. +* Gawk Summary::                `gawk' Options and Language Summary.
  2385. +* Sample Program::              A sample `awk' program with a
  2386. +                                complete explanation.
  2387. +* Bugs::                        Reporting Problems and Bugs.
  2388. +* Notes::                       Something about the
  2389. +                                implementation of `gawk'.
  2390. +* Glossary::                    An explanation of some unfamiliar terms.
  2391. +* Index::
  2392. +
  2393. +
  2394. +File: gawk.info,  Node: Preface,  Next: Copying,  Prev: Top,  Up: Top
  2395. +
  2396. +Preface
  2397. +*******
  2398. +
  2399. +   If you are like many computer users, you would frequently like to
  2400. +make changes in various text files wherever certain patterns appear, or
  2401. +extract data from parts of certain lines while discarding the rest.  To
  2402. +write a program to do this in a language such as C or Pascal is a
  2403. +time-consuming inconvenience that may take many lines of code.  The job
  2404. +may be easier with `awk'.
  2405. +
  2406. +   The `awk' utility interprets a special-purpose programming language
  2407. +that makes it possible to handle simple data-reformatting jobs easily
  2408. +with just a few lines of code.
  2409. +
  2410. +   The GNU implementation of `awk' is called `gawk'; it is fully upward
  2411. +compatible with the System V Release 4 version of `awk'.  `gawk' is
  2412. +also upward compatible with the POSIX (draft) specification of the
  2413. +`awk' language.  This means that all properly written `awk' programs
  2414. +should work with `gawk'.  Thus, we usually don't distinguish between
  2415. +`gawk' and other `awk' implementations in this manual.
  2416. +
  2417. +   This manual teaches you what `awk' does and how you can use `awk'
  2418. +effectively.  You should already be familiar with basic system commands
  2419. +such as `ls'.  Using `awk' you can:
  2420. +
  2421. +   * manage small, personal databases
  2422. +
  2423. +   * generate reports
  2424. +
  2425. +   * validate data
  2426. +
  2427. +   * produce indexes, and perform other document preparation tasks
  2428. +
  2429. +   * even experiment with algorithms that can be adapted later to other
  2430. +     computer languages
  2431. +
  2432. +* Menu:
  2433. +
  2434. +* History::                     The history of `gawk' and
  2435. +                                `awk'.  Acknowledgements.
  2436. +
  2437. +
  2438. +File: gawk.info,  Node: History,  Prev: Preface,  Up: Preface
  2439. +
  2440. +History of `awk' and `gawk'
  2441. +===========================
  2442. +
  2443. +   The name `awk' comes from the initials of its designers: Alfred V.
  2444. +Aho, Peter J. Weinberger, and Brian W. Kernighan.  The original version
  2445. +of `awk' was written in 1977.  In 1985 a new version made the
  2446. +programming language more powerful, introducing user-defined functions,
  2447. +multiple input streams, and computed regular expressions.  This new
  2448. +version became generally available with System V Release 3.1.  The
  2449. +version in System V Release 4 added some new features and also cleaned
  2450. +up the behavior in some of the "dark corners" of the language.  The
  2451. +specification for `awk' in the POSIX Command Language and Utilities
  2452. +standard further clarified the language based on feedback from both the
  2453. +`gawk' designers, and the original `awk' designers.
  2454. +
  2455. +   The GNU implementation, `gawk', was written in 1986 by Paul Rubin
  2456. +and Jay Fenlason, with advice from Richard Stallman.  John Woods
  2457. +contributed parts of the code as well.  In 1988 and 1989, David
  2458. +Trueman, with help from Arnold Robbins, thoroughly reworked `gawk' for
  2459. +compatibility with the newer `awk'.  Current development (1992) focuses
  2460. +on bug fixes, performance improvements, and standards compliance.
  2461. +
  2462. +   We need to thank many people for their assistance in producing this
  2463. +manual.  Jay Fenlason contributed many ideas and sample programs.
  2464. +Richard Mlynarik and Robert J. Chassell gave helpful comments on early
  2465. +drafts of this manual.  The paper `A Supplemental Document for `awk''
  2466. +by John W.  Pierce of the Chemistry Department at UC San Diego,
  2467. +pinpointed several issues relevant both to `awk' implementation and to
  2468. +this manual, that would otherwise have escaped us.  David Trueman, Pat
  2469. +Rankin, and Michal Jaegermann also contributed sections of the manual.
  2470. +
  2471. +   The following people provided many helpful comments on this edition
  2472. +of the manual: Rick Adams, Michael Brennan, Rich Burridge, Diane Close,
  2473. +Christopher ("Topher") Eliot, Michael Lijewski, Pat Rankin, Miriam
  2474. +Robbins, and Michal Jaegermann.  Robert J. Chassell provided much
  2475. +valuable advice on the use of Texinfo.
  2476. +
  2477. +   Finally, we would like to thank Brian Kernighan of Bell Labs for
  2478. +invaluable assistance during the testing and debugging of `gawk', and
  2479. +for help in clarifying numerous points about the language.
  2480. +
  2481. +
  2482. +File: gawk.info,  Node: Copying,  Next: This Manual,  Prev: Preface,  Up: Top
  2483. +
  2484. +GNU GENERAL PUBLIC LICENSE
  2485. +**************************
  2486. +
  2487. +                         Version 2, June 1991
  2488. +
  2489. +     Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  2490. +     675 Mass Ave, Cambridge, MA 02139, USA
  2491. +     
  2492. +     Everyone is permitted to copy and distribute verbatim copies
  2493. +     of this license document, but changing it is not allowed.
  2494. +
  2495. +Preamble
  2496. +========
  2497. +
  2498. +   The licenses for most software are designed to take away your
  2499. +freedom to share and change it.  By contrast, the GNU General Public
  2500. +License is intended to guarantee your freedom to share and change free
  2501. +software--to make sure the software is free for all its users.  This
  2502. +General Public License applies to most of the Free Software
  2503. +Foundation's software and to any other program whose authors commit to
  2504. +using it.  (Some other Free Software Foundation software is covered by
  2505. +the GNU Library General Public License instead.)  You can apply it to
  2506. +your programs, too.
  2507. +
  2508. +   When we speak of free software, we are referring to freedom, not
  2509. +price.  Our General Public Licenses are designed to make sure that you
  2510. +have the freedom to distribute copies of free software (and charge for
  2511. +this service if you wish), that you receive source code or can get it
  2512. +if you want it, that you can change the software or use pieces of it in
  2513. +new free programs; and that you know you can do these things.
  2514. +
  2515. +   To protect your rights, we need to make restrictions that forbid
  2516. +anyone to deny you these rights or to ask you to surrender the rights.
  2517. +These restrictions translate to certain responsibilities for you if you
  2518. +distribute copies of the software, or if you modify it.
  2519. +
  2520. +   For example, if you distribute copies of such a program, whether
  2521. +gratis or for a fee, you must give the recipients all the rights that
  2522. +you have.  You must make sure that they, too, receive or can get the
  2523. +source code.  And you must show them these terms so they know their
  2524. +rights.
  2525. +
  2526. +   We protect your rights with two steps: (1) copyright the software,
  2527. +and (2) offer you this license which gives you legal permission to copy,
  2528. +distribute and/or modify the software.
  2529. +
  2530. +   Also, for each author's protection and ours, we want to make certain
  2531. +that everyone understands that there is no warranty for this free
  2532. +software.  If the software is modified by someone else and passed on, we
  2533. +want its recipients to know that what they have is not the original, so
  2534. +that any problems introduced by others will not reflect on the original
  2535. +authors' reputations.
  2536. +
  2537. +   Finally, any free program is threatened constantly by software
  2538. +patents.  We wish to avoid the danger that redistributors of a free
  2539. +program will individually obtain patent licenses, in effect making the
  2540. +program proprietary.  To prevent this, we have made it clear that any
  2541. +patent must be licensed for everyone's free use or not licensed at all.
  2542. +
  2543. +   The precise terms and conditions for copying, distribution and
  2544. +modification follow.
  2545. +
  2546. +    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  2547. +
  2548. +  1. This License applies to any program or other work which contains a
  2549. +     notice placed by the copyright holder saying it may be distributed
  2550. +     under the terms of this General Public License.  The "Program",
  2551. +     below, refers to any such program or work, and a "work based on
  2552. +     the Program" means either the Program or any derivative work under
  2553. +     copyright law: that is to say, a work containing the Program or a
  2554. +     portion of it, either verbatim or with modifications and/or
  2555. +     translated into another language.  (Hereinafter, translation is
  2556. +     included without limitation in the term "modification".)  Each
  2557. +     licensee is addressed as "you".
  2558. +
  2559. +     Activities other than copying, distribution and modification are
  2560. +     not covered by this License; they are outside its scope.  The act
  2561. +     of running the Program is not restricted, and the output from the
  2562. +     Program is covered only if its contents constitute a work based on
  2563. +     the Program (independent of having been made by running the
  2564. +     Program).  Whether that is true depends on what the Program does.
  2565. +
  2566. +  2. You may copy and distribute verbatim copies of the Program's
  2567. +     source code as you receive it, in any medium, provided that you
  2568. +     conspicuously and appropriately publish on each copy an appropriate
  2569. +     copyright notice and disclaimer of warranty; keep intact all the
  2570. +     notices that refer to this License and to the absence of any
  2571. +     warranty; and give any other recipients of the Program a copy of
  2572. +     this License along with the Program.
  2573. +
  2574. +     You may charge a fee for the physical act of transferring a copy,
  2575. +     and you may at your option offer warranty protection in exchange
  2576. +     for a fee.
  2577. +
  2578. +  3. You may modify your copy or copies of the Program or any portion
  2579. +     of it, thus forming a work based on the Program, and copy and
  2580. +     distribute such modifications or work under the terms of Section 1
  2581. +     above, provided that you also meet all of these conditions:
  2582. +
  2583. +       a. You must cause the modified files to carry prominent notices
  2584. +          stating that you changed the files and the date of any change.
  2585. +
  2586. +       b. You must cause any work that you distribute or publish, that
  2587. +          in whole or in part contains or is derived from the Program
  2588. +          or any part thereof, to be licensed as a whole at no charge
  2589. +          to all third parties under the terms of this License.
  2590. +
  2591. +       c. If the modified program normally reads commands interactively
  2592. +          when run, you must cause it, when started running for such
  2593. +          interactive use in the most ordinary way, to print or display
  2594. +          an announcement including an appropriate copyright notice and
  2595. +          a notice that there is no warranty (or else, saying that you
  2596. +          provide a warranty) and that users may redistribute the
  2597. +          program under these conditions, and telling the user how to
  2598. +          view a copy of this License.  (Exception: if the Program
  2599. +          itself is interactive but does not normally print such an
  2600. +          announcement, your work based on the Program is not required
  2601. +          to print an announcement.)
  2602. +
  2603. +     These requirements apply to the modified work as a whole.  If
  2604. +     identifiable sections of that work are not derived from the
  2605. +     Program, and can be reasonably considered independent and separate
  2606. +     works in themselves, then this License, and its terms, do not
  2607. +     apply to those sections when you distribute them as separate
  2608. +     works.  But when you distribute the same sections as part of a
  2609. +     whole which is a work based on the Program, the distribution of
  2610. +     the whole must be on the terms of this License, whose permissions
  2611. +     for other licensees extend to the entire whole, and thus to each
  2612. +     and every part regardless of who wrote it.
  2613. +
  2614. +     Thus, it is not the intent of this section to claim rights or
  2615. +     contest your rights to work written entirely by you; rather, the
  2616. +     intent is to exercise the right to control the distribution of
  2617. +     derivative or collective works based on the Program.
  2618. +
  2619. +     In addition, mere aggregation of another work not based on the
  2620. +     Program with the Program (or with a work based on the Program) on
  2621. +     a volume of a storage or distribution medium does not bring the
  2622. +     other work under the scope of this License.
  2623. +
  2624. +  4. You may copy and distribute the Program (or a work based on it,
  2625. +     under Section 2) in object code or executable form under the terms
  2626. +     of Sections 1 and 2 above provided that you also do one of the
  2627. +     following:
  2628. +
  2629. +       a. Accompany it with the complete corresponding machine-readable
  2630. +          source code, which must be distributed under the terms of
  2631. +          Sections 1 and 2 above on a medium customarily used for
  2632. +          software interchange; or,
  2633. +
  2634. +       b. Accompany it with a written offer, valid for at least three
  2635. +          years, to give any third party, for a charge no more than your
  2636. +          cost of physically performing source distribution, a complete
  2637. +          machine-readable copy of the corresponding source code, to be
  2638. +          distributed under the terms of Sections 1 and 2 above on a
  2639. +          medium customarily used for software interchange; or,
  2640. +
  2641. +       c. Accompany it with the information you received as to the offer
  2642. +          to distribute corresponding source code.  (This alternative is
  2643. +          allowed only for noncommercial distribution and only if you
  2644. +          received the program in object code or executable form with
  2645. +          such an offer, in accord with Subsection b above.)
  2646. +
  2647. +     The source code for a work means the preferred form of the work for
  2648. +     making modifications to it.  For an executable work, complete
  2649. +     source code means all the source code for all modules it contains,
  2650. +     plus any associated interface definition files, plus the scripts
  2651. +     used to control compilation and installation of the executable.
  2652. +     However, as a special exception, the source code distributed need
  2653. +     not include anything that is normally distributed (in either
  2654. +     source or binary form) with the major components (compiler,
  2655. +     kernel, and so on) of the operating system on which the executable
  2656. +     runs, unless that component itself accompanies the executable.
  2657. +
  2658. +     If distribution of executable or object code is made by offering
  2659. +     access to copy from a designated place, then offering equivalent
  2660. +     access to copy the source code from the same place counts as
  2661. +     distribution of the source code, even though third parties are not
  2662. +     compelled to copy the source along with the object code.
  2663. +
  2664. +  5. You may not copy, modify, sublicense, or distribute the Program
  2665. +     except as expressly provided under this License.  Any attempt
  2666. +     otherwise to copy, modify, sublicense or distribute the Program is
  2667. +     void, and will automatically terminate your rights under this
  2668. +     License.  However, parties who have received copies, or rights,
  2669. +     from you under this License will not have their licenses
  2670. +     terminated so long as such parties remain in full compliance.
  2671. +
  2672. +  6. You are not required to accept this License, since you have not
  2673. +     signed it.  However, nothing else grants you permission to modify
  2674. +     or distribute the Program or its derivative works.  These actions
  2675. +     are prohibited by law if you do not accept this License.
  2676. +     Therefore, by modifying or distributing the Program (or any work
  2677. +     based on the Program), you indicate your acceptance of this
  2678. +     License to do so, and all its terms and conditions for copying,
  2679. +     distributing or modifying the Program or works based on it.
  2680. +
  2681. +  7. Each time you redistribute the Program (or any work based on the
  2682. +     Program), the recipient automatically receives a license from the
  2683. +     original licensor to copy, distribute or modify the Program
  2684. +     subject to these terms and conditions.  You may not impose any
  2685. +     further restrictions on the recipients' exercise of the rights
  2686. +     granted herein.  You are not responsible for enforcing compliance
  2687. +     by third parties to this License.
  2688. +
  2689. +  8. If, as a consequence of a court judgment or allegation of patent
  2690. +     infringement or for any other reason (not limited to patent
  2691. +     issues), conditions are imposed on you (whether by court order,
  2692. +     agreement or otherwise) that contradict the conditions of this
  2693. +     License, they do not excuse you from the conditions of this
  2694. +     License.  If you cannot distribute so as to satisfy simultaneously
  2695. +     your obligations under this License and any other pertinent
  2696. +     obligations, then as a consequence you may not distribute the
  2697. +     Program at all.  For example, if a patent license would not permit
  2698. +     royalty-free redistribution of the Program by all those who
  2699. +     receive copies directly or indirectly through you, then the only
  2700. +     way you could satisfy both it and this License would be to refrain
  2701. +     entirely from distribution of the Program.
  2702. +
  2703. +     If any portion of this section is held invalid or unenforceable
  2704. +     under any particular circumstance, the balance of the section is
  2705. +     intended to apply and the section as a whole is intended to apply
  2706. +     in other circumstances.
  2707. +
  2708. +     It is not the purpose of this section to induce you to infringe any
  2709. +     patents or other property right claims or to contest validity of
  2710. +     any such claims; this section has the sole purpose of protecting
  2711. +     the integrity of the free software distribution system, which is
  2712. +     implemented by public license practices.  Many people have made
  2713. +     generous contributions to the wide range of software distributed
  2714. +     through that system in reliance on consistent application of that
  2715. +     system; it is up to the author/donor to decide if he or she is
  2716. +     willing to distribute software through any other system and a
  2717. +     licensee cannot impose that choice.
  2718. +
  2719. +     This section is intended to make thoroughly clear what is believed
  2720. +     to be a consequence of the rest of this License.
  2721. +
  2722. +  9. If the distribution and/or use of the Program is restricted in
  2723. +     certain countries either by patents or by copyrighted interfaces,
  2724. +     the original copyright holder who places the Program under this
  2725. +     License may add an explicit geographical distribution limitation
  2726. +     excluding those countries, so that distribution is permitted only
  2727. +     in or among countries not thus excluded.  In such case, this
  2728. +     License incorporates the limitation as if written in the body of
  2729. +     this License.
  2730. +
  2731. + 10. The Free Software Foundation may publish revised and/or new
  2732. +     versions of the General Public License from time to time.  Such
  2733. +     new versions will be similar in spirit to the present version, but
  2734. +     may differ in detail to address new problems or concerns.
  2735. +
  2736. +     Each version is given a distinguishing version number.  If the
  2737. +     Program specifies a version number of this License which applies
  2738. +     to it and "any later version", you have the option of following
  2739. +     the terms and conditions either of that version or of any later
  2740. +     version published by the Free Software Foundation.  If the Program
  2741. +     does not specify a version number of this License, you may choose
  2742. +     any version ever published by the Free Software Foundation.
  2743. +
  2744. + 11. If you wish to incorporate parts of the Program into other free
  2745. +     programs whose distribution conditions are different, write to the
  2746. +     author to ask for permission.  For software which is copyrighted
  2747. +     by the Free Software Foundation, write to the Free Software
  2748. +     Foundation; we sometimes make exceptions for this.  Our decision
  2749. +     will be guided by the two goals of preserving the free status of
  2750. +     all derivatives of our free software and of promoting the sharing
  2751. +     and reuse of software generally.
  2752. +
  2753. +                                NO WARRANTY
  2754. +
  2755. + 12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
  2756. +     WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
  2757. +     LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  2758. +     HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
  2759. +     WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
  2760. +     NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  2761. +     FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE
  2762. +     QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  2763. +     PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
  2764. +     SERVICING, REPAIR OR CORRECTION.
  2765. +
  2766. + 13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
  2767. +     WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
  2768. +     MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
  2769. +     LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
  2770. +     INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  2771. +     INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
  2772. +     DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
  2773. +     OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
  2774. +     OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
  2775. +     ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  2776. +
  2777. +                      END OF TERMS AND CONDITIONS
  2778. +
  2779. +How to Apply These Terms to Your New Programs
  2780. +=============================================
  2781. +
  2782. +   If you develop a new program, and you want it to be of the greatest
  2783. +possible use to the public, the best way to achieve this is to make it
  2784. +free software which everyone can redistribute and change under these
  2785. +terms.
  2786. +
  2787. +   To do so, attach the following notices to the program.  It is safest
  2788. +to attach them to the start of each source file to most effectively
  2789. +convey the exclusion of warranty; and each file should have at least
  2790. +the "copyright" line and a pointer to where the full notice is found.
  2791. +
  2792. +     ONE LINE TO GIVE THE PROGRAM'S NAME AND A BRIEF IDEA OF WHAT IT DOES.
  2793. +     Copyright (C) 19YY  NAME OF AUTHOR
  2794. +     
  2795. +     This program is free software; you can redistribute it and/or modify
  2796. +     it under the terms of the GNU General Public License as published by
  2797. +     the Free Software Foundation; either version 2 of the License, or
  2798. +     (at your option) any later version.
  2799. +     
  2800. +     This program is distributed in the hope that it will be useful,
  2801. +     but WITHOUT ANY WARRANTY; without even the implied warranty of
  2802. +     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2803. +     GNU General Public License for more details.
  2804. +     
  2805. +     You should have received a copy of the GNU General Public License
  2806. +     along with this program; if not, write to the Free Software
  2807. +     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  2808. +
  2809. +   Also add information on how to contact you by electronic and paper
  2810. +mail.
  2811. +
  2812. +   If the program is interactive, make it output a short notice like
  2813. +this when it starts in an interactive mode:
  2814. +
  2815. +     Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
  2816. +     Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
  2817. +     type `show w'.
  2818. +     This is free software, and you are welcome to redistribute it
  2819. +     under certain conditions; type `show c' for details.
  2820. +
  2821. +   The hypothetical commands `show w' and `show c' should show the
  2822. +appropriate parts of the General Public License.  Of course, the
  2823. +commands you use may be called something other than `show w' and `show
  2824. +c'; they could even be mouse-clicks or menu items--whatever suits your
  2825. +program.
  2826. +
  2827. +   You should also get your employer (if you work as a programmer) or
  2828. +your school, if any, to sign a "copyright disclaimer" for the program,
  2829. +if necessary.  Here is a sample; alter the names:
  2830. +
  2831. +     Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  2832. +     `Gnomovision' (which makes passes at compilers) written by James Hacker.
  2833. +     
  2834. +     SIGNATURE OF TY COON, 1 April 1989
  2835. +     Ty Coon, President of Vice
  2836. +
  2837. +   This General Public License does not permit incorporating your
  2838. +program into proprietary programs.  If your program is a subroutine
  2839. +library, you may consider it more useful to permit linking proprietary
  2840. +applications with the library.  If this is what you want to do, use the
  2841. +GNU Library General Public License instead of this License.
  2842. +
  2843. +
  2844. +File: gawk.info,  Node: This Manual,  Next: Getting Started,  Prev: Copying,  Up: Top
  2845. +
  2846. +Using this Manual
  2847. +*****************
  2848. +
  2849. +   The term `awk' refers to a particular program, and to the language
  2850. +you use to tell this program what to do.  When we need to be careful,
  2851. +we call the program "the `awk' utility" and the language "the `awk'
  2852. +language."  The term `gawk' refers to a version of `awk' developed as
  2853. +part the GNU project.  The purpose of this manual is to explain both the
  2854. +`awk' language and how to run the `awk' utility.
  2855. +
  2856. +   While concentrating on the features of `gawk', the manual will also
  2857. +attempt to describe important differences between `gawk' and other
  2858. +`awk' implementations.  In particular, any features that are not in the
  2859. +POSIX standard for `awk' will be noted.
  2860. +
  2861. +   The term "`awk' program" refers to a program written by you in the
  2862. +`awk' programming language.
  2863. +
  2864. +   *Note Getting Started with `awk': Getting Started, for the bare
  2865. +essentials you need to know to start using `awk'.
  2866. +
  2867. +   Some useful "one-liners" are included to give you a feel for the
  2868. +`awk' language (*note Useful "One-liners": One-liners.).
  2869. +
  2870. +   A sample `awk' program has been provided for you (*note Sample
  2871. +Program::.).
  2872. +
  2873. +   If you find terms that you aren't familiar with, try looking them up
  2874. +in the glossary (*note Glossary::.).
  2875. +
  2876. +   The entire `awk' language is summarized for quick reference in *Note
  2877. +`gawk' Summary: Gawk Summary.  Look there if you just need to refresh
  2878. +your memory about a particular feature.
  2879. +
  2880. +   Most of the time complete `awk' programs are used as examples, but in
  2881. +some of the more advanced sections, only the part of the `awk' program
  2882. +that illustrates the concept being described is shown.
  2883. +
  2884. +* Menu:
  2885. +
  2886. +* Sample Data Files::           Sample data files for use in the `awk'
  2887. +                                programs illustrated in this manual.
  2888. +
  2889. +
  2890. +File: gawk.info,  Node: Sample Data Files,  Prev: This Manual,  Up: This Manual
  2891. +
  2892. +Data Files for the Examples
  2893. +===========================
  2894. +
  2895. +   Many of the examples in this manual take their input from two sample
  2896. +data files.  The first, called `BBS-list', represents a list of
  2897. +computer bulletin board systems together with information about those
  2898. +systems.  The second data file, called `inventory-shipped', contains
  2899. +information about shipments on a monthly basis.  Each line of these
  2900. +files is one "record".
  2901. +
  2902. +   In the file `BBS-list', each record contains the name of a computer
  2903. +bulletin board, its phone number, the board's baud rate, and a code for
  2904. +the number of hours it is operational.  An `A' in the last column means
  2905. +the board operates 24 hours a day.  A `B' in the last column means the
  2906. +board operates evening and weekend hours, only.  A `C' means the board
  2907. +operates only on weekends.
  2908. +
  2909. +     aardvark     555-5553     1200/300          B
  2910. +     alpo-net     555-3412     2400/1200/300     A
  2911. +     barfly       555-7685     1200/300          A
  2912. +     bites        555-1675     2400/1200/300     A
  2913. +     camelot      555-0542     300               C
  2914. +     core         555-2912     1200/300          C
  2915. +     fooey        555-1234     2400/1200/300     B
  2916. +     foot         555-6699     1200/300          B
  2917. +     macfoo       555-6480     1200/300          A
  2918. +     sdace        555-3430     2400/1200/300     A
  2919. +     sabafoo      555-2127     1200/300          C
  2920. +
  2921. +   The second data file, called `inventory-shipped', represents
  2922. +information about shipments during the year.  Each record contains the
  2923. +month of the year, the number of green crates shipped, the number of
  2924. +red boxes shipped, the number of orange bags shipped, and the number of
  2925. +blue packages shipped, respectively.  There are 16 entries, covering
  2926. +the 12 months of one year and 4 months of the next year.
  2927. +
  2928. +     Jan  13  25  15 115
  2929. +     Feb  15  32  24 226
  2930. +     Mar  15  24  34 228
  2931. +     Apr  31  52  63 420
  2932. +     May  16  34  29 208
  2933. +     Jun  31  42  75 492
  2934. +     Jul  24  34  67 436
  2935. +     Aug  15  34  47 316
  2936. +     Sep  13  55  37 277
  2937. +     Oct  29  54  68 525
  2938. +     Nov  20  87  82 577
  2939. +     Dec  17  35  61 401
  2940. +     
  2941. +     Jan  21  36  64 620
  2942. +     Feb  26  58  80 652
  2943. +     Mar  24  75  70 495
  2944. +     Apr  21  70  74 514
  2945. +
  2946. +   If you are reading this in GNU Emacs using Info, you can copy the
  2947. +regions of text showing these sample files into your own test files.
  2948. +This way you can try out the examples shown in the remainder of this
  2949. +document.  You do this by using the command `M-x write-region' to copy
  2950. +text from the Info file into a file for use with `awk' (*Note Misc File
  2951. +Ops: (emacs)Misc File Ops, for more information).  Using this
  2952. +information, create your own `BBS-list' and `inventory-shipped' files,
  2953. +and practice what you learn in this manual.
  2954. +
  2955. +
  2956. +File: gawk.info,  Node: Getting Started,  Next: Reading Files,  Prev: This Manual,  Up: Top
  2957. +
  2958. +Getting Started with `awk'
  2959. +**************************
  2960. +
  2961. +   The basic function of `awk' is to search files for lines (or other
  2962. +units of text) that contain certain patterns.  When a line matches one
  2963. +of the patterns, `awk' performs specified actions on that line.  `awk'
  2964. +keeps processing input lines in this way until the end of the input
  2965. +file is reached.
  2966. +
  2967. +   When you run `awk', you specify an `awk' "program" which tells `awk'
  2968. +what to do.  The program consists of a series of "rules".  (It may also
  2969. +contain "function definitions", but that is an advanced feature, so we
  2970. +will ignore it for now.  *Note User-defined Functions: User-defined.)
  2971. +Each rule specifies one pattern to search for, and one action to
  2972. +perform when that pattern is found.
  2973. +
  2974. +   Syntactically, a rule consists of a pattern followed by an action.
  2975. +The action is enclosed in curly braces to separate it from the pattern.
  2976. +Rules are usually separated by newlines.  Therefore, an `awk' program
  2977. +looks like this:
  2978. +
  2979. +     PATTERN { ACTION }
  2980. +     PATTERN { ACTION }
  2981. +     ...
  2982. +
  2983. +* Menu:
  2984. +
  2985. +* Very Simple::                 A very simple example.
  2986. +* Two Rules::                   A less simple one-line example with two rules.
  2987. +* More Complex::                A more complex example.
  2988. +* Running gawk::                How to run `gawk' programs;
  2989. +                                includes command line syntax.
  2990. +* Comments::                    Adding documentation to `gawk' programs.
  2991. +* Statements/Lines::            Subdividing or combining statements into lines.
  2992. +* When::                        When to use `gawk' and
  2993. +                                when to use other things.
  2994. +
  2995. +
  2996. +File: gawk.info,  Node: Very Simple,  Next: Two Rules,  Prev: Getting Started,  Up: Getting Started
  2997. +
  2998. +A Very Simple Example
  2999. +=====================
  3000. +
  3001. +   The following command runs a simple `awk' program that searches the
  3002. +input file `BBS-list' for the string of characters: `foo'.  (A string
  3003. +of characters is usually called, a "string".  The term "string" is
  3004. +perhaps based on similar usage in English, such as "a string of
  3005. +pearls," or, "a string of cars in a train.")
  3006. +
  3007. +     awk '/foo/ { print $0 }' BBS-list
  3008. +
  3009. +When lines containing `foo' are found, they are printed, because
  3010. +`print $0' means print the current line.  (Just `print' by itself means
  3011. +the same thing, so we could have written that instead.)
  3012. +
  3013. +   You will notice that slashes, `/', surround the string `foo' in the
  3014. +actual `awk' program.  The slashes indicate that `foo' is a pattern to
  3015. +search for.  This type of pattern is called a "regular expression", and
  3016. +is covered in more detail later (*note Regular Expressions as Patterns:
  3017. +Regexp.).  There are single-quotes around the `awk' program so that the
  3018. +shell won't interpret any of it as special shell characters.
  3019. +
  3020. +   Here is what this program prints:
  3021. +
  3022. +     fooey        555-1234     2400/1200/300     B
  3023. +     foot         555-6699     1200/300          B
  3024. +     macfoo       555-6480     1200/300          A
  3025. +     sabafoo      555-2127     1200/300          C
  3026. +
  3027. +   In an `awk' rule, either the pattern or the action can be omitted,
  3028. +but not both.  If the pattern is omitted, then the action is performed
  3029. +for *every* input line.  If the action is omitted, the default action
  3030. +is to print all lines that match the pattern.
  3031. +
  3032. +   Thus, we could leave out the action (the `print' statement and the
  3033. +curly braces) in the above example, and the result would be the same:
  3034. +all lines matching the pattern `foo' would be printed.  By comparison,
  3035. +omitting the `print' statement but retaining the curly braces makes an
  3036. +empty action that does nothing; then no lines would be printed.
  3037. +
  3038. +
  3039. +File: gawk.info,  Node: Two Rules,  Next: More Complex,  Prev: Very Simple,  Up: Getting Started
  3040. +
  3041. +An Example with Two Rules
  3042. +=========================
  3043. +
  3044. +   The `awk' utility reads the input files one line at a time.  For
  3045. +each line, `awk' tries the patterns of each of the rules.  If several
  3046. +patterns match then several actions are run, in the order in which they
  3047. +appear in the `awk' program.  If no patterns match, then no actions are
  3048. +run.
  3049. +
  3050. +   After processing all the rules (perhaps none) that match the line,
  3051. +`awk' reads the next line (however, *note The `next' Statement: Next
  3052. +Statement.).  This continues until the end of the file is reached.
  3053. +
  3054. +   For example, the `awk' program:
  3055. +
  3056. +     /12/  { print $0 }
  3057. +     /21/  { print $0 }
  3058. +
  3059. +contains two rules.  The first rule has the string `12' as the pattern
  3060. +and `print $0' as the action.  The second rule has the string `21' as
  3061. +the pattern and also has `print $0' as the action.  Each rule's action
  3062. +is enclosed in its own pair of braces.
  3063. +
  3064. +   This `awk' program prints every line that contains the string `12'
  3065. +*or* the string `21'.  If a line contains both strings, it is printed
  3066. +twice, once by each rule.
  3067. +
  3068. +   If we run this program on our two sample data files, `BBS-list' and
  3069. +`inventory-shipped', as shown here:
  3070. +
  3071. +     awk '/12/ { print $0 }
  3072. +          /21/ { print $0 }' BBS-list inventory-shipped
  3073. +
  3074. +we get the following output:
  3075. +
  3076. +     aardvark     555-5553     1200/300          B
  3077. +     alpo-net     555-3412     2400/1200/300     A
  3078. +     barfly       555-7685     1200/300          A
  3079. +     bites        555-1675     2400/1200/300     A
  3080. +     core         555-2912     1200/300          C
  3081. +     fooey        555-1234     2400/1200/300     B
  3082. +     foot         555-6699     1200/300          B
  3083. +     macfoo       555-6480     1200/300          A
  3084. +     sdace        555-3430     2400/1200/300     A
  3085. +     sabafoo      555-2127     1200/300          C
  3086. +     sabafoo      555-2127     1200/300          C
  3087. +     Jan  21  36  64 620
  3088. +     Apr  21  70  74 514
  3089. +
  3090. +Note how the line in `BBS-list' beginning with `sabafoo' was printed
  3091. +twice, once for each rule.
  3092. +
  3093. +
  3094. +File: gawk.info,  Node: More Complex,  Next: Running gawk,  Prev: Two Rules,  Up: Getting Started
  3095. +
  3096. +A More Complex Example
  3097. +======================
  3098. +
  3099. +   Here is an example to give you an idea of what typical `awk'
  3100. +programs do.  This example shows how `awk' can be used to summarize,
  3101. +select, and rearrange the output of another utility.  It uses features
  3102. +that haven't been covered yet, so don't worry if you don't understand
  3103. +all the details.
  3104. +
  3105. +     ls -l | awk '$5 == "Nov" { sum += $4 }
  3106. +                  END { print sum }'
  3107. +
  3108. +   This command prints the total number of bytes in all the files in the
  3109. +current directory that were last modified in November (of any year).
  3110. +(In the C shell you would need to type a semicolon and then a backslash
  3111. +at the end of the first line; in a POSIX-compliant shell, such as the
  3112. +Bourne shell or the Bourne-Again shell, you can type the example as
  3113. +shown.)
  3114. +
  3115. +   The `ls -l' part of this example is a command that gives you a
  3116. +listing of the files in a directory, including file size and date.  Its
  3117. +output looks like this:
  3118. +
  3119. +     -rw-r--r--  1 close        1933 Nov  7 13:05 Makefile
  3120. +     -rw-r--r--  1 close       10809 Nov  7 13:03 gawk.h
  3121. +     -rw-r--r--  1 close         983 Apr 13 12:14 gawk.tab.h
  3122. +     -rw-r--r--  1 close       31869 Jun 15 12:20 gawk.y
  3123. +     -rw-r--r--  1 close       22414 Nov  7 13:03 gawk1.c
  3124. +     -rw-r--r--  1 close       37455 Nov  7 13:03 gawk2.c
  3125. +     -rw-r--r--  1 close       27511 Dec  9 13:07 gawk3.c
  3126. +     -rw-r--r--  1 close        7989 Nov  7 13:03 gawk4.c
  3127. +
  3128. +The first field contains read-write permissions, the second field
  3129. +contains the number of links to the file, and the third field
  3130. +identifies the owner of the file.  The fourth field contains the size
  3131. +of the file in bytes.  The fifth, sixth, and seventh fields contain the
  3132. +month, day, and time, respectively, that the file was last modified.
  3133. +Finally, the eighth field contains the name of the file.
  3134. +
  3135. +   The `$5 == "Nov"' in our `awk' program is an expression that tests
  3136. +whether the fifth field of the output from `ls -l' matches the string
  3137. +`Nov'.  Each time a line has the string `Nov' in its fifth field, the
  3138. +action `{ sum += $4 }' is performed.  This adds the fourth field (the
  3139. +file size) to the variable `sum'.  As a result, when `awk' has finished
  3140. +reading all the input lines, `sum' is the sum of the sizes of files
  3141. +whose lines matched the pattern.  (This works because `awk' variables
  3142. +are automatically initialized to zero.)
  3143. +
  3144. +   After the last line of output from `ls' has been processed, the
  3145. +`END' rule is executed, and the value of `sum' is printed.  In this
  3146. +example, the value of `sum' would be 80600.
  3147. +
  3148. +   These more advanced `awk' techniques are covered in later sections
  3149. +(*note Overview of Actions: Actions.).  Before you can move on to more
  3150. +advanced `awk' programming, you have to know how `awk' interprets your
  3151. +input and displays your output.  By manipulating fields and using
  3152. +`print' statements, you can produce some very useful and spectacular
  3153. +looking reports.
  3154. +
  3155. +
  3156. +File: gawk.info,  Node: Running gawk,  Next: Comments,  Prev: More Complex,  Up: Getting Started
  3157. +
  3158. +How to Run `awk' Programs
  3159. +=========================
  3160. +
  3161. +   There are several ways to run an `awk' program.  If the program is
  3162. +short, it is easiest to include it in the command that runs `awk', like
  3163. +this:
  3164. +
  3165. +     awk 'PROGRAM' INPUT-FILE1 INPUT-FILE2 ...
  3166. +
  3167. +where PROGRAM consists of a series of patterns and actions, as
  3168. +described earlier.
  3169. +
  3170. +   When the program is long, it is usually more convenient to put it in
  3171. +a file and run it with a command like this:
  3172. +
  3173. +     awk -f PROGRAM-FILE INPUT-FILE1 INPUT-FILE2 ...
  3174. +
  3175. +* Menu:
  3176. +
  3177. +* One-shot::                    Running a short throw-away `awk' program.
  3178. +* Read Terminal::               Using no input files (input from
  3179. +                                terminal instead).
  3180. +* Long::                        Putting permanent `awk' programs in files.
  3181. +* Executable Scripts::          Making self-contained `awk' programs.
  3182. +
  3183. +
  3184. +File: gawk.info,  Node: One-shot,  Next: Read Terminal,  Prev: Running gawk,  Up: Running gawk
  3185. +
  3186. +One-shot Throw-away `awk' Programs
  3187. +----------------------------------
  3188. +
  3189. +   Once you are familiar with `awk', you will often type simple
  3190. +programs at the moment you want to use them.  Then you can write the
  3191. +program as the first argument of the `awk' command, like this:
  3192. +
  3193. +     awk 'PROGRAM' INPUT-FILE1 INPUT-FILE2 ...
  3194. +
  3195. +where PROGRAM consists of a series of PATTERNS and ACTIONS, as
  3196. +described earlier.
  3197. +
  3198. +   This command format instructs the shell to start `awk' and use the
  3199. +PROGRAM to process records in the input file(s).  There are single
  3200. +quotes around PROGRAM so that the shell doesn't interpret any `awk'
  3201. +characters as special shell characters.  They also cause the shell to
  3202. +treat all of PROGRAM as a single argument for `awk' and allow PROGRAM
  3203. +to be more than one line long.
  3204. +
  3205. +   This format is also useful for running short or medium-sized `awk'
  3206. +programs from shell scripts, because it avoids the need for a separate
  3207. +file for the `awk' program.  A self-contained shell script is more
  3208. +reliable since there are no other files to misplace.
  3209. +
  3210. +
  3211. +File: gawk.info,  Node: Read Terminal,  Next: Long,  Prev: One-shot,  Up: Running gawk
  3212. +
  3213. +Running `awk' without Input Files
  3214. +---------------------------------
  3215. +
  3216. +   You can also run `awk' without any input files.  If you type the
  3217. +command line:
  3218. +
  3219. +     awk 'PROGRAM'
  3220. +
  3221. +then `awk' applies the PROGRAM to the "standard input", which usually
  3222. +means whatever you type on the terminal.  This continues until you
  3223. +indicate end-of-file by typing `Control-d'.
  3224. +
  3225. +   For example, if you execute this command:
  3226. +
  3227. +     awk '/th/'
  3228. +
  3229. +whatever you type next is taken as data for that `awk' program.  If you
  3230. +go on to type the following data:
  3231. +
  3232. +     Kathy
  3233. +     Ben
  3234. +     Tom
  3235. +     Beth
  3236. +     Seth
  3237. +     Karen
  3238. +     Thomas
  3239. +     `Control-d'
  3240. +
  3241. +then `awk' prints this output:
  3242. +
  3243. +     Kathy
  3244. +     Beth
  3245. +     Seth
  3246. +
  3247. +as matching the pattern `th'.  Notice that it did not recognize
  3248. +`Thomas' as matching the pattern.  The `awk' language is "case
  3249. +sensitive", and matches patterns exactly.  (However, you can override
  3250. +this with the variable `IGNORECASE'.  *Note Case-sensitivity in
  3251. +Matching: Case-sensitivity.)
  3252. +
  3253. +
  3254. +File: gawk.info,  Node: Long,  Next: Executable Scripts,  Prev: Read Terminal,  Up: Running gawk
  3255. +
  3256. +Running Long Programs
  3257. +---------------------
  3258. +
  3259. +   Sometimes your `awk' programs can be very long.  In this case it is
  3260. +more convenient to put the program into a separate file.  To tell `awk'
  3261. +to use that file for its program, you type:
  3262. +
  3263. +     awk -f SOURCE-FILE INPUT-FILE1 INPUT-FILE2 ...
  3264. +
  3265. +   The `-f' instructs the `awk' utility to get the `awk' program from
  3266. +the file SOURCE-FILE.  Any file name can be used for SOURCE-FILE.  For
  3267. +example, you could put the program:
  3268. +
  3269. +     /th/
  3270. +
  3271. +into the file `th-prog'.  Then this command:
  3272. +
  3273. +     awk -f th-prog
  3274. +
  3275. +does the same thing as this one:
  3276. +
  3277. +     awk '/th/'
  3278. +
  3279. +which was explained earlier (*note Running `awk' without Input Files:
  3280. +Read Terminal.).  Note that you don't usually need single quotes around
  3281. +the file name that you specify with `-f', because most file names don't
  3282. +contain any of the shell's special characters.  Notice that in
  3283. +`th-prog', the `awk' program did not have single quotes around it.  The
  3284. +quotes are only needed for programs that are provided on the `awk'
  3285. +command line.
  3286. +
  3287. +   If you want to identify your `awk' program files clearly as such,
  3288. +you can add the extension `.awk' to the file name.  This doesn't affect
  3289. +the execution of the `awk' program, but it does make "housekeeping"
  3290. +easier.
  3291. +
  3292. +
  3293. +File: gawk.info,  Node: Executable Scripts,  Prev: Long,  Up: Running gawk
  3294. +
  3295. +Executable `awk' Programs
  3296. +-------------------------
  3297. +
  3298. +   Once you have learned `awk', you may want to write self-contained
  3299. +`awk' scripts, using the `#!' script mechanism.  You can do this on
  3300. +many Unix systems (1) (and someday on GNU).
  3301. +
  3302. +   For example, you could create a text file named `hello', containing
  3303. +the following (where `BEGIN' is a feature we have not yet discussed):
  3304. +
  3305. +     #! /bin/awk -f
  3306. +     
  3307. +     # a sample awk program
  3308. +     BEGIN    { print "hello, world" }
  3309. +
  3310. +After making this file executable (with the `chmod' command), you can
  3311. +simply type:
  3312. +
  3313. +     hello
  3314. +
  3315. +at the shell, and the system will arrange to run `awk' (2) as if you
  3316. +had typed:
  3317. +
  3318. +     awk -f hello
  3319. +
  3320. +Self-contained `awk' scripts are useful when you want to write a
  3321. +program which users can invoke without knowing that the program is
  3322. +written in `awk'.
  3323. +
  3324. +   If your system does not support the `#!' mechanism, you can get a
  3325. +similar effect using a regular shell script.  It would look something
  3326. +like this:
  3327. +
  3328. +     : The colon makes sure this script is executed by the Bourne shell.
  3329. +     awk 'PROGRAM' "$@"
  3330. +
  3331. +   Using this technique, it is *vital* to enclose the PROGRAM in single
  3332. +quotes to protect it from interpretation by the shell.  If you omit the
  3333. +quotes, only a shell wizard can predict the results.
  3334. +
  3335. +   The `"$@"' causes the shell to forward all the command line
  3336. +arguments to the `awk' program, without interpretation.  The first
  3337. +line, which starts with a colon, is used so that this shell script will
  3338. +work even if invoked by a user who uses the C shell.
  3339. +
  3340. +   ---------- Footnotes ----------
  3341. +
  3342. +   (1)  The `#!' mechanism works on Unix systems derived from Berkeley
  3343. +Unix, System V Release 4, and some System V Release 3 systems.
  3344. +
  3345. +   (2)  The line beginning with `#!' lists the full pathname of an
  3346. +interpreter to be run, and an optional initial command line argument to
  3347. +pass to that interpreter.  The operating system then runs the
  3348. +interpreter with the given argument and the full argument list of the
  3349. +executed program.  The first argument in the list is the full pathname
  3350. +of the `awk' program.  The rest of the argument list will either be
  3351. +options to `awk', or data files, or both.
  3352. +
  3353. +
  3354. +File: gawk.info,  Node: Comments,  Next: Statements/Lines,  Prev: Running gawk,  Up: Getting Started
  3355. +
  3356. +Comments in `awk' Programs
  3357. +==========================
  3358. +
  3359. +   A "comment" is some text that is included in a program for the sake
  3360. +of human readers, and that is not really part of the program.  Comments
  3361. +can explain what the program does, and how it works.  Nearly all
  3362. +programming languages have provisions for comments, because programs are
  3363. +typically hard to understand without their extra help.
  3364. +
  3365. +   In the `awk' language, a comment starts with the sharp sign
  3366. +character, `#', and continues to the end of the line.  The `awk'
  3367. +language ignores the rest of a line following a sharp sign.  For
  3368. +example, we could have put the following into `th-prog':
  3369. +
  3370. +     # This program finds records containing the pattern `th'.  This is how
  3371. +     # you continue comments on additional lines.
  3372. +     /th/
  3373. +
  3374. +   You can put comment lines into keyboard-composed throw-away `awk'
  3375. +programs also, but this usually isn't very useful; the purpose of a
  3376. +comment is to help you or another person understand the program at a
  3377. +later time.
  3378. +
  3379. diff -rup --new-file baseline/fsf/gawk/gawk.info-2 amiga/fsf/gawk/gawk.info-2
  3380. --- baseline/fsf/gawk/gawk.info-2    Wed Dec 31 17:00:00 1969
  3381. +++ amiga/fsf/gawk/gawk.info-2    Sat Sep 28 00:00:00 1996
  3382. @@ -0,0 +1,1236 @@
  3383. +This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  3384. +file /gnu-src/gawk-2.15.6/gawk.texi.
  3385. +
  3386. +   This file documents `awk', a program that you can use to select
  3387. +particular records in a file and perform operations upon them.
  3388. +
  3389. +   This is Edition 0.15 of `The GAWK Manual',
  3390. +for the 2.15 version of the GNU implementation
  3391. +of AWK.
  3392. +
  3393. +   Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  3394. +
  3395. +   Permission is granted to make and distribute verbatim copies of this
  3396. +manual provided the copyright notice and this permission notice are
  3397. +preserved on all copies.
  3398. +
  3399. +   Permission is granted to copy and distribute modified versions of
  3400. +this manual under the conditions for verbatim copying, provided that
  3401. +the entire resulting derived work is distributed under the terms of a
  3402. +permission notice identical to this one.
  3403. +
  3404. +   Permission is granted to copy and distribute translations of this
  3405. +manual into another language, under the above conditions for modified
  3406. +versions, except that this permission notice may be stated in a
  3407. +translation approved by the Foundation.
  3408. +
  3409. +
  3410. +File: gawk.info,  Node: Statements/Lines,  Next: When,  Prev: Comments,  Up: Getting Started
  3411. +
  3412. +`awk' Statements versus Lines
  3413. +=============================
  3414. +
  3415. +   Most often, each line in an `awk' program is a separate statement or
  3416. +separate rule, like this:
  3417. +
  3418. +     awk '/12/  { print $0 }
  3419. +          /21/  { print $0 }' BBS-list inventory-shipped
  3420. +
  3421. +   But sometimes statements can be more than one line, and lines can
  3422. +contain several statements.  You can split a statement into multiple
  3423. +lines by inserting a newline after any of the following:
  3424. +
  3425. +     ,    {    ?    :    ||    &&    do    else
  3426. +
  3427. +A newline at any other point is considered the end of the statement.
  3428. +(Splitting lines after `?' and `:' is a minor `gawk' extension.  The
  3429. +`?' and `:' referred to here is the three operand conditional
  3430. +expression described in *Note Conditional Expressions: Conditional Exp.)
  3431. +
  3432. +   If you would like to split a single statement into two lines at a
  3433. +point where a newline would terminate it, you can "continue" it by
  3434. +ending the first line with a backslash character, `\'.  This is allowed
  3435. +absolutely anywhere in the statement, even in the middle of a string or
  3436. +regular expression.  For example:
  3437. +
  3438. +     awk '/This program is too long, so continue it\
  3439. +      on the next line/ { print $1 }'
  3440. +
  3441. +We have generally not used backslash continuation in the sample
  3442. +programs in this manual.  Since in `gawk' there is no limit on the
  3443. +length of a line, it is never strictly necessary; it just makes
  3444. +programs prettier.  We have preferred to make them even more pretty by
  3445. +keeping the statements short.  Backslash continuation is most useful
  3446. +when your `awk' program is in a separate source file, instead of typed
  3447. +in on the command line.  You should also note that many `awk'
  3448. +implementations are more picky about where you may use backslash
  3449. +continuation.  For maximal portability of your `awk' programs, it is
  3450. +best not to split your lines in the middle of a regular expression or a
  3451. +string.
  3452. +
  3453. +   *Warning: backslash continuation does not work as described above
  3454. +with the C shell.*  Continuation with backslash works for `awk'
  3455. +programs in files, and also for one-shot programs *provided* you are
  3456. +using a POSIX-compliant shell, such as the Bourne shell or the
  3457. +Bourne-again shell.  But the C shell used on Berkeley Unix behaves
  3458. +differently!  There, you must use two backslashes in a row, followed by
  3459. +a newline.
  3460. +
  3461. +   When `awk' statements within one rule are short, you might want to
  3462. +put more than one of them on a line.  You do this by separating the
  3463. +statements with a semicolon, `;'.  This also applies to the rules
  3464. +themselves.  Thus, the previous program could have been written:
  3465. +
  3466. +     /12/ { print $0 } ; /21/ { print $0 }
  3467. +
  3468. +*Note:* the requirement that rules on the same line must be separated
  3469. +with a semicolon is a recent change in the `awk' language; it was done
  3470. +for consistency with the treatment of statements within an action.
  3471. +
  3472. +
  3473. +File: gawk.info,  Node: When,  Prev: Statements/Lines,  Up: Getting Started
  3474. +
  3475. +When to Use `awk'
  3476. +=================
  3477. +
  3478. +   You might wonder how `awk' might be useful for you.  Using additional
  3479. +utility programs, more advanced patterns, field separators, arithmetic
  3480. +statements, and other selection criteria, you can produce much more
  3481. +complex output.  The `awk' language is very useful for producing
  3482. +reports from large amounts of raw data, such as summarizing information
  3483. +from the output of other utility programs like `ls'.  (*Note A More
  3484. +Complex Example: More Complex.)
  3485. +
  3486. +   Programs written with `awk' are usually much smaller than they would
  3487. +be in other languages.  This makes `awk' programs easy to compose and
  3488. +use.  Often `awk' programs can be quickly composed at your terminal,
  3489. +used once, and thrown away.  Since `awk' programs are interpreted, you
  3490. +can avoid the usually lengthy edit-compile-test-debug cycle of software
  3491. +development.
  3492. +
  3493. +   Complex programs have been written in `awk', including a complete
  3494. +retargetable assembler for 8-bit microprocessors (*note Glossary::., for
  3495. +more information) and a microcode assembler for a special purpose Prolog
  3496. +computer.  However, `awk''s capabilities are strained by tasks of such
  3497. +complexity.
  3498. +
  3499. +   If you find yourself writing `awk' scripts of more than, say, a few
  3500. +hundred lines, you might consider using a different programming
  3501. +language.  Emacs Lisp is a good choice if you need sophisticated string
  3502. +or pattern matching capabilities.  The shell is also good at string and
  3503. +pattern matching; in addition, it allows powerful use of the system
  3504. +utilities.  More conventional languages, such as C, C++, and Lisp, offer
  3505. +better facilities for system programming and for managing the complexity
  3506. +of large programs.  Programs in these languages may require more lines
  3507. +of source code than the equivalent `awk' programs, but they are easier
  3508. +to maintain and usually run more efficiently.
  3509. +
  3510. +
  3511. +File: gawk.info,  Node: Reading Files,  Next: Printing,  Prev: Getting Started,  Up: Top
  3512. +
  3513. +Reading Input Files
  3514. +*******************
  3515. +
  3516. +   In the typical `awk' program, all input is read either from the
  3517. +standard input (by default the keyboard, but often a pipe from another
  3518. +command) or from files whose names you specify on the `awk' command
  3519. +line.  If you specify input files, `awk' reads them in order, reading
  3520. +all the data from one before going on to the next.  The name of the
  3521. +current input file can be found in the built-in variable `FILENAME'
  3522. +(*note Built-in Variables::.).
  3523. +
  3524. +   The input is read in units called records, and processed by the
  3525. +rules one record at a time.  By default, each record is one line.  Each
  3526. +record is split automatically into fields, to make it more convenient
  3527. +for a rule to work on its parts.
  3528. +
  3529. +   On rare occasions you will need to use the `getline' command, which
  3530. +can do explicit input from any number of files (*note Explicit Input
  3531. +with `getline': Getline.).
  3532. +
  3533. +* Menu:
  3534. +
  3535. +* Records::                     Controlling how data is split into records.
  3536. +* Fields::                      An introduction to fields.
  3537. +* Non-Constant Fields::         Non-constant Field Numbers.
  3538. +* Changing Fields::             Changing the Contents of a Field.
  3539. +* Field Separators::            The field separator and how to change it.
  3540. +* Constant Size::               Reading constant width data.
  3541. +* Multiple Line::               Reading multi-line records.
  3542. +* Getline::                     Reading files under explicit program control
  3543. +                                using the `getline' function.
  3544. +* Close Input::                 Closing an input file (so you can read from
  3545. +                                the beginning once more).
  3546. +
  3547. +
  3548. +File: gawk.info,  Node: Records,  Next: Fields,  Prev: Reading Files,  Up: Reading Files
  3549. +
  3550. +How Input is Split into Records
  3551. +===============================
  3552. +
  3553. +   The `awk' language divides its input into records and fields.
  3554. +Records are separated by a character called the "record separator".  By
  3555. +default, the record separator is the newline character, defining a
  3556. +record to be a single line of text.
  3557. +
  3558. +   Sometimes you may want to use a different character to separate your
  3559. +records.  You can use a different character by changing the built-in
  3560. +variable `RS'.  The value of `RS' is a string that says how to separate
  3561. +records; the default value is `"\n"', the string containing just a
  3562. +newline character.  This is why records are, by default, single lines.
  3563. +
  3564. +   `RS' can have any string as its value, but only the first character
  3565. +of the string is used as the record separator.  The other characters are
  3566. +ignored.  `RS' is exceptional in this regard; `awk' uses the full value
  3567. +of all its other built-in variables.
  3568. +
  3569. +   You can change the value of `RS' in the `awk' program with the
  3570. +assignment operator, `=' (*note Assignment Expressions: Assignment
  3571. +Ops.).  The new record-separator character should be enclosed in
  3572. +quotation marks to make a string constant.  Often the right time to do
  3573. +this is at the beginning of execution, before any input has been
  3574. +processed, so that the very first record will be read with the proper
  3575. +separator.  To do this, use the special `BEGIN' pattern (*note `BEGIN'
  3576. +and `END' Special Patterns: BEGIN/END.).  For example:
  3577. +
  3578. +     awk 'BEGIN { RS = "/" } ; { print $0 }' BBS-list
  3579. +
  3580. +changes the value of `RS' to `"/"', before reading any input.  This is
  3581. +a string whose first character is a slash; as a result, records are
  3582. +separated by slashes.  Then the input file is read, and the second rule
  3583. +in the `awk' program (the action with no pattern) prints each record.
  3584. +Since each `print' statement adds a newline at the end of its output,
  3585. +the effect of this `awk' program is to copy the input with each slash
  3586. +changed to a newline.
  3587. +
  3588. +   Another way to change the record separator is on the command line,
  3589. +using the variable-assignment feature (*note Invoking `awk': Command
  3590. +Line.).
  3591. +
  3592. +     awk '{ print $0 }' RS="/" BBS-list
  3593. +
  3594. +This sets `RS' to `/' before processing `BBS-list'.
  3595. +
  3596. +   Reaching the end of an input file terminates the current input
  3597. +record, even if the last character in the file is not the character in
  3598. +`RS'.
  3599. +
  3600. +   The empty string, `""' (a string of no characters), has a special
  3601. +meaning as the value of `RS': it means that records are separated only
  3602. +by blank lines.  *Note Multiple-Line Records: Multiple Line, for more
  3603. +details.
  3604. +
  3605. +   The `awk' utility keeps track of the number of records that have
  3606. +been read so far from the current input file.  This value is stored in a
  3607. +built-in variable called `FNR'.  It is reset to zero when a new file is
  3608. +started.  Another built-in variable, `NR', is the total number of input
  3609. +records read so far from all files.  It starts at zero but is never
  3610. +automatically reset to zero.
  3611. +
  3612. +   If you change the value of `RS' in the middle of an `awk' run, the
  3613. +new value is used to delimit subsequent records, but the record
  3614. +currently being processed (and records already processed) are not
  3615. +affected.
  3616. +
  3617. +
  3618. +File: gawk.info,  Node: Fields,  Next: Non-Constant Fields,  Prev: Records,  Up: Reading Files
  3619. +
  3620. +Examining Fields
  3621. +================
  3622. +
  3623. +   When `awk' reads an input record, the record is automatically
  3624. +separated or "parsed" by the interpreter into chunks called "fields".
  3625. +By default, fields are separated by whitespace, like words in a line.
  3626. +Whitespace in `awk' means any string of one or more spaces and/or tabs;
  3627. +other characters such as newline, formfeed, and so on, that are
  3628. +considered whitespace by other languages are *not* considered
  3629. +whitespace by `awk'.
  3630. +
  3631. +   The purpose of fields is to make it more convenient for you to refer
  3632. +to these pieces of the record.  You don't have to use them--you can
  3633. +operate on the whole record if you wish--but fields are what make
  3634. +simple `awk' programs so powerful.
  3635. +
  3636. +   To refer to a field in an `awk' program, you use a dollar-sign, `$',
  3637. +followed by the number of the field you want.  Thus, `$1' refers to the
  3638. +first field, `$2' to the second, and so on.  For example, suppose the
  3639. +following is a line of input:
  3640. +
  3641. +     This seems like a pretty nice example.
  3642. +
  3643. +Here the first field, or `$1', is `This'; the second field, or `$2', is
  3644. +`seems'; and so on.  Note that the last field, `$7', is `example.'.
  3645. +Because there is no space between the `e' and the `.', the period is
  3646. +considered part of the seventh field.
  3647. +
  3648. +   No matter how many fields there are, the last field in a record can
  3649. +be represented by `$NF'.  So, in the example above, `$NF' would be the
  3650. +same as `$7', which is `example.'.  Why this works is explained below
  3651. +(*note Non-constant Field Numbers: Non-Constant Fields.).  If you try
  3652. +to refer to a field beyond the last one, such as `$8' when the record
  3653. +has only 7 fields, you get the empty string.
  3654. +
  3655. +   Plain `NF', with no `$', is a built-in variable whose value is the
  3656. +number of fields in the current record.
  3657. +
  3658. +   `$0', which looks like an attempt to refer to the zeroth field, is a
  3659. +special case: it represents the whole input record.  This is what you
  3660. +would use if you weren't interested in fields.
  3661. +
  3662. +   Here are some more examples:
  3663. +
  3664. +     awk '$1 ~ /foo/ { print $0 }' BBS-list
  3665. +
  3666. +This example prints each record in the file `BBS-list' whose first
  3667. +field contains the string `foo'.  The operator `~' is called a
  3668. +"matching operator" (*note Comparison Expressions: Comparison Ops.); it
  3669. +tests whether a string (here, the field `$1') matches a given regular
  3670. +expression.
  3671. +
  3672. +   By contrast, the following example:
  3673. +
  3674. +     awk '/foo/ { print $1, $NF }' BBS-list
  3675. +
  3676. +looks for `foo' in *the entire record* and prints the first field and
  3677. +the last field for each input record containing a match.
  3678. +
  3679. +
  3680. +File: gawk.info,  Node: Non-Constant Fields,  Next: Changing Fields,  Prev: Fields,  Up: Reading Files
  3681. +
  3682. +Non-constant Field Numbers
  3683. +==========================
  3684. +
  3685. +   The number of a field does not need to be a constant.  Any
  3686. +expression in the `awk' language can be used after a `$' to refer to a
  3687. +field.  The value of the expression specifies the field number.  If the
  3688. +value is a string, rather than a number, it is converted to a number.
  3689. +Consider this example:
  3690. +
  3691. +     awk '{ print $NR }'
  3692. +
  3693. +Recall that `NR' is the number of records read so far: 1 in the first
  3694. +record, 2 in the second, etc.  So this example prints the first field
  3695. +of the first record, the second field of the second record, and so on.
  3696. +For the twentieth record, field number 20 is printed; most likely, the
  3697. +record has fewer than 20 fields, so this prints a blank line.
  3698. +
  3699. +   Here is another example of using expressions as field numbers:
  3700. +
  3701. +     awk '{ print $(2*2) }' BBS-list
  3702. +
  3703. +   The `awk' language must evaluate the expression `(2*2)' and use its
  3704. +value as the number of the field to print.  The `*' sign represents
  3705. +multiplication, so the expression `2*2' evaluates to 4.  The
  3706. +parentheses are used so that the multiplication is done before the `$'
  3707. +operation; they are necessary whenever there is a binary operator in
  3708. +the field-number expression.  This example, then, prints the hours of
  3709. +operation (the fourth field) for every line of the file `BBS-list'.
  3710. +
  3711. +   If the field number you compute is zero, you get the entire record.
  3712. +Thus, `$(2-2)' has the same value as `$0'.  Negative field numbers are
  3713. +not allowed.
  3714. +
  3715. +   The number of fields in the current record is stored in the built-in
  3716. +variable `NF' (*note Built-in Variables::.).  The expression `$NF' is
  3717. +not a special feature: it is the direct consequence of evaluating `NF'
  3718. +and using its value as a field number.
  3719. +
  3720. +
  3721. +File: gawk.info,  Node: Changing Fields,  Next: Field Separators,  Prev: Non-Constant Fields,  Up: Reading Files
  3722. +
  3723. +Changing the Contents of a Field
  3724. +================================
  3725. +
  3726. +   You can change the contents of a field as seen by `awk' within an
  3727. +`awk' program; this changes what `awk' perceives as the current input
  3728. +record.  (The actual input is untouched: `awk' never modifies the input
  3729. +file.)
  3730. +
  3731. +   Consider this example:
  3732. +
  3733. +     awk '{ $3 = $2 - 10; print $2, $3 }' inventory-shipped
  3734. +
  3735. +The `-' sign represents subtraction, so this program reassigns field
  3736. +three, `$3', to be the value of field two minus ten, `$2 - 10'.  (*Note
  3737. +Arithmetic Operators: Arithmetic Ops.) Then field two, and the new
  3738. +value for field three, are printed.
  3739. +
  3740. +   In order for this to work, the text in field `$2' must make sense as
  3741. +a number; the string of characters must be converted to a number in
  3742. +order for the computer to do arithmetic on it.  The number resulting
  3743. +from the subtraction is converted back to a string of characters which
  3744. +then becomes field three.  *Note Conversion of Strings and Numbers:
  3745. +Conversion.
  3746. +
  3747. +   When you change the value of a field (as perceived by `awk'), the
  3748. +text of the input record is recalculated to contain the new field where
  3749. +the old one was.  Therefore, `$0' changes to reflect the altered field.
  3750. +Thus,
  3751. +
  3752. +     awk '{ $2 = $2 - 10; print $0 }' inventory-shipped
  3753. +
  3754. +prints a copy of the input file, with 10 subtracted from the second
  3755. +field of each line.
  3756. +
  3757. +   You can also assign contents to fields that are out of range.  For
  3758. +example:
  3759. +
  3760. +     awk '{ $6 = ($5 + $4 + $3 + $2) ; print $6 }' inventory-shipped
  3761. +
  3762. +We've just created `$6', whose value is the sum of fields `$2', `$3',
  3763. +`$4', and `$5'.  The `+' sign represents addition.  For the file
  3764. +`inventory-shipped', `$6' represents the total number of parcels
  3765. +shipped for a particular month.
  3766. +
  3767. +   Creating a new field changes the internal `awk' copy of the current
  3768. +input record--the value of `$0'.  Thus, if you do `print $0' after
  3769. +adding a field, the record printed includes the new field, with the
  3770. +appropriate number of field separators between it and the previously
  3771. +existing fields.
  3772. +
  3773. +   This recomputation affects and is affected by several features not
  3774. +yet discussed, in particular, the "output field separator", `OFS',
  3775. +which is used to separate the fields (*note Output Separators::.), and
  3776. +`NF' (the number of fields; *note Examining Fields: Fields.).  For
  3777. +example, the value of `NF' is set to the number of the highest field
  3778. +you create.
  3779. +
  3780. +   Note, however, that merely *referencing* an out-of-range field does
  3781. +*not* change the value of either `$0' or `NF'.  Referencing an
  3782. +out-of-range field merely produces a null string.  For example:
  3783. +
  3784. +     if ($(NF+1) != "")
  3785. +         print "can't happen"
  3786. +     else
  3787. +         print "everything is normal"
  3788. +
  3789. +should print `everything is normal', because `NF+1' is certain to be
  3790. +out of range.  (*Note The `if' Statement: If Statement, for more
  3791. +information about `awk''s `if-else' statements.)
  3792. +
  3793. +   It is important to note that assigning to a field will change the
  3794. +value of `$0', but will not change the value of `NF', even when you
  3795. +assign the null string to a field.  For example:
  3796. +
  3797. +     echo a b c d | awk '{ OFS = ":"; $2 = "" ; print ; print NF }'
  3798. +
  3799. +prints
  3800. +
  3801. +     a::c:d
  3802. +     4
  3803. +
  3804. +The field is still there, it just has an empty value.  You can tell
  3805. +because there are two colons in a row.
  3806. +
  3807. +
  3808. +File: gawk.info,  Node: Field Separators,  Next: Constant Size,  Prev: Changing Fields,  Up: Reading Files
  3809. +
  3810. +Specifying how Fields are Separated
  3811. +===================================
  3812. +
  3813. +   (This section is rather long; it describes one of the most
  3814. +fundamental operations in `awk'.  If you are a novice with `awk', we
  3815. +recommend that you re-read this section after you have studied the
  3816. +section on regular expressions, *Note Regular Expressions as Patterns:
  3817. +Regexp.)
  3818. +
  3819. +   The way `awk' splits an input record into fields is controlled by
  3820. +the "field separator", which is a single character or a regular
  3821. +expression.  `awk' scans the input record for matches for the
  3822. +separator; the fields themselves are the text between the matches.  For
  3823. +example, if the field separator is `oo', then the following line:
  3824. +
  3825. +     moo goo gai pan
  3826. +
  3827. +would be split into three fields: `m', ` g' and ` gai  pan'.
  3828. +
  3829. +   The field separator is represented by the built-in variable `FS'.
  3830. +Shell programmers take note!  `awk' does not use the name `IFS' which
  3831. +is used by the shell.
  3832. +
  3833. +   You can change the value of `FS' in the `awk' program with the
  3834. +assignment operator, `=' (*note Assignment Expressions: Assignment
  3835. +Ops.).  Often the right time to do this is at the beginning of
  3836. +execution, before any input has been processed, so that the very first
  3837. +record will be read with the proper separator.  To do this, use the
  3838. +special `BEGIN' pattern (*note `BEGIN' and `END' Special Patterns:
  3839. +BEGIN/END.).  For example, here we set the value of `FS' to the string
  3840. +`","':
  3841. +
  3842. +     awk 'BEGIN { FS = "," } ; { print $2 }'
  3843. +
  3844. +Given the input line,
  3845. +
  3846. +     John Q. Smith, 29 Oak St., Walamazoo, MI 42139
  3847. +
  3848. +this `awk' program extracts the string ` 29 Oak St.'.
  3849. +
  3850. +   Sometimes your input data will contain separator characters that
  3851. +don't separate fields the way you thought they would.  For instance, the
  3852. +person's name in the example we've been using might have a title or
  3853. +suffix attached, such as `John Q. Smith, LXIX'.  From input containing
  3854. +such a name:
  3855. +
  3856. +     John Q. Smith, LXIX, 29 Oak St., Walamazoo, MI 42139
  3857. +
  3858. +the previous sample program would extract ` LXIX', instead of ` 29 Oak
  3859. +St.'.  If you were expecting the program to print the address, you
  3860. +would be surprised.  So choose your data layout and separator
  3861. +characters carefully to prevent such problems.
  3862. +
  3863. +   As you know, by default, fields are separated by whitespace sequences
  3864. +(spaces and tabs), not by single spaces: two spaces in a row do not
  3865. +delimit an empty field.  The default value of the field separator is a
  3866. +string `" "' containing a single space.  If this value were interpreted
  3867. +in the usual way, each space character would separate fields, so two
  3868. +spaces in a row would make an empty field between them.  The reason
  3869. +this does not happen is that a single space as the value of `FS' is a
  3870. +special case: it is taken to specify the default manner of delimiting
  3871. +fields.
  3872. +
  3873. +   If `FS' is any other single character, such as `","', then each
  3874. +occurrence of that character separates two fields.  Two consecutive
  3875. +occurrences delimit an empty field.  If the character occurs at the
  3876. +beginning or the end of the line, that too delimits an empty field.  The
  3877. +space character is the only single character which does not follow these
  3878. +rules.
  3879. +
  3880. +   More generally, the value of `FS' may be a string containing any
  3881. +regular expression.  Then each match in the record for the regular
  3882. +expression separates fields.  For example, the assignment:
  3883. +
  3884. +     FS = ", \t"
  3885. +
  3886. +makes every area of an input line that consists of a comma followed by a
  3887. +space and a tab, into a field separator.  (`\t' stands for a tab.)
  3888. +
  3889. +   For a less trivial example of a regular expression, suppose you want
  3890. +single spaces to separate fields the way single commas were used above.
  3891. +You can set `FS' to `"[ ]"'.  This regular expression matches a single
  3892. +space and nothing else.
  3893. +
  3894. +   `FS' can be set on the command line.  You use the `-F' argument to
  3895. +do so.  For example:
  3896. +
  3897. +     awk -F, 'PROGRAM' INPUT-FILES
  3898. +
  3899. +sets `FS' to be the `,' character.  Notice that the argument uses a
  3900. +capital `F'.  Contrast this with `-f', which specifies a file
  3901. +containing an `awk' program.  Case is significant in command options:
  3902. +the `-F' and `-f' options have nothing to do with each other.  You can
  3903. +use both options at the same time to set the `FS' argument *and* get an
  3904. +`awk' program from a file.
  3905. +
  3906. +   The value used for the argument to `-F' is processed in exactly the
  3907. +same way as assignments to the built-in variable `FS'.  This means that
  3908. +if the field separator contains special characters, they must be escaped
  3909. +appropriately.  For example, to use a `\' as the field separator, you
  3910. +would have to type:
  3911. +
  3912. +     # same as FS = "\\"
  3913. +     awk -F\\\\ '...' files ...
  3914. +
  3915. +Since `\' is used for quoting in the shell, `awk' will see `-F\\'.
  3916. +Then `awk' processes the `\\' for escape characters (*note Constant
  3917. +Expressions: Constants.), finally yielding a single `\' to be used for
  3918. +the field separator.
  3919. +
  3920. +   As a special case, in compatibility mode (*note Invoking `awk':
  3921. +Command Line.), if the argument to `-F' is `t', then `FS' is set to the
  3922. +tab character.  (This is because if you type `-F\t', without the quotes,
  3923. +at the shell, the `\' gets deleted, so `awk' figures that you really
  3924. +want your fields to be separated with tabs, and not `t's.  Use `-v
  3925. +FS="t"' on the command line if you really do want to separate your
  3926. +fields with `t's.)
  3927. +
  3928. +   For example, let's use an `awk' program file called `baud.awk' that
  3929. +contains the pattern `/300/', and the action `print $1'.  Here is the
  3930. +program:
  3931. +
  3932. +     /300/   { print $1 }
  3933. +
  3934. +   Let's also set `FS' to be the `-' character, and run the program on
  3935. +the file `BBS-list'.  The following command prints a list of the names
  3936. +of the bulletin boards that operate at 300 baud and the first three
  3937. +digits of their phone numbers:
  3938. +
  3939. +     awk -F- -f baud.awk BBS-list
  3940. +
  3941. +It produces this output:
  3942. +
  3943. +     aardvark     555
  3944. +     alpo
  3945. +     barfly       555
  3946. +     bites        555
  3947. +     camelot      555
  3948. +     core         555
  3949. +     fooey        555
  3950. +     foot         555
  3951. +     macfoo       555
  3952. +     sdace        555
  3953. +     sabafoo      555
  3954. +
  3955. +Note the second line of output.  If you check the original file, you
  3956. +will see that the second line looked like this:
  3957. +
  3958. +     alpo-net     555-3412     2400/1200/300     A
  3959. +
  3960. +   The `-' as part of the system's name was used as the field
  3961. +separator, instead of the `-' in the phone number that was originally
  3962. +intended.  This demonstrates why you have to be careful in choosing
  3963. +your field and record separators.
  3964. +
  3965. +   The following program searches the system password file, and prints
  3966. +the entries for users who have no password:
  3967. +
  3968. +     awk -F: '$2 == ""' /etc/passwd
  3969. +
  3970. +Here we use the `-F' option on the command line to set the field
  3971. +separator.  Note that fields in `/etc/passwd' are separated by colons.
  3972. +The second field represents a user's encrypted password, but if the
  3973. +field is empty, that user has no password.
  3974. +
  3975. +   According to the POSIX standard, `awk' is supposed to behave as if
  3976. +each record is split into fields at the time that it is read.  In
  3977. +particular, this means that you can change the value of `FS' after a
  3978. +record is read, but before any of the fields are referenced.  The value
  3979. +of the fields (i.e. how they were split) should reflect the old value
  3980. +of `FS', not the new one.
  3981. +
  3982. +   However, many implementations of `awk' do not do this.  Instead,
  3983. +they defer splitting the fields until a field reference actually
  3984. +happens, using the *current* value of `FS'!  This behavior can be
  3985. +difficult to diagnose. The following example illustrates the results of
  3986. +the two methods.  (The `sed' command prints just the first line of
  3987. +`/etc/passwd'.)
  3988. +
  3989. +     sed 1q /etc/passwd | awk '{ FS = ":" ; print $1 }'
  3990. +
  3991. +will usually print
  3992. +
  3993. +     root
  3994. +
  3995. +on an incorrect implementation of `awk', while `gawk' will print
  3996. +something like
  3997. +
  3998. +     root:nSijPlPhZZwgE:0:0:Root:/:
  3999. +
  4000. +   There is an important difference between the two cases of `FS = " "'
  4001. +(a single blank) and `FS = "[ \t]+"' (which is a regular expression
  4002. +matching one or more blanks or tabs).  For both values of `FS', fields
  4003. +are separated by runs of blanks and/or tabs.  However, when the value of
  4004. +`FS' is `" "', `awk' will strip leading and trailing whitespace from
  4005. +the record, and then decide where the fields are.
  4006. +
  4007. +   For example, the following expression prints `b':
  4008. +
  4009. +     echo ' a b c d ' | awk '{ print $2 }'
  4010. +
  4011. +However, the following prints `a':
  4012. +
  4013. +     echo ' a b c d ' | awk 'BEGIN { FS = "[ \t]+" } ; { print $2 }'
  4014. +
  4015. +In this case, the first field is null.
  4016. +
  4017. +   The stripping of leading and trailing whitespace also comes into
  4018. +play whenever `$0' is recomputed.  For instance, this pipeline
  4019. +
  4020. +     echo '   a b c d' | awk '{ print; $2 = $2; print }'
  4021. +
  4022. +produces this output:
  4023. +
  4024. +        a b c d
  4025. +     a b c d
  4026. +
  4027. +The first `print' statement prints the record as it was read, with
  4028. +leading whitespace intact.  The assignment to `$2' rebuilds `$0' by
  4029. +concatenating `$1' through `$NF' together, separated by the value of
  4030. +`OFS'.  Since the leading whitespace was ignored when finding `$1', it
  4031. +is not part of the new `$0'.  Finally, the last `print' statement
  4032. +prints the new `$0'.
  4033. +
  4034. +   The following table summarizes how fields are split, based on the
  4035. +value of `FS'.
  4036. +
  4037. +`FS == " "'
  4038. +     Fields are separated by runs of whitespace.  Leading and trailing
  4039. +     whitespace are ignored.  This is the default.
  4040. +
  4041. +`FS == ANY SINGLE CHARACTER'
  4042. +     Fields are separated by each occurrence of the character.  Multiple
  4043. +     successive occurrences delimit empty fields, as do leading and
  4044. +     trailing occurrences.
  4045. +
  4046. +`FS == REGEXP'
  4047. +     Fields are separated by occurrences of characters that match
  4048. +     REGEXP.  Leading and trailing matches of REGEXP delimit empty
  4049. +     fields.
  4050. +
  4051. +
  4052. +File: gawk.info,  Node: Constant Size,  Next: Multiple Line,  Prev: Field Separators,  Up: Reading Files
  4053. +
  4054. +Reading Fixed-width Data
  4055. +========================
  4056. +
  4057. +   (This section discusses an advanced, experimental feature.  If you
  4058. +are a novice `awk' user, you may wish to skip it on the first reading.)
  4059. +
  4060. +   `gawk' 2.13 introduced a new facility for dealing with fixed-width
  4061. +fields with no distinctive field separator.  Data of this nature arises
  4062. +typically in one of at least two ways:  the input for old FORTRAN
  4063. +programs where numbers are run together, and the output of programs
  4064. +that did not anticipate the use of their output as input for other
  4065. +programs.
  4066. +
  4067. +   An example of the latter is a table where all the columns are lined
  4068. +up by the use of a variable number of spaces and *empty fields are just
  4069. +spaces*.  Clearly, `awk''s normal field splitting based on `FS' will
  4070. +not work well in this case.  (Although a portable `awk' program can use
  4071. +a series of `substr' calls on `$0', this is awkward and inefficient for
  4072. +a large number of fields.)
  4073. +
  4074. +   The splitting of an input record into fixed-width fields is
  4075. +specified by assigning a string containing space-separated numbers to
  4076. +the built-in variable `FIELDWIDTHS'.  Each number specifies the width
  4077. +of the field *including* columns between fields.  If you want to ignore
  4078. +the columns between fields, you can specify the width as a separate
  4079. +field that is subsequently ignored.
  4080. +
  4081. +   The following data is the output of the `w' utility.  It is useful
  4082. +to illustrate the use of `FIELDWIDTHS'.
  4083. +
  4084. +      10:06pm  up 21 days, 14:04,  23 users
  4085. +     User     tty       login  idle   JCPU   PCPU  what
  4086. +     hzuo     ttyV0     8:58pm            9      5  vi p24.tex
  4087. +     hzang    ttyV3     6:37pm    50                -csh
  4088. +     eklye    ttyV5     9:53pm            7      1  em thes.tex
  4089. +     dportein ttyV6     8:17pm  1:47                -csh
  4090. +     gierd    ttyD3    10:00pm     1                elm
  4091. +     dave     ttyD4     9:47pm            4      4  w
  4092. +     brent    ttyp0    26Jun91  4:46  26:46   4:41  bash
  4093. +     dave     ttyq4    26Jun9115days     46     46  wnewmail
  4094. +
  4095. +   The following program takes the above input, converts the idle time
  4096. +to number of seconds and prints out the first two fields and the
  4097. +calculated idle time.  (This program uses a number of `awk' features
  4098. +that haven't been introduced yet.)
  4099. +
  4100. +     BEGIN  { FIELDWIDTHS = "9 6 10 6 7 7 35" }
  4101. +     NR > 2 {
  4102. +         idle = $4
  4103. +         sub(/^  */, "", idle)   # strip leading spaces
  4104. +         if (idle == "") idle = 0
  4105. +         if (idle ~ /:/) { split(idle, t, ":"); idle = t[1] * 60 + t[2] }
  4106. +         if (idle ~ /days/) { idle *= 24 * 60 * 60 }
  4107. +     
  4108. +         print $1, $2, idle
  4109. +     }
  4110. +
  4111. +   Here is the result of running the program on the data:
  4112. +
  4113. +     hzuo      ttyV0  0
  4114. +     hzang     ttyV3  50
  4115. +     eklye     ttyV5  0
  4116. +     dportein  ttyV6  107
  4117. +     gierd     ttyD3  1
  4118. +     dave      ttyD4  0
  4119. +     brent     ttyp0  286
  4120. +     dave      ttyq4  1296000
  4121. +
  4122. +   Another (possibly more practical) example of fixed-width input data
  4123. +would be the input from a deck of balloting cards.  In some parts of
  4124. +the United States, voters make their choices by punching holes in
  4125. +computer cards.  These cards are then processed to count the votes for
  4126. +any particular candidate or on any particular issue.  Since a voter may
  4127. +choose not to vote on some issue, any column on the card may be empty.
  4128. +An `awk' program for processing such data could use the `FIELDWIDTHS'
  4129. +feature to simplify reading the data.
  4130. +
  4131. +   This feature is still experimental, and will likely evolve over time.
  4132. +
  4133. +
  4134. +File: gawk.info,  Node: Multiple Line,  Next: Getline,  Prev: Constant Size,  Up: Reading Files
  4135. +
  4136. +Multiple-Line Records
  4137. +=====================
  4138. +
  4139. +   In some data bases, a single line cannot conveniently hold all the
  4140. +information in one entry.  In such cases, you can use multi-line
  4141. +records.
  4142. +
  4143. +   The first step in doing this is to choose your data format: when
  4144. +records are not defined as single lines, how do you want to define them?
  4145. +What should separate records?
  4146. +
  4147. +   One technique is to use an unusual character or string to separate
  4148. +records.  For example, you could use the formfeed character (written
  4149. +`\f' in `awk', as in C) to separate them, making each record a page of
  4150. +the file.  To do this, just set the variable `RS' to `"\f"' (a string
  4151. +containing the formfeed character).  Any other character could equally
  4152. +well be used, as long as it won't be part of the data in a record.
  4153. +
  4154. +   Another technique is to have blank lines separate records.  By a
  4155. +special dispensation, a null string as the value of `RS' indicates that
  4156. +records are separated by one or more blank lines.  If you set `RS' to
  4157. +the null string, a record always ends at the first blank line
  4158. +encountered.  And the next record doesn't start until the first nonblank
  4159. +line that follows--no matter how many blank lines appear in a row, they
  4160. +are considered one record-separator. (End of file is also considered a
  4161. +record separator.)
  4162. +
  4163. +   The second step is to separate the fields in the record.  One way to
  4164. +do this is to put each field on a separate line: to do this, just set
  4165. +the variable `FS' to the string `"\n"'.  (This simple regular
  4166. +expression matches a single newline.)
  4167. +
  4168. +   Another way to separate fields is to divide each of the lines into
  4169. +fields in the normal manner.  This happens by default as a result of a
  4170. +special feature: when `RS' is set to the null string, the newline
  4171. +character *always* acts as a field separator.  This is in addition to
  4172. +whatever field separations result from `FS'.
  4173. +
  4174. +   The original motivation for this special exception was probably so
  4175. +that you get useful behavior in the default case (i.e., `FS == " "').
  4176. +This feature can be a problem if you really don't want the newline
  4177. +character to separate fields, since there is no way to prevent it.
  4178. +However, you can work around this by using the `split' function to
  4179. +break up the record manually (*note Built-in Functions for String
  4180. +Manipulation: String Functions.).
  4181. +
  4182. +
  4183. +File: gawk.info,  Node: Getline,  Next: Close Input,  Prev: Multiple Line,  Up: Reading Files
  4184. +
  4185. +Explicit Input with `getline'
  4186. +=============================
  4187. +
  4188. +   So far we have been getting our input files from `awk''s main input
  4189. +stream--either the standard input (usually your terminal) or the files
  4190. +specified on the command line.  The `awk' language has a special
  4191. +built-in command called `getline' that can be used to read input under
  4192. +your explicit control.
  4193. +
  4194. +   This command is quite complex and should *not* be used by beginners.
  4195. +It is covered here because this is the chapter on input.  The examples
  4196. +that follow the explanation of the `getline' command include material
  4197. +that has not been covered yet.  Therefore, come back and study the
  4198. +`getline' command *after* you have reviewed the rest of this manual and
  4199. +have a good knowledge of how `awk' works.
  4200. +
  4201. +   `getline' returns 1 if it finds a record, and 0 if the end of the
  4202. +file is encountered.  If there is some error in getting a record, such
  4203. +as a file that cannot be opened, then `getline' returns -1.  In this
  4204. +case, `gawk' sets the variable `ERRNO' to a string describing the error
  4205. +that occurred.
  4206. +
  4207. +   In the following examples, COMMAND stands for a string value that
  4208. +represents a shell command.
  4209. +
  4210. +`getline'
  4211. +     The `getline' command can be used without arguments to read input
  4212. +     from the current input file.  All it does in this case is read the
  4213. +     next input record and split it up into fields.  This is useful if
  4214. +     you've finished processing the current record, but you want to do
  4215. +     some special processing *right now* on the next record.  Here's an
  4216. +     example:
  4217. +
  4218. +          awk '{
  4219. +               if (t = index($0, "/*")) {
  4220. +                    if (t > 1)
  4221. +                         tmp = substr($0, 1, t - 1)
  4222. +                    else
  4223. +                         tmp = ""
  4224. +                    u = index(substr($0, t + 2), "*/")
  4225. +                    while (u == 0) {
  4226. +                         getline
  4227. +                         t = -1
  4228. +                         u = index($0, "*/")
  4229. +                    }
  4230. +                    if (u <= length($0) - 2)
  4231. +                         $0 = tmp substr($0, t + u + 3)
  4232. +                    else
  4233. +                         $0 = tmp
  4234. +               }
  4235. +               print $0
  4236. +          }'
  4237. +
  4238. +     This `awk' program deletes all C-style comments, `/* ...  */',
  4239. +     from the input.  By replacing the `print $0' with other
  4240. +     statements, you could perform more complicated processing on the
  4241. +     decommented input, like searching for matches of a regular
  4242. +     expression.  (This program has a subtle problem--can you spot it?)
  4243. +
  4244. +     This form of the `getline' command sets `NF' (the number of
  4245. +     fields; *note Examining Fields: Fields.), `NR' (the number of
  4246. +     records read so far; *note How Input is Split into Records:
  4247. +     Records.), `FNR' (the number of records read from this input
  4248. +     file), and the value of `$0'.
  4249. +
  4250. +     *Note:* the new value of `$0' is used in testing the patterns of
  4251. +     any subsequent rules.  The original value of `$0' that triggered
  4252. +     the rule which executed `getline' is lost.  By contrast, the
  4253. +     `next' statement reads a new record but immediately begins
  4254. +     processing it normally, starting with the first rule in the
  4255. +     program.  *Note The `next' Statement: Next Statement.
  4256. +
  4257. +`getline VAR'
  4258. +     This form of `getline' reads a record into the variable VAR.  This
  4259. +     is useful when you want your program to read the next record from
  4260. +     the current input file, but you don't want to subject the record
  4261. +     to the normal input processing.
  4262. +
  4263. +     For example, suppose the next line is a comment, or a special
  4264. +     string, and you want to read it, but you must make certain that it
  4265. +     won't trigger any rules.  This version of `getline' allows you to
  4266. +     read that line and store it in a variable so that the main
  4267. +     read-a-line-and-check-each-rule loop of `awk' never sees it.
  4268. +
  4269. +     The following example swaps every two lines of input.  For
  4270. +     example, given:
  4271. +
  4272. +          wan
  4273. +          tew
  4274. +          free
  4275. +          phore
  4276. +
  4277. +     it outputs:
  4278. +
  4279. +          tew
  4280. +          wan
  4281. +          phore
  4282. +          free
  4283. +
  4284. +     Here's the program:
  4285. +
  4286. +          awk '{
  4287. +               if ((getline tmp) > 0) {
  4288. +                    print tmp
  4289. +                    print $0
  4290. +               } else
  4291. +                    print $0
  4292. +          }'
  4293. +
  4294. +     The `getline' function used in this way sets only the variables
  4295. +     `NR' and `FNR' (and of course, VAR).  The record is not split into
  4296. +     fields, so the values of the fields (including `$0') and the value
  4297. +     of `NF' do not change.
  4298. +
  4299. +`getline < FILE'
  4300. +     This form of the `getline' function takes its input from the file
  4301. +     FILE.  Here FILE is a string-valued expression that specifies the
  4302. +     file name.  `< FILE' is called a "redirection" since it directs
  4303. +     input to come from a different place.
  4304. +
  4305. +     This form is useful if you want to read your input from a
  4306. +     particular file, instead of from the main input stream.  For
  4307. +     example, the following program reads its input record from the
  4308. +     file `foo.input' when it encounters a first field with a value
  4309. +     equal to 10 in the current input file.
  4310. +
  4311. +          awk '{
  4312. +              if ($1 == 10) {
  4313. +                   getline < "foo.input"
  4314. +                   print
  4315. +              } else
  4316. +                   print
  4317. +          }'
  4318. +
  4319. +     Since the main input stream is not used, the values of `NR' and
  4320. +     `FNR' are not changed.  But the record read is split into fields in
  4321. +     the normal manner, so the values of `$0' and other fields are
  4322. +     changed.  So is the value of `NF'.
  4323. +
  4324. +     This does not cause the record to be tested against all the
  4325. +     patterns in the `awk' program, in the way that would happen if the
  4326. +     record were read normally by the main processing loop of `awk'.
  4327. +     However the new record is tested against any subsequent rules,
  4328. +     just as when `getline' is used without a redirection.
  4329. +
  4330. +`getline VAR < FILE'
  4331. +     This form of the `getline' function takes its input from the file
  4332. +     FILE and puts it in the variable VAR.  As above, FILE is a
  4333. +     string-valued expression that specifies the file from which to
  4334. +     read.
  4335. +
  4336. +     In this version of `getline', none of the built-in variables are
  4337. +     changed, and the record is not split into fields.  The only
  4338. +     variable changed is VAR.
  4339. +
  4340. +     For example, the following program copies all the input files to
  4341. +     the output, except for records that say `@include FILENAME'.  Such
  4342. +     a record is replaced by the contents of the file FILENAME.
  4343. +
  4344. +          awk '{
  4345. +               if (NF == 2 && $1 == "@include") {
  4346. +                    while ((getline line < $2) > 0)
  4347. +                         print line
  4348. +                    close($2)
  4349. +               } else
  4350. +                    print
  4351. +          }'
  4352. +
  4353. +     Note here how the name of the extra input file is not built into
  4354. +     the program; it is taken from the data, from the second field on
  4355. +     the `@include' line.
  4356. +
  4357. +     The `close' function is called to ensure that if two identical
  4358. +     `@include' lines appear in the input, the entire specified file is
  4359. +     included twice.  *Note Closing Input Files and Pipes: Close Input.
  4360. +
  4361. +     One deficiency of this program is that it does not process nested
  4362. +     `@include' statements the way a true macro preprocessor would.
  4363. +
  4364. +`COMMAND | getline'
  4365. +     You can "pipe" the output of a command into `getline'.  A pipe is
  4366. +     simply a way to link the output of one program to the input of
  4367. +     another.  In this case, the string COMMAND is run as a shell
  4368. +     command and its output is piped into `awk' to be used as input.
  4369. +     This form of `getline' reads one record from the pipe.
  4370. +
  4371. +     For example, the following program copies input to output, except
  4372. +     for lines that begin with `@execute', which are replaced by the
  4373. +     output produced by running the rest of the line as a shell command:
  4374. +
  4375. +          awk '{
  4376. +               if ($1 == "@execute") {
  4377. +                    tmp = substr($0, 10)
  4378. +                    while ((tmp | getline) > 0)
  4379. +                         print
  4380. +                    close(tmp)
  4381. +               } else
  4382. +                    print
  4383. +          }'
  4384. +
  4385. +     The `close' function is called to ensure that if two identical
  4386. +     `@execute' lines appear in the input, the command is run for each
  4387. +     one.  *Note Closing Input Files and Pipes: Close Input.
  4388. +
  4389. +     Given the input:
  4390. +
  4391. +          foo
  4392. +          bar
  4393. +          baz
  4394. +          @execute who
  4395. +          bletch
  4396. +
  4397. +     the program might produce:
  4398. +
  4399. +          foo
  4400. +          bar
  4401. +          baz
  4402. +          hack     ttyv0   Jul 13 14:22
  4403. +          hack     ttyp0   Jul 13 14:23     (gnu:0)
  4404. +          hack     ttyp1   Jul 13 14:23     (gnu:0)
  4405. +          hack     ttyp2   Jul 13 14:23     (gnu:0)
  4406. +          hack     ttyp3   Jul 13 14:23     (gnu:0)
  4407. +          bletch
  4408. +
  4409. +     Notice that this program ran the command `who' and printed the
  4410. +     result.  (If you try this program yourself, you will get different
  4411. +     results, showing you who is logged in on your system.)
  4412. +
  4413. +     This variation of `getline' splits the record into fields, sets the
  4414. +     value of `NF' and recomputes the value of `$0'.  The values of
  4415. +     `NR' and `FNR' are not changed.
  4416. +
  4417. +`COMMAND | getline VAR'
  4418. +     The output of the command COMMAND is sent through a pipe to
  4419. +     `getline' and into the variable VAR.  For example, the following
  4420. +     program reads the current date and time into the variable
  4421. +     `current_time', using the `date' utility, and then prints it.
  4422. +
  4423. +          awk 'BEGIN {
  4424. +               "date" | getline current_time
  4425. +               close("date")
  4426. +               print "Report printed on " current_time
  4427. +          }'
  4428. +
  4429. +     In this version of `getline', none of the built-in variables are
  4430. +     changed, and the record is not split into fields.
  4431. +
  4432. +
  4433. +File: gawk.info,  Node: Close Input,  Prev: Getline,  Up: Reading Files
  4434. +
  4435. +Closing Input Files and Pipes
  4436. +=============================
  4437. +
  4438. +   If the same file name or the same shell command is used with
  4439. +`getline' more than once during the execution of an `awk' program, the
  4440. +file is opened (or the command is executed) only the first time.  At
  4441. +that time, the first record of input is read from that file or command.
  4442. +The next time the same file or command is used in `getline', another
  4443. +record is read from it, and so on.
  4444. +
  4445. +   This implies that if you want to start reading the same file again
  4446. +from the beginning, or if you want to rerun a shell command (rather than
  4447. +reading more output from the command), you must take special steps.
  4448. +What you must do is use the `close' function, as follows:
  4449. +
  4450. +     close(FILENAME)
  4451. +
  4452. +or
  4453. +
  4454. +     close(COMMAND)
  4455. +
  4456. +   The argument FILENAME or COMMAND can be any expression.  Its value
  4457. +must exactly equal the string that was used to open the file or start
  4458. +the command--for example, if you open a pipe with this:
  4459. +
  4460. +     "sort -r names" | getline foo
  4461. +
  4462. +then you must close it with this:
  4463. +
  4464. +     close("sort -r names")
  4465. +
  4466. +   Once this function call is executed, the next `getline' from that
  4467. +file or command will reopen the file or rerun the command.
  4468. +
  4469. +   `close' returns a value of zero if the close succeeded.  Otherwise,
  4470. +the value will be non-zero.  In this case, `gawk' sets the variable
  4471. +`ERRNO' to a string describing the error that occurred.
  4472. +
  4473. +
  4474. +File: gawk.info,  Node: Printing,  Next: One-liners,  Prev: Reading Files,  Up: Top
  4475. +
  4476. +Printing Output
  4477. +***************
  4478. +
  4479. +   One of the most common things that actions do is to output or "print"
  4480. +some or all of the input.  For simple output, use the `print'
  4481. +statement.  For fancier formatting use the `printf' statement.  Both
  4482. +are described in this chapter.
  4483. +
  4484. +* Menu:
  4485. +
  4486. +* Print::                       The `print' statement.
  4487. +* Print Examples::              Simple examples of `print' statements.
  4488. +* Output Separators::           The output separators and how to change them.
  4489. +* OFMT::                        Controlling Numeric Output With `print'.
  4490. +* Printf::                      The `printf' statement.
  4491. +* Redirection::                 How to redirect output to multiple
  4492. +                                files and pipes.
  4493. +* Special Files::               File name interpretation in `gawk'.
  4494. +                                `gawk' allows access to
  4495. +                                inherited file descriptors.
  4496. +
  4497. +
  4498. +File: gawk.info,  Node: Print,  Next: Print Examples,  Prev: Printing,  Up: Printing
  4499. +
  4500. +The `print' Statement
  4501. +=====================
  4502. +
  4503. +   The `print' statement does output with simple, standardized
  4504. +formatting.  You specify only the strings or numbers to be printed, in a
  4505. +list separated by commas.  They are output, separated by single spaces,
  4506. +followed by a newline.  The statement looks like this:
  4507. +
  4508. +     print ITEM1, ITEM2, ...
  4509. +
  4510. +The entire list of items may optionally be enclosed in parentheses.  The
  4511. +parentheses are necessary if any of the item expressions uses a
  4512. +relational operator; otherwise it could be confused with a redirection
  4513. +(*note Redirecting Output of `print' and `printf': Redirection.).  The
  4514. +relational operators are `==', `!=', `<', `>', `>=', `<=', `~' and `!~'
  4515. +(*note Comparison Expressions: Comparison Ops.).
  4516. +
  4517. +   The items printed can be constant strings or numbers, fields of the
  4518. +current record (such as `$1'), variables, or any `awk' expressions.
  4519. +The `print' statement is completely general for computing *what* values
  4520. +to print.  With two exceptions, you cannot specify *how* to print
  4521. +them--how many columns, whether to use exponential notation or not, and
  4522. +so on.  (*Note Output Separators::, and *Note Controlling Numeric
  4523. +Output with `print': OFMT.) For that, you need the `printf' statement
  4524. +(*note Using `printf' Statements for Fancier Printing: Printf.).
  4525. +
  4526. +   The simple statement `print' with no items is equivalent to `print
  4527. +$0': it prints the entire current record.  To print a blank line, use
  4528. +`print ""', where `""' is the null, or empty, string.
  4529. +
  4530. +   To print a fixed piece of text, use a string constant such as
  4531. +`"Hello there"' as one item.  If you forget to use the double-quote
  4532. +characters, your text will be taken as an `awk' expression, and you
  4533. +will probably get an error.  Keep in mind that a space is printed
  4534. +between any two items.
  4535. +
  4536. +   Most often, each `print' statement makes one line of output.  But it
  4537. +isn't limited to one line.  If an item value is a string that contains a
  4538. +newline, the newline is output along with the rest of the string.  A
  4539. +single `print' can make any number of lines this way.
  4540. +
  4541. +
  4542. +File: gawk.info,  Node: Print Examples,  Next: Output Separators,  Prev: Print,  Up: Printing
  4543. +
  4544. +Examples of `print' Statements
  4545. +==============================
  4546. +
  4547. +   Here is an example of printing a string that contains embedded
  4548. +newlines:
  4549. +
  4550. +     awk 'BEGIN { print "line one\nline two\nline three" }'
  4551. +
  4552. +produces output like this:
  4553. +
  4554. +     line one
  4555. +     line two
  4556. +     line three
  4557. +
  4558. +   Here is an example that prints the first two fields of each input
  4559. +record, with a space between them:
  4560. +
  4561. +     awk '{ print $1, $2 }' inventory-shipped
  4562. +
  4563. +Its output looks like this:
  4564. +
  4565. +     Jan 13
  4566. +     Feb 15
  4567. +     Mar 15
  4568. +     ...
  4569. +
  4570. +   A common mistake in using the `print' statement is to omit the comma
  4571. +between two items.  This often has the effect of making the items run
  4572. +together in the output, with no space.  The reason for this is that
  4573. +juxtaposing two string expressions in `awk' means to concatenate them.
  4574. +For example, without the comma:
  4575. +
  4576. +     awk '{ print $1 $2 }' inventory-shipped
  4577. +
  4578. +prints:
  4579. +
  4580. +     Jan13
  4581. +     Feb15
  4582. +     Mar15
  4583. +     ...
  4584. +
  4585. +   Neither example's output makes much sense to someone unfamiliar with
  4586. +the file `inventory-shipped'.  A heading line at the beginning would
  4587. +make it clearer.  Let's add some headings to our table of months (`$1')
  4588. +and green crates shipped (`$2').  We do this using the `BEGIN' pattern
  4589. +(*note `BEGIN' and `END' Special Patterns: BEGIN/END.) to force the
  4590. +headings to be printed only once:
  4591. +
  4592. +     awk 'BEGIN {  print "Month Crates"
  4593. +                   print "----- ------" }
  4594. +                {  print $1, $2 }' inventory-shipped
  4595. +
  4596. +Did you already guess what happens?  This program prints the following:
  4597. +
  4598. +     Month Crates
  4599. +     ----- ------
  4600. +     Jan 13
  4601. +     Feb 15
  4602. +     Mar 15
  4603. +     ...
  4604. +
  4605. +The headings and the table data don't line up!  We can fix this by
  4606. +printing some spaces between the two fields:
  4607. +
  4608. +     awk 'BEGIN { print "Month Crates"
  4609. +                  print "----- ------" }
  4610. +                { print $1, "     ", $2 }' inventory-shipped
  4611. +
  4612. +   You can imagine that this way of lining up columns can get pretty
  4613. +complicated when you have many columns to fix.  Counting spaces for two
  4614. +or three columns can be simple, but more than this and you can get
  4615. +"lost" quite easily.  This is why the `printf' statement was created
  4616. +(*note Using `printf' Statements for Fancier Printing: Printf.); one of
  4617. +its specialties is lining up columns of data.
  4618. +
  4619. diff -rup --new-file baseline/fsf/gawk/gawk.info-3 amiga/fsf/gawk/gawk.info-3
  4620. --- baseline/fsf/gawk/gawk.info-3    Wed Dec 31 17:00:00 1969
  4621. +++ amiga/fsf/gawk/gawk.info-3    Sat Sep 28 00:00:00 1996
  4622. @@ -0,0 +1,1288 @@
  4623. +This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  4624. +file /gnu-src/gawk-2.15.6/gawk.texi.
  4625. +
  4626. +   This file documents `awk', a program that you can use to select
  4627. +particular records in a file and perform operations upon them.
  4628. +
  4629. +   This is Edition 0.15 of `The GAWK Manual',
  4630. +for the 2.15 version of the GNU implementation
  4631. +of AWK.
  4632. +
  4633. +   Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  4634. +
  4635. +   Permission is granted to make and distribute verbatim copies of this
  4636. +manual provided the copyright notice and this permission notice are
  4637. +preserved on all copies.
  4638. +
  4639. +   Permission is granted to copy and distribute modified versions of
  4640. +this manual under the conditions for verbatim copying, provided that
  4641. +the entire resulting derived work is distributed under the terms of a
  4642. +permission notice identical to this one.
  4643. +
  4644. +   Permission is granted to copy and distribute translations of this
  4645. +manual into another language, under the above conditions for modified
  4646. +versions, except that this permission notice may be stated in a
  4647. +translation approved by the Foundation.
  4648. +
  4649. +
  4650. +File: gawk.info,  Node: Output Separators,  Next: OFMT,  Prev: Print Examples,  Up: Printing
  4651. +
  4652. +Output Separators
  4653. +=================
  4654. +
  4655. +   As mentioned previously, a `print' statement contains a list of
  4656. +items, separated by commas.  In the output, the items are normally
  4657. +separated by single spaces.  But they do not have to be spaces; a
  4658. +single space is only the default.  You can specify any string of
  4659. +characters to use as the "output field separator" by setting the
  4660. +built-in variable `OFS'.  The initial value of this variable is the
  4661. +string `" "', that is, just a single space.
  4662. +
  4663. +   The output from an entire `print' statement is called an "output
  4664. +record".  Each `print' statement outputs one output record and then
  4665. +outputs a string called the "output record separator".  The built-in
  4666. +variable `ORS' specifies this string.  The initial value of the
  4667. +variable is the string `"\n"' containing a newline character; thus,
  4668. +normally each `print' statement makes a separate line.
  4669. +
  4670. +   You can change how output fields and records are separated by
  4671. +assigning new values to the variables `OFS' and/or `ORS'.  The usual
  4672. +place to do this is in the `BEGIN' rule (*note `BEGIN' and `END'
  4673. +Special Patterns: BEGIN/END.), so that it happens before any input is
  4674. +processed.  You may also do this with assignments on the command line,
  4675. +before the names of your input files.
  4676. +
  4677. +   The following example prints the first and second fields of each
  4678. +input record separated by a semicolon, with a blank line added after
  4679. +each line:
  4680. +
  4681. +     awk 'BEGIN { OFS = ";"; ORS = "\n\n" }
  4682. +                { print $1, $2 }'  BBS-list
  4683. +
  4684. +   If the value of `ORS' does not contain a newline, all your output
  4685. +will be run together on a single line, unless you output newlines some
  4686. +other way.
  4687. +
  4688. +
  4689. +File: gawk.info,  Node: OFMT,  Next: Printf,  Prev: Output Separators,  Up: Printing
  4690. +
  4691. +Controlling Numeric Output with `print'
  4692. +=======================================
  4693. +
  4694. +   When you use the `print' statement to print numeric values, `awk'
  4695. +internally converts the number to a string of characters, and prints
  4696. +that string.  `awk' uses the `sprintf' function to do this conversion.
  4697. +For now, it suffices to say that the `sprintf' function accepts a
  4698. +"format specification" that tells it how to format numbers (or
  4699. +strings), and that there are a number of different ways that numbers
  4700. +can be formatted.  The different format specifications are discussed
  4701. +more fully in *Note Using `printf' Statements for Fancier Printing:
  4702. +Printf.
  4703. +
  4704. +   The built-in variable `OFMT' contains the default format
  4705. +specification that `print' uses with `sprintf' when it wants to convert
  4706. +a number to a string for printing.  By supplying different format
  4707. +specifications as the value of `OFMT', you can change how `print' will
  4708. +print your numbers.  As a brief example:
  4709. +
  4710. +     awk 'BEGIN { OFMT = "%d"  # print numbers as integers
  4711. +                  print 17.23 }'
  4712. +
  4713. +will print `17'.
  4714. +
  4715. +
  4716. +File: gawk.info,  Node: Printf,  Next: Redirection,  Prev: OFMT,  Up: Printing
  4717. +
  4718. +Using `printf' Statements for Fancier Printing
  4719. +==============================================
  4720. +
  4721. +   If you want more precise control over the output format than `print'
  4722. +gives you, use `printf'.  With `printf' you can specify the width to
  4723. +use for each item, and you can specify various stylistic choices for
  4724. +numbers (such as what radix to use, whether to print an exponent,
  4725. +whether to print a sign, and how many digits to print after the decimal
  4726. +point).  You do this by specifying a string, called the "format
  4727. +string", which controls how and where to print the other arguments.
  4728. +
  4729. +* Menu:
  4730. +
  4731. +* Basic Printf::                Syntax of the `printf' statement.
  4732. +* Control Letters::             Format-control letters.
  4733. +* Format Modifiers::            Format-specification modifiers.
  4734. +* Printf Examples::             Several examples.
  4735. +
  4736. +
  4737. +File: gawk.info,  Node: Basic Printf,  Next: Control Letters,  Prev: Printf,  Up: Printf
  4738. +
  4739. +Introduction to the `printf' Statement
  4740. +--------------------------------------
  4741. +
  4742. +   The `printf' statement looks like this:
  4743. +
  4744. +     printf FORMAT, ITEM1, ITEM2, ...
  4745. +
  4746. +The entire list of arguments may optionally be enclosed in parentheses.
  4747. +The parentheses are necessary if any of the item expressions uses a
  4748. +relational operator; otherwise it could be confused with a redirection
  4749. +(*note Redirecting Output of `print' and `printf': Redirection.).  The
  4750. +relational operators are `==', `!=', `<', `>', `>=', `<=', `~' and `!~'
  4751. +(*note Comparison Expressions: Comparison Ops.).
  4752. +
  4753. +   The difference between `printf' and `print' is the argument FORMAT.
  4754. +This is an expression whose value is taken as a string; it specifies
  4755. +how to output each of the other arguments.  It is called the "format
  4756. +string".
  4757. +
  4758. +   The format string is the same as in the ANSI C library function
  4759. +`printf'.  Most of FORMAT is text to be output verbatim.  Scattered
  4760. +among this text are "format specifiers", one per item.  Each format
  4761. +specifier says to output the next item at that place in the format.
  4762. +
  4763. +   The `printf' statement does not automatically append a newline to its
  4764. +output.  It outputs only what the format specifies.  So if you want a
  4765. +newline, you must include one in the format.  The output separator
  4766. +variables `OFS' and `ORS' have no effect on `printf' statements.
  4767. +
  4768. +
  4769. +File: gawk.info,  Node: Control Letters,  Next: Format Modifiers,  Prev: Basic Printf,  Up: Printf
  4770. +
  4771. +Format-Control Letters
  4772. +----------------------
  4773. +
  4774. +   A format specifier starts with the character `%' and ends with a
  4775. +"format-control letter"; it tells the `printf' statement how to output
  4776. +one item.  (If you actually want to output a `%', write `%%'.)  The
  4777. +format-control letter specifies what kind of value to print.  The rest
  4778. +of the format specifier is made up of optional "modifiers" which are
  4779. +parameters such as the field width to use.
  4780. +
  4781. +   Here is a list of the format-control letters:
  4782. +
  4783. +`c'
  4784. +     This prints a number as an ASCII character.  Thus, `printf "%c",
  4785. +     65' outputs the letter `A'.  The output for a string value is the
  4786. +     first character of the string.
  4787. +
  4788. +`d'
  4789. +     This prints a decimal integer.
  4790. +
  4791. +`i'
  4792. +     This also prints a decimal integer.
  4793. +
  4794. +`e'
  4795. +     This prints a number in scientific (exponential) notation.  For
  4796. +     example,
  4797. +
  4798. +          printf "%4.3e", 1950
  4799. +
  4800. +     prints `1.950e+03', with a total of four significant figures of
  4801. +     which three follow the decimal point.  The `4.3' are "modifiers",
  4802. +     discussed below.
  4803. +
  4804. +`f'
  4805. +     This prints a number in floating point notation.
  4806. +
  4807. +`g'
  4808. +     This prints a number in either scientific notation or floating
  4809. +     point notation, whichever uses fewer characters.
  4810. +
  4811. +`o'
  4812. +     This prints an unsigned octal integer.
  4813. +
  4814. +`s'
  4815. +     This prints a string.
  4816. +
  4817. +`x'
  4818. +     This prints an unsigned hexadecimal integer.
  4819. +
  4820. +`X'
  4821. +     This prints an unsigned hexadecimal integer.  However, for the
  4822. +     values 10 through 15, it uses the letters `A' through `F' instead
  4823. +     of `a' through `f'.
  4824. +
  4825. +`%'
  4826. +     This isn't really a format-control letter, but it does have a
  4827. +     meaning when used after a `%': the sequence `%%' outputs one `%'.
  4828. +     It does not consume an argument.
  4829. +
  4830. +
  4831. +File: gawk.info,  Node: Format Modifiers,  Next: Printf Examples,  Prev: Control Letters,  Up: Printf
  4832. +
  4833. +Modifiers for `printf' Formats
  4834. +------------------------------
  4835. +
  4836. +   A format specification can also include "modifiers" that can control
  4837. +how much of the item's value is printed and how much space it gets.  The
  4838. +modifiers come between the `%' and the format-control letter.  Here are
  4839. +the possible modifiers, in the order in which they may appear:
  4840. +
  4841. +`-'
  4842. +     The minus sign, used before the width modifier, says to
  4843. +     left-justify the argument within its specified width.  Normally
  4844. +     the argument is printed right-justified in the specified width.
  4845. +     Thus,
  4846. +
  4847. +          printf "%-4s", "foo"
  4848. +
  4849. +     prints `foo '.
  4850. +
  4851. +`WIDTH'
  4852. +     This is a number representing the desired width of a field.
  4853. +     Inserting any number between the `%' sign and the format control
  4854. +     character forces the field to be expanded to this width.  The
  4855. +     default way to do this is to pad with spaces on the left.  For
  4856. +     example,
  4857. +
  4858. +          printf "%4s", "foo"
  4859. +
  4860. +     prints ` foo'.
  4861. +
  4862. +     The value of WIDTH is a minimum width, not a maximum.  If the item
  4863. +     value requires more than WIDTH characters, it can be as wide as
  4864. +     necessary.  Thus,
  4865. +
  4866. +          printf "%4s", "foobar"
  4867. +
  4868. +     prints `foobar'.
  4869. +
  4870. +     Preceding the WIDTH with a minus sign causes the output to be
  4871. +     padded with spaces on the right, instead of on the left.
  4872. +
  4873. +`.PREC'
  4874. +     This is a number that specifies the precision to use when printing.
  4875. +     This specifies the number of digits you want printed to the right
  4876. +     of the decimal point.  For a string, it specifies the maximum
  4877. +     number of characters from the string that should be printed.
  4878. +
  4879. +   The C library `printf''s dynamic WIDTH and PREC capability (for
  4880. +example, `"%*.*s"') is supported.  Instead of supplying explicit WIDTH
  4881. +and/or PREC values in the format string, you pass them in the argument
  4882. +list.  For example:
  4883. +
  4884. +     w = 5
  4885. +     p = 3
  4886. +     s = "abcdefg"
  4887. +     printf "<%*.*s>\n", w, p, s
  4888. +
  4889. +is exactly equivalent to
  4890. +
  4891. +     s = "abcdefg"
  4892. +     printf "<%5.3s>\n", s
  4893. +
  4894. +Both programs output `<**abc>'.  (We have used the bullet symbol "*" to
  4895. +represent a space, to clearly show you that there are two spaces in the
  4896. +output.)
  4897. +
  4898. +   Earlier versions of `awk' did not support this capability.  You may
  4899. +simulate it by using concatenation to build up the format string, like
  4900. +so:
  4901. +
  4902. +     w = 5
  4903. +     p = 3
  4904. +     s = "abcdefg"
  4905. +     printf "<%" w "." p "s>\n", s
  4906. +
  4907. +This is not particularly easy to read, however.
  4908. +
  4909. +
  4910. +File: gawk.info,  Node: Printf Examples,  Prev: Format Modifiers,  Up: Printf
  4911. +
  4912. +Examples of Using `printf'
  4913. +--------------------------
  4914. +
  4915. +   Here is how to use `printf' to make an aligned table:
  4916. +
  4917. +     awk '{ printf "%-10s %s\n", $1, $2 }' BBS-list
  4918. +
  4919. +prints the names of bulletin boards (`$1') of the file `BBS-list' as a
  4920. +string of 10 characters, left justified.  It also prints the phone
  4921. +numbers (`$2') afterward on the line.  This produces an aligned
  4922. +two-column table of names and phone numbers:
  4923. +
  4924. +     aardvark   555-5553
  4925. +     alpo-net   555-3412
  4926. +     barfly     555-7685
  4927. +     bites      555-1675
  4928. +     camelot    555-0542
  4929. +     core       555-2912
  4930. +     fooey      555-1234
  4931. +     foot       555-6699
  4932. +     macfoo     555-6480
  4933. +     sdace      555-3430
  4934. +     sabafoo    555-2127
  4935. +
  4936. +   Did you notice that we did not specify that the phone numbers be
  4937. +printed as numbers?  They had to be printed as strings because the
  4938. +numbers are separated by a dash.  This dash would be interpreted as a
  4939. +minus sign if we had tried to print the phone numbers as numbers.  This
  4940. +would have led to some pretty confusing results.
  4941. +
  4942. +   We did not specify a width for the phone numbers because they are the
  4943. +last things on their lines.  We don't need to put spaces after them.
  4944. +
  4945. +   We could make our table look even nicer by adding headings to the
  4946. +tops of the columns.  To do this, use the `BEGIN' pattern (*note
  4947. +`BEGIN' and `END' Special Patterns: BEGIN/END.) to force the header to
  4948. +be printed only once, at the beginning of the `awk' program:
  4949. +
  4950. +     awk 'BEGIN { print "Name      Number"
  4951. +                  print "----      ------" }
  4952. +          { printf "%-10s %s\n", $1, $2 }' BBS-list
  4953. +
  4954. +   Did you notice that we mixed `print' and `printf' statements in the
  4955. +above example?  We could have used just `printf' statements to get the
  4956. +same results:
  4957. +
  4958. +     awk 'BEGIN { printf "%-10s %s\n", "Name", "Number"
  4959. +                  printf "%-10s %s\n", "----", "------" }
  4960. +          { printf "%-10s %s\n", $1, $2 }' BBS-list
  4961. +
  4962. +By outputting each column heading with the same format specification
  4963. +used for the elements of the column, we have made sure that the headings
  4964. +are aligned just like the columns.
  4965. +
  4966. +   The fact that the same format specification is used three times can
  4967. +be emphasized by storing it in a variable, like this:
  4968. +
  4969. +     awk 'BEGIN { format = "%-10s %s\n"
  4970. +                  printf format, "Name", "Number"
  4971. +                  printf format, "----", "------" }
  4972. +          { printf format, $1, $2 }' BBS-list
  4973. +
  4974. +   See if you can use the `printf' statement to line up the headings and
  4975. +table data for our `inventory-shipped' example covered earlier in the
  4976. +section on the `print' statement (*note The `print' Statement: Print.).
  4977. +
  4978. +
  4979. +File: gawk.info,  Node: Redirection,  Next: Special Files,  Prev: Printf,  Up: Printing
  4980. +
  4981. +Redirecting Output of `print' and `printf'
  4982. +==========================================
  4983. +
  4984. +   So far we have been dealing only with output that prints to the
  4985. +standard output, usually your terminal.  Both `print' and `printf' can
  4986. +also send their output to other places.  This is called "redirection".
  4987. +
  4988. +   A redirection appears after the `print' or `printf' statement.
  4989. +Redirections in `awk' are written just like redirections in shell
  4990. +commands, except that they are written inside the `awk' program.
  4991. +
  4992. +* Menu:
  4993. +
  4994. +* File/Pipe Redirection::       Redirecting Output to Files and Pipes.
  4995. +* Close Output::                How to close output files and pipes.
  4996. +
  4997. +
  4998. +File: gawk.info,  Node: File/Pipe Redirection,  Next: Close Output,  Prev: Redirection,  Up: Redirection
  4999. +
  5000. +Redirecting Output to Files and Pipes
  5001. +-------------------------------------
  5002. +
  5003. +   Here are the three forms of output redirection.  They are all shown
  5004. +for the `print' statement, but they work identically for `printf' also.
  5005. +
  5006. +`print ITEMS > OUTPUT-FILE'
  5007. +     This type of redirection prints the items onto the output file
  5008. +     OUTPUT-FILE.  The file name OUTPUT-FILE can be any expression.
  5009. +     Its value is changed to a string and then used as a file name
  5010. +     (*note Expressions as Action Statements: Expressions.).
  5011. +
  5012. +     When this type of redirection is used, the OUTPUT-FILE is erased
  5013. +     before the first output is written to it.  Subsequent writes do not
  5014. +     erase OUTPUT-FILE, but append to it.  If OUTPUT-FILE does not
  5015. +     exist, then it is created.
  5016. +
  5017. +     For example, here is how one `awk' program can write a list of BBS
  5018. +     names to a file `name-list' and a list of phone numbers to a file
  5019. +     `phone-list'.  Each output file contains one name or number per
  5020. +     line.
  5021. +
  5022. +          awk '{ print $2 > "phone-list"
  5023. +                 print $1 > "name-list" }' BBS-list
  5024. +
  5025. +`print ITEMS >> OUTPUT-FILE'
  5026. +     This type of redirection prints the items onto the output file
  5027. +     OUTPUT-FILE.  The difference between this and the single-`>'
  5028. +     redirection is that the old contents (if any) of OUTPUT-FILE are
  5029. +     not erased.  Instead, the `awk' output is appended to the file.
  5030. +
  5031. +`print ITEMS | COMMAND'
  5032. +     It is also possible to send output through a "pipe" instead of
  5033. +     into a file.   This type of redirection opens a pipe to COMMAND
  5034. +     and writes the values of ITEMS through this pipe, to another
  5035. +     process created to execute COMMAND.
  5036. +
  5037. +     The redirection argument COMMAND is actually an `awk' expression.
  5038. +     Its value is converted to a string, whose contents give the shell
  5039. +     command to be run.
  5040. +
  5041. +     For example, this produces two files, one unsorted list of BBS
  5042. +     names and one list sorted in reverse alphabetical order:
  5043. +
  5044. +          awk '{ print $1 > "names.unsorted"
  5045. +                 print $1 | "sort -r > names.sorted" }' BBS-list
  5046. +
  5047. +     Here the unsorted list is written with an ordinary redirection
  5048. +     while the sorted list is written by piping through the `sort'
  5049. +     utility.
  5050. +
  5051. +     Here is an example that uses redirection to mail a message to a
  5052. +     mailing list `bug-system'.  This might be useful when trouble is
  5053. +     encountered in an `awk' script run periodically for system
  5054. +     maintenance.
  5055. +
  5056. +          report = "mail bug-system"
  5057. +          print "Awk script failed:", $0 | report
  5058. +          print "at record number", FNR, "of", FILENAME  | report
  5059. +          close(report)
  5060. +
  5061. +     We call the `close' function here because it's a good idea to close
  5062. +     the pipe as soon as all the intended output has been sent to it.
  5063. +     *Note Closing Output Files and Pipes: Close Output, for more
  5064. +     information on this.  This example also illustrates the use of a
  5065. +     variable to represent a FILE or COMMAND: it is not necessary to
  5066. +     always use a string constant.  Using a variable is generally a
  5067. +     good idea, since `awk' requires you to spell the string value
  5068. +     identically every time.
  5069. +
  5070. +   Redirecting output using `>', `>>', or `|' asks the system to open a
  5071. +file or pipe only if the particular FILE or COMMAND you've specified
  5072. +has not already been written to by your program, or if it has been
  5073. +closed since it was last written to.
  5074. +
  5075. +
  5076. +File: gawk.info,  Node: Close Output,  Prev: File/Pipe Redirection,  Up: Redirection
  5077. +
  5078. +Closing Output Files and Pipes
  5079. +------------------------------
  5080. +
  5081. +   When a file or pipe is opened, the file name or command associated
  5082. +with it is remembered by `awk' and subsequent writes to the same file or
  5083. +command are appended to the previous writes.  The file or pipe stays
  5084. +open until `awk' exits.  This is usually convenient.
  5085. +
  5086. +   Sometimes there is a reason to close an output file or pipe earlier
  5087. +than that.  To do this, use the `close' function, as follows:
  5088. +
  5089. +     close(FILENAME)
  5090. +
  5091. +or
  5092. +
  5093. +     close(COMMAND)
  5094. +
  5095. +   The argument FILENAME or COMMAND can be any expression.  Its value
  5096. +must exactly equal the string used to open the file or pipe to begin
  5097. +with--for example, if you open a pipe with this:
  5098. +
  5099. +     print $1 | "sort -r > names.sorted"
  5100. +
  5101. +then you must close it with this:
  5102. +
  5103. +     close("sort -r > names.sorted")
  5104. +
  5105. +   Here are some reasons why you might need to close an output file:
  5106. +
  5107. +   * To write a file and read it back later on in the same `awk'
  5108. +     program.  Close the file when you are finished writing it; then
  5109. +     you can start reading it with `getline' (*note Explicit Input with
  5110. +     `getline': Getline.).
  5111. +
  5112. +   * To write numerous files, successively, in the same `awk' program.
  5113. +     If you don't close the files, eventually you may exceed a system
  5114. +     limit on the number of open files in one process.  So close each
  5115. +     one when you are finished writing it.
  5116. +
  5117. +   * To make a command finish.  When you redirect output through a pipe,
  5118. +     the command reading the pipe normally continues to try to read
  5119. +     input as long as the pipe is open.  Often this means the command
  5120. +     cannot really do its work until the pipe is closed.  For example,
  5121. +     if you redirect output to the `mail' program, the message is not
  5122. +     actually sent until the pipe is closed.
  5123. +
  5124. +   * To run the same program a second time, with the same arguments.
  5125. +     This is not the same thing as giving more input to the first run!
  5126. +
  5127. +     For example, suppose you pipe output to the `mail' program.  If you
  5128. +     output several lines redirected to this pipe without closing it,
  5129. +     they make a single message of several lines.  By contrast, if you
  5130. +     close the pipe after each line of output, then each line makes a
  5131. +     separate message.
  5132. +
  5133. +   `close' returns a value of zero if the close succeeded.  Otherwise,
  5134. +the value will be non-zero.  In this case, `gawk' sets the variable
  5135. +`ERRNO' to a string describing the error that occurred.
  5136. +
  5137. +
  5138. +File: gawk.info,  Node: Special Files,  Prev: Redirection,  Up: Printing
  5139. +
  5140. +Standard I/O Streams
  5141. +====================
  5142. +
  5143. +   Running programs conventionally have three input and output streams
  5144. +already available to them for reading and writing.  These are known as
  5145. +the "standard input", "standard output", and "standard error output".
  5146. +These streams are, by default, terminal input and output, but they are
  5147. +often redirected with the shell, via the `<', `<<', `>', `>>', `>&' and
  5148. +`|' operators.  Standard error is used only for writing error messages;
  5149. +the reason we have two separate streams, standard output and standard
  5150. +error, is so that they can be redirected separately.
  5151. +
  5152. +   In other implementations of `awk', the only way to write an error
  5153. +message to standard error in an `awk' program is as follows:
  5154. +
  5155. +     print "Serious error detected!\n" | "cat 1>&2"
  5156. +
  5157. +This works by opening a pipeline to a shell command which can access the
  5158. +standard error stream which it inherits from the `awk' process.  This
  5159. +is far from elegant, and is also inefficient, since it requires a
  5160. +separate process.  So people writing `awk' programs have often
  5161. +neglected to do this.  Instead, they have sent the error messages to the
  5162. +terminal, like this:
  5163. +
  5164. +     NF != 4 {
  5165. +        printf("line %d skipped: doesn't have 4 fields\n", FNR) > "/dev/tty"
  5166. +     }
  5167. +
  5168. +This has the same effect most of the time, but not always: although the
  5169. +standard error stream is usually the terminal, it can be redirected, and
  5170. +when that happens, writing to the terminal is not correct.  In fact, if
  5171. +`awk' is run from a background job, it may not have a terminal at all.
  5172. +Then opening `/dev/tty' will fail.
  5173. +
  5174. +   `gawk' provides special file names for accessing the three standard
  5175. +streams.  When you redirect input or output in `gawk', if the file name
  5176. +matches one of these special names, then `gawk' directly uses the
  5177. +stream it stands for.
  5178. +
  5179. +`/dev/stdin'
  5180. +     The standard input (file descriptor 0).
  5181. +
  5182. +`/dev/stdout'
  5183. +     The standard output (file descriptor 1).
  5184. +
  5185. +`/dev/stderr'
  5186. +     The standard error output (file descriptor 2).
  5187. +
  5188. +`/dev/fd/N'
  5189. +     The file associated with file descriptor N.  Such a file must have
  5190. +     been opened by the program initiating the `awk' execution
  5191. +     (typically the shell).  Unless you take special pains, only
  5192. +     descriptors 0, 1 and 2 are available.
  5193. +
  5194. +   The file names `/dev/stdin', `/dev/stdout', and `/dev/stderr' are
  5195. +aliases for `/dev/fd/0', `/dev/fd/1', and `/dev/fd/2', respectively,
  5196. +but they are more self-explanatory.
  5197. +
  5198. +   The proper way to write an error message in a `gawk' program is to
  5199. +use `/dev/stderr', like this:
  5200. +
  5201. +     NF != 4 {
  5202. +       printf("line %d skipped: doesn't have 4 fields\n", FNR) > "/dev/stderr"
  5203. +     }
  5204. +
  5205. +   `gawk' also provides special file names that give access to
  5206. +information about the running `gawk' process.  Each of these "files"
  5207. +provides a single record of information.  To read them more than once,
  5208. +you must first close them with the `close' function (*note Closing
  5209. +Input Files and Pipes: Close Input.).  The filenames are:
  5210. +
  5211. +`/dev/pid'
  5212. +     Reading this file returns the process ID of the current process,
  5213. +     in decimal, terminated with a newline.
  5214. +
  5215. +`/dev/ppid'
  5216. +     Reading this file returns the parent process ID of the current
  5217. +     process, in decimal, terminated with a newline.
  5218. +
  5219. +`/dev/pgrpid'
  5220. +     Reading this file returns the process group ID of the current
  5221. +     process, in decimal, terminated with a newline.
  5222. +
  5223. +`/dev/user'
  5224. +     Reading this file returns a single record terminated with a
  5225. +     newline.  The fields are separated with blanks.  The fields
  5226. +     represent the following information:
  5227. +
  5228. +    `$1'
  5229. +          The value of the `getuid' system call.
  5230. +
  5231. +    `$2'
  5232. +          The value of the `geteuid' system call.
  5233. +
  5234. +    `$3'
  5235. +          The value of the `getgid' system call.
  5236. +
  5237. +    `$4'
  5238. +          The value of the `getegid' system call.
  5239. +
  5240. +     If there are any additional fields, they are the group IDs
  5241. +     returned by `getgroups' system call.  (Multiple groups may not be
  5242. +     supported on all systems.)
  5243. +
  5244. +   These special file names may be used on the command line as data
  5245. +files, as well as for I/O redirections within an `awk' program.  They
  5246. +may not be used as source files with the `-f' option.
  5247. +
  5248. +   Recognition of these special file names is disabled if `gawk' is in
  5249. +compatibility mode (*note Invoking `awk': Command Line.).
  5250. +
  5251. +     *Caution*:  Unless your system actually has a `/dev/fd' directory
  5252. +     (or any of the other above listed special files), the
  5253. +     interpretation of these file names is done by `gawk' itself.  For
  5254. +     example, using `/dev/fd/4' for output will actually write on file
  5255. +     descriptor 4, and not on a new file descriptor that was `dup''ed
  5256. +     from file descriptor 4.  Most of the time this does not matter;
  5257. +     however, it is important to *not* close any of the files related
  5258. +     to file descriptors 0, 1, and 2.  If you do close one of these
  5259. +     files, unpredictable behavior will result.
  5260. +
  5261. +
  5262. +File: gawk.info,  Node: One-liners,  Next: Patterns,  Prev: Printing,  Up: Top
  5263. +
  5264. +Useful "One-liners"
  5265. +*******************
  5266. +
  5267. +   Useful `awk' programs are often short, just a line or two.  Here is a
  5268. +collection of useful, short programs to get you started.  Some of these
  5269. +programs contain constructs that haven't been covered yet.  The
  5270. +description of the program will give you a good idea of what is going
  5271. +on, but please read the rest of the manual to become an `awk' expert!
  5272. +
  5273. +   Since you are reading this in Info, each line of the example code is
  5274. +enclosed in quotes, to represent text that you would type literally.
  5275. +The examples themselves represent shell commands that use single quotes
  5276. +to keep the shell from interpreting the contents of the program.  When
  5277. +reading the examples, focus on the text between the open and close
  5278. +quotes.
  5279. +
  5280. +`awk '{ if (NF > max) max = NF }'
  5281. +`     END { print max }''
  5282. +     This program prints the maximum number of fields on any input line.
  5283. +
  5284. +`awk 'length($0) > 80''
  5285. +     This program prints every line longer than 80 characters.  The sole
  5286. +     rule has a relational expression as its pattern, and has no action
  5287. +     (so the default action, printing the record, is used).
  5288. +
  5289. +`awk 'NF > 0''
  5290. +     This program prints every line that has at least one field.  This
  5291. +     is an easy way to delete blank lines from a file (or rather, to
  5292. +     create a new file similar to the old file but from which the blank
  5293. +     lines have been deleted).
  5294. +
  5295. +`awk '{ if (NF > 0) print }''
  5296. +     This program also prints every line that has at least one field.
  5297. +     Here we allow the rule to match every line, then decide in the
  5298. +     action whether to print.
  5299. +
  5300. +`awk 'BEGIN { for (i = 1; i <= 7; i++)'
  5301. +`               print int(101 * rand()) }''
  5302. +     This program prints 7 random numbers from 0 to 100, inclusive.
  5303. +
  5304. +`ls -l FILES | awk '{ x += $4 } ; END { print "total bytes: " x }''
  5305. +     This program prints the total number of bytes used by FILES.
  5306. +
  5307. +`expand FILE | awk '{ if (x < length()) x = length() }'
  5308. +`                  END { print "maximum line length is " x }''
  5309. +     This program prints the maximum line length of FILE.  The input is
  5310. +     piped through the `expand' program to change tabs into spaces, so
  5311. +     the widths compared are actually the right-margin columns.
  5312. +
  5313. +`awk 'BEGIN { FS = ":" }'
  5314. +`     { print $1 | "sort" }' /etc/passwd'
  5315. +     This program prints a sorted list of the login names of all users.
  5316. +
  5317. +`awk '{ nlines++ }'
  5318. +`     END { print nlines }''
  5319. +     This programs counts lines in a file.
  5320. +
  5321. +`awk 'END { print NR }''
  5322. +     This program also counts lines in a file, but lets `awk' do the
  5323. +     work.
  5324. +
  5325. +`awk '{ print NR, $0 }''
  5326. +     This program adds line numbers to all its input files, similar to
  5327. +     `cat -n'.
  5328. +
  5329. +
  5330. +File: gawk.info,  Node: Patterns,  Next: Actions,  Prev: One-liners,  Up: Top
  5331. +
  5332. +Patterns
  5333. +********
  5334. +
  5335. +   Patterns in `awk' control the execution of rules: a rule is executed
  5336. +when its pattern matches the current input record.  This chapter tells
  5337. +all about how to write patterns.
  5338. +
  5339. +* Menu:
  5340. +
  5341. +* Kinds of Patterns::           A list of all kinds of patterns.
  5342. +                                The following subsections describe
  5343. +                                them in detail.
  5344. +* Regexp::                      Regular expressions such as `/foo/'.
  5345. +* Comparison Patterns::         Comparison expressions such as `$1 > 10'.
  5346. +* Boolean Patterns::            Combining comparison expressions.
  5347. +* Expression Patterns::         Any expression can be used as a pattern.
  5348. +* Ranges::                      Pairs of patterns specify record ranges.
  5349. +* BEGIN/END::                   Specifying initialization and cleanup rules.
  5350. +* Empty::                       The empty pattern, which matches every record.
  5351. +
  5352. +
  5353. +File: gawk.info,  Node: Kinds of Patterns,  Next: Regexp,  Prev: Patterns,  Up: Patterns
  5354. +
  5355. +Kinds of Patterns
  5356. +=================
  5357. +
  5358. +   Here is a summary of the types of patterns supported in `awk'.
  5359. +
  5360. +`/REGULAR EXPRESSION/'
  5361. +     A regular expression as a pattern.  It matches when the text of the
  5362. +     input record fits the regular expression.  (*Note Regular
  5363. +     Expressions as Patterns: Regexp.)
  5364. +
  5365. +`EXPRESSION'
  5366. +     A single expression.  It matches when its value, converted to a
  5367. +     number, is nonzero (if a number) or nonnull (if a string).  (*Note
  5368. +     Expressions as Patterns: Expression Patterns.)
  5369. +
  5370. +`PAT1, PAT2'
  5371. +     A pair of patterns separated by a comma, specifying a range of
  5372. +     records.  (*Note Specifying Record Ranges with Patterns: Ranges.)
  5373. +
  5374. +`BEGIN'
  5375. +`END'
  5376. +     Special patterns to supply start-up or clean-up information to
  5377. +     `awk'.  (*Note `BEGIN' and `END' Special Patterns: BEGIN/END.)
  5378. +
  5379. +`NULL'
  5380. +     The empty pattern matches every input record.  (*Note The Empty
  5381. +     Pattern: Empty.)
  5382. +
  5383. +
  5384. +File: gawk.info,  Node: Regexp,  Next: Comparison Patterns,  Prev: Kinds of Patterns,  Up: Patterns
  5385. +
  5386. +Regular Expressions as Patterns
  5387. +===============================
  5388. +
  5389. +   A "regular expression", or "regexp", is a way of describing a class
  5390. +of strings.  A regular expression enclosed in slashes (`/') is an `awk'
  5391. +pattern that matches every input record whose text belongs to that
  5392. +class.
  5393. +
  5394. +   The simplest regular expression is a sequence of letters, numbers, or
  5395. +both.  Such a regexp matches any string that contains that sequence.
  5396. +Thus, the regexp `foo' matches any string containing `foo'.  Therefore,
  5397. +the pattern `/foo/' matches any input record containing `foo'.  Other
  5398. +kinds of regexps let you specify more complicated classes of strings.
  5399. +
  5400. +* Menu:
  5401. +
  5402. +* Regexp Usage::                How to Use Regular Expressions
  5403. +* Regexp Operators::            Regular Expression Operators
  5404. +* Case-sensitivity::            How to do case-insensitive matching.
  5405. +
  5406. +
  5407. +File: gawk.info,  Node: Regexp Usage,  Next: Regexp Operators,  Prev: Regexp,  Up: Regexp
  5408. +
  5409. +How to Use Regular Expressions
  5410. +------------------------------
  5411. +
  5412. +   A regular expression can be used as a pattern by enclosing it in
  5413. +slashes.  Then the regular expression is matched against the entire
  5414. +text of each record.  (Normally, it only needs to match some part of
  5415. +the text in order to succeed.)  For example, this prints the second
  5416. +field of each record that contains `foo' anywhere:
  5417. +
  5418. +     awk '/foo/ { print $2 }' BBS-list
  5419. +
  5420. +   Regular expressions can also be used in comparison expressions.  Then
  5421. +you can specify the string to match against; it need not be the entire
  5422. +current input record.  These comparison expressions can be used as
  5423. +patterns or in `if', `while', `for', and `do' statements.
  5424. +
  5425. +`EXP ~ /REGEXP/'
  5426. +     This is true if the expression EXP (taken as a character string)
  5427. +     is matched by REGEXP.  The following example matches, or selects,
  5428. +     all input records with the upper-case letter `J' somewhere in the
  5429. +     first field:
  5430. +
  5431. +          awk '$1 ~ /J/' inventory-shipped
  5432. +
  5433. +     So does this:
  5434. +
  5435. +          awk '{ if ($1 ~ /J/) print }' inventory-shipped
  5436. +
  5437. +`EXP !~ /REGEXP/'
  5438. +     This is true if the expression EXP (taken as a character string)
  5439. +     is *not* matched by REGEXP.  The following example matches, or
  5440. +     selects, all input records whose first field *does not* contain
  5441. +     the upper-case letter `J':
  5442. +
  5443. +          awk '$1 !~ /J/' inventory-shipped
  5444. +
  5445. +   The right hand side of a `~' or `!~' operator need not be a constant
  5446. +regexp (i.e., a string of characters between slashes).  It may be any
  5447. +expression.  The expression is evaluated, and converted if necessary to
  5448. +a string; the contents of the string are used as the regexp.  A regexp
  5449. +that is computed in this way is called a "dynamic regexp".  For example:
  5450. +
  5451. +     identifier_regexp = "[A-Za-z_][A-Za-z_0-9]+"
  5452. +     $0 ~ identifier_regexp
  5453. +
  5454. +sets `identifier_regexp' to a regexp that describes `awk' variable
  5455. +names, and tests if the input record matches this regexp.
  5456. +
  5457. +
  5458. +File: gawk.info,  Node: Regexp Operators,  Next: Case-sensitivity,  Prev: Regexp Usage,  Up: Regexp
  5459. +
  5460. +Regular Expression Operators
  5461. +----------------------------
  5462. +
  5463. +   You can combine regular expressions with the following characters,
  5464. +called "regular expression operators", or "metacharacters", to increase
  5465. +the power and versatility of regular expressions.
  5466. +
  5467. +   Here is a table of metacharacters.  All characters not listed in the
  5468. +table stand for themselves.
  5469. +
  5470. +`^'
  5471. +     This matches the beginning of the string or the beginning of a line
  5472. +     within the string.  For example:
  5473. +
  5474. +          ^@chapter
  5475. +
  5476. +     matches the `@chapter' at the beginning of a string, and can be
  5477. +     used to identify chapter beginnings in Texinfo source files.
  5478. +
  5479. +`$'
  5480. +     This is similar to `^', but it matches only at the end of a string
  5481. +     or the end of a line within the string.  For example:
  5482. +
  5483. +          p$
  5484. +
  5485. +     matches a record that ends with a `p'.
  5486. +
  5487. +`.'
  5488. +     This matches any single character except a newline.  For example:
  5489. +
  5490. +          .P
  5491. +
  5492. +     matches any single character followed by a `P' in a string.  Using
  5493. +     concatenation we can make regular expressions like `U.A', which
  5494. +     matches any three-character sequence that begins with `U' and ends
  5495. +     with `A'.
  5496. +
  5497. +`[...]'
  5498. +     This is called a "character set".  It matches any one of the
  5499. +     characters that are enclosed in the square brackets.  For example:
  5500. +
  5501. +          [MVX]
  5502. +
  5503. +     matches any one of the characters `M', `V', or `X' in a string.
  5504. +
  5505. +     Ranges of characters are indicated by using a hyphen between the
  5506. +     beginning and ending characters, and enclosing the whole thing in
  5507. +     brackets.  For example:
  5508. +
  5509. +          [0-9]
  5510. +
  5511. +     matches any digit.
  5512. +
  5513. +     To include the character `\', `]', `-' or `^' in a character set,
  5514. +     put a `\' in front of it.  For example:
  5515. +
  5516. +          [d\]]
  5517. +
  5518. +     matches either `d', or `]'.
  5519. +
  5520. +     This treatment of `\' is compatible with other `awk'
  5521. +     implementations, and is also mandated by the POSIX Command Language
  5522. +     and Utilities standard.  The regular expressions in `awk' are a
  5523. +     superset of the POSIX specification for Extended Regular
  5524. +     Expressions (EREs).  POSIX EREs are based on the regular
  5525. +     expressions accepted by the traditional `egrep' utility.
  5526. +
  5527. +     In `egrep' syntax, backslash is not syntactically special within
  5528. +     square brackets.  This means that special tricks have to be used to
  5529. +     represent the characters `]', `-' and `^' as members of a
  5530. +     character set.
  5531. +
  5532. +     In `egrep' syntax, to match `-', write it as `---', which is a
  5533. +     range containing only `-'.  You may also give `-' as the first or
  5534. +     last character in the set.  To match `^', put it anywhere except
  5535. +     as the first character of a set.  To match a `]', make it the
  5536. +     first character in the set.  For example:
  5537. +
  5538. +          []d^]
  5539. +
  5540. +     matches either `]', `d' or `^'.
  5541. +
  5542. +`[^ ...]'
  5543. +     This is a "complemented character set".  The first character after
  5544. +     the `[' *must* be a `^'.  It matches any characters *except* those
  5545. +     in the square brackets (or newline).  For example:
  5546. +
  5547. +          [^0-9]
  5548. +
  5549. +     matches any character that is not a digit.
  5550. +
  5551. +`|'
  5552. +     This is the "alternation operator" and it is used to specify
  5553. +     alternatives.  For example:
  5554. +
  5555. +          ^P|[0-9]
  5556. +
  5557. +     matches any string that matches either `^P' or `[0-9]'.  This
  5558. +     means it matches any string that contains a digit or starts with
  5559. +     `P'.
  5560. +
  5561. +     The alternation applies to the largest possible regexps on either
  5562. +     side.
  5563. +
  5564. +`(...)'
  5565. +     Parentheses are used for grouping in regular expressions as in
  5566. +     arithmetic.  They can be used to concatenate regular expressions
  5567. +     containing the alternation operator, `|'.
  5568. +
  5569. +`*'
  5570. +     This symbol means that the preceding regular expression is to be
  5571. +     repeated as many times as possible to find a match.  For example:
  5572. +
  5573. +          ph*
  5574. +
  5575. +     applies the `*' symbol to the preceding `h' and looks for matches
  5576. +     to one `p' followed by any number of `h's.  This will also match
  5577. +     just `p' if no `h's are present.
  5578. +
  5579. +     The `*' repeats the *smallest* possible preceding expression.
  5580. +     (Use parentheses if you wish to repeat a larger expression.)  It
  5581. +     finds as many repetitions as possible.  For example:
  5582. +
  5583. +          awk '/\(c[ad][ad]*r x\)/ { print }' sample
  5584. +
  5585. +     prints every record in the input containing a string of the form
  5586. +     `(car x)', `(cdr x)', `(cadr x)', and so on.
  5587. +
  5588. +`+'
  5589. +     This symbol is similar to `*', but the preceding expression must be
  5590. +     matched at least once.  This means that:
  5591. +
  5592. +          wh+y
  5593. +
  5594. +     would match `why' and `whhy' but not `wy', whereas `wh*y' would
  5595. +     match all three of these strings.  This is a simpler way of
  5596. +     writing the last `*' example:
  5597. +
  5598. +          awk '/\(c[ad]+r x\)/ { print }' sample
  5599. +
  5600. +`?'
  5601. +     This symbol is similar to `*', but the preceding expression can be
  5602. +     matched once or not at all.  For example:
  5603. +
  5604. +          fe?d
  5605. +
  5606. +     will match `fed' and `fd', but nothing else.
  5607. +
  5608. +`\'
  5609. +     This is used to suppress the special meaning of a character when
  5610. +     matching.  For example:
  5611. +
  5612. +          \$
  5613. +
  5614. +     matches the character `$'.
  5615. +
  5616. +     The escape sequences used for string constants (*note Constant
  5617. +     Expressions: Constants.) are valid in regular expressions as well;
  5618. +     they are also introduced by a `\'.
  5619. +
  5620. +   In regular expressions, the `*', `+', and `?' operators have the
  5621. +highest precedence, followed by concatenation, and finally by `|'.  As
  5622. +in arithmetic, parentheses can change how operators are grouped.
  5623. +
  5624. +
  5625. +File: gawk.info,  Node: Case-sensitivity,  Prev: Regexp Operators,  Up: Regexp
  5626. +
  5627. +Case-sensitivity in Matching
  5628. +----------------------------
  5629. +
  5630. +   Case is normally significant in regular expressions, both when
  5631. +matching ordinary characters (i.e., not metacharacters), and inside
  5632. +character sets.  Thus a `w' in a regular expression matches only a
  5633. +lower case `w' and not an upper case `W'.
  5634. +
  5635. +   The simplest way to do a case-independent match is to use a character
  5636. +set: `[Ww]'.  However, this can be cumbersome if you need to use it
  5637. +often; and it can make the regular expressions harder for humans to
  5638. +read.  There are two other alternatives that you might prefer.
  5639. +
  5640. +   One way to do a case-insensitive match at a particular point in the
  5641. +program is to convert the data to a single case, using the `tolower' or
  5642. +`toupper' built-in string functions (which we haven't discussed yet;
  5643. +*note Built-in Functions for String Manipulation: String Functions.).
  5644. +For example:
  5645. +
  5646. +     tolower($1) ~ /foo/  { ... }
  5647. +
  5648. +converts the first field to lower case before matching against it.
  5649. +
  5650. +   Another method is to set the variable `IGNORECASE' to a nonzero
  5651. +value (*note Built-in Variables::.).  When `IGNORECASE' is not zero,
  5652. +*all* regexp operations ignore case.  Changing the value of
  5653. +`IGNORECASE' dynamically controls the case sensitivity of your program
  5654. +as it runs.  Case is significant by default because `IGNORECASE' (like
  5655. +most variables) is initialized to zero.
  5656. +
  5657. +     x = "aB"
  5658. +     if (x ~ /ab/) ...   # this test will fail
  5659. +     
  5660. +     IGNORECASE = 1
  5661. +     if (x ~ /ab/) ...   # now it will succeed
  5662. +
  5663. +   In general, you cannot use `IGNORECASE' to make certain rules
  5664. +case-insensitive and other rules case-sensitive, because there is no way
  5665. +to set `IGNORECASE' just for the pattern of a particular rule.  To do
  5666. +this, you must use character sets or `tolower'.  However, one thing you
  5667. +can do only with `IGNORECASE' is turn case-sensitivity on or off
  5668. +dynamically for all the rules at once.
  5669. +
  5670. +   `IGNORECASE' can be set on the command line, or in a `BEGIN' rule.
  5671. +Setting `IGNORECASE' from the command line is a way to make a program
  5672. +case-insensitive without having to edit it.
  5673. +
  5674. +   The value of `IGNORECASE' has no effect if `gawk' is in
  5675. +compatibility mode (*note Invoking `awk': Command Line.).  Case is
  5676. +always significant in compatibility mode.
  5677. +
  5678. +
  5679. +File: gawk.info,  Node: Comparison Patterns,  Next: Boolean Patterns,  Prev: Regexp,  Up: Patterns
  5680. +
  5681. +Comparison Expressions as Patterns
  5682. +==================================
  5683. +
  5684. +   "Comparison patterns" test relationships such as equality between
  5685. +two strings or numbers.  They are a special case of expression patterns
  5686. +(*note Expressions as Patterns: Expression Patterns.).  They are written
  5687. +with "relational operators", which are a superset of those in C.  Here
  5688. +is a table of them:
  5689. +
  5690. +`X < Y'
  5691. +     True if X is less than Y.
  5692. +
  5693. +`X <= Y'
  5694. +     True if X is less than or equal to Y.
  5695. +
  5696. +`X > Y'
  5697. +     True if X is greater than Y.
  5698. +
  5699. +`X >= Y'
  5700. +     True if X is greater than or equal to Y.
  5701. +
  5702. +`X == Y'
  5703. +     True if X is equal to Y.
  5704. +
  5705. +`X != Y'
  5706. +     True if X is not equal to Y.
  5707. +
  5708. +`X ~ Y'
  5709. +     True if X matches the regular expression described by Y.
  5710. +
  5711. +`X !~ Y'
  5712. +     True if X does not match the regular expression described by Y.
  5713. +
  5714. +   The operands of a relational operator are compared as numbers if they
  5715. +are both numbers.  Otherwise they are converted to, and compared as,
  5716. +strings (*note Conversion of Strings and Numbers: Conversion., for the
  5717. +detailed rules).  Strings are compared by comparing the first character
  5718. +of each, then the second character of each, and so on, until there is a
  5719. +difference.  If the two strings are equal until the shorter one runs
  5720. +out, the shorter one is considered to be less than the longer one.
  5721. +Thus, `"10"' is less than `"9"', and `"abc"' is less than `"abcd"'.
  5722. +
  5723. +   The left operand of the `~' and `!~' operators is a string.  The
  5724. +right operand is either a constant regular expression enclosed in
  5725. +slashes (`/REGEXP/'), or any expression, whose string value is used as
  5726. +a dynamic regular expression (*note How to Use Regular Expressions:
  5727. +Regexp Usage.).
  5728. +
  5729. +   The following example prints the second field of each input record
  5730. +whose first field is precisely `foo'.
  5731. +
  5732. +     awk '$1 == "foo" { print $2 }' BBS-list
  5733. +
  5734. +Contrast this with the following regular expression match, which would
  5735. +accept any record with a first field that contains `foo':
  5736. +
  5737. +     awk '$1 ~ "foo" { print $2 }' BBS-list
  5738. +
  5739. +or, equivalently, this one:
  5740. +
  5741. +     awk '$1 ~ /foo/ { print $2 }' BBS-list
  5742. +
  5743. +
  5744. +File: gawk.info,  Node: Boolean Patterns,  Next: Expression Patterns,  Prev: Comparison Patterns,  Up: Patterns
  5745. +
  5746. +Boolean Operators and Patterns
  5747. +==============================
  5748. +
  5749. +   A "boolean pattern" is an expression which combines other patterns
  5750. +using the "boolean operators" "or" (`||'), "and" (`&&'), and "not"
  5751. +(`!').  Whether the boolean pattern matches an input record depends on
  5752. +whether its subpatterns match.
  5753. +
  5754. +   For example, the following command prints all records in the input
  5755. +file `BBS-list' that contain both `2400' and `foo'.
  5756. +
  5757. +     awk '/2400/ && /foo/' BBS-list
  5758. +
  5759. +   The following command prints all records in the input file
  5760. +`BBS-list' that contain *either* `2400' or `foo', or both.
  5761. +
  5762. +     awk '/2400/ || /foo/' BBS-list
  5763. +
  5764. +   The following command prints all records in the input file
  5765. +`BBS-list' that do *not* contain the string `foo'.
  5766. +
  5767. +     awk '! /foo/' BBS-list
  5768. +
  5769. +   Note that boolean patterns are a special case of expression patterns
  5770. +(*note Expressions as Patterns: Expression Patterns.); they are
  5771. +expressions that use the boolean operators.  *Note Boolean Expressions:
  5772. +Boolean Ops, for complete information on the boolean operators.
  5773. +
  5774. +   The subpatterns of a boolean pattern can be constant regular
  5775. +expressions, comparisons, or any other `awk' expressions.  Range
  5776. +patterns are not expressions, so they cannot appear inside boolean
  5777. +patterns.  Likewise, the special patterns `BEGIN' and `END', which
  5778. +never match any input record, are not expressions and cannot appear
  5779. +inside boolean patterns.
  5780. +
  5781. +
  5782. +File: gawk.info,  Node: Expression Patterns,  Next: Ranges,  Prev: Boolean Patterns,  Up: Patterns
  5783. +
  5784. +Expressions as Patterns
  5785. +=======================
  5786. +
  5787. +   Any `awk' expression is also valid as an `awk' pattern.  Then the
  5788. +pattern "matches" if the expression's value is nonzero (if a number) or
  5789. +nonnull (if a string).
  5790. +
  5791. +   The expression is reevaluated each time the rule is tested against a
  5792. +new input record.  If the expression uses fields such as `$1', the
  5793. +value depends directly on the new input record's text; otherwise, it
  5794. +depends only on what has happened so far in the execution of the `awk'
  5795. +program, but that may still be useful.
  5796. +
  5797. +   Comparison patterns are actually a special case of this.  For
  5798. +example, the expression `$5 == "foo"' has the value 1 when the value of
  5799. +`$5' equals `"foo"', and 0 otherwise; therefore, this expression as a
  5800. +pattern matches when the two values are equal.
  5801. +
  5802. +   Boolean patterns are also special cases of expression patterns.
  5803. +
  5804. +   A constant regexp as a pattern is also a special case of an
  5805. +expression pattern.  `/foo/' as an expression has the value 1 if `foo'
  5806. +appears in the current input record; thus, as a pattern, `/foo/'
  5807. +matches any record containing `foo'.
  5808. +
  5809. +   Other implementations of `awk' that are not yet POSIX compliant are
  5810. +less general than `gawk': they allow comparison expressions, and
  5811. +boolean combinations thereof (optionally with parentheses), but not
  5812. +necessarily other kinds of expressions.
  5813. +
  5814. +
  5815. +File: gawk.info,  Node: Ranges,  Next: BEGIN/END,  Prev: Expression Patterns,  Up: Patterns
  5816. +
  5817. +Specifying Record Ranges with Patterns
  5818. +======================================
  5819. +
  5820. +   A "range pattern" is made of two patterns separated by a comma, of
  5821. +the form `BEGPAT, ENDPAT'.  It matches ranges of consecutive input
  5822. +records.  The first pattern BEGPAT controls where the range begins, and
  5823. +the second one ENDPAT controls where it ends.  For example,
  5824. +
  5825. +     awk '$1 == "on", $1 == "off"'
  5826. +
  5827. +prints every record between `on'/`off' pairs, inclusive.
  5828. +
  5829. +   A range pattern starts out by matching BEGPAT against every input
  5830. +record; when a record matches BEGPAT, the range pattern becomes "turned
  5831. +on".  The range pattern matches this record.  As long as it stays
  5832. +turned on, it automatically matches every input record read.  It also
  5833. +matches ENDPAT against every input record; when that succeeds, the
  5834. +range pattern is turned off again for the following record.  Now it
  5835. +goes back to checking BEGPAT against each record.
  5836. +
  5837. +   The record that turns on the range pattern and the one that turns it
  5838. +off both match the range pattern.  If you don't want to operate on
  5839. +these records, you can write `if' statements in the rule's action to
  5840. +distinguish them.
  5841. +
  5842. +   It is possible for a pattern to be turned both on and off by the same
  5843. +record, if both conditions are satisfied by that record.  Then the
  5844. +action is executed for just that record.
  5845. +
  5846. +
  5847. +File: gawk.info,  Node: BEGIN/END,  Next: Empty,  Prev: Ranges,  Up: Patterns
  5848. +
  5849. +`BEGIN' and `END' Special Patterns
  5850. +==================================
  5851. +
  5852. +   `BEGIN' and `END' are special patterns.  They are not used to match
  5853. +input records.  Rather, they are used for supplying start-up or
  5854. +clean-up information to your `awk' script.  A `BEGIN' rule is executed,
  5855. +once, before the first input record has been read.  An `END' rule is
  5856. +executed, once, after all the input has been read.  For example:
  5857. +
  5858. +     awk 'BEGIN { print "Analysis of `foo'" }
  5859. +          /foo/ { ++foobar }
  5860. +          END   { print "`foo' appears " foobar " times." }' BBS-list
  5861. +
  5862. +   This program finds the number of records in the input file `BBS-list'
  5863. +that contain the string `foo'.  The `BEGIN' rule prints a title for the
  5864. +report.  There is no need to use the `BEGIN' rule to initialize the
  5865. +counter `foobar' to zero, as `awk' does this for us automatically
  5866. +(*note Variables::.).
  5867. +
  5868. +   The second rule increments the variable `foobar' every time a record
  5869. +containing the pattern `foo' is read.  The `END' rule prints the value
  5870. +of `foobar' at the end of the run.
  5871. +
  5872. +   The special patterns `BEGIN' and `END' cannot be used in ranges or
  5873. +with boolean operators (indeed, they cannot be used with any operators).
  5874. +
  5875. +   An `awk' program may have multiple `BEGIN' and/or `END' rules.  They
  5876. +are executed in the order they appear, all the `BEGIN' rules at
  5877. +start-up and all the `END' rules at termination.
  5878. +
  5879. +   Multiple `BEGIN' and `END' sections are useful for writing library
  5880. +functions, since each library can have its own `BEGIN' or `END' rule to
  5881. +do its own initialization and/or cleanup.  Note that the order in which
  5882. +library functions are named on the command line controls the order in
  5883. +which their `BEGIN' and `END' rules are executed.  Therefore you have
  5884. +to be careful to write such rules in library files so that the order in
  5885. +which they are executed doesn't matter.  *Note Invoking `awk': Command
  5886. +Line, for more information on using library functions.
  5887. +
  5888. +   If an `awk' program only has a `BEGIN' rule, and no other rules,
  5889. +then the program exits after the `BEGIN' rule has been run.  (Older
  5890. +versions of `awk' used to keep reading and ignoring input until end of
  5891. +file was seen.)  However, if an `END' rule exists as well, then the
  5892. +input will be read, even if there are no other rules in the program.
  5893. +This is necessary in case the `END' rule checks the `NR' variable.
  5894. +
  5895. +   `BEGIN' and `END' rules must have actions; there is no default
  5896. +action for these rules since there is no current record when they run.
  5897. +
  5898. +
  5899. +File: gawk.info,  Node: Empty,  Prev: BEGIN/END,  Up: Patterns
  5900. +
  5901. +The Empty Pattern
  5902. +=================
  5903. +
  5904. +   An empty pattern is considered to match *every* input record.  For
  5905. +example, the program:
  5906. +
  5907. +     awk '{ print $1 }' BBS-list
  5908. +
  5909. +prints the first field of every record.
  5910. +
  5911. diff -rup --new-file baseline/fsf/gawk/gawk.info-4 amiga/fsf/gawk/gawk.info-4
  5912. --- baseline/fsf/gawk/gawk.info-4    Wed Dec 31 17:00:00 1969
  5913. +++ amiga/fsf/gawk/gawk.info-4    Sat Sep 28 00:00:00 1996
  5914. @@ -0,0 +1,1305 @@
  5915. +This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  5916. +file /gnu-src/gawk-2.15.6/gawk.texi.
  5917. +
  5918. +   This file documents `awk', a program that you can use to select
  5919. +particular records in a file and perform operations upon them.
  5920. +
  5921. +   This is Edition 0.15 of `The GAWK Manual',
  5922. +for the 2.15 version of the GNU implementation
  5923. +of AWK.
  5924. +
  5925. +   Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  5926. +
  5927. +   Permission is granted to make and distribute verbatim copies of this
  5928. +manual provided the copyright notice and this permission notice are
  5929. +preserved on all copies.
  5930. +
  5931. +   Permission is granted to copy and distribute modified versions of
  5932. +this manual under the conditions for verbatim copying, provided that
  5933. +the entire resulting derived work is distributed under the terms of a
  5934. +permission notice identical to this one.
  5935. +
  5936. +   Permission is granted to copy and distribute translations of this
  5937. +manual into another language, under the above conditions for modified
  5938. +versions, except that this permission notice may be stated in a
  5939. +translation approved by the Foundation.
  5940. +
  5941. +
  5942. +File: gawk.info,  Node: Actions,  Next: Expressions,  Prev: Patterns,  Up: Top
  5943. +
  5944. +Overview of Actions
  5945. +*******************
  5946. +
  5947. +   An `awk' program or script consists of a series of rules and
  5948. +function definitions, interspersed.  (Functions are described later.
  5949. +*Note User-defined Functions: User-defined.)
  5950. +
  5951. +   A rule contains a pattern and an action, either of which may be
  5952. +omitted.  The purpose of the "action" is to tell `awk' what to do once
  5953. +a match for the pattern is found.  Thus, the entire program looks
  5954. +somewhat like this:
  5955. +
  5956. +     [PATTERN] [{ ACTION }]
  5957. +     [PATTERN] [{ ACTION }]
  5958. +     ...
  5959. +     function NAME (ARGS) { ... }
  5960. +     ...
  5961. +
  5962. +   An action consists of one or more `awk' "statements", enclosed in
  5963. +curly braces (`{' and `}').  Each statement specifies one thing to be
  5964. +done.  The statements are separated by newlines or semicolons.
  5965. +
  5966. +   The curly braces around an action must be used even if the action
  5967. +contains only one statement, or even if it contains no statements at
  5968. +all.  However, if you omit the action entirely, omit the curly braces as
  5969. +well.  (An omitted action is equivalent to `{ print $0 }'.)
  5970. +
  5971. +   Here are the kinds of statements supported in `awk':
  5972. +
  5973. +   * Expressions, which can call functions or assign values to variables
  5974. +     (*note Expressions as Action Statements: Expressions.).  Executing
  5975. +     this kind of statement simply computes the value of the expression
  5976. +     and then ignores it.  This is useful when the expression has side
  5977. +     effects (*note Assignment Expressions: Assignment Ops.).
  5978. +
  5979. +   * Control statements, which specify the control flow of `awk'
  5980. +     programs.  The `awk' language gives you C-like constructs (`if',
  5981. +     `for', `while', and so on) as well as a few special ones (*note
  5982. +     Control Statements in Actions: Statements.).
  5983. +
  5984. +   * Compound statements, which consist of one or more statements
  5985. +     enclosed in curly braces.  A compound statement is used in order
  5986. +     to put several statements together in the body of an `if',
  5987. +     `while', `do' or `for' statement.
  5988. +
  5989. +   * Input control, using the `getline' command (*note Explicit Input
  5990. +     with `getline': Getline.), and the `next' statement (*note The
  5991. +     `next' Statement: Next Statement.).
  5992. +
  5993. +   * Output statements, `print' and `printf'.  *Note Printing Output:
  5994. +     Printing.
  5995. +
  5996. +   * Deletion statements, for deleting array elements.  *Note The
  5997. +     `delete' Statement: Delete.
  5998. +
  5999. +
  6000. +File: gawk.info,  Node: Expressions,  Next: Statements,  Prev: Actions,  Up: Top
  6001. +
  6002. +Expressions as Action Statements
  6003. +********************************
  6004. +
  6005. +   Expressions are the basic building block of `awk' actions.  An
  6006. +expression evaluates to a value, which you can print, test, store in a
  6007. +variable or pass to a function.  But beyond that, an expression can
  6008. +assign a new value to a variable or a field, with an assignment
  6009. +operator.
  6010. +
  6011. +   An expression can serve as a statement on its own.  Most other kinds
  6012. +of statements contain one or more expressions which specify data to be
  6013. +operated on.  As in other languages, expressions in `awk' include
  6014. +variables, array references, constants, and function calls, as well as
  6015. +combinations of these with various operators.
  6016. +
  6017. +* Menu:
  6018. +
  6019. +* Constants::                   String, numeric, and regexp constants.
  6020. +* Variables::                   Variables give names to values for later use.
  6021. +* Arithmetic Ops::              Arithmetic operations (`+', `-', etc.)
  6022. +* Concatenation::               Concatenating strings.
  6023. +* Comparison Ops::              Comparison of numbers and strings
  6024. +                                with `<', etc.
  6025. +* Boolean Ops::                 Combining comparison expressions
  6026. +                                using boolean operators
  6027. +                                `||' ("or"), `&&' ("and") and `!' ("not").
  6028. +
  6029. +* Assignment Ops::              Changing the value of a variable or a field.
  6030. +* Increment Ops::               Incrementing the numeric value of a variable.
  6031. +
  6032. +* Conversion::                  The conversion of strings to numbers
  6033. +                                and vice versa.
  6034. +* Values::                      The whole truth about numbers and strings.
  6035. +* Conditional Exp::             Conditional expressions select
  6036. +                                between two subexpressions under control
  6037. +                                of a third subexpression.
  6038. +* Function Calls::              A function call is an expression.
  6039. +* Precedence::                  How various operators nest.
  6040. +
  6041. +
  6042. +File: gawk.info,  Node: Constants,  Next: Variables,  Prev: Expressions,  Up: Expressions
  6043. +
  6044. +Constant Expressions
  6045. +====================
  6046. +
  6047. +   The simplest type of expression is the "constant", which always has
  6048. +the same value.  There are three types of constants: numeric constants,
  6049. +string constants, and regular expression constants.
  6050. +
  6051. +   A "numeric constant" stands for a number.  This number can be an
  6052. +integer, a decimal fraction, or a number in scientific (exponential)
  6053. +notation.  Note that all numeric values are represented within `awk' in
  6054. +double-precision floating point.  Here are some examples of numeric
  6055. +constants, which all have the same value:
  6056. +
  6057. +     105
  6058. +     1.05e+2
  6059. +     1050e-1
  6060. +
  6061. +   A string constant consists of a sequence of characters enclosed in
  6062. +double-quote marks.  For example:
  6063. +
  6064. +     "parrot"
  6065. +
  6066. +represents the string whose contents are `parrot'.  Strings in `gawk'
  6067. +can be of any length and they can contain all the possible 8-bit ASCII
  6068. +characters including ASCII NUL.  Other `awk' implementations may have
  6069. +difficulty with some character codes.
  6070. +
  6071. +   Some characters cannot be included literally in a string constant.
  6072. +You represent them instead with "escape sequences", which are character
  6073. +sequences beginning with a backslash (`\').
  6074. +
  6075. +   One use of an escape sequence is to include a double-quote character
  6076. +in a string constant.  Since a plain double-quote would end the string,
  6077. +you must use `\"' to represent a single double-quote character as a
  6078. +part of the string.  The backslash character itself is another
  6079. +character that cannot be included normally; you write `\\' to put one
  6080. +backslash in the string.  Thus, the string whose contents are the two
  6081. +characters `"\' must be written `"\"\\"'.
  6082. +
  6083. +   Another use of backslash is to represent unprintable characters such
  6084. +as newline.  While there is nothing to stop you from writing most of
  6085. +these characters directly in a string constant, they may look ugly.
  6086. +
  6087. +   Here is a table of all the escape sequences used in `awk':
  6088. +
  6089. +`\\'
  6090. +     Represents a literal backslash, `\'.
  6091. +
  6092. +`\a'
  6093. +     Represents the "alert" character, control-g, ASCII code 7.
  6094. +
  6095. +`\b'
  6096. +     Represents a backspace, control-h, ASCII code 8.
  6097. +
  6098. +`\f'
  6099. +     Represents a formfeed, control-l, ASCII code 12.
  6100. +
  6101. +`\n'
  6102. +     Represents a newline, control-j, ASCII code 10.
  6103. +
  6104. +`\r'
  6105. +     Represents a carriage return, control-m, ASCII code 13.
  6106. +
  6107. +`\t'
  6108. +     Represents a horizontal tab, control-i, ASCII code 9.
  6109. +
  6110. +`\v'
  6111. +     Represents a vertical tab, control-k, ASCII code 11.
  6112. +
  6113. +`\NNN'
  6114. +     Represents the octal value NNN, where NNN are one to three digits
  6115. +     between 0 and 7.  For example, the code for the ASCII ESC (escape)
  6116. +     character is `\033'.
  6117. +
  6118. +`\xHH...'
  6119. +     Represents the hexadecimal value HH, where HH are hexadecimal
  6120. +     digits (`0' through `9' and either `A' through `F' or `a' through
  6121. +     `f').  Like the same construct in ANSI C, the escape sequence
  6122. +     continues until the first non-hexadecimal digit is seen.  However,
  6123. +     using more than two hexadecimal digits produces undefined results.
  6124. +     (The `\x' escape sequence is not allowed in POSIX `awk'.)
  6125. +
  6126. +   A "constant regexp" is a regular expression description enclosed in
  6127. +slashes, such as `/^beginning and end$/'.  Most regexps used in `awk'
  6128. +programs are constant, but the `~' and `!~' operators can also match
  6129. +computed or "dynamic" regexps (*note How to Use Regular Expressions:
  6130. +Regexp Usage.).
  6131. +
  6132. +   Constant regexps may be used like simple expressions.  When a
  6133. +constant regexp is not on the right hand side of the `~' or `!~'
  6134. +operators, it has the same meaning as if it appeared in a pattern, i.e.
  6135. +`($0 ~ /foo/)' (*note Expressions as Patterns: Expression Patterns.).
  6136. +This means that the two code segments,
  6137. +
  6138. +     if ($0 ~ /barfly/ || $0 ~ /camelot/)
  6139. +         print "found"
  6140. +
  6141. +and
  6142. +
  6143. +     if (/barfly/ || /camelot/)
  6144. +         print "found"
  6145. +
  6146. +are exactly equivalent.  One rather bizarre consequence of this rule is
  6147. +that the following boolean expression is legal, but does not do what
  6148. +the user intended:
  6149. +
  6150. +     if (/foo/ ~ $1) print "found foo"
  6151. +
  6152. +   This code is "obviously" testing `$1' for a match against the regexp
  6153. +`/foo/'.  But in fact, the expression `(/foo/ ~ $1)' actually means
  6154. +`(($0 ~ /foo/) ~ $1)'.  In other words, first match the input record
  6155. +against the regexp `/foo/'.  The result will be either a 0 or a 1,
  6156. +depending upon the success or failure of the match.  Then match that
  6157. +result against the first field in the record.
  6158. +
  6159. +   Since it is unlikely that you would ever really wish to make this
  6160. +kind of test, `gawk' will issue a warning when it sees this construct in
  6161. +a program.
  6162. +
  6163. +   Another consequence of this rule is that the assignment statement
  6164. +
  6165. +     matches = /foo/
  6166. +
  6167. +will assign either 0 or 1 to the variable `matches', depending upon the
  6168. +contents of the current input record.
  6169. +
  6170. +   Constant regular expressions are also used as the first argument for
  6171. +the `sub' and `gsub' functions (*note Built-in Functions for String
  6172. +Manipulation: String Functions.).
  6173. +
  6174. +   This feature of the language was never well documented until the
  6175. +POSIX specification.
  6176. +
  6177. +   You may be wondering, when is
  6178. +
  6179. +     $1 ~ /foo/ { ... }
  6180. +
  6181. +preferable to
  6182. +
  6183. +     $1 ~ "foo" { ... }
  6184. +
  6185. +   Since the right-hand sides of both `~' operators are constants, it
  6186. +is more efficient to use the `/foo/' form: `awk' can note that you have
  6187. +supplied a regexp and store it internally in a form that makes pattern
  6188. +matching more efficient.  In the second form, `awk' must first convert
  6189. +the string into this internal form, and then perform the pattern
  6190. +matching.  The first form is also better style; it shows clearly that
  6191. +you intend a regexp match.
  6192. +
  6193. +
  6194. +File: gawk.info,  Node: Variables,  Next: Arithmetic Ops,  Prev: Constants,  Up: Expressions
  6195. +
  6196. +Variables
  6197. +=========
  6198. +
  6199. +   Variables let you give names to values and refer to them later.  You
  6200. +have already seen variables in many of the examples.  The name of a
  6201. +variable must be a sequence of letters, digits and underscores, but it
  6202. +may not begin with a digit.  Case is significant in variable names; `a'
  6203. +and `A' are distinct variables.
  6204. +
  6205. +   A variable name is a valid expression by itself; it represents the
  6206. +variable's current value.  Variables are given new values with
  6207. +"assignment operators" and "increment operators".  *Note Assignment
  6208. +Expressions: Assignment Ops.
  6209. +
  6210. +   A few variables have special built-in meanings, such as `FS', the
  6211. +field separator, and `NF', the number of fields in the current input
  6212. +record.  *Note Built-in Variables::, for a list of them.  These
  6213. +built-in variables can be used and assigned just like all other
  6214. +variables, but their values are also used or changed automatically by
  6215. +`awk'.  Each built-in variable's name is made entirely of upper case
  6216. +letters.
  6217. +
  6218. +   Variables in `awk' can be assigned either numeric or string values.
  6219. +By default, variables are initialized to the null string, which is
  6220. +effectively zero if converted to a number.  There is no need to
  6221. +"initialize" each variable explicitly in `awk', the way you would in C
  6222. +or most other traditional languages.
  6223. +
  6224. +* Menu:
  6225. +
  6226. +* Assignment Options::          Setting variables on the command line
  6227. +                                and a summary of command line syntax.
  6228. +                                This is an advanced method of input.
  6229. +
  6230. +
  6231. +File: gawk.info,  Node: Assignment Options,  Prev: Variables,  Up: Variables
  6232. +
  6233. +Assigning Variables on the Command Line
  6234. +---------------------------------------
  6235. +
  6236. +   You can set any `awk' variable by including a "variable assignment"
  6237. +among the arguments on the command line when you invoke `awk' (*note
  6238. +Invoking `awk': Command Line.).  Such an assignment has this form:
  6239. +
  6240. +     VARIABLE=TEXT
  6241. +
  6242. +With it, you can set a variable either at the beginning of the `awk'
  6243. +run or in between input files.
  6244. +
  6245. +   If you precede the assignment with the `-v' option, like this:
  6246. +
  6247. +     -v VARIABLE=TEXT
  6248. +
  6249. +then the variable is set at the very beginning, before even the `BEGIN'
  6250. +rules are run.  The `-v' option and its assignment must precede all the
  6251. +file name arguments, as well as the program text.
  6252. +
  6253. +   Otherwise, the variable assignment is performed at a time determined
  6254. +by its position among the input file arguments: after the processing of
  6255. +the preceding input file argument.  For example:
  6256. +
  6257. +     awk '{ print $n }' n=4 inventory-shipped n=2 BBS-list
  6258. +
  6259. +prints the value of field number `n' for all input records.  Before the
  6260. +first file is read, the command line sets the variable `n' equal to 4.
  6261. +This causes the fourth field to be printed in lines from the file
  6262. +`inventory-shipped'.  After the first file has finished, but before the
  6263. +second file is started, `n' is set to 2, so that the second field is
  6264. +printed in lines from `BBS-list'.
  6265. +
  6266. +   Command line arguments are made available for explicit examination by
  6267. +the `awk' program in an array named `ARGV' (*note Built-in
  6268. +Variables::.).
  6269. +
  6270. +   `awk' processes the values of command line assignments for escape
  6271. +sequences (*note Constant Expressions: Constants.).
  6272. +
  6273. +
  6274. +File: gawk.info,  Node: Arithmetic Ops,  Next: Concatenation,  Prev: Variables,  Up: Expressions
  6275. +
  6276. +Arithmetic Operators
  6277. +====================
  6278. +
  6279. +   The `awk' language uses the common arithmetic operators when
  6280. +evaluating expressions.  All of these arithmetic operators follow normal
  6281. +precedence rules, and work as you would expect them to.  This example
  6282. +divides field three by field four, adds field two, stores the result
  6283. +into field one, and prints the resulting altered input record:
  6284. +
  6285. +     awk '{ $1 = $2 + $3 / $4; print }' inventory-shipped
  6286. +
  6287. +   The arithmetic operators in `awk' are:
  6288. +
  6289. +`X + Y'
  6290. +     Addition.
  6291. +
  6292. +`X - Y'
  6293. +     Subtraction.
  6294. +
  6295. +`- X'
  6296. +     Negation.
  6297. +
  6298. +`+ X'
  6299. +     Unary plus.  No real effect on the expression.
  6300. +
  6301. +`X * Y'
  6302. +     Multiplication.
  6303. +
  6304. +`X / Y'
  6305. +     Division.  Since all numbers in `awk' are double-precision
  6306. +     floating point, the result is not rounded to an integer: `3 / 4'
  6307. +     has the value 0.75.
  6308. +
  6309. +`X % Y'
  6310. +     Remainder.  The quotient is rounded toward zero to an integer,
  6311. +     multiplied by Y and this result is subtracted from X.  This
  6312. +     operation is sometimes known as "trunc-mod."  The following
  6313. +     relation always holds:
  6314. +
  6315. +          b * int(a / b) + (a % b) == a
  6316. +
  6317. +     One possibly undesirable effect of this definition of remainder is
  6318. +     that `X % Y' is negative if X is negative.  Thus,
  6319. +
  6320. +          -17 % 8 = -1
  6321. +
  6322. +     In other `awk' implementations, the signedness of the remainder
  6323. +     may be machine dependent.
  6324. +
  6325. +`X ^ Y'
  6326. +`X ** Y'
  6327. +     Exponentiation: X raised to the Y power.  `2 ^ 3' has the value 8.
  6328. +     The character sequence `**' is equivalent to `^'.  (The POSIX
  6329. +     standard only specifies the use of `^' for exponentiation.)
  6330. +
  6331. +
  6332. +File: gawk.info,  Node: Concatenation,  Next: Comparison Ops,  Prev: Arithmetic Ops,  Up: Expressions
  6333. +
  6334. +String Concatenation
  6335. +====================
  6336. +
  6337. +   There is only one string operation: concatenation.  It does not have
  6338. +a specific operator to represent it.  Instead, concatenation is
  6339. +performed by writing expressions next to one another, with no operator.
  6340. +For example:
  6341. +
  6342. +     awk '{ print "Field number one: " $1 }' BBS-list
  6343. +
  6344. +produces, for the first record in `BBS-list':
  6345. +
  6346. +     Field number one: aardvark
  6347. +
  6348. +   Without the space in the string constant after the `:', the line
  6349. +would run together.  For example:
  6350. +
  6351. +     awk '{ print "Field number one:" $1 }' BBS-list
  6352. +
  6353. +produces, for the first record in `BBS-list':
  6354. +
  6355. +     Field number one:aardvark
  6356. +
  6357. +   Since string concatenation does not have an explicit operator, it is
  6358. +often necessary to insure that it happens where you want it to by
  6359. +enclosing the items to be concatenated in parentheses.  For example, the
  6360. +following code fragment does not concatenate `file' and `name' as you
  6361. +might expect:
  6362. +
  6363. +     file = "file"
  6364. +     name = "name"
  6365. +     print "something meaningful" > file name
  6366. +
  6367. +It is necessary to use the following:
  6368. +
  6369. +     print "something meaningful" > (file name)
  6370. +
  6371. +   We recommend you use parentheses around concatenation in all but the
  6372. +most common contexts (such as in the right-hand operand of `=').
  6373. +
  6374. +
  6375. +File: gawk.info,  Node: Comparison Ops,  Next: Boolean Ops,  Prev: Concatenation,  Up: Expressions
  6376. +
  6377. +Comparison Expressions
  6378. +======================
  6379. +
  6380. +   "Comparison expressions" compare strings or numbers for
  6381. +relationships such as equality.  They are written using "relational
  6382. +operators", which are a superset of those in C.  Here is a table of
  6383. +them:
  6384. +
  6385. +`X < Y'
  6386. +     True if X is less than Y.
  6387. +
  6388. +`X <= Y'
  6389. +     True if X is less than or equal to Y.
  6390. +
  6391. +`X > Y'
  6392. +     True if X is greater than Y.
  6393. +
  6394. +`X >= Y'
  6395. +     True if X is greater than or equal to Y.
  6396. +
  6397. +`X == Y'
  6398. +     True if X is equal to Y.
  6399. +
  6400. +`X != Y'
  6401. +     True if X is not equal to Y.
  6402. +
  6403. +`X ~ Y'
  6404. +     True if the string X matches the regexp denoted by Y.
  6405. +
  6406. +`X !~ Y'
  6407. +     True if the string X does not match the regexp denoted by Y.
  6408. +
  6409. +`SUBSCRIPT in ARRAY'
  6410. +     True if array ARRAY has an element with the subscript SUBSCRIPT.
  6411. +
  6412. +   Comparison expressions have the value 1 if true and 0 if false.
  6413. +
  6414. +   The rules `gawk' uses for performing comparisons are based on those
  6415. +in draft 11.2 of the POSIX standard.  The POSIX standard introduced the
  6416. +concept of a "numeric string", which is simply a string that looks like
  6417. +a number, for example, `" +2"'.
  6418. +
  6419. +   When performing a relational operation, `gawk' considers the type of
  6420. +an operand to be the type it received on its last *assignment*, rather
  6421. +than the type of its last *use* (*note Numeric and String Values:
  6422. +Values.).  This type is *unknown* when the operand is from an
  6423. +"external" source: field variables, command line arguments, array
  6424. +elements resulting from a `split' operation, and the value of an
  6425. +`ENVIRON' element.  In this case only, if the operand is a numeric
  6426. +string, then it is considered to be of both string type and numeric
  6427. +type.  If at least one operand of a comparison is of string type only,
  6428. +then a string comparison is performed.  Any numeric operand will be
  6429. +converted to a string using the value of `CONVFMT' (*note Conversion of
  6430. +Strings and Numbers: Conversion.).  If one operand of a comparison is
  6431. +numeric, and the other operand is either numeric or both numeric and
  6432. +string, then `gawk' does a numeric comparison.  If both operands have
  6433. +both types, then the comparison is numeric.  Strings are compared by
  6434. +comparing the first character of each, then the second character of
  6435. +each, and so on.  Thus `"10"' is less than `"9"'.  If there are two
  6436. +strings where one is a prefix of the other, the shorter string is less
  6437. +than the longer one.  Thus `"abc"' is less than `"abcd"'.
  6438. +
  6439. +   Here are some sample expressions, how `gawk' compares them, and what
  6440. +the result of the comparison is.
  6441. +
  6442. +`1.5 <= 2.0'
  6443. +     numeric comparison (true)
  6444. +
  6445. +`"abc" >= "xyz"'
  6446. +     string comparison (false)
  6447. +
  6448. +`1.5 != " +2"'
  6449. +     string comparison (true)
  6450. +
  6451. +`"1e2" < "3"'
  6452. +     string comparison (true)
  6453. +
  6454. +`a = 2; b = "2"'
  6455. +`a == b'
  6456. +     string comparison (true)
  6457. +
  6458. +     echo 1e2 3 | awk '{ print ($1 < $2) ? "true" : "false" }'
  6459. +
  6460. +prints `false' since both `$1' and `$2' are numeric strings and thus
  6461. +have both string and numeric types, thus dictating a numeric comparison.
  6462. +
  6463. +   The purpose of the comparison rules and the use of numeric strings is
  6464. +to attempt to produce the behavior that is "least surprising," while
  6465. +still "doing the right thing."
  6466. +
  6467. +   String comparisons and regular expression comparisons are very
  6468. +different.  For example,
  6469. +
  6470. +     $1 == "foo"
  6471. +
  6472. +has the value of 1, or is true, if the first field of the current input
  6473. +record is precisely `foo'.  By contrast,
  6474. +
  6475. +     $1 ~ /foo/
  6476. +
  6477. +has the value 1 if the first field contains `foo', such as `foobar'.
  6478. +
  6479. +   The right hand operand of the `~' and `!~' operators may be either a
  6480. +constant regexp (`/.../'), or it may be an ordinary expression, in
  6481. +which case the value of the expression as a string is a dynamic regexp
  6482. +(*note How to Use Regular Expressions: Regexp Usage.).
  6483. +
  6484. +   In very recent implementations of `awk', a constant regular
  6485. +expression in slashes by itself is also an expression.  The regexp
  6486. +`/REGEXP/' is an abbreviation for this comparison expression:
  6487. +
  6488. +     $0 ~ /REGEXP/
  6489. +
  6490. +   In some contexts it may be necessary to write parentheses around the
  6491. +regexp to avoid confusing the `gawk' parser.  For example, `(/x/ - /y/)
  6492. +> threshold' is not allowed, but `((/x/) - (/y/)) > threshold' parses
  6493. +properly.
  6494. +
  6495. +   One special place where `/foo/' is *not* an abbreviation for `$0 ~
  6496. +/foo/' is when it is the right-hand operand of `~' or `!~'! *Note
  6497. +Constant Expressions: Constants, where this is discussed in more detail.
  6498. +
  6499. +
  6500. +File: gawk.info,  Node: Boolean Ops,  Next: Assignment Ops,  Prev: Comparison Ops,  Up: Expressions
  6501. +
  6502. +Boolean Expressions
  6503. +===================
  6504. +
  6505. +   A "boolean expression" is a combination of comparison expressions or
  6506. +matching expressions, using the boolean operators "or" (`||'), "and"
  6507. +(`&&'), and "not" (`!'), along with parentheses to control nesting.
  6508. +The truth of the boolean expression is computed by combining the truth
  6509. +values of the component expressions.
  6510. +
  6511. +   Boolean expressions can be used wherever comparison and matching
  6512. +expressions can be used.  They can be used in `if', `while' `do' and
  6513. +`for' statements.  They have numeric values (1 if true, 0 if false),
  6514. +which come into play if the result of the boolean expression is stored
  6515. +in a variable, or used in arithmetic.
  6516. +
  6517. +   In addition, every boolean expression is also a valid boolean
  6518. +pattern, so you can use it as a pattern to control the execution of
  6519. +rules.
  6520. +
  6521. +   Here are descriptions of the three boolean operators, with an
  6522. +example of each.  It may be instructive to compare these examples with
  6523. +the analogous examples of boolean patterns (*note Boolean Operators and
  6524. +Patterns: Boolean Patterns.), which use the same boolean operators in
  6525. +patterns instead of expressions.
  6526. +
  6527. +`BOOLEAN1 && BOOLEAN2'
  6528. +     True if both BOOLEAN1 and BOOLEAN2 are true.  For example, the
  6529. +     following statement prints the current input record if it contains
  6530. +     both `2400' and `foo'.
  6531. +
  6532. +          if ($0 ~ /2400/ && $0 ~ /foo/) print
  6533. +
  6534. +     The subexpression BOOLEAN2 is evaluated only if BOOLEAN1 is true.
  6535. +     This can make a difference when BOOLEAN2 contains expressions that
  6536. +     have side effects: in the case of `$0 ~ /foo/ && ($2 == bar++)',
  6537. +     the variable `bar' is not incremented if there is no `foo' in the
  6538. +     record.
  6539. +
  6540. +`BOOLEAN1 || BOOLEAN2'
  6541. +     True if at least one of BOOLEAN1 or BOOLEAN2 is true.  For
  6542. +     example, the following command prints all records in the input
  6543. +     file `BBS-list' that contain *either* `2400' or `foo', or both.
  6544. +
  6545. +          awk '{ if ($0 ~ /2400/ || $0 ~ /foo/) print }' BBS-list
  6546. +
  6547. +     The subexpression BOOLEAN2 is evaluated only if BOOLEAN1 is false.
  6548. +     This can make a difference when BOOLEAN2 contains expressions
  6549. +     that have side effects.
  6550. +
  6551. +`!BOOLEAN'
  6552. +     True if BOOLEAN is false.  For example, the following program
  6553. +     prints all records in the input file `BBS-list' that do *not*
  6554. +     contain the string `foo'.
  6555. +
  6556. +          awk '{ if (! ($0 ~ /foo/)) print }' BBS-list
  6557. +
  6558. +
  6559. +File: gawk.info,  Node: Assignment Ops,  Next: Increment Ops,  Prev: Boolean Ops,  Up: Expressions
  6560. +
  6561. +Assignment Expressions
  6562. +======================
  6563. +
  6564. +   An "assignment" is an expression that stores a new value into a
  6565. +variable.  For example, let's assign the value 1 to the variable `z':
  6566. +
  6567. +     z = 1
  6568. +
  6569. +   After this expression is executed, the variable `z' has the value 1.
  6570. +Whatever old value `z' had before the assignment is forgotten.
  6571. +
  6572. +   Assignments can store string values also.  For example, this would
  6573. +store the value `"this food is good"' in the variable `message':
  6574. +
  6575. +     thing = "food"
  6576. +     predicate = "good"
  6577. +     message = "this " thing " is " predicate
  6578. +
  6579. +(This also illustrates concatenation of strings.)
  6580. +
  6581. +   The `=' sign is called an "assignment operator".  It is the simplest
  6582. +assignment operator because the value of the right-hand operand is
  6583. +stored unchanged.
  6584. +
  6585. +   Most operators (addition, concatenation, and so on) have no effect
  6586. +except to compute a value.  If you ignore the value, you might as well
  6587. +not use the operator.  An assignment operator is different; it does
  6588. +produce a value, but even if you ignore the value, the assignment still
  6589. +makes itself felt through the alteration of the variable.  We call this
  6590. +a "side effect".
  6591. +
  6592. +   The left-hand operand of an assignment need not be a variable (*note
  6593. +Variables::.); it can also be a field (*note Changing the Contents of a
  6594. +Field: Changing Fields.) or an array element (*note Arrays in `awk':
  6595. +Arrays.).  These are all called "lvalues", which means they can appear
  6596. +on the left-hand side of an assignment operator.  The right-hand
  6597. +operand may be any expression; it produces the new value which the
  6598. +assignment stores in the specified variable, field or array element.
  6599. +
  6600. +   It is important to note that variables do *not* have permanent types.
  6601. +The type of a variable is simply the type of whatever value it happens
  6602. +to hold at the moment.  In the following program fragment, the variable
  6603. +`foo' has a numeric value at first, and a string value later on:
  6604. +
  6605. +     foo = 1
  6606. +     print foo
  6607. +     foo = "bar"
  6608. +     print foo
  6609. +
  6610. +When the second assignment gives `foo' a string value, the fact that it
  6611. +previously had a numeric value is forgotten.
  6612. +
  6613. +   An assignment is an expression, so it has a value: the same value
  6614. +that is assigned.  Thus, `z = 1' as an expression has the value 1.  One
  6615. +consequence of this is that you can write multiple assignments together:
  6616. +
  6617. +     x = y = z = 0
  6618. +
  6619. +stores the value 0 in all three variables.  It does this because the
  6620. +value of `z = 0', which is 0, is stored into `y', and then the value of
  6621. +`y = z = 0', which is 0, is stored into `x'.
  6622. +
  6623. +   You can use an assignment anywhere an expression is called for.  For
  6624. +example, it is valid to write `x != (y = 1)' to set `y' to 1 and then
  6625. +test whether `x' equals 1.  But this style tends to make programs hard
  6626. +to read; except in a one-shot program, you should rewrite it to get rid
  6627. +of such nesting of assignments.  This is never very hard.
  6628. +
  6629. +   Aside from `=', there are several other assignment operators that do
  6630. +arithmetic with the old value of the variable.  For example, the
  6631. +operator `+=' computes a new value by adding the right-hand value to
  6632. +the old value of the variable.  Thus, the following assignment adds 5
  6633. +to the value of `foo':
  6634. +
  6635. +     foo += 5
  6636. +
  6637. +This is precisely equivalent to the following:
  6638. +
  6639. +     foo = foo + 5
  6640. +
  6641. +Use whichever one makes the meaning of your program clearer.
  6642. +
  6643. +   Here is a table of the arithmetic assignment operators.  In each
  6644. +case, the right-hand operand is an expression whose value is converted
  6645. +to a number.
  6646. +
  6647. +`LVALUE += INCREMENT'
  6648. +     Adds INCREMENT to the value of LVALUE to make the new value of
  6649. +     LVALUE.
  6650. +
  6651. +`LVALUE -= DECREMENT'
  6652. +     Subtracts DECREMENT from the value of LVALUE.
  6653. +
  6654. +`LVALUE *= COEFFICIENT'
  6655. +     Multiplies the value of LVALUE by COEFFICIENT.
  6656. +
  6657. +`LVALUE /= QUOTIENT'
  6658. +     Divides the value of LVALUE by QUOTIENT.
  6659. +
  6660. +`LVALUE %= MODULUS'
  6661. +     Sets LVALUE to its remainder by MODULUS.
  6662. +
  6663. +`LVALUE ^= POWER'
  6664. +`LVALUE **= POWER'
  6665. +     Raises LVALUE to the power POWER.  (Only the `^=' operator is
  6666. +     specified by POSIX.)
  6667. +
  6668. +
  6669. +File: gawk.info,  Node: Increment Ops,  Next: Conversion,  Prev: Assignment Ops,  Up: Expressions
  6670. +
  6671. +Increment Operators
  6672. +===================
  6673. +
  6674. +   "Increment operators" increase or decrease the value of a variable
  6675. +by 1.  You could do the same thing with an assignment operator, so the
  6676. +increment operators add no power to the `awk' language; but they are
  6677. +convenient abbreviations for something very common.
  6678. +
  6679. +   The operator to add 1 is written `++'.  It can be used to increment
  6680. +a variable either before or after taking its value.
  6681. +
  6682. +   To pre-increment a variable V, write `++V'.  This adds 1 to the
  6683. +value of V and that new value is also the value of this expression.
  6684. +The assignment expression `V += 1' is completely equivalent.
  6685. +
  6686. +   Writing the `++' after the variable specifies post-increment.  This
  6687. +increments the variable value just the same; the difference is that the
  6688. +value of the increment expression itself is the variable's *old* value.
  6689. +Thus, if `foo' has the value 4, then the expression `foo++' has the
  6690. +value 4, but it changes the value of `foo' to 5.
  6691. +
  6692. +   The post-increment `foo++' is nearly equivalent to writing `(foo +=
  6693. +1) - 1'.  It is not perfectly equivalent because all numbers in `awk'
  6694. +are floating point: in floating point, `foo + 1 - 1' does not
  6695. +necessarily equal `foo'.  But the difference is minute as long as you
  6696. +stick to numbers that are fairly small (less than a trillion).
  6697. +
  6698. +   Any lvalue can be incremented.  Fields and array elements are
  6699. +incremented just like variables.  (Use `$(i++)' when you wish to do a
  6700. +field reference and a variable increment at the same time.  The
  6701. +parentheses are necessary because of the precedence of the field
  6702. +reference operator, `$'.)
  6703. +
  6704. +   The decrement operator `--' works just like `++' except that it
  6705. +subtracts 1 instead of adding.  Like `++', it can be used before the
  6706. +lvalue to pre-decrement or after it to post-decrement.
  6707. +
  6708. +   Here is a summary of increment and decrement expressions.
  6709. +
  6710. +`++LVALUE'
  6711. +     This expression increments LVALUE and the new value becomes the
  6712. +     value of this expression.
  6713. +
  6714. +`LVALUE++'
  6715. +     This expression causes the contents of LVALUE to be incremented.
  6716. +     The value of the expression is the *old* value of LVALUE.
  6717. +
  6718. +`--LVALUE'
  6719. +     Like `++LVALUE', but instead of adding, it subtracts.  It
  6720. +     decrements LVALUE and delivers the value that results.
  6721. +
  6722. +`LVALUE--'
  6723. +     Like `LVALUE++', but instead of adding, it subtracts.  It
  6724. +     decrements LVALUE.  The value of the expression is the *old* value
  6725. +     of LVALUE.
  6726. +
  6727. +
  6728. +File: gawk.info,  Node: Conversion,  Next: Values,  Prev: Increment Ops,  Up: Expressions
  6729. +
  6730. +Conversion of Strings and Numbers
  6731. +=================================
  6732. +
  6733. +   Strings are converted to numbers, and numbers to strings, if the
  6734. +context of the `awk' program demands it.  For example, if the value of
  6735. +either `foo' or `bar' in the expression `foo + bar' happens to be a
  6736. +string, it is converted to a number before the addition is performed.
  6737. +If numeric values appear in string concatenation, they are converted to
  6738. +strings.  Consider this:
  6739. +
  6740. +     two = 2; three = 3
  6741. +     print (two three) + 4
  6742. +
  6743. +This eventually prints the (numeric) value 27.  The numeric values of
  6744. +the variables `two' and `three' are converted to strings and
  6745. +concatenated together, and the resulting string is converted back to the
  6746. +number 23, to which 4 is then added.
  6747. +
  6748. +   If, for some reason, you need to force a number to be converted to a
  6749. +string, concatenate the null string with that number.  To force a string
  6750. +to be converted to a number, add zero to that string.
  6751. +
  6752. +   A string is converted to a number by interpreting a numeric prefix
  6753. +of the string as numerals: `"2.5"' converts to 2.5, `"1e3"' converts to
  6754. +1000, and `"25fix"' has a numeric value of 25.  Strings that can't be
  6755. +interpreted as valid numbers are converted to zero.
  6756. +
  6757. +   The exact manner in which numbers are converted into strings is
  6758. +controlled by the `awk' built-in variable `CONVFMT' (*note Built-in
  6759. +Variables::.).  Numbers are converted using a special version of the
  6760. +`sprintf' function (*note Built-in Functions: Built-in.) with `CONVFMT'
  6761. +as the format specifier.
  6762. +
  6763. +   `CONVFMT''s default value is `"%.6g"', which prints a value with at
  6764. +least six significant digits.  For some applications you will want to
  6765. +change it to specify more precision.  Double precision on most modern
  6766. +machines gives you 16 or 17 decimal digits of precision.
  6767. +
  6768. +   Strange results can happen if you set `CONVFMT' to a string that
  6769. +doesn't tell `sprintf' how to format floating point numbers in a useful
  6770. +way.  For example, if you forget the `%' in the format, all numbers
  6771. +will be converted to the same constant string.
  6772. +
  6773. +   As a special case, if a number is an integer, then the result of
  6774. +converting it to a string is *always* an integer, no matter what the
  6775. +value of `CONVFMT' may be.  Given the following code fragment:
  6776. +
  6777. +     CONVFMT = "%2.2f"
  6778. +     a = 12
  6779. +     b = a ""
  6780. +
  6781. +`b' has the value `"12"', not `"12.00"'.
  6782. +
  6783. +   Prior to the POSIX standard, `awk' specified that the value of
  6784. +`OFMT' was used for converting numbers to strings.  `OFMT' specifies
  6785. +the output format to use when printing numbers with `print'.  `CONVFMT'
  6786. +was introduced in order to separate the semantics of conversions from
  6787. +the semantics of printing.  Both `CONVFMT' and `OFMT' have the same
  6788. +default value: `"%.6g"'.  In the vast majority of cases, old `awk'
  6789. +programs will not change their behavior.  However, this use of `OFMT'
  6790. +is something to keep in mind if you must port your program to other
  6791. +implementations of `awk'; we recommend that instead of changing your
  6792. +programs, you just port `gawk' itself!
  6793. +
  6794. +
  6795. +File: gawk.info,  Node: Values,  Next: Conditional Exp,  Prev: Conversion,  Up: Expressions
  6796. +
  6797. +Numeric and String Values
  6798. +=========================
  6799. +
  6800. +   Through most of this manual, we present `awk' values (such as
  6801. +constants, fields, or variables) as *either* numbers *or* strings.
  6802. +This is a convenient way to think about them, since typically they are
  6803. +used in only one way, or the other.
  6804. +
  6805. +   In truth though, `awk' values can be *both* string and numeric, at
  6806. +the same time.  Internally, `awk' represents values with a string, a
  6807. +(floating point) number, and an indication that one, the other, or both
  6808. +representations of the value are valid.
  6809. +
  6810. +   Keeping track of both kinds of values is important for execution
  6811. +efficiency:  a variable can acquire a string value the first time it is
  6812. +used as a string, and then that string value can be used until the
  6813. +variable is assigned a new value.  Thus, if a variable with only a
  6814. +numeric value is used in several concatenations in a row, it only has
  6815. +to be given a string representation once.  The numeric value remains
  6816. +valid, so that no conversion back to a number is necessary if the
  6817. +variable is later used in an arithmetic expression.
  6818. +
  6819. +   Tracking both kinds of values is also important for precise numerical
  6820. +calculations.  Consider the following:
  6821. +
  6822. +     a = 123.321
  6823. +     CONVFMT = "%3.1f"
  6824. +     b = a " is a number"
  6825. +     c = a + 1.654
  6826. +
  6827. +The variable `a' receives a string value in the concatenation and
  6828. +assignment to `b'.  The string value of `a' is `"123.3"'.  If the
  6829. +numeric value was lost when it was converted to a string, then the
  6830. +numeric use of `a' in the last statement would lose information.  `c'
  6831. +would be assigned the value 124.954 instead of 124.975.  Such errors
  6832. +accumulate rapidly, and very adversely affect numeric computations.
  6833. +
  6834. +   Once a numeric value acquires a corresponding string value, it stays
  6835. +valid until a new assignment is made.  If `CONVFMT' (*note Conversion
  6836. +of Strings and Numbers: Conversion.) changes in the meantime, the old
  6837. +string value will still be used.  For example:
  6838. +
  6839. +     BEGIN {
  6840. +         CONVFMT = "%2.2f"
  6841. +         a = 123.456
  6842. +         b = a ""                # force `a' to have string value too
  6843. +         printf "a = %s\n", a
  6844. +         CONVFMT = "%.6g"
  6845. +         printf "a = %s\n", a
  6846. +         a += 0                  # make `a' numeric only again
  6847. +         printf "a = %s\n", a    # use `a' as string
  6848. +     }
  6849. +
  6850. +This program prints `a = 123.46' twice, and then prints `a = 123.456'.
  6851. +
  6852. +   *Note Conversion of Strings and Numbers: Conversion, for the rules
  6853. +that specify how string values are made from numeric values.
  6854. +
  6855. +
  6856. +File: gawk.info,  Node: Conditional Exp,  Next: Function Calls,  Prev: Values,  Up: Expressions
  6857. +
  6858. +Conditional Expressions
  6859. +=======================
  6860. +
  6861. +   A "conditional expression" is a special kind of expression with
  6862. +three operands.  It allows you to use one expression's value to select
  6863. +one of two other expressions.
  6864. +
  6865. +   The conditional expression looks the same as in the C language:
  6866. +
  6867. +     SELECTOR ? IF-TRUE-EXP : IF-FALSE-EXP
  6868. +
  6869. +There are three subexpressions.  The first, SELECTOR, is always
  6870. +computed first.  If it is "true" (not zero and not null) then
  6871. +IF-TRUE-EXP is computed next and its value becomes the value of the
  6872. +whole expression.  Otherwise, IF-FALSE-EXP is computed next and its
  6873. +value becomes the value of the whole expression.
  6874. +
  6875. +   For example, this expression produces the absolute value of `x':
  6876. +
  6877. +     x > 0 ? x : -x
  6878. +
  6879. +   Each time the conditional expression is computed, exactly one of
  6880. +IF-TRUE-EXP and IF-FALSE-EXP is computed; the other is ignored.  This
  6881. +is important when the expressions contain side effects.  For example,
  6882. +this conditional expression examines element `i' of either array `a' or
  6883. +array `b', and increments `i'.
  6884. +
  6885. +     x == y ? a[i++] : b[i++]
  6886. +
  6887. +This is guaranteed to increment `i' exactly once, because each time one
  6888. +or the other of the two increment expressions is executed, and the
  6889. +other is not.
  6890. +
  6891. +
  6892. +File: gawk.info,  Node: Function Calls,  Next: Precedence,  Prev: Conditional Exp,  Up: Expressions
  6893. +
  6894. +Function Calls
  6895. +==============
  6896. +
  6897. +   A "function" is a name for a particular calculation.  Because it has
  6898. +a name, you can ask for it by name at any point in the program.  For
  6899. +example, the function `sqrt' computes the square root of a number.
  6900. +
  6901. +   A fixed set of functions are "built-in", which means they are
  6902. +available in every `awk' program.  The `sqrt' function is one of these.
  6903. +*Note Built-in Functions: Built-in, for a list of built-in functions
  6904. +and their descriptions.  In addition, you can define your own functions
  6905. +in the program for use elsewhere in the same program.  *Note
  6906. +User-defined Functions: User-defined, for how to do this.
  6907. +
  6908. +   The way to use a function is with a "function call" expression,
  6909. +which consists of the function name followed by a list of "arguments"
  6910. +in parentheses.  The arguments are expressions which give the raw
  6911. +materials for the calculation that the function will do.  When there is
  6912. +more than one argument, they are separated by commas.  If there are no
  6913. +arguments, write just `()' after the function name.  Here are some
  6914. +examples:
  6915. +
  6916. +     sqrt(x^2 + y^2)      # One argument
  6917. +     atan2(y, x)          # Two arguments
  6918. +     rand()               # No arguments
  6919. +
  6920. +   *Do not put any space between the function name and the
  6921. +open-parenthesis!*  A user-defined function name looks just like the
  6922. +name of a variable, and space would make the expression look like
  6923. +concatenation of a variable with an expression inside parentheses.
  6924. +Space before the parenthesis is harmless with built-in functions, but
  6925. +it is best not to get into the habit of using space to avoid mistakes
  6926. +with user-defined functions.
  6927. +
  6928. +   Each function expects a particular number of arguments.  For
  6929. +example, the `sqrt' function must be called with a single argument, the
  6930. +number to take the square root of:
  6931. +
  6932. +     sqrt(ARGUMENT)
  6933. +
  6934. +   Some of the built-in functions allow you to omit the final argument.
  6935. +If you do so, they use a reasonable default.  *Note Built-in Functions:
  6936. +Built-in, for full details.  If arguments are omitted in calls to
  6937. +user-defined functions, then those arguments are treated as local
  6938. +variables, initialized to the null string (*note User-defined
  6939. +Functions: User-defined.).
  6940. +
  6941. +   Like every other expression, the function call has a value, which is
  6942. +computed by the function based on the arguments you give it.  In this
  6943. +example, the value of `sqrt(ARGUMENT)' is the square root of the
  6944. +argument.  A function can also have side effects, such as assigning the
  6945. +values of certain variables or doing I/O.
  6946. +
  6947. +   Here is a command to read numbers, one number per line, and print the
  6948. +square root of each one:
  6949. +
  6950. +     awk '{ print "The square root of", $1, "is", sqrt($1) }'
  6951. +
  6952. +
  6953. +File: gawk.info,  Node: Precedence,  Prev: Function Calls,  Up: Expressions
  6954. +
  6955. +Operator Precedence (How Operators Nest)
  6956. +========================================
  6957. +
  6958. +   "Operator precedence" determines how operators are grouped, when
  6959. +different operators appear close by in one expression.  For example,
  6960. +`*' has higher precedence than `+'; thus, `a + b * c' means to multiply
  6961. +`b' and `c', and then add `a' to the product (i.e., `a + (b * c)').
  6962. +
  6963. +   You can overrule the precedence of the operators by using
  6964. +parentheses.  You can think of the precedence rules as saying where the
  6965. +parentheses are assumed if you do not write parentheses yourself.  In
  6966. +fact, it is wise to always use parentheses whenever you have an unusual
  6967. +combination of operators, because other people who read the program may
  6968. +not remember what the precedence is in this case.  You might forget,
  6969. +too; then you could make a mistake.  Explicit parentheses will help
  6970. +prevent any such mistake.
  6971. +
  6972. +   When operators of equal precedence are used together, the leftmost
  6973. +operator groups first, except for the assignment, conditional and
  6974. +exponentiation operators, which group in the opposite order.  Thus, `a
  6975. +- b + c' groups as `(a - b) + c'; `a = b = c' groups as `a = (b = c)'.
  6976. +
  6977. +   The precedence of prefix unary operators does not matter as long as
  6978. +only unary operators are involved, because there is only one way to
  6979. +parse them--innermost first.  Thus, `$++i' means `$(++i)' and `++$x'
  6980. +means `++($x)'.  However, when another operator follows the operand,
  6981. +then the precedence of the unary operators can matter.  Thus, `$x^2'
  6982. +means `($x)^2', but `-x^2' means `-(x^2)', because `-' has lower
  6983. +precedence than `^' while `$' has higher precedence.
  6984. +
  6985. +   Here is a table of the operators of `awk', in order of increasing
  6986. +precedence:
  6987. +
  6988. +assignment
  6989. +     `=', `+=', `-=', `*=', `/=', `%=', `^=', `**='.  These operators
  6990. +     group right-to-left.  (The `**=' operator is not specified by
  6991. +     POSIX.)
  6992. +
  6993. +conditional
  6994. +     `?:'.  This operator groups right-to-left.
  6995. +
  6996. +logical "or".
  6997. +     `||'.
  6998. +
  6999. +logical "and".
  7000. +     `&&'.
  7001. +
  7002. +array membership
  7003. +     `in'.
  7004. +
  7005. +matching
  7006. +     `~', `!~'.
  7007. +
  7008. +relational, and redirection
  7009. +     The relational operators and the redirections have the same
  7010. +     precedence level.  Characters such as `>' serve both as
  7011. +     relationals and as redirections; the context distinguishes between
  7012. +     the two meanings.
  7013. +
  7014. +     The relational operators are `<', `<=', `==', `!=', `>=' and `>'.
  7015. +
  7016. +     The I/O redirection operators are `<', `>', `>>' and `|'.
  7017. +
  7018. +     Note that I/O redirection operators in `print' and `printf'
  7019. +     statements belong to the statement level, not to expressions.  The
  7020. +     redirection does not produce an expression which could be the
  7021. +     operand of another operator.  As a result, it does not make sense
  7022. +     to use a redirection operator near another operator of lower
  7023. +     precedence, without parentheses.  Such combinations, for example
  7024. +     `print foo > a ? b : c', result in syntax errors.
  7025. +
  7026. +concatenation
  7027. +     No special token is used to indicate concatenation.  The operands
  7028. +     are simply written side by side.
  7029. +
  7030. +add, subtract
  7031. +     `+', `-'.
  7032. +
  7033. +multiply, divide, mod
  7034. +     `*', `/', `%'.
  7035. +
  7036. +unary plus, minus, "not"
  7037. +     `+', `-', `!'.
  7038. +
  7039. +exponentiation
  7040. +     `^', `**'.  These operators group right-to-left.  (The `**'
  7041. +     operator is not specified by POSIX.)
  7042. +
  7043. +increment, decrement
  7044. +     `++', `--'.
  7045. +
  7046. +field
  7047. +     `$'.
  7048. +
  7049. +
  7050. +File: gawk.info,  Node: Statements,  Next: Arrays,  Prev: Expressions,  Up: Top
  7051. +
  7052. +Control Statements in Actions
  7053. +*****************************
  7054. +
  7055. +   "Control statements" such as `if', `while', and so on control the
  7056. +flow of execution in `awk' programs.  Most of the control statements in
  7057. +`awk' are patterned on similar statements in C.
  7058. +
  7059. +   All the control statements start with special keywords such as `if'
  7060. +and `while', to distinguish them from simple expressions.
  7061. +
  7062. +   Many control statements contain other statements; for example, the
  7063. +`if' statement contains another statement which may or may not be
  7064. +executed.  The contained statement is called the "body".  If you want
  7065. +to include more than one statement in the body, group them into a
  7066. +single compound statement with curly braces, separating them with
  7067. +newlines or semicolons.
  7068. +
  7069. +* Menu:
  7070. +
  7071. +* If Statement::                Conditionally execute
  7072. +                                some `awk' statements.
  7073. +* While Statement::             Loop until some condition is satisfied.
  7074. +* Do Statement::                Do specified action while looping until some
  7075. +                                condition is satisfied.
  7076. +* For Statement::               Another looping statement, that provides
  7077. +                                initialization and increment clauses.
  7078. +* Break Statement::             Immediately exit the innermost enclosing loop.
  7079. +* Continue Statement::          Skip to the end of the innermost
  7080. +                                enclosing loop.
  7081. +* Next Statement::              Stop processing the current input record.
  7082. +* Next File Statement::         Stop processing the current file.
  7083. +* Exit Statement::              Stop execution of `awk'.
  7084. +
  7085. +
  7086. +File: gawk.info,  Node: If Statement,  Next: While Statement,  Prev: Statements,  Up: Statements
  7087. +
  7088. +The `if' Statement
  7089. +==================
  7090. +
  7091. +   The `if'-`else' statement is `awk''s decision-making statement.  It
  7092. +looks like this:
  7093. +
  7094. +     if (CONDITION) THEN-BODY [else ELSE-BODY]
  7095. +
  7096. +CONDITION is an expression that controls what the rest of the statement
  7097. +will do.  If CONDITION is true, THEN-BODY is executed; otherwise,
  7098. +ELSE-BODY is executed (assuming that the `else' clause is present).
  7099. +The `else' part of the statement is optional.  The condition is
  7100. +considered false if its value is zero or the null string, and true
  7101. +otherwise.
  7102. +
  7103. +   Here is an example:
  7104. +
  7105. +     if (x % 2 == 0)
  7106. +         print "x is even"
  7107. +     else
  7108. +         print "x is odd"
  7109. +
  7110. +   In this example, if the expression `x % 2 == 0' is true (that is,
  7111. +the value of `x' is divisible by 2), then the first `print' statement
  7112. +is executed, otherwise the second `print' statement is performed.
  7113. +
  7114. +   If the `else' appears on the same line as THEN-BODY, and THEN-BODY
  7115. +is not a compound statement (i.e., not surrounded by curly braces),
  7116. +then a semicolon must separate THEN-BODY from `else'.  To illustrate
  7117. +this, let's rewrite the previous example:
  7118. +
  7119. +     awk '{ if (x % 2 == 0) print "x is even"; else
  7120. +             print "x is odd" }'
  7121. +
  7122. +If you forget the `;', `awk' won't be able to parse the statement, and
  7123. +you will get a syntax error.
  7124. +
  7125. +   We would not actually write this example this way, because a human
  7126. +reader might fail to see the `else' if it were not the first thing on
  7127. +its line.
  7128. +
  7129. +
  7130. +File: gawk.info,  Node: While Statement,  Next: Do Statement,  Prev: If Statement,  Up: Statements
  7131. +
  7132. +The `while' Statement
  7133. +=====================
  7134. +
  7135. +   In programming, a "loop" means a part of a program that is (or at
  7136. +least can be) executed two or more times in succession.
  7137. +
  7138. +   The `while' statement is the simplest looping statement in `awk'.
  7139. +It repeatedly executes a statement as long as a condition is true.  It
  7140. +looks like this:
  7141. +
  7142. +     while (CONDITION)
  7143. +       BODY
  7144. +
  7145. +Here BODY is a statement that we call the "body" of the loop, and
  7146. +CONDITION is an expression that controls how long the loop keeps
  7147. +running.
  7148. +
  7149. +   The first thing the `while' statement does is test CONDITION.  If
  7150. +CONDITION is true, it executes the statement BODY.  (CONDITION is true
  7151. +when the value is not zero and not a null string.)  After BODY has been
  7152. +executed, CONDITION is tested again, and if it is still true, BODY is
  7153. +executed again.  This process repeats until CONDITION is no longer
  7154. +true.  If CONDITION is initially false, the body of the loop is never
  7155. +executed.
  7156. +
  7157. +   This example prints the first three fields of each record, one per
  7158. +line.
  7159. +
  7160. +     awk '{ i = 1
  7161. +            while (i <= 3) {
  7162. +                print $i
  7163. +                i++
  7164. +            }
  7165. +     }'
  7166. +
  7167. +Here the body of the loop is a compound statement enclosed in braces,
  7168. +containing two statements.
  7169. +
  7170. +   The loop works like this: first, the value of `i' is set to 1.
  7171. +Then, the `while' tests whether `i' is less than or equal to three.
  7172. +This is the case when `i' equals one, so the `i'-th field is printed.
  7173. +Then the `i++' increments the value of `i' and the loop repeats.  The
  7174. +loop terminates when `i' reaches 4.
  7175. +
  7176. +   As you can see, a newline is not required between the condition and
  7177. +the body; but using one makes the program clearer unless the body is a
  7178. +compound statement or is very simple.  The newline after the open-brace
  7179. +that begins the compound statement is not required either, but the
  7180. +program would be hard to read without it.
  7181. +
  7182. +
  7183. +File: gawk.info,  Node: Do Statement,  Next: For Statement,  Prev: While Statement,  Up: Statements
  7184. +
  7185. +The `do'-`while' Statement
  7186. +==========================
  7187. +
  7188. +   The `do' loop is a variation of the `while' looping statement.  The
  7189. +`do' loop executes the BODY once, then repeats BODY as long as
  7190. +CONDITION is true.  It looks like this:
  7191. +
  7192. +     do
  7193. +       BODY
  7194. +     while (CONDITION)
  7195. +
  7196. +   Even if CONDITION is false at the start, BODY is executed at least
  7197. +once (and only once, unless executing BODY makes CONDITION true).
  7198. +Contrast this with the corresponding `while' statement:
  7199. +
  7200. +     while (CONDITION)
  7201. +       BODY
  7202. +
  7203. +This statement does not execute BODY even once if CONDITION is false to
  7204. +begin with.
  7205. +
  7206. +   Here is an example of a `do' statement:
  7207. +
  7208. +     awk '{ i = 1
  7209. +            do {
  7210. +               print $0
  7211. +               i++
  7212. +            } while (i <= 10)
  7213. +     }'
  7214. +
  7215. +prints each input record ten times.  It isn't a very realistic example,
  7216. +since in this case an ordinary `while' would do just as well.  But this
  7217. +reflects actual experience; there is only occasionally a real use for a
  7218. +`do' statement.
  7219. +
  7220. diff -rup --new-file baseline/fsf/gawk/gawk.info-5 amiga/fsf/gawk/gawk.info-5
  7221. --- baseline/fsf/gawk/gawk.info-5    Wed Dec 31 17:00:00 1969
  7222. +++ amiga/fsf/gawk/gawk.info-5    Sat Sep 28 00:00:00 1996
  7223. @@ -0,0 +1,1256 @@
  7224. +This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  7225. +file /gnu-src/gawk-2.15.6/gawk.texi.
  7226. +
  7227. +   This file documents `awk', a program that you can use to select
  7228. +particular records in a file and perform operations upon them.
  7229. +
  7230. +   This is Edition 0.15 of `The GAWK Manual',
  7231. +for the 2.15 version of the GNU implementation
  7232. +of AWK.
  7233. +
  7234. +   Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  7235. +
  7236. +   Permission is granted to make and distribute verbatim copies of this
  7237. +manual provided the copyright notice and this permission notice are
  7238. +preserved on all copies.
  7239. +
  7240. +   Permission is granted to copy and distribute modified versions of
  7241. +this manual under the conditions for verbatim copying, provided that
  7242. +the entire resulting derived work is distributed under the terms of a
  7243. +permission notice identical to this one.
  7244. +
  7245. +   Permission is granted to copy and distribute translations of this
  7246. +manual into another language, under the above conditions for modified
  7247. +versions, except that this permission notice may be stated in a
  7248. +translation approved by the Foundation.
  7249. +
  7250. +
  7251. +File: gawk.info,  Node: For Statement,  Next: Break Statement,  Prev: Do Statement,  Up: Statements
  7252. +
  7253. +The `for' Statement
  7254. +===================
  7255. +
  7256. +   The `for' statement makes it more convenient to count iterations of a
  7257. +loop.  The general form of the `for' statement looks like this:
  7258. +
  7259. +     for (INITIALIZATION; CONDITION; INCREMENT)
  7260. +       BODY
  7261. +
  7262. +This statement starts by executing INITIALIZATION.  Then, as long as
  7263. +CONDITION is true, it repeatedly executes BODY and then INCREMENT.
  7264. +Typically INITIALIZATION sets a variable to either zero or one,
  7265. +INCREMENT adds 1 to it, and CONDITION compares it against the desired
  7266. +number of iterations.
  7267. +
  7268. +   Here is an example of a `for' statement:
  7269. +
  7270. +     awk '{ for (i = 1; i <= 3; i++)
  7271. +               print $i
  7272. +     }'
  7273. +
  7274. +This prints the first three fields of each input record, one field per
  7275. +line.
  7276. +
  7277. +   In the `for' statement, BODY stands for any statement, but
  7278. +INITIALIZATION, CONDITION and INCREMENT are just expressions.  You
  7279. +cannot set more than one variable in the INITIALIZATION part unless you
  7280. +use a multiple assignment statement such as `x = y = 0', which is
  7281. +possible only if all the initial values are equal.  (But you can
  7282. +initialize additional variables by writing their assignments as
  7283. +separate statements preceding the `for' loop.)
  7284. +
  7285. +   The same is true of the INCREMENT part; to increment additional
  7286. +variables, you must write separate statements at the end of the loop.
  7287. +The C compound expression, using C's comma operator, would be useful in
  7288. +this context, but it is not supported in `awk'.
  7289. +
  7290. +   Most often, INCREMENT is an increment expression, as in the example
  7291. +above.  But this is not required; it can be any expression whatever.
  7292. +For example, this statement prints all the powers of 2 between 1 and
  7293. +100:
  7294. +
  7295. +     for (i = 1; i <= 100; i *= 2)
  7296. +       print i
  7297. +
  7298. +   Any of the three expressions in the parentheses following the `for'
  7299. +may be omitted if there is nothing to be done there.  Thus,
  7300. +`for (;x > 0;)' is equivalent to `while (x > 0)'.  If the CONDITION is
  7301. +omitted, it is treated as TRUE, effectively yielding an "infinite loop"
  7302. +(i.e., a loop that will never terminate).
  7303. +
  7304. +   In most cases, a `for' loop is an abbreviation for a `while' loop,
  7305. +as shown here:
  7306. +
  7307. +     INITIALIZATION
  7308. +     while (CONDITION) {
  7309. +       BODY
  7310. +       INCREMENT
  7311. +     }
  7312. +
  7313. +The only exception is when the `continue' statement (*note The
  7314. +`continue' Statement: Continue Statement.) is used inside the loop;
  7315. +changing a `for' statement to a `while' statement in this way can
  7316. +change the effect of the `continue' statement inside the loop.
  7317. +
  7318. +   There is an alternate version of the `for' loop, for iterating over
  7319. +all the indices of an array:
  7320. +
  7321. +     for (i in array)
  7322. +         DO SOMETHING WITH array[i]
  7323. +
  7324. +*Note Arrays in `awk': Arrays, for more information on this version of
  7325. +the `for' loop.
  7326. +
  7327. +   The `awk' language has a `for' statement in addition to a `while'
  7328. +statement because often a `for' loop is both less work to type and more
  7329. +natural to think of.  Counting the number of iterations is very common
  7330. +in loops.  It can be easier to think of this counting as part of
  7331. +looping rather than as something to do inside the loop.
  7332. +
  7333. +   The next section has more complicated examples of `for' loops.
  7334. +
  7335. +
  7336. +File: gawk.info,  Node: Break Statement,  Next: Continue Statement,  Prev: For Statement,  Up: Statements
  7337. +
  7338. +The `break' Statement
  7339. +=====================
  7340. +
  7341. +   The `break' statement jumps out of the innermost `for', `while', or
  7342. +`do'-`while' loop that encloses it.  The following example finds the
  7343. +smallest divisor of any integer, and also identifies prime numbers:
  7344. +
  7345. +     awk '# find smallest divisor of num
  7346. +          { num = $1
  7347. +            for (div = 2; div*div <= num; div++)
  7348. +              if (num % div == 0)
  7349. +                break
  7350. +            if (num % div == 0)
  7351. +              printf "Smallest divisor of %d is %d\n", num, div
  7352. +            else
  7353. +              printf "%d is prime\n", num  }'
  7354. +
  7355. +   When the remainder is zero in the first `if' statement, `awk'
  7356. +immediately "breaks out" of the containing `for' loop.  This means that
  7357. +`awk' proceeds immediately to the statement following the loop and
  7358. +continues processing.  (This is very different from the `exit'
  7359. +statement which stops the entire `awk' program.  *Note The `exit'
  7360. +Statement: Exit Statement.)
  7361. +
  7362. +   Here is another program equivalent to the previous one.  It
  7363. +illustrates how the CONDITION of a `for' or `while' could just as well
  7364. +be replaced with a `break' inside an `if':
  7365. +
  7366. +     awk '# find smallest divisor of num
  7367. +          { num = $1
  7368. +            for (div = 2; ; div++) {
  7369. +              if (num % div == 0) {
  7370. +                printf "Smallest divisor of %d is %d\n", num, div
  7371. +                break
  7372. +              }
  7373. +              if (div*div > num) {
  7374. +                printf "%d is prime\n", num
  7375. +                break
  7376. +              }
  7377. +            }
  7378. +     }'
  7379. +
  7380. +
  7381. +File: gawk.info,  Node: Continue Statement,  Next: Next Statement,  Prev: Break Statement,  Up: Statements
  7382. +
  7383. +The `continue' Statement
  7384. +========================
  7385. +
  7386. +   The `continue' statement, like `break', is used only inside `for',
  7387. +`while', and `do'-`while' loops.  It skips over the rest of the loop
  7388. +body, causing the next cycle around the loop to begin immediately.
  7389. +Contrast this with `break', which jumps out of the loop altogether.
  7390. +Here is an example:
  7391. +
  7392. +     # print names that don't contain the string "ignore"
  7393. +     
  7394. +     # first, save the text of each line
  7395. +     { names[NR] = $0 }
  7396. +     
  7397. +     # print what we're interested in
  7398. +     END {
  7399. +        for (x in names) {
  7400. +            if (names[x] ~ /ignore/)
  7401. +                continue
  7402. +            print names[x]
  7403. +        }
  7404. +     }
  7405. +
  7406. +   If one of the input records contains the string `ignore', this
  7407. +example skips the print statement for that record, and continues back to
  7408. +the first statement in the loop.
  7409. +
  7410. +   This is not a practical example of `continue', since it would be
  7411. +just as easy to write the loop like this:
  7412. +
  7413. +     for (x in names)
  7414. +       if (names[x] !~ /ignore/)
  7415. +         print names[x]
  7416. +
  7417. +   The `continue' statement in a `for' loop directs `awk' to skip the
  7418. +rest of the body of the loop, and resume execution with the
  7419. +increment-expression of the `for' statement.  The following program
  7420. +illustrates this fact:
  7421. +
  7422. +     awk 'BEGIN {
  7423. +          for (x = 0; x <= 20; x++) {
  7424. +              if (x == 5)
  7425. +                  continue
  7426. +              printf ("%d ", x)
  7427. +          }
  7428. +          print ""
  7429. +     }'
  7430. +
  7431. +This program prints all the numbers from 0 to 20, except for 5, for
  7432. +which the `printf' is skipped.  Since the increment `x++' is not
  7433. +skipped, `x' does not remain stuck at 5.  Contrast the `for' loop above
  7434. +with the `while' loop:
  7435. +
  7436. +     awk 'BEGIN {
  7437. +          x = 0
  7438. +          while (x <= 20) {
  7439. +              if (x == 5)
  7440. +                  continue
  7441. +              printf ("%d ", x)
  7442. +              x++
  7443. +          }
  7444. +          print ""
  7445. +     }'
  7446. +
  7447. +This program loops forever once `x' gets to 5.
  7448. +
  7449. +   As described above, the `continue' statement has no meaning when
  7450. +used outside the body of a loop.  However, although it was never
  7451. +documented, historical implementations of `awk' have treated the
  7452. +`continue' statement outside of a loop as if it were a `next' statement
  7453. +(*note The `next' Statement: Next Statement.).  By default, `gawk'
  7454. +silently supports this usage.  However, if `-W posix' has been
  7455. +specified on the command line (*note Invoking `awk': Command Line.), it
  7456. +will be treated as an error, since the POSIX standard specifies that
  7457. +`continue' should only be used inside the body of a loop.
  7458. +
  7459. +
  7460. +File: gawk.info,  Node: Next Statement,  Next: Next File Statement,  Prev: Continue Statement,  Up: Statements
  7461. +
  7462. +The `next' Statement
  7463. +====================
  7464. +
  7465. +   The `next' statement forces `awk' to immediately stop processing the
  7466. +current record and go on to the next record.  This means that no
  7467. +further rules are executed for the current record.  The rest of the
  7468. +current rule's action is not executed either.
  7469. +
  7470. +   Contrast this with the effect of the `getline' function (*note
  7471. +Explicit Input with `getline': Getline.).  That too causes `awk' to
  7472. +read the next record immediately, but it does not alter the flow of
  7473. +control in any way.  So the rest of the current action executes with a
  7474. +new input record.
  7475. +
  7476. +   At the highest level, `awk' program execution is a loop that reads
  7477. +an input record and then tests each rule's pattern against it.  If you
  7478. +think of this loop as a `for' statement whose body contains the rules,
  7479. +then the `next' statement is analogous to a `continue' statement: it
  7480. +skips to the end of the body of this implicit loop, and executes the
  7481. +increment (which reads another record).
  7482. +
  7483. +   For example, if your `awk' program works only on records with four
  7484. +fields, and you don't want it to fail when given bad input, you might
  7485. +use this rule near the beginning of the program:
  7486. +
  7487. +     NF != 4 {
  7488. +       printf("line %d skipped: doesn't have 4 fields", FNR) > "/dev/stderr"
  7489. +       next
  7490. +     }
  7491. +
  7492. +so that the following rules will not see the bad record.  The error
  7493. +message is redirected to the standard error output stream, as error
  7494. +messages should be.  *Note Standard I/O Streams: Special Files.
  7495. +
  7496. +   According to the POSIX standard, the behavior is undefined if the
  7497. +`next' statement is used in a `BEGIN' or `END' rule.  `gawk' will treat
  7498. +it as a syntax error.
  7499. +
  7500. +   If the `next' statement causes the end of the input to be reached,
  7501. +then the code in the `END' rules, if any, will be executed.  *Note
  7502. +`BEGIN' and `END' Special Patterns: BEGIN/END.
  7503. +
  7504. +
  7505. +File: gawk.info,  Node: Next File Statement,  Next: Exit Statement,  Prev: Next Statement,  Up: Statements
  7506. +
  7507. +The `next file' Statement
  7508. +=========================
  7509. +
  7510. +   The `next file' statement is similar to the `next' statement.
  7511. +However, instead of abandoning processing of the current record, the
  7512. +`next file' statement instructs `awk' to stop processing the current
  7513. +data file.
  7514. +
  7515. +   Upon execution of the `next file' statement, `FILENAME' is updated
  7516. +to the name of the next data file listed on the command line, `FNR' is
  7517. +reset to 1, and processing starts over with the first rule in the
  7518. +progam.  *Note Built-in Variables::.
  7519. +
  7520. +   If the `next file' statement causes the end of the input to be
  7521. +reached, then the code in the `END' rules, if any, will be executed.
  7522. +*Note `BEGIN' and `END' Special Patterns: BEGIN/END.
  7523. +
  7524. +   The `next file' statement is a `gawk' extension; it is not
  7525. +(currently) available in any other `awk' implementation.  You can
  7526. +simulate its behavior by creating a library file named `nextfile.awk',
  7527. +with the following contents.  (This sample program uses user-defined
  7528. +functions, a feature that has not been presented yet.  *Note
  7529. +User-defined Functions: User-defined, for more information.)
  7530. +
  7531. +     # nextfile --- function to skip remaining records in current file
  7532. +     
  7533. +     # this should be read in before the "main" awk program
  7534. +     
  7535. +     function nextfile() { _abandon_ = FILENAME; next }
  7536. +     
  7537. +     _abandon_ == FILENAME && FNR > 1   { next }
  7538. +     _abandon_ == FILENAME && FNR == 1  { _abandon_ = "" }
  7539. +
  7540. +   The `nextfile' function simply sets a "private" variable(1) to the
  7541. +name of the current data file, and then retrieves the next record.
  7542. +Since this file is read before the main `awk' program, the rules that
  7543. +follows the function definition will be executed before the rules in
  7544. +the main program.  The first rule continues to skip records as long as
  7545. +the name of the input file has not changed, and this is not the first
  7546. +record in the file.  This rule is sufficient most of the time.  But
  7547. +what if the *same* data file is named twice in a row on the command
  7548. +line?  This rule would not process the data file the second time.  The
  7549. +second rule catches this case: If the data file name is what was being
  7550. +skipped, but `FNR' is 1, then this is the second time the file is being
  7551. +processed, and it should not be skipped.
  7552. +
  7553. +   The `next file' statement would be useful if you have many data
  7554. +files to process, and due to the nature of the data, you expect that you
  7555. +would not want to process every record in the file.  In order to move
  7556. +on to the next data file, you would have to continue scanning the
  7557. +unwanted records (as described above).  The `next file' statement
  7558. +accomplishes this much more efficiently.
  7559. +
  7560. +   ---------- Footnotes ----------
  7561. +
  7562. +   (1)  Since all variables in `awk' are global, this program uses the
  7563. +common practice of prefixing the variable name with an underscore.  In
  7564. +fact, it also suffixes the variable name with an underscore, as extra
  7565. +insurance against using a variable name that might be used in some
  7566. +other library file.
  7567. +
  7568. +
  7569. +File: gawk.info,  Node: Exit Statement,  Prev: Next File Statement,  Up: Statements
  7570. +
  7571. +The `exit' Statement
  7572. +====================
  7573. +
  7574. +   The `exit' statement causes `awk' to immediately stop executing the
  7575. +current rule and to stop processing input; any remaining input is
  7576. +ignored.
  7577. +
  7578. +   If an `exit' statement is executed from a `BEGIN' rule the program
  7579. +stops processing everything immediately.  No input records are read.
  7580. +However, if an `END' rule is present, it is executed (*note `BEGIN' and
  7581. +`END' Special Patterns: BEGIN/END.).
  7582. +
  7583. +   If `exit' is used as part of an `END' rule, it causes the program to
  7584. +stop immediately.
  7585. +
  7586. +   An `exit' statement that is part of an ordinary rule (that is, not
  7587. +part of a `BEGIN' or `END' rule) stops the execution of any further
  7588. +automatic rules, but the `END' rule is executed if there is one.  If
  7589. +you do not want the `END' rule to do its job in this case, you can set
  7590. +a variable to nonzero before the `exit' statement, and check that
  7591. +variable in the `END' rule.
  7592. +
  7593. +   If an argument is supplied to `exit', its value is used as the exit
  7594. +status code for the `awk' process.  If no argument is supplied, `exit'
  7595. +returns status zero (success).
  7596. +
  7597. +   For example, let's say you've discovered an error condition you
  7598. +really don't know how to handle.  Conventionally, programs report this
  7599. +by exiting with a nonzero status.  Your `awk' program can do this using
  7600. +an `exit' statement with a nonzero argument.  Here's an example of this:
  7601. +
  7602. +     BEGIN {
  7603. +            if (("date" | getline date_now) < 0) {
  7604. +              print "Can't get system date" > "/dev/stderr"
  7605. +              exit 4
  7606. +            }
  7607. +     }
  7608. +
  7609. +
  7610. +File: gawk.info,  Node: Arrays,  Next: Built-in,  Prev: Statements,  Up: Top
  7611. +
  7612. +Arrays in `awk'
  7613. +***************
  7614. +
  7615. +   An "array" is a table of values, called "elements".  The elements of
  7616. +an array are distinguished by their indices.  "Indices" may be either
  7617. +numbers or strings.  Each array has a name, which looks like a variable
  7618. +name, but must not be in use as a variable name in the same `awk'
  7619. +program.
  7620. +
  7621. +* Menu:
  7622. +
  7623. +* Array Intro::                 Introduction to Arrays
  7624. +* Reference to Elements::       How to examine one element of an array.
  7625. +* Assigning Elements::          How to change an element of an array.
  7626. +* Array Example::               Basic Example of an Array
  7627. +* Scanning an Array::           A variation of the `for' statement.
  7628. +                                It loops through the indices of
  7629. +                                an array's existing elements.
  7630. +* Delete::                      The `delete' statement removes
  7631. +                                an element from an array.
  7632. +* Numeric Array Subscripts::    How to use numbers as subscripts in `awk'.
  7633. +* Multi-dimensional::           Emulating multi-dimensional arrays in `awk'.
  7634. +* Multi-scanning::              Scanning multi-dimensional arrays.
  7635. +
  7636. +
  7637. +File: gawk.info,  Node: Array Intro,  Next: Reference to Elements,  Prev: Arrays,  Up: Arrays
  7638. +
  7639. +Introduction to Arrays
  7640. +======================
  7641. +
  7642. +   The `awk' language has one-dimensional "arrays" for storing groups
  7643. +of related strings or numbers.
  7644. +
  7645. +   Every `awk' array must have a name.  Array names have the same
  7646. +syntax as variable names; any valid variable name would also be a valid
  7647. +array name.  But you cannot use one name in both ways (as an array and
  7648. +as a variable) in one `awk' program.
  7649. +
  7650. +   Arrays in `awk' superficially resemble arrays in other programming
  7651. +languages; but there are fundamental differences.  In `awk', you don't
  7652. +need to specify the size of an array before you start to use it.
  7653. +Additionally, any number or string in `awk' may be used as an array
  7654. +index.
  7655. +
  7656. +   In most other languages, you have to "declare" an array and specify
  7657. +how many elements or components it contains.  In such languages, the
  7658. +declaration causes a contiguous block of memory to be allocated for that
  7659. +many elements.  An index in the array must be a positive integer; for
  7660. +example, the index 0 specifies the first element in the array, which is
  7661. +actually stored at the beginning of the block of memory.  Index 1
  7662. +specifies the second element, which is stored in memory right after the
  7663. +first element, and so on.  It is impossible to add more elements to the
  7664. +array, because it has room for only as many elements as you declared.
  7665. +
  7666. +   A contiguous array of four elements might look like this,
  7667. +conceptually, if the element values are `8', `"foo"', `""' and `30':
  7668. +
  7669. +     +---------+---------+--------+---------+
  7670. +     |    8    |  "foo"  |   ""   |    30   |    value
  7671. +     +---------+---------+--------+---------+
  7672. +          0         1         2         3        index
  7673. +
  7674. +Only the values are stored; the indices are implicit from the order of
  7675. +the values.  `8' is the value at index 0, because `8' appears in the
  7676. +position with 0 elements before it.
  7677. +
  7678. +   Arrays in `awk' are different: they are "associative".  This means
  7679. +that each array is a collection of pairs: an index, and its
  7680. +corresponding array element value:
  7681. +
  7682. +     Element 4     Value 30
  7683. +     Element 2     Value "foo"
  7684. +     Element 1     Value 8
  7685. +     Element 3     Value ""
  7686. +
  7687. +We have shown the pairs in jumbled order because their order is
  7688. +irrelevant.
  7689. +
  7690. +   One advantage of an associative array is that new pairs can be added
  7691. +at any time.  For example, suppose we add to the above array a tenth
  7692. +element whose value is `"number ten"'.  The result is this:
  7693. +
  7694. +     Element 10    Value "number ten"
  7695. +     Element 4     Value 30
  7696. +     Element 2     Value "foo"
  7697. +     Element 1     Value 8
  7698. +     Element 3     Value ""
  7699. +
  7700. +Now the array is "sparse" (i.e., some indices are missing): it has
  7701. +elements 1-4 and 10, but doesn't have elements 5, 6, 7, 8, or 9.
  7702. +
  7703. +   Another consequence of associative arrays is that the indices don't
  7704. +have to be positive integers.  Any number, or even a string, can be an
  7705. +index.  For example, here is an array which translates words from
  7706. +English into French:
  7707. +
  7708. +     Element "dog" Value "chien"
  7709. +     Element "cat" Value "chat"
  7710. +     Element "one" Value "un"
  7711. +     Element 1     Value "un"
  7712. +
  7713. +Here we decided to translate the number 1 in both spelled-out and
  7714. +numeric form--thus illustrating that a single array can have both
  7715. +numbers and strings as indices.
  7716. +
  7717. +   When `awk' creates an array for you, e.g., with the `split' built-in
  7718. +function, that array's indices are consecutive integers starting at 1.
  7719. +(*Note Built-in Functions for String Manipulation: String Functions.)
  7720. +
  7721. +
  7722. +File: gawk.info,  Node: Reference to Elements,  Next: Assigning Elements,  Prev: Array Intro,  Up: Arrays
  7723. +
  7724. +Referring to an Array Element
  7725. +=============================
  7726. +
  7727. +   The principal way of using an array is to refer to one of its
  7728. +elements.  An array reference is an expression which looks like this:
  7729. +
  7730. +     ARRAY[INDEX]
  7731. +
  7732. +Here, ARRAY is the name of an array.  The expression INDEX is the index
  7733. +of the element of the array that you want.
  7734. +
  7735. +   The value of the array reference is the current value of that array
  7736. +element.  For example, `foo[4.3]' is an expression for the element of
  7737. +array `foo' at index 4.3.
  7738. +
  7739. +   If you refer to an array element that has no recorded value, the
  7740. +value of the reference is `""', the null string.  This includes elements
  7741. +to which you have not assigned any value, and elements that have been
  7742. +deleted (*note The `delete' Statement: Delete.).  Such a reference
  7743. +automatically creates that array element, with the null string as its
  7744. +value.  (In some cases, this is unfortunate, because it might waste
  7745. +memory inside `awk').
  7746. +
  7747. +   You can find out if an element exists in an array at a certain index
  7748. +with the expression:
  7749. +
  7750. +     INDEX in ARRAY
  7751. +
  7752. +This expression tests whether or not the particular index exists,
  7753. +without the side effect of creating that element if it is not present.
  7754. +The expression has the value 1 (true) if `ARRAY[INDEX]' exists, and 0
  7755. +(false) if it does not exist.
  7756. +
  7757. +   For example, to test whether the array `frequencies' contains the
  7758. +index `"2"', you could write this statement:
  7759. +
  7760. +     if ("2" in frequencies) print "Subscript \"2\" is present."
  7761. +
  7762. +   Note that this is *not* a test of whether or not the array
  7763. +`frequencies' contains an element whose *value* is `"2"'.  (There is no
  7764. +way to do that except to scan all the elements.)  Also, this *does not*
  7765. +create `frequencies["2"]', while the following (incorrect) alternative
  7766. +would do so:
  7767. +
  7768. +     if (frequencies["2"] != "") print "Subscript \"2\" is present."
  7769. +
  7770. +
  7771. +File: gawk.info,  Node: Assigning Elements,  Next: Array Example,  Prev: Reference to Elements,  Up: Arrays
  7772. +
  7773. +Assigning Array Elements
  7774. +========================
  7775. +
  7776. +   Array elements are lvalues: they can be assigned values just like
  7777. +`awk' variables:
  7778. +
  7779. +     ARRAY[SUBSCRIPT] = VALUE
  7780. +
  7781. +Here ARRAY is the name of your array.  The expression SUBSCRIPT is the
  7782. +index of the element of the array that you want to assign a value.  The
  7783. +expression VALUE is the value you are assigning to that element of the
  7784. +array.
  7785. +
  7786. +
  7787. +File: gawk.info,  Node: Array Example,  Next: Scanning an Array,  Prev: Assigning Elements,  Up: Arrays
  7788. +
  7789. +Basic Example of an Array
  7790. +=========================
  7791. +
  7792. +   The following program takes a list of lines, each beginning with a
  7793. +line number, and prints them out in order of line number.  The line
  7794. +numbers are not in order, however, when they are first read:  they are
  7795. +scrambled.  This program sorts the lines by making an array using the
  7796. +line numbers as subscripts.  It then prints out the lines in sorted
  7797. +order of their numbers.  It is a very simple program, and gets confused
  7798. +if it encounters repeated numbers, gaps, or lines that don't begin with
  7799. +a number.
  7800. +
  7801. +     {
  7802. +       if ($1 > max)
  7803. +         max = $1
  7804. +       arr[$1] = $0
  7805. +     }
  7806. +     
  7807. +     END {
  7808. +       for (x = 1; x <= max; x++)
  7809. +         print arr[x]
  7810. +     }
  7811. +
  7812. +   The first rule keeps track of the largest line number seen so far;
  7813. +it also stores each line into the array `arr', at an index that is the
  7814. +line's number.
  7815. +
  7816. +   The second rule runs after all the input has been read, to print out
  7817. +all the lines.
  7818. +
  7819. +   When this program is run with the following input:
  7820. +
  7821. +     5  I am the Five man
  7822. +     2  Who are you?  The new number two!
  7823. +     4  . . . And four on the floor
  7824. +     1  Who is number one?
  7825. +     3  I three you.
  7826. +
  7827. +its output is this:
  7828. +
  7829. +     1  Who is number one?
  7830. +     2  Who are you?  The new number two!
  7831. +     3  I three you.
  7832. +     4  . . . And four on the floor
  7833. +     5  I am the Five man
  7834. +
  7835. +   If a line number is repeated, the last line with a given number
  7836. +overrides the others.
  7837. +
  7838. +   Gaps in the line numbers can be handled with an easy improvement to
  7839. +the program's `END' rule:
  7840. +
  7841. +     END {
  7842. +       for (x = 1; x <= max; x++)
  7843. +         if (x in arr)
  7844. +           print arr[x]
  7845. +     }
  7846. +
  7847. +
  7848. +File: gawk.info,  Node: Scanning an Array,  Next: Delete,  Prev: Array Example,  Up: Arrays
  7849. +
  7850. +Scanning all Elements of an Array
  7851. +=================================
  7852. +
  7853. +   In programs that use arrays, often you need a loop that executes
  7854. +once for each element of an array.  In other languages, where arrays are
  7855. +contiguous and indices are limited to positive integers, this is easy:
  7856. +the largest index is one less than the length of the array, and you can
  7857. +find all the valid indices by counting from zero up to that value.  This
  7858. +technique won't do the job in `awk', since any number or string may be
  7859. +an array index.  So `awk' has a special kind of `for' statement for
  7860. +scanning an array:
  7861. +
  7862. +     for (VAR in ARRAY)
  7863. +       BODY
  7864. +
  7865. +This loop executes BODY once for each different value that your program
  7866. +has previously used as an index in ARRAY, with the variable VAR set to
  7867. +that index.
  7868. +
  7869. +   Here is a program that uses this form of the `for' statement.  The
  7870. +first rule scans the input records and notes which words appear (at
  7871. +least once) in the input, by storing a 1 into the array `used' with the
  7872. +word as index.  The second rule scans the elements of `used' to find
  7873. +all the distinct words that appear in the input.  It prints each word
  7874. +that is more than 10 characters long, and also prints the number of
  7875. +such words.  *Note Built-in Functions: Built-in, for more information
  7876. +on the built-in function `length'.
  7877. +
  7878. +     # Record a 1 for each word that is used at least once.
  7879. +     {
  7880. +       for (i = 1; i <= NF; i++)
  7881. +         used[$i] = 1
  7882. +     }
  7883. +     
  7884. +     # Find number of distinct words more than 10 characters long.
  7885. +     END {
  7886. +       for (x in used)
  7887. +         if (length(x) > 10) {
  7888. +           ++num_long_words
  7889. +           print x
  7890. +       }
  7891. +       print num_long_words, "words longer than 10 characters"
  7892. +     }
  7893. +
  7894. +*Note Sample Program::, for a more detailed example of this type.
  7895. +
  7896. +   The order in which elements of the array are accessed by this
  7897. +statement is determined by the internal arrangement of the array
  7898. +elements within `awk' and cannot be controlled or changed.  This can
  7899. +lead to problems if new elements are added to ARRAY by statements in
  7900. +BODY; you cannot predict whether or not the `for' loop will reach them.
  7901. +Similarly, changing VAR inside the loop can produce strange results.
  7902. +It is best to avoid such things.
  7903. +
  7904. +
  7905. +File: gawk.info,  Node: Delete,  Next: Numeric Array Subscripts,  Prev: Scanning an Array,  Up: Arrays
  7906. +
  7907. +The `delete' Statement
  7908. +======================
  7909. +
  7910. +   You can remove an individual element of an array using the `delete'
  7911. +statement:
  7912. +
  7913. +     delete ARRAY[INDEX]
  7914. +
  7915. +   You can not refer to an array element after it has been deleted; it
  7916. +is as if you had never referred to it and had never given it any value.
  7917. +You can no longer obtain any value the element once had.
  7918. +
  7919. +   Here is an example of deleting elements in an array:
  7920. +
  7921. +     for (i in frequencies)
  7922. +       delete frequencies[i]
  7923. +
  7924. +This example removes all the elements from the array `frequencies'.
  7925. +
  7926. +   If you delete an element, a subsequent `for' statement to scan the
  7927. +array will not report that element, and the `in' operator to check for
  7928. +the presence of that element will return 0:
  7929. +
  7930. +     delete foo[4]
  7931. +     if (4 in foo)
  7932. +       print "This will never be printed"
  7933. +
  7934. +   It is not an error to delete an element which does not exist.
  7935. +
  7936. +
  7937. +File: gawk.info,  Node: Numeric Array Subscripts,  Next: Multi-dimensional,  Prev: Delete,  Up: Arrays
  7938. +
  7939. +Using Numbers to Subscript Arrays
  7940. +=================================
  7941. +
  7942. +   An important aspect of arrays to remember is that array subscripts
  7943. +are *always* strings.  If you use a numeric value as a subscript, it
  7944. +will be converted to a string value before it is used for subscripting
  7945. +(*note Conversion of Strings and Numbers: Conversion.).
  7946. +
  7947. +   This means that the value of the `CONVFMT' can potentially affect
  7948. +how your program accesses elements of an array.  For example:
  7949. +
  7950. +     a = b = 12.153
  7951. +     data[a] = 1
  7952. +     CONVFMT = "%2.2f"
  7953. +     if (b in data)
  7954. +         printf "%s is in data", b
  7955. +     else
  7956. +         printf "%s is not in data", b
  7957. +
  7958. +should print `12.15 is not in data'.  The first statement gives both
  7959. +`a' and `b' the same numeric value.  Assigning to `data[a]' first gives
  7960. +`a' the string value `"12.153"' (using the default conversion value of
  7961. +`CONVFMT', `"%.6g"'), and then assigns 1 to `data["12.153"]'.  The
  7962. +program then changes the value of `CONVFMT'.  The test `(b in data)'
  7963. +forces `b' to be converted to a string, this time `"12.15"', since the
  7964. +value of `CONVFMT' only allows two significant digits.  This test fails,
  7965. +since `"12.15"' is a different string from `"12.153"'.
  7966. +
  7967. +   According to the rules for conversions (*note Conversion of Strings
  7968. +and Numbers: Conversion.), integer values are always converted to
  7969. +strings as integers, no matter what the value of `CONVFMT' may happen
  7970. +to be.  So the usual case of
  7971. +
  7972. +     for (i = 1; i <= maxsub; i++)
  7973. +         do something with array[i]
  7974. +
  7975. +will work, no matter what the value of `CONVFMT'.
  7976. +
  7977. +   Like many things in `awk', the majority of the time things work as
  7978. +you would expect them to work.  But it is useful to have a precise
  7979. +knowledge of the actual rules, since sometimes they can have a subtle
  7980. +effect on your programs.
  7981. +
  7982. +
  7983. +File: gawk.info,  Node: Multi-dimensional,  Next: Multi-scanning,  Prev: Numeric Array Subscripts,  Up: Arrays
  7984. +
  7985. +Multi-dimensional Arrays
  7986. +========================
  7987. +
  7988. +   A multi-dimensional array is an array in which an element is
  7989. +identified by a sequence of indices, not a single index.  For example, a
  7990. +two-dimensional array requires two indices.  The usual way (in most
  7991. +languages, including `awk') to refer to an element of a two-dimensional
  7992. +array named `grid' is with `grid[X,Y]'.
  7993. +
  7994. +   Multi-dimensional arrays are supported in `awk' through
  7995. +concatenation of indices into one string.  What happens is that `awk'
  7996. +converts the indices into strings (*note Conversion of Strings and
  7997. +Numbers: Conversion.) and concatenates them together, with a separator
  7998. +between them.  This creates a single string that describes the values
  7999. +of the separate indices.  The combined string is used as a single index
  8000. +into an ordinary, one-dimensional array.  The separator used is the
  8001. +value of the built-in variable `SUBSEP'.
  8002. +
  8003. +   For example, suppose we evaluate the expression `foo[5,12]="value"'
  8004. +when the value of `SUBSEP' is `"@"'.  The numbers 5 and 12 are
  8005. +converted to strings and concatenated with an `@' between them,
  8006. +yielding `"5@12"'; thus, the array element `foo["5@12"]' is set to
  8007. +`"value"'.
  8008. +
  8009. +   Once the element's value is stored, `awk' has no record of whether
  8010. +it was stored with a single index or a sequence of indices.  The two
  8011. +expressions `foo[5,12]' and `foo[5 SUBSEP 12]' always have the same
  8012. +value.
  8013. +
  8014. +   The default value of `SUBSEP' is the string `"\034"', which contains
  8015. +a nonprinting character that is unlikely to appear in an `awk' program
  8016. +or in the input data.
  8017. +
  8018. +   The usefulness of choosing an unlikely character comes from the fact
  8019. +that index values that contain a string matching `SUBSEP' lead to
  8020. +combined strings that are ambiguous.  Suppose that `SUBSEP' were `"@"';
  8021. +then `foo["a@b", "c"]' and `foo["a", "b@c"]' would be indistinguishable
  8022. +because both would actually be stored as `foo["a@b@c"]'.  Because
  8023. +`SUBSEP' is `"\034"', such confusion can arise only when an index
  8024. +contains the character with ASCII code 034, which is a rare event.
  8025. +
  8026. +   You can test whether a particular index-sequence exists in a
  8027. +"multi-dimensional" array with the same operator `in' used for single
  8028. +dimensional arrays.  Instead of a single index as the left-hand operand,
  8029. +write the whole sequence of indices, separated by commas, in
  8030. +parentheses:
  8031. +
  8032. +     (SUBSCRIPT1, SUBSCRIPT2, ...) in ARRAY
  8033. +
  8034. +   The following example treats its input as a two-dimensional array of
  8035. +fields; it rotates this array 90 degrees clockwise and prints the
  8036. +result.  It assumes that all lines have the same number of elements.
  8037. +
  8038. +     awk '{
  8039. +          if (max_nf < NF)
  8040. +               max_nf = NF
  8041. +          max_nr = NR
  8042. +          for (x = 1; x <= NF; x++)
  8043. +               vector[x, NR] = $x
  8044. +     }
  8045. +     
  8046. +     END {
  8047. +          for (x = 1; x <= max_nf; x++) {
  8048. +               for (y = max_nr; y >= 1; --y)
  8049. +                    printf("%s ", vector[x, y])
  8050. +               printf("\n")
  8051. +          }
  8052. +     }'
  8053. +
  8054. +When given the input:
  8055. +
  8056. +     1 2 3 4 5 6
  8057. +     2 3 4 5 6 1
  8058. +     3 4 5 6 1 2
  8059. +     4 5 6 1 2 3
  8060. +
  8061. +it produces:
  8062. +
  8063. +     4 3 2 1
  8064. +     5 4 3 2
  8065. +     6 5 4 3
  8066. +     1 6 5 4
  8067. +     2 1 6 5
  8068. +     3 2 1 6
  8069. +
  8070. +
  8071. +File: gawk.info,  Node: Multi-scanning,  Prev: Multi-dimensional,  Up: Arrays
  8072. +
  8073. +Scanning Multi-dimensional Arrays
  8074. +=================================
  8075. +
  8076. +   There is no special `for' statement for scanning a
  8077. +"multi-dimensional" array; there cannot be one, because in truth there
  8078. +are no multi-dimensional arrays or elements; there is only a
  8079. +multi-dimensional *way of accessing* an array.
  8080. +
  8081. +   However, if your program has an array that is always accessed as
  8082. +multi-dimensional, you can get the effect of scanning it by combining
  8083. +the scanning `for' statement (*note Scanning all Elements of an Array:
  8084. +Scanning an Array.) with the `split' built-in function (*note Built-in
  8085. +Functions for String Manipulation: String Functions.).  It works like
  8086. +this:
  8087. +
  8088. +     for (combined in ARRAY) {
  8089. +       split(combined, separate, SUBSEP)
  8090. +       ...
  8091. +     }
  8092. +
  8093. +This finds each concatenated, combined index in the array, and splits it
  8094. +into the individual indices by breaking it apart where the value of
  8095. +`SUBSEP' appears.  The split-out indices become the elements of the
  8096. +array `separate'.
  8097. +
  8098. +   Thus, suppose you have previously stored in `ARRAY[1, "foo"]'; then
  8099. +an element with index `"1\034foo"' exists in ARRAY.  (Recall that the
  8100. +default value of `SUBSEP' contains the character with code 034.)
  8101. +Sooner or later the `for' statement will find that index and do an
  8102. +iteration with `combined' set to `"1\034foo"'.  Then the `split'
  8103. +function is called as follows:
  8104. +
  8105. +     split("1\034foo", separate, "\034")
  8106. +
  8107. +The result of this is to set `separate[1]' to 1 and `separate[2]' to
  8108. +`"foo"'.  Presto, the original sequence of separate indices has been
  8109. +recovered.
  8110. +
  8111. +
  8112. +File: gawk.info,  Node: Built-in,  Next: User-defined,  Prev: Arrays,  Up: Top
  8113. +
  8114. +Built-in Functions
  8115. +******************
  8116. +
  8117. +   "Built-in" functions are functions that are always available for
  8118. +your `awk' program to call.  This chapter defines all the built-in
  8119. +functions in `awk'; some of them are mentioned in other sections, but
  8120. +they are summarized here for your convenience.  (You can also define
  8121. +new functions yourself.  *Note User-defined Functions: User-defined.)
  8122. +
  8123. +* Menu:
  8124. +
  8125. +* Calling Built-in::            How to call built-in functions.
  8126. +* Numeric Functions::           Functions that work with numbers,
  8127. +                                including `int', `sin' and `rand'.
  8128. +* String Functions::            Functions for string manipulation,
  8129. +                                such as `split', `match', and `sprintf'.
  8130. +* I/O Functions::               Functions for files and shell commands.
  8131. +* Time Functions::              Functions for dealing with time stamps.
  8132. +
  8133. +
  8134. +File: gawk.info,  Node: Calling Built-in,  Next: Numeric Functions,  Prev: Built-in,  Up: Built-in
  8135. +
  8136. +Calling Built-in Functions
  8137. +==========================
  8138. +
  8139. +   To call a built-in function, write the name of the function followed
  8140. +by arguments in parentheses.  For example, `atan2(y + z, 1)' is a call
  8141. +to the function `atan2', with two arguments.
  8142. +
  8143. +   Whitespace is ignored between the built-in function name and the
  8144. +open-parenthesis, but we recommend that you avoid using whitespace
  8145. +there.  User-defined functions do not permit whitespace in this way, and
  8146. +you will find it easier to avoid mistakes by following a simple
  8147. +convention which always works: no whitespace after a function name.
  8148. +
  8149. +   Each built-in function accepts a certain number of arguments.  In
  8150. +most cases, any extra arguments given to built-in functions are
  8151. +ignored.  The defaults for omitted arguments vary from function to
  8152. +function and are described under the individual functions.
  8153. +
  8154. +   When a function is called, expressions that create the function's
  8155. +actual parameters are evaluated completely before the function call is
  8156. +performed.  For example, in the code fragment:
  8157. +
  8158. +     i = 4
  8159. +     j = sqrt(i++)
  8160. +
  8161. +the variable `i' is set to 5 before `sqrt' is called with a value of 4
  8162. +for its actual parameter.
  8163. +
  8164. +
  8165. +File: gawk.info,  Node: Numeric Functions,  Next: String Functions,  Prev: Calling Built-in,  Up: Built-in
  8166. +
  8167. +Numeric Built-in Functions
  8168. +==========================
  8169. +
  8170. +   Here is a full list of built-in functions that work with numbers:
  8171. +
  8172. +`int(X)'
  8173. +     This gives you the integer part of X, truncated toward 0.  This
  8174. +     produces the nearest integer to X, located between X and 0.
  8175. +
  8176. +     For example, `int(3)' is 3, `int(3.9)' is 3, `int(-3.9)' is -3,
  8177. +     and `int(-3)' is -3 as well.
  8178. +
  8179. +`sqrt(X)'
  8180. +     This gives you the positive square root of X.  It reports an error
  8181. +     if X is negative.  Thus, `sqrt(4)' is 2.
  8182. +
  8183. +`exp(X)'
  8184. +     This gives you the exponential of X, or reports an error if X is
  8185. +     out of range.  The range of values X can have depends on your
  8186. +     machine's floating point representation.
  8187. +
  8188. +`log(X)'
  8189. +     This gives you the natural logarithm of X, if X is positive;
  8190. +     otherwise, it reports an error.
  8191. +
  8192. +`sin(X)'
  8193. +     This gives you the sine of X, with X in radians.
  8194. +
  8195. +`cos(X)'
  8196. +     This gives you the cosine of X, with X in radians.
  8197. +
  8198. +`atan2(Y, X)'
  8199. +     This gives you the arctangent of `Y / X' in radians.
  8200. +
  8201. +`rand()'
  8202. +     This gives you a random number.  The values of `rand' are
  8203. +     uniformly-distributed between 0 and 1.  The value is never 0 and
  8204. +     never 1.
  8205. +
  8206. +     Often you want random integers instead.  Here is a user-defined
  8207. +     function you can use to obtain a random nonnegative integer less
  8208. +     than N:
  8209. +
  8210. +          function randint(n) {
  8211. +               return int(n * rand())
  8212. +          }
  8213. +
  8214. +     The multiplication produces a random real number greater than 0
  8215. +     and less than N.  We then make it an integer (using `int') between
  8216. +     0 and `N - 1'.
  8217. +
  8218. +     Here is an example where a similar function is used to produce
  8219. +     random integers between 1 and N.  Note that this program will
  8220. +     print a new random number for each input record.
  8221. +
  8222. +          awk '
  8223. +          # Function to roll a simulated die.
  8224. +          function roll(n) { return 1 + int(rand() * n) }
  8225. +          
  8226. +          # Roll 3 six-sided dice and print total number of points.
  8227. +          {
  8228. +                printf("%d points\n", roll(6)+roll(6)+roll(6))
  8229. +          }'
  8230. +
  8231. +     *Note:* `rand' starts generating numbers from the same point, or
  8232. +     "seed", each time you run `awk'.  This means that a program will
  8233. +     produce the same results each time you run it.  The numbers are
  8234. +     random within one `awk' run, but predictable from run to run.
  8235. +     This is convenient for debugging, but if you want a program to do
  8236. +     different things each time it is used, you must change the seed to
  8237. +     a value that will be different in each run.  To do this, use
  8238. +     `srand'.
  8239. +
  8240. +`srand(X)'
  8241. +     The function `srand' sets the starting point, or "seed", for
  8242. +     generating random numbers to the value X.
  8243. +
  8244. +     Each seed value leads to a particular sequence of "random" numbers.
  8245. +     Thus, if you set the seed to the same value a second time, you
  8246. +     will get the same sequence of "random" numbers again.
  8247. +
  8248. +     If you omit the argument X, as in `srand()', then the current date
  8249. +     and time of day are used for a seed.  This is the way to get random
  8250. +     numbers that are truly unpredictable.
  8251. +
  8252. +     The return value of `srand' is the previous seed.  This makes it
  8253. +     easy to keep track of the seeds for use in consistently reproducing
  8254. +     sequences of random numbers.
  8255. +
  8256. +
  8257. +File: gawk.info,  Node: String Functions,  Next: I/O Functions,  Prev: Numeric Functions,  Up: Built-in
  8258. +
  8259. +Built-in Functions for String Manipulation
  8260. +==========================================
  8261. +
  8262. +   The functions in this section look at or change the text of one or
  8263. +more strings.
  8264. +
  8265. +`index(IN, FIND)'
  8266. +     This searches the string IN for the first occurrence of the string
  8267. +     FIND, and returns the position in characters where that occurrence
  8268. +     begins in the string IN.  For example:
  8269. +
  8270. +          awk 'BEGIN { print index("peanut", "an") }'
  8271. +
  8272. +     prints `3'.  If FIND is not found, `index' returns 0.  (Remember
  8273. +     that string indices in `awk' start at 1.)
  8274. +
  8275. +`length(STRING)'
  8276. +     This gives you the number of characters in STRING.  If STRING is a
  8277. +     number, the length of the digit string representing that number is
  8278. +     returned.  For example, `length("abcde")' is 5.  By contrast,
  8279. +     `length(15 * 35)' works out to 3.  How?  Well, 15 * 35 = 525, and
  8280. +     525 is then converted to the string `"525"', which has three
  8281. +     characters.
  8282. +
  8283. +     If no argument is supplied, `length' returns the length of `$0'.
  8284. +
  8285. +     In older versions of `awk', you could call the `length' function
  8286. +     without any parentheses.  Doing so is marked as "deprecated" in the
  8287. +     POSIX standard.  This means that while you can do this in your
  8288. +     programs, it is a feature that can eventually be removed from a
  8289. +     future version of the standard.  Therefore, for maximal
  8290. +     portability of your `awk' programs you should always supply the
  8291. +     parentheses.
  8292. +
  8293. +`match(STRING, REGEXP)'
  8294. +     The `match' function searches the string, STRING, for the longest,
  8295. +     leftmost substring matched by the regular expression, REGEXP.  It
  8296. +     returns the character position, or "index", of where that
  8297. +     substring begins (1, if it starts at the beginning of STRING).  If
  8298. +     no match if found, it returns 0.
  8299. +
  8300. +     The `match' function sets the built-in variable `RSTART' to the
  8301. +     index.  It also sets the built-in variable `RLENGTH' to the length
  8302. +     in characters of the matched substring.  If no match is found,
  8303. +     `RSTART' is set to 0, and `RLENGTH' to -1.
  8304. +
  8305. +     For example:
  8306. +
  8307. +          awk '{
  8308. +                 if ($1 == "FIND")
  8309. +                   regex = $2
  8310. +                 else {
  8311. +                   where = match($0, regex)
  8312. +                   if (where)
  8313. +                     print "Match of", regex, "found at", where, "in", $0
  8314. +                 }
  8315. +          }'
  8316. +
  8317. +     This program looks for lines that match the regular expression
  8318. +     stored in the variable `regex'.  This regular expression can be
  8319. +     changed.  If the first word on a line is `FIND', `regex' is
  8320. +     changed to be the second word on that line.  Therefore, given:
  8321. +
  8322. +          FIND fo*bar
  8323. +          My program was a foobar
  8324. +          But none of it would doobar
  8325. +          FIND Melvin
  8326. +          JF+KM
  8327. +          This line is property of The Reality Engineering Co.
  8328. +          This file created by Melvin.
  8329. +
  8330. +     `awk' prints:
  8331. +
  8332. +          Match of fo*bar found at 18 in My program was a foobar
  8333. +          Match of Melvin found at 26 in This file created by Melvin.
  8334. +
  8335. +`split(STRING, ARRAY, FIELDSEP)'
  8336. +     This divides STRING into pieces separated by FIELDSEP, and stores
  8337. +     the pieces in ARRAY.  The first piece is stored in `ARRAY[1]', the
  8338. +     second piece in `ARRAY[2]', and so forth.  The string value of the
  8339. +     third argument, FIELDSEP, is a regexp describing where to split
  8340. +     STRING (much as `FS' can be a regexp describing where to split
  8341. +     input records).  If the FIELDSEP is omitted, the value of `FS' is
  8342. +     used.  `split' returns the number of elements created.
  8343. +
  8344. +     The `split' function, then, splits strings into pieces in a manner
  8345. +     similar to the way input lines are split into fields.  For example:
  8346. +
  8347. +          split("auto-da-fe", a, "-")
  8348. +
  8349. +     splits the string `auto-da-fe' into three fields using `-' as the
  8350. +     separator.  It sets the contents of the array `a' as follows:
  8351. +
  8352. +          a[1] = "auto"
  8353. +          a[2] = "da"
  8354. +          a[3] = "fe"
  8355. +
  8356. +     The value returned by this call to `split' is 3.
  8357. +
  8358. +     As with input field-splitting, when the value of FIELDSEP is `"
  8359. +     "', leading and trailing whitespace is ignored, and the elements
  8360. +     are separated by runs of whitespace.
  8361. +
  8362. +`sprintf(FORMAT, EXPRESSION1,...)'
  8363. +     This returns (without printing) the string that `printf' would
  8364. +     have printed out with the same arguments (*note Using `printf'
  8365. +     Statements for Fancier Printing: Printf.).  For example:
  8366. +
  8367. +          sprintf("pi = %.2f (approx.)", 22/7)
  8368. +
  8369. +     returns the string `"pi = 3.14 (approx.)"'.
  8370. +
  8371. +`sub(REGEXP, REPLACEMENT, TARGET)'
  8372. +     The `sub' function alters the value of TARGET.  It searches this
  8373. +     value, which should be a string, for the leftmost substring
  8374. +     matched by the regular expression, REGEXP, extending this match as
  8375. +     far as possible.  Then the entire string is changed by replacing
  8376. +     the matched text with REPLACEMENT.  The modified string becomes
  8377. +     the new value of TARGET.
  8378. +
  8379. +     This function is peculiar because TARGET is not simply used to
  8380. +     compute a value, and not just any expression will do: it must be a
  8381. +     variable, field or array reference, so that `sub' can store a
  8382. +     modified value there.  If this argument is omitted, then the
  8383. +     default is to use and alter `$0'.
  8384. +
  8385. +     For example:
  8386. +
  8387. +          str = "water, water, everywhere"
  8388. +          sub(/at/, "ith", str)
  8389. +
  8390. +     sets `str' to `"wither, water, everywhere"', by replacing the
  8391. +     leftmost, longest occurrence of `at' with `ith'.
  8392. +
  8393. +     The `sub' function returns the number of substitutions made (either
  8394. +     one or zero).
  8395. +
  8396. +     If the special character `&' appears in REPLACEMENT, it stands for
  8397. +     the precise substring that was matched by REGEXP.  (If the regexp
  8398. +     can match more than one string, then this precise substring may
  8399. +     vary.)  For example:
  8400. +
  8401. +          awk '{ sub(/candidate/, "& and his wife"); print }'
  8402. +
  8403. +     changes the first occurrence of `candidate' to `candidate and his
  8404. +     wife' on each input line.
  8405. +
  8406. +     Here is another example:
  8407. +
  8408. +          awk 'BEGIN {
  8409. +                  str = "daabaaa"
  8410. +                  sub(/a*/, "c&c", str)
  8411. +                  print str
  8412. +          }'
  8413. +
  8414. +     prints `dcaacbaaa'.  This show how `&' can represent a non-constant
  8415. +     string, and also illustrates the "leftmost, longest" rule.
  8416. +
  8417. +     The effect of this special character (`&') can be turned off by
  8418. +     putting a backslash before it in the string.  As usual, to insert
  8419. +     one backslash in the string, you must write two backslashes.
  8420. +     Therefore, write `\\&' in a string constant to include a literal
  8421. +     `&' in the replacement.  For example, here is how to replace the
  8422. +     first `|' on each line with an `&':
  8423. +
  8424. +          awk '{ sub(/\|/, "\\&"); print }'
  8425. +
  8426. +     *Note:* as mentioned above, the third argument to `sub' must be an
  8427. +     lvalue.  Some versions of `awk' allow the third argument to be an
  8428. +     expression which is not an lvalue.  In such a case, `sub' would
  8429. +     still search for the pattern and return 0 or 1, but the result of
  8430. +     the substitution (if any) would be thrown away because there is no
  8431. +     place to put it.  Such versions of `awk' accept expressions like
  8432. +     this:
  8433. +
  8434. +          sub(/USA/, "United States", "the USA and Canada")
  8435. +
  8436. +     But that is considered erroneous in `gawk'.
  8437. +
  8438. +`gsub(REGEXP, REPLACEMENT, TARGET)'
  8439. +     This is similar to the `sub' function, except `gsub' replaces
  8440. +     *all* of the longest, leftmost, *nonoverlapping* matching
  8441. +     substrings it can find.  The `g' in `gsub' stands for "global,"
  8442. +     which means replace everywhere.  For example:
  8443. +
  8444. +          awk '{ gsub(/Britain/, "United Kingdom"); print }'
  8445. +
  8446. +     replaces all occurrences of the string `Britain' with `United
  8447. +     Kingdom' for all input records.
  8448. +
  8449. +     The `gsub' function returns the number of substitutions made.  If
  8450. +     the variable to be searched and altered, TARGET, is omitted, then
  8451. +     the entire input record, `$0', is used.
  8452. +
  8453. +     As in `sub', the characters `&' and `\' are special, and the third
  8454. +     argument must be an lvalue.
  8455. +
  8456. +`substr(STRING, START, LENGTH)'
  8457. +     This returns a LENGTH-character-long substring of STRING, starting
  8458. +     at character number START.  The first character of a string is
  8459. +     character number one.  For example, `substr("washington", 5, 3)'
  8460. +     returns `"ing"'.
  8461. +
  8462. +     If LENGTH is not present, this function returns the whole suffix of
  8463. +     STRING that begins at character number START.  For example,
  8464. +     `substr("washington", 5)' returns `"ington"'.  This is also the
  8465. +     case if LENGTH is greater than the number of characters remaining
  8466. +     in the string, counting from character number START.
  8467. +
  8468. +`tolower(STRING)'
  8469. +     This returns a copy of STRING, with each upper-case character in
  8470. +     the string replaced with its corresponding lower-case character.
  8471. +     Nonalphabetic characters are left unchanged.  For example,
  8472. +     `tolower("MiXeD cAsE 123")' returns `"mixed case 123"'.
  8473. +
  8474. +`toupper(STRING)'
  8475. +     This returns a copy of STRING, with each lower-case character in
  8476. +     the string replaced with its corresponding upper-case character.
  8477. +     Nonalphabetic characters are left unchanged.  For example,
  8478. +     `toupper("MiXeD cAsE 123")' returns `"MIXED CASE 123"'.
  8479. +
  8480. diff -rup --new-file baseline/fsf/gawk/gawk.info-6 amiga/fsf/gawk/gawk.info-6
  8481. --- baseline/fsf/gawk/gawk.info-6    Wed Dec 31 17:00:00 1969
  8482. +++ amiga/fsf/gawk/gawk.info-6    Sat Sep 28 00:00:00 1996
  8483. @@ -0,0 +1,1234 @@
  8484. +This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  8485. +file /gnu-src/gawk-2.15.6/gawk.texi.
  8486. +
  8487. +   This file documents `awk', a program that you can use to select
  8488. +particular records in a file and perform operations upon them.
  8489. +
  8490. +   This is Edition 0.15 of `The GAWK Manual',
  8491. +for the 2.15 version of the GNU implementation
  8492. +of AWK.
  8493. +
  8494. +   Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  8495. +
  8496. +   Permission is granted to make and distribute verbatim copies of this
  8497. +manual provided the copyright notice and this permission notice are
  8498. +preserved on all copies.
  8499. +
  8500. +   Permission is granted to copy and distribute modified versions of
  8501. +this manual under the conditions for verbatim copying, provided that
  8502. +the entire resulting derived work is distributed under the terms of a
  8503. +permission notice identical to this one.
  8504. +
  8505. +   Permission is granted to copy and distribute translations of this
  8506. +manual into another language, under the above conditions for modified
  8507. +versions, except that this permission notice may be stated in a
  8508. +translation approved by the Foundation.
  8509. +
  8510. +
  8511. +File: gawk.info,  Node: I/O Functions,  Next: Time Functions,  Prev: String Functions,  Up: Built-in
  8512. +
  8513. +Built-in Functions for Input/Output
  8514. +===================================
  8515. +
  8516. +`close(FILENAME)'
  8517. +     Close the file FILENAME, for input or output.  The argument may
  8518. +     alternatively be a shell command that was used for redirecting to
  8519. +     or from a pipe; then the pipe is closed.
  8520. +
  8521. +     *Note Closing Input Files and Pipes: Close Input, regarding closing
  8522. +     input files and pipes.  *Note Closing Output Files and Pipes:
  8523. +     Close Output, regarding closing output files and pipes.
  8524. +
  8525. +`system(COMMAND)'
  8526. +     The system function allows the user to execute operating system
  8527. +     commands and then return to the `awk' program.  The `system'
  8528. +     function executes the command given by the string COMMAND.  It
  8529. +     returns, as its value, the status returned by the command that was
  8530. +     executed.
  8531. +
  8532. +     For example, if the following fragment of code is put in your `awk'
  8533. +     program:
  8534. +
  8535. +          END {
  8536. +               system("mail -s 'awk run done' operator < /dev/null")
  8537. +          }
  8538. +
  8539. +     the system operator will be sent mail when the `awk' program
  8540. +     finishes processing input and begins its end-of-input processing.
  8541. +
  8542. +     Note that much the same result can be obtained by redirecting
  8543. +     `print' or `printf' into a pipe.  However, if your `awk' program
  8544. +     is interactive, `system' is useful for cranking up large
  8545. +     self-contained programs, such as a shell or an editor.
  8546. +
  8547. +     Some operating systems cannot implement the `system' function.
  8548. +     `system' causes a fatal error if it is not supported.
  8549. +
  8550. +Controlling Output Buffering with `system'
  8551. +------------------------------------------
  8552. +
  8553. +   Many utility programs will "buffer" their output; they save
  8554. +information to be written to a disk file or terminal in memory, until
  8555. +there is enough to be written in one operation.  This is often more
  8556. +efficient than writing every little bit of information as soon as it is
  8557. +ready.  However, sometimes it is necessary to force a program to
  8558. +"flush" its buffers; that is, write the information to its destination,
  8559. +even if a buffer is not full.  You can do this from your `awk' program
  8560. +by calling `system' with a null string as its argument:
  8561. +
  8562. +     system("")   # flush output
  8563. +
  8564. +`gawk' treats this use of the `system' function as a special case, and
  8565. +is smart enough not to run a shell (or other command interpreter) with
  8566. +the empty command.  Therefore, with `gawk', this idiom is not only
  8567. +useful, it is efficient.  While this idiom should work with other `awk'
  8568. +implementations, it will not necessarily avoid starting an unnecessary
  8569. +shell.
  8570. +
  8571. +
  8572. +File: gawk.info,  Node: Time Functions,  Prev: I/O Functions,  Up: Built-in
  8573. +
  8574. +Functions for Dealing with Time Stamps
  8575. +======================================
  8576. +
  8577. +   A common use for `awk' programs is the processing of log files.  Log
  8578. +files often contain time stamp information, indicating when a
  8579. +particular log record was written.  Many programs log their time stamp
  8580. +in the form returned by the `time' system call, which is the number of
  8581. +seconds since a particular epoch.  On POSIX systems, it is the number
  8582. +of seconds since Midnight, January 1, 1970, UTC.
  8583. +
  8584. +   In order to make it easier to process such log files, and to easily
  8585. +produce useful reports, `gawk' provides two functions for working with
  8586. +time stamps.  Both of these are `gawk' extensions; they are not
  8587. +specified in the POSIX standard, nor are they in any other known version
  8588. +of `awk'.
  8589. +
  8590. +`systime()'
  8591. +     This function returns the current time as the number of seconds
  8592. +     since the system epoch.  On POSIX systems, this is the number of
  8593. +     seconds since Midnight, January 1, 1970, UTC.  It may be a
  8594. +     different number on other systems.
  8595. +
  8596. +`strftime(FORMAT, TIMESTAMP)'
  8597. +     This function returns a string.  It is similar to the function of
  8598. +     the same name in the ANSI C standard library.  The time specified
  8599. +     by TIMESTAMP is used to produce a string, based on the contents of
  8600. +     the FORMAT string.
  8601. +
  8602. +   The `systime' function allows you to compare a time stamp from a log
  8603. +file with the current time of day.  In particular, it is easy to
  8604. +determine how long ago a particular record was logged.  It also allows
  8605. +you to produce log records using the "seconds since the epoch" format.
  8606. +
  8607. +   The `strftime' function allows you to easily turn a time stamp into
  8608. +human-readable information.  It is similar in nature to the `sprintf'
  8609. +function, copying non-format specification characters verbatim to the
  8610. +returned string, and substituting date and time values for format
  8611. +specifications in the FORMAT string.  If no TIMESTAMP argument is
  8612. +supplied, `gawk' will use the current time of day as the time stamp.
  8613. +
  8614. +   `strftime' is guaranteed by the ANSI C standard to support the
  8615. +following date format specifications:
  8616. +
  8617. +`%a'
  8618. +     The locale's abbreviated weekday name.
  8619. +
  8620. +`%A'
  8621. +     The locale's full weekday name.
  8622. +
  8623. +`%b'
  8624. +     The locale's abbreviated month name.
  8625. +
  8626. +`%B'
  8627. +     The locale's full month name.
  8628. +
  8629. +`%c'
  8630. +     The locale's "appropriate" date and time representation.
  8631. +
  8632. +`%d'
  8633. +     The day of the month as a decimal number (01-31).
  8634. +
  8635. +`%H'
  8636. +     The hour (24-hour clock) as a decimal number (00-23).
  8637. +
  8638. +`%I'
  8639. +     The hour (12-hour clock) as a decimal number (01-12).
  8640. +
  8641. +`%j'
  8642. +     The day of the year as a decimal number (001-366).
  8643. +
  8644. +`%m'
  8645. +     The month as a decimal number (01-12).
  8646. +
  8647. +`%M'
  8648. +     The minute as a decimal number (00-59).
  8649. +
  8650. +`%p'
  8651. +     The locale's equivalent of the AM/PM designations associated with
  8652. +     a 12-hour clock.
  8653. +
  8654. +`%S'
  8655. +     The second as a decimal number (00-61).  (Occasionally there are
  8656. +     minutes in a year with one or two leap seconds, which is why the
  8657. +     seconds can go from 0 all the way to 61.)
  8658. +
  8659. +`%U'
  8660. +     The week number of the year (the first Sunday as the first day of
  8661. +     week 1) as a decimal number (00-53).
  8662. +
  8663. +`%w'
  8664. +     The weekday as a decimal number (0-6).  Sunday is day 0.
  8665. +
  8666. +`%W'
  8667. +     The week number of the year (the first Monday as the first day of
  8668. +     week 1) as a decimal number (00-53).
  8669. +
  8670. +`%x'
  8671. +     The locale's "appropriate" date representation.
  8672. +
  8673. +`%X'
  8674. +     The locale's "appropriate" time representation.
  8675. +
  8676. +`%y'
  8677. +     The year without century as a decimal number (00-99).
  8678. +
  8679. +`%Y'
  8680. +     The year with century as a decimal number.
  8681. +
  8682. +`%Z'
  8683. +     The time zone name or abbreviation, or no characters if no time
  8684. +     zone is determinable.
  8685. +
  8686. +`%%'
  8687. +     A literal `%'.
  8688. +
  8689. +   If a conversion specifier is not one of the above, the behavior is
  8690. +undefined.  (This is because the ANSI standard for C leaves the
  8691. +behavior of the C version of `strftime' undefined, and `gawk' will use
  8692. +the system's version of `strftime' if it's there.  Typically, the
  8693. +conversion specifier will either not appear in the returned string, or
  8694. +it will appear literally.)
  8695. +
  8696. +   Informally, a "locale" is the geographic place in which a program is
  8697. +meant to run.  For example, a common way to abbreviate the date
  8698. +September 4, 1991 in the United States would be "9/4/91".  In many
  8699. +countries in Europe, however, it would be abbreviated "4.9.91".  Thus,
  8700. +the `%x' specification in a `"US"' locale might produce `9/4/91', while
  8701. +in a `"EUROPE"' locale, it might produce `4.9.91'.  The ANSI C standard
  8702. +defines a default `"C"' locale, which is an environment that is typical
  8703. +of what most C programmers are used to.
  8704. +
  8705. +   A public-domain C version of `strftime' is shipped with `gawk' for
  8706. +systems that are not yet fully ANSI-compliant.  If that version is used
  8707. +to compile `gawk' (*note Installing `gawk': Installation.), then the
  8708. +following additional format specifications are available:
  8709. +
  8710. +`%D'
  8711. +     Equivalent to specifying `%m/%d/%y'.
  8712. +
  8713. +`%e'
  8714. +     The day of the month, padded with a blank if it is only one digit.
  8715. +
  8716. +`%h'
  8717. +     Equivalent to `%b', above.
  8718. +
  8719. +`%n'
  8720. +     A newline character (ASCII LF).
  8721. +
  8722. +`%r'
  8723. +     Equivalent to specifying `%I:%M:%S %p'.
  8724. +
  8725. +`%R'
  8726. +     Equivalent to specifying `%H:%M'.
  8727. +
  8728. +`%T'
  8729. +     Equivalent to specifying `%H:%M:%S'.
  8730. +
  8731. +`%t'
  8732. +     A TAB character.
  8733. +
  8734. +`%k'
  8735. +     is replaced by the hour (24-hour clock) as a decimal number (0-23).
  8736. +     Single digit numbers are padded with a blank.
  8737. +
  8738. +`%l'
  8739. +     is replaced by the hour (12-hour clock) as a decimal number (1-12).
  8740. +     Single digit numbers are padded with a blank.
  8741. +
  8742. +`%C'
  8743. +     The century, as a number between 00 and 99.
  8744. +
  8745. +`%u'
  8746. +     is replaced by the weekday as a decimal number [1 (Monday)-7].
  8747. +
  8748. +`%V'
  8749. +     is replaced by the week number of the year (the first Monday as
  8750. +     the first day of week 1) as a decimal number (01-53).  The method
  8751. +     for determining the week number is as specified by ISO 8601 (to
  8752. +     wit: if the week containing January 1 has four or more days in the
  8753. +     new year, then it is week 1, otherwise it is week 53 of the
  8754. +     previous year and the next week is week 1).
  8755. +
  8756. +`%Ec %EC %Ex %Ey %EY %Od %Oe %OH %OI'
  8757. +`%Om %OM %OS %Ou %OU %OV %Ow %OW %Oy'
  8758. +     These are "alternate representations" for the specifications that
  8759. +     use only the second letter (`%c', `%C', and so on).  They are
  8760. +     recognized, but their normal representations are used.  (These
  8761. +     facilitate compliance with the POSIX `date' utility.)
  8762. +
  8763. +`%v'
  8764. +     The date in VMS format (e.g. 20-JUN-1991).
  8765. +
  8766. +   Here are two examples that use `strftime'.  The first is an `awk'
  8767. +version of the C `ctime' function.  (This is a user defined function,
  8768. +which we have not discussed yet.  *Note User-defined Functions:
  8769. +User-defined, for more information.)
  8770. +
  8771. +     # ctime.awk
  8772. +     #
  8773. +     # awk version of C ctime(3) function
  8774. +     
  8775. +     function ctime(ts,    format)
  8776. +     {
  8777. +         format = "%a %b %e %H:%M:%S %Z %Y"
  8778. +         if (ts == 0)
  8779. +             ts = systime()         # use current time as default
  8780. +         return strftime(format, ts)
  8781. +     }
  8782. +
  8783. +   This next example is an `awk' implementation of the POSIX `date'
  8784. +utility.  Normally, the `date' utility prints the current date and time
  8785. +of day in a well known format.  However, if you provide an argument to
  8786. +it that begins with a `+', `date' will copy non-format specifier
  8787. +characters to the standard output, and will interpret the current time
  8788. +according to the format specifiers in the string.  For example:
  8789. +
  8790. +     date '+Today is %A, %B %d, %Y.'
  8791. +
  8792. +might print
  8793. +
  8794. +     Today is Thursday, July 11, 1991.
  8795. +
  8796. +   Here is the `awk' version of the `date' utility.
  8797. +
  8798. +     #! /bin/gawk -f
  8799. +     #
  8800. +     # date --- implement the P1003.2 Draft 11 'date' command
  8801. +     #
  8802. +     # Bug: does not recognize the -u argument.
  8803. +     
  8804. +     BEGIN    \
  8805. +     {
  8806. +         format = "%a %b %e %H:%M:%S %Z %Y"
  8807. +         exitval = 0
  8808. +     
  8809. +         if (ARGC > 2)
  8810. +             exitval = 1
  8811. +         else if (ARGC == 2) {
  8812. +             format = ARGV[1]
  8813. +             if (format ~ /^\+/)
  8814. +                 format = substr(format, 2)    # remove leading +
  8815. +         }
  8816. +         print strftime(format)
  8817. +         exit exitval
  8818. +     }
  8819. +
  8820. +
  8821. +File: gawk.info,  Node: User-defined,  Next: Built-in Variables,  Prev: Built-in,  Up: Top
  8822. +
  8823. +User-defined Functions
  8824. +**********************
  8825. +
  8826. +   Complicated `awk' programs can often be simplified by defining your
  8827. +own functions.  User-defined functions can be called just like built-in
  8828. +ones (*note Function Calls::.), but it is up to you to define them--to
  8829. +tell `awk' what they should do.
  8830. +
  8831. +* Menu:
  8832. +
  8833. +* Definition Syntax::           How to write definitions and what they mean.
  8834. +* Function Example::            An example function definition and
  8835. +                                what it does.
  8836. +* Function Caveats::            Things to watch out for.
  8837. +* Return Statement::            Specifying the value a function returns.
  8838. +
  8839. +
  8840. +File: gawk.info,  Node: Definition Syntax,  Next: Function Example,  Prev: User-defined,  Up: User-defined
  8841. +
  8842. +Syntax of Function Definitions
  8843. +==============================
  8844. +
  8845. +   Definitions of functions can appear anywhere between the rules of the
  8846. +`awk' program.  Thus, the general form of an `awk' program is extended
  8847. +to include sequences of rules *and* user-defined function definitions.
  8848. +
  8849. +   The definition of a function named NAME looks like this:
  8850. +
  8851. +     function NAME (PARAMETER-LIST) {
  8852. +          BODY-OF-FUNCTION
  8853. +     }
  8854. +
  8855. +NAME is the name of the function to be defined.  A valid function name
  8856. +is like a valid variable name: a sequence of letters, digits and
  8857. +underscores, not starting with a digit.  Functions share the same pool
  8858. +of names as variables and arrays.
  8859. +
  8860. +   PARAMETER-LIST is a list of the function's arguments and local
  8861. +variable names, separated by commas.  When the function is called, the
  8862. +argument names are used to hold the argument values given in the call.
  8863. +The local variables are initialized to the null string.
  8864. +
  8865. +   The BODY-OF-FUNCTION consists of `awk' statements.  It is the most
  8866. +important part of the definition, because it says what the function
  8867. +should actually *do*.  The argument names exist to give the body a way
  8868. +to talk about the arguments; local variables, to give the body places
  8869. +to keep temporary values.
  8870. +
  8871. +   Argument names are not distinguished syntactically from local
  8872. +variable names; instead, the number of arguments supplied when the
  8873. +function is called determines how many argument variables there are.
  8874. +Thus, if three argument values are given, the first three names in
  8875. +PARAMETER-LIST are arguments, and the rest are local variables.
  8876. +
  8877. +   It follows that if the number of arguments is not the same in all
  8878. +calls to the function, some of the names in PARAMETER-LIST may be
  8879. +arguments on some occasions and local variables on others.  Another way
  8880. +to think of this is that omitted arguments default to the null string.
  8881. +
  8882. +   Usually when you write a function you know how many names you intend
  8883. +to use for arguments and how many you intend to use as locals.  By
  8884. +convention, you should write an extra space between the arguments and
  8885. +the locals, so other people can follow how your function is supposed to
  8886. +be used.
  8887. +
  8888. +   During execution of the function body, the arguments and local
  8889. +variable values hide or "shadow" any variables of the same names used
  8890. +in the rest of the program.  The shadowed variables are not accessible
  8891. +in the function definition, because there is no way to name them while
  8892. +their names have been taken away for the local variables.  All other
  8893. +variables used in the `awk' program can be referenced or set normally
  8894. +in the function definition.
  8895. +
  8896. +   The arguments and local variables last only as long as the function
  8897. +body is executing.  Once the body finishes, the shadowed variables come
  8898. +back.
  8899. +
  8900. +   The function body can contain expressions which call functions.  They
  8901. +can even call this function, either directly or by way of another
  8902. +function.  When this happens, we say the function is "recursive".
  8903. +
  8904. +   There is no need in `awk' to put the definition of a function before
  8905. +all uses of the function.  This is because `awk' reads the entire
  8906. +program before starting to execute any of it.
  8907. +
  8908. +   In many `awk' implementations, the keyword `function' may be
  8909. +abbreviated `func'.  However, POSIX only specifies the use of the
  8910. +keyword `function'.  This actually has some practical implications.  If
  8911. +`gawk' is in POSIX-compatibility mode (*note Invoking `awk': Command
  8912. +Line.), then the following statement will *not* define a function:
  8913. +
  8914. +     func foo() { a = sqrt($1) ; print a }
  8915. +
  8916. +Instead it defines a rule that, for each record, concatenates the value
  8917. +of the variable `func' with the return value of the function `foo', and
  8918. +based on the truth value of the result, executes the corresponding
  8919. +action.  This is probably not what was desired.  (`awk' accepts this
  8920. +input as syntactically valid, since functions may be used before they
  8921. +are defined in `awk' programs.)
  8922. +
  8923. +
  8924. +File: gawk.info,  Node: Function Example,  Next: Function Caveats,  Prev: Definition Syntax,  Up: User-defined
  8925. +
  8926. +Function Definition Example
  8927. +===========================
  8928. +
  8929. +   Here is an example of a user-defined function, called `myprint', that
  8930. +takes a number and prints it in a specific format.
  8931. +
  8932. +     function myprint(num)
  8933. +     {
  8934. +          printf "%6.3g\n", num
  8935. +     }
  8936. +
  8937. +To illustrate, here is an `awk' rule which uses our `myprint' function:
  8938. +
  8939. +     $3 > 0     { myprint($3) }
  8940. +
  8941. +This program prints, in our special format, all the third fields that
  8942. +contain a positive number in our input.  Therefore, when given:
  8943. +
  8944. +      1.2   3.4    5.6   7.8
  8945. +      9.10 11.12 -13.14 15.16
  8946. +     17.18 19.20  21.22 23.24
  8947. +
  8948. +this program, using our function to format the results, prints:
  8949. +
  8950. +        5.6
  8951. +       21.2
  8952. +
  8953. +   Here is a rather contrived example of a recursive function.  It
  8954. +prints a string backwards:
  8955. +
  8956. +     function rev (str, len) {
  8957. +         if (len == 0) {
  8958. +             printf "\n"
  8959. +             return
  8960. +         }
  8961. +         printf "%c", substr(str, len, 1)
  8962. +         rev(str, len - 1)
  8963. +     }
  8964. +
  8965. +
  8966. +File: gawk.info,  Node: Function Caveats,  Next: Return Statement,  Prev: Function Example,  Up: User-defined
  8967. +
  8968. +Calling User-defined Functions
  8969. +==============================
  8970. +
  8971. +   "Calling a function" means causing the function to run and do its
  8972. +job.  A function call is an expression, and its value is the value
  8973. +returned by the function.
  8974. +
  8975. +   A function call consists of the function name followed by the
  8976. +arguments in parentheses.  What you write in the call for the arguments
  8977. +are `awk' expressions; each time the call is executed, these
  8978. +expressions are evaluated, and the values are the actual arguments.  For
  8979. +example, here is a call to `foo' with three arguments (the first being
  8980. +a string concatenation):
  8981. +
  8982. +     foo(x y, "lose", 4 * z)
  8983. +
  8984. +     *Caution:* whitespace characters (spaces and tabs) are not allowed
  8985. +     between the function name and the open-parenthesis of the argument
  8986. +     list.  If you write whitespace by mistake, `awk' might think that
  8987. +     you mean to concatenate a variable with an expression in
  8988. +     parentheses.  However, it notices that you used a function name
  8989. +     and not a variable name, and reports an error.
  8990. +
  8991. +   When a function is called, it is given a *copy* of the values of its
  8992. +arguments.  This is called "call by value".  The caller may use a
  8993. +variable as the expression for the argument, but the called function
  8994. +does not know this: it only knows what value the argument had.  For
  8995. +example, if you write this code:
  8996. +
  8997. +     foo = "bar"
  8998. +     z = myfunc(foo)
  8999. +
  9000. +then you should not think of the argument to `myfunc' as being "the
  9001. +variable `foo'."  Instead, think of the argument as the string value,
  9002. +`"bar"'.
  9003. +
  9004. +   If the function `myfunc' alters the values of its local variables,
  9005. +this has no effect on any other variables.  In particular, if `myfunc'
  9006. +does this:
  9007. +
  9008. +     function myfunc (win) {
  9009. +       print win
  9010. +       win = "zzz"
  9011. +       print win
  9012. +     }
  9013. +
  9014. +to change its first argument variable `win', this *does not* change the
  9015. +value of `foo' in the caller.  The role of `foo' in calling `myfunc'
  9016. +ended when its value, `"bar"', was computed.  If `win' also exists
  9017. +outside of `myfunc', the function body cannot alter this outer value,
  9018. +because it is shadowed during the execution of `myfunc' and cannot be
  9019. +seen or changed from there.
  9020. +
  9021. +   However, when arrays are the parameters to functions, they are *not*
  9022. +copied.  Instead, the array itself is made available for direct
  9023. +manipulation by the function.  This is usually called "call by
  9024. +reference".  Changes made to an array parameter inside the body of a
  9025. +function *are* visible outside that function.  This can be *very*
  9026. +dangerous if you do not watch what you are doing.  For example:
  9027. +
  9028. +     function changeit (array, ind, nvalue) {
  9029. +          array[ind] = nvalue
  9030. +     }
  9031. +     
  9032. +     BEGIN {
  9033. +                a[1] = 1 ; a[2] = 2 ; a[3] = 3
  9034. +                changeit(a, 2, "two")
  9035. +                printf "a[1] = %s, a[2] = %s, a[3] = %s\n", a[1], a[2], a[3]
  9036. +           }
  9037. +
  9038. +prints `a[1] = 1, a[2] = two, a[3] = 3', because calling `changeit'
  9039. +stores `"two"' in the second element of `a'.
  9040. +
  9041. +
  9042. +File: gawk.info,  Node: Return Statement,  Prev: Function Caveats,  Up: User-defined
  9043. +
  9044. +The `return' Statement
  9045. +======================
  9046. +
  9047. +   The body of a user-defined function can contain a `return' statement.
  9048. +This statement returns control to the rest of the `awk' program.  It
  9049. +can also be used to return a value for use in the rest of the `awk'
  9050. +program.  It looks like this:
  9051. +
  9052. +     return EXPRESSION
  9053. +
  9054. +   The EXPRESSION part is optional.  If it is omitted, then the returned
  9055. +value is undefined and, therefore, unpredictable.
  9056. +
  9057. +   A `return' statement with no value expression is assumed at the end
  9058. +of every function definition.  So if control reaches the end of the
  9059. +function body, then the function returns an unpredictable value.  `awk'
  9060. +will not warn you if you use the return value of such a function; you
  9061. +will simply get unpredictable or unexpected results.
  9062. +
  9063. +   Here is an example of a user-defined function that returns a value
  9064. +for the largest number among the elements of an array:
  9065. +
  9066. +     function maxelt (vec,   i, ret) {
  9067. +          for (i in vec) {
  9068. +               if (ret == "" || vec[i] > ret)
  9069. +                    ret = vec[i]
  9070. +          }
  9071. +          return ret
  9072. +     }
  9073. +
  9074. +You call `maxelt' with one argument, which is an array name.  The local
  9075. +variables `i' and `ret' are not intended to be arguments; while there
  9076. +is nothing to stop you from passing two or three arguments to `maxelt',
  9077. +the results would be strange.  The extra space before `i' in the
  9078. +function parameter list is to indicate that `i' and `ret' are not
  9079. +supposed to be arguments.  This is a convention which you should follow
  9080. +when you define functions.
  9081. +
  9082. +   Here is a program that uses our `maxelt' function.  It loads an
  9083. +array, calls `maxelt', and then reports the maximum number in that
  9084. +array:
  9085. +
  9086. +     awk '
  9087. +     function maxelt (vec,   i, ret) {
  9088. +          for (i in vec) {
  9089. +               if (ret == "" || vec[i] > ret)
  9090. +                    ret = vec[i]
  9091. +          }
  9092. +          return ret
  9093. +     }
  9094. +     
  9095. +     # Load all fields of each record into nums.
  9096. +     {
  9097. +               for(i = 1; i <= NF; i++)
  9098. +                    nums[NR, i] = $i
  9099. +     }
  9100. +     
  9101. +     END {
  9102. +          print maxelt(nums)
  9103. +     }'
  9104. +
  9105. +   Given the following input:
  9106. +
  9107. +      1 5 23 8 16
  9108. +     44 3 5 2 8 26
  9109. +     256 291 1396 2962 100
  9110. +     -6 467 998 1101
  9111. +     99385 11 0 225
  9112. +
  9113. +our program tells us (predictably) that:
  9114. +
  9115. +     99385
  9116. +
  9117. +is the largest number in our array.
  9118. +
  9119. +
  9120. +File: gawk.info,  Node: Built-in Variables,  Next: Command Line,  Prev: User-defined,  Up: Top
  9121. +
  9122. +Built-in Variables
  9123. +******************
  9124. +
  9125. +   Most `awk' variables are available for you to use for your own
  9126. +purposes; they never change except when your program assigns values to
  9127. +them, and never affect anything except when your program examines them.
  9128. +
  9129. +   A few variables have special built-in meanings.  Some of them `awk'
  9130. +examines automatically, so that they enable you to tell `awk' how to do
  9131. +certain things.  Others are set automatically by `awk', so that they
  9132. +carry information from the internal workings of `awk' to your program.
  9133. +
  9134. +   This chapter documents all the built-in variables of `gawk'.  Most
  9135. +of them are also documented in the chapters where their areas of
  9136. +activity are described.
  9137. +
  9138. +* Menu:
  9139. +
  9140. +* User-modified::               Built-in variables that you change
  9141. +                                to control `awk'.
  9142. +* Auto-set::                    Built-in variables where `awk'
  9143. +                                gives you information.
  9144. +
  9145. +
  9146. +File: gawk.info,  Node: User-modified,  Next: Auto-set,  Prev: Built-in Variables,  Up: Built-in Variables
  9147. +
  9148. +Built-in Variables that Control `awk'
  9149. +=====================================
  9150. +
  9151. +   This is a list of the variables which you can change to control how
  9152. +`awk' does certain things.
  9153. +
  9154. +`CONVFMT'
  9155. +     This string is used by `awk' to control conversion of numbers to
  9156. +     strings (*note Conversion of Strings and Numbers: Conversion.).
  9157. +     It works by being passed, in effect, as the first argument to the
  9158. +     `sprintf' function.  Its default value is `"%.6g"'.  `CONVFMT' was
  9159. +     introduced by the POSIX standard.
  9160. +
  9161. +`FIELDWIDTHS'
  9162. +     This is a space separated list of columns that tells `gawk' how to
  9163. +     manage input with fixed, columnar boundaries.  It is an
  9164. +     experimental feature that is still evolving.  Assigning to
  9165. +     `FIELDWIDTHS' overrides the use of `FS' for field splitting.
  9166. +     *Note Reading Fixed-width Data: Constant Size, for more
  9167. +     information.
  9168. +
  9169. +     If `gawk' is in compatibility mode (*note Invoking `awk': Command
  9170. +     Line.), then `FIELDWIDTHS' has no special meaning, and field
  9171. +     splitting operations are done based exclusively on the value of
  9172. +     `FS'.
  9173. +
  9174. +`FS'
  9175. +     `FS' is the input field separator (*note Specifying how Fields are
  9176. +     Separated: Field Separators.).  The value is a single-character
  9177. +     string or a multi-character regular expression that matches the
  9178. +     separations between fields in an input record.
  9179. +
  9180. +     The default value is `" "', a string consisting of a single space.
  9181. +     As a special exception, this value actually means that any
  9182. +     sequence of spaces and tabs is a single separator.  It also causes
  9183. +     spaces and tabs at the beginning or end of a line to be ignored.
  9184. +
  9185. +     You can set the value of `FS' on the command line using the `-F'
  9186. +     option:
  9187. +
  9188. +          awk -F, 'PROGRAM' INPUT-FILES
  9189. +
  9190. +     If `gawk' is using `FIELDWIDTHS' for field-splitting, assigning a
  9191. +     value to `FS' will cause `gawk' to return to the normal,
  9192. +     regexp-based, field splitting.
  9193. +
  9194. +`IGNORECASE'
  9195. +     If `IGNORECASE' is nonzero, then *all* regular expression matching
  9196. +     is done in a case-independent fashion.  In particular, regexp
  9197. +     matching with `~' and `!~', and the `gsub' `index', `match',
  9198. +     `split' and `sub' functions all ignore case when doing their
  9199. +     particular regexp operations.  *Note:* since field splitting with
  9200. +     the value of the `FS' variable is also a regular expression
  9201. +     operation, that too is done with case ignored.  *Note
  9202. +     Case-sensitivity in Matching: Case-sensitivity.
  9203. +
  9204. +     If `gawk' is in compatibility mode (*note Invoking `awk': Command
  9205. +     Line.), then `IGNORECASE' has no special meaning, and regexp
  9206. +     operations are always case-sensitive.
  9207. +
  9208. +`OFMT'
  9209. +     This string is used by `awk' to control conversion of numbers to
  9210. +     strings (*note Conversion of Strings and Numbers: Conversion.) for
  9211. +     printing with the `print' statement.  It works by being passed, in
  9212. +     effect, as the first argument to the `sprintf' function.  Its
  9213. +     default value is `"%.6g"'.  Earlier versions of `awk' also used
  9214. +     `OFMT' to specify the format for converting numbers to strings in
  9215. +     general expressions; this has been taken over by `CONVFMT'.
  9216. +
  9217. +`OFS'
  9218. +     This is the output field separator (*note Output Separators::.).
  9219. +     It is output between the fields output by a `print' statement.  Its
  9220. +     default value is `" "', a string consisting of a single space.
  9221. +
  9222. +`ORS'
  9223. +     This is the output record separator.  It is output at the end of
  9224. +     every `print' statement.  Its default value is a string containing
  9225. +     a single newline character, which could be written as `"\n"'.
  9226. +     (*Note Output Separators::.)
  9227. +
  9228. +`RS'
  9229. +     This is `awk''s input record separator.  Its default value is a
  9230. +     string containing a single newline character, which means that an
  9231. +     input record consists of a single line of text.  (*Note How Input
  9232. +     is Split into Records: Records.)
  9233. +
  9234. +`SUBSEP'
  9235. +     `SUBSEP' is the subscript separator.  It has the default value of
  9236. +     `"\034"', and is used to separate the parts of the name of a
  9237. +     multi-dimensional array.  Thus, if you access `foo[12,3]', it
  9238. +     really accesses `foo["12\0343"]' (*note Multi-dimensional Arrays:
  9239. +     Multi-dimensional.).
  9240. +
  9241. +
  9242. +File: gawk.info,  Node: Auto-set,  Prev: User-modified,  Up: Built-in Variables
  9243. +
  9244. +Built-in Variables that Convey Information
  9245. +==========================================
  9246. +
  9247. +   This is a list of the variables that are set automatically by `awk'
  9248. +on certain occasions so as to provide information to your program.
  9249. +
  9250. +`ARGC'
  9251. +`ARGV'
  9252. +     The command-line arguments available to `awk' programs are stored
  9253. +     in an array called `ARGV'.  `ARGC' is the number of command-line
  9254. +     arguments present.  *Note Invoking `awk': Command Line.  `ARGV' is
  9255. +     indexed from zero to `ARGC - 1'.  For example:
  9256. +
  9257. +          awk 'BEGIN {
  9258. +                 for (i = 0; i < ARGC; i++)
  9259. +                     print ARGV[i]
  9260. +               }' inventory-shipped BBS-list
  9261. +
  9262. +     In this example, `ARGV[0]' contains `"awk"', `ARGV[1]' contains
  9263. +     `"inventory-shipped"', and `ARGV[2]' contains `"BBS-list"'.  The
  9264. +     value of `ARGC' is 3, one more than the index of the last element
  9265. +     in `ARGV' since the elements are numbered from zero.
  9266. +
  9267. +     The names `ARGC' and `ARGV', as well the convention of indexing
  9268. +     the array from 0 to `ARGC - 1', are derived from the C language's
  9269. +     method of accessing command line arguments.
  9270. +
  9271. +     Notice that the `awk' program is not entered in `ARGV'.  The other
  9272. +     special command line options, with their arguments, are also not
  9273. +     entered.  But variable assignments on the command line *are*
  9274. +     treated as arguments, and do show up in the `ARGV' array.
  9275. +
  9276. +     Your program can alter `ARGC' and the elements of `ARGV'.  Each
  9277. +     time `awk' reaches the end of an input file, it uses the next
  9278. +     element of `ARGV' as the name of the next input file.  By storing a
  9279. +     different string there, your program can change which files are
  9280. +     read.  You can use `"-"' to represent the standard input.  By
  9281. +     storing additional elements and incrementing `ARGC' you can cause
  9282. +     additional files to be read.
  9283. +
  9284. +     If you decrease the value of `ARGC', that eliminates input files
  9285. +     from the end of the list.  By recording the old value of `ARGC'
  9286. +     elsewhere, your program can treat the eliminated arguments as
  9287. +     something other than file names.
  9288. +
  9289. +     To eliminate a file from the middle of the list, store the null
  9290. +     string (`""') into `ARGV' in place of the file's name.  As a
  9291. +     special feature, `awk' ignores file names that have been replaced
  9292. +     with the null string.
  9293. +
  9294. +`ARGIND'
  9295. +     The index in `ARGV' of the current file being processed.  Every
  9296. +     time `gawk' opens a new data file for processing, it sets `ARGIND'
  9297. +     to the index in `ARGV' of the file name.  Thus, the condition
  9298. +     `FILENAME == ARGV[ARGIND]' is always true.
  9299. +
  9300. +     This variable is useful in file processing; it allows you to tell
  9301. +     how far along you are in the list of data files, and to
  9302. +     distinguish between multiple successive instances of the same
  9303. +     filename on the command line.
  9304. +
  9305. +     While you can change the value of `ARGIND' within your `awk'
  9306. +     program, `gawk' will automatically set it to a new value when the
  9307. +     next file is opened.
  9308. +
  9309. +     This variable is a `gawk' extension; in other `awk' implementations
  9310. +     it is not special.
  9311. +
  9312. +`ENVIRON'
  9313. +     This is an array that contains the values of the environment.  The
  9314. +     array indices are the environment variable names; the values are
  9315. +     the values of the particular environment variables.  For example,
  9316. +     `ENVIRON["HOME"]' might be `/u/close'.  Changing this array does
  9317. +     not affect the environment passed on to any programs that `awk'
  9318. +     may spawn via redirection or the `system' function.  (In a future
  9319. +     version of `gawk', it may do so.)
  9320. +
  9321. +     Some operating systems may not have environment variables.  On
  9322. +     such systems, the array `ENVIRON' is empty.
  9323. +
  9324. +`ERRNO'
  9325. +     If a system error occurs either doing a redirection for `getline',
  9326. +     during a read for `getline', or during a `close' operation, then
  9327. +     `ERRNO' will contain a string describing the error.
  9328. +
  9329. +     This variable is a `gawk' extension; in other `awk' implementations
  9330. +     it is not special.
  9331. +
  9332. +`FILENAME'
  9333. +     This is the name of the file that `awk' is currently reading.  If
  9334. +     `awk' is reading from the standard input (in other words, there
  9335. +     are no files listed on the command line), `FILENAME' is set to
  9336. +     `"-"'.  `FILENAME' is changed each time a new file is read (*note
  9337. +     Reading Input Files: Reading Files.).
  9338. +
  9339. +`FNR'
  9340. +     `FNR' is the current record number in the current file.  `FNR' is
  9341. +     incremented each time a new record is read (*note Explicit Input
  9342. +     with `getline': Getline.).  It is reinitialized to 0 each time a
  9343. +     new input file is started.
  9344. +
  9345. +`NF'
  9346. +     `NF' is the number of fields in the current input record.  `NF' is
  9347. +     set each time a new record is read, when a new field is created,
  9348. +     or when `$0' changes (*note Examining Fields: Fields.).
  9349. +
  9350. +`NR'
  9351. +     This is the number of input records `awk' has processed since the
  9352. +     beginning of the program's execution.  (*note How Input is Split
  9353. +     into Records: Records.).  `NR' is set each time a new record is
  9354. +     read.
  9355. +
  9356. +`RLENGTH'
  9357. +     `RLENGTH' is the length of the substring matched by the `match'
  9358. +     function (*note Built-in Functions for String Manipulation: String
  9359. +     Functions.).  `RLENGTH' is set by invoking the `match' function.
  9360. +     Its value is the length of the matched string, or -1 if no match
  9361. +     was found.
  9362. +
  9363. +`RSTART'
  9364. +     `RSTART' is the start-index in characters of the substring matched
  9365. +     by the `match' function (*note Built-in Functions for String
  9366. +     Manipulation: String Functions.).  `RSTART' is set by invoking the
  9367. +     `match' function.  Its value is the position of the string where
  9368. +     the matched substring starts, or 0 if no match was found.
  9369. +
  9370. +
  9371. +File: gawk.info,  Node: Command Line,  Next: Language History,  Prev: Built-in Variables,  Up: Top
  9372. +
  9373. +Invoking `awk'
  9374. +**************
  9375. +
  9376. +   There are two ways to run `awk': with an explicit program, or with
  9377. +one or more program files.  Here are templates for both of them; items
  9378. +enclosed in `[...]' in these templates are optional.
  9379. +
  9380. +   Besides traditional one-letter POSIX-style options, `gawk' also
  9381. +supports GNU long named options.
  9382. +
  9383. +     awk [POSIX OR GNU STYLE OPTIONS] -f progfile [`--'] FILE ...
  9384. +     awk [POSIX OR GNU STYLE OPTIONS] [`--'] 'PROGRAM' FILE ...
  9385. +
  9386. +* Menu:
  9387. +
  9388. +* Options::                     Command line options and their meanings.
  9389. +* Other Arguments::             Input file names and variable assignments.
  9390. +* AWKPATH Variable::            Searching directories for `awk' programs.
  9391. +* Obsolete::                    Obsolete Options and/or features.
  9392. +* Undocumented::                Undocumented Options and Features.
  9393. +
  9394. +
  9395. +File: gawk.info,  Node: Options,  Next: Other Arguments,  Prev: Command Line,  Up: Command Line
  9396. +
  9397. +Command Line Options
  9398. +====================
  9399. +
  9400. +   Options begin with a minus sign, and consist of a single character.
  9401. +GNU style long named options consist of two minus signs and a keyword
  9402. +that can be abbreviated if the abbreviation allows the option to be
  9403. +uniquely identified.  If the option takes an argument, then the keyword
  9404. +is immediately followed by an equals sign (`=') and the argument's
  9405. +value.  For brevity, the discussion below only refers to the
  9406. +traditional short options; however the long and short options are
  9407. +interchangeable in all contexts.
  9408. +
  9409. +   Each long named option for `gawk' has a corresponding POSIX-style
  9410. +option.  The options and their meanings are as follows:
  9411. +
  9412. +`-F FS'
  9413. +`--field-separator=FS'
  9414. +     Sets the `FS' variable to FS (*note Specifying how Fields are
  9415. +     Separated: Field Separators.).
  9416. +
  9417. +`-f SOURCE-FILE'
  9418. +`--file=SOURCE-FILE'
  9419. +     Indicates that the `awk' program is to be found in SOURCE-FILE
  9420. +     instead of in the first non-option argument.
  9421. +
  9422. +`-v VAR=VAL'
  9423. +`--assign=VAR=VAL'
  9424. +     Sets the variable VAR to the value VAL *before* execution of the
  9425. +     program begins.  Such variable values are available inside the
  9426. +     `BEGIN' rule (see below for a fuller explanation).
  9427. +
  9428. +     The `-v' option can only set one variable, but you can use it more
  9429. +     than once, setting another variable each time, like this:
  9430. +     `-v foo=1 -v bar=2'.
  9431. +
  9432. +`-W GAWK-OPT'
  9433. +     Following the POSIX standard, options that are implementation
  9434. +     specific are supplied as arguments to the `-W' option.  With
  9435. +     `gawk', these arguments may be separated by commas, or quoted and
  9436. +     separated by whitespace.  Case is ignored when processing these
  9437. +     options.  These options also have corresponding GNU style long
  9438. +     named options.  The following `gawk'-specific options are
  9439. +     available:
  9440. +
  9441. +    `-W compat'
  9442. +    `--compat'
  9443. +          Specifies "compatibility mode", in which the GNU extensions in
  9444. +          `gawk' are disabled, so that `gawk' behaves just like Unix
  9445. +          `awk'.  *Note Extensions in `gawk' not in POSIX `awk':
  9446. +          POSIX/GNU, which summarizes the extensions.  Also see *Note
  9447. +          Downward Compatibility and Debugging: Compatibility Mode.
  9448. +
  9449. +    `-W copyleft'
  9450. +    `-W copyright'
  9451. +    `--copyleft'
  9452. +    `--copyright'
  9453. +          Print the short version of the General Public License.  This
  9454. +          option may disappear in a future version of `gawk'.
  9455. +
  9456. +    `-W help'
  9457. +    `-W usage'
  9458. +    `--help'
  9459. +    `--usage'
  9460. +          Print a "usage" message summarizing the short and long style
  9461. +          options that `gawk' accepts, and then exit.
  9462. +
  9463. +    `-W lint'
  9464. +    `--lint'
  9465. +          Provide warnings about constructs that are dubious or
  9466. +          non-portable to other `awk' implementations.  Some warnings
  9467. +          are issued when `gawk' first reads your program.  Others are
  9468. +          issued at run-time, as your program executes.
  9469. +
  9470. +    `-W posix'
  9471. +    `--posix'
  9472. +          Operate in strict POSIX mode.  This disables all `gawk'
  9473. +          extensions (just like `-W compat'), and adds the following
  9474. +          additional restrictions:
  9475. +
  9476. +             * `\x' escape sequences are not recognized (*note Constant
  9477. +               Expressions: Constants.).
  9478. +
  9479. +             * The synonym `func' for the keyword `function' is not
  9480. +               recognized (*note Syntax of Function Definitions:
  9481. +               Definition Syntax.).
  9482. +
  9483. +             * The operators `**' and `**=' cannot be used in place of
  9484. +               `^' and `^=' (*note Arithmetic Operators: Arithmetic
  9485. +               Ops., and also *note Assignment Expressions: Assignment
  9486. +               Ops.).
  9487. +
  9488. +             * Specifying `-Ft' on the command line does not set the
  9489. +               value of `FS' to be a single tab character (*note
  9490. +               Specifying how Fields are Separated: Field Separators.).
  9491. +
  9492. +          Although you can supply both `-W compat' and `-W posix' on the
  9493. +          command line, `-W posix' will take precedence.
  9494. +
  9495. +    `-W source=PROGRAM-TEXT'
  9496. +    `--source=PROGRAM-TEXT'
  9497. +          Program source code is taken from the PROGRAM-TEXT.  This
  9498. +          option allows you to mix `awk' source code in files with
  9499. +          program source code that you would enter on the command line.
  9500. +          This is particularly useful when you have library functions
  9501. +          that you wish to use from your command line programs (*note
  9502. +          The `AWKPATH' Environment Variable: AWKPATH Variable.).
  9503. +
  9504. +    `-W version'
  9505. +    `--version'
  9506. +          Prints version information for this particular copy of `gawk'.
  9507. +          This is so you can determine if your copy of `gawk' is up to
  9508. +          date with respect to whatever the Free Software Foundation is
  9509. +          currently distributing.  This option may disappear in a
  9510. +          future version of `gawk'.
  9511. +
  9512. +`--'
  9513. +     Signals the end of the command line options.  The following
  9514. +     arguments are not treated as options even if they begin with `-'.
  9515. +     This interpretation of `--' follows the POSIX argument parsing
  9516. +     conventions.
  9517. +
  9518. +     This is useful if you have file names that start with `-', or in
  9519. +     shell scripts, if you have file names that will be specified by
  9520. +     the user which could start with `-'.
  9521. +
  9522. +   Any other options are flagged as invalid with a warning message, but
  9523. +are otherwise ignored.
  9524. +
  9525. +   In compatibility mode, as a special case, if the value of FS supplied
  9526. +to the `-F' option is `t', then `FS' is set to the tab character
  9527. +(`"\t"').  This is only true for `-W compat', and not for `-W posix'
  9528. +(*note Specifying how Fields are Separated: Field Separators.).
  9529. +
  9530. +   If the `-f' option is *not* used, then the first non-option command
  9531. +line argument is expected to be the program text.
  9532. +
  9533. +   The `-f' option may be used more than once on the command line.  If
  9534. +it is, `awk' reads its program source from all of the named files, as
  9535. +if they had been concatenated together into one big file.  This is
  9536. +useful for creating libraries of `awk' functions.  Useful functions can
  9537. +be written once, and then retrieved from a standard place, instead of
  9538. +having to be included into each individual program.  You can still type
  9539. +in a program at the terminal and use library functions, by specifying
  9540. +`-f /dev/tty'.  `awk' will read a file from the terminal to use as part
  9541. +of the `awk' program.  After typing your program, type `Control-d' (the
  9542. +end-of-file character) to terminate it.  (You may also use `-f -' to
  9543. +read program source from the standard input, but then you will not be
  9544. +able to also use the standard input as a source of data.)
  9545. +
  9546. +   Because it is clumsy using the standard `awk' mechanisms to mix
  9547. +source file and command line `awk' programs, `gawk' provides the
  9548. +`--source' option.  This does not require you to pre-empt the standard
  9549. +input for your source code, and allows you to easily mix command line
  9550. +and library source code (*note The `AWKPATH' Environment Variable:
  9551. +AWKPATH Variable.).
  9552. +
  9553. +   If no `-f' or `--source' option is specified, then `gawk' will use
  9554. +the first non-option command line argument as the text of the program
  9555. +source code.
  9556. +
  9557. +
  9558. +File: gawk.info,  Node: Other Arguments,  Next: AWKPATH Variable,  Prev: Options,  Up: Command Line
  9559. +
  9560. +Other Command Line Arguments
  9561. +============================
  9562. +
  9563. +   Any additional arguments on the command line are normally treated as
  9564. +input files to be processed in the order specified.  However, an
  9565. +argument that has the form `VAR=VALUE', means to assign the value VALUE
  9566. +to the variable VAR--it does not specify a file at all.
  9567. +
  9568. +   All these arguments are made available to your `awk' program in the
  9569. +`ARGV' array (*note Built-in Variables::.).  Command line options and
  9570. +the program text (if present) are omitted from the `ARGV' array.  All
  9571. +other arguments, including variable assignments, are included.
  9572. +
  9573. +   The distinction between file name arguments and variable-assignment
  9574. +arguments is made when `awk' is about to open the next input file.  At
  9575. +that point in execution, it checks the "file name" to see whether it is
  9576. +really a variable assignment; if so, `awk' sets the variable instead of
  9577. +reading a file.
  9578. +
  9579. +   Therefore, the variables actually receive the specified values after
  9580. +all previously specified files have been read.  In particular, the
  9581. +values of variables assigned in this fashion are *not* available inside
  9582. +a `BEGIN' rule (*note `BEGIN' and `END' Special Patterns: BEGIN/END.),
  9583. +since such rules are run before `awk' begins scanning the argument list.
  9584. +The values given on the command line are processed for escape sequences
  9585. +(*note Constant Expressions: Constants.).
  9586. +
  9587. +   In some earlier implementations of `awk', when a variable assignment
  9588. +occurred before any file names, the assignment would happen *before*
  9589. +the `BEGIN' rule was executed.  Some applications came to depend upon
  9590. +this "feature."  When `awk' was changed to be more consistent, the `-v'
  9591. +option was added to accommodate applications that depended upon this
  9592. +old behavior.
  9593. +
  9594. +   The variable assignment feature is most useful for assigning to
  9595. +variables such as `RS', `OFS', and `ORS', which control input and
  9596. +output formats, before scanning the data files.  It is also useful for
  9597. +controlling state if multiple passes are needed over a data file.  For
  9598. +example:
  9599. +
  9600. +     awk 'pass == 1  { PASS 1 STUFF }
  9601. +          pass == 2  { PASS 2 STUFF }' pass=1 datafile pass=2 datafile
  9602. +
  9603. +   Given the variable assignment feature, the `-F' option is not
  9604. +strictly necessary.  It remains for historical compatibility.
  9605. +
  9606. +
  9607. +File: gawk.info,  Node: AWKPATH Variable,  Next: Obsolete,  Prev: Other Arguments,  Up: Command Line
  9608. +
  9609. +The `AWKPATH' Environment Variable
  9610. +==================================
  9611. +
  9612. +   The previous section described how `awk' program files can be named
  9613. +on the command line with the `-f' option.  In some `awk'
  9614. +implementations, you must supply a precise path name for each program
  9615. +file, unless the file is in the current directory.
  9616. +
  9617. +   But in `gawk', if the file name supplied in the `-f' option does not
  9618. +contain a `/', then `gawk' searches a list of directories (called the
  9619. +"search path"), one by one, looking for a file with the specified name.
  9620. +
  9621. +   The search path is actually a string consisting of directory names
  9622. +separated by colons.  `gawk' gets its search path from the `AWKPATH'
  9623. +environment variable.  If that variable does not exist, `gawk' uses the
  9624. +default path, which is `.:/local/lib/awk:/ade/lib/awk'.  (Programs
  9625. +written by system administrators should use an `AWKPATH' variable that
  9626. +does not include the current directory, `.'.)
  9627. +
  9628. +   The search path feature is particularly useful for building up
  9629. +libraries of useful `awk' functions.  The library files can be placed
  9630. +in a standard directory that is in the default path, and then specified
  9631. +on the command line with a short file name.  Otherwise, the full file
  9632. +name would have to be typed for each file.
  9633. +
  9634. +   By combining the `--source' and `-f' options, your command line
  9635. +`awk' programs can use facilities in `awk' library files.
  9636. +
  9637. +   Path searching is not done if `gawk' is in compatibility mode.  This
  9638. +is true for both `-W compat' and `-W posix'.  *Note Command Line
  9639. +Options: Options.
  9640. +
  9641. +   *Note:* if you want files in the current directory to be found, you
  9642. +must include the current directory in the path, either by writing `.'
  9643. +as an entry in the path, or by writing a null entry in the path.  (A
  9644. +null entry is indicated by starting or ending the path with a colon, or
  9645. +by placing two colons next to each other (`::').)  If the current
  9646. +directory is not included in the path, then files cannot be found in
  9647. +the current directory.  This path search mechanism is identical to the
  9648. +shell's.
  9649. +
  9650. +
  9651. +File: gawk.info,  Node: Obsolete,  Next: Undocumented,  Prev: AWKPATH Variable,  Up: Command Line
  9652. +
  9653. +Obsolete Options and/or Features
  9654. +================================
  9655. +
  9656. +   This section describes features and/or command line options from the
  9657. +previous release of `gawk' that are either not available in the current
  9658. +version, or that are still supported but deprecated (meaning that they
  9659. +will *not* be in the next release).
  9660. +
  9661. +   For version 2.15 of `gawk', the following command line options from
  9662. +version 2.11.1 are no longer recognized.
  9663. +
  9664. +`-c'
  9665. +     Use `-W compat' instead.
  9666. +
  9667. +`-V'
  9668. +     Use `-W version' instead.
  9669. +
  9670. +`-C'
  9671. +     Use `-W copyright' instead.
  9672. +
  9673. +`-a'
  9674. +`-e'
  9675. +     These options produce an "unrecognized option" error message but
  9676. +     have no effect on the execution of `gawk'.  The POSIX standard now
  9677. +     specifies traditional `awk' regular expressions for the `awk'
  9678. +     utility.
  9679. +
  9680. +   The public-domain version of `strftime' that is distributed with
  9681. +`gawk' changed for the 2.14 release.  The `%V' conversion specifier
  9682. +that used to generate the date in VMS format was changed to `%v'.  This
  9683. +is because the POSIX standard for the `date' utility now specifies a
  9684. +`%V' conversion specifier.  *Note Functions for Dealing with Time
  9685. +Stamps: Time Functions, for details.
  9686. +
  9687. +
  9688. +File: gawk.info,  Node: Undocumented,  Prev: Obsolete,  Up: Command Line
  9689. +
  9690. +Undocumented Options and Features
  9691. +=================================
  9692. +
  9693. +   This section intentionally left blank.
  9694. +
  9695. +
  9696. +File: gawk.info,  Node: Language History,  Next: Installation,  Prev: Command Line,  Up: Top
  9697. +
  9698. +The Evolution of the `awk' Language
  9699. +***********************************
  9700. +
  9701. +   This manual describes the GNU implementation of `awk', which is
  9702. +patterned after the POSIX specification.  Many `awk' users are only
  9703. +familiar with the original `awk' implementation in Version 7 Unix,
  9704. +which is also the basis for the version in Berkeley Unix (through
  9705. +4.3-Reno).  This chapter briefly describes the evolution of the `awk'
  9706. +language.
  9707. +
  9708. +* Menu:
  9709. +
  9710. +* V7/S5R3.1::                   The major changes between V7 and
  9711. +                                System V Release 3.1.
  9712. +* S5R4::                        Minor changes between System V
  9713. +                                Releases 3.1 and 4.
  9714. +* POSIX::                       New features from the POSIX standard.
  9715. +* POSIX/GNU::                   The extensions in `gawk'
  9716. +                                not in POSIX `awk'.
  9717. +
  9718. diff -rup --new-file baseline/fsf/gawk/gawk.info-7 amiga/fsf/gawk/gawk.info-7
  9719. --- baseline/fsf/gawk/gawk.info-7    Wed Dec 31 17:00:00 1969
  9720. +++ amiga/fsf/gawk/gawk.info-7    Sat Sep 28 00:00:00 1996
  9721. @@ -0,0 +1,1265 @@
  9722. +This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  9723. +file /gnu-src/gawk-2.15.6/gawk.texi.
  9724. +
  9725. +   This file documents `awk', a program that you can use to select
  9726. +particular records in a file and perform operations upon them.
  9727. +
  9728. +   This is Edition 0.15 of `The GAWK Manual',
  9729. +for the 2.15 version of the GNU implementation
  9730. +of AWK.
  9731. +
  9732. +   Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  9733. +
  9734. +   Permission is granted to make and distribute verbatim copies of this
  9735. +manual provided the copyright notice and this permission notice are
  9736. +preserved on all copies.
  9737. +
  9738. +   Permission is granted to copy and distribute modified versions of
  9739. +this manual under the conditions for verbatim copying, provided that
  9740. +the entire resulting derived work is distributed under the terms of a
  9741. +permission notice identical to this one.
  9742. +
  9743. +   Permission is granted to copy and distribute translations of this
  9744. +manual into another language, under the above conditions for modified
  9745. +versions, except that this permission notice may be stated in a
  9746. +translation approved by the Foundation.
  9747. +
  9748. +
  9749. +File: gawk.info,  Node: V7/S5R3.1,  Next: S5R4,  Prev: Language History,  Up: Language History
  9750. +
  9751. +Major Changes between V7 and S5R3.1
  9752. +===================================
  9753. +
  9754. +   The `awk' language evolved considerably between the release of
  9755. +Version 7 Unix (1978) and the new version first made widely available in
  9756. +System V Release 3.1 (1987).  This section summarizes the changes, with
  9757. +cross-references to further details.
  9758. +
  9759. +   * The requirement for `;' to separate rules on a line (*note `awk'
  9760. +     Statements versus Lines: Statements/Lines.).
  9761. +
  9762. +   * User-defined functions, and the `return' statement (*note
  9763. +     User-defined Functions: User-defined.).
  9764. +
  9765. +   * The `delete' statement (*note The `delete' Statement: Delete.).
  9766. +
  9767. +   * The `do'-`while' statement (*note The `do'-`while' Statement: Do
  9768. +     Statement.).
  9769. +
  9770. +   * The built-in functions `atan2', `cos', `sin', `rand' and `srand'
  9771. +     (*note Numeric Built-in Functions: Numeric Functions.).
  9772. +
  9773. +   * The built-in functions `gsub', `sub', and `match' (*note Built-in
  9774. +     Functions for String Manipulation: String Functions.).
  9775. +
  9776. +   * The built-in functions `close', which closes an open file, and
  9777. +     `system', which allows the user to execute operating system
  9778. +     commands (*note Built-in Functions for Input/Output: I/O
  9779. +     Functions.).
  9780. +
  9781. +   * The `ARGC', `ARGV', `FNR', `RLENGTH', `RSTART', and `SUBSEP'
  9782. +     built-in variables (*note Built-in Variables::.).
  9783. +
  9784. +   * The conditional expression using the operators `?' and `:' (*note
  9785. +     Conditional Expressions: Conditional Exp.).
  9786. +
  9787. +   * The exponentiation operator `^' (*note Arithmetic Operators:
  9788. +     Arithmetic Ops.) and its assignment operator form `^=' (*note
  9789. +     Assignment Expressions: Assignment Ops.).
  9790. +
  9791. +   * C-compatible operator precedence, which breaks some old `awk'
  9792. +     programs (*note Operator Precedence (How Operators Nest):
  9793. +     Precedence.).
  9794. +
  9795. +   * Regexps as the value of `FS' (*note Specifying how Fields are
  9796. +     Separated: Field Separators.), and as the third argument to the
  9797. +     `split' function (*note Built-in Functions for String
  9798. +     Manipulation: String Functions.).
  9799. +
  9800. +   * Dynamic regexps as operands of the `~' and `!~' operators (*note
  9801. +     How to Use Regular Expressions: Regexp Usage.).
  9802. +
  9803. +   * Escape sequences (*note Constant Expressions: Constants.) in
  9804. +     regexps.
  9805. +
  9806. +   * The escape sequences `\b', `\f', and `\r' (*note Constant
  9807. +     Expressions: Constants.).
  9808. +
  9809. +   * Redirection of input for the `getline' function (*note Explicit
  9810. +     Input with `getline': Getline.).
  9811. +
  9812. +   * Multiple `BEGIN' and `END' rules (*note `BEGIN' and `END' Special
  9813. +     Patterns: BEGIN/END.).
  9814. +
  9815. +   * Simulated multi-dimensional arrays (*note Multi-dimensional
  9816. +     Arrays: Multi-dimensional.).
  9817. +
  9818. +
  9819. +File: gawk.info,  Node: S5R4,  Next: POSIX,  Prev: V7/S5R3.1,  Up: Language History
  9820. +
  9821. +Changes between S5R3.1 and S5R4
  9822. +===============================
  9823. +
  9824. +   The System V Release 4 version of Unix `awk' added these features
  9825. +(some of which originated in `gawk'):
  9826. +
  9827. +   * The `ENVIRON' variable (*note Built-in Variables::.).
  9828. +
  9829. +   * Multiple `-f' options on the command line (*note Invoking `awk':
  9830. +     Command Line.).
  9831. +
  9832. +   * The `-v' option for assigning variables before program execution
  9833. +     begins (*note Invoking `awk': Command Line.).
  9834. +
  9835. +   * The `--' option for terminating command line options.
  9836. +
  9837. +   * The `\a', `\v', and `\x' escape sequences (*note Constant
  9838. +     Expressions: Constants.).
  9839. +
  9840. +   * A defined return value for the `srand' built-in function (*note
  9841. +     Numeric Built-in Functions: Numeric Functions.).
  9842. +
  9843. +   * The `toupper' and `tolower' built-in string functions for case
  9844. +     translation (*note Built-in Functions for String Manipulation:
  9845. +     String Functions.).
  9846. +
  9847. +   * A cleaner specification for the `%c' format-control letter in the
  9848. +     `printf' function (*note Using `printf' Statements for Fancier
  9849. +     Printing: Printf.).
  9850. +
  9851. +   * The ability to dynamically pass the field width and precision
  9852. +     (`"%*.*d"') in the argument list of the `printf' function (*note
  9853. +     Using `printf' Statements for Fancier Printing: Printf.).
  9854. +
  9855. +   * The use of constant regexps such as `/foo/' as expressions, where
  9856. +     they are equivalent to use of the matching operator, as in `$0 ~
  9857. +     /foo/' (*note Constant Expressions: Constants.).
  9858. +
  9859. +
  9860. +File: gawk.info,  Node: POSIX,  Next: POSIX/GNU,  Prev: S5R4,  Up: Language History
  9861. +
  9862. +Changes between S5R4 and POSIX `awk'
  9863. +====================================
  9864. +
  9865. +   The POSIX Command Language and Utilities standard for `awk'
  9866. +introduced the following changes into the language:
  9867. +
  9868. +   * The use of `-W' for implementation-specific options.
  9869. +
  9870. +   * The use of `CONVFMT' for controlling the conversion of numbers to
  9871. +     strings (*note Conversion of Strings and Numbers: Conversion.).
  9872. +
  9873. +   * The concept of a numeric string, and tighter comparison rules to go
  9874. +     with it (*note Comparison Expressions: Comparison Ops.).
  9875. +
  9876. +   * More complete documentation of many of the previously undocumented
  9877. +     features of the language.
  9878. +
  9879. +
  9880. +File: gawk.info,  Node: POSIX/GNU,  Prev: POSIX,  Up: Language History
  9881. +
  9882. +Extensions in `gawk' not in POSIX `awk'
  9883. +=======================================
  9884. +
  9885. +   The GNU implementation, `gawk', adds these features:
  9886. +
  9887. +   * The `AWKPATH' environment variable for specifying a path search for
  9888. +     the `-f' command line option (*note Invoking `awk': Command Line.).
  9889. +
  9890. +   * The various `gawk' specific features available via the `-W'
  9891. +     command line option (*note Invoking `awk': Command Line.).
  9892. +
  9893. +   * The `ARGIND' variable, that tracks the movement of `FILENAME'
  9894. +     through `ARGV'.  (*note Built-in Variables::.).
  9895. +
  9896. +   * The `ERRNO' variable, that contains the system error message when
  9897. +     `getline' returns -1, or when `close' fails.  (*note Built-in
  9898. +     Variables::.).
  9899. +
  9900. +   * The `IGNORECASE' variable and its effects (*note Case-sensitivity
  9901. +     in Matching: Case-sensitivity.).
  9902. +
  9903. +   * The `FIELDWIDTHS' variable and its effects (*note Reading
  9904. +     Fixed-width Data: Constant Size.).
  9905. +
  9906. +   * The `next file' statement for skipping to the next data file
  9907. +     (*note The `next file' Statement: Next File Statement.).
  9908. +
  9909. +   * The `systime' and `strftime' built-in functions for obtaining and
  9910. +     printing time stamps (*note Functions for Dealing with Time
  9911. +     Stamps: Time Functions.).
  9912. +
  9913. +   * The `/dev/stdin', `/dev/stdout', `/dev/stderr', and `/dev/fd/N'
  9914. +     file name interpretation (*note Standard I/O Streams: Special
  9915. +     Files.).
  9916. +
  9917. +   * The `-W compat' option to turn off these extensions (*note
  9918. +     Invoking `awk': Command Line.).
  9919. +
  9920. +   * The `-W posix' option for full POSIX compliance (*note Invoking
  9921. +     `awk': Command Line.).
  9922. +
  9923. +
  9924. +File: gawk.info,  Node: Installation,  Next: Gawk Summary,  Prev: Language History,  Up: Top
  9925. +
  9926. +Installing `gawk'
  9927. +*****************
  9928. +
  9929. +   This chapter provides instructions for installing `gawk' on the
  9930. +various platforms that are supported by the developers.  The primary
  9931. +developers support Unix (and one day, GNU), while the other ports were
  9932. +contributed.  The file `ACKNOWLEDGMENT' in the `gawk' distribution
  9933. +lists the electronic mail addresses of the people who did the
  9934. +respective ports.
  9935. +
  9936. +* Menu:
  9937. +
  9938. +* Gawk Distribution::           What is in the `gawk' distribution.
  9939. +* Unix Installation::           Installing `gawk' under various versions
  9940. +                                of Unix.
  9941. +* VMS Installation::            Installing `gawk' on VMS.
  9942. +* MS-DOS Installation::         Installing `gawk' on MS-DOS.
  9943. +* Atari Installation::          Installing `gawk' on the Atari ST.
  9944. +
  9945. +
  9946. +File: gawk.info,  Node: Gawk Distribution,  Next: Unix Installation,  Prev: Installation,  Up: Installation
  9947. +
  9948. +The `gawk' Distribution
  9949. +=======================
  9950. +
  9951. +   This section first describes how to get and extract the `gawk'
  9952. +distribution, and then discusses what is in the various files and
  9953. +subdirectories.
  9954. +
  9955. +* Menu:
  9956. +
  9957. +* Extracting::                  How to get and extract the distribution.
  9958. +* Distribution contents::       What is in the distribution.
  9959. +
  9960. +
  9961. +File: gawk.info,  Node: Extracting,  Next: Distribution contents,  Prev: Gawk Distribution,  Up: Gawk Distribution
  9962. +
  9963. +Getting the `gawk' Distribution
  9964. +-------------------------------
  9965. +
  9966. +   `gawk' is distributed as a `tar' file compressed with the GNU Zip
  9967. +program, `gzip'.  You can get it via anonymous `ftp' to the Internet
  9968. +host `prep.ai.mit.edu'.  Like all GNU software, it will be archived at
  9969. +other well known systems, from which it will be possible to use some
  9970. +sort of anonymous `uucp' to obtain the distribution as well.  You can
  9971. +also order `gawk' on tape or CD-ROM directly from the Free Software
  9972. +Foundation.  (The address is on the copyright page.) Doing so directly
  9973. +contributes to the support of the foundation and to the production of
  9974. +more free software.
  9975. +
  9976. +   Once you have the distribution (for example, `gawk-2.15.0.tar.z'),
  9977. +first use `gzip' to expand the file, and then use `tar' to extract it.
  9978. +You can use the following pipeline to produce the `gawk' distribution:
  9979. +
  9980. +     # Under System V, add 'o' to the tar flags
  9981. +     gzip -d -c gawk-2.15.0.tar.z | tar -xvpf -
  9982. +
  9983. +This will create a directory named `gawk-2.15' in the current directory.
  9984. +
  9985. +   The distribution file name is of the form `gawk-2.15.N.tar.Z'.  The
  9986. +N represents a "patchlevel", meaning that minor bugs have been fixed in
  9987. +the major release.  The current patchlevel is 0, but when retrieving
  9988. +distributions, you should get the version with the highest patchlevel.
  9989. +
  9990. +   If you are not on a Unix system, you will need to make other
  9991. +arrangements for getting and extracting the `gawk' distribution.  You
  9992. +should consult a local expert.
  9993. +
  9994. +
  9995. +File: gawk.info,  Node: Distribution contents,  Prev: Extracting,  Up: Gawk Distribution
  9996. +
  9997. +Contents of the `gawk' Distribution
  9998. +-----------------------------------
  9999. +
  10000. +   `gawk' has a number of C source files, documentation files,
  10001. +subdirectories and files related to the configuration process (*note
  10002. +Compiling and Installing `gawk' on Unix: Unix Installation.), and
  10003. +several subdirectories related to different, non-Unix, operating
  10004. +systems.
  10005. +
  10006. +various `.c', `.y', and `.h' files
  10007. +     The C and YACC source files are the actual `gawk' source code.
  10008. +
  10009. +`README'
  10010. +`README.VMS'
  10011. +`README.dos'
  10012. +`README.rs6000'
  10013. +`README.ultrix'
  10014. +     Descriptive files: `README' for `gawk' under Unix, and the rest
  10015. +     for the various hardware and software combinations.
  10016. +
  10017. +`PORTS'
  10018. +     A list of systems to which `gawk' has been ported, and which have
  10019. +     successfully run the test suite.
  10020. +
  10021. +`ACKNOWLEDGMENT'
  10022. +     A list of the people who contributed major parts of the code or
  10023. +     documentation.
  10024. +
  10025. +`NEWS'
  10026. +     A list of changes to `gawk' since the last release or patch.
  10027. +
  10028. +`COPYING'
  10029. +     The GNU General Public License.
  10030. +
  10031. +`FUTURES'
  10032. +     A brief list of features and/or changes being contemplated for
  10033. +     future releases, with some indication of the time frame for the
  10034. +     feature, based on its difficulty.
  10035. +
  10036. +`LIMITATIONS'
  10037. +     A list of those factors that limit `gawk''s performance.  Most of
  10038. +     these depend on the hardware or operating system software, and are
  10039. +     not limits in `gawk' itself.
  10040. +
  10041. +`PROBLEMS'
  10042. +     A file describing known problems with the current release.
  10043. +
  10044. +`gawk.1'
  10045. +     The `troff' source for a manual page describing `gawk'.
  10046. +
  10047. +`gawk.texinfo'
  10048. +     The `texinfo' source file for this Info file.  It should be
  10049. +     processed with TeX to produce a printed manual, and with
  10050. +     `makeinfo' to produce the Info file.
  10051. +
  10052. +`Makefile.in'
  10053. +`config'
  10054. +`config.in'
  10055. +`configure'
  10056. +`missing'
  10057. +`mungeconf'
  10058. +     These files and subdirectories are used when configuring `gawk'
  10059. +     for various Unix systems.  They are explained in detail in *Note
  10060. +     Compiling and Installing `gawk' on Unix: Unix Installation.
  10061. +
  10062. +`atari'
  10063. +     Files needed for building `gawk' on an Atari ST.  *Note Installing
  10064. +     `gawk' on the Atari ST: Atari Installation, for details.
  10065. +
  10066. +`pc'
  10067. +     Files needed for building `gawk' under MS-DOS.  *Note Installing
  10068. +     `gawk' on MS-DOS: MS-DOS Installation, for details.
  10069. +
  10070. +`vms'
  10071. +     Files needed for building `gawk' under VMS.  *Note Compiling
  10072. +     Installing and Running `gawk' on VMS: VMS Installation, for
  10073. +     details.
  10074. +
  10075. +`test'
  10076. +     Many interesting `awk' programs, provided as a test suite for
  10077. +     `gawk'.  You can use `make test' from the top level `gawk'
  10078. +     directory to run your version of `gawk' against the test suite.
  10079. +     If `gawk' successfully passes `make test' then you can be
  10080. +     confident of a successful port.
  10081. +
  10082. +
  10083. +File: gawk.info,  Node: Unix Installation,  Next: VMS Installation,  Prev: Gawk Distribution,  Up: Installation
  10084. +
  10085. +Compiling and Installing `gawk' on Unix
  10086. +=======================================
  10087. +
  10088. +   Often, you can compile and install `gawk' by typing only two
  10089. +commands.  However, if you do not use a supported system, you may need
  10090. +to configure `gawk' for your system yourself.
  10091. +
  10092. +* Menu:
  10093. +
  10094. +* Quick Installation::          Compiling `gawk' on a
  10095. +                                supported Unix version.
  10096. +* Configuration Philosophy::    How it's all supposed to work.
  10097. +* New Configurations::          What to do if there is no supplied
  10098. +                                configuration for your system.
  10099. +
  10100. +
  10101. +File: gawk.info,  Node: Quick Installation,  Next: Configuration Philosophy,  Prev: Unix Installation,  Up: Unix Installation
  10102. +
  10103. +Compiling `gawk' for a Supported Unix Version
  10104. +---------------------------------------------
  10105. +
  10106. +   After you have extracted the `gawk' distribution, `cd' to
  10107. +`gawk-2.15'.  Look in the `config' subdirectory for a file that matches
  10108. +your hardware/software combination.  In general, only the software is
  10109. +relevant; for example `sunos41' is used for SunOS 4.1, on both Sun 3
  10110. +and Sun 4 hardware.
  10111. +
  10112. +   If you find such a file, run the command:
  10113. +
  10114. +     # assume you have SunOS 4.1
  10115. +     ./configure sunos41
  10116. +
  10117. +   This produces a `Makefile' and `config.h' tailored to your system.
  10118. +You may wish to edit the `Makefile' to use a different C compiler, such
  10119. +as `gcc', the GNU C compiler, if you have it.  You may also wish to
  10120. +change the `CFLAGS' variable, which controls the command line options
  10121. +that are passed to the C compiler (such as optimization levels, or
  10122. +compiling for debugging).
  10123. +
  10124. +   After you have configured `Makefile' and `config.h', type:
  10125. +
  10126. +     make
  10127. +
  10128. +and shortly thereafter, you should have an executable version of `gawk'.
  10129. +That's all there is to it!
  10130. +
  10131. +
  10132. +File: gawk.info,  Node: Configuration Philosophy,  Next: New Configurations,  Prev: Quick Installation,  Up: Unix Installation
  10133. +
  10134. +The Configuration Process
  10135. +-------------------------
  10136. +
  10137. +   (This section is of interest only if you know something about using
  10138. +the C language and the Unix operating system.)
  10139. +
  10140. +   The source code for `gawk' generally attempts to adhere to industry
  10141. +standards wherever possible.  This means that `gawk' uses library
  10142. +routines that are specified by the ANSI C standard and by the POSIX
  10143. +operating system interface standard.  When using an ANSI C compiler,
  10144. +function prototypes are provided to help improve the compile-time
  10145. +checking.
  10146. +
  10147. +   Many older Unix systems do not support all of either the ANSI or the
  10148. +POSIX standards.  The `missing' subdirectory in the `gawk' distribution
  10149. +contains replacement versions of those subroutines that are most likely
  10150. +to be missing.
  10151. +
  10152. +   The `config.h' file that is created by the `configure' program
  10153. +contains definitions that describe features of the particular operating
  10154. +system where you are attempting to compile `gawk'.  For the most part,
  10155. +it lists which standard subroutines are *not* available.  For example,
  10156. +if your system lacks the `getopt' routine, then `GETOPT_MISSING' would
  10157. +be defined.
  10158. +
  10159. +   `config.h' also defines constants that describe facts about your
  10160. +variant of Unix.  For example, there may not be an `st_blksize' element
  10161. +in the `stat' structure.  In this case `BLKSIZE_MISSING' would be
  10162. +defined.
  10163. +
  10164. +   Based on the list in `config.h' of standard subroutines that are
  10165. +missing, `missing.c' will do a `#include' of the appropriate file(s)
  10166. +from the `missing' subdirectory.
  10167. +
  10168. +   Conditionally compiled code in the other source files relies on the
  10169. +other definitions in the `config.h' file.
  10170. +
  10171. +   Besides creating `config.h', `configure' produces a `Makefile' from
  10172. +`Makefile.in'.  There are a number of lines in `Makefile.in' that are
  10173. +system or feature specific.  For example, there is line that begins
  10174. +with `##MAKE_ALLOCA_C##'.  This is normally a comment line, since it
  10175. +starts with `#'.  If a configuration file has `MAKE_ALLOCA_C' in it,
  10176. +then `configure' will delete the `##MAKE_ALLOCA_C##' from the beginning
  10177. +of the line.  This will enable the rules in the `Makefile' that use a C
  10178. +version of `alloca'.  There are several similar features that work in
  10179. +this fashion.
  10180. +
  10181. +
  10182. +File: gawk.info,  Node: New Configurations,  Prev: Configuration Philosophy,  Up: Unix Installation
  10183. +
  10184. +Configuring `gawk' for a New System
  10185. +-----------------------------------
  10186. +
  10187. +   (This section is of interest only if you know something about using
  10188. +the C language and the Unix operating system, and if you have to install
  10189. +`gawk' on a system that is not supported by the `gawk' distribution.
  10190. +If you are a C or Unix novice, get help from a local expert.)
  10191. +
  10192. +   If you need to configure `gawk' for a Unix system that is not
  10193. +supported in the distribution, first see *Note The Configuration
  10194. +Process: Configuration Philosophy.  Then, copy `config.in' to
  10195. +`config.h', and copy `Makefile.in' to `Makefile'.
  10196. +
  10197. +   Next, edit both files.  Both files are liberally commented, and the
  10198. +necessary changes should be straightforward.
  10199. +
  10200. +   While editing `config.h', you need to determine what library
  10201. +routines you do or do not have by consulting your system documentation,
  10202. +or by perusing your actual libraries using the `ar' or `nm' utilities.
  10203. +In the worst case, simply do not define *any* of the macros for missing
  10204. +subroutines.  When you compile `gawk', the final link-editing step will
  10205. +fail.  The link editor will provide you with a list of unresolved
  10206. +external references--these are the missing subroutines.  Edit
  10207. +`config.h' again and recompile, and you should be set.
  10208. +
  10209. +   Editing the `Makefile' should also be straightforward.  Enable or
  10210. +disable the lines that begin with `##MAKE_WHATEVER##', as appropriate.
  10211. +Select the correct C compiler and `CFLAGS' for it.  Then run `make'.
  10212. +
  10213. +   Getting a correct configuration is likely to be an iterative process.
  10214. +Do not be discouraged if it takes you several tries.  If you have no
  10215. +luck whatsoever, please report your system type, and the steps you took.
  10216. +Once you do have a working configuration, please send it to the
  10217. +maintainers so that support for your system can be added to the
  10218. +official release.
  10219. +
  10220. +   *Note Reporting Problems and Bugs: Bugs, for information on how to
  10221. +report problems in configuring `gawk'.  You may also use the same
  10222. +mechanisms for sending in new configurations.
  10223. +
  10224. +
  10225. +File: gawk.info,  Node: VMS Installation,  Next: MS-DOS Installation,  Prev: Unix Installation,  Up: Installation
  10226. +
  10227. +Compiling, Installing, and Running `gawk' on VMS
  10228. +================================================
  10229. +
  10230. +   This section describes how to compile and install `gawk' under VMS.
  10231. +
  10232. +* Menu:
  10233. +
  10234. +* VMS Compilation::             How to compile `gawk' under VMS.
  10235. +* VMS Installation Details::    How to install `gawk' under VMS.
  10236. +* VMS Running::                 How to run `gawk' under VMS.
  10237. +* VMS POSIX::                   Alternate instructions for VMS POSIX.
  10238. +
  10239. +
  10240. +File: gawk.info,  Node: VMS Compilation,  Next: VMS Installation Details,  Prev: VMS Installation,  Up: VMS Installation
  10241. +
  10242. +Compiling `gawk' under VMS
  10243. +--------------------------
  10244. +
  10245. +   To compile `gawk' under VMS, there is a `DCL' command procedure that
  10246. +will issue all the necessary `CC' and `LINK' commands, and there is
  10247. +also a `Makefile' for use with the `MMS' utility.  From the source
  10248. +directory, use either
  10249. +
  10250. +     $ @[.VMS]VMSBUILD.COM
  10251. +
  10252. +or
  10253. +
  10254. +     $ MMS/DESCRIPTION=[.VMS]DECSRIP.MMS GAWK
  10255. +
  10256. +   Depending upon which C compiler you are using, follow one of the sets
  10257. +of instructions in this table:
  10258. +
  10259. +VAX C V3.x
  10260. +     Use either `vmsbuild.com' or `descrip.mms' as is.  These use
  10261. +     `CC/OPTIMIZE=NOLINE', which is essential for Version 3.0.
  10262. +
  10263. +VAX C V2.x
  10264. +     You must have Version 2.3 or 2.4; older ones won't work.  Edit
  10265. +     either `vmsbuild.com' or `descrip.mms' according to the comments
  10266. +     in them.  For `vmsbuild.com', this just entails removing two `!'
  10267. +     delimiters.  Also edit `config.h' (which is a copy of file
  10268. +     `[.config]vms-conf.h') and comment out or delete the two lines
  10269. +     `#define __STDC__ 0' and `#define VAXC_BUILTINS' near the end.
  10270. +
  10271. +GNU C
  10272. +     Edit `vmsbuild.com' or `descrip.mms'; the changes are different
  10273. +     from those for VAX C V2.x, but equally straightforward.  No
  10274. +     changes to `config.h' should be needed.
  10275. +
  10276. +DEC C
  10277. +     Edit `vmsbuild.com' or `descrip.mms' according to their comments.
  10278. +     No changes to `config.h' should be needed.
  10279. +
  10280. +   `gawk' 2.15 has been tested under VAX/VMS 5.5-1 using VAX C V3.2,
  10281. +GNU C 1.40 and 2.3.  It should work without modifications for VMS V4.6
  10282. +and up.
  10283. +
  10284. +
  10285. +File: gawk.info,  Node: VMS Installation Details,  Next: VMS Running,  Prev: VMS Compilation,  Up: VMS Installation
  10286. +
  10287. +Installing `gawk' on VMS
  10288. +------------------------
  10289. +
  10290. +   To install `gawk', all you need is a "foreign" command, which is a
  10291. +`DCL' symbol whose value begins with a dollar sign.
  10292. +
  10293. +     $ GAWK :== $device:[directory]GAWK
  10294. +
  10295. +(Substitute the actual location of `gawk.exe' for
  10296. +`device:[directory]'.) The symbol should be placed in the `login.com'
  10297. +of any user who wishes to run `gawk', so that it will be defined every
  10298. +time the user logs on.  Alternatively, the symbol may be placed in the
  10299. +system-wide `sylogin.com' procedure, which will allow all users to run
  10300. +`gawk'.
  10301. +
  10302. +   Optionally, the help entry can be loaded into a VMS help library:
  10303. +
  10304. +     $ LIBRARY/HELP SYS$HELP:HELPLIB [.VMS]GAWK.HLP
  10305. +
  10306. +(You may want to substitute a site-specific help library rather than
  10307. +the standard VMS library `HELPLIB'.)  After loading the help text,
  10308. +
  10309. +     $ HELP GAWK
  10310. +
  10311. +will provide information about both the `gawk' implementation and the
  10312. +`awk' programming language.
  10313. +
  10314. +   The logical name `AWK_LIBRARY' can designate a default location for
  10315. +`awk' program files.  For the `-f' option, if the specified filename
  10316. +has no device or directory path information in it, `gawk' will look in
  10317. +the current directory first, then in the directory specified by the
  10318. +translation of `AWK_LIBRARY' if the file was not found.  If after
  10319. +searching in both directories, the file still is not found, then `gawk'
  10320. +appends the suffix `.awk' to the filename and the file search will be
  10321. +re-tried.  If `AWK_LIBRARY' is not defined, that portion of the file
  10322. +search will fail benignly.
  10323. +
  10324. +
  10325. +File: gawk.info,  Node: VMS Running,  Next: VMS POSIX,  Prev: VMS Installation Details,  Up: VMS Installation
  10326. +
  10327. +Running `gawk' on VMS
  10328. +---------------------
  10329. +
  10330. +   Command line parsing and quoting conventions are significantly
  10331. +different on VMS, so examples in this manual or from other sources
  10332. +often need minor changes.  They *are* minor though, and all `awk'
  10333. +programs should run correctly.
  10334. +
  10335. +   Here are a couple of trivial tests:
  10336. +
  10337. +     $ gawk -- "BEGIN {print ""Hello, World!""}"
  10338. +     $ gawk -"W" version     ! could also be -"W version" or "-W version"
  10339. +
  10340. +Note that upper-case and mixed-case text must be quoted.
  10341. +
  10342. +   The VMS port of `gawk' includes a `DCL'-style interface in addition
  10343. +to the original shell-style interface (see the help entry for details).
  10344. +One side-effect of dual command line parsing is that if there is only a
  10345. +single parameter (as in the quoted string program above), the command
  10346. +becomes ambiguous.  To work around this, the normally optional `--'
  10347. +flag is required to force Unix style rather than `DCL' parsing.  If any
  10348. +other dash-type options (or multiple parameters such as data files to be
  10349. +processed) are present, there is no ambiguity and `--' can be omitted.
  10350. +
  10351. +   The default search path when looking for `awk' program files
  10352. +specified by the `-f' option is `"SYS$DISK:[],AWK_LIBRARY:"'.  The
  10353. +logical name `AWKPATH' can be used to override this default.  The format
  10354. +of `AWKPATH' is a comma-separated list of directory specifications.
  10355. +When defining it, the value should be quoted so that it retains a single
  10356. +translation, and not a multi-translation `RMS' searchlist.
  10357. +
  10358. +
  10359. +File: gawk.info,  Node: VMS POSIX,  Prev: VMS Running,  Up: VMS Installation
  10360. +
  10361. +Building and using `gawk' under VMS POSIX
  10362. +-----------------------------------------
  10363. +
  10364. +   Ignore the instructions above, although `vms/gawk.hlp' should still
  10365. +be made available in a help library.  Make sure that the two scripts,
  10366. +`configure' and `mungeconf', are executable; use `chmod +x' on them if
  10367. +necessary.  Then execute the following commands:
  10368. +
  10369. +     $ POSIX
  10370. +     psx> configure vms-posix
  10371. +     psx> make awktab.c gawk
  10372. +
  10373. +The first command will construct files `config.h' and `Makefile' out of
  10374. +templates.  The second command will compile and link `gawk'.  Due to a
  10375. +`make' bug in VMS POSIX V1.0 and V1.1, the file `awktab.c' must be
  10376. +given as an explicit target or it will not be built and the final link
  10377. +step will fail.  Ignore the warning `"Could not find lib m in lib
  10378. +list"'; it is harmless, caused by the explicit use of `-lm' as a linker
  10379. +option which is not needed under VMS POSIX.  Under V1.1 (but not V1.0)
  10380. +a problem with the `yacc' skeleton `/etc/yyparse.c' will cause a
  10381. +compiler warning for `awktab.c', followed by a linker warning about
  10382. +compilation warnings in the resulting object module.  These warnings
  10383. +can be ignored.
  10384. +
  10385. +   Once built, `gawk' will work like any other shell utility.  Unlike
  10386. +the normal VMS port of `gawk', no special command line manipulation is
  10387. +needed in the VMS POSIX environment.
  10388. +
  10389. +
  10390. +File: gawk.info,  Node: MS-DOS Installation,  Next: Atari Installation,  Prev: VMS Installation,  Up: Installation
  10391. +
  10392. +Installing `gawk' on MS-DOS
  10393. +===========================
  10394. +
  10395. +   The first step is to get all the files in the `gawk' distribution
  10396. +onto your PC.  Move all the files from the `pc' directory into the main
  10397. +directory where the other files are.  Edit the file `make.bat' so that
  10398. +it will be an acceptable MS-DOS batch file.  This means making sure
  10399. +that all lines are terminated with the ASCII carriage return and line
  10400. +feed characters.  restrictions.
  10401. +
  10402. +   `gawk' has only been compiled with version 5.1 of the Microsoft C
  10403. +compiler.  The file `make.bat' from the `pc' directory assumes that you
  10404. +have this compiler.
  10405. +
  10406. +   Copy the file `setargv.obj' from the library directory where it
  10407. +resides to the `gawk' source code directory.
  10408. +
  10409. +   Run `make.bat'.  This will compile `gawk' for you, and link it.
  10410. +That's all there is to it!
  10411. +
  10412. +
  10413. +File: gawk.info,  Node: Atari Installation,  Prev: MS-DOS Installation,  Up: Installation
  10414. +
  10415. +Installing `gawk' on the Atari ST
  10416. +=================================
  10417. +
  10418. +   This section assumes that you are running TOS.  It applies to other
  10419. +Atari models (STe, TT) as well.
  10420. +
  10421. +   In order to use `gawk', you need to have a shell, either text or
  10422. +graphics, that does not map all the characters of a command line to
  10423. +upper case.  Maintaining case distinction in option flags is very
  10424. +important (*note Invoking `awk': Command Line.).  Popular shells like
  10425. +`gulam' or `gemini' will work, as will newer versions of `desktop'.
  10426. +Support for I/O redirection is necessary to make it easy to import
  10427. +`awk' programs from other environments.  Pipes are nice to have, but
  10428. +not vital.
  10429. +
  10430. +   If you have received an executable version of `gawk', place it, as
  10431. +usual, anywhere in your `PATH' where your shell will find it.
  10432. +
  10433. +   While executing, `gawk' creates a number of temporary files.  `gawk'
  10434. +looks for either of the environment variables `TEMP' or `TMPDIR', in
  10435. +that order.  If either one is found, its value is assumed to be a
  10436. +directory for temporary files.  This directory must exist, and if you
  10437. +can spare the memory, it is a good idea to put it on a RAM drive.  If
  10438. +neither `TEMP' nor `TMPDIR' are found, then `gawk' uses the current
  10439. +directory for its temporary files.
  10440. +
  10441. +   The ST version of `gawk' searches for its program files as described
  10442. +in *Note The `AWKPATH' Environment Variable: AWKPATH Variable.  On the
  10443. +ST, the default value for the `AWKPATH' variable is
  10444. +`".,c:\lib\awk,c:\gnu\lib\awk"'.  The search path can be modified by
  10445. +explicitly setting `AWKPATH' to whatever you wish.  Note that colons
  10446. +cannot be used on the ST to separate elements in the `AWKPATH'
  10447. +variable, since they have another, reserved, meaning.  Instead, you
  10448. +must use a comma to separate elements in the path.  If you are
  10449. +recompiling `gawk' on the ST, then you can choose a new default search
  10450. +path, by setting the value of `DEFPATH' in the file `...\config\atari'.
  10451. +You may choose a different separator character by setting the value of
  10452. +`ENVSEP' in the same file.  The new values will be used when creating
  10453. +the header file `config.h'.
  10454. +
  10455. +   Although `awk' allows great flexibility in doing I/O redirections
  10456. +from within a program, this facility should be used with care on the ST.
  10457. +In some circumstances the OS routines for file handle pool processing
  10458. +lose track of certain events, causing the computer to crash, and
  10459. +requiring a reboot.  Often a warm reboot is sufficient.  Fortunately,
  10460. +this happens infrequently, and in rather esoteric situations.  In
  10461. +particular, avoid having one part of an `awk' program using `print'
  10462. +statements explicitly redirected to `"/dev/stdout"', while other
  10463. +`print' statements use the default standard output, and a calling shell
  10464. +has redirected standard output to a file.
  10465. +
  10466. +   When `gawk' is compiled with the ST version of `gcc' and its usual
  10467. +libraries, it will accept both `/' and `\' as path separators.  While
  10468. +this is convenient, it should be remembered that this removes one,
  10469. +technically legal, character (`/') from your file names, and that it
  10470. +may create problems for external programs, called via the `system()'
  10471. +function, which may not support this convention.  Whenever it is
  10472. +possible that a file created by `gawk' will be used by some other
  10473. +program, use only backslashes.  Also remember that in `awk',
  10474. +backslashes in strings have to be doubled in order to get literal
  10475. +backslashes.
  10476. +
  10477. +   The initial port of `gawk' to the ST was done with `gcc'.  If you
  10478. +wish to recompile `gawk' from scratch, you will need to use a compiler
  10479. +that accepts ANSI standard C (such as `gcc', Turbo C, or Prospero C).
  10480. +If `sizeof(int) != sizeof(int *)', the correctness of the generated
  10481. +code depends heavily on the fact that all function calls have function
  10482. +prototypes in the current scope.  If your compiler does not accept
  10483. +function prototypes, you will probably have to add a number of casts to
  10484. +the code.
  10485. +
  10486. +   If you are using `gcc', make sure that you have up-to-date libraries.
  10487. +Older versions have problems with some library functions (`atan2()',
  10488. +`strftime()', the `%g' conversion in `sprintf()') which may affect the
  10489. +operation of `gawk'.
  10490. +
  10491. +   In the `atari' subdirectory of the `gawk' distribution is a version
  10492. +of the `system()' function that has been tested with `gulam' and `msh';
  10493. +it should work with other shells as well.  With `gulam', it passes the
  10494. +string to be executed without spawning an extra copy of a shell.  It is
  10495. +possible to replace this version of `system()' with a similar function
  10496. +from a library or from some other source if that version would be a
  10497. +better choice for the shell you prefer.
  10498. +
  10499. +   The files needed to recompile `gawk' on the ST can be found in the
  10500. +`atari' directory.  The provided files and instructions below assume
  10501. +that you have the GNU C compiler (`gcc'), the `gulam' shell, and an ST
  10502. +version of `sed'. The `Makefile' is set up to use `byacc' as a `yacc'
  10503. +replacement.  With a different set of tools some adjustments and/or
  10504. +editing will be needed.
  10505. +
  10506. +   `cd' to the `atari' directory.  Copy `Makefile.st' to `makefile' in
  10507. +the source (parent) directory.  Possibly adjust `../config/atari' to
  10508. +suit your system.  Execute the script `mkconf.g' which will create the
  10509. +header file `../config.h'.  Go back to the source directory.  If you
  10510. +are not using `gcc', check the file `missing.c'.  It may be necessary
  10511. +to change forward slashes in the references to files from the `atari'
  10512. +subdirectory into backslashes.  Type `make' and enjoy.
  10513. +
  10514. +   Compilation with `gcc' of some of the bigger modules, like
  10515. +`awk_tab.c', may require a full four megabytes of memory.  On smaller
  10516. +machines you would need to cut down on optimizations, or you would have
  10517. +to switch to another, less memory hungry, compiler.
  10518. +
  10519. +
  10520. +File: gawk.info,  Node: Gawk Summary,  Next: Sample Program,  Prev: Installation,  Up: Top
  10521. +
  10522. +`gawk' Summary
  10523. +**************
  10524. +
  10525. +   This appendix provides a brief summary of the `gawk' command line
  10526. +and the `awk' language.  It is designed to serve as "quick reference."
  10527. +It is therefore terse, but complete.
  10528. +
  10529. +* Menu:
  10530. +
  10531. +* Command Line Summary::        Recapitulation of the command line.
  10532. +* Language Summary::            A terse review of the language.
  10533. +* Variables/Fields::            Variables, fields, and arrays.
  10534. +* Rules Summary::               Patterns and Actions, and their
  10535. +                                component parts.
  10536. +* Functions Summary::           Defining and calling functions.
  10537. +* Historical Features::         Some undocumented but supported "features".
  10538. +
  10539. +
  10540. +File: gawk.info,  Node: Command Line Summary,  Next: Language Summary,  Prev: Gawk Summary,  Up: Gawk Summary
  10541. +
  10542. +Command Line Options Summary
  10543. +============================
  10544. +
  10545. +   The command line consists of options to `gawk' itself, the `awk'
  10546. +program text (if not supplied via the `-f' option), and values to be
  10547. +made available in the `ARGC' and `ARGV' predefined `awk' variables:
  10548. +
  10549. +     awk [POSIX OR GNU STYLE OPTIONS] -f source-file [`--'] FILE ...
  10550. +     awk [POSIX OR GNU STYLE OPTIONS] [`--'] 'PROGRAM' FILE ...
  10551. +
  10552. +   The options that `gawk' accepts are:
  10553. +
  10554. +`-F FS'
  10555. +`--field-separator=FS'
  10556. +     Use FS for the input field separator (the value of the `FS'
  10557. +     predefined variable).
  10558. +
  10559. +`-f PROGRAM-FILE'
  10560. +`--file=PROGRAM-FILE'
  10561. +     Read the `awk' program source from the file PROGRAM-FILE, instead
  10562. +     of from the first command line argument.
  10563. +
  10564. +`-v VAR=VAL'
  10565. +`--assign=VAR=VAL'
  10566. +     Assign the variable VAR the value VAL before program execution
  10567. +     begins.
  10568. +
  10569. +`-W compat'
  10570. +`--compat'
  10571. +     Specifies compatibility mode, in which `gawk' extensions are turned
  10572. +     off.
  10573. +
  10574. +`-W copyleft'
  10575. +`-W copyright'
  10576. +`--copyleft'
  10577. +`--copyright'
  10578. +     Print the short version of the General Public License on the error
  10579. +     output.  This option may disappear in a future version of `gawk'.
  10580. +
  10581. +`-W help'
  10582. +`-W usage'
  10583. +`--help'
  10584. +`--usage'
  10585. +     Print a relatively short summary of the available options on the
  10586. +     error output.
  10587. +
  10588. +`-W lint'
  10589. +`--lint'
  10590. +     Give warnings about dubious or non-portable `awk' constructs.
  10591. +
  10592. +`-W posix'
  10593. +`--posix'
  10594. +     Specifies POSIX compatibility mode, in which `gawk' extensions are
  10595. +     turned off and additional restrictions apply.
  10596. +
  10597. +`-W source=PROGRAM-TEXT'
  10598. +`--source=PROGRAM-TEXT'
  10599. +     Use PROGRAM-TEXT as `awk' program source code.  This option allows
  10600. +     mixing command line source code with source code from files, and is
  10601. +     particularly useful for mixing command line programs with library
  10602. +     functions.
  10603. +
  10604. +`-W version'
  10605. +`--version'
  10606. +     Print version information for this particular copy of `gawk' on
  10607. +     the error output.  This option may disappear in a future version
  10608. +     of `gawk'.
  10609. +
  10610. +`--'
  10611. +     Signal the end of options.  This is useful to allow further
  10612. +     arguments to the `awk' program itself to start with a `-'.  This
  10613. +     is mainly for consistency with the argument parsing conventions of
  10614. +     POSIX.
  10615. +
  10616. +   Any other options are flagged as invalid, but are otherwise ignored.
  10617. +*Note Invoking `awk': Command Line, for more details.
  10618. +
  10619. +
  10620. +File: gawk.info,  Node: Language Summary,  Next: Variables/Fields,  Prev: Command Line Summary,  Up: Gawk Summary
  10621. +
  10622. +Language Summary
  10623. +================
  10624. +
  10625. +   An `awk' program consists of a sequence of pattern-action statements
  10626. +and optional function definitions.
  10627. +
  10628. +     PATTERN    { ACTION STATEMENTS }
  10629. +     
  10630. +     function NAME(PARAMETER LIST)     { ACTION STATEMENTS }
  10631. +
  10632. +   `gawk' first reads the program source from the PROGRAM-FILE(s) if
  10633. +specified, or from the first non-option argument on the command line.
  10634. +The `-f' option may be used multiple times on the command line.  `gawk'
  10635. +reads the program text from all the PROGRAM-FILE files, effectively
  10636. +concatenating them in the order they are specified.  This is useful for
  10637. +building libraries of `awk' functions, without having to include them
  10638. +in each new `awk' program that uses them.  To use a library function in
  10639. +a file from a program typed in on the command line, specify `-f
  10640. +/dev/tty'; then type your program, and end it with a `Control-d'.
  10641. +*Note Invoking `awk': Command Line.
  10642. +
  10643. +   The environment variable `AWKPATH' specifies a search path to use
  10644. +when finding source files named with the `-f' option.  The default
  10645. +path, which is `.:/local/lib/awk:/gnu/lib/awk' is used if `AWKPATH' is
  10646. +not set.  If a file name given to the `-f' option contains a `/'
  10647. +character, no path search is performed.  *Note The `AWKPATH'
  10648. +Environment Variable: AWKPATH Variable, for a full description of the
  10649. +`AWKPATH' environment variable.
  10650. +
  10651. +   `gawk' compiles the program into an internal form, and then proceeds
  10652. +to read each file named in the `ARGV' array.  If there are no files
  10653. +named on the command line, `gawk' reads the standard input.
  10654. +
  10655. +   If a "file" named on the command line has the form `VAR=VAL', it is
  10656. +treated as a variable assignment: the variable VAR is assigned the
  10657. +value VAL.  If any of the files have a value that is the null string,
  10658. +that element in the list is skipped.
  10659. +
  10660. +   For each line in the input, `gawk' tests to see if it matches any
  10661. +PATTERN in the `awk' program.  For each pattern that the line matches,
  10662. +the associated ACTION is executed.
  10663. +
  10664. +
  10665. +File: gawk.info,  Node: Variables/Fields,  Next: Rules Summary,  Prev: Language Summary,  Up: Gawk Summary
  10666. +
  10667. +Variables and Fields
  10668. +====================
  10669. +
  10670. +   `awk' variables are dynamic; they come into existence when they are
  10671. +first used.  Their values are either floating-point numbers or strings.
  10672. +`awk' also has one-dimension arrays; multiple-dimensional arrays may be
  10673. +simulated.  There are several predefined variables that `awk' sets as a
  10674. +program runs; these are summarized below.
  10675. +
  10676. +* Menu:
  10677. +
  10678. +* Fields Summary::              Input field splitting.
  10679. +* Built-in Summary::            `awk''s built-in variables.
  10680. +* Arrays Summary::              Using arrays.
  10681. +* Data Type Summary::           Values in `awk' are numbers or strings.
  10682. +
  10683. +
  10684. +File: gawk.info,  Node: Fields Summary,  Next: Built-in Summary,  Prev: Variables/Fields,  Up: Variables/Fields
  10685. +
  10686. +Fields
  10687. +------
  10688. +
  10689. +   As each input line is read, `gawk' splits the line into FIELDS,
  10690. +using the value of the `FS' variable as the field separator.  If `FS'
  10691. +is a single character, fields are separated by that character.
  10692. +Otherwise, `FS' is expected to be a full regular expression.  In the
  10693. +special case that `FS' is a single blank, fields are separated by runs
  10694. +of blanks and/or tabs.  Note that the value of `IGNORECASE' (*note
  10695. +Case-sensitivity in Matching: Case-sensitivity.) also affects how
  10696. +fields are split when `FS' is a regular expression.
  10697. +
  10698. +   Each field in the input line may be referenced by its position, `$1',
  10699. +`$2', and so on.  `$0' is the whole line.  The value of a field may be
  10700. +assigned to as well.  Field numbers need not be constants:
  10701. +
  10702. +     n = 5
  10703. +     print $n
  10704. +
  10705. +prints the fifth field in the input line.  The variable `NF' is set to
  10706. +the total number of fields in the input line.
  10707. +
  10708. +   References to nonexistent fields (i.e., fields after `$NF') return
  10709. +the null-string.  However, assigning to a nonexistent field (e.g.,
  10710. +`$(NF+2) = 5') increases the value of `NF', creates any intervening
  10711. +fields with the null string as their value, and causes the value of
  10712. +`$0' to be recomputed, with the fields being separated by the value of
  10713. +`OFS'.
  10714. +
  10715. +   *Note Reading Input Files: Reading Files, for a full description of
  10716. +the way `awk' defines and uses fields.
  10717. +
  10718. +
  10719. +File: gawk.info,  Node: Built-in Summary,  Next: Arrays Summary,  Prev: Fields Summary,  Up: Variables/Fields
  10720. +
  10721. +Built-in Variables
  10722. +------------------
  10723. +
  10724. +   `awk''s built-in variables are:
  10725. +
  10726. +`ARGC'
  10727. +     The number of command line arguments (not including options or the
  10728. +     `awk' program itself).
  10729. +
  10730. +`ARGIND'
  10731. +     The index in `ARGV' of the current file being processed.  It is
  10732. +     always true that `FILENAME == ARGV[ARGIND]'.
  10733. +
  10734. +`ARGV'
  10735. +     The array of command line arguments.  The array is indexed from 0
  10736. +     to `ARGC' - 1.  Dynamically changing the contents of `ARGV' can
  10737. +     control the files used for data.
  10738. +
  10739. +`CONVFMT'
  10740. +     The conversion format to use when converting numbers to strings.
  10741. +
  10742. +`FIELDWIDTHS'
  10743. +     A space separated list of numbers describing the fixed-width input
  10744. +     data.
  10745. +
  10746. +`ENVIRON'
  10747. +     An array containing the values of the environment variables.  The
  10748. +     array is indexed by variable name, each element being the value of
  10749. +     that variable.  Thus, the environment variable `HOME' would be in
  10750. +     `ENVIRON["HOME"]'.  Its value might be `/u/close'.
  10751. +
  10752. +     Changing this array does not affect the environment seen by
  10753. +     programs which `gawk' spawns via redirection or the `system'
  10754. +     function.  (This may change in a future version of `gawk'.)
  10755. +
  10756. +     Some operating systems do not have environment variables.  The
  10757. +     array `ENVIRON' is empty when running on these systems.
  10758. +
  10759. +`ERRNO'
  10760. +     The system error message when an error occurs using `getline' or
  10761. +     `close'.
  10762. +
  10763. +`FILENAME'
  10764. +     The name of the current input file.  If no files are specified on
  10765. +     the command line, the value of `FILENAME' is `-'.
  10766. +
  10767. +`FNR'
  10768. +     The input record number in the current input file.
  10769. +
  10770. +`FS'
  10771. +     The input field separator, a blank by default.
  10772. +
  10773. +`IGNORECASE'
  10774. +     The case-sensitivity flag for regular expression operations.  If
  10775. +     `IGNORECASE' has a nonzero value, then pattern matching in rules,
  10776. +     field splitting with `FS', regular expression matching with `~'
  10777. +     and `!~', and the `gsub', `index', `match', `split' and `sub'
  10778. +     predefined functions all ignore case when doing regular expression
  10779. +     operations.
  10780. +
  10781. +`NF'
  10782. +     The number of fields in the current input record.
  10783. +
  10784. +`NR'
  10785. +     The total number of input records seen so far.
  10786. +
  10787. +`OFMT'
  10788. +     The output format for numbers for the `print' statement, `"%.6g"'
  10789. +     by default.
  10790. +
  10791. +`OFS'
  10792. +     The output field separator, a blank by default.
  10793. +
  10794. +`ORS'
  10795. +     The output record separator, by default a newline.
  10796. +
  10797. +`RS'
  10798. +     The input record separator, by default a newline.  `RS' is
  10799. +     exceptional in that only the first character of its string value
  10800. +     is used for separating records.  If `RS' is set to the null
  10801. +     string, then records are separated by blank lines.  When `RS' is
  10802. +     set to the null string, then the newline character always acts as
  10803. +     a field separator, in addition to whatever value `FS' may have.
  10804. +
  10805. +`RSTART'
  10806. +     The index of the first character matched by `match'; 0 if no match.
  10807. +
  10808. +`RLENGTH'
  10809. +     The length of the string matched by `match'; -1 if no match.
  10810. +
  10811. +`SUBSEP'
  10812. +     The string used to separate multiple subscripts in array elements,
  10813. +     by default `"\034"'.
  10814. +
  10815. +   *Note Built-in Variables::, for more information.
  10816. +
  10817. +
  10818. +File: gawk.info,  Node: Arrays Summary,  Next: Data Type Summary,  Prev: Built-in Summary,  Up: Variables/Fields
  10819. +
  10820. +Arrays
  10821. +------
  10822. +
  10823. +   Arrays are subscripted with an expression between square brackets
  10824. +(`[' and `]').  Array subscripts are *always* strings; numbers are
  10825. +converted to strings as necessary, following the standard conversion
  10826. +rules (*note Conversion of Strings and Numbers: Conversion.).
  10827. +
  10828. +   If you use multiple expressions separated by commas inside the square
  10829. +brackets, then the array subscript is a string consisting of the
  10830. +concatenation of the individual subscript values, converted to strings,
  10831. +separated by the subscript separator (the value of `SUBSEP').
  10832. +
  10833. +   The special operator `in' may be used in an `if' or `while'
  10834. +statement to see if an array has an index consisting of a particular
  10835. +value.
  10836. +
  10837. +     if (val in array)
  10838. +             print array[val]
  10839. +
  10840. +   If the array has multiple subscripts, use `(i, j, ...) in array' to
  10841. +test for existence of an element.
  10842. +
  10843. +   The `in' construct may also be used in a `for' loop to iterate over
  10844. +all the elements of an array.  *Note Scanning all Elements of an Array:
  10845. +Scanning an Array.
  10846. +
  10847. +   An element may be deleted from an array using the `delete' statement.
  10848. +
  10849. +   *Note Arrays in `awk': Arrays, for more detailed information.
  10850. +
  10851. +
  10852. +File: gawk.info,  Node: Data Type Summary,  Prev: Arrays Summary,  Up: Variables/Fields
  10853. +
  10854. +Data Types
  10855. +----------
  10856. +
  10857. +   The value of an `awk' expression is always either a number or a
  10858. +string.
  10859. +
  10860. +   Certain contexts (such as arithmetic operators) require numeric
  10861. +values.  They convert strings to numbers by interpreting the text of
  10862. +the string as a numeral.  If the string does not look like a numeral,
  10863. +it converts to 0.
  10864. +
  10865. +   Certain contexts (such as concatenation) require string values.
  10866. +They convert numbers to strings by effectively printing them with
  10867. +`sprintf'.  *Note Conversion of Strings and Numbers: Conversion, for
  10868. +the details.
  10869. +
  10870. +   To force conversion of a string value to a number, simply add 0 to
  10871. +it.  If the value you start with is already a number, this does not
  10872. +change it.
  10873. +
  10874. +   To force conversion of a numeric value to a string, concatenate it
  10875. +with the null string.
  10876. +
  10877. +   The `awk' language defines comparisons as being done numerically if
  10878. +both operands are numeric, or if one is numeric and the other is a
  10879. +numeric string.  Otherwise one or both operands are converted to
  10880. +strings and a string comparison is performed.
  10881. +
  10882. +   Uninitialized variables have the string value `""' (the null, or
  10883. +empty, string).  In contexts where a number is required, this is
  10884. +equivalent to 0.
  10885. +
  10886. +   *Note Variables::, for more information on variable naming and
  10887. +initialization; *note Conversion of Strings and Numbers: Conversion.,
  10888. +for more information on how variable values are interpreted.
  10889. +
  10890. +
  10891. +File: gawk.info,  Node: Rules Summary,  Next: Functions Summary,  Prev: Variables/Fields,  Up: Gawk Summary
  10892. +
  10893. +Patterns and Actions
  10894. +====================
  10895. +
  10896. +* Menu:
  10897. +
  10898. +* Pattern Summary::             Quick overview of patterns.
  10899. +* Regexp Summary::              Quick overview of regular expressions.
  10900. +* Actions Summary::             Quick overview of actions.
  10901. +
  10902. +   An `awk' program is mostly composed of rules, each consisting of a
  10903. +pattern followed by an action.  The action is enclosed in `{' and `}'.
  10904. +Either the pattern may be missing, or the action may be missing, but,
  10905. +of course, not both.  If the pattern is missing, the action is executed
  10906. +for every single line of input.  A missing action is equivalent to this
  10907. +action,
  10908. +
  10909. +     { print }
  10910. +
  10911. +which prints the entire line.
  10912. +
  10913. +   Comments begin with the `#' character, and continue until the end of
  10914. +the line.  Blank lines may be used to separate statements.  Normally, a
  10915. +statement ends with a newline, however, this is not the case for lines
  10916. +ending in a `,', `{', `?', `:', `&&', or `||'.  Lines ending in `do' or
  10917. +`else' also have their statements automatically continued on the
  10918. +following line.  In other cases, a line can be continued by ending it
  10919. +with a `\', in which case the newline is ignored.
  10920. +
  10921. +   Multiple statements may be put on one line by separating them with a
  10922. +`;'.  This applies to both the statements within the action part of a
  10923. +rule (the usual case), and to the rule statements.
  10924. +
  10925. +   *Note Comments in `awk' Programs: Comments, for information on
  10926. +`awk''s commenting convention; *note `awk' Statements versus Lines:
  10927. +Statements/Lines., for a description of the line continuation mechanism
  10928. +in `awk'.
  10929. +
  10930. +
  10931. +File: gawk.info,  Node: Pattern Summary,  Next: Regexp Summary,  Prev: Rules Summary,  Up: Rules Summary
  10932. +
  10933. +Patterns
  10934. +--------
  10935. +
  10936. +   `awk' patterns may be one of the following:
  10937. +
  10938. +     /REGULAR EXPRESSION/
  10939. +     RELATIONAL EXPRESSION
  10940. +     PATTERN && PATTERN
  10941. +     PATTERN || PATTERN
  10942. +     PATTERN ? PATTERN : PATTERN
  10943. +     (PATTERN)
  10944. +     ! PATTERN
  10945. +     PATTERN1, PATTERN2
  10946. +     BEGIN
  10947. +     END
  10948. +
  10949. +   `BEGIN' and `END' are two special kinds of patterns that are not
  10950. +tested against the input.  The action parts of all `BEGIN' rules are
  10951. +merged as if all the statements had been written in a single `BEGIN'
  10952. +rule.  They are executed before any of the input is read.  Similarly,
  10953. +all the `END' rules are merged, and executed when all the input is
  10954. +exhausted (or when an `exit' statement is executed).  `BEGIN' and `END'
  10955. +patterns cannot be combined with other patterns in pattern expressions.
  10956. +`BEGIN' and `END' rules cannot have missing action parts.
  10957. +
  10958. +   For `/REGULAR-EXPRESSION/' patterns, the associated statement is
  10959. +executed for each input line that matches the regular expression.
  10960. +Regular expressions are extensions of those in `egrep', and are
  10961. +summarized below.
  10962. +
  10963. +   A RELATIONAL EXPRESSION may use any of the operators defined below in
  10964. +the section on actions.  These generally test whether certain fields
  10965. +match certain regular expressions.
  10966. +
  10967. +   The `&&', `||', and `!' operators are logical "and," logical "or,"
  10968. +and logical "not," respectively, as in C.  They do short-circuit
  10969. +evaluation, also as in C, and are used for combining more primitive
  10970. +pattern expressions.  As in most languages, parentheses may be used to
  10971. +change the order of evaluation.
  10972. +
  10973. +   The `?:' operator is like the same operator in C.  If the first
  10974. +pattern matches, then the second pattern is matched against the input
  10975. +record; otherwise, the third is matched.  Only one of the second and
  10976. +third patterns is matched.
  10977. +
  10978. +   The `PATTERN1, PATTERN2' form of a pattern is called a range
  10979. +pattern.  It matches all input lines starting with a line that matches
  10980. +PATTERN1, and continuing until a line that matches PATTERN2, inclusive.
  10981. +A range pattern cannot be used as an operand to any of the pattern
  10982. +operators.
  10983. +
  10984. +   *Note Patterns::, for a full description of the pattern part of `awk'
  10985. +rules.
  10986. +
  10987. diff -rup --new-file baseline/fsf/gawk/gawk.info-8 amiga/fsf/gawk/gawk.info-8
  10988. --- baseline/fsf/gawk/gawk.info-8    Wed Dec 31 17:00:00 1969
  10989. +++ amiga/fsf/gawk/gawk.info-8    Sat Sep 28 00:00:00 1996
  10990. @@ -0,0 +1,1173 @@
  10991. +This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  10992. +file /gnu-src/gawk-2.15.6/gawk.texi.
  10993. +
  10994. +   This file documents `awk', a program that you can use to select
  10995. +particular records in a file and perform operations upon them.
  10996. +
  10997. +   This is Edition 0.15 of `The GAWK Manual',
  10998. +for the 2.15 version of the GNU implementation
  10999. +of AWK.
  11000. +
  11001. +   Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  11002. +
  11003. +   Permission is granted to make and distribute verbatim copies of this
  11004. +manual provided the copyright notice and this permission notice are
  11005. +preserved on all copies.
  11006. +
  11007. +   Permission is granted to copy and distribute modified versions of
  11008. +this manual under the conditions for verbatim copying, provided that
  11009. +the entire resulting derived work is distributed under the terms of a
  11010. +permission notice identical to this one.
  11011. +
  11012. +   Permission is granted to copy and distribute translations of this
  11013. +manual into another language, under the above conditions for modified
  11014. +versions, except that this permission notice may be stated in a
  11015. +translation approved by the Foundation.
  11016. +
  11017. +
  11018. +File: gawk.info,  Node: Regexp Summary,  Next: Actions Summary,  Prev: Pattern Summary,  Up: Rules Summary
  11019. +
  11020. +Regular Expressions
  11021. +-------------------
  11022. +
  11023. +   Regular expressions are the extended kind found in `egrep'.  They
  11024. +are composed of characters as follows:
  11025. +
  11026. +`C'
  11027. +     matches the character C (assuming C is a character with no special
  11028. +     meaning in regexps).
  11029. +
  11030. +`\C'
  11031. +     matches the literal character C.
  11032. +
  11033. +`.'
  11034. +     matches any character except newline.
  11035. +
  11036. +`^'
  11037. +     matches the beginning of a line or a string.
  11038. +
  11039. +`$'
  11040. +     matches the end of a line or a string.
  11041. +
  11042. +`[ABC...]'
  11043. +     matches any of the characters ABC... (character class).
  11044. +
  11045. +`[^ABC...]'
  11046. +     matches any character except ABC... and newline (negated character
  11047. +     class).
  11048. +
  11049. +`R1|R2'
  11050. +     matches either R1 or R2 (alternation).
  11051. +
  11052. +`R1R2'
  11053. +     matches R1, and then R2 (concatenation).
  11054. +
  11055. +`R+'
  11056. +     matches one or more R's.
  11057. +
  11058. +`R*'
  11059. +     matches zero or more R's.
  11060. +
  11061. +`R?'
  11062. +     matches zero or one R's.
  11063. +
  11064. +`(R)'
  11065. +     matches R (grouping).
  11066. +
  11067. +   *Note Regular Expressions as Patterns: Regexp, for a more detailed
  11068. +explanation of regular expressions.
  11069. +
  11070. +   The escape sequences allowed in string constants are also valid in
  11071. +regular expressions (*note Constant Expressions: Constants.).
  11072. +
  11073. +
  11074. +File: gawk.info,  Node: Actions Summary,  Prev: Regexp Summary,  Up: Rules Summary
  11075. +
  11076. +Actions
  11077. +-------
  11078. +
  11079. +   Action statements are enclosed in braces, `{' and `}'.  Action
  11080. +statements consist of the usual assignment, conditional, and looping
  11081. +statements found in most languages.  The operators, control statements,
  11082. +and input/output statements available are patterned after those in C.
  11083. +
  11084. +* Menu:
  11085. +
  11086. +* Operator Summary::            `awk' operators.
  11087. +* Control Flow Summary::        The control statements.
  11088. +* I/O Summary::                 The I/O statements.
  11089. +* Printf Summary::              A summary of `printf'.
  11090. +* Special File Summary::        Special file names interpreted internally.
  11091. +* Numeric Functions Summary::   Built-in numeric functions.
  11092. +* String Functions Summary::    Built-in string functions.
  11093. +* Time Functions Summary::      Built-in time functions.
  11094. +* String Constants Summary::    Escape sequences in strings.
  11095. +
  11096. +
  11097. +File: gawk.info,  Node: Operator Summary,  Next: Control Flow Summary,  Prev: Actions Summary,  Up: Actions Summary
  11098. +
  11099. +Operators
  11100. +.........
  11101. +
  11102. +   The operators in `awk', in order of increasing precedence, are:
  11103. +
  11104. +`= += -= *= /= %= ^='
  11105. +     Assignment.  Both absolute assignment (`VAR=VALUE') and operator
  11106. +     assignment (the other forms) are supported.
  11107. +
  11108. +`?:'
  11109. +     A conditional expression, as in C.  This has the form `EXPR1 ?
  11110. +     eXPR2 : EXPR3'.  If EXPR1 is true, the value of the expression is
  11111. +     EXPR2; otherwise it is EXPR3.  Only one of EXPR2 and EXPR3 is
  11112. +     evaluated.
  11113. +
  11114. +`||'
  11115. +     Logical "or".
  11116. +
  11117. +`&&'
  11118. +     Logical "and".
  11119. +
  11120. +`~ !~'
  11121. +     Regular expression match, negated match.
  11122. +
  11123. +`< <= > >= != =='
  11124. +     The usual relational operators.
  11125. +
  11126. +`BLANK'
  11127. +     String concatenation.
  11128. +
  11129. +`+ -'
  11130. +     Addition and subtraction.
  11131. +
  11132. +`* / %'
  11133. +     Multiplication, division, and modulus.
  11134. +
  11135. +`+ - !'
  11136. +     Unary plus, unary minus, and logical negation.
  11137. +
  11138. +`^'
  11139. +     Exponentiation (`**' may also be used, and `**=' for the assignment
  11140. +     operator, but they are not specified in the POSIX standard).
  11141. +
  11142. +`++ --'
  11143. +     Increment and decrement, both prefix and postfix.
  11144. +
  11145. +`$'
  11146. +     Field reference.
  11147. +
  11148. +   *Note Expressions as Action Statements: Expressions, for a full
  11149. +description of all the operators listed above.  *Note Examining Fields:
  11150. +Fields, for a description of the field reference operator.
  11151. +
  11152. +
  11153. +File: gawk.info,  Node: Control Flow Summary,  Next: I/O Summary,  Prev: Operator Summary,  Up: Actions Summary
  11154. +
  11155. +Control Statements
  11156. +..................
  11157. +
  11158. +   The control statements are as follows:
  11159. +
  11160. +     if (CONDITION) STATEMENT [ else STATEMENT ]
  11161. +     while (CONDITION) STATEMENT
  11162. +     do STATEMENT while (CONDITION)
  11163. +     for (EXPR1; EXPR2; EXPR3) STATEMENT
  11164. +     for (VAR in ARRAY) STATEMENT
  11165. +     break
  11166. +     continue
  11167. +     delete ARRAY[INDEX]
  11168. +     exit [ EXPRESSION ]
  11169. +     { STATEMENTS }
  11170. +
  11171. +   *Note Control Statements in Actions: Statements, for a full
  11172. +description of all the control statements listed above.
  11173. +
  11174. +
  11175. +File: gawk.info,  Node: I/O Summary,  Next: Printf Summary,  Prev: Control Flow Summary,  Up: Actions Summary
  11176. +
  11177. +I/O Statements
  11178. +..............
  11179. +
  11180. +   The input/output statements are as follows:
  11181. +
  11182. +`getline'
  11183. +     Set `$0' from next input record; set `NF', `NR', `FNR'.
  11184. +
  11185. +`getline <FILE'
  11186. +     Set `$0' from next record of FILE; set `NF'.
  11187. +
  11188. +`getline VAR'
  11189. +     Set VAR from next input record; set `NF', `FNR'.
  11190. +
  11191. +`getline VAR <FILE'
  11192. +     Set VAR from next record of FILE.
  11193. +
  11194. +`next'
  11195. +     Stop processing the current input record.  The next input record
  11196. +     is read and processing starts over with the first pattern in the
  11197. +     `awk' program.  If the end of the input data is reached, the `END'
  11198. +     rule(s), if any, are executed.
  11199. +
  11200. +`next file'
  11201. +     Stop processing the current input file.  The next input record
  11202. +     read comes from the next input file.  `FILENAME' is updated, `FNR'
  11203. +     is set to 1, and processing starts over with the first pattern in
  11204. +     the `awk' program.  If the end of the input data is reached, the
  11205. +     `END' rule(s), if any, are executed.
  11206. +
  11207. +`print'
  11208. +     Prints the current record.
  11209. +
  11210. +`print EXPR-LIST'
  11211. +     Prints expressions.
  11212. +
  11213. +`print EXPR-LIST > FILE'
  11214. +     Prints expressions on FILE.
  11215. +
  11216. +`printf FMT, EXPR-LIST'
  11217. +     Format and print.
  11218. +
  11219. +`printf FMT, EXPR-LIST > file'
  11220. +     Format and print on FILE.
  11221. +
  11222. +   Other input/output redirections are also allowed.  For `print' and
  11223. +`printf', `>> FILE' appends output to the FILE, and `| COMMAND' writes
  11224. +on a pipe.  In a similar fashion, `COMMAND | getline' pipes input into
  11225. +`getline'.  `getline' returns 0 on end of file, and -1 on an error.
  11226. +
  11227. +   *Note Explicit Input with `getline': Getline, for a full description
  11228. +of the `getline' statement.  *Note Printing Output: Printing, for a
  11229. +full description of `print' and `printf'.  Finally, *note The `next'
  11230. +Statement: Next Statement., for a description of how the `next'
  11231. +statement works.
  11232. +
  11233. +
  11234. +File: gawk.info,  Node: Printf Summary,  Next: Special File Summary,  Prev: I/O Summary,  Up: Actions Summary
  11235. +
  11236. +`printf' Summary
  11237. +................
  11238. +
  11239. +   The `awk' `printf' statement and `sprintf' function accept the
  11240. +following conversion specification formats:
  11241. +
  11242. +`%c'
  11243. +     An ASCII character.  If the argument used for `%c' is numeric, it
  11244. +     is treated as a character and printed.  Otherwise, the argument is
  11245. +     assumed to be a string, and the only first character of that
  11246. +     string is printed.
  11247. +
  11248. +`%d'
  11249. +`%i'
  11250. +     A decimal number (the integer part).
  11251. +
  11252. +`%e'
  11253. +     A floating point number of the form `[-]d.ddddddE[+-]dd'.
  11254. +
  11255. +`%f'
  11256. +     A floating point number of the form [`-']`ddd.dddddd'.
  11257. +
  11258. +`%g'
  11259. +     Use `%e' or `%f' conversion, whichever produces a shorter string,
  11260. +     with nonsignificant zeros suppressed.
  11261. +
  11262. +`%o'
  11263. +     An unsigned octal number (again, an integer).
  11264. +
  11265. +`%s'
  11266. +     A character string.
  11267. +
  11268. +`%x'
  11269. +     An unsigned hexadecimal number (an integer).
  11270. +
  11271. +`%X'
  11272. +     Like `%x', except use `A' through `F' instead of `a' through `f'
  11273. +     for decimal 10 through 15.
  11274. +
  11275. +`%%'
  11276. +     A single `%' character; no argument is converted.
  11277. +
  11278. +   There are optional, additional parameters that may lie between the
  11279. +`%' and the control letter:
  11280. +
  11281. +`-'
  11282. +     The expression should be left-justified within its field.
  11283. +
  11284. +`WIDTH'
  11285. +     The field should be padded to this width.  If WIDTH has a leading
  11286. +     zero, then the field is padded with zeros.  Otherwise it is padded
  11287. +     with blanks.
  11288. +
  11289. +`.PREC'
  11290. +     A number indicating the maximum width of strings or digits to the
  11291. +     right of the decimal point.
  11292. +
  11293. +   Either or both of the WIDTH and PREC values may be specified as `*'.
  11294. +In that case, the particular value is taken from the argument list.
  11295. +
  11296. +   *Note Using `printf' Statements for Fancier Printing: Printf, for
  11297. +examples and for a more detailed description.
  11298. +
  11299. +
  11300. +File: gawk.info,  Node: Special File Summary,  Next: Numeric Functions Summary,  Prev: Printf Summary,  Up: Actions Summary
  11301. +
  11302. +Special File Names
  11303. +..................
  11304. +
  11305. +   When doing I/O redirection from either `print' or `printf' into a
  11306. +file, or via `getline' from a file, `gawk' recognizes certain special
  11307. +file names internally.  These file names allow access to open file
  11308. +descriptors inherited from `gawk''s parent process (usually the shell).
  11309. +The file names are:
  11310. +
  11311. +`/dev/stdin'
  11312. +     The standard input.
  11313. +
  11314. +`/dev/stdout'
  11315. +     The standard output.
  11316. +
  11317. +`/dev/stderr'
  11318. +     The standard error output.
  11319. +
  11320. +`/dev/fd/N'
  11321. +     The file denoted by the open file descriptor N.
  11322. +
  11323. +   In addition the following files provide process related information
  11324. +about the running `gawk' program.
  11325. +
  11326. +`/dev/pid'
  11327. +     Reading this file returns the process ID of the current process,
  11328. +     in decimal, terminated with a newline.
  11329. +
  11330. +`/dev/ppid'
  11331. +     Reading this file returns the parent process ID of the current
  11332. +     process, in decimal, terminated with a newline.
  11333. +
  11334. +`/dev/pgrpid'
  11335. +     Reading this file returns the process group ID of the current
  11336. +     process, in decimal, terminated with a newline.
  11337. +
  11338. +`/dev/user'
  11339. +     Reading this file returns a single record terminated with a
  11340. +     newline.  The fields are separated with blanks.  The fields
  11341. +     represent the following information:
  11342. +
  11343. +    `$1'
  11344. +          The value of the `getuid' system call.
  11345. +
  11346. +    `$2'
  11347. +          The value of the `geteuid' system call.
  11348. +
  11349. +    `$3'
  11350. +          The value of the `getgid' system call.
  11351. +
  11352. +    `$4'
  11353. +          The value of the `getegid' system call.
  11354. +
  11355. +     If there are any additional fields, they are the group IDs
  11356. +     returned by `getgroups' system call.  (Multiple groups may not be
  11357. +     supported on all systems.)
  11358. +
  11359. +These file names may also be used on the command line to name data
  11360. +files.  These file names are only recognized internally if you do not
  11361. +actually have files by these names on your system.
  11362. +
  11363. +   *Note Standard I/O Streams: Special Files, for a longer description
  11364. +that provides the motivation for this feature.
  11365. +
  11366. +
  11367. +File: gawk.info,  Node: Numeric Functions Summary,  Next: String Functions Summary,  Prev: Special File Summary,  Up: Actions Summary
  11368. +
  11369. +Numeric Functions
  11370. +.................
  11371. +
  11372. +   `awk' has the following predefined arithmetic functions:
  11373. +
  11374. +`atan2(Y, X)'
  11375. +     returns the arctangent of Y/X in radians.
  11376. +
  11377. +`cos(EXPR)'
  11378. +     returns the cosine in radians.
  11379. +
  11380. +`exp(EXPR)'
  11381. +     the exponential function.
  11382. +
  11383. +`int(EXPR)'
  11384. +     truncates to integer.
  11385. +
  11386. +`log(EXPR)'
  11387. +     the natural logarithm function.
  11388. +
  11389. +`rand()'
  11390. +     returns a random number between 0 and 1.
  11391. +
  11392. +`sin(EXPR)'
  11393. +     returns the sine in radians.
  11394. +
  11395. +`sqrt(EXPR)'
  11396. +     the square root function.
  11397. +
  11398. +`srand(EXPR)'
  11399. +     use EXPR as a new seed for the random number generator.  If no EXPR
  11400. +     is provided, the time of day is used.  The return value is the
  11401. +     previous seed for the random number generator.
  11402. +
  11403. +
  11404. +File: gawk.info,  Node: String Functions Summary,  Next: Time Functions Summary,  Prev: Numeric Functions Summary,  Up: Actions Summary
  11405. +
  11406. +String Functions
  11407. +................
  11408. +
  11409. +   `awk' has the following predefined string functions:
  11410. +
  11411. +`gsub(R, S, T)'
  11412. +     for each substring matching the regular expression R in the string
  11413. +     T, substitute the string S, and return the number of substitutions.
  11414. +     If T is not supplied, use `$0'.
  11415. +
  11416. +`index(S, T)'
  11417. +     returns the index of the string T in the string S, or 0 if T is
  11418. +     not present.
  11419. +
  11420. +`length(S)'
  11421. +     returns the length of the string S.  The length of `$0' is
  11422. +     returned if no argument is supplied.
  11423. +
  11424. +`match(S, R)'
  11425. +     returns the position in S where the regular expression R occurs,
  11426. +     or 0 if R is not present, and sets the values of `RSTART' and
  11427. +     `RLENGTH'.
  11428. +
  11429. +`split(S, A, R)'
  11430. +     splits the string S into the array A on the regular expression R,
  11431. +     and returns the number of fields.  If R is omitted, `FS' is used
  11432. +     instead.
  11433. +
  11434. +`sprintf(FMT, EXPR-LIST)'
  11435. +     prints EXPR-LIST according to FMT, and returns the resulting
  11436. +     string.
  11437. +
  11438. +`sub(R, S, T)'
  11439. +     this is just like `gsub', but only the first matching substring is
  11440. +     replaced.
  11441. +
  11442. +`substr(S, I, N)'
  11443. +     returns the N-character substring of S starting at I.  If N is
  11444. +     omitted, the rest of S is used.
  11445. +
  11446. +`tolower(STR)'
  11447. +     returns a copy of the string STR, with all the upper-case
  11448. +     characters in STR translated to their corresponding lower-case
  11449. +     counterparts.  Nonalphabetic characters are left unchanged.
  11450. +
  11451. +`toupper(STR)'
  11452. +     returns a copy of the string STR, with all the lower-case
  11453. +     characters in STR translated to their corresponding upper-case
  11454. +     counterparts.  Nonalphabetic characters are left unchanged.
  11455. +
  11456. +`system(CMD-LINE)'
  11457. +     Execute the command CMD-LINE, and return the exit status.
  11458. +
  11459. +
  11460. +File: gawk.info,  Node: Time Functions Summary,  Next: String Constants Summary,  Prev: String Functions Summary,  Up: Actions Summary
  11461. +
  11462. +Built-in time functions
  11463. +.......................
  11464. +
  11465. +   The following two functions are available for getting the current
  11466. +time of day, and for formatting time stamps.
  11467. +
  11468. +`systime()'
  11469. +     returns the current time of day as the number of seconds since a
  11470. +     particular epoch (Midnight, January 1, 1970 UTC, on POSIX systems).
  11471. +
  11472. +`strftime(FORMAT, TIMESTAMP)'
  11473. +     formats TIMESTAMP according to the specification in FORMAT.  The
  11474. +     current time of day is used if no TIMESTAMP is supplied.  *Note
  11475. +     Functions for Dealing with Time Stamps: Time Functions, for the
  11476. +     details on the conversion specifiers that `strftime' accepts.
  11477. +
  11478. +
  11479. +File: gawk.info,  Node: String Constants Summary,  Prev: Time Functions Summary,  Up: Actions Summary
  11480. +
  11481. +String Constants
  11482. +................
  11483. +
  11484. +   String constants in `awk' are sequences of characters enclosed
  11485. +between double quotes (`"').  Within strings, certain "escape sequences"
  11486. +are recognized, as in C.  These are:
  11487. +
  11488. +`\\'
  11489. +     A literal backslash.
  11490. +
  11491. +`\a'
  11492. +     The "alert" character; usually the ASCII BEL character.
  11493. +
  11494. +`\b'
  11495. +     Backspace.
  11496. +
  11497. +`\f'
  11498. +     Formfeed.
  11499. +
  11500. +`\n'
  11501. +     Newline.
  11502. +
  11503. +`\r'
  11504. +     Carriage return.
  11505. +
  11506. +`\t'
  11507. +     Horizontal tab.
  11508. +
  11509. +`\v'
  11510. +     Vertical tab.
  11511. +
  11512. +`\xHEX DIGITS'
  11513. +     The character represented by the string of hexadecimal digits
  11514. +     following the `\x'.  As in ANSI C, all following hexadecimal
  11515. +     digits are considered part of the escape sequence.  (This feature
  11516. +     should tell us something about language design by committee.)
  11517. +     E.g., `"\x1B"' is a string containing the ASCII ESC (escape)
  11518. +     character.  (The `\x' escape sequence is not in POSIX `awk'.)
  11519. +
  11520. +`\DDD'
  11521. +     The character represented by the 1-, 2-, or 3-digit sequence of
  11522. +     octal digits.  Thus, `"\033"' is also a string containing the
  11523. +     ASCII ESC (escape) character.
  11524. +
  11525. +`\C'
  11526. +     The literal character C.
  11527. +
  11528. +   The escape sequences may also be used inside constant regular
  11529. +expressions (e.g., the regexp `/[ \t\f\n\r\v]/' matches whitespace
  11530. +characters).
  11531. +
  11532. +   *Note Constant Expressions: Constants.
  11533. +
  11534. +
  11535. +File: gawk.info,  Node: Functions Summary,  Next: Historical Features,  Prev: Rules Summary,  Up: Gawk Summary
  11536. +
  11537. +Functions
  11538. +=========
  11539. +
  11540. +   Functions in `awk' are defined as follows:
  11541. +
  11542. +     function NAME(PARAMETER LIST) { STATEMENTS }
  11543. +
  11544. +   Actual parameters supplied in the function call are used to
  11545. +instantiate the formal parameters declared in the function.  Arrays are
  11546. +passed by reference, other variables are passed by value.
  11547. +
  11548. +   If there are fewer arguments passed than there are names in
  11549. +PARAMETER-LIST, the extra names are given the null string as value.
  11550. +Extra names have the effect of local variables.
  11551. +
  11552. +   The open-parenthesis in a function call of a user-defined function
  11553. +must immediately follow the function name, without any intervening
  11554. +white space.  This is to avoid a syntactic ambiguity with the
  11555. +concatenation operator.
  11556. +
  11557. +   The word `func' may be used in place of `function' (but not in POSIX
  11558. +`awk').
  11559. +
  11560. +   Use the `return' statement to return a value from a function.
  11561. +
  11562. +   *Note User-defined Functions: User-defined, for a more complete
  11563. +description.
  11564. +
  11565. +
  11566. +File: gawk.info,  Node: Historical Features,  Prev: Functions Summary,  Up: Gawk Summary
  11567. +
  11568. +Historical Features
  11569. +===================
  11570. +
  11571. +   There are two features of historical `awk' implementations that
  11572. +`gawk' supports.  First, it is possible to call the `length' built-in
  11573. +function not only with no arguments, but even without parentheses!
  11574. +
  11575. +     a = length
  11576. +
  11577. +is the same as either of
  11578. +
  11579. +     a = length()
  11580. +     a = length($0)
  11581. +
  11582. +This feature is marked as "deprecated" in the POSIX standard, and
  11583. +`gawk' will issue a warning about its use if `-W lint' is specified on
  11584. +the command line.
  11585. +
  11586. +   The other feature is the use of the `continue' statement outside the
  11587. +body of a `while', `for', or `do' loop.  Traditional `awk'
  11588. +implementations have treated such usage as equivalent to the `next'
  11589. +statement.  `gawk' will support this usage if `-W posix' has not been
  11590. +specified.
  11591. +
  11592. +
  11593. +File: gawk.info,  Node: Sample Program,  Next: Bugs,  Prev: Gawk Summary,  Up: Top
  11594. +
  11595. +Sample Program
  11596. +**************
  11597. +
  11598. +   The following example is a complete `awk' program, which prints the
  11599. +number of occurrences of each word in its input.  It illustrates the
  11600. +associative nature of `awk' arrays by using strings as subscripts.  It
  11601. +also demonstrates the `for X in ARRAY' construction.  Finally, it shows
  11602. +how `awk' can be used in conjunction with other utility programs to do
  11603. +a useful task of some complexity with a minimum of effort.  Some
  11604. +explanations follow the program listing.
  11605. +
  11606. +     awk '
  11607. +     # Print list of word frequencies
  11608. +     {
  11609. +         for (i = 1; i <= NF; i++)
  11610. +             freq[$i]++
  11611. +     }
  11612. +     
  11613. +     END {
  11614. +         for (word in freq)
  11615. +             printf "%s\t%d\n", word, freq[word]
  11616. +     }'
  11617. +
  11618. +   The first thing to notice about this program is that it has two
  11619. +rules.  The first rule, because it has an empty pattern, is executed on
  11620. +every line of the input.  It uses `awk''s field-accessing mechanism
  11621. +(*note Examining Fields: Fields.) to pick out the individual words from
  11622. +the line, and the built-in variable `NF' (*note Built-in Variables::.)
  11623. +to know how many fields are available.
  11624. +
  11625. +   For each input word, an element of the array `freq' is incremented to
  11626. +reflect that the word has been seen an additional time.
  11627. +
  11628. +   The second rule, because it has the pattern `END', is not executed
  11629. +until the input has been exhausted.  It prints out the contents of the
  11630. +`freq' table that has been built up inside the first action.
  11631. +
  11632. +   Note that this program has several problems that would prevent it
  11633. +from being useful by itself on real text files:
  11634. +
  11635. +   * Words are detected using the `awk' convention that fields are
  11636. +     separated by whitespace and that other characters in the input
  11637. +     (except newlines) don't have any special meaning to `awk'.  This
  11638. +     means that punctuation characters count as part of words.
  11639. +
  11640. +   * The `awk' language considers upper and lower case characters to be
  11641. +     distinct.  Therefore, `foo' and `Foo' are not treated by this
  11642. +     program as the same word.  This is undesirable since in normal
  11643. +     text, words are capitalized if they begin sentences, and a
  11644. +     frequency analyzer should not be sensitive to that.
  11645. +
  11646. +   * The output does not come out in any useful order.  You're more
  11647. +     likely to be interested in which words occur most frequently, or
  11648. +     having an alphabetized table of how frequently each word occurs.
  11649. +
  11650. +   The way to solve these problems is to use some of the more advanced
  11651. +features of the `awk' language.  First, we use `tolower' to remove case
  11652. +distinctions.  Next, we use `gsub' to remove punctuation characters.
  11653. +Finally, we use the system `sort' utility to process the output of the
  11654. +`awk' script.  First, here is the new version of the program:
  11655. +
  11656. +     awk '
  11657. +     # Print list of word frequencies
  11658. +     {
  11659. +         $0 = tolower($0)    # remove case distinctions
  11660. +         gsub(/[^a-z0-9_ \t]/, "", $0)  # remove punctuation
  11661. +         for (i = 1; i <= NF; i++)
  11662. +             freq[$i]++
  11663. +     }
  11664. +     
  11665. +     END {
  11666. +         for (word in freq)
  11667. +             printf "%s\t%d\n", word, freq[word]
  11668. +     }'
  11669. +
  11670. +   Assuming we have saved this program in a file named `frequency.awk',
  11671. +and that the data is in `file1', the following pipeline
  11672. +
  11673. +     awk -f frequency.awk file1 | sort +1 -nr
  11674. +
  11675. +produces a table of the words appearing in `file1' in order of
  11676. +decreasing frequency.
  11677. +
  11678. +   The `awk' program suitably massages the data and produces a word
  11679. +frequency table, which is not ordered.
  11680. +
  11681. +   The `awk' script's output is then sorted by the `sort' command and
  11682. +printed on the terminal.  The options given to `sort' in this example
  11683. +specify to sort using the second field of each input line (skipping one
  11684. +field), that the sort keys should be treated as numeric quantities
  11685. +(otherwise `15' would come before `5'), and that the sorting should be
  11686. +done in descending (reverse) order.
  11687. +
  11688. +   We could have even done the `sort' from within the program, by
  11689. +changing the `END' action to:
  11690. +
  11691. +     END {
  11692. +         sort = "sort +1 -nr"
  11693. +         for (word in freq)
  11694. +             printf "%s\t%d\n", word, freq[word] | sort
  11695. +         close(sort)
  11696. +     }'
  11697. +
  11698. +   See the general operating system documentation for more information
  11699. +on how to use the `sort' command.
  11700. +
  11701. +
  11702. +File: gawk.info,  Node: Bugs,  Next: Notes,  Prev: Sample Program,  Up: Top
  11703. +
  11704. +Reporting Problems and Bugs
  11705. +***************************
  11706. +
  11707. +   If you have problems with `gawk' or think that you have found a bug,
  11708. +please report it to the developers; we cannot promise to do anything
  11709. +but we might well want to fix it.
  11710. +
  11711. +   Before reporting a bug, make sure you have actually found a real bug.
  11712. +Carefully reread the documentation and see if it really says you can do
  11713. +what you're trying to do.  If it's not clear whether you should be able
  11714. +to do something or not, report that too; it's a bug in the
  11715. +documentation!
  11716. +
  11717. +   Before reporting a bug or trying to fix it yourself, try to isolate
  11718. +it to the smallest possible `awk' program and input data file that
  11719. +reproduces the problem.  Then send us the program and data file, some
  11720. +idea of what kind of Unix system you're using, and the exact results
  11721. +`gawk' gave you.  Also say what you expected to occur; this will help
  11722. +us decide whether the problem was really in the documentation.
  11723. +
  11724. +   Once you have a precise problem, send e-mail to (Internet)
  11725. +`bug-gnu-utils@prep.ai.mit.edu' or (UUCP)
  11726. +`mit-eddie!prep.ai.mit.edu!bug-gnu-utils'.  Please include the version
  11727. +number of `gawk' you are using.  You can get this information with the
  11728. +command `gawk -W version '{}' /dev/null'.  You should send carbon
  11729. +copies of your mail to David Trueman at `david@cs.dal.ca', and to
  11730. +Arnold Robbins, who can be reached at `arnold@skeeve.atl.ga.us'.  David
  11731. +is most likely to fix code problems, while Arnold is most likely to fix
  11732. +documentation problems.
  11733. +
  11734. +   Non-bug suggestions are always welcome as well.  If you have
  11735. +questions about things that are unclear in the documentation or are
  11736. +just obscure features, ask Arnold Robbins; he will try to help you out,
  11737. +although he may not have the time to fix the problem.  You can send him
  11738. +electronic mail at the Internet address above.
  11739. +
  11740. +   If you find bugs in one of the non-Unix ports of `gawk', please send
  11741. +an electronic mail message to the person who maintains that port.  They
  11742. +are listed below, and also in the `README' file in the `gawk'
  11743. +distribution.  Information in the `README' file should be considered
  11744. +authoritative if it conflicts with this manual.
  11745. +
  11746. +   The people maintaining the non-Unix ports of `gawk' are:
  11747. +
  11748. +MS-DOS
  11749. +     The port to MS-DOS is maintained by Scott Deifik.  His electronic
  11750. +     mail address is `scottd@amgen.com'.
  11751. +
  11752. +VMS
  11753. +     The port to VAX VMS is maintained by Pat Rankin.  His electronic
  11754. +     mail address is `rankin@eql.caltech.edu'.
  11755. +
  11756. +Atari ST
  11757. +     The port to the Atari ST is maintained by Michal Jaegermann.  His
  11758. +     electronic mail address is `ntomczak@vm.ucs.ualberta.ca'.
  11759. +
  11760. +   If your bug is also reproducible under Unix, please send copies of
  11761. +your report to the general GNU bug list, as well as to Arnold Robbins
  11762. +and David Trueman, at the addresses listed above.
  11763. +
  11764. +
  11765. +File: gawk.info,  Node: Notes,  Next: Glossary,  Prev: Bugs,  Up: Top
  11766. +
  11767. +Implementation Notes
  11768. +********************
  11769. +
  11770. +   This appendix contains information mainly of interest to
  11771. +implementors and maintainers of `gawk'.  Everything in it applies
  11772. +specifically to `gawk', and not to other implementations.
  11773. +
  11774. +* Menu:
  11775. +
  11776. +* Compatibility Mode::          How to disable certain `gawk' extensions.
  11777. +* Future Extensions::           New features we may implement soon.
  11778. +* Improvements::                Suggestions for improvements by volunteers.
  11779. +
  11780. +
  11781. +File: gawk.info,  Node: Compatibility Mode,  Next: Future Extensions,  Prev: Notes,  Up: Notes
  11782. +
  11783. +Downward Compatibility and Debugging
  11784. +====================================
  11785. +
  11786. +   *Note Extensions in `gawk' not in POSIX `awk': POSIX/GNU, for a
  11787. +summary of the GNU extensions to the `awk' language and program.  All
  11788. +of these features can be turned off by invoking `gawk' with the `-W
  11789. +compat' option, or with the `-W posix' option.
  11790. +
  11791. +   If `gawk' is compiled for debugging with `-DDEBUG', then there is
  11792. +one more option available on the command line:
  11793. +
  11794. +`-W parsedebug'
  11795. +     Print out the parse stack information as the program is being
  11796. +     parsed.
  11797. +
  11798. +   This option is intended only for serious `gawk' developers, and not
  11799. +for the casual user.  It probably has not even been compiled into your
  11800. +version of `gawk', since it slows down execution.
  11801. +
  11802. +
  11803. +File: gawk.info,  Node: Future Extensions,  Next: Improvements,  Prev: Compatibility Mode,  Up: Notes
  11804. +
  11805. +Probable Future Extensions
  11806. +==========================
  11807. +
  11808. +   This section briefly lists extensions that indicate the directions
  11809. +we are currently considering for `gawk'.  The file `FUTURES' in the
  11810. +`gawk' distributions lists these extensions, as well as several others.
  11811. +
  11812. +`RS' as a regexp
  11813. +     The meaning of `RS' may be generalized along the lines of `FS'.
  11814. +
  11815. +Control of subprocess environment
  11816. +     Changes made in `gawk' to the array `ENVIRON' may be propagated to
  11817. +     subprocesses run by `gawk'.
  11818. +
  11819. +Databases
  11820. +     It may be possible to map a GDBM/NDBM/SDBM file into an `awk'
  11821. +     array.
  11822. +
  11823. +Single-character fields
  11824. +     The null string, `""', as a field separator, will cause field
  11825. +     splitting and the `split' function to separate individual
  11826. +     characters.  Thus, `split(a, "abcd", "")' would yield `a[1] ==
  11827. +     "a"', `a[2] == "b"', and so on.
  11828. +
  11829. +More `lint' warnings
  11830. +     There are more things that could be checked for portability.
  11831. +
  11832. +`RECLEN' variable for fixed length records
  11833. +     Along with `FIELDWIDTHS', this would speed up the processing of
  11834. +     fixed-length records.
  11835. +
  11836. +`RT' variable to hold the record terminator
  11837. +     It is occasionally useful to have access to the actual string of
  11838. +     characters that matched the `RS' variable.  The `RT' variable
  11839. +     would hold these characters.
  11840. +
  11841. +A `restart' keyword
  11842. +     After modifying `$0', `restart' would restart the pattern matching
  11843. +     loop, without reading a new record from the input.
  11844. +
  11845. +A `|&' redirection
  11846. +     The `|&' redirection, in place of `|', would open a two-way
  11847. +     pipeline for communication with a sub-process (via `getline' and
  11848. +     `print' and `printf').
  11849. +
  11850. +`IGNORECASE' affecting all comparisons
  11851. +     The effects of the `IGNORECASE' variable may be generalized to all
  11852. +     string comparisons, and not just regular expression operations.
  11853. +
  11854. +A way to mix command line source code and library files
  11855. +     There may be a new option that would make it possible to easily
  11856. +     use library functions from a program entered on the command line.
  11857. +
  11858. +GNU-style long options
  11859. +     We will add GNU-style long options to `gawk' for compatibility
  11860. +     with other GNU programs.  (For example, `--field-separator=:'
  11861. +     would be equivalent to `-F:'.)
  11862. +
  11863. +
  11864. +File: gawk.info,  Node: Improvements,  Prev: Future Extensions,  Up: Notes
  11865. +
  11866. +Suggestions for Improvements
  11867. +============================
  11868. +
  11869. +   Here are some projects that would-be `gawk' hackers might like to
  11870. +take on.  They vary in size from a few days to a few weeks of
  11871. +programming, depending on which one you choose and how fast a
  11872. +programmer you are.  Please send any improvements you write to the
  11873. +maintainers at the GNU project.
  11874. +
  11875. +  1. Compilation of `awk' programs: `gawk' uses a Bison (YACC-like)
  11876. +     parser to convert the script given it into a syntax tree; the
  11877. +     syntax tree is then executed by a simple recursive evaluator.
  11878. +     This method incurs a lot of overhead, since the recursive
  11879. +     evaluator performs many procedure calls to do even the simplest
  11880. +     things.
  11881. +
  11882. +     It should be possible for `gawk' to convert the script's parse tree
  11883. +     into a C program which the user would then compile, using the
  11884. +     normal C compiler and a special `gawk' library to provide all the
  11885. +     needed functions (regexps, fields, associative arrays, type
  11886. +     coercion, and so on).
  11887. +
  11888. +     An easier possibility might be for an intermediate phase of `awk'
  11889. +     to convert the parse tree into a linear byte code form like the
  11890. +     one used in GNU Emacs Lisp.  The recursive evaluator would then be
  11891. +     replaced by a straight line byte code interpreter that would be
  11892. +     intermediate in speed between running a compiled program and doing
  11893. +     what `gawk' does now.
  11894. +
  11895. +     This may actually happen for the 3.0 version of `gawk'.
  11896. +
  11897. +  2. An error message section has not been included in this version of
  11898. +     the manual.  Perhaps some nice beta testers will document some of
  11899. +     the messages for the future.
  11900. +
  11901. +  3. The programs in the test suite could use documenting in this
  11902. +     manual.
  11903. +
  11904. +  4. The programs and data files in the manual should be available in
  11905. +     separate files to facilitate experimentation.
  11906. +
  11907. +  5. See the `FUTURES' file for more ideas.  Contact us if you would
  11908. +     seriously like to tackle any of the items listed there.
  11909. +
  11910. +
  11911. +File: gawk.info,  Node: Glossary,  Next: Index,  Prev: Notes,  Up: Top
  11912. +
  11913. +Glossary
  11914. +********
  11915. +
  11916. +Action
  11917. +     A series of `awk' statements attached to a rule.  If the rule's
  11918. +     pattern matches an input record, the `awk' language executes the
  11919. +     rule's action.  Actions are always enclosed in curly braces.
  11920. +     *Note Overview of Actions: Actions.
  11921. +
  11922. +Amazing `awk' Assembler
  11923. +     Henry Spencer at the University of Toronto wrote a retargetable
  11924. +     assembler completely as `awk' scripts.  It is thousands of lines
  11925. +     long, including machine descriptions for several 8-bit
  11926. +     microcomputers.  It is a good example of a program that would have
  11927. +     been better written in another language.
  11928. +
  11929. +ANSI
  11930. +     The American National Standards Institute.  This organization
  11931. +     produces many standards, among them the standard for the C
  11932. +     programming language.
  11933. +
  11934. +Assignment
  11935. +     An `awk' expression that changes the value of some `awk' variable
  11936. +     or data object.  An object that you can assign to is called an
  11937. +     "lvalue".  *Note Assignment Expressions: Assignment Ops.
  11938. +
  11939. +`awk' Language
  11940. +     The language in which `awk' programs are written.
  11941. +
  11942. +`awk' Program
  11943. +     An `awk' program consists of a series of "patterns" and "actions",
  11944. +     collectively known as "rules".  For each input record given to the
  11945. +     program, the program's rules are all processed in turn.  `awk'
  11946. +     programs may also contain function definitions.
  11947. +
  11948. +`awk' Script
  11949. +     Another name for an `awk' program.
  11950. +
  11951. +Built-in Function
  11952. +     The `awk' language provides built-in functions that perform various
  11953. +     numerical, time stamp related, and string computations.  Examples
  11954. +     are `sqrt' (for the square root of a number) and `substr' (for a
  11955. +     substring of a string).  *Note Built-in Functions: Built-in.
  11956. +
  11957. +Built-in Variable
  11958. +     `ARGC', `ARGIND', `ARGV', `CONVFMT', `ENVIRON', `ERRNO',
  11959. +     `FIELDWIDTHS', `FILENAME', `FNR', `FS', `IGNORECASE', `NF', `NR',
  11960. +     `OFMT', `OFS', `ORS', `RLENGTH', `RSTART', `RS', and `SUBSEP', are
  11961. +     the variables that have special meaning to `awk'.  Changing some
  11962. +     of them affects `awk''s running environment.  *Note Built-in
  11963. +     Variables::.
  11964. +
  11965. +Braces
  11966. +     See "Curly Braces."
  11967. +
  11968. +C
  11969. +     The system programming language that most GNU software is written
  11970. +     in.  The `awk' programming language has C-like syntax, and this
  11971. +     manual points out similarities between `awk' and C when
  11972. +     appropriate.
  11973. +
  11974. +CHEM
  11975. +     A preprocessor for `pic' that reads descriptions of molecules and
  11976. +     produces `pic' input for drawing them.  It was written by Brian
  11977. +     Kernighan, and is available from `netlib@research.att.com'.
  11978. +
  11979. +Compound Statement
  11980. +     A series of `awk' statements, enclosed in curly braces.  Compound
  11981. +     statements may be nested.  *Note Control Statements in Actions:
  11982. +     Statements.
  11983. +
  11984. +Concatenation
  11985. +     Concatenating two strings means sticking them together, one after
  11986. +     another, giving a new string.  For example, the string `foo'
  11987. +     concatenated with the string `bar' gives the string `foobar'.
  11988. +     *Note String Concatenation: Concatenation.
  11989. +
  11990. +Conditional Expression
  11991. +     An expression using the `?:' ternary operator, such as `EXPR1 ?
  11992. +     EXPR2 : EXPR3'.  The expression EXPR1 is evaluated; if the result
  11993. +     is true, the value of the whole expression is the value of EXPR2
  11994. +     otherwise the value is EXPR3.  In either case, only one of EXPR2
  11995. +     and EXPR3 is evaluated.  *Note Conditional Expressions:
  11996. +     Conditional Exp.
  11997. +
  11998. +Constant Regular Expression
  11999. +     A constant regular expression is a regular expression written
  12000. +     within slashes, such as `/foo/'.  This regular expression is chosen
  12001. +     when you write the `awk' program, and cannot be changed doing its
  12002. +     execution.  *Note How to Use Regular Expressions: Regexp Usage.
  12003. +
  12004. +Comparison Expression
  12005. +     A relation that is either true or false, such as `(a < b)'.
  12006. +     Comparison expressions are used in `if', `while', and `for'
  12007. +     statements, and in patterns to select which input records to
  12008. +     process.  *Note Comparison Expressions: Comparison Ops.
  12009. +
  12010. +Curly Braces
  12011. +     The characters `{' and `}'.  Curly braces are used in `awk' for
  12012. +     delimiting actions, compound statements, and function bodies.
  12013. +
  12014. +Data Objects
  12015. +     These are numbers and strings of characters.  Numbers are
  12016. +     converted into strings and vice versa, as needed.  *Note
  12017. +     Conversion of Strings and Numbers: Conversion.
  12018. +
  12019. +Dynamic Regular Expression
  12020. +     A dynamic regular expression is a regular expression written as an
  12021. +     ordinary expression.  It could be a string constant, such as
  12022. +     `"foo"', but it may also be an expression whose value may vary.
  12023. +     *Note How to Use Regular Expressions: Regexp Usage.
  12024. +
  12025. +Escape Sequences
  12026. +     A special sequence of characters used for describing nonprinting
  12027. +     characters, such as `\n' for newline, or `\033' for the ASCII ESC
  12028. +     (escape) character.  *Note Constant Expressions: Constants.
  12029. +
  12030. +Field
  12031. +     When `awk' reads an input record, it splits the record into pieces
  12032. +     separated by whitespace (or by a separator regexp which you can
  12033. +     change by setting the built-in variable `FS').  Such pieces are
  12034. +     called fields.  If the pieces are of fixed length, you can use the
  12035. +     built-in variable `FIELDWIDTHS' to describe their lengths.  *Note
  12036. +     How Input is Split into Records: Records.
  12037. +
  12038. +Format
  12039. +     Format strings are used to control the appearance of output in the
  12040. +     `printf' statement.  Also, data conversions from numbers to strings
  12041. +     are controlled by the format string contained in the built-in
  12042. +     variable `CONVFMT'.  *Note Format-Control Letters: Control Letters.
  12043. +
  12044. +Function
  12045. +     A specialized group of statements often used to encapsulate general
  12046. +     or program-specific tasks.  `awk' has a number of built-in
  12047. +     functions, and also allows you to define your own.  *Note Built-in
  12048. +     Functions: Built-in.  Also, see *Note User-defined Functions:
  12049. +     User-defined.
  12050. +
  12051. +`gawk'
  12052. +     The GNU implementation of `awk'.
  12053. +
  12054. +GNU
  12055. +     "GNU's not Unix".  An on-going project of the Free Software
  12056. +     Foundation to create a complete, freely distributable,
  12057. +     POSIX-compliant computing environment.
  12058. +
  12059. +Input Record
  12060. +     A single chunk of data read in by `awk'.  Usually, an `awk' input
  12061. +     record consists of one line of text.  *Note How Input is Split
  12062. +     into Records: Records.
  12063. +
  12064. +Keyword
  12065. +     In the `awk' language, a keyword is a word that has special
  12066. +     meaning.  Keywords are reserved and may not be used as variable
  12067. +     names.
  12068. +
  12069. +     `awk''s keywords are: `if', `else', `while', `do...while', `for',
  12070. +     `for...in', `break', `continue', `delete', `next', `function',
  12071. +     `func', and `exit'.
  12072. +
  12073. +Lvalue
  12074. +     An expression that can appear on the left side of an assignment
  12075. +     operator.  In most languages, lvalues can be variables or array
  12076. +     elements.  In `awk', a field designator can also be used as an
  12077. +     lvalue.
  12078. +
  12079. +Number
  12080. +     A numeric valued data object.  The `gawk' implementation uses
  12081. +     double precision floating point to represent numbers.
  12082. +
  12083. +Pattern
  12084. +     Patterns tell `awk' which input records are interesting to which
  12085. +     rules.
  12086. +
  12087. +     A pattern is an arbitrary conditional expression against which
  12088. +     input is tested.  If the condition is satisfied, the pattern is
  12089. +     said to "match" the input record.  A typical pattern might compare
  12090. +     the input record against a regular expression.  *Note Patterns::.
  12091. +
  12092. +POSIX
  12093. +     The name for a series of standards being developed by the IEEE
  12094. +     that specify a Portable Operating System interface.  The "IX"
  12095. +     denotes the Unix heritage of these standards.  The main standard
  12096. +     of interest for `awk' users is P1003.2, the Command Language and
  12097. +     Utilities standard.
  12098. +
  12099. +Range (of input lines)
  12100. +     A sequence of consecutive lines from the input file.  A pattern
  12101. +     can specify ranges of input lines for `awk' to process, or it can
  12102. +     specify single lines.  *Note Patterns::.
  12103. +
  12104. +Recursion
  12105. +     When a function calls itself, either directly or indirectly.  If
  12106. +     this isn't clear, refer to the entry for "recursion."
  12107. +
  12108. +Redirection
  12109. +     Redirection means performing input from other than the standard
  12110. +     input stream, or output to other than the standard output stream.
  12111. +
  12112. +     You can redirect the output of the `print' and `printf' statements
  12113. +     to a file or a system command, using the `>', `>>', and `|'
  12114. +     operators.  You can redirect input to the `getline' statement using
  12115. +     the `<' and `|' operators.  *Note Redirecting Output of `print'
  12116. +     and `printf': Redirection.
  12117. +
  12118. +Regular Expression
  12119. +     See "regexp."
  12120. +
  12121. +Regexp
  12122. +     Short for "regular expression".  A regexp is a pattern that
  12123. +     denotes a set of strings, possibly an infinite set.  For example,
  12124. +     the regexp `R.*xp' matches any string starting with the letter `R'
  12125. +     and ending with the letters `xp'.  In `awk', regexps are used in
  12126. +     patterns and in conditional expressions.  Regexps may contain
  12127. +     escape sequences.  *Note Regular Expressions as Patterns: Regexp.
  12128. +
  12129. +Rule
  12130. +     A segment of an `awk' program, that specifies how to process single
  12131. +     input records.  A rule consists of a "pattern" and an "action".
  12132. +     `awk' reads an input record; then, for each rule, if the input
  12133. +     record satisfies the rule's pattern, `awk' executes the rule's
  12134. +     action.  Otherwise, the rule does nothing for that input record.
  12135. +
  12136. +Side Effect
  12137. +     A side effect occurs when an expression has an effect aside from
  12138. +     merely producing a value.  Assignment expressions, increment
  12139. +     expressions and function calls have side effects.  *Note
  12140. +     Assignment Expressions: Assignment Ops.
  12141. +
  12142. +Special File
  12143. +     A file name interpreted internally by `gawk', instead of being
  12144. +     handed directly to the underlying operating system.  For example,
  12145. +     `/dev/stdin'.  *Note Standard I/O Streams: Special Files.
  12146. +
  12147. +Stream Editor
  12148. +     A program that reads records from an input stream and processes
  12149. +     them one or more at a time.  This is in contrast with batch
  12150. +     programs, which may expect to read their input files in entirety
  12151. +     before starting to do anything, and with interactive programs,
  12152. +     which require input from the user.
  12153. +
  12154. +String
  12155. +     A datum consisting of a sequence of characters, such as `I am a
  12156. +     string'.  Constant strings are written with double-quotes in the
  12157. +     `awk' language, and may contain escape sequences.  *Note Constant
  12158. +     Expressions: Constants.
  12159. +
  12160. +Whitespace
  12161. +     A sequence of blank or tab characters occurring inside an input
  12162. +     record or a string.
  12163. +
  12164. diff -rup --new-file baseline/fsf/gawk/gawk.info-9 amiga/fsf/gawk/gawk.info-9
  12165. --- baseline/fsf/gawk/gawk.info-9    Wed Dec 31 17:00:00 1969
  12166. +++ amiga/fsf/gawk/gawk.info-9    Sat Sep 28 00:00:00 1996
  12167. @@ -0,0 +1,359 @@
  12168. +This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  12169. +file /gnu-src/gawk-2.15.6/gawk.texi.
  12170. +
  12171. +   This file documents `awk', a program that you can use to select
  12172. +particular records in a file and perform operations upon them.
  12173. +
  12174. +   This is Edition 0.15 of `The GAWK Manual',
  12175. +for the 2.15 version of the GNU implementation
  12176. +of AWK.
  12177. +
  12178. +   Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  12179. +
  12180. +   Permission is granted to make and distribute verbatim copies of this
  12181. +manual provided the copyright notice and this permission notice are
  12182. +preserved on all copies.
  12183. +
  12184. +   Permission is granted to copy and distribute modified versions of
  12185. +this manual under the conditions for verbatim copying, provided that
  12186. +the entire resulting derived work is distributed under the terms of a
  12187. +permission notice identical to this one.
  12188. +
  12189. +   Permission is granted to copy and distribute translations of this
  12190. +manual into another language, under the above conditions for modified
  12191. +versions, except that this permission notice may be stated in a
  12192. +translation approved by the Foundation.
  12193. +
  12194. +
  12195. +File: gawk.info,  Node: Index,  Prev: Glossary,  Up: Top
  12196. +
  12197. +Index
  12198. +*****
  12199. +
  12200. +* Menu:
  12201. +
  12202. +* $ (field operator):                   Fields.
  12203. +* -assign option:                       Options.
  12204. +* -compat option:                       Options.
  12205. +* -copyleft option:                     Options.
  12206. +* -copyright option:                    Options.
  12207. +* -field-separator option:              Options.
  12208. +* -file option:                         Options.
  12209. +* -help option:                         Options.
  12210. +* -lint option:                         Options.
  12211. +* -posix option:                        Options.
  12212. +* -source option:                       Options.
  12213. +* -usage option:                        Options.
  12214. +* -version option:                      Options.
  12215. +* AWKPATH environment variable:         AWKPATH Variable.
  12216. +* awk language:                         This Manual.
  12217. +* awk program:                          This Manual.
  12218. +* BEGIN special pattern:                BEGIN/END.
  12219. +* break statement:                      Break Statement.
  12220. +* continue statement:                   Continue Statement.
  12221. +* delete statement:                     Delete.
  12222. +* END special pattern:                  BEGIN/END.
  12223. +* exit statement:                       Exit Statement.
  12224. +* for (x in ...):                       Scanning an Array.
  12225. +* for statement:                        For Statement.
  12226. +* if statement:                         If Statement.
  12227. +* next file statement:                  Next File Statement.
  12228. +* next statement:                       Next Statement.
  12229. +* printf statement, syntax of:          Basic Printf.
  12230. +* printf, format-control characters:    Control Letters.
  12231. +* printf, modifiers:                    Format Modifiers.
  12232. +* print statement:                      Print.
  12233. +* return statement:                     Return Statement.
  12234. +* while statement:                      While Statement.
  12235. +* /dev/fd/:                             Special Files.
  12236. +* /dev/pgrpid:                          Special Files.
  12237. +* /dev/pid:                             Special Files.
  12238. +* /dev/ppid:                            Special Files.
  12239. +* /dev/stderr:                          Special Files.
  12240. +* /dev/stdin:                           Special Files.
  12241. +* /dev/stdout:                          Special Files.
  12242. +* /dev/user:                            Special Files.
  12243. +* BBS-list file:                        Sample Data Files.
  12244. +* inventory-shipped file:               Sample Data Files.
  12245. +* #!:                                   Executable Scripts.
  12246. +* #:                                    Comments.
  12247. +* -F option:                            Field Separators.
  12248. +* -f option:                            Long.
  12249. +* -v option:                            Options.
  12250. +* -W option:                            Options.
  12251. +* print $0:                             Very Simple.
  12252. +* accessing fields:                     Fields.
  12253. +* acronym:                              History.
  12254. +* action, curly braces:                 Actions.
  12255. +* action, default:                      Very Simple.
  12256. +* action, definition of:                Actions.
  12257. +* action, separating statements:        Actions.
  12258. +* addition:                             Arithmetic Ops.
  12259. +* and operator:                         Boolean Ops.
  12260. +* anonymous ftp:                        Extracting.
  12261. +* anonymous uucp:                       Extracting.
  12262. +* applications of awk:                  When.
  12263. +* ARGIND:                               Auto-set.
  12264. +* arguments in function call:           Function Calls.
  12265. +* arguments, command line:              Command Line.
  12266. +* ARGV:                                 Other Arguments.
  12267. +* arithmetic operators:                 Arithmetic Ops.
  12268. +* array assignment:                     Assigning Elements.
  12269. +* array reference:                      Reference to Elements.
  12270. +* arrays:                               Array Intro.
  12271. +* arrays, definition of:                Array Intro.
  12272. +* arrays, deleting an element:          Delete.
  12273. +* arrays, multi-dimensional subscripts: Multi-dimensional.
  12274. +* arrays, presence of elements:         Reference to Elements.
  12275. +* arrays, special for statement:        Scanning an Array.
  12276. +* assignment operators:                 Assignment Ops.
  12277. +* assignment to fields:                 Changing Fields.
  12278. +* associative arrays:                   Array Intro.
  12279. +* backslash continuation:               Statements/Lines.
  12280. +* basic function of gawk:               Getting Started.
  12281. +* body of a loop:                       While Statement.
  12282. +* boolean expressions:                  Boolean Ops.
  12283. +* boolean operators:                    Boolean Ops.
  12284. +* boolean patterns:                     Boolean Patterns.
  12285. +* buffering output:                     I/O Functions.
  12286. +* buffers, flushing:                    I/O Functions.
  12287. +* built-in functions:                   Built-in.
  12288. +* built-in variables:                   Built-in Variables.
  12289. +* built-in variables, user modifiable:  User-modified.
  12290. +* call by reference:                    Function Caveats.
  12291. +* call by value:                        Function Caveats.
  12292. +* calling a function:                   Function Calls.
  12293. +* case sensitivity:                     Read Terminal.
  12294. +* changing contents of a field:         Changing Fields.
  12295. +* close:                                Close Input.
  12296. +* close:                                Close Output.
  12297. +* closing input files and pipes:        Close Input.
  12298. +* closing output files and pipes:       Close Output.
  12299. +* command line:                         Command Line.
  12300. +* command line formats:                 Running gawk.
  12301. +* command line, setting FS on:          Field Separators.
  12302. +* comments:                             Comments.
  12303. +* comparison expressions:               Comparison Ops.
  12304. +* comparison expressions as patterns:   Comparison Patterns.
  12305. +* computed regular expressions:         Regexp Usage.
  12306. +* concatenation:                        Concatenation.
  12307. +* conditional expression:               Conditional Exp.
  12308. +* constants, types of:                  Constants.
  12309. +* continuation of lines:                Statements/Lines.
  12310. +* control statement:                    Statements.
  12311. +* conversion of strings and numbers:    Conversion.
  12312. +* conversion of strings and numbers:    Values.
  12313. +* conversions, during subscripting:     Numeric Array Subscripts.
  12314. +* CONVFMT:                              Numeric Array Subscripts.
  12315. +* CONVFMT:                              Comparison Ops.
  12316. +* CONVFMT:                              Conversion.
  12317. +* curly braces:                         Actions.
  12318. +* default action:                       Very Simple.
  12319. +* default pattern:                      Very Simple.
  12320. +* defining functions:                   Definition Syntax.
  12321. +* deleting elements of arrays:          Delete.
  12322. +* deprecated features:                  Obsolete.
  12323. +* deprecated options:                   Obsolete.
  12324. +* differences: gawk and awk:            Getline.
  12325. +* directory search:                     AWKPATH Variable.
  12326. +* division:                             Arithmetic Ops.
  12327. +* documenting awk programs:             Comments.
  12328. +* dynamic regular expressions:          Regexp Usage.
  12329. +* element assignment:                   Assigning Elements.
  12330. +* element of array:                     Reference to Elements.
  12331. +* empty pattern:                        Empty.
  12332. +* ENVIRON:                              Auto-set.
  12333. +* ERRNO:                                Getline.
  12334. +* escape sequence notation:             Constants.
  12335. +* examining fields:                     Fields.
  12336. +* executable scripts:                   Executable Scripts.
  12337. +* explicit input:                       Getline.
  12338. +* exponentiation:                       Arithmetic Ops.
  12339. +* expression:                           Expressions.
  12340. +* expression, conditional:              Conditional Exp.
  12341. +* expressions, assignment:              Assignment Ops.
  12342. +* expressions, boolean:                 Boolean Ops.
  12343. +* expressions, comparison:              Comparison Ops.
  12344. +* field separator, FS:                  Field Separators.
  12345. +* field separator, choice of:           Field Separators.
  12346. +* field separator: on command line:     Field Separators.
  12347. +* field, changing contents of:          Changing Fields.
  12348. +* fields:                               Fields.
  12349. +* fields, separating:                   Field Separators.
  12350. +* file descriptors:                     Special Files.
  12351. +* file, awk program:                    Long.
  12352. +* FILENAME:                             Reading Files.
  12353. +* flushing buffers:                     I/O Functions.
  12354. +* FNR:                                  Records.
  12355. +* format specifier:                     Control Letters.
  12356. +* format string:                        Basic Printf.
  12357. +* formatted output:                     Printf.
  12358. +* FS:                                   Field Separators.
  12359. +* ftp, anonymous:                       Extracting.
  12360. +* function call:                        Function Calls.
  12361. +* function definition:                  Definition Syntax.
  12362. +* functions, user-defined:              User-defined.
  12363. +* getline:                              Getline.
  12364. +* getting gawk:                         Extracting.
  12365. +* gsub:                                 String Functions.
  12366. +* history of awk:                       History.
  12367. +* how awk works:                        Two Rules.
  12368. +* increment operators:                  Increment Ops.
  12369. +* input:                                Reading Files.
  12370. +* input file, sample:                   Sample Data Files.
  12371. +* input redirection:                    Getline.
  12372. +* input, getline command:               Getline.
  12373. +* input, explicit:                      Getline.
  12374. +* input, multiple line records:         Multiple Line.
  12375. +* input, standard:                      Read Terminal.
  12376. +* installation, atari:                  Atari Installation.
  12377. +* installation, ms-dos:                 MS-DOS Installation.
  12378. +* installation, unix:                   Quick Installation.
  12379. +* installation, vms:                    VMS Installation.
  12380. +* interaction, awk and other programs:  I/O Functions.
  12381. +* invocation of gawk:                   Command Line.
  12382. +* language, awk:                        This Manual.
  12383. +* length:                               String Functions.
  12384. +* logical operations:                   Boolean Ops.
  12385. +* long options:                         Command Line.
  12386. +* loop:                                 While Statement.
  12387. +* loops, exiting:                       Break Statement.
  12388. +* lvalue:                               Assignment Ops.
  12389. +* manual, using this:                   This Manual.
  12390. +* match:                                String Functions.
  12391. +* match:                                String Functions.
  12392. +* metacharacters:                       Regexp Operators.
  12393. +* modifiers (in format specifiers):     Format Modifiers.
  12394. +* multi-dimensional subscripts:         Multi-dimensional.
  12395. +* multiple line records:                Multiple Line.
  12396. +* multiple passes over data:            Other Arguments.
  12397. +* multiple statements on one line:      Statements/Lines.
  12398. +* multiplication:                       Arithmetic Ops.
  12399. +* NF:                                   Fields.
  12400. +* not operator:                         Boolean Ops.
  12401. +* NR:                                   Records.
  12402. +* number of fields, NF:                 Fields.
  12403. +* number of records, NR or FNR:         Records.
  12404. +* numbers, used as subscripts:          Numeric Array Subscripts.
  12405. +* numeric constant:                     Constants.
  12406. +* numeric value:                        Constants.
  12407. +* obsolete features:                    Obsolete.
  12408. +* obsolete options:                     Obsolete.
  12409. +* OFMT:                                 Conversion.
  12410. +* OFMT:                                 OFMT.
  12411. +* OFS:                                  Output Separators.
  12412. +* one-liners:                           One-liners.
  12413. +* operator precedence:                  Precedence.
  12414. +* operators, $:                         Fields.
  12415. +* operators, arithmetic:                Arithmetic Ops.
  12416. +* operators, assignment:                Assignment Ops.
  12417. +* operators, boolean:                   Boolean Ops.
  12418. +* operators, increment:                 Increment Ops.
  12419. +* operators, regexp matching:           Regexp Usage.
  12420. +* operators, relational:                Comparison Patterns.
  12421. +* operators, relational:                Comparison Ops.
  12422. +* operators, string:                    Concatenation.
  12423. +* operators, string-matching:           Regexp Usage.
  12424. +* options, command line:                Command Line.
  12425. +* options, long:                        Command Line.
  12426. +* or operator:                          Boolean Ops.
  12427. +* ORS:                                  Output Separators.
  12428. +* output:                               Printing.
  12429. +* output field separator, OFS:          Output Separators.
  12430. +* output record separator, ORS:         Output Separators.
  12431. +* output redirection:                   Redirection.
  12432. +* output, buffering:                    I/O Functions.
  12433. +* output, formatted:                    Printf.
  12434. +* output, piping:                       File/Pipe Redirection.
  12435. +* passes, multiple:                     Other Arguments.
  12436. +* path, search:                         AWKPATH Variable.
  12437. +* pattern, case sensitive:              Read Terminal.
  12438. +* pattern, comparison expressions:      Comparison Patterns.
  12439. +* pattern, default:                     Very Simple.
  12440. +* pattern, definition of:               Patterns.
  12441. +* pattern, empty:                       Empty.
  12442. +* pattern, regular expressions:         Regexp.
  12443. +* patterns, BEGIN:                      BEGIN/END.
  12444. +* patterns, END:                        BEGIN/END.
  12445. +* patterns, boolean:                    Boolean Patterns.
  12446. +* patterns, range:                      Ranges.
  12447. +* patterns, types of:                   Kinds of Patterns.
  12448. +* pipes for output:                     File/Pipe Redirection.
  12449. +* precedence:                           Precedence.
  12450. +* printing:                             Printing.
  12451. +* program file:                         Long.
  12452. +* program, awk:                         This Manual.
  12453. +* program, definition of:               Getting Started.
  12454. +* program, self contained:              Executable Scripts.
  12455. +* programs, documenting:                Comments.
  12456. +* quotient:                             Arithmetic Ops.
  12457. +* range pattern:                        Ranges.
  12458. +* reading files:                        Reading Files.
  12459. +* reading files, getline command:       Getline.
  12460. +* reading files, multiple line records: Multiple Line.
  12461. +* record separator:                     Records.
  12462. +* records, multiple line:               Multiple Line.
  12463. +* redirection of input:                 Getline.
  12464. +* redirection of output:                Redirection.
  12465. +* reference to array:                   Reference to Elements.
  12466. +* regexp:                               Regexp.
  12467. +* regexp as expression:                 Comparison Ops.
  12468. +* regexp operators:                     Comparison Ops.
  12469. +* regexp search operators:              Regexp Usage.
  12470. +* regular expression matching operators: Regexp Usage.
  12471. +* regular expression metacharacters:    Regexp Operators.
  12472. +* regular expressions as field separators: Field Separators.
  12473. +* regular expressions as patterns:      Regexp.
  12474. +* regular expressions, computed:        Regexp Usage.
  12475. +* relational operators:                 Comparison Ops.
  12476. +* relational operators:                 Comparison Patterns.
  12477. +* remainder:                            Arithmetic Ops.
  12478. +* removing elements of arrays:          Delete.
  12479. +* RLENGTH:                              String Functions.
  12480. +* RS:                                   Records.
  12481. +* RSTART:                               String Functions.
  12482. +* rule, definition of:                  Getting Started.
  12483. +* running awk programs:                 Running gawk.
  12484. +* running long programs:                Long.
  12485. +* sample input file:                    Sample Data Files.
  12486. +* scanning an array:                    Scanning an Array.
  12487. +* script, definition of:                Getting Started.
  12488. +* scripts, executable:                  Executable Scripts.
  12489. +* scripts, shell:                       Executable Scripts.
  12490. +* search path:                          AWKPATH Variable.
  12491. +* self contained programs:              Executable Scripts.
  12492. +* shell scripts:                        Executable Scripts.
  12493. +* side effect:                          Assignment Ops.
  12494. +* single quotes, why needed:            One-shot.
  12495. +* split:                                String Functions.
  12496. +* sprintf:                              String Functions.
  12497. +* standard error output:                Special Files.
  12498. +* standard input:                       Read Terminal.
  12499. +* standard input:                       Reading Files.
  12500. +* standard input:                       Special Files.
  12501. +* standard output:                      Special Files.
  12502. +* strftime:                             Time Functions.
  12503. +* string constants:                     Constants.
  12504. +* string operators:                     Concatenation.
  12505. +* string-matching operators:            Regexp Usage.
  12506. +* sub:                                  String Functions.
  12507. +* subscripts in arrays:                 Multi-dimensional.
  12508. +* SUBSEP:                               Multi-dimensional.
  12509. +* substr:                               String Functions.
  12510. +* subtraction:                          Arithmetic Ops.
  12511. +* system:                               I/O Functions.
  12512. +* systime:                              Time Functions.
  12513. +* time of day:                          Time Functions.
  12514. +* time stamps:                          Time Functions.
  12515. +* tolower:                              String Functions.
  12516. +* toupper:                              String Functions.
  12517. +* use of comments:                      Comments.
  12518. +* user-defined functions:               User-defined.
  12519. +* user-defined variables:               Variables.
  12520. +* uses of awk:                          Preface.
  12521. +* using this manual:                    This Manual.
  12522. +* uucp, anonymous:                      Extracting.
  12523. +* variables, user-defined:              Variables.
  12524. +* when to use awk:                      When.
  12525. +
  12526. +
  12527. diff -rup --new-file baseline/fsf/gawk/gawk.texi amiga/fsf/gawk/gawk.texi
  12528. --- baseline/fsf/gawk/gawk.texi    Thu May  6 10:37:11 1993
  12529. +++ amiga/fsf/gawk/gawk.texi    Sat Sep 28 00:00:00 1996
  12530. @@ -7567,7 +7567,7 @@ Today is Thursday, July 11, 1991.
  12531.  Here is the @code{awk} version of the @code{date} utility.
  12532.  
  12533.  @smallexample
  12534. -#! /usr/bin/gawk -f
  12535. +#! /bin/gawk -f
  12536.  #
  12537.  # date --- implement the P1003.2 Draft 11 'date' command
  12538.  #
  12539. @@ -8555,7 +8555,7 @@ The search path is actually a string con
  12540.  separated by colons.  @code{gawk} gets its search path from the
  12541.  @code{AWKPATH} environment variable.  If that variable does not exist,
  12542.  @code{gawk} uses the default path, which is
  12543. -@samp{.:/usr/lib/awk:/usr/local/lib/awk}.  (Programs written by
  12544. +@samp{.:/local/lib/awk:/gnu/lib/awk}.  (Programs written by
  12545.  system administrators should use an @code{AWKPATH} variable that
  12546.  does not include the current directory, @samp{.}.)@refill
  12547.  
  12548. @@ -9674,7 +9674,7 @@ then type your program, and end it with 
  12549.  The environment variable @code{AWKPATH} specifies a search path to use
  12550.  when finding source files named with the @samp{-f} option.  The default
  12551.  path, which is
  12552. -@samp{.:/usr/lib/awk:/usr/local/lib/awk} is used if @code{AWKPATH} is not set.
  12553. +@samp{.:/local/lib/awk:/gnu/lib/awk} is used if @code{AWKPATH} is not set.
  12554.  If a file name given to the @samp{-f} option contains a @samp{/} character,
  12555.  no path search is performed.
  12556.  @xref{AWKPATH Variable, ,The @code{AWKPATH} Environment Variable},
  12557. diff -rup --new-file baseline/fsf/gawk/install.sh amiga/fsf/gawk/install.sh
  12558. --- baseline/fsf/gawk/install.sh    Wed Dec 31 17:00:00 1969
  12559. +++ amiga/fsf/gawk/install.sh    Sat Sep 28 00:00:00 1996
  12560. @@ -0,0 +1,236 @@
  12561. +#!/bin/sh
  12562. +#
  12563. +# install - install a program, script, or datafile
  12564. +# This comes from X11R5.
  12565. +#
  12566. +# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
  12567. +#
  12568. +# This script is compatible with the BSD install script, but was written
  12569. +# from scratch.
  12570. +#
  12571. +
  12572. +
  12573. +# set DOITPROG to echo to test this script
  12574. +
  12575. +# Don't use :- since 4.3BSD and earlier shells don't like it.
  12576. +doit="${DOITPROG-}"
  12577. +
  12578. +
  12579. +# put in absolute paths if you don't have them in your path; or use env. vars.
  12580. +
  12581. +mvprog="${MVPROG-mv}"
  12582. +cpprog="${CPPROG-cp}"
  12583. +chmodprog="${CHMODPROG-chmod}"
  12584. +chownprog="${CHOWNPROG-chown}"
  12585. +chgrpprog="${CHGRPPROG-chgrp}"
  12586. +stripprog="${STRIPPROG-strip}"
  12587. +rmprog="${RMPROG-rm}"
  12588. +mkdirprog="${MKDIRPROG-mkdir}"
  12589. +
  12590. +tranformbasename=""
  12591. +transform_arg=""
  12592. +instcmd="$mvprog"
  12593. +chmodcmd="$chmodprog 0755"
  12594. +chowncmd=""
  12595. +chgrpcmd=""
  12596. +stripcmd=""
  12597. +rmcmd="$rmprog -f"
  12598. +mvcmd="$mvprog"
  12599. +src=""
  12600. +dst=""
  12601. +dir_arg=""
  12602. +
  12603. +while [ x"$1" != x ]; do
  12604. +    case $1 in
  12605. +    -c) instcmd="$cpprog"
  12606. +        shift
  12607. +        continue;;
  12608. +
  12609. +    -d) dir_arg=true
  12610. +        shift
  12611. +        continue;;
  12612. +
  12613. +    -m) chmodcmd="$chmodprog $2"
  12614. +        shift
  12615. +        shift
  12616. +        continue;;
  12617. +
  12618. +    -o) chowncmd="$chownprog $2"
  12619. +        shift
  12620. +        shift
  12621. +        continue;;
  12622. +
  12623. +    -g) chgrpcmd="$chgrpprog $2"
  12624. +        shift
  12625. +        shift
  12626. +        continue;;
  12627. +
  12628. +    -s) stripcmd="$stripprog"
  12629. +        shift
  12630. +        continue;;
  12631. +
  12632. +    -t=*) transformarg=`echo $1 | sed 's/-t=//'`
  12633. +        shift
  12634. +        continue;;
  12635. +
  12636. +    -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
  12637. +        shift
  12638. +        continue;;
  12639. +
  12640. +    *)  if [ x"$src" = x ]
  12641. +        then
  12642. +        src=$1
  12643. +        else
  12644. +        # this colon is to work around a 386BSD /bin/sh bug
  12645. +        :
  12646. +        dst=$1
  12647. +        fi
  12648. +        shift
  12649. +        continue;;
  12650. +    esac
  12651. +done
  12652. +
  12653. +if [ x"$src" = x ]
  12654. +then
  12655. +    echo "install:    no input file specified"
  12656. +    exit 1
  12657. +else
  12658. +    true
  12659. +fi
  12660. +
  12661. +if [ x"$dir_arg" != x ]; then
  12662. +    dst=$src
  12663. +    src=""
  12664. +    
  12665. +    if [ -d $dst ]; then
  12666. +        instcmd=:
  12667. +    else
  12668. +        instcmd=mkdir
  12669. +    fi
  12670. +else
  12671. +
  12672. +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
  12673. +# might cause directories to be created, which would be especially bad 
  12674. +# if $src (and thus $dsttmp) contains '*'.
  12675. +
  12676. +    if [ -f $src -o -d $src ]
  12677. +    then
  12678. +        true
  12679. +    else
  12680. +        echo "install:  $src does not exist"
  12681. +        exit 1
  12682. +    fi
  12683. +    
  12684. +    if [ x"$dst" = x ]
  12685. +    then
  12686. +        echo "install:    no destination specified"
  12687. +        exit 1
  12688. +    else
  12689. +        true
  12690. +    fi
  12691. +
  12692. +# If destination is a directory, append the input filename; if your system
  12693. +# does not like double slashes in filenames, you may need to add some logic
  12694. +
  12695. +    if [ -d $dst ]
  12696. +    then
  12697. +        dst="$dst"/`basename $src`
  12698. +    else
  12699. +        true
  12700. +    fi
  12701. +fi
  12702. +
  12703. +## this sed command emulates the dirname command
  12704. +dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
  12705. +
  12706. +# Make sure that the destination directory exists.
  12707. +#  this part is taken from Noah Friedman's mkinstalldirs script
  12708. +
  12709. +# Skip lots of stat calls in the usual case.
  12710. +if [ ! -d "$dstdir" ]; then
  12711. +defaultIFS='    
  12712. +'
  12713. +IFS="${IFS-${defaultIFS}}"
  12714. +
  12715. +oIFS="${IFS}"
  12716. +# Some sh's can't handle IFS=/ for some reason.
  12717. +IFS='%'
  12718. +set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
  12719. +IFS="${oIFS}"
  12720. +
  12721. +pathcomp=''
  12722. +
  12723. +while [ $# -ne 0 ] ; do
  12724. +    pathcomp="${pathcomp}${1}"
  12725. +    shift
  12726. +
  12727. +    if [ ! -d "${pathcomp}" ] ;
  12728. +        then
  12729. +        $mkdirprog "${pathcomp}"
  12730. +    else
  12731. +        true
  12732. +    fi
  12733. +
  12734. +    pathcomp="${pathcomp}/"
  12735. +done
  12736. +fi
  12737. +
  12738. +if [ x"$dir_arg" != x ]
  12739. +then
  12740. +    $doit $instcmd $dst &&
  12741. +
  12742. +    if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
  12743. +    if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
  12744. +    if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
  12745. +    if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
  12746. +else
  12747. +
  12748. +# If we're going to rename the final executable, determine the name now.
  12749. +
  12750. +    if [ x"$transformarg" = x ] 
  12751. +    then
  12752. +        dstfile=`basename $dst`
  12753. +    else
  12754. +        dstfile=`basename $dst $transformbasename | 
  12755. +            sed $transformarg`$transformbasename
  12756. +    fi
  12757. +
  12758. +# don't allow the sed command to completely eliminate the filename
  12759. +
  12760. +    if [ x"$dstfile" = x ] 
  12761. +    then
  12762. +        dstfile=`basename $dst`
  12763. +    else
  12764. +        true
  12765. +    fi
  12766. +
  12767. +# Make a temp file name in the proper directory.
  12768. +
  12769. +    dsttmp=$dstdir/#inst.$$#
  12770. +
  12771. +# Move or copy the file name to the temp name
  12772. +
  12773. +    $doit $instcmd $src $dsttmp &&
  12774. +
  12775. +    trap "rm -f ${dsttmp}" 0 &&
  12776. +
  12777. +# and set any options; do chmod last to preserve setuid bits
  12778. +
  12779. +# If any of these fail, we abort the whole thing.  If we want to
  12780. +# ignore errors from any of these, just make sure not to ignore
  12781. +# errors from the above "$doit $instcmd $src $dsttmp" command.
  12782. +
  12783. +    if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
  12784. +    if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
  12785. +    if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
  12786. +    if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
  12787. +
  12788. +# Now rename the file to the real destination.
  12789. +
  12790. +    $doit $rmcmd -f $dstdir/$dstfile &&
  12791. +    $doit $mvcmd $dsttmp $dstdir/$dstfile 
  12792. +
  12793. +fi &&
  12794. +
  12795. +
  12796. +exit 0
  12797. diff -rup --new-file baseline/fsf/gawk/io.c amiga/fsf/gawk/io.c
  12798. --- baseline/fsf/gawk/io.c    Thu Mar  9 09:28:01 1995
  12799. +++ amiga/fsf/gawk/io.c    Sat Sep 28 00:00:00 1996
  12800. @@ -563,8 +563,10 @@ flush_io ()
  12801.          status++;
  12802.      }
  12803.      if (fflush(stderr)) {
  12804. +#ifndef __amigaos__  /* HACK (fnf) */
  12805.          warning("error writing standard error (%s).", strerror(errno));
  12806.          status++;
  12807. +#endif
  12808.      }
  12809.      for (rp = red_head; rp != NULL; rp = rp->next)
  12810.          /* flush both files and pipes, what the heck */
  12811. @@ -605,8 +607,10 @@ close_io ()
  12812.          status++;
  12813.      }
  12814.      if (fflush(stderr)) {
  12815. +#ifndef __amigaos__  /* HACK (fnf) */
  12816.          warning("error writing standard error (%s).", strerror(errno));
  12817.          status++;
  12818. +#endif
  12819.      }
  12820.      return status;
  12821.  }
  12822. @@ -917,7 +921,7 @@ static int
  12823.  wait_any(interesting)
  12824.  int interesting;    /* pid of interest, if any */
  12825.  {
  12826. -    SIGTYPE (*hstat)(), (*istat)(), (*qstat)();
  12827. +    RETSIGTYPE (*hstat)(), (*istat)(), (*qstat)();
  12828.      int pid;
  12829.      int status = 0;
  12830.      struct redirect *redp;
  12831. diff -rup --new-file baseline/fsf/gawk/main.c amiga/fsf/gawk/main.c
  12832. --- baseline/fsf/gawk/main.c    Thu Mar  9 09:28:15 1995
  12833. +++ amiga/fsf/gawk/main.c    Sat Sep 28 00:00:00 1996
  12834. @@ -33,7 +33,7 @@ static void cmdline_fs P((char *str));
  12835.  static void init_args P((int argc0, int argc, char *argv0, char **argv));
  12836.  static void init_vars P((void));
  12837.  static void pre_assign P((char *v));
  12838. -SIGTYPE catchsig P((int sig, int code));
  12839. +RETSIGTYPE catchsig P((int sig, int code));
  12840.  static void gawk_option P((char *optstr));
  12841.  static void nostalgia P((void));
  12842.  static void version P((void));
  12843. @@ -152,10 +152,10 @@ char **argv;
  12844.      setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
  12845.  #endif
  12846.  
  12847. -    (void) signal(SIGFPE,  (SIGTYPE (*) P((int))) catchsig);
  12848. -    (void) signal(SIGSEGV, (SIGTYPE (*) P((int))) catchsig);
  12849. +    (void) signal(SIGFPE,  (RETSIGTYPE (*) P((int))) catchsig);
  12850. +    (void) signal(SIGSEGV, (RETSIGTYPE (*) P((int))) catchsig);
  12851.  #ifdef SIGBUS
  12852. -    (void) signal(SIGBUS,  (SIGTYPE (*) P((int))) catchsig);
  12853. +    (void) signal(SIGBUS,  (RETSIGTYPE (*) P((int))) catchsig);
  12854.  #endif
  12855.  
  12856.      myname = gawk_name(argv[0]);
  12857. @@ -642,7 +642,7 @@ char *v;
  12858.      }
  12859.  }
  12860.  
  12861. -SIGTYPE
  12862. +RETSIGTYPE
  12863.  catchsig(sig, code)
  12864.  int sig, code;
  12865.  {
  12866. diff -rup --new-file baseline/fsf/gawk/manifests/bin amiga/fsf/gawk/manifests/bin
  12867. --- baseline/fsf/gawk/manifests/bin    Wed Dec 31 17:00:00 1969
  12868. +++ amiga/fsf/gawk/manifests/bin    Sat Sep 28 00:00:00 1996
  12869. @@ -0,0 +1,15 @@
  12870. +COPYING
  12871. +COPYING.info
  12872. +bin/awk
  12873. +bin/gawk
  12874. +info/gawk.info
  12875. +info/gawk.info-1
  12876. +info/gawk.info-2
  12877. +info/gawk.info-3
  12878. +info/gawk.info-4
  12879. +info/gawk.info-5
  12880. +info/gawk.info-6
  12881. +info/gawk.info-7
  12882. +info/gawk.info-8
  12883. +info/gawk.info-9
  12884. +man/man1/gawk.1
  12885. diff -rup --new-file baseline/fsf/gawk/manifests/src amiga/fsf/gawk/manifests/src
  12886. --- baseline/fsf/gawk/manifests/src    Wed Dec 31 17:00:00 1969
  12887. +++ amiga/fsf/gawk/manifests/src    Sat Sep 28 00:00:00 1996
  12888. @@ -0,0 +1,275 @@
  12889. +fsf/gawk/ACKNOWLEDGMENT
  12890. +fsf/gawk/COPYING
  12891. +fsf/gawk/FUTURES
  12892. +fsf/gawk/INSTALL
  12893. +fsf/gawk/LIMITATIONS
  12894. +fsf/gawk/Makefile.bsd44
  12895. +fsf/gawk/Makefile.cline
  12896. +fsf/gawk/Makefile.dec
  12897. +fsf/gawk/Makefile.in
  12898. +fsf/gawk/NEWS
  12899. +fsf/gawk/PORTS
  12900. +fsf/gawk/POSIX
  12901. +fsf/gawk/PROBLEMS
  12902. +fsf/gawk/Product-Info
  12903. +fsf/gawk/README
  12904. +fsf/gawk/README.FIRST
  12905. +fsf/gawk/README.VMS
  12906. +fsf/gawk/README.amiga
  12907. +fsf/gawk/README.atari
  12908. +fsf/gawk/README.hpux8x
  12909. +fsf/gawk/README.pc
  12910. +fsf/gawk/README.rs6000
  12911. +fsf/gawk/README.rt-aos
  12912. +fsf/gawk/README.sgi
  12913. +fsf/gawk/README.sun386i
  12914. +fsf/gawk/README.ultrix
  12915. +fsf/gawk/README.yacc
  12916. +fsf/gawk/alloca.c
  12917. +fsf/gawk/alloca.s
  12918. +fsf/gawk/array.c
  12919. +fsf/gawk/atari/Makefile.st
  12920. +fsf/gawk/atari/config.h
  12921. +fsf/gawk/atari/mkconf.g
  12922. +fsf/gawk/atari/mkscrpt.sed
  12923. +fsf/gawk/atari/stack.c
  12924. +fsf/gawk/atari/system.c
  12925. +fsf/gawk/atari/tmpnam.c
  12926. +fsf/gawk/awk.h
  12927. +fsf/gawk/awk.y
  12928. +fsf/gawk/awktab.c
  12929. +fsf/gawk/builtin.c
  12930. +fsf/gawk/config.h.in
  12931. +fsf/gawk/config.in
  12932. +fsf/gawk/config/amigaos
  12933. +fsf/gawk/config/apollo
  12934. +fsf/gawk/config/atari
  12935. +fsf/gawk/config/bsd42
  12936. +fsf/gawk/config/bsd43
  12937. +fsf/gawk/config/bsd43r
  12938. +fsf/gawk/config/bsd43t
  12939. +fsf/gawk/config/bsd44
  12940. +fsf/gawk/config/convex
  12941. +fsf/gawk/config/cray
  12942. +fsf/gawk/config/cray2-50
  12943. +fsf/gawk/config/cray2-60
  12944. +fsf/gawk/config/cray60
  12945. +fsf/gawk/config/gnu
  12946. +fsf/gawk/config/hiosf1
  12947. +fsf/gawk/config/hiuxwe2
  12948. +fsf/gawk/config/hpux7.0
  12949. +fsf/gawk/config/hpux8x
  12950. +fsf/gawk/config/ibmrt-aos
  12951. +fsf/gawk/config/interactive2.2
  12952. +fsf/gawk/config/linux
  12953. +fsf/gawk/config/lynxos
  12954. +fsf/gawk/config/mach
  12955. +fsf/gawk/config/msc60
  12956. +fsf/gawk/config/news
  12957. +fsf/gawk/config/next20
  12958. +fsf/gawk/config/next21
  12959. +fsf/gawk/config/next30
  12960. +fsf/gawk/config/osf1
  12961. +fsf/gawk/config/osf1.dec
  12962. +fsf/gawk/config/riscos452
  12963. +fsf/gawk/config/rs6000
  12964. +fsf/gawk/config/sco
  12965. +fsf/gawk/config/sequent
  12966. +fsf/gawk/config/sgi
  12967. +fsf/gawk/config/sgi33
  12968. +fsf/gawk/config/sgi33.cc
  12969. +fsf/gawk/config/sgi405
  12970. +fsf/gawk/config/sgi405.cc
  12971. +fsf/gawk/config/solaris2.cc
  12972. +fsf/gawk/config/sunos3
  12973. +fsf/gawk/config/sunos40
  12974. +fsf/gawk/config/sunos41
  12975. +fsf/gawk/config/sunos41-glibc
  12976. +fsf/gawk/config/sunos41.cc
  12977. +fsf/gawk/config/sysv2
  12978. +fsf/gawk/config/sysv3
  12979. +fsf/gawk/config/sysv4
  12980. +fsf/gawk/config/ultrix31
  12981. +fsf/gawk/config/ultrix40
  12982. +fsf/gawk/config/ultrix41
  12983. +fsf/gawk/config/utek
  12984. +fsf/gawk/config/v10config.h
  12985. +fsf/gawk/config/vms-conf.h
  12986. +fsf/gawk/config/vms-posix
  12987. +fsf/gawk/configure
  12988. +fsf/gawk/configure.in
  12989. +fsf/gawk/dfa.c
  12990. +fsf/gawk/dfa.h
  12991. +fsf/gawk/eval.c
  12992. +fsf/gawk/field.c
  12993. +fsf/gawk/gawk.1
  12994. +fsf/gawk/gawk.info
  12995. +fsf/gawk/gawk.info-1
  12996. +fsf/gawk/gawk.info-2
  12997. +fsf/gawk/gawk.info-3
  12998. +fsf/gawk/gawk.info-4
  12999. +fsf/gawk/gawk.info-5
  13000. +fsf/gawk/gawk.info-6
  13001. +fsf/gawk/gawk.info-7
  13002. +fsf/gawk/gawk.info-8
  13003. +fsf/gawk/gawk.info-9
  13004. +fsf/gawk/gawk.texi
  13005. +fsf/gawk/getopt.c
  13006. +fsf/gawk/getopt.h
  13007. +fsf/gawk/getopt1.c
  13008. +fsf/gawk/install.sh
  13009. +fsf/gawk/io.c
  13010. +fsf/gawk/iop.c
  13011. +fsf/gawk/main.c
  13012. +fsf/gawk/manifests/bin
  13013. +fsf/gawk/manifests/src
  13014. +fsf/gawk/missing.c
  13015. +fsf/gawk/missing/memcmp.c
  13016. +fsf/gawk/missing/memcpy.c
  13017. +fsf/gawk/missing/memset.c
  13018. +fsf/gawk/missing/random.c
  13019. +fsf/gawk/missing/strchr.c
  13020. +fsf/gawk/missing/strerror.c
  13021. +fsf/gawk/missing/strftime.3
  13022. +fsf/gawk/missing/strftime.c
  13023. +fsf/gawk/missing/strncasecmp.c
  13024. +fsf/gawk/missing/strtod.c
  13025. +fsf/gawk/missing/system.c
  13026. +fsf/gawk/missing/tzset.c
  13027. +fsf/gawk/msg.c
  13028. +fsf/gawk/mungeconf
  13029. +fsf/gawk/node.c
  13030. +fsf/gawk/patchlevel.h
  13031. +fsf/gawk/pc/Makefile.emx
  13032. +fsf/gawk/pc/Makefile.msc
  13033. +fsf/gawk/pc/Makefile.os2
  13034. +fsf/gawk/pc/config.h
  13035. +fsf/gawk/pc/gawk-32.def
  13036. +fsf/gawk/pc/gawk.def
  13037. +fsf/gawk/pc/getid.c
  13038. +fsf/gawk/pc/makegawk.bat
  13039. +fsf/gawk/pc/mkconf.cmd
  13040. +fsf/gawk/pc/mungeconf.cmd
  13041. +fsf/gawk/pc/names.lnk
  13042. +fsf/gawk/pc/names2.lnk
  13043. +fsf/gawk/pc/popen.c
  13044. +fsf/gawk/pc/popen.h
  13045. +fsf/gawk/protos.h
  13046. +fsf/gawk/re.c
  13047. +fsf/gawk/regex.c
  13048. +fsf/gawk/regex.h
  13049. +fsf/gawk/support/texindex.c
  13050. +fsf/gawk/support/texinfo.tex
  13051. +fsf/gawk/test/Makefile
  13052. +fsf/gawk/test/anchgsub.awk
  13053. +fsf/gawk/test/anchgsub.good
  13054. +fsf/gawk/test/anchgsub.in
  13055. +fsf/gawk/test/argarray.awk
  13056. +fsf/gawk/test/argarray.good
  13057. +fsf/gawk/test/argtest.awk
  13058. +fsf/gawk/test/argtest.good
  13059. +fsf/gawk/test/arrayparm.awk
  13060. +fsf/gawk/test/arrayparm.good
  13061. +fsf/gawk/test/arrayref
  13062. +fsf/gawk/test/arrayref.good
  13063. +fsf/gawk/test/asgext.awk
  13064. +fsf/gawk/test/asgext.good
  13065. +fsf/gawk/test/asgext.in
  13066. +fsf/gawk/test/awkpath.good
  13067. +fsf/gawk/test/badargs.good
  13068. +fsf/gawk/test/compare.awk
  13069. +fsf/gawk/test/compare.good
  13070. +fsf/gawk/test/compare.in
  13071. +fsf/gawk/test/convfmt.awk
  13072. +fsf/gawk/test/convfmt.good
  13073. +fsf/gawk/test/csi1.out
  13074. +fsf/gawk/test/data
  13075. +fsf/gawk/test/fieldwdth.good
  13076. +fsf/gawk/test/fontdata.txt
  13077. +fsf/gawk/test/fsbs.good
  13078. +fsf/gawk/test/fsbs.in
  13079. +fsf/gawk/test/fsrs.awk
  13080. +fsf/gawk/test/fsrs.good
  13081. +fsf/gawk/test/fsrs.in
  13082. +fsf/gawk/test/fstabplus
  13083. +fsf/gawk/test/fstabplus.good
  13084. +fsf/gawk/test/getline.awk
  13085. +fsf/gawk/test/getline.good
  13086. +fsf/gawk/test/header.awk
  13087. +fsf/gawk/test/igncfs.awk
  13088. +fsf/gawk/test/igncfs.good
  13089. +fsf/gawk/test/igncfs.in
  13090. +fsf/gawk/test/ignrcase.good
  13091. +fsf/gawk/test/include.awk
  13092. +fsf/gawk/test/inftest.awk
  13093. +fsf/gawk/test/inftest.good
  13094. +fsf/gawk/test/lastnpages
  13095. +fsf/gawk/test/lib/awkpath.awk
  13096. +fsf/gawk/test/longwrds.awk
  13097. +fsf/gawk/test/longwrds.good
  13098. +fsf/gawk/test/manpage
  13099. +fsf/gawk/test/manyfiles.awk
  13100. +fsf/gawk/test/messages.awk
  13101. +fsf/gawk/test/negexp.good
  13102. +fsf/gawk/test/nfset.awk
  13103. +fsf/gawk/test/nfset.good
  13104. +fsf/gawk/test/nfset.in
  13105. +fsf/gawk/test/nonl.awk
  13106. +fsf/gawk/test/nonl.good
  13107. +fsf/gawk/test/numfunc.awk
  13108. +fsf/gawk/test/out1.good
  13109. +fsf/gawk/test/out2.good
  13110. +fsf/gawk/test/out3.good
  13111. +fsf/gawk/test/paramdup.awk
  13112. +fsf/gawk/test/paramdup.good
  13113. +fsf/gawk/test/plus-minus
  13114. +fsf/gawk/test/posix
  13115. +fsf/gawk/test/posix.good
  13116. +fsf/gawk/test/poundbang
  13117. +fsf/gawk/test/poundbang.good
  13118. +fsf/gawk/test/rand.awk
  13119. +fsf/gawk/test/reg/exp-eq.awk
  13120. +fsf/gawk/test/reg/exp-eq.good
  13121. +fsf/gawk/test/reg/exp-eq.in
  13122. +fsf/gawk/test/reg/exp.awk
  13123. +fsf/gawk/test/reg/exp.good
  13124. +fsf/gawk/test/reg/exp.in
  13125. +fsf/gawk/test/reg/func.awk
  13126. +fsf/gawk/test/reg/func.good
  13127. +fsf/gawk/test/reg/func.in
  13128. +fsf/gawk/test/reg/func2.awk
  13129. +fsf/gawk/test/reg/func2.good
  13130. +fsf/gawk/test/reg/func2.in
  13131. +fsf/gawk/test/reg/log.awk
  13132. +fsf/gawk/test/reg/log.good
  13133. +fsf/gawk/test/reg/log.in
  13134. +fsf/gawk/test/regtest
  13135. +fsf/gawk/test/reparse.awk
  13136. +fsf/gawk/test/reparse.good
  13137. +fsf/gawk/test/reparse.in
  13138. +fsf/gawk/test/reverse.awk
  13139. +fsf/gawk/test/rs.data
  13140. +fsf/gawk/test/rs.good
  13141. +fsf/gawk/test/splitargv.awk
  13142. +fsf/gawk/test/splitargv.good
  13143. +fsf/gawk/test/splitargv.in
  13144. +fsf/gawk/test/sqrt.awk
  13145. +fsf/gawk/test/swaplns.awk
  13146. +fsf/gawk/test/swaplns.good
  13147. +fsf/gawk/test/up_down.awk
  13148. +fsf/gawk/test/zap_cpp.awk
  13149. +fsf/gawk/version.c
  13150. +fsf/gawk/vms/descrip.mms
  13151. +fsf/gawk/vms/fcntl.h
  13152. +fsf/gawk/vms/gawk.cld
  13153. +fsf/gawk/vms/gawk.hlp
  13154. +fsf/gawk/vms/unixlib.h
  13155. +fsf/gawk/vms/varargs.h
  13156. +fsf/gawk/vms/vms.h
  13157. +fsf/gawk/vms/vms_args.c
  13158. +fsf/gawk/vms/vms_cli.c
  13159. +fsf/gawk/vms/vms_fwrite.c
  13160. +fsf/gawk/vms/vms_gawk.c
  13161. +fsf/gawk/vms/vms_misc.c
  13162. +fsf/gawk/vms/vms_popen.c
  13163. +fsf/gawk/vms/vmsbuild.com
  13164. diff -rup --new-file baseline/fsf/gawk/pc/config.h amiga/fsf/gawk/pc/config.h
  13165. --- baseline/fsf/gawk/pc/config.h    Wed Dec 29 08:44:38 1993
  13166. +++ amiga/fsf/gawk/pc/config.h    Sat Sep 28 00:00:00 1996
  13167. @@ -258,7 +258,7 @@
  13168.   * this.
  13169.   */
  13170.  
  13171. -/* #define DEFPATH    ".:/usr/lib/awk:/usr/local/lib/awk" */
  13172. +/* #define DEFPATH    ".:/local/lib/awk:/ade/lib/awk" */
  13173.  /* #define ENVSEP    ':' */
  13174.  #define ENVSEP    ';'
  13175.  
  13176. diff -rup --new-file baseline/fsf/gawk/protos.h amiga/fsf/gawk/protos.h
  13177. --- baseline/fsf/gawk/protos.h    Sun May  1 15:20:21 1994
  13178. +++ amiga/fsf/gawk/protos.h    Sat Sep 28 00:00:00 1996
  13179. @@ -69,7 +69,9 @@ extern int memcmp P((const aptr_t, const
  13180.  extern int fprintf P((FILE *, const char *, ...));
  13181.  #if !defined(MSDOS) && !defined(__GNU_LIBRARY__)
  13182.  #ifdef __STDC__
  13183. +#ifndef __amigaos__    /* HACK - conflicts with stdio.h - FIXME */
  13184.  extern size_t fwrite P((const aptr_t, size_t, size_t, FILE *));
  13185. +#endif
  13186.  #else
  13187.  extern int fwrite();
  13188.  #endif
  13189. @@ -84,7 +86,7 @@ extern void abort P(());
  13190.  extern int isatty P((int));
  13191.  extern void exit P((int));
  13192.  extern int system P((const char *));
  13193. -extern int sscanf P((const char *, const char *, ...));
  13194. +/* extern int sscanf P((const char *, const char *, ...)); */
  13195.  #ifndef toupper
  13196.  extern int toupper P((int));
  13197.  #endif
  13198. diff -rup --new-file baseline/fsf/gawk/regex.c amiga/fsf/gawk/regex.c
  13199. --- baseline/fsf/gawk/regex.c    Thu Mar  9 09:29:01 1995
  13200. +++ amiga/fsf/gawk/regex.c    Sat Sep 28 00:00:00 1996
  13201. @@ -3,7 +3,7 @@
  13202.     (Implements POSIX draft P10003.2/D11.2, except for
  13203.     internationalization features.)
  13204.  
  13205. -   Copyright (C) 1993-1995 Free Software Foundation, Inc.
  13206. +   Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
  13207.  
  13208.     This program is free software; you can redistribute it and/or modify
  13209.     it under the terms of the GNU General Public License as published by
  13210. @@ -27,14 +27,17 @@
  13211.  #define _GNU_SOURCE
  13212.  
  13213.  #ifdef HAVE_CONFIG_H
  13214. -#include "config.h"
  13215. +#include <config.h>
  13216.  #endif
  13217.  
  13218. -#if defined(STDC_HEADERS) && !defined(emacs)
  13219. -#include <stddef.h>
  13220. -#else
  13221.  /* We need this for `regex.h', and perhaps for the Emacs include files.  */
  13222.  #include <sys/types.h>
  13223. +
  13224. +/* This is for other GNU distributions with internationalized messages.  */
  13225. +#if HAVE_LIBINTL_H || defined (_LIBC)
  13226. +# include <libintl.h>
  13227. +#else
  13228. +# define gettext(msgid) (msgid)
  13229.  #endif
  13230.  
  13231.  /* The `emacs' switch turns on certain matching commands
  13232. @@ -45,14 +48,35 @@
  13233.  #include "buffer.h"
  13234.  #include "syntax.h"
  13235.  
  13236. -/* Emacs uses `NULL' as a predicate.  */
  13237. -#undef NULL
  13238. -
  13239.  #else  /* not emacs */
  13240.  
  13241. -/* We used to test for `BSTRING' here, but only GCC and Emacs define
  13242. -   `BSTRING', as far as I know, and neither of them use this code.  */
  13243. -#if HAVE_STRING_H || STDC_HEADERS
  13244. +/* If we are not linking with Emacs proper,
  13245. +   we can't use the relocating allocator
  13246. +   even if config.h says that we can.  */
  13247. +#undef REL_ALLOC
  13248. +
  13249. +#if defined (STDC_HEADERS) || defined (_LIBC)
  13250. +#include <stdlib.h>
  13251. +#else
  13252. +char *malloc ();
  13253. +char *realloc ();
  13254. +#endif
  13255. +
  13256. +/* When used in Emacs's lib-src, we need to get bzero and bcopy somehow.
  13257. +   If nothing else has been done, use the method below.  */
  13258. +#ifdef INHIBIT_STRING_HEADER
  13259. +#if !(defined (HAVE_BZERO) && defined (HAVE_BCOPY))
  13260. +#if !defined (bzero) && !defined (bcopy)
  13261. +#undef INHIBIT_STRING_HEADER
  13262. +#endif
  13263. +#endif
  13264. +#endif
  13265. +
  13266. +/* This is the normal way of making sure we have a bcopy and a bzero.
  13267. +   This is used in most programs--a few other programs avoid this
  13268. +   by defining INHIBIT_STRING_HEADER.  */
  13269. +#ifndef INHIBIT_STRING_HEADER
  13270. +#if defined (HAVE_STRING_H) || defined (STDC_HEADERS) || defined (_LIBC)
  13271.  #include <string.h>
  13272.  #ifndef bcmp
  13273.  #define bcmp(s1, s2, n)    memcmp ((s1), (s2), (n))
  13274. @@ -66,15 +90,8 @@
  13275.  #else
  13276.  #include <strings.h>
  13277.  #endif
  13278. -
  13279. -#ifdef STDC_HEADERS
  13280. -#include <stdlib.h>
  13281. -#else
  13282. -char *malloc ();
  13283. -char *realloc ();
  13284.  #endif
  13285.  
  13286. -
  13287.  /* Define the syntax stuff for \<, \>, etc.  */
  13288.  
  13289.  /* This must be nonzero for the wordchar and notwordchar pattern
  13290. @@ -83,6 +100,12 @@ char *realloc ();
  13291.  #define Sword 1
  13292.  #endif
  13293.  
  13294. +#ifdef SWITCH_ENUM_BUG
  13295. +#define SWITCH_ENUM_CAST(x) ((int)(x))
  13296. +#else
  13297. +#define SWITCH_ENUM_CAST(x) (x)
  13298. +#endif
  13299. +
  13300.  #ifdef SYNTAX_TABLE
  13301.  
  13302.  extern char *re_syntax_table;
  13303. @@ -141,35 +164,37 @@ init_syntax_once ()
  13304.     macros don't need to be guarded with references to isascii. ...
  13305.     Defining isascii to 1 should let any compiler worth its salt
  13306.     eliminate the && through constant folding."  */
  13307. -#if ! defined (isascii) || defined (STDC_HEADERS)
  13308. -#undef isascii
  13309. -#define isascii(c) 1
  13310. +
  13311. +#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
  13312. +#define ISASCII(c) 1
  13313. +#else
  13314. +#define ISASCII(c) isascii(c)
  13315.  #endif
  13316.  
  13317.  #ifdef isblank
  13318. -#define ISBLANK(c) (isascii (c) && isblank (c))
  13319. +#define ISBLANK(c) (ISASCII (c) && isblank (c))
  13320.  #else
  13321.  #define ISBLANK(c) ((c) == ' ' || (c) == '\t')
  13322.  #endif
  13323.  #ifdef isgraph
  13324. -#define ISGRAPH(c) (isascii (c) && isgraph (c))
  13325. +#define ISGRAPH(c) (ISASCII (c) && isgraph (c))
  13326.  #else
  13327. -#define ISGRAPH(c) (isascii (c) && isprint (c) && !isspace (c))
  13328. +#define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
  13329.  #endif
  13330.  
  13331. -#define ISPRINT(c) (isascii (c) && isprint (c))
  13332. -#define ISDIGIT(c) (isascii (c) && isdigit (c))
  13333. -#define ISALNUM(c) (isascii (c) && isalnum (c))
  13334. -#define ISALPHA(c) (isascii (c) && isalpha (c))
  13335. -#define ISCNTRL(c) (isascii (c) && iscntrl (c))
  13336. -#define ISLOWER(c) (isascii (c) && islower (c))
  13337. -#define ISPUNCT(c) (isascii (c) && ispunct (c))
  13338. -#define ISSPACE(c) (isascii (c) && isspace (c))
  13339. -#define ISUPPER(c) (isascii (c) && isupper (c))
  13340. -#define ISXDIGIT(c) (isascii (c) && isxdigit (c))
  13341. +#define ISPRINT(c) (ISASCII (c) && isprint (c))
  13342. +#define ISDIGIT(c) (ISASCII (c) && isdigit (c))
  13343. +#define ISALNUM(c) (ISASCII (c) && isalnum (c))
  13344. +#define ISALPHA(c) (ISASCII (c) && isalpha (c))
  13345. +#define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
  13346. +#define ISLOWER(c) (ISASCII (c) && islower (c))
  13347. +#define ISPUNCT(c) (ISASCII (c) && ispunct (c))
  13348. +#define ISSPACE(c) (ISASCII (c) && isspace (c))
  13349. +#define ISUPPER(c) (ISASCII (c) && isupper (c))
  13350. +#define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
  13351.  
  13352.  #ifndef NULL
  13353. -#define NULL 0
  13354. +#define NULL (void *)0
  13355.  #endif
  13356.  
  13357.  /* We remove any previous definition of `SIGN_EXTEND_CHAR',
  13358. @@ -198,6 +223,7 @@ init_syntax_once ()
  13359.  
  13360.  #define REGEX_ALLOCATE malloc
  13361.  #define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize)
  13362. +#define REGEX_FREE free
  13363.  
  13364.  #else /* not REGEX_MALLOC  */
  13365.  
  13366. @@ -227,8 +253,41 @@ char *alloca ();
  13367.     bcopy (source, destination, osize),                    \
  13368.     destination)
  13369.  
  13370. +/* No need to do anything to free, after alloca.  */
  13371. +#define REGEX_FREE(arg) ((void)0) /* Do nothing!  But inhibit gcc warning.  */
  13372. +
  13373.  #endif /* not REGEX_MALLOC */
  13374.  
  13375. +/* Define how to allocate the failure stack.  */
  13376. +
  13377. +#ifdef REL_ALLOC
  13378. +#define REGEX_ALLOCATE_STACK(size)                \
  13379. +  r_alloc (&failure_stack_ptr, (size))
  13380. +#define REGEX_REALLOCATE_STACK(source, osize, nsize)        \
  13381. +  r_re_alloc (&failure_stack_ptr, (nsize))
  13382. +#define REGEX_FREE_STACK(ptr)                    \
  13383. +  r_alloc_free (&failure_stack_ptr)
  13384. +
  13385. +#else /* not REL_ALLOC */
  13386. +
  13387. +#ifdef REGEX_MALLOC
  13388. +
  13389. +#define REGEX_ALLOCATE_STACK malloc
  13390. +#define REGEX_REALLOCATE_STACK(source, osize, nsize) realloc (source, nsize)
  13391. +#define REGEX_FREE_STACK free
  13392. +
  13393. +#else /* not REGEX_MALLOC */
  13394. +
  13395. +#define REGEX_ALLOCATE_STACK alloca
  13396. +
  13397. +#define REGEX_REALLOCATE_STACK(source, osize, nsize)            \
  13398. +   REGEX_REALLOCATE (source, osize, nsize)
  13399. +/* No need to explicitly free anything.  */
  13400. +#define REGEX_FREE_STACK(arg)
  13401. +
  13402. +#endif /* not REGEX_MALLOC */
  13403. +#endif /* not REL_ALLOC */
  13404. +
  13405.  
  13406.  /* True if `size1' is non-NULL and PTR is pointing anywhere inside
  13407.     `string1' or just past its end.  This works if PTR is NULL, which is
  13408. @@ -239,34 +298,39 @@ char *alloca ();
  13409.  /* (Re)Allocate N items of type T using malloc, or fail.  */
  13410.  #define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t)))
  13411.  #define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t)))
  13412. +#define RETALLOC_IF(addr, n, t) \
  13413. +  if (addr) RETALLOC((addr), (n), t); else (addr) = TALLOC ((n), t)
  13414.  #define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t)))
  13415.  
  13416.  #define BYTEWIDTH 8 /* In bits.  */
  13417.  
  13418.  #define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
  13419.  
  13420. +#undef MAX
  13421. +#undef MIN
  13422.  #define MAX(a, b) ((a) > (b) ? (a) : (b))
  13423.  #define MIN(a, b) ((a) < (b) ? (a) : (b))
  13424.  
  13425.  typedef char boolean;
  13426.  #define false 0
  13427.  #define true 1
  13428. +
  13429. +static int re_match_2_internal ();
  13430.  
  13431.  /* These are the command codes that appear in compiled regular
  13432.     expressions.  Some opcodes are followed by argument bytes.  A
  13433.     command code can specify any interpretation whatsoever for its
  13434. -   arguments.  Zero bytes may appear in the compiled regular expression.
  13435. -
  13436. -   The value of `exactn' is needed in search.c (search_buffer) in Emacs.
  13437. -   So regex.h defines a symbol `RE_EXACTN_VALUE' to be 1; the value of
  13438. -   `exactn' we use here must also be 1.  */
  13439. +   arguments.  Zero bytes may appear in the compiled regular expression.  */
  13440.  
  13441.  typedef enum
  13442.  {
  13443.    no_op = 0,
  13444.  
  13445. +  /* Succeed right away--no more backtracking.  */
  13446. +  succeed,
  13447. +
  13448.          /* Followed by one byte giving n, then by n literal bytes.  */
  13449. -  exactn = 1,
  13450. +  exactn,
  13451.  
  13452.          /* Matches any (more or less) character.  */
  13453.    anychar,
  13454. @@ -496,8 +560,6 @@ static int debug = 0;
  13455.    if (debug) print_double_string (w, s1, sz1, s2, sz2)
  13456.  
  13457.  
  13458. -extern void printchar ();
  13459. -
  13460.  /* Print the fastmap in human-readable form.  */
  13461.  
  13462.  void
  13463. @@ -512,7 +574,7 @@ print_fastmap (fastmap)
  13464.        if (fastmap[i++])
  13465.      {
  13466.        was_a_range = 0;
  13467. -          printchar (i - 1);
  13468. +          putchar (i - 1);
  13469.            while (i < (1 << BYTEWIDTH)  &&  fastmap[i])
  13470.              {
  13471.                was_a_range = 1;
  13472. @@ -521,7 +583,7 @@ print_fastmap (fastmap)
  13473.        if (was_a_range)
  13474.              {
  13475.                printf ("-");
  13476. -              printchar (i - 1);
  13477. +              putchar (i - 1);
  13478.              }
  13479.          }
  13480.      }
  13481. @@ -564,7 +626,7 @@ print_partial_compiled_pattern (start, e
  13482.            do
  13483.          {
  13484.                putchar ('/');
  13485. -          printchar (*p++);
  13486. +          putchar (*p++);
  13487.              }
  13488.            while (--mcnt);
  13489.            break;
  13490. @@ -611,18 +673,18 @@ print_partial_compiled_pattern (start, e
  13491.            /* Have we broken a range?  */
  13492.            else if (last + 1 != c && in_range)
  13493.                {
  13494. -              printchar (last);
  13495. +              putchar (last);
  13496.                in_range = 0;
  13497.              }
  13498.                  
  13499.            if (! in_range)
  13500. -            printchar (c);
  13501. +            putchar (c);
  13502.  
  13503.            last = c;
  13504.                }
  13505.  
  13506.          if (in_range)
  13507. -          printchar (last);
  13508. +          putchar (last);
  13509.  
  13510.          putchar (']');
  13511.  
  13512. @@ -807,13 +869,13 @@ print_double_string (where, string1, siz
  13513.        if (FIRST_STRING_P (where))
  13514.          {
  13515.            for (this_char = where - string1; this_char < size1; this_char++)
  13516. -            printchar (string1[this_char]);
  13517. +            putchar (string1[this_char]);
  13518.  
  13519.            where = string2;    
  13520.          }
  13521.  
  13522.        for (this_char = where - string2; this_char < size2; this_char++)
  13523. -        printchar (string2[this_char]);
  13524. +        putchar (string2[this_char]);
  13525.      }
  13526.  }
  13527.  
  13528. @@ -842,7 +904,9 @@ printchar (c)
  13529.  /* Set by `re_set_syntax' to the current regexp syntax to recognize.  Can
  13530.     also be assigned to arbitrarily: each pattern buffer stores its own
  13531.     syntax, so it can be changed between regex compilations.  */
  13532. -reg_syntax_t re_syntax_options = RE_SYNTAX_EMACS;
  13533. +/* This has no initializer because initialized variables in Emacs
  13534. +   become read-only after dumping.  */
  13535. +reg_syntax_t re_syntax_options;
  13536.  
  13537.  
  13538.  /* Specify the precise syntax of regexps for compilation.  This provides
  13539. @@ -863,27 +927,454 @@ re_set_syntax (syntax)
  13540.  }
  13541.  
  13542.  /* This table gives an error message for each of the error codes listed
  13543. -   in regex.h.  Obviously the order here has to be same as there.  */
  13544. +   in regex.h.  Obviously the order here has to be same as there.
  13545. +   POSIX doesn't require that we do anything for REG_NOERROR,
  13546. +   but why not be nice?  */
  13547. +
  13548. +static const char *re_error_msgid[] =
  13549. +  { "Success",                    /* REG_NOERROR */
  13550. +    "No match",                    /* REG_NOMATCH */
  13551. +    "Invalid regular expression",        /* REG_BADPAT */
  13552. +    "Invalid collation character",        /* REG_ECOLLATE */
  13553. +    "Invalid character class name",        /* REG_ECTYPE */
  13554. +    "Trailing backslash",            /* REG_EESCAPE */
  13555. +    "Invalid back reference",            /* REG_ESUBREG */
  13556. +    "Unmatched [ or [^",            /* REG_EBRACK */
  13557. +    "Unmatched ( or \\(",            /* REG_EPAREN */
  13558. +    "Unmatched \\{",                /* REG_EBRACE */
  13559. +    "Invalid content of \\{\\}",        /* REG_BADBR */
  13560. +    "Invalid range end",            /* REG_ERANGE */
  13561. +    "Memory exhausted",                /* REG_ESPACE */
  13562. +    "Invalid preceding regular expression",    /* REG_BADRPT */
  13563. +    "Premature end of regular expression",    /* REG_EEND */
  13564. +    "Regular expression too big",        /* REG_ESIZE */
  13565. +    "Unmatched ) or \\)",            /* REG_ERPAREN */
  13566. +  };
  13567. +
  13568. +/* Avoiding alloca during matching, to placate r_alloc.  */
  13569. +
  13570. +/* Define MATCH_MAY_ALLOCATE unless we need to make sure that the
  13571. +   searching and matching functions should not call alloca.  On some
  13572. +   systems, alloca is implemented in terms of malloc, and if we're
  13573. +   using the relocating allocator routines, then malloc could cause a
  13574. +   relocation, which might (if the strings being searched are in the
  13575. +   ralloc heap) shift the data out from underneath the regexp
  13576. +   routines.
  13577. +
  13578. +   Here's another reason to avoid allocation: Emacs 
  13579. +   processes input from X in a signal handler; processing X input may
  13580. +   call malloc; if input arrives while a matching routine is calling
  13581. +   malloc, then we're scrod.  But Emacs can't just block input while
  13582. +   calling matching routines; then we don't notice interrupts when
  13583. +   they come in.  So, Emacs blocks input around all regexp calls
  13584. +   except the matching calls, which it leaves unprotected, in the
  13585. +   faith that they will not malloc.  */
  13586. +
  13587. +/* Normally, this is fine.  */
  13588. +#define MATCH_MAY_ALLOCATE
  13589. +
  13590. +/* When using GNU C, we are not REALLY using the C alloca, no matter
  13591. +   what config.h may say.  So don't take precautions for it.  */
  13592. +#ifdef __GNUC__
  13593. +#undef C_ALLOCA
  13594. +#endif
  13595. +
  13596. +/* The match routines may not allocate if (1) they would do it with malloc
  13597. +   and (2) it's not safe for them to use malloc.
  13598. +   Note that if REL_ALLOC is defined, matching would not use malloc for the
  13599. +   failure stack, but we would still use it for the register vectors;
  13600. +   so REL_ALLOC should not affect this.  */
  13601. +#if (defined (C_ALLOCA) || defined (REGEX_MALLOC)) && defined (emacs)
  13602. +#undef MATCH_MAY_ALLOCATE
  13603. +#endif
  13604. +
  13605. +
  13606. +/* Failure stack declarations and macros; both re_compile_fastmap and
  13607. +   re_match_2 use a failure stack.  These have to be macros because of
  13608. +   REGEX_ALLOCATE_STACK.  */
  13609. +   
  13610. +
  13611. +/* Number of failure points for which to initially allocate space
  13612. +   when matching.  If this number is exceeded, we allocate more
  13613. +   space, so it is not a hard limit.  */
  13614. +#ifndef INIT_FAILURE_ALLOC
  13615. +#define INIT_FAILURE_ALLOC 5
  13616. +#endif
  13617. +
  13618. +/* Roughly the maximum number of failure points on the stack.  Would be
  13619. +   exactly that if always used MAX_FAILURE_SPACE each time we failed.
  13620. +   This is a variable only so users of regex can assign to it; we never
  13621. +   change it ourselves.  */
  13622. +#if defined (MATCH_MAY_ALLOCATE)
  13623. +int re_max_failures = 200000;
  13624. +#else
  13625. +int re_max_failures = 2000;
  13626. +#endif
  13627. +
  13628. +union fail_stack_elt
  13629. +{
  13630. +  unsigned char *pointer;
  13631. +  int integer;
  13632. +};
  13633. +
  13634. +typedef union fail_stack_elt fail_stack_elt_t;
  13635. +
  13636. +typedef struct
  13637. +{
  13638. +  fail_stack_elt_t *stack;
  13639. +  unsigned size;
  13640. +  unsigned avail;            /* Offset of next open position.  */
  13641. +} fail_stack_type;
  13642. +
  13643. +#define FAIL_STACK_EMPTY()     (fail_stack.avail == 0)
  13644. +#define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0)
  13645. +#define FAIL_STACK_FULL()      (fail_stack.avail == fail_stack.size)
  13646. +
  13647. +
  13648. +/* Define macros to initialize and free the failure stack.
  13649. +   Do `return -2' if the alloc fails.  */
  13650. +
  13651. +#ifdef MATCH_MAY_ALLOCATE
  13652. +#define INIT_FAIL_STACK()                        \
  13653. +  do {                                    \
  13654. +    fail_stack.stack = (fail_stack_elt_t *)                \
  13655. +      REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t));    \
  13656. +                                    \
  13657. +    if (fail_stack.stack == NULL)                    \
  13658. +      return -2;                            \
  13659. +                                    \
  13660. +    fail_stack.size = INIT_FAILURE_ALLOC;                \
  13661. +    fail_stack.avail = 0;                        \
  13662. +  } while (0)
  13663. +
  13664. +#define RESET_FAIL_STACK()  REGEX_FREE_STACK (fail_stack.stack)
  13665. +#else
  13666. +#define INIT_FAIL_STACK()                        \
  13667. +  do {                                    \
  13668. +    fail_stack.avail = 0;                        \
  13669. +  } while (0)
  13670. +
  13671. +#define RESET_FAIL_STACK()
  13672. +#endif
  13673. +
  13674. +
  13675. +/* Double the size of FAIL_STACK, up to approximately `re_max_failures' items.
  13676. +
  13677. +   Return 1 if succeeds, and 0 if either ran out of memory
  13678. +   allocating space for it or it was already too large.  
  13679. +   
  13680. +   REGEX_REALLOCATE_STACK requires `destination' be declared.   */
  13681. +
  13682. +#define DOUBLE_FAIL_STACK(fail_stack)                    \
  13683. +  ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS        \
  13684. +   ? 0                                    \
  13685. +   : ((fail_stack).stack = (fail_stack_elt_t *)                \
  13686. +        REGEX_REALLOCATE_STACK ((fail_stack).stack,             \
  13687. +          (fail_stack).size * sizeof (fail_stack_elt_t),        \
  13688. +          ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)),    \
  13689. +                                    \
  13690. +      (fail_stack).stack == NULL                    \
  13691. +      ? 0                                \
  13692. +      : ((fail_stack).size <<= 1,                     \
  13693. +         1)))
  13694. +
  13695. +
  13696. +/* Push pointer POINTER on FAIL_STACK. 
  13697. +   Return 1 if was able to do so and 0 if ran out of memory allocating
  13698. +   space to do so.  */
  13699. +#define PUSH_PATTERN_OP(POINTER, FAIL_STACK)                \
  13700. +  ((FAIL_STACK_FULL ()                            \
  13701. +    && !DOUBLE_FAIL_STACK (FAIL_STACK))                    \
  13702. +   ? 0                                    \
  13703. +   : ((FAIL_STACK).stack[(FAIL_STACK).avail++].pointer = POINTER,    \
  13704. +      1))
  13705. +
  13706. +/* Push a pointer value onto the failure stack.
  13707. +   Assumes the variable `fail_stack'.  Probably should only
  13708. +   be called from within `PUSH_FAILURE_POINT'.  */
  13709. +#define PUSH_FAILURE_POINTER(item)                    \
  13710. +  fail_stack.stack[fail_stack.avail++].pointer = (unsigned char *) (item)
  13711. +
  13712. +/* This pushes an integer-valued item onto the failure stack.
  13713. +   Assumes the variable `fail_stack'.  Probably should only
  13714. +   be called from within `PUSH_FAILURE_POINT'.  */
  13715. +#define PUSH_FAILURE_INT(item)                    \
  13716. +  fail_stack.stack[fail_stack.avail++].integer = (item)
  13717. +
  13718. +/* Push a fail_stack_elt_t value onto the failure stack.
  13719. +   Assumes the variable `fail_stack'.  Probably should only
  13720. +   be called from within `PUSH_FAILURE_POINT'.  */
  13721. +#define PUSH_FAILURE_ELT(item)                    \
  13722. +  fail_stack.stack[fail_stack.avail++] =  (item)
  13723. +
  13724. +/* These three POP... operations complement the three PUSH... operations.
  13725. +   All assume that `fail_stack' is nonempty.  */
  13726. +#define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail].pointer
  13727. +#define POP_FAILURE_INT() fail_stack.stack[--fail_stack.avail].integer
  13728. +#define POP_FAILURE_ELT() fail_stack.stack[--fail_stack.avail]
  13729. +
  13730. +/* Used to omit pushing failure point id's when we're not debugging.  */
  13731. +#ifdef DEBUG
  13732. +#define DEBUG_PUSH PUSH_FAILURE_INT
  13733. +#define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_INT ()
  13734. +#else
  13735. +#define DEBUG_PUSH(item)
  13736. +#define DEBUG_POP(item_addr)
  13737. +#endif
  13738. +
  13739. +
  13740. +/* Push the information about the state we will need
  13741. +   if we ever fail back to it.  
  13742. +   
  13743. +   Requires variables fail_stack, regstart, regend, reg_info, and
  13744. +   num_regs be declared.  DOUBLE_FAIL_STACK requires `destination' be
  13745. +   declared.
  13746. +   
  13747. +   Does `return FAILURE_CODE' if runs out of memory.  */
  13748. +
  13749. +#define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code)    \
  13750. +  do {                                    \
  13751. +    char *destination;                            \
  13752. +    /* Must be int, so when we don't save any registers, the arithmetic    \
  13753. +       of 0 + -1 isn't done as unsigned.  */                \
  13754. +    /* Can't be int, since there is not a shred of a guarantee that int \
  13755. +       is wide enough to hold a value of something to which pointer can \
  13756. +       be assigned */                            \
  13757. +    s_reg_t this_reg;                            \
  13758. +                                        \
  13759. +    DEBUG_STATEMENT (failure_id++);                    \
  13760. +    DEBUG_STATEMENT (nfailure_points_pushed++);                \
  13761. +    DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id);        \
  13762. +    DEBUG_PRINT2 ("  Before push, next avail: %d\n", (fail_stack).avail);\
  13763. +    DEBUG_PRINT2 ("                     size: %d\n", (fail_stack).size);\
  13764. +                                    \
  13765. +    DEBUG_PRINT2 ("  slots needed: %d\n", NUM_FAILURE_ITEMS);        \
  13766. +    DEBUG_PRINT2 ("     available: %d\n", REMAINING_AVAIL_SLOTS);    \
  13767. +                                    \
  13768. +    /* Ensure we have enough space allocated for what we will push.  */    \
  13769. +    while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS)            \
  13770. +      {                                    \
  13771. +        if (!DOUBLE_FAIL_STACK (fail_stack))                \
  13772. +          return failure_code;                        \
  13773. +                                    \
  13774. +        DEBUG_PRINT2 ("\n  Doubled stack; size now: %d\n",        \
  13775. +               (fail_stack).size);                \
  13776. +        DEBUG_PRINT2 ("  slots available: %d\n", REMAINING_AVAIL_SLOTS);\
  13777. +      }
  13778. +
  13779. +#define PUSH_FAILURE_POINT2(pattern_place, string_place, failure_code)    \
  13780. +    /* Push the info, starting with the registers.  */            \
  13781. +    DEBUG_PRINT1 ("\n");                        \
  13782. +                                    \
  13783. +    PUSH_FAILURE_POINT_LOOP ();                        \
  13784. +                                    \
  13785. +    DEBUG_PRINT2 ("  Pushing  low active reg: %d\n", lowest_active_reg);\
  13786. +    PUSH_FAILURE_INT (lowest_active_reg);                \
  13787. +                                    \
  13788. +    DEBUG_PRINT2 ("  Pushing high active reg: %d\n", highest_active_reg);\
  13789. +    PUSH_FAILURE_INT (highest_active_reg);                \
  13790. +                                    \
  13791. +    DEBUG_PRINT2 ("  Pushing pattern 0x%x: ", pattern_place);        \
  13792. +    DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend);        \
  13793. +    PUSH_FAILURE_POINTER (pattern_place);                \
  13794. +                                    \
  13795. +    DEBUG_PRINT2 ("  Pushing string 0x%x: `", string_place);        \
  13796. +    DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2,   \
  13797. +                 size2);                \
  13798. +    DEBUG_PRINT1 ("'\n");                        \
  13799. +    PUSH_FAILURE_POINTER (string_place);                \
  13800. +                                    \
  13801. +    DEBUG_PRINT2 ("  Pushing failure id: %u\n", failure_id);        \
  13802. +    DEBUG_PUSH (failure_id);                        \
  13803. +  } while (0)
  13804. +
  13805. +/*  Pulled out of PUSH_FAILURE_POINT() to shorten the definition
  13806. +    of that macro.  (for VAX C) */
  13807. +#define PUSH_FAILURE_POINT_LOOP()                    \
  13808. +    for (this_reg = lowest_active_reg; this_reg <= highest_active_reg;    \
  13809. +         this_reg++)                            \
  13810. +      {                                    \
  13811. +    DEBUG_PRINT2 ("  Pushing reg: %d\n", this_reg);            \
  13812. +        DEBUG_STATEMENT (num_regs_pushed++);                \
  13813. +                                    \
  13814. +    DEBUG_PRINT2 ("    start: 0x%x\n", regstart[this_reg]);        \
  13815. +        PUSH_FAILURE_POINTER (regstart[this_reg]);            \
  13816. +                                                                        \
  13817. +    DEBUG_PRINT2 ("    end: 0x%x\n", regend[this_reg]);        \
  13818. +        PUSH_FAILURE_POINTER (regend[this_reg]);            \
  13819. +                                    \
  13820. +    DEBUG_PRINT2 ("    info: 0x%x\n      ", reg_info[this_reg]);    \
  13821. +        DEBUG_PRINT2 (" match_null=%d",                    \
  13822. +                      REG_MATCH_NULL_STRING_P (reg_info[this_reg]));    \
  13823. +        DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg]));    \
  13824. +        DEBUG_PRINT2 (" matched_something=%d",                \
  13825. +                      MATCHED_SOMETHING (reg_info[this_reg]));        \
  13826. +        DEBUG_PRINT2 (" ever_matched=%d",                \
  13827. +                      EVER_MATCHED_SOMETHING (reg_info[this_reg]));    \
  13828. +    DEBUG_PRINT1 ("\n");                        \
  13829. +        PUSH_FAILURE_ELT (reg_info[this_reg].word);            \
  13830. +      }
  13831. +
  13832. +/* This is the number of items that are pushed and popped on the stack
  13833. +   for each register.  */
  13834. +#define NUM_REG_ITEMS  3
  13835. +
  13836. +/* Individual items aside from the registers.  */
  13837. +#ifdef DEBUG
  13838. +#define NUM_NONREG_ITEMS 5 /* Includes failure point id.  */
  13839. +#else
  13840. +#define NUM_NONREG_ITEMS 4
  13841. +#endif
  13842. +
  13843. +/* We push at most this many items on the stack.  */
  13844. +#define MAX_FAILURE_ITEMS ((num_regs - 1) * NUM_REG_ITEMS + NUM_NONREG_ITEMS)
  13845. +
  13846. +/* We actually push this many items.  */
  13847. +#define NUM_FAILURE_ITEMS                        \
  13848. +  ((highest_active_reg - lowest_active_reg + 1) * NUM_REG_ITEMS     \
  13849. +    + NUM_NONREG_ITEMS)
  13850. +
  13851. +/* How many items can still be added to the stack without overflowing it.  */
  13852. +#define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail)
  13853. +
  13854. +
  13855. +/* Pops what PUSH_FAIL_STACK pushes.
  13856. +
  13857. +   We restore into the parameters, all of which should be lvalues:
  13858. +     STR -- the saved data position.
  13859. +     PAT -- the saved pattern position.
  13860. +     LOW_REG, HIGH_REG -- the highest and lowest active registers.
  13861. +     REGSTART, REGEND -- arrays of string positions.
  13862. +     REG_INFO -- array of information about each subexpression.
  13863. +   
  13864. +   Also assumes the variables `fail_stack' and (if debugging), `bufp',
  13865. +   `pend', `string1', `size1', `string2', and `size2'.  */
  13866. +
  13867. +#define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\
  13868. +{                                    \
  13869. +  DEBUG_STATEMENT (fail_stack_elt_t failure_id;)            \
  13870. +  s_reg_t this_reg;                            \
  13871. +  const unsigned char *string_temp;                    \
  13872. +                                    \
  13873. +  assert (!FAIL_STACK_EMPTY ());                    \
  13874. +                                    \
  13875. +  /* Remove failure points and point to how many regs pushed.  */    \
  13876. +  DEBUG_PRINT1 ("POP_FAILURE_POINT:\n");                \
  13877. +  DEBUG_PRINT2 ("  Before pop, next avail: %d\n", fail_stack.avail);    \
  13878. +  DEBUG_PRINT2 ("                    size: %d\n", fail_stack.size);    \
  13879. +                                    \
  13880. +  assert (fail_stack.avail >= NUM_NONREG_ITEMS);            \
  13881. +                                    \
  13882. +  DEBUG_POP (&failure_id);                        \
  13883. +  DEBUG_PRINT2 ("  Popping failure id: %u\n", failure_id);        \
  13884. +                                    \
  13885. +  /* If the saved string location is NULL, it came from an        \
  13886. +     on_failure_keep_string_jump opcode, and we want to throw away the    \
  13887. +     saved NULL, thus retaining our current position in the string.  */    \
  13888. +  string_temp = POP_FAILURE_POINTER ();                    \
  13889. +  if (string_temp != NULL)                        \
  13890. +    str = (const char *) string_temp;                    \
  13891. +                                    \
  13892. +  DEBUG_PRINT2 ("  Popping string 0x%x: `", str);            \
  13893. +  DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2);    \
  13894. +  DEBUG_PRINT1 ("'\n");                            \
  13895. +                                    \
  13896. +  pat = (unsigned char *) POP_FAILURE_POINTER ();            \
  13897. +  DEBUG_PRINT2 ("  Popping pattern 0x%x: ", pat);            \
  13898. +  DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend);            \
  13899. +                                    \
  13900. +  POP_FAILURE_POINT2 (low_reg, high_reg, regstart, regend, reg_info);
  13901. +
  13902. +/*  Pulled out of POP_FAILURE_POINT() to shorten the definition
  13903. +    of that macro.  (for MSC 5.1) */
  13904. +#define POP_FAILURE_POINT2(low_reg, high_reg, regstart, regend, reg_info) \
  13905. +                                    \
  13906. +  /* Restore register info.  */                        \
  13907. +  high_reg = (active_reg_t) POP_FAILURE_INT ();                \
  13908. +  DEBUG_PRINT2 ("  Popping high active reg: %d\n", high_reg);        \
  13909. +                                    \
  13910. +  low_reg = (active_reg_t) POP_FAILURE_INT ();                \
  13911. +  DEBUG_PRINT2 ("  Popping  low active reg: %d\n", low_reg);        \
  13912. +                                    \
  13913. +  for (this_reg = high_reg; this_reg >= low_reg; this_reg--)        \
  13914. +    {                                    \
  13915. +      DEBUG_PRINT2 ("    Popping reg: %d\n", this_reg);            \
  13916. +                                    \
  13917. +      reg_info[this_reg].word = POP_FAILURE_ELT ();            \
  13918. +      DEBUG_PRINT2 ("      info: 0x%x\n", reg_info[this_reg]);        \
  13919. +                                    \
  13920. +      regend[this_reg] = (const char *) POP_FAILURE_POINTER ();        \
  13921. +      DEBUG_PRINT2 ("      end: 0x%x\n", regend[this_reg]);        \
  13922. +                                    \
  13923. +      regstart[this_reg] = (const char *) POP_FAILURE_POINTER ();    \
  13924. +      DEBUG_PRINT2 ("      start: 0x%x\n", regstart[this_reg]);        \
  13925. +    }                                    \
  13926. +                                    \
  13927. +  set_regs_matched_done = 0;                        \
  13928. +  DEBUG_STATEMENT (nfailure_points_popped++);                \
  13929. +} /* POP_FAILURE_POINT */
  13930. +
  13931. +
  13932. +
  13933. +/* Structure for per-register (a.k.a. per-group) information.
  13934. +   Other register information, such as the
  13935. +   starting and ending positions (which are addresses), and the list of
  13936. +   inner groups (which is a bits list) are maintained in separate
  13937. +   variables.  
  13938. +   
  13939. +   We are making a (strictly speaking) nonportable assumption here: that
  13940. +   the compiler will pack our bit fields into something that fits into
  13941. +   the type of `word', i.e., is something that fits into one item on the
  13942. +   failure stack.  */
  13943. +
  13944. +
  13945. +/* Declarations and macros for re_match_2.  */
  13946. +
  13947. +typedef union
  13948. +{
  13949. +  fail_stack_elt_t word;
  13950. +  struct
  13951. +  {
  13952. +      /* This field is one if this group can match the empty string,
  13953. +         zero if not.  If not yet determined,  `MATCH_NULL_UNSET_VALUE'.  */
  13954. +#define MATCH_NULL_UNSET_VALUE 3
  13955. +    unsigned match_null_string_p : 2;
  13956. +    unsigned is_active : 1;
  13957. +    unsigned matched_something : 1;
  13958. +    unsigned ever_matched_something : 1;
  13959. +  } bits;
  13960. +} register_info_type;
  13961. +
  13962. +#define REG_MATCH_NULL_STRING_P(R)  ((R).bits.match_null_string_p)
  13963. +#define IS_ACTIVE(R)  ((R).bits.is_active)
  13964. +#define MATCHED_SOMETHING(R)  ((R).bits.matched_something)
  13965. +#define EVER_MATCHED_SOMETHING(R)  ((R).bits.ever_matched_something)
  13966. +
  13967. +
  13968. +/* Call this when have matched a real character; it sets `matched' flags
  13969. +   for the subexpressions which we are currently inside.  Also records
  13970. +   that those subexprs have matched.  */
  13971. +#define SET_REGS_MATCHED()                        \
  13972. +  do                                    \
  13973. +    {                                    \
  13974. +      if (!set_regs_matched_done)                    \
  13975. +    {                                \
  13976. +      active_reg_t r;                        \
  13977. +      set_regs_matched_done = 1;                    \
  13978. +      for (r = lowest_active_reg; r <= highest_active_reg; r++)    \
  13979. +        {                                \
  13980. +          MATCHED_SOMETHING (reg_info[r])                \
  13981. +        = EVER_MATCHED_SOMETHING (reg_info[r])            \
  13982. +        = 1;                            \
  13983. +        }                                \
  13984. +    }                                \
  13985. +    }                                    \
  13986. +  while (0)
  13987.  
  13988. -static const char *re_error_msg[] =
  13989. -  { NULL,                    /* REG_NOERROR */
  13990. -    "No match",                    /* REG_NOMATCH */
  13991. -    "Invalid regular expression",        /* REG_BADPAT */
  13992. -    "Invalid collation character",        /* REG_ECOLLATE */
  13993. -    "Invalid character class name",        /* REG_ECTYPE */
  13994. -    "Trailing backslash",            /* REG_EESCAPE */
  13995. -    "Invalid back reference",            /* REG_ESUBREG */
  13996. -    "Unmatched [ or [^",            /* REG_EBRACK */
  13997. -    "Unmatched ( or \\(",            /* REG_EPAREN */
  13998. -    "Unmatched \\{",                /* REG_EBRACE */
  13999. -    "Invalid content of \\{\\}",        /* REG_BADBR */
  14000. -    "Invalid range end",            /* REG_ERANGE */
  14001. -    "Memory exhausted",                /* REG_ESPACE */
  14002. -    "Invalid preceding regular expression",    /* REG_BADRPT */
  14003. -    "Premature end of regular expression",    /* REG_EEND */
  14004. -    "Regular expression too big",        /* REG_ESIZE */
  14005. -    "Unmatched ) or \\)",            /* REG_ERPAREN */
  14006. -  };
  14007. +/* Registers are set to a sentinel when they haven't yet matched.  */
  14008. +static char reg_unset_dummy;
  14009. +#define REG_UNSET_VALUE (®_unset_dummy)
  14010. +#define REG_UNSET(e) ((e) == REG_UNSET_VALUE)
  14011.  
  14012.  /* Subroutine declarations and macros for regex_compile.  */
  14013.  
  14014. @@ -1116,6 +1607,54 @@ typedef struct
  14015.      || STREQ (string, "punct") || STREQ (string, "graph")        \
  14016.      || STREQ (string, "cntrl") || STREQ (string, "blank"))
  14017.  
  14018. +#ifndef MATCH_MAY_ALLOCATE
  14019. +
  14020. +/* If we cannot allocate large objects within re_match_2_internal,
  14021. +   we make the fail stack and register vectors global.
  14022. +   The fail stack, we grow to the maximum size when a regexp
  14023. +   is compiled.
  14024. +   The register vectors, we adjust in size each time we
  14025. +   compile a regexp, according to the number of registers it needs.  */
  14026. +
  14027. +static fail_stack_type fail_stack;
  14028. +
  14029. +/* Size with which the following vectors are currently allocated.
  14030. +   That is so we can make them bigger as needed,
  14031. +   but never make them smaller.  */
  14032. +static int regs_allocated_size;
  14033. +
  14034. +static const char **     regstart, **     regend;
  14035. +static const char ** old_regstart, ** old_regend;
  14036. +static const char **best_regstart, **best_regend;
  14037. +static register_info_type *reg_info; 
  14038. +static const char **reg_dummy;
  14039. +static register_info_type *reg_info_dummy;
  14040. +
  14041. +/* Make the register vectors big enough for NUM_REGS registers,
  14042. +   but don't make them smaller.  */
  14043. +
  14044. +static
  14045. +regex_grow_registers (num_regs)
  14046. +     int num_regs;
  14047. +{
  14048. +  if (num_regs > regs_allocated_size)
  14049. +    {
  14050. +      RETALLOC_IF (regstart,     num_regs, const char *);
  14051. +      RETALLOC_IF (regend,     num_regs, const char *);
  14052. +      RETALLOC_IF (old_regstart, num_regs, const char *);
  14053. +      RETALLOC_IF (old_regend,     num_regs, const char *);
  14054. +      RETALLOC_IF (best_regstart, num_regs, const char *);
  14055. +      RETALLOC_IF (best_regend,     num_regs, const char *);
  14056. +      RETALLOC_IF (reg_info,     num_regs, register_info_type);
  14057. +      RETALLOC_IF (reg_dummy,     num_regs, const char *);
  14058. +      RETALLOC_IF (reg_info_dummy, num_regs, register_info_type);
  14059. +
  14060. +      regs_allocated_size = num_regs;
  14061. +    }
  14062. +}
  14063. +
  14064. +#endif /* not MATCH_MAY_ALLOCATE */
  14065. +
  14066.  static boolean group_in_compile_stack _RE_ARGS((compile_stack_type
  14067.                          compile_stack,
  14068.                          regnum_t regnum));
  14069. @@ -1138,6 +1677,10 @@ static boolean group_in_compile_stack _R
  14070.     The `fastmap' and `newline_anchor' fields are neither
  14071.     examined nor set.  */
  14072.  
  14073. +/* Return, freeing storage we allocated.  */
  14074. +#define FREE_STACK_RETURN(value)        \
  14075. +  return (free (compile_stack.stack), value)
  14076. +
  14077.  static reg_errcode_t
  14078.  regex_compile (pattern, size, syntax, bufp)
  14079.       const char *pattern;
  14080. @@ -1150,7 +1693,7 @@ regex_compile (pattern, size, syntax, bu
  14081.       they can be reliably used as array indices.  */
  14082.    register unsigned char c, c1;
  14083.    
  14084. -  /* A random tempory spot in PATTERN.  */
  14085. +  /* A random temporary spot in PATTERN.  */
  14086.    const char *p1;
  14087.  
  14088.    /* Points to the end of the buffer, where we should append.  */
  14089. @@ -1201,7 +1744,7 @@ regex_compile (pattern, size, syntax, bu
  14090.        unsigned debug_count;
  14091.        
  14092.        for (debug_count = 0; debug_count < size; debug_count++)
  14093. -        printchar (pattern[debug_count]);
  14094. +        putchar (pattern[debug_count]);
  14095.        putchar ('\n');
  14096.      }
  14097.  #endif /* DEBUG */
  14098. @@ -1244,7 +1787,7 @@ regex_compile (pattern, size, syntax, bu
  14099.          { /* Caller did not allocate a buffer.  Do it for them.  */
  14100.            bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char);
  14101.          }
  14102. -      if (!bufp->buffer) return REG_ESPACE;
  14103. +      if (!bufp->buffer) FREE_STACK_RETURN (REG_ESPACE);
  14104.  
  14105.        bufp->allocated = INIT_BUF_SIZE;
  14106.      }
  14107. @@ -1299,7 +1842,7 @@ regex_compile (pattern, size, syntax, bu
  14108.            if (!laststart)
  14109.              {
  14110.                if (syntax & RE_CONTEXT_INVALID_OPS)
  14111. -                return REG_BADRPT;
  14112. +                FREE_STACK_RETURN (REG_BADRPT);
  14113.                else if (!(syntax & RE_CONTEXT_INDEP_OPS))
  14114.                  goto normal_char;
  14115.              }
  14116. @@ -1332,7 +1875,7 @@ regex_compile (pattern, size, syntax, bu
  14117.  
  14118.                  else if (syntax & RE_BK_PLUS_QM  &&  c == '\\')
  14119.                    {
  14120. -                    if (p == pend) return REG_EESCAPE;
  14121. +                    if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
  14122.  
  14123.                      PATFETCH (c1);
  14124.                      if (!(c1 == '+' || c1 == '?'))
  14125. @@ -1431,7 +1974,7 @@ regex_compile (pattern, size, syntax, bu
  14126.            {
  14127.              boolean had_char_class = false;
  14128.  
  14129. -            if (p == pend) return REG_EBRACK;
  14130. +            if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
  14131.  
  14132.              /* Ensure that we have enough space to push a charset: the
  14133.                 opcode, the length count, and the bitset; 34 bytes in all.  */
  14134. @@ -1462,14 +2005,14 @@ regex_compile (pattern, size, syntax, bu
  14135.              /* Read in characters and ranges, setting map bits.  */
  14136.              for (;;)
  14137.                {
  14138. -                if (p == pend) return REG_EBRACK;
  14139. +                if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
  14140.  
  14141.                  PATFETCH (c);
  14142.  
  14143.                  /* \ might escape characters inside [...] and [^...].  */
  14144.                  if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\')
  14145.                    {
  14146. -                    if (p == pend) return REG_EESCAPE;
  14147. +                    if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
  14148.  
  14149.                      PATFETCH (c1);
  14150.                      SET_LIST_BIT (c1);
  14151. @@ -1485,7 +2028,7 @@ regex_compile (pattern, size, syntax, bu
  14152.                  /* Look ahead to see if it's a range when the last thing
  14153.                     was a character class.  */
  14154.                  if (had_char_class && c == '-' && *p != ']')
  14155. -                  return REG_ERANGE;
  14156. +                  FREE_STACK_RETURN (REG_ERANGE);
  14157.  
  14158.                  /* Look ahead to see if it's a range when the last thing
  14159.                     was a character: if this is a hyphen not at the
  14160. @@ -1498,7 +2041,7 @@ regex_compile (pattern, size, syntax, bu
  14161.                    {
  14162.                      reg_errcode_t ret
  14163.                        = compile_range (&p, pend, translate, syntax, b);
  14164. -                    if (ret != REG_NOERROR) return ret;
  14165. +                    if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
  14166.                    }
  14167.  
  14168.                  else if (p[0] == '-' && p[1] != ']')
  14169. @@ -1509,7 +2052,7 @@ regex_compile (pattern, size, syntax, bu
  14170.                      PATFETCH (c1);
  14171.                      
  14172.                      ret = compile_range (&p, pend, translate, syntax, b);
  14173. -                    if (ret != REG_NOERROR) return ret;
  14174. +                    if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
  14175.                    }
  14176.  
  14177.                  /* See if we're at the beginning of a possible character
  14178. @@ -1523,7 +2066,7 @@ regex_compile (pattern, size, syntax, bu
  14179.                      c1 = 0;
  14180.  
  14181.                      /* If pattern is `[[:'.  */
  14182. -                    if (p == pend) return REG_EBRACK;
  14183. +                    if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
  14184.  
  14185.                      for (;;)
  14186.                        {
  14187. @@ -1554,29 +2097,34 @@ regex_compile (pattern, size, syntax, bu
  14188.                          boolean is_upper = STREQ (str, "upper");
  14189.                          boolean is_xdigit = STREQ (str, "xdigit");
  14190.                          
  14191. -                        if (!IS_CHAR_CLASS (str)) return REG_ECTYPE;
  14192. +                        if (!IS_CHAR_CLASS (str))
  14193. +              FREE_STACK_RETURN (REG_ECTYPE);
  14194.  
  14195.                          /* Throw away the ] at the end of the character
  14196.                             class.  */
  14197.                          PATFETCH (c);                    
  14198.  
  14199. -                        if (p == pend) return REG_EBRACK;
  14200. +                        if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
  14201.  
  14202.                          for (ch = 0; ch < 1 << BYTEWIDTH; ch++)
  14203.                            {
  14204. +                /* This was split into 3 if's to
  14205. +                   avoid an arbitrary limit in some compiler.  */
  14206.                              if (   (is_alnum  && ISALNUM (ch))
  14207.                                  || (is_alpha  && ISALPHA (ch))
  14208.                                  || (is_blank  && ISBLANK (ch))
  14209. -                                || (is_cntrl  && ISCNTRL (ch))
  14210. -                                || (is_digit  && ISDIGIT (ch))
  14211. +                                || (is_cntrl  && ISCNTRL (ch)))
  14212. +                  SET_LIST_BIT (ch);
  14213. +                if (   (is_digit  && ISDIGIT (ch))
  14214.                                  || (is_graph  && ISGRAPH (ch))
  14215.                                  || (is_lower  && ISLOWER (ch))
  14216. -                                || (is_print  && ISPRINT (ch))
  14217. -                                || (is_punct  && ISPUNCT (ch))
  14218. +                                || (is_print  && ISPRINT (ch)))
  14219. +                  SET_LIST_BIT (ch);
  14220. +                if (   (is_punct  && ISPUNCT (ch))
  14221.                                  || (is_space  && ISSPACE (ch))
  14222.                                  || (is_upper  && ISUPPER (ch))
  14223.                                  || (is_xdigit && ISXDIGIT (ch)))
  14224. -                            SET_LIST_BIT (ch);
  14225. +                  SET_LIST_BIT (ch);
  14226.                            }
  14227.                          had_char_class = true;
  14228.                        }
  14229. @@ -1642,7 +2190,7 @@ regex_compile (pattern, size, syntax, bu
  14230.  
  14231.  
  14232.          case '\\':
  14233. -          if (p == pend) return REG_EESCAPE;
  14234. +          if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
  14235.  
  14236.            /* Do not translate the character after the \, so that we can
  14237.               distinguish, e.g., \B from \b, even if we normally would
  14238. @@ -1707,7 +2255,7 @@ regex_compile (pattern, size, syntax, bu
  14239.                  if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
  14240.                    goto normal_backslash;
  14241.                  else
  14242. -                  return REG_ERPAREN;
  14243. +                  FREE_STACK_RETURN (REG_ERPAREN);
  14244.  
  14245.              handle_close:
  14246.                if (fixup_alt_jump)
  14247. @@ -1727,7 +2275,7 @@ regex_compile (pattern, size, syntax, bu
  14248.                  if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
  14249.                    goto normal_char;
  14250.                  else
  14251. -                  return REG_ERPAREN;
  14252. +                  FREE_STACK_RETURN (REG_ERPAREN);
  14253.  
  14254.                /* Since we just checked for an empty stack above, this
  14255.                   ``can't happen''.  */
  14256. @@ -1834,7 +2382,7 @@ regex_compile (pattern, size, syntax, bu
  14257.                      if (syntax & RE_NO_BK_BRACES)
  14258.                        goto unfetch_interval;
  14259.                      else
  14260. -                      return REG_EBRACE;
  14261. +                      FREE_STACK_RETURN (REG_EBRACE);
  14262.                    }
  14263.  
  14264.                  GET_UNSIGNED_NUMBER (lower_bound);
  14265. @@ -1854,12 +2402,12 @@ regex_compile (pattern, size, syntax, bu
  14266.                      if (syntax & RE_NO_BK_BRACES)
  14267.                        goto unfetch_interval;
  14268.                      else 
  14269. -                      return REG_BADBR;
  14270. +                      FREE_STACK_RETURN (REG_BADBR);
  14271.                    }
  14272.  
  14273.                  if (!(syntax & RE_NO_BK_BRACES)) 
  14274.                    {
  14275. -                    if (c != '\\') return REG_EBRACE;
  14276. +                    if (c != '\\') FREE_STACK_RETURN (REG_EBRACE);
  14277.  
  14278.                      PATFETCH (c);
  14279.                    }
  14280. @@ -1869,7 +2417,7 @@ regex_compile (pattern, size, syntax, bu
  14281.                      if (syntax & RE_NO_BK_BRACES)
  14282.                        goto unfetch_interval;
  14283.                      else 
  14284. -                      return REG_BADBR;
  14285. +                      FREE_STACK_RETURN (REG_BADBR);
  14286.                    }
  14287.  
  14288.                  /* We just parsed a valid interval.  */
  14289. @@ -1878,7 +2426,7 @@ regex_compile (pattern, size, syntax, bu
  14290.                  if (!laststart)
  14291.                    {
  14292.                      if (syntax & RE_CONTEXT_INVALID_OPS)
  14293. -                      return REG_BADRPT;
  14294. +                      FREE_STACK_RETURN (REG_BADRPT);
  14295.                      else if (syntax & RE_CONTEXT_INDEP_OPS)
  14296.                        laststart = b;
  14297.                      else
  14298. @@ -1899,7 +2447,7 @@ regex_compile (pattern, size, syntax, bu
  14299.                      we're all done, the pattern will look like:
  14300.                        set_number_at <jump count> <upper bound>
  14301.                        set_number_at <succeed_n count> <lower bound>
  14302. -                      succeed_n <after jump addr> <succed_n count>
  14303. +                      succeed_n <after jump addr> <succeed_n count>
  14304.                        <body of loop>
  14305.                        jump_n <succeed_n addr> <jump count>
  14306.                      (The upper bound and `jump_n' are omitted if
  14307. @@ -2061,7 +2609,7 @@ regex_compile (pattern, size, syntax, bu
  14308.                c1 = c - '0';
  14309.  
  14310.                if (c1 > regnum)
  14311. -                return REG_ESUBREG;
  14312. +                FREE_STACK_RETURN (REG_ESUBREG);
  14313.  
  14314.                /* Can't back reference to a subexpression if inside of it.  */
  14315.                if (group_in_compile_stack (compile_stack, (regnum_t)c1))
  14316. @@ -2133,7 +2681,12 @@ regex_compile (pattern, size, syntax, bu
  14317.      STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
  14318.  
  14319.    if (!COMPILE_STACK_EMPTY) 
  14320. -    return REG_EPAREN;
  14321. +    FREE_STACK_RETURN (REG_EPAREN);
  14322. +
  14323. +  /* If we don't want backtracking, force success
  14324. +     the first time we reach the end of the compiled pattern.  */
  14325. +  if (syntax & RE_NO_POSIX_BACKTRACKING)
  14326. +    BUF_PUSH (succeed);
  14327.  
  14328.    free (compile_stack.stack);
  14329.  
  14330. @@ -2148,6 +2701,47 @@ regex_compile (pattern, size, syntax, bu
  14331.      }
  14332.  #endif /* DEBUG */
  14333.  
  14334. +#ifndef MATCH_MAY_ALLOCATE
  14335. +  /* Initialize the failure stack to the largest possible stack.  This
  14336. +     isn't necessary unless we're trying to avoid calling alloca in
  14337. +     the search and match routines.  */
  14338. +  {
  14339. +    int num_regs = bufp->re_nsub + 1;
  14340. +
  14341. +    /* Since DOUBLE_FAIL_STACK refuses to double only if the current size
  14342. +       is strictly greater than re_max_failures, the largest possible stack
  14343. +       is 2 * re_max_failures failure points.  */
  14344. +    if (fail_stack.size < (2 * re_max_failures * MAX_FAILURE_ITEMS))
  14345. +      {
  14346. +    fail_stack.size = (2 * re_max_failures * MAX_FAILURE_ITEMS);
  14347. +
  14348. +#ifdef emacs
  14349. +    if (! fail_stack.stack)
  14350. +      fail_stack.stack
  14351. +        = (fail_stack_elt_t *) xmalloc (fail_stack.size 
  14352. +                        * sizeof (fail_stack_elt_t));
  14353. +    else
  14354. +      fail_stack.stack
  14355. +        = (fail_stack_elt_t *) xrealloc (fail_stack.stack,
  14356. +                         (fail_stack.size
  14357. +                          * sizeof (fail_stack_elt_t)));
  14358. +#else /* not emacs */
  14359. +    if (! fail_stack.stack)
  14360. +      fail_stack.stack
  14361. +        = (fail_stack_elt_t *) malloc (fail_stack.size 
  14362. +                       * sizeof (fail_stack_elt_t));
  14363. +    else
  14364. +      fail_stack.stack
  14365. +        = (fail_stack_elt_t *) realloc (fail_stack.stack,
  14366. +                        (fail_stack.size
  14367. +                         * sizeof (fail_stack_elt_t)));
  14368. +#endif /* not emacs */
  14369. +      }
  14370. +
  14371. +    regex_grow_registers (num_regs);
  14372. +  }
  14373. +#endif /* not MATCH_MAY_ALLOCATE */
  14374. +
  14375.    return REG_NOERROR;
  14376.  } /* regex_compile */
  14377.  
  14378. @@ -2249,7 +2843,7 @@ at_endline_loc_p (p, pend, syntax)
  14379.  {
  14380.    const char *next = p;
  14381.    boolean next_backslash = *next == '\\';
  14382. -  const char *next_next = p + 1 < pend ? p + 1 : NULL;
  14383. +  const char *next_next = p + 1 < pend ? p + 1 : 0;
  14384.    
  14385.    return
  14386.         /* Before a subexpression?  */
  14387. @@ -2310,322 +2904,33 @@ compile_range (p_ptr, pend, translate, s
  14388.    /* Even though the pattern is a signed `char *', we need to fetch
  14389.       with unsigned char *'s; if the high bit of the pattern character
  14390.       is set, the range endpoints will be negative if we fetch using a
  14391. -     signed char *.
  14392. -
  14393. -     We also want to fetch the endpoints without translating them; the 
  14394. -     appropriate translation is done in the bit-setting loop below.  */
  14395. -  range_start = ((unsigned char *) p)[-2];
  14396. -  range_end   = ((unsigned char *) p)[0];
  14397. -
  14398. -  /* Have to increment the pointer into the pattern string, so the
  14399. -     caller isn't still at the ending character.  */
  14400. -  (*p_ptr)++;
  14401. -
  14402. -  /* If the start is after the end, the range is empty.  */
  14403. -  if (range_start > range_end)
  14404. -    return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR;
  14405. -
  14406. -  /* Here we see why `this_char' has to be larger than an `unsigned
  14407. -     char' -- the range is inclusive, so if `range_end' == 0xff
  14408. -     (assuming 8-bit characters), we would otherwise go into an infinite
  14409. -     loop, since all characters <= 0xff.  */
  14410. -  for (this_char = range_start; this_char <= range_end; this_char++)
  14411. -    {
  14412. -      SET_LIST_BIT (TRANSLATE (this_char));
  14413. -    }
  14414. -  
  14415. -  return REG_NOERROR;
  14416. -}
  14417. -
  14418. -/* Failure stack declarations and macros; both re_compile_fastmap and
  14419. -   re_match_2 use a failure stack.  These have to be macros because of
  14420. -   REGEX_ALLOCATE.  */
  14421. -   
  14422. -
  14423. -/* Number of failure points for which to initially allocate space
  14424. -   when matching.  If this number is exceeded, we allocate more
  14425. -   space, so it is not a hard limit.  */
  14426. -#ifndef INIT_FAILURE_ALLOC
  14427. -#define INIT_FAILURE_ALLOC 5
  14428. -#endif
  14429. -
  14430. -/* Roughly the maximum number of failure points on the stack.  Would be
  14431. -   exactly that if always used MAX_FAILURE_SPACE each time we failed.
  14432. -   This is a variable only so users of regex can assign to it; we never
  14433. -   change it ourselves.  */
  14434. -int re_max_failures = 2000;
  14435. -
  14436. -typedef const unsigned char *fail_stack_elt_t;
  14437. -
  14438. -typedef struct
  14439. -{
  14440. -  fail_stack_elt_t *stack;
  14441. -  unsigned size;
  14442. -  unsigned avail;            /* Offset of next open position.  */
  14443. -} fail_stack_type;
  14444. -
  14445. -#define FAIL_STACK_EMPTY()     (fail_stack.avail == 0)
  14446. -#define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0)
  14447. -#define FAIL_STACK_FULL()      (fail_stack.avail == fail_stack.size)
  14448. -#define FAIL_STACK_TOP()       (fail_stack.stack[fail_stack.avail])
  14449. -
  14450. -
  14451. -/* Initialize `fail_stack'.  Do `return -2' if the alloc fails.  */
  14452. -
  14453. -#define INIT_FAIL_STACK()                        \
  14454. -  do {                                    \
  14455. -    fail_stack.stack = (fail_stack_elt_t *)                \
  14456. -      REGEX_ALLOCATE (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t));    \
  14457. -                                    \
  14458. -    if (fail_stack.stack == NULL)                    \
  14459. -      return -2;                            \
  14460. -                                    \
  14461. -    fail_stack.size = INIT_FAILURE_ALLOC;                \
  14462. -    fail_stack.avail = 0;                        \
  14463. -  } while (0)
  14464. -
  14465. -
  14466. -/* Double the size of FAIL_STACK, up to approximately `re_max_failures' items.
  14467. -
  14468. -   Return 1 if succeeds, and 0 if either ran out of memory
  14469. -   allocating space for it or it was already too large.  
  14470. -   
  14471. -   REGEX_REALLOCATE requires `destination' be declared.   */
  14472. -
  14473. -#define DOUBLE_FAIL_STACK(fail_stack)                    \
  14474. -  ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS        \
  14475. -   ? 0                                    \
  14476. -   : ((fail_stack).stack = (fail_stack_elt_t *)                \
  14477. -        REGEX_REALLOCATE ((fail_stack).stack,                 \
  14478. -          (fail_stack).size * sizeof (fail_stack_elt_t),        \
  14479. -          ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)),    \
  14480. -                                    \
  14481. -      (fail_stack).stack == NULL                    \
  14482. -      ? 0                                \
  14483. -      : ((fail_stack).size <<= 1,                     \
  14484. -         1)))
  14485. -
  14486. -
  14487. -/* Push PATTERN_OP on FAIL_STACK. 
  14488. -
  14489. -   Return 1 if was able to do so and 0 if ran out of memory allocating
  14490. -   space to do so.  */
  14491. -#define PUSH_PATTERN_OP(pattern_op, fail_stack)                \
  14492. -  ((FAIL_STACK_FULL ()                            \
  14493. -    && !DOUBLE_FAIL_STACK (fail_stack))                    \
  14494. -    ? 0                                    \
  14495. -    : ((fail_stack).stack[(fail_stack).avail++] = pattern_op,        \
  14496. -       1))
  14497. -
  14498. -/* This pushes an item onto the failure stack.  Must be a four-byte
  14499. -   value.  Assumes the variable `fail_stack'.  Probably should only
  14500. -   be called from within `PUSH_FAILURE_POINT'.  */
  14501. -#define PUSH_FAILURE_ITEM(item)                        \
  14502. -  fail_stack.stack[fail_stack.avail++] = (fail_stack_elt_t) item
  14503. -
  14504. -/* The complement operation.  Assumes `fail_stack' is nonempty.  */
  14505. -#define POP_FAILURE_ITEM() fail_stack.stack[--fail_stack.avail]
  14506. -
  14507. -/* Used to omit pushing failure point id's when we're not debugging.  */
  14508. -#ifdef DEBUG
  14509. -#define DEBUG_PUSH PUSH_FAILURE_ITEM
  14510. -#define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_ITEM ()
  14511. -#else
  14512. -#define DEBUG_PUSH(item)
  14513. -#define DEBUG_POP(item_addr)
  14514. -#endif
  14515. -
  14516. -
  14517. -/* Push the information about the state we will need
  14518. -   if we ever fail back to it.  
  14519. -   
  14520. -   Requires variables fail_stack, regstart, regend, reg_info, and
  14521. -   num_regs be declared.  DOUBLE_FAIL_STACK requires `destination' be
  14522. -   declared.
  14523. -   
  14524. -   Does `return FAILURE_CODE' if runs out of memory.  */
  14525. -
  14526. -#define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code)    \
  14527. -  do {                                    \
  14528. -    char *destination;                            \
  14529. -    /* Must be int, so when we don't save any registers, the arithmetic    \
  14530. -       of 0 + -1 isn't done as unsigned.  */                \
  14531. -    /* Can't be int, since there is not a shred of a guarantee that int \
  14532. -       is wide enough to hold a value of something to which pointer can \
  14533. -       be assigned */                            \
  14534. -    s_reg_t this_reg;                            \
  14535. -                                        \
  14536. -    DEBUG_STATEMENT (failure_id++);                    \
  14537. -    DEBUG_STATEMENT (nfailure_points_pushed++);                \
  14538. -    DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id);        \
  14539. -    DEBUG_PRINT2 ("  Before push, next avail: %d\n", (fail_stack).avail);\
  14540. -    DEBUG_PRINT2 ("                     size: %d\n", (fail_stack).size);\
  14541. -                                    \
  14542. -    DEBUG_PRINT2 ("  slots needed: %d\n", NUM_FAILURE_ITEMS);        \
  14543. -    DEBUG_PRINT2 ("     available: %d\n", REMAINING_AVAIL_SLOTS);    \
  14544. -                                    \
  14545. -    /* Ensure we have enough space allocated for what we will push.  */    \
  14546. -    while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS)            \
  14547. -      {                                    \
  14548. -    if (!DOUBLE_FAIL_STACK (fail_stack))            \
  14549. -      return failure_code;                        \
  14550. -                                    \
  14551. -    DEBUG_PRINT2 ("\n  Doubled stack; size now: %d\n",        \
  14552. -               (fail_stack).size);                \
  14553. -    DEBUG_PRINT2 ("  slots available: %d\n", REMAINING_AVAIL_SLOTS);\
  14554. -      }                                    
  14555. -
  14556. -#define PUSH_FAILURE_POINT2(pattern_place, string_place, failure_code)    \
  14557. -    /* Push the info, starting with the registers.  */            \
  14558. -    DEBUG_PRINT1 ("\n");                        \
  14559. -                                    \
  14560. -    PUSH_FAILURE_POINT_LOOP ();                        \
  14561. -                                    \
  14562. -    DEBUG_PRINT2 ("  Pushing  low active reg: %d\n", lowest_active_reg);\
  14563. -    PUSH_FAILURE_ITEM (lowest_active_reg);                \
  14564. -                                    \
  14565. -    DEBUG_PRINT2 ("  Pushing high active reg: %d\n", highest_active_reg);\
  14566. -    PUSH_FAILURE_ITEM (highest_active_reg);                \
  14567. -                                    \
  14568. -    DEBUG_PRINT2 ("  Pushing pattern 0x%x: ", pattern_place);        \
  14569. -    DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend);        \
  14570. -    PUSH_FAILURE_ITEM (pattern_place);                    \
  14571. -                                    \
  14572. -    DEBUG_PRINT2 ("  Pushing string 0x%x: `", string_place);        \
  14573. -    DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2,    \
  14574. -                 size2);                \
  14575. -    DEBUG_PRINT1 ("'\n");                        \
  14576. -    PUSH_FAILURE_ITEM (string_place);                    \
  14577. -                                    \
  14578. -    DEBUG_PRINT2 ("  Pushing failure id: %u\n", failure_id);        \
  14579. -    DEBUG_PUSH (failure_id);                        \
  14580. -  } while (0)
  14581. -
  14582. -/*  Pulled out of PUSH_FAILURE_POINT() to shorten the definition
  14583. -    of that macro.  (for VAX C) */
  14584. -#define PUSH_FAILURE_POINT_LOOP()                    \
  14585. -    for (this_reg = lowest_active_reg; this_reg <= highest_active_reg;    \
  14586. -     this_reg++)                            \
  14587. -      {                                    \
  14588. -    DEBUG_PRINT2 ("  Pushing reg: %d\n", this_reg);            \
  14589. -    DEBUG_STATEMENT (num_regs_pushed++);                \
  14590. -                                    \
  14591. -    DEBUG_PRINT2 ("    start: 0x%x\n", regstart[this_reg]);        \
  14592. -    PUSH_FAILURE_ITEM (regstart[this_reg]);                \
  14593. -                                    \
  14594. -    DEBUG_PRINT2 ("    end: 0x%x\n", regend[this_reg]);        \
  14595. -    PUSH_FAILURE_ITEM (regend[this_reg]);                \
  14596. -                                    \
  14597. -    DEBUG_PRINT2 ("    info: 0x%x\n      ", reg_info[this_reg]);    \
  14598. -    DEBUG_PRINT2 (" match_null=%d",                    \
  14599. -              REG_MATCH_NULL_STRING_P (reg_info[this_reg]));    \
  14600. -    DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg]));    \
  14601. -    DEBUG_PRINT2 (" matched_something=%d",                \
  14602. -              MATCHED_SOMETHING (reg_info[this_reg]));        \
  14603. -    DEBUG_PRINT2 (" ever_matched=%d",                \
  14604. -              EVER_MATCHED_SOMETHING (reg_info[this_reg]));    \
  14605. -    DEBUG_PRINT1 ("\n");                        \
  14606. -    PUSH_FAILURE_ITEM (reg_info[this_reg].word);            \
  14607. -      }
  14608. -
  14609. -/* This is the number of items that are pushed and popped on the stack
  14610. -   for each register.  */
  14611. -#define NUM_REG_ITEMS  3
  14612. -
  14613. -/* Individual items aside from the registers.  */
  14614. -#ifdef DEBUG
  14615. -#define NUM_NONREG_ITEMS 5 /* Includes failure point id.  */
  14616. -#else
  14617. -#define NUM_NONREG_ITEMS 4
  14618. -#endif
  14619. -
  14620. -/* We push at most this many items on the stack.  */
  14621. -#define MAX_FAILURE_ITEMS ((num_regs - 1) * NUM_REG_ITEMS + NUM_NONREG_ITEMS)
  14622. -
  14623. -/* We actually push this many items.  */
  14624. -#define NUM_FAILURE_ITEMS                        \
  14625. -  ((highest_active_reg - lowest_active_reg + 1) * NUM_REG_ITEMS     \
  14626. -    + NUM_NONREG_ITEMS)
  14627. -
  14628. -/* How many items can still be added to the stack without overflowing it.  */
  14629. -#define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail)
  14630. -
  14631. -
  14632. -/* Pops what PUSH_FAIL_STACK pushes.
  14633. -
  14634. -   We restore into the parameters, all of which should be lvalues:
  14635. -     STR -- the saved data position.
  14636. -     PAT -- the saved pattern position.
  14637. -     LOW_REG, HIGH_REG -- the highest and lowest active registers.
  14638. -     REGSTART, REGEND -- arrays of string positions.
  14639. -     REG_INFO -- array of information about each subexpression.
  14640. -   
  14641. -   Also assumes the variables `fail_stack' and (if debugging), `bufp',
  14642. -   `pend', `string1', `size1', `string2', and `size2'.  */
  14643. +     signed char *.
  14644.  
  14645. -#define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\
  14646. -{                                    \
  14647. -  DEBUG_STATEMENT (fail_stack_elt_t failure_id;)            \
  14648. -  s_reg_t this_reg;                            \
  14649. -  const unsigned char *string_temp;                    \
  14650. -                                    \
  14651. -  assert (!FAIL_STACK_EMPTY ());                    \
  14652. -                                    \
  14653. -  /* Remove failure points and point to how many regs pushed.  */    \
  14654. -  DEBUG_PRINT1 ("POP_FAILURE_POINT:\n");                \
  14655. -  DEBUG_PRINT2 ("  Before pop, next avail: %d\n", fail_stack.avail);    \
  14656. -  DEBUG_PRINT2 ("                    size: %d\n", fail_stack.size);    \
  14657. -                                    \
  14658. -  assert (fail_stack.avail >= NUM_NONREG_ITEMS);            \
  14659. -                                    \
  14660. -  DEBUG_POP (&failure_id);                        \
  14661. -  DEBUG_PRINT2 ("  Popping failure id: %u\n", failure_id);        \
  14662. -                                    \
  14663. -  /* If the saved string location is NULL, it came from an        \
  14664. -     on_failure_keep_string_jump opcode, and we want to throw away the    \
  14665. -     saved NULL, thus retaining our current position in the string.  */    \
  14666. -  string_temp = POP_FAILURE_ITEM ();                    \
  14667. -  if (string_temp != NULL)                        \
  14668. -    str = (const char *) string_temp;                    \
  14669. -                                    \
  14670. -  DEBUG_PRINT2 ("  Popping string 0x%x: `", str);            \
  14671. -  DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2);    \
  14672. -  DEBUG_PRINT1 ("'\n");                            \
  14673. -                                    \
  14674. -  pat = (unsigned char *) POP_FAILURE_ITEM ();                \
  14675. -  DEBUG_PRINT2 ("  Popping pattern 0x%x: ", pat);            \
  14676. -  DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend);            \
  14677. -                                    \
  14678. -  POP_FAILURE_POINT2 (low_reg, high_reg, regstart, regend, reg_info);
  14679. +     We also want to fetch the endpoints without translating them; the 
  14680. +     appropriate translation is done in the bit-setting loop below.  */
  14681. +  /* The SVR4 compiler on the 3B2 had trouble with unsigned const char *.  */
  14682. +  range_start = ((const unsigned char *) p)[-2];
  14683. +  range_end   = ((const unsigned char *) p)[0];
  14684.  
  14685. -/*  Pulled out of POP_FAILURE_POINT() to shorten the definition
  14686. -    of that macro.  (for MSC 5.1) */
  14687. -#define POP_FAILURE_POINT2(low_reg, high_reg, regstart, regend, reg_info) \
  14688. -                                    \
  14689. -  /* Restore register info.  */                        \
  14690. -  high_reg = (active_reg_t) POP_FAILURE_ITEM ();            \
  14691. -  DEBUG_PRINT2 ("  Popping high active reg: %d\n", high_reg);        \
  14692. -                                    \
  14693. -  low_reg = (active_reg_t) POP_FAILURE_ITEM ();                \
  14694. -  DEBUG_PRINT2 ("  Popping  low active reg: %d\n", low_reg);        \
  14695. -                                    \
  14696. -  for (this_reg = high_reg; this_reg >= low_reg; this_reg--)        \
  14697. -    {                                    \
  14698. -      DEBUG_PRINT2 ("    Popping reg: %d\n", this_reg);            \
  14699. -                                    \
  14700. -      reg_info[this_reg].word = POP_FAILURE_ITEM ();            \
  14701. -      DEBUG_PRINT2 ("      info: 0x%x\n", reg_info[this_reg]);        \
  14702. -                                    \
  14703. -      regend[this_reg] = (const char *) POP_FAILURE_ITEM ();        \
  14704. -      DEBUG_PRINT2 ("      end: 0x%x\n", regend[this_reg]);        \
  14705. -                                    \
  14706. -      regstart[this_reg] = (const char *) POP_FAILURE_ITEM ();        \
  14707. -      DEBUG_PRINT2 ("      start: 0x%x\n", regstart[this_reg]);        \
  14708. -    }                                    \
  14709. -                                    \
  14710. -  DEBUG_STATEMENT (nfailure_points_popped++);                \
  14711. -} /* POP_FAILURE_POINT */
  14712. +  /* Have to increment the pointer into the pattern string, so the
  14713. +     caller isn't still at the ending character.  */
  14714. +  (*p_ptr)++;
  14715. +
  14716. +  /* If the start is after the end, the range is empty.  */
  14717. +  if (range_start > range_end)
  14718. +    return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR;
  14719.  
  14720. +  /* Here we see why `this_char' has to be larger than an `unsigned
  14721. +     char' -- the range is inclusive, so if `range_end' == 0xff
  14722. +     (assuming 8-bit characters), we would otherwise go into an infinite
  14723. +     loop, since all characters <= 0xff.  */
  14724. +  for (this_char = range_start; this_char <= range_end; this_char++)
  14725. +    {
  14726. +      SET_LIST_BIT (TRANSLATE (this_char));
  14727. +    }
  14728. +  
  14729. +  return REG_NOERROR;
  14730. +}
  14731.  
  14732.  /* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in
  14733.     BUFP.  A fastmap records which of the (1 << BYTEWIDTH) possible
  14734. @@ -2645,7 +2950,9 @@ re_compile_fastmap (bufp)
  14735.       struct re_pattern_buffer *bufp;
  14736.  {
  14737.    int j, k;
  14738. +#ifdef MATCH_MAY_ALLOCATE
  14739.    fail_stack_type fail_stack;
  14740. +#endif
  14741.  #ifndef REGEX_MALLOC
  14742.    char *destination;
  14743.  #endif
  14744. @@ -2654,9 +2961,13 @@ re_compile_fastmap (bufp)
  14745.    
  14746.    register char *fastmap = bufp->fastmap;
  14747.    unsigned char *pattern = bufp->buffer;
  14748. -  const unsigned char *p = pattern;
  14749. +  unsigned char *p = pattern;
  14750.    register unsigned char *pend = pattern + bufp->used;
  14751.  
  14752. +  /* This holds the pointer to the failure stack, when
  14753. +     it is allocated relocatably.  */
  14754. +  fail_stack_elt_t *failure_stack_ptr;
  14755. +
  14756.    /* Assume that each path through the pattern can be null until
  14757.       proven otherwise.  We set this false at the bottom of switch
  14758.       statement, to which we get only if a particular path doesn't
  14759. @@ -2673,26 +2984,30 @@ re_compile_fastmap (bufp)
  14760.    bufp->fastmap_accurate = 1;        /* It will be when we're done.  */
  14761.    bufp->can_be_null = 0;
  14762.        
  14763. -  while (p != pend || !FAIL_STACK_EMPTY ())
  14764. +  while (1)
  14765.      {
  14766. -      if (p == pend)
  14767. -        {
  14768. -          bufp->can_be_null |= path_can_be_null;
  14769. -          
  14770. -          /* Reset for next path.  */
  14771. -          path_can_be_null = true;
  14772. -          
  14773. -          p = fail_stack.stack[--fail_stack.avail];
  14774. +      if (p == pend || *p == succeed)
  14775. +    {
  14776. +      /* We have reached the (effective) end of pattern.  */
  14777. +      if (!FAIL_STACK_EMPTY ())
  14778. +        {
  14779. +          bufp->can_be_null |= path_can_be_null;
  14780. +
  14781. +          /* Reset for next path.  */
  14782. +          path_can_be_null = true;
  14783. +
  14784. +          p = fail_stack.stack[--fail_stack.avail].pointer;
  14785. +
  14786. +          continue;
  14787. +        }
  14788. +      else
  14789. +        break;
  14790.      }
  14791.  
  14792.        /* We should never be about to go beyond the end of the pattern.  */
  14793.        assert (p < pend);
  14794.        
  14795. -#ifdef SWITCH_ENUM_BUG
  14796. -      switch ((int) ((re_opcode_t) *p++))
  14797. -#else
  14798. -      switch ((re_opcode_t) *p++)
  14799. -#endif
  14800. +      switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++))
  14801.      {
  14802.  
  14803.          /* I guess the idea here is to simply not bother with a fastmap
  14804. @@ -2702,7 +3017,7 @@ re_compile_fastmap (bufp)
  14805.             that is all we do.  */
  14806.      case duplicate:
  14807.        bufp->can_be_null = 1;
  14808. -          return 0;
  14809. +          goto done;
  14810.  
  14811.  
  14812.        /* Following are the cases which match a character.  These end
  14813. @@ -2746,22 +3061,25 @@ re_compile_fastmap (bufp)
  14814.  
  14815.  
  14816.          case anychar:
  14817. -          /* `.' matches anything ...  */
  14818. -      for (j = 0; j < (1 << BYTEWIDTH); j++)
  14819. -            fastmap[j] = 1;
  14820. +      {
  14821. +        int fastmap_newline = fastmap['\n'];
  14822.  
  14823. -          /* ... except perhaps newline.  */
  14824. -          if (!(bufp->syntax & RE_DOT_NEWLINE))
  14825. -            fastmap['\n'] = 0;
  14826. -
  14827. -          /* Return if we have already set `can_be_null'; if we have,
  14828. -             then the fastmap is irrelevant.  Something's wrong here.  */
  14829. -      else if (bufp->can_be_null)
  14830. -        return 0;
  14831. +        /* `.' matches anything ...  */
  14832. +        for (j = 0; j < (1 << BYTEWIDTH); j++)
  14833. +          fastmap[j] = 1;
  14834.  
  14835. -          /* Otherwise, have to check alternative paths.  */
  14836. -      break;
  14837. +        /* ... except perhaps newline.  */
  14838. +        if (!(bufp->syntax & RE_DOT_NEWLINE))
  14839. +          fastmap['\n'] = fastmap_newline;
  14840. +
  14841. +        /* Return if we have already set `can_be_null'; if we have,
  14842. +           then the fastmap is irrelevant.  Something's wrong here.  */
  14843. +        else if (bufp->can_be_null)
  14844. +          goto done;
  14845.  
  14846. +        /* Otherwise, have to check alternative paths.  */
  14847. +        break;
  14848. +      }
  14849.  
  14850.  #ifdef emacs
  14851.          case syntaxspec:
  14852. @@ -2830,7 +3148,7 @@ re_compile_fastmap (bufp)
  14853.        
  14854.            /* If what's on the stack is where we are now, pop it.  */
  14855.            if (!FAIL_STACK_EMPTY () 
  14856. -          && fail_stack.stack[fail_stack.avail - 1] == p)
  14857. +          && fail_stack.stack[fail_stack.avail - 1].pointer == p)
  14858.              fail_stack.avail--;
  14859.  
  14860.            continue;
  14861. @@ -2851,7 +3169,10 @@ re_compile_fastmap (bufp)
  14862.            if (p + j < pend)
  14863.              {
  14864.                if (!PUSH_PATTERN_OP (p + j, fail_stack))
  14865. -                return -2;
  14866. +        {
  14867. +          RESET_FAIL_STACK ();
  14868. +          return -2;
  14869. +        }
  14870.              }
  14871.            else
  14872.              bufp->can_be_null = 1;
  14873. @@ -2908,6 +3229,9 @@ re_compile_fastmap (bufp)
  14874.    /* Set `can_be_null' for the last path (also the first path, if the
  14875.       pattern is empty).  */
  14876.    bufp->can_be_null |= path_can_be_null;
  14877. +
  14878. + done:
  14879. +  RESET_FAIL_STACK ();
  14880.    return 0;
  14881.  } /* re_compile_fastmap */
  14882.  
  14883. @@ -2942,7 +3266,7 @@ re_set_registers (bufp, regs, num_regs, 
  14884.      {
  14885.        bufp->regs_allocated = REGS_UNALLOCATED;
  14886.        regs->num_regs = 0;
  14887. -      regs->start = regs->end = 0;
  14888. +      regs->start = regs->end = (regoff_t *) 0;
  14889.      }
  14890.  }
  14891.  
  14892. @@ -3075,8 +3399,14 @@ re_search_2 (bufp, string1, size1, strin
  14893.            && !bufp->can_be_null)
  14894.      return -1;
  14895.  
  14896. -      val = re_match_2 (bufp, string1, size1, string2, size2,
  14897. -                    startpos, regs, stop);
  14898. +      val = re_match_2_internal (bufp, string1, size1, string2, size2,
  14899. +                 startpos, regs, stop);
  14900. +#ifndef REGEX_MALLOC
  14901. +#ifdef C_ALLOCA
  14902. +      alloca (0);
  14903. +#endif
  14904. +#endif
  14905. +
  14906.        if (val >= 0)
  14907.      return startpos;
  14908.          
  14909. @@ -3100,79 +3430,12 @@ re_search_2 (bufp, string1, size1, strin
  14910.    return -1;
  14911.  } /* re_search_2 */
  14912.  
  14913. -/* Structure for per-register (a.k.a. per-group) information.
  14914. -   This must not be longer than one word, because we push this value
  14915. -   onto the failure stack.  Other register information, such as the
  14916. -   starting and ending positions (which are addresses), and the list of
  14917. -   inner groups (which is a bits list) are maintained in separate
  14918. -   variables.  
  14919. -   
  14920. -   We are making a (strictly speaking) nonportable assumption here: that
  14921. -   the compiler will pack our bit fields into something that fits into
  14922. -   the type of `word', i.e., is something that fits into one item on the
  14923. -   failure stack.  */
  14924. -
  14925. -/* Declarations and macros for re_match_2.  */
  14926. -
  14927. -typedef union
  14928. -{
  14929. -  fail_stack_elt_t word;
  14930. -  struct
  14931. -  {
  14932. -      /* This field is one if this group can match the empty string,
  14933. -         zero if not.  If not yet determined,  `MATCH_NULL_UNSET_VALUE'.  */
  14934. -#define MATCH_NULL_UNSET_VALUE 3
  14935. -    unsigned match_null_string_p : 2;
  14936. -    unsigned is_active : 1;
  14937. -    unsigned matched_something : 1;
  14938. -    unsigned ever_matched_something : 1;
  14939. -  } bits;
  14940. -} register_info_type;
  14941. -
  14942. -#define REG_MATCH_NULL_STRING_P(R)  ((R).bits.match_null_string_p)
  14943. -#define IS_ACTIVE(R)  ((R).bits.is_active)
  14944. -#define MATCHED_SOMETHING(R)  ((R).bits.matched_something)
  14945. -#define EVER_MATCHED_SOMETHING(R)  ((R).bits.ever_matched_something)
  14946. -
  14947. -static boolean group_match_null_string_p _RE_ARGS((unsigned char **p,
  14948. -                           unsigned char *end,
  14949. -                        register_info_type *reg_info));
  14950. -static boolean alt_match_null_string_p _RE_ARGS((unsigned char *p,
  14951. -                         unsigned char *end,
  14952. -                      register_info_type *reg_info));
  14953. -static boolean common_op_match_null_string_p _RE_ARGS((unsigned char **p,
  14954. -                               unsigned char *end,
  14955. -                        register_info_type *reg_info));
  14956. -static int bcmp_translate _RE_ARGS((const char *s1, const char *s2,
  14957. -                    int len, char *translate));
  14958. -
  14959. -/* Call this when have matched a real character; it sets `matched' flags
  14960. -   for the subexpressions which we are currently inside.  Also records
  14961. -   that those subexprs have matched.  */
  14962. -#define SET_REGS_MATCHED()                        \
  14963. -  do                                    \
  14964. -    {                                    \
  14965. -      active_reg_t r;                            \
  14966. -      for (r = lowest_active_reg; r <= highest_active_reg; r++)        \
  14967. -        {                                \
  14968. -          MATCHED_SOMETHING (reg_info[r])                \
  14969. -            = EVER_MATCHED_SOMETHING (reg_info[r])            \
  14970. -            = 1;                            \
  14971. -        }                                \
  14972. -    }                                    \
  14973. -  while (0)
  14974. -
  14975. -
  14976.  /* This converts PTR, a pointer into one of the search strings `string1'
  14977.     and `string2' into an offset from the beginning of that string.  */
  14978. -#define POINTER_TO_OFFSET(ptr)                        \
  14979. -  (FIRST_STRING_P (ptr) ? (ptr) - string1 : (ptr) - string2 + size1)
  14980. -
  14981. -/* Registers are set to a sentinel when they haven't yet matched.  */
  14982. -static char reg_unset_dummy;
  14983. -#define REG_UNSET_VALUE (®_unset_dummy)
  14984. -#define REG_UNSET(e) ((e) == REG_UNSET_VALUE)
  14985. -
  14986. +#define POINTER_TO_OFFSET(ptr)            \
  14987. +  (FIRST_STRING_P (ptr)                \
  14988. +   ? ((regoff_t) ((ptr) - string1))        \
  14989. +   : ((regoff_t) ((ptr) - string2 + size1)))
  14990.  
  14991.  /* Macros for dealing with the split strings in re_match_2.  */
  14992.  
  14993. @@ -3215,11 +3478,11 @@ static char reg_unset_dummy;
  14994.  
  14995.  
  14996.  /* Free everything we malloc.  */
  14997. -#ifdef REGEX_MALLOC
  14998. -#define FREE_VAR(var) if (var) free (var); var = NULL
  14999. +#ifdef MATCH_MAY_ALLOCATE
  15000. +#define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL
  15001.  #define FREE_VARIABLES()                        \
  15002.    do {                                    \
  15003. -    FREE_VAR (fail_stack.stack);                    \
  15004. +    REGEX_FREE_STACK (fail_stack.stack);                \
  15005.      FREE_VAR (regstart);                        \
  15006.      FREE_VAR (regend);                            \
  15007.      FREE_VAR (old_regstart);                        \
  15008. @@ -3230,11 +3493,9 @@ static char reg_unset_dummy;
  15009.      FREE_VAR (reg_dummy);                        \
  15010.      FREE_VAR (reg_info_dummy);                        \
  15011.    } while (0)
  15012. -#else /* not REGEX_MALLOC */
  15013. -/* Some MIPS systems (at least) want this to free alloca'd storage.  */
  15014. -#define FREE_VARIABLES() alloca (0)
  15015. -#endif /* not REGEX_MALLOC */
  15016. -
  15017. +#else
  15018. +#define FREE_VARIABLES() ((void)0) /* Do nothing!  But inhibit gcc warning.  */
  15019. +#endif /* not MATCH_MAY_ALLOCATE */
  15020.  
  15021.  /* These values must meet several constraints.  They must not be valid
  15022.     register values; since we have a limit of 255 registers (because
  15023. @@ -3257,11 +3518,25 @@ re_match (bufp, string, size, pos, regs)
  15024.       const char *string;
  15025.       int size, pos;
  15026.       struct re_registers *regs;
  15027. - {
  15028. -  return re_match_2 (bufp, NULL, 0, string, size, pos, regs, size); 
  15029. +{
  15030. +  int result = re_match_2_internal (bufp, NULL, 0, string, size,
  15031. +                    pos, regs, size);
  15032. +  alloca (0);
  15033. +  return result;
  15034.  }
  15035.  #endif /* not emacs */
  15036.  
  15037. +static boolean group_match_null_string_p _RE_ARGS((unsigned char **p,
  15038. +                           unsigned char *end,
  15039. +                        register_info_type *reg_info));
  15040. +static boolean alt_match_null_string_p _RE_ARGS((unsigned char *p,
  15041. +                         unsigned char *end,
  15042. +                      register_info_type *reg_info));
  15043. +static boolean common_op_match_null_string_p _RE_ARGS((unsigned char **p,
  15044. +                               unsigned char *end,
  15045. +                        register_info_type *reg_info));
  15046. +static int bcmp_translate _RE_ARGS((const char *s1, const char *s2,
  15047. +                    int len, char *translate));
  15048.  
  15049.  /* re_match_2 matches the compiled pattern in BUFP against the
  15050.     the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1
  15051. @@ -3285,6 +3560,23 @@ re_match_2 (bufp, string1, size1, string
  15052.       struct re_registers *regs;
  15053.       int stop;
  15054.  {
  15055. +  int result = re_match_2_internal (bufp, string1, size1, string2, size2,
  15056. +                    pos, regs, stop);
  15057. +  alloca (0);
  15058. +  return result;
  15059. +}
  15060. +
  15061. +/* This is a separate function so that we can force an alloca cleanup
  15062. +   afterwards.  */
  15063. +static int
  15064. +re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop)
  15065. +     struct re_pattern_buffer *bufp;
  15066. +     const char *string1, *string2;
  15067. +     int size1, size2;
  15068. +     int pos;
  15069. +     struct re_registers *regs;
  15070. +     int stop;
  15071. +{
  15072.    /* General temporaries.  */
  15073.    int mcnt;
  15074.    unsigned char *p1;
  15075. @@ -3303,6 +3595,10 @@ re_match_2 (bufp, string1, size1, string
  15076.    unsigned char *p = bufp->buffer;
  15077.    register unsigned char *pend = p + bufp->used;
  15078.  
  15079. +  /* Mark the opcode just after a start_memory, so we can test for an
  15080. +     empty subpattern when we get to the stop_memory.  */
  15081. +  unsigned char *just_past_start_mem = 0;
  15082. +
  15083.    /* We use this to map every character in the string.  */
  15084.    char *translate = bufp->translate;
  15085.  
  15086. @@ -3315,12 +3611,18 @@ re_match_2 (bufp, string1, size1, string
  15087.       scanning the strings.  If the latter is zero, the failure point is
  15088.       a ``dummy''; if a failure happens and the failure point is a dummy,
  15089.       it gets discarded and the next next one is tried.  */
  15090. +#ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global.  */
  15091.    fail_stack_type fail_stack;
  15092. +#endif
  15093.  #ifdef DEBUG
  15094.    static unsigned failure_id = 0;
  15095.    unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0;
  15096.  #endif
  15097.  
  15098. +  /* This holds the pointer to the failure stack, when
  15099. +     it is allocated relocatably.  */
  15100. +  fail_stack_elt_t *failure_stack_ptr;
  15101. +
  15102.    /* We fill all the registers internally, independent of what we
  15103.       return, for use in backreferences.  The number here includes
  15104.       an element for register zero.  */
  15105. @@ -3337,14 +3639,18 @@ re_match_2 (bufp, string1, size1, string
  15106.       matching and the regnum-th regend points to right after where we
  15107.       stopped matching the regnum-th subexpression.  (The zeroth register
  15108.       keeps track of what the whole pattern matches.)  */
  15109. +#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global.  */
  15110.    const char **regstart = 0, **regend = 0;
  15111. +#endif
  15112.  
  15113.    /* If a group that's operated upon by a repetition operator fails to
  15114.       match anything, then the register for its start will need to be
  15115.       restored because it will have been set to wherever in the string we
  15116.       are when we last see its open-group operator.  Similarly for a
  15117.       register's end.  */
  15118. +#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global.  */
  15119.    const char **old_regstart = 0, **old_regend = 0;
  15120. +#endif
  15121.  
  15122.    /* The is_active field of reg_info helps us keep track of which (possibly
  15123.       nested) subexpressions we are currently in. The matched_something
  15124. @@ -3352,14 +3658,18 @@ re_match_2 (bufp, string1, size1, string
  15125.       matched any of the pattern so far this time through the reg_num-th
  15126.       subexpression.  These two fields get reset each time through any
  15127.       loop their register is in.  */
  15128. +#ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global.  */
  15129.    register_info_type *reg_info = 0; 
  15130. +#endif
  15131.  
  15132.    /* The following record the register info as found in the above
  15133.       variables when we find a match better than any we've seen before. 
  15134.       This happens as we backtrack through the failure points, which in
  15135.       turn happens only if we have not yet matched the entire string. */
  15136.    unsigned best_regs_set = false;
  15137. +#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global.  */
  15138.    const char **best_regstart = 0, **best_regend = 0;
  15139. +#endif
  15140.    
  15141.    /* Logically, this is `best_regend[0]'.  But we don't want to have to
  15142.       allocate space for that if we're not allocating space for anything
  15143. @@ -3371,9 +3681,14 @@ re_match_2 (bufp, string1, size1, string
  15144.       and need to test it, it's not garbage.  */
  15145.    const char *match_end = NULL;
  15146.  
  15147. +  /* This helps SET_REGS_MATCHED avoid doing redundant work.  */
  15148. +  int set_regs_matched_done = 0;
  15149. +
  15150.    /* Used when we pop values we don't care about.  */
  15151. +#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global.  */
  15152.    const char **reg_dummy = 0;
  15153.    register_info_type *reg_info_dummy = 0;
  15154. +#endif
  15155.  
  15156.  #ifdef DEBUG
  15157.    /* Counts the total number of registers pushed.  */
  15158. @@ -3384,6 +3699,7 @@ re_match_2 (bufp, string1, size1, string
  15159.    
  15160.    INIT_FAIL_STACK ();
  15161.    
  15162. +#ifdef MATCH_MAY_ALLOCATE
  15163.    /* Do not bother to initialize all the register variables if there are
  15164.       no groups in the pattern, as it takes a fair amount of time.  If
  15165.       there are groups, we include space for register 0 (the whole
  15166. @@ -3408,7 +3724,6 @@ re_match_2 (bufp, string1, size1, string
  15167.            return -2;
  15168.          }
  15169.      }
  15170. -#ifdef REGEX_MALLOC
  15171.    else
  15172.      {
  15173.        /* We must initialize all our variables to NULL, so that
  15174. @@ -3417,7 +3732,7 @@ re_match_2 (bufp, string1, size1, string
  15175.          = best_regend = reg_dummy = NULL;
  15176.        reg_info = reg_info_dummy = (register_info_type *) NULL;
  15177.      }
  15178. -#endif /* REGEX_MALLOC */
  15179. +#endif /* MATCH_MAY_ALLOCATE */
  15180.  
  15181.    /* The starting position is bogus.  */
  15182.    if (pos < 0 || pos > size1 + size2)
  15183. @@ -3502,17 +3817,27 @@ re_match_2 (bufp, string1, size1, string
  15184.               longest match, try backtracking.  */
  15185.            if (d != end_match_2)
  15186.          {
  15187. +          /* 1 if this match ends in the same string (string1 or string2)
  15188. +         as the best previous match.  */
  15189. +          boolean same_str_p = (FIRST_STRING_P (match_end) 
  15190. +                    == MATCHING_IN_FIRST_STRING);
  15191. +          /* 1 if this match is the best seen so far.  */
  15192. +          boolean best_match_p;
  15193. +
  15194. +          /* AIX compiler got confused when this was combined
  15195. +         with the previous declaration.  */
  15196. +          if (same_str_p)
  15197. +        best_match_p = d > match_end;
  15198. +          else
  15199. +        best_match_p = !MATCHING_IN_FIRST_STRING;
  15200. +
  15201.                DEBUG_PRINT1 ("backtracking.\n");
  15202.                
  15203.                if (!FAIL_STACK_EMPTY ())
  15204.                  { /* More failure points to try.  */
  15205. -                  boolean same_str_p = (FIRST_STRING_P (match_end) 
  15206. -                                == MATCHING_IN_FIRST_STRING);
  15207.  
  15208.                    /* If exceeds best match so far, save it.  */
  15209. -                  if (!best_regs_set
  15210. -                      || (same_str_p && d > match_end)
  15211. -                      || (!same_str_p && !MATCHING_IN_FIRST_STRING))
  15212. +                  if (!best_regs_set || best_match_p)
  15213.                      {
  15214.                        best_regs_set = true;
  15215.                        match_end = d;
  15216. @@ -3528,8 +3853,10 @@ re_match_2 (bufp, string1, size1, string
  15217.                    goto fail;           
  15218.                  }
  15219.  
  15220. -              /* If no failure points, don't restore garbage.  */
  15221. -              else if (best_regs_set)   
  15222. +              /* If no failure points, don't restore garbage.  And if
  15223. +                 last match is real best match, don't restore second
  15224. +                 best one. */
  15225. +              else if (best_regs_set && !best_match_p)
  15226.                  {
  15227.                restore_best_regs:
  15228.                    /* Restore best match.  It may happen that `dend ==
  15229. @@ -3551,6 +3878,7 @@ re_match_2 (bufp, string1, size1, string
  15230.                  }
  15231.              } /* d != end_match_2 */
  15232.  
  15233. +    succeed_label:
  15234.            DEBUG_PRINT1 ("Accepting match.\n");
  15235.  
  15236.            /* If caller wants register contents data back, do it.  */
  15237. @@ -3565,7 +3893,10 @@ re_match_2 (bufp, string1, size1, string
  15238.                    regs->start = TALLOC (regs->num_regs, regoff_t);
  15239.                    regs->end = TALLOC (regs->num_regs, regoff_t);
  15240.                    if (regs->start == NULL || regs->end == NULL)
  15241. -                    return -2;
  15242. +            {
  15243. +              FREE_VARIABLES ();
  15244. +              return -2;
  15245. +            }
  15246.                    bufp->regs_allocated = REGS_REALLOCATE;
  15247.                  }
  15248.                else if (bufp->regs_allocated == REGS_REALLOCATE)
  15249. @@ -3578,7 +3909,10 @@ re_match_2 (bufp, string1, size1, string
  15250.                        RETALLOC (regs->start, regs->num_regs, regoff_t);
  15251.                        RETALLOC (regs->end, regs->num_regs, regoff_t);
  15252.                        if (regs->start == NULL || regs->end == NULL)
  15253. -                        return -2;
  15254. +            {
  15255. +              FREE_VARIABLES ();
  15256. +              return -2;
  15257. +            }
  15258.                      }
  15259.                  }
  15260.                else
  15261. @@ -3594,8 +3928,9 @@ re_match_2 (bufp, string1, size1, string
  15262.                if (regs->num_regs > 0)
  15263.                  {
  15264.                    regs->start[0] = pos;
  15265. -                  regs->end[0] = (MATCHING_IN_FIRST_STRING ? d - string1
  15266. -                      : d - string2 + size1);
  15267. +                  regs->end[0] = (MATCHING_IN_FIRST_STRING
  15268. +                  ? ((regoff_t) (d - string1))
  15269. +                      : ((regoff_t) (d - string2 + size1)));
  15270.                  }
  15271.                
  15272.                /* Go through the first `min (num_regs, regs->num_regs)'
  15273. @@ -3606,8 +3941,10 @@ re_match_2 (bufp, string1, size1, string
  15274.                      regs->start[mcnt] = regs->end[mcnt] = -1;
  15275.                    else
  15276.                      {
  15277. -              regs->start[mcnt] = POINTER_TO_OFFSET (regstart[mcnt]);
  15278. -                      regs->end[mcnt] = POINTER_TO_OFFSET (regend[mcnt]);
  15279. +              regs->start[mcnt]
  15280. +            = (regoff_t) POINTER_TO_OFFSET (regstart[mcnt]);
  15281. +                      regs->end[mcnt]
  15282. +            = (regoff_t) POINTER_TO_OFFSET (regend[mcnt]);
  15283.                      }
  15284.          }
  15285.                
  15286. @@ -3620,7 +3957,6 @@ re_match_2 (bufp, string1, size1, string
  15287.                  regs->start[mcnt] = regs->end[mcnt] = -1;
  15288.          } /* regs && !bufp->no_sub */
  15289.  
  15290. -          FREE_VARIABLES ();
  15291.            DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n",
  15292.                          nfailure_points_pushed, nfailure_points_popped,
  15293.                          nfailure_points_pushed - nfailure_points_popped);
  15294. @@ -3632,15 +3968,12 @@ re_match_2 (bufp, string1, size1, string
  15295.  
  15296.            DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt);
  15297.  
  15298. +          FREE_VARIABLES ();
  15299.            return mcnt;
  15300.          }
  15301.  
  15302.        /* Otherwise match next pattern command.  */
  15303. -#ifdef SWITCH_ENUM_BUG
  15304. -      switch ((int) ((re_opcode_t) *p++))
  15305. -#else
  15306. -      switch ((re_opcode_t) *p++)
  15307. -#endif
  15308. +      switch (SWITCH_ENUM_CAST ((re_opcode_t) *p++))
  15309.      {
  15310.          /* Ignore these.  Used to ignore the n of succeed_n's which
  15311.             currently have n == 0.  */
  15312. @@ -3648,6 +3981,9 @@ re_match_2 (bufp, string1, size1, string
  15313.            DEBUG_PRINT1 ("EXECUTING no_op.\n");
  15314.            break;
  15315.  
  15316. +    case succeed:
  15317. +          DEBUG_PRINT1 ("EXECUTING succeed.\n");
  15318. +      goto succeed_label;
  15319.  
  15320.          /* Match the next n pattern characters exactly.  The following
  15321.             byte in the pattern defines n, and the n bytes after that
  15322. @@ -3755,6 +4091,9 @@ re_match_2 (bufp, string1, size1, string
  15323.  
  15324.            IS_ACTIVE (reg_info[*p]) = 1;
  15325.            MATCHED_SOMETHING (reg_info[*p]) = 0;
  15326. +
  15327. +      /* Clear this whenever we change the register activity status.  */
  15328. +      set_regs_matched_done = 0;
  15329.            
  15330.            /* This is the new highest active register.  */
  15331.            highest_active_reg = *p;
  15332. @@ -3766,6 +4105,8 @@ re_match_2 (bufp, string1, size1, string
  15333.  
  15334.            /* Move past the register number and inner group count.  */
  15335.            p += 2;
  15336. +      just_past_start_mem = p;
  15337. +
  15338.            break;
  15339.  
  15340.  
  15341. @@ -3791,7 +4132,10 @@ re_match_2 (bufp, string1, size1, string
  15342.  
  15343.            /* This register isn't active anymore.  */
  15344.            IS_ACTIVE (reg_info[*p]) = 0;
  15345. -          
  15346. +
  15347. +      /* Clear this whenever we change the register activity status.  */
  15348. +      set_regs_matched_done = 0;
  15349. +
  15350.            /* If this was the only register active, nothing is active
  15351.               anymore.  */
  15352.            if (lowest_active_reg == highest_active_reg)
  15353. @@ -3830,7 +4174,7 @@ re_match_2 (bufp, string1, size1, string
  15354.               information for this group that we had before trying this
  15355.               last match.  */
  15356.            if ((!MATCHED_SOMETHING (reg_info[*p])
  15357. -               || (re_opcode_t) p[-3] == start_memory)
  15358. +               || just_past_start_mem == p - 1)
  15359.            && (p + 2) < pend)              
  15360.              {
  15361.                boolean is_a_jump_n = false;
  15362. @@ -3960,6 +4304,9 @@ re_match_2 (bufp, string1, size1, string
  15363.                      : bcmp (d, d2, mcnt))
  15364.            goto fail;
  15365.          d += mcnt, d2 += mcnt;
  15366. +
  15367. +        /* Do this because we've match some characters.  */
  15368. +        SET_REGS_MATCHED ();
  15369.            }
  15370.        }
  15371.        break;
  15372. @@ -4119,11 +4466,27 @@ re_match_2 (bufp, string1, size1, string
  15373.                 detect that here, the alternative has put on a dummy
  15374.                 failure point which is what we will end up popping.  */
  15375.  
  15376. -        /* Skip over open/close-group commands.  */
  15377. -        while (p2 + 2 < pend
  15378. -           && ((re_opcode_t) *p2 == stop_memory
  15379. -               || (re_opcode_t) *p2 == start_memory))
  15380. -          p2 += 3;            /* Skip over args, too.  */
  15381. +        /* Skip over open/close-group commands.
  15382. +           If what follows this loop is a ...+ construct,
  15383. +           look at what begins its body, since we will have to
  15384. +           match at least one of that.  */
  15385. +        while (1)
  15386. +          {
  15387. +        if (p2 + 2 < pend
  15388. +            && ((re_opcode_t) *p2 == stop_memory
  15389. +            || (re_opcode_t) *p2 == start_memory))
  15390. +          p2 += 3;
  15391. +        else if (p2 + 6 < pend
  15392. +             && (re_opcode_t) *p2 == dummy_failure_jump)
  15393. +          p2 += 6;
  15394. +        else
  15395. +          break;
  15396. +          }
  15397. +
  15398. +        p1 = p + mcnt;
  15399. +        /* p1[0] ... p1[2] are the `on_failure_jump' corresponding
  15400. +           to the `maybe_finalize_jump' of this case.  Examine what 
  15401. +           follows.  */
  15402.  
  15403.              /* If we're at the end of the pattern, we can change.  */
  15404.              if (p2 == pend)
  15405. @@ -4141,11 +4504,7 @@ re_match_2 (bufp, string1, size1, string
  15406.            {
  15407.          register unsigned char c
  15408.                    = *p2 == (unsigned char) endline ? '\n' : p2[2];
  15409. -        p1 = p + mcnt;
  15410.  
  15411. -                /* p1[0] ... p1[2] are the `on_failure_jump' corresponding
  15412. -                   to the `maybe_finalize_jump' of this case.  Examine what 
  15413. -                   follows.  */
  15414.                  if ((re_opcode_t) p1[3] == exactn && p1[5] != c)
  15415.                    {
  15416.                p[-3] = (unsigned char) pop_failure_jump;
  15417. @@ -4171,6 +4530,58 @@ re_match_2 (bufp, string1, size1, string
  15418.                        }
  15419.            }
  15420.            }
  15421. +            else if ((re_opcode_t) *p2 == charset)
  15422. +          {
  15423. +#ifdef DEBUG
  15424. +        register unsigned char c
  15425. +                  = *p2 == (unsigned char) endline ? '\n' : p2[2];
  15426. +#endif
  15427. +
  15428. +                if ((re_opcode_t) p1[3] == exactn
  15429. +            && ! ((int) p2[1] * BYTEWIDTH > (int) p1[4]
  15430. +              && (p2[1 + p1[4] / BYTEWIDTH]
  15431. +                  & (1 << (p1[4] % BYTEWIDTH)))))
  15432. +                  {
  15433. +              p[-3] = (unsigned char) pop_failure_jump;
  15434. +                    DEBUG_PRINT3 ("  %c != %c => pop_failure_jump.\n",
  15435. +                                  c, p1[5]);
  15436. +                  }
  15437. +                  
  15438. +        else if ((re_opcode_t) p1[3] == charset_not)
  15439. +          {
  15440. +            int idx;
  15441. +            /* We win if the charset_not inside the loop
  15442. +               lists every character listed in the charset after.  */
  15443. +            for (idx = 0; idx < (int) p2[1]; idx++)
  15444. +              if (! (p2[2 + idx] == 0
  15445. +                 || (idx < (int) p1[4]
  15446. +                 && ((p2[2 + idx] & ~ p1[5 + idx]) == 0))))
  15447. +            break;
  15448. +
  15449. +            if (idx == p2[1])
  15450. +                      {
  15451. +                  p[-3] = (unsigned char) pop_failure_jump;
  15452. +                        DEBUG_PRINT1 ("  No match => pop_failure_jump.\n");
  15453. +                      }
  15454. +          }
  15455. +        else if ((re_opcode_t) p1[3] == charset)
  15456. +          {
  15457. +            int idx;
  15458. +            /* We win if the charset inside the loop
  15459. +               has no overlap with the one after the loop.  */
  15460. +            for (idx = 0;
  15461. +             idx < (int) p2[1] && idx < (int) p1[4];
  15462. +             idx++)
  15463. +              if ((p2[2 + idx] & p1[5 + idx]) != 0)
  15464. +            break;
  15465. +
  15466. +            if (idx == p2[1] || idx == p1[4])
  15467. +                      {
  15468. +                  p[-3] = (unsigned char) pop_failure_jump;
  15469. +                        DEBUG_PRINT1 ("  No match => pop_failure_jump.\n");
  15470. +                      }
  15471. +          }
  15472. +          }
  15473.        }
  15474.        p -= 2;        /* Point at relative address again.  */
  15475.        if ((re_opcode_t) p[-1] != pop_failure_jump)
  15476. @@ -4329,7 +4740,6 @@ re_match_2 (bufp, string1, size1, string
  15477.            goto fail;
  15478.  
  15479.  #ifdef emacs
  15480. -#ifdef emacs19
  15481.        case before_dot:
  15482.            DEBUG_PRINT1 ("EXECUTING before_dot.\n");
  15483.         if (PTR_CHAR_POS ((unsigned char *) d) >= point)
  15484. @@ -4347,7 +4757,7 @@ re_match_2 (bufp, string1, size1, string
  15485.            if (PTR_CHAR_POS ((unsigned char *) d) <= point)
  15486.            goto fail;
  15487.          break;
  15488. -#else /* not emacs19 */
  15489. +#if 0 /* not emacs19 */
  15490.      case at_dot:
  15491.            DEBUG_PRINT1 ("EXECUTING at_dot.\n");
  15492.        if (PTR_CHAR_POS ((unsigned char *) d) + 1 != point)
  15493. @@ -4365,8 +4775,10 @@ re_match_2 (bufp, string1, size1, string
  15494.        mcnt = (int) Sword;
  15495.          matchsyntax:
  15496.        PREFETCH ();
  15497. -      if (SYNTAX (*d++) != (enum syntaxcode) mcnt)
  15498. -            goto fail;
  15499. +      /* Can't use *d++ here; SYNTAX may be an unsafe macro.  */
  15500. +      d++;
  15501. +      if (SYNTAX (d[-1]) != (enum syntaxcode) mcnt)
  15502. +        goto fail;
  15503.            SET_REGS_MATCHED ();
  15504.        break;
  15505.  
  15506. @@ -4380,8 +4792,10 @@ re_match_2 (bufp, string1, size1, string
  15507.        mcnt = (int) Sword;
  15508.          matchnotsyntax:
  15509.        PREFETCH ();
  15510. -      if (SYNTAX (*d++) == (enum syntaxcode) mcnt)
  15511. -            goto fail;
  15512. +      /* Can't use *d++ here; SYNTAX may be an unsafe macro.  */
  15513. +      d++;
  15514. +      if (SYNTAX (d[-1]) == (enum syntaxcode) mcnt)
  15515. +        goto fail;
  15516.        SET_REGS_MATCHED ();
  15517.            break;
  15518.  
  15519. @@ -4764,13 +5178,15 @@ re_compile_pattern (pattern, length, buf
  15520.    
  15521.    ret = regex_compile (pattern, length, re_syntax_options, bufp);
  15522.  
  15523. -  return re_error_msg[(int) ret];
  15524. +  if (!ret)
  15525. +    return NULL;
  15526. +  return gettext (re_error_msgid[(int) ret]);
  15527.  }     
  15528.  
  15529.  /* Entry points compatible with 4.2 BSD regex library.  We don't define
  15530. -   them if this is an Emacs or POSIX compilation.  */
  15531. +   them unless specifically requested.  */
  15532.  
  15533. -#if !defined (emacs) && !defined (_POSIX_SOURCE)
  15534. +#ifdef _REGEX_RE_COMP
  15535.  
  15536.  /* BSD has one and only one pattern buffer.  */
  15537.  static struct re_pattern_buffer re_comp_buf;
  15538. @@ -4784,7 +5200,7 @@ re_comp (s)
  15539.    if (!s)
  15540.      {
  15541.        if (!re_comp_buf.buffer)
  15542. -    return "No previous regular expression";
  15543. +    return gettext ("No previous regular expression");
  15544.        return 0;
  15545.      }
  15546.  
  15547. @@ -4792,12 +5208,12 @@ re_comp (s)
  15548.      {
  15549.        re_comp_buf.buffer = (unsigned char *) malloc (200);
  15550.        if (re_comp_buf.buffer == NULL)
  15551. -        return "Memory exhausted";
  15552. +        return gettext (re_error_msgid[(int) REG_ESPACE]);
  15553.        re_comp_buf.allocated = 200;
  15554.  
  15555.        re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH);
  15556.        if (re_comp_buf.fastmap == NULL)
  15557. -    return "Memory exhausted";
  15558. +    return gettext (re_error_msgid[(int) REG_ESPACE]);
  15559.      }
  15560.  
  15561.    /* Since `re_exec' always passes NULL for the `regs' argument, we
  15562. @@ -4808,8 +5224,11 @@ re_comp (s)
  15563.  
  15564.    ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf);
  15565.    
  15566. -  /* Yes, we're discarding `const' here.  */
  15567. -  return (char *) re_error_msg[(int) ret];
  15568. +  if (!ret)
  15569. +    return NULL;
  15570. +
  15571. +  /* Yes, we're discarding `const' here if !HAVE_LIBINTL.  */
  15572. +  return (char *) gettext (re_error_msgid[(int) ret]);
  15573.  }
  15574.  
  15575.  
  15576. @@ -4821,7 +5240,7 @@ re_exec (s)
  15577.    return
  15578.      0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0);
  15579.  }
  15580. -#endif /* not emacs and not _POSIX_SOURCE */
  15581. +#endif /* _REGEX_RE_COMP */
  15582.  
  15583.  /* POSIX.2 functions.  Don't define these for Emacs.  */
  15584.  
  15585. @@ -5013,19 +5432,14 @@ regerror (errcode, preg, errbuf, errbuf_
  15586.    size_t msg_size;
  15587.  
  15588.    if (errcode < 0
  15589. -      || errcode >= (sizeof (re_error_msg) / sizeof (re_error_msg[0])))
  15590. +      || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0])))
  15591.      /* Only error codes returned by the rest of the code should be passed 
  15592.         to this routine.  If we are given anything else, or if other regex
  15593.         code generates an invalid error code, then the program has a bug.
  15594.         Dump core so we can fix it.  */
  15595.      abort ();
  15596.  
  15597. -  msg = re_error_msg[errcode];
  15598. -
  15599. -  /* POSIX doesn't require that we do anything in this case, but why
  15600. -     not be nice.  */
  15601. -  if (! msg)
  15602. -    msg = "Success";
  15603. +  msg = gettext (re_error_msgid[errcode]);
  15604.  
  15605.    msg_size = strlen (msg) + 1; /* Includes the null.  */
  15606.    
  15607. diff -rup --new-file baseline/fsf/gawk/regex.h amiga/fsf/gawk/regex.h
  15608. --- baseline/fsf/gawk/regex.h    Thu Mar  9 09:29:15 1995
  15609. +++ amiga/fsf/gawk/regex.h    Sat Sep 28 00:00:00 1996
  15610. @@ -1,7 +1,7 @@
  15611.  /* Definitions for data structures and routines for the regular
  15612.     expression library, version 0.12.
  15613.  
  15614. -   Copyright (C) 1985, 1989, 1990-1995 Free Software Foundation, Inc.
  15615. +   Copyright (C) 1985, 89, 90, 91, 92, 93, 95 Free Software Foundation, Inc.
  15616.  
  15617.     This program is free software; you can redistribute it and/or modify
  15618.     it under the terms of the GNU General Public License as published by
  15619. @@ -23,7 +23,7 @@
  15620.  /* POSIX says that <sys/types.h> must be included (by the caller) before
  15621.     <regex.h>.  */
  15622.  
  15623. -#ifdef VMS
  15624. +#if !defined (_POSIX_C_SOURCE) && !defined (_POSIX_SOURCE) && defined (VMS)
  15625.  /* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
  15626.     should be there.  */
  15627.  #include <stddef.h>
  15628. @@ -137,9 +137,13 @@ typedef unsigned long reg_syntax_t;
  15629.     If not set, then an unmatched ) is invalid.  */
  15630.  #define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
  15631.  
  15632. +/* If this bit is set, succeed as soon as we match the whole pattern,
  15633. +   without further backtracking.  */
  15634. +#define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
  15635. +
  15636.  /* If this bit is set, do not process the GNU regex operators.
  15637.     IF not set, then the GNU regex operators are recognized. */
  15638. -#define RE_NO_GNU_OPS (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
  15639. +#define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
  15640.  
  15641.  /* This global variable defines the particular regexp syntax to use (for
  15642.     some interfaces).  When a regexp is compiled, the syntax used is
  15643. @@ -360,11 +364,6 @@ struct re_pattern_buffer
  15644.  };
  15645.  
  15646.  typedef struct re_pattern_buffer regex_t;
  15647. -
  15648. -
  15649. -/* search.c (search_buffer) in Emacs needs this one opcode value.  It is
  15650. -   defined both in `regex.c' and here.  */
  15651. -#define RE_EXACTN_VALUE 1
  15652.  
  15653.  /* Type for byte offsets within the string.  POSIX mandates this.  */
  15654.  typedef int regoff_t;
  15655. @@ -481,10 +480,12 @@ extern void re_set_registers
  15656.    _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
  15657.               unsigned num_regs, regoff_t *starts, regoff_t *ends));
  15658.  
  15659. +#ifdef _REGEX_RE_COMP
  15660.  #ifndef _CRAY
  15661.  /* 4.2 bsd compatibility.  */
  15662.  extern char *re_comp _RE_ARGS ((const char *));
  15663.  extern int re_exec _RE_ARGS ((const char *));
  15664. +#endif
  15665.  #endif
  15666.  
  15667.  /* POSIX compatibility.  */
  15668. diff -rup --new-file baseline/fsf/gawk/test/Makefile amiga/fsf/gawk/test/Makefile
  15669. --- baseline/fsf/gawk/test/Makefile    Thu Mar  9 09:30:07 1995
  15670. +++ amiga/fsf/gawk/test/Makefile    Sat Sep 28 00:00:00 1996
  15671. @@ -20,6 +20,8 @@
  15672.  # the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15673.  
  15674.  SHELL = /bin/sh
  15675. +#COMPARE = cmp
  15676. +COMPARE = diff
  15677.  
  15678.  bigtest:    basic poundbang gawk.extensions
  15679.  
  15680. @@ -36,7 +38,7 @@ extra:    regtest inftest
  15681.  poundbang::
  15682.      cp ../gawk /tmp && chmod +x poundbang && ./poundbang poundbang >tmp
  15683.      rm -f /tmp/gawk
  15684. -    cmp poundbang.good tmp && rm -f tmp
  15685. +    -$(COMPARE) poundbang.good tmp && rm -f tmp
  15686.  
  15687.  msg::
  15688.      @echo 'Any output from "cmp" is bad news, although some differences'
  15689. @@ -46,7 +48,7 @@ msg::
  15690.  
  15691.  swaplns::
  15692.      @../gawk -f swaplns.awk data >tmp
  15693. -    cmp swaplns.good tmp && rm -f tmp
  15694. +    -$(COMPARE) swaplns.good tmp && rm -f tmp
  15695.  
  15696.  messages::
  15697.      @../gawk -f messages.awk >out2 2>out3
  15698. @@ -54,31 +56,31 @@ messages::
  15699.  
  15700.  argarray::
  15701.      @TEST=test echo just a test | ../gawk -f argarray.awk argarray.awk - >tmp
  15702. -    cmp argarray.good tmp && rm -f tmp
  15703. +    -$(COMPARE) argarray.good tmp && rm -f tmp
  15704.  
  15705.  fstabplus::
  15706.      @echo '1        2' | ../gawk -f fstabplus >tmp
  15707. -    cmp fstabplus.good tmp && rm -f tmp
  15708. +    -$(COMPARE) fstabplus.good tmp && rm -f tmp
  15709.  
  15710.  fsrs::
  15711.      @../gawk -f fsrs.awk fsrs.in >tmp
  15712. -    cmp fsrs.good tmp && rm -f tmp
  15713. +    -$(COMPARE) fsrs.good tmp && rm -f tmp
  15714.  
  15715.  igncfs::
  15716.      @../gawk -f igncfs.awk igncfs.in >tmp
  15717. -    cmp igncfs.good tmp && rm -f tmp
  15718. +    -$(COMPARE) igncfs.good tmp && rm -f tmp
  15719.  
  15720.  longwrds::
  15721.      @../gawk -f longwrds.awk manpage | sort >tmp
  15722. -    cmp longwrds.good tmp && rm -f tmp
  15723. +    -$(COMPARE) longwrds.good tmp && rm -f tmp
  15724.  
  15725.  fieldwdth::
  15726.      @echo '123456789' | ../gawk -v FIELDWIDTHS="2 3 4" '{ print $$2}' >tmp
  15727. -    cmp fieldwdth.good tmp && rm -f tmp
  15728. +    -$(COMPARE) fieldwdth.good tmp && rm -f tmp
  15729.  
  15730.  ignrcase::
  15731.      @echo xYz | ../gawk -v IGNORECASE=1 '{ sub(/y/, ""); print}' >tmp
  15732. -    cmp ignrcase.good tmp && rm -f tmp
  15733. +    -$(COMPARE) ignrcase.good tmp && rm -f tmp
  15734.  
  15735.  regtest::
  15736.      @echo 'Some of the output from regtest is very system specific, do not'
  15737. @@ -88,7 +90,7 @@ regtest::
  15738.  
  15739.  posix::
  15740.      @echo '1:2,3 4' | ../gawk -f posix >tmp
  15741. -    cmp posix.good tmp && rm -f tmp
  15742. +    -$(COMPARE) posix.good tmp && rm -f tmp
  15743.  
  15744.  manyfiles::
  15745.      @rm -rf junk
  15746. @@ -101,28 +103,28 @@ manyfiles::
  15747.  
  15748.  compare::
  15749.      @../gawk -f compare.awk 0 1 compare.in >tmp
  15750. -    cmp compare.good tmp && rm -f tmp
  15751. +    -$(COMPARE) compare.good tmp && rm -f tmp
  15752.  
  15753.  arrayref::
  15754.      @../gawk -f arrayref >tmp
  15755. -    cmp arrayref.good tmp && rm -f tmp
  15756. +    -$(COMPARE) arrayref.good tmp && rm -f tmp
  15757.  
  15758.  rs::
  15759.      @../gawk -v RS="" '{ print $$1, $$2}' rs.data >tmp
  15760. -    cmp rs.good tmp && rm -f tmp
  15761. +    -$(COMPARE) rs.good tmp && rm -f tmp
  15762.  
  15763.  fsbs::
  15764.      @../gawk -v FS='\' '{ print $$1, $$2 }' fsbs.in >tmp
  15765. -    cmp fsbs.good tmp && rm -f tmp
  15766. +    -$(COMPARE) fsbs.good tmp && rm -f tmp
  15767.  
  15768.  inftest::
  15769.      @echo This test is very machine specific...
  15770.      @../gawk -f inftest.awk >tmp
  15771. -    cmp inftest.good tmp && rm -f tmp
  15772. +    -$(COMPARE) inftest.good tmp && rm -f tmp
  15773.  
  15774.  getline::
  15775.      @../gawk -f getline.awk getline.awk getline.awk >tmp
  15776. -    cmp getline.good tmp && rm -f tmp
  15777. +    -$(COMPARE) getline.good tmp && rm -f tmp
  15778.  
  15779.  rand::
  15780.      @echo The following line should just be 19 random numbers between 1 and 100
  15781. @@ -145,8 +147,8 @@ splitargv::
  15782.      cmp splitargv.good tmp && rm -f tmp
  15783.  
  15784.  awkpath::
  15785. -    @AWKPATH=".:lib" ../gawk -f awkpath.awk >tmp
  15786. -    cmp awkpath.good tmp && rm -f tmp
  15787. +#    @AWKPATH=".:lib" ../gawk -f awkpath.awk >tmp
  15788. +#    cmp awkpath.good tmp && rm -f tmp
  15789.  
  15790.  nfset::
  15791.      @../gawk -f nfset.awk nfset.in >tmp
  15792. diff -rup --new-file baseline/fsf/gawk/test/poundbang amiga/fsf/gawk/test/poundbang
  15793. --- baseline/fsf/gawk/test/poundbang    Tue Oct 19 17:07:58 1993
  15794. +++ amiga/fsf/gawk/test/poundbang    Sat Sep 28 00:00:00 1996
  15795. @@ -1,3 +1,3 @@
  15796. -#! /tmp/gawk -f 
  15797. +#!/tmp/gawk -f 
  15798.      { ccount += length($0) }
  15799.  END { printf "average line length is %2.4f\n", ccount/NR}
  15800.