aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-04-23 16:31:41 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-04-23 16:31:41 -0700
commit57f4e4ed68140a9f20cb59c45c79214cfa552970 (patch)
treee63b55b41f0923f23a66dcb9307a86fd647b9fa8
parent44e30eb85147c413c7e4959c2d8e50cf1de673a8 (diff)
downloadcppawk-57f4e4ed68140a9f20cb59c45c79214cfa552970.tar.gz
cppawk-57f4e4ed68140a9f20cb59c45c79214cfa552970.tar.bz2
cppawk-57f4e4ed68140a9f20cb59c45c79214cfa552970.zip
set_fields: document/test the start index param.
-rw-r--r--cppawk-cons.115
-rw-r--r--testcases-cons27
2 files changed, 38 insertions, 4 deletions
diff --git a/cppawk-cons.1 b/cppawk-cons.1
index 64939af..f41abe0 100644
--- a/cppawk-cons.1
+++ b/cppawk-cons.1
@@ -108,7 +108,7 @@ cons \- Lisp-like data representation and control flow macros
\fI// Field/list conversion\fP
fields([\fIi \fP[, \fIn\fP]]) \fI// convert Awk positional fields to list\fP
- set_fields(\fIx\fP) \fI// set Awk positional fields from list x\fP
+ set_fields(\fIx\fP[, \fIi\fP])\fI// set Awk positional fields from list x\fP
\fI// list iteration\fP
@@ -1974,7 +1974,7 @@ or unboxed objects.
.ft B
fields([\fIi \fP[, \fIn\fP]])
- set_fields(\fIx\fP)
+ set_fields(\fIx\fP[, \fIi\fP])
.ft R
.B Description
@@ -2013,9 +2013,16 @@ The
.B set_fields
function replaces the positional values with the contents of list
.I x
-setting
+starting at position
+.I i
+which defaults to 1.
+The last element of the list becomes the last field, whose index
+therefore becomes the new value of the
.B NF
-to the length of the list.
+variable.
+If
+.I i
+is less than 1, it is ignored and the default value 1 is used.
Since the fields and
.B NF
diff --git a/testcases-cons b/testcases-cons
index e5342c0..ebf9241 100644
--- a/testcases-cons
+++ b/testcases-cons
@@ -937,3 +937,30 @@ nil
("brown" "fox")
("fox")
nil
+--
+47:
+$cppawk '
+#include <cons.h>
+
+BEGIN {
+ $0 = "the quick brown fox"
+ print sexp(fields())
+
+ set_fields(list(1, cons(1, 2), "foo", box_str("foo")), 3)
+
+ for (i = 1; i <= NF; i++)
+ print $i
+
+ set_fields(list("fast", "fox"), 2)
+ print sexp(fields())
+}'
+:
+("the" "quick" "brown" "fox")
+the
+quick
+1
+C1,1:12
+foo
+Tfoo
+("the" "fast" "fox")
+--