#! /usr/bin/perl
# 
# $Header: /cvsroot/netatalk/netatalk/contrib/shell_utils/apple_rm,v 1.2 2000/08/09 14:12:06 rufustfirefly Exp $
#
# $Log: apple_rm,v $
# Revision 1.2  2000/08/09 14:12:06  rufustfirefly
# /usr/local/bin/perl -> /usr/bin/perl and portability fixes
#
# Revision 1.1  2000/08/09 14:08:06  rufustfirefly
# Shell utils from http://www.-genome.wi.mit.edu/ftp/distribution/software/Bass/bass-1.29/apple_util/ (initial import)
#
# Revision 1.1  1996/04/03 02:13:14  lstein
# Added all these files because they're essential utilities.
#
# Revision 1.1  1996/02/09  18:21:35  will
# Initial revision
#
#

$USAGE = <<USAGE;
Usage: $0 filename ...
Do an apple remove, remove the resource fork as well
USAGE

die $USAGE if @ARGV < 1;

foreach $path (@ARGV) {
    if (!-f $path) {
	print STDERR "file $path does not exist\n";
	die $USAGE;
    }

    ($dir, $file) = &split_dir_file($path);

    $cmd = "rm '$path'";
    system $cmd || die "error executing $cmd";
    
    $cmd = "rm '$dir/.AppleDouble/$file'";
    system $cmd || die "error executing $cmd";
}

# split a file path into a directory and file name.
sub split_dir_file {
    my $path = shift;

    @path_elems = split(/\//, $path);

    my $file = pop(@path_elems);
    my $dir;
    if (!@path_elems) {
	$dir = '.';
    } else {
	$dir = join('/', @path_elems);
    }

    $dir, $file;
}
