gawk

[old] Sed-like interface to the Gopher protocol
Log | Files | Refs | LICENSE

commit fafbfebf68d5f724ff4d4d3c75150fbaad575451
parent 9d2f50d1f09844c6f2a3863e281b44074de97114
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Wed, 23 Dec 2020 12:22:02 -0800

Add range filter

Diffstat:
Mmain.c | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)

diff --git a/main.c b/main.c @@ -370,6 +370,24 @@ findex(int argc, const char **argv, int index, const char **item, command *func) return 0; } +/* NOTE: inclusive */ +int +frange(int argc, const char **argv, int index, const char **item, command *func) +{ + unsigned int range[2]; + int i; + + if (badargs(2, -1, argc, argv)) + return -1; + + for (i = 0; i < 2; ++i) + if (strtorange(&range[i], 0, UINT_MAX, argv[i])) + return -1; + if (index >= range[0] && index <= range[1]) + return 1; + return 0; +} + int fstring(int argc, const char **argv, int index, const char **item, command *func) { @@ -541,6 +559,8 @@ getfilter(int c) return findex; case 's': return fstring; + case 'r': + return frange; default: return NULL; }