#!/usr/bin/perl
#
# csf2tar - make tar 'module' from csf file

if ($#ARGV != 0)
  {
  print "usage: csf2tar filename.csf\n";
  exit 1;
  }

if (!open(IN,$ARGV[0]))
  {
  print "Couldn't open '$ARGV[0]'.\n";
  exit 1;
  }

# work out samples to store in tar file.
# we use an associative array as a nice easy way of eliminating
# duplicates.

while (<IN>)
  {
  if ((/^\*samples/ .. /^\*blocklist/) && !/^[\*\#]/)
    {
    s/[ \t]+[0-9]+$//;
    @samples{$_}='x';
    }
  }

$samples=join(' ',keys(%samples));
$samples=~s/\n//g;

$tarfile=$ARGV[0];
$tarfile=~s/\.csf$/.tar/;
$tarfile='out.tar' if $tarfile eq $ARGV[0];

system "tar -cvvf $tarfile $ARGV[0] $samples";

# 
# Local Variables:
# mode:alt-c
# End:
