DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
#!perl -w
package	MacCVS;

# package	Mac::Apps::MacCVS; this should really be the name of the package
# but due to our directory hierarchy in mozilla, I am not doing it

require 5.004;
require	Exporter;

use strict;

use vars qw($VERSION @ISA @EXPORT $MacCVSLib);
use Mac::StandardFile;
use Moz;
use Cwd;
use Exporter;
use File::Basename;

@ISA				= qw(Exporter);
@EXPORT			= qw( new print checkout);
$VERSION = "1.00";

# Architecture:
# cvs session object:
# name - session name
# session_file - session file
# 
# globals
# $MacCVSLib - location of MacCVS applescript library
#
# 

#
# utility routines
#

# just like Mac::DoAppleScript, 1 is success, 0 is failure
sub _myDoAppleScript($)	
{
	my($script) = @_;
	my $asresult = MacPerl::DoAppleScript($script);
	if ($asresult eq "0")
	{
		return 1;
	}
	else
	{
		print STDERR "AppleScript error: $asresult\n";
		print STDERR "AppleScript was: \n $script \n";
		return 0;
	}
}

# _useMacCVSLib
# returns 1 on success
# Search the include path for the file called MacCVSLib
sub _useMacCVSLib() 
{
	unless ( defined($MacCVSLib) )
	{
		my($libname) = "MacCVSLib";
# try the directory we were run from
		my($c) = dirname($0) . ":" . $libname;
		if ( -e $c)
		{
			$MacCVSLib = $c;
		}
		else
		{
	# now search the include directories
			foreach (@INC)
			{
				unless ( m/^Dev:Pseudo/ )	# This is some bizarre MacPerl special-case directory
				{
					$c = $_ . $libname;
					if (-e $c)
					{
						$MacCVSLib = $c;
						last;
					}
				}
			}
		}
		if (! (-e $MacCVSLib))
		{
			print STDERR "MacCVS lib could not be found! $MacCVSLib";
			return 0;
		}
	}
	return 1;
}


#
# Session object methods
#

sub new		{
	my ( $proto, $session_file) = @_;
	my $class = ref($proto) || $proto;
	my $self = {};

	if ( defined($session_file) && ( -e $session_file) )
	{
		$self->{"name"} = basename( $session_file );
		$self->{"session_file"} = $session_file;
		bless $self, $class;
		return $self;
	}
	else
	{
		print STDERR "MacCVS->new cvs file < $session_file > does not exist\n";
		return;
	}
}

# makes sure that the session is open
# assertSessionOpen()
# returns 1 on failure
sub assertSessionOpen()	{
	my ($self) = shift;
	_useMacCVSLib() || die "Could not load MacCVSLib\n";
	my $script = <<END_OF_APPLESCRIPT;
	tell (load script file "$MacCVSLib") to OpenSession("$self->{session_file}")
END_OF_APPLESCRIPT
	return _myDoAppleScript($script);
}

# prints the cvs object, used mostly for debugging
sub print {
	my($self) = shift;
	print "MacCVS:: name: ", $self->{name}, " session file: ", $self->{session_file}, "\n";
}

# checkout( self, module, revision, date)
# MacCVS checkout command
# returns 1 on failure
sub checkout {
	my($self, $module, $revision, $date ) = @_;
	unless( defined ($module) ) { $module = ""; }	# get rid of the pesky undefined warnings
	unless( defined ($revision) ) { $revision = ""; }
	unless( defined ($date) ) { $date = ""; }

	$self->assertSessionOpen() || return 1;
	
	my $script = <<END_OF_APPLESCRIPT;
	tell (load script file "$MacCVSLib") to Checkout given sessionName:"$self->{name}", module:"$module", revision:"$revision", date:"$date"
END_OF_APPLESCRIPT
	return _myDoAppleScript($script);
}

1;
=pod

=head1 NAME

MacCVS - Interface to MacCVS

=head1 SYNOPSIS

	use MacCVS;
	$session = MacCVS->new( <session_file_path>) || die "cannot create session";
	$session->checkout([module] [revision] [date]) || die "Could not check out";
		
=head1 DESCRIPTION

This is a MacCVS interface for talking to MacCVS Pro client.
MacCVSSession is the class used to manipulate the session

=item new
	MacCVS->new( <cvs session file path>);
	
	Creates a new session. Returns undef on failure.

=item checkout( <module> [revision] [date] )

	cvs checkout command. Revision and date are optional
	returns 0 on failure
	
=cut

=head1 SEE ALSO

=over

=item MacCVS Home Page

http://www.maccvs.org/

=back 

=head1 AUTHORS

Aleks Totic atotic@netscape.com

=cut

__END__