diff options
author | 2024-08-02 15:31:54 +0100 | |
---|---|---|
committer | 2024-08-02 17:21:14 +0100 | |
commit | 2e8bbd04cb55163b3d18ab407ffd8be24bf82c6e (patch) | |
tree | 2f3dab2cf0280736681c24a6654312afe34a672b /functions | |
parent | Render hr() faster still for shells other than bash (diff) | |
download | gentoo-functions-2e8bbd04cb55163b3d18ab407ffd8be24bf82c6e.tar.gz gentoo-functions-2e8bbd04cb55163b3d18ab407ffd8be24bf82c6e.tar.bz2 gentoo-functions-2e8bbd04cb55163b3d18ab407ffd8be24bf82c6e.zip |
Move is_subset() to experimental
I'm not yet ready to commit to it being among the core functions for the
inaugural API level.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
Diffstat (limited to 'functions')
-rw-r--r-- | functions/experimental.sh | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/functions/experimental.sh b/functions/experimental.sh index bbbf0fa..0ca9904 100644 --- a/functions/experimental.sh +++ b/functions/experimental.sh @@ -83,6 +83,46 @@ is_interactive() } # +# Collects the intersection of the parameters up to - but not including - a +# sentinel value then determines whether the resulting set is a subset of the +# intersection of the remaining parameters. If the SENTINEL variable is set, it +# shall be taken as the value of the sentinel. Otherwise, the value of the +# sentinel shall be defined as <hyphen-dash><hyphen-dash>. If the sentinel value +# is not encountered or if either set is empty then the return value shall be +# greater than 1. +# +is_subset() +{ + SENTINEL=${SENTINEL-'--'} awk -f - -- "$@" <<-'EOF' + BEGIN { + argc = ARGC + ARGC = 1 + for (i = 1; i < argc; i++) { + word = ARGV[i] + if (word == ENVIRON["SENTINEL"]) { + break + } else { + set1[word] + } + } + if (i == 1 || argc - i < 2) { + exit 1 + } + for (i++; i < argc; i++) { + word = ARGV[i] + set2[word] + } + for (word in set2) { + delete set1[word] + } + for (word in set1) { + exit 1 + } + } + EOF +} + +# # Continuously reads lines from the standard input, prepending each with a # timestamp before printing to the standard output. Timestamps shall be in the # format of "%FT%T%z", per strftime(3). Output buffering shall not be employed. |