#!/usr/bin/perl -w
#
# Part of the cbm4linux_utils package
# Copyright (C) 2001  Hugo Cornelis <hugo@bbf.uia.ac.be>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cbm4linux, a linux loadable module to attach a cbm 
# drive to a linux box, available at http://sta.c64.org/ ;
# if not, write to the Free Software Foundation, 
# Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Project: cbm4linux_utils $
# $ProjectHeader: cbm4linux_utils 0.5 Thu, 16 Aug 2001 16:16:48 +0200 cbm64 $
# $Id: d64copy 1.2 Thu, 09 Aug 2001 16:57:22 +0200 cbm64 $
#


=head1 NAME 

C<d64copy> - Automatically create a set of .d64 files.

=head1 SYNOPSIS

  d64copy

=head1 DESCRIPTION

Automatically create a set of .d64 files in appropriate 
subdirectories for indexing them with d64index.

Subdirectories are numbered from 1 upwards, if interrupted, d64copy 
tries to guess the next directory number.  Inside directories, disks 
are normally named side_1.d64 and side_2.d64.  To skip the b side,
let the program flip without a disk :-), it will continue afterwards.

If you want to quit, type one of 'qQnN' to the question.  You can
continue copying two days later if you want, the directory numbers
will increase as needed.

You need the perl script 'C<nextdir>' in your C<$PATH> variable

=head1 SEE ALSO

cbmctrl(1),d64index(1)

=cut


# get next dir

my $dir = `nextdir` ;

my $bCont = 1 ;

while ( $bCont )
  {
    # ask if continue

    print "Ok to continue with disk $dir side a ?\n" ;

    my $ans = <STDIN> ;

    if ( $ans !~ /[qQnN]/ )
      {
	# create dir
	
	print "Creating $dir\n" ;
	
	mkdir $dir,0755 ;
	
	# copy disk to dir
	
	chdir $dir ;

#	system "d64copy -h" ;

	system "d64copy -t serial2 8 side_1.d64" ;
	
	print "Ok to continue with disk $dir side b ?\n" ;

	$ans = <STDIN> ;

	if ( $ans !~ /[qQnN]/ )
	  {
	    system "d64copy -t serial2 8 side_2.d64" ;
	  }
	else
	  {
	    $bCont = 0 ;
	  }

	chdir ".." ;
	
	# get next dir entry
	
	$dir = `nextdir` ;
      }
    else
      {
	$bCont = 0 ;
      }
  }
