aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-06-19 20:24:04 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-06-19 20:24:04 +0300
commit5cb84303090ceeaae218692e849d76bb5f0dce69 (patch)
tree4c422995d737143137ef8a7fccdf2c183502412e
parentfe3173cd6266b73b5400bcf7dd6862979e64e4df (diff)
downloadegawk-5cb84303090ceeaae218692e849d76bb5f0dce69.tar.gz
egawk-5cb84303090ceeaae218692e849d76bb5f0dce69.tar.bz2
egawk-5cb84303090ceeaae218692e849d76bb5f0dce69.zip
Add more comments and whitespace for do_sub().
-rw-r--r--ChangeLog5
-rw-r--r--builtin.c39
2 files changed, 28 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 36ac6f2d..3d7dd673 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-06-19 Arnold D. Robbins <arnold@skeeve.com>
+
+ * builtin.c (do_sub): Add more info to leading comment.
+ Add some whitespace in the code.
+
2014-06-08 Arnold D. Robbins <arnold@skeeve.com>
* dfa.c: Sync with GNU grep.
diff --git a/builtin.c b/builtin.c
index b5d38d8d..fa03222b 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2647,23 +2647,28 @@ do_match(int nargs)
* 2001 standard:
*
* sub(ere, repl[, in ])
- * Substitute the string repl in place of the first instance of the extended regular
- * expression ERE in string in and return the number of substitutions. An ampersand
- * ('&') appearing in the string repl shall be replaced by the string from in that
- * matches the ERE. An ampersand preceded with a backslash ('\') shall be
- * interpreted as the literal ampersand character. An occurrence of two consecutive
- * backslashes shall be interpreted as just a single literal backslash character. Any
- * other occurrence of a backslash (for example, preceding any other character) shall
- * be treated as a literal backslash character. Note that if repl is a string literal (the
- * lexical token STRING; see Grammar (on page 170)), the handling of the
- * ampersand character occurs after any lexical processing, including any lexical
- * backslash escape sequence processing. If in is specified and it is not an lvalue (see
- * Expressions in awk (on page 156)), the behavior is undefined. If in is omitted, awk
- * shall use the current record ($0) in its place.
+ * Substitute the string repl in place of the first instance of the
+ * extended regular expression ERE in string in and return the number of
+ * substitutions. An ampersand ('&') appearing in the string repl shall
+ * be replaced by the string from in that matches the ERE. An ampersand
+ * preceded with a backslash ('\') shall be interpreted as the literal
+ * ampersand character. An occurrence of two consecutive backslashes shall
+ * be interpreted as just a single literal backslash character. Any other
+ * occurrence of a backslash (for example, preceding any other character)
+ * shall be treated as a literal backslash character. Note that if repl is a
+ * string literal (the lexical token STRING; see Grammar (on page 170)), the
+ * handling of the ampersand character occurs after any lexical processing,
+ * including any lexical backslash escape sequence processing. If in is
+ * specified and it is not an lvalue (see Expressions in awk (on page 156)),
+ * the behavior is undefined. If in is omitted, awk shall use the current
+ * record ($0) in its place.
*
- * 11/2010: The text in the 2008 standard is the same as just quoted. However, POSIX behavior
- * is now the default. This can change the behavior of awk programs. The old behavior
- * is not available.
+ * 11/2010: The text in the 2008 standard is the same as just quoted.
+ * However, POSIX behavior is now the default. This can change the behavior
+ * of awk programs. The old behavior is not available.
+ *
+ * 7/2011: Reverted backslash handling to what it used to be. It was in
+ * gawk for too long. Should have known better.
*/
/*
@@ -2774,9 +2779,11 @@ set_how_many:
repl = s->stptr;
replend = repl + s->stlen;
repllen = replend - repl;
+
emalloc(buf, char *, buflen + 2, "do_sub");
buf[buflen] = '\0';
buf[buflen + 1] = '\0';
+
ampersands = 0;
/*