#! /bin/sh
#
# Written by Pavel Machek
#
# (C) 2000 The Free Software Foundation.
#
# FIXME: it would be much nicer to use names like track-01.wav, like cdfs does.
#

audiofs_list ()
{
cdparanoia -Q -d $1 2>&1 | grep '^[ 0-9][ 0-9][ 0-9]\.' | while true
    do
    read A B C || break
    SIZE=$[44+$B*2352]
    echo "-r--r--r--   4 0  0         $SIZE Jan  1 0:00 track${A}wav"
    done
}

audiofs_copyout ()
{
TRACK=`echo $2 | sed 's/track//' | sed 's/\.wav//'`
cdparanoia -d $1 -v $TRACK $3
}

if [ ! -b $2 ]
    then
    BASE=/dev/cdrom
else
    BASE=$2
fi

case "$1" in
  list) audiofs_list $BASE; exit 0;;
  copyout) audiofs_copyout $BASE $3 $4; exit 0;;
esac
exit 1
