summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlemens Nanni <kn@cvs.openbsd.org>2023-02-16 18:10:29 +0000
committerKlemens Nanni <kn@cvs.openbsd.org>2023-02-16 18:10:29 +0000
commit6b38196187696a9426ec3476e90c41ea1654a4a5 (patch)
tree14a37b20f23f64343a2d182d97b39574da199777
parent44d7307efbd1b84387f72a8015343676dac062a2 (diff)
Rewrite bsort() from hand-rolled recursive to simpler iterative reusing code
ksh(1) can sort itself and addel() ensures uniqueness, so reuse both to get a much simpler shell version of `sort -u' that is bug-for-bug compatible with the old one but shorter and easier to tweak/reason about. OK afresh1
-rw-r--r--distrib/miniroot/install.sub35
1 files changed, 12 insertions, 23 deletions
diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub
index a0858392115..7d445b75e79 100644
--- a/distrib/miniroot/install.sub
+++ b/distrib/miniroot/install.sub
@@ -1,5 +1,5 @@
#!/bin/ksh
-# $OpenBSD: install.sub,v 1.1227 2023/02/09 10:38:41 kn Exp $
+# $OpenBSD: install.sub,v 1.1228 2023/02/16 18:10:28 kn Exp $
#
# Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback
# Copyright (c) 2015, Robert Peichaer <rpe@openbsd.org>
@@ -109,28 +109,6 @@ wait_cgiinfo() {
# Utils functions
# ------------------------------------------------------------------------------
-# Sort and print unique list of provided arguments.
-bsort() {
- local _a=$1 _b _l
-
- (($#)) && shift || return
-
- for _b; do
- [[ $_a == "$_b" ]] && continue
- if [[ $_a > $_b ]]; then
- _l="$_a $_l" _a=$_b
- else
- _l="$_b $_l"
- fi
- done
-
- # Output the smallest value found.
- (($#)) && echo -n "$_a " || echo -n "$_a"
-
- # Sort remaining values.
- bsort $_l
-}
-
# Test the first argument against the remaining ones, return success on a match.
isin() {
local _a=$1 _b
@@ -163,6 +141,17 @@ rmel() {
echo -n "$_c"
}
+# Sort and print unique list of provided arguments.
+bsort() {
+ local _a _l
+
+ set -s -- $@
+ for _a; do
+ _l=$(addel $_a $_l)
+ done
+ echo -n $_l
+}
+
# If possible, print the timestamp received from the ftplist.cgi output,
# adjusted with the time elapsed since it was received.
http_time() {