From 44e30eb85147c413c7e4959c2d8e50cf1de673a8 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 22 Apr 2022 21:39:21 -0700 Subject: fields: new parameters to select subrange. --- cppawk-include/cons-priv.h | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'cppawk-include/cons-priv.h') diff --git a/cppawk-include/cons-priv.h b/cppawk-include/cons-priv.h index 6ca2c05..172f20f 100644 --- a/cppawk-include/cons-priv.h +++ b/cppawk-include/cons-priv.h @@ -336,12 +336,33 @@ function __keys(__array, } -function __fields( __tmp, __i, __val) +function __fields(__start, __count, + __tmp, __end, __val) { + if (!__present(__start)) + __start = 1 + + if (!__present(__count)) + __count = NF - __start + 1 + + if (__count < 1) + return __nil + + __end = __start + __count - 1 + + if (__end > NF) + __end = NF + + if (__start < 1) + __start = 1 + + if (__start > __end) + return __nil + __tmp = __list_begin() - __dofields (__i, __val) - __tmp = __list_add(__tmp, __val) + for (; __start <= __end; __start++) + __tmp = __list_add(__tmp, $(__start)) return __list_end(__tmp) } -- cgit v1.2.3