#!/usr/bin/perl

# Thanks to http://use.perl.org/~pudge/journal/10437

use Mac::Errors;
use Mac::Files;
use Mac::Resources;
   
# Source path (may be an Alias)
my $path = $ARGV[0];
if( ! -e $path ) {
	print STDERR "$path: does not exist\n";
	exit 255;
}
if( ! -r $path ) {
	print STDERR "$path: not readable\n";
	exit 254;
}

# If $path is an Alias, dereference it
my $res  = FSpOpenResFile($path, 0);
if( ! defined $res ) {
	print STDERR "$path: could not open Resource Fork\n";
	exit 1;
}

# get resource by index; get first "alis" resource
my $alis = GetIndResource('alis', 1) or die $Mac::Errors::MacError;
if (! $?) {
	$link = ResolveAlias($alis);
	print "$link\n";
}
