+remove_old_logfiles () {
+ base=$1
+ ## Remove old logfiles with names of the form BASE.DATE#N, so that there
+ ## are at most $MAXLOG of them.
+
+ ## Count up the logfiles.
+ nlog=0
+ for i in "$base".*; do
+ if [ ! -f "$i" ]; then continue; fi
+ nlog=$(( nlog + 1 ))
+ done
+
+ ## If there are too many, go through and delete some early ones.
+ if [ $dryrun = nil ] && [ $nlog -gt $MAXLOG ]; then
+ n=$(( nlog - MAXLOG ))
+ for i in "$base".*; do
+ if [ ! -f "$i" ]; then continue; fi
+ rm -f "$i"
+ n=$(( n - 1 ))
+ if [ $n -eq 0 ]; then break; fi
+ done
+ fi
+}
+