* [gentoo-commits] proj/gentoo-functions:master commit in: /, functions/
@ 2024-07-07 5:55 Sam James
0 siblings, 0 replies; 4+ messages in thread
From: Sam James @ 2024-07-07 5:55 UTC (permalink / raw
To: gentoo-commits
commit: feaa7438ef8c749179bf5fb99f93a3683e6d40fd
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Jun 30 23:15:36 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Jul 1 02:31:58 2024 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=feaa7438
Move substr() to experimental
Though it works very well, 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 <AT> plushkava.net>
functions.sh | 41 -----------------------------------------
functions/experimental.sh | 41 +++++++++++++++++++++++++++++++++++++++++
test-functions | 2 +-
3 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/functions.sh b/functions.sh
index 087b62d..1926c40 100644
--- a/functions.sh
+++ b/functions.sh
@@ -436,47 +436,6 @@ srandom()
srandom
}
-#
-# Takes the first parameter as a string (s), the second parameter as a numerical
-# position (m) and, optionally, the third parameter as a numerical length (n).
-# It shall then print a <newline> terminated substring of s that is at most, n
-# characters in length and which begins at position m, numbering from 1. If n is
-# omitted, or if n specifies more characters than are left in the string, the
-# length of the substring shall be limited by the length of s. The function
-# shall return 0 provided that none of the parameters are invalid.
-#
-substr()
-{
- local i str
-
- if [ "$#" -lt 2 ]; then
- warn "substr: too few arguments (got $#, expected at least 2)"
- return 1
- elif ! is_int "$2"; then
- _warn_for_args substr "$2"
- return 1
- elif [ "$#" -ge 3 ]; then
- if ! is_int "$3"; then
- _warn_for_args substr "$3"
- return 1
- elif [ "$3" -lt 0 ]; then
- set -- "$1" "$2" 0
- fi
- fi
- str=$1
- i=0
- while [ "$(( i += 1 ))" -lt "$2" ]; do
- str=${str#?}
- done
- i=0
- while [ "${#str}" -gt "${3-${#str}}" ]; do
- str=${str%?}
- done
- if [ "${#str}" -gt 0 ]; then
- printf '%s\n' "${str}"
- fi
-}
-
#
# Trims leading and trailing whitespace from one or more lines. If at least one
# parameter is provided, each positional parameter shall be considered as a line
diff --git a/functions/experimental.sh b/functions/experimental.sh
index 1aac078..4d56cfa 100644
--- a/functions/experimental.sh
+++ b/functions/experimental.sh
@@ -94,6 +94,47 @@ str_between()
fi
}
+#
+# Takes the first parameter as a string (s), the second parameter as a numerical
+# position (m) and, optionally, the third parameter as a numerical length (n).
+# It shall then print a <newline> terminated substring of s that is at most, n
+# characters in length and which begins at position m, numbering from 1. If n is
+# omitted, or if n specifies more characters than are left in the string, the
+# length of the substring shall be limited by the length of s. The function
+# shall return 0 provided that none of the parameters are invalid.
+#
+substr()
+{
+ local i str
+
+ if [ "$#" -lt 2 ]; then
+ warn "substr: too few arguments (got $#, expected at least 2)"
+ return 1
+ elif ! is_int "$2"; then
+ _warn_for_args substr "$2"
+ return 1
+ elif [ "$#" -ge 3 ]; then
+ if ! is_int "$3"; then
+ _warn_for_args substr "$3"
+ return 1
+ elif [ "$3" -lt 0 ]; then
+ set -- "$1" "$2" 0
+ fi
+ fi
+ str=$1
+ i=0
+ while [ "$(( i += 1 ))" -lt "$2" ]; do
+ str=${str#?}
+ done
+ i=0
+ while [ "${#str}" -gt "${3-${#str}}" ]; do
+ str=${str%?}
+ done
+ if [ "${#str}" -gt 0 ]; then
+ printf '%s\n' "${str}"
+ fi
+}
+
#
# Takes the first parameter as either a relative pathname or an integer
# referring to a number of iterations. To be recognised as a pathname, the first
diff --git a/test-functions b/test-functions
index 68e73eb..34ff54a 100755
--- a/test-functions
+++ b/test-functions
@@ -793,7 +793,7 @@ test_is_anyof || rc=1
test_is_subset || rc=1
test_trueof_all || rc=1
test_trueof_any || rc=1
-test_substr || rc=1
+#test_substr || rc=1
cleanup_tmpdir
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] proj/gentoo-functions:master commit in: /, functions/
@ 2024-07-07 5:55 Sam James
0 siblings, 0 replies; 4+ messages in thread
From: Sam James @ 2024-07-07 5:55 UTC (permalink / raw
To: gentoo-commits
commit: 23ce043cfccf6b39caf790464c18f2df1d5b7d1b
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Mon Jul 1 02:29:27 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Jul 1 02:32:27 2024 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=23ce043c
Move fetch() 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 <AT> plushkava.net>
functions.sh | 42 ------------------------------------------
functions/experimental.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/functions.sh b/functions.sh
index a4fa946..cfaddc3 100644
--- a/functions.sh
+++ b/functions.sh
@@ -138,48 +138,6 @@ contains_any()
return "${retval}"
}
-#
-# Considers the first parameter as an URL then attempts to fetch it with either
-# curl(1) or wget(1). If the URL does not contain a scheme then the https://
-# scheme shall be presumed. Both utilities shall be invoked in a manner that
-# suppresses all output unless an error occurs, and whereby HTTP redirections
-# are honoured. Upon success, the body of the response shall be printed to the
-# standard output. Otherwise, the return value shall be greater than 0.
-#
-fetch()
-{
- if hash curl 2>/dev/null; then
- fetch()
- {
- if [ "$#" -gt 0 ]; then
- # Discard any extraneous parameters.
- set -- "$1"
- fi
- curl -f -sS -L --connect-timeout 10 --proto-default https -- "$@"
- }
- elif hash wget 2>/dev/null; then
- fetch()
- {
- if [ "$#" -gt 0 ]; then
- # Discard any extraneous parameters.
- case $1 in
- ''|ftp://*|ftps://*|https://*)
- set -- "$1"
- ;;
- *)
- set -- "https://$1"
- esac
- fi
- wget -nv -O - --connect-timeout 10 -- "$@"
- }
- else
- warn "fetch: this function requires that curl or wget be installed"
- return 127
- fi
-
- fetch "$@"
-}
-
#
# Determines whether the current shell is a subprocess of portage.
#
diff --git a/functions/experimental.sh b/functions/experimental.sh
index 4d56cfa..bbbf0fa 100644
--- a/functions/experimental.sh
+++ b/functions/experimental.sh
@@ -12,6 +12,48 @@
warn "sourcing the experimental module from gentoo-functions; no stability guarantee is provided"
+#
+# Considers the first parameter as an URL then attempts to fetch it with either
+# curl(1) or wget(1). If the URL does not contain a scheme then the https://
+# scheme shall be presumed. Both utilities shall be invoked in a manner that
+# suppresses all output unless an error occurs, and whereby HTTP redirections
+# are honoured. Upon success, the body of the response shall be printed to the
+# standard output. Otherwise, the return value shall be greater than 0.
+#
+fetch()
+{
+ if hash curl 2>/dev/null; then
+ fetch()
+ {
+ if [ "$#" -gt 0 ]; then
+ # Discard any extraneous parameters.
+ set -- "$1"
+ fi
+ curl -f -sS -L --connect-timeout 10 --proto-default https -- "$@"
+ }
+ elif hash wget 2>/dev/null; then
+ fetch()
+ {
+ if [ "$#" -gt 0 ]; then
+ # Discard any extraneous parameters.
+ case $1 in
+ ''|ftp://*|ftps://*|https://*)
+ set -- "$1"
+ ;;
+ *)
+ set -- "https://$1"
+ esac
+ fi
+ wget -nv -O - --connect-timeout 10 -- "$@"
+ }
+ else
+ warn "fetch: this function requires that curl or wget be installed"
+ return 127
+ fi
+
+ fetch "$@"
+}
+
#
# Expects three parameters, all of which must be integers, and determines
# whether the first is numerically greater than or equal to the second, and
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] proj/gentoo-functions:master commit in: /, functions/
@ 2024-08-02 23:14 Sam James
0 siblings, 0 replies; 4+ messages in thread
From: Sam James @ 2024-08-02 23:14 UTC (permalink / raw
To: gentoo-commits
commit: 2e8bbd04cb55163b3d18ab407ffd8be24bf82c6e
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Aug 2 14:31:54 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Aug 2 16:21:14 2024 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=2e8bbd04
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 <AT> plushkava.net>
functions.sh | 40 ----------------------------------------
functions/experimental.sh | 40 ++++++++++++++++++++++++++++++++++++++++
test-functions | 2 +-
3 files changed, 41 insertions(+), 41 deletions(-)
diff --git a/functions.sh b/functions.sh
index a002e54..69b9bf5 100644
--- a/functions.sh
+++ b/functions.sh
@@ -246,46 +246,6 @@ is_anyof()
false
}
-#
-# 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
-}
-
#
# Considers one or more pathnames and prints the one having the newest
# modification time. If at least one parameter is provided, all parameters shall
diff --git a/functions/experimental.sh b/functions/experimental.sh
index bbbf0fa..0ca9904 100644
--- a/functions/experimental.sh
+++ b/functions/experimental.sh
@@ -82,6 +82,46 @@ is_interactive()
test -t 0 && { true 3>&1; } 2>/dev/null
}
+#
+# 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
diff --git a/test-functions b/test-functions
index 8070c8d..43b5320 100755
--- a/test-functions
+++ b/test-functions
@@ -909,7 +909,7 @@ else
test_whenceforth || rc=1
test_parallel_run || rc=1
test_is_anyof || rc=1
- test_is_subset || rc=1
+ #test_is_subset || rc=1
test_trueof_all || rc=1
test_trueof_any || rc=1
#test_substr || rc=1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] proj/gentoo-functions:master commit in: /, functions/
@ 2024-08-11 10:11 Sam James
0 siblings, 0 replies; 4+ messages in thread
From: Sam James @ 2024-08-11 10:11 UTC (permalink / raw
To: gentoo-commits
commit: 8f708ef54a07f200b308f82fd64c2c87f5e89b11
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Aug 10 06:57:17 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Aug 11 10:11:05 2024 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=8f708ef5
Remedy false positives in categories SC2034 and SC2154
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
functions.sh | 5 -----
functions/experimental.sh | 1 +
functions/rc.sh | 8 ++++++++
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/functions.sh b/functions.sh
index eff7f5f..38eef62 100644
--- a/functions.sh
+++ b/functions.sh
@@ -958,11 +958,6 @@ if [ ! "${genfun_basedir+set}" ]; then
genfun_basedir=${genfun_prefix}/lib/gentoo
fi
-# Assign the LF ('\n') character for later expansion. POSIX-1.2024 permits $'\n'
-# but it may take years for it to be commonly implemented.
-genfun_newline='
-'
-
# The GENFUN_MODULES variable acts as a means of selecting modules, which are
# merely optional collections of functions. If unset then set it now.
if [ ! "${GENFUN_MODULES+set}" ]; then
diff --git a/functions/experimental.sh b/functions/experimental.sh
index 0ca9904..7c2fb25 100644
--- a/functions/experimental.sh
+++ b/functions/experimental.sh
@@ -168,6 +168,7 @@ str_between()
else
set -- "$2" "$1" "$3"
i=0
+ # shellcheck disable=2034
printf '%s\n' "$@" |
sort |
while IFS= read -r line; do
diff --git a/functions/rc.sh b/functions/rc.sh
index 4eff3c8..101b99e 100644
--- a/functions/rc.sh
+++ b/functions/rc.sh
@@ -347,6 +347,7 @@ _eend()
"${efunc}" "${msg}"
fi
# Generate an indicator for ebegin's unsuccessful conclusion.
+ # shellcheck disable=2154
if _update_tty_level <&1; [ "${genfun_tty}" -eq 0 ]; then
msg="[ !! ]"
else
@@ -356,6 +357,7 @@ _eend()
return "${retval}"
else
# Generate an indicator for ebegin's successful conclusion.
+ # shellcheck disable=2154
if _update_tty_level <&1; [ "${genfun_tty}" -eq 0 ]; then
msg="[ ok ]"
else
@@ -367,6 +369,7 @@ _eend()
# Save the cursor position with DECSC, move it up by one line
# with CUU, position it horizontally with CHA, print the
# indicator, then restore the cursor position with DECRC.
+ # shellcheck disable=2154
col=$(( genfun_cols > 6 ? genfun_cols - 6 : 1 ))
printf '\0337\033[1A\033[%dG %s\0338' "$(( col + genfun_offset ))" "${msg}"
else
@@ -484,5 +487,10 @@ else
genfun_offset=0
fi
+# Assign the LF ('\n') character for later expansion. POSIX-1.2024 permits $'\n'
+# but it may take years for it to be commonly implemented.
+genfun_newline='
+'
+
# shellcheck disable=2034
RC_GOT_FUNCTIONS=yes
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-11 10:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-02 23:14 [gentoo-commits] proj/gentoo-functions:master commit in: /, functions/ Sam James
-- strict thread matches above, loose matches on Subject: below --
2024-08-11 10:11 Sam James
2024-07-07 5:55 Sam James
2024-07-07 5:55 Sam James
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox