2 eval "exec perl -S $0 $*"
3 if $running_under_some_shell;
5 # $Id: patsnap.SH 1 2006-08-24 12:32:52Z rmanfredi $
7 # Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
9 # You may redistribute only under the terms of the Artistic Licence,
10 # as specified in the README file that comes with the distribution.
11 # You may reuse parts of this distribution only within the terms of
12 # that same Artistic Licence; a copy of which may be found at the root
13 # of the source tree for dist 4.0.
15 # $Log: patsnap.SH,v $
16 # Revision 3.0.1.2 1994/01/24 14:33:08 ram
17 # patch16: now prefix error messages with program's name
18 # patch16: added ~/.dist_profile awareness
20 # Revision 3.0.1.1 1993/08/24 12:22:08 ram
27 $progname = &profile; # Read ~/.dist_profile
29 &usage unless $#ARGV >= 0;
30 &usage unless &Getopts("aho:V");
32 $SNAPSHOT = 'SNAPSHOT'; # Default snapshot file name
35 print STDERR "$progname $version PL$patchlevel\n";
43 $RCSEXT = ',v' unless $RCSEXT;
44 $TOPDIR = ''; # We are at the top-level directory
45 $SNAPSHOT = $opt_o if $opt_o;
48 open(MANI,"MANIFEST.new") || die "$progname: can't read MANIFEST.new: $!\n";
53 next if m|^patchlevel.h|; # Special file
61 open(SNAPSHOT, ">$SNAPSHOT") || die "$progname: can't create $SNAPSHOT: $!\n";
63 foreach $file (@ARGV) {
64 $files = &rcsargs($file);
65 @files = split(' ',$files);
67 $rlog = `rlog -r$baserev -r$revbranch $files 2>&1`;
68 ($revs) = ($rlog =~ /selected revisions: (\d+)/);
70 print "$progname: $file has never been checked in--skipping\n";
74 print "$progname: last revision for $file is $baserev.\n";
75 print SNAPSHOT "$file\t$baserev\n";
78 ($lastrev) = ($rlog =~ /revision $revbranch\.(\d+)/);
79 print "$progname: last revision for $file is $revbranch.$lastrev.\n";
80 print SNAPSHOT "$file\t$revbranch.$lastrev\n";
88 Usage: $progname [-ahV] [-o snapshot] [filelist]
89 -a : all the files in MANIFEST.new
90 -h : print this message and exit
91 -o : specify snapshot file output (default $SNAPSHOT)
92 -V : print version number and exit
98 if (! -f '.package') {
101 -f '../../.package' ||
102 -f '../../../.package' ||
103 -f '../../../../.package'
105 die "Run in top level directory only.\n";
107 die "No .package file! Run packinit.\n";
110 open(PACKAGE,'.package');
114 if (($var,$val) = /^\s*(\w+)=(.*)/) {
115 $val = "\"$val\"" unless $val =~ /^['"]/;
116 eval "\$$var = $val;";
125 while ($_ = shift(@_)) {
128 } elsif ($#_ >= 0 && do equiv($_,$_[0])) {
129 $result .= $_ . ' ' . $_[0] . ' ';
132 $result .= $_ . ' ' . do other($_) . ' ';
139 local($s1, $s2) = @_;
144 } elsif ($s1 =~ s/$RCSEXT$// || $s2 =~ s/$RCSEXT$//) {
153 ($dir,$file) = ('./',$s1) unless local($dir,$file) = ($s1 =~ m|(.*/)(.*)|);
154 $dir = $TOPDIR . $dir if -d $TOPDIR . "$dir/RCS";
155 local($wasrcs) = ($file =~ s/$RCSEXT$//);
157 `mkdir $dir` unless -d $dir;
161 `mkdir $dir` unless -d $dir;
169 local($comment) = '';
172 if (/^(.*)\$Log[:\$]/) { # They know better than us (hopefully)
179 if ($file =~ /\.SH$|[Mm]akefile/) { # Makefile template
181 } elsif ($file =~ /\.U$/) { # Metaconfig unit
183 } elsif ($file =~ /\.man$/) { # Manual page
185 } elsif ($file =~ /\.\d\w?$/) { # Manual page
187 } elsif ($file =~ /\.[chyl]$/) { # C source
189 } elsif ($file =~ /\.e$/) { # Eiffel source
191 } elsif ($file =~ /\.pl$/) { # Perl library
198 # Perform ~name expansion ala ksh...
199 # (banish csh from your vocabulary ;-)
202 return $path unless $path =~ /^~/;
203 $path =~ s:^~([^/]+):(getpwnam($1))[$[+7]:e; # ~name
204 $path =~ s:^~:$ENV{'HOME'} || (getpwuid($<))[$[+7]:e; # ~
208 # Set up profile components into %Profile, add any profile-supplied options
209 # into @ARGV and return the command invocation name.
211 local($profile) = &tilda_expand($ENV{'DIST'} || '~/.dist_profile');
212 local($me) = $0; # Command name
213 $me =~ s|.*/(.*)|$1|; # Keep only base name
214 return $me unless -s $profile;
215 local(*PROFILE); # Local file descriptor
216 local($options) = ''; # Options we get back from profile
217 unless (open(PROFILE, $profile)) {
218 warn "$me: cannot open $profile: $!\n";
224 next if /^\s*#/; # Skip comments
226 if (s/^$me://o) { # progname: options
228 $options .= $_; # Merge options if more than one line
230 elsif (s/^$me-([^:]+)://o) { # progname-component: value
233 s/^\s+//; # Trim leading and trailing spaces
235 $Profile{$component} = $_;
239 return unless $options;
240 require 'shellwords.pl';
242 eval '@opts = &shellwords($options)'; # Protect against mismatched quotes
243 unshift(@ARGV, @opts);
244 return $me; # Return our invocation name