View | Details | Raw Unified | Return to bug 15255
Collapse All | Expand All

(-)awk/ChangeLog (+301 lines)
Lines 1-3 Link Here
1
Wed Jun 30 16:14:36 1999  Arnold D. Robbins  <arnold@gnu.org>
2
3
	* Release 3.0.4: Release tar file made.  This time for sure.
4
5
Wed Jun 30 16:10:11 1999  Arnold D. Robbins  <arnold@gnu.org>
6
7
	* awk.h: add include of <assert.h>, and comment about config.h
8
	  having to be included before any system headers.  Otherwise,
9
	  with egcs-2.91.66 and later on Linux systems, and possibly
10
	  others, things break badly, due to the LFS macros.
11
	* awk.y, builtin.c, eval.c, field.c, io.c: removed include
12
	  of assert.h
13
14
Wed Jun  9 11:39:19 1999  Paul Eggert  <eggert@twinsun.com>
15
16
	Port the large-file code to AIX, HP-UX, and IRIX.
17
	Add cross-compilation support for large files.
18
19
	* config.guess, config.sub: New files.
20
21
	* configure.in (AC_CANONICAL_HOST):
22
	  Add; GAWK_AC_SYS_LARGEFILE needs this.
23
	  (GAWK_AC_SYS_LARGEFILE): Renamed from GAWK_AC_LARGE_FILES.
24
25
	* aclocal.m4 (GAWK_AC_SYS_LARGEFILE): Renamed from GAWK_AC_LARGE_FILES.
26
	  Add support for AIX and HP-UX.
27
	  (GAWK_AC_SYS_LARGEFILE_FLAGS, GAWK_AC_SYS_LARGEFILE_SPACE_APPEND,
28
	  GAWK_AC_SYS_LARGEFILE_MACRO_VALUE): New macros.
29
30
	* acconfig.h (_FILE_OFFSET_BITS, _LARGEFILE_SOURCE, _LARGE_FILES):
31
	  New macros.
32
33
	* Makefile.in (MISC): add config.guess and config.sub so they get
34
	  included in the distribution.
35
36
Wed Jun  9 11:29:29 1999  Paul Eggert  <eggert@twinsun.com>
37
38
	* io.c (iop_alloc): Don't mmap files whose sizes don't fit in `int'.
39
	  [ This isn't really needed, as HAVE_MMAP is #undef'ed at the top,
40
	  but it's there in case people want to take their life in their hands. ]
41
42
Sun Jun  6 11:28:07 1999  Arnold D. Robbins  <arnold@gnu.org>
43
44
	* BETA Release 3.0.46: Release tar file made.
45
46
Wed Jun  2 14:36:24 1999  Arnold D. Robbins  <arnold@gnu.org>
47
48
	* PORTS: Updated with a more recent list of systems
49
	  that gawk compiles and tests ok on.
50
51
Tue Jun  1 14:24:59 1999  Arnold D. Robbins  <arnold@gnu.org>
52
53
	* BETA Release 3.0.45: Release tar file made.
54
55
Tue May 25 16:32:37 1999  Arnold D. Robbins  <arnold@gnu.org>
56
57
	* builtin.c (format_tree): more smarts for weird cases, such as
58
	  zero precisions and zero values used with the `#' flag.
59
	  Thanks to Andreas Schwab (schwab@gnu.org) for pointing these out.
60
61
Wed May 19 14:02:54 1999  Arnold D. Robbins  <arnold@gnu.org>
62
63
	* io.c (do_close): move test for `close(FILENAME)' to after
64
	  loop through all open redirections. Fixes problems in obscure
65
	  cases with redirections in END rules.
66
67
Sun May 16 14:08:39 1999  Arnold D. Robbins  <arnold@gnu.org>
68
69
	* awk.y (yylex): fix group of characters including ',' to
70
	  set want_assign = FALSE.  Fixes bizarre parsing problems in
71
	  function call lists, for example.
72
	* io.c (get_a_record): repair logic for single-leading-newline
73
	  case.
74
75
Tue May 11 16:48:11 1999  Arnold D. Robbins  <arnold@gnu.org>
76
77
	* aclocal.m4 (GAWK_AC_AIX_TWEAK): new macro.
78
	* configure.in: call it
79
	* Makefile.in: (awklib/all): pass CFLAGS on to sub-make so
80
	  that password programs will get AIX magic defines. Avoids
81
	  having to tweak program code for those in doc/gawk.texi.
82
83
Mon May  3 16:56:23 1999  Arnold D. Robbins  <arnold@gnu.org>
84
85
	* array.c (do_delete): don't free_temp(subs) until after all
86
	  references to it are finished.
87
88
Mon May  3 13:41:16 1999  Arnold D. Robbins  <arnold@gnu.org>
89
90
	* BETA Release 3.0.44: Release tar file made.
91
92
Sun May  2 18:25:43 1999  Arnold D. Robbins  <arnold@gnu.org>
93
94
	* io.c (get_a_record): Do a really good job of stripping newlines
95
	  from the front of records when RS = "" and there's only one
96
	  newline at the front of the file, which the regex didn't catch.
97
98
Wed Apr 28 12:27:49 1999  Arnold D. Robbins  <arnold@gnu.org>
99
100
	* configure.in: more HP stuff: fix the manual alloca code so that
101
	  gawk will compile and link on HP systems. See the comments.
102
103
Sun Apr 25 13:39:16 1999  Arnold D. Robbins  <arnold@gnu.org>
104
105
	* Makefile.in (gawk): add $(CFLAGS) to linking step.
106
	* configure.in: correctly do AC_FUNC_GETPRGP on HP systems too.
107
108
Tue Apr 13 20:21:00 1999  Arnold D. Robbins  <arnold@gnu.org>
109
110
	* BETA Release 3.0.43: Release tar file made.
111
112
Tue Apr 13 19:02:20 1999  Arnold D. Robbins  <arnold@gnu.org>
113
114
	* io.c (useropen, pidopen): add casts to int on arguments to
115
	  silence gcc warnings.
116
	* regex.c (regcomp,regexec,regfree): add ifdef for APPLE.
117
118
Thu Feb  4 10:38:02 1999  Arnold D. Robbins  <arnold@gnu.org>
119
120
	* custom.h: hacks for BeOS. Not documented in the manual right now.
121
	* configure.in: hacks for BeOS.  Check for HP-UX and define C_ALLOCA
122
	  if not using gcc.  I wish they'd just fix bison already.
123
124
Sun Dec 20 16:57:38 1998  Arnold D. Robbins  <arnold@gnu.org>
125
126
	* BETA Release 3.0.42: Release tar file made.
127
128
Sun Nov 15 21:05:39 1998  Arnold D. Robbins  <arnold@gnu.org>
129
130
	* io.c (gawk_popen): Add WIN32 to list of systems that use
131
	  the non-real-pipe version. From the PC gawk guys.
132
133
Wed Nov  4 11:32:24 1998  Arnold D. Robbins  <arnold@gnu.org>
134
135
	* BETA Release 3.0.41: Release tar file made.
136
137
Tue Nov  3 16:24:35 1998  Arnold D. Robbins  <arnold@gnu.org>
138
139
	* eval.c (r_get_lhs): Fix the cases for the special variables,
140
	  don't unref their current value if it's the same as the internal
141
	  copy; perhaps the current one is used in a concatenation or some
142
	  other expression somewhere higher up in the call chain.  Ouch.
143
	  See test/getnr2tm.awk.
144
145
Sun Nov  1 15:24:52 1998  Arnold D. Robbins  <arnold@gnu.org>
146
147
	* builtin.c (format_tree): improve handling of zero-fill
148
	  when a precision is present. See test/zeroflag.awk.
149
150
Wed Oct 28 20:40:17 1998  Arnold D. Robbins  <arnold@gnu.org>
151
152
	* eval.c (r_tree_eval): Case for Node_concat. Get lengthes
153
	  separately, in case one expression has a side effect that
154
	  that changes another. Ugly, but it keeps gawk from core
155
	  dumping. See test/nasty.awk.
156
157
Sun Oct 18 21:27:24 1998  Arnold D. Robbins  <arnold@gnu.org>
158
159
	* awk.y (append_right): bug fix, if `list' or `new' are NULL,
160
	  return `list', so that things don't break too badly.
161
	* regex.c (re_compile_fastmap): remove unused variable `num_regs'.
162
163
Thu Oct  8 19:36:57 1998  Arnold D. Robbins  <arnold@gnu.org>
164
165
	* BETA Release 3.0.40: Release tar file made.
166
167
Mon Jul 27 10:14:33 1998  Arnold D. Robbins  <arnold@gnu.org>
168
169
	* node.c (parse_escape): Remove assignment with side effects
170
	  from ISXDIGIT test. Thanks to "Mihai T. LAZARESCU"
171
	  <mihai@ccmserv.polito.it> for pointing this out.
172
173
Mon Apr 27 11:31:32 1998  Arnold D. Robbins  <arnold@gnu.org>
174
175
	* main.c (usage): fix the email address for the bug list.
176
	  (copyleft): update the copyright year.
177
178
Mon Mar 23 21:22:32 1998  Arnold D. Robbins  <arnold@gnu.org>
179
180
	* eval.c (r_get_lhs): make sure that values of type
181
	  Node_param_list don't have the FUNC flag set. This means
182
	  we don't allow the use of a function name as a variable or
183
	  array from within the function.
184
185
Sun Mar 22 19:12:32 1998  Paul Eggert  <eggert@twinsun.com>
186
187
	* aclocal.m4 (GAWK_AC_LARGE_FILES): new macro that checks for
188
	  large file support, and updates CPPFLAGS, LDFLAGS, LIBS as
189
	  needed.
190
	* configure.in: call GAWK_AC_LARGE_FILES.
191
	* Makefile.in (CPPFLAGS, LDFLAGS): Let autoconf configure.
192
	(COMPFLAGS): Add $(CPPFLAGS).
193
194
Mon Mar 16 14:06:41 1998  Arnold D. Robbins  <arnold@gnu.org>
195
196
	* field.c (using_FIELDWIDTHS): new macro.
197
	  (using_fieldwidths): use new macro.
198
	  (do_split): in case for FS_DFLT, also check that
199
	  we're not using FIELDWIDTHS. Otherwise, split() would use
200
	  FIELDWIDTHS, not current value of FS. Oops.
201
202
Sun Nov 16 20:08:59 1997  Arnold D. Robbins  <arnold@gnu.org>
203
204
	* builtin.c (sub_common): fix for count of matches in gsub
205
	  from Geert.Debyser@esat.kuleuven.ac.be.
206
207
Wed Oct 15 03:38:12 1997  Arnold D. Robbins  <arnold@gnu.org>
208
209
	* field.c (set_FS): Use `sc_parsefield' if the value of FS is not
210
	  alphabetic OR if not ignoring case. Bug fix if IGNORECASE
211
	  is true and FS happens to be '^'. Sheesh, talk about obscure.
212
	  (rebuild_record): Add more smarts to the code that sets up the
213
	  fields. Thanks to Alan J. Broder (ajb@dtmr.com).
214
215
Sun Oct  5 11:56:52 1997  Arnold D. Robbins  <arnold@gnu.org>
216
217
	* configure.in: if ISC add -D_SYSV3 to CFLAGS, per email from
218
	  Mario Vanoni (vanonim@dial.eunet.ch).
219
220
Fri Sep 26 00:57:49 1997  Arnold D. Robbins  <arnold@gnu.org>
221
222
	* awk.y (append_right): return if either list is NULL. Prevents
223
	  syntax errors from causing core dumps.
224
225
Wed Sep 17 15:34:15 1997  Arnold D. Robbins  <arnold@gnu.org>
226
227
	* field.c (rebuild_record): set things up so that all fields point
228
	  into the new record and release any changed fields without
229
	  causing memory leaks.  Avoids problems when fields are extended
230
	  with the value of $0 or other fields and then $0 is assigned to.
231
232
Mon Sep 15 16:12:55 1997  Arnold D. Robbins  <arnold@gnu.org>
233
234
	* builtin.c (do_print): when testing for NUMBER, make sure
235
	  it's not a string too. Thanks to Michael Brennan for
236
	  clarifying the semantics.
237
238
Sun Sep 14 19:55:12 1997  Arnold D. Robbins  <arnold@gnu.org>
239
240
	* node.c (format_val): always format values ourselves: avoids
241
	  problems if OFMT is bizarre, like %s.
242
243
Sun Sep 14 00:08:53 1997  Arnold D. Robbins  <arnold@gnu.org>
244
245
	* io.c (get_a_record): replace all occurrences of the test
246
	  `grRS == FALSE' with `RS_is_null' which makes ` RS = "\0" '
247
 	  actually work, is clearer code, and actually makes use of
248
	  the `RS_is_null' variable!
249
250
Sun Aug 17 07:15:12 1997  Arnold D. Robbins  <arnold@gnu.org>
251
252
	* field.c (set_FS): Change logic to always set parse_field, even
253
	  if FS hasn't changed. Thanks to Igor Sheyn for catching this.
254
255
Wed Aug  6 21:04:37 1997  Arnold D. Robbins  <arnold@gnu.org>
256
257
	* io.c (VMS et al gawk_popen): use pclose, not fclose, if
258
	  iop_alloc fails.
259
260
Wed Jul 30 19:53:52 1997  Arnold D. Robbins  <arnold@gnu.org>
261
262
	* awk.y [variable]: fix case for subscript if $3 == NULL.
263
264
Sun Jul 27 22:47:30 1997  Arnold D. Robbins  <arnold@gnu.org>
265
266
	* awk.y (get_src_buf): don't close file if it's stdin.
267
268
Sun Jul 27 22:47:15 1997  Pat Rankin  <rankin@eql.caltech.edu>
269
270
	* io.c (#if VMS: vmsrtl_fileno): new routine.
271
	  (#if VMS: fileno): new macro substituted for stdio one.
272
273
Thu Jul 17 20:05:59 1997  Arnold D. Robbins  <arnold@gnu.org>
274
275
	* builtin.c (do_print): When OFMT != CONVFMT, create a new
276
	  temporary node with just the numeric value valid and format it,
277
	  and use that for printing. Avoids memory corruption.
278
279
Wed Jul 16 10:01:16 1997  Arnold D. Robbins  <arnold@gnu.org>
280
281
	* regex.c: When SYNTAX_TABLE is defined, but not emacs, then
282
	  CHAR_SET_SIZE is not defined, though used in regcomp.  It should
283
	  be taken out of #ifdef SYNTAX_TABLE. Fix from bug group, from
284
	  Akim Demaille, demaille@inf.enst.fr.
285
	* awk.h (isnondecimal): make test a little smarter.
286
	  builtin.c (nondec2awknum): add bailout for decimal numbers, e.g.
287
	  `00.1'. Fix from Larry Schwimmer <rosebud@cyclone.Stanford.EDU>.
288
289
Thu Jun 19 19:00:40 1997  Arnold D. Robbins  <arnold@gnu.org>
290
291
	* eval.c (interpret): case Node_K_next, Node_K_nextfile: fatal
292
	  error if called from BEGIN or END.
293
	  (Fixed completely Mon May  3 13:31:42 1999.)
294
295
Mon Jun  9 22:40:04 1997  Arnold D. Robbins  <arnold@gnu.org>
296
297
	* builtin.c (nondec2awknum): Allow `f' and `F' in hexadecimal numbers.
298
	  Gotta get more sleep...
299
	* array.c (assoc_lookup): Fix from Tom Karzes (karzes@equator.com)
300
	  for memory leak when forcing type to Node_var_array.
301
1
Thu May 15 12:49:08 1997  Arnold D. Robbins  <arnold@skeeve.atl.ga.us>
302
Thu May 15 12:49:08 1997  Arnold D. Robbins  <arnold@skeeve.atl.ga.us>
2
303
3
	* Release 3.0.3: Release tar file made.
304
	* Release 3.0.3: Release tar file made.
(-)awk/FREEBSD-upgrade (+138 lines)
Lines 55-57 Link Here
55
In addition, doc/gawk.1 and doc/gawk.texi were renamed to awk.1 and awk.texi.
55
In addition, doc/gawk.1 and doc/gawk.texi were renamed to awk.1 and awk.texi.
56
56
57
jraynard@freebsd.org
57
jraynard@freebsd.org
58
59
60
Import of GNU awk 3.0.4
61
62
Original source available as ftp://prep.ai.mit.edu/pub/gnu/gawk-3.0.4.tar.gz
63
64
The file config.h was generated with configure
65
66
The following files and directories were removed for this import:
67
68
[smame as listed above]
69
acconfig.h
70
config.guess
71
config.sub
72
73
These patches have been applied:
74
75
diff -u ./awk.h /src/src/contrib/awk/awk.h
76
--- ./awk.h	Fri May  2 03:36:12 1997
77
+++ /src/src/contrib/awk/awk.h	Sun Oct 26 13:14:52 1997
78
@@ -172,7 +172,11 @@
79
 
80
 #define	GNU_REGEX
81
 #ifdef GNU_REGEX
82
+#ifdef __FreeBSD__
83
+#include <gnuregex.h>
84
+#else
85
 #include "regex.h"
86
+#endif
87
 #include "dfa.h"
88
 typedef struct Regexp {
89
 	struct re_pattern_buffer pat;
90
diff -u ./builtin.c /src/src/contrib/awk/builtin.c
91
--- ./builtin.c	Tue May 13 18:13:50 1997
92
+++ /src/src/contrib/awk/builtin.c	Sun Oct 26 13:14:52 1997
93
@@ -30,6 +30,7 @@
94
 #undef CHARBITS
95
 #undef INTBITS
96
 #include <math.h>
97
+#ifndef __FreeBSD__
98
 #include "random.h"
99
 
100
 /* can declare these, since we always use the random shipped with gawk */
101
@@ -37,6 +38,7 @@
102
 extern char *setstate P((char *state));
103
 extern long random P((void));
104
 extern void srandom P((unsigned int seed));
105
+#endif
106
 
107
 extern NODE **fields_arr;
108
 extern int output_is_tty;
109
@@ -1261,7 +1263,11 @@
110
 		(void) setstate(state);
111
 
112
 	if (tree == NULL)
113
+#ifdef __FreeBSD__
114
+		srandom((unsigned int) (save_seed = (long) time((time_t *) 0) ^ getpid()));
115
+#else
116
 		srandom((unsigned int) (save_seed = (long) time((time_t *) 0)));
117
+#endif
118
 	else {
119
 		tmp = tree_eval(tree->lnode);
120
 		srandom((unsigned int) (save_seed = (long) force_number(tmp)));
121
diff -u ./dfa.c /src/src/contrib/awk/dfa.c
122
--- ./dfa.c	Fri May  2 03:36:18 1997
123
+++ /src/src/contrib/awk/dfa.c	Sun Oct 26 13:17:33 1997
124
@@ -77,7 +77,11 @@
125
 #define ISCNTRL(C) (isascii(C) && iscntrl(C))
126
 #endif
127
 
128
+#ifndef __FreeBSD__
129
 #include "regex.h"
130
+#else
131
+#include <gnuregex.h>
132
+#endif
133
 #include "dfa.h"
134
 
135
 #ifdef __STDC__
136
@@ -132,6 +136,23 @@
137
 static char **addlists _RE_ARGS((char **old, char **new));
138
 static char **inboth _RE_ARGS((char **left, char **right));
139
 
140
+#ifdef __FreeBSD__
141
+static int collate_range_cmp (a, b)
142
+	int a, b;
143
+{
144
+	int r;
145
+	static char s[2][2];
146
+
147
+	if ((unsigned char)a == (unsigned char)b)
148
+		return 0;
149
+	s[0][0] = a;
150
+	s[1][0] = b;
151
+	if ((r = strcoll(s[0], s[1])) == 0)
152
+		r = (unsigned char)a - (unsigned char)b;
153
+	return r;
154
+}
155
+#endif
156
+
157
 static ptr_t
158
 xcalloc(n, s)
159
      size_t n;
160
@@ -700,6 +721,27 @@
161
 		}
162
 	      else
163
 		c2 = c;
164
+#ifdef __FreeBSD__
165
+	      { token c3;
166
+
167
+		if (collate_range_cmp(c, c2) > 0) {
168
+		  FETCH(c2, "Invalid range");
169
+		  goto skip;
170
+		}
171
+
172
+		for (c3 = 0; c3 < NOTCHAR; ++c3)
173
+		  if (   collate_range_cmp(c, c3) <= 0
174
+		      && collate_range_cmp(c3, c2) <= 0
175
+		     ) {
176
+		    setbit(c3, ccl);
177
+		    if (case_fold)
178
+		      if (ISUPPER(c3))
179
+			setbit(tolower(c3), ccl);
180
+		      else if (ISLOWER(c3))
181
+			setbit(toupper(c3), ccl);
182
+		  }
183
+	      }
184
+#else
185
 	      while (c <= c2)
186
 		{
187
 		  setbit(c, ccl);
188
@@ -710,6 +752,7 @@
189
 		      setbit(toupper(c), ccl);
190
 		  ++c;
191
 		}
192
+#endif
193
 	    skip:
194
 	      ;
195
 	    }
(-)awk/FUTURES (-2 lines)
Lines 73-80 Link Here
73
73
74
	Use GNU malloc.
74
	Use GNU malloc.
75
75
76
	Use rx instead of regex.
77
78
	DONE: Do a reference card.
76
	DONE: Do a reference card.
79
77
80
	? Have strftime() pay attention to the value of ENVIRON["TZ"]
78
	? Have strftime() pay attention to the value of ENVIRON["TZ"]
(-)awk/NEWS (+76 lines)
Lines 1-3 Link Here
1
Changes from 3.0.3 to 3.0.4
2
---------------------------
3
4
This is a bug fix release only, pending further development on 3.1.0.
5
6
Bugs Fixed:
7
8
 1. A memory leak when turning a function parameter into an array was
9
    fixed.
10
11
 2. The non-decimal data option now works correctly.
12
13
 3. Using an empty pair of brackets as an array subscript no longer causes
14
    a core dump during parsing.  In general, syntax errors should not
15
    cause core dumps any more.
16
 
17
 4. Standard input is no longer closed if it provides program source,
18
    avoiding strange I/O problems.
19
20
 5. Memory corruption during printing with `print' has been fixed.
21
22
 6. The gsub function now correctly counts the number of matches.
23
24
 7. A typo in doc/Makefile.in has been fixed, making installation work.
25
26
 8. Calling `next' or `nextfile' from a BEGIN or END rule is now fatal.
27
28
 9. Subtle problems in rebuilding $0 when fields were changed have been
29
    fixed.
30
31
10. `FS = FS' now correctly turns off the use of FIELDWIDTHS.
32
33
11. Gawk now parses fields correctly when FS is a single character.
34
35
12. It is now possible for RS to be the NUL character ("\0").
36
37
13. Weird problems with number conversions on MIPS and other systems
38
    have been fixed.
39
40
14. When parsing using FIELDWIDTHS is in effect, split() with no third
41
    argument will still use the value of FS.
42
43
15. Large File Support for Solaris, HP-UX, AIX, and IRIX is now enabled at
44
    compile time, thanks to Paul Eggert.
45
46
16. Attempting to use the name of a function as a variable or array
47
    from within the function is now caught as a fatal error, instead
48
    of as a core dump.
49
50
17. A bug in parsing hex escapes was fixed.
51
52
18. A weird bug with concatenation where one expression has side effects
53
    that changes another was fixed.
54
55
19. printf/sprintf now behave much better for uses of the '0' and '#' flags
56
    and with precisions and field widths.
57
58
20. Further strangenesses with concatenation and multiple accesses of some
59
    of the special variables was fixed.
60
61
21. The Atari port is marked as no longer supported.
62
63
22. Build problems on HP-UX have been fixed.
64
65
23. Minor fixes and additional explanations added to the documentation.
66
67
24. For RS = "", even a single leading newline is now correctly stripped.
68
69
25. Obscure parsing problems for regex constants like /=.../ fixed, so
70
    that a regex constant is recognized, and not the /= operator.
71
72
26. Fixed a bug when closing a redirection that matched the current
73
    or last FILENAME.
74
75
27. Build problems on AIX fixed.
76
1
Changes from 3.0.2 to 3.0.3
77
Changes from 3.0.2 to 3.0.3
2
---------------------------
78
---------------------------
3
79
(-)awk/PORTS (-33 / +24 lines)
Lines 1-36 Link Here
1
A recent version of gawk has been successfully compiled and run "make test"
1
Gawk 3.0.4 has been successfully compiled and run "make test"
2
on the following:
2
on the following:
3
3
4
Using cc:
4
Linux 2.2.5                     gcc 2.7.2.3
5
	Dec Alpha OSF 4.0
5
Linux 2.0.33                    gcc 2.7.2.1
6
	HP9000/755 HP-UX 9.01
6
IRIX64 6.4                      gcc 2.8.1
7
	IBM PowerPC AIX 4.1.4.0
7
IRIX 5.3                        gcc 2.7.2.2
8
	SCO Unix (OpenServer 5)
8
UNIX_SV maxion OS 4.2MP         gcc 2.7.2
9
	SGI IRIX 4.0.5
9
IRIX 6.2                        gcc 2.7.2.2
10
	SGI IRIX 5.3
10
CYGWIN_95-4.0 20.1 (0.3/1/1)    egcs-2.91.66 (has minor problems due to env.)
11
	SGI IRIX 6.1
12
	SGI IRIX 6.2
13
	SunOS 4.1.3
14
	SunOS 5.5
15
	IBM SP2 AIX 4.1
16
11
17
Other systems:
12
The builds of gawk-3.0.45, and validation and installation, were
18
	DEC Alpha		Linux/AXP
13
successful on these systems:
19
	DEC Alpha               OSF/1 3.2
14
20
	DECstation 5000         ULTRIX 4.3
15
        DEC Alpha               OSF/1 3.2
21
	HP 9000/735             HP-UX 10.01
16
        HP 9000/735             HP-UX 10.01
22
	IBM RS/6000             AIX 3.2
17
        IBM PowerPC             AIX 4.2
23
	IBM SP2                 AIX 4.1
18
        Intel Pentium II MMX    GNU/Linux 2.0.35
24
	Intel x86		DOS  (compiler: djgpp v2, emx+gcc,
19
        NeXT Turbostation       Mach 3.3
25
					and MSC 6.00A, 7, and 8)
20
        SGI Indigo/2            IRIX 5.3
26
	Intel x86		Linux 2.0.27
21
        SGI O2 R10000-SC        IRIX 6.3
27
	Intel x86		Linux 2.1.36
22
        Sun SPARC               Solaris 2.6
28
	Intel x86		OS+2 (compiler: emx+gcc)
23
29
	NeXT Turbostation       Mach 3.3
24
On 
30
	SGI Indigo/2            IRIX 5.3
25
        SGI Origin 200          IRIX 6.4
31
	SGI O2			IRIX 6.2
26
a build with gcc-2.8.1 succeeded, but several tests failed; a rebuild
32
	SGI PowerChallenge      IRIX 6.1
27
with c89 fixed the problem.
33
	Sun SPARC		Linux 2.0.22
34
	Sun SPARC               Solaris 2.5
35
	Sun SPARC               Solaris 2.5.1
36
	Sun SPARC               SunOS 4.1.3
(-)awk/POSIX.STD (+5 lines)
Lines 1-3 Link Here
1
October 1998:
2
3
The 1003.2 work has been at a stand-still for ages. Who knows if or
4
when a new revision will actually happen...
5
1
August 1995:
6
August 1995:
2
7
3
Although the published 1003.2 standard contained the incorrect
8
Although the published 1003.2 standard contained the incorrect
(-)awk/README (-4 / +4 lines)
Lines 1-10 Link Here
1
README:
1
README:
2
2
3
This is GNU Awk 3.0.3. It should be upwardly compatible with the Bell
3
This is GNU Awk 3.0.4. It should be upwardly compatible with the Bell
4
Labs research version of awk.  It is almost completely compliant with
4
Labs research version of awk.  It is almost completely compliant with
5
the 1993 POSIX 1003.2 standard for awk. (See the note below about POSIX.)
5
the 1993 POSIX 1003.2 standard for awk. (See the note below about POSIX.)
6
6
7
Patches 1 through 3 just fix bugs -- see NEWS and ChangeLog for details.
7
Patches 1 through 4 just fix bugs -- see NEWS and ChangeLog for details.
8
8
9
See the file INSTALL for installation instructions.
9
See the file INSTALL for installation instructions.
10
10
Lines 66-72 Link Here
66
outlined in the manual.
66
outlined in the manual.
67
67
68
Arnold Robbins
68
Arnold Robbins
69
INTERNET:	arnold@gnu.ai.mit.edu
69
INTERNET:	arnold@gnu.org
70
70
71
BUG REPORTS AND FIXES (non-Unix ports):
71
BUG REPORTS AND FIXES (non-Unix ports):
72
72
Lines 81-87 Link Here
81
	Pat Rankin
81
	Pat Rankin
82
	rankin@eql.caltech.edu
82
	rankin@eql.caltech.edu
83
83
84
Atari ST:
84
Alpha/Linux:
85
	Michal Jaegermann
85
	Michal Jaegermann
86
	michal@gortel.phys.ualberta.ca
86
	michal@gortel.phys.ualberta.ca
87
87
(-)awk/README_d/README.FIRST (-1 / +1 lines)
Lines 18-21 Link Here
18
file, I will yell at you.
18
file, I will yell at you.
19
19
20
Arnold Robbins
20
Arnold Robbins
21
arnold@gnu.ai.mit.edu
21
arnold@gnu.org
(-)awk/acconfig.h (-36 lines)
Lines 1-36 Link Here
1
/*
2
 * acconfig.h -- configuration definitions for gawk.
3
 */
4
5
/* 
6
 * Copyright (C) 1995-1997 the Free Software Foundation, Inc.
7
 * 
8
 * This file is part of GAWK, the GNU implementation of the
9
 * AWK Programming Language.
10
 * 
11
 * GAWK is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 2 of the License, or
14
 * (at your option) any later version.
15
 * 
16
 * GAWK is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 * 
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
24
 */
25
26
@TOP@
27
28
#undef HAVE_STRINGIZE	/* can use ANSI # operator in cpp */
29
#undef REGEX_MALLOC	/* use malloc instead of alloca in regex.c */
30
#undef SPRINTF_RET	/* return type of sprintf */
31
#undef BITOPS		/* bitwise ops (undocumented feature) */
32
#undef NONDECDATA	/* non-decimal input data (undocumented feature) */
33
34
@BOTTOM@
35
36
#include <custom.h>	/* overrides for stuff autoconf can't deal with */
(-)awk/array.c (-3 / +7 lines)
Lines 3-9 Link Here
3
 */
3
 */
4
4
5
/* 
5
/* 
6
 * Copyright (C) 1986, 1988, 1989, 1991 - 97 the Free Software Foundation, Inc.
6
 * Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
7
 * 
7
 * 
8
 * This file is part of GAWK, the GNU implementation of the
8
 * This file is part of GAWK, the GNU implementation of the
9
 * AWK Programming Language.
9
 * AWK Programming Language.
Lines 272-278 Link Here
272
		fatal("attempt to use scalar as array");
272
		fatal("attempt to use scalar as array");
273
273
274
	if (symbol->var_array == NULL) {
274
	if (symbol->var_array == NULL) {
275
		symbol->type = Node_var_array;
275
		if (symbol->type != Node_var_array) {
276
			unref(symbol->var_value);
277
			symbol->type = Node_var_array;
278
		}
276
		symbol->array_size = symbol->table_size = 0;	/* sanity */
279
		symbol->array_size = symbol->table_size = 0;	/* sanity */
277
		symbol->flags &= ~ARRAYMAXED;
280
		symbol->flags &= ~ARRAYMAXED;
278
		grow_table(symbol);
281
		grow_table(symbol);
Lines 360-372 Link Here
360
			last = bucket, bucket = bucket->ahnext)
363
			last = bucket, bucket = bucket->ahnext)
361
		if (cmp_nodes(bucket->ahname, subs) == 0)
364
		if (cmp_nodes(bucket->ahname, subs) == 0)
362
			break;
365
			break;
363
	free_temp(subs);
364
	if (bucket == NULL) {
366
	if (bucket == NULL) {
365
		if (do_lint)
367
		if (do_lint)
366
			warning("delete: index `%s' not in array `%s'",
368
			warning("delete: index `%s' not in array `%s'",
367
				subs->stptr, symbol->vname);
369
				subs->stptr, symbol->vname);
370
		free_temp(subs);
368
		return;
371
		return;
369
	}
372
	}
373
	free_temp(subs);
370
	if (last != NULL)
374
	if (last != NULL)
371
		last->ahnext = bucket->ahnext;
375
		last->ahnext = bucket->ahnext;
372
	else
376
	else
(-)awk/awk.h (-2 / +12 lines)
Lines 3-9 Link Here
3
 */
3
 */
4
4
5
/* 
5
/* 
6
 * Copyright (C) 1986, 1988, 1989, 1991-1997 the Free Software Foundation, Inc.
6
 * Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
7
 * 
7
 * 
8
 * This file is part of GAWK, the GNU implementation of the
8
 * This file is part of GAWK, the GNU implementation of the
9
 * AWK Programming Language.
9
 * AWK Programming Language.
Lines 25-30 Link Here
25
25
26
/* ------------------------------ Includes ------------------------------ */
26
/* ------------------------------ Includes ------------------------------ */
27
27
28
/*
29
 * config.h absolutely, positively, *M*U*S*T* be included before
30
 * any system headers.  Otherwise, extreme death, destruction
31
 * and loss of life results.
32
 *
33
 * Well, OK, gawk just won't work on systems using egcs and LFS.  But
34
 * that's almost as bad.
35
 */
28
#ifdef HAVE_CONFIG_H
36
#ifdef HAVE_CONFIG_H
29
#include <config.h>
37
#include <config.h>
30
#endif
38
#endif
Lines 34-39 Link Here
34
#endif /* _GNU_SOURCE */
42
#endif /* _GNU_SOURCE */
35
43
36
#include <stdio.h>
44
#include <stdio.h>
45
#include <assert.h>
37
#ifdef HAVE_LIMITS_H
46
#ifdef HAVE_LIMITS_H
38
#include <limits.h>
47
#include <limits.h>
39
#endif /* HAVE_LIMITS_H */
48
#endif /* HAVE_LIMITS_H */
Lines 588-594 Link Here
588
/* ------------------------- Pseudo-functions ------------------------- */
597
/* ------------------------- Pseudo-functions ------------------------- */
589
598
590
#define is_identchar(c)		(isalnum(c) || (c) == '_')
599
#define is_identchar(c)		(isalnum(c) || (c) == '_')
591
#define isnondecimal(str)	(((str)[0]) == '0')
600
#define isnondecimal(str)	(((str)[0]) == '0' && (ISDIGIT((str)[1]) \
601
					|| (str)[1] == 'x' || (str)[1] == 'X'))
592
602
593
#ifdef MPROF
603
#ifdef MPROF
594
#define	getnode(n)	emalloc(n, NODE *, sizeof(NODE), "getnode")
604
#define	getnode(n)	emalloc(n, NODE *, sizeof(NODE), "getnode")
(-)awk/awk.y (-5 / +14 lines)
Lines 3-9 Link Here
3
 */
3
 */
4
4
5
/* 
5
/* 
6
 * Copyright (C) 1986, 1988, 1989, 1991-1997 the Free Software Foundation, Inc.
6
 * Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
7
 * 
7
 * 
8
 * This file is part of GAWK, the GNU implementation of the
8
 * This file is part of GAWK, the GNU implementation of the
9
 * AWK Programming Language.
9
 * AWK Programming Language.
Lines 830-836 Link Here
830
		{ $$ = variable($1, CAN_FREE, Node_var); }
830
		{ $$ = variable($1, CAN_FREE, Node_var); }
831
	| NAME '[' expression_list ']'
831
	| NAME '[' expression_list ']'
832
		{
832
		{
833
		if ($3->rnode == NULL) {
833
		if ($3 == NULL) {
834
			fatal("invalid subscript expression");
835
		} else if ($3->rnode == NULL) {
834
			$$ = node(variable($1, CAN_FREE, Node_var_array), Node_subscript, $3->lnode);
836
			$$ = node(variable($1, CAN_FREE, Node_var_array), Node_subscript, $3->lnode);
835
			freenode($3);
837
			freenode($3);
836
		} else
838
		} else
Lines 1169-1175 Link Here
1169
				warning("source file `%s' is empty", source);
1171
				warning("source file `%s' is empty", source);
1170
			}
1172
			}
1171
		}
1173
		}
1172
		close(fd);
1174
		if (fileno(stdin) != fd)	/* safety */
1175
			close(fd);
1173
		samefile = FALSE;
1176
		samefile = FALSE;
1174
		nextfile++;
1177
		nextfile++;
1175
		if (lexeme)
1178
		if (lexeme)
Lines 1451-1464 Link Here
1451
	case ':':
1454
	case ':':
1452
	case '?':
1455
	case '?':
1453
		allow_newline();
1456
		allow_newline();
1454
		/* fall through */
1457
		return lasttok = c;
1458
1455
	case ')':
1459
	case ')':
1456
	case ']':
1460
	case ']':
1457
	case '(':	
1461
	case '(':	
1458
	case '[':
1459
	case ';':
1462
	case ';':
1460
	case '{':
1463
	case '{':
1461
	case ',':
1464
	case ',':
1465
		want_assign = FALSE;
1466
		/* fall through */
1467
	case '[':
1462
		return lasttok = c;
1468
		return lasttok = c;
1463
1469
1464
	case '*':
1470
	case '*':
Lines 2108-2113 Link Here
2108
{
2114
{
2109
	register NODE *oldlist;
2115
	register NODE *oldlist;
2110
	static NODE *savefront = NULL, *savetail = NULL;
2116
	static NODE *savefront = NULL, *savetail = NULL;
2117
2118
	if (list == NULL || new == NULL)
2119
		return list;
2111
2120
2112
	oldlist = list;
2121
	oldlist = list;
2113
	if (savefront == oldlist) {
2122
	if (savefront == oldlist) {
(-)awk/builtin.c (-25 / +84 lines)
Lines 3-9 Link Here
3
 */
3
 */
4
4
5
/* 
5
/* 
6
 * Copyright (C) 1986, 1988, 1989, 1991-1997 the Free Software Foundation, Inc.
6
 * Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
7
 * 
7
 * 
8
 * This file is part of GAWK, the GNU implementation of the
8
 * This file is part of GAWK, the GNU implementation of the
9
 * AWK Programming Language.
9
 * AWK Programming Language.
Lines 25-31 Link Here
25
25
26
26
27
#include "awk.h"
27
#include "awk.h"
28
#include <assert.h>
29
#undef HUGE
28
#undef HUGE
30
#undef CHARBITS
29
#undef CHARBITS
31
#undef INTBITS
30
#undef INTBITS
Lines 410-415 Link Here
410
	double tmpval;
409
	double tmpval;
411
	char signchar = FALSE;
410
	char signchar = FALSE;
412
	size_t len;
411
	size_t len;
412
	int zero_flag = FALSE;
413
	static char sp[] = " ";
413
	static char sp[] = " ";
414
	static char zero_string[] = "0";
414
	static char zero_string[] = "0";
415
	static char lchbuf[] = "0123456789abcdef";
415
	static char lchbuf[] = "0123456789abcdef";
Lines 437-442 Link Here
437
		prec = 0;
437
		prec = 0;
438
		have_prec = FALSE;
438
		have_prec = FALSE;
439
		signchar = FALSE;
439
		signchar = FALSE;
440
		zero_flag = FALSE;
440
		lj = alt = big = bigbig = small = FALSE;
441
		lj = alt = big = bigbig = small = FALSE;
441
		fill = sp;
442
		fill = sp;
442
		cp = cend;
443
		cp = cend;
Lines 460-469 Link Here
460
			break;
461
			break;
461
462
462
		case '0':
463
		case '0':
464
			zero_flag = TRUE;
463
			if (lj)
465
			if (lj)
464
				goto retry;
466
				goto retry;
465
			if (cur == &fw)
466
				fill = zero_string;
467
			/* FALL through */
467
			/* FALL through */
468
		case '1':
468
		case '1':
469
		case '2':
469
		case '2':
Lines 587-592 Link Here
587
			goto retry;
587
			goto retry;
588
		case 'c':
588
		case 'c':
589
			need_format = FALSE;
589
			need_format = FALSE;
590
			if (zero_flag && ! lj)
591
				fill = zero_string;
590
			parse_next_arg();
592
			parse_next_arg();
591
			/* user input that looks numeric is numeric */
593
			/* user input that looks numeric is numeric */
592
			if ((arg->flags & (MAYBE_NUM|NUMBER)) == MAYBE_NUM)
594
			if ((arg->flags & (MAYBE_NUM|NUMBER)) == MAYBE_NUM)
Lines 611-616 Link Here
611
			goto pr_tail;
613
			goto pr_tail;
612
		case 's':
614
		case 's':
613
			need_format = FALSE;
615
			need_format = FALSE;
616
			if (zero_flag && ! lj)
617
				fill = zero_string;
614
			parse_next_arg();
618
			parse_next_arg();
615
			arg = force_string(arg);
619
			arg = force_string(arg);
616
			if (! have_prec || prec > arg->stlen)
620
			if (! have_prec || prec > arg->stlen)
Lines 622-627 Link Here
622
			need_format = FALSE;
626
			need_format = FALSE;
623
			parse_next_arg();
627
			parse_next_arg();
624
			tmpval = force_number(arg);
628
			tmpval = force_number(arg);
629
630
			/*
631
			 * ``The result of converting a zero value with a
632
			 * precision of zero is no characters.''
633
			 */
634
			if (have_prec && prec == 0 && tmpval == 0)
635
				goto pr_tail;
636
625
			if (tmpval < 0) {
637
			if (tmpval < 0) {
626
				if (tmpval < LONG_MIN)
638
				if (tmpval < LONG_MIN)
627
					goto out_of_range;
639
					goto out_of_range;
Lines 639-655 Link Here
639
				*--cp = (char) ('0' + uval % 10);
651
				*--cp = (char) ('0' + uval % 10);
640
				uval /= 10;
652
				uval /= 10;
641
			} while (uval > 0);
653
			} while (uval > 0);
654
655
			/* add more output digits to match the precision */
656
			if (have_prec) {
657
				while (cend - cp < prec)
658
					*--cp = '0';
659
			}
660
642
			if (sgn)
661
			if (sgn)
643
				*--cp = '-';
662
				*--cp = '-';
644
			else if (signchar)
663
			else if (signchar)
645
				*--cp = signchar;
664
				*--cp = signchar;
646
			/*
665
			/*
647
			 * precision overrides '0' flags. however, for
666
			 * When to fill with zeroes is of course not simple.
648
			 * integer formats, precsion is minimum number of
667
			 * First: No zero fill if left-justifying.
649
			 * *digits*, not characters, thus we want to fill
668
			 * Next: There seem to be two cases:
650
			 * with zeroes.
669
			 * 	A '0' without a precision, e.g. %06d
670
			 * 	A precision with no field width, e.g. %.10d
671
			 * Any other case, we don't want to fill with zeroes.
651
			 */
672
			 */
652
			if (have_prec)
673
			if (! lj
674
			    && ((zero_flag && ! have_prec)
675
				 || (fw == 0 && have_prec)))
653
				fill = zero_string;
676
				fill = zero_string;
654
			if (prec > fw)
677
			if (prec > fw)
655
				fw = prec;
678
				fw = prec;
Lines 673-678 Link Here
673
			need_format = FALSE;
696
			need_format = FALSE;
674
			parse_next_arg();
697
			parse_next_arg();
675
			tmpval = force_number(arg);
698
			tmpval = force_number(arg);
699
700
			/*
701
			 * ``The result of converting a zero value with a
702
			 * precision of zero is no characters.''
703
			 *
704
			 * If I remember the ANSI C standard, though,
705
			 * it says that for octal conversions
706
			 * the precision is artificially increased
707
			 * to add an extra 0 if # is supplied.
708
			 * Indeed, in C,
709
			 * 	printf("%#.0o\n", 0);
710
			 * prints a single 0.
711
			 */
712
			if (! alt && have_prec && prec == 0 && tmpval == 0)
713
				goto pr_tail;
714
676
			if (tmpval < 0) {
715
			if (tmpval < 0) {
677
				if (tmpval < LONG_MIN)
716
				if (tmpval < LONG_MIN)
678
					goto out_of_range;
717
					goto out_of_range;
Lines 685-702 Link Here
685
				uval = (unsigned long) tmpval;
724
				uval = (unsigned long) tmpval;
686
			}
725
			}
687
			/*
726
			/*
688
			 * precision overrides '0' flags. however, for
727
			 * When to fill with zeroes is of course not simple.
689
			 * integer formats, precsion is minimum number of
728
			 * First: No zero fill if left-justifying.
690
			 * *digits*, not characters, thus we want to fill
729
			 * Next: There seem to be two cases:
691
			 * with zeroes.
730
			 * 	A '0' without a precision, e.g. %06d
731
			 * 	A precision with no field width, e.g. %.10d
732
			 * Any other case, we don't want to fill with zeroes.
692
			 */
733
			 */
693
			if (have_prec)
734
			if (! lj
735
			    && ((zero_flag && ! have_prec)
736
				 || (fw == 0 && have_prec)))
694
				fill = zero_string;
737
				fill = zero_string;
695
			do {
738
			do {
696
				*--cp = chbuf[uval % base];
739
				*--cp = chbuf[uval % base];
697
				uval /= base;
740
				uval /= base;
698
			} while (uval > 0);
741
			} while (uval > 0);
699
			if (alt) {
742
743
			/* add more output digits to match the precision */
744
			if (have_prec) {
745
				while (cend - cp < prec)
746
					*--cp = '0';
747
			}
748
749
			if (alt && tmpval != 0) {
700
				if (base == 16) {
750
				if (base == 16) {
701
					*--cp = cs1;
751
					*--cp = cs1;
702
					*--cp = '0';
752
					*--cp = '0';
Lines 755-761 Link Here
755
				*cp++ = signchar;
805
				*cp++ = signchar;
756
			if (alt)
806
			if (alt)
757
				*cp++ = '#';
807
				*cp++ = '#';
758
			if (fill != sp)
808
			if (zero_flag)
759
				*cp++ = '0';
809
				*cp++ = '0';
760
			cp = strcpy(cp, "*.*") + 3;
810
			cp = strcpy(cp, "*.*") + 3;
761
			*cp++ = cs1;
811
			*cp++ = cs1;
Lines 1084-1089 Link Here
1084
	register FILE *fp;
1134
	register FILE *fp;
1085
	int numnodes, i;
1135
	int numnodes, i;
1086
	NODE *save;
1136
	NODE *save;
1137
	NODE *tval;
1087
1138
1088
	if (tree->rnode) {
1139
	if (tree->rnode) {
1089
		int errflg;		/* not used, sigh */
1140
		int errflg;		/* not used, sigh */
Lines 1117-1141 Link Here
1117
		t[i] = dupnode(n);
1168
		t[i] = dupnode(n);
1118
		free_temp(n);
1169
		free_temp(n);
1119
1170
1120
		if (t[i]->flags & NUMBER) {
1171
		if ((t[i]->flags & (NUMBER|STRING)) == NUMBER) {
1121
			if (OFMTidx == CONVFMTidx)
1172
			if (OFMTidx == CONVFMTidx)
1122
				(void) force_string(t[i]);
1173
				(void) force_string(t[i]);
1123
			else
1174
			else {
1124
				t[i] = format_val(OFMT, OFMTidx, t[i]);
1175
				tval = tmp_number(t[i]->numbr);
1176
				unref(t[i]);
1177
				t[i] = format_val(OFMT, OFMTidx, tval);
1178
			}
1125
		}
1179
		}
1126
	}
1180
	}
1127
1181
1128
	for (i = 0; i < numnodes; i++) {
1182
	for (i = 0; i < numnodes; i++) {
1129
		efwrite(t[i]->stptr, sizeof(char), t[i]->stlen, fp, "print", rp, FALSE);
1183
		efwrite(t[i]->stptr, sizeof(char), t[i]->stlen, fp, "print", rp, FALSE);
1130
		unref(t[i]);
1184
		unref(t[i]);
1131
		if (i != numnodes - 1) {
1185
1132
			if (OFSlen > 0)
1186
		if (i != numnodes - 1 && OFSlen > 0)
1133
				efwrite(OFS, sizeof(char), (size_t) OFSlen,
1187
			efwrite(OFS, sizeof(char), (size_t) OFSlen,
1134
					fp, "print", rp, FALSE);
1188
				fp, "print", rp, FALSE);
1135
		}
1189
1136
	}
1190
	}
1137
	if (ORSlen > 0)
1191
	if (ORSlen > 0)
1138
		efwrite(ORS, sizeof(char), (size_t) ORSlen, fp, "print", rp, TRUE);
1192
		efwrite(ORS, sizeof(char), (size_t) ORSlen, fp, "print", rp, TRUE);
1193
1139
	free(t);
1194
	free(t);
1140
}
1195
}
1141
1196
Lines 1512-1517 Link Here
1512
			 */
1567
			 */
1513
			if (lastmatchnonzero && matchstart == matchend) {
1568
			if (lastmatchnonzero && matchstart == matchend) {
1514
				lastmatchnonzero = FALSE;
1569
				lastmatchnonzero = FALSE;
1570
				matches--;
1515
				goto empty;
1571
				goto empty;
1516
			}
1572
			}
1517
			/*
1573
			/*
Lines 2022-2027 Link Here
2022
			case 'c':
2078
			case 'c':
2023
			case 'd':
2079
			case 'd':
2024
			case 'e':
2080
			case 'e':
2081
			case 'f':
2025
				val = *str - 'a' + 10;
2082
				val = *str - 'a' + 10;
2026
				break;
2083
				break;
2027
			case 'A':
2084
			case 'A':
Lines 2029-2034 Link Here
2029
			case 'C':
2086
			case 'C':
2030
			case 'D':
2087
			case 'D':
2031
			case 'E':
2088
			case 'E':
2089
			case 'F':
2032
				val = *str - 'A' + 10;
2090
				val = *str - 'A' + 10;
2033
				break;
2091
				break;
2034
			default:
2092
			default:
Lines 2039-2049 Link Here
2039
	} else if (*str == '0') {
2097
	} else if (*str == '0') {
2040
		for (; len > 0; len--) {
2098
		for (; len > 0; len--) {
2041
			if (! isdigit(*str) || *str == '8' || *str == '9')
2099
			if (! isdigit(*str) || *str == '8' || *str == '9')
2042
				goto done;
2100
				goto decimal;
2043
			retval = (retval * 8) + (*str - '0');
2101
			retval = (retval * 8) + (*str - '0');
2044
			str++;
2102
			str++;
2045
		}
2103
		}
2046
	} else {
2104
	} else {
2105
decimal:
2047
		save = str[len];
2106
		save = str[len];
2048
		retval = atof(str);
2107
		retval = atof(str);
2049
		str[len] = save;
2108
		str[len] = save;
(-)awk/config.h (-1 / +4 lines)
Lines 5-11 Link Here
5
 */
5
 */
6
6
7
/* 
7
/* 
8
 * Copyright (C) 1995-1997 the Free Software Foundation, Inc.
8
 * Copyright (C) 1995-1999 the Free Software Foundation, Inc.
9
 * 
9
 * 
10
 * This file is part of GAWK, the GNU implementation of the
10
 * This file is part of GAWK, the GNU implementation of the
11
 * AWK Programming Language.
11
 * AWK Programming Language.
Lines 131-136 Link Here
131
#define SPRINTF_RET int /* return type of sprintf */
131
#define SPRINTF_RET int /* return type of sprintf */
132
/* #undef BITOPS */  /* bitwise ops (undocumented feature) */
132
/* #undef BITOPS */  /* bitwise ops (undocumented feature) */
133
/* #undef NONDECDATA */ /* non-decimal input data (undocumented feature) */
133
/* #undef NONDECDATA */ /* non-decimal input data (undocumented feature) */
134
/* #undef _FILE_OFFSET_BITS */ /* bits in a file offset, where this matters */
135
/* #undef _LARGEFILE_SOURCE */ /* makes fseeko etc. visible on some hosts */
136
/* #undef _LARGE_FILES */ /* emables large files on AIX-style hosts */
134
137
135
/* Define if you have the fmod function.  */
138
/* Define if you have the fmod function.  */
136
#define HAVE_FMOD 1
139
#define HAVE_FMOD 1
(-)awk/custom.h (-2 / +9 lines)
Lines 7-17 Link Here
7
 * information.
7
 * information.
8
 *
8
 *
9
 * If you make additions to this file for your system, please send me
9
 * If you make additions to this file for your system, please send me
10
 * the information, to arnold@gnu.ai.mit.edu.
10
 * the information, to arnold@gnu.org.
11
 */
11
 */
12
12
13
/* 
13
/* 
14
 * Copyright (C) 1995-1997 the Free Software Foundation, Inc.
14
 * Copyright (C) 1995-1999 the Free Software Foundation, Inc.
15
 * 
15
 * 
16
 * This file is part of GAWK, the GNU implementation of the
16
 * This file is part of GAWK, the GNU implementation of the
17
 * AWK Programming Language.
17
 * AWK Programming Language.
Lines 56-59 Link Here
56
/* For sequent, based on email with Aron Griffis <agriffis@calypso.coat.com> */
56
/* For sequent, based on email with Aron Griffis <agriffis@calypso.coat.com> */
57
#ifdef _SEQUENT_
57
#ifdef _SEQUENT_
58
#undef HAVE_MMAP
58
#undef HAVE_MMAP
59
#endif
60
61
/* For BeOS, from mc@whoever.com */
62
#if defined(__dest_os) && __dest_os == __be_os
63
#define BROKEN_STRNCASECMP
64
#define ELIDE_CODE
65
#include <alloca.h>
59
#endif
66
#endif
(-)awk/doc/ChangeLog (+27 lines)
Lines 1-3 Link Here
1
Wed Jun 30 16:14:36 1999  Arnold D. Robbins  <arnold@gnu.org>
2
3
	* Release 3.0.4: Release tar file made.  This time for sure.
4
5
Wed Oct  7 21:59:33 1998  Arnold D. Robbins  <arnold@gnu.org>
6
7
	* texinfo.tex: Updated to version 2.227, from Texinfo 3.12.
8
9
Sun Oct 19 12:26:08 1997  Arnold D. Robbins  <arnold@gnu.org>
10
11
	* ALL: change references to arnold@gnu.ai.mit.edu to arnold@gnu.org.
12
13
Tue Sep 23 10:31:17 1997  Arnold D. Robbins  <arnold@gnu.org>
14
15
	* texinfo.tex: Updated to version 2.218, from Texinfo 3.11.
16
17
Fri Jul  4 08:19:00 1997  Arnold D. Robbins  <arnold@gnu.org>
18
19
	* Makefile.in ($(infodir)/gawk.info): Don't make dependent upon
20
	  gawk.info, in case installed one is newer. Instead, check that
21
	  an installed gawk.info exists and is identical to current one.
22
	  If so, just exit; otherwise do the install.
23
24
Wed Jul  2 14:55:12 1997  Arnold D. Robbins  <arnold@gnu.org>
25
26
	* Makefile.in ($(infodir)/gawk.info): typo fix.
27
1
Thu May 15 12:49:08 1997  Arnold D. Robbins  <arnold@skeeve.atl.ga.us>
28
Thu May 15 12:49:08 1997  Arnold D. Robbins  <arnold@skeeve.atl.ga.us>
2
29
3
	* Release 3.0.3: Release tar file made.
30
	* Release 3.0.3: Release tar file made.
(-)awk/doc/awk.1 (-6 / +12 lines)
Lines 1-7 Link Here
1
.ds PX \s-1POSIX\s+1
1
.ds PX \s-1POSIX\s+1
2
.ds UX \s-1UNIX\s+1
2
.ds UX \s-1UNIX\s+1
3
.ds AN \s-1ANSI\s+1
3
.ds AN \s-1ANSI\s+1
4
.TH GAWK 1 "Dec 19 1996" "Free Software Foundation" "Utility Commands"
4
.TH GAWK 1 "Apr 28 1999" "Free Software Foundation" "Utility Commands"
5
.SH NAME
5
.SH NAME
6
gawk \- pattern scanning and processing language
6
gawk \- pattern scanning and processing language
7
.SH SYNOPSIS
7
.SH SYNOPSIS
Lines 2150-2155 Link Here
2150
Function parameters used as local variables are initialized
2150
Function parameters used as local variables are initialized
2151
to the null string and the number zero upon function invocation.
2151
to the null string and the number zero upon function invocation.
2152
.PP
2152
.PP
2153
Use
2154
.BI return " expr"
2155
to return a value from a function. The return value is undefined if no
2156
value is provided, or if the function returns by ``falling off'' the
2157
end.
2158
.PP
2153
If
2159
If
2154
.B \-\^\-lint
2160
.B \-\^\-lint
2155
has been provided,
2161
has been provided,
Lines 2481-2487 Link Here
2481
will support this usage if
2487
will support this usage if
2482
.B \-\^\-traditional
2488
.B \-\^\-traditional
2483
has been specified.
2489
has been specified.
2484
.SH ENVIRONMENT
2490
.SH ENVIRONMENT VARIABLES
2485
If
2491
If
2486
.B POSIXLY_CORRECT
2492
.B POSIXLY_CORRECT
2487
exists in the environment, then
2493
exists in the environment, then
Lines 2535-2541 Link Here
2535
.SH VERSION INFORMATION
2541
.SH VERSION INFORMATION
2536
This man page documents
2542
This man page documents
2537
.IR gawk ,
2543
.IR gawk ,
2538
version 3.0.2.
2544
version 3.0.4.
2539
.SH AUTHORS
2545
.SH AUTHORS
2540
The original version of \*(UX
2546
The original version of \*(UX
2541
.I awk
2547
.I awk
Lines 2566-2575 Link Here
2566
If you find a bug in
2572
If you find a bug in
2567
.IR gawk ,
2573
.IR gawk ,
2568
please send electronic mail to
2574
please send electronic mail to
2569
.BR bug-gnu-utils@prep.ai.mit.edu ,
2575
.BR bug-gnu-utils@gnu.org ,
2570
.I with
2576
.I with
2571
a carbon copy to
2577
a carbon copy to
2572
.BR arnold@gnu.ai.mit.edu .
2578
.BR arnold@gnu.org .
2573
Please include your operating system and its revision, the version of
2579
Please include your operating system and its revision, the version of
2574
.IR gawk ,
2580
.IR gawk ,
2575
what C compiler you used to compile it, and a test program
2581
what C compiler you used to compile it, and a test program
Lines 2598-2604 Link Here
2598
provided valuable assistance during testing and debugging.
2604
provided valuable assistance during testing and debugging.
2599
We thank him.
2605
We thank him.
2600
.SH COPYING PERMISSIONS
2606
.SH COPYING PERMISSIONS
2601
Copyright \(co\) 1996 Free Software Foundation, Inc.
2607
Copyright \(co) 1996,97,98,99 Free Software Foundation, Inc.
2602
.PP
2608
.PP
2603
Permission is granted to make and distribute verbatim copies of
2609
Permission is granted to make and distribute verbatim copies of
2604
this manual page provided the copyright notice and this permission
2610
this manual page provided the copyright notice and this permission
(-)awk/doc/gawk.texi (-63 / +159 lines)
Lines 21-30 Link Here
21
@c applies to, and when the document was updated.
21
@c applies to, and when the document was updated.
22
@set TITLE Effective AWK Programming
22
@set TITLE Effective AWK Programming
23
@set SUBTITLE A User's Guide for GNU Awk
23
@set SUBTITLE A User's Guide for GNU Awk
24
@set PATCHLEVEL 3
24
@set PATCHLEVEL 4
25
@set EDITION 1.0.@value{PATCHLEVEL}
25
@set EDITION 1.0.@value{PATCHLEVEL}
26
@set VERSION 3.0
26
@set VERSION 3.0
27
@set UPDATE-MONTH February 1997
27
@set UPDATE-MONTH April, 1999
28
@iftex
28
@iftex
29
@set DOCUMENT book
29
@set DOCUMENT book
30
@end iftex
30
@end iftex
Lines 74-80 Link Here
74
This is Edition @value{EDITION} of @cite{@value{TITLE}},
74
This is Edition @value{EDITION} of @cite{@value{TITLE}},
75
for the @value{VERSION}.@value{PATCHLEVEL} version of the GNU implementation of AWK.
75
for the @value{VERSION}.@value{PATCHLEVEL} version of the GNU implementation of AWK.
76
76
77
Copyright (C) 1989, 1991, 92, 93, 96, 97 Free Software Foundation, Inc.
77
Copyright (C) 1989, 1991, 92, 93, 96, 97, 98, 99 Free Software Foundation, Inc.
78
78
79
Permission is granted to make and distribute verbatim copies of
79
Permission is granted to make and distribute verbatim copies of
80
this manual provided the copyright notice and this permission notice
80
this manual provided the copyright notice and this permission notice
Lines 138-144 Link Here
138
Registered Trademark of Paramount Pictures Corporation. @*
138
Registered Trademark of Paramount Pictures Corporation. @*
139
@c sorry, i couldn't resist
139
@c sorry, i couldn't resist
140
@sp 3
140
@sp 3
141
Copyright @copyright{} 1989, 1991, 92, 93, 96, 97 Free Software Foundation, Inc.
141
Copyright @copyright{} 1989, 1991, 92, 93, 96, 97, 98, 99 Free Software Foundation, Inc.
142
@sp 2
142
@sp 2
143
        
143
        
144
This is Edition @value{EDITION} of @cite{@value{TITLE}}, @*
144
This is Edition @value{EDITION} of @cite{@value{TITLE}}, @*
Lines 153-168 Link Here
153
@item Seattle, WA 98155 USA @tab Boston, MA  02111-1307 USA
153
@item Seattle, WA 98155 USA @tab Boston, MA  02111-1307 USA
154
@item Phone: +1-206-782-7733 @tab Phone: +1-617-542-5942
154
@item Phone: +1-206-782-7733 @tab Phone: +1-617-542-5942
155
@item Fax: +1-206-782-7191 @tab Fax: +1-617-542-2652
155
@item Fax: +1-206-782-7191 @tab Fax: +1-617-542-2652
156
@item E-mail: @code{sales@@ssc.com} @tab E-mail: @code{gnu@@prep.ai.mit.edu}
156
@item E-mail: @code{sales@@ssc.com} @tab E-mail: @code{gnu@@gnu.org}
157
@item URL: @code{http://www.ssc.com/} @tab URL: @code{http://www.fsf.org/}
157
@item URL: @code{http://www.ssc.com/} @tab URL: @code{http://www.fsf.org/}
158
@end multitable
158
@end multitable
159
159
160
@sp 1
160
@sp 1
161
@c this ISBN can change! Check with SSC
161
@c this ISBN can change! Check with SSC
162
@c This one is correct for gawk 3.0 and edition 1.0 from the FSF
162
@c This one is correct for gawk 3.0 and edition 1.0 from the FSF
163
@c ISBN 1-882114-26-4 @*
163
ISBN 1-882114-26-4 @*
164
@c This one is correct for gawk 3.0.3 and edition 1.0.3 from SSC
164
@c This one is correct for gawk 3.0.3 and edition 1.0.3 from SSC
165
ISBN 1-57831-000-8 @*
165
@c ISBN 1-57831-000-8 @*
166
166
167
Permission is granted to make and distribute verbatim copies of
167
Permission is granted to make and distribute verbatim copies of
168
this manual provided the copyright notice and this permission notice
168
this manual provided the copyright notice and this permission notice
Lines 1387-1392 Link Here
1387
program which users can invoke without their having to know that the program is
1387
program which users can invoke without their having to know that the program is
1388
written in @code{awk}.
1388
written in @code{awk}.
1389
1389
1390
@strong{Caution:} You should not put more than one argument on the @samp{#!}
1391
line after the path to @code{awk}. This will not work. The operating system
1392
treats the rest of the line as a single agument, and passes it to @code{awk}.
1393
Doing this will lead to confusing behavior: most likely a usage diagnostic
1394
of some sort from @code{awk}.
1395
1390
@cindex shell scripts
1396
@cindex shell scripts
1391
@cindex scripts, shell
1397
@cindex scripts, shell
1392
Some older systems do not support the @samp{#!} mechanism. You can get a
1398
Some older systems do not support the @samp{#!} mechanism. You can get a
Lines 1441-1446 Link Here
1441
comment is to help you or another person understand the program at
1447
comment is to help you or another person understand the program at
1442
a later time.
1448
a later time.
1443
1449
1450
@strong{Caution:} As mentioned in
1451
@ref{One-shot, ,One-shot Throw-away @code{awk} Programs},
1452
you can enclose small to medium programs in single quotes, in order to keep
1453
your shell scripts self-contained.  When doing so, @emph{don't} put
1454
an apostrophe (i.e., a single quote) into a comment (or anywhere else
1455
in your program). The shell will interpret the quote as the closing
1456
quote for the entire program. As a result, usually the shell will
1457
print a message about mismatched quotes, and if @code{awk} actually
1458
runs, it will probably print strange messages about syntax errors.
1459
For example:
1460
1461
@example
1462
awk 'BEGIN @{ print "hello" @} # let's be cute'
1463
@end example
1464
1444
@node Very Simple, Two Rules, Running gawk, Getting Started
1465
@node Very Simple, Two Rules, Running gawk, Getting Started
1445
@section A Very Simple Example
1466
@section A Very Simple Example
1446
1467
Lines 2142-2148 Link Here
2142
Another interesting question arises. Suppose you use an octal or hexadecimal
2163
Another interesting question arises. Suppose you use an octal or hexadecimal
2143
escape to represent a regexp metacharacter
2164
escape to represent a regexp metacharacter
2144
(@pxref{Regexp Operators, ,  Regular Expression Operators}).
2165
(@pxref{Regexp Operators, ,  Regular Expression Operators}).
2145
Does @code{awk} treat the character as literal character, or as a regexp
2166
Does @code{awk} treat the character as a literal character, or as a regexp
2146
operator?
2167
operator?
2147
2168
2148
@cindex dark corner
2169
@cindex dark corner
Lines 4450-4455 Link Here
4450
because the concatenation operator is not parenthesized, and you should
4471
because the concatenation operator is not parenthesized, and you should
4451
write it as @samp{("echo " "date") | getline} if you want your program
4472
write it as @samp{("echo " "date") | getline} if you want your program
4452
to be portable to other @code{awk} implementations.
4473
to be portable to other @code{awk} implementations.
4474
(It happens that @code{gawk} gets it right, but you should not
4475
rely on this. Parentheses make it easier to read, anyway.) 
4453
4476
4454
@node Getline/Variable/Pipe, Getline Summary, Getline/Pipe, Getline
4477
@node Getline/Variable/Pipe, Getline Summary, Getline/Pipe, Getline
4455
@subsection Using @code{getline} Into a Variable from a Pipe
4478
@subsection Using @code{getline} Into a Variable from a Pipe
Lines 4482-4487 Link Here
4482
because the concatenation operator is not parenthesized, and you should
4505
because the concatenation operator is not parenthesized, and you should
4483
write it as @samp{("echo " "date") | getline @var{var}} if you want your
4506
write it as @samp{("echo " "date") | getline @var{var}} if you want your
4484
program to be portable to other @code{awk} implementations.
4507
program to be portable to other @code{awk} implementations.
4508
(It happens that @code{gawk} gets it right, but you should not
4509
rely on this. Parentheses make it easier to read, anyway.) 
4485
@end ifinfo
4510
@end ifinfo
4486
4511
4487
@node Getline Summary,  , Getline/Variable/Pipe, Getline
4512
@node Getline Summary,  , Getline/Variable/Pipe, Getline
Lines 4616-4622 Link Here
4616
4641
4617
Here is an example of printing a string that contains embedded newlines
4642
Here is an example of printing a string that contains embedded newlines
4618
(the @samp{\n} is an escape sequence, used to represent the newline
4643
(the @samp{\n} is an escape sequence, used to represent the newline
4619
character; see @ref{Escape Sequences}):
4644
character; @pxref{Escape Sequences}):
4620
4645
4621
@example
4646
@example
4622
@group
4647
@group
Lines 6975-6980 Link Here
6975
However, you cannot put a newline in front
7000
However, you cannot put a newline in front
6976
of either character without using backslash continuation
7001
of either character without using backslash continuation
6977
(@pxref{Statements/Lines, ,@code{awk} Statements Versus Lines}).
7002
(@pxref{Statements/Lines, ,@code{awk} Statements Versus Lines}).
7003
If @samp{--posix} is specified
7004
(@pxref{Options, , Command Line Options}), then this extension is disabled.
6978
7005
6979
@node Function Calls, Precedence, Conditional Exp, Expressions
7006
@node Function Calls, Precedence, Conditional Exp, Expressions
6980
@section Function Calls
7007
@section Function Calls
Lines 8264-8270 Link Here
8264
@example
8291
@example
8265
@group
8292
@group
8266
BEGIN @{
8293
BEGIN @{
8267
       if (("date" | getline date_now) < 0) @{
8294
       if (("date" | getline date_now) <= 0) @{
8268
         print "Can't get system date" > "/dev/stderr"
8295
         print "Can't get system date" > "/dev/stderr"
8269
         exit 1
8296
         exit 1
8270
       @}
8297
       @}
Lines 8627-8635 Link Here
8627
8654
8628
Notice that the @code{awk} program is not entered in @code{ARGV}.  The
8655
Notice that the @code{awk} program is not entered in @code{ARGV}.  The
8629
other special command line options, with their arguments, are also not
8656
other special command line options, with their arguments, are also not
8630
entered.  But variable assignments on the command line @emph{are}
8657
entered.  This includes variable assignments done with the @samp{-v}
8658
option (@pxref{Options, ,Command Line Options}).
8659
Normal variable assignments on the command line @emph{are}
8631
treated as arguments, and do show up in the @code{ARGV} array.
8660
treated as arguments, and do show up in the @code{ARGV} array.
8632
8661
8662
@example
8663
$ cat showargs.awk
8664
@print{} BEGIN @{
8665
@print{}     printf "A=%d, B=%d\n", A, B
8666
@print{}     for (i = 0; i < ARGC; i++)
8667
@print{}         printf "\tARGV[%d] = %s\n", i, ARGV[i]
8668
@print{} @}
8669
@print{} END   @{ printf "A=%d, B=%d\n", A, B @}
8670
$ awk -v A=1 -f showargs.awk B=2 /dev/null
8671
@print{} A=1, B=0
8672
@print{} 	ARGV[0] = awk
8673
@print{} 	ARGV[1] = B=2
8674
@print{} 	ARGV[2] = /dev/null
8675
@print{} A=1, B=2
8676
@end example
8677
8633
Your program can alter @code{ARGC} and the elements of @code{ARGV}.
8678
Your program can alter @code{ARGC} and the elements of @code{ARGV}.
8634
Each time @code{awk} reaches the end of an input file, it uses the next
8679
Each time @code{awk} reaches the end of an input file, it uses the next
8635
element of @code{ARGV} as the name of the next input file.  By storing a
8680
element of @code{ARGV} as the name of the next input file.  By storing a
Lines 9172-9177 Link Here
9172
apart the null string. Since there is no data to split out, the
9217
apart the null string. Since there is no data to split out, the
9173
function simply clears the array and then returns.
9218
function simply clears the array and then returns.
9174
9219
9220
@strong{Caution:} Deleting an array does not change its type; you cannot
9221
delete an array and then use the array's name as a scalar. For
9222
example, this will not work:
9223
9224
@example
9225
a[1] = 3; delete a; a = 3
9226
@end example
9227
9175
@node Numeric Array Subscripts, Uninitialized Subscripts, Delete, Arrays
9228
@node Numeric Array Subscripts, Uninitialized Subscripts, Delete, Arrays
9176
@section Using Numbers to Subscript Arrays
9229
@section Using Numbers to Subscript Arrays
9177
9230
Lines 9785-9790 Link Here
9785
Before splitting the string, @code{split} deletes any previously existing
9838
Before splitting the string, @code{split} deletes any previously existing
9786
elements in the array @var{array} (d.c.).
9839
elements in the array @var{array} (d.c.).
9787
9840
9841
If @var{string} does not match @var{fieldsep} at all, @var{array} will have
9842
one element. The value of that element will be the original
9843
@var{string}.
9844
9788
@item sprintf(@var{format}, @var{expression1},@dots{})
9845
@item sprintf(@var{format}, @var{expression1},@dots{})
9789
@findex sprintf
9846
@findex sprintf
9790
This returns (without printing) the string that @code{printf} would
9847
This returns (without printing) the string that @code{printf} would
Lines 9901-9906 Link Here
9901
object as the third parameter will cause a fatal error, and your program
9958
object as the third parameter will cause a fatal error, and your program
9902
will not run.
9959
will not run.
9903
9960
9961
Finally, if the @var{regexp} is not a regexp constant, it is converted into a
9962
string and then the value of that string is treated as the regexp to match.
9963
9904
@item gsub(@var{regexp}, @var{replacement} @r{[}, @var{target}@r{]})
9964
@item gsub(@var{regexp}, @var{replacement} @r{[}, @var{target}@r{]})
9905
@findex gsub
9965
@findex gsub
9906
This is similar to the @code{sub} function, except @code{gsub} replaces
9966
This is similar to the @code{sub} function, except @code{gsub} replaces
Lines 9980-9985 Link Here
9980
@samp{G}, or if it is a number that is less than zero, only one
10040
@samp{G}, or if it is a number that is less than zero, only one
9981
substitution is performed.
10041
substitution is performed.
9982
10042
10043
If @var{regexp} does not match @var{target}, @code{gensub}'s return value
10044
is the original, unchanged value of @var{target}.
10045
9983
@cindex differences between @code{gawk} and @code{awk}
10046
@cindex differences between @code{gawk} and @code{awk}
9984
@code{gensub} is a @code{gawk} extension; it is not available
10047
@code{gensub} is a @code{gawk} extension; it is not available
9985
in compatibility mode (@pxref{Options, ,Command Line Options}).
10048
in compatibility mode (@pxref{Options, ,Command Line Options}).
Lines 10310-10316 Link Here
10310
@item system(@var{command})
10373
@item system(@var{command})
10311
@findex system
10374
@findex system
10312
@cindex interaction, @code{awk} and other programs
10375
@cindex interaction, @code{awk} and other programs
10313
The system function allows the user to execute operating system commands
10376
The @code{system} function allows the user to execute operating system commands
10314
and then return to the @code{awk} program.  The @code{system} function
10377
and then return to the @code{awk} program.  The @code{system} function
10315
executes the command given by the string @var{command}.  It returns, as
10378
executes the command given by the string @var{command}.  It returns, as
10316
its value, the status returned by the command that was executed.
10379
its value, the status returned by the command that was executed.
Lines 10329-10335 Link Here
10329
finishes processing input and begins its end-of-input processing.
10392
finishes processing input and begins its end-of-input processing.
10330
10393
10331
Note that redirecting @code{print} or @code{printf} into a pipe is often
10394
Note that redirecting @code{print} or @code{printf} into a pipe is often
10332
enough to accomplish your task.  However, if your @code{awk}
10395
enough to accomplish your task.  If you need to run many commands, it
10396
will be more efficient to simply print them to a pipe to the shell:
10397
10398
@example
10399
while (@var{more stuff to do})
10400
    print @var{command} | "/bin/sh"
10401
close("/bin/sh")
10402
@end example
10403
10404
@noindent
10405
However, if your @code{awk}
10333
program is interactive, @code{system} is useful for cranking up large
10406
program is interactive, @code{system} is useful for cranking up large
10334
self-contained programs, such as a shell or an editor.
10407
self-contained programs, such as a shell or an editor.
10335
10408
Lines 11889-11895 Link Here
11889
@c file eg/lib/nextfile.awk
11962
@c file eg/lib/nextfile.awk
11890
# nextfile --- skip remaining records in current file
11963
# nextfile --- skip remaining records in current file
11891
# correctly handle successive occurrences of the same file
11964
# correctly handle successive occurrences of the same file
11892
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
11965
# Arnold Robbins, arnold@@gnu.org, Public Domain
11893
# May, 1993
11966
# May, 1993
11894
11967
11895
# this should be read in before the "main" awk program
11968
# this should be read in before the "main" awk program
Lines 11983-11989 Link Here
11983
@c @group
12056
@c @group
11984
@c file eg/lib/assert.awk
12057
@c file eg/lib/assert.awk
11985
# assert --- assert that a condition is true. Otherwise exit.
12058
# assert --- assert that a condition is true. Otherwise exit.
11986
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
12059
# Arnold Robbins, arnold@@gnu.org, Public Domain
11987
# May, 1993
12060
# May, 1993
11988
12061
11989
function assert(condition, string)
12062
function assert(condition, string)
Lines 12038-12044 Link Here
12038
@end example
12111
@end example
12039
12112
12040
There is a problem with this version of @code{assert}, that it may not
12113
There is a problem with this version of @code{assert}, that it may not
12041
be possible to work around.  An @code{END} rule is automatically added
12114
be possible to work around with standard @code{awk}.
12115
An @code{END} rule is automatically added
12042
to the program calling @code{assert}.  Normally, if a program consists
12116
to the program calling @code{assert}.  Normally, if a program consists
12043
of just a @code{BEGIN} rule, the input files and/or standard input are
12117
of just a @code{BEGIN} rule, the input files and/or standard input are
12044
not read. However, now that the program has an @code{END} rule, @code{awk}
12118
not read. However, now that the program has an @code{END} rule, @code{awk}
Lines 12069-12075 Link Here
12069
@c file eg/lib/round.awk
12143
@c file eg/lib/round.awk
12070
# round --- do normal rounding
12144
# round --- do normal rounding
12071
#
12145
#
12072
# Arnold Robbins, arnold@@gnu.ai.mit.edu, August, 1996
12146
# Arnold Robbins, arnold@@gnu.org, August, 1996
12073
# Public Domain
12147
# Public Domain
12074
12148
12075
function round(x,   ival, aval, fraction)
12149
function round(x,   ival, aval, fraction)
Lines 12130-12136 Link Here
12130
#    _ord_init:    function to initialize _ord_
12204
#    _ord_init:    function to initialize _ord_
12131
#
12205
#
12132
# Arnold Robbins
12206
# Arnold Robbins
12133
# arnold@@gnu.ai.mit.edu
12207
# arnold@@gnu.org
12134
# Public Domain
12208
# Public Domain
12135
# 16 January, 1992
12209
# 16 January, 1992
12136
# 20 July, 1992, revised
12210
# 20 July, 1992, revised
Lines 12254-12260 Link Here
12254
@group
12328
@group
12255
@c file eg/lib/join.awk
12329
@c file eg/lib/join.awk
12256
# join.awk --- join an array into a string
12330
# join.awk --- join an array into a string
12257
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
12331
# Arnold Robbins, arnold@@gnu.org, Public Domain
12258
# May 1993
12332
# May 1993
12259
12333
12260
function join(array, start, end, sep,    result, i)
12334
function join(array, start, end, sep,    result, i)
Lines 12329-12335 Link Here
12329
@c file eg/lib/mktime.awk
12403
@c file eg/lib/mktime.awk
12330
# mktime.awk --- convert a canonical date representation
12404
# mktime.awk --- convert a canonical date representation
12331
#                into a timestamp
12405
#                into a timestamp
12332
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
12406
# Arnold Robbins, arnold@@gnu.org, Public Domain
12333
# May 1993
12407
# May 1993
12334
12408
12335
BEGIN    \
12409
BEGIN    \
Lines 12624-12630 Link Here
12624
@c @group
12698
@c @group
12625
@c file eg/lib/gettime.awk
12699
@c file eg/lib/gettime.awk
12626
# gettimeofday --- get the time of day in a usable format
12700
# gettimeofday --- get the time of day in a usable format
12627
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain, May 1993
12701
# Arnold Robbins, arnold@@gnu.org, Public Domain, May 1993
12628
#
12702
#
12629
# Returns a string in the format of output of date(1)
12703
# Returns a string in the format of output of date(1)
12630
# Populates the array argument time with individual values:
12704
# Populates the array argument time with individual values:
Lines 12732-12738 Link Here
12732
# that each take the name of the file being started or
12806
# that each take the name of the file being started or
12733
# finished, respectively.
12807
# finished, respectively.
12734
#
12808
#
12735
# Arnold Robbins, arnold@@gnu.ai.mit.edu, January 1992
12809
# Arnold Robbins, arnold@@gnu.org, January 1992
12736
# Public Domain
12810
# Public Domain
12737
12811
12738
FILENAME != _oldfilename \
12812
FILENAME != _oldfilename \
Lines 12784-12790 Link Here
12784
#
12858
#
12785
# user supplies beginfile() and endfile() functions
12859
# user supplies beginfile() and endfile() functions
12786
#
12860
#
12787
# Arnold Robbins, arnold@@gnu.ai.mit.edu. November 1992
12861
# Arnold Robbins, arnold@@gnu.org, November 1992
12788
# Public Domain
12862
# Public Domain
12789
12863
12790
FNR == 1 @{
12864
FNR == 1 @{
Lines 12929-12935 Link Here
12929
@c file eg/lib/getopt.awk
13003
@c file eg/lib/getopt.awk
12930
# getopt --- do C library getopt(3) function in awk
13004
# getopt --- do C library getopt(3) function in awk
12931
#
13005
#
12932
# arnold@@gnu.ai.mit.edu
13006
# arnold@@gnu.org
12933
# Public domain
13007
# Public domain
12934
#
13008
#
12935
# Initial version: March, 1991
13009
# Initial version: March, 1991
Lines 13206-13212 Link Here
13206
 * Generate a printable version of the password database
13280
 * Generate a printable version of the password database
13207
 *
13281
 *
13208
 * Arnold Robbins
13282
 * Arnold Robbins
13209
 * arnold@@gnu.ai.mit.edu
13283
 * arnold@@gnu.org
13210
 * May 1993
13284
 * May 1993
13211
 * Public Domain
13285
 * Public Domain
13212
 */
13286
 */
Lines 13289-13295 Link Here
13289
@c file eg/lib/passwdawk.in
13363
@c file eg/lib/passwdawk.in
13290
@group
13364
@group
13291
# passwd.awk --- access password file information
13365
# passwd.awk --- access password file information
13292
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
13366
# Arnold Robbins, arnold@@gnu.org, Public Domain
13293
# May 1993
13367
# May 1993
13294
13368
13295
BEGIN @{
13369
BEGIN @{
Lines 13477-13483 Link Here
13477
 *
13551
 *
13478
 * Generate a printable version of the group database
13552
 * Generate a printable version of the group database
13479
 *
13553
 *
13480
 * Arnold Robbins, arnold@@gnu.ai.mit.edu
13554
 * Arnold Robbins, arnold@@gnu.org
13481
 * May 1993
13555
 * May 1993
13482
 * Public Domain
13556
 * Public Domain
13483
 */
13557
 */
Lines 13558-13564 Link Here
13558
@group
13632
@group
13559
@c file eg/lib/groupawk.in
13633
@c file eg/lib/groupawk.in
13560
# group.awk --- functions for dealing with the group file
13634
# group.awk --- functions for dealing with the group file
13561
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
13635
# Arnold Robbins, arnold@@gnu.org, Public Domain
13562
# May 1993
13636
# May 1993
13563
13637
13564
BEGIN    \
13638
BEGIN    \
Lines 13725-13731 Link Here
13725
function getgrent()
13799
function getgrent()
13726
@{
13800
@{
13727
    _gr_init()
13801
    _gr_init()
13728
    if (++gr_count in _gr_bycount)
13802
    if (++_gr_count in _gr_bycount)
13729
        return _gr_bycount[_gr_count]
13803
        return _gr_bycount[_gr_count]
13730
    return ""
13804
    return ""
13731
@}
13805
@}
Lines 13947-13953 Link Here
13947
@c @group
14021
@c @group
13948
@c file eg/prog/cut.awk
14022
@c file eg/prog/cut.awk
13949
# cut.awk --- implement cut in awk
14023
# cut.awk --- implement cut in awk
13950
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
14024
# Arnold Robbins, arnold@@gnu.org, Public Domain
13951
# May 1993
14025
# May 1993
13952
14026
13953
# Options:
14027
# Options:
Lines 14275-14281 Link Here
14275
@c @group
14349
@c @group
14276
@c file eg/prog/egrep.awk
14350
@c file eg/prog/egrep.awk
14277
# egrep.awk --- simulate egrep in awk
14351
# egrep.awk --- simulate egrep in awk
14278
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
14352
# Arnold Robbins, arnold@@gnu.org, Public Domain
14279
# May 1993
14353
# May 1993
14280
14354
14281
# Options:
14355
# Options:
Lines 14558-14564 Link Here
14558
@c @group
14632
@c @group
14559
@c file eg/prog/id.awk
14633
@c file eg/prog/id.awk
14560
# id.awk --- implement id in awk
14634
# id.awk --- implement id in awk
14561
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
14635
# Arnold Robbins, arnold@@gnu.org, Public Domain
14562
# May 1993
14636
# May 1993
14563
14637
14564
# output is:
14638
# output is:
Lines 14670-14676 Link Here
14670
@c @group
14744
@c @group
14671
@c file eg/prog/split.awk
14745
@c file eg/prog/split.awk
14672
# split.awk --- do split in awk
14746
# split.awk --- do split in awk
14673
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
14747
# Arnold Robbins, arnold@@gnu.org, Public Domain
14674
# May 1993
14748
# May 1993
14675
14749
14676
# usage: split [-num] [file] [outname]
14750
# usage: split [-num] [file] [outname]
Lines 14798-14804 Link Here
14798
@group
14872
@group
14799
@c file eg/prog/tee.awk
14873
@c file eg/prog/tee.awk
14800
# tee.awk --- tee in awk
14874
# tee.awk --- tee in awk
14801
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
14875
# Arnold Robbins, arnold@@gnu.org, Public Domain
14802
# May 1993
14876
# May 1993
14803
# Revised December 1995
14877
# Revised December 1995
14804
@end group
14878
@end group
Lines 14961-14967 Link Here
14961
@c @group
15035
@c @group
14962
@c file eg/prog/uniq.awk
15036
@c file eg/prog/uniq.awk
14963
# uniq.awk --- do uniq in awk
15037
# uniq.awk --- do uniq in awk
14964
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
15038
# Arnold Robbins, arnold@@gnu.org, Public Domain
14965
# May 1993
15039
# May 1993
14966
15040
14967
@group
15041
@group
Lines 15197-15203 Link Here
15197
@c @group
15271
@c @group
15198
@c file eg/prog/wc.awk
15272
@c file eg/prog/wc.awk
15199
# wc.awk --- count lines, words, characters
15273
# wc.awk --- count lines, words, characters
15200
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
15274
# Arnold Robbins, arnold@@gnu.org, Public Domain
15201
# May 1993
15275
# May 1993
15202
15276
15203
# Options:
15277
# Options:
Lines 15354-15360 Link Here
15354
@group
15428
@group
15355
@c file eg/prog/dupword.awk
15429
@c file eg/prog/dupword.awk
15356
# dupword --- find duplicate words in text
15430
# dupword --- find duplicate words in text
15357
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
15431
# Arnold Robbins, arnold@@gnu.org, Public Domain
15358
# December 1991
15432
# December 1991
15359
15433
15360
@{
15434
@{
Lines 15398-15404 Link Here
15398
@c @group
15472
@c @group
15399
@c file eg/prog/alarm.awk
15473
@c file eg/prog/alarm.awk
15400
# alarm --- set an alarm
15474
# alarm --- set an alarm
15401
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
15475
# Arnold Robbins, arnold@@gnu.org, Public Domain
15402
# May 1993
15476
# May 1993
15403
15477
15404
# usage: alarm time [ "message" [ count [ delay ] ] ]
15478
# usage: alarm time [ "message" [ count [ delay ] ] ]
Lines 15585-15591 Link Here
15585
@c @group
15659
@c @group
15586
@c file eg/prog/translate.awk
15660
@c file eg/prog/translate.awk
15587
# translate --- do tr like stuff
15661
# translate --- do tr like stuff
15588
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
15662
# Arnold Robbins, arnold@@gnu.org, Public Domain
15589
# August 1989
15663
# August 1989
15590
15664
15591
# bugs: does not handle things like: tr A-Z a-z, it has
15665
# bugs: does not handle things like: tr A-Z a-z, it has
Lines 15703-15709 Link Here
15703
@c @group
15777
@c @group
15704
@c file eg/prog/labels.awk
15778
@c file eg/prog/labels.awk
15705
# labels.awk
15779
# labels.awk
15706
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
15780
# Arnold Robbins, arnold@@gnu.org, Public Domain
15707
# June 1992
15781
# June 1992
15708
15782
15709
# Program to print labels.  Each label is 5 lines of data
15783
# Program to print labels.  Each label is 5 lines of data
Lines 15919-15925 Link Here
15919
@group
15993
@group
15920
@c file eg/prog/histsort.awk
15994
@c file eg/prog/histsort.awk
15921
# histsort.awk --- compact a shell history file
15995
# histsort.awk --- compact a shell history file
15922
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
15996
# Arnold Robbins, arnold@@gnu.org, Public Domain
15923
# May 1993
15997
# May 1993
15924
15998
15925
# Thanks to Byron Rakitzis for the general idea
15999
# Thanks to Byron Rakitzis for the general idea
Lines 16016-16021 Link Here
16016
@file{extract.awk} to extract the sample
16090
@file{extract.awk} to extract the sample
16017
programs and install many of them in a standard directory, where
16091
programs and install many of them in a standard directory, where
16018
@code{gawk} can find them.
16092
@code{gawk} can find them.
16093
The Texinfo file looks something like this:
16094
16095
@example
16096
@dots{}
16097
This program has a @@code@{BEGIN@} block,
16098
which prints a nice message:
16099
16100
@@example
16101
@@c file examples/messages.awk
16102
BEGIN @@@{ print "Don't panic!" @@@}
16103
@@c end file
16104
@@end example
16105
16106
It also prints some final advice:
16107
16108
@@example
16109
@@c file examples/messages.awk
16110
END @@@{ print "Always avoid bored archeologists!" @@@}
16111
@@c end file
16112
@@end example
16113
@dots{}
16114
@end example
16019
16115
16020
@file{extract.awk} begins by setting @code{IGNORECASE} to one, so that
16116
@file{extract.awk} begins by setting @code{IGNORECASE} to one, so that
16021
mixed upper-case and lower-case letters in the directives won't matter.
16117
mixed upper-case and lower-case letters in the directives won't matter.
Lines 16030-16036 Link Here
16030
@c file eg/prog/extract.awk
16126
@c file eg/prog/extract.awk
16031
# extract.awk --- extract files and run programs
16127
# extract.awk --- extract files and run programs
16032
#                 from texinfo files
16128
#                 from texinfo files
16033
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
16129
# Arnold Robbins, arnold@@gnu.org, Public Domain
16034
# May 1993
16130
# May 1993
16035
16131
16036
BEGIN    @{ IGNORECASE = 1 @}
16132
BEGIN    @{ IGNORECASE = 1 @}
Lines 16080-16085 Link Here
16080
the loop.
16176
the loop.
16081
If the line is an @samp{@@group} or @samp{@@end group} line, then it
16177
If the line is an @samp{@@group} or @samp{@@end group} line, then it
16082
ignores it, and goes on to the next line.
16178
ignores it, and goes on to the next line.
16179
(These Texinfo control lines keep blocks of code together on one page;
16180
unfortunately, @TeX{} isn't always smart enough to do things exactly right,
16181
and we have to give it some advice.)
16083
16182
16084
Most of the work is in the following few lines.  If the line has no @samp{@@}
16183
Most of the work is in the following few lines.  If the line has no @samp{@@}
16085
symbols, it can be printed directly.  Otherwise, each leading @samp{@@} must be
16184
symbols, it can be printed directly.  Otherwise, each leading @samp{@@} must be
Lines 16213-16219 Link Here
16213
# awksed.awk --- do s/foo/bar/g using just print
16312
# awksed.awk --- do s/foo/bar/g using just print
16214
#    Thanks to Michael Brennan for the idea
16313
#    Thanks to Michael Brennan for the idea
16215
16314
16216
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
16315
# Arnold Robbins, arnold@@gnu.org, Public Domain
16217
# August 1995
16316
# August 1995
16218
16317
16219
@group
16318
@group
Lines 16447-16453 Link Here
16447
#! /bin/sh
16546
#! /bin/sh
16448
16547
16449
# igawk --- like gawk but do @@include processing
16548
# igawk --- like gawk but do @@include processing
16450
# Arnold Robbins, arnold@@gnu.ai.mit.edu, Public Domain
16549
# Arnold Robbins, arnold@@gnu.org, Public Domain
16451
# July 1993
16550
# July 1993
16452
16551
16453
if [ "$1" = debug ]
16552
if [ "$1" = debug ]
Lines 18493-18499 Link Here
18493
Boston, MA  02111-1307 USA @*
18592
Boston, MA  02111-1307 USA @*
18494
Phone: +1-617-542-5942 @*
18593
Phone: +1-617-542-5942 @*
18495
Fax (including Japan): +1-617-542-2652 @*
18594
Fax (including Japan): +1-617-542-2652 @*
18496
E-mail: @code{gnu@@prep.ai.mit.edu} @*
18595
E-mail: @code{gnu@@gnu.org} @*
18497
@end quotation
18596
@end quotation
18498
18597
18499
@noindent
18598
@noindent
Lines 18502-18508 Link Here
18502
18601
18503
@item
18602
@item
18504
You can get @code{gawk} by using anonymous @code{ftp} to the Internet host
18603
You can get @code{gawk} by using anonymous @code{ftp} to the Internet host
18505
@code{ftp.gnu.ai.mit.edu}, in the directory @file{/pub/gnu}.
18604
@code{gnudist.gnu.org}, in the directory @file{/gnu/gawk}.
18506
18605
18507
Here is a list of alternate @code{ftp} sites from which you can obtain GNU
18606
Here is a list of alternate @code{ftp} sites from which you can obtain GNU
18508
software.  When a site is listed as ``@var{site}@code{:}@var{directory}'' the
18607
software.  When a site is listed as ``@var{site}@code{:}@var{directory}'' the
Lines 19318-19334 Link Here
19318
19417
19319
@table @asis
19418
@table @asis
19320
@item Internet:
19419
@item Internet:
19321
@samp{bug-gnu-utils@@prep.ai.mit.edu}
19420
@samp{bug-gnu-utils@@gnu.org}
19322
19421
19323
@item UUCP:
19422
@item UUCP:
19324
@samp{uunet!prep.ai.mit.edu!bug-gnu-utils}
19423
@samp{uunet!gnu.org!bug-gnu-utils}
19325
@end table
19424
@end table
19326
19425
19327
Please include the
19426
Please include the
19328
version number of @code{gawk} you are using.  You can get this information
19427
version number of @code{gawk} you are using.  You can get this information
19329
with the command @samp{gawk --version}.
19428
with the command @samp{gawk --version}.
19330
You should send a carbon copy of your mail to Arnold Robbins, who can
19429
You should send a carbon copy of your mail to Arnold Robbins, who can
19331
be reached at @samp{arnold@@gnu.ai.mit.edu}.
19430
be reached at @samp{arnold@@gnu.org}.
19332
19431
19333
@cindex @code{comp.lang.awk}
19432
@cindex @code{comp.lang.awk}
19334
@strong{Important!} Do @emph{not} try to report bugs in @code{gawk} by
19433
@strong{Important!} Do @emph{not} try to report bugs in @code{gawk} by
Lines 19408-19420 Link Here
19408
@item Unix @code{awk}
19507
@item Unix @code{awk}
19409
Brian Kernighan has been able to make his implementation of
19508
Brian Kernighan has been able to make his implementation of
19410
@code{awk} freely available.  You can get it via anonymous @code{ftp}
19509
@code{awk} freely available.  You can get it via anonymous @code{ftp}
19411
to the host @code{@w{netlib.att.com}}.  Change directory to
19510
to the host @code{@w{netlib.bell-labs.com}}.  Change directory to
19412
@file{/netlib/research}. Use ``binary'' or ``image'' mode, and
19511
@file{/netlib/research}. Use ``binary'' or ``image'' mode, and
19413
retrieve @file{awk.bundle.Z}.
19512
retrieve @file{awk.bundle.gz}.
19513
19514
This is a shell archive that has been compressed with the GNU @code{gzip}
19515
utility. It can be uncompressed with the @code{gunzip} utility.
19414
19516
19415
This is a shell archive that has been compressed with the @code{compress}
19517
You can also retrieve this version via the World Wide Web from
19416
utility. It can be uncompressed with either @code{uncompress} or the
19518
@uref{http://cm.bell-labs.com/who/bwk, Brian Kernighan's home page}.
19417
GNU @code{gunzip} utility.
19418
19519
19419
This version requires an ANSI C compiler; GCC (the GNU C compiler)
19520
This version requires an ANSI C compiler; GCC (the GNU C compiler)
19420
works quite nicely.
19521
works quite nicely.
Lines 19496-19502 Link Here
19496
You are free to add any new features you like to @code{gawk}.
19597
You are free to add any new features you like to @code{gawk}.
19497
However, if you want your changes to be incorporated into the @code{gawk}
19598
However, if you want your changes to be incorporated into the @code{gawk}
19498
distribution, there are several steps that you need to take in order to
19599
distribution, there are several steps that you need to take in order to
19499
make it possible for me to include to your changes.
19600
make it possible for me to include your changes.
19500
19601
19501
@enumerate 1
19602
@enumerate 1
19502
@item
19603
@item
Lines 19598-19604 Link Here
19598
Both of these actions are easy to do, and @emph{many} people have done so
19699
Both of these actions are easy to do, and @emph{many} people have done so
19599
already. If you have questions, please contact me
19700
already. If you have questions, please contact me
19600
(@pxref{Bugs, , Reporting Problems and Bugs}),
19701
(@pxref{Bugs, , Reporting Problems and Bugs}),
19601
or @code{gnu@@prep.ai.mit.edu}.
19702
or @code{gnu@@gnu.org}.
19602
19703
19603
@item
19704
@item
19604
Update the documentation.
19705
Update the documentation.
Lines 19718-19724 Link Here
19718
@ifinfo
19819
@ifinfo
19719
Both of these actions are easy to do, and @emph{many} people have done so
19820
Both of these actions are easy to do, and @emph{many} people have done so
19720
already. If you have questions, please contact me, or
19821
already. If you have questions, please contact me, or
19721
@code{gnu@@prep.ai.mit.edu}.
19822
@code{gnu@@gnu.org}.
19722
@end ifinfo
19823
@end ifinfo
19723
@end enumerate
19824
@end enumerate
19724
19825
Lines 19855-19865 Link Here
19855
The GNU version of @code{malloc} could potentially speed up @code{gawk},
19956
The GNU version of @code{malloc} could potentially speed up @code{gawk},
19856
since it relies heavily on the use of dynamic memory allocation.
19957
since it relies heavily on the use of dynamic memory allocation.
19857
19958
19858
@item Use of the @code{rx} regexp library
19859
The @code{rx} regular expression library could potentially speed up
19860
all regexp operations that require knowing the exact location of matches.
19861
This includes record termination, field and array splitting,
19862
and the @code{sub}, @code{gsub}, @code{gensub} and @code{match} functions.
19863
@end table
19959
@end table
19864
19960
19865
@node Improvements,  , Future Extensions, Notes
19961
@node Improvements,  , Future Extensions, Notes
Lines 20006-20012 Link Here
20006
A preprocessor for @code{pic} that reads descriptions of molecules
20102
A preprocessor for @code{pic} that reads descriptions of molecules
20007
and produces @code{pic} input for drawing them.  It was written in @code{awk}
20103
and produces @code{pic} input for drawing them.  It was written in @code{awk}
20008
by Brian Kernighan and Jon Bentley, and is available from
20104
by Brian Kernighan and Jon Bentley, and is available from
20009
@code{@w{netlib@@research.att.com}}.
20105
@email{@w{netlib@@research.bell-labs.com}}.
20010
20106
20011
@item Compound Statement
20107
@item Compound Statement
20012
A series of @code{awk} statements, enclosed in curly braces.  Compound
20108
A series of @code{awk} statements, enclosed in curly braces.  Compound
(-)awk/eval.c (-20 / +56 lines)
Lines 3-9 Link Here
3
 */
3
 */
4
4
5
/* 
5
/* 
6
 * Copyright (C) 1986, 1988, 1989, 1991-1997 the Free Software Foundation, Inc.
6
 * Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
7
 * 
7
 * 
8
 * This file is part of GAWK, the GNU implementation of the
8
 * This file is part of GAWK, the GNU implementation of the
9
 * AWK Programming Language.
9
 * AWK Programming Language.
Lines 25-32 Link Here
25
25
26
#include "awk.h"
26
#include "awk.h"
27
27
28
#include <assert.h>
29
30
extern double pow P((double x, double y));
28
extern double pow P((double x, double y));
31
extern double modf P((double x, double *yp));
29
extern double modf P((double x, double *yp));
32
extern double fmod P((double x, double y));
30
extern double fmod P((double x, double y));
Lines 566-579 Link Here
566
		break;
564
		break;
567
565
568
	case Node_K_next:
566
	case Node_K_next:
567
		if (in_begin_rule)
568
			fatal("`next' cannot be called from a BEGIN rule");
569
		else if (in_end_rule)
570
			fatal("`next' cannot be called from an END rule");
571
569
		if (in_function())
572
		if (in_function())
570
			pop_fcall_stack();
573
			pop_fcall_stack();
574
571
		longjmp(rule_tag, TAG_CONTINUE);
575
		longjmp(rule_tag, TAG_CONTINUE);
572
		break;
576
		break;
573
577
574
	case Node_K_nextfile:
578
	case Node_K_nextfile:
579
		if (in_begin_rule)
580
			fatal("`nextfile' cannot be called from a BEGIN rule");
581
		else if (in_end_rule)
582
			fatal("`nextfile' cannot be called from an END rule");
583
575
		if (in_function())
584
		if (in_function())
576
			pop_fcall_stack();
585
			pop_fcall_stack();
586
577
		do_nextfile();
587
		do_nextfile();
578
		break;
588
		break;
579
589
Lines 759-765 Link Here
759
		register size_t len;
769
		register size_t len;
760
		char *str;
770
		char *str;
761
		register char *dest;
771
		register char *dest;
762
		int count;
772
		int alloc_count, str_count;
773
		int i;
763
774
764
		/*
775
		/*
765
		 * This is an efficiency hack for multiple adjacent string
776
		 * This is an efficiency hack for multiple adjacent string
Lines 773-788 Link Here
773
		/*
784
		/*
774
		 * But first, no arbitrary limits. Count the number of
785
		 * But first, no arbitrary limits. Count the number of
775
		 * nodes and malloc the treelist and strlist arrays.
786
		 * nodes and malloc the treelist and strlist arrays.
776
		 * There will be count + 1 items to concatenate. We
787
		 * There will be alloc_count + 1 items to concatenate. We
777
		 * also leave room for an extra pointer at the end to
788
		 * also leave room for an extra pointer at the end to
778
		 * use as a sentinel.  Thus, start count at 2.
789
		 * use as a sentinel.  Thus, start alloc_count at 2.
779
		 */
790
		 */
780
		save_tree = tree;
791
		save_tree = tree;
781
		for (count = 2; tree && tree->type == Node_concat; tree = tree->lnode)
792
		for (alloc_count = 2; tree && tree->type == Node_concat; tree = tree->lnode)
782
			count++;
793
			alloc_count++;
783
		tree = save_tree;
794
		tree = save_tree;
784
		emalloc(treelist, NODE **, sizeof(NODE *) * count, "tree_eval");
795
		emalloc(treelist, NODE **, sizeof(NODE *) * alloc_count, "tree_eval");
785
		emalloc(strlist, NODE **, sizeof(NODE *) * count, "tree_eval");
796
		emalloc(strlist, NODE **, sizeof(NODE *) * alloc_count, "tree_eval");
786
797
787
		/* Now, here we go. */
798
		/* Now, here we go. */
788
		treep = treelist;
799
		treep = treelist;
Lines 795-809 Link Here
795
		 * Now, evaluate to strings in LIFO order, accumulating
806
		 * Now, evaluate to strings in LIFO order, accumulating
796
		 * the string length, so we can do a single malloc at the
807
		 * the string length, so we can do a single malloc at the
797
		 * end.
808
		 * end.
809
		 *
810
		 * Evaluate the expressions first, then get their
811
		 * lengthes, in case one of the expressions has a
812
		 * side effect that changes one of the others.
813
		 * See test/nasty.awk.
798
		 */
814
		 */
799
		strp = strlist;
815
		strp = strlist;
800
		len = 0;
816
		len = 0;
801
		while (treep >= treelist) {
817
		while (treep >= treelist) {
802
			*strp = force_string(tree_eval(*treep--));
818
			*strp = force_string(tree_eval(*treep--));
803
			len += (*strp)->stlen;
804
			strp++;
819
			strp++;
805
		}
820
		}
806
		*strp = NULL;
821
		*strp = NULL;
822
823
		str_count = strp - strlist;
824
		strp = strlist;
825
		for (i = 0; i < str_count; i++) {
826
			len += (*strp)->stlen;
827
			strp++;
828
		}
807
		emalloc(str, char *, len+2, "tree_eval");
829
		emalloc(str, char *, len+2, "tree_eval");
808
		str[len] = str[len+1] = '\0';	/* for good measure */
830
		str[len] = str[len+1] = '\0';	/* for good measure */
809
		dest = str;
831
		dest = str;
Lines 1397-1402 Link Here
1397
 * r_get_lhs:
1419
 * r_get_lhs:
1398
 * This returns a POINTER to a node pointer. get_lhs(ptr) is the current
1420
 * This returns a POINTER to a node pointer. get_lhs(ptr) is the current
1399
 * value of the var, or where to store the var's new value 
1421
 * value of the var, or where to store the var's new value 
1422
 *
1423
 * For the special variables, don't unref their current value if it's
1424
 * the same as the internal copy; perhaps the current one is used in
1425
 * a concatenation or some other expression somewhere higher up in the
1426
 * call chain.  Ouch.
1400
 */
1427
 */
1401
1428
1402
NODE **
1429
NODE **
Lines 1409-1416 Link Here
1409
1436
1410
	if (assign)
1437
	if (assign)
1411
		*assign = NULL;	/* for safety */
1438
		*assign = NULL;	/* for safety */
1412
	if (ptr->type == Node_param_list)
1439
	if (ptr->type == Node_param_list) {
1440
		if ((ptr->flags & FUNC) != 0)
1441
			fatal("can't use function name `%s' as variable or array", ptr->vname);
1413
		ptr = stack_ptr[ptr->param_cnt];
1442
		ptr = stack_ptr[ptr->param_cnt];
1443
	}
1414
1444
1415
	switch (ptr->type) {
1445
	switch (ptr->type) {
1416
	case Node_var_array:
1446
	case Node_var_array:
Lines 1444-1469 Link Here
1444
		break;
1474
		break;
1445
1475
1446
	case Node_FNR:
1476
	case Node_FNR:
1447
		unref(FNR_node->var_value);
1477
		if (FNR_node->var_value->numbr != FNR) {
1448
		FNR_node->var_value = make_number((AWKNUM) FNR);
1478
			unref(FNR_node->var_value);
1479
			FNR_node->var_value = make_number((AWKNUM) FNR);
1480
		}
1449
		aptr = &(FNR_node->var_value);
1481
		aptr = &(FNR_node->var_value);
1450
		if (assign != NULL)
1482
		if (assign != NULL)
1451
			*assign = set_FNR;
1483
			*assign = set_FNR;
1452
		break;
1484
		break;
1453
1485
1454
	case Node_NR:
1486
	case Node_NR:
1455
		unref(NR_node->var_value);
1487
		if (NR_node->var_value->numbr != NR) {
1456
		NR_node->var_value = make_number((AWKNUM) NR);
1488
			unref(NR_node->var_value);
1489
			NR_node->var_value = make_number((AWKNUM) NR);
1490
		}
1457
		aptr = &(NR_node->var_value);
1491
		aptr = &(NR_node->var_value);
1458
		if (assign != NULL)
1492
		if (assign != NULL)
1459
			*assign = set_NR;
1493
			*assign = set_NR;
1460
		break;
1494
		break;
1461
1495
1462
	case Node_NF:
1496
	case Node_NF:
1463
		if (NF == -1)
1497
		if (NF == -1 || NF_node->var_value->numbr != NF) {
1464
			(void) get_field(HUGE-1, assign); /* parse record */
1498
			if (NF == -1)
1465
		unref(NF_node->var_value);
1499
				(void) get_field(HUGE-1, assign); /* parse record */
1466
		NF_node->var_value = make_number((AWKNUM) NF);
1500
			unref(NF_node->var_value);
1501
			NF_node->var_value = make_number((AWKNUM) NF);
1502
		}
1467
		aptr = &(NF_node->var_value);
1503
		aptr = &(NF_node->var_value);
1468
		if (assign != NULL)
1504
		if (assign != NULL)
1469
			*assign = set_NF;
1505
			*assign = set_NF;
(-)awk/field.c (-27 / +39 lines)
Lines 3-9 Link Here
3
 */
3
 */
4
4
5
/* 
5
/* 
6
 * Copyright (C) 1986, 1988, 1989, 1991-1997 the Free Software Foundation, Inc.
6
 * Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
7
 * 
7
 * 
8
 * This file is part of GAWK, the GNU implementation of the
8
 * This file is part of GAWK, the GNU implementation of the
9
 * AWK Programming Language.
9
 * AWK Programming Language.
Lines 24-30 Link Here
24
 */
24
 */
25
25
26
#include "awk.h"
26
#include "awk.h"
27
#include <assert.h>
28
27
29
typedef void (* Setfunc) P((long, char *, long, NODE *));
28
typedef void (* Setfunc) P((long, char *, long, NODE *));
30
29
Lines 63-68 Link Here
63
Regexp *FS_regexp = NULL;
62
Regexp *FS_regexp = NULL;
64
static NODE *Null_field = NULL;
63
static NODE *Null_field = NULL;
65
64
65
/* using_FIELDWIDTHS --- static function, macro to avoid overhead */
66
#define using_FIELDWIDTHS()	(parse_field == fw_parse_field)
67
66
/* init_fields --- set up the fields array to start with */
68
/* init_fields --- set up the fields array to start with */
67
69
68
void
70
void
Lines 140-146 Link Here
140
	char *ops;
142
	char *ops;
141
	register char *cops;
143
	register char *cops;
142
	long i;
144
	long i;
143
	char *f0start, *f0end;
144
145
145
	assert(NF != -1);
146
	assert(NF != -1);
146
147
Lines 184-198 Link Here
184
	 * any fields that still point into it, and have them point
185
	 * any fields that still point into it, and have them point
185
	 * into the new field zero.
186
	 * into the new field zero.
186
	 */
187
	 */
187
	f0start = fields_arr[0]->stptr;
188
	f0end = fields_arr[0]->stptr + fields_arr[0]->stlen;
189
	for (cops = ops, i = 1; i <= NF; i++) {
188
	for (cops = ops, i = 1; i <= NF; i++) {
190
		char *field_data = fields_arr[i]->stptr;
189
		if (fields_arr[i]->stlen > 0) {
191
190
 		        NODE *n;
192
		if (fields_arr[i]->stlen > 0
191
		        getnode(n);
193
		    && f0start <= field_data && field_data < f0end)
192
194
			fields_arr[i]->stptr = cops;
193
			if ((fields_arr[i]->flags & FIELD) == 0) {
194
				*n = *Null_field;
195
				n->stlen = fields_arr[i]->stlen;
196
				if ((fields_arr[i]->flags & (NUM|NUMBER)) != 0) {
197
					n->flags |= (fields_arr[i]->flags & (NUM|NUMBER));
198
					n->numbr = fields_arr[i]->numbr;
199
				}
200
			} else {
201
				*n = *(fields_arr[i]);
202
				n->flags &= ~(MALLOC|TEMP|PERM|STRING);
203
			}
195
204
205
			n->stptr = cops;
206
			unref(fields_arr[i]);
207
			fields_arr[i] = n;
208
		}
196
		cops += fields_arr[i]->stlen + ofslen;
209
		cops += fields_arr[i]->stlen + ofslen;
197
	}
210
	}
198
211
Lines 751-757 Link Here
751
	arr->type = Node_var_array;
764
	arr->type = Node_var_array;
752
	assoc_clear(arr);
765
	assoc_clear(arr);
753
766
754
	if (sep->re_flags & FS_DFLT) {
767
	if ((sep->re_flags & FS_DFLT) != 0 && ! using_FIELDWIDTHS()) {
755
		parseit = parse_field;
768
		parseit = parse_field;
756
		fs = force_string(FS_node->var_value);
769
		fs = force_string(FS_node->var_value);
757
		rp = FS_regexp;
770
		rp = FS_regexp;
Lines 851-870 Link Here
851
	if (fields_arr != NULL)
864
	if (fields_arr != NULL)
852
		(void) get_field(HUGE - 1, 0);
865
		(void) get_field(HUGE - 1, 0);
853
866
854
	if (save_fs && cmp_nodes(FS_node->var_value, save_fs) == 0
867
	if (! (save_fs && cmp_nodes(FS_node->var_value, save_fs) == 0
855
	 && save_rs && cmp_nodes(RS_node->var_value, save_rs) == 0)
868
		&& save_rs && cmp_nodes(RS_node->var_value, save_rs) == 0)) {
856
		return;
869
		unref(save_fs);
857
	unref(save_fs);
870
		save_fs = dupnode(FS_node->var_value);
858
	save_fs = dupnode(FS_node->var_value);
871
		unref(save_rs);
859
	unref(save_rs);
872
		save_rs = dupnode(RS_node->var_value);
860
	save_rs = dupnode(RS_node->var_value);
873
		resave_fs = TRUE;
861
	resave_fs = TRUE;
874
		if (FS_regexp) {
862
  	buf[0] = '\0';
875
			refree(FS_regexp);
863
  	default_FS = FALSE;
876
			FS_regexp = NULL;
864
  	if (FS_regexp) {
877
		}
865
		refree(FS_regexp);
866
		FS_regexp = NULL;
867
	}
878
	}
879
	buf[0] = '\0';
880
	default_FS = FALSE;
868
	fs = force_string(FS_node->var_value);
881
	fs = force_string(FS_node->var_value);
869
	if (! do_traditional && fs->stlen == 0)
882
	if (! do_traditional && fs->stlen == 0)
870
		parse_field = null_parse_field;
883
		parse_field = null_parse_field;
Lines 887-893 Link Here
887
		if (fs->stptr[0] == ' ' && fs->stlen == 1)
900
		if (fs->stptr[0] == ' ' && fs->stlen == 1)
888
			default_FS = TRUE;
901
			default_FS = TRUE;
889
		else if (fs->stptr[0] != ' ' && fs->stlen == 1) {
902
		else if (fs->stptr[0] != ' ' && fs->stlen == 1) {
890
			if (! IGNORECASE)
903
			if (! IGNORECASE || ! isalpha(fs->stptr[0]))
891
				parse_field = sc_parse_field;
904
				parse_field = sc_parse_field;
892
			else if (fs->stptr[0] == '\\')
905
			else if (fs->stptr[0] == '\\')
893
				/* yet another special case */
906
				/* yet another special case */
Lines 910-915 Link Here
910
int
923
int
911
using_fieldwidths()
924
using_fieldwidths()
912
{
925
{
913
	return 	parse_field == fw_parse_field;
926
	return using_FIELDWIDTHS();
914
}
927
}
915
(-)awk/gawkmisc.c (-1 / +1 lines)
Lines 3-9 Link Here
3
 */
3
 */
4
4
5
/* 
5
/* 
6
 * Copyright (C) 1986, 1988, 1989, 1991 - 97 the Free Software Foundation, Inc.
6
 * Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
7
 * 
7
 * 
8
 * This file is part of GAWK, the GNU implementation of the
8
 * This file is part of GAWK, the GNU implementation of the
9
 * AWK Programming Language.
9
 * AWK Programming Language.
(-)awk/io.c (-43 / +60 lines)
Lines 3-9 Link Here
3
 */
3
 */
4
4
5
/* 
5
/* 
6
 * Copyright (C) 1986, 1988, 1989, 1991-1997 the Free Software Foundation, Inc.
6
 * Copyright (C) 1976, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
7
 * 
7
 * 
8
 * This file is part of GAWK, the GNU implementation of the
8
 * This file is part of GAWK, the GNU implementation of the
9
 * AWK Programming Language.
9
 * AWK Programming Language.
Lines 49-56 Link Here
49
#define O_ACCMODE	(O_RDONLY|O_WRONLY|O_RDWR)
49
#define O_ACCMODE	(O_RDONLY|O_WRONLY|O_RDWR)
50
#endif
50
#endif
51
51
52
#include <assert.h>
53
54
#if ! defined(S_ISREG) && defined(S_IFREG)
52
#if ! defined(S_ISREG) && defined(S_IFREG)
55
#define	S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
53
#define	S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
56
#endif
54
#endif
Lines 95-113 Link Here
95
static int pidopen P((IOBUF *iop, const char *name, const char *mode));
93
static int pidopen P((IOBUF *iop, const char *name, const char *mode));
96
static int useropen P((IOBUF *iop, const char *name, const char *mode));
94
static int useropen P((IOBUF *iop, const char *name, const char *mode));
97
95
98
#if defined (MSDOS) && !defined (__GO32__)
96
#if defined (HAVE_POPEN_H)
99
#include "popen.h"
97
#include "popen.h"
100
#define popen(c, m)	os_popen(c, m)
101
#define pclose(f)	os_pclose(f)
102
#else
103
#if defined (OS2)	/* OS/2, but not family mode */
104
#if defined (_MSC_VER)
105
#define popen(c, m)	_popen(c, m)
106
#define pclose(f)	_pclose(f)
107
#endif
108
#else
109
extern FILE	*popen();
110
#endif
111
#endif
98
#endif
112
99
113
static struct redirect *red_head = NULL;
100
static struct redirect *red_head = NULL;
Lines 125-130 Link Here
125
112
126
static jmp_buf filebuf;		/* for do_nextfile() */
113
static jmp_buf filebuf;		/* for do_nextfile() */
127
114
115
#ifdef VMS
116
/* File pointers have an extra level of indirection, and there are cases where
117
   `stdin' can be null.  That can crash gawk if fileno() is used as-is.  */
118
static int vmsrtl_fileno P((FILE *));
119
static int vmsrtl_fileno(fp) FILE *fp; { return fileno(fp); }
120
#undef fileno
121
#define fileno(FP) (((FP) && *(FP)) ? vmsrtl_fileno(FP) : -1)
122
#endif	/* VMS */
123
128
/* do_nextfile --- implement gawk "nextfile" extension */
124
/* do_nextfile --- implement gawk "nextfile" extension */
129
125
130
void
126
void
Lines 487-495 Link Here
487
			/* too many files open -- close one and try again */
483
			/* too many files open -- close one and try again */
488
			if (errno == EMFILE || errno == ENFILE)
484
			if (errno == EMFILE || errno == ENFILE)
489
				close_one();
485
				close_one();
490
#ifdef HAVE_MMAP
486
#if defined __MINGW32__ || defined HAVE_MMAP
491
			/* this works for solaris 2.5, not sunos */
487
			/* this works for solaris 2.5, not sunos */
492
			else if (errno == 0)	/* HACK! */
488
			/* it is also needed for MINGW32 */
489
			else if (errno == 0)    /* HACK! */
493
				close_one();
490
				close_one();
494
#endif
491
#endif
495
			else {
492
			else {
Lines 573-596 Link Here
573
570
574
	tmp = force_string(tree_eval(tree->subnode));
571
	tmp = force_string(tree_eval(tree->subnode));
575
572
576
	/* icky special case: close(FILENAME) called. */
577
	if (tree->subnode == FILENAME_node
578
	    || (tmp->stlen == FILENAME_node->var_value->stlen
579
		&& STREQN(tmp->stptr, FILENAME_node->var_value->stptr, tmp->stlen))) {
580
		(void) nextfile(TRUE);
581
		free_temp(tmp);
582
		return tmp_number((AWKNUM) 0.0);
583
	}
584
585
	for (rp = red_head; rp != NULL; rp = rp->next) {
573
	for (rp = red_head; rp != NULL; rp = rp->next) {
586
		if (strlen(rp->value) == tmp->stlen
574
		if (strlen(rp->value) == tmp->stlen
587
		    && STREQN(rp->value, tmp->stptr, tmp->stlen))
575
		    && STREQN(rp->value, tmp->stptr, tmp->stlen))
588
			break;
576
			break;
589
	}
577
	}
578
590
	if (rp == NULL) {	/* no match */
579
	if (rp == NULL) {	/* no match */
591
		if (do_lint)
580
		/* icky special case: close(FILENAME) called. */
581
		if (tree->subnode == FILENAME_node
582
		    || (tmp->stlen == FILENAME_node->var_value->stlen
583
			&& STREQN(tmp->stptr, FILENAME_node->var_value->stptr, tmp->stlen))) {
584
			(void) nextfile(TRUE);
585
		} else if (do_lint)
592
			warning("close: `%.*s' is not an open file or pipe",
586
			warning("close: `%.*s' is not an open file or pipe",
593
				tmp->stlen, tmp->stptr);
587
				tmp->stlen, tmp->stptr);
588
594
		free_temp(tmp);
589
		free_temp(tmp);
595
		return tmp_number((AWKNUM) 0.0);
590
		return tmp_number((AWKNUM) 0.0);
596
	}
591
	}
Lines 888-898 Link Here
888
	int i;
883
	int i;
889
884
890
	if (name[6] == 'g')
885
	if (name[6] == 'g')
891
		sprintf(tbuf, "%d\n", getpgrp(getpgrp_arg()));
886
		sprintf(tbuf, "%d\n", (int) getpgrp(getpgrp_arg()));
892
	else if (name[6] == 'i')
887
	else if (name[6] == 'i')
893
		sprintf(tbuf, "%d\n", getpid());
888
		sprintf(tbuf, "%d\n", (int) getpid());
894
	else
889
	else
895
		sprintf(tbuf, "%d\n", getppid());
890
		sprintf(tbuf, "%d\n", (int) getppid());
896
	i = strlen(tbuf);
891
	i = strlen(tbuf);
897
	spec_setup(iop, i, TRUE);
892
	spec_setup(iop, i, TRUE);
898
	strcpy(iop->buf, tbuf);
893
	strcpy(iop->buf, tbuf);
Lines 923-929 Link Here
923
	int ngroups;
918
	int ngroups;
924
#endif
919
#endif
925
920
926
	sprintf(tbuf, "%d %d %d %d", getuid(), geteuid(), getgid(), getegid());
921
	sprintf(tbuf, "%d %d %d %d", (int) getuid(), (int) geteuid(), (int) getgid(), (int) getegid());
927
922
928
	cp = tbuf + strlen(tbuf);
923
	cp = tbuf + strlen(tbuf);
929
#if defined(NGROUPS_MAX) && NGROUPS_MAX > 0
924
#if defined(NGROUPS_MAX) && NGROUPS_MAX > 0
Lines 1008-1014 Link Here
1008
	if (openfd == INVALID_HANDLE)
1003
	if (openfd == INVALID_HANDLE)
1009
		openfd = open(name, flag, 0666);
1004
		openfd = open(name, flag, 0666);
1010
	if (openfd != INVALID_HANDLE && fstat(openfd, &buf) > 0) 
1005
	if (openfd != INVALID_HANDLE && fstat(openfd, &buf) > 0) 
1011
		if ((buf.st_mode & S_IFMT) == S_IFDIR)
1006
		if (S_ISDIR(buf.st_mode))
1012
			fatal("file `%s' is a directory", name);
1007
			fatal("file `%s' is a directory", name);
1013
	return iop_alloc(openfd, name, iop);
1008
	return iop_alloc(openfd, name, iop);
1014
}
1009
}
Lines 1120-1126 Link Here
1120
 * except if popen() provides real pipes too
1115
 * except if popen() provides real pipes too
1121
 */
1116
 */
1122
1117
1123
#if defined(VMS) || defined(OS2) || defined (MSDOS)
1118
#if defined(VMS) || defined(OS2) || defined (MSDOS) || defined(WIN32)
1124
1119
1125
/* gawk_popen --- open an IOBUF on a child process */
1120
/* gawk_popen --- open an IOBUF on a child process */
1126
1121
Lines 1135-1141 Link Here
1135
		return NULL;
1130
		return NULL;
1136
	rp->iop = iop_alloc(fileno(current), cmd, NULL);
1131
	rp->iop = iop_alloc(fileno(current), cmd, NULL);
1137
	if (rp->iop == NULL) {
1132
	if (rp->iop == NULL) {
1138
		(void) fclose(current);
1133
		(void) pclose(current);
1139
		current = NULL;
1134
		current = NULL;
1140
	}
1135
	}
1141
	rp->ifp = current;
1136
	rp->ifp = current;
Lines 1434-1440 Link Here
1434
	iop->name = name;
1429
	iop->name = name;
1435
	iop->getrec = get_a_record;
1430
	iop->getrec = get_a_record;
1436
#ifdef HAVE_MMAP
1431
#ifdef HAVE_MMAP
1437
	if (S_ISREG(sbuf.st_mode) && sbuf.st_size > 0) {
1432
	/* Use mmap only for regular files with positive sizes.
1433
	   The size must fit into size_t, so that mmap works correctly.
1434
	   Also, it must fit into int, so that iop->cnt won't overflow.  */
1435
	if (S_ISREG(sbuf.st_mode) && sbuf.st_size > 0
1436
	    && sbuf.st_size == (size_t) sbuf.st_size
1437
	    && sbuf.st_size == (int) sbuf.st_size) {
1438
		register char *cp;
1438
		register char *cp;
1439
1439
1440
		iop->buf = iop->off = mmap((caddr_t) 0, sbuf.st_size,
1440
		iop->buf = iop->off = mmap((caddr_t) 0, sbuf.st_size,
Lines 1535-1541 Link Here
1535
		return EOF;
1535
		return EOF;
1536
	}
1536
	}
1537
1537
1538
	if (grRS == FALSE)	/* special case:  RS == "" */
1538
	if (RS_is_null)	/* special case:  RS == "" */
1539
		rs = '\n';
1539
		rs = '\n';
1540
	else
1540
	else
1541
		rs = (char) grRS;
1541
		rs = (char) grRS;
Lines 1648-1654 Link Here
1648
		 */
1648
		 */
1649
		if (! do_traditional && RSre != NULL)	/* regexp */
1649
		if (! do_traditional && RSre != NULL)	/* regexp */
1650
			rsre = RSre;
1650
			rsre = RSre;
1651
		else if (grRS == FALSE)		/* RS = "" */
1651
		else if (RS_is_null)		/* RS = "" */
1652
			rsre = RS_null_re;
1652
			rsre = RS_null_re;
1653
		else
1653
		else
1654
			rsre = NULL;
1654
			rsre = NULL;
Lines 1675-1680 Link Here
1675
			/* cases 1 and 2 are simple, just keep going */
1675
			/* cases 1 and 2 are simple, just keep going */
1676
			if (research(rsre, start, 0, iop->end - start, TRUE) == -1
1676
			if (research(rsre, start, 0, iop->end - start, TRUE) == -1
1677
			    || RESTART(rsre, start) == REEND(rsre, start)) {
1677
			    || RESTART(rsre, start) == REEND(rsre, start)) {
1678
				/*
1679
				 * Leading newlines at the beginning of the file
1680
				 * should be ignored. Whew!
1681
				 */
1682
				if (RS_is_null && *start == '\n') {
1683
					/*
1684
					 * have to catch the case of a
1685
					 * single newline at the front of
1686
					 * the record, which the regex
1687
					 * doesn't. gurr.
1688
					 */
1689
					while (*start == '\n' && start < iop->end)
1690
						start++;
1691
					goto again;
1692
				}
1678
				bp = iop->end;
1693
				bp = iop->end;
1679
				continue;
1694
				continue;
1680
			}
1695
			}
Lines 1690-1697 Link Here
1690
			/*
1705
			/*
1691
			 * Leading newlines at the beginning of the file
1706
			 * Leading newlines at the beginning of the file
1692
			 * should be ignored. Whew!
1707
			 * should be ignored. Whew!
1708
			 *
1709
			 * Is this code ever executed?
1693
			 */
1710
			 */
1694
			if (grRS == FALSE && RESTART(rsre, start) == 0) {
1711
			if (RS_is_null && RESTART(rsre, start) == 0) {
1695
				start += REEND(rsre, start);
1712
				start += REEND(rsre, start);
1696
				goto again;
1713
				goto again;
1697
			}
1714
			}
Lines 1737-1743 Link Here
1737
			bstart = bp;
1754
			bstart = bp;
1738
		}
1755
		}
1739
		*bp = '\0';
1756
		*bp = '\0';
1740
	} else if (grRS == FALSE && iop->cnt == EOF) {
1757
	} else if (RS_is_null && iop->cnt == EOF) {
1741
		/*
1758
		/*
1742
		 * special case, delete trailing newlines,
1759
		 * special case, delete trailing newlines,
1743
		 * should never be more than one.
1760
		 * should never be more than one.
Lines 1811-1817 Link Here
1811
		return EOF;
1828
		return EOF;
1812
	}
1829
	}
1813
1830
1814
	if (grRS == FALSE)	/* special case:  RS == "" */
1831
	if (RS_is_null)	/* special case:  RS == "" */
1815
		rs = '\n';
1832
		rs = '\n';
1816
	else
1833
	else
1817
		rs = (char) grRS;
1834
		rs = (char) grRS;
Lines 1821-1827 Link Here
1821
		rs = casetable[rs];
1838
		rs = casetable[rs];
1822
1839
1823
	/* if RS = "", skip leading newlines at the front of the file */
1840
	/* if RS = "", skip leading newlines at the front of the file */
1824
	if (grRS == FALSE && iop->off == iop->buf) {
1841
	if (RS_is_null && iop->off == iop->buf) {
1825
		for (bp = iop->off; *bp == '\n'; bp++)
1842
		for (bp = iop->off; *bp == '\n'; bp++)
1826
			continue;
1843
			continue;
1827
1844
Lines 1835-1841 Link Here
1835
	 */
1852
	 */
1836
	if (! do_traditional && RSre != NULL)	/* regexp */
1853
	if (! do_traditional && RSre != NULL)	/* regexp */
1837
		rsre = RSre;
1854
		rsre = RSre;
1838
	else if (grRS == FALSE)		/* RS = "" */
1855
	else if (RS_is_null)		/* RS = "" */
1839
		rsre = RS_null_re;
1856
		rsre = RS_null_re;
1840
	else
1857
	else
1841
		rsre = NULL;
1858
		rsre = NULL;
Lines 1862-1868 Link Here
1862
			iop->off = iop->end;	/* all done with the record */
1879
			iop->off = iop->end;	/* all done with the record */
1863
			set_RT_to_null();
1880
			set_RT_to_null();
1864
			/* special case, don't allow trailing newlines */
1881
			/* special case, don't allow trailing newlines */
1865
			if (grRS == FALSE && *(iop->end - 1) == '\n')
1882
			if (RS_is_null && *(iop->end - 1) == '\n')
1866
				return iop->end - start - 1;
1883
				return iop->end - start - 1;
1867
			else
1884
			else
1868
				return iop->end - start;
1885
				return iop->end - start;
(-)awk/main.c (-4 / +4 lines)
Lines 3-9 Link Here
3
 */
3
 */
4
4
5
/* 
5
/* 
6
 * Copyright (C) 1986, 1988, 1989, 1991-1997 the Free Software Foundation, Inc.
6
 * Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
7
 * 
7
 * 
8
 * This file is part of GAWK, the GNU implementation of the
8
 * This file is part of GAWK, the GNU implementation of the
9
 * AWK Programming Language.
9
 * AWK Programming Language.
Lines 439-446 Link Here
439
	fputs("\t-W traditional\t\t--traditional\n", fp);
439
	fputs("\t-W traditional\t\t--traditional\n", fp);
440
	fputs("\t-W usage\t\t--usage\n", fp);
440
	fputs("\t-W usage\t\t--usage\n", fp);
441
	fputs("\t-W version\t\t--version\n", fp);
441
	fputs("\t-W version\t\t--version\n", fp);
442
	fputs("\nReport bugs to bug-gnu-utils@prep.ai.mit.edu,\n", fp);
442
	fputs("\nReport bugs to bug-gnu-utils@gnu.org,\n", fp);
443
	fputs("with a Cc: to arnold@gnu.ai.mit.edu\n", fp);
443
	fputs("with a Cc: to arnold@gnu.org\n", fp);
444
	exit(exitval);
444
	exit(exitval);
445
}
445
}
446
446
Lines 450-456 Link Here
450
copyleft()
450
copyleft()
451
{
451
{
452
	static char blurb_part1[] =
452
	static char blurb_part1[] =
453
"Copyright (C) 1989, 1991-1997 Free Software Foundation.\n\
453
"Copyright (C) 1989, 1991-1999 Free Software Foundation.\n\
454
\n\
454
\n\
455
This program is free software; you can redistribute it and/or modify\n\
455
This program is free software; you can redistribute it and/or modify\n\
456
it under the terms of the GNU General Public License as published by\n\
456
it under the terms of the GNU General Public License as published by\n\
(-)awk/msg.c (-1 / +1 lines)
Lines 3-9 Link Here
3
 */
3
 */
4
4
5
/* 
5
/* 
6
 * Copyright (C) 1986, 1988, 1989, 1991-1997 the Free Software Foundation, Inc.
6
 * Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
7
 * 
7
 * 
8
 * This file is part of GAWK, the GNU implementation of the
8
 * This file is part of GAWK, the GNU implementation of the
9
 * AWK Programming Language.
9
 * AWK Programming Language.
(-)awk/node.c (-15 / +16 lines)
Lines 3-9 Link Here
3
 */
3
 */
4
4
5
/* 
5
/* 
6
 * Copyright (C) 1986, 1988, 1989, 1991-1997 the Free Software Foundation, Inc.
6
 * Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
7
 * 
7
 * 
8
 * This file is part of GAWK, the GNU implementation of the
8
 * This file is part of GAWK, the GNU implementation of the
9
 * AWK Programming Language.
9
 * AWK Programming Language.
Lines 36-41 Link Here
36
	char save;
36
	char save;
37
	char *ptr;
37
	char *ptr;
38
	unsigned int newflags;
38
	unsigned int newflags;
39
	extern double strtod();
39
40
40
#ifdef DEBUG
41
#ifdef DEBUG
41
	if (n == NULL)
42
	if (n == NULL)
Lines 140-146 Link Here
140
	/* not an integral value, or out of range */
141
	/* not an integral value, or out of range */
141
	if ((val = double_to_int(s->numbr)) != s->numbr
142
	if ((val = double_to_int(s->numbr)) != s->numbr
142
	    || val < LONG_MIN || val > LONG_MAX) {
143
	    || val < LONG_MIN || val > LONG_MAX) {
143
#ifdef GFMT_WORKAROUND
144
		/*
145
		 * Once upon a time, if GFMT_WORKAROUND wasn't defined,
146
		 * we just blindly did this:
147
		 *	sprintf(sp, format, s->numbr);
148
		 *	s->stlen = strlen(sp);
149
		 *	s->stfmt = (char) index;
150
		 * but that's no good if, e.g., OFMT is %s. So we punt,
151
		 * and just always format the value ourselves.
152
		 */
153
144
		NODE *dummy, *r;
154
		NODE *dummy, *r;
145
		unsigned short oflags;
155
		unsigned short oflags;
146
		extern NODE *format_tree P((const char *, int, NODE *));
156
		extern NODE *format_tree P((const char *, int, NODE *));
Lines 161-175 Link Here
161
		freenode(dummy);	/* to keep s->stptr == r->stpr.  */
171
		freenode(dummy);	/* to keep s->stptr == r->stpr.  */
162
172
163
		goto no_malloc;
173
		goto no_malloc;
164
#else
165
		/*
166
		 * no need for a "replacement" formatting by gawk,
167
		 * just use sprintf
168
		 */
169
		sprintf(sp, format, s->numbr);
170
		s->stlen = strlen(sp);
171
		s->stfmt = (char) index;
172
#endif /* GFMT_WORKAROUND */
173
	} else {
174
	} else {
174
		/* integral value */
175
		/* integral value */
175
	        /* force conversion to long only once */
176
	        /* force conversion to long only once */
Lines 183-193 Link Here
183
		}
184
		}
184
		s->stfmt = -1;
185
		s->stfmt = -1;
185
	}
186
	}
186
	emalloc(s->stptr, char *, s->stlen + 2, "force_string");
187
	emalloc(s->stptr, char *, s->stlen + 2, "format_val");
187
	memcpy(s->stptr, sp, s->stlen+1);
188
	memcpy(s->stptr, sp, s->stlen+1);
188
#ifdef GFMT_WORKAROUND
189
no_malloc:
189
no_malloc:
190
#endif /* GFMT_WORKAROUND */
191
	s->stref = 1;
190
	s->stref = 1;
192
	s->flags |= STR;
191
	s->flags |= STR;
193
	return s;
192
	return s;
Lines 495-501 Link Here
495
		}
494
		}
496
		i = 0;
495
		i = 0;
497
		for (;;) {
496
		for (;;) {
498
			if (ISXDIGIT((c = *(*string_ptr)++))) {
497
			/* do outside test to avoid multiple side effects */
498
			c = *(*string_ptr)++;
499
			if (ISXDIGIT(c)) {
499
				i *= 16;
500
				i *= 16;
500
				if (ISDIGIT(c))
501
				if (ISDIGIT(c))
501
					i += c - '0';
502
					i += c - '0';
(-)awk/patchlevel.h (-1 / +1 lines)
Line 1 Link Here
1
#define PATCHLEVEL	3
1
#define PATCHLEVEL	4
(-)awk/posix/ChangeLog (+4 lines)
Lines 1-3 Link Here
1
Wed Jun 30 16:14:36 1999  Arnold D. Robbins  <arnold@gnu.org>
2
3
	* Release 3.0.4: Release tar file made.  This time for sure.
4
1
Thu May 15 12:49:08 1997  Arnold D. Robbins  <arnold@skeeve.atl.ga.us>
5
Thu May 15 12:49:08 1997  Arnold D. Robbins  <arnold@skeeve.atl.ga.us>
2
6
3
	* Release 3.0.3: Release tar file made.
7
	* Release 3.0.3: Release tar file made.

Return to bug 15255