aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--extension/ChangeLog5
-rw-r--r--extension/inplace.c8
-rw-r--r--test/ChangeLog10
-rw-r--r--test/Makefile.am52
-rw-r--r--test/Makefile.in52
-rw-r--r--test/inplace.1.in2
-rw-r--r--test/inplace.2.in2
-rw-r--r--test/inplace.in3
-rw-r--r--test/inplace1.1.ok2
-rw-r--r--test/inplace1.2.ok2
-rw-r--r--test/inplace1.ok6
-rw-r--r--test/inplace2.1.bak.ok2
-rw-r--r--test/inplace2.1.ok2
-rw-r--r--test/inplace2.2.bak.ok2
-rw-r--r--test/inplace2.2.ok2
-rw-r--r--test/inplace2.ok6
-rw-r--r--test/inplace3.1.bak.ok2
-rw-r--r--test/inplace3.1.ok2
-rw-r--r--test/inplace3.2.bak.ok2
-rw-r--r--test/inplace3.2.ok2
-rw-r--r--test/inplace3.ok12
21 files changed, 171 insertions, 7 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 7fea3bf0..33fb6459 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,8 @@
+2013-01-10 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * inplace.c (do_inplace_begin): No need to get the 2nd suffix argument,
+ since it is not currently used in this function.
+
2013-01-08 Andrew J. Schorr <aschorr@telemetry-investments.com>
* inplace.c: New extension to implement in-place editing.
diff --git a/extension/inplace.c b/extension/inplace.c
index 69b188b8..31f21b60 100644
--- a/extension/inplace.c
+++ b/extension/inplace.c
@@ -93,7 +93,7 @@ invalid_filename(const awk_string_t *filename)
static awk_value_t *
do_inplace_begin(int nargs, awk_value_t *result)
{
- awk_value_t filename, suffix;
+ awk_value_t filename;
struct stat sbuf;
char *p;
int fd;
@@ -109,8 +109,10 @@ do_inplace_begin(int nargs, awk_value_t *result)
if (! get_argument(0, AWK_STRING, &filename))
fatal(ext_id, _("inplace_begin: cannot retrieve 1st argument as a string filename"));
- if (! get_argument(1, AWK_STRING, &suffix))
- suffix.str_value.str = NULL;
+ /*
+ * N.B. In the current implementation, the 2nd suffix arg is not used
+ * in this function. It is used only in the inplace_end function.
+ */
if (invalid_filename(&filename.str_value)) {
warning(ext_id, _("inplace_begin: disabling in-place editing for invalid FILENAME `%s'"),
diff --git a/test/ChangeLog b/test/ChangeLog
index b9a29c1b..914a0fd1 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,13 @@
+2013-01-10 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * inplace.1.in, inplace.2.in, inplace.in, inplace1.1.ok, inplace1.2.ok,
+ inplace1.ok, inplace2.1.bak.ok, inplace2.1.ok, inplace2.2.bak.ok,
+ inplace2.2.ok, inplace2.ok, inplace3.1.bak.ok, inplace3.1.ok,
+ inplace3.2.bak.ok, inplace3.2.ok, inplace3.ok: New files.
+ * Makefile.am (EXTRA_DIST): Add new files.
+ (SHLIB_TESTS): Add inplace1, inplace2, and inplace3.
+ (inplace1, inplace2, inplace3): New tests.
+
2012-12-25 Arnold D. Robbins <arnold@skeeve.com>
* assignconst.awk, assignconst.ok: Removed.
diff --git a/test/Makefile.am b/test/Makefile.am
index da67b059..7a541f97 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -403,6 +403,22 @@ EXTRA_DIST = \
indirectcall.ok \
inftest.awk \
inftest.ok \
+ inplace.in \
+ inplace.1.in \
+ inplace.2.in \
+ inplace1.ok \
+ inplace1.1.ok \
+ inplace1.2.ok \
+ inplace2.ok \
+ inplace2.1.ok \
+ inplace2.1.bak.ok \
+ inplace2.2.ok \
+ inplace2.2.bak.ok \
+ inplace3.ok \
+ inplace3.1.ok \
+ inplace3.1.bak.ok \
+ inplace3.2.ok \
+ inplace3.2.bak.ok \
inputred.awk \
inputred.ok \
intest.awk \
@@ -953,8 +969,8 @@ LOCALE_CHARSET_TESTS = \
mbprintf1 mbprintf2 mbprintf3 rebt8b2 rtlenmb sort1 sprintfc
SHLIB_TESTS = \
- fnmatch filefuncs fork fork2 fts ordchr ordchr2 \
- readdir readfile revout revtwoway rwarray testext time
+ fnmatch filefuncs fork fork2 fts inplace1 inplace2 inplace3 \
+ ordchr ordchr2 readdir readfile revout revtwoway rwarray testext time
# List of the tests which should be run with --lint option:
NEED_LINT = \
@@ -1675,6 +1691,38 @@ incdupe7::
@AWKPATH=$(srcdir) $(AWK) --lint -f hello -i inchello >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+inplace1::
+ @echo $@
+ @cp $(srcdir)/inplace.1.in _$@.1
+ @cp $(srcdir)/inplace.2.in _$@.2
+ @AWKPATH=$(srcdir)/../awklib/eg/lib $(AWK) -i inplace 'BEGIN {print "before"} {gsub(/foo/, "bar"); print} END {print "after"}' _$@.1 - _$@.2 < $(srcdir)/inplace.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+ @-$(CMP) $(srcdir)/$@.1.ok _$@.1 && rm -f _$@.1
+ @-$(CMP) $(srcdir)/$@.2.ok _$@.2 && rm -f _$@.2
+
+inplace2::
+ @echo $@
+ @cp $(srcdir)/inplace.1.in _$@.1
+ @cp $(srcdir)/inplace.2.in _$@.2
+ @AWKPATH=$(srcdir)/../awklib/eg/lib $(AWK) -i inplace -v INPLACE_SUFFIX=.bak 'BEGIN {print "before"} {gsub(/foo/, "bar"); print} END {print "after"}' _$@.1 - _$@.2 < $(srcdir)/inplace.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+ @-$(CMP) $(srcdir)/$@.1.ok _$@.1 && rm -f _$@.1
+ @-$(CMP) $(srcdir)/$@.1.bak.ok _$@.1.bak && rm -f _$@.1.bak
+ @-$(CMP) $(srcdir)/$@.2.ok _$@.2 && rm -f _$@.2
+ @-$(CMP) $(srcdir)/$@.2.bak.ok _$@.2.bak && rm -f _$@.2.bak
+
+inplace3::
+ @echo $@
+ @cp $(srcdir)/inplace.1.in _$@.1
+ @cp $(srcdir)/inplace.2.in _$@.2
+ @AWKPATH=$(srcdir)/../awklib/eg/lib $(AWK) -i inplace -v INPLACE_SUFFIX=.bak 'BEGIN {print "before"} {gsub(/foo/, "bar"); print} END {print "after"}' _$@.1 - _$@.2 < $(srcdir)/inplace.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @AWKPATH=$(srcdir)/../awklib/eg/lib $(AWK) -i inplace -v INPLACE_SUFFIX=.bak 'BEGIN {print "Before"} {gsub(/bar/, "foo"); print} END {print "After"}' _$@.1 - _$@.2 < $(srcdir)/inplace.in >>_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+ @-$(CMP) $(srcdir)/$@.1.ok _$@.1 && rm -f _$@.1
+ @-$(CMP) $(srcdir)/$@.1.bak.ok _$@.1.bak && rm -f _$@.1.bak
+ @-$(CMP) $(srcdir)/$@.2.ok _$@.2 && rm -f _$@.2
+ @-$(CMP) $(srcdir)/$@.2.bak.ok _$@.2.bak && rm -f _$@.2.bak
+
testext::
@echo $@
@$(AWK) '/^(@load|BEGIN)/,/^}/' $(top_srcdir)/extension/testext.c > testext.awk
diff --git a/test/Makefile.in b/test/Makefile.in
index e4b22fd8..52d8edc5 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -615,6 +615,22 @@ EXTRA_DIST = \
indirectcall.ok \
inftest.awk \
inftest.ok \
+ inplace.in \
+ inplace.1.in \
+ inplace.2.in \
+ inplace1.ok \
+ inplace1.1.ok \
+ inplace1.2.ok \
+ inplace2.ok \
+ inplace2.1.ok \
+ inplace2.1.bak.ok \
+ inplace2.2.ok \
+ inplace2.2.bak.ok \
+ inplace3.ok \
+ inplace3.1.ok \
+ inplace3.1.bak.ok \
+ inplace3.2.ok \
+ inplace3.2.bak.ok \
inputred.awk \
inputred.ok \
intest.awk \
@@ -1160,8 +1176,8 @@ LOCALE_CHARSET_TESTS = \
mbprintf1 mbprintf2 mbprintf3 rebt8b2 rtlenmb sort1 sprintfc
SHLIB_TESTS = \
- fnmatch filefuncs fork fork2 fts ordchr ordchr2 \
- readdir readfile revout revtwoway rwarray testext time
+ fnmatch filefuncs fork fork2 fts inplace1 inplace2 inplace3 \
+ ordchr ordchr2 readdir readfile revout revtwoway rwarray testext time
# List of the tests which should be run with --lint option:
@@ -2056,6 +2072,38 @@ incdupe7::
@AWKPATH=$(srcdir) $(AWK) --lint -f hello -i inchello >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+inplace1::
+ @echo $@
+ @cp $(srcdir)/inplace.1.in _$@.1
+ @cp $(srcdir)/inplace.2.in _$@.2
+ @AWKPATH=$(srcdir)/../awklib/eg/lib $(AWK) -i inplace 'BEGIN {print "before"} {gsub(/foo/, "bar"); print} END {print "after"}' _$@.1 - _$@.2 < $(srcdir)/inplace.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+ @-$(CMP) $(srcdir)/$@.1.ok _$@.1 && rm -f _$@.1
+ @-$(CMP) $(srcdir)/$@.2.ok _$@.2 && rm -f _$@.2
+
+inplace2::
+ @echo $@
+ @cp $(srcdir)/inplace.1.in _$@.1
+ @cp $(srcdir)/inplace.2.in _$@.2
+ @AWKPATH=$(srcdir)/../awklib/eg/lib $(AWK) -i inplace -v INPLACE_SUFFIX=.bak 'BEGIN {print "before"} {gsub(/foo/, "bar"); print} END {print "after"}' _$@.1 - _$@.2 < $(srcdir)/inplace.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+ @-$(CMP) $(srcdir)/$@.1.ok _$@.1 && rm -f _$@.1
+ @-$(CMP) $(srcdir)/$@.1.bak.ok _$@.1.bak && rm -f _$@.1.bak
+ @-$(CMP) $(srcdir)/$@.2.ok _$@.2 && rm -f _$@.2
+ @-$(CMP) $(srcdir)/$@.2.bak.ok _$@.2.bak && rm -f _$@.2.bak
+
+inplace3::
+ @echo $@
+ @cp $(srcdir)/inplace.1.in _$@.1
+ @cp $(srcdir)/inplace.2.in _$@.2
+ @AWKPATH=$(srcdir)/../awklib/eg/lib $(AWK) -i inplace -v INPLACE_SUFFIX=.bak 'BEGIN {print "before"} {gsub(/foo/, "bar"); print} END {print "after"}' _$@.1 - _$@.2 < $(srcdir)/inplace.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @AWKPATH=$(srcdir)/../awklib/eg/lib $(AWK) -i inplace -v INPLACE_SUFFIX=.bak 'BEGIN {print "Before"} {gsub(/bar/, "foo"); print} END {print "After"}' _$@.1 - _$@.2 < $(srcdir)/inplace.in >>_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@
+ @-$(CMP) $(srcdir)/$@.1.ok _$@.1 && rm -f _$@.1
+ @-$(CMP) $(srcdir)/$@.1.bak.ok _$@.1.bak && rm -f _$@.1.bak
+ @-$(CMP) $(srcdir)/$@.2.ok _$@.2 && rm -f _$@.2
+ @-$(CMP) $(srcdir)/$@.2.bak.ok _$@.2.bak && rm -f _$@.2.bak
+
testext::
@echo $@
@$(AWK) '/^(@load|BEGIN)/,/^}/' $(top_srcdir)/extension/testext.c > testext.awk
diff --git a/test/inplace.1.in b/test/inplace.1.in
new file mode 100644
index 00000000..d87f79a1
--- /dev/null
+++ b/test/inplace.1.in
@@ -0,0 +1,2 @@
+is foo replaced?
+and again foo here?
diff --git a/test/inplace.2.in b/test/inplace.2.in
new file mode 100644
index 00000000..4644a915
--- /dev/null
+++ b/test/inplace.2.in
@@ -0,0 +1,2 @@
+another input file containing foo and foo and more foo
+but nothing to replace here
diff --git a/test/inplace.in b/test/inplace.in
new file mode 100644
index 00000000..bf2cf989
--- /dev/null
+++ b/test/inplace.in
@@ -0,0 +1,3 @@
+stdin start
+is foo replaced?
+stdin end
diff --git a/test/inplace1.1.ok b/test/inplace1.1.ok
new file mode 100644
index 00000000..8faa542e
--- /dev/null
+++ b/test/inplace1.1.ok
@@ -0,0 +1,2 @@
+is bar replaced?
+and again bar here?
diff --git a/test/inplace1.2.ok b/test/inplace1.2.ok
new file mode 100644
index 00000000..64427be3
--- /dev/null
+++ b/test/inplace1.2.ok
@@ -0,0 +1,2 @@
+another input file containing bar and bar and more bar
+but nothing to replace here
diff --git a/test/inplace1.ok b/test/inplace1.ok
new file mode 100644
index 00000000..ffcb768d
--- /dev/null
+++ b/test/inplace1.ok
@@ -0,0 +1,6 @@
+before
+gawk: inplace:9: warning: inplace_begin: disabling in-place editing for invalid FILENAME `-'
+stdin start
+is bar replaced?
+stdin end
+after
diff --git a/test/inplace2.1.bak.ok b/test/inplace2.1.bak.ok
new file mode 100644
index 00000000..d87f79a1
--- /dev/null
+++ b/test/inplace2.1.bak.ok
@@ -0,0 +1,2 @@
+is foo replaced?
+and again foo here?
diff --git a/test/inplace2.1.ok b/test/inplace2.1.ok
new file mode 100644
index 00000000..8faa542e
--- /dev/null
+++ b/test/inplace2.1.ok
@@ -0,0 +1,2 @@
+is bar replaced?
+and again bar here?
diff --git a/test/inplace2.2.bak.ok b/test/inplace2.2.bak.ok
new file mode 100644
index 00000000..4644a915
--- /dev/null
+++ b/test/inplace2.2.bak.ok
@@ -0,0 +1,2 @@
+another input file containing foo and foo and more foo
+but nothing to replace here
diff --git a/test/inplace2.2.ok b/test/inplace2.2.ok
new file mode 100644
index 00000000..64427be3
--- /dev/null
+++ b/test/inplace2.2.ok
@@ -0,0 +1,2 @@
+another input file containing bar and bar and more bar
+but nothing to replace here
diff --git a/test/inplace2.ok b/test/inplace2.ok
new file mode 100644
index 00000000..ffcb768d
--- /dev/null
+++ b/test/inplace2.ok
@@ -0,0 +1,6 @@
+before
+gawk: inplace:9: warning: inplace_begin: disabling in-place editing for invalid FILENAME `-'
+stdin start
+is bar replaced?
+stdin end
+after
diff --git a/test/inplace3.1.bak.ok b/test/inplace3.1.bak.ok
new file mode 100644
index 00000000..8faa542e
--- /dev/null
+++ b/test/inplace3.1.bak.ok
@@ -0,0 +1,2 @@
+is bar replaced?
+and again bar here?
diff --git a/test/inplace3.1.ok b/test/inplace3.1.ok
new file mode 100644
index 00000000..d87f79a1
--- /dev/null
+++ b/test/inplace3.1.ok
@@ -0,0 +1,2 @@
+is foo replaced?
+and again foo here?
diff --git a/test/inplace3.2.bak.ok b/test/inplace3.2.bak.ok
new file mode 100644
index 00000000..64427be3
--- /dev/null
+++ b/test/inplace3.2.bak.ok
@@ -0,0 +1,2 @@
+another input file containing bar and bar and more bar
+but nothing to replace here
diff --git a/test/inplace3.2.ok b/test/inplace3.2.ok
new file mode 100644
index 00000000..4644a915
--- /dev/null
+++ b/test/inplace3.2.ok
@@ -0,0 +1,2 @@
+another input file containing foo and foo and more foo
+but nothing to replace here
diff --git a/test/inplace3.ok b/test/inplace3.ok
new file mode 100644
index 00000000..7cd960bc
--- /dev/null
+++ b/test/inplace3.ok
@@ -0,0 +1,12 @@
+before
+gawk: inplace:9: warning: inplace_begin: disabling in-place editing for invalid FILENAME `-'
+stdin start
+is bar replaced?
+stdin end
+after
+Before
+gawk: inplace:9: warning: inplace_begin: disabling in-place editing for invalid FILENAME `-'
+stdin start
+is foo replaced?
+stdin end
+After