END
}
+# Copyright 2006 Ian Jackson <ian@chiark.greenend.org.uk>
+#
+# This script and its documentation (if any) are free software; you
+# can redistribute it and/or modify them under the terms of the GNU
+# General Public License as published by the Free Software Foundation;
+# either version 3, or (at your option) any later version.
+#
+# chiark-named-conf and its manpage are distributed in the hope that
+# it will be useful, but WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, consult the Free Software Foundation's
+# website at www.fsf.org, or the GNU Project website at www.gnu.org.
+
+
trap 'exit 16' 0
badusage () { echo >&2 "bad usage: $*"; usage >&2; trap '' 0; exit 8; }
# We process each minimum/extent pair, to have it select a bunch of
# versions to keep. We annotate entries in $l: if we are keeping
-# an entry we prepend a colon.
+# an entry we prepend a colon; temporarily, if we are keeping an entry
+# because of this particular minimum/extent, we prepend a comma.
# For each minimum/extent pair we look at the list from most recent
# to least recent,
)
for ni in "$@"; do
- min=$(( ${ni#*x} * $unit - $slop ))
wantcount=${ni%x*}
- ls=''
+ div=1
+
+ while true; do
+ min=$(( (${ni#*x} * $unit) / $div - $slop ))
+
+ ls=''
+ lnew=''
+ skipped=0
+ for ce in $l; do
+ cn=${ce#*/}; cl=${ce%%/*}
+ cs=${cl#,}; cs=${cs#:}
+ case $cl in ,*) ls=$cs; continue;; esac
+ if [ $wantcount != 0 ]; then
+ if ! [ "$ls" ] || \
+ [ $(( $ls - $cs )) -ge $min ]; then
+ echo "keep (for $ni) $cn"
+ ce=,$ce
+ ls=$cs
+ wantcount=$(( $wantcount - 1 ))
+ else
+ skipped=$(( $skipped+1 ))
+ fi
+ fi
+ lnew="$lnew $ce"
+ done
+ l=$lnew
+
+ if [ $wantcount = 0 ]; then break; fi
+ printf "%s" "insufficient (for $ni) by $wantcount"
+ if [ $skipped = 0 ]; then echo; break; fi
+ div=$(( $div * 2 ))
+ echo " shortening interval ${div}x"
+ done
+
+ # s/([,:]+).*/:\1/g
lnew=''
for ce in $l; do
- cn=${ce#*/}; cl=${ce%%/*}; cs=${cl#:}
- if [ $wantcount != 0 ]; then
- if ! [ "$ls" ] || \
- [ $(( $ls - $cs )) -ge $min ]; then
- echo "keep (for $ni) $cn"
- ls=$cs
- ce=:$cs/$cn
- wantcount=$(( $wantcount - 1 ))
- fi
- fi
+ case $ce in ,*) ce=:${ce#,};; esac
+ case $ce in ::*) ce=${ce#:};; esac
lnew="$lnew $ce"
done
- if [ $wantcount != 0 ];then
- echo "insufficient (for $ni) by $wantcount"
- fi
l=$lnew
done