#!/bin/csh -f
#
# pickint - pick out specific synch intervals from the elogdump coming
#  through the stdin.
#
# usage: elogdump foo.elog | pickint from to
# selects intervals [from..to] (inclusive). If "to" is missing, it means
# to=from. If to=0, it means print through the end of the log.
# To include the stuff before the E_BEGIN,
# use from=0. If from > to, nothing is printed. 
# Note that pickint 0 selects the whole log (a no-op). 
#
# This requires at least event codes 5, 6, and 3 to be included in the log.
#

if ($#argv < 1 || $#argv > 2) then
    echo usage: pickint from to
    exit 1
endif

if ($#argv == 2) then
    set from=$1
    set to=$2
    # empty range
    if ($from > $to && $to > 0) exit 0
else
    set from=$1
    set to=$from
endif

set P=`procdir`

set awkfile=/tmp/pickint$$
onintr cleanup

echo BEGIN "{ from=$from; to=$to;" > $awkfile
cat $P/pickint.awk >> $awkfile

# input from stdin of this script
Awk -f $awkfile

cleanup:
rm -f $awkfile
