Files
mercury/tools/cur_param
Zoltan Somogyi 47a1a02a92 Add vim modelines to most tools.
tools/add_cont_lines:
tools/appears:
tools/assemble:
tools/avg_frame_size:
tools/build_srcdist:
tools/cleanint:
tools/compare_frame_sizes:
tools/configure_mingw_cross:
tools/cont:
tools/ctor_rep_stats:
tools/cur_param:
tools/dd_speedtest:
tools/divide:
tools/extract_dd_stats:
tools/file_name_translation_stats:
tools/frame_sizes:
tools/gdbrun:
tools/half:
tools/info_stats.awk:
tools/linear:
tools/lmc.in:
tools/mai_stats:
tools/make_arena:
tools/next_param:
tools/not:
tools/optstages:
tools/type_ctor_stats:
    Add vim mode lines. Replace tabs with spaces.
2021-04-27 03:54:27 +10:00

50 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# vim: ft=sh ts=4 sw=4 et
#
# The scripts cur_param and next_param allow their callers to cycle through
# circular lists of parameters. Both scripts take two parameters, a directory
# name and a counter name.
#
# The idea is that the user sets up the file $dir/list.$counter to contain
# a list of parameters, one per line. Each time the user calls cur_param,
# they get back as the output of the script the current parameter (initially
# the first). Each time the user calls next_param, the scripts' notion of
# the current parameter is set to the parameter on the next line of the file,
# or, if there are none left, back to the parameter on the first line.
# next_param has only this side-effect; it does not output anything.
#
# Both scripts exit with a non-zero status in case of internal error.
usage="cur_param dir counter"
if test $# != 2
then
echo $usage
exit 1
fi
dir=$1
counter=$2
if test ! -f $dir/next.$counter
then
echo 1 > $dir/next.$counter
fi
if test -s $dir/list.$counter
then
cur=`cat $dir/next.$counter`
if awk "NR == $cur" $dir/list.$counter
then
true
else
echo "$dir/list.$counter isn't long enough"
exit 1
fi
else
echo "$dir/list.$counter doesn't exist or is empty"
exit 1
fi
exit 0