2 eval "exec perl -S $0 $*"
3 if $running_under_some_shell;
5 # $Id: patbase.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 # Original Author: Larry Wall <lwall@netlabs.com>
17 # $Log: patbase.SH,v $
18 # Revision 3.0.1.3 1994/01/24 14:29:24 ram
19 # patch16: added ~/.dist_profile awareness
21 # Revision 3.0.1.2 1993/08/24 12:15:58 ram
22 # patch3: random cleanup
24 # Revision 3.0.1.1 1993/08/19 06:42:32 ram
25 # patch1: leading config.sh searching was not aborting properly
27 # Revision 3.0 1993/08/18 12:10:38 ram
28 # Baseline for dist 3.0 netwide release.
34 $progname = &profile; # My name
37 &usage unless $#ARGV >= 0;
38 &usage unless &Getopts("ahV");
41 print STDERR "$progname $version PL$patchlevel\n";
49 $RCSEXT = ',v' unless $RCSEXT;
50 $TOPDIR = ''; # We are at the top-level directory
53 open(MANI,"MANIFEST.new") || die "No MANIFEST.new found.\n";
58 next if m|^patchlevel.h|; # Special file
66 foreach $file (@ARGV) {
67 $files = &rcsargs($file);
68 @files = split(' ',$files);
70 $rlog = `rlog -r$baserev -r$revbranch $files 2>&1`;
71 ($revs) = ($rlog =~ /selected revisions: (\d+)/);
73 print "$progname: $file has never been checked in--checking in...\n";
74 system 'perl', '-S', 'patcil', $file;
77 print "Last revision for $file is $baserev.\n";
78 system 'rcs', "-Nlastpat:$baserev", @files;
81 ($lastrev) = ($rlog =~ /revision $revbranch\.(\d+)/);
82 print "Last revision for $file is $revbranch.$lastrev.\n";
83 system 'rcs', "-Nlastpat:$revbranch.$lastrev", @files;
88 print STDERR "Usage: $progname [-ahV] [filelist]\n";
89 print STDERR " -a : all the files in MANIFEST.new\n";
90 print STDERR " -h : print this message and exit\n";
91 print STDERR " -V : print version number and exit\n";
96 if (! -f '.package') {
99 -f '../../.package' ||
100 -f '../../../.package' ||
101 -f '../../../../.package'
103 die "Run in top level directory only.\n";
105 die "No .package file! Run packinit.\n";
108 open(PACKAGE,'.package');
112 if (($var,$val) = /^\s*(\w+)=(.*)/) {
113 $val = "\"$val\"" unless $val =~ /^['"]/;
114 eval "\$$var = $val;";
123 while ($_ = shift(@_)) {
126 } elsif ($#_ >= 0 && do equiv($_,$_[0])) {
127 $result .= $_ . ' ' . $_[0] . ' ';
130 $result .= $_ . ' ' . do other($_) . ' ';
137 local($s1, $s2) = @_;
142 } elsif ($s1 =~ s/$RCSEXT$// || $s2 =~ s/$RCSEXT$//) {
151 ($dir,$file) = ('./',$s1) unless local($dir,$file) = ($s1 =~ m|(.*/)(.*)|);
152 $dir = $TOPDIR . $dir if -d $TOPDIR . "$dir/RCS";
153 local($wasrcs) = ($file =~ s/$RCSEXT$//);
155 `mkdir $dir` unless -d $dir;
159 `mkdir $dir` unless -d $dir;
167 local($comment) = '';
170 if (/^(.*)\$Log[:\$]/) { # They know better than us (hopefully)
177 if ($file =~ /\.SH$|[Mm]akefile/) { # Makefile template
179 } elsif ($file =~ /\.U$/) { # Metaconfig unit
181 } elsif ($file =~ /\.man$/) { # Manual page
183 } elsif ($file =~ /\.\d\w?$/) { # Manual page
185 } elsif ($file =~ /\.[chyl]$/) { # C source
187 } elsif ($file =~ /\.e$/) { # Eiffel source
189 } elsif ($file =~ /\.pl$/) { # Perl library
196 # Perform ~name expansion ala ksh...
197 # (banish csh from your vocabulary ;-)
200 return $path unless $path =~ /^~/;
201 $path =~ s:^~([^/]+):(getpwnam($1))[$[+7]:e; # ~name
202 $path =~ s:^~:$ENV{'HOME'} || (getpwuid($<))[$[+7]:e; # ~
206 # Set up profile components into %Profile, add any profile-supplied options
207 # into @ARGV and return the command invocation name.
209 local($profile) = &tilda_expand($ENV{'DIST'} || '~/.dist_profile');
210 local($me) = $0; # Command name
211 $me =~ s|.*/(.*)|$1|; # Keep only base name
212 return $me unless -s $profile;
213 local(*PROFILE); # Local file descriptor
214 local($options) = ''; # Options we get back from profile
215 unless (open(PROFILE, $profile)) {
216 warn "$me: cannot open $profile: $!\n";
222 next if /^\s*#/; # Skip comments
224 if (s/^$me://o) { # progname: options
226 $options .= $_; # Merge options if more than one line
228 elsif (s/^$me-([^:]+)://o) { # progname-component: value
231 s/^\s+//; # Trim leading and trailing spaces
233 $Profile{$component} = $_;
237 return unless $options;
238 require 'shellwords.pl';
240 eval '@opts = &shellwords($options)'; # Protect against mismatched quotes
241 unshift(@ARGV, @opts);
242 return $me; # Return our invocation name