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
|
#!/usr/local/bin/perl5
# Original author: Ulrich Pfeifer
# modified jglick@sig.bsh.com:
# $Id: prcs-ediff 1.2 Sat, 11 Apr 1998 17:54:43 -0700 jmacd $
use strict;
use Cwd qw(cwd);
my $use_emerge=0; # set this to 1 if you don't have the ediff package
# for emacs installed.
my $pwd = cwd;
# Get the arguments
my (
$Working_label,
$Working_file,
$Common_label,
$Common_file,
$Selected_label,
$Selected_file,
$Output_file,
) = @ARGV;
# Make paths absolute (could use &File::PathConvert::rel2abs)
for ($Working_file, $Common_file, $Selected_file, $Output_file) {
$_ = $pwd . '/' . $_ unless m!^/!;
}
my $signal = 'USR1';
my $command;
if ($use_emerge) {
# emerge supports a quit-hook as argument
my $I_am_finished = qq((lambda () (signal-process $$ \'SIG$signal)));
if ($Common_file ne '/dev/null') {
$command =
qq((emerge-files-with-ancestor nil
"$Working_file" "$Selected_file" "$Common_file" "$Output_file"
nil $I_am_finished));
} else {
$command =
qq((emerge-files nil "$Working_file" "$Selected_file" "$Output_file"
nil $I_am_finished));
}
} else {
# Ediff uses a global quit-hook. Since it does not support an output
# file as argument we use the quit-hook to store the file.
# State kept in control buffer for safety.
$command = <<LISP;
(require \'prcs-ediff)
LISP
if ($Common_file ne '/dev/null') {
$command .= <<LISP;
(ediff-files-internal
"$Working_file" "$Selected_file" "$Common_file"
nil \'ediff-merge-files-with-ancestor)
LISP
} else {
$command .= <<LISP;
(ediff-files-internal
"$Working_file" "$Selected_file" nil
nil \'ediff-merge-files)
LISP
}
$command .= <<LISP;
(prcs-merge-startup \'((working-file . "$Working_file")
(selected-file . "$Selected_file")
(common-file . "$Common_file")
(working-label . "$Working_label")
(selected-label . "$Selected_label")
(common-label . "$Common_label")
(output-file . "$Output_file")
(process . $$)
(signal . SIG$signal)))
\'OK!
LISP
}
# set up the signal handlers
$SIG{$signal} = sub {
print STDERR "Emerge $$ done\n";
exit 0;
};
$SIG{'CHLD'} = sub {
my $waitedpid = wait;
my $code = ($? >> 8);
my $sig = ($? & 0xFF);
# does not seem to correspond to reality!
return;
if ($code) {
die "Merge failed (status $code, signal $sig)";
# We should restore the working file here ;-)
}
};
my $pid;
if (!defined($pid = fork)) {
die "cannot fork: $!\n";
} elsif ($pid) {
print STDERR "Started $pid, Try 'kill -$signal $$' to terminate if things mess up\n";
sleep 5 while 1;
} else {
print STDERR $command if $ENV{PRCS_EDIFF_DEBUG};
exec 'gnudoit', $command or die "Could not run gnudoit: $!\n";
}
|