find-first-fail: -s start value for searching.

This commit is contained in:
Ole Tange 2020-09-13 19:25:23 +02:00
parent ba8eee5953
commit 0d32feb0cc

View file

@ -10,7 +10,7 @@ find-first-fail - find the lowest argument that makes a command fail
=head1 SYNOPSIS
B<find-first-fail> [-2] [-q] I<command>
B<find-first-fail> [-2] [-q] [-s I<start>] I<command>
=head1 DESCRIPTION
@ -39,6 +39,10 @@ arguments: I<from> I<to>.
Quiet. Ignore output from I<command>.
=item B<-s I<start>>
Start searching from the value I<start>. Normally searching will start from the value 1.
=back
@ -164,20 +168,22 @@ find-first-fail() {
quiet=""
opt2=false
verbose=false
start=1
# Parse and remove options
while getopts "2vq" options; do
while getopts "2vqs:" options; do
case "${options}" in
(2) opt2=true;;
(q) quiet=">/dev/null 2>/dev/null";;
(v) verbose=true;;
(s) start="$2";;
(-) break;;
esac
done
shift $(( OPTIND - 1))
# If function(1) = false: run 'not function()' instead
if _run 1 1 "$@" ; then
if _run "$start" "$start" "$@" ; then
not=''
else
not='!'
@ -186,8 +192,8 @@ find-first-fail() {
# exponential search for the first value that is false
# low = previous value (function($low) == true)
# high = low * 2 (function($high) == false)
high=1
while _run 1 $high "$@" ; do
high=$start
while _run $start $high "$@" ; do
low=$high
high=$(( $high*2 ))
if [ $high -gt 4611686018427387900 ] ; then